diff options
author | Yvonne Wong <ywong@cyngn.com> | 2015-10-09 13:26:24 -0700 |
---|---|---|
committer | emancebo <emancebo@cyngn.com> | 2015-10-09 18:18:46 -0700 |
commit | 585b522239eb0d329029bad53db6566b564da485 (patch) | |
tree | 440f2f0cc8e2b919bd4c592ba27e0dace8c5456e | |
parent | e81b6f7219497c26c5532f6afaa3c13474334914 (diff) | |
download | android_packages_apps_Trebuchet-585b522239eb0d329029bad53db6566b564da485.tar.gz android_packages_apps_Trebuchet-585b522239eb0d329029bad53db6566b564da485.tar.bz2 android_packages_apps_Trebuchet-585b522239eb0d329029bad53db6566b564da485.zip |
Trebuchet: make workspace layout configurable by prebundled mcc
issue-id: PAELLA-42
Change-Id: Ice4f73ee6ebaa55e27c07a02f1cc5b989f91c59a
-rw-r--r-- | res/values/cm_strings.xml | 1 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherAppState.java | 48 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherProvider.java | 54 |
3 files changed, 100 insertions, 3 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index c15a813e8..6fbde6a11 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -48,6 +48,7 @@ <!-- Folder titles --> <string name="google_title" translatable="false">Google</string> <string name="play_folder_title">Play</string> + <string name="partner_title" translatable="false"></string> <!-- Scroll effect --> <string name="scroll_effect_text">Scroll effect</string> diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index a207f1e2c..1d75dfa6e 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -27,6 +27,11 @@ import android.content.res.Resources; import android.database.ContentObserver; import android.os.Handler; import android.util.Log; +import android.content.pm.PackageManager; +import android.content.res.AssetManager; +import android.os.SystemProperties; +import android.text.TextUtils; +import android.util.DisplayMetrics; import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo; @@ -40,6 +45,8 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks { private static final boolean DEBUG = false; + private static final String MCC_PROP_NAME = "ro.prebundled.mcc"; + private final AppFilter mAppFilter; private final BuildInfo mBuildInfo; private LauncherModel mModel; @@ -200,15 +207,52 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks { int width, int height, int availableWidth, int availableHeight) { + Resources resources = context.getResources(); + String mcc = SystemProperties.get(MCC_PROP_NAME); + if (!TextUtils.isEmpty(mcc)) { + Log.d(TAG, "mcc not empty: " + mcc); + + Configuration tempConfiguration = new Configuration(resources.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 + e.printStackTrace(); + } + + if (shouldUseTempConfig) { + String publicSrcDir = null; + try { + String packageName = sContext.getPackageName(); + publicSrcDir = sContext.getPackageManager().getApplicationInfo(packageName, + 0).publicSourceDir; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + + AssetManager assetManager = new AssetManager(); + if (!TextUtils.isEmpty(publicSrcDir)) { + assetManager.addAssetPath(publicSrcDir); + } + + resources = new Resources(assetManager, new DisplayMetrics(), + tempConfiguration); + } + } + + mDynamicGrid = new DynamicGrid(context, - context.getResources(), + resources, minWidth, minHeight, width, height, availableWidth, availableHeight); mDynamicGrid.getDeviceProfile().addCallback(this); // Update the icon size DeviceProfile grid = mDynamicGrid.getDeviceProfile(); - grid.updateFromConfiguration(context, context.getResources(), width, height, + grid.updateFromConfiguration(context, resources, width, height, availableWidth, availableHeight); return grid; } diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index f1b7d337c..4a9da6ba9 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -35,6 +35,9 @@ import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.content.pm.PackageManager; +import android.content.res.AssetManager; +import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.database.Cursor; @@ -47,8 +50,10 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; +import android.os.SystemProperties; import android.provider.Settings; import android.text.TextUtils; +import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseArray; @@ -106,6 +111,8 @@ public class LauncherProvider extends ContentProvider { static final Uri CONTENT_APPWIDGET_RESET_URI = Uri.parse("content://" + AUTHORITY + "/appWidgetReset"); + private static final String MCC_PROP_NAME = "ro.prebundled.mcc"; + private DatabaseHelper mOpenHelper; private static boolean sJustLoadedFromOldDb; @@ -325,11 +332,56 @@ public class LauncherProvider extends ContentProvider { SharedPreferences sp = getContext().getSharedPreferences(spKey, Context.MODE_PRIVATE); if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) { - Log.d(TAG, "loading default workspace"); + if (LOGD) Log.d(TAG, "loading default workspace"); WorkspaceLoader loader = AutoInstallsLayout.get(getContext(), mOpenHelper.mAppWidgetHost, mOpenHelper); + String mcc = SystemProperties.get(MCC_PROP_NAME); + + 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 + e.printStackTrace(); + } + + if (shouldUseTempConfig) { + String publicSrcDir = null; + try { + String packageName = getContext().getPackageName(); + publicSrcDir = getContext().getPackageManager(). + getApplicationInfo(packageName, 0).publicSourceDir; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + + AssetManager assetManager = new AssetManager(); + if (!TextUtils.isEmpty(publicSrcDir)) { + assetManager.addAssetPath(publicSrcDir); + } + Resources customResources = new Resources(assetManager, new DisplayMetrics(), + tempConfiguration); + + int mccLayout = LauncherAppState.getInstance() + .getDynamicGrid().getDeviceProfile().defaultLayoutId; + + if (mccLayout != 0) { + if (LOGD) Log.d(TAG, "mcc layout id: " + mccLayout); + + loader = new SimpleWorkspaceLoader(mOpenHelper, customResources, mccLayout); + } + } + } + if (loader == null) { final Partner partner = Partner.get(getContext().getPackageManager()); if (partner != null && partner.hasDefaultLayout()) { |