summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/util
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2017-01-05 21:50:27 -0800
committerSunny Goyal <sunnygoyal@google.com>2017-01-10 13:53:50 -0800
commitaaf86fe9a0406720cca7cfe204f28e2d2de085eb (patch)
treecc3c034548692ac963545d9eb11dc5742099ff74 /src/com/android/launcher3/util
parente09bacc1ef50aa7c4fe551a7360d7f5613927ee9 (diff)
downloadandroid_packages_apps_Trebuchet-aaf86fe9a0406720cca7cfe204f28e2d2de085eb.tar.gz
android_packages_apps_Trebuchet-aaf86fe9a0406720cca7cfe204f28e2d2de085eb.tar.bz2
android_packages_apps_Trebuchet-aaf86fe9a0406720cca7cfe204f28e2d2de085eb.zip
Refactoring some loadWorkspace logic in a separate class
Bug: 34112546 Change-Id: I8a43ed1646056aa1957ac3d6ea82018691df6386
Diffstat (limited to 'src/com/android/launcher3/util')
-rw-r--r--src/com/android/launcher3/util/ContentWriter.java28
-rw-r--r--src/com/android/launcher3/util/CursorIconInfo.java86
-rw-r--r--src/com/android/launcher3/util/PackageManagerHelper.java10
3 files changed, 38 insertions, 86 deletions
diff --git a/src/com/android/launcher3/util/ContentWriter.java b/src/com/android/launcher3/util/ContentWriter.java
index 1c347c0a4..76ba9d63a 100644
--- a/src/com/android/launcher3/util/ContentWriter.java
+++ b/src/com/android/launcher3/util/ContentWriter.java
@@ -20,6 +20,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
+import android.net.Uri;
import android.os.UserHandle;
import com.android.launcher3.LauncherAppState;
@@ -35,9 +36,15 @@ public class ContentWriter {
private final ContentValues mValues;
private final Context mContext;
+ private CommitParams mCommitParams;
private Bitmap mIcon;
private UserHandle mUser;
+ public ContentWriter(Context context, CommitParams commitParams) {
+ this(context);
+ mCommitParams = commitParams;
+ }
+
public ContentWriter(Context context) {
this(new ContentValues(), context);
}
@@ -95,4 +102,25 @@ public class ContentWriter {
}
return mValues;
}
+
+ public int commit() {
+ if (mCommitParams != null) {
+ return mContext.getContentResolver().update(mCommitParams.mUri, getValues(),
+ mCommitParams.mWhere, mCommitParams.mSelectionArgs);
+ }
+ return 0;
+ }
+
+ public static final class CommitParams {
+
+ final Uri mUri = LauncherSettings.Favorites.CONTENT_URI;
+ String mWhere;
+ String[] mSelectionArgs;
+
+ public CommitParams(String where, String[] selectionArgs) {
+ mWhere = where;
+ mSelectionArgs = selectionArgs;
+ }
+
+ }
}
diff --git a/src/com/android/launcher3/util/CursorIconInfo.java b/src/com/android/launcher3/util/CursorIconInfo.java
deleted file mode 100644
index 3bc4eabc5..000000000
--- a/src/com/android/launcher3/util/CursorIconInfo.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.util;
-
-import android.content.Context;
-import android.content.Intent.ShortcutIconResource;
-import android.database.Cursor;
-import android.graphics.Bitmap;
-import android.text.TextUtils;
-
-import com.android.launcher3.LauncherSettings;
-import com.android.launcher3.ShortcutInfo;
-import com.android.launcher3.Utilities;
-import com.android.launcher3.graphics.LauncherIcons;
-
-/**
- * Utility class to load icon from a cursor.
- */
-public class CursorIconInfo {
- public final int iconPackageIndex;
- public final int iconResourceIndex;
- public final int iconIndex;
-
- public final int titleIndex;
-
- private final Context mContext;
-
- public CursorIconInfo(Context context, Cursor c) {
- mContext = context;
-
- iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
- iconPackageIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_PACKAGE);
- iconResourceIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_RESOURCE);
-
- titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
- }
-
- /**
- * Loads the icon from the cursor and updates the {@param info} if the icon is an app resource.
- */
- public Bitmap loadIcon(Cursor c, ShortcutInfo info) {
- Bitmap icon = null;
- String packageName = c.getString(iconPackageIndex);
- String resourceName = c.getString(iconResourceIndex);
- if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
- info.iconResource = new ShortcutIconResource();
- info.iconResource.packageName = packageName;
- info.iconResource.resourceName = resourceName;
- icon = LauncherIcons.createIconBitmap(info.iconResource, mContext);
- }
- if (icon == null) {
- // Failed to load from resource, try loading from DB.
- icon = loadIcon(c);
- }
- return icon;
- }
-
- /**
- * Loads the fixed bitmap from the icon if available.
- */
- public Bitmap loadIcon(Cursor c) {
- return LauncherIcons.createIconBitmap(c, iconIndex, mContext);
- }
-
- /**
- * Returns the title or empty string
- */
- public String getTitle(Cursor c) {
- String title = c.getString(titleIndex);
- return TextUtils.isEmpty(title) ? "" : Utilities.trim(c.getString(titleIndex));
- }
-}
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
index b61d6095f..33a9fc68d 100644
--- a/src/com/android/launcher3/util/PackageManagerHelper.java
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -23,6 +23,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
+import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
@@ -124,4 +125,13 @@ public class PackageManagerHelper {
return false;
}
+
+ public static Intent getMarketIntent(String packageName) {
+ return new Intent(Intent.ACTION_VIEW)
+ .setData(new Uri.Builder()
+ .scheme("market")
+ .authority("details")
+ .appendQueryParameter("id", packageName)
+ .build());
+ }
}