Example usage for android.content Context getColor

List of usage examples for android.content Context getColor

Introduction

In this page you can find the example usage for android.content Context getColor.

Prototype

@ColorInt
public final int getColor(@ColorRes int id) 

Source Link

Document

Returns a color associated with a particular resource ID and styled for the current theme.

Usage

From source file:com.android.settings.sim.SimSelectNotification.java

private void createNotification(Context context) {
    final Resources resources = context.getResources();
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp)
            .setColor(context.getColor(R.color.sim_noitification))
            .setContentTitle(resources.getString(R.string.sim_notification_title))
            .setContentText(resources.getString(R.string.sim_notification_summary));
    Intent resultIntent = new Intent(context, SimSettingsActivity.class);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}

From source file:co.carlosandresjimenez.android.gotit.notification.AlarmReceiver.java

private void createNotification(Context context) {
    mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class),
            0);/*from   w ww  .  j  a v a  2 s  . com*/

    int color;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        color = context.getColor(R.color.colorPrimary);
    else
        color = context.getResources().getColor(R.color.colorPrimary);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_stat_got_it).setColor(color)
            .setContentTitle(context.getString(R.string.notification_title))
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(context.getString(R.string.notification_text)))
            .setContentText(context.getString(R.string.notification_text));

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.avapira.bobroreader.hanabira.HanabiraParser.java

public HanabiraParser(HanabiraPost post) {
    Context context = Hanabira.getFlower();
    if (!contextInitCompleted) {
        bulletMarginPerLevel = Utils.convertDpToPx(context.getApplicationContext(), 12);
        spoilerHiddenColor = context.getColor(R.color.dobro_dark);
        spoilerShownColor = context.getColor(R.color.dobro_primary_text);
        refLinkColor = context.getColor(R.color.dobro_ref_text);
        quoteColor = context.getColor(R.color.dobro_quote);
        showSpoilers = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_spoilers",
                false);// ww w.j a va  2s .  c  o  m
        contextInitCompleted = true;
    }
    this.post = post;
    builder = new SpannableStringBuilder(replaceInternalLinkWithReference(post.getMessage()));
    Linkify.addLinks(builder, Linkify.WEB_URLS);
}

From source file:ru.valle.btc.MainActivity.java

private static int getColor(Context context, int id) {
    if (Build.VERSION.SDK_INT >= 23) {
        return context.getColor(id);
    } else {/*from  w  w  w  .ja v  a  2  s  .c o m*/
        //noinspection deprecation
        return context.getResources().getColor(id);
    }
}

From source file:com.rexmtorres.android.patternlock.PatternLockView.java

@SuppressWarnings("deprecation")
public PatternLockView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mContext = getContext();/*from  w  ww  .  ja  va 2s  . co  m*/

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PatternLockView,
            R.attr.patternLockViewStyle, 0);
    final String aspect = a.getString(R.styleable.PatternLockView_aspect);
    if ("square".equals(aspect)) {
        mAspect = ASPECT_SQUARE;
    } else if ("lock_width".equals(aspect)) {
        mAspect = ASPECT_LOCK_WIDTH;
    } else if ("lock_height".equals(aspect)) {
        mAspect = ASPECT_LOCK_HEIGHT;
    } else {
        mAspect = ASPECT_SQUARE;
    }
    setClickable(true);
    mPathPaint.setAntiAlias(true);
    mPathPaint.setDither(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mRegularColor = context.getColor(R.color.lock_pattern_view_regular_color);
        mErrorColor = context.getColor(R.color.lock_pattern_view_error_color);
        mSuccessColor = context.getColor(R.color.lock_pattern_view_success_color);
    } else {
        Resources resources = context.getResources();

        mRegularColor = resources.getColor(R.color.lock_pattern_view_regular_color);
        mErrorColor = resources.getColor(R.color.lock_pattern_view_error_color);
        mSuccessColor = resources.getColor(R.color.lock_pattern_view_success_color);
    }

    mRegularColor = a.getColor(R.styleable.PatternLockView_regularColor, mRegularColor);
    mErrorColor = a.getColor(R.styleable.PatternLockView_errorColor, mErrorColor);
    mSuccessColor = a.getColor(R.styleable.PatternLockView_successColor, mSuccessColor);

    int pathColor = a.getColor(R.styleable.PatternLockView_pathColor, mRegularColor);

    // [START rexmtorres 20160401] If set, replaces the pattern dots with the specified bitmap.
    Drawable oDotDrawable = a.getDrawable(R.styleable.PatternLockView_dotBitmap);

    if (oDotDrawable != null) {
        if (oDotDrawable instanceof BitmapDrawable) {
            m_oDotBitmap = ((BitmapDrawable) oDotDrawable).getBitmap();
            m_oBigDotBitmap = Bitmap.createScaledBitmap(m_oDotBitmap, (int) (m_oDotBitmap.getWidth() * 1.25),
                    (int) (m_oDotBitmap.getHeight() * 1.25), false);
        }
    }
    // [END rexmtorres 20160401]

    a.recycle();

    mPathPaint.setColor(pathColor);
    mPathPaint.setStyle(Paint.Style.STROKE);
    mPathPaint.setStrokeJoin(Paint.Join.ROUND);
    mPathPaint.setStrokeCap(Paint.Cap.ROUND);
    mPathWidth = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_line_width);
    mPathPaint.setStrokeWidth(mPathWidth);
    mDotSize = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_size);
    mDotSizeActivated = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_size_activated);
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mCellStates = new CellState[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            mCellStates[i][j] = new CellState();
            mCellStates[i][j].radius = mDotSize / 2;
            mCellStates[i][j].row = i;
            mCellStates[i][j].col = j;
            mCellStates[i][j].bitmapDot = m_oDotBitmap;
        }
    }

    mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    mLinearOutSlowInInterpolator = new LinearOutSlowInInterpolator();
    mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
    mAccessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
    mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
}