Example usage for android.graphics Color parseColor

List of usage examples for android.graphics Color parseColor

Introduction

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

Prototype

@ColorInt
public static int parseColor(@Size(min = 1) String colorString) 

Source Link

Document

Parse the color string, and return the corresponding color-int.

Usage

From source file:com.crearo.gpslogger.ui.fragments.display.GpsSimpleViewFragment.java

private void setColor(ImageView imgView, IconColorIndicator colorIndicator) {
    imgView.clearColorFilter();/*from  ww  w. ja va 2 s .com*/

    if (colorIndicator == IconColorIndicator.Inactive) {
        return;
    }

    int color = -1;
    switch (colorIndicator) {
    case Bad:
        color = Color.parseColor("#FFEEEE");
        break;
    case Good:
        color = ContextCompat.getColor(context, R.color.accentColor);
        break;
    case Warning:
        color = Color.parseColor("#D4FFA300");
        break;
    }

    imgView.setColorFilter(color);

}

From source file:com.marianhello.bgloc.LocationService.java

private Integer parseNotificationIconColor(String color) {
    int iconColor = 0;
    if (color != null) {
        try {//from  www. ja  v  a 2  s .  c  o m
            iconColor = Color.parseColor(color);
        } catch (IllegalArgumentException e) {
            log.error("Couldn't parse color from android options");
        }
    }
    return iconColor;
}

From source file:com.apptentive.android.sdk.util.Util.java

/**
 * The web standard for colors is RGBA, but Android uses ARGB. This method provides a way to convert RGBA to ARGB.
 *//*  w  w  w  . j  ava 2 s . co  m*/
public static Integer parseWebColorAsAndroidColor(String input) {
    // Swap if input is #RRGGBBAA, but not if it is #RRGGBB
    Boolean swapAlpha = (input.length() == 9);
    try {
        Integer ret = Color.parseColor(input);
        if (swapAlpha) {
            ret = (ret >>> 8) | ((ret & 0x000000FF) << 24);
        }
        return ret;
    } catch (IllegalArgumentException e) {
        //
    }
    return null;
}

From source file:com.example.sam.savemeapp.StatisticsFragment.java

/**
 * Sets up the initial legend with the contained categories shown
 * in the pie chart and bullet points with the corresponding colors.
 *//*w w w. ja  v a2s  .  c o m*/
public void setUpPiechart() {
    pieChart.getDescription().setEnabled(false);
    Legend pieL = pieChart.getLegend();
    Log.d("stats", Float.toString(pieL.getEntries().length));
    startLegend = pieL;
    LegendEntry[] legends = pieL.getEntries();
    pieL.setEnabled(false);
    mLegend.removeAllViews();
    //The default legend consist of TextViews and ImageViews which contains a bullet point.
    //The legends are contained inside of a horizontal LinearLayout which is contained in a vertical LinearLayout.
    for (int t = 0; t < legends.length - 1; t++) {
        LegendEntry x = legends[t];
        LinearLayout hLayout = new LinearLayout(getContext());
        hLayout.setLayoutParams(params);
        TextView tv = new TextView(getContext());
        tv.setText(x.label);
        tv.setTextColor(x.formColor);
        tv.setTypeface(fontLight);
        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                getResources().getDimension(R.dimen.statistics_main_text_size));
        tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
        LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        textViewParams.setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin));
        tv.setLayoutParams(textViewParams);
        ImageView iv = new ImageView(getContext());
        Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend);
        dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC);
        iv.setImageDrawable(dot);
        iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        hLayout.addView(iv);
        hLayout.addView(tv);
        mLegend.addView(hLayout);
    }

    designPiechart();

    pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
        private int color;

        @Override
        public void onValueSelected(Entry e, Highlight h) {
            //it creates new legends with the information of the subcategories when a
            // category in the pi chart is clicked
            ArrayList<LegendEntry> list = new ArrayList<>();
            mLegend.removeAllViews();
            if (e.getData().equals(Color.parseColor("#00a0ae"))) {
                for (LegendEntry x : startLegend.getEntries()) {
                    if (x.label.equals("Food & Beverage")) {
                        color = x.formColor;
                    }
                }
                list.add(new LegendEntry("Food & Beverage: "
                        + u.categories.get("Food & Beverage").get("Food & Beverage") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Restaurant & Caf: "
                        + u.categories.get("Food & Beverage").get("Restaurant & Caf") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry(
                        "Supermarket: " + u.categories.get("Food & Beverage").get("Supermarket") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                mLegend.removeAllViews();
                //This category legends consist of the main category in this case "Food & Beverage" in the top of the legend
                //and the sub categories bellow. The name is also shown together with the amount spend in that category.
                for (LegendEntry x : list) {
                    TextView tv = new TextView(getContext());
                    if (x.equals(list.get(0))) {
                        tv.setTypeface(fontBlack);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_main_text_size));
                    } else {
                        tv.setTypeface(fontLight);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_text_size));
                    }
                    tv.setText(x.label);
                    tv.setTextColor(color);
                    tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
                    mLegend.addView(tv);
                }
            } else if (e.getData().equals(Color.parseColor("#be3127"))) {
                for (LegendEntry x : startLegend.getEntries()) {
                    if (x.label.equals("Transportation")) {
                        color = x.formColor;
                    }
                }
                list.add(new LegendEntry("Transportation: "
                        + u.categories.get("Transportation").get("Transportation") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Public transport: "
                        + u.categories.get("Transportation").get("Public transport") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry(
                        "Taxi & Uber: " + u.categories.get("Transportation").get("Taxi & Uber") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry(
                        "Petrol: " + u.categories.get("Transportation").get("Petrol") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry(
                        "Maintenance: " + u.categories.get("Transportation").get("Maintenance") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                mLegend.removeAllViews();
                for (LegendEntry x : list) {
                    TextView tv = new TextView(getContext());
                    if (x.equals(list.get(0))) {
                        tv.setTypeface(fontBlack);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_main_text_size));
                    } else {
                        tv.setTypeface(fontLight);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_text_size));
                    }
                    tv.setText(x.label);
                    tv.setTextColor(color);
                    tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
                    mLegend.addView(tv);
                }
            } else if (e.getData().equals(Color.parseColor("#7dc725"))) {
                for (LegendEntry x : startLegend.getEntries()) {
                    if (x.label.equals("Shopping")) {
                        color = x.formColor;
                    }
                }
                list.add(new LegendEntry(
                        "Shopping: " + u.categories.get("Shopping").get("Shopping") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry(
                        "Clothing: " + u.categories.get("Shopping").get("Clothing") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry(
                        "Electronics: " + u.categories.get("Shopping").get("Electronics") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Books: " + u.categories.get("Shopping").get("Books") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Gifts: " + u.categories.get("Shopping").get("Gifts") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Other: " + u.categories.get("Shopping").get("Other") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                mLegend.removeAllViews();
                for (LegendEntry x : list) {
                    TextView tv = new TextView(getContext());
                    if (x.equals(list.get(0))) {
                        tv.setTypeface(fontBlack);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_main_text_size));
                    } else {
                        tv.setTypeface(fontLight);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_text_size));
                    }
                    tv.setText(x.label);
                    tv.setTextColor(color);
                    tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
                    mLegend.addView(tv);
                }
            } else if (e.getData().equals(Color.parseColor("#e88300"))) {
                for (LegendEntry x : startLegend.getEntries()) {
                    if (x.label.equals("Entertainment")) {
                        color = x.formColor;
                    }
                }
                list.add(new LegendEntry(
                        "Entertainment: " + u.categories.get("Entertainment").get("Entertainment") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry(
                        "Going out: " + u.categories.get("Entertainment").get("Going out") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry(
                        "Sports: " + u.categories.get("Entertainment").get("Sports") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                mLegend.removeAllViews();
                for (LegendEntry x : list) {
                    TextView tv = new TextView(getContext());
                    if (x.equals(list.get(0))) {
                        tv.setTypeface(fontBlack);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_main_text_size));
                    } else {
                        tv.setTypeface(fontLight);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_text_size));
                    }
                    tv.setText(x.label);
                    tv.setTextColor(color);
                    tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
                    mLegend.addView(tv);
                }
            } else if (e.getData().equals(Color.parseColor("#dc006d"))) {
                for (LegendEntry x : startLegend.getEntries()) {
                    if (x.label.equals("Health")) {
                        color = x.formColor;
                    }
                }
                list.add(new LegendEntry("Health: " + u.categories.get("Health").get("Health") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Doctor: " + u.categories.get("Health").get("Doctor") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Pharmacy: " + u.categories.get("Health").get("Pharmacy") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                mLegend.removeAllViews();
                for (LegendEntry x : list) {
                    TextView tv = new TextView(getContext());
                    if (x.equals(list.get(0))) {
                        tv.setTypeface(fontBlack);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_main_text_size));
                    } else {
                        tv.setTypeface(fontLight);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_text_size));
                    }
                    tv.setText(x.label);
                    tv.setTextColor(color);
                    tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
                    mLegend.addView(tv);
                }
            } else if (e.getData().equals(Color.parseColor("#1562a4"))) {
                for (LegendEntry x : startLegend.getEntries()) {
                    if (x.label.equals("Bills")) {
                        color = x.formColor;
                    }
                }
                list.add(new LegendEntry("Bills: " + u.categories.get("Bills").get("Bills") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Water: " + u.categories.get("Bills").get("Water") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry(
                        "Electricity: " + u.categories.get("Bills").get("Electricity") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Gas: " + u.categories.get("Bills").get("Gas") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Rent: " + u.categories.get("Bills").get("Rent") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Phone: " + u.categories.get("Bills").get("Phone") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(
                        new LegendEntry("Insurance: " + u.categories.get("Bills").get("Insurance") + u.currency,
                                Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("TV: " + u.categories.get("Bills").get("TV") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                list.add(new LegendEntry("Internet: " + u.categories.get("Bills").get("Internet") + u.currency,
                        Legend.LegendForm.SQUARE, 7f, 7f, null, color));
                mLegend.removeAllViews();
                for (LegendEntry x : list) {
                    TextView tv = new TextView(getContext());
                    if (x.equals(list.get(0))) {
                        tv.setTypeface(fontBlack);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_main_text_size));
                    } else {
                        tv.setTypeface(fontLight);
                        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                                getResources().getDimension(R.dimen.statistics_text_size));
                    }
                    tv.setText(x.label);
                    tv.setTextColor(color);
                    tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
                    mLegend.addView(tv);
                }
            }
        }

        @Override
        public void onNothingSelected() {
            //Sets up the default legend when nothing is selected
            pieChart = (PieChart) v.findViewById(R.id.piechart);
            pieChart.setUsePercentValues(true);
            LegendEntry[] legends = startLegend.getEntries();
            startLegend.setEnabled(false);
            mLegend.removeAllViews();
            for (LegendEntry x : legends) {
                LinearLayout hLayout = new LinearLayout(getContext());
                hLayout.setLayoutParams(params);
                TextView tv = new TextView(getContext());
                tv.setText(x.label);
                tv.setTextColor(x.formColor);
                tv.setTypeface(fontLight);
                tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,
                        getResources().getDimension(R.dimen.statistics_main_text_size));
                tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
                LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                textViewParams
                        .setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin));
                tv.setLayoutParams(textViewParams);
                ImageView iv = new ImageView(getContext());
                Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend);
                dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC);
                iv.setImageDrawable(dot);
                iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
                hLayout.addView(iv);
                hLayout.addView(tv);
                mLegend.addView(hLayout);
            }
        }
    });
}

From source file:com.skalski.websocketsclient.ActivityMain.java

@Override
public void onTextMessage(String payload) {

    try {/*ww w.  ja v a 2  s . co m*/

        Log.i(TAG_LOG, "New message from server");
        JSONObject jsonObj = new JSONObject(payload);

        if ((jsonObj.has(TAG_JSON_TYPE)) && (jsonObj.has(TAG_JSON_MSG))) {

            /*
             * Notification
             */
            if (jsonObj.getString(TAG_JSON_TYPE).equals("notification")) {

                if (ActivitySettings.pref_notifications_disabled(getBaseContext())) {

                    Log.i(TAG_LOG, "Notifications are disabled");

                } else {

                    int notification_id;

                    if (ActivitySettings.pref_multiple_notifications_disabled(getBaseContext()))
                        notification_id = 0;
                    else
                        notification_id = (int) System.currentTimeMillis();

                    /* create new notification */
                    Notification new_notification = new Notification.Builder(this)
                            .setContentTitle(getResources().getString(R.string.app_name))
                            .setContentText(jsonObj.getString(TAG_JSON_MSG))
                            .setSmallIcon(R.drawable.ic_launcher).build();
                    new_notification.defaults |= Notification.DEFAULT_ALL;
                    NotificationManager notificationManager = (NotificationManager) getSystemService(
                            NOTIFICATION_SERVICE);
                    notificationManager.notify(notification_id, new_notification);

                    appendText(cmdOutput, "[SERVER] Asynchronous Notification\n",
                            Color.parseColor("#ff0099cc"));
                }

                /*
                 * Standard message
                 */
            } else if (jsonObj.getString(TAG_JSON_TYPE).equals("standard")) {

                appendText(cmdOutput, "[SERVER] " + jsonObj.getString(TAG_JSON_MSG) + "\n",
                        Color.parseColor("#ff99cc00"));

                /*
                 * JSON object is not valid
                 */
            } else {
                show_info(getResources().getString(R.string.info_msg_4), false);
                Log.e(TAG_LOG, "Received invalid JSON from server");
            }
        }
    } catch (JSONException e) {

        /* JSON object is not valid */
        show_info(getResources().getString(R.string.info_msg_4), false);
        Log.e(TAG_LOG, "Received invalid JSON from server");
    }
}

