Example usage for android.graphics Paint setColor

List of usage examples for android.graphics Paint setColor

Introduction

In this page you can find the example usage for android.graphics Paint setColor.

Prototype

public void setColor(@ColorInt int color) 

Source Link

Document

Set the paint's color.

Usage

From source file:com.lemon.lime.MainActivity.java

private void addBarGraphRenderers() {
    Paint paint = new Paint();
    paint.setStrokeWidth(50f);/*from w  ww . j a  v  a 2  s .c o m*/
    paint.setAntiAlias(true);
    paint.setColor(Color.argb(200, 56, 138, 252));
    BarGraphRenderer barGraphRendererBottom = new BarGraphRenderer(16, paint, false);
    mVisualizerView.addRenderer(barGraphRendererBottom);

    Paint paint2 = new Paint();
    paint2.setStrokeWidth(12f);
    paint2.setAntiAlias(true);
    paint2.setColor(Color.argb(200, 181, 111, 233));
    BarGraphRenderer barGraphRendererTop = new BarGraphRenderer(4, paint2, true);
    mVisualizerView.addRenderer(barGraphRendererTop);
}

From source file:net.line2soft.preambul.views.SlippyMapActivity.java

/**
 * Creates a {@link Paint} object with a certain color
 * @param color The wanted color//  ww w  .  ja  v  a 2s.com
 * @param alpha The alpha channel
 * @return The created Paint object
 */
private Paint createPaint(int color, int alpha) {
    Paint pnt = new Paint(Paint.ANTI_ALIAS_FLAG);
    pnt.setColor(color);
    pnt.setAlpha(alpha);
    pnt.setStyle(Paint.Style.STROKE);
    pnt.setStrokeWidth(7);
    pnt.setStrokeJoin(Paint.Join.ROUND);
    pnt.setStrokeCap(Paint.Cap.ROUND);
    //pnt.setPathEffect(new DashPathEffect(new float[] { 20, 20 }, 0));
    return pnt;
}

From source file:ucsc.hci.rankit.DynamicListView.java

/** Draws a black border over the screenshot of the view passed in. */
private Bitmap getBitmapWithBorder(View v) {
    Bitmap bitmap = getBitmapFromView(v);
    Canvas can = new Canvas(bitmap);

    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(LINE_THICKNESS);
    paint.setColor(Color.WHITE);

    can.drawBitmap(bitmap, 0, 0, null);//from  w  w w. j  a v  a  2s .  c o m
    can.drawRect(rect, paint);

    return bitmap;
}

From source file:github.madmarty.madsonic.util.ImageLoader.java

private Bitmap createReflection(Bitmap originalImage) {

    //   int reflectionH = 80;

    int width = originalImage.getWidth();
    int height = originalImage.getHeight();

    // Height of reflection
    int reflectionHeight = height / 2;

    // The gap we want between the reflection and the original image
    final int reflectionGap = 4;

    // Create a new bitmap with same width but taller to fit reflection
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + reflectionHeight),
            Bitmap.Config.ARGB_8888);/*from   w w w  .ja  va2  s.co m*/

    //// ----

    Bitmap reflection = Bitmap.createBitmap(width, reflectionHeight, Bitmap.Config.ARGB_8888);
    Bitmap blurryBitmap = Bitmap.createBitmap(originalImage, 0, height - reflectionHeight, height,
            reflectionHeight);

    // cheap and easy scaling algorithm; down-scale it, then
    // upscale it. The filtering during the scale operations
    // will blur the resulting image
    blurryBitmap = Bitmap
            .createScaledBitmap(
                    Bitmap.createScaledBitmap(blurryBitmap, blurryBitmap.getWidth() / 2,
                            blurryBitmap.getHeight() / 2, true),
                    blurryBitmap.getWidth(), blurryBitmap.getHeight(), true);

    // This shadier will hold a cropped, inverted,
    // blurry version of the original image
    BitmapShader bitmapShader = new BitmapShader(blurryBitmap, TileMode.CLAMP, TileMode.CLAMP);
    Matrix invertMatrix = new Matrix();
    invertMatrix.setScale(1f, -1f);
    invertMatrix.preTranslate(0, -reflectionHeight);
    bitmapShader.setLocalMatrix(invertMatrix);

    // This shader holds an alpha gradient
    Shader alphaGradient = new LinearGradient(0, 0, 0, reflectionHeight, 0x80ffffff, 0x00000000,
            TileMode.CLAMP);

    // This shader combines the previous two, resulting in a
    // blurred, fading reflection
    ComposeShader compositor = new ComposeShader(bitmapShader, alphaGradient, PorterDuff.Mode.DST_IN);

    Paint reflectionPaint = new Paint();
    reflectionPaint.setShader(compositor);

    // Draw the reflection into the bitmap that we will return
    Canvas canvas = new Canvas(reflection);
    canvas.drawRect(0, 0, reflection.getWidth(), reflection.getHeight(), reflectionPaint);

    /// -----

    // Create a new Canvas with the bitmap that's big enough for
    // the image plus gap plus reflection
    Canvas finalcanvas = new Canvas(bitmapWithReflection);

    // Draw in the original image
    finalcanvas.drawBitmap(originalImage, 0, 0, null);

    // Draw in the gap
    Paint defaultPaint = new Paint();

    // transparent gap
    defaultPaint.setColor(0);

    finalcanvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);

    // Draw in the reflection
    finalcanvas.drawBitmap(reflection, 0, height + reflectionGap, null);

    return bitmapWithReflection;
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * Return text As bitmap/*from  w w  w. ja  va 2 s.c om*/
 *
 * @param text
 * @param textSize
 * @param textColor
 * @return
 */
public static Bitmap textAsBitmap(String text, float textSize, int textColor) {
    Paint paint = new Paint(ANTI_ALIAS_FLAG);
    paint.setTextSize(textSize); //text size
    paint.setColor(textColor); //text color
    paint.setTextAlign(Paint.Align.LEFT); //align center
    float baseline = -paint.ascent(); // ascent() is negative
    int width = (int) (paint.measureText(text) + 0.0f); // round
    int height = (int) (baseline + paint.descent() + 0.0f);
    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    canvas.drawText(text, 0, baseline, paint); //draw text
    return image;
}

From source file:com.waz.zclient.pages.main.conversation.LocationFragment.java

private Bitmap getMarker() {
    if (marker != null) {
        return marker;
    }//from w  w w . j av  a 2  s . c  o  m
    int size = getResources().getDimensionPixelSize(R.dimen.share_location__current_location_marker__size);
    int outerCircleRadius = getResources()
            .getDimensionPixelSize(R.dimen.share_location__current_location_marker__outer_ring_radius);
    int midCircleRadius = getResources()
            .getDimensionPixelSize(R.dimen.share_location__current_location_marker__mid_ring_radius);
    int innerCircleRadius = getResources()
            .getDimensionPixelSize(R.dimen.share_location__current_location_marker__inner_ring_radius);

    Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setColor(getControllerFactory().getAccentColorController().getColor());
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setAlpha(
            getResources().getInteger(R.integer.share_location__current_location_marker__outer_ring_alpha));
    canvas.drawCircle(size / 2, size / 2, outerCircleRadius, paint);
    paint.setAlpha(
            getResources().getInteger(R.integer.share_location__current_location_marker__mid_ring_alpha));
    canvas.drawCircle(size / 2, size / 2, midCircleRadius, paint);
    paint.setAlpha(
            getResources().getInteger(R.integer.share_location__current_location_marker__inner_ring_alpha));
    canvas.drawCircle(size / 2, size / 2, innerCircleRadius, paint);
    marker = bitmap;
    return marker;
}

From source file:com.gmail.walles.johan.batterylogger.BatteryPlotFragment.java

