Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40c5ed30 authored by Chris Wren's avatar Chris Wren
Browse files

Offer to delete broken promise icons.

Track state of promise in the info, not the view.
Fix bugs around moving promises to folders.
Fix bugs around filterign and removing promises.

Bug: 12764789
Change-Id: If5e8b6d315e463154b5bafe8aef7ef4f9889bb95
parent 9041a982
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -277,4 +277,21 @@ s -->
    <string name="package_state_unknown">Unknown</string>
    <!-- Label on an icon that references an uninstalled package, for which restore from market has failed. [CHAR_LIMIT=15] -->
    <string name="package_state_error">Not restored</string>

    <!-- Button for abandoned promises dialog, that removes all abandoned promise icons. -->
    <string name="abandoned_clean_all">Remove All</string>
    <!-- Button for abandoned promises dialog, to removes this abandoned promise icon. -->
    <string name="abandoned_clean_this">Remove</string>
    <!-- Button for abandoned promise dialog, to search in the market for the missing package. -->
    <string name="abandoned_search">Search</string>
    <!-- Title for abandoned promise dialog. -->
    <string name="abandoned_promises_title">This Package is not Installed</string>
    <!-- Explanation for abandoned promise dialog. -->
    <plurals name="abandoned_promises_explanation">
        <item quantity="one">The package for this icon is not installed.  You many remove it, or
            attempt to search for the package and install it manually.</item>
        <item quantity="other">The package for this icon is not installed.  You many remove all
            similarly broken icons, remove only this icon, or attempt to search for the package and
            install it manually.</item>
    </plurals>
