Example usage for android.graphics LinearGradient LinearGradient

List of usage examples for android.graphics LinearGradient LinearGradient

Introduction

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

Prototype

public LinearGradient(float x0, float y0, float x1, float y1, @ColorInt int color0, @ColorInt int color1,
        @NonNull TileMode tile) 

Source Link

Document

Create a shader that draws a linear gradient along a line.

Usage

From source file:com.ternup.caddisfly.fragment.DetailsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getActivity().setTitle(R.string.details);
    mContext = getActivity();// www. java 2 s .  c o m

    ListView listView = getListView();

    mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY);

    View header = getActivity().getLayoutInflater().inflate(R.layout.fragment_result, null, false);

    mPpmText = (TextView) header.findViewById(R.id.ppmText);
    mDateView = (TextView) header.findViewById(R.id.testDate);
    mTitleView = (TextView) header.findViewById(R.id.titleView);
    mResultTextView = (TextView) header.findViewById(R.id.result);
    mAddressText = (TextView) header.findViewById(R.id.address1);
    mAddress2Text = (TextView) header.findViewById(R.id.address2);
    mAddress3Text = (TextView) header.findViewById(R.id.address3);
    mSourceText = (TextView) header.findViewById(R.id.sourceType);

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);

    mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY);
    mId = getArguments().getLong(getString(R.string.currentTestId));
    mLocationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1);

    File directory = new File(FileUtils.getStoragePath(getActivity(), mLocationId, mFolderName, false));

    long locationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1);

    final ArrayList<String> imagePaths = FileUtils.getFilePaths(getActivity(), mFolderName, "/small/",
            locationId);

    if (mId > -1) {
        if (!directory.exists()) {
            Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId);
            mContext.getContentResolver().delete(uri, null, null);
            goBack();
        } else if (imagePaths.size() > 0) {
            displayResult();
        } else {
            FileUtils.deleteFolder(getActivity(), mLocationId, mFolderName);
            goBack();
        }
    }

    ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer);
    drawerList.setItemChecked(-1, true);
    drawerList.setSelection(-1);

    assert listView != null;
    listView.addHeaderView(header);

    // Gradient shading for title
    assert header != null;

    //Collections.sort(imagePaths);

    GalleryListAdapter adapter = new GalleryListAdapter(getActivity(), mTestTypeId, mId, imagePaths, true);
    setListAdapter(adapter);

    Shader textShader = new LinearGradient(0, 0, 0, mTitleView.getPaint().getTextSize(),
            new int[] { getResources().getColor(R.color.textGradientStart),
                    getResources().getColor(R.color.textGradientEnd) },
            new float[] { 0, 1 }, Shader.TileMode.CLAMP);
    mTitleView.getPaint().setShader(textShader);

}

From source file:devlight.io.library.TintLayout.java

public void invalidateTint() {
    // Clear previous tint
    mTintCanvas.drawColor(0, PorterDuff.Mode.CLEAR);

    // Get angle point of a child
    final float startX = (float) (mChildBounds.left + Math.cos(mAngle * Math.PI / 180.0F) * mRadius);
    final float startY = (float) (mChildBounds.top + Math.sin(mAngle * Math.PI / 180.0F) * mRadius);

    // Set counters
    mLeftCounter = mChildBounds.left;// ww  w. j  av a2s. c o m
    mTopCounter = mChildBounds.top;
    // Calculate offsets
    mOffsetX = (startX - mChildBounds.left) / mRadius;
    mOffsetY = (startY - mChildBounds.top) / mRadius;

    // Draw tint while bitmap contained in bounds and in angle area
    if (mAngle >= 0.0F && mAngle <= 90.0F) {
        while (mLeftCounter < mBounds.width() && mTopCounter < mBounds.height())
            drawTintBitmap();
    } else if (mAngle >= 90.0F && mAngle <= 180.0F) {
        while (mLeftCounter > -mChildBounds.width() && mTopCounter < mBounds.height())
            drawTintBitmap();
    } else if (mAngle >= 180.0F && mAngle <= 270.0F) {
        while (mLeftCounter > -mChildBounds.width() && mTopCounter > -mChildBounds.height())
            drawTintBitmap();
    } else if (mAngle >= 270.0F && mAngle <= 360.0F) {
        while (mLeftCounter < mBounds.width() && mTopCounter > -mChildBounds.height())
            drawTintBitmap();
    }

    // Calculate gradient
    if (mColors != null) {
        // Get angle point of a child
        final float endX = (float) (mLeftCounter + Math.cos(mAngle * Math.PI / 180.0F) * mRadius);
        final float endY = (float) (mTopCounter + Math.sin(mAngle * Math.PI / 180.0F) * mRadius);

        mColorPaint.setShader(
                new LinearGradient(startX, startY, endX, endY, mColors, null, Shader.TileMode.CLAMP));
    }

    postInvalidate();
}

