Example usage for android.widget RemoteViews setImageViewResource

List of usage examples for android.widget RemoteViews setImageViewResource

Introduction

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

Prototype

public void setImageViewResource(int viewId, int srcId) 

Source Link

Document

Equivalent to calling ImageView#setImageResource(int)

Usage

From source file:org.kei.android.phone.cellhistory.CellHistoryApp.java

private RemoteViews getRemoteViews(final String name, final int cellid, final int lac, final int ss,
        final int ssp, final long rxsp, final long txsp) {
    final RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(),
            R.layout.notifications_main);
    contentView.setImageViewResource(R.id.imagenotileft, R.drawable.ic_launcher);
    contentView.setTextViewText(R.id.title, getString(R.string.app_name));
    contentView.setTextViewText(R.id.textInfo, "CellID: " + cellid + ", LAC: " + lac);
    String speeds = "Rx:" + RecorderCtx.convertToHuman(rxsp, false) + "/s, Tx:"
            + RecorderCtx.convertToHuman(txsp, false) + "/s";
    contentView.setTextViewText(R.id.textNetwork, "Network: " + name + ", " + speeds);
    contentView.setTextViewText(R.id.textSS, "Signal strength: " + ss + " dBm (" + ssp + "%)");
    return contentView;
}

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:com.shanet.relayremote.Background.java

protected void onPostExecute(ArrayList<BasicNameValuePair> states) {
    // Dismiss the dialog and cancel the timer
    if (!isWidget) {
        dialog.dismiss();//w ww.j ava2 s  .c  om
        tt.cancel();
    }

    // If the context is an instance of the main activity, update the state of the relays in the listview
    if (!isWidget && (Activity) context instanceof Main && states.size() > 1) {
        ((Main) context).setRelaysAndGroupsStates(states);
        // If a widget, update the indicator light and states map 
    } else if (isWidget) {
        for (int i = 1; i < states.size(); i++) {
            if (pin == Integer.valueOf(states.get(i).getName())) {
                // Update the indicator image
                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
                views.setImageViewResource(R.id.widgetIndicator,
                        (states.get(i).getValue().charAt(0) == Constants.CMD_ON) ? R.drawable.widget_on
                                : R.drawable.widget_off);
                AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, views);

                // Set the state of the widget in the widget class
                Widget.setState(appWidgetId,
                        (states.get(i).getValue().charAt(0) == Constants.CMD_ON) ? Widget.STATE_ON
                                : Widget.STATE_OFF);
            }
        }
    }
}

From source file:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java

/**
 * Updates the record button.//from w  w w. j ava  2  s .  c  om
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param isRecording true if recording
 * @param recordingTrackPaused true if recording track is paused
 */
private void updateRecordButton(Context context, RemoteViews remoteViews, boolean isRecording,
        boolean recordingTrackPaused) {
    remoteViews.setImageViewResource(R.id.track_widget_record_button,
            isRecording && !recordingTrackPaused ? R.drawable.ic_pause : R.drawable.ic_record);
    int recordActionId;
    if (isRecording) {
        recordActionId = recordingTrackPaused ? R.string.track_action_resume : R.string.track_action_pause;
    } else {
        recordActionId = R.string.track_action_start;
    }
    Intent intent = new Intent(context, ControlRecordingService.class)
            .setAction(context.getString(recordActionId));
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.track_widget_record_button, pendingIntent);
}

From source file:com.shanet.relayremote.Main.java

