Example usage for android.widget RemoteViews setProgressBar

List of usage examples for android.widget RemoteViews setProgressBar

Introduction

In this page you can find the example usage for android.widget RemoteViews setProgressBar.

Prototype

public void setProgressBar(int viewId, int max, int progress, boolean indeterminate) 

Source Link

Document

Equivalent to calling ProgressBar#setMax ProgressBar.setMax , ProgressBar#setProgress ProgressBar.setProgress , and ProgressBar#setIndeterminate ProgressBar.setIndeterminate If indeterminate is true, then the values for max and progress are ignored.

Usage

From source file:com.perm.DoomPlay.DownloadNotifBuilder.java

public Notification createPaused() {
    Notification notification = new Notification();
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notif_download);

    views.setProgressBar(R.id.progressDownload, 100, 0, false);
    views.setTextViewText(R.id.notifTitle, context.getResources().getString(R.string.paused));
    views.setTextViewText(R.id.notifArtist, track.getArtist() + "-" + track.getTitle());
    views.setImageViewResource(R.id.notifPause, R.drawable.widget_play);

    Intent intentClose = new Intent(PlayingService.actionClose);
    intentClose.putExtra("aid", track.getAid());
    intentClose.setComponent(new ComponentName(context, DownloadingService.class));

    Intent intentPause = new Intent(PlayingService.actionIconPlay);
    intentPause.putExtra("aid", track.getAid());
    intentPause.setComponent(new ComponentName(context, DownloadingService.class));

    views.setOnClickPendingIntent(R.id.notifClose,
            PendingIntent.getService(context, notificationId, intentClose, PendingIntent.FLAG_UPDATE_CURRENT));

    views.setOnClickPendingIntent(R.id.notifPause,
            PendingIntent.getService(context, notificationId, intentPause, PendingIntent.FLAG_UPDATE_CURRENT));

    notification.contentView = views;/*from w  w  w  .j av a2s  . c  o  m*/
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.download_icon;

    return notification;
}

From source file:com.perm.DoomPlay.DownloadNotifBuilder.java

private Notification createStartingNew() {
    Notification notification = new Notification();
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notif_download);

    views.setProgressBar(R.id.progressDownload, 100, 0, true);
    views.setTextViewText(R.id.notifTitle, context.getResources().getString(R.string.Downloading));
    views.setTextViewText(R.id.notifArtist, track.getArtist() + "-" + track.getTitle());
    views.setImageViewResource(R.id.notifPause, R.drawable.widget_pause);

    ComponentName componentName = new ComponentName(context, DownloadingService.class);

    Intent intentClose = new Intent(PlayingService.actionClose);
    intentClose.putExtra("aid", track.getAid());
    intentClose.setComponent(componentName);

    Intent intentPause = new Intent(PlayingService.actionIconPause);
    intentPause.putExtra("aid", track.getAid());
    intentPause.setComponent(componentName);

    views.setOnClickPendingIntent(R.id.notifClose,
            PendingIntent.getService(context, notificationId, intentClose, PendingIntent.FLAG_UPDATE_CURRENT));

    views.setOnClickPendingIntent(R.id.notifPause,
            PendingIntent.getService(context, notificationId, intentPause, PendingIntent.FLAG_UPDATE_CURRENT));

    notification.contentView = views;/*from   w w  w .j a va2  s.  c o m*/
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.download_icon;

    return notification;

}

From source file:com.gelakinetic.mtgfam.helpers.DbUpdaterService.java

protected void switchToUpdating(String title) {
    final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.progress_notification);
    contentView.setProgressBar(R.id.progress_notification_bar, 100, 0, false);
    contentView.setTextViewText(R.id.progress_notification_title, title);

    mUpdateNotification.contentView = contentView;
    mUpdateNotification.contentIntent = mNotificationIntent;

    mNotificationManager.notify(STATUS_NOTIFICATION, mUpdateNotification);

    mProgressUpdater = new Runnable() {
        public void run() {
            contentView.setProgressBar(R.id.progress_notification_bar, 100, mProgress, false);
            mNotificationManager.notify(STATUS_NOTIFICATION, mUpdateNotification);
            mHandler.postDelayed(mProgressUpdater, 200);
        }//from  www .ja va  2 s .c  o  m
    };
    mHandler.postDelayed(mProgressUpdater, 200);
}

From source file:org.exobel.routerkeygen.AutoConnectService.java

