summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYvonne Wong <ywong@cyngn.com>2015-10-09 13:26:24 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-10-09 17:59:53 -0700
commit486bcb308dd39e341250348fef68414c0015b656 (patch)
tree67c9959e3c94a0712b8a64c3b8ad596127be9f68
parent769805b18f1627d0650b3126d5edcc68550bedec (diff)
downloadandroid_packages_apps_Trebuchet-486bcb308dd39e341250348fef68414c0015b656.tar.gz
android_packages_apps_Trebuchet-486bcb308dd39e341250348fef68414c0015b656.tar.bz2
android_packages_apps_Trebuchet-486bcb308dd39e341250348fef68414c0015b656.zip
Trebuchet: make workspace layout configurable by prebundled mcc
issue-id: PAELLA-42 Change-Id: Ice4f73ee6ebaa55e27c07a02f1cc5b989f91c59a
-rw-r--r--res/values/cm_strings.xml1
-rw-r--r--src/com/android/launcher3/LauncherAppState.java49
-rw-r--r--src/com/android/launcher3/LauncherProvider.java55
3 files changed, 102 insertions, 3 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 225e3358e..7602ac107 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 efa203769..c55adfcf6 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -23,12 +23,16 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Point;
import android.os.Build;
import android.os.Handler;
+import android.os.SystemProperties;
+import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
@@ -44,6 +48,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 final LauncherModel mModel;
@@ -210,13 +216,52 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks {
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
+ Resources resources = context.getResources();
+
if (dynamicGrid == null) {
Point smallestSize = new Point();
Point largestSize = new Point();
display.getCurrentSizeRange(smallestSize, largestSize);
+ 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);
+ }
+
+ }
+
dynamicGrid = new DynamicGrid(context,
- context.getResources(),
+ resources,
Math.min(smallestSize.x, smallestSize.y),
Math.min(largestSize.x, largestSize.y),
realSize.x, realSize.y,
@@ -225,7 +270,7 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks {
// Update the icon size
DeviceProfile grid = dynamicGrid.getDeviceProfile();
- grid.updateFromConfiguration(context, context.getResources(),
+ grid.updateFromConfiguration(context, resources,
realSize.x, realSize.y,
dm.widthPixels, dm.heightPixels);
return dynamicGrid;
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 753f6e746..c754edb13 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -30,6 +30,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.OperationApplicationException;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.content.res.AssetManager;
+import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.SQLException;
@@ -40,8 +43,10 @@ import android.database.sqlite.SQLiteStatement;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
+import android.os.SystemProperties;
import android.provider.Settings;
import android.text.TextUtils;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
@@ -90,6 +95,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;
@@ -311,11 +318,57 @@ 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");
AutoInstallsLayout 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 DefaultLayoutParser(getContext(), mOpenHelper.mAppWidgetHost,
+ mOpenHelper, customResources, mccLayout);
+ }
+ }
+ }
+
if (loader == null) {
final Partner partner = Partner.get(getContext().getPackageManager());
if (partner != null && partner.hasDefaultLayout()) {