From source file:org.stockchart.core.Appearance.java

public void applyFill(Paint p, RectF rect) {
    p.reset();//w ww  .ja  v a2s .co  m
    p.setStyle(Style.FILL);
    p.setColor(fPrimaryFillColor);

    switch (fGradient) {
    case LINEAR_HORIZONTAL: {
        p.setShader(new LinearGradient(rect.left, rect.top, rect.right, rect.top, fPrimaryFillColor,
                fSecondaryFillColor, TileMode.MIRROR));
    }
        break;

    case LINEAR_VERTICAL: {
        p.setShader(new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, fPrimaryFillColor,
                fSecondaryFillColor, TileMode.MIRROR));
    }
        break;
    default:
        p.setShader(null);
    }
}

From source file:me.lizheng.deckview.helpers.FakeShadowDrawable.java

private void buildShadowCorners() {
    RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-mShadowSize, -mShadowSize);

    if (mCornerShadowPath == null) {
        mCornerShadowPath = new Path();
    } else {/*from w ww  .  j  av  a2 s  .com*/
        mCornerShadowPath.reset();
    }
    mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
    mCornerShadowPath.moveTo(-mCornerRadius, 0);
    mCornerShadowPath.rLineTo(-mShadowSize, 0);
    // outer arc
    mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
    // inner arc
    mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
    mCornerShadowPath.close();

    float startRatio = mCornerRadius / (mCornerRadius + mShadowSize);
    mCornerShadowPaint.setShader(new RadialGradient(0, 0, mCornerRadius + mShadowSize,
            new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor },
            new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP));

    // we offset the content shadowSize/2 pixels up to make it more realistic.
    // this is why edge shadow shader has some extra space
    // When drawing bottom edge shadow, we use that extra space.
    mEdgeShadowPaint.setShader(new LinearGradient(0, -mCornerRadius + mShadowSize, 0,
            -mCornerRadius - mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor },
            new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP));
}

From source file:org.onebusaway.android.map.googlemapsv2.StopOverlay.java

/**
 * Creates a bus stop icon with the given direction arrow, or without a direction arrow if
 * the direction is NO_DIRECTION//from  w  ww.  j a v  a2  s  .com
 *
 * @param direction Bus stop direction, obtained from ObaStop.getDirection() and defined in
 *                  constants in this class, or NO_DIRECTION if the stop icon shouldn't have a
 *                  direction arrow
 * @return a bus stop icon bitmap with the arrow pointing the given direction, or with no arrow
 * if direction is NO_DIRECTION
 */
private static Bitmap createBusStopIcon(String direction) throws NullPointerException {
    if (direction == null) {
        throw new IllegalArgumentException(direction);
    }

    Resources r = Application.get().getResources();
    Context context = Application.get();

    Float directionAngle = null; // 0-360 degrees
    Bitmap bm;
    Canvas c;
    Drawable shape;
    Float rotationX = null, rotationY = null; // Point around which to rotate the arrow

    Paint arrowPaintFill = new Paint();
    arrowPaintFill.setStyle(Paint.Style.FILL);
    arrowPaintFill.setAntiAlias(true);

    if (direction.equals(NO_DIRECTION)) {
        // Don't draw the arrow
        bm = Bitmap.createBitmap(mPx, mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, bm.getWidth(), bm.getHeight());
    } else if (direction.equals(NORTH)) {
        directionAngle = 0f;
        bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, 0, bm.getWidth() / 2, mArrowHeightPx,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // For NORTH, no rotation occurs - use center of image anyway so we have some value
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(NORTH_WEST)) {
        directionAngle = 315f; // Arrow is drawn N, rotate 315 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, (int) mBuffer, bm.getWidth(), bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(0, 0, mBuffer, mBuffer, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = mPx / 2f + mBuffer / 2f;
        rotationY = bm.getHeight() / 2f - mBuffer / 2f;
    } else if (direction.equals(WEST)) {
        directionAngle = 0f; // Arrow is drawn pointing West, so no rotation
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, 0, bm.getWidth(), bm.getHeight());
        arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight() / 2, mArrowHeightPx, bm.getHeight() / 2,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // For WEST
        rotationX = bm.getHeight() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(SOUTH_WEST)) {
        directionAngle = 225f; // Arrow is drawn N, rotate 225 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds((int) mBuffer, 0, bm.getWidth(), mPx);
        arrowPaintFill.setShader(new LinearGradient(0, bm.getHeight(), mBuffer, bm.getHeight() - mBuffer,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = bm.getWidth() / 2f - mBuffer / 4f;
        rotationY = mPx / 2f + mBuffer / 4f;
    } else if (direction.equals(SOUTH)) {
        directionAngle = 180f; // Arrow is drawn N, rotate 180 degrees
        bm = Bitmap.createBitmap(mPx, (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, bm.getWidth(), (int) (bm.getHeight() - mBuffer));
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth() / 2, bm.getHeight(), bm.getWidth() / 2,
                bm.getHeight() - mArrowHeightPx, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(SOUTH_EAST)) {
        directionAngle = 135f; // Arrow is drawn N, rotate 135 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, mPx, mPx);
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight(), bm.getWidth() - mBuffer,
                bm.getHeight() - mBuffer, r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent),
                Shader.TileMode.MIRROR));
        // Rotate around below coordinates (trial and error)
        rotationX = (mPx + mBuffer / 2) / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(EAST)) {
        directionAngle = 180f; // Arrow is drawn pointing West, so rotate 180
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), mPx, Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, 0, mPx, bm.getHeight());
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), bm.getHeight() / 2,
                bm.getWidth() - mArrowHeightPx, bm.getHeight() / 2, r.getColor(R.color.theme_primary),
                r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        rotationX = bm.getWidth() / 2f;
        rotationY = bm.getHeight() / 2f;
    } else if (direction.equals(NORTH_EAST)) {
        directionAngle = 45f; // Arrow is drawn pointing N, so rotate 45 degrees
        bm = Bitmap.createBitmap((int) (mPx + mBuffer), (int) (mPx + mBuffer), Bitmap.Config.ARGB_8888);
        c = new Canvas(bm);
        shape = ContextCompat.getDrawable(context, R.drawable.map_stop_icon);
        shape.setBounds(0, (int) mBuffer, mPx, bm.getHeight());
        // Shade with darkest color at tip of arrow
        arrowPaintFill.setShader(new LinearGradient(bm.getWidth(), 0, bm.getWidth() - mBuffer, mBuffer,
                r.getColor(R.color.theme_primary), r.getColor(R.color.theme_accent), Shader.TileMode.MIRROR));
        // Rotate around middle of circle
        rotationX = (float) mPx / 2;
        rotationY = bm.getHeight() - (float) mPx / 2;
    } else {
        throw new IllegalArgumentException(direction);
    }

    shape.draw(c);

    if (direction.equals(NO_DIRECTION)) {
        // Everything after this point is for drawing the arrow image, so return the bitmap as-is for no arrow
        return bm;
    }

    /**
     * Draw the arrow - all dimensions should be relative to px so the arrow is drawn the same
     * size for all orientations
     */
    // Height of the cutout in the bottom of the triangle that makes it an arrow (0=triangle)
    final float CUTOUT_HEIGHT = mPx / 12;
    Path path = new Path();
    float x1 = 0, y1 = 0; // Tip of arrow
    float x2 = 0, y2 = 0; // lower left
    float x3 = 0, y3 = 0; // cutout in arrow bottom
    float x4 = 0, y4 = 0; // lower right

    if (direction.equals(NORTH) || direction.equals(SOUTH) || direction.equals(NORTH_EAST)
            || direction.equals(SOUTH_EAST) || direction.equals(NORTH_WEST) || direction.equals(SOUTH_WEST)) {
        // Arrow is drawn pointing NORTH
        // Tip of arrow
        x1 = mPx / 2;
        y1 = 0;

        // lower left
        x2 = (mPx / 2) - (mArrowWidthPx / 2);
        y2 = mArrowHeightPx;

        // cutout in arrow bottom
        x3 = mPx / 2;
        y3 = mArrowHeightPx - CUTOUT_HEIGHT;

        // lower right
        x4 = (mPx / 2) + (mArrowWidthPx / 2);
        y4 = mArrowHeightPx;
    } else if (direction.equals(EAST) || direction.equals(WEST)) {
        // Arrow is drawn pointing WEST
        // Tip of arrow
        x1 = 0;
        y1 = mPx / 2;

        // lower left
        x2 = mArrowHeightPx;
        y2 = (mPx / 2) - (mArrowWidthPx / 2);

        // cutout in arrow bottom
        x3 = mArrowHeightPx - CUTOUT_HEIGHT;
        y3 = mPx / 2;

        // lower right
        x4 = mArrowHeightPx;
        y4 = (mPx / 2) + (mArrowWidthPx / 2);
    }

    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x4, y4);
    path.lineTo(x1, y1);
    path.close();

    // Rotate arrow around (rotationX, rotationY) point
    Matrix matrix = new Matrix();
    matrix.postRotate(directionAngle, rotationX, rotationY);
    path.transform(matrix);

    c.drawPath(path, arrowPaintFill);
    c.drawPath(path, mArrowPaintStroke);

    return bm;
}

From source file:com.taobao.weex.utils.WXResourceUtils.java

/**
 * Assembly gradients// w w  w .jav  a  2 s  .  co  m
 * @param image gradient values contains direction?colors
 * @param width component width
 * @param height component height
 * @return gradient shader
 */
public static Shader getShader(String image, float width, float height) {
    List<String> valueList = parseGradientValues(image);
    if (valueList != null && valueList.size() == 3) {
        float[] points = parseGradientDirection(valueList.get(0), width, height);
        Shader shader = new LinearGradient(points[0], points[1], points[2], points[3],
                getColor(valueList.get(1), Color.WHITE), getColor(valueList.get(2), Color.WHITE),
                Shader.TileMode.REPEAT);
        return shader;
    }
    return null;
}

From source file:com.android.mail.ui.FolderDisplayer.java

public static void drawFolder(Canvas canvas, float x, float y, int width, int height, String name, int fgColor,
        int bgColor, FolderDisplayer.FolderDrawableResources res, BidiFormatter formatter, Paint paint) {
    canvas.save();//w ww.  j a  va 2 s  .  c  om
    canvas.translate(x, y + res.folderVerticalOffset);

    // Draw the box.
    paint.setColor(bgColor);
    paint.setStyle(Paint.Style.FILL);
    final RectF rect = new RectF(0, 0, width, height);
    canvas.drawRoundRect(rect, res.folderRoundedCornerRadius, res.folderRoundedCornerRadius, paint);

    // Draw the text based on the language locale and layout direction.
    paint.setColor(fgColor);
    paint.setStyle(Paint.Style.FILL);

    // Compute the text/gradient indices
    final int textLength = (int) paint.measureText(name);
    final int gradientX0;
    final int gradientX1;
    final int textX;

    /***************************************************************************************************
     * width               - the actual folder chip rectangle.                                         *
     * textLength          - the length of the folder's full name (can be longer than                  *
     *                         the actual chip, which is what overflow gradient is for).               *
     * innerPadding        - the padding between the text and the chip edge.                           *
     * overflowPadding     - the padding between start of overflow and the chip edge.                  *
     *                                                                                                 *
     *                                                                                                 *
     * text is in a RTL language                                                                       *
     *                                                                                                 *
     *                   index-0                                                                       *
     *                      |<---------------------------- width ---------------------------->|        *
     *        |<-------------------------textLength------------------>|                       |        *
     *        |             |<----- overflowPadding ----->|                                   |        *
     *        |             |<- innerPadding ->|<-------->|<--------->|<- horizontalPadding ->|        *
     *       textX                            gX1        gX0                                           *
     *                                                                                                 *
     *                                                                                                 *
     * text is in a LTR language.                                                                      *
     *                                                                                                 *
     *     index-0                                                                                     *
     *        |<------------------------------ width ------------------------------->|                 *
     *        |                       |<-------------------------textLength-------------------->|      *
     *        |                                   |<-------- overflowPadding ------->|                 *
     *        |<- horizontalPadding ->|<--------->|<-------->|<- horizontalPadding ->|                 *
     *                              textX        gX0        gX1                                        *
     *                                                                                                 *
     **************************************************************************************************/
    if (formatter.isRtl(name)) {
        gradientX0 = res.overflowGradientPadding;
        gradientX1 = res.folderHorizontalPadding;
        textX = width - res.folderHorizontalPadding - textLength;
    } else {
        gradientX0 = width - res.overflowGradientPadding;
        gradientX1 = width - res.folderHorizontalPadding;
        textX = res.folderHorizontalPadding;
    }

    // Draw the text and the possible overflow gradient
    // Overflow happens when the text is longer than the chip width minus side paddings.
    if (textLength > width - 2 * res.folderHorizontalPadding) {
        final Shader shader = new LinearGradient(gradientX0, 0, gradientX1, 0, fgColor,
                Utils.getTransparentColor(fgColor), Shader.TileMode.CLAMP);
        paint.setShader(shader);
    }
    final int textY = height / 2 - (int) (paint.descent() + paint.ascent()) / 2;
    canvas.drawText(name, textX, textY, paint);
    paint.setShader(null);

    canvas.restore();
}