From source file:at.alladin.rmbt.android.test.RMBTTestFragment.java

/**
 * //from  w  ww .ja  v a2s. co  m
 * @param view
 * @param inflater
 * @return
 */
private View createView(final View view, final LayoutInflater inflater, final Bundle savedInstanceState) {
    testView = (TestView) view.findViewById(R.id.test_view);
    graphView = (GraphView) view.findViewById(R.id.test_graph);
    infoView = (ViewGroup) view.findViewById(R.id.test_view_info_container);
    textView = (TextView) view.findViewById(R.id.test_text);
    qosProgressView = (ViewGroup) view.findViewById(R.id.test_view_qos_container);
    groupCountContainerView = (ViewGroup) view.findViewById(R.id.test_view_group_count_container);

    if (savedInstanceState != null) {
        if (testView != null) {
            testView.setHeaderString(savedInstanceState.getString("header_string"));
            testView.setSubHeaderString(
                    savedInstanceState.getString("sub_header_string", testView.getSubHeaderString()));
            testView.setResultPingString(
                    savedInstanceState.getString("ping_string", testView.getResultPingString()));
            testView.setResultDownString(
                    savedInstanceState.getString("down_string", testView.getResultDownString()));
            testView.setResultUpString(savedInstanceState.getString("up_string", testView.getResultUpString()));
        }

        if (textView != null) {
            textView.setText(savedInstanceState.getString("test_info"));
        }
    } else {
        if (textView != null) {
            textView.setText("\n\n\n");
        }
    }

    if (graphView != null) {
        if (speedGraphData == null) {
            speedGraph = SmoothGraph.addGraph(graphView, Color.parseColor("#00f940"), SMOOTHING_DATA_AMOUNT,
                    SMOOTHING_FUNCTION, false);
        } else {
            speedGraph = SmoothGraph.addGraph(graphView, SMOOTHING_DATA_AMOUNT, SMOOTHING_FUNCTION, false,
                    speedGraphData);
        }

        speedGraph.setMaxTime(GRAPH_MAX_NSECS);

        if (signalGraphData == null) {
            signalGraph = SimpleGraph.addGraph(graphView, Color.parseColor("#f8a000"), GRAPH_MAX_NSECS);
        } else {
            signalGraph = SimpleGraph.addGraph(graphView, GRAPH_MAX_NSECS, signalGraphData);
        }

        //graphView.getLabelInfoVerticalList().add(new GraphLabel(getActivity().getString(R.string.test_dbm), "#f8a000"));
        graphView.setRowLinesLabelList(ResultGraphView.SPEED_LABELS);
    }
    //uploadGraph = false;
    graphStarted = false;

    final Resources res = getActivity().getResources();
    final String progressTitle = res.getString(R.string.test_progress_title);
    final String progressText = res.getString(R.string.test_progress_text);

    lastShownWaitTime = -1;
    if (progressDialog == null) {
        progressDialog = ProgressDialog.show(getActivity(), progressTitle, progressText, true, false);
        progressDialog.setOnKeyListener(backKeyListener);
    }

    return view;
}

