summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaesu Lee <taesu82.lee@samsung.com>2020-02-10 15:20:27 +0900
committerLuca Stefani <luca.stefani.ge1@gmail.com>2020-02-12 14:20:08 +0100
commit4a832963637111731df630d14796e883ef3a4c23 (patch)
tree23123f8c219d0df698c5335cbb5c80da2cdac7b3
parent55c8fd976803d58961b51143d8a2161eac8f3f14 (diff)
downloadandroid_packages_apps_Messaging-4a832963637111731df630d14796e883ef3a4c23.tar.gz
android_packages_apps_Messaging-4a832963637111731df630d14796e883ef3a4c23.tar.bz2
android_packages_apps_Messaging-4a832963637111731df630d14796e883ef3a4c23.zip
Register implicit broadcasts at runtime for updating widgets
It resolves Broadcast Limitations issue if target API level is changed as 26 or higher later. It includes fixing code style also. Test: Check messaging widgets' changes. Change-Id: I6e08027b1d6a5a19cfd17f8ec3e9a895dbb3c44a Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
-rw-r--r--AndroidManifest.xml6
-rw-r--r--src/com/android/messaging/widget/BaseWidgetProvider.java84
2 files changed, 45 insertions, 45 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ea945c5..e3f65ae 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -489,9 +489,6 @@
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</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"
android:resource="@xml/widget_conversation_list" />
</receiver>
@@ -502,9 +499,6 @@
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</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"
android:resource="@xml/widget_conversation" />
</receiver>
diff --git a/src/com/android/messaging/widget/BaseWidgetProvider.java b/src/com/android/messaging/widget/BaseWidgetProvider.java
index 431a6c7..6632c5f 100644
--- a/src/com/android/messaging/widget/BaseWidgetProvider.java
+++ b/src/com/android/messaging/widget/BaseWidgetProvider.java
@@ -21,6 +21,7 @@ import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.os.Bundle;
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 int getListId();
@@ -87,52 +94,51 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
*/
protected abstract void updateWidget(Context context, int appWidgetId);
- private int getWidgetSize(AppWidgetManager appWidgetManager,
- int appWidgetId) {
- if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
- LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize");
- }
+ private int getWidgetSize(AppWidgetManager appWidgetManager, int appWidgetId) {
+ if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
+ LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize");
+ }
- // Get the dimensions
- final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
+ // Get the dimensions
+ final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
- // Get min width and height.
- final int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
- final int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
+ // Get min width and height.
+ final int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
+ final int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
- // First find out rows and columns based on width provided.
- final int rows = getCellsForSize(minHeight);
- final int columns = getCellsForSize(minWidth);
+ // First find out rows and columns based on width provided.
+ final int rows = getCellsForSize(minHeight);
+ final int columns = getCellsForSize(minWidth);
- if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
- LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize row: " + rows +
- " columns: " + columns);
- }
+ 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
+ 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;
- }
+ } 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);
+ // 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());
+ // 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);
+ if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
+ LogUtil.v(TAG, "BaseWidgetProvider.getWidgetSize old size: " + savedSize
+ + " new size saved: " + size);
+ }
}
- }
- return size;
+ return size;
}
/**
@@ -142,10 +148,10 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider {
* @return Size in number of cells.
*/
private static int getCellsForSize(int size) {
- // The hardwired sizes in this function come from the hardwired formula found in
- // Android's UI guidelines for widget design:
- // http://developer.android.com/guide/practices/ui_guidelines/widget_design.html
- return (size + 30) / 70;
+ // The hardwired sizes in this function come from the hardwired formula found in
+ // Android's UI guidelines for widget design:
+ // http://developer.android.com/guide/practices/ui_guidelines/widget_design.html
+ return (size + 30) / 70;
}
@Override