From 6a8dada0a3a3e0f51890541e053830e84480fef4 Mon Sep 17 00:00:00 2001 From: huiwan Date: Mon, 10 Nov 2014 10:35:03 -0800 Subject: Launcher: display APP icon paged in main screen as Carrier require Carrier require display customized APP: - recommened APP will be placed on the first page on main screen - Carrier's specific APP will be placed on the second page - rest and third APP will be placed on other page Change-Id: I2e52285068012a3e99526225b99bd25365df9bec Signed-off-by: Xiaojing Zhang --- res/values/config.xml | 1 - .../android/launcher3/AppsCustomizePagedView.java | 45 +++++++++++++++------- src/com/android/launcher3/Launcher.java | 19 +++++++++ src/com/android/launcher3/LauncherApplication.java | 3 +- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/res/values/config.xml b/res/values/config.xml index 8ce37fe28..0287c83e0 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -118,7 +118,6 @@ 100 - false false false false diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java index 2897d592b..c9be6265e 100644 --- a/src/com/android/launcher3/AppsCustomizePagedView.java +++ b/src/com/android/launcher3/AppsCustomizePagedView.java @@ -360,7 +360,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen configClassArray(context, mPreClassArray, PRE_CLASS_IDENTIFIER, true); - if (LauncherApplication.SHOW_CTAPP_FEATRUE) { + if (LauncherApplication.SHOW_CTAPP_FEATURE) { configClassArray(context, mCTClassArray, CT_CLASS_IDENTIFIER, false); configClassArray(context, mCTFirstPageArray, CT_FIRSTPAGE_IDENTIFIER, false); } @@ -463,6 +463,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mNumWidgetPages = (int) Math.ceil(mWidgets.size() / (float) (mWidgetCountX * mWidgetCountY)); mNumAppsPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY)); + if(LauncherApplication.SHOW_CTAPP_FEATURE){ + mNumAppsPages = mNumAppsPages + 2; //for ct + } } protected void onDataReady(int width, int height) { @@ -1080,16 +1083,18 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen AppsCustomizeCellLayout layout = (AppsCustomizeCellLayout) getPageAt(page); //set page 1 & 2 to CT's app - boolean isflag = LauncherApplication.SHOW_CTAPP_FEATRUE && (page <= 1); + boolean isCTFlag = LauncherApplication.SHOW_CTAPP_FEATURE + && (page < CT_CUSTOMIZED_PAGE_COUNT); - int startIndex = isflag ? 0 : (LauncherApplication.SHOW_CTAPP_FEATRUE && page>1 ? - (page-2)* numCells : page * numCells); + int startIndex = isCTFlag ? 0 : ((LauncherApplication.SHOW_CTAPP_FEATURE + && page >= CT_CUSTOMIZED_PAGE_COUNT) ? (page - CT_CUSTOMIZED_PAGE_COUNT) * numCells + : page * numCells); - int ctEndIndex = page==0 ? Math.min(startIndex + numCells, ctFirstPageApps.size()) - : Math.min(startIndex + numCells, ctApps.size()); + int ctEndIndex = (page == 0) ? Math.min(startIndex + numCells, ctFirstPageApps.size()) + : Math.min(startIndex + numCells, ctApps.size()); int defEndIndex = Math.min(startIndex + numCells, mApps.size()); - int endIndex = isflag ? ctEndIndex : defEndIndex ; + int endIndex = isCTFlag ? ctEndIndex : defEndIndex ; layout.removeAllViewsOnPage(); ArrayList items = new ArrayList(); @@ -1098,8 +1103,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen SettingsProvider.SETTINGS_UI_DRAWER_HIDE_ICON_LABELS, R.bool.preferences_interface_drawer_hide_icon_labels_default); for (int i = startIndex; i < endIndex; ++i) { - AppInfo info = isflag ? (page==0 ? ctFirstPageApps.get(i) : - ctApps.get(i)) : mApps.get(i); + AppInfo info = isCTFlag + ? ((page == 0) ? ctFirstPageApps.get(i) : ctApps.get(i)) + : mApps.get(i); BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate( R.layout.apps_customize_application, layout, false); @@ -1759,11 +1765,24 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen private void removeAppsWithoutInvalidate(ArrayList list) { // loop through all the apps and remove apps that have the same component int length = list.size(); + final int INVALID_INDEX = -1; for (int i = 0; i < length; ++i) { AppInfo info = list.get(i); - int removeIndex = findAppByComponent(mApps, info); - if (removeIndex > -1) { - mApps.remove(removeIndex); + if(ctFirstPageApps.contains(info)) { //for CT first page + int removeCTFirstPageIndex = findAppByComponent(ctFirstPageApps, info); + if (removeCTFirstPageIndex > INVALID_INDEX) { + ctFirstPageApps.remove(removeCTFirstPageIndex); + } + } else if(ctApps.contains(info)){ //for CT + int removeCTIndex = findAppByComponent(ctApps, info); + if (removeCTIndex > INVALID_INDEX) { + ctApps.remove(removeCTIndex); + } + } else { + int removeIndex = findAppByComponent(mApps, info); + if (removeIndex > INVALID_INDEX) { + mApps.remove(removeIndex); + } } } } @@ -1969,7 +1988,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } private void sortByCustomization() { - if(LauncherApplication.SHOW_CTAPP_FEATRUE){ + if(LauncherApplication.SHOW_CTAPP_FEATURE){ ctApps.clear(); ctFirstPageApps.clear(); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index e82f5b03b..edca71f28 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2948,6 +2948,25 @@ public class Launcher extends Activity throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); } + final ComponentName componentName = intent.getComponent(); + if(componentName != null){ + String name = componentName.getPackageName(); + PackageManager packageManager = getPackageManager(); + + try{ + String sourceDir = (packageManager.getApplicationInfo(name, 0)).sourceDir; + + if(!new File(sourceDir).exists()){ + Toast.makeText(this, R.string.activity_not_found, + Toast.LENGTH_SHORT).show(); + return; + } + } catch (NameNotFoundException e) { + Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); + return; + } + } + boolean success = startActivitySafely(v, intent, tag); mStats.recordLaunch(intent, shortcut); diff --git a/src/com/android/launcher3/LauncherApplication.java b/src/com/android/launcher3/LauncherApplication.java index 06d7dae08..520beb639 100644 --- a/src/com/android/launcher3/LauncherApplication.java +++ b/src/com/android/launcher3/LauncherApplication.java @@ -21,7 +21,7 @@ import android.app.Application; public class LauncherApplication extends Application { public static boolean LAUNCHER_SHOW_UNREAD_NUMBER; public static boolean LAUNCHER_SHORTCUT_ENABLED; - public static boolean SHOW_CTAPP_FEATRUE = false; + public static boolean SHOW_CTAPP_FEATURE; @Override public void onCreate() { @@ -30,6 +30,7 @@ public class LauncherApplication extends Application { R.bool.config_launcher_show_unread_number); LAUNCHER_SHORTCUT_ENABLED = getResources().getBoolean( R.bool.config_launcher_shortcut); + SHOW_CTAPP_FEATURE = getResources().getBoolean(R.bool.config_launcher_page); LauncherAppState.setApplicationContext(this); LauncherAppState.getInstance(); } -- cgit v1.2.3