List of usage examples for android.appwidget AppWidgetManager getInstance
public static AppWidgetManager getInstance(Context context)
From source file:com.feathercoin.wallet.feathercoin.service.BlockchainServiceImpl.java
public void notifyWidgets() { final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class); final int[] appWidgetIds; try {/* w w w .j av a2s.co m*/ appWidgetIds = appWidgetManager.getAppWidgetIds(providerName); } catch (RuntimeException e) { // Bug #6 - App server dead? Log.e("Feathercoin", "App server appears dead - Runtime Exception when running getAppWidgetIds. Returning.."); return; } if (appWidgetIds.length > 0) { final Wallet wallet = application.getWallet(); final BigInteger balance = wallet.getBalance(BalanceType.ESTIMATED); WalletBalanceWidgetProvider.updateWidgets(this, appWidgetManager, appWidgetIds, balance); } }
From source file:de.schildbach.wallet.digitalcoin.service.BlockchainServiceImpl.java
public void notifyWidgets() { final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class); final int[] appWidgetIds; try {//www .ja va 2s . c om appWidgetIds = appWidgetManager.getAppWidgetIds(providerName); } catch (RuntimeException e) { // Bug #6 - App server dead? Log.e("digitalcoin", "App server appears dead - Runtime Exception when running getAppWidgetIds. Returning.."); return; } if (appWidgetIds.length > 0) { final Wallet wallet = application.getWallet(); final BigInteger balance = wallet.getBalance(BalanceType.ESTIMATED); WalletBalanceWidgetProvider.updateWidgets(this, appWidgetManager, appWidgetIds, balance); } }
From source file:de.schildbach.wallet.goldcoin.service.BlockchainServiceImpl.java
public void notifyWidgets() { final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class); final int[] appWidgetIds; try {/*w w w . ja va 2 s. co m*/ appWidgetIds = appWidgetManager.getAppWidgetIds(providerName); } catch (RuntimeException e) { // Bug #6 - App server dead? Log.e("Litecoin", "App server appears dead - Runtime Exception when running getAppWidgetIds. Returning.."); return; } if (appWidgetIds.length > 0) { final Wallet wallet = application.getWallet(); final BigInteger balance = wallet.getBalance(BalanceType.ESTIMATED); WalletBalanceWidgetProvider.updateWidgets(this, appWidgetManager, appWidgetIds, balance); } }
From source file:de.schildbach.wallet.marscoin.service.BlockchainServiceImpl.java
public void notifyWidgets() { final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class); final int[] appWidgetIds; try {//from w w w . j a v a 2 s.c o m appWidgetIds = appWidgetManager.getAppWidgetIds(providerName); } catch (RuntimeException e) { // Bug #6 - App server dead? Log.e("marscoin", "App server appears dead - Runtime Exception when running getAppWidgetIds. Returning.."); return; } if (appWidgetIds.length > 0) { final Wallet wallet = application.getWallet(); final BigInteger balance = wallet.getBalance(BalanceType.ESTIMATED); WalletBalanceWidgetProvider.updateWidgets(this, appWidgetManager, appWidgetIds, balance); } }
From source file:de.schildbach.wallet.elysium.service.BlockchainServiceImpl.java
public void notifyWidgets() { final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); final ComponentName providerName = new ComponentName(this, WalletBalanceWidgetProvider.class); final int[] appWidgetIds; try {/*from w ww . ja v a2 s . c o m*/ appWidgetIds = appWidgetManager.getAppWidgetIds(providerName); } catch (RuntimeException e) { // Bug #6 - App server dead? Log.e("Elysium", "App server appears dead - Runtime Exception when running getAppWidgetIds. Returning.."); return; } if (appWidgetIds.length > 0) { final Wallet wallet = application.getWallet(); final BigInteger balance = wallet.getBalance(BalanceType.ESTIMATED); WalletBalanceWidgetProvider.updateWidgets(this, appWidgetManager, appWidgetIds, balance); } }
From source file:com.piusvelte.sonet.core.SonetService.java
protected void putValidatedUpdates(int[] appWidgetIds, int reload) { int[] awi = Sonet.getWidgets(getApplicationContext(), AppWidgetManager.getInstance(getApplicationContext())); if ((appWidgetIds != null) && (appWidgetIds.length > 0)) { // check for phantom widgets for (int appWidgetId : appWidgetIds) { // About.java will send an invalid appwidget id if ((appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) || Sonet.arrayContains(awi, appWidgetId)) { putNewUpdate(appWidgetId, reload); } else { // remove phantom widgets getContentResolver().delete(Widgets.getContentUri(SonetService.this), Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); getContentResolver().delete(Widget_accounts.getContentUri(SonetService.this), Widget_accounts.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); getContentResolver().delete(Statuses.getContentUri(SonetService.this), Statuses.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); }//from www.j a v a 2 s. c om } } else if ((awi != null) && (awi.length > 0)) { for (int appWidgetId : awi) { putNewUpdate(appWidgetId, reload); } } }
From source file:com.shafiq.myfeedle.core.MyfeedleService.java
protected void putValidatedUpdates(int[] appWidgetIds, int reload) { int[] awi = Myfeedle.getWidgets(getApplicationContext(), AppWidgetManager.getInstance(getApplicationContext())); if ((appWidgetIds != null) && (appWidgetIds.length > 0)) { // check for phantom widgets for (int appWidgetId : appWidgetIds) { // About.java will send an invalid appwidget id if ((appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) || Myfeedle.arrayContains(awi, appWidgetId)) { putNewUpdate(appWidgetId, reload); } else { // remove phantom widgets getContentResolver().delete(Widgets.getContentUri(MyfeedleService.this), Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); getContentResolver().delete(Widget_accounts.getContentUri(MyfeedleService.this), Widget_accounts.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); getContentResolver().delete(Statuses.getContentUri(MyfeedleService.this), Statuses.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); }// w w w . j a v a 2s .c o m } } else if ((awi != null) && (awi.length > 0)) { for (int appWidgetId : awi) { putNewUpdate(appWidgetId, reload); } } }
From source file:com.xperia64.timidityae.MusicService.java
@Override public void onCreate() { super.onCreate(); if (serviceReceiver != null) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(getResources().getString(R.string.msrv_rec)); intentFilter.addAction(Intent.ACTION_HEADSET_PLUG); intentFilter.addAction(Intent.ACTION_MEDIA_BUTTON); registerReceiver(serviceReceiver, intentFilter); }// ww w. j av a 2 s . c o m pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Timidity AE"); wl.setReferenceCounted(false); if (shouldDoWidget) ids = AppWidgetManager.getInstance(getApplication()) .getAppWidgetIds(new ComponentName(getApplication(), TimidityAEWidgetProvider.class)); TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (mgr != null) { mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } //foreground=false; if (wl.isHeld()) wl.release(); stopForeground(true); }
From source file:info.corne.performancetool.MainActivity.java
@Override public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { String selectedProfile = (String) profilesAdapter.getItem(pos); dialog = ProgressDialog.show(this, getResources().getString(R.string.please_wait), getResources().getString(R.string.being_saved)); SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); RemoteViews rv = new RemoteViews(getApplicationContext().getPackageName(), R.layout.widget_layout); if (pos == 0) { DefaultSettings settings = new DefaultSettings(); String[] files = settings.getFileNames(); String[] values = settings.getValues(); SetHardwareInfoTask task = new SetHardwareInfoTask(files, values, dialog, true); task.addListener(this); task.execute();/*from ww w . j a v a2s. c om*/ rv.setImageViewResource(R.id.widgetButton, R.drawable.widget_default); } else if (pos == 1) { PowerSettings settings = new PowerSettings(); String[] files = settings.getFileNames(); String[] values = settings.getValues(); SetHardwareInfoTask task = new SetHardwareInfoTask(files, values, dialog, true); task.addListener(this); task.execute(); rv.setImageViewResource(R.id.widgetButton, R.drawable.widget_power); } else if (pos == 2) { AudioSettings settings = new AudioSettings(); String[] files = settings.getFileNames(); String[] values = settings.getValues(); SetHardwareInfoTask task = new SetHardwareInfoTask(files, values, dialog, true); task.addListener(this); task.execute(); rv.setImageViewResource(R.id.widgetButton, R.drawable.widget_audio); } else { ProfileSettings settings = new ProfileSettings(selectedProfile, sharedPreferences); String[] files = settings.getFileNames(); String[] values = settings.getValues(); SetHardwareInfoTask task = new SetHardwareInfoTask(files, values, dialog, true); task.addListener(this); task.execute(); rv.setImageViewResource(R.id.widgetButton, R.drawable.widget_default); } Editor editor = sharedPreferences.edit(); editor.putInt(Settings.CURRENT_WIDGET_PROFILE, pos); editor.commit(); ComponentName cn = new ComponentName(getApplicationContext(), WidgetReceiver.class); (AppWidgetManager.getInstance(getApplicationContext())).updateAppWidget(cn, rv); }
From source file:com.xperia64.timidityae.MusicService.java
@SuppressLint("NewApi") public void play() { if (playList != null && currSongNumber >= 0) { shouldAdvance = false;//ww w . ja v a 2 s.c o m death = true; fullStop = false; stop(); death = false; Globals.shouldRestore = true; while (!death && ((Globals.isPlaying == 0 || JNIHandler.alternativeCheck == 333333))) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } if (!death) { MediaMetadataRetriever mmr = new MediaMetadataRetriever(); String tmpTitle; Globals.currArt = null; final int songIndex; if (shuffleMode == 1) { songIndex = realSongNumber = shuffledIndices.get(currSongNumber); } else { songIndex = realSongNumber = currSongNumber; } try { mmr.setDataSource(playList.get(songIndex)); tmpTitle = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); if (tmpTitle != null) { if (TextUtils.isEmpty(tmpTitle)) tmpTitle = playList.get(songIndex) .substring(playList.get(songIndex).lastIndexOf('/') + 1); } else { tmpTitle = playList.get(songIndex).substring(playList.get(songIndex).lastIndexOf('/') + 1); } } catch (RuntimeException e) { tmpTitle = playList.get(songIndex).substring(playList.get(songIndex).lastIndexOf('/') + 1); } boolean goodart = false; if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) // Please work { try { byte[] art = mmr.getEmbeddedPicture(); if (art != null) { Globals.currArt = BitmapFactory.decodeByteArray(art, 0, art.length); goodart = Globals.currArt != null; } } catch (Exception e) { } } if (!goodart) { String goodPath = playList.get(songIndex).substring(0, playList.get(songIndex).lastIndexOf('/') + 1) + "folder.jpg"; if (new File(goodPath).exists()) { try { Globals.currArt = BitmapFactory.decodeFile(goodPath); } catch (RuntimeException e) { } } else { // Try albumart.jpg goodPath = playList.get(songIndex).substring(0, playList.get(songIndex).lastIndexOf('/') + 1) + "AlbumArt.jpg"; if (new File(goodPath).exists()) { try { Globals.currArt = BitmapFactory.decodeFile(goodPath); } catch (RuntimeException e) { // } } } } if (shouldDoWidget) { Intent intent = new Intent(this, TimidityAEWidgetProvider.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID, // since it seems the onUpdate() is only fired on that: ids = AppWidgetManager.getInstance(getApplication()) .getAppWidgetIds(new ComponentName(getApplication(), TimidityAEWidgetProvider.class)); //intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.onlyart", true); sendBroadcast(intent); } Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.ta_rec)); new_intent.putExtra(getResources().getString(R.string.ta_cmd), 6); sendBroadcast(new_intent); currTitle = tmpTitle; shouldAdvance = true; paused = false; final int x = JNIHandler.play(playList.get(songIndex)); if (x != 0) { switch (x) { case -1: handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getResources().getString(R.string.srv_fnf), Toast.LENGTH_SHORT).show(); } }); break; case -3: handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), "Error initializing AudioTrack. Try decreasing the buffer size.", Toast.LENGTH_LONG).show(); } }); break; case -9: handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getResources().getString(R.string.srv_loading), Toast.LENGTH_SHORT).show(); } }); break; default: handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), String.format(getResources().getString(R.string.srv_unk), x), Toast.LENGTH_SHORT).show(); } }); break; } Globals.isPlaying = 1; JNIHandler.type = true; shouldAdvance = false; JNIHandler.paused = false; stop(); } else { updateNotification(currTitle, paused); new Thread(new Runnable() { public void run() { while (!death && ((Globals.isPlaying == 1 && shouldAdvance))) { if (JNIHandler.alternativeCheck == 555555) death = true; //System.out.println(String.format("alt check: %d death: %s isplaying: %d shouldAdvance: %s seekBarReady: %s",JNIHandler.alternativeCheck,death?"true":"false",Globals.isPlaying,shouldAdvance?"true":"false",JNIHandler.seekbarReady?"true":"false")); try { Thread.sleep(10); } catch (InterruptedException e) { } } if (!death) { Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.ta_rec)); new_intent.putExtra(getResources().getString(R.string.ta_cmd), 0); new_intent.putExtra(getResources().getString(R.string.ta_startt), JNIHandler.maxTime); new_intent.putExtra(getResources().getString(R.string.ta_songttl), currTitle); new_intent.putExtra(getResources().getString(R.string.ta_filename), playList.get(songIndex)); new_intent.putExtra("stupidNumber", songIndex); sendBroadcast(new_intent); } if (new File(playList.get(songIndex) + ".def.tcf").exists() || new File(playList.get(songIndex) + ".def.tzf").exists()) { String suffix; if (new File(playList.get(songIndex) + ".def.tcf").exists() && new File(playList.get(songIndex) + ".def.tzf").exists()) { suffix = (Globals.compressCfg ? ".def.tzf" : ".def.tcf"); } else if (new File(playList.get(songIndex) + ".def.tcf").exists()) { suffix = ".def.tcf"; } else { suffix = ".def.tzf"; } JNIHandler.shouldPlayNow = false; JNIHandler.currTime = 0; while (Globals.isPlaying == 0 && !death && shouldAdvance && !JNIHandler.dataWritten) { try { Thread.sleep(25); } catch (InterruptedException e) { e.printStackTrace(); } } Intent new_intent = new Intent(); // silly, but should be done async. I think. new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 17); new_intent.putExtra(getResources().getString(R.string.msrv_infile), playList.get(songIndex) + suffix); new_intent.putExtra(getResources().getString(R.string.msrv_reset), true); sendBroadcast(new_intent); } while (!death && (((Globals.isPlaying == 0 || JNIHandler.alternativeCheck == 333333) && shouldAdvance))) { try { Thread.sleep(25); } catch (InterruptedException e) { } } if (shouldAdvance && !death) { shouldAdvance = false; new Thread(new Runnable() { public void run() { if (playList.size() > 1 && (((songIndex + 1 < playList.size() && loopMode == 0)) || loopMode == 1)) { next(); } else if (loopMode == 2 || playList.size() == 1) { play(); } else if (loopMode == 0) { Globals.hardStop = true; Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.ta_rec)); new_intent.putExtra(getResources().getString(R.string.ta_cmd), 5); new_intent.putExtra(getResources().getString(R.string.ta_pause), false); sendBroadcast(new_intent); } } }).start(); } } }).start(); } } } }