Advertisement
bigrushdog

Untitled

Sep 18th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.61 KB | None | 0 0
  1.  
  2. package com.android.settings.eos;
  3.  
  4. import android.content.Context;
  5. import android.content.pm.PackageManager;
  6. import android.content.pm.PackageManager.NameNotFoundException;
  7. import android.content.pm.ResolveInfo;
  8. import android.content.res.Configuration;
  9. import android.content.res.Resources;
  10. import android.util.DisplayMetrics;
  11.  
  12. public class AppConfigPackage extends AppPackage {
  13.     public static final int TABLET_MODE = Configuration.SCREENLAYOUT_SIZE_XLARGE
  14.             & ~Configuration.SCREENLAYOUT_SIZE_MASK;
  15.     public static final int HYBRID_MODE = Configuration.SCREENLAYOUT_SIZE_LARGE
  16.             & ~Configuration.SCREENLAYOUT_SIZE_MASK;
  17.     public static final int PHONE_MODE = Configuration.SCREENLAYOUT_SIZE_NORMAL
  18.             & ~Configuration.SCREENLAYOUT_SIZE_MASK;
  19.     public static final int TINY_MODE = Configuration.SCREENLAYOUT_SIZE_SMALL
  20.             & ~Configuration.SCREENLAYOUT_SIZE_MASK;
  21.  
  22.     Context mContext;
  23.     Resources mAppRes;
  24.     Configuration mStockConfig;
  25.     Configuration mCustomConfig;
  26.     boolean mDisabled = false;
  27.  
  28.     // needed for updating package configuration
  29.     // i think. So we can make it static and set from calling class
  30.     static DisplayMetrics mMetrics;
  31.  
  32.     AppConfigPackage(ResolveInfo ri, PackageManager pm) {
  33.         super(ri, pm);
  34.         try {
  35.             mAppRes = pm.getResourcesForActivity(getComponent());
  36.             mStockConfig = mAppRes.getConfiguration();
  37.         } catch (NameNotFoundException e) {
  38.             // TODO Auto-generated catch block
  39.             e.printStackTrace();
  40.             mStockConfig = null;
  41.             mCustomConfig = null;
  42.             mAppRes = null;
  43.             mDisabled = true;
  44.         }
  45.         if (mStockConfig != null) {
  46.             mCustomConfig = mStockConfig;
  47.         }
  48.     }
  49.    
  50.     public void setStockConfig() {
  51.         mCustomConfig = mStockConfig;
  52.         mAppRes.updateConfiguration(mCustomConfig, getDisplayMetrics());
  53.     }
  54.  
  55.     public boolean setCustomConfig(int mode) {
  56.         if (mCustomConfig == null)
  57.             return false;
  58.         if (mode != TABLET_MODE
  59.                 || mode != HYBRID_MODE
  60.                 || mode != PHONE_MODE
  61.                 || mode != TINY_MODE) {
  62.             return false;
  63.         }
  64.         mCustomConfig.screenLayout = mode;
  65.         mAppRes.updateConfiguration(mCustomConfig, getDisplayMetrics());
  66.         return true;
  67.     }
  68.  
  69.     // just in case something goes wrong in constructor
  70.     public boolean isFeatureDisabled() {
  71.         return mDisabled;
  72.     }
  73.  
  74.     public static DisplayMetrics getDisplayMetrics() {
  75.         return mMetrics;
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement