2010-12-01 15:47:31 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010 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.launcher2;
|
|
|
|
|
|
2010-12-21 11:31:54 -08:00
|
|
|
import android.animation.ObjectAnimator;
|
2010-12-01 15:47:31 -08:00
|
|
|
import android.appwidget.AppWidgetProviderInfo;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.content.pm.ResolveInfo;
|
2010-12-21 11:31:54 -08:00
|
|
|
import android.content.res.Resources;
|
2010-12-01 15:47:31 -08:00
|
|
|
import android.content.res.TypedArray;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.graphics.Paint;
|
2011-02-24 18:09:44 -08:00
|
|
|
import android.graphics.PorterDuff;
|
2010-12-14 17:25:59 -08:00
|
|
|
import android.graphics.PorterDuff.Mode;
|
2011-02-24 18:09:44 -08:00
|
|
|
import android.graphics.PorterDuffXfermode;
|
|
|
|
|
import android.graphics.Rect;
|
|
|
|
|
import android.graphics.RectF;
|
2010-12-01 15:47:31 -08:00
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.HandlerThread;
|
|
|
|
|
import android.os.Message;
|
|
|
|
|
import android.util.AttributeSet;
|
2011-04-13 11:27:36 -07:00
|
|
|
import android.view.KeyEvent;
|
2010-12-01 15:47:31 -08:00
|
|
|
import android.view.MotionEvent;
|
2011-01-17 16:37:14 -08:00
|
|
|
import android.view.View;
|
2010-12-21 11:31:54 -08:00
|
|
|
import android.widget.Checkable;
|
2010-12-01 15:47:31 -08:00
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher.R;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The linear layout used strictly for the widget/wallpaper tab of the customization tray
|
|
|
|
|
*/
|
2010-12-21 11:31:54 -08:00
|
|
|
public class PagedViewWidget extends LinearLayout implements Checkable {
|
2010-12-01 15:47:31 -08:00
|
|
|
static final String TAG = "PagedViewWidgetLayout";
|
|
|
|
|
|
|
|
|
|
private final Paint mPaint = new Paint();
|
|
|
|
|
private static HolographicOutlineHelper sHolographicOutlineHelper;
|
|
|
|
|
private Bitmap mHolographicOutline;
|
|
|
|
|
private final Canvas mHolographicOutlineCanvas = new Canvas();
|
|
|
|
|
private FastBitmapDrawable mPreview;
|
2011-02-24 18:09:44 -08:00
|
|
|
private ImageView mPreviewImageView;
|
|
|
|
|
private final RectF mTmpScaleRect = new RectF();
|
|
|
|
|
private final Rect mEraseStrokeRect = new Rect();
|
|
|
|
|
private final Paint mEraseStrokeRectPaint = new Paint();
|
2010-12-01 15:47:31 -08:00
|
|
|
|
2011-01-05 13:54:43 -08:00
|
|
|
private PagedViewIconCache.Key mIconCacheKey;
|
|
|
|
|
private PagedViewIconCache mIconCache;
|
2011-05-05 17:06:13 -07:00
|
|
|
private String mDimensionsFormatString;
|
2011-01-05 13:54:43 -08:00
|
|
|
|
2010-12-01 15:47:31 -08:00
|
|
|
private int mAlpha = 255;
|
|
|
|
|
private int mHolographicAlpha;
|
|
|
|
|
|
|
|
|
|
// Highlight colors
|
|
|
|
|
private int mHoloBlurColor;
|
|
|
|
|
private int mHoloOutlineColor;
|
|
|
|
|
|
2010-12-21 11:31:54 -08:00
|
|
|
private boolean mIsChecked;
|
|
|
|
|
private ObjectAnimator mCheckedAlphaAnimator;
|
|
|
|
|
private float mCheckedAlpha = 1.0f;
|
|
|
|
|
private int mCheckedFadeInDuration;
|
|
|
|
|
private int mCheckedFadeOutDuration;
|
|
|
|
|
|
2010-12-01 15:47:31 -08:00
|
|
|
private static final HandlerThread sWorkerThread = new HandlerThread("pagedviewwidget-helper");
|
|
|
|
|
static {
|
|
|
|
|
sWorkerThread.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final int MESSAGE_CREATE_HOLOGRAPHIC_OUTLINE = 1;
|
|
|
|
|
|
|
|
|
|
private static final Handler sWorker = new Handler(sWorkerThread.getLooper()) {
|
|
|
|
|
private DeferredHandler mHandler = new DeferredHandler();
|
|
|
|
|
public void handleMessage(Message msg) {
|
|
|
|
|
final PagedViewWidget widget = (PagedViewWidget) msg.obj;
|
|
|
|
|
final int prevAlpha = widget.mPreview.getAlpha();
|
2011-02-24 18:09:44 -08:00
|
|
|
final int width = Math.max(widget.mPreview.getIntrinsicWidth(),
|
|
|
|
|
widget.getMeasuredWidth());
|
|
|
|
|
final int height = Math.max(widget.mPreview.getIntrinsicHeight(),
|
|
|
|
|
widget.getMeasuredHeight());
|
|
|
|
|
final Bitmap outline = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
2010-12-01 15:47:31 -08:00
|
|
|
|
|
|
|
|
widget.mHolographicOutlineCanvas.setBitmap(outline);
|
|
|
|
|
widget.mHolographicOutlineCanvas.save();
|
|
|
|
|
widget.mHolographicOutlineCanvas.translate(widget.mPaddingLeft, widget.mPaddingTop);
|
|
|
|
|
widget.mPreview.setAlpha(255);
|
|
|
|
|
widget.mPreview.draw(widget.mHolographicOutlineCanvas);
|
|
|
|
|
widget.mPreview.setAlpha(prevAlpha);
|
2010-12-14 17:25:59 -08:00
|
|
|
// Temporary workaround to make the default widget outlines visible
|
|
|
|
|
widget.mHolographicOutlineCanvas.drawColor(Color.argb(156, 0, 0, 0), Mode.SRC_OVER);
|
2010-12-01 15:47:31 -08:00
|
|
|
widget.mHolographicOutlineCanvas.restore();
|
|
|
|
|
|
2011-02-24 18:09:44 -08:00
|
|
|
// To account for the fact that some previews run up straight to the edge (we subtract
|
|
|
|
|
// the edge from the holographic preview (before we apply the holograph)
|
|
|
|
|
widget.mEraseStrokeRect.set(0, 0, width, height);
|
|
|
|
|
widget.mHolographicOutlineCanvas.drawRect(widget.mEraseStrokeRect,
|
|
|
|
|
widget.mEraseStrokeRectPaint);
|
|
|
|
|
|
2010-12-03 11:39:55 -08:00
|
|
|
sHolographicOutlineHelper.applyThickExpensiveOutlineWithBlur(outline,
|
2010-12-01 15:47:31 -08:00
|
|
|
widget.mHolographicOutlineCanvas, widget.mHoloBlurColor,
|
|
|
|
|
widget.mHoloOutlineColor);
|
|
|
|
|
|
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
widget.mHolographicOutline = outline;
|
2011-01-05 13:54:43 -08:00
|
|
|
widget.mIconCache.addOutline(widget.mIconCacheKey, outline);
|
2010-12-01 15:47:31 -08:00
|
|
|
widget.invalidate();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public PagedViewWidget(Context context) {
|
|
|
|
|
this(context, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PagedViewWidget(Context context, AttributeSet attrs) {
|
|
|
|
|
this(context, attrs, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PagedViewWidget(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
|
|
|
|
|
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedViewWidget,
|
|
|
|
|
defStyle, 0);
|
|
|
|
|
mHoloBlurColor = a.getColor(R.styleable.PagedViewWidget_blurColor, 0);
|
|
|
|
|
mHoloOutlineColor = a.getColor(R.styleable.PagedViewWidget_outlineColor, 0);
|
2011-02-24 18:09:44 -08:00
|
|
|
mEraseStrokeRectPaint.setStyle(Paint.Style.STROKE);
|
|
|
|
|
mEraseStrokeRectPaint.setStrokeWidth(HolographicOutlineHelper.MIN_OUTER_BLUR_RADIUS);
|
|
|
|
|
mEraseStrokeRectPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
|
|
|
|
|
mEraseStrokeRectPaint.setFilterBitmap(true);
|
|
|
|
|
mEraseStrokeRectPaint.setAntiAlias(true);
|
2010-12-01 15:47:31 -08:00
|
|
|
a.recycle();
|
|
|
|
|
|
|
|
|
|
if (sHolographicOutlineHelper == null) {
|
|
|
|
|
sHolographicOutlineHelper = new HolographicOutlineHelper();
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-21 11:31:54 -08:00
|
|
|
// Set up fade in/out constants
|
|
|
|
|
final Resources r = context.getResources();
|
2011-04-14 16:08:02 -07:00
|
|
|
final int alpha = r.getInteger(R.integer.config_dragAppsCustomizeIconFadeAlpha);
|
2010-12-21 11:31:54 -08:00
|
|
|
if (alpha > 0) {
|
2011-04-14 16:08:02 -07:00
|
|
|
mCheckedAlpha = r.getInteger(R.integer.config_dragAppsCustomizeIconFadeAlpha) / 256.0f;
|
|
|
|
|
mCheckedFadeInDuration =
|
|
|
|
|
r.getInteger(R.integer.config_dragAppsCustomizeIconFadeInDuration);
|
|
|
|
|
mCheckedFadeOutDuration =
|
|
|
|
|
r.getInteger(R.integer.config_dragAppsCustomizeIconFadeOutDuration);
|
2010-12-21 11:31:54 -08:00
|
|
|
}
|
2011-05-05 17:06:13 -07:00
|
|
|
mDimensionsFormatString = r.getString(R.string.widget_dims_format);
|
2010-12-21 11:31:54 -08:00
|
|
|
|
2010-12-01 15:47:31 -08:00
|
|
|
setWillNotDraw(false);
|
|
|
|
|
setClipToPadding(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void queueHolographicOutlineCreation() {
|
|
|
|
|
// Generate the outline in the background
|
2011-01-05 13:54:43 -08:00
|
|
|
if (mHolographicOutline == null && mPreview != null) {
|
2010-12-01 15:47:31 -08:00
|
|
|
Message m = sWorker.obtainMessage(MESSAGE_CREATE_HOLOGRAPHIC_OUTLINE);
|
|
|
|
|
m.obj = this;
|
|
|
|
|
sWorker.sendMessage(m);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void applyFromAppWidgetProviderInfo(AppWidgetProviderInfo info,
|
2011-01-05 13:54:43 -08:00
|
|
|
FastBitmapDrawable preview, int maxWidth, int[] cellSpan,
|
|
|
|
|
PagedViewIconCache cache, boolean createHolographicOutline) {
|
2010-12-01 15:47:31 -08:00
|
|
|
final ImageView image = (ImageView) findViewById(R.id.widget_preview);
|
2011-04-27 17:40:20 -07:00
|
|
|
if (maxWidth > -1) {
|
|
|
|
|
image.setMaxWidth(maxWidth);
|
|
|
|
|
}
|
2010-12-01 15:47:31 -08:00
|
|
|
image.setImageDrawable(preview);
|
2011-02-24 18:09:44 -08:00
|
|
|
mPreviewImageView = image;
|
2010-12-01 15:47:31 -08:00
|
|
|
final TextView name = (TextView) findViewById(R.id.widget_name);
|
|
|
|
|
name.setText(info.label);
|
2011-01-17 16:37:14 -08:00
|
|
|
name.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
2010-12-01 15:47:31 -08:00
|
|
|
final TextView dims = (TextView) findViewById(R.id.widget_dims);
|
2011-05-05 17:06:13 -07:00
|
|
|
dims.setText(String.format(mDimensionsFormatString, cellSpan[0], cellSpan[1]));
|
2011-01-17 16:37:14 -08:00
|
|
|
dims.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
2011-01-05 13:54:43 -08:00
|
|
|
|
|
|
|
|
if (createHolographicOutline) {
|
|
|
|
|
mIconCache = cache;
|
|
|
|
|
mIconCacheKey = new PagedViewIconCache.Key(info);
|
|
|
|
|
mHolographicOutline = mIconCache.getOutline(mIconCacheKey);
|
|
|
|
|
mPreview = preview;
|
|
|
|
|
}
|
2010-12-01 15:47:31 -08:00
|
|
|
}
|
|
|
|
|
|
2011-05-03 16:18:34 -07:00
|
|
|
public void applyFromResolveInfo(PackageManager pm, ResolveInfo info,
|
|
|
|
|
FastBitmapDrawable preview, PagedViewIconCache cache, boolean createHolographicOutline){
|
|
|
|
|
final ImageView image = (ImageView) findViewById(R.id.widget_preview);
|
|
|
|
|
image.setImageDrawable(preview);
|
|
|
|
|
mPreviewImageView = image;
|
|
|
|
|
final TextView name = (TextView) findViewById(R.id.widget_name);
|
|
|
|
|
name.setText(info.loadLabel(pm));
|
|
|
|
|
name.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
|
|
|
|
final TextView dims = (TextView) findViewById(R.id.widget_dims);
|
2011-05-05 17:06:13 -07:00
|
|
|
dims.setText(String.format(mDimensionsFormatString, 1, 1));
|
2011-05-03 16:18:34 -07:00
|
|
|
dims.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
|
|
|
|
|
|
|
|
|
if (createHolographicOutline) {
|
|
|
|
|
mIconCache = cache;
|
|
|
|
|
mIconCacheKey = new PagedViewIconCache.Key(info);
|
|
|
|
|
mHolographicOutline = mIconCache.getOutline(mIconCacheKey);
|
|
|
|
|
mPreview = preview;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-01 15:47:31 -08:00
|
|
|
public void applyFromWallpaperInfo(ResolveInfo info, PackageManager packageManager,
|
2011-01-05 13:54:43 -08:00
|
|
|
FastBitmapDrawable preview, int maxWidth, PagedViewIconCache cache,
|
|
|
|
|
boolean createHolographicOutline) {
|
2010-12-01 15:47:31 -08:00
|
|
|
ImageView image = (ImageView) findViewById(R.id.wallpaper_preview);
|
|
|
|
|
image.setMaxWidth(maxWidth);
|
|
|
|
|
image.setImageDrawable(preview);
|
2011-02-24 18:09:44 -08:00
|
|
|
mPreviewImageView = image;
|
2010-12-01 15:47:31 -08:00
|
|
|
TextView name = (TextView) findViewById(R.id.wallpaper_name);
|
|
|
|
|
name.setText(info.loadLabel(packageManager));
|
2011-01-17 16:37:14 -08:00
|
|
|
name.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
2011-01-05 13:54:43 -08:00
|
|
|
|
|
|
|
|
if (createHolographicOutline) {
|
|
|
|
|
mIconCache = cache;
|
|
|
|
|
mIconCacheKey = new PagedViewIconCache.Key(info);
|
|
|
|
|
mHolographicOutline = mIconCache.getOutline(mIconCacheKey);
|
|
|
|
|
mPreview = preview;
|
|
|
|
|
}
|
2010-12-01 15:47:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
|
// We eat up the touch events here, since the PagedView (which uses the same swiping
|
|
|
|
|
// touch code as Workspace previously) uses onInterceptTouchEvent() to determine when
|
|
|
|
|
// the user is scrolling between pages. This means that if the pages themselves don't
|
|
|
|
|
// handle touch events, it gets forwarded up to PagedView itself, and it's own
|
|
|
|
|
// onTouchEvent() handling will prevent further intercept touch events from being called
|
|
|
|
|
// (it's the same view in that case). This is not ideal, but to prevent more changes,
|
|
|
|
|
// we just always mark the touch event as handled.
|
|
|
|
|
return super.onTouchEvent(event) || true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-13 11:27:36 -07:00
|
|
|
@Override
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2011-05-09 11:56:34 -07:00
|
|
|
if (LauncherApplication.isScreenXLarge()) {
|
|
|
|
|
return FocusHelper.handlePagedViewWidgetKeyEvent(this, keyCode, event)
|
|
|
|
|
|| super.onKeyDown(keyCode, event);
|
|
|
|
|
} else {
|
|
|
|
|
return FocusHelper.handlePagedViewGridLayoutWidgetKeyEvent(this, keyCode, event)
|
|
|
|
|
|| super.onKeyDown(keyCode, event);
|
|
|
|
|
}
|
2011-04-13 11:27:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
2011-05-09 11:56:34 -07:00
|
|
|
if (LauncherApplication.isScreenXLarge()) {
|
|
|
|
|
return FocusHelper.handlePagedViewWidgetKeyEvent(this, keyCode, event)
|
|
|
|
|
|| super.onKeyUp(keyCode, event);
|
|
|
|
|
} else {
|
|
|
|
|
return FocusHelper.handlePagedViewGridLayoutWidgetKeyEvent(this, keyCode, event)
|
|
|
|
|
|| super.onKeyUp(keyCode, event);
|
|
|
|
|
}
|
2011-04-13 11:27:36 -07:00
|
|
|
}
|
|
|
|
|
|
2010-12-01 15:47:31 -08:00
|
|
|
@Override
|
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
|
if (mAlpha > 0) {
|
|
|
|
|
super.onDraw(canvas);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// draw any blended overlays
|
|
|
|
|
if (mHolographicOutline != null && mHolographicAlpha > 0) {
|
2011-02-24 18:09:44 -08:00
|
|
|
// Calculate how much to scale the holographic preview
|
|
|
|
|
mTmpScaleRect.set(0,0,1,1);
|
|
|
|
|
mPreviewImageView.getImageMatrix().mapRect(mTmpScaleRect);
|
|
|
|
|
|
2010-12-01 15:47:31 -08:00
|
|
|
mPaint.setAlpha(mHolographicAlpha);
|
2011-02-24 18:09:44 -08:00
|
|
|
canvas.save();
|
|
|
|
|
canvas.scale(mTmpScaleRect.right, mTmpScaleRect.bottom);
|
2010-12-01 15:47:31 -08:00
|
|
|
canvas.drawBitmap(mHolographicOutline, 0, 0, mPaint);
|
2011-02-24 18:09:44 -08:00
|
|
|
canvas.restore();
|
2010-12-01 15:47:31 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean onSetAlpha(int alpha) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setAlpha(float alpha) {
|
|
|
|
|
final float viewAlpha = sHolographicOutlineHelper.viewAlphaInterpolator(alpha);
|
|
|
|
|
final float holographicAlpha = sHolographicOutlineHelper.highlightAlphaInterpolator(alpha);
|
|
|
|
|
int newViewAlpha = (int) (viewAlpha * 255);
|
|
|
|
|
int newHolographicAlpha = (int) (holographicAlpha * 255);
|
|
|
|
|
if ((mAlpha != newViewAlpha) || (mHolographicAlpha != newHolographicAlpha)) {
|
|
|
|
|
mAlpha = newViewAlpha;
|
|
|
|
|
mHolographicAlpha = newHolographicAlpha;
|
|
|
|
|
setChildrenAlpha(viewAlpha);
|
|
|
|
|
super.setAlpha(viewAlpha);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setChildrenAlpha(float alpha) {
|
|
|
|
|
final int childCount = getChildCount();
|
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
|
getChildAt(i).setAlpha(alpha);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
|
|
|
if (w > 0 && h > 0) {
|
|
|
|
|
queueHolographicOutlineCreation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.onSizeChanged(w, h, oldw, oldh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDetachedFromWindow() {
|
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
|
sWorker.removeMessages(MESSAGE_CREATE_HOLOGRAPHIC_OUTLINE, this);
|
|
|
|
|
}
|
2010-12-21 11:31:54 -08:00
|
|
|
|
2011-02-18 14:35:21 -08:00
|
|
|
void setChecked(boolean checked, boolean animate) {
|
2010-12-21 11:31:54 -08:00
|
|
|
if (mIsChecked != checked) {
|
|
|
|
|
mIsChecked = checked;
|
|
|
|
|
|
|
|
|
|
float alpha;
|
|
|
|
|
int duration;
|
|
|
|
|
if (mIsChecked) {
|
|
|
|
|
alpha = mCheckedAlpha;
|
|
|
|
|
duration = mCheckedFadeInDuration;
|
|
|
|
|
} else {
|
|
|
|
|
alpha = 1.0f;
|
|
|
|
|
duration = mCheckedFadeOutDuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize the animator
|
|
|
|
|
if (mCheckedAlphaAnimator != null) {
|
|
|
|
|
mCheckedAlphaAnimator.cancel();
|
|
|
|
|
}
|
2011-02-18 14:35:21 -08:00
|
|
|
if (animate) {
|
|
|
|
|
mCheckedAlphaAnimator = ObjectAnimator.ofFloat(this, "alpha", getAlpha(), alpha);
|
|
|
|
|
mCheckedAlphaAnimator.setDuration(duration);
|
|
|
|
|
mCheckedAlphaAnimator.start();
|
|
|
|
|
} else {
|
|
|
|
|
setAlpha(alpha);
|
|
|
|
|
}
|
2010-12-21 11:31:54 -08:00
|
|
|
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-18 14:35:21 -08:00
|
|
|
@Override
|
|
|
|
|
public void setChecked(boolean checked) {
|
|
|
|
|
setChecked(checked, true);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-21 11:31:54 -08:00
|
|
|
@Override
|
|
|
|
|
public boolean isChecked() {
|
|
|
|
|
return mIsChecked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void toggle() {
|
|
|
|
|
setChecked(!mIsChecked);
|
|
|
|
|
}
|
2010-12-01 15:47:31 -08:00
|
|
|
}
|