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:Main.java

public static SpannableStringBuilder replaceTags(String str, int flag) {
    try {/* ww w. ja  va  2s .co m*/
        int start;
        int end;
        StringBuilder stringBuilder = new StringBuilder(str);
        if ((flag & FLAG_TAG_BR) != 0) {
            while ((start = stringBuilder.indexOf("<br>")) != -1) {
                stringBuilder.replace(start, start + 4, "\n");
            }
            while ((start = stringBuilder.indexOf("<br/>")) != -1) {
                stringBuilder.replace(start, start + 5, "\n");
            }
        }
        ArrayList<Integer> bolds = new ArrayList<>();
        if ((flag & FLAG_TAG_BOLD) != 0) {
            while ((start = stringBuilder.indexOf("<b>")) != -1) {
                stringBuilder.replace(start, start + 3, "");
                end = stringBuilder.indexOf("</b>");
                if (end == -1) {
                    end = stringBuilder.indexOf("<b>");
                }
                stringBuilder.replace(end, end + 4, "");
                bolds.add(start);
                bolds.add(end);
            }
        }
        ArrayList<Integer> colors = new ArrayList<>();
        if ((flag & FLAG_TAG_COLOR) != 0) {
            while ((start = stringBuilder.indexOf("<c#")) != -1) {
                stringBuilder.replace(start, start + 2, "");
                end = stringBuilder.indexOf(">", start);
                int color = Color.parseColor(stringBuilder.substring(start, end));
                stringBuilder.replace(start, end + 1, "");
                end = stringBuilder.indexOf("</c>");
                stringBuilder.replace(end, end + 4, "");
                colors.add(start);
                colors.add(end);
                colors.add(color);
            }
        }
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder);
        // for (int a = 0; a < bolds.size() / 2; a++) {
        // spannableStringBuilder.setSpan(
        // new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")),
        // bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        // }
        for (int a = 0; a < colors.size() / 3; a++) {
            spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3),
                    colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return spannableStringBuilder;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new SpannableStringBuilder(str);
}

From source file:Main.java

public static int parseColor(String inColor) {
    int reColor = 0;
    try {// w ww .j a  v a  2s. co m
        if (inColor != null && inColor.length() != 0) {
            inColor = inColor.replace(" ", "");
            if (inColor.charAt(0) == 'r') { //rgba
                int start = inColor.indexOf('(') + 1;
                int off = inColor.indexOf(')');
                inColor = inColor.substring(start, off);
                String[] rgba = inColor.split(",");
                int r = Integer.parseInt(rgba[0]);
                int g = Integer.parseInt(rgba[1]);
                int b = Integer.parseInt(rgba[2]);
                int a = Integer.parseInt(rgba[3]);
                reColor = (a << 24) | (r << 16) | (g << 8) | b;
            } else if (inColor.startsWith("#")) { // #
                String tmpColor = inColor.substring(1);
                if (3 == tmpColor.length()) {
                    char[] t = new char[6];
                    t[0] = tmpColor.charAt(0);
                    t[1] = tmpColor.charAt(0);
                    t[2] = tmpColor.charAt(1);
                    t[3] = tmpColor.charAt(1);
                    t[4] = tmpColor.charAt(2);
                    t[5] = tmpColor.charAt(2);
                    inColor = "#" + String.valueOf(t);
                }
                reColor = Color.parseColor(inColor);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        reColor = 0;
    }
    return reColor;
}

From source file:com.aloknath.splitmytrip.Activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.include);
    setSupportActionBar(toolbar);//w  w w.  j a  v  a  2s  .co  m
    getSupportActionBar().setTitle("Split My Trip");
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#8C000000")));

    android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager()
            .beginTransaction();
    Fragment_New_Trip fragment_new_trip = new Fragment_New_Trip();
    fragmentTransaction.replace(R.id.fragmentNewTrip, fragment_new_trip.newInstance("New Trip"));
    Fragment_Existing_Trip fragment_existing_trip = new Fragment_Existing_Trip();
    fragmentTransaction.replace(R.id.fragmentExistingTrip, fragment_existing_trip.newInstance("Existing Trip"));
    Fragment_Billing fragment_billing = new Fragment_Billing();
    fragmentTransaction.replace(R.id.fragmentBilling, fragment_billing.newInstance("Send Amount"));
    Fragment_Google_Maps fragment_google_maps = new Fragment_Google_Maps();
    fragmentTransaction.replace(R.id.fragmentgoogleMaps, fragment_google_maps.newInstance("Google Maps"));
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    fragmentTransaction.commit();

}

From source file:Main.java

/**
 * Gets the rounded corner bitmap./*w ww  .  j  ava  2  s .  co  m*/
 * 
 * @param bitmap
 *            the bitmap
 * @return the rounded corner bitmap
 */
public static Bitmap getRoundedCornerBitmap(Context context, Bitmap bitmap, Boolean create_circle) {
    DisplayMetrics mMetrics = context.getResources().getDisplayMetrics();
    float mScaleFactor = mMetrics.density;
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = Color.BLACK;
    final Paint paint = new Paint();
    int width = bitmap.getWidth();
    int height = (bitmap.getHeight() > width) ? width : bitmap.getHeight();
    final Rect rect = new Rect(0, 0, width, height);
    final RectF rectF = new RectF(rect);
    final float roundPx = (create_circle) ? (bitmap.getWidth() > 360) ? bitmap.getWidth() : 360 : 2;

    paint.setAntiAlias(true);
    paint.setColor(color);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    // draw border
    paint.setColor(Color.parseColor("#cccccc"));
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(0.5F * mScaleFactor);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    return output;
}

From source file:co.uk.sentinelweb.drawcustom.api.DrawCustomSetItem.java

public String fromJSON(JSONObject o) {
    try {/*from  w  w  w  .  ja  v  a2  s.co m*/
        width = o.getInt("width");
    } catch (JSONException e) {
    }
    try {
        height = o.getInt("height");
    } catch (JSONException e) {
    }
    try {
        String colorString = o.getString("bg");
        bgColor = Color.parseColor(colorString);
    } catch (Exception e) {
    }
    try {
        description = o.getString("description");
    } catch (JSONException e) {
    }
    try {
        String id = o.getString("id");
        return id;
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:com.conferenceengineer.android.iosched.io.TracksHandler.java

private static void parseTrack(TrackResponse track, ArrayList<ContentProviderOperation> batch) {
    ContentProviderOperation.Builder builder = ContentProviderOperation
            .newInsert(ScheduleContract.addCallerIsSyncAdapterParameter(ScheduleContract.Tracks.CONTENT_URI));
    builder.withValue(ScheduleContract.Tracks.TRACK_ID, track.getId());
    builder.withValue(ScheduleContract.Tracks.TRACK_NAME, track.getTitle());
    builder.withValue(ScheduleContract.Tracks.TRACK_COLOR, Color.parseColor(track.getColour()));
    builder.withValue(ScheduleContract.Tracks.TRACK_ABSTRACT, track.getDescription());
    builder.withValue(ScheduleContract.Tracks.TRACK_META, track.getMeta());
    builder.withValue(ScheduleContract.Tracks.TRACK_HASHTAG, ParserUtils.sanitizeId(track.getTitle()));
    batch.add(builder.build());/*from  ww  w.jav  a2 s  . c  o  m*/
}

From source file:com.echo.holographlibrarysample.MultiSeriesDonutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_multiseriesdonutgraph, container, false);
    MultiSeriesDonutGraph mg = (MultiSeriesDonutGraph) v.findViewById(R.id.multiseriesdonutgraph);

    MultiSeriesDonutSlice slice = new MultiSeriesDonutSlice();
    slice.setColor(Color.parseColor("#99CC00"));
    slice.setValue(2);/*w  w w  .ja  v  a2  s .  com*/
    mg.addSlice(0, slice);
    slice = new MultiSeriesDonutSlice();
    slice.setColor(Color.parseColor("#FFBB33"));
    slice.setValue(3);
    mg.addSlice(0, slice);
    slice = new MultiSeriesDonutSlice();
    slice.setColor(Color.parseColor("#AA66CC"));
    slice.setValue(8);
    mg.addSlice(0, slice);

    slice = new MultiSeriesDonutSlice();
    slice.setColor(Color.parseColor("#99CC00"));
    slice.setValue(8);
    mg.addSlice(1, slice);
    slice = new MultiSeriesDonutSlice();
    slice.setColor(Color.parseColor("#FFBB33"));
    slice.setValue(5);
    mg.addSlice(1, slice);
    slice = new MultiSeriesDonutSlice();
    slice.setColor(Color.parseColor("#AA66CC"));
    slice.setValue(3);
    mg.addSlice(1, slice);

    mg.setOnSliceClickedListener(new MultiSeriesDonutGraph.OnSeriesSliceClickedListener() {
        @Override
        public void onClick(int series, int index) {
        }
    });

    return v;
}

From source file:com.busdrone.android.ui.VehicleMarkerRenderer.java

public Bitmap get(String color, String route) {
    String key = color + "_" + route;
    Bitmap bitmap = mCache.get(key);/* w  w w. j  av  a 2 s.  c  o  m*/
    if (bitmap != null) {
        return bitmap;
    }
    bitmap = render(Color.parseColor(color), route);
    mCache.put(key, bitmap);
    return bitmap;
}

From source file:com.avolatile.randomdaily.IntroductionActivitySlideFragment1.java

@Override
public int getDefaultBackgroundColor() {
    return Color.parseColor("#4CAF50");
}

From source file:com.avolatile.randomdaily.IntroductionActivitySlideFragment2.java

@Override
public int getDefaultBackgroundColor() {
    return Color.parseColor("#2D2D2D");
}