Java Code Examples for android.widget.RemoteViews

The following examples show how to use android.widget.RemoteViews. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: fingen   Source File: WidgetTransfer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_transfer);
    Intent configIntent = new Intent(context, ActivityEditTransaction.class);
    Transaction transaction = new Transaction(PrefUtils.getDefDepID(context));
    transaction.setTransactionType(Transaction.TRANSACTION_TYPE_TRANSFER);
    configIntent.putExtra("transaction", transaction);
    configIntent.putExtra("update_date", true);
    configIntent.putExtra("EXIT", true);
    configIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Uri data = Uri.withAppendedPath(Uri.parse("ABCD" + "://widget/id/"),String.valueOf(appWidgetIds[0]));
    configIntent.setData(data);

    PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0);

    remoteViews.setOnClickPendingIntent(R.id.widgetContainer, configPendingIntent);
    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
}
 
Example 2
Source Project: RoMote   Source File: RokuAppWidgetProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Initialize given widgets to default state, where we launch Music on default click
 * and hide actions if service not running.
 */
private void defaultAppWidget(Context context, int[] appWidgetIds) {
    Device device = null;

    try {
        device = PreferenceUtils.getConnectedDevice(context);
    } catch (Exception ex) {
        return;
    }

    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.roku_appwidget);

    views.setTextViewText(R.id.model_name_text, device.getModelName());

    linkButtons(context, views, false /* not playing */);

    Intent intent = new Intent(context, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context,
            0 /* no requestCode */, intent, 0 /* no flags */);
    views.setOnClickPendingIntent(R.id.info_layout, pendingIntent);

    pushUpdate(context, appWidgetIds, views);
}
 
Example 3
Source Project: GitJourney   Source File: StackWidgetService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    Log.v(TAG, "getViewAt: position = " + position);

    // Construct a remote views item based on the app widget item XML file,
    // and set the text based on the position.
    RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_list_item);
    Intent fillInIntent = new Intent();
    fillInIntent.putExtra(EXTRA_LIST_VIEW_ROW_NUMBER, position);
    rv.setOnClickFillInIntent(R.id.main_list_item, fillInIntent);

    rv.setTextViewText(R.id.w_author_name, widgetDatas.get(position).getAuthorName());
    rv.setTextViewText(R.id.w_title, widgetDatas.get(position).getTitle());
    Picasso pic = Picasso.with(context);
    try {
        Bitmap map = pic.load(widgetDatas.get(position).getAvatar()).get();
        rv.setImageViewBitmap(R.id.w_github_user_image, map);
    } catch (IOException e) {
        Log.e(TAG, "", e);
    }
    return rv;
}
 
Example 4
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // TODO: Implement this method
    lg("on update");
    lg("Status: " + state);
    for (int i = 0; i < appWidgetIds.length; i++) {
        int currentId = appWidgetIds[i];
        lg("id: " + currentId);
        Intent intent = new Intent(context, APWidget.class);
        intent.putExtra(STATE, true);
        PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget);
        rv.setImageViewResource(R.id.widgetButton1, toggleButton());
        //rv.setTextViewText(R.id.widgetButton1,gettext(state));
        //rv.setTextColor(R.id.widgetButton1,getColor(!state));
        //rv.setTextColor(R.id.widgetTextView1,getColor(state));
        //rv.setTextViewText(R.id.widgetTextView1,getStatus(state));
        rv.setOnClickPendingIntent(R.id.widgetButton1, pi);
        //Intent tetherSettings = new Intent();
        //tetherSettings.setClassName(context, "com.android.settings.TetherSettings");
        rv.setOnClickPendingIntent(R.id.widgetLinearLayout1, tphs(context));
        appWidgetManager.updateAppWidget(currentId, rv);
        lg("Updated");
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
Example 5
@Override
public void updateViews(Context context, int appWidgetId, RemoteViews views, SuntimesRiseSetData data)
{
    super.updateViews(context, appWidgetId, views, data);
    boolean showSeconds = WidgetSettings.loadShowSecondsPref(context, appWidgetId);
    WidgetSettings.RiseSetOrder order = WidgetSettings.loadRiseSetOrderPref(context, appWidgetId);

    Calendar event = data.sunriseCalendar(1);
    if (order != WidgetSettings.RiseSetOrder.TODAY)
    {
        Calendar now = Calendar.getInstance();
        if (now.after(event)) {
            event = data.sunriseCalendar(2);
        }
    }
    updateViewsSunriseText(context, views, event, showSeconds);
}
 
Example 6
Source Project: chromadoze   Source File: NoiseService.java    License: GNU General Public License v3.0 6 votes vote down vote up
private RemoteViews addButtonToNotification(Notification n) {
    // Create a new RV with a Stop button.
    RemoteViews rv = new RemoteViews(
            getPackageName(), R.layout.notification_with_stop_button);
    PendingIntent pendingIntent = PendingIntent.getService(
            this,
            0,
            newStopIntent(this, R.string.stop_reason_notification),
            PendingIntent.FLAG_CANCEL_CURRENT);
    rv.setOnClickPendingIntent(R.id.stop_button, pendingIntent);

    // Pre-render the original RV, and copy some of the colors.
    RemoteViews oldRV = getContentView(this, n);
    final View inflated = oldRV.apply(this, new FrameLayout(this));
    final TextView titleText = findTextView(inflated, getString(R.string.app_name));
    final TextView defaultText = findTextView(inflated, getString(R.string.notification_text));
    rv.setInt(R.id.divider, "setBackgroundColor", defaultText.getTextColors().getDefaultColor());
    rv.setInt(R.id.stop_button_square, "setBackgroundColor", titleText.getTextColors().getDefaultColor());

    // Insert a copy of the original RV into the new one.
    rv.addView(R.id.notification_insert, oldRV.clone());
    
    return rv;
}
 
Example 7
Source Project: SuntimesWidget   Source File: MoonLayout.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected void themeViewsMoonPhase(Context context, RemoteViews views, SuntimesTheme theme)
{
    int waningColor = theme.getMoonWaningColor();
    int waxingColor = theme.getMoonWaxingColor();

    phaseColors.put(MoonPhaseDisplay.FIRST_QUARTER, waxingColor);
    phaseColors.put(MoonPhaseDisplay.WAXING_CRESCENT, waxingColor);
    phaseColors.put(MoonPhaseDisplay.WAXING_GIBBOUS, waxingColor);

    phaseColors.put(MoonPhaseDisplay.NEW, theme.getMoonNewColor());
    phaseColors.put(MoonPhaseDisplay.FULL, theme.getMoonFullColor());

    phaseColors.put(MoonPhaseDisplay.THIRD_QUARTER, waningColor);
    phaseColors.put(MoonPhaseDisplay.WANING_CRESCENT, waningColor);
    phaseColors.put(MoonPhaseDisplay.WANING_GIBBOUS, waningColor);
}
 
Example 8
Source Project: DebugPurge   Source File: WidgetProvider.java    License: MIT License 6 votes vote down vote up
private RemoteViews updateWidgetListView(Context context,
                                         int appWidgetId) {
    //which layout to show on widget
    RemoteViews remoteViews = new RemoteViews(
            context.getPackageName(),R.layout.widget_layout);
    //RemoteViews Service needed to provide adapter for ListView
    Intent intent = new Intent(context, WidgetService.class);
    //passing app widget id to that RemoteViews Service
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(
            intent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetId, R.id.listView,
            intent);
    remoteViews.setEmptyView(R.id.listView, R.id.emptyView);

    Intent toastIntent = new Intent(context, WidgetProvider.class);
    toastIntent.setAction(WidgetProvider.UNINSTALL_ACTION);
    toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.listView, toastPendingIntent);

    return remoteViews;
}
 
Example 9
private void linkButtons(final RemoteViews notificationLayout, final RemoteViews notificationLayoutBig) {
    PendingIntent pendingIntent;

    final ComponentName serviceName = new ComponentName(service, MusicService.class);

    // Previous track
    pendingIntent = buildPendingIntent(service, ACTION_REWIND, serviceName);
    notificationLayout.setOnClickPendingIntent(R.id.action_prev, pendingIntent);
    notificationLayoutBig.setOnClickPendingIntent(R.id.action_prev, pendingIntent);

    // Play and pause
    pendingIntent = buildPendingIntent(service, ACTION_TOGGLE_PAUSE, serviceName);
    notificationLayout.setOnClickPendingIntent(R.id.action_play_pause, pendingIntent);
    notificationLayoutBig.setOnClickPendingIntent(R.id.action_play_pause, pendingIntent);

    // Next track
    pendingIntent = buildPendingIntent(service,  ACTION_SKIP, serviceName);
    notificationLayout.setOnClickPendingIntent(R.id.action_next, pendingIntent);
    notificationLayoutBig.setOnClickPendingIntent(R.id.action_next, pendingIntent);
}
 
Example 10
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int appWidgetId : appWidgetIds) {
        Intent svcIntent = new Intent(context, WidgetService.class);
        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));

        RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_profile);
        widget.setRemoteAdapter(R.id.profile_list, svcIntent);

        widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK));

        appWidgetManager.updateAppWidget(appWidgetId, widget);
    }
}
 
Example 11
Source Project: container   Source File: PendIntentCompat.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void setIntentByViewGroup(RemoteViews remoteViews, ViewGroup viewGroup, List<RectInfo> list) {
	int count = viewGroup.getChildCount();
	for (int i = 0; i < count; i++) {
		View v = viewGroup.getChildAt(i);
		if (v instanceof ViewGroup) {
			// linearlayout
			setIntentByViewGroup(remoteViews, (ViewGroup) v, list);
		} else if (v instanceof TextView) {
			// textview
			Rect rect = new Rect();
			v.getHitRect(rect);
			// height修正
			rect.top += viewGroup.getTop();
			rect.bottom += viewGroup.getTop();
			PendingIntent pendingIntent = findIntent(rect, list);
			if (pendingIntent != null) {
				remoteViews.setOnClickPendingIntent(v.getId(), pendingIntent);
			}
		}
	}
}
 
Example 12
Source Project: MaxLock   Source File: MasterSwitchWidget.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("WorldReadableFiles")
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    Intent intent = new Intent(context, ActionActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(ActionsHelper.ACTION_EXTRA_KEY, ActionsHelper.ACTION_TOGGLE_MASTER_SWITCH);
    PendingIntent pending = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    boolean masterSwitchOn = MLPreferences.getPrefsApps(context).getBoolean(Common.MASTER_SWITCH_ON, true);

    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.master_switch_widget);
        views.setImageViewResource(R.id.widget_master_switch_icon, masterSwitchOn ? R.drawable.ic_lock_48dp : R.drawable.ic_lock_open_48dp);
        views.setOnClickPendingIntent(R.id.widget_background, pending);
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
 
Example 13
Source Project: SuntimesWidget   Source File: MoonLayout.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected void themeViewsMoonRiseSetText(Context context, RemoteViews views, SuntimesTheme theme)
{
    int moonriseColor = theme.getMoonriseTextColor();
    int suffixColor = theme.getTimeSuffixColor();
    views.setTextColor(R.id.text_time_moonrise_suffix, suffixColor);
    views.setTextColor(R.id.text_time_moonrise, moonriseColor);

    int moonsetColor = theme.getMoonsetTextColor();
    views.setTextColor(R.id.text_time_moonset_suffix, suffixColor);
    views.setTextColor(R.id.text_time_moonset, moonsetColor);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
    {
        float timeSize = theme.getTimeSizeSp();
        float suffSize = theme.getTimeSuffixSizeSp();

        views.setTextViewTextSize(R.id.text_time_moonrise_suffix, TypedValue.COMPLEX_UNIT_DIP, suffSize);
        views.setTextViewTextSize(R.id.text_time_moonrise, TypedValue.COMPLEX_UNIT_DIP, timeSize);

        views.setTextViewTextSize(R.id.text_time_moonset, TypedValue.COMPLEX_UNIT_DIP, timeSize);
        views.setTextViewTextSize(R.id.text_time_moonset_suffix, TypedValue.COMPLEX_UNIT_DIP, suffSize);
    }
}
 
Example 14
Source Project: protrip   Source File: PlacesWidgetProvider.java    License: MIT License 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int i = 0; i < appWidgetIds.length; i++) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_collection);

        Intent intent = new Intent(context, PlacesWidgetRemoteViewsService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        views.setRemoteAdapter(R.id.widget_list, intent);

        Intent toastIntent = new Intent(context, PlacesWidgetRemoteViewsService.class);
        toastIntent.setAction(PlacesWidgetProvider.TOAST_ACTION);
        toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.widget_list, toastPendingIntent);

        appWidgetManager.updateAppWidget(appWidgetIds[i], views);
    }

    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
Example 15
/**
 * Populates remote views for pre-N targeting apps.
 */
private void maybePopulateRemoteViews(Notification notification) {
    if (getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N) {
        Builder builder = Builder.recoverBuilder(getContext(), notification);

        // Some styles wrap Notification's contentView, bigContentView and headsUpContentView.
        // First inflate them all, only then set them to avoid recursive wrapping.
        RemoteViews content = builder.createContentView();
        RemoteViews big = builder.createBigContentView();
        RemoteViews headsUp = builder.createHeadsUpContentView();

        notification.contentView = content;
        notification.bigContentView = big;
        notification.headsUpContentView = headsUp;
    }
}
 
Example 16
Source Project: RoMote   Source File: RokuAppWidgetProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Link up various button actions using {@link PendingIntents}.
 *
 * @param playerActive True if player is active in background, which means
 *            widget click will launch {@link MainActivity},
 *            otherwise we launch {@link MainActivity}.
 */
private void linkButtons(Context context, RemoteViews views, boolean playerActive) {
    Log.d(TAG, "linkButtons called");

    linkButton(context, views, KeypressKeyValues.BACK, R.id.back_button, 0);
    linkButton(context, views, KeypressKeyValues.UP, R.id.up_button, 1);
    linkButton(context, views, KeypressKeyValues.HOME, R.id.home_button, 2);

    linkButton(context, views, KeypressKeyValues.LEFT, R.id.left_button, 3);
    linkButton(context, views, KeypressKeyValues.SELECT, R.id.ok_button, 4);
    linkButton(context, views, KeypressKeyValues.RIGHT, R.id.right_button, 5);

    linkButton(context, views, KeypressKeyValues.INTANT_REPLAY, R.id.instant_replay_button, 6);
    linkButton(context, views, KeypressKeyValues.DOWN, R.id.down_button, 7);
    linkButton(context, views, KeypressKeyValues.INFO, R.id.info_button, 8);

    linkButton(context, views, KeypressKeyValues.REV, R.id.rev_button, 9);
    linkButton(context, views, KeypressKeyValues.PLAY, R.id.play_button, 10);
    linkButton(context, views, KeypressKeyValues.FWD, R.id.fwd_button, 11);
}
 
Example 17
/**
 * {@inheritDoc}
 */
@Override
public boolean hasIdenticalIds(@Nullable OpenNotification n) {
    if (n == null) {
        return false;
    }

    EqualsBuilder builder = new EqualsBuilder();

    RemoteViews cv = getNotification().contentView;
    RemoteViews cv2 = n.getNotification().contentView;
    if (cv != null && cv2 != null) {
        builder.append(cv.getLayoutId(), cv2.getLayoutId());
    }

    return builder
            .append(getNotification().ledARGB, n.getNotification().ledARGB)
            .append(getPackageName(), n.getPackageName())
            .append(titleText, n.titleText)
            .isEquals();

}
 
Example 18
public static void setWidgetTheme(Context context, RemoteViews remoteViews, int widgetId) {
    appendLog(context, TAG, "setWidgetTheme:start");
    int textColorId = AppPreference.getTextColor(context);
    int backgroundColorId = AppPreference.getWidgetBackgroundColor(context);
    int windowHeaderBackgroundColorId = AppPreference.getWindowHeaderBackgroundColorId(context);

    remoteViews.setInt(R.id.widget_ext_loc_forecast_graph_3x3_widget_root, "setBackgroundColor", backgroundColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_widget_temperature, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_widget_description, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_widget_description, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_widget_second_temperature, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_1_widget_day, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_1_widget_temperatures, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_2_widget_day, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_2_widget_temperatures, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_3_widget_day, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_3_widget_temperatures, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_4_widget_day, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_4_widget_temperatures, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_5_widget_day, textColorId);
    remoteViews.setTextColor(R.id.widget_ext_loc_forecast_graph_3x3_forecast_5_widget_temperatures, textColorId);
    remoteViews.setInt(R.id.widget_ext_loc_forecast_graph_3x3_header_layout, "setBackgroundColor", windowHeaderBackgroundColorId);

    appendLog(context, TAG, "setWidgetTheme:end");
}
 
Example 19
Source Project: android_9.0.0_r45   Source File: PendingHostUpdate.java    License: Apache License 2.0 6 votes vote down vote up
private PendingHostUpdate(Parcel in) {
    appWidgetId = in.readInt();
    type = in.readInt();

    switch (type) {
        case TYPE_VIEWS_UPDATE:
            if (0 != in.readInt()) {
                views = new RemoteViews(in);
            }
            break;
        case TYPE_PROVIDER_CHANGED:
            if (0 != in.readInt()) {
                widgetInfo = new AppWidgetProviderInfo(in);
            }
            break;
        case TYPE_VIEW_DATA_CHANGED:
            viewId = in.readInt();
    }
}
 
Example 20
Source Project: ampdroid   Source File: Mp3PlayerService.java    License: MIT License 6 votes vote down vote up
private void setNotifiction() {
	RemoteViews notificationView = new RemoteViews(this.getPackageName(), R.layout.player_notification);
	notificationView.setTextViewText(R.id.notificationSongArtist, getArtist());
	notificationView.setTextViewText(R.id.notificationSongTitle, getCurrentTitle());
	/* 1. Setup Notification Builder */
	Notification.Builder builder = new Notification.Builder(this);

	/* 2. Configure Notification Alarm */
	builder.setSmallIcon(R.drawable.ic_stat_notify).setAutoCancel(true).setWhen(System.currentTimeMillis())
			.setTicker(getCurrentTitle());

	Intent intent = new Intent(this, MainActivity.class);
	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
	PendingIntent notifIntent = PendingIntent.getActivity(this, 0, intent, 0);

	builder.setContentIntent(notifIntent);
	builder.setContent(notificationView);

	/* 4. Create Notification and use Manager to launch it */
	Notification notification = builder.build();
	String ns = Context.NOTIFICATION_SERVICE;
	notifManager = (NotificationManager) getSystemService(ns);
	notifManager.notify(NOTIFICATION_ID, notification);
	startForeground(NOTIFICATION_ID, notification);
}
 
Example 21
Source Project: 365browser   Source File: CustomTabBottomBarDelegate.java    License: Apache License 2.0 6 votes vote down vote up
private void showRemoteViews(RemoteViews remoteViews) {
    final View inflatedView = remoteViews.apply(mActivity, getBottomBarView());
    if (mClickableIDs != null && mClickPendingIntent != null) {
        for (int id: mClickableIDs) {
            if (id < 0) return;
            View view = inflatedView.findViewById(id);
            if (view != null) view.setOnClickListener(mBottomBarClickListener);
        }
    }
    getBottomBarView().addView(inflatedView, 1);
    inflatedView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                int oldLeft, int oldTop, int oldRight, int oldBottom) {
            inflatedView.removeOnLayoutChangeListener(this);
            mFullscreenManager.setBottomControlsHeight(v.getHeight());
        }
    });
}
 
Example 22
private void extractDefaultTextColor() {
    if (mDefaultTextColor != null) return;
    ;
    try {
        Notification.Builder builder = new Notification.Builder(getContext());
        builder.setContentTitle("COLOR_SEARCH_1ST");
        Notification ntf = builder.build();
        LinearLayout group = new LinearLayout(getContext());
        RemoteViews contentView = ntf.contentView;
        if (contentView == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            contentView = Notification.Builder.recoverBuilder(getContext(), ntf).createContentView();
        }
        ViewGroup event = (ViewGroup) contentView.apply(getContext(), group);
        recurseGroup(event);
        group.removeAllViews();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 23
Source Project: physical-web   Source File: UrlDeviceDiscoveryService.java    License: Apache License 2.0 6 votes vote down vote up
private void updateSummaryNotificationRemoteViewsFirstBeacon(PwPair pwPair,
                                                             RemoteViews remoteViews) {
  PwsResult pwsResult = pwPair.getPwsResult();
  remoteViews.setImageViewBitmap(
      R.id.icon_firstBeacon, Utils.getBitmapIcon(mPwCollection, pwsResult));
  remoteViews.setTextViewText(R.id.title_firstBeacon, pwsResult.getTitle());
  remoteViews.setTextViewText(R.id.url_firstBeacon, pwsResult.getSiteUrl());
  remoteViews.setTextViewText(R.id.description_firstBeacon, pwsResult.getDescription());
  // Recolor notifications to have light text for non-Lollipop devices
  if (!(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) {
    remoteViews.setTextColor(R.id.title_firstBeacon, NON_LOLLIPOP_NOTIFICATION_TITLE_COLOR);
    remoteViews.setTextColor(R.id.url_firstBeacon, NON_LOLLIPOP_NOTIFICATION_URL_COLOR);
    remoteViews.setTextColor(R.id.description_firstBeacon,
                             NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR);
  }

  // Create an intent that will open the browser to the beacon's url
  // if the user taps the notification
  remoteViews.setOnClickPendingIntent(R.id.first_beacon_main_layout,
      Utils.createNavigateToUrlPendingIntent(pwsResult, this));
  remoteViews.setViewVisibility(R.id.firstBeaconLayout, View.VISIBLE);
}
 
Example 24
Source Project: android-news-app   Source File: NewsWidgetProvider.java    License: Apache License 2.0 6 votes vote down vote up
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {

    // Get sample news story strings
    CharSequence sampleNewStoryOne = context.getString(R.string.sample_news_story_1);
    CharSequence sampleNewStoryTwo = context.getString(R.string.sample_news_story_2);
    CharSequence sampleNewStoryThree = context.getString(R.string.sample_news_story_3);

    // Construct the RemoteViews object
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.news_widget);
    views.setTextViewText(R.id.appwidget_tv_1, sampleNewStoryOne);
    views.setTextViewText(R.id.appwidget_tv_2, sampleNewStoryTwo);
    views.setTextViewText(R.id.appwidget_tv_3, sampleNewStoryThree);

    // Widget click open app
    Intent intent = new Intent(context, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
    views.setOnClickPendingIntent(R.id.news_widget_container, pendingIntent);

    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example 25
public static void updateWidgetView(Context context, Location location) {
    WidgetConfig config = getWidgetConfig(
            context,
            context.getString(R.string.sp_widget_clock_day_horizontal_setting)
    );

    RemoteViews views = getRemoteViews(
            context, location,
            config.cardStyle, config.cardAlpha, config.textColor, config.textSize, config.clockFont,
            config.hideLunar
    );

    AppWidgetManager.getInstance(context).updateAppWidget(
            new ComponentName(context, WidgetClockDayHorizontalProvider.class),
            views
    );
}
 
Example 26
Source Project: DongWeather   Source File: ListViewService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    Log.d(TAG, "getViewAt: " + position);
    RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
    Log.d(TAG, "getViewAt: RemoteViews Succeed");
    //设置viewlist中的单项的值
    HeWeather5 heWeather5 = heWeather5List.get(position);
    if (null != heWeather5.basic) {
        views.setTextViewText(R.id.widget_countyname_tv, heWeather5.basic.cityName);
    }
    try {
        String filename = heWeather5.now.cond.code + ".png";
        views.setImageViewBitmap(R.id.widget_weather_im, BitmapFactory.decodeStream(getAssets().open(filename)));
    } catch (IOException e) {
        e.printStackTrace();
    }
    views.setTextViewText(R.id.widget_temperature_tv, heWeather5.now.tmp + "º");
    Log.d(TAG, "getViewAt: add succeed");
    Bundle extras = new Bundle();
    extras.putInt(ListViewService.INITENT_DATA, position);
    Intent skipIntent = new Intent();
    skipIntent.setAction(WidgetProvider.SKIP_COUNTY_WEATHER);
    skipIntent.putExtras(extras);
    views.setOnClickFillInIntent(R.id.widget_item_id, skipIntent);
    return views;

}
 
Example 27
Source Project: Android-Audio-Recorder   Source File: RecordingService.java    License: Apache License 2.0 5 votes vote down vote up
public void showNotificationAlarm(boolean show) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    if (!show) {
        notificationManager.cancel(NOTIFICATION_RECORDING_ICON);
    } else {
        PendingIntent main = PendingIntent.getService(this, 0,
                new Intent(this, RecordingService.class).setAction(SHOW_ACTIVITY),
                PendingIntent.FLAG_UPDATE_CURRENT);

        PendingIntent pe = PendingIntent.getService(this, 0,
                new Intent(this, RecordingService.class).setAction(PAUSE_BUTTON),
                PendingIntent.FLAG_UPDATE_CURRENT);

        RemoteViews view = new RemoteViews(getPackageName(), MainApplication.getTheme(getBaseContext(),
                R.layout.notifictaion_recording_light,
                R.layout.notifictaion_recording_dark));

        view.setOnClickPendingIntent(R.id.status_bar_latest_event_content, main);
        view.setTextViewText(R.id.notification_text, ".../" + targetFile);
        view.setOnClickPendingIntent(R.id.notification_pause, pe);
        view.setImageViewResource(R.id.notification_pause, !recording ? R.drawable.play : R.drawable.pause);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setOngoing(true)
                .setContentTitle(getString(R.string.recording_title))
                .setSmallIcon(R.drawable.ic_mic_24dp)
                .setContent(view);

        if (Build.VERSION.SDK_INT >= 21)
            builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

        notificationManager.notify(NOTIFICATION_RECORDING_ICON, builder.build());
    }
}
 
Example 28
Source Project: FimiX8-RE   Source File: DownloadApkService.java    License: MIT License 5 votes vote down vote up
public void onCreate() {
    super.onCreate();
    this.notificationManager = (NotificationManager) getSystemService("notification");
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    this.notification = new Notification();
    this.notification.icon = R.drawable.ic_launcher;
    this.notification.tickerText = getString(R.string.fimi_sdk_apk_downing) + getString(R.string.app_product_name);
    this.notification.contentIntent = pendIntent;
    this.notification.contentView = new RemoteViews(getPackageName(), R.layout.fimisdk_apk_download_notification);
    this.notification.contentView.setProgressBar(R.id.download_bar, 100, 0, false);
    this.notification.contentView.setTextViewText(R.id.text_download_title, getString(R.string.fimi_sdk_apk_downing) + " " + getString(R.string.app_product_name));
    this.notification.contentView.setTextViewText(R.id.text_download_process, "0%");
}
 
Example 29
Source Project: input-samples   Source File: ResponseAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public FillResponse buildResponseForFocusedNode(String datasetName, FilledAutofillField field,
        FieldType fieldType) {
    FillResponse.Builder responseBuilder = new FillResponse.Builder();
    RemoteViews remoteViews = RemoteViewsHelper.viewsWithNoAuth(
            mPackageName, datasetName);
    Dataset dataset = mDatasetAdapter.buildDatasetForFocusedNode(field, fieldType, remoteViews);
    if (dataset != null) {
        responseBuilder.addDataset(dataset);
        return responseBuilder.build();
    } else {
        return null;
    }
}
 
Example 30
Source Project: input-samples   Source File: RemoteViewsHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static RemoteViews simpleRemoteViews(String packageName, String remoteViewsText,
        @DrawableRes int drawableId) {
    RemoteViews presentation = new RemoteViews(packageName,
            R.layout.multidataset_service_list_item);
    presentation.setTextViewText(R.id.text, remoteViewsText);
    presentation.setImageViewResource(R.id.icon, drawableId);
    return presentation;
}