Search in sources :

Example 76 with RemoteViews

use of android.widget.RemoteViews in project AndroidChromium by JackyAndroid.

the class CustomTabBottomBarDelegate method showBottomBarIfNecessary.

/**
     * Makes the bottom bar area to show, if any.
     */
public void showBottomBarIfNecessary() {
    if (!mDataProvider.shouldShowBottomBar())
        return;
    RemoteViews remoteViews = mDataProvider.getBottomBarRemoteViews();
    if (remoteViews != null) {
        REMOTE_VIEWS_SHOWN.record();
        mClickableIDs = mDataProvider.getClickableViewIDs();
        mClickPendingIntent = mDataProvider.getRemoteViewsPendingIntent();
        showRemoteViews(remoteViews);
    } else {
        List<CustomButtonParams> items = mDataProvider.getCustomButtonsOnBottombar();
        if (items.isEmpty())
            return;
        LinearLayout layout = new LinearLayout(mActivity);
        layout.setId(R.id.custom_tab_bottom_bar_wrapper);
        layout.setBackgroundColor(mDataProvider.getBottomBarColor());
        for (CustomButtonParams params : items) {
            if (params.showOnToolbar())
                continue;
            final PendingIntent pendingIntent = params.getPendingIntent();
            OnClickListener clickListener = null;
            if (pendingIntent != null) {
                clickListener = new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        sendPendingIntentWithUrl(pendingIntent, null, mActivity);
                    }
                };
            }
            layout.addView(params.buildBottomBarButton(mActivity, getBottomBarView(), clickListener));
        }
        getBottomBarView().addView(layout);
    }
}
Also used : RemoteViews(android.widget.RemoteViews) OnClickListener(android.view.View.OnClickListener) PendingIntent(android.app.PendingIntent) View(android.view.View) LinearLayout(android.widget.LinearLayout)

Example 77 with RemoteViews

use of android.widget.RemoteViews in project AntennaPod by AntennaPod.

the class PlayerWidgetService method updateViews.

private void updateViews() {
    isUpdating = true;
    ComponentName playerWidget = new ComponentName(this, PlayerWidget.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    RemoteViews views = new RemoteViews(getPackageName(), R.layout.player_widget);
    PendingIntent startMediaplayer = PendingIntent.getActivity(this, 0, PlaybackService.getPlayerActivityIntent(this), 0);
    Intent startApp = new Intent(getBaseContext(), MainActivity.class);
    startApp.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startApp.putExtra(MainActivity.EXTRA_FRAGMENT_TAG, QueueFragment.TAG);
    PendingIntent startAppPending = PendingIntent.getActivity(getBaseContext(), 0, startApp, PendingIntent.FLAG_UPDATE_CURRENT);
    boolean nothingPlaying = false;
    if (playbackService != null) {
        final Playable media = playbackService.getPlayable();
        if (media != null) {
            PlayerStatus status = playbackService.getStatus();
            views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
            views.setTextViewText(R.id.txtvTitle, media.getEpisodeTitle());
            String progressString = getProgressString();
            if (progressString != null) {
                views.setViewVisibility(R.id.txtvProgress, View.VISIBLE);
                views.setTextViewText(R.id.txtvProgress, progressString);
            }
            if (status == PlayerStatus.PLAYING) {
                views.setImageViewResource(R.id.butPlay, R.drawable.ic_pause_white_24dp);
                if (Build.VERSION.SDK_INT >= 15) {
                    views.setContentDescription(R.id.butPlay, getString(R.string.pause_label));
                }
            } else {
                views.setImageViewResource(R.id.butPlay, R.drawable.ic_play_arrow_white_24dp);
                if (Build.VERSION.SDK_INT >= 15) {
                    views.setContentDescription(R.id.butPlay, getString(R.string.play_label));
                }
            }
            views.setOnClickPendingIntent(R.id.butPlay, createMediaButtonIntent());
        } else {
            nothingPlaying = true;
        }
    } else {
        nothingPlaying = true;
    }
    if (nothingPlaying) {
        // start the app if they click anything
        views.setOnClickPendingIntent(R.id.layout_left, startAppPending);
        views.setOnClickPendingIntent(R.id.butPlay, startAppPending);
        views.setViewVisibility(R.id.txtvProgress, View.INVISIBLE);
        views.setTextViewText(R.id.txtvTitle, this.getString(R.string.no_media_playing_label));
        views.setImageViewResource(R.id.butPlay, R.drawable.ic_play_arrow_white_24dp);
    }
    manager.updateAppWidget(playerWidget, views);
    isUpdating = false;
}
Also used : RemoteViews(android.widget.RemoteViews) Playable(de.danoeh.antennapod.core.util.playback.Playable) AppWidgetManager(android.appwidget.AppWidgetManager) PlayerStatus(de.danoeh.antennapod.core.service.playback.PlayerStatus) ComponentName(android.content.ComponentName) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 78 with RemoteViews

use of android.widget.RemoteViews in project OneSignal-Android-SDK by OneSignal.

the class GenerateNotification method addBackgroundImage.

// Keep 'throws Throwable' as 'onesignal_bgimage_notif_layout' may not be available
//    This maybe the case if a jar is used instead of an aar.
private static void addBackgroundImage(JSONObject gcmBundle, NotificationCompat.Builder notifBuilder) throws Throwable {
    // Required to right align image
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
        return;
    Bitmap bg_image = null;
    JSONObject jsonBgImage = null;
    String jsonStrBgImage = gcmBundle.optString("bg_img", null);
    if (jsonStrBgImage != null) {
        jsonBgImage = new JSONObject(jsonStrBgImage);
        bg_image = getBitmap(jsonBgImage.optString("img", null));
    }
    if (bg_image == null)
        bg_image = getBitmapFromAssetsOrResourceName("onesignal_bgimage_default_image");
    if (bg_image != null) {
        RemoteViews customView = new RemoteViews(currentContext.getPackageName(), R.layout.onesignal_bgimage_notif_layout);
        customView.setTextViewText(R.id.os_bgimage_notif_title, getTitle(gcmBundle));
        customView.setTextViewText(R.id.os_bgimage_notif_body, gcmBundle.optString("alert"));
        setTextColor(customView, jsonBgImage, R.id.os_bgimage_notif_title, "tc", "onesignal_bgimage_notif_title_color");
        setTextColor(customView, jsonBgImage, R.id.os_bgimage_notif_body, "bc", "onesignal_bgimage_notif_body_color");
        String alignSetting = null;
        if (jsonBgImage != null && jsonBgImage.has("img_align"))
            alignSetting = jsonBgImage.getString("img_align");
        else {
            int iAlignSetting = contextResources.getIdentifier("onesignal_bgimage_notif_image_align", "string", packageName);
            if (iAlignSetting != 0)
                alignSetting = contextResources.getString(iAlignSetting);
        }
        if ("right".equals(alignSetting)) {
            // Use os_bgimage_notif_bgimage_right_aligned instead of os_bgimage_notif_bgimage
            //    which has scaleType="fitEnd" set.
            // This is required as setScaleType can not be called through RemoteViews as it is an enum.
            customView.setViewPadding(R.id.os_bgimage_notif_bgimage_align_layout, -5000, 0, 0, 0);
            customView.setImageViewBitmap(R.id.os_bgimage_notif_bgimage_right_aligned, bg_image);
            // visible
            customView.setViewVisibility(R.id.os_bgimage_notif_bgimage_right_aligned, 0);
            // gone
            customView.setViewVisibility(R.id.os_bgimage_notif_bgimage, 2);
        } else
            customView.setImageViewBitmap(R.id.os_bgimage_notif_bgimage, bg_image);
        notifBuilder.setContent(customView);
        // Remove style to prevent expanding by the user.
        // Future: Create an extended image option, will need its own layout.
        notifBuilder.setStyle(null);
    }
}
Also used : Bitmap(android.graphics.Bitmap) RemoteViews(android.widget.RemoteViews) JSONObject(org.json.JSONObject) SpannableString(android.text.SpannableString) OSUtils.getResourceString(com.onesignal.OSUtils.getResourceString)

Example 79 with RemoteViews

use of android.widget.RemoteViews in project android_frameworks_base by DirtyUnicorns.

the class TestAppWidgetProvider method onReceive.

public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Log.d(TAG, "intent=" + intent);
    if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
        Log.d(TAG, "ENABLED");
    } else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
        Log.d(TAG, "DISABLED");
    } else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
        Log.d(TAG, "UPDATE");
        // BEGIN_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
        Bundle extras = intent.getExtras();
        int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        // END_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
        SharedPreferences prefs = context.getSharedPreferences(TestAppWidgetProvider.PREFS_NAME, 0);
        String prefix = prefs.getString(PREF_PREFIX_KEY, "hai");
        AppWidgetManager gm = AppWidgetManager.getInstance(context);
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
        views.setTextViewText(R.id.oh_hai_text, prefix + ": " + SystemClock.elapsedRealtime());
        if (false) {
            gm.updateAppWidget(appWidgetIds, views);
        } else {
            gm.updateAppWidget(new ComponentName("com.android.tests.appwidgethost", "com.android.tests.appwidgethost.TestAppWidgetProvider"), views);
        }
    }
}
Also used : RemoteViews(android.widget.RemoteViews) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 80 with RemoteViews

use of android.widget.RemoteViews in project SimplifyReader by chentao0707.

the class DownloadListenerImpl method createNotification.

/**
	 * TODO 创建通知对象
	 */
private static Notification createNotification(Context c) {
    Notification n = new Notification();
    Class<? extends Activity> cacheActivity = YoukuPlayerApplication.instance.getCachingActivityClass();
    Intent i = new Intent(c, cacheActivity);
    i.putExtra("go", "downloading");
    n.contentIntent = PendingIntent.getActivity(c, 4, i, PendingIntent.FLAG_UPDATE_CURRENT);
    n.contentView = new RemoteViews(c.getPackageName(), R.layout.notify);
    return n;
}
Also used : RemoteViews(android.widget.RemoteViews) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Aggregations

RemoteViews (android.widget.RemoteViews)217 Intent (android.content.Intent)86 PendingIntent (android.app.PendingIntent)77 TextView (android.widget.TextView)35 Test (org.junit.Test)35 Notification (android.app.Notification)30 SmallTest (android.support.test.filters.SmallTest)30 View (android.view.View)29 ImageView (android.widget.ImageView)28 AppWidgetManager (android.appwidget.AppWidgetManager)26 ComponentName (android.content.ComponentName)24 Bitmap (android.graphics.Bitmap)24 Bundle (android.os.Bundle)16 NavigationBarView (com.android.systemui.statusbar.phone.NavigationBarView)15 RemoteInputView (com.android.systemui.statusbar.policy.RemoteInputView)15 NotificationCompat (android.support.v4.app.NotificationCompat)14 Resources (android.content.res.Resources)12 StatusBarNotification (android.service.notification.StatusBarNotification)12 SharedPreferences (android.content.SharedPreferences)11 NotificationPanelView (com.android.systemui.statusbar.phone.NotificationPanelView)11