|
|
|
@ -34,18 +34,21 @@ import android.view.View;
|
|
|
|
import android.widget.RemoteViews;
|
|
|
|
import android.widget.RemoteViews;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.core.graphics.ColorUtils;
|
|
|
|
import androidx.core.graphics.ColorUtils;
|
|
|
|
|
|
|
|
import androidx.core.widget.RemoteViewsCompat;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
|
|
|
|
|
|
public class WidgetUnified extends AppWidgetProvider {
|
|
|
|
public class WidgetUnified extends AppWidgetProvider {
|
|
|
|
@Override
|
|
|
|
private static final ExecutorService executor = Helper.getBackgroundExecutor(1, "widget");
|
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
|
|
|
|
|
|
|
|
|
private static RemoteViews getRemoteViews(Context context, int appWidgetId, WidgetUnifiedRemoteViewsFactory factory) {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
|
|
|
|
|
|
|
int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground);
|
|
|
|
int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground);
|
|
|
|
int lightColorSeparator = context.getResources().getColor(R.color.lightColorSeparator);
|
|
|
|
int lightColorSeparator = context.getResources().getColor(R.color.lightColorSeparator);
|
|
|
|
int darkColorSeparator = context.getResources().getColor(R.color.darkColorSeparator);
|
|
|
|
int darkColorSeparator = context.getResources().getColor(R.color.darkColorSeparator);
|
|
|
|
|
|
|
|
|
|
|
|
for (int appWidgetId : appWidgetIds) {
|
|
|
|
|
|
|
|
String name = prefs.getString("widget." + appWidgetId + ".name", null);
|
|
|
|
String name = prefs.getString("widget." + appWidgetId + ".name", null);
|
|
|
|
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
|
|
|
|
long account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
|
|
|
|
long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
|
|
|
|
long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
|
|
|
|
@ -126,11 +129,16 @@ public class WidgetUnified extends AppWidgetProvider {
|
|
|
|
views.setViewPadding(R.id.compose, px, px, px, px);
|
|
|
|
views.setViewPadding(R.id.compose, px, px, px, px);
|
|
|
|
views.setOnClickPendingIntent(R.id.compose, piCompose);
|
|
|
|
views.setOnClickPendingIntent(R.id.compose, piCompose);
|
|
|
|
|
|
|
|
|
|
|
|
Intent service = new Intent(context, WidgetUnifiedService.class);
|
|
|
|
// https://developer.android.com/reference/kotlin/androidx/core/widget/RemoteViewsCompat.RemoteCollectionItems.Builder
|
|
|
|
service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
|
|
|
RemoteViewsCompat.RemoteCollectionItems.Builder builder =
|
|
|
|
service.setData(Uri.parse(service.toUri(Intent.URI_INTENT_SCHEME)));
|
|
|
|
new RemoteViewsCompat.RemoteCollectionItems.Builder()
|
|
|
|
|
|
|
|
.setHasStableIds(factory.hasStableIds())
|
|
|
|
|
|
|
|
.setViewTypeCount(factory.getViewTypeCount());
|
|
|
|
|
|
|
|
for (int i = 0; i < factory.getCount(); i++)
|
|
|
|
|
|
|
|
builder.addItem(factory.getItemId(i), factory.getViewAt(i));
|
|
|
|
|
|
|
|
|
|
|
|
views.setRemoteAdapter(R.id.lv, service);
|
|
|
|
// https://developer.android.com/reference/kotlin/androidx/core/widget/RemoteViewsCompat#setRemoteAdapter(android.content.Context,android.widget.RemoteViews,kotlin.Int,kotlin.Int,androidx.core.widget.RemoteViewsCompat.RemoteCollectionItems)
|
|
|
|
|
|
|
|
RemoteViewsCompat.setRemoteAdapter(context, views, appWidgetId, R.id.lv, builder.build());
|
|
|
|
|
|
|
|
|
|
|
|
Intent thread = new Intent(context, ActivityView.class);
|
|
|
|
Intent thread = new Intent(context, ActivityView.class);
|
|
|
|
thread.setPackage(BuildConfig.APPLICATION_ID);
|
|
|
|
thread.setPackage(BuildConfig.APPLICATION_ID);
|
|
|
|
@ -196,17 +204,31 @@ public class WidgetUnified extends AppWidgetProvider {
|
|
|
|
int dp6 = Helper.dp2pixels(context, 6);
|
|
|
|
int dp6 = Helper.dp2pixels(context, 6);
|
|
|
|
views.setViewPadding(R.id.content, dp6, 0, dp6, 0);
|
|
|
|
views.setViewPadding(R.id.content, dp6, 0, dp6, 0);
|
|
|
|
|
|
|
|
|
|
|
|
appWidgetManager.updateAppWidget(appWidgetId, views);
|
|
|
|
return views;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RunnableEx update = new RunnableEx("widget") {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
|
|
|
|
|
|
executor.submit(new RunnableEx("widget") {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void delegate() {
|
|
|
|
|
|
|
|
for (int appWidgetId : appWidgetIds) {
|
|
|
|
|
|
|
|
Intent service = new Intent(context, WidgetUnifiedService.class);
|
|
|
|
|
|
|
|
service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
|
|
|
|
|
|
|
service.setData(Uri.parse(service.toUri(Intent.URI_INTENT_SCHEME)));
|
|
|
|
|
|
|
|
WidgetUnifiedRemoteViewsFactory factory = new WidgetUnifiedRemoteViewsFactory(context.getApplicationContext(), service);
|
|
|
|
|
|
|
|
factory.onDataSetChanged();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationEx.getMainHandler().post(new RunnableEx("widget:" + appWidgetId) {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void delegate() {
|
|
|
|
protected void delegate() {
|
|
|
|
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv);
|
|
|
|
RemoteViews views = getRemoteViews(context, appWidgetId, factory);
|
|
|
|
|
|
|
|
appWidgetManager.updateAppWidget(appWidgetId, views);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ApplicationEx.getMainHandler().removeCallbacks(update);
|
|
|
|
|
|
|
|
ApplicationEx.getMainHandler().postDelayed(update, 1000L);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@ -278,7 +300,8 @@ public class WidgetUnified extends AppWidgetProvider {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetUnified.class));
|
|
|
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetUnified.class));
|
|
|
|
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv);
|
|
|
|
for (int appWidgetId : appWidgetIds)
|
|
|
|
|
|
|
|
init(context, appWidgetId);
|
|
|
|
EntityLog.log(context, "Updated widget data count=" + appWidgetIds.length);
|
|
|
|
EntityLog.log(context, "Updated widget data count=" + appWidgetIds.length);
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
Log.e(ex);
|
|
|
|
|