From source file:com.chalmers.feedlr.activity.FeedActivity.java

@Override
protected void onResume() {
    super.onResume();

    boolean isFacebookAuthorized = Clients.isAuthorized(Clients.FACEBOOK, this);
    facebookAuthButton.setText(isFacebookAuthorized ? res.getString(R.string.facebook_authorized)
            : res.getString(R.string.authorize_facebook));
    facebookAuthButton.setEnabled(!isFacebookAuthorized);
    if (isFacebookAuthorized) {
        facebookAuthButton.setTextColor(Color.parseColor("#919191"));
        facebookAuthButton.setBackgroundResource(R.drawable.facebook_logo_disabled);
    }//from   www .ja  v  a 2s. co  m

    boolean isTwitterAuthorized = Clients.isAuthorized(Clients.TWITTER, this);
    twitterAuthButton.setText(isTwitterAuthorized ? res.getString(R.string.twitter_authorized)
            : res.getString(R.string.authorize_twitter));
    twitterAuthButton.setEnabled(!isTwitterAuthorized);
    if (isTwitterAuthorized) {
        twitterAuthButton.setTextColor(Color.parseColor("#919191"));
        twitterAuthButton.setBackgroundResource(R.drawable.twitter_logo_disabled);
    }

    lbm.registerReceiver(receiver, intentFilter);

    // facebook kittens will die if this isn't called onResume
    clientHandler.extendFacebookAccessTokenIfNeeded();
}

From source file:com.example.sergey.currentweather.ui.fragment.MainFragment.java

private void initSwipe() {
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0,
            ItemTouchHelper.LEFT) {/*from w w  w .  jav a  2 s. c o m*/

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            int position = viewHolder.getAdapterPosition();
            if (direction == ItemTouchHelper.LEFT) {
                deleteData(mCityListAdapter.removeItem(position));
            }
        }

        @Override
        public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                float dX, float dY, int actionState, boolean isCurrentlyActive) {
            Bitmap icon;
            if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
                View itemView = viewHolder.itemView;
                float height = (float) itemView.getBottom() - (float) itemView.getTop();
                float width = height / 3;
                if (dX < 0) {
                    mPoint.setColor(Color.parseColor("#D32F2F"));
                    RectF background = new RectF((float) itemView.getRight() + dX, (float) itemView.getTop(),
                            (float) itemView.getRight(), (float) itemView.getBottom());
                    c.drawRect(background, mPoint);
                    icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_delete_white);
                    RectF icon_dest = new RectF((float) itemView.getRight() - 2 * width,
                            (float) itemView.getTop() + width, (float) itemView.getRight() - width,
                            (float) itemView.getBottom() - width);
                    c.drawBitmap(icon, null, icon_dest, mPoint);
                }
            }
            super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);
}

From source file:com.cuelogic.android.WheelIndicatorView.java

private void drawOnlyArc(WheelIndicatorItem indicatorItem, RectF surfaceRectF, float angle, float repeatAngle,
        Canvas canvas) {//from   www  . ja va  2s  . c om
    itemArcPaint.setColor(Color.parseColor("#FF9000"));
    itemEndPointsPaint.setColor(Color.parseColor("#FF9000"));

    // Draw arc
    canvas.drawArc(surfaceRectF, ANGLE_INIT_OFFSET, angle, false, itemArcPaint);

    //        // Draw top circle
    canvas.drawCircle(minDistViewSize / 2, 0 + itemsLineWidth, itemsLineWidth, itemEndPointsPaint);
    int topPosition = minDistViewSize / 2 - itemsLineWidth;

    // Draw end circle
    canvas.drawCircle(
            (float) (Math.cos(Math.toRadians(angle + ANGLE_INIT_OFFSET)) * topPosition + topPosition
                    + itemsLineWidth),
            (float) (Math.sin(Math.toRadians((angle + ANGLE_INIT_OFFSET))) * topPosition + topPosition
                    + itemsLineWidth),
            itemsLineWidth, itemEndPointsPaint);

    //        draw(indicatorItem, wheelBoundsRectF, repeatAngle, canvas);
}