Enforce max number of 5 lockscreen widgets
Change-Id: I7b7fca18174736c8f1aa0018f7399982c80b1cb0
This commit is contained in:
@@ -69,6 +69,8 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
// Found in KeyguardAppWidgetPickActivity.java
|
// Found in KeyguardAppWidgetPickActivity.java
|
||||||
static final int APPWIDGET_HOST_ID = 0x4B455947;
|
static final int APPWIDGET_HOST_ID = 0x4B455947;
|
||||||
|
|
||||||
|
private final int MAX_WIDGETS = 5;
|
||||||
|
|
||||||
private AppWidgetHost mAppWidgetHost;
|
private AppWidgetHost mAppWidgetHost;
|
||||||
private AppWidgetManager mAppWidgetManager;
|
private AppWidgetManager mAppWidgetManager;
|
||||||
private KeyguardWidgetPager mAppWidgetContainer;
|
private KeyguardWidgetPager mAppWidgetContainer;
|
||||||
@@ -225,6 +227,9 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
addDefaultWidgets();
|
addDefaultWidgets();
|
||||||
|
|
||||||
addWidgetsFromSettings();
|
addWidgetsFromSettings();
|
||||||
|
if (numWidgets() >= MAX_WIDGETS) {
|
||||||
|
setAddWidgetEnabled(false);
|
||||||
|
}
|
||||||
checkAppWidgetConsistency();
|
checkAppWidgetConsistency();
|
||||||
mSwitchPageRunnable.run();
|
mSwitchPageRunnable.run();
|
||||||
// This needs to be called after the pages are all added.
|
// This needs to be called after the pages are all added.
|
||||||
@@ -313,6 +318,13 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
public void onUserActivityTimeoutChanged() {
|
public void onUserActivityTimeoutChanged() {
|
||||||
KeyguardHostView.this.onUserActivityTimeoutChanged();
|
KeyguardHostView.this.onUserActivityTimeoutChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoveView(View v) {
|
||||||
|
if (numWidgets() < MAX_WIDGETS) {
|
||||||
|
setAddWidgetEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public void userActivity() {
|
public void userActivity() {
|
||||||
@@ -975,13 +987,33 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private int numWidgets() {
|
||||||
|
final int childCount = mAppWidgetContainer.getChildCount();
|
||||||
|
int widgetCount = 0;
|
||||||
|
for (int i = 0; i < childCount; i++) {
|
||||||
|
if (mAppWidgetContainer.isWidgetPage(i)) {
|
||||||
|
widgetCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return widgetCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setAddWidgetEnabled(boolean clickable) {
|
||||||
|
View addWidget = mAppWidgetContainer.findViewById(R.id.keyguard_add_widget);
|
||||||
|
if (addWidget != null) {
|
||||||
|
View addWidgetButton = addWidget.findViewById(R.id.keyguard_add_widget_view);
|
||||||
|
addWidgetButton.setEnabled(clickable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addDefaultWidgets() {
|
private void addDefaultWidgets() {
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
inflater.inflate(R.layout.keyguard_transport_control_view, this, true);
|
inflater.inflate(R.layout.keyguard_transport_control_view, this, true);
|
||||||
|
|
||||||
if (!mSafeModeEnabled && !widgetsDisabledByDpm()) {
|
if (!mSafeModeEnabled && !widgetsDisabledByDpm()) {
|
||||||
View addWidget = inflater.inflate(R.layout.keyguard_add_widget, this, false);
|
View addWidget = inflater.inflate(R.layout.keyguard_add_widget, this, false);
|
||||||
mAppWidgetContainer.addWidget(addWidget);
|
mAppWidgetContainer.addWidget(addWidget, 0);
|
||||||
View addWidgetButton = addWidget.findViewById(R.id.keyguard_add_widget_view);
|
View addWidgetButton = addWidget.findViewById(R.id.keyguard_add_widget_view);
|
||||||
addWidgetButton.setOnClickListener(new OnClickListener() {
|
addWidgetButton.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
|
|||||||
public interface Callbacks {
|
public interface Callbacks {
|
||||||
public void userActivity();
|
public void userActivity();
|
||||||
public void onUserActivityTimeoutChanged();
|
public void onUserActivityTimeoutChanged();
|
||||||
|
public void onRemoveView(View v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWidget(View widget) {
|
public void addWidget(View widget) {
|
||||||
@@ -245,6 +246,9 @@ public class KeyguardWidgetPager extends PagedView implements PagedView.PageSwit
|
|||||||
|
|
||||||
public void onRemoveView(View v) {
|
public void onRemoveView(View v) {
|
||||||
final int appWidgetId = ((KeyguardWidgetFrame) v).getContentAppWidgetId();
|
final int appWidgetId = ((KeyguardWidgetFrame) v).getContentAppWidgetId();
|
||||||
|
if (mCallbacks != null) {
|
||||||
|
mCallbacks.onRemoveView(v);
|
||||||
|
}
|
||||||
mBackgroundWorkerHandler.post(new Runnable() {
|
mBackgroundWorkerHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
Reference in New Issue
Block a user