CompatibilityInfo.java revision 2f5e6b2d31f445a4e9faf3a7ace94f9ef6948336
1/* 2 * Copyright (C) 2006 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 17package android.content.res; 18 19import android.content.pm.ApplicationInfo; 20import android.util.DisplayMetrics; 21import android.view.Gravity; 22 23/** 24 * CompatibilityInfo class keeps the information about compatibility mode that the application is 25 * running under. 26 * 27 * {@hide} 28 */ 29public class CompatibilityInfo { 30 /** default compatibility info object for compatible applications */ 31 public static final CompatibilityInfo DEFAULT_COMPATIBILITY_INFO = new CompatibilityInfo(); 32 33 /** 34 * The default width of the screen in portrait mode. 35 */ 36 public static final int DEFAULT_PORTRAIT_WIDTH = 320; 37 38 /** 39 * The default height of the screen in portrait mode. 40 */ 41 public static final int DEFAULT_PORTRAIT_HEIGHT = 480; 42 43 /** 44 * Application's scale. 45 */ 46 public final float mApplicationScale; 47 48 /** 49 * Application's inverted scale. 50 */ 51 public final float mApplicationInvertedScale; 52 53 /** 54 * 55 * A boolean flag to indicates that the application can expand over the original size. 56 */ 57 public final boolean mExpandable; 58 59 /** 60 * A boolean flag to tell if the application needs scaling (when mApplicationScale != 1.0f) 61 */ 62 public final boolean mScalingRequired; 63 64 public CompatibilityInfo(ApplicationInfo appInfo) { 65 // A temp workaround to fix rotation issue. 66 // mExpandable = appInfo.expandable; 67 mExpandable = true; 68 float packageDensityScale = -1.0f; 69 if (appInfo.supportsDensities != null) { 70 int minDiff = Integer.MAX_VALUE; 71 for (int density : appInfo.supportsDensities) { 72 int tmpDiff = Math.abs(DisplayMetrics.DEVICE_DENSITY - density); 73 if (tmpDiff == 0) { 74 packageDensityScale = 1.0f; 75 break; 76 } 77 // prefer higher density (appScale>1.0), unless that's only option. 78 if (tmpDiff < minDiff && packageDensityScale < 1.0f) { 79 packageDensityScale = DisplayMetrics.DEVICE_DENSITY / (float) density; 80 minDiff = tmpDiff; 81 } 82 } 83 } 84 if (packageDensityScale > 0.0f) { 85 mApplicationScale = packageDensityScale; 86 } else { 87 mApplicationScale = DisplayMetrics.DEVICE_DENSITY / (float) DisplayMetrics.DEFAULT_DENSITY; 88 } 89 mApplicationInvertedScale = 1.0f / mApplicationScale; 90 mScalingRequired = mApplicationScale != 1.0f; 91 } 92 93 private CompatibilityInfo() { 94 mApplicationScale = mApplicationInvertedScale = 1.0f; 95 mExpandable = true; 96 mScalingRequired = false; 97 } 98 99 @Override 100 public String toString() { 101 return "CompatibilityInfo{scale=" + mApplicationScale + 102 ", expandable=" + mExpandable + "}"; 103 } 104} 105