From d0a92d6799a340fbbab924e0a128f189d6284e1c Mon Sep 17 00:00:00 2001 From: Danesh Mondegarian Date: Sun, 15 Sep 2013 21:27:47 -0700 Subject: Trebuchet : Icon edit dialog fixes Append text rather than setText for the edit dialog title, so that the cursor moves to the end. Keep track of customIconResource state to ensure its not reset. Preserve custom icons when the linking application is updated Change-Id: Icab0f0ce45f1dbb79ce895228303aa2c944f1213 --- src/com/cyanogenmod/trebuchet/Launcher.java | 20 +++++++++----------- src/com/cyanogenmod/trebuchet/LauncherModel.java | 2 ++ src/com/cyanogenmod/trebuchet/ShortcutInfo.java | 1 + src/com/cyanogenmod/trebuchet/Workspace.java | 5 +++++ 4 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src/com') diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java index dfd27048a..8b8eb3241 100644 --- a/src/com/cyanogenmod/trebuchet/Launcher.java +++ b/src/com/cyanogenmod/trebuchet/Launcher.java @@ -338,7 +338,10 @@ public final class Launcher extends Activity private boolean mFullscreenMode; private boolean mWallpaperVisible; - private ImageButton mDialogIcon; + + // Shortcut edit dialog + private ImageView mDialogIcon; + private String mSelectedDialogId; private Runnable mBuildLayersRunnable = new Runnable() { public void run() { @@ -688,11 +691,9 @@ public final class Launcher extends Activity if (resultCode == RESULT_OK) { if (data == null) { // Get/Set default icon - String id = (String) mDialogIcon.getTag(); final PackageManager manager = getPackageManager(); - final Cursor c = getContentResolver().query(LauncherSettings.Favorites.CONTENT_URI, - null, LauncherSettings.Favorites._ID + "=?", new String[]{id}, null); + null, LauncherSettings.Favorites._ID + "=?", new String[]{mSelectedDialogId}, null); if (c != null && c.getCount() > 0) { c.moveToFirst(); final int itemTypeIndex = c.getColumnIndexOrThrow( @@ -1145,6 +1146,7 @@ public final class Launcher extends Activity * @param info The shortcut to be edited */ void updateShortcut(final ShortcutInfo info) { + mSelectedDialogId = String.valueOf(info.id); AlertDialog.Builder builder = new AlertDialog.Builder(this); View layout = mInflater.inflate(R.layout.dialog_edit, null); mDialogIcon = (ImageButton) layout.findViewById(R.id.dialog_edit_icon); @@ -1153,32 +1155,28 @@ public final class Launcher extends Activity mDialogIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - mDialogIcon.setTag(String.valueOf(info.id)); IconPackHelper.pickIconPack(Launcher.this, true); } }); final EditText title = (EditText) layout.findViewById(R.id.dialog_edit_text); - title.setText(info.title); + title.append(info.title); builder.setView(layout) .setTitle(info.title) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (!info.title.equals(title.getText())) { - info.setTitle(title.getText()); + info.setTitle(title.getText().toString()); } + info.customIconResource = (String) mDialogIcon.getTag(); if (mDialogIcon.getTag() != null) { - info.customIconResource = (String) mDialogIcon.getTag(); Drawable d = mModel.getDrawableForCustomIcon(Launcher.this, info.customIconResource); if (d != null) { info.setIcon(Utilities.createIconBitmap(d, Launcher.this)); } } else { - info.customIconResource = null; info.setIcon(((BitmapDrawable)mDialogIcon.getDrawable()).getBitmap()); } - - LauncherModel.updateItemInDatabase(Launcher.this, info); } }) .setNegativeButton(android.R.string.cancel, null); diff --git a/src/com/cyanogenmod/trebuchet/LauncherModel.java b/src/com/cyanogenmod/trebuchet/LauncherModel.java index 08efc6fa8..51fac6f7a 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherModel.java +++ b/src/com/cyanogenmod/trebuchet/LauncherModel.java @@ -2321,6 +2321,7 @@ public class LauncherModel extends BroadcastReceiver { } Bitmap customIcon = getCustomIconFromCursor(c, context, customIconIndex); if (customIcon != null) { + info.customIconResource = c.getString(customIconIndex); icon = customIcon; } @@ -2461,6 +2462,7 @@ public class LauncherModel extends BroadcastReceiver { } Bitmap customIcon = getCustomIconFromCursor(c, context, customIconIndex); if (customIcon != null) { + info.customIconResource = c.getString(customIconIndex); icon = customIcon; } info.setIcon(icon); diff --git a/src/com/cyanogenmod/trebuchet/ShortcutInfo.java b/src/com/cyanogenmod/trebuchet/ShortcutInfo.java index 14fd0c0fa..54193bb25 100644 --- a/src/com/cyanogenmod/trebuchet/ShortcutInfo.java +++ b/src/com/cyanogenmod/trebuchet/ShortcutInfo.java @@ -92,6 +92,7 @@ class ShortcutInfo extends ItemInfo { iconResource.packageName = info.iconResource.packageName; iconResource.resourceName = info.iconResource.resourceName; } + customIconResource = info.customIconResource; mIcon = info.mIcon; // TODO: should make a copy here. maybe we don't need this ctor at all customIcon = info.customIcon; } diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java index c4318a768..4dd4523ff 100644 --- a/src/com/cyanogenmod/trebuchet/Workspace.java +++ b/src/com/cyanogenmod/trebuchet/Workspace.java @@ -46,6 +46,7 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.IBinder; import android.os.Parcelable; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; @@ -4541,6 +4542,10 @@ public class Workspace extends PagedView } for (ApplicationInfo app : apps) { if (app.componentName.equals(name)) { + if (!TextUtils.isEmpty(info.customIconResource) + || !TextUtils.isEmpty(info.title)) { + continue; + } BubbleTextView shortcut = (BubbleTextView) view; info.updateIcon(mIconCache); info.title = app.title.toString(); -- cgit v1.2.3