中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

獲得屏幕相關(guān)的Android輔助類

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
    import android.app.Activity;  
    import android.content.Context;  
    import android.graphics.Bitmap;  
    import android.graphics.Rect;  
    import android.util.DisplayMetrics;  
    import android.view.View;  
    import android.view.WindowManager;  
      
    //獲得屏幕相關(guān)的輔助類  
    public class ScreenUtils  
    {  
        private ScreenUtils()  
        {  
            /* cannot be instantiated */  
            throw new UnsupportedOperationException("cannot be instantiated");  
        }  
      
        /** 
         * 獲得屏幕高度 
         *  
         * @param context 
         * @return 
         */  
        public static int getScreenWidth(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(Context context)  
        {  
            WindowManager wm = (WindowManager) context  
                    .getSystemService(Context.WINDOW_SERVICE);  
            DisplayMetrics outMetrics = new DisplayMetrics();  
            wm.getDefaultDisplay().getMetrics(outMetrics);  
            return outMetrics.heightPixels;  
        }  
      
        /** 
         * 獲得狀態(tài)欄的高度 
         *  
         * @param context 
         * @return 
         */  
        public static int getStatusHeight(Context context)  
        {  
      
            int statusHeight = -1;  
            try  
            {  
                Class<?> clazz = Class.forName("com.android.internal.R$dimen");  
                Object object = clazz.newInstance();  
                int height = Integer.parseInt(clazz.getField("status_bar_height")  
                        .get(object).toString());  
                statusHeight = context.getResources().getDimensionPixelSize(height);  
            } catch (Exception e)  
            {  
                e.printStackTrace();  
            }  
            return statusHeight;  
        }  
      
        /** 
         * 獲取當(dāng)前屏幕截圖,包含狀態(tài)欄 
         *  
         * @param activity 
         * @return 
         */  
        public static Bitmap snapShotWithStatusBar(Activity activity)  
        {  
            View view = activity.getWindow().getDecorView();  
            view.setDrawingCacheEnabled(true);  
            view.buildDrawingCache();  
            Bitmap bmp = view.getDrawingCache();  
            int width = getScreenWidth(activity);  
            int height = getScreenHeight(activity);  
            Bitmap bp = null;  
            bp = Bitmap.createBitmap(bmp, 0, 0, width, height);  
            view.destroyDrawingCache();  
            return bp;  
      
        }  
      
        /** 
         * 獲取當(dāng)前屏幕截圖,不包含狀態(tài)欄 
         *  
         * @param activity 
         * @return 
         */  
        public static Bitmap snapShotWithoutStatusBar(Activity activity)  
        {  
            View view = activity.getWindow().getDecorView();  
            view.setDrawingCacheEnabled(true);  
            view.buildDrawingCache();  
            Bitmap bmp = view.getDrawingCache();  
            Rect frame = new Rect();  
            activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);  
            int statusBarHeight = frame.top;  
      
            int width = getScreenWidth(activity);  
            int height = getScreenHeight(activity);  
            Bitmap bp = null;  
            bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height  
                    - statusBarHeight);  
            view.destroyDrawingCache();  
            return bp;  
      
        }  
      
    }  

標(biāo)簽: isp

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:Android設(shè)備判斷網(wǎng)絡(luò)連接狀態(tài)

下一篇:最新電話號(hào)碼驗(yàn)證正則表達(dá)式