Example usage for android.graphics Color argb

List of usage examples for android.graphics Color argb

Introduction

In this page you can find the example usage for android.graphics Color argb.

Prototype

@ColorInt
public static int argb(float alpha, float red, float green, float blue) 

Source Link

Document

Return a color-int from alpha, red, green, blue float components in the range \([0..1]\).

Usage

From source file:oak.demo.svg.AnimatedWtaLogoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRootView = inflater.inflate(R.layout.fragment_animated_wta_logo, container, false);
    mSubtitleView = mRootView.findViewById(R.id.logo_subtitle);

    mLogoView = (AnimatedSvgView) mRootView.findViewById(R.id.animated_logo);
    mLogoView.setOnStateChangeListener(new AnimatedSvgView.OnStateChangeListener() {
        @Override/*from  w w w  .  j  a  va  2  s .  c  om*/
        public void onStateChange(int state) {
            if (state == AnimatedSvgView.STATE_FILL_STARTED) {
                ViewHelper.setAlpha(mSubtitleView, 0);
                mSubtitleView.setVisibility(View.VISIBLE);
                //mSubtitleView.setTranslationX(-mSubtitleView.getWidth());

                // Bug in older versions where set.setInterpolator didn't work
                AnimatorSet set = new AnimatorSet();
                Interpolator interpolator = new AccelerateInterpolator();
                ObjectAnimator a1 = ObjectAnimator.ofFloat(mLogoView, "translationX", 0);
                ObjectAnimator a2 = ObjectAnimator.ofFloat(mSubtitleView, "translationX", 0);
                ObjectAnimator a3 = ObjectAnimator.ofFloat(mSubtitleView, "alpha", 1);
                a1.setInterpolator(interpolator);
                a2.setInterpolator(interpolator);
                set.setDuration(500).playTogether(a1, a2, a3);
                set.start();

                if (mOnFillStartedCallback != null) {
                    mOnFillStartedCallback.run();
                }
            }
        }
    });
    mLogoView.setGlyphStrings(WtaLogoPaths.CIRCLE_ONLY_GLYPHS);
    int tc = Color.argb(255, 0, 0, 0);
    int rc = Color.argb(50, 0, 0, 0);
    int[] fillAlphas = new int[WtaLogoPaths.CIRCLE_ONLY_GLYPHS.length];
    int[] fillReds = new int[WtaLogoPaths.CIRCLE_ONLY_GLYPHS.length];
    int[] fillGreens = new int[WtaLogoPaths.CIRCLE_ONLY_GLYPHS.length];
    int[] fillBlues = new int[WtaLogoPaths.CIRCLE_ONLY_GLYPHS.length];
    int[] traceColors = new int[WtaLogoPaths.CIRCLE_ONLY_GLYPHS.length];
    int[] residueColors = new int[WtaLogoPaths.CIRCLE_ONLY_GLYPHS.length];
    for (int i = 0; i < WtaLogoPaths.CIRCLE_ONLY_GLYPHS.length; i++) {
        fillAlphas[i] = 255;
        fillReds[i] = 136;
        fillGreens[i] = 194;
        fillBlues[i] = 200;
        traceColors[i] = tc;
        residueColors[i] = rc;
    }
    mLogoView.setFillPaints(fillAlphas, fillReds, fillGreens, fillBlues);
    mLogoView.setTraceColors(traceColors);
    mLogoView.setTraceResidueColors(residueColors);
    return mRootView;
}

From source file:com.ibm.demo.IoTStarter.utils.MessageConductor.java

/**
 * Steer incoming MQTT messages to the proper activities based on their content.
 *
 * @param payload The log of the MQTT message.
 * @param topic The topic the MQTT message was received on.
 * @throws JSONException If the message contains invalid JSON.
 *///from ww  w  .j av  a 2 s . c  om
