Home | History | Annotate | Download | only in base
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.documentsui.base;
     18 
     19 import android.app.Activity;
     20 import android.content.Context;
     21 import android.graphics.Point;
     22 import android.util.TypedValue;
     23 
     24 /*
     25  * Convenience class for getting display related attributes
     26  */
     27 public final class Display {
     28     /*
     29      * Returns the screen width in raw pixels.
     30      */
     31     public static float screenWidth(Activity activity) {
     32         Point size = new Point();
     33         activity.getWindowManager().getDefaultDisplay().getSize(size);
     34         return size.x;
     35     }
     36 
     37     /*
     38      * Returns logical density of the display.
     39      */
     40     public static float density(Context context) {
     41         return context.getResources().getDisplayMetrics().density;
     42     }
     43 
     44     /*
     45      * Returns action bar height in raw pixels.
     46      */
     47     public static float actionBarHeight(Context context) {
     48         int actionBarHeight = 0;
     49         TypedValue tv = new TypedValue();
     50         if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
     51             actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
     52                     context.getResources().getDisplayMetrics());
     53         }
     54         return actionBarHeight;
     55     }
     56 }
     57