private void setRelayStates(ArrayList<BasicNameValuePair> states) {
    if (states == null)
        return;/*from  w ww.j  a v  a  2 s. com*/

    // The server these states correspond to is the first entry
    String server = states.get(0).getValue();

    Relay relay;
    ArrayList<Bundle> widgets = database.selectAllWidgets();

    relay_loop: for (int i = 0; i < relays.size(); i++) {
        relay = relays.get(i);

        // If the current relay belongs to the server the states belong to, find it's state by matching pins
        if (relay.getServer().equals(server)) {
            for (int j = 1; j < states.size(); j++) {
                if (relay.getPin() == Integer.valueOf(states.get(j).getName())) {
                    if (states.get(j).getValue().charAt(0) == Constants.CMD_ON) {
                        relay.turnOn();
                    } else {
                        relay.turnOff();
                    }

                    // Check if any widgets are assigned to this relay, and if so, update them
                    for (Bundle widget : widgets) {
                        if (widget.getInt("type") == Constants.WIDGET_RELAY
                                && widget.getInt("id") == relay.getRid()) {
                            // Update the indicator image
                            RemoteViews views = new RemoteViews(this.getPackageName(), R.layout.widget);
                            views.setImageViewResource(R.id.widgetIndicator,
                                    (states.get(i).getValue().charAt(0) == Constants.CMD_ON)
                                            ? R.drawable.widget_on
                                            : R.drawable.widget_off);
                            AppWidgetManager.getInstance(this).updateAppWidget(widget.getInt("wid"), views);

                            // Set the state of the widget in the widget class
                            Widget.setState(widget.getInt("wid"),
                                    (states.get(i).getValue().charAt(0) == Constants.CMD_ON) ? Widget.STATE_ON
                                            : Widget.STATE_OFF);
                        }
                    }

                    // Done with this relay; move to the next one
                    continue relay_loop;
                }
            }
        }
    }
}

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);//w  w  w  . ja v a  2  s .  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  ww.  j  a v  a  2  s .  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.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);//from  ww w. ja va 2 s.  co  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.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.appd.login.V_Connection.java

/**
 * Action Initial Synchronization// w  w w. j  a v a 2  s .  com
 * @author Yamel Senih 24/04/2012, 00:14:42
 *          Carlos Parada 17/05/2012 Se Coloco la carga inicial automatica desde adempiere
 * @return void
 */
private void synchronize() {

    m_load = new InitialLoad(this) {

        @Override
        protected void onPostExecute(Object result) {
            super.onPostExecute(result);
            //   Load Context
            loadContext();
        }
    };

    m_load.LoadSoapFromContext(getActivity());

    if (!Env.isEnvLoad(getActivity())) {
        RemoteViews contentView = new RemoteViews(getActivity().getPackageName(), R.layout.v_progressdialog);
        contentView.setImageViewResource(R.id.iV_Synchronizing, R.drawable.syncserver_m);
        contentView.setTextViewText(R.id.tV_CurrentSinchronizing,
                getResources().getString(R.string.msg_CallingWebService));
        contentView.setTextViewText(R.id.tV_Percentaje, "0%");

        NotificationManager notify = Msg.notificationMsg(getActivity(), R.drawable.syncserver_h, "", 0,
                getActivity().getIntent(), contentView);
        m_load.setContentView(contentView);
        m_load.setM_NotificationManager(notify);
        m_load.execute();

    } else {
        loadContext();
    }

}

From source file:com.customprogrammingsolutions.MediaStreamer.MediaStreamerService.java

private void startNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
    contentView.setImageViewResource(R.id.notification_icon, R.drawable.notification_icon);
    contentView.setTextViewText(R.id.notification_title, getString(R.string.notification_title));
    contentView.setTextViewText(R.id.notification_text, urlToStream);
    if (isPreparing) {
        contentView.setImageViewResource(R.id.media_state_indicator_icon,
                R.drawable.notification_playback_loading);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon,
                PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0));
    } else if (isStreamError) {
        contentView.setImageViewResource(R.id.media_state_indicator_icon,
                R.drawable.notification_playback_error);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon,
                PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0));
    } else if (isPlaying) {
        contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.stop_button);
        PendingIntent stopIntentPending = PendingIntent.getService(this, 0,
                new Intent(MainActivity.STOP_INTENT), PendingIntent.FLAG_CANCEL_CURRENT);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, stopIntentPending);
    } else {/*from   www . j  a  va2 s .  c  o  m*/
        contentView.setImageViewResource(R.id.media_state_indicator_icon, R.drawable.play_button);
        Intent playIntent = new Intent(MainActivity.PLAY_INTENT);
        playIntent.putExtra(MainActivity.URL_EXTRA, urlToStream);

        PendingIntent playIntentPending = PendingIntent.getService(this, 0, playIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        contentView.setOnClickPendingIntent(R.id.media_state_indicator_icon, playIntentPending);
    }

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
    contentView.setOnClickPendingIntent(R.id.notification_layout, contentIntent);

    PendingIntent killIntentPending = PendingIntent.getService(this, 0,
            new Intent(MainActivity.KILL_SERVICE_INTENT), 0);
    contentView.setOnClickPendingIntent(R.id.close_notification_icon, killIntentPending);

    builder.setContent(contentView);

    builder.setSmallIcon(R.drawable.notification_icon);

    builder.setAutoCancel(false);

    startForeground(NOTIFICATION_ID, builder.build());
}