summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherModel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r--src/com/android/launcher3/LauncherModel.java37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 7a12eb8ef..36fab7c62 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -28,6 +28,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.Intent.ShortcutIconResource;
import android.content.IntentFilter;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
@@ -64,6 +65,9 @@ import com.android.launcher3.util.ManagedProfileHeuristic;
import com.android.launcher3.util.Thunk;
import cyanogenmod.providers.CMSettings;
+import com.android.launcher3.settings.SettingsProvider;
+import com.android.launcher3.stats.internal.service.AggregationIntentService;
+
import java.lang.ref.WeakReference;
import java.net.URISyntaxException;
import java.security.InvalidParameterException;
@@ -1012,10 +1016,22 @@ public class LauncherModel extends BroadcastReceiver
}
/**
+ * Saves the total widget count to a shared preference
+ *
+ * @param context {@link Context}
+ */
+ /* package */ static void saveWidgetCount(Context context) {
+ int widgetCount = LauncherModel.sBgAppWidgets.size();
+ SharedPreferences prefs = context.getSharedPreferences(LauncherAppState
+ .getSharedPreferencesKey(), Context.MODE_PRIVATE);
+ prefs.edit().putInt(AggregationIntentService.PREF_KEY_WIDGET_COUNT, widgetCount).apply();
+ }
+
+ /**
* Add an item to the database in a specified container. Sets the container, screen, cellX and
* cellY fields of the item. Also assigns an ID to the item.
*/
- public static void addItemToDatabase(Context context, final ItemInfo item, final long container,
+ public static void addItemToDatabase(final Context context, final ItemInfo item, final long container,
final long screenId, final int cellX, final int cellY) {
item.container = container;
item.cellX = cellX;
@@ -1065,6 +1081,7 @@ public class LauncherModel extends BroadcastReceiver
break;
case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
sBgAppWidgets.add((LauncherAppWidgetInfo) item);
+ saveWidgetCount(context);
break;
}
}
@@ -1117,7 +1134,7 @@ public class LauncherModel extends BroadcastReceiver
* @param context
* @param items
*/
- static void deleteItemsFromDatabase(Context context, final ArrayList<? extends ItemInfo> items) {
+ static void deleteItemsFromDatabase(final Context context, final ArrayList<? extends ItemInfo> items) {
final ContentResolver cr = context.getContentResolver();
Runnable r = new Runnable() {
public void run() {
@@ -1147,6 +1164,7 @@ public class LauncherModel extends BroadcastReceiver
break;
case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
sBgAppWidgets.remove((LauncherAppWidgetInfo) item);
+ saveWidgetCount(context);
break;
}
sBgItemsIdMap.remove(item.id);
@@ -1158,10 +1176,22 @@ public class LauncherModel extends BroadcastReceiver
}
/**
+ * Saves the count of workspace pages
+ *
+ * @param context {@link Context}
+ */
+ /* package */ static void savePageCount(Context context) {
+ int pageCount = LauncherModel.sBgWorkspaceScreens.size();
+ SharedPreferences prefs = context.getSharedPreferences(LauncherAppState
+ .getSharedPreferencesKey(), Context.MODE_PRIVATE);
+ prefs.edit().putInt(AggregationIntentService.PREF_KEY_PAGE_COUNT, pageCount).apply();
+ }
+
+ /**
* Update the order of the workspace screens in the database. The array list contains
* a list of screen ids in the order that they should appear.
*/
- public void updateWorkspaceScreenOrder(Context context, final ArrayList<Long> screens) {
+ public void updateWorkspaceScreenOrder(final Context context, final ArrayList<Long> screens) {
final ArrayList<Long> screensCopy = new ArrayList<Long>(screens);
final ContentResolver cr = context.getContentResolver();
final Uri uri = LauncherSettings.WorkspaceScreens.CONTENT_URI;
@@ -1199,6 +1229,7 @@ public class LauncherModel extends BroadcastReceiver
synchronized (sBgLock) {
sBgWorkspaceScreens.clear();
sBgWorkspaceScreens.addAll(screensCopy);
+ savePageCount(context);
}
}
};