diff options
author | cretin45 <cretin45@gmail.com> | 2016-05-11 14:30:53 -0700 |
---|---|---|
committer | Ed Carrigan <cretin45@gmail.com> | 2016-05-11 14:59:01 -0700 |
commit | ae9635267a160d9cb99e03d9a5a614a4c67198b1 (patch) | |
tree | 7801ce04eca1a664399c73852ebba517c1983520 | |
parent | 87ab24a020b3a91ff3b1e8d97d36404193644a3d (diff) | |
download | android_packages_apps_Trebuchet-ae9635267a160d9cb99e03d9a5a614a4c67198b1.tar.gz android_packages_apps_Trebuchet-ae9635267a160d9cb99e03d9a5a614a4c67198b1.tar.bz2 android_packages_apps_Trebuchet-ae9635267a160d9cb99e03d9a5a614a4c67198b1.zip |
Trebuchet: Make workspace layout configurable by prebundled mcc
Ported patch: http://review.cyanogenmod.org/#/c/111725/
Issue-id: PAELLA-236
Change-Id: I1d02cfc4f1e7e7fc5b1aaf326072b0ffe8966c05
(cherry picked from commit fe7faac0dba67667ae671e6cf59c9706d45e579b)
-rw-r--r-- | src/com/android/launcher3/LauncherProvider.java | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 8047e7c16..3ae2ea599 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -30,7 +30,10 @@ import android.content.Context; import android.content.Intent; import android.content.OperationApplicationException; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.AssetManager; +import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.database.SQLException; @@ -44,8 +47,10 @@ import android.os.Build; import android.os.Bundle; import android.os.Process; import android.os.StrictMode; +import android.os.SystemProperties; import android.os.UserManager; import android.text.TextUtils; +import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseArray; @@ -79,6 +84,8 @@ public class LauncherProvider extends ContentProvider { private static final String RESTRICTION_PACKAGE_NAME = "workspace.configuration.package.name"; + private static final String MCC_PROP_NAME = "ro.prebundled.mcc"; + @Thunk LauncherProviderChangeListener mListener; @Thunk DatabaseHelper mOpenHelper; @@ -442,10 +449,50 @@ public class LauncherProvider extends ContentProvider { } private DefaultLayoutParser getDefaultLayoutParser() { + String mcc = SystemProperties.get(MCC_PROP_NAME); + Resources customResources = null; + if (!TextUtils.isEmpty(mcc)) { + if (LOGD) Log.d(TAG, "mcc: " + mcc); + + Configuration tempConfiguration = new Configuration(getContext().getResources(). + getConfiguration()); + boolean shouldUseTempConfig = false; + + try { + tempConfiguration.mcc = Integer.parseInt(mcc); + shouldUseTempConfig = true; + } catch (NumberFormatException e) { + // not able to parse mcc, catch exception and exit out of this logic + Log.e(TAG, "Unable to parse mcc", e); + } + + if (shouldUseTempConfig) { + String publicSrcDir = null; + try { + String packageName = getContext().getPackageName(); + publicSrcDir = getContext().getPackageManager(). + getApplicationInfo(packageName, 0).publicSourceDir; + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, "Failed getting source dir", e); + } + + AssetManager assetManager = new AssetManager(); + if (!TextUtils.isEmpty(publicSrcDir)) { + assetManager.addAssetPath(publicSrcDir); + } + customResources = new Resources(assetManager, new DisplayMetrics(), + tempConfiguration); + } + } + int defaultLayout = LauncherAppState.getInstance() .getInvariantDeviceProfile().defaultLayoutId; + return new DefaultLayoutParser(getContext(), mOpenHelper.mAppWidgetHost, - mOpenHelper, getContext().getResources(), defaultLayout); + mOpenHelper, customResources != null ? + customResources : + getContext().getResources(), + defaultLayout); } public void migrateLauncher2Shortcuts() { |