private void addPlotData(final XYPlot plot) {
    LineAndPointFormatter medianFormatter = getMedianFormatter();

    try {/*from ww w  .  ja  va2  s  . c o  m*/
        // Add battery drain series to the plot
        History history = new History(getActivity());
        if (history.isEmpty() && BuildConfig.DEBUG && isRunningOnEmulator()) {
            history = History.createFakeHistory();
        }

        drainDots = history.getBatteryDrain();
        enableDrainDots(plot);

        final List<XYSeries> medians = history.getDrainLines();
        for (XYSeries median : medians) {
            plot.addSeries(median, medianFormatter);
        }

        // Add red restart lines to the plot
        Paint restartPaint = new Paint();
        restartPaint.setAntiAlias(true);
        restartPaint.setColor(Color.RED);
        restartPaint.setStrokeWidth(dpToPixels(0.5f));
        plot.addSeries(history.getEvents(), new RestartFormatter(restartPaint));

        // Add events to the plot
        Paint labelPaint = new Paint();
        labelPaint.setAntiAlias(true);
        labelPaint.setColor(Color.WHITE);
        labelPaint.setTextSize(spToPixels(IN_GRAPH_TEXT_SIZE_SP));

        eventFormatter = new EventFormatter(labelPaint);
        plot.addSeries(history.getEvents(), eventFormatter);

        if (history.isEmpty()) {
            showAlertDialogOnce("No Battery History Recorded",
                    "Come back in a few hours to get a graph, or in a week to be able to see patterns.");
        } else if (medians.size() < 5) {
            showAlertDialogOnce("Very Short Battery History Recorded",
                    "If you come back in a week you'll be able to see patterns much better.");
        }
    } catch (IOException e) {
        Log.e(TAG, "Reading battery history failed", e);
        showAlertDialog("Reading Battery History Failed", e.getMessage());
    }
}

From source file:com.cssweb.android.view.PriceMini.java

private void setColor(Paint paint, double d0, double d1) {
    if (d0 == 0)//  w  w w .  ja va 2 s . c  o  m
        paint.setColor(GlobalColor.colorPriceEqual);
    else if (d0 > d1)
        paint.setColor(GlobalColor.colorpriceUp);
    else if (d0 < d1)
        paint.setColor(GlobalColor.colorPriceDown);
    else
        paint.setColor(GlobalColor.colorPriceEqual);
}

From source file:com.android.contacts.common.ContactPhotoManager.java

/**
 * If necessary, decodes bytes stored in the holder to Bitmap.  As long as the
 * bitmap is held either by {@link #mBitmapCache} or by a soft reference in
 * the holder, it will not be necessary to decode the bitmap.
 *//*from   w ww.  j  a  va 2s.c  o  m*/
private static void inflateBitmap(BitmapHolder holder, int requestedExtent) {
    final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent);
    byte[] bytes = holder.bytes;
    if (bytes == null || bytes.length == 0) {
        return;
    }

    if (sampleSize == holder.decodedSampleSize) {
        // Check the soft reference.  If will be retained if the bitmap is also
        // in the LRU cache, so we don't need to check the LRU cache explicitly.
        if (holder.bitmapRef != null) {
            holder.bitmap = holder.bitmapRef.get();
            if (holder.bitmap != null) {
                return;
            }
        }
    }

    try {
        Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize);

        // TODO: As a temporary workaround while framework support is being added to
        // clip non-square bitmaps into a perfect circle, manually crop the bitmap into
        // into a square if it will be displayed as a thumbnail so that it can be cropped
        // into a circle.
        final int height = bitmap.getHeight();
        final int width = bitmap.getWidth();

        // The smaller dimension of a scaled bitmap can range from anywhere from 0 to just
        // below twice the length of a thumbnail image due to the way we calculate the optimal
        // sample size.
        if (height != width && Math.min(height, width) <= mThumbnailSize * 2) {
            final int dimension = Math.min(height, width);
            bitmap = ThumbnailUtils.extractThumbnail(bitmap, dimension, dimension);
        }
        // make bitmap mutable and draw size onto it
        if (DEBUG_SIZES) {
            Bitmap original = bitmap;
            bitmap = bitmap.copy(bitmap.getConfig(), true);
            original.recycle();
            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setTextSize(16);
            paint.setColor(Color.BLUE);
            paint.setStyle(Style.FILL);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint);
            paint.setColor(Color.WHITE);
            paint.setAntiAlias(true);
            canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint);
        }

        holder.decodedSampleSize = sampleSize;
        holder.bitmap = bitmap;
        holder.bitmapRef = new SoftReference<Bitmap>(bitmap);
        if (DEBUG) {
            Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x"
                    + bitmap.getHeight() + ", " + btk(bitmap.getByteCount()));
        }
    } catch (OutOfMemoryError e) {
        // Do nothing - the photo will appear to be missing
    }
}

From source file:edumsg.edumsg_android_app.MainActivity.java

