List of usage examples for android.widget RemoteViews setProgressBar
public void setProgressBar(int viewId, int max, int progress, boolean indeterminate)
From source file:com.sonetel.service.Downloader.java
@Override protected void onHandleIntent(Intent intent) { HttpGet getMethod = new HttpGet(intent.getData().toString()); int result = Activity.RESULT_CANCELED; String outPath = intent.getStringExtra(EXTRA_OUTPATH); boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false); int icon = intent.getIntExtra(EXTRA_ICON, 0); String title = intent.getStringExtra(EXTRA_TITLE); boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title)); // Build notification Builder nb = new NotificationCompat.Builder(this); nb.setWhen(System.currentTimeMillis()); nb.setContentTitle(title);//w ww .j a v a 2s . c om nb.setSmallIcon(android.R.drawable.stat_sys_download); nb.setOngoing(true); Intent i = new Intent(this, SipHome.class); nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.download_notif); contentView.setImageViewResource(R.id.status_icon, icon); contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text)); contentView.setProgressBar(R.id.status_progress, 50, 0, false); contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE); nb.setContent(contentView); final Notification notification = showNotif ? nb.getNotification() : null; notification.contentView = contentView; if (!TextUtils.isEmpty(outPath)) { try { File output = new File(outPath); if (output.exists()) { output.delete(); } if (notification != null) { notificationManager.notify(NOTIF_DOWNLOAD, notification); } ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() { private int oldState = 0; @Override public void run(long progress, long total) { //Log.d(THIS_FILE, "Progress is "+progress+" on "+total); int newState = (int) Math.round(progress * 50.0f / total); if (oldState != newState) { notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false); notificationManager.notify(NOTIF_DOWNLOAD, notification); oldState = newState; } } }); boolean hasReply = client.execute(getMethod, responseHandler); if (hasReply) { if (checkMd5) { URL url = new URL(intent.getData().toString().concat(".md5sum")); InputStream content = (InputStream) url.getContent(); if (content != null) { BufferedReader br = new BufferedReader(new InputStreamReader(content)); String downloadedMD5 = ""; try { downloadedMD5 = br.readLine().split(" ")[0]; } catch (NullPointerException e) { throw new IOException("md5_verification : no sum on server"); } if (!MD5.checkMD5(downloadedMD5, output)) { throw new IOException("md5_verification : incorrect"); } } } PendingIntent pendingIntent = (PendingIntent) intent .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT); try { Runtime.getRuntime().exec("chmod 644 " + outPath); } catch (IOException e) { Log.e(THIS_FILE, "Unable to make the apk file readable", e); } Log.d(THIS_FILE, "Download finished of : " + outPath); if (pendingIntent != null) { notification.contentIntent = pendingIntent; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.icon = android.R.drawable.stat_sys_download_done; notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE); notification.contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.done) // TODO should be a parameter of this class + " - Click to install"); notificationManager.notify(NOTIF_DOWNLOAD, notification); /* try { pendingIntent.send(); notificationManager.cancel(NOTIF_DOWNLOAD); } catch (CanceledException e) { Log.e(THIS_FILE, "Impossible to start pending intent for download finish"); } */ } else { Log.w(THIS_FILE, "Invalid pending intent for finish !!!"); } result = Activity.RESULT_OK; } } catch (IOException e) { Log.e(THIS_FILE, "Exception in download", e); } } if (result == Activity.RESULT_CANCELED) { notificationManager.cancel(NOTIF_DOWNLOAD); } }
From source file:org.kei.android.phone.cellhistory.CellHistoryApp.java
private RemoteViews getRecorderRemoteViews(final long records, final String size, final int buffer, final int max) { final RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_recorder); contentView.setImageViewResource(R.id.imagenotileft, R.drawable.ic_launcher_green); contentView.setTextViewText(R.id.title, getString(R.string.app_name)); contentView.setTextViewText(R.id.textBuffer, "Buffer: "); contentView.setTextViewText(R.id.textPackets, "Records: " + records); contentView.setTextViewText(R.id.textSize, "Size: " + size); contentView.setProgressBar(R.id.pbBuffer, max, buffer, false); return contentView; }
From source file:cm.aptoide.pt.DownloadQueueService.java
private void setNotification(int apkidHash, int progress) { String apkid = notifications.get(apkidHash).get("apkid"); int size = Integer.parseInt(notifications.get(apkidHash).get("intSize")); String version = notifications.get(apkidHash).get("version"); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification); contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification); contentView.setTextViewText(R.id.download_notification_name, getString(R.string.download_alrt) + " " + apkid + " v." + version); contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, progress, false);// ww w. j a v a 2 s . c o m Intent onClick = new Intent(); onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt"); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.setAction("cm.aptoide.pt.FROM_NOTIFICATION"); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0); Notification notification = new Notification(R.drawable.ic_notification, getString(R.string.download_alrt) + " " + apkid, System.currentTimeMillis()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; notification.contentView = contentView; // Set the info for the notification panel. notification.contentIntent = onClickAction; // notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Send the notification. // We use the position because it is a unique number. We use it later to cancel. notificationManager.notify(apkidHash, notification); // Log.d("Aptoide-DownloadQueueService", "Notification Set"); }
From source file:cm.aptoide.pt.DownloadQueueService.java
private void setFinishedNotification(int apkidHash, String localPath) { String apkid = notifications.get(apkidHash).get("apkid"); int size = Integer.parseInt(notifications.get(apkidHash).get("intSize")); String version = notifications.get(apkidHash).get("version"); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification); contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification); contentView.setTextViewText(R.id.download_notification_name, getString(R.string.finished_download_message) + " " + apkid + " v." + version); contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, size * KBYTES_TO_BYTES, false); Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid)); onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab"); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.putExtra("localPath", localPath); onClick.putExtra("apkid", apkid); onClick.putExtra("apkidHash", apkidHash); onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate"))); /*Changed by Rafael Campos*/ onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version")); Log.d("Aptoide-DownloadQueuService", "finished notification apkidHash: " + apkidHash + " localPath: " + localPath); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0); Notification notification = new Notification(R.drawable.ic_notification, getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.contentView = contentView; // Set the info for the notification panel. notification.contentIntent = onClickAction; // notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Send the notification. // We use the position because it is a unique number. We use it later to cancel. notificationManager.notify(apkidHash, notification); // Log.d("Aptoide-DownloadQueueService", "Notification Set"); }
From source file:org.alfresco.mobile.android.platform.AlfrescoNotificationManager.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public int createNotification(int notificationId, Bundle params) { Notification notification;/*from w w w . ja v a2 s .co m*/ // Get the builder to create notification. NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext.getApplicationContext()); builder.setContentTitle(params.getString(ARGUMENT_TITLE)); if (params.containsKey(ARGUMENT_DESCRIPTION)) { builder.setContentText(params.getString(ARGUMENT_DESCRIPTION)); } builder.setNumber(0); if (AndroidVersion.isLollipopOrAbove()) { builder.setSmallIcon(R.drawable.ic_notification); builder.setColor(appContext.getResources().getColor(R.color.alfresco_sky)); } else { builder.setSmallIcon(R.drawable.ic_notification); } if (params.containsKey(ARGUMENT_DESCRIPTION)) { builder.setContentText(params.getString(ARGUMENT_DESCRIPTION)); } if (params.containsKey(ARGUMENT_CONTENT_INFO)) { builder.setContentInfo(params.getString(ARGUMENT_CONTENT_INFO)); } if (params.containsKey(ARGUMENT_SMALL_ICON)) { builder.setSmallIcon(params.getInt(ARGUMENT_SMALL_ICON)); } Intent i; PendingIntent pIntent; switch (notificationId) { case CHANNEL_SYNC: i = new Intent(PrivateIntent.ACTION_SYNCHRO_DISPLAY); pIntent = PendingIntent.getActivity(appContext, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); break; default: i = new Intent(PrivateIntent.ACTION_DISPLAY_OPERATIONS); i.putExtra(PrivateIntent.EXTRA_OPERATIONS_TYPE, notificationId); if (SessionUtils.getAccount(appContext) != null) { i.putExtra(PrivateIntent.EXTRA_ACCOUNT_ID, SessionUtils.getAccount(appContext).getId()); } pIntent = PendingIntent.getActivity(appContext, 0, i, 0); break; } builder.setContentIntent(pIntent); if (AndroidVersion.isICSOrAbove()) { if (params.containsKey(ARGUMENT_PROGRESS_MAX) && params.containsKey(ARGUMENT_PROGRESS)) { long max = params.getLong(ARGUMENT_PROGRESS_MAX); long progress = params.getLong(ARGUMENT_PROGRESS); float value = (((float) progress / ((float) max)) * 100); int percentage = Math.round(value); builder.setProgress(100, percentage, false); } if (params.getBoolean(ARGUMENT_INDETERMINATE)) { builder.setProgress(0, 0, true); } } else { RemoteViews remote = new RemoteViews(appContext.getPackageName(), R.layout.app_notification); remote.setImageViewResource(R.id.status_icon, R.drawable.ic_application_logo); remote.setTextViewText(R.id.status_text, params.getString(ARGUMENT_TITLE)); remote.setProgressBar(R.id.status_progress, params.getInt(ARGUMENT_PROGRESS_MAX), 0, false); builder.setContent(remote); } if (AndroidVersion.isJBOrAbove()) { builder.setPriority(0); notification = builder.build(); } else { notification = builder.getNotification(); } notification.flags |= Notification.FLAG_AUTO_CANCEL; ((NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE)).notify(notificationId, notification); return notificationId; }
From source file:com.chainsaw.clearweather.OpenWeatherAPI.java
public OpenWeatherAPI(final Context context, final int widgetId) { final RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.widget_layout); final AppWidgetManager manager = AppWidgetManager.getInstance(context); asyncLoader = new BackgroundFetch(context) { @Override//from www . ja v a2 s . c om protected void onPostExecute(WeatherData result) { remote.setViewVisibility(R.id.loading, View.INVISIBLE); if (OpenWeatherAPI.this.listener != null) OpenWeatherAPI.this.listener.onDataReady(result); } @Override protected void onProgressUpdate(Integer... values) { remote.setViewVisibility(R.id.temp, View.INVISIBLE); remote.setViewVisibility(R.id.tempUnit, View.INVISIBLE); remote.setViewVisibility(R.id.humidity, View.INVISIBLE); remote.setViewVisibility(R.id.humidityUnit, View.INVISIBLE); remote.setViewVisibility(R.id.location, View.INVISIBLE); remote.setViewVisibility(R.id.weather, View.INVISIBLE); remote.setViewVisibility(R.id.timestamp, View.INVISIBLE); remote.setViewVisibility(R.id.loading, View.VISIBLE); remote.setProgressBar(R.id.loading, 10, 5, true); manager.updateAppWidget(widgetId, remote); super.onProgressUpdate(values); } }; }
From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java
/** * Equation for all of the Nutrition and Meal information *//*from www .j av a2 s.c o m*/ private void equations() { double mCalorieGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_CALORIES_TO_REACH_GOAL, "")); double mFatGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_FAT, "")); double mCarbGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_CARBOHYDRATES, "")); double mProteinGoal = Double.valueOf(sharedPreferences.getString(Globals.USER_DAILY_PROTEIN, "")); mCalorieGoalMeal = Double.valueOf(sharedPreferences.getString(Globals.USER_CALORIES_TO_REACH_GOAL, "")) / 4; icSnack = (ImageView) v.findViewById(R.id.icSnack); icBreakfast = (ImageView) v.findViewById(R.id.icBreakfast); icLunch = (ImageView) v.findViewById(R.id.icLunch); icDinner = (ImageView) v.findViewById(R.id.icDinner); // _________________________Calories Snack_____________________________ double mCalConsumedSnack = 0; for (LogMeal logMeal : mLogSnackAdapter.getLogs()) { mCalConsumedSnack += logMeal.getCalorieCount(); } mCalSnack.setText(df.format(mCalConsumedSnack)); // Set icon visible and color based on calories consumed for meal. if (mCalConsumedSnack >= mCalorieGoalMeal + 100) { icSnack.setImageResource(R.mipmap.ic_check_circle); icSnack.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY); } else if (mCalConsumedSnack > mCalorieGoalMeal - 100 && mCalConsumedSnack < mCalorieGoalMeal + 99) { icSnack.setImageResource(R.mipmap.ic_check_circle); icSnack.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY); } else { icSnack.setImageResource(R.mipmap.ic_check); icSnack.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY); } // _________________________Calories Breakfast_____________________________ double mCalConsumedBreakfast = 0; for (LogMeal logMeal : mLogBreakfastAdapter.getLogs()) { mCalConsumedBreakfast += logMeal.getCalorieCount(); } mCalBreakfast.setText(df.format(mCalConsumedBreakfast)); // Set icon visible and color based on calories consumed for meal. if (mCalConsumedBreakfast >= mCalorieGoalMeal + 100) { icBreakfast.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY); icBreakfast.setImageResource(R.mipmap.ic_check_circle); } else if (mCalConsumedBreakfast > mCalorieGoalMeal - 100 && mCalConsumedBreakfast < mCalorieGoalMeal + 99) { icBreakfast.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY); icBreakfast.setImageResource(R.mipmap.ic_check_circle); } else { icBreakfast.setImageResource(R.mipmap.ic_check); icBreakfast.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY); } // _________________________Calories Lunch_____________________________ double mCalConsumedLunch = 0; for (LogMeal logMeal : mLogLunchAdapter.getLogs()) { mCalConsumedLunch += logMeal.getCalorieCount(); } mCalLunch.setText(df.format(mCalConsumedLunch)); // Set icon visible and color based on calories consumed for meal. if (mCalConsumedLunch >= mCalorieGoalMeal + 100) { icLunch.setImageResource(R.mipmap.ic_check_circle); icLunch.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY); } else if (mCalConsumedLunch > mCalorieGoalMeal - 100 && mCalConsumedLunch < mCalorieGoalMeal + 99) { icLunch.setImageResource(R.mipmap.ic_check_circle); icLunch.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY); } else { icLunch.setImageResource(R.mipmap.ic_check); icLunch.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY); } // _________________________Calories Lunch_____________________________ double mCalConsumedDinner = 0; for (LogMeal logMeal : mLogDinnerAdapter.getLogs()) { mCalConsumedDinner += logMeal.getCalorieCount(); } mCalDinner.setText(df.format(mCalConsumedDinner)); // Set icon visible and color based on calories consumed for meal. if (mCalConsumedDinner >= mCalorieGoalMeal + 100) { icDinner.setImageResource(R.mipmap.ic_check_circle); icDinner.setColorFilter(Color.parseColor("#F44336"), android.graphics.PorterDuff.Mode.MULTIPLY); } else if (mCalConsumedDinner > mCalorieGoalMeal - 100 && mCalConsumedDinner < mCalorieGoalMeal + 99) { icDinner.setImageResource(R.mipmap.ic_check_circle); icDinner.setColorFilter(Color.parseColor("#4CAF50"), android.graphics.PorterDuff.Mode.MULTIPLY); } else { icDinner.setImageResource(R.mipmap.ic_check); icDinner.setColorFilter(Color.parseColor("#6D6D6D"), android.graphics.PorterDuff.Mode.MULTIPLY); } // _________________________Calories, Fat, Carbs, Protein All_____________________________ // Nutrition Consumed double mAllCaloriesConsumed = 0; double mAllFatConsumed = 0; double mAllCarbsConsumed = 0; double mAllProteinConsumed = 0; for (LogMeal logMeal : mLogAdapterAll.getLogs()) { mAllCaloriesConsumed += logMeal.getCalorieCount(); mAllFatConsumed += logMeal.getFatCount(); mAllCarbsConsumed += logMeal.getCarbCount(); mAllProteinConsumed += logMeal.getProteinCount(); } // Nutrition Goals // Remainder Nutrition mCaloriesRemainder.setText(df.format(mCalorieGoal - mAllCaloriesConsumed) + " Left"); mFatRemainder.setText(df.format(mFatGoal - mAllFatConsumed) + " Left"); mCarbRemainder.setText(df.format(mCarbGoal - mAllCarbsConsumed) + " Left"); mProteinRemainder.setText(df.format(mProteinGoal - mAllProteinConsumed) + " Left"); // Progress bars mPbCalories.setMax(Integer.valueOf(df.format(mCalorieGoal))); mPbCalories.setProgress(Integer.valueOf(df.format(mAllCaloriesConsumed))); mPbFat.setMax(Integer.valueOf(df.format(mFatGoal))); mPbFat.setProgress(Integer.valueOf(df.format(mAllFatConsumed))); mPbCarbs.setMax(Integer.valueOf(df.format(mCarbGoal))); mPbCarbs.setProgress(Integer.valueOf(df.format(mAllCarbsConsumed))); mPbProtein.setMax(Integer.valueOf(df.format(mProteinGoal))); mPbProtein.setProgress(Integer.valueOf(df.format(mAllProteinConsumed))); /** * Update Widget */ Context context = getActivity(); AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); if (appWidgetManager != null) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget); ComponentName thisWidget = new ComponentName(context, FitHealthWidget.class); views.setProgressBar(R.id.pbCal, Integer.valueOf(df.format(mCalorieGoal)), Integer.valueOf(df.format(mAllCaloriesConsumed)), false); views.setProgressBar(R.id.pbFat, Integer.valueOf(df.format(mFatGoal)), Integer.valueOf(df.format(mAllFatConsumed)), false); views.setProgressBar(R.id.pbCarb, Integer.valueOf(df.format(mCarbGoal)), Integer.valueOf(df.format(mAllCarbsConsumed)), false); views.setProgressBar(R.id.pbPro, Integer.valueOf(df.format(mProteinGoal)), Integer.valueOf(df.format(mAllProteinConsumed)), false); views.setTextViewText(R.id.txtRemainderCal, df.format(mCalorieGoal - mAllCaloriesConsumed)); views.setTextViewText(R.id.txtRemainderFat, df.format(mFatGoal - mAllFatConsumed)); views.setTextViewText(R.id.txtRemainderCarb, df.format(mCarbGoal - mAllCarbsConsumed)); views.setTextViewText(R.id.txtRemainderPro, df.format(mProteinGoal - mAllProteinConsumed)); appWidgetManager.updateAppWidget(thisWidget, views); } }
From source file:RhodesService.java
private void updateDownloadNotification(String url, int totalBytes, int currentBytes) { Context context = RhodesActivity.getContext(); Notification n = new Notification(); n.icon = android.R.drawable.stat_sys_download; n.flags |= Notification.FLAG_ONGOING_EVENT; RemoteViews expandedView = new RemoteViews(context.getPackageName(), R.layout.status_bar_ongoing_event_progress_bar); StringBuilder newUrl = new StringBuilder(); if (url.length() < 17) newUrl.append(url);/*from ww w. j av a 2 s . c o m*/ else { newUrl.append(url.substring(0, 7)); newUrl.append("..."); newUrl.append(url.substring(url.length() - 7, url.length())); } expandedView.setTextViewText(R.id.title, newUrl.toString()); StringBuffer downloadingText = new StringBuffer(); if (totalBytes > 0) { long progress = currentBytes * 100 / totalBytes; downloadingText.append(progress); downloadingText.append('%'); } expandedView.setTextViewText(R.id.progress_text, downloadingText.toString()); expandedView.setProgressBar(R.id.progress_bar, totalBytes < 0 ? 100 : totalBytes, currentBytes, totalBytes < 0); n.contentView = expandedView; Intent intent = new Intent(ACTION_ASK_CANCEL_DOWNLOAD); n.contentIntent = PendingIntent.getBroadcast(context, 0, intent, 0); intent = new Intent(ACTION_CANCEL_DOWNLOAD); n.deleteIntent = PendingIntent.getBroadcast(context, 0, intent, 0); mNM.notify(DOWNLOAD_PACKAGE_ID, n); }