Example usage for android.content.res Resources getColor

List of usage examples for android.content.res Resources getColor

Introduction

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

Prototype

@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException 

Source Link

Document

Returns a color integer associated with a particular resource ID.

Usage

From source file:com.limewoodmedia.nsdroid.fragments.WACouncilFragment.java

private void setUpChartRenderer(XYMultipleSeriesRenderer chartRenderer) {
    Log.d(TAG, "Set up chart renderer");
    Resources r = getResources();
    float labelTextSize = r.getDimension(R.dimen.bar_chart_label_size);

    // For renderer
    forRenderer = new XYSeriesRenderer();
    forRenderer.setColor(r.getColor(R.color.wa_for));
    forRenderer.setChartValuesTextSize(labelTextSize);
    forRenderer.setDisplayChartValues(true);

    againstRenderer = new XYSeriesRenderer();
    againstRenderer.setColor(r.getColor(R.color.wa_against));
    againstRenderer.setChartValuesTextSize(labelTextSize);
    againstRenderer.setDisplayChartValues(true);

    chartRenderer.setZoomButtonsVisible(false);
    chartRenderer.setOrientation(XYMultipleSeriesRenderer.Orientation.HORIZONTAL);
    chartRenderer.setClickEnabled(true);
    chartRenderer.setInScroll(true);/*from  w  ww.ja  v a2  s.  co  m*/
    chartRenderer.setAntialiasing(true);
    chartRenderer.setShowLegend(false);
    chartRenderer.setTextTypeface(Typeface.DEFAULT);
    chartRenderer.setPanEnabled(false);
    chartRenderer.setShowLabels(false);
    chartRenderer.setXAxisMin(-0.5);
    chartRenderer.setXAxisMax(2.5);
    chartRenderer.setYAxisMin(0);
    chartRenderer.setXLabels(0);
    chartRenderer.setYLabels(0);
    chartRenderer.setBarWidth(r.getDimensionPixelSize(R.dimen.wa_bar_width));
    chartRenderer.setGridColor(Color.WHITE);
    chartRenderer.setMarginsColor(Color.WHITE);
    chartRenderer.setMargins(new int[] { 0, 0, 0, 0 });
    chartRenderer.setBackgroundColor(Color.WHITE);
    chartRenderer.setApplyBackgroundColor(true);
    chartRenderer.removeAllRenderers();
    chartRenderer.addSeriesRenderer(forRenderer);
    chartRenderer.addSeriesRenderer(againstRenderer);
}

From source file:com.youhei.easytools.view.progressbar.CircleProgressBar.java

/**
 * Update the background color of the mBgCircle image view.
 *//*from   w  w  w . j  av a 2s .co  m*/
@SuppressWarnings("deprecation")
public void setBackgroundColor(@ColorRes int colorRes) {
    if (getBackground() instanceof ShapeDrawable) {
        final Resources res = getResources();
        ((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(colorRes));
    }
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_piegraph, container, false);
    final Resources resources = getResources();
    final PieGraph pg = (PieGraph) v.findViewById(R.id.piegraph);
    final Button animateButton = (Button) v.findViewById(R.id.animatePieButton);
    PieSlice slice = new PieSlice();
    slice.setColor(resources.getColor(R.color.green_light));
    slice.setSelectedColor(resources.getColor(R.color.transparent_orange));
    slice.setValue(2);/*from w  w w  .j  a v  a2  s  .  c  o m*/
    slice.setTitle("first");
    pg.addSlice(slice);
    slice = new PieSlice();
    slice.setColor(resources.getColor(R.color.orange));
    slice.setValue(3);
    pg.addSlice(slice);
    slice = new PieSlice();
    slice.setColor(resources.getColor(R.color.purple));
    slice.setValue(8);
    pg.addSlice(slice);
    pg.setOnSliceClickedListener(new OnSliceClickedListener() {

        @Override
        public void onClick(int index) {
            Toast.makeText(getActivity(), "Slice " + index + " clicked", Toast.LENGTH_SHORT).show();
        }
    });

    Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    pg.setBackgroundBitmap(b);

    SeekBar seekBar = (SeekBar) v.findViewById(R.id.seekBarRatio);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            pg.setInnerCircleRatio(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    seekBar = (SeekBar) v.findViewById(R.id.seekBarPadding);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            pg.setPadding(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1)
        animateButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (PieSlice s : pg.getSlices())
                    s.setGoalValue((float) Math.random() * 10);
                pg.setDuration(1000);//default if unspecified is 300 ms
                pg.setInterpolator(new AccelerateDecelerateInterpolator());//default if unspecified is linear; constant speed
                pg.setAnimationListener(getAnimationListener());
                pg.animateToGoalValues();//animation will always overwrite. Pass true to call the onAnimationCancel Listener with onAnimationEnd

            }
        });
    return v;
}

