2009-03-03 19:32:27 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2009 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2009-03-11 12:11:58 -07:00
|
|
|
import android.appwidget.AppWidgetHostView;
|
2014-03-05 18:07:04 -08:00
|
|
|
import android.appwidget.AppWidgetProviderInfo;
|
2009-03-03 19:32:27 -08:00
|
|
|
import android.content.Context;
|
2015-10-28 23:28:21 -07:00
|
|
|
import android.graphics.Rect;
|
2016-09-25 21:23:25 -07:00
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.SystemClock;
|
2016-11-02 11:22:39 -07:00
|
|
|
import android.util.Log;
|
2016-09-25 21:23:25 -07:00
|
|
|
import android.util.SparseBooleanArray;
|
2015-10-28 23:28:21 -07:00
|
|
|
import android.view.KeyEvent;
|
2009-03-03 19:32:27 -08:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
2014-04-15 15:23:31 -04:00
|
|
|
import android.view.ViewConfiguration;
|
2016-02-09 11:28:52 -08:00
|
|
|
import android.view.ViewDebug;
|
2011-04-13 11:27:36 -07:00
|
|
|
import android.view.ViewGroup;
|
2016-03-10 05:34:30 -08:00
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
2016-09-25 21:23:25 -07:00
|
|
|
import android.widget.Advanceable;
|
2012-06-01 17:17:08 -07:00
|
|
|
import android.widget.RemoteViews;
|
2009-03-03 19:32:27 -08:00
|
|
|
|
2015-08-19 17:55:02 -07:00
|
|
|
import com.android.launcher3.dragndrop.DragLayer.TouchCompleteListener;
|
2013-10-08 19:16:14 -07:00
|
|
|
|
2016-11-02 11:22:39 -07:00
|
|
|
import java.lang.reflect.Method;
|
2015-10-28 23:28:21 -07:00
|
|
|
import java.util.ArrayList;
|
2016-11-02 11:22:39 -07:00
|
|
|
import java.util.concurrent.Executor;
|
2015-10-28 23:28:21 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
2013-10-08 19:16:14 -07:00
|
|
|
public class LauncherAppWidgetHostView extends AppWidgetHostView implements TouchCompleteListener {
|
2014-07-23 13:58:07 -07:00
|
|
|
|
2016-11-02 11:22:39 -07:00
|
|
|
private static final String TAG = "LauncherWidgetHostView";
|
|
|
|
|
|
2016-09-25 21:23:25 -07:00
|
|
|
// Related to the auto-advancing of widgets
|
|
|
|
|
private static final long ADVANCE_INTERVAL = 20000;
|
|
|
|
|
private static final long ADVANCE_STAGGER = 250;
|
|
|
|
|
|
|
|
|
|
// Maintains a list of widget ids which are supposed to be auto advanced.
|
|
|
|
|
private static final SparseBooleanArray sAutoAdvanceWidgetIds = new SparseBooleanArray();
|
|
|
|
|
|
2014-07-23 13:58:07 -07:00
|
|
|
LayoutInflater mInflater;
|
|
|
|
|
|
2012-02-23 15:23:44 -08:00
|
|
|
private CheckLongPressHelper mLongPressHelper;
|
2015-06-02 15:02:14 -07:00
|
|
|
private StylusEventHelper mStylusEventHelper;
|
2012-06-01 17:17:08 -07:00
|
|
|
private Context mContext;
|
2016-02-09 11:28:52 -08:00
|
|
|
@ViewDebug.ExportedProperty(category = "launcher")
|
2012-06-01 17:17:08 -07:00
|
|
|
private int mPreviousOrientation;
|
2011-01-07 15:37:17 -08:00
|
|
|
|
2014-04-15 15:23:31 -04:00
|
|
|
private float mSlop;
|
|
|
|
|
|
2016-02-09 11:28:52 -08:00
|
|
|
@ViewDebug.ExportedProperty(category = "launcher")
|
2015-10-28 23:28:21 -07:00
|
|
|
private boolean mChildrenFocused;
|
|
|
|
|
|
2016-09-25 21:23:25 -07:00
|
|
|
private boolean mIsAttachedToWindow;
|
|
|
|
|
private boolean mIsAutoAdvanceRegistered;
|
|
|
|
|
private Runnable mAutoAdvanceRunnable;
|
|
|
|
|
|
2009-03-11 12:11:58 -07:00
|
|
|
public LauncherAppWidgetHostView(Context context) {
|
2009-03-03 19:32:27 -08:00
|
|
|
super(context);
|
2012-06-01 17:17:08 -07:00
|
|
|
mContext = context;
|
2012-02-23 15:23:44 -08:00
|
|
|
mLongPressHelper = new CheckLongPressHelper(this);
|
2015-07-15 16:34:34 -07:00
|
|
|
mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);
|
2016-11-04 10:19:58 -07:00
|
|
|
mInflater = LayoutInflater.from(context);
|
2016-07-08 08:32:44 -07:00
|
|
|
setAccessibilityDelegate(Launcher.getLauncher(context).getAccessibilityDelegate());
|
2016-02-10 12:15:41 -08:00
|
|
|
setBackgroundResource(R.drawable.widget_internal_focus_bg);
|
2016-11-02 11:22:39 -07:00
|
|
|
|
|
|
|
|
if (Utilities.isAtLeastO()) {
|
|
|
|
|
try {
|
|
|
|
|
Method asyncMethod = AppWidgetHostView.class
|
|
|
|
|
.getMethod("setAsyncExecutor", Executor.class);
|
|
|
|
|
asyncMethod.invoke(this, Utilities.THREAD_POOL_EXECUTOR);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Log.e(TAG, "Unable to set async executor", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2011-05-31 15:52:28 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
@Override
|
|
|
|
|
protected View getErrorView() {
|
2016-10-07 16:17:19 -07:00
|
|
|
return mInflater.inflate(R.layout.appwidget_error, this, false);
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
|
|
|
|
|
2014-03-05 18:07:04 -08:00
|
|
|
public void updateLastInflationOrientation() {
|
|
|
|
|
mPreviousOrientation = mContext.getResources().getConfiguration().orientation;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-01 17:17:08 -07:00
|
|
|
@Override
|
|
|
|
|
public void updateAppWidget(RemoteViews remoteViews) {
|
|
|
|
|
// Store the orientation in which the widget was inflated
|
2014-03-05 18:07:04 -08:00
|
|
|
updateLastInflationOrientation();
|
2012-06-01 17:17:08 -07:00
|
|
|
super.updateAppWidget(remoteViews);
|
2016-09-25 21:23:25 -07:00
|
|
|
|
|
|
|
|
// The provider info or the views might have changed.
|
|
|
|
|
checkIfAutoAdvance();
|
2012-06-01 17:17:08 -07:00
|
|
|
}
|
|
|
|
|
|
2014-07-23 13:58:07 -07:00
|
|
|
public boolean isReinflateRequired() {
|
|
|
|
|
// Re-inflate is required if the orientation has changed since last inflated.
|
2012-06-01 17:17:08 -07:00
|
|
|
int orientation = mContext.getResources().getConfiguration().orientation;
|
|
|
|
|
if (mPreviousOrientation != orientation) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
2013-10-16 10:30:50 -07:00
|
|
|
// Just in case the previous long press hasn't been cleared, we make sure to start fresh
|
|
|
|
|
// on touch down.
|
|
|
|
|
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
|
mLongPressHelper.cancelLongPress();
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
// Consume any touch events for ourselves after longpress is triggered
|
2012-02-23 15:23:44 -08:00
|
|
|
if (mLongPressHelper.hasPerformedLongPress()) {
|
|
|
|
|
mLongPressHelper.cancelLongPress();
|
2009-03-03 19:32:27 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
2011-05-31 14:30:45 -07:00
|
|
|
|
2015-06-02 15:02:14 -07:00
|
|
|
// Watch for longpress or stylus button press events at this level to
|
|
|
|
|
// make sure users can always pick up this widget
|
2015-07-15 16:34:34 -07:00
|
|
|
if (mStylusEventHelper.onMotionEvent(ev)) {
|
2015-06-02 15:02:14 -07:00
|
|
|
mLongPressHelper.cancelLongPress();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
switch (ev.getAction()) {
|
|
|
|
|
case MotionEvent.ACTION_DOWN: {
|
2015-06-02 15:02:14 -07:00
|
|
|
if (!mStylusEventHelper.inStylusButtonPressed()) {
|
|
|
|
|
mLongPressHelper.postCheckForLongPress();
|
|
|
|
|
}
|
2016-07-11 17:30:03 -07:00
|
|
|
Launcher.getLauncher(getContext()).getDragLayer().setTouchCompleteListener(this);
|
2009-03-03 19:32:27 -08:00
|
|
|
break;
|
|
|
|
|
}
|
2011-05-31 14:30:45 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
|
|
case MotionEvent.ACTION_CANCEL:
|
2012-02-23 15:23:44 -08:00
|
|
|
mLongPressHelper.cancelLongPress();
|
2009-03-03 19:32:27 -08:00
|
|
|
break;
|
2014-04-15 15:23:31 -04:00
|
|
|
case MotionEvent.ACTION_MOVE:
|
|
|
|
|
if (!Utilities.pointInView(this, ev.getX(), ev.getY(), mSlop)) {
|
|
|
|
|
mLongPressHelper.cancelLongPress();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|
2011-05-31 14:30:45 -07:00
|
|
|
|
2009-03-03 19:32:27 -08:00
|
|
|
// Otherwise continue letting touch events fall through to children
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-02-18 19:25:06 -08:00
|
|
|
|
2013-08-16 11:10:59 -07:00
|
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
|
|
|
|
// If the widget does not handle touch, then cancel
|
|
|
|
|
// long press when we release the touch
|
|
|
|
|
switch (ev.getAction()) {
|
|
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
|
|
case MotionEvent.ACTION_CANCEL:
|
|
|
|
|
mLongPressHelper.cancelLongPress();
|
|
|
|
|
break;
|
2014-04-15 15:23:31 -04:00
|
|
|
case MotionEvent.ACTION_MOVE:
|
|
|
|
|
if (!Utilities.pointInView(this, ev.getX(), ev.getY(), mSlop)) {
|
|
|
|
|
mLongPressHelper.cancelLongPress();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-08-16 11:10:59 -07:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-15 15:23:31 -04:00
|
|
|
@Override
|
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
|
mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
|
2016-09-25 21:23:25 -07:00
|
|
|
|
|
|
|
|
mIsAttachedToWindow = true;
|
|
|
|
|
checkIfAutoAdvance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
|
|
|
|
|
|
// We can't directly use isAttachedToWindow() here, as this is called before the internal
|
|
|
|
|
// state is updated. So isAttachedToWindow() will return true until next frame.
|
|
|
|
|
mIsAttachedToWindow = false;
|
|
|
|
|
checkIfAutoAdvance();
|
2014-04-15 15:23:31 -04:00
|
|
|
}
|
|
|
|
|
|
2009-04-20 21:03:13 -07:00
|
|
|
@Override
|
|
|
|
|
public void cancelLongPress() {
|
|
|
|
|
super.cancelLongPress();
|
2013-10-08 19:16:14 -07:00
|
|
|
mLongPressHelper.cancelLongPress();
|
|
|
|
|
}
|
2009-04-20 21:03:13 -07:00
|
|
|
|
2014-03-05 18:07:04 -08:00
|
|
|
@Override
|
|
|
|
|
public AppWidgetProviderInfo getAppWidgetInfo() {
|
|
|
|
|
AppWidgetProviderInfo info = super.getAppWidgetInfo();
|
2015-02-17 11:44:15 -08:00
|
|
|
if (info != null && !(info instanceof LauncherAppWidgetProviderInfo)) {
|
2014-03-05 18:07:04 -08:00
|
|
|
throw new IllegalStateException("Launcher widget must have"
|
2015-02-17 11:44:15 -08:00
|
|
|
+ " LauncherAppWidgetProviderInfo");
|
2014-03-05 18:07:04 -08:00
|
|
|
}
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-08 19:16:14 -07:00
|
|
|
@Override
|
|
|
|
|
public void onTouchComplete() {
|
2013-10-16 10:30:50 -07:00
|
|
|
if (!mLongPressHelper.hasPerformedLongPress()) {
|
|
|
|
|
// If a long press has been performed, we don't want to clear the record of that since
|
|
|
|
|
// we still may be receiving a touch up which we want to intercept
|
|
|
|
|
mLongPressHelper.cancelLongPress();
|
|
|
|
|
}
|
2009-04-20 21:03:13 -07:00
|
|
|
}
|
2011-01-07 15:37:17 -08:00
|
|
|
|
2011-04-13 11:27:36 -07:00
|
|
|
@Override
|
|
|
|
|
public int getDescendantFocusability() {
|
2015-10-28 23:28:21 -07:00
|
|
|
return mChildrenFocused ? ViewGroup.FOCUS_BEFORE_DESCENDANTS
|
|
|
|
|
: ViewGroup.FOCUS_BLOCK_DESCENDANTS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
|
|
|
|
if (mChildrenFocused && event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE
|
|
|
|
|
&& event.getAction() == KeyEvent.ACTION_UP) {
|
|
|
|
|
mChildrenFocused = false;
|
|
|
|
|
requestFocus();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return super.dispatchKeyEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
|
if (!mChildrenFocused && keyCode == KeyEvent.KEYCODE_ENTER) {
|
|
|
|
|
event.startTracking();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
|
if (event.isTracking()) {
|
|
|
|
|
if (!mChildrenFocused && keyCode == KeyEvent.KEYCODE_ENTER) {
|
|
|
|
|
mChildrenFocused = true;
|
|
|
|
|
ArrayList<View> focusableChildren = getFocusables(FOCUS_FORWARD);
|
|
|
|
|
focusableChildren.remove(this);
|
|
|
|
|
int childrenCount = focusableChildren.size();
|
|
|
|
|
switch (childrenCount) {
|
|
|
|
|
case 0:
|
|
|
|
|
mChildrenFocused = false;
|
|
|
|
|
break;
|
|
|
|
|
case 1: {
|
|
|
|
|
if (getTag() instanceof ItemInfo) {
|
|
|
|
|
ItemInfo item = (ItemInfo) getTag();
|
|
|
|
|
if (item.spanX == 1 && item.spanY == 1) {
|
|
|
|
|
focusableChildren.get(0).performClick();
|
|
|
|
|
mChildrenFocused = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// continue;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
focusableChildren.get(0).requestFocus();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
|
|
|
|
|
if (gainFocus) {
|
|
|
|
|
mChildrenFocused = false;
|
2016-02-10 12:15:41 -08:00
|
|
|
dispatchChildFocus(false);
|
2015-10-28 23:28:21 -07:00
|
|
|
}
|
|
|
|
|
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
|
2011-04-13 11:27:36 -07:00
|
|
|
}
|
2015-12-01 13:21:49 -08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void requestChildFocus(View child, View focused) {
|
|
|
|
|
super.requestChildFocus(child, focused);
|
2016-05-04 14:03:40 -07:00
|
|
|
dispatchChildFocus(mChildrenFocused && focused != null);
|
2016-02-10 12:15:41 -08:00
|
|
|
if (focused != null) {
|
|
|
|
|
focused.setFocusableInTouchMode(false);
|
|
|
|
|
}
|
2015-12-01 13:21:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void clearChildFocus(View child) {
|
|
|
|
|
super.clearChildFocus(child);
|
|
|
|
|
dispatchChildFocus(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean dispatchUnhandledMove(View focused, int direction) {
|
|
|
|
|
return mChildrenFocused;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-10 12:15:41 -08:00
|
|
|
private void dispatchChildFocus(boolean childIsFocused) {
|
|
|
|
|
// The host view's background changes when selected, to indicate the focus is inside.
|
|
|
|
|
setSelected(childIsFocused);
|
2015-12-01 13:21:49 -08:00
|
|
|
}
|
2016-01-25 17:28:37 -08:00
|
|
|
|
2016-11-04 10:19:58 -07:00
|
|
|
public void switchToErrorView() {
|
|
|
|
|
// Update the widget with 0 Layout id, to reset the view to error view.
|
|
|
|
|
updateAppWidget(new RemoteViews(getAppWidgetInfo().provider.getPackageName(), 0));
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 17:28:37 -08:00
|
|
|
@Override
|
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
|
try {
|
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
|
} catch (final RuntimeException e) {
|
|
|
|
|
post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
2016-11-04 10:19:58 -07:00
|
|
|
switchToErrorView();
|
2016-01-25 17:28:37 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-10 05:34:30 -08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
|
|
|
|
|
super.onInitializeAccessibilityNodeInfo(info);
|
|
|
|
|
info.setClassName(getClass().getName());
|
|
|
|
|
}
|
2016-09-25 21:23:25 -07:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onWindowVisibilityChanged(int visibility) {
|
|
|
|
|
super.onWindowVisibilityChanged(visibility);
|
|
|
|
|
maybeRegisterAutoAdvance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkIfAutoAdvance() {
|
|
|
|
|
boolean isAutoAdvance = false;
|
|
|
|
|
Advanceable target = getAdvanceable();
|
|
|
|
|
if (target != null) {
|
|
|
|
|
isAutoAdvance = true;
|
|
|
|
|
target.fyiWillBeAdvancedByHostKThx();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean wasAutoAdvance = sAutoAdvanceWidgetIds.indexOfKey(getAppWidgetId()) >= 0;
|
|
|
|
|
if (isAutoAdvance != wasAutoAdvance) {
|
|
|
|
|
if (isAutoAdvance) {
|
|
|
|
|
sAutoAdvanceWidgetIds.put(getAppWidgetId(), true);
|
|
|
|
|
} else {
|
|
|
|
|
sAutoAdvanceWidgetIds.delete(getAppWidgetId());
|
|
|
|
|
}
|
|
|
|
|
maybeRegisterAutoAdvance();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Advanceable getAdvanceable() {
|
|
|
|
|
AppWidgetProviderInfo info = getAppWidgetInfo();
|
|
|
|
|
if (info == null || info.autoAdvanceViewId == NO_ID || !mIsAttachedToWindow) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
View v = findViewById(info.autoAdvanceViewId);
|
|
|
|
|
return (v instanceof Advanceable) ? (Advanceable) v : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void maybeRegisterAutoAdvance() {
|
|
|
|
|
Handler handler = getHandler();
|
|
|
|
|
boolean shouldRegisterAutoAdvance = getWindowVisibility() == VISIBLE && handler != null
|
|
|
|
|
&& (sAutoAdvanceWidgetIds.indexOfKey(getAppWidgetId()) >= 0);
|
|
|
|
|
if (shouldRegisterAutoAdvance != mIsAutoAdvanceRegistered) {
|
|
|
|
|
mIsAutoAdvanceRegistered = shouldRegisterAutoAdvance;
|
|
|
|
|
if (mAutoAdvanceRunnable == null) {
|
|
|
|
|
mAutoAdvanceRunnable = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
runAutoAdvance();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handler.removeCallbacks(mAutoAdvanceRunnable);
|
|
|
|
|
scheduleNextAdvance();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void scheduleNextAdvance() {
|
|
|
|
|
if (!mIsAutoAdvanceRegistered) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
long now = SystemClock.uptimeMillis();
|
|
|
|
|
long advanceTime = now + (ADVANCE_INTERVAL - (now % ADVANCE_INTERVAL)) +
|
|
|
|
|
ADVANCE_STAGGER * sAutoAdvanceWidgetIds.indexOfKey(getAppWidgetId());
|
|
|
|
|
Handler handler = getHandler();
|
|
|
|
|
if (handler != null) {
|
|
|
|
|
handler.postAtTime(mAutoAdvanceRunnable, advanceTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void runAutoAdvance() {
|
|
|
|
|
Advanceable target = getAdvanceable();
|
|
|
|
|
if (target != null) {
|
|
|
|
|
target.advance();
|
|
|
|
|
}
|
|
|
|
|
scheduleNextAdvance();
|
|
|
|
|
}
|
2009-03-03 19:32:27 -08:00
|
|
|
}
|