public static void updateWidgets( final Context context, @Nonnull final AppWidgetManager appWidgetManager, @Nonnull final int[] appWidgetIds, @Nonnull final BigInteger balance) { final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context)); final Spannable balanceStr = new SpannableString( GenericUtils.formatValue(balance, config.getBtcPrecision(), config.getBtcShift())); WalletUtils.formatSignificant(balanceStr, WalletUtils.SMALLER_SPAN); for (final int appWidgetId : appWidgetIds) { final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.wallet_balance_widget_content); views.setTextViewText(R.id.widget_wallet_prefix, config.getBtcPrefix()); views.setTextViewText(R.id.widget_wallet_balance, balanceStr); views.setOnClickPendingIntent( R.id.widget_button_balance, PendingIntent.getActivity(context, 0, new Intent(context, WalletActivity.class), 0)); views.setOnClickPendingIntent( R.id.widget_button_request, PendingIntent.getActivity( context, 0, new Intent(context, RequestCoinsActivity.class), 0)); views.setOnClickPendingIntent( R.id.widget_button_send, PendingIntent.getActivity(context, 0, new Intent(context, SendCoinsActivity.class), 0)); views.setOnClickPendingIntent( R.id.widget_button_send_qr, PendingIntent.getActivity(context, 0, new Intent(context, SendCoinsQrActivity.class), 0)); appWidgetManager.updateAppWidget(appWidgetId, views); } }
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); adapter = new ExchangeRatesAdapter(activity); setListAdapter(adapter); loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks); defaultCurrency = config.getExchangeCurrencyCode(); config.registerOnSharedPreferenceChangeListener(this); }
@Override public void onDestroy() { config.unregisterOnSharedPreferenceChangeListener(this); loaderManager.destroyLoader(ID_RATE_LOADER); super.onDestroy(); }
@Override public void onSharedPreferenceChanged( final SharedPreferences sharedPreferences, final String key) { if (Configuration.PREFS_KEY_EXCHANGE_CURRENCY.equals(key) || Configuration.PREFS_KEY_BTC_PRECISION.equals(key)) { defaultCurrency = config.getExchangeCurrencyCode(); updateView(); } }
private void updateView() { balance = application.getWallet().getBalance(BalanceType.ESTIMATED); if (adapter != null) { final int btcShift = config.getBtcShift(); final BigInteger base = btcShift == 0 ? GenericUtils.ONE_BTC : GenericUtils.ONE_MBTC; adapter.setRateBase(base); } }