Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.android.settings.eos;
- import android.content.Context;
- import android.content.pm.PackageManager;
- import android.content.pm.PackageManager.NameNotFoundException;
- import android.content.pm.ResolveInfo;
- import android.content.res.Configuration;
- import android.content.res.Resources;
- import android.util.DisplayMetrics;
- public class AppConfigPackage extends AppPackage {
- public static final int TABLET_MODE = Configuration.SCREENLAYOUT_SIZE_XLARGE
- & ~Configuration.SCREENLAYOUT_SIZE_MASK;
- public static final int HYBRID_MODE = Configuration.SCREENLAYOUT_SIZE_LARGE
- & ~Configuration.SCREENLAYOUT_SIZE_MASK;
- public static final int PHONE_MODE = Configuration.SCREENLAYOUT_SIZE_NORMAL
- & ~Configuration.SCREENLAYOUT_SIZE_MASK;
- public static final int TINY_MODE = Configuration.SCREENLAYOUT_SIZE_SMALL
- & ~Configuration.SCREENLAYOUT_SIZE_MASK;
- Context mContext;
- Resources mAppRes;
- Configuration mStockConfig;
- Configuration mCustomConfig;
- boolean mDisabled = false;
- // needed for updating package configuration
- // i think. So we can make it static and set from calling class
- static DisplayMetrics mMetrics;
- AppConfigPackage(ResolveInfo ri, PackageManager pm) {
- super(ri, pm);
- try {
- mAppRes = pm.getResourcesForActivity(getComponent());
- mStockConfig = mAppRes.getConfiguration();
- } catch (NameNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- mStockConfig = null;
- mCustomConfig = null;
- mAppRes = null;
- mDisabled = true;
- }
- if (mStockConfig != null) {
- mCustomConfig = mStockConfig;
- }
- }
- public void setStockConfig() {
- mCustomConfig = mStockConfig;
- mAppRes.updateConfiguration(mCustomConfig, getDisplayMetrics());
- }
- public boolean setCustomConfig(int mode) {
- if (mCustomConfig == null)
- return false;
- if (mode != TABLET_MODE
- || mode != HYBRID_MODE
- || mode != PHONE_MODE
- || mode != TINY_MODE) {
- return false;
- }
- mCustomConfig.screenLayout = mode;
- mAppRes.updateConfiguration(mCustomConfig, getDisplayMetrics());
- return true;
- }
- // just in case something goes wrong in constructor
- public boolean isFeatureDisabled() {
- return mDisabled;
- }
- public static DisplayMetrics getDisplayMetrics() {
- return mMetrics;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement