Java Code Examples for android.widget.RemoteViews

The following are top voted examples for showing how to use android.widget.RemoteViews. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: boohee_v5.6   File: NotificationCompatImplBase.java   Source Code and License 9 votes vote down vote up
private static <T extends Action> RemoteViews generateBigContentView(Context context, CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo, int number, Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, List<T> actions, boolean showCancelButton, PendingIntent cancelButtonIntent) {
    int actionCount = Math.min(actions.size(), 5);
    RemoteViews big = applyStandardTemplate(context, contentTitle, contentText, contentInfo, number, largeIcon, subText, useChronometer, when, getBigLayoutResource(actionCount), false);
    big.removeAllViews(R.id.media_actions);
    if (actionCount > 0) {
        for (int i = 0; i < actionCount; i++) {
            big.addView(R.id.media_actions, generateMediaActionButton(context, (Action) actions.get(i)));
        }
    }
    if (showCancelButton) {
        big.setViewVisibility(R.id.cancel_action, 0);
        big.setInt(R.id.cancel_action, "setAlpha", context.getResources().getInteger(R.integer.cancel_button_image_alpha));
        big.setOnClickPendingIntent(R.id.cancel_action, cancelButtonIntent);
    } else {
        big.setViewVisibility(R.id.cancel_action, 8);
    }
    return big;
}
 
Example 2
Project: q-mail   File: MessageListWidgetProvider.java   Source Code and License 7 votes vote down vote up
private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.message_list_widget_layout);

    views.setTextViewText(R.id.folder, context.getString(R.string.integrated_inbox_title));

    Intent intent = new Intent(context, MessageListWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    views.setRemoteAdapter(R.id.listView, intent);

    PendingIntent viewAction = viewActionTemplatePendingIntent(context);
    views.setPendingIntentTemplate(R.id.listView, viewAction);

    PendingIntent composeAction = composeActionPendingIntent(context);
    views.setOnClickPendingIntent(R.id.new_message, composeAction);

    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example 3
Project: Clases-2017c1   File: HiAppWidget.java   Source Code and License 7 votes vote down vote up
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {

    CharSequence widgetText = HiAppWidgetConfigureActivity.loadTitlePref(context, appWidgetId);
    int pos = HiAppWidgetConfigureActivity.loadPosPref(context, appWidgetId) % texts.length;
    // Construct the RemoteViews object
    int layoutId = pos == 3 ? R.layout.hi_app_widget_other : R.layout.hi_app_widget;
    RemoteViews views = new RemoteViews(context.getPackageName(), layoutId);
    views.setTextViewText(R.id.title, widgetText);
    views.setTextViewText(R.id.appwidget_text, context.getString(texts[pos]));

    views.setOnClickPendingIntent(R.id.back, getPendingIntent(context, appWidgetId, -1));
    views.setOnClickPendingIntent(R.id.next, getPendingIntent(context, appWidgetId, +1));

    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example 4
Project: buildAPKsSamples   File: StackWidgetProvider.java   Source Code and License 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // update each of the widgets with the remote adapter
    for (int i = 0; i < appWidgetIds.length; ++i) {

        // Here we setup the intent which points to the StackViewService which will
        // provide the views for this collection.
        Intent intent = new Intent(context, StackWidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        // When intents are compared, the extras are ignored, so we need to embed the extras
        // into the data so that the extras will not be ignored.
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_view, intent);

        // The empty view is displayed when the collection has no items. It should be a sibling
        // of the collection view.
        rv.setEmptyView(R.id.stack_view, R.id.empty_view);

        // Here we setup the a pending intent template. Individuals items of a collection
        // cannot setup their own pending intents, instead, the collection as a whole can
        // setup a pending intent template, and the individual items can set a fillInIntent
        // to create unique before on an item to item basis.
        Intent toastIntent = new Intent(context, StackWidgetProvider.class);
        toastIntent.setAction(StackWidgetProvider.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);
        rv.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent);

        appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
Example 5
Project: financisto1-holo   File: AccountWidget.java   Source Code and License 6 votes vote down vote up
private static void updateWidgets(Context context, AppWidgetManager manager, int[] appWidgetIds, boolean nextAccount) {
    Log.d("FinancistoWidget", "updateWidgets " + Arrays.toString(appWidgetIds) + " -> " + nextAccount);
    for (int id : appWidgetIds) {
        AppWidgetProviderInfo appWidgetInfo = manager.getAppWidgetInfo(id);
        if (appWidgetInfo != null) {
            int layoutId = appWidgetInfo.initialLayout;
            if (MyPreferences.isWidgetEnabled(context)) {
                long accountId = loadAccountForWidget(context, id);
                Class providerClass = getProviderClass(appWidgetInfo);
                Log.d("FinancistoWidget", "using provider " + providerClass);
                RemoteViews remoteViews = nextAccount || accountId == -1
                        ? buildUpdateForNextAccount(context, id, layoutId, providerClass, accountId)
                        : buildUpdateForCurrentAccount(context, id, layoutId, providerClass, accountId);
                manager.updateAppWidget(id, remoteViews);
            } else {
                manager.updateAppWidget(id, noDataUpdate(context, layoutId));
            }
        }
    }
}
 
Example 6
Project: ThunderMusic   File: MediaAppWidgetProvider4x2_Light.java   Source Code and License 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) {
    final Resources res = context.getResources();
    final RemoteViews views = new RemoteViews(context.getPackageName(),
            R.layout.album_appwidget4x2_light);

    views.setViewVisibility(R.id.albumname, View.GONE);
    views.setViewVisibility(R.id.trackname, View.GONE);
    views.setTextViewText(R.id.artistname,
            res.getText(R.string.widget_initial_text));
    views.setImageViewResource(R.id.albumart,
            R.drawable.albumart_mp_unknown);

    linkButtons(context, views);
    pushUpdate(context, appWidgetIds, views);
}
 
Example 7
Project: MinimalismJotter   File: NotesRemoteViewsFactory.java   Source Code and License 6 votes vote down vote up
@Override
    // 返回item对应的子View
    public RemoteViews getViewAt(int position) {
        Logger.INSTANCE.i(" --> getViewAt");
        if (mNotes.get(position) == null) {
            return null;
        }
        RemoteViews rv = new RemoteViews(context.getPackageName(),
                R.layout.app_widget_notes_item);
        Note note = mNotes.get(position);

        rv.setTextViewText(R.id.ic_notes_item_title_tv, note.getLabel());
        rv.setTextViewText(R.id.ic_notes_item_content_tv, note.getContent());
        rv.setTextViewText(R.id.ic_notes_item_data_tv, context.getString(R.string.note_log_text, context.getString(R.string.create),
                TimeUtils.getTime(note.getCreateTime())));
//        if (StringUtils.isEmpty(note.getImagePath()) || "[]".equals(note.getImagePath())) {
//            rv.setViewVisibility(R.id.ic_small_pic, Visibility);
//        } else {
//            rv.
//            holder.setVisible(R.id.small_pic, true);
//            ImageUtils.INSTANCE.showThumbnail(mContext, note.getImagePath(), (ImageView) holder.getView(R.id.small_pic));
//        }

        loadItemOnClickExtras(rv, position);
        return rv;
    }
 
Example 8
Project: Canvas-Vision   File: StackWidgetProvider.java   Source Code and License 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int i = 0; i < appWidgetIds.length; ++i) {

        Intent intent = new Intent(context, StackWidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
        rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_view, intent);

        rv.setEmptyView(R.id.stack_view, R.id.empty_view);

        Intent widgetIntent = new Intent(context, StackWidgetProvider.class);
        widgetIntent.setAction(StackWidgetProvider.WIDGET_ACTION);
        widgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        PendingIntent widgetPendingIntent = PendingIntent.getBroadcast(context, 0, widgetIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        rv.setPendingIntentTemplate(R.id.stack_view, widgetPendingIntent);

        appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
Example 9
Project: aosp_nav_bar_ex   File: MainActivity.java   Source Code and License 6 votes vote down vote up
private void addView()
{
	NavBarEntry entry = navBarEntryFromView();
	if (entry == null) return;

	RemoteViews remoteViews = createRemoteViewsId(entry);
	if (remoteViews == null) return;

	NavBarExServiceMgr navBarExServiceMgr = (NavBarExServiceMgr) getSystemService(Context.NAVBAREX_SERVICE);

	String id = navBarExServiceMgr.addView(entry.priority, remoteViews);
	if (TextUtils.isEmpty(id))
	{
		Toast.makeText(this, "Failed to add remote views. Returned null.", Toast.LENGTH_SHORT).show();
		return;
	}
	settings.getIdsMap().put(id, entry);
	settings.saveDeferred();

	fillListView();
	fillViews();
}
 
Example 10
Project: buildAPKsApps   File: AppWidget.java   Source Code and License 6 votes vote down vote up
private RemoteViews buildUpdate(Context context) {
	RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget);

	AudioManager audioManager = (AudioManager) context.getSystemService(Activity.AUDIO_SERVICE);
	if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
		updateViews.setImageViewResource(R.id.phoneState, R.drawable.phone_state_normal);
		audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
	} else {
		updateViews.setImageViewResource(R.id.phoneState, R.drawable.phone_state_silent);
		audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
	}

	Intent i = new Intent(this, AppWidget.class);
	PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
	updateViews.setOnClickPendingIntent(R.id.phoneState, pi);

	return updateViews;

}
 
Example 11
Project: AJCPlayer   File: SecondAudioActivity.java   Source Code and License 6 votes vote down vote up
@Override
public RemoteViews notificationChange(Notification notification, int notificationId, RemoteViews remoteViews) {

    if (mImageNotification != null) {
        remoteViews.setViewVisibility(R.id.notification_icon, View.VISIBLE);
        Picasso.with(this).load(mImageNotification)
                .into(remoteViews, R.id.notification_icon, notificationId, notification);
    }

    remoteViews.setViewVisibility(R.id.notification_title, View.VISIBLE);
    remoteViews.setTextViewText(R.id.notification_title, mTitle.getText().toString());

    remoteViews.setViewVisibility(R.id.notification_subtitle, View.VISIBLE);
    remoteViews.setTextViewText(R.id.notification_subtitle, mSubtitle.getText().toString());

    if (!mStop.isChecked()) {
        remoteViews.setViewVisibility(R.id.stop_icon, View.GONE);
    }

    if (!mPlayPause.isChecked()) {
        remoteViews.setViewVisibility(R.id.play_icon, View.GONE);
        remoteViews.setViewVisibility(R.id.pause_icon, View.GONE);
    }

    return remoteViews;
}
 
Example 12
Project: android_packages_apps_ClockWidget   File: ClockWidget.java   Source Code and License 6 votes vote down vote up
private static void setClockAmPm(Context context, RemoteViews widget) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (DateFormat.is24HourFormat(context)) {
            widget.setViewVisibility(R.id.ampm_text, View.GONE);
        } else {
            widget.setViewVisibility(R.id.ampm_text, View.VISIBLE);
            Calendar currentCalendar = Calendar.getInstance();

            int hour = currentCalendar.get(Calendar.HOUR_OF_DAY);

            if (hour < 12) {
                widget.setTextViewText(R.id.ampm_text, context.getResources().getString(R.string.time_am_default));
            } else {
                widget.setTextViewText(R.id.ampm_text, context.getResources().getString(R.string.time_pm_default));
            }
        }
    }
    else{
        widget.setViewVisibility(R.id.ampm_text, View.GONE);
    }

}
 
Example 13
Project: GarageDoor   File: GarageDoorWidgetProvider.java   Source Code and License 6 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int i = 0; i < appWidgetIds.length; i++) {
        int appWidgetId = appWidgetIds[i];

        // Get the layout for the App Widget and attach an on-click listener
        // to the button
        RemoteViews views = new RemoteViews(context.getPackageName(),
                R.layout.garage_door_widget);

        Intent intent = new Intent(context, GarageDoorIntentService.class);
        PendingIntent pendingIntent = PendingIntent.getService(
                context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
 
Example 14
Project: android-widget   File: KaemWidget.java   Source Code and License 6 votes vote down vote up
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {

    setCountersDK(context);
    setCountersIO(context);
    setCountersFromPreferences(context);

    // Construct the RemoteViews object
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.kaem_widget);
    views.setTextViewText(R.id.dk_kaem_users, dkUsersCount);
    views.setTextViewText(R.id.dk_kaem_projects, dkProjectsCount);
    views.setTextViewText(R.id.dk_kaem_teams, dkTeamsCount);
    views.setTextViewText(R.id.dk_kaem_lookups, dkLookupsCount);

    views.setTextViewText(R.id.io_kaem_users, ioUsersCount);
    views.setTextViewText(R.id.io_kaem_projects, ioProjectsCount);
    views.setTextViewText(R.id.io_kaem_teams, ioTeamsCount);
    views.setTextViewText(R.id.io_kaem_lookups, ioLookupsCount);

    // Pending intent for refresh button
    Intent intent = new Intent(REFRESH_BUTTON);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.REFRESH_BUTTON, pendingIntent);

    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example 15
Project: markor   File: FilesWidgetFactory.java   Source Code and License 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews rowView = new RemoteViews(_context.getPackageName(), R.layout.widget_file_item);
    rowView.setTextViewText(R.id.widget_note_title, "???");
    if (position < _widgetFilesList.length) {
        File file = _widgetFilesList[position];
        Intent fillInIntent = new Intent().putExtra(DocumentIO.EXTRA_PATH, file);
        rowView.setTextViewText(R.id.widget_note_title, MarkdownTextConverter.MD_EXTENSION_PATTERN.matcher(file.getName()).replaceAll(""));
        rowView.setOnClickFillInIntent(R.id.widget_note_title, fillInIntent);
    }
    return rowView;
}
 
Example 16
Project: notification-adapter   File: NotificationAdapterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testNotificationAdapter() {
    final String NOTIFICATION_TEXT = "adapter-text";
    final String NOTIFICATION_TITLE = "adapter-title";
    final long TIMEOUT = 5000;

    Context appContext = InstrumentationRegistry.getTargetContext();

    RemoteViews contentView = new RemoteViews("cn.dreamtobe.toolset.test", R.layout.custom_layout);
    contentView.setTextViewText(R.id.title, NOTIFICATION_TITLE);
    contentView.setTextViewText(R.id.text, NOTIFICATION_TEXT);

    // Fix the Notification-Style problem ---------------
    // Set the default title style color to title view.
    contentView.setTextColor(R.id.title, NotificationAdapter.getTitleColor(appContext));
    // Set the default title style size to title view
    contentView.setTextViewTextSize(R.id.title, COMPLEX_UNIT_PX, NotificationAdapter.getTitleSize(appContext));
    // Set the default text style color to text view
    contentView.setTextColor(R.id.text, NotificationAdapter.getTextColor(appContext));
    // Set the default text style size to text view
    contentView.setTextViewTextSize(R.id.text, COMPLEX_UNIT_PX, NotificationAdapter.getTextSize(appContext));
    // End fix the Notification-Style problem ---------------

    Notification notification = new Notification();
    notification.icon = R.drawable.ic_launcher;
    notification.contentView = contentView;

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    NotificationManager notifyMgr =
            (NotificationManager) appContext.getSystemService(NOTIFICATION_SERVICE);
    notifyMgr.notify(1, notification);

    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    device.openNotification();
    device.wait(Until.hasObject(By.text(NOTIFICATION_TITLE)), TIMEOUT);
}
 
Example 17
Project: orgzly-android   File: ListWidgetViewsFactory.java   Source Code and License 5 votes vote down vote up
private void setContent(RemoteViews row, Note note) {
    /* see also HeadsListViewAdapter.bindView */
    OrgHead head = note.getHead();
    row.setTextViewText(R.id.item_list_widget_title, titleGenerator.generateTitle(note, head));

    /* Closed time. */
    if (head.hasClosed() && AppPreferences.displayPlanning(mContext)) {
        row.setTextViewText(R.id.item_list_widget_closed_text, userTimeFormatter.formatAll(head.getClosed()));
        row.setViewVisibility(R.id.item_list_widget_closed, View.VISIBLE);
    } else {
        row.setViewVisibility(R.id.item_list_widget_closed, View.GONE);
    }

    /* Deadline time. */
    if (head.hasDeadline() && AppPreferences.displayPlanning(mContext)) {
        row.setTextViewText(R.id.item_list_widget_deadline_text, userTimeFormatter.formatAll(head.getDeadline()));
        row.setViewVisibility(R.id.item_list_widget_deadline, View.VISIBLE);
    } else {
        row.setViewVisibility(R.id.item_list_widget_deadline, View.GONE);
    }

    /* Scheduled time. */
    if (head.hasScheduled() && AppPreferences.displayPlanning(mContext)) {
        row.setTextViewText(R.id.item_list_widget_scheduled_text, userTimeFormatter.formatAll(head.getScheduled()));
        row.setViewVisibility(R.id.item_list_widget_scheduled, View.VISIBLE);
    } else {
        row.setViewVisibility(R.id.item_list_widget_scheduled, View.GONE);
    }

    if (AppPreferences.todoKeywordsSet(mContext).contains(head.getState())) {
        row.setViewVisibility(R.id.item_list_widget_done, View.VISIBLE);
    } else {
        row.setViewVisibility(R.id.item_list_widget_done, View.GONE);
    }
}
 
Example 18
Project: blockvote   File: AppWidgetUpdateService.java   Source Code and License 5 votes vote down vote up
@Override
protected void onHandleWork(@NonNull Intent intent) {
	AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
	int[]            ids              = appWidgetManager.getAppWidgetIds(new ComponentName(this, AppWidget.class));
	RemoteViews      views            = new RemoteViews(getPackageName(), R.layout.app_widget);

	try (Cursor cursor = getContentResolver().query(StatsProvider.CONTENT_URI, null, null, null, null)) {
		if (cursor == null || cursor.getCount() <= 0) {
			return;
		}


		cursor.moveToPrevious();
		while (cursor.moveToNext()) {
			switch (getEnum(cursor, Stats.ID, Id.class)) {
				case S2X:
					setCell(views, R.id.appwidget_value_sw, getFloat(cursor, Stats.D1));
					break;

				case EC:
					setCell(views, R.id.appwidget_value_ec, getFloat(cursor, Stats.D1));
					break;
			}
		}
	}

	Intent        mainIntent    = new Intent(this, MainActivity.class);
	PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, mainIntent, 0);
	views.setOnClickPendingIntent(R.id.appwidget_root, pendingIntent);
	appWidgetManager.updateAppWidget(ids, views);
}
 
Example 19
Project: q-mail   File: MessageListRemoteViewFactory.java   Source Code and License 5 votes vote down vote up
@Override
public RemoteViews getLoadingView() {
    RemoteViews loadingView = new RemoteViews(context.getPackageName(), R.layout.message_list_widget_loading);
    loadingView.setTextViewText(R.id.loadingText, context.getString(R.string.mail_list_widget_loading));
    loadingView.setViewVisibility(R.id.loadingText, View.VISIBLE);
    return loadingView;
}
 
Example 20
Project: homescreenarcade   File: UpDownWidget.java   Source Code and License 5 votes vote down vote up
protected void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.up_down_widget);
    views.setOnClickPendingIntent(R.id.up_btn,
            PendingIntent.getBroadcast(context, 0, new Intent(ArcadeCommon.ACTION_UP), 0));
    views.setOnClickPendingIntent(R.id.down_btn,
            PendingIntent.getBroadcast(context, 0, new Intent(ArcadeCommon.ACTION_DOWN), 0));
            
    appWidgetManager.updateAppWidget(appWidgetId, views);
}
 
Example 21
Project: GitHub   File: AppWidgetTargetTest.java   Source Code and License 5 votes vote down vote up
@Before
public void setUp() {
  shadowManager = (UpdateShadowAppWidgetManager) Shadow
      .extract(AppWidgetManager.getInstance(RuntimeEnvironment.application));
  viewId = 1234;
  views = mock(RemoteViews.class);
}
 
Example 22
Project: lighthouse   File: MediaNotificationManager.java   Source Code and License 5 votes vote down vote up
private void setRecordState(RemoteViews remoteViews, Podcast podcast, Record record) {
    remoteViews.setTextViewText(android.R.id.title, podcast.getName());
    remoteViews.setTextViewText(android.R.id.text1, record.getName());

    BitmapInfo bitmapInfo = PodcastImageCache.getInstance().getIcon(podcast.getId());
    if (bitmapInfo != null) {
        remoteViews.setImageViewBitmap(android.R.id.icon, bitmapInfo.getBitmap());
    }
}
 
Example 23
Project: chromium-for-android-56-debug-video   File: CustomTabBottomBarDelegate.java   Source Code and License 5 votes vote down vote up
private void showRemoteViews(RemoteViews remoteViews) {
    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);
}
 
Example 24
Project: GitHub   File: RouteService.java   Source Code and License 5 votes vote down vote up
private void initNotification() {
    int icon = R.mipmap.bike_icon2;
    contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
    notification = new NotificationCompat.Builder(this).setContent(contentView).setSmallIcon(icon).build();
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.putExtra("flag", "notification");
    notification.contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
}
 
Example 25
Project: chromium-for-android-56-debug-video   File: CustomTabActivity.java   Source Code and License 5 votes vote down vote up
/**
 * Checks whether the active {@link CustomTabContentHandler} belongs to the given session, and
 * if true, updates {@link RemoteViews} on the secondary toolbar.
 * @return Whether the update is successful.
 */
static boolean updateRemoteViews(
        CustomTabsSessionToken session, RemoteViews remoteViews, int[] clickableIDs,
        PendingIntent pendingIntent) {
    ThreadUtils.assertOnUiThread();
    // Do nothing if there is no activity or the activity does not belong to this session.
    if (sActiveContentHandler == null || !sActiveContentHandler.getSession().equals(session)) {
        return false;
    }
    return sActiveContentHandler.updateRemoteViews(remoteViews, clickableIDs, pendingIntent);
}
 
Example 26
Project: Mobike   File: RouteService.java   Source Code and License 5 votes vote down vote up
private void initNotification() {
    int icon = R.drawable.mobike_logo;
    contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
    notification = new NotificationCompat.Builder(this).setContent(contentView).setSmallIcon(icon).build();
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.putExtra("flag", "notification");
    notification.contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
}
 
Example 27
Project: MusicX-music-player   File: MusicXwidget4x4.java   Source Code and License 5 votes vote down vote up
private void pushUpdate(Context context, int[] appWidgetIds, RemoteViews views) {
    // Update specific list of appWidgetIds if given, otherwise default to all
    final AppWidgetManager gm = AppWidgetManager.getInstance(context);
    if (appWidgetIds != null) {
        gm.updateAppWidget(appWidgetIds, views);
    } else {
        gm.updateAppWidget(new ComponentName(context, this.getClass()), views);
    }
}
 
Example 28
Project: letv   File: DownloadNotification.java   Source Code and License 5 votes vote down vote up
private void initNotification() {
    if (this.mNotification == null || this.nm == null) {
        this.mNotification = new Notification(R.drawable.notification_icon, this.mContext.getString(R.string.notification_download_ing), System.currentTimeMillis());
        this.mNotification.contentView = new RemoteViews(this.mContext.getPackageName(), R.layout.notification_download);
        this.mNotification.contentView.setProgressBar(R.id.notify_progressbar, 100, 0, false);
        this.mNotification.flags = 32;
        this.nm = (NotificationManager) this.mContext.getSystemService("notification");
    }
}
 
Example 29
Project: javaide   File: WidgetHelper.java   Source Code and License 5 votes vote down vote up
private static void updateWidget(Context context, AppWidgetManager manager, int appWidgetId, boolean serviceRunning) {


        RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_recording);

        // change the subtext depending on whether the service is running or not
        CharSequence subtext = context.getText(
                serviceRunning ? R.string.widget_recording_in_progress : R.string.widget_start_recording);
        updateViews.setTextViewText(R.id.widget_subtext, subtext);

        // if service not running, don't show the "recording" icon
        updateViews.setViewVisibility(R.id.record_badge_image_view, serviceRunning ? View.VISIBLE : View.INVISIBLE);

        PendingIntent pendingIntent = getPendingIntent(context, appWidgetId);

        updateViews.setOnClickPendingIntent(R.id.clickable_linear_layout, pendingIntent);

        manager.updateAppWidget(appWidgetId, updateViews);

    }
 
Example 30
Project: MuslimMateAndroid   File: CalenderWidget.java   Source Code and License 5 votes vote down vote up
/**
 * Function fire on system update widget
 *
 * @param context          Context of application
 * @param appWidgetManager App widget manger
 * @param appWidgetIds     Widget system ids
 */
@Override
public void onUpdate(Context context, final AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    final int count = appWidgetIds.length;

    //set widget language with the system language
    Locale locale = new Locale(Resources.getSystem().getConfiguration().locale.getLanguage());
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
    this.context = context;

    //loop in all widgets
    for (int i = 0; i < count; i++) {
        svcIntent = new Intent(context, CalenderRemoteViewsService.class);
        final int widgetId = appWidgetIds[i];
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_calender);
        remoteViews.setRemoteAdapter(R.id.calendar_pager, svcIntent);
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i], R.id.calendar_pager);
        HGDate hgDate = new HGDate();
        hgDate.toHigri();
        remoteViews.setTextViewText(R.id.textView8, Dates.getCurrentWeekDay());
        remoteViews.setTextViewText(R.id.textView7, NumbersLocal.convertToNumberTypeSystem(context, hgDate.getDay() + ""));
        remoteViews.setTextViewText(R.id.textView24, NumbersLocal.convertToNumberTypeSystem(context, hgDate.getYear() + ""));
        remoteViews.setTextViewText(R.id.curr_month_txt, Dates.islamicMonthName(context, hgDate.getMonth() - 1));
        remoteViews.setTextViewText(R.id.curr_month_txt_other, showOtherMonth(hgDate));

        PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
        remoteViews.setOnClickPendingIntent(R.id.relativeLayout, configPendingIntent);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);

    }
}
 
Example 31
Project: buildAPKsSamples   File: WeatherWidgetService.java   Source Code and License 5 votes vote down vote up
public RemoteViews getViewAt(int position) {
    // Get the data for this position from the content provider
    String day = "Unknown Day";
    int temp = 0;
    if (mCursor.moveToPosition(position)) {
        final int dayColIndex = mCursor.getColumnIndex(WeatherDataProvider.Columns.DAY);
        final int tempColIndex = mCursor.getColumnIndex(
                WeatherDataProvider.Columns.TEMPERATURE);
        day = mCursor.getString(dayColIndex);
        temp = mCursor.getInt(tempColIndex);
    }

    // Return a proper item with the proper day and temperature
    final String formatStr = mContext.getResources().getString(R.string.item_format_string);
    final int itemId = R.layout.widget_item;
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), itemId);
    rv.setTextViewText(R.id.widget_item, String.format(formatStr, temp, day));

    // Set the click intent so that we can handle it and show a toast message
    final Intent fillInIntent = new Intent();
    final Bundle extras = new Bundle();
    extras.putString(WeatherWidgetProvider.EXTRA_DAY_ID, day);
    fillInIntent.putExtras(extras);
    rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent);

    return rv;
}
 
Example 32
Project: QuranAndroid   File: QuranPageReadActivity.java   Source Code and License 5 votes vote down vote up
public void cancelNotification() {
    remoteViews = new RemoteViews(this.getPackageName(), R.layout.notification_download_progress);
    builder = new NotificationCompat.Builder(this)
            .setSmallIcon(aboveLollipopFlag ? R.drawable.ic_quran_trans : R.drawable.logo)
            .setColor(Color.parseColor("#3E686A"));
    builder.setAutoCancel(true);
}
 
Example 33
Project: PlusGram   File: MusicPlayerService.java   Source Code and License 5 votes vote down vote up
public void setListeners(RemoteViews view) {
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_previous, pendingIntent);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_close, pendingIntent);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_pause, pendingIntent);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_next, pendingIntent);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PLAY), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_play, pendingIntent);
}
 
Example 34
Project: airgram   File: MusicPlayerService.java   Source Code and License 5 votes vote down vote up
public void setListeners(RemoteViews view) {
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_previous, pendingIntent);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_CLOSE), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_close, pendingIntent);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_pause, pendingIntent);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_next, pendingIntent);
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PLAY), PendingIntent.FLAG_UPDATE_CURRENT);
    view.setOnClickPendingIntent(R.id.player_play, pendingIntent);
}
 
Example 35
Project: IdealMedia   File: NotificationUtils.java   Source Code and License 5 votes vote down vote up
public static RemoteViews getNotificationViews(final Track track, final Context context,  boolean isPlaying) {
    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notification);

    views.setTextViewText(R.id.notifTitle, track.getTitle());
    views.setTextViewText(R.id.notifArtist, track.getArtist());

    Bitmap cover =  MediaUtils.getArtworkQuick(context, track, 180, 180);
    if (cover != null)
        views.setImageViewBitmap(R.id.notifAlbum, cover);
    else
        views.setImageViewResource(R.id.notifAlbum,  R.drawable.ic_launcher);

    if (Build.VERSION.SDK_INT < 11) {
        views.setViewVisibility(R.id.action_prev, View.GONE);
        views.setViewVisibility(R.id.action_play, View.GONE);
        views.setViewVisibility(R.id.action_next, View.GONE);
    }

    views.setImageViewResource(R.id.action_play, isPlaying ? R.drawable.selector_pause_button : R.drawable.selector_play_button);

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

    Intent intentPlay = new Intent(PlayerService.PLAY);
    intentPlay.setComponent(componentName);
    views.setOnClickPendingIntent(R.id.action_play, PendingIntent.getService(context, 0, intentPlay, 0));

    Intent intentNext = new Intent(PlayerService.NEXT);
    intentNext.setComponent(componentName);
    views.setOnClickPendingIntent(R.id.action_next, PendingIntent.getService(context, 0, intentNext, 0));

    Intent intentPrevious = new Intent(PlayerService.PREV);
    intentPrevious.setComponent(componentName);
    views.setOnClickPendingIntent(R.id.action_prev, PendingIntent.getService(context, 0, intentPrevious, 0));

    return views;
}
 
Example 36
Project: ArtOfAndroid   File: MyAppWidgetProvider.java   Source Code and License 5 votes vote down vote up
/**
 * 更新桌面小部件
 */
private void onWidgetUpdate(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    Log.d(TAG, "appWidgetId = " + appWidgetId);

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.layout_widget);

    //设置点击事件
    Intent clickIntent = new Intent(ACTION_CLICK);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, clickIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.iv_widget, pendingIntent);

    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
 
Example 37
Project: CSipSimple   File: AccountWidgetProvider.java   Source Code and License 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
       // Update each requested appWidgetId
       for (int widgetId : appWidgetIds) {
       	RemoteViews view = buildUpdate(context, widgetId);
           appWidgetManager.updateAppWidget(widgetId, view);
       }
}
 
Example 38
Project: PingWidget   File: Util.java   Source Code and License 5 votes vote down vote up
public static void registerWidgetStartPauseOnClickListener(Context context, int widgetId, RemoteViews views) {

        //Register an Intent so that onClicks on the widget are received by PingWidgetProvider.onReceive()
        //Create an Intent, set PING_WIDGET_TOGGLE action to it, put EXTRA_APPWIDGET_ID as extra
        Intent clickIntent = new Intent(context, PingWidgetProvider.class);
        clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
        clickIntent.setAction(Constants.PING_WIDGET_TOGGLE);

        //Construct a PendingIntent using the Intent above
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, widgetId, clickIntent, 0);

        //Register pendingIntent in RemoteViews onClick
        views.setOnClickPendingIntent(R.id.widget_start_pause, pendingIntent);
    }
 
Example 39
Project: letv   File: LetvPushService.java   Source Code and License 5 votes vote down vote up
private RemoteViews createBigRemoteViews(Bitmap bitmapBig, String title, String subtitle) {
    if (bitmapBig == null) {
        return null;
    }
    RemoteViews bigView = new RemoteViews(getPackageName(), R.layout.push_layout_3);
    bigView.setImageViewBitmap(R.id.push_big_img, bitmapBig);
    bigView.setTextViewText(R.id.push_big_img_title, title);
    bigView.setTextViewText(R.id.push_big_img_title_subtitle, subtitle);
    return bigView;
}
 
Example 40
Project: DroidPlugin   File: INotificationManagerHookHandle.java   Source Code and License 5 votes vote down vote up
private boolean shouldBlockByRemoteViews(RemoteViews remoteViews) {
    if (remoteViews == null) {
        return false;
    } else if (remoteViews != null && sSystemLayoutResIds.containsKey(remoteViews.getLayoutId())) {
        return false;
    } else {
        return true;
    }
}
 
Example 41
Project: CCDownload   File: UploadService.java   Source Code and License 5 votes vote down vote up
@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);
		}

	}
}
 
Example 42
Project: fitnotifications   File: ServiceToggle.java   Source Code and License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    if (TOGGLE_CLICKED.equals(intent.getAction())) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget);
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        if (NLService.isEnabled()) {
            preferences.edit().putBoolean(context.getString(R.string.notification_listener_service_state_key), false).apply();
            NLService.setEnabled(false);
            views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red));
        } else {
            preferences.edit().putBoolean(context.getString(R.string.notification_listener_service_state_key), true).apply();
            NLService.setEnabled(true);
            views.setImageViewResource(R.id.widgetToggleButton,R.drawable.ic_speaker_notes_white_48dp);
            views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green);
            views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text));
            views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green));
        }

        views.setOnClickPendingIntent(
                R.id.widgetToggleButton,
                getPendingSelfIntent(context, 0, TOGGLE_CLICKED));

        ComponentName componentName = new ComponentName(context, ServiceToggle.class);
        appWidgetManager.updateAppWidget(componentName, views);
    }
}
 
Example 43
Project: TaipeiTechRefined   File: CourseWidgetProvider.java   Source Code and License 5 votes vote down vote up
private void showABCD(Context context, RemoteViews views,
                      boolean isDisplayABCD) {
    for (int row = 10; row < TABLE_ROW; row++) {
        int table_cell_id = context.getResources().getIdentifier(
                "course_widget_row_" + row, "id", context.getPackageName());
        views.setViewVisibility(table_cell_id, isDisplayABCD ? View.VISIBLE
                : View.GONE);
    }
}
 