public void steerMessage(String payload, String topic) throws JSONException {
    Log.d(TAG, ".steerMessage() entered");
    JSONObject top = new JSONObject(payload);
    JSONObject d = top.getJSONObject("d");

    if (topic.contains(Constants.COLOR_EVENT)) {
        Log.d(TAG, "Color Event");
        int r = d.getInt("r");
        int g = d.getInt("g");
        int b = d.getInt("b");

        /*
         * nessage example publish to
         * iot-2/type/phao-mvk/id/8c705ae36b0c/cmd/color/fmt/json
         * 
         * {"d":{
        "r": "150",
        "g": "50",
        "b": "10",
        "alpha":"0.5"}}
         */

        Log.d(TAG, ".steerMessage() - color r = " + d.getInt("r"));
        Log.d(TAG, ".steerMessage() - color g = " + d.getInt("g"));
        // alpha value received is 0.0 < a < 1.0 but Color.agrb expects 0 < a < 255
        int alpha = (int) (d.getDouble("alpha") * 255.0);
        if ((r > 255 || r < 0) || (g > 255 || g < 0) || (b > 255 || b < 0) || (alpha > 255 || alpha < 0)) {
            return;
        }

        app.setColor(Color.argb(alpha, r, g, b));

        String runningActivity = app.getCurrentRunningActivity();
        if (runningActivity != null && runningActivity.equals(IoTFragment.class.getName())) {
            Intent actionIntent = new Intent(Constants.APP_ID + Constants.INTENT_IOT);
            actionIntent.putExtra(Constants.INTENT_DATA, Constants.COLOR_EVENT);
            context.sendBroadcast(actionIntent);
        }
    } else if (topic.contains(Constants.LIGHT_EVENT)) {
        app.handleLightMessage();
    } else if (topic.contains(Constants.TEXT_EVENT)) {
        int unreadCount = app.getUnreadCount();
        app.setUnreadCount(++unreadCount);

        // save payload in an arrayList
        List messageRecvd = new ArrayList<String>();
        messageRecvd.add(payload);

        app.getMessageLog().add(d.getString("text"));

        String runningActivity = app.getCurrentRunningActivity();
        if (runningActivity != null && runningActivity.equals(LogFragment.class.getName())) {
            Intent actionIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOG);
            actionIntent.putExtra(Constants.INTENT_DATA, Constants.TEXT_EVENT);
            context.sendBroadcast(actionIntent);
        }

        Intent unreadIntent;
        if (runningActivity.equals(LogFragment.class.getName())) {
            unreadIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOG);
        } else if (runningActivity.equals(LoginFragment.class.getName())) {
            unreadIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOGIN);
        } else if (runningActivity.equals(IoTFragment.class.getName())) {
            unreadIntent = new Intent(Constants.APP_ID + Constants.INTENT_IOT);
        } else if (runningActivity.equals(ProfilesActivity.class.getName())) {
            unreadIntent = new Intent(Constants.APP_ID + Constants.INTENT_PROFILES);
        } else {
            return;
        }

        String messageText = d.getString("text");
        if (messageText != null) {
            unreadIntent.putExtra(Constants.INTENT_DATA, Constants.UNREAD_EVENT);
            context.sendBroadcast(unreadIntent);
        }
    } else if (topic.contains(Constants.ALERT_EVENT)) {
        // save payload in an arrayList
        int unreadCount = app.getUnreadCount();
        app.setUnreadCount(++unreadCount);

        List messageRecvd = new ArrayList<String>();
        messageRecvd.add(payload);

        app.getMessageLog().add(d.getString("text"));

        String runningActivity = app.getCurrentRunningActivity();
        if (runningActivity != null) {
            if (runningActivity.equals(LogFragment.class.getName())) {
                Intent actionIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOG);
                actionIntent.putExtra(Constants.INTENT_DATA, Constants.TEXT_EVENT);
                context.sendBroadcast(actionIntent);
            }

            Intent alertIntent;
            if (runningActivity.equals(LogFragment.class.getName())) {
                alertIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOG);
            } else if (runningActivity.equals(LoginFragment.class.getName())) {
                alertIntent = new Intent(Constants.APP_ID + Constants.INTENT_LOGIN);
            } else if (runningActivity.equals(IoTFragment.class.getName())) {
                alertIntent = new Intent(Constants.APP_ID + Constants.INTENT_IOT);
            } else if (runningActivity.equals(ProfilesActivity.class.getName())) {
                alertIntent = new Intent(Constants.APP_ID + Constants.INTENT_PROFILES);
            } else {
                return;
            }

            String messageText = d.getString("text");
            if (messageText != null) {
                alertIntent.putExtra(Constants.INTENT_DATA, Constants.ALERT_EVENT);
                alertIntent.putExtra(Constants.INTENT_DATA_MESSAGE, d.getString("text"));
                context.sendBroadcast(alertIntent);
            }
        }
    }
}

From source file:de.markusressel.android.tutorialtooltip.DialogFragmentTest.java