</resources>
+19 −15
Original line number Diff line number Diff line
@@ -74,8 +74,6 @@ public class BubbleTextView extends TextView {
    private CheckLongPressHelper mLongPressHelper;
    private int mInstallState;

    private int mState;

    private CharSequence mDefaultText = "";

    public BubbleTextView(Context context) {
@@ -124,10 +122,9 @@ public class BubbleTextView extends TextView {
        Drawable iconDrawable = Utilities.createIconDrawable(b);
        setCompoundDrawables(null, iconDrawable, null, null);
        setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
        setText(info.title);
        setTag(info);
        if (info.isPromise()) {
            setState(ShortcutInfo.PACKAGE_STATE_UNKNOWN); // TODO: persist this state somewhere
            applyState();
        }
    }

@@ -150,6 +147,11 @@ public class BubbleTextView extends TextView {
            LauncherModel.checkItemInfo((ItemInfo) tag);
        }
        super.setTag(tag);
        if (tag instanceof ShortcutInfo) {
            final ShortcutInfo info = (ShortcutInfo) tag;
            mDefaultText = info.title;
            setText(mDefaultText);
        }
    }

    @Override
@@ -415,19 +417,12 @@ public class BubbleTextView extends TextView {
        mLongPressHelper.cancelLongPress();
    }

    public void setState(int state) {
        if (mState == ShortcutInfo.PACKAGE_STATE_DEFAULT && mState != state) {
            mDefaultText = getText();
        }
        mState = state;
        applyState();
    }

    private void applyState() {
    public void applyState() {
        int alpha = getResources().getInteger(R.integer.promise_icon_alpha);
        if (DEBUG) Log.d(TAG, "applying icon state: " + mState);
        final int state = getState();
        if (DEBUG) Log.d(TAG, "applying icon state: " + state);

        switch(mState) {
        switch(state) {
            case ShortcutInfo.PACKAGE_STATE_DEFAULT:
                super.setText(mDefaultText);
                alpha = 255;
@@ -462,4 +457,13 @@ public class BubbleTextView extends TextView {
            }
        }
    }

    private int getState() {
        if (! (getTag() instanceof ShortcutInfo)) {
            return ShortcutInfo.PACKAGE_STATE_DEFAULT;
        } else {
            ShortcutInfo info = (ShortcutInfo) getTag();
            return info.getState();
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -575,6 +575,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
        textView.setTextColor(getResources().getColor(R.color.folder_items_text_color));
        textView.setShadowsEnabled(false);
        textView.setGlowColor(getResources().getColor(R.color.folder_items_glow_color));
        textView.applyState();

        textView.setOnClickListener(this);
        textView.setOnLongClickListener(this);
+51 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.AlertDialog;
import android.app.SearchManager;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
@@ -38,6 +39,7 @@ import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
@@ -2517,7 +2519,7 @@ public class Launcher extends Activity
     *
     * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
     */
    protected void onClickAppShortcut(View v) {
    protected void onClickAppShortcut(final View v) {
        if (LOGD) Log.d(TAG, "onClickAppShortcut");
        Object tag = v.getTag();
        if (!(tag instanceof ShortcutInfo)) {
@@ -2541,7 +2543,55 @@ public class Launcher extends Activity
            }
        }

        // Check for abandoned promise
        if (shortcut.isAbandoned() && v instanceof BubbleTextView) {
            final ArrayList<BubbleTextView> abandoned =
                    mWorkspace.getAbandonedPromises(new ArrayList<BubbleTextView>());
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.abandoned_promises_title);
            builder.setMessage(getResources().getQuantityString(
                    R.plurals.abandoned_promises_explanation, abandoned.size()));
            builder.setPositiveButton(R.string.abandoned_search,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            startAppShortcutActivity(v);
                        }
                    }
            );
            if (abandoned.size() > 1) {
                builder.setNegativeButton(R.string.abandoned_clean_all,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                final UserHandleCompat user = UserHandleCompat.myUserHandle();
                                mWorkspace.removeAbandonedPromises(abandoned, user);
                            }
                        }
                );
            }
            builder.setNeutralButton(R.string.abandoned_clean_this,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            final BubbleTextView bubble = (BubbleTextView) v;
                            final UserHandleCompat user = UserHandleCompat.myUserHandle();
                            mWorkspace.removeAbandonedPromise(bubble, user);
                        }
                    });
            builder.create().show();
            return;
        }

        // Start activities
        startAppShortcutActivity(v);
    }

    private void startAppShortcutActivity(View v) {
        Object tag = v.getTag();
        if (!(tag instanceof ShortcutInfo)) {
            throw new IllegalArgumentException("Input must be a Shortcut");
        }
        final ShortcutInfo shortcut = (ShortcutInfo) tag;
        final Intent intent = shortcut.intent;

        int[] pos = new int[2];
        v.getLocationOnScreen(pos);
        intent.setSourceBounds(new Rect(pos[0], pos[1],
+7 −0
Original line number Diff line number Diff line
@@ -2975,6 +2975,7 @@ public class LauncherModel extends BroadcastReceiver
        info.setIcon(mIconCache.getIcon(intent, info.title.toString(), info.user));
        info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
        info.restoredIntent = intent;
        info.setState(ShortcutInfo.PACKAGE_STATE_UNKNOWN);
        return info;
    }

@@ -3088,6 +3089,9 @@ public class LauncherModel extends BroadcastReceiver
            if (i instanceof ShortcutInfo) {
                ShortcutInfo info = (ShortcutInfo) i;
                ComponentName cn = info.intent.getComponent();
                if (info.restoredIntent != null) {
                    cn = info.restoredIntent.getComponent();
                }
                if (cn != null && f.filterItem(null, info, cn)) {
                    filtered.add(info);
                }
@@ -3095,6 +3099,9 @@ public class LauncherModel extends BroadcastReceiver
                FolderInfo info = (FolderInfo) i;
                for (ShortcutInfo s : info.contents) {
                    ComponentName cn = s.intent.getComponent();
                    if (s.restoredIntent != null) {
                        cn = s.restoredIntent.getComponent();
                    }
                    if (cn != null && f.filterItem(info, s, cn)) {
                        filtered.add(s);
                    }
Loading