Example 44
Project: PingWidget   File: PingWidgetUpdateService.java   Source Code and License 5 votes vote down vote up
private void handleWidgetClick(int widgetId) {
    //Get widget data from SharedPreferences
    PingWidgetData currentWidget = SharedPreferencesHelper.readPingWidgetData(getApplicationContext(), widgetId);


    PingAsyncTask task = mAsyncTasks.get(widgetId);
    if(currentWidget.isRunning()) {
        if(task != null && !task.isCancelled()) {
            Log.d(TAG, "ERROR: Task already running when trying to create a new one! ID=" + widgetId);
            task.cancel(true);

        } else {

            //Set widget_press_start to GONE
            PingWidgetData data = SharedPreferencesHelper.readPingWidgetData(getApplicationContext(), widgetId);

            if(data != null) {
                RemoteViews views = RemoteViewsUtil.getRemoteViews(getApplicationContext(), data.getWidgetLayoutType());

                views.setViewVisibility(R.id.widget_press_start, View.GONE);
                AppWidgetManager.getInstance(getApplicationContext()).updateAppWidget(widgetId, views);

                //Create a new task and run it, also save it to mAsyncTasks using widgetId
                task = new PingAsyncTask(this.getApplicationContext(), widgetId);
                mAsyncTasks.put(widgetId, task);

                //Get stored address from PreferenceSettings
                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, currentWidget.getAddress());
            }
        }
    } else {
        mAsyncTasks.remove(widgetId);

        if(task == null)
            Log.d(TAG, "ERROR: Could not find asyncTask to cancel! ID=" + widgetId);
        else if(!task.isCancelled())
            task.cancel(false);
    }
}
 
Example 45
Project: LaunchEnr   File: LauncherAppWidgetHostView.java   Source Code and License 5 votes vote down vote up
@Override
public void updateAppWidget(RemoteViews remoteViews) {
    // Store the orientation in which the widget was inflated
    updateLastInflationOrientation();
    super.updateAppWidget(remoteViews);

    // The provider info or the views might have changed.
    checkIfAutoAdvance();
}
 
Example 46
Project: MovingGdufe-Android   File: WidgetListProviderFactory.java   Source Code and License 5 votes vote down vote up
@Override
    public RemoteViews getViewAt(int position) {
        RemoteViews remoteView = new RemoteViews(mContext.getPackageName(), R.layout.desktop_widget_item);
        Schedule item = mData.get(position);
        remoteView.setTextViewText(R.id.widget_item_name, item.getName());
        remoteView.setTextViewText(R.id.widget_item_time, item.getStartSec()+"-"+item.getEndSec());
        remoteView.setTextViewText(R.id.widget_item_location, item.getLocation());

//        item点击事件调到app,setOnClickFillInIntent的第一个id为item布局的根布局,需要先在CourseAppWidgetProvider调用了setPendingIntentTemplate才生效
        Intent intent = new Intent(mContext, MainActivity.class);
        remoteView.setOnClickFillInIntent(R.id.desktop_widget_layout_item, intent);
        return remoteView;
    }
 
Example 47
Project: DailyStudy   File: MyAppWidgetProvider.java   Source Code and License 5 votes vote down vote up
private void onWidgetUpdate(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
    Intent intent = new Intent();
    intent.setAction(CLICK_ACTION);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    remoteViews.setOnClickPendingIntent(R.id.imageview, pendingIntent);
    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);

}
 
Example 48
Project: Espresso   File: AppWidgetProvider.java   Source Code and License 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {
        RemoteViews remoteViews = updateWidgetListView(context, appWidgetId);
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
 
Example 49
Project: QuranAndroid   File: DownloadManager.java   Source Code and License 5 votes vote down vote up
/**
 * Initialize and show notification of download failed
 */
public void showFailedNotification() {
    remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_download_failed);
    builder = new NotificationCompat
            .Builder(context)
            .setSmallIcon(aboveLollipopFlag ? R.drawable.ic_quran_trans : R.drawable.logo)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(context.getString(R.string.download_failed))
            .setColor(Color.parseColor("#3E686A"));
    notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}
 
Example 50
Project: DepressingThoughts   File: AppWidget.java   Source Code and License 5 votes vote down vote up
private static void settingUpViews(Context context, int appWidgetId) {
    CharSequence widgetText = context.getString(R.string.appwidget_text_loading);
    int backgroundColor = AppWidgetConfigureActivity.loadBackgroundColorPref(context, appWidgetId);
    int buttonColor = AppWidgetConfigureActivity.loadButtonColorPref(context, appWidgetId);
    int textColor = AppWidgetConfigureActivity.loadTextColorPref(context, appWidgetId);

    // Construct the RemoteViews object
    views = new RemoteViews(context.getPackageName(), R.layout.app_widget);
    views.setTextViewText(R.id.appwidgetText, widgetText);
    views.setTextViewTextSize(R.id.appwidgetText, TypedValue.COMPLEX_UNIT_SP, AppSettings.textSizeWidget(context));
    views.setInt(R.id.relativeLayout, "setBackgroundColor", backgroundColor);
    views.setTextColor(R.id.updateButton, buttonColor);
    views.setTextColor(R.id.appwidgetText, textColor);
}
 
Example 51
Project: MusicX-music-player   File: MusicxWidget4x2.java   Source Code and License 5 votes vote down vote up
private void defaultAppWidget(Context context, int[] appWidgetIds) {
    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
    views.setTextViewText(R.id.title, "Hello");
    views.setTextViewText(R.id.artist, "Adele");
    controls(views, context);
    pushUpdate(context, appWidgetIds, views);
}
 
