本文整理汇总了Java中android.widget.RemoteViews.setProgressBar方法的典型用法代码示例。如果您正苦于以下问题:Java RemoteViews.setProgressBar方法的具体用法?Java RemoteViews.setProgressBar怎么用?Java RemoteViews.setProgressBar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.RemoteViews
的用法示例。
在下文中一共展示了RemoteViews.setProgressBar方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notifyDownloadStart
import android.widget.RemoteViews; //导入方法依赖的package包/类
/**
* 开始下载
*
* @param context
* @param title
* @param icon
*/
private void notifyDownloadStart(Context context, Request request)
{
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.api_download_notification);
remoteViews.setProgressBar(R.id.noti_progressBar, PROGRESSBAR_MAX, 0, false);
remoteViews.setImageViewResource(R.id.noti_icon, R.drawable.notification_remote_icon);
remoteViews.setTextViewText(R.id.noti_file_name, request.mTitle);
String host = CommonUtils.getHost(request.mDownloadUrl);
if (CommonUtils.isWo2bHost(request.mDownloadUrl))
{
remoteViews.setTextViewText(R.id.noti_progressBarLeft, "www.wo2b.com");
}
else
{
remoteViews.setTextViewText(R.id.noti_progressBarLeft, host);
}
// 执行取消操作的PendingIntent, 向DownloadService发起取消下载的命令
Intent cancelIntent = new Intent();
cancelIntent.setClass(context, DownloadService.class);
cancelIntent.putExtra(DownloadService.EXTRA_EVENT_TYPE, DownloadService.EVENT_CANCEL);
cancelIntent.putExtra(DownloadService.EXTRA_DOWNLOAD_URL, request.mDownloadUrl);
PendingIntent cancelPendingIntent = PendingIntent.getService(context, 100, cancelIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.noti_cancel, cancelPendingIntent);
// 消息信息设置
Notification notification = new Notification();
notification.tickerText = request.mTitle;
notification.icon = R.drawable.notification_icon;
notification.contentView = remoteViews;
// notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.flags = Notification.FLAG_ONGOING_EVENT;
// 点击通知栏
Intent intent = new Intent();
intent.setAction("com.wo2b.download.AActivity");
// intent.setClass(context, Download.class);
notification.contentIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT);
// 生成通知ID
int notificationId = new Random().nextInt(10000);
mNotificationManager.notify(notificationId, notification);
request.mNotification = notification;
request.mNotificationId = notificationId;
}
示例2: handleProcess
import android.widget.RemoteViews; //导入方法依赖的package包/类
@Override
public void handleProcess(long range, long size, String videoId) {
if (stop) {
return;
}
int p = (int) ((double) range / size * 100);
if (progress <= 100) {
if (p == progress) {
return;
}
progressText = ParamsUtil.byteToM(range).
concat("M / ").
concat(ParamsUtil.byteToM(ParamsUtil.getLong(videoInfo.getFileByteSize()))).
concat("M");
progress = p;
if (progress % 10 == 0) {
progress = p;
// 更新进度
RemoteViews contentView = notification.contentView;
contentView.setTextViewText(R.id.progressRate, progress + "%");
contentView.setProgressBar(R.id.progress, 100, progress, false);
// 通知更新
notificationManager.notify(NOTIFY_ID, notification);
}
}
}
示例3: onStartCommand
import android.widget.RemoteViews; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// configure the notification
notificationBuilder = new Notification.Builder(this);
contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_progress);
contentView.setImageViewResource(R.id.image, R.drawable.ic_wifip2p);
contentView.setTextViewText(R.id.title, "Waiting for connection to download");
contentView.setProgressBar(R.id.status_progress, 100, 0, false);
notificationBuilder.setContent(contentView);
notificationBuilder.setSmallIcon(R.drawable.ic_wifip2p);
notificationBuilder.setOngoing(true);
notificationBuilder.setTicker("WiFi Direct service started");
notificationBuilder.setOnlyAlertOnce(true);
Intent i = new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
boolean client = false;
if (intent != null && intent.hasExtra("client"))
client = intent.getBooleanExtra("client", false);
if (intent != null && intent.hasExtra("path"))
path = intent.getStringExtra("path");
i.setComponent(new ComponentName("com.archos.wifidirect",
client ? "com.archos.wifidirect.WiFiDirectSenderActivity" : "com.archos.wifidirect.WiFiDirectReceiverActivity"));
PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(pi);
notificationManager = (NotificationManager) getApplicationContext().getSystemService(
Context.NOTIFICATION_SERVICE);
//To not be killed
startForeground(NOTIFICATION_ID, notificationBuilder.getNotification());
return START_STICKY;
}
示例4: onPreExecute
import android.widget.RemoteViews; //导入方法依赖的package包/类
protected void onPreExecute() {
super.onPreExecute();
PendingIntent pendingIntent = PendingIntent.getActivity(this.mContext, 0, new Intent(), 0);
this.notification.icon = R.drawable.notification_icon;
this.notification.tickerText = this.mContext.getString(R.string.update_asynctask_downloading);
this.notification.flags = 16;
RemoteViews remoteViews = new RemoteViews(this.mContext.getPackageName(), R.layout.notification_updata_layout);
remoteViews.setTextViewText(R.id.app_name, this.apkNameCn);
remoteViews.setTextViewText(R.id.progress_text, "0%");
remoteViews.setProgressBar(R.id.progress_value, 100, 0, false);
this.notification.contentView = remoteViews;
notificationManager.notify(this.notificationId, this.notification);
}
示例5: onPreExecute
import android.widget.RemoteViews; //导入方法依赖的package包/类
protected void onPreExecute() {
super.onPreExecute();
PendingIntent pendingIntent = PendingIntent.getActivity(this.activity, 0, new Intent(), 0);
this.notification.icon = R.anim.notification_download;
this.notification.tickerText = BaseApplication.getInstance().getString(R.string.update_asynctask_downloading);
this.notification.flags = 16;
RemoteViews remoteViews = new RemoteViews(this.activity.getPackageName(), R.layout.notification_updata_layout);
remoteViews.setTextViewText(R.id.app_name, this.activity.getString(R.string.unknown_apk) + this.apkNameCn);
remoteViews.setTextViewText(R.id.progress_text, "0%");
remoteViews.setProgressBar(R.id.progress_value, 100, 0, false);
this.notification.contentView = remoteViews;
this.notification.contentIntent = pendingIntent;
notificationManager.notify(this.notificationId, this.notification);
}
示例6: handleMessage
import android.widget.RemoteViews; //导入方法依赖的package包/类
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
mNotificationManager.cancel(0);
installApk();
break;
case 1:
int rate = msg.arg1;
if (rate < 100) {
RemoteViews views = mNotification.contentView;
views.setTextViewText(R.id.tv_download_progress, mTitle + "(" + rate
+ "%" + ")");
//views.setTextColor(R.id.tv_download_progress,getColor(R.color.text_title_color));
views.setProgressBar(R.id.pb_progress, 100, rate,
false);
} else {
// 下载完毕后变换通知形式
mNotification.flags = Notification.FLAG_AUTO_CANCEL;
mNotification.contentView = null;
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("completed", "yes");
PendingIntent contentIntent = PendingIntent.getActivity(
getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
mNotificationManager.notify(0, mNotification);
break;
}
}
示例7: build
import android.widget.RemoteViews; //导入方法依赖的package包/类
@Override
public Notification build() {
if (android.os.Build.VERSION.SDK_INT > 10) {
// only matters for Honeycomb
setOnlyAlertOnce(true);
}
// Build the RemoteView object
RemoteViews expandedView = new RemoteViews(
mContext.getPackageName(),
Helpers.getLayoutResource(mContext, "status_bar_ongoing_event_progress_bar"));
expandedView.setTextViewText(Helpers.getIdResource(mContext, "title"), mContentTitle);
// look at strings
expandedView.setViewVisibility(Helpers.getIdResource(mContext, "description"), View.VISIBLE);
expandedView.setTextViewText(Helpers.getIdResource(mContext, "description"),
Helpers.getDownloadProgressString(this.mCurrentBytes, mTotalBytes));
expandedView.setViewVisibility(Helpers.getIdResource(mContext, "progress_bar_frame"), View.VISIBLE);
expandedView.setProgressBar(Helpers.getIdResource(mContext, "progress_bar"),
(int) (mTotalBytes >> 8),
(int) (mCurrentBytes >> 8),
mTotalBytes <= 0);
expandedView.setViewVisibility(Helpers.getIdResource(mContext, "time_remaining"), View.VISIBLE);
expandedView.setTextViewText(
Helpers.getIdResource(mContext, "time_remaining"),
mContentInfo);
expandedView.setTextViewText(Helpers.getIdResource(mContext, "progress_text"),
Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes));
expandedView.setImageViewResource(Helpers.getIdResource(mContext, "appIcon"), mIcon);
Notification n = super.build();
n.contentView = expandedView;
return n;
}
示例8: updateNotification
import android.widget.RemoteViews; //导入方法依赖的package包/类
@Override
public Notification updateNotification(Context c) {
Notification n = mNotification;
n.icon = mIcon;
n.flags |= Notification.FLAG_ONGOING_EVENT;
if (android.os.Build.VERSION.SDK_INT > 10) {
n.flags |= Notification.FLAG_ONLY_ALERT_ONCE; // only matters for
// Honeycomb
}
// Build the RemoteView object
RemoteViews expandedView = new RemoteViews(
c.getPackageName(),
R.layout.status_bar_ongoing_event_progress_bar);
expandedView.setTextViewText(R.id.title, mTitle);
// look at strings
expandedView.setViewVisibility(R.id.description, View.VISIBLE);
expandedView.setTextViewText(R.id.description,
Helpers.getDownloadProgressString(mCurrentBytes, mTotalBytes));
expandedView.setViewVisibility(R.id.progress_bar_frame, View.VISIBLE);
expandedView.setProgressBar(R.id.progress_bar,
(int) (mTotalBytes >> 8),
(int) (mCurrentBytes >> 8),
mTotalBytes <= 0);
expandedView.setViewVisibility(R.id.time_remaining, View.VISIBLE);
expandedView.setTextViewText(
R.id.time_remaining,
c.getString(R.string.time_remaining_notification,
Helpers.getTimeRemaining(mTimeRemaining)));
expandedView.setTextViewText(R.id.progress_text,
Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes));
expandedView.setImageViewResource(R.id.appIcon, mIcon);
n.contentView = expandedView;
n.contentIntent = mPendingIntent;
return n;
}
示例9: notifyDownloadCompleted
import android.widget.RemoteViews; //导入方法依赖的package包/类
/**
* 下载完成, 发送下载完成的广播
*/
private void notifyDownloadCompleted(final Context context, final Request request, final File file)
{
// 取消旧上一个通知
int preNotificationId = request.mNotificationId;
mNotificationManager.cancel(preNotificationId);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.api_download_notification_ok);
remoteViews.setImageViewResource(R.id.noti_icon, R.drawable.notification_icon);
remoteViews.setTextViewText(R.id.noti_file_name, request.mTitle);
remoteViews.setTextViewText(R.id.noti_progressBarLeft, context.getString(R.string.cdk_download_ok));
remoteViews.setTextViewText(R.id.noti_progressBarRight, PROGRESSBAR_MAX + "%");
remoteViews.setProgressBar(R.id.noti_progressBar, PROGRESSBAR_MAX, PROGRESSBAR_MAX, false);
// 消息信息设置
Notification notification = new Notification();
notification.tickerText = request.mTitle;
notification.icon = R.drawable.notification_icon;
notification.contentView = remoteViews;
notification.flags = Notification.FLAG_AUTO_CANCEL;
// 点击通知栏
String extName = FileUtils.getFileExtension(file.getName());
Intent intent = new Intent();
if ("apk".equalsIgnoreCase(extName))
{
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
}
else
{
intent.setAction("com.wo2b.download.AActivity");
}
notification.contentIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT);
mNotificationManager.notify(preNotificationId, notification);
}
示例10: onHandleIntent
import android.widget.RemoteViews; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(@Nullable Intent intent) {
//Retrieve widget ids
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
new ComponentName(this, PerformanceWidgetProvider.class));
//Create a latch for synchronization
final CountDownLatch latch = new CountDownLatch(1);
context = getApplicationContext();
//Get firebaseuid
String firebaseUid = CacheUtils.getFirebaseUserId(context);
//Get data from firebase
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
statsDbRef = firebaseDatabase.getReference()
.child("users").child(firebaseUid).child("stats");
valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
stats = dataSnapshot.getValue(Stats.class);
latch.countDown();
}
@Override
public void onCancelled(DatabaseError databaseError) {
latch.countDown();
}
};
statsDbRef.addListenerForSingleValueEvent(valueEventListener);
try {
//wait for firebase to download data
latch.await();
//check if download is successful
if (stats != null) {
final int todaysTotalSeconds = stats.getTodaysTotalSeconds();
final int dailyAverage = stats.getDailyAverageSeconds();
float progress;
if (todaysTotalSeconds < dailyAverage) {
progress = (todaysTotalSeconds / (float) dailyAverage) * 100f;
} else {
progress = 100f;
}
progress = Math.round(progress * 100) / 100f;
for (int appWidgetId : appWidgetIds) {
RemoteViews views = new RemoteViews(getPackageName(), R.layout.performance_widget);
views.setTextViewText(R.id.todays_activity,
getString(R.string.todays_total_log_time, FormatUtils.getFormattedTime(context, todaysTotalSeconds)));
views.setTextViewText(R.id.daily_average_text,
getString(R.string.daily_average_format, FormatUtils.getFormattedTime(context, dailyAverage)));
views.setProgressBar(R.id.performance_bar, 100, (int) progress, false);
String progressCd = getString(R.string.progress_description, progress);
views.setContentDescription(R.id.performance_bar, progressCd);
// Create an Intent to launch NavigationDrawerActivity
Intent launchIntent = new Intent(this, NavigationDrawerActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);
views.setOnClickPendingIntent(R.id.widget, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
} catch (InterruptedException e) {
FirebaseCrash.report(e);
}
}