From source file:com.grottworkshop.gwsprocessbutton.ActionProcessButton.java

@SuppressWarnings("deprecation")
private void init(Context context) {
    Resources res = context.getResources();

    mMode = Mode.ENDLESS;//from ww w  .  j  ava  2  s  . c  o  m

    //TODO: getColor depreciated
    mColor1 = res.getColor(R.color.holo_blue_bright);
    //TODO: getColor depreciated
    mColor2 = res.getColor(R.color.holo_green_light);
    //TODO: getColor depreciated
    mColor3 = res.getColor(R.color.holo_orange_light);
    //TODO: getColor depreciated
    mColor4 = res.getColor(R.color.holo_red_light);
}

From source file:com.demo.wpq.mydemo.customview.progressbar.QLKCircleProgressBar.java

/**
 * Update the background color of the mBgCircle image view.
 *//*from  w  ww  .j  a v a2s .  c  o  m*/

public void setBackgroundColor(@ColorRes int colorRes) {
    if (getBackground() instanceof ShapeDrawable) {
        final Resources res = getResources();
        ((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(colorRes));
    }
}

From source file:com.horry.MicroBlog.widget.mdprogressbar.CircleProgressBar.java

/**
 * Update the background color of the mBgCircle image view.
 *//*  ww  w  . ja v a 2s . c o m*/
public void setBackgroundColor(int colorRes) {
    if (getBackground() instanceof ShapeDrawable) {
        final Resources res = getResources();

        ((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(colorRes));

    }
}

From source file:com.chn.halo.view.progressbar.MaterialProgressBar.java

public void setColorSchemeResources(int... colorResIds) {
    final Resources res = getResources();
    int[] colorRes = new int[colorResIds.length];
    for (int i = 0; i < colorResIds.length; i++) {
        colorRes[i] = res.getColor(colorResIds[i]);
    }/*from w w w.  ja va  2s.c om*/
    setColorSchemeColors(colorRes);
}

From source file:com.androzic.waypoint.WaypointDetails.java

@SuppressLint("NewApi")
private void updateWaypointDetails(double lat, double lon) {
    Androzic application = Androzic.getApplication();
    AppCompatActivity activity = (AppCompatActivity) getActivity();

    activity.getSupportActionBar().setTitle(waypoint.name);

    View view = getView();/*from  ww  w. j a  v  a2 s .  c om*/

    final TextView coordsView = (TextView) view.findViewById(R.id.coordinates);
    coordsView.requestFocus();
    coordsView.setTag(Integer.valueOf(StringFormatter.coordinateFormat));
    coordsView.setText(StringFormatter.coordinates(" ", waypoint.latitude, waypoint.longitude));
    coordsView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int format = ((Integer) coordsView.getTag()).intValue() + 1;
            if (format == 5)
                format = 0;
            coordsView.setText(StringFormatter.coordinates(format, " ", waypoint.latitude, waypoint.longitude));
            coordsView.setTag(Integer.valueOf(format));
        }
    });

    if (waypoint.altitude != Integer.MIN_VALUE) {
        ((TextView) view.findViewById(R.id.altitude))
                .setText("\u2336 " + StringFormatter.elevationH(waypoint.altitude));
        view.findViewById(R.id.altitude).setVisibility(View.VISIBLE);
    } else {
        view.findViewById(R.id.altitude).setVisibility(View.GONE);
    }

    if (waypoint.proximity > 0) {
        ((TextView) view.findViewById(R.id.proximity))
                .setText("~ " + StringFormatter.distanceH(waypoint.proximity));
        view.findViewById(R.id.proximity).setVisibility(View.VISIBLE);
    } else {
        view.findViewById(R.id.proximity).setVisibility(View.GONE);
    }

    double dist = Geo.distance(lat, lon, waypoint.latitude, waypoint.longitude);
    double bearing = Geo.bearing(lat, lon, waypoint.latitude, waypoint.longitude);
    bearing = application.fixDeclination(bearing);
    String distance = StringFormatter.distanceH(dist) + " " + StringFormatter.angleH(bearing);
    ((TextView) view.findViewById(R.id.distance)).setText(distance);

    ((TextView) view.findViewById(R.id.waypointset)).setText(waypoint.set.name);

    if (waypoint.date != null) {
        view.findViewById(R.id.date_row).setVisibility(View.VISIBLE);
        ((TextView) view.findViewById(R.id.date))
                .setText(DateFormat.getDateFormat(activity).format(waypoint.date) + " "
                        + DateFormat.getTimeFormat(activity).format(waypoint.date));
    } else {
        view.findViewById(R.id.date_row).setVisibility(View.GONE);
    }

    if ("".equals(waypoint.description)) {
        view.findViewById(R.id.description_row).setVisibility(View.GONE);
    } else {
        WebView description = (WebView) view.findViewById(R.id.description);
        String descriptionHtml;
        try {
            TypedValue tv = new TypedValue();
            Theme theme = activity.getTheme();
            Resources resources = getResources();
            theme.resolveAttribute(android.R.attr.textColorPrimary, tv, true);
            int secondaryColor = resources.getColor(tv.resourceId);
            String css = String.format(
                    "<style type=\"text/css\">html,body{margin:0;background:transparent} *{color:#%06X}</style>\n",
                    (secondaryColor & 0x00FFFFFF));
            descriptionHtml = css + waypoint.description;
            description.setWebViewClient(new WebViewClient() {
                @SuppressLint("NewApi")
                @Override
                public void onPageFinished(WebView view, String url) {
                    view.setBackgroundColor(Color.TRANSPARENT);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
                }
            });
            description.setBackgroundColor(Color.TRANSPARENT);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                description.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
        } catch (Resources.NotFoundException e) {
            description.setBackgroundColor(Color.LTGRAY);
            descriptionHtml = waypoint.description;
        }

        WebSettings settings = description.getSettings();
        settings.setDefaultTextEncodingName("utf-8");
        settings.setAllowFileAccess(true);
        Uri baseUrl = Uri.fromFile(new File(application.dataPath));
        description.loadDataWithBaseURL(baseUrl.toString() + "/", descriptionHtml, "text/html", "utf-8", null);
        view.findViewById(R.id.description_row).setVisibility(View.VISIBLE);
    }
}

From source file:com.viewpagerindicator.EgouCirclePageIndicator.java

public EgouCirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*w  w  w  .j  a  va2s. c  o m*/

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);
    final float defaultIndicatorPadding = res.getDimension(R.dimen.default_indicator_padding);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);
    mCirclePadding = a.getDimension(R.styleable.CirclePageIndicator_circlePadding, defaultIndicatorPadding);

    Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    a.recycle();
}

From source file:com.androtex.viewpagerindicator.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle,
            R.style.Widget_CirclePageIndicator);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);
    mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke//from  www .ja  v  a2  s. com
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();
}