Example 52
Project: buildAPKsSamples   File: StackWidgetService.java   Source Code and License 5 votes vote down vote up
public RemoteViews getViewAt(int position) {
    // position will always range from 0 to getCount() - 1.

    // We construct a remote views item based on our widget item xml file, and set the
    // text based on the position.
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
    rv.setTextViewText(R.id.widget_item, mWidgetItems.get(position).text);

    // Next, we set a fill-intent which will be used to fill-in the pending intent template
    // which is set on the collection view in StackWidgetProvider.
    Bundle extras = new Bundle();
    extras.putInt(StackWidgetProvider.EXTRA_ITEM, position);
    Intent fillInIntent = new Intent();
    fillInIntent.putExtras(extras);
    rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent);

    // You can do heaving lifting in here, synchronously. For example, if you need to
    // process an image, fetch something from the network, etc., it is ok to do it here,
    // synchronously. A loading view will show up in lieu of the actual contents in the
    // interim.
    try {
        System.out.println("Loading view " + position);
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    // Return the remote views object.
    return rv;
}
 
Example 53
Project: AnotherRSS   File: MyWidgetProvider.java   Source Code and License 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    final int count = appWidgetIds.length;
    final AlarmManager m = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final Calendar TIME = Calendar.getInstance();

    for (int i = 0; i < count; i++) {

        TIME.set(Calendar.MINUTE, 0);
        TIME.set(Calendar.SECOND, 0);
        TIME.set(Calendar.MILLISECOND, 0);
        Intent in = new Intent(context, WidgetUpdateService.class);

        if (service == null) {
            service = PendingIntent.getService(context, 0, in, PendingIntent.FLAG_CANCEL_CURRENT);
        }

        m.setRepeating(AlarmManager.RTC, TIME.getTime().getTime(), LONG_UPDATE, service);

        // ---------
        int widgetId = appWidgetIds[i];

        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main_widget);
        Intent intent = new Intent(context, MyWidgetProvider.class);

        intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                context, widgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT
        );
        remoteViews.setOnClickPendingIntent(R.id.wFeedtitlesLayout, pendingIntent);
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    }
}
 
Example 54
Project: RetroMusicPlayer   File: BaseAppWidget.java   Source Code and License 5 votes vote down vote up
protected void pushUpdate(final Context context, final int[] appWidgetIds, final RemoteViews views) {
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    if (appWidgetIds != null) {
        appWidgetManager.updateAppWidget(appWidgetIds, views);
    } else {
        appWidgetManager.updateAppWidget(new ComponentName(context, getClass()), views);
    }
}
 
Example 55
Project: PingWidget   File: PingWidgetProvider.java   Source Code and License 5 votes vote down vote up
@Override
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {
    Log.d(TAG, "onAppWidgetOptionsChanged() appWidgetId=" + appWidgetId);

    //int OPTION_APPWIDGET_MAX_HEIGHT = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, -1);
    //int OPTION_APPWIDGET_MAX_WIDTH = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, -1);
    //int OPTION_APPWIDGET_MIN_WIDTH = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, -1);
    int OPTION_APPWIDGET_MIN_HEIGHT = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, -1);
    Log.d(TAG, "onAppWidgetOptionsChanged() Changed widget size! New OPTION_APPWIDGET_MIN_HEIGHT = " + OPTION_APPWIDGET_MIN_HEIGHT);

    //Update SharedPreferenceData
    PingWidgetData data = SharedPreferencesHelper.readPingWidgetData(context, appWidgetId);

    if(data != null) {
        data.setWidgetLayoutType(WidgetLayoutType.getWidgetLayoutTypeByHeight(OPTION_APPWIDGET_MIN_HEIGHT));
        SharedPreferencesHelper.writePingWidgetData(context, appWidgetId, data);

        //Get new RemoteViews layout and update widget
        RemoteViews views = RemoteViewsUtil.getRemoteViews(context, data.getWidgetLayoutType());
        RemoteViewsUtil.initWidgetViews(context, views, data);

        //Register an Intent so that onClicks on the widget are received by PingWidgetProvider.onReceive()
        //Create an Intent, set PING_WIDGET_TOGGLE action to it, put EXTRA_APPWIDGET_ID as extra
        Util.registerWidgetStartPauseOnClickListener(context, appWidgetId, views);
        Util.registerWidgetReconfigureClickListener(context, appWidgetId, views);

        AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, views);
    }


    super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
}
 
Example 56
Project: MTweaks-KernelAdiutorMOD   File: Widget.java   Source Code and License 5 votes vote down vote up
@Override
public RemoteViews getViewAt(int position) {
    RemoteViews row = new RemoteViews(mContext.getPackageName(), R.layout.widget_profile_item);

    row.setTextViewText(R.id.text, mItems.get(position).getName());

    Intent i = new Intent();
    Bundle extras = new Bundle();

    extras.putInt(ITEM_ARG, position);
    i.putExtras(extras);
    row.setOnClickFillInIntent(R.id.text, i);

    return (row);
}
 
Example 57
Project: QuranAndroid   File: DownloadManager.java   Source Code and License 5 votes vote down vote up
/**
 * Initialize and show notification of download completes
 */
public void showCompleteNotification() {
    remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_download_finished);
    builder = new NotificationCompat
            .Builder(context)
            .setSmallIcon(aboveLollipopFlag ? R.drawable.ic_quran_trans : R.drawable.logo)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(context.getString(R.string.download_complete))
            .setColor(Color.parseColor("#3E686A"));
    builder.setContentIntent(notificationPending);
    notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}
 
Example 58
Project: TPlayer   File: NotificationCompatCompatV21.java   Source Code and License 4 votes vote down vote up
private ApplicationInfo getApplicationInfo(RemoteViews remoteViews) {
    if (remoteViews != null) {
        return mirror.android.widget.RemoteViews.mApplication.get(remoteViews);
    }
    return null;
}
 
Example 59
Project: BakingApp   File: RecipeIngredientsWidgetService.java   Source Code and License 4 votes vote down vote up
@Override
public RemoteViews getLoadingView() {
    return null;
}
 
Example 60
Project: android_packages_apps_ClockWidget   File: ClockWidget.java   Source Code and License 4 votes vote down vote up
private void setupActiveView(Context context, RemoteViews widget) {
    setClockAmPm(context, widget);
    setNextScheduledAlarm(context, widget);
    setupEditOnClick(context, widget);
}