private void showTutorialTooltip() {
    // custom message view
    CardMessageView cardMessageView = new CardMessageView(getActivity());
    @ColorInt//from   w  ww .  ja v a  2  s  .c  om
    int transparentWhite = Color.argb(255, 255, 255, 255);
    cardMessageView.setBorderColor(Color.BLACK);

    // custom indicator view
    WaveIndicatorView waveIndicatorView = new WaveIndicatorView(getActivity());
    waveIndicatorView.setStrokeWidth(10); // customization that is not included in the IndicatorBuilder

    TutorialTooltipBuilder tutorialTooltipBuilder = new TutorialTooltipBuilder(getActivity()).anchor(button)
            .attachToDialog(getDialog())
            .message(new MessageBuilder().customView(cardMessageView).offset(0, 0)
                    .text("This is a tutorial message!\nNow with two lines!").textColor(Color.BLACK)
                    .backgroundColor(Color.WHITE).gravity(TutorialTooltipView.Gravity.TOP) // relative to the indicator
                    .onClick(new OnMessageClickedListener() {
                        @Override
                        public void onMessageClicked(int id, TutorialTooltipView tutorialTooltipView,
                                TutorialTooltipMessage message, View messageView) {
                            // this will intercept touches only for the message view
                            // if you don't want the main OnTutorialTooltipClickedListener listener
                            // to react to touches here just specify an empty OnMessageClickedListener

                            TutorialTooltip.remove(getDialog(), id, true);
                        }
                    }).size(MessageBuilder.WRAP_CONTENT, MessageBuilder.WRAP_CONTENT).build())
            .indicator(new IndicatorBuilder().customView(waveIndicatorView).offset(0, 0)
                    .size(IndicatorBuilder.MATCH_ANCHOR, IndicatorBuilder.MATCH_ANCHOR).color(Color.BLUE)
                    .onClick(new OnIndicatorClickedListener() {
                        @Override
                        public void onIndicatorClicked(int id, TutorialTooltipView tutorialTooltipView,
                                TutorialTooltipIndicator indicator, View indicatorView) {
                            // this will intercept touches only for the indicator view
                            // if you don't want the main OnTutorialTooltipClickedListener listener
                            // to react to touches here just specify an empty OnIndicatorClickedListener

                            TutorialTooltip.remove(getDialog(), id, true);
                        }
                    }).build())
            .onClick(new OnTutorialTooltipClickedListener() {
                @Override
                public void onTutorialTooltipClicked(int id, TutorialTooltipView tutorialTooltipView) {
                    // this will intercept touches of the complete window
                    // if you don't specify additional listeners for the indicator or
                    // message view they will be included

                    TutorialTooltip.remove(getDialog(), id, true);
                }
            }).build();

    TutorialTooltip.show(tutorialTooltipBuilder);
}

From source file:com.jjoe64.graphview_demos.fragments.Styling.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    GraphView graph = (GraphView) rootView.findViewById(R.id.graph);

    DataPoint[] points = new DataPoint[30];
    for (int i = 0; i < 30; i++) {
        points[i] = new DataPoint(i, Math.sin(i * 0.5) * 20 * (Math.random() * 10 + 1));
    }/*from  w  w  w .j  av a 2 s  . c o m*/
    LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(points);

    points = new DataPoint[15];
    for (int i = 0; i < 15; i++) {
        points[i] = new DataPoint(i * 2, Math.sin(i * 0.5) * 20 * (Math.random() * 10 + 1));
    }
    LineGraphSeries<DataPoint> series2 = new LineGraphSeries<DataPoint>(points);

    // styling grid/labels
    graph.getGridLabelRenderer().setGridColor(Color.RED);
    graph.getGridLabelRenderer().setHighlightZeroLines(false);
    graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.GREEN);
    graph.getGridLabelRenderer().setVerticalLabelsColor(Color.RED);
    graph.getGridLabelRenderer().setVerticalLabelsAlign(Paint.Align.LEFT);
    graph.getGridLabelRenderer().setLabelVerticalWidth(150);
    graph.getGridLabelRenderer().setTextSize(40);
    graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.HORIZONTAL);
    graph.getGridLabelRenderer().reloadStyles();

    // styling viewport
    graph.getViewport().setBackgroundColor(Color.argb(255, 222, 222, 222));

    // styling series
    series.setTitle("Random Curve 1");
    series.setColor(Color.GREEN);
    series.setDrawDataPoints(true);
    series.setDataPointsRadius(10);
    series.setThickness(8);

    series2.setTitle("Random Curve 2");
    series2.setDrawBackground(true);
    series2.setBackgroundColor(Color.argb(100, 255, 255, 0));
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(10);
    paint.setPathEffect(new DashPathEffect(new float[] { 8, 5 }, 0));
    series2.setCustomPaint(paint);

    // styling legend
    graph.getLegendRenderer().setVisible(true);
    graph.getLegendRenderer().setTextSize(25);
    graph.getLegendRenderer().setBackgroundColor(Color.argb(150, 50, 0, 0));
    graph.getLegendRenderer().setTextColor(Color.WHITE);
    //graph.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP);
    //graph.getLegendRenderer().setMargin(30);
    graph.getLegendRenderer().setFixedPosition(150, 0);

    graph.addSeries(series);
    graph.addSeries(series2);

    return rootView;
}

From source file:com.nkc.education.service.NotificationHelper.java

/**
 * Basic Text Notification for Task Butler, using NotificationCompat
 *
 * @param context//from   w w  w  .  j av  a 2 s  . c o  m
        
 */
public void sendBasicNotification(Context context, Task task) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean vibrate = prefs.getBoolean(AppConfig.VIBRATE_ON_ALARM, true);
    int alarmInterval;
    int alarmUnits;

    if (task.hasFinalDateDue()) {
        alarmInterval = Integer.parseInt(prefs.getString(AppConfig.ALARM_TIME, AppConfig.DEFAULT_ALARM_TIME));
        alarmUnits = Calendar.MINUTE;
    } else {
        alarmInterval = Integer
                .parseInt(prefs.getString(AppConfig.REMINDER_TIME, AppConfig.DEFAULT_REMINDER_TIME));
        alarmUnits = Calendar.HOUR_OF_DAY;
    }

    Calendar next_reminder = GregorianCalendar.getInstance();
    next_reminder.add(alarmUnits, alarmInterval);

    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setContentIntent(getPendingIntent(context, task.getID()))
            .setContentInfo(Task.PRIORITY_LABELS[task.getPriority()]).setContentTitle(task.getName())
            .setContentText(task.getDetail())
            .setDefaults(vibrate ? Notification.DEFAULT_ALL
                    : Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
            .setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? R.drawable.ic_exam_name
                    : R.drawable.ic_exam_name)
            .setLargeIcon(bitmap).setTicker(task.getName()).setPriority(Notification.PRIORITY_MAX)
            .setColor(Color.argb(255, 21, 149, 196)).setWhen(System.currentTimeMillis());

    @SuppressWarnings("deprecation")
    Notification notification = builder.getNotification();
    NotificationManager notificationManager = getNotificationManager(context);
    notificationManager.notify(task.getID(), notification);
}

From source file:com.simplecity.amp_library.utils.color.ColorHelper.java

/**
 * Finds a suitable alpha such that there's enough contrast.
 *
 * @param color the color to start searching from.
 * @param backgroundColor the color to ensure contrast against.
 * @param minRatio the minimum contrast ratio required.
 * @return the same color as {@param color} with potentially modified alpha to meet contrast
 *//*from w w w . jav  a2 s.c  om*/
private static int findAlphaToMeetContrast(int color, int backgroundColor, double minRatio) {
    int fg = color;
    int bg = backgroundColor;
    if (ColorUtilsFromCompat.calculateContrast(fg, bg) >= minRatio) {
        return color;
    }
    int startAlpha = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    int low = startAlpha, high = 255;
    for (int i = 0; i < 15 && high - low > 0; i++) {
        final int alpha = (low + high) / 2;
        fg = Color.argb(alpha, r, g, b);
        if (ColorUtilsFromCompat.calculateContrast(fg, bg) > minRatio) {
            high = alpha;
        } else {
            low = alpha;
        }
    }
    return Color.argb(high, r, g, b);
}

From source file:it.andreale.mdatetimepicker.date.MonthAdapter.java

@Override
public int getWeekDayColor() {
    int textColor = mController.getTextColor();
    return Color.argb(127, Color.red(textColor), Color.green(textColor), Color.blue(textColor));
}

From source file:cc.kenai.common.AnimatedSvgView.java

private void init(Context context, AttributeSet attrs) {
    mFillPaint = new Paint();
    mFillPaint.setAntiAlias(true);//from   w  w  w .j a  v  a  2  s.  com
    mFillPaint.setStyle(Paint.Style.FILL);

    mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARKER_LENGTH_DIP,
            getResources().getDisplayMetrics());

    mTraceColors = new int[1];
    mTraceColors[0] = Color.BLACK;
    mTraceResidueColors = new int[1];
    mTraceResidueColors[0] = Color.argb(50, 0, 0, 0);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView);

        mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        Log.i(TAG, "mViewportWidth=" + mViewportWidth);
        mRatioSizingInfo.aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);
        mRatioSizingInfo.aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);

        mTraceTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTime, 2000);
        mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTimePerGlyph, 1000);
        mFillStart = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillStart, 1200);
        mFillTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillTime, 1000);

        a.recycle();

        mViewport = new PointF(mViewportWidth, mViewportHeight);
    }
    loadConfig();
}

From source file:app.philm.in.view.InsetFrameLayout.java

public void setInsetBackgroundColor(int color) {
    Resources r = getResources();

    setInsetBackgroundColorRaw(Color.argb(Color.alpha(r.getColor(R.color.chrome_custom_background_alpha)),
            Color.red(color), Color.green(color), Color.blue(color)));
}

From source file:com.serchinastico.coolswitch.CoolSwitch.java

private void initialize() {
    backgroundAlpha = isChecked() ? MAX_BACKGROUND_ALPHA : MIN_BACKGROUND_ALPHA;

    setBackgroundColor(Color.argb(0, 0, 0, 0));
    setOnClickListener(this);
}