mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 02:38:20 +00:00
Merge "Allowing widgets to be focusable" into ub-launcher3-burnaby-polish
This commit is contained in:
@@ -1621,18 +1621,28 @@ public class Launcher extends Activity
|
||||
// The AppWidgetHostView has already been inflated and instantiated
|
||||
launcherInfo.hostView = hostView;
|
||||
}
|
||||
launcherInfo.hostView.setTag(launcherInfo);
|
||||
launcherInfo.hostView.setVisibility(View.VISIBLE);
|
||||
launcherInfo.notifyWidgetSizeChanged(this);
|
||||
|
||||
mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, info.cellX,
|
||||
info.cellY, launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
|
||||
|
||||
addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
|
||||
addAppWidgetToWorkspace(launcherInfo, appWidgetInfo, isWorkspaceLocked());
|
||||
}
|
||||
resetAddInfo();
|
||||
}
|
||||
|
||||
private void addAppWidgetToWorkspace(LauncherAppWidgetInfo item,
|
||||
LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
|
||||
item.hostView.setTag(item);
|
||||
item.onBindAppWidget(this);
|
||||
|
||||
item.hostView.setFocusable(true);
|
||||
item.hostView.setOnFocusChangeListener(mFocusHandler);
|
||||
|
||||
mWorkspace.addInScreen(item.hostView, item.container, item.screenId,
|
||||
item.cellX, item.cellY, item.spanX, item.spanY, insert);
|
||||
|
||||
if (!item.isCustomWidget()) {
|
||||
addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@@ -4105,15 +4115,7 @@ public class Launcher extends Activity
|
||||
item.hostView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
item.hostView.setTag(item);
|
||||
item.onBindAppWidget(this);
|
||||
|
||||
workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
|
||||
item.cellY, item.spanX, item.spanY, false);
|
||||
if (!item.isCustomWidget()) {
|
||||
addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
|
||||
}
|
||||
|
||||
addAppWidgetToWorkspace(item, appWidgetInfo, false);
|
||||
workspace.requestLayout();
|
||||
|
||||
if (DEBUG_WIDGETS) {
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.android.launcher3;
|
||||
import android.appwidget.AppWidgetHostView;
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -28,6 +30,8 @@ import android.widget.RemoteViews;
|
||||
|
||||
import com.android.launcher3.DragLayer.TouchCompleteListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -43,6 +47,8 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView implements Touc
|
||||
|
||||
private float mSlop;
|
||||
|
||||
private boolean mChildrenFocused;
|
||||
|
||||
public LauncherAppWidgetHostView(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
@@ -175,6 +181,67 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView implements Touc
|
||||
|
||||
@Override
|
||||
public int getDescendantFocusability() {
|
||||
return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
|
||||
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;
|
||||
}
|
||||
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,17 +123,11 @@ public class LauncherAppWidgetInfo extends ItemInfo {
|
||||
*/
|
||||
void onBindAppWidget(Launcher launcher) {
|
||||
if (!mHasNotifiedInitialWidgetSizeChanged) {
|
||||
notifyWidgetSizeChanged(launcher);
|
||||
AppWidgetResizeFrame.updateWidgetSizeRanges(hostView, launcher, spanX, spanY);
|
||||
mHasNotifiedInitialWidgetSizeChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger an update callback to the widget to notify it that its size has changed.
|
||||
*/
|
||||
void notifyWidgetSizeChanged(Launcher launcher) {
|
||||
AppWidgetResizeFrame.updateWidgetSizeRanges(hostView, launcher, spanX, spanY);
|
||||
mHasNotifiedInitialWidgetSizeChanged = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
Reference in New Issue
Block a user