/**
 *
 * The onCreate method first retrieves the sessionId and username from the parent {@link android.content.Intent},
 * which is either created from a {@link LoginFragment} or a {@link RegisterFragment}. Afterwards,
 * it configures the action bar and performs view look-ups for the action bar buttons, followed
 * by setting the onClick listeners for the action bar buttons. Finally, it initializes the
 * properties, sets the onRefresh listener for the swipe refresh layout, and calls the method
 * {@link MainActivity#getFeed()}.//from w  w w  . jav a 2s.co m
 *
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sessionId = getIntent().getExtras().getString("sessionId");
    username = getIntent().getExtras().getString("username");
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);
    final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.menu_main, null);
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(actionBarLayout);
    ImageButton homeButton = ButterKnife.findById(actionBarLayout, R.id.btn_home);
    final ImageButton searchButton = ButterKnife.findById(actionBarLayout, R.id.btn_search);
    ImageButton createButton = ButterKnife.findById(actionBarLayout, R.id.btn_create);
    ImageButton navButton = ButterKnife.findById(actionBarLayout, R.id.btn_nav);

    final ViewGroup searchLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.menu_search, null);
    final SearchView searchView = ButterKnife.findById(searchLayout, R.id.search);
    final ImageButton backBtn = ButterKnife.findById(searchLayout, R.id.btn_back);

    homeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    searchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actionBar.setCustomView(searchLayout);
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager
                    .getSearchableInfo(new ComponentName(MainActivity.this, SearchResultsActivity.class)));
            searchView.setQuery("", false);
            searchView.setIconified(false);
            searchView.setFocusable(true);
            searchView.requestFocusFromTouch();
        }
    });

    backBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            actionBar.setCustomView(actionBarLayout);
            InputMethodManager imm = (InputMethodManager) getApplicationContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(
                    MainActivity.this.getWindow().getDecorView().getRootView().getWindowToken(), 0);
        }
    });

    createButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

            final EditText input = new EditText(MainActivity.this);
            input.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
            input.setLines(4);
            input.setSingleLine(false);
            input.setBackgroundDrawable(null);
            builder.setView(input);
            builder.setPositiveButton("Tweet", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    createTweet(input.getText().toString());
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            final AlertDialog dialog = builder.create();

            dialog.setOnShowListener(new DialogInterface.OnShowListener() {
                @Override
                public void onShow(DialogInterface dialogInterface) {
                    Button posBtn = dialog.getButton(AlertDialog.BUTTON_NEGATIVE);
                    posBtn.setBackgroundColor(cPrimary);
                    posBtn.setTextColor(Color.WHITE);
                    final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
                    int pixels = (int) (10 * scale + 0.5f);
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    layoutParams.setMargins(0, 0, pixels, 0);
                    posBtn.setLayoutParams(layoutParams);
                    Button negBtn = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                    negBtn.setBackgroundColor(cPrimary);
                    negBtn.setTextColor(Color.WHITE);
                }
            });
            dialog.show();
        }
    });

    navButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentManager fragmentManager = getSupportFragmentManager();
            List<Fragment> fragments = fragmentManager.getFragments();
            if (fragments != null) {
                for (Fragment fragment : fragments) {
                    if (fragment instanceof NavigationFragment)
                        return;
                }
            }
            NavigationFragment navigationFragment = new NavigationFragment();
            //                Bundle bundle = new_user Bundle();
            //                bundle.putInt("userId", userId);
            //                mainActivityFragment.setArguments(bundle);
            fragmentManager.beginTransaction().add(android.R.id.content, navigationFragment)
                    .addToBackStack("nav").commit();
            //                logout();
            //                launchMessages();
            //                Intent intent = new_user Intent(MainActivity.this, ProfileActivity.class);
            //                intent.putExtra("username", getUsername());
            //                intent.putExtra("name", getName());
            //                intent.putExtra("avatar_url", getAvatar_url());
            //                intent.putExtra("bio", getBio());
            //                intent.putExtra("creatorId", getUserId());
            //                intent.putExtra("userId", getUserId());
            //                startActivity(intent);
        }
    });

    recyclerView.setHasFixedSize(true);
    final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
    int pixels = (int) (160 * scale + 0.5f);
    Paint paint = new Paint();
    paint.setStrokeWidth(3.0f);
    paint.setColor(Color.rgb(220, 220, 220));
    paint.setAntiAlias(true);
    recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).paint(paint).build());
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    tweetObjects = new ArrayList<>();
    rvAdapter = new RVAdapter(this, tweetObjects, sessionId);
    recyclerView.setAdapter(rvAdapter);

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            tweetObjects.clear();
            getFeed();
        }
    });

    getFeed();
}