update promise icon status

also fix a crash in LauncherModel.DEBUG_LOADERS

Bug: 10778992
Change-Id: Iafc28c1e0c2f2a1283783a7ce27e181634b62993
This commit is contained in:
Chris Wren
2014-02-14 16:59:24 -05:00
parent bfbd52a5e6
commit aeff7ea434
9 changed files with 268 additions and 64 deletions

View File

@@ -25,6 +25,7 @@ import android.graphics.Region;
import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.widget.TextView;
@@ -43,6 +44,10 @@ public class BubbleTextView extends TextView {
static final float PADDING_H = 8.0f;
static final float PADDING_V = 3.0f;
private static final String TAG = "BubbleTextView";
private static final boolean DEBUG = false;
private int mPrevAlpha = -1;
private HolographicOutlineHelper mOutlineHelper;
@@ -64,6 +69,11 @@ public class BubbleTextView extends TextView {
private boolean mStayPressed;
private CheckLongPressHelper mLongPressHelper;
private int mInstallState;
private int mState;
private CharSequence mDefaultText = "";
public BubbleTextView(Context context) {
super(context);
@@ -108,11 +118,14 @@ public class BubbleTextView extends TextView {
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
setCompoundDrawables(null,
Utilities.createIconDrawable(b), null, null);
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
}
}
@Override
@@ -392,4 +405,52 @@ 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() {
int alpha = getResources().getInteger(R.integer.promise_icon_alpha);
if (DEBUG) Log.d(TAG, "applying icon state: " + mState);
switch(mState) {
case ShortcutInfo.PACKAGE_STATE_DEFAULT:
super.setText(mDefaultText);
alpha = 255;
break;
case ShortcutInfo.PACKAGE_STATE_ENQUEUED:
setText(R.string.package_state_enqueued);
break;
case ShortcutInfo.PACKAGE_STATE_DOWNLOADING:
setText(R.string.package_state_downloading);
break;
case ShortcutInfo.PACKAGE_STATE_INSTALLING:
setText(R.string.package_state_installing);
break;
case ShortcutInfo.PACKAGE_STATE_ERROR:
setText(R.string.package_state_error);
break;
case ShortcutInfo.PACKAGE_STATE_UNKNOWN:
default:
setText(R.string.package_state_unknown);
break;
}
if (DEBUG) Log.d(TAG, "setting icon alpha to: " + alpha);
Drawable[] drawables = getCompoundDrawables();
for (int i = 0; i < drawables.length; i++) {
if (drawables[i] != null) {
drawables[i].setAlpha(alpha);
}
}
}
}