Java Code Examples for android.widget.RemoteViews#setBoolean()

The following examples show how to use android.widget.RemoteViews#setBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LeanplumNotificationHelper.java    From Leanplum-Android-SDK with Apache License 2.0 5 votes vote down vote up
/**
 * Gets Notification.BigPictureStyle with 2 lines text.
 *
 * @param message Push notification Bundle.
 * @param bigPicture Bitmap for BigPictureStyle notification.
 * @param title String with title for push notification.
 * @param messageText String with text for push notification.
 * @return Notification.BigPictureStyle or null.
 */
@TargetApi(16)
static Notification.BigPictureStyle getBigPictureStyle(Bundle message, Bitmap bigPicture,
    String title, final String messageText) {
  if (Build.VERSION.SDK_INT < 16 || message == null || bigPicture == null) {
    return null;
  }

  Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle() {
    @Override
    protected RemoteViews getStandardView(int layoutId) {
      RemoteViews remoteViews = super.getStandardView(layoutId);
      if (messageText != null && messageText.length() >= MAX_ONE_LINE_TEXT_LENGTH) {
        // Modifications of standard push RemoteView.
        try {
          int id = Resources.getSystem().getIdentifier("text", "id", "android");
          remoteViews.setBoolean(id, "setSingleLine", false);
          remoteViews.setInt(id, "setLines", 2);
          if (Build.VERSION.SDK_INT < 23) {
            // Make text smaller.
            remoteViews.setViewPadding(id, 0, BIGPICTURE_TEXT_TOP_PADDING, 0, 0);
            remoteViews.setTextViewTextSize(id, TypedValue.COMPLEX_UNIT_SP, BIGPICTURE_TEXT_SIZE);
          }
        } catch (Throwable throwable) {
          Log.e("Cannot modify push notification layout.");
        }
      }
      return remoteViews;
    }
  };

  bigPictureStyle.bigPicture(bigPicture)
      .setBigContentTitle(title)
      .setSummaryText(message.getString(Constants.Keys.PUSH_MESSAGE_TEXT));

  return bigPictureStyle;
}
 
Example 2
Source File: TrackWidgetProvider.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the stop button.
 * 
 * @param context the context
 * @param remoteViews the remote views
 * @param isRecording true if recording
 */
private static void updateStopButton(
    Context context, RemoteViews remoteViews, boolean isRecording) {
  remoteViews.setImageViewResource(R.id.track_widget_stop_button,
      isRecording ? R.drawable.button_stop : R.drawable.ic_button_stop_disabled);
  remoteViews.setBoolean(R.id.track_widget_stop_button, "setEnabled", isRecording);
  if (isRecording) {
    Intent intent = new Intent(context, ControlRecordingService.class).setAction(
        context.getString(R.string.track_action_end));
    PendingIntent pendingIntent = PendingIntent.getService(
        context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.track_widget_stop_button, pendingIntent);
  }
}
 
Example 3
Source File: ClementineWidgetProvider.java    From Android-Remote with GNU General Public License v3.0 4 votes vote down vote up
private void updateViewsOnConnectionStatusChange(Context context, RemoteViews views) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean canConnect = prefs.contains(SharedPreferencesKeys.SP_KEY_IP);

    views.setBoolean(R.id.widget_btn_play_pause, "setEnabled", false);
    views.setBoolean(R.id.widget_btn_next, "setEnabled", false);

    switch (mCurrentConnectionStatus) {
        case IDLE:
        case DISCONNECTED:
            // Reset play button
            views.setImageViewResource(R.id.widget_btn_play_pause,
                    R.drawable.ab_media_play);

            if (canConnect) {
                // Textviews
                views.setTextViewText(R.id.widget_subtitle, prefs.getString(
                        SharedPreferencesKeys.SP_KEY_IP, ""));
                views.setTextViewText(R.id.widget_title,
                        context.getString(R.string.widget_connect_to));

                // Start an intent to connect to Clemetine
                Intent intentConnect = new Intent(context, ClementineBroadcastReceiver.class);
                intentConnect.setAction(ClementineBroadcastReceiver.CONNECT);
                views.setOnClickPendingIntent(R.id.widget_layout, PendingIntent
                        .getBroadcast(context, 0, intentConnect, PendingIntent.FLAG_ONE_SHOT));
            } else {
                // Textviews
                views.setTextViewText(R.id.widget_subtitle,
                        context.getString(R.string.widget_open_clementine));
                views.setTextViewText(R.id.widget_title,
                        context.getString(R.string.widget_not_connected));

                // Start Clementine Remote
                views.setOnClickPendingIntent(R.id.widget_layout,
                        Utilities.getClementineRemotePendingIntent(context));
            }
            break;
        case CONNECTING:
            views.setTextViewText(R.id.widget_subtitle, "");
            views.setTextViewText(R.id.widget_title,
                    context.getString(R.string.connectdialog_connecting));
            break;
        case NO_CONNECTION:
            views.setTextViewText(R.id.widget_subtitle,
                    context.getString(R.string.widget_open_clementine));
            views.setTextViewText(R.id.widget_title,
                    context.getString(R.string.widget_couldnt_connect));
            // Start Clementine Remote
            views.setOnClickPendingIntent(R.id.widget_layout,
                    Utilities.getClementineRemotePendingIntent(context));
            break;
        case CONNECTED:
            views.setBoolean(R.id.widget_btn_play_pause, "setEnabled", true);
            views.setBoolean(R.id.widget_btn_next, "setEnabled", true);
            break;
    }
}
 
Example 4
Source File: DynamicViewUtils.java    From dynamic-utils with Apache License 2.0 3 votes vote down vote up
/**
 * Set the enabled state for the remote views.
 *
 * @param remoteViews The remote views to set the enabled state.
 * @param viewId The id of the view whose enabled state to be set.
 * @param enabled {@code true} to enable the view.
 *
 * @see RemoteViews#setBoolean(int, String, boolean)
 */
public static void setEnabled(@Nullable RemoteViews remoteViews,
        @IdRes int viewId, boolean enabled) {
    if (remoteViews == null) {
        return;
    }

    remoteViews.setBoolean(viewId, "setEnabled", enabled);
}