Merge "Register implicit broadcasts at runtime for updating widgets" am: 9d1aeb4d80 am: df7c6643ae

Change-Id: I358737606c3697dcd418cf618911769ac090d93a
This commit is contained in:
Automerger Merge Worker
2020-02-11 22:37:03 +00:00
2 changed files with 49 additions and 49 deletions
-6
View File
@@ -484,9 +484,6 @@
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="com.android.Bugle.intent.action.ACTION_NOTIFY_CONVERSATIONS_CHANGED" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" <meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_conversation_list" /> android:resource="@xml/widget_conversation_list" />
</receiver> </receiver>
@@ -497,9 +494,6 @@
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="com.android.Bugle.intent.action.ACTION_NOTIFY_MESSAGES_CHANGED" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" <meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_conversation" /> android:resource="@xml/widget_conversation" />
</receiver> </receiver>
@@ -21,6 +21,7 @@ import android.appwidget.AppWidgetProvider;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import com.android.messaging.util.LogUtil; import com.android.messaging.util.LogUtil;
@@ -78,6 +79,12 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
} }
} }
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
context.getApplicationContext().registerReceiver(this, new IntentFilter(getAction()));
}
protected abstract String getAction(); protected abstract String getAction();
protected abstract int getListId(); protected abstract int getListId();
@@ -87,52 +94,51 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
*/ */
protected abstract void updateWidget(Context context, int appWidgetId); protected abstract void updateWidget(Context context, int appWidgetId);
private int getWidgetSize(AppWidgetManager appWidgetManager, private int getWidgetSize(AppWidgetManager appWidgetManager, int appWidgetId) {
int appWidgetId) { if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) { LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize");
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize"); }
}
// Get the dimensions // Get the dimensions
final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId); final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
// Get min width and height. // Get min width and height.
final int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH); final int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
final int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT); final int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
// First find out rows and columns based on width provided. // First find out rows and columns based on width provided.
final int rows = getCellsForSize(minHeight); final int rows = getCellsForSize(minHeight);
final int columns = getCellsForSize(minWidth); final int columns = getCellsForSize(minWidth);
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize row: " + rows +
" columns: " + columns);
}
int size = SIZE_MEDIUM;
if (rows == 1) {
size = SIZE_SMALL; // Our widget doesn't let itself get this small. Perhaps in the
// future will add a super-mini widget.
} else if (columns > 3) {
size = SIZE_LARGE;
}
// put the size in the bundle so our service know what size it's dealing with.
final int savedSize = options.getInt(WIDGET_SIZE_KEY);
if (savedSize != size) {
options.putInt(WIDGET_SIZE_KEY, size);
appWidgetManager.updateAppWidgetOptions(appWidgetId, options);
// The size changed. We have to force the widget to rebuild the list.
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, getListId());
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) { if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize old size: " + savedSize + LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize row: " + rows
" new size saved: " + size); + " columns: " + columns);
} }
}
return size; int size = SIZE_MEDIUM;
if (rows == 1) {
size = SIZE_SMALL; // Our widget doesn't let itself get this small. Perhaps in the
// future will add a super-mini widget.
} else if (columns > 3) {
size = SIZE_LARGE;
}
// put the size in the bundle so our service know what size it's dealing with.
final int savedSize = options.getInt(WIDGET_SIZE_KEY);
if (savedSize != size) {
options.putInt(WIDGET_SIZE_KEY, size);
appWidgetManager.updateAppWidgetOptions(appWidgetId, options);
// The size changed. We have to force the widget to rebuild the list.
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, getListId());
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize old size: " + savedSize
+ " new size saved: " + size);
}
}
return size;
} }
/** /**
@@ -142,10 +148,10 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
* @return Size in number of cells. * @return Size in number of cells.
*/ */
private static int getCellsForSize(int size) { private static int getCellsForSize(int size) {
// The hardwired sizes in this function come from the hardwired formula found in // The hardwired sizes in this function come from the hardwired formula found in
// Android's UI guidelines for widget design: // Android's UI guidelines for widget design:
// http://developer.android.com/guide/practices/ui_guidelines/widget_design.html // http://developer.android.com/guide/practices/ui_guidelines/widget_design.html
return (size + 30) / 70; return (size + 30) / 70;
} }
@Override @Override