/*
 * Copyright (C) 2015, 程序亦非猿
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package me.yifeiyuan.utils;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.WindowManager;

/**
 * Created by 程序亦非猿 on 16/1/7.
 */
public class ScreenUtil {

    /**
     * 获得屏幕高度
     *
     * @param context
     * @return
     */
    public static int getScreenWidth(@NonNull Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.widthPixels;
    }

    /**
     * 获得屏幕宽度
     *
     * @param context
     * @return
     */
    public static int getScreenHeight(@NonNull Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.heightPixels;
    }

    /**
     * 获取状态栏高度
     * @param context
     * @return 状态栏高度  默认为0
     */
    public static int getStatusBarHeight(@NonNull Context context) {
        int result = 0;

        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");

        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }

        return result;
    }

    /**
     * 获取toolbar的高度
     * @param context
     * @return 默认为0
     */
    public static int getToolbarHeight(@NonNull Context context) {
        TypedValue typedValue = new TypedValue();

        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
            return TypedValue.complexToDimensionPixelSize(typedValue.data, context.getResources().getDisplayMetrics());
        }

        return 0;
    }
}

@@ -634,22 +634,113 @@
 oid.
-content.Contex
+app.Activity;%0Aimport android.content.Context;%0Aimport android.graphics.Bitmap;%0Aimport android.graphics.Rec
 t;%0Ai
@@ -817,16 +817,16 @@
 etrics;%0A
-
 import a
@@ -849,16 +849,42 @@
 dValue;%0A
+import android.view.View;%0A
 import a
@@ -2639,11 +2639,1324 @@
 0;%0A    %7D
+%0A%0A    /**%0A     * %E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE %E5%8C%85%E5%90%AB%E7%8A%B6%E6%80%81%E6%A0%8F%0A     * @param activity%0A     * @return%0A     */%0A    public static Bitmap snapShotWithStatusBar(@NonNull Activity activity) %7B%0A        View view = activity.getWindow().getDecorView();%0A        view.setDrawingCacheEnabled(true);%0A        view.buildDrawingCache();%0A        Bitmap bmp = view.getDrawingCache();%0A        int width = getScreenWidth(activity);%0A        int height = getScreenHeight(activity);%0A        Bitmap bp = null;%0A        bp = Bitmap.createBitmap(bmp, 0, 0, width, height);%0A        view.destroyDrawingCache();%0A        return bp;%0A%0A    %7D%0A%0A    /**%0A     * %E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE %E4%BD%86%E4%B8%8D%E5%8C%85%E5%90%AB%E7%8A%B6%E6%80%81%E6%A0%8F%0A     * @param activity%0A     * @return%0A     */%0A    public static Bitmap snapShotWithoutStatusBar(@NonNull Activity activity) %7B%0A        View view = activity.getWindow().getDecorView();%0A        view.setDrawingCacheEnabled(true);%0A        view.buildDrawingCache();%0A        Bitmap bmp = view.getDrawingCache();%0A        Rect frame = new Rect();%0A        view.getWindowVisibleDisplayFrame(frame);%0A        int statusBarHeight = frame.top;%0A%0A        int width = getScreenWidth(activity);%0A        int height = getScreenHeight(activity);%0A        Bitmap bp = null;%0A        bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height- statusBarHeight);%0A        view.destroyDrawingCache();%0A        return bp;%0A%0A    %7D%0A%0A
 %0A%7D%0A

update screen