List of usage examples for android.graphics Color argb
@ColorInt public static int argb(float alpha, float red, float green, float blue)
From source file:edu.stanford.mobisocial.dungbeetle.model.Feed.java
public static int colorFor(String name, int alpha) { if (name == null) return Color.BLACK; int c = colorFor(name); return Color.argb(alpha, Color.red(c), Color.green(c), Color.blue(c)); }
From source file:app.witness.com.myapplication.plaint.ColorUtils.java
/** * Blend {@code color1} and {@code color2} using the given ratio. * * @param ratio of which to blend. 0.0 will return {@code color1}, 0.5 will give an even blend, * 1.0 will return {@code color2}. *///from w w w . jav a 2 s.c om public static @CheckResult @ColorInt int blendColors(@ColorInt int color1, @ColorInt int color2, @FloatRange(from = 0f, to = 1f) float ratio) { final float inverseRatio = 1f - ratio; float a = (Color.alpha(color1) * inverseRatio) + (Color.alpha(color2) * ratio); float r = (Color.red(color1) * inverseRatio) + (Color.red(color2) * ratio); float g = (Color.green(color1) * inverseRatio) + (Color.green(color2) * ratio); float b = (Color.blue(color1) * inverseRatio) + (Color.blue(color2) * ratio); return Color.argb((int) a, (int) r, (int) g, (int) b); }
From source file:net.saik0.android.examples.nestedpager.ChildFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); int realPosition = getArguments().getInt(REAL_POSITION, -1); int blue = realPosition * 15; TextView text1 = (TextView) view.findViewById(android.R.id.text1); text1.setText(String.format(getActivity().getString(R.string.fragment), realPosition + 1)); text1.setBackgroundColor(Color.argb(255, 0, 0, blue)); }
From source file:com.awt.supark.LayoutHandler.java
public void appBackgroundColorChange(View view, int time, int r, int g, int b) { ColorDrawable wBack = (ColorDrawable) view.getBackground(); int color = wBack.getColor(); int r1 = Color.red(color); int g1 = Color.green(color); int b1 = Color.blue(color); ObjectAnimator colorFade = ObjectAnimator.ofObject(view, "backgroundColor", new ArgbEvaluator(), Color.argb(255, r1, g1, b1), Color.argb(255, r, g, b)); colorFade.setDuration(time);/*from w w w .ja v a 2 s. c o m*/ colorFade.start(); }
From source file:com.hookedonplay.decoviewsample.SampleFit2Fragment.java
@Override protected void createTracks() { setDemoFinished(false);// w w w. jav a 2s . com final View view = getView(); final DecoView decoView = getDecoView(); if (view == null || decoView == null) { return; } view.setBackgroundColor(Color.argb(255, 196, 196, 128)); decoView.executeReset(); decoView.deleteAll(); final float mSeriesMax = 100f; SeriesItem seriesBack1Item = new SeriesItem.Builder(COLOR_BACK).setRange(0, mSeriesMax, mSeriesMax) .setLineWidth(getDimension(46)).build(); decoView.addSeries(seriesBack1Item); SeriesItem series1Item = new SeriesItem.Builder(COLOR_NEUTRAL).setRange(0, mSeriesMax, 0) .setInitialVisibility(false).setLineWidth(getDimension(46)).setCapRounded(true) .addEdgeDetail(new EdgeDetail(EdgeDetail.EdgeType.EDGE_INNER, COLOR_EDGE, 0.3f)) .setShowPointWhenEmpty(true).build(); mSeries1Index = decoView.addSeries(series1Item); TextView textListener = (TextView) view.findViewById(R.id.textProgress); addFitListener(series1Item, textListener); }
From source file:me.nereo.gztsg.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // setup shadow for drawer mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // setup content modal color mDrawerLayout.setScrimColor(Color.argb(100, 0, 0, 0)); final ActionBar mActionBar = getActionBar(); // display left to icon mActionBar.setDisplayHomeAsUpEnabled(true); // enable icon click mActionBar.setHomeButtonEnabled(true); mActionBar.setDisplayShowTitleEnabled(true); mActionBar.setTitle(R.string.app_name); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {// w w w . j a va 2 s . com @Override public void onDrawerClosed(View drawerView) { mActionBar.setTitle(R.string.app_name); // recreate option menu invalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { mActionBar.setTitle(R.string.setting_title); // recreate option menu invalidateOptionsMenu(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { attachSearchBookFragment(); } }
From source file:com.hookedonplay.decoviewsample.SampleEndcapFragment.java
@Override protected void createTracks() { setDemoFinished(false);//from w w w.j a va 2s . com final View view = getView(); final DecoView decoView = getDecoView(); if (view == null || decoView == null) { return; } view.setBackgroundColor(Color.argb(255, 196, 196, 128)); decoView.executeReset(); decoView.deleteAll(); final float mSeriesMax = 100f; SeriesItem seriesBack1Item = new SeriesItem.Builder(COLOR_BACK).setRange(0, mSeriesMax, mSeriesMax) .setLineWidth(getDimension(40)).build(); decoView.addSeries(seriesBack1Item); SeriesItem series1Item = new SeriesItem.Builder(COLOR_NEUTRAL).setRange(0, mSeriesMax, 0) .setInitialVisibility(false).setLineWidth(getDimension(30)).setEndCap(EndCapType.CAP_CONCAVE) .setShowPointWhenEmpty(true) .addEdgeDetail(new EdgeDetail(EdgeDetail.EdgeType.EDGE_INNER, COLOR_EDGE, 0.3f)).build(); mSeries1Index = decoView.addSeries(series1Item); TextView textListener = (TextView) view.findViewById(R.id.textProgress); addFitListener(series1Item, textListener); }
From source file:org.opensilk.common.ui.util.ThemeUtils.java
public static int setColorAlpha(int color, int alpha) { return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)); }
From source file:Main.java
public static Bitmap createRoundedFramedImage(Drawable imageDrawable, int borderThickness) { int size = Math.min(imageDrawable.getMinimumWidth(), imageDrawable.getMinimumHeight()); // Drawable imageDrawable = (image != null) ? new BitmapDrawable(image) : placeHolder; Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); float cornerRadius = size / 18f; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.RED);/*from w w w . j av a 2 s .co m*/ canvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); // Save the layer to apply the paint canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG); imageDrawable.draw(canvas); canvas.restore(); // FRAMING THE PHOTO float border = size / 15f; // 1. Create offscreen bitmap link: http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1035s Bitmap framedOutput = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas framedCanvas = new Canvas(framedOutput); // End of Step 1 // Start - TODO IMPORTANT - this section shouldn't be included in the final code // It's needed here to differentiate step 2 (red) with the background color of the activity // It's should be commented out after the codes includes step 3 onwards // Paint squaredPaint = new Paint(Paint.ANTI_ALIAS_FLAG); // squaredPaint.setColor(Color.BLUE); // framedCanvas.drawRoundRect(outerRect, 0f, 0f, squaredPaint); // End // 2. Draw an opaque rounded rectangle link: // http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1044s RectF innerRect = new RectF(border, border, size - border, size - border); Paint innerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); innerPaint.setColor(Color.RED); framedCanvas.drawRoundRect(innerRect, cornerRadius, cornerRadius, innerPaint); // 3. Set the Power Duff mode link: // http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1056s Paint outerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); outerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); // 4. Draw a translucent rounded rectangle link: // http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU outerPaint.setColor(Color.argb(100, 0, 0, 0)); framedCanvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, outerPaint); // 5. Draw the frame on top of original bitmap canvas.drawBitmap(framedOutput, 0f, 0f, null); return output; }
From source file:com.android.example.leanback.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //setup ViewPager mAdapter = new MoviePagerAdapter(getFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mAdapter);/*from www .j a v a 2 s .com*/ // Sliding tabs for viewpager SlidingTabLayout slidingTab = (SlidingTabLayout) findViewById(R.id.sliding_tabs); slidingTab.setViewPager(mPager); // slidingTab.setSelectedIndicatorColors(new int[]{getResources().getColor(android.R.color.white)}); slidingTab.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() { @Override public int getIndicatorColor(int position) { return getResources().getColor(R.color.accent); } @Override public int getDividerColor(int position) { return Color.argb(0, 0, 0, 0); } }); }