From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java

private Bitmap createReflectionBitmap(Bitmap original) {
    final int w = original.getWidth();
    final int h = original.getHeight();
    final int rh = (int) (h * mReflectionHeight);
    final int gradientColor = Color.argb(mReflectionOpacity, 0xff, 0xff, 0xff);

    final Bitmap reflection = Bitmap.createBitmap(original, 0, rh, w, rh, mReflectionMatrix, false);

    final LinearGradient shader = new LinearGradient(0, 0, 0, reflection.getHeight(), gradientColor, 0x00ffffff,
            TileMode.CLAMP);/*www  .j a v a2  s.c  om*/
    mPaint.reset();
    mPaint.setShader(shader);
    mPaint.setXfermode(mXfermode);

    mReflectionCanvas.setBitmap(reflection);
    mReflectionCanvas.drawRect(0, 0, reflection.getWidth(), reflection.getHeight(), mPaint);

    return reflection;
}

From source file:android.support.design.widget.ShadowDrawableWrapper.java

private void buildShadowCorners() {
    RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-mShadowSize, -mShadowSize);

    if (mCornerShadowPath == null) {
        mCornerShadowPath = new Path();
    } else {//from ww w  .  j a  va2s .  c  om
        mCornerShadowPath.reset();
    }
    mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
    mCornerShadowPath.moveTo(-mCornerRadius, 0);
    mCornerShadowPath.rLineTo(-mShadowSize, 0);
    // outer arc
    mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
    // inner arc
    mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
    mCornerShadowPath.close();

    float shadowRadius = -outerBounds.top;
    if (shadowRadius > 0f) {
        float startRatio = mCornerRadius / shadowRadius;
        float midRatio = startRatio + ((1f - startRatio) / 2f);
        mCornerShadowPaint.setShader(new RadialGradient(0, 0, shadowRadius,
                new int[] { 0, mShadowStartColor, mShadowMiddleColor, mShadowEndColor },
                new float[] { 0f, startRatio, midRatio, 1f }, Shader.TileMode.CLAMP));
    }

    // we offset the content shadowSize/2 pixels up to make it more realistic.
    // this is why edge shadow shader has some extra space
    // When drawing bottom edge shadow, we use that extra space.
    mEdgeShadowPaint.setShader(new LinearGradient(0, innerBounds.top, 0, outerBounds.top,
            new int[] { mShadowStartColor, mShadowMiddleColor, mShadowEndColor }, new float[] { 0f, .5f, 1f },
            Shader.TileMode.CLAMP));
    mEdgeShadowPaint.setAntiAlias(false);
}

From source file:com.geeya.wifitv.widget.PagerSlidingTabStrip.java

@SuppressLint("DrawAllocation")
@Override//from  ww  w.  ja  v a2 s  . c o  m
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;
    }

    final int height = getHeight();

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    //canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    // draw underline

    Shader mShader = new LinearGradient(0, height - underlineHeight, tabsContainer.getWidth(), height,
            new int[] { 0xfffba534, 0xffffff00, 0xfffba534 }, null, Shader.TileMode.REPEAT);
    rectPaint.setShader(mShader);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    //dividerPaint.setColor(dividerColor);
    //      for (int i = 0; i < tabCount - 1; i++) {
    //         View tab = tabsContainer.getChildAt(i);
    //         canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    //      }
}