Skip to content

Commit

Permalink
Merge pull request #2023 from moneymanagerex/orm
Browse files Browse the repository at this point in the history
Widget: format and clean up
  • Loading branch information
guanlisheng authored Dec 28, 2024
2 parents 9acdc62 + 778e370 commit e39fc31
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
/**
* All Accounts widget
*/
public class AccountBillsWidgetProvider
extends AppWidgetProvider {
public class AccountBillsWidgetProvider extends AppWidgetProvider {

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
Expand All @@ -45,7 +44,7 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager,
MmexApplication app = new MmexApplication();
CurrencyService currencyService = new CurrencyService(context);

for (int i = 0; i < appWidgetIds.length; ++i) {
for (int appWidgetId : appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_account_bills);
remoteViews.setTextViewText(R.id.textViewUserName, app.loadUserNameFromDatabase(context));
remoteViews.setTextViewText(R.id.textViewTotalAccounts, context.getString(R.string.summary) + ": "
Expand All @@ -59,19 +58,19 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager,
Intent intentRefresh = new Intent(context, AccountBillsWidgetProvider.class);
intentRefresh.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intentRefresh.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingRefresh = PendingIntent.getBroadcast(context, 0, intentRefresh, PendingIntent.FLAG_UPDATE_CURRENT|PendingIntent.FLAG_IMMUTABLE);
PendingIntent pendingRefresh = PendingIntent.getBroadcast(context, 0, intentRefresh, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
remoteViews.setOnClickPendingIntent(R.id.imageButtonRefresh, pendingRefresh);

//service
Intent svcIntent = new Intent(context, AccountBillsWidgetService.class);

svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
remoteViews.setRemoteAdapter(R.id.listViewAccountBills, svcIntent);

// update widget
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i], R.id.listViewAccountBills);
appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.listViewAccountBills);
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import android.content.Intent;
import android.widget.RemoteViewsService;

public class AccountBillsWidgetService
extends RemoteViewsService {
public class AccountBillsWidgetService extends RemoteViewsService {

@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@

public class ButtonAddTransactionWidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {

for (int i = 0; i < appWidgetIds.length; ++i) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_button_add_transaction);
// register on click in icon launch application
Intent intent = new Intent(context, CheckingTransactionEditActivity.class);
intent.setAction(Intent.ACTION_INSERT);
intent.putExtra(EditTransactionActivityConstants.KEY_TRANS_SOURCE, "ButtonAddTransactionWidgetProvider.java");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
remoteViews.setOnClickPendingIntent(R.id.buttonNewOperation, pendingIntent);

// update widget
appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews);
}
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

for (int appWidgetId : appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_button_add_transaction);
// register on click in icon launch application
Intent intent = new Intent(context, CheckingTransactionEditActivity.class);
intent.setAction(Intent.ACTION_INSERT);
intent.putExtra(EditTransactionActivityConstants.KEY_TRANS_SOURCE, "ButtonAddTransactionWidgetProvider.java");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
remoteViews.setOnClickPendingIntent(R.id.buttonNewOperation, pendingIntent);

// update widget
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,8 @@
* Implementation of App Widget functionality.
* App Widget Configuration implemented in {@link SingleAccountWidgetConfigureActivity SingleAccountWidgetConfigureActivity}
*/
public class SingleAccountWidget
extends AppWidgetProvider {

public class SingleAccountWidget extends AppWidgetProvider {
// Static

/**
* Returns number of cells needed for given size of the widget.
*
Expand All @@ -64,7 +61,6 @@ private static long getCellsForSize(long size) {
}

// Dynamic

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;

import com.money.manager.ex.currency.CurrencyService;
Expand All @@ -31,6 +30,7 @@
import com.money.manager.ex.R;

import info.javaperformance.money.MoneyFactory;
import timber.log.Timber;

public class SummaryWidgetProvider
extends AppWidgetProvider {
Expand All @@ -45,7 +45,7 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager,

int[] allWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, SummaryWidgetProvider.class));

for (int i = 0; i < allWidgetIds.length; ++i) {
for (int allWidgetId : allWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_summary);
remoteViews.setTextViewText(R.id.textViewUserName, app.loadUserNameFromDatabase(context));
remoteViews.setTextViewText(R.id.textViewTotalAccounts, context.getString(R.string.summary) + ": "
Expand All @@ -59,14 +59,14 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager,
Intent intentRefresh = new Intent(context, SummaryWidgetProvider.class);
intentRefresh.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intentRefresh.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingRefresh = PendingIntent.getBroadcast(context, 0, intentRefresh, PendingIntent.FLAG_UPDATE_CURRENT|PendingIntent.FLAG_IMMUTABLE);
PendingIntent pendingRefresh = PendingIntent.getBroadcast(context, 0, intentRefresh, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
remoteViews.setOnClickPendingIntent(R.id.imageButtonRefresh, pendingRefresh);

// update widget
try {
appWidgetManager.updateAppWidget(allWidgetIds[i], remoteViews);
appWidgetManager.updateAppWidget(allWidgetId, remoteViews);
} catch (Exception e) {
Log.e(SummaryWidgetProvider.class.getSimpleName(), e.getMessage());
Timber.tag(SummaryWidgetProvider.class.getSimpleName()).e(e);
}
}
}
Expand Down

0 comments on commit e39fc31

Please sign in to comment.