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

The following examples show how to use android.widget.RemoteViews#setTextViewCompoundDrawables() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeCatNotification.java    From timecat with Apache License 2.0 4 votes vote down vote up
/**
 * 设置contentView
 */
public void setContetView() {
    // 在2.3到5.1以前, 通知栏的背景是黑色的, 所以RemoteView的背景色可以设置为透明
    contentView = new RemoteViews(mContext.getPackageName(), R.layout.notification_trans);

    boolean isRun = SPHelper.getBoolean(Constants.TOTAL_SWITCH, true);

    boolean clipborad = SPHelper.getBoolean(Constants.MONITOR_CLIP_BOARD, true);
    boolean click = SPHelper.getBoolean(Constants.MONITOR_CLICK, true);


    String totalSwitch = !isRun ? mContext.getString(R.string.notify_total_switch_off) : mContext.getString(R.string.notify_total_switch_on);
    String monitorClick = !click ? mContext.getString(R.string.notify_monitor_click_off) : mContext.getString(R.string.notify_monitor_click_on);
    String monitorClipboard = !clipborad ? mContext.getString(R.string.notify_monitor_clipboard_off) : mContext.getString(R.string.notify_monitor_clipboard_on);

    int totalSwitccRes = !isRun ? R.drawable.notify_off : R.drawable.notify_on;
    int monitorClickRes = !click ? R.drawable.notify_click_off : R.drawable.notify_click_on;
    int monitorClipboardRes = !clipborad ? R.drawable.notify_clipboare_off : R.drawable.notify_clipboard_on;


    int totalSwitccColor = !isRun ? R.color.text_color_notify : R.color.colorPrimary;
    int monitorClickColor = !click ? R.color.text_color_notify : R.color.colorPrimary;
    int monitorClipboardColor = !clipborad ? R.color.text_color_notify : R.color.colorPrimary;


    //SettingActivity的跳转, 在SDK 3.0 (11)之上
    try {
        contentView.setViewVisibility(R.id.total_switch, View.VISIBLE);
        contentView.setOnClickPendingIntent(R.id.total_switch, createPendingIntent(mContext.getPackageName(), 123456, Constants.TOTAL_SWITCH_BROADCAST));
        contentView.setTextViewText(R.id.total_switch, totalSwitch);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            contentView.setTextViewCompoundDrawables(R.id.total_switch, 0, totalSwitccRes, 0, 0);
        }
        contentView.setTextColor(R.id.total_switch, mContext.getResources().getColor(totalSwitccColor));

        contentView.setViewVisibility(R.id.monitor_click, View.VISIBLE);
        contentView.setOnClickPendingIntent(R.id.monitor_click, createPendingIntent(mContext.getPackageName(), 123457, Constants.MONITOR_CLICK_BROADCAST));
        contentView.setTextViewText(R.id.monitor_click, monitorClick);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            contentView.setTextViewCompoundDrawables(R.id.monitor_click, 0, monitorClickRes, 0, 0);
        }
        contentView.setTextColor(R.id.monitor_click, mContext.getResources().getColor(monitorClickColor));

        contentView.setViewVisibility(R.id.monitor_clipboard, View.VISIBLE);
        contentView.setOnClickPendingIntent(R.id.monitor_clipboard, createPendingIntent(mContext.getPackageName(), 123458, Constants.MONITOR_CLIPBOARD_BROADCAST));
        contentView.setTextViewText(R.id.monitor_clipboard, monitorClipboard);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            contentView.setTextViewCompoundDrawables(R.id.monitor_clipboard, 0, monitorClipboardRes, 0, 0);
        }
        contentView.setTextColor(R.id.monitor_clipboard, mContext.getResources().getColor(monitorClipboardColor));

        contentView.setViewVisibility(R.id.universal_copy, View.VISIBLE);
        contentView.setOnClickPendingIntent(R.id.universal_copy, createPendingIntent(mContext, SplashActivity.class, Constants.NOTIFY_UNIVERSAL_COPY_BROADCAST));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            contentView.setTextViewCompoundDrawables(R.id.universal_copy, 0, R.drawable.notify_copy, 0, 0);
        }

        contentView.setViewVisibility(R.id.screen_cap, View.VISIBLE);
        contentView.setOnClickPendingIntent(R.id.screen_cap, createPendingIntent(mContext, ScreenCaptureActivity.class, Constants.NOTIFY_SCREEN_CAPTURE_OVER_BROADCAST));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            contentView.setTextViewCompoundDrawables(R.id.screen_cap, 0, R.drawable.notify_screen, 0, 0);
        }

    } catch (Exception ignored) {
    } catch (Error error) {
    }
    contentView.setOnClickPendingIntent(R.id.Layout_notify_msearch, createPendingIntent(mContext, SettingActivity.class));
    notification.contentView = contentView;
}