private Notification createProgressBar(CharSequence title, CharSequence content, int progress) {
    final NotificationCompat.Builder builder = getSimple(title, content);
    final PendingIntent i = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(this, CancelOperationActivity.class)
                    .putExtra(CancelOperationActivity.SERVICE_TO_TERMINATE, AutoConnectService.class.getName())
                    .putExtra(CancelOperationActivity.MESSAGE, getString(R.string.cancel_auto_test)),
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(i);//w  w  w .ja  va2s. c o  m
    builder.setOngoing(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        builder.setProgress(keys.size(), progress, false);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            builder.addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(android.R.string.cancel),
                    i);
        }
    } else {
        final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);
        contentView.setTextViewText(R.id.text1, content);
        contentView.setProgressBar(R.id.progress, keys.size(), progress, false);
        final Notification not = builder.build();
        not.contentView = contentView;
        return not;
    }
    return builder.build();
}

From source file:com.maass.android.imgur_uploader.ImgurUpload.java

/**
 * Method to generate the remote view for the progress notification
 * /*from   w w w. j av a 2s . c  om*/
 * 
 */
private RemoteViews generateProgressNotificationView(final int progress, final int total) {
    final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout_upload);
    contentView.setProgressBar(R.id.UploadProgress, total, progress, false);
    contentView.setTextViewText(R.id.text, "Uploaded " + progress + " of " + total + " bytes");
    return contentView;
}

From source file:org.droidkit.app.UpdateService.java

private void notifyDownloading(String json) {
    Intent intent = new Intent(this, UpdateActivity.class);
    intent.putExtra("downloading", true);
    intent.putExtra("json", json);

    String desc = "Downloading " + getString(getApplicationInfo().labelRes);
    PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);
    Notification n = new Notification(android.R.drawable.stat_sys_download, "Downloading update...",
            System.currentTimeMillis());
    n.flags = Notification.FLAG_ONGOING_EVENT;
    n.contentIntent = pending;//from  ww w .j  a  va2  s .  co m

    RemoteViews view = new RemoteViews(getPackageName(),
            Resources.getId(this, "update_notification", Resources.TYPE_LAYOUT));
    view.setTextViewText(Resources.getId(this, "update_title_text", Resources.TYPE_ID), desc);
    view.setProgressBar(Resources.getId(this, "update_progress_bar", Resources.TYPE_ID), 100, 0, true);
    view.setImageViewResource(Resources.getId(this, "update_notif_icon", Resources.TYPE_ID),
            android.R.drawable.stat_sys_download);

    n.contentView = view;

    mNotificationManager.notify("Downloading update...", UPDATE_DOWNLOADING_ID, n);
}

From source file:com.fanfou.app.opensource.service.DownloadService.java

private void showProgress() {
    this.notification = new Notification(R.drawable.ic_notify_download, "?",
            System.currentTimeMillis());
    this.notification.flags |= Notification.FLAG_ONGOING_EVENT;
    this.notification.flags |= Notification.FLAG_AUTO_CANCEL;
    this.notification.contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    final RemoteViews view = new RemoteViews(getPackageName(), R.layout.download_notification);
    view.setTextViewText(R.id.download_notification_text, "? 0%");
    view.setProgressBar(R.id.download_notification_progress, 100, 0, false);
    this.notification.contentView = view;
    this.nm.notify(DownloadService.NOTIFICATION_PROGRESS_ID, this.notification);
}

From source file:com.google.android.vending.expansion.downloader.impl.V4CustomNotificationBuilder.java

@Override
public Notification build() {
    if (android.os.Build.VERSION.SDK_INT > 10) {
        // only matters for Honeycomb
        setOnlyAlertOnce(true);/* w w  w. j  a v  a 2s.c  o  m*/
    }

    // Build the RemoteView object
    RemoteViews expandedView = new RemoteViews(mContext.getPackageName(),
            R.layout.status_bar_ongoing_event_progress_bar);

    expandedView.setTextViewText(R.id.title, mContentTitle);
    // look at strings
    expandedView.setViewVisibility(R.id.description, View.VISIBLE);
    expandedView.setTextViewText(R.id.description,
            Helpers.getDownloadProgressString(this.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, mContentInfo);
    expandedView.setTextViewText(R.id.progress_text,
            Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes));
    expandedView.setImageViewResource(R.id.appIcon, mIcon);

    Notification n = super.build();
    n.contentView = expandedView;
    return n;
}

From source file:com.sip.pwc.sipphone.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 Builder(this);
    nb.setWhen(System.currentTimeMillis());
    nb.setContentTitle(title);//from  w  ww.  j  av  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.build() : 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:com.csipsimple.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);/*from w w w.  j a v a2  s  .  c  o  m*/
    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.build() : 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);
    }
}