diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-03-26 11:32:11 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2015-03-27 13:00:44 -0700 |
commit | b2d46ceaaa32ece85f18e049d9e30a5ccaf80e45 (patch) | |
tree | 09937cb0c0fac8f4c02599eb6a71c3853119319f /src/com/android/launcher3/AutoInstallsLayout.java | |
parent | 28f4188bacad6a1e72cbed04ff3af1597d234cad (diff) | |
download | android_packages_apps_Trebuchet-b2d46ceaaa32ece85f18e049d9e30a5ccaf80e45.tar.gz android_packages_apps_Trebuchet-b2d46ceaaa32ece85f18e049d9e30a5ccaf80e45.tar.bz2 android_packages_apps_Trebuchet-b2d46ceaaa32ece85f18e049d9e30a5ccaf80e45.zip |
Configuration of workspace through app restrictions
> Checking for a grid specific layout before loading the default layout
Change-Id: I1e8d4176341e61d0876b0a9bea9ad8010e3a0f6a
Diffstat (limited to 'src/com/android/launcher3/AutoInstallsLayout.java')
-rw-r--r-- | src/com/android/launcher3/AutoInstallsLayout.java | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/com/android/launcher3/AutoInstallsLayout.java b/src/com/android/launcher3/AutoInstallsLayout.java index cbab08bec..9180dcf42 100644 --- a/src/com/android/launcher3/AutoInstallsLayout.java +++ b/src/com/android/launcher3/AutoInstallsLayout.java @@ -45,6 +45,7 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.Locale; /** * Layout parsing code for auto installs layout @@ -57,6 +58,11 @@ public class AutoInstallsLayout { static final String ACTION_LAUNCHER_CUSTOMIZATION = "android.autoinstalls.config.action.PLAY_AUTO_INSTALL"; + /** + * Layout resource which also includes grid size and hotseat count, e.g., default_layout_6x6_h5 + */ + private static final String FORMATTED_LAYOUT_RES_WITH_HOSTEAT = "default_layout_%dx%d_h%s"; + private static final String FORMATTED_LAYOUT_RES = "default_layout_%dx%d"; private static final String LAYOUT_RES = "default_layout"; static AutoInstallsLayout get(Context context, AppWidgetHost appWidgetHost, @@ -66,15 +72,39 @@ public class AutoInstallsLayout { if (customizationApkInfo == null) { return null; } + return get(context, customizationApkInfo.first, customizationApkInfo.second, + appWidgetHost, callback); + } + + static AutoInstallsLayout get(Context context, String pkg, Resources targetRes, + AppWidgetHost appWidgetHost, LayoutParserCallback callback) { + DeviceProfile grid = LauncherAppState.getInstance().getDynamicGrid().getDeviceProfile(); + + // Try with grid size and hotseat count + String layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES_WITH_HOSTEAT, + (int) grid.numColumns, (int) grid.numRows, (int) grid.numHotseatIcons); + int layoutId = targetRes.getIdentifier(layoutName, "xml", pkg); + + // Try with only grid size + if (layoutId == 0) { + Log.d(TAG, "Formatted layout: " + layoutName + + " not found. Trying layout without hosteat"); + layoutName = String.format(Locale.ENGLISH, FORMATTED_LAYOUT_RES, + (int) grid.numColumns, (int) grid.numRows); + layoutId = targetRes.getIdentifier(layoutName, "xml", pkg); + } + + // Try the default layout + if (layoutId == 0) { + Log.d(TAG, "Formatted layout: " + layoutName + " not found. Trying the default layout"); + layoutId = targetRes.getIdentifier(LAYOUT_RES, "xml", pkg); + } - String pkg = customizationApkInfo.first; - Resources res = customizationApkInfo.second; - int layoutId = res.getIdentifier(LAYOUT_RES, "xml", pkg); if (layoutId == 0) { Log.e(TAG, "Layout definition not found in package: " + pkg); return null; } - return new AutoInstallsLayout(context, appWidgetHost, callback, res, layoutId, + return new AutoInstallsLayout(context, appWidgetHost, callback, targetRes, layoutId, TAG_WORKSPACE); } |