Java Code Examples for android.graphics.Paint.setShadowLayer()

The following are Jave code examples for showing how to use setShadowLayer() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LaunchEnr   File: BoardUtils.java   View Source Code Vote up 8 votes
public static Bitmap createRoundIcon(Context context, Bitmap defaultIcon) {

        //calculate dimensions
        //-1 to take into account the shadow layer
        int w = defaultIcon.getWidth();
        int h = defaultIcon.getHeight();
        int r = w / 2 - 1;

        //create bitmap
        Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

        //draw a circle of the same dimensions
        Canvas canvas = new Canvas(b);
        Paint paint = new Paint();
        paint.setColor(IconColorExtractor.get(context, defaultIcon));
        final int SHADOW_COLOR = 0x80000000;
        paint.setShadowLayer(0.5f, 1, 1, SHADOW_COLOR);
        paint.setAntiAlias(true);
        canvas.drawCircle(r, r, r, paint);

        //scale default icon and center inside the canvas
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(defaultIcon, r, r, true);
        canvas.drawBitmap(scaledBitmap, (r * 2 - scaledBitmap.getWidth()) / 2, (r * 2 - scaledBitmap.getHeight()) / 2, paint);

        return b;
    }
 
Example 2
Project: LaunchEnr   File: WidgetPreviewLoader.java   View Source Code Vote up 6 votes
private RectF drawBoxWithShadow(Canvas c, Paint p, int width, int height) {
    Resources res = mContext.getResources();
    float shadowBlur = res.getDimension(R.dimen.widget_preview_shadow_blur);
    float keyShadowDistance = res.getDimension(R.dimen.widget_preview_key_shadow_distance);
    float corner = res.getDimension(R.dimen.widget_preview_corner_radius);

    RectF bounds = new RectF(shadowBlur, shadowBlur,
            width - shadowBlur, height - shadowBlur - keyShadowDistance);
    p.setColor(Color.WHITE);

    // Key shadow
    p.setShadowLayer(shadowBlur, 0, keyShadowDistance,
            ShadowGenerator.KEY_SHADOW_ALPHA << 24);
    c.drawRoundRect(bounds, corner, corner, p);

    // Ambient shadow
    p.setShadowLayer(shadowBlur, 0, 0,
            ColorUtils.setAlphaComponent(Color.BLACK, ShadowGenerator.AMBIENT_SHADOW_ALPHA));
    c.drawRoundRect(bounds, corner, corner, p);

    p.clearShadowLayer();
    return bounds;
}
 
Example 3
Project: starcor.xul   File: XulRenderContext.java   View Source Code Vote up 6 votes
static public Paint getShadowTextPaintByName(String name) {
	if (name == null) {
		return getDefShadowTextPaint();
	}
	TypefaceInfo typefaceInfo = _font_map.get(name);
	if (typefaceInfo == null) {
		return getDefShadowTextPaint();
	}
	Paint paint = typefaceInfo.paint;
	if (paint == null) {
		typefaceInfo.paint = paint = new Paint();
		paint.setTypeface(typefaceInfo.typeface);
		paint.setAntiAlias(true);
		paint.setSubpixelText(true);
		paint.setShadowLayer(3, 0, 0, Color.BLACK);
	}
	return paint;
}
 
Example 4
Project: Eye   File: PersonInfoView.java   View Source Code Vote up 6 votes
private void setupInfoView() {

        outlinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        outlinePaint.setStyle(Paint.Style.STROKE);
        outlinePaint.setStrokeWidth(Util.dpToPixels(context, 1));
        outlinePaint.setColor(getRandomColor());

        basePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        basePaint.setStyle(Paint.Style.FILL);
        basePaint.setColor(Color.WHITE);
        basePaint.setShadowLayer(Util.dpToPixels(context, 1), 0, 0, Color.DKGRAY);
        setLayerType(LAYER_TYPE_SOFTWARE, basePaint);

        textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        textPaint.setTextSize(Util.dpToPixels(context, 6));
        textPaint.setColor(Color.BLACK);
        textPaint.setStyle(Paint.Style.FILL);

        gap = Util.dpToPixels(context, 2);
        radiusPixels = Util.dpToPixels(context, 2);
        textPadding = Util.dpToPixels(context, 2);
        textLinePadding = Util.dpToPixels(context, 1);

    }
 
Example 5
Project: Cable-Android   File: CanvasView.java   View Source Code Vote up 5 votes
/**
 * This method creates the instance of Paint.
 * In addition, this method sets styles for Paint.
 *
 * @return paint This is returned as the instance of Paint
 */
private Paint createPaint() {
  Paint paint = new Paint();

  paint.setAntiAlias(true);
  paint.setStyle(this.paintStyle);
  paint.setStrokeWidth(this.paintStrokeWidth);
  paint.setStrokeCap(this.lineCap);
  paint.setStrokeJoin(Paint.Join.MITER);  // fixed

  // for Text
  if (this.mode == Mode.TEXT) {
    paint.setTypeface(this.fontFamily);
    paint.setTextSize(this.fontSize);
    paint.setTextAlign(this.textAlign);
    paint.setStrokeWidth(0F);
  }

  if (this.mode == Mode.ERASER) {
    // Eraser
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    paint.setARGB(0, 0, 0, 0);

    // paint.setColor(this.baseColor);
    // paint.setShadowLayer(this.blur, 0F, 0F, this.baseColor);
  } else {
    // Otherwise
    paint.setColor(this.paintStrokeColor);
    paint.setShadowLayer(this.blur, 0F, 0F, this.paintStrokeColor);
    paint.setAlpha(this.opacity);
  }

  return paint;
}
 
Example 6
Project: GitHub   File: WaveView.java   View Source Code Vote up 5 votes
private void setUpPaint() {
        float density = getResources().getDisplayMetrics().density;
        mPaint = new Paint();
        mPaint.setColor(0xff2196F3);
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setShadowLayer((int) (0.5f + 2.0f * density), 0f, 0f, SHADOW_COLOR);

//    float density = getResources().getDisplayMetrics().density;
//    mShadowPaint = new Paint();
//    mShadowPaint.setAntiAlias(true);
//    mShadowPaint.setShadowLayer((int) (0.5f + 2.0f * density), 0f, 0f, SHADOW_COLOR);
    }
 
Example 7
Project: ShadowImageView   File: ShadowImageView.java   View Source Code Vote up 5 votes
@Override
protected void dispatchDraw(Canvas canvas) {

    if (mInvalidat) {

        mInvalidat = false;

        View view = getChildAt(0);

        Paint shadowPaint = new Paint();

        shadowPaint.setColor(Color.WHITE);
        shadowPaint.setStyle(Paint.Style.FILL);
        shadowPaint.setAntiAlias(true);

        int radius = view.getHeight() / 12 > 40 ? 40 : view.getHeight() / 12;
        int shadowDimen = view.getHeight() / 16 > 28 ? 28 : view.getHeight() / 16;

        Bitmap bitmap;
        int rgb;

        if (((ImageView) view).getDrawable() instanceof ColorDrawable) {
            rgb = ((ColorDrawable) ((ImageView) view).getDrawable()).getColor();
            shadowPaint.setShadowLayer(40, 0, 28, getDarkerColor(rgb));
        } else if (((ImageView) view).getDrawable() instanceof BitmapDrawable) {
            bitmap = ((BitmapDrawable) ((ImageView) view).getDrawable()).getBitmap();
            Palette.Swatch mSwatch = Palette.from(bitmap).generate().getDominantSwatch();

            if (null != mSwatch) {
                rgb = mSwatch.getRgb();
            } else {
                rgb = Color.parseColor("#8D8D8D");
            }

            shadowPaint.setShadowLayer(radius, 0, shadowDimen, getDarkerColor(rgb));
            Bitmap bitmapT = Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 4 * 3,
                    bitmap.getWidth(), bitmap.getHeight() / 4);

            if (null != Palette.from(bitmapT).generate().getDominantSwatch()) {
                rgb = Palette.from(bitmapT).generate().getDominantSwatch().getRgb();
                shadowPaint.setShadowLayer(radius, 0, shadowDimen, rgb);
            }
        } else {
            rgb = Color.parseColor("#8D8D8D");
            shadowPaint.setShadowLayer(radius, 0, shadowDimen, getDarkerColor(rgb));
        }

        if (this.shadowColor != -147483648) {
            shadowPaint.setShadowLayer(radius, 0, shadowDimen, this.shadowColor);
        }

        RectF rectF = new RectF(view.getX() + (view.getWidth() / 20), view.getY(), view.getX() + view.getWidth() - (view.getWidth() / 20), view.getY() + view.getHeight() - ((view.getHeight() / 40)));

        canvas.drawRoundRect(rectF, shadowRound, shadowRound, shadowPaint);

        canvas.save();
    }
    super.dispatchDraw(canvas);
}
 
Example 8
Project: FacebookReaction   File: RoundedBoard.java   View Source Code Vote up 5 votes
private void initPaint() {
  boardPaint = new Paint();
  boardPaint.setAntiAlias(true);
  boardPaint.setStyle(Paint.Style.FILL);
  boardPaint.setColor(Color.WHITE);
  boardPaint.setShadowLayer(5.0f, 0.0f, 2.0f, 0xFF000000);
}
 
Example 9
Project: PswText   File: PswText.java   View Source Code Vote up 5 votes
private void initPaint() {
	//密码圆点画笔初始化
	pswDotPaint = new Paint();
	pswDotPaint.setAntiAlias(true);
	pswDotPaint.setStrokeWidth(3);
	pswDotPaint.setStyle(Paint.Style.FILL);
	pswDotPaint.setColor(pswColor);

	//明文密码画笔初始化
	pswTextPaint = new Paint();
	pswTextPaint.setAntiAlias(true);
	pswTextPaint.setFakeBoldText(true);
	pswTextPaint.setColor(pswColor);

	//边框画笔初始化
	borderPaint = new Paint();
	borderPaint.setAntiAlias(true);
	borderPaint.setColor(borderColor);
	borderPaint.setStyle(Paint.Style.STROKE);
	borderPaint.setStrokeWidth(3);

	//输入时边框画笔初始化
	inputBorderPaint = new Paint();
	inputBorderPaint.setAntiAlias(true);
	inputBorderPaint.setColor(inputBorderColor);
	inputBorderPaint.setStyle(Paint.Style.STROKE);
	inputBorderPaint.setStrokeWidth(3);
	//是否绘制边框阴影
	if (isShowBorderShadow) {
		inputBorderPaint.setShadowLayer(6, 0, 0, borderShadowColor);
		setLayerType(LAYER_TYPE_SOFTWARE, inputBorderPaint);
	}
}
 
Example 10
Project: FlickLauncher   File: FolderIcon.java   View Source Code Vote up 5 votes
public void drawBackground(Canvas canvas, Paint paint) {
    canvas.save();
    canvas.translate(getOffsetX(), getOffsetY());

    paint.reset();
    if(Utilities.isAllowFolderTransparentPrefEnabled(Launcher.getLauncherActivity().getApplicationContext())){
        paint.setStyle(Paint.Style.STROKE);
    }else {
        paint.setStyle(Paint.Style.FILL);
    }
    paint.setXfermode(null);
    paint.setAntiAlias(true);

    int alpha = (int) Math.min(MAX_BG_OPACITY, BG_OPACITY * mColorMultiplier);
    if(Utilities.getFolderPreviewBackgroundPrefEnabled(Launcher.getLauncherActivity().getApplicationContext()) != -1){
        paint.setColor(Utilities.getFolderPreviewBackgroundPrefEnabled(Launcher.getLauncherActivity().getApplicationContext()));
    }else {
        paint.setColor(Color.argb(alpha, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY));
    }
    float radius = getScaledRadius();

    canvas.drawCircle(radius, radius, radius, paint);
    canvas.clipPath(mClipPath, Region.Op.DIFFERENCE);

    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.TRANSPARENT);
    paint.setShadowLayer(mStrokeWidth, 0, mStrokeWidth, Color.argb(SHADOW_OPACITY, 0, 0, 0));
    canvas.drawCircle(radius, radius, radius, paint);

    canvas.restore();
}
 
Example 11
Project: referendum_1o_android   File: DefaultClusterOptionsProvider.java   View Source Code Vote up 5 votes
private Paint createTextPaint(Resources resources) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(resources.getColor(R.color.ame_default_cluster_text_color));
    shadowBlurRadius = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_blur_radius);
    if (shadowBlurRadius > 0.0f) {
        shadowOffsetX = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_offset_x);
        shadowOffsetY = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_offset_y);
        int shadowColor = resources.getColor(R.color.ame_default_cluster_text_shadow_color);
        paint.setShadowLayer(shadowBlurRadius, shadowOffsetX, shadowOffsetY, shadowColor);
    }
    paint.setTextSize(resources.getDimension(R.dimen.ame_default_cluster_text_size));
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    return paint;
}
 
Example 12
Project: SeafoodBerserker   File: MainFishView.java   View Source Code Vote up 5 votes
private void init(Context context) {
    if (!this.isInEditMode()) {

        splats[0] = BitmapFactory.decodeResource(getResources(), R.drawable.splat1);
        splats[1] = BitmapFactory.decodeResource(getResources(), R.drawable.splat2);
        splats[2] = BitmapFactory.decodeResource(getResources(), R.drawable.splat2);
        anchor[0] = BitmapFactory.decodeResource(getResources(), R.drawable.anchor_sm);
        axes[0] = BitmapFactory.decodeResource(getResources(), R.drawable.axe2);
        bgs[0] = BitmapFactory.decodeResource(getResources(), R.drawable.sea);
        fgtops[0] = BitmapFactory.decodeResource(getResources(), R.drawable.sail);
        fgbottoms[0] = BitmapFactory.decodeResource(getResources(), R.drawable.shipside2);

        final SurfaceHolder holder = getHolder();
        holder.addCallback(this);
        TypedArray fish = getResources().obtainTypedArray(R.array.fish);
        int[] values = getResources().getIntArray(R.array.points);
        totalValue = 0;
        for (int i = 0; i < fish.length(); i++) {
            FlyingItem item = new FlyingItem(BitmapFactory.decodeResource(getResources(), fish.getResourceId(i, 0)));
            item.setValue(values[i]);
            availableItems.add(item);
            totalValue += (100 - values[i]);
        }
        fish.recycle();

        this.setOnTouchListener(this);
        mLinePaint = new Paint();
        mLinePaint.setARGB(255, 255, 64, 64);
        mLinePaint.setStrokeWidth(5);
        mBGPaint = new Paint();
        mBGPaint.setARGB(255, 127, 127, 200);

        mTextPaint = new Paint();
        mTextPaint.setColor(Color.BLACK);
        mTextPaint.setShadowLayer(8,8,8,Color.WHITE);
        mTextPaint.setTextSize(80);

    }
}
 
Example 13
Project: RunHDU   File: GradeProgressView.java   View Source Code Vote up 5 votes
private void setup() {

        mRectF = new RectF();
        mOuterRectF = new RectF();

        mOuterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mOuterPaint.setStrokeWidth(outLineWidth);
        mOuterPaint.setColor(mBackgroundColor);
        mOuterPaint.setStyle(Paint.Style.STROKE);

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStrokeWidth(lineWidth);
        mPaint.setColor(mBackgroundColor);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setPathEffect(new DashPathEffect(new float[]{dashWith, dashSpace}, dashSpace));

        mProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mProgressPaint.setStrokeWidth(lineWidth);
        mProgressPaint.setColor(mProgressColor);
        mProgressPaint.setStyle(Paint.Style.STROKE);
        mProgressPaint.setPathEffect(new DashPathEffect(new float[]{dashWith, dashSpace}, dashSpace));

        mPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPointerPaint.setStrokeWidth(pointLineWidth / 2);
        mPointerPaint.setColor(mProgressColor);
        mPointerPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPointerPaint.setStrokeCap(Paint.Cap.ROUND);
        mPointerPaint.setShadowLayer(4, 3, 0, 0x20000000);

        mInnerCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mInnerCirclePaint.setStrokeWidth(pointLineWidth);
        mInnerCirclePaint.setColor(mProgressColor);
        mInnerCirclePaint.setStyle(Paint.Style.STROKE);
        mInnerCirclePaint.setShadowLayer(4, 3, 0, 0x20000000);
    }
 
Example 14
Project: SmartRefreshLayout   File: MaterialHeader.java   View Source Code Vote up 5 votes
private void initView(Context context, AttributeSet attrs) {
    setMinimumHeight(DensityUtil.dp2px(100));

    mProgress = new MaterialProgressDrawable(context, this);
    mProgress.setBackgroundColor(CIRCLE_BG_LIGHT);
    mProgress.setAlpha(255);
    mProgress.setColorSchemeColors(0xff0099cc,0xffff4444,0xff669900,0xffaa66cc,0xffff8800);
    mCircleView = new CircleImageView(context,CIRCLE_BG_LIGHT);
    mCircleView.setImageDrawable(mProgress);
    mCircleView.setVisibility(View.GONE);
    addView(mCircleView);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleDiameter = (int) (CIRCLE_DIAMETER * metrics.density);

    mBezierPath = new Path();
    mBezierPaint = new Paint();
    mBezierPaint.setAntiAlias(true);
    mBezierPaint.setStyle(Paint.Style.FILL);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MaterialHeader);
    mShowBezierWave = ta.getBoolean(R.styleable.MaterialHeader_mhShowBezierWave, mShowBezierWave);
    mBezierPaint.setColor(ta.getColor(R.styleable.MaterialHeader_mhPrimaryColor, 0xff11bbff));
    if (ta.hasValue(R.styleable.MaterialHeader_mhShadowRadius)) {
        int radius = ta.getDimensionPixelOffset(R.styleable.MaterialHeader_mhShadowRadius, 0);
        int color = ta.getColor(R.styleable.MaterialHeader_mhShadowColor, 0xff000000);
        mBezierPaint.setShadowLayer(radius, 0, 0, color);
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
    ta.recycle();

}
 
Example 15
Project: simple-keyboard   File: MainKeyboardView.java   View Source Code Vote up 5 votes
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) {
    final Keyboard keyboard = getKeyboard();
    if (keyboard == null) {
        return;
    }
    final int width = key.getWidth();
    final int height = key.getHeight();
    paint.setTextAlign(Align.CENTER);
    paint.setTypeface(Typeface.DEFAULT);
    paint.setTextSize(mLanguageOnSpacebarTextSize);
    final String language = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width);
    // Draw language text with shadow
    final float descent = paint.descent();
    final float textHeight = -paint.ascent() + descent;
    final float baseline = height / 2 + textHeight / 2;
    if (mLanguageOnSpacebarTextShadowRadius > 0.0f) {
        paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0,
                mLanguageOnSpacebarTextShadowColor);
    } else {
        paint.clearShadowLayer();
    }
    paint.setColor(mLanguageOnSpacebarTextColor);
    paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
    canvas.drawText(language, width / 2, baseline - descent, paint);
    paint.clearShadowLayer();
    paint.setTextScaleX(1.0f);
}
 
Example 16
Project: SmartRefresh   File: WaterDropView.java   View Source Code Vote up 5 votes
private void initView(Context context, AttributeSet attrs) {
//        setBackgroundColor(0xffbbff11);
        topCircle = new Circle();
        bottomCircle = new Circle();
        mPath = new Path();
        mPaint = new Paint();
        mPaint.setColor(Color.GRAY);
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeWidth(STROKE_WIDTH = DensityUtil.dp2px(1));
        mPaint.setShadowLayer(STROKE_WIDTH, 0, 0, 0xff000000);
        setLayerType(LAYER_TYPE_SOFTWARE, null);

        int padding = 4 * STROKE_WIDTH;
        setPadding(padding, padding, padding, padding);

        mPaint.setColor(Color.GRAY);
        mMaxCircleRadius = DensityUtil.dp2px(20);
        mMinCircleRaidus = mMaxCircleRadius / 4;

        topCircle.radius = (mMaxCircleRadius);
        bottomCircle.radius = (mMaxCircleRadius);

        topCircle.x = (STROKE_WIDTH + mMaxCircleRadius);
        topCircle.y = (STROKE_WIDTH + mMaxCircleRadius);

        bottomCircle.x = (STROKE_WIDTH + mMaxCircleRadius);
        bottomCircle.y = (STROKE_WIDTH + mMaxCircleRadius);
    }
 
Example 17
Project: PaoMovie   File: WaveformView.java   View Source Code Vote up 4 votes
public WaveformView(Context context, AttributeSet attrs) {
       super(context, attrs);

       // We don't want keys, the markers get these
       setFocusable(false);

       mGridPaint = new Paint();
       mGridPaint.setAntiAlias(false);
       mGridPaint.setColor(
           getResources().getColor(R.drawable.grid_line));
       mSelectedLinePaint = new Paint();
       mSelectedLinePaint.setAntiAlias(false);
       mSelectedLinePaint.setColor(
           getResources().getColor(R.drawable.waveform_selected));
       mUnselectedLinePaint = new Paint();
       mUnselectedLinePaint.setAntiAlias(false);
       mUnselectedLinePaint.setColor(
           getResources().getColor(R.drawable.waveform_unselected));
       mUnselectedBkgndLinePaint = new Paint();
       mUnselectedBkgndLinePaint.setAntiAlias(false);
       mUnselectedBkgndLinePaint.setColor(
           getResources().getColor(
               R.drawable.waveform_unselected_bkgnd_overlay));
       mBorderLinePaint = new Paint();
       mBorderLinePaint.setAntiAlias(true);
       mBorderLinePaint.setStrokeWidth(1.5f);
       mBorderLinePaint.setPathEffect(
           new DashPathEffect(new float[] { 3.0f, 2.0f }, 0.0f));
       mBorderLinePaint.setColor(
           getResources().getColor(R.drawable.selection_border));
       mPlaybackLinePaint = new Paint();
       mPlaybackLinePaint.setAntiAlias(false);
       mPlaybackLinePaint.setColor(
           getResources().getColor(R.drawable.playback_indicator));
       mTimecodePaint = new Paint();
       mTimecodePaint.setTextSize(12);
       mTimecodePaint.setAntiAlias(true);
       mTimecodePaint.setColor(
           getResources().getColor(R.drawable.timecode));
       mTimecodePaint.setShadowLayer(
           2, 1, 1,
           getResources().getColor(R.drawable.timecode_shadow));

mGestureDetector = new GestureDetector(
        context,
	new GestureDetector.SimpleOnGestureListener() {
	    public boolean onFling(
		        MotionEvent e1, MotionEvent e2, float vx, float vy) {
		mListener.waveformFling(vx);
		return true;
	    }
	});

       mSoundFile = null;
       mLenByZoomLevel = null;
       mValuesByZoomLevel = null;
       mHeightsAtThisZoomLevel = null;
       mOffset = 0;
       mPlaybackPos = -1;
       mSelectionStart = 0;
       mSelectionEnd = 0;
       mDensity = 1.0f;
       mInitialized = false;
   }
 
Example 18
Project: RetroMusicPlayer   File: ShadowImageView.java   View Source Code Vote up 4 votes
@Override
protected void dispatchDraw(Canvas canvas) {

    if (mInvalidat) {

        mInvalidat = false;

        View view = getChildAt(0);

        Paint shadowPaint = new Paint();

        shadowPaint.setColor(Color.WHITE);
        shadowPaint.setStyle(Paint.Style.FILL);
        shadowPaint.setAntiAlias(true);

        int radius = view.getHeight() / 12 > 40 ? 40 : view.getHeight() / 12;
        int shadowDimen = view.getHeight() / 16 > 28 ? 28 : view.getHeight() / 16;

        Bitmap bitmap;
        int rgb;

        if (((ImageView) view).getDrawable() instanceof ColorDrawable) {
            rgb = ((ColorDrawable) ((ImageView) view).getDrawable()).getColor();
            shadowPaint.setShadowLayer(40, 0, 28, getDarkerColor(rgb));
        } else if (((ImageView) view).getDrawable() instanceof BitmapDrawable) {
            bitmap = ((BitmapDrawable) ((ImageView) view).getDrawable()).getBitmap();
            Palette.Swatch mSwatch = Palette.from(bitmap).generate().getDominantSwatch();

            if (null != mSwatch) {
                rgb = mSwatch.getRgb();
            } else {
                rgb = Color.parseColor("#8D8D8D");
            }

            shadowPaint.setShadowLayer(radius, 0, shadowDimen, getDarkerColor(rgb));
            Bitmap bitmapT = Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 4 * 3,
                    bitmap.getWidth(), bitmap.getHeight() / 4);

            if (null != Palette.from(bitmapT).generate().getDominantSwatch()) {
                rgb = Palette.from(bitmapT).generate().getDominantSwatch().getRgb();
                shadowPaint.setShadowLayer(radius, 0, shadowDimen, rgb);
            }
        } else {
            rgb = Color.parseColor("#8D8D8D");
            shadowPaint.setShadowLayer(radius, 0, shadowDimen, getDarkerColor(rgb));
        }

        if (this.shadowColor != -147483648) {
            shadowPaint.setShadowLayer(radius, 0, shadowDimen, this.shadowColor);
        }

        RectF rectF = new RectF(view.getX() + (view.getWidth() / 20), view.getY(), view.getX() + view.getWidth() - (view.getWidth() / 20), view.getY() + view.getHeight() - ((view.getHeight() / 40)));

        canvas.drawRoundRect(rectF, shadowRound, shadowRound, shadowPaint);

        canvas.save();
    }
    super.dispatchDraw(canvas);
}
 
Example 19
Project: starcor.xul   File: XulWorker.java   View Source Code Vote up 4 votes
private static Bitmap toRoundCornerShadowBitmap(Canvas canvas, Paint paintSolid, Paint paintSrcIn, Paint paintDstOut, Paint paintShadow, Bitmap srcBitmap, float[] roundRadius, float shadowSize, int shadowColor) {
	int borderSize = XulUtils.roundToInt(shadowSize) * 2;
	Bitmap output;
	if (false) {
		output = BitmapTools.createBitmapFromRecycledBitmaps(srcBitmap.getWidth(), srcBitmap.getHeight(), XulManager.DEF_PIXEL_FMT);
	} else {
		output = BitmapTools.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), XulManager.DEF_PIXEL_FMT);
	}
	canvas.setBitmap(output);
	Rect rectSrc = new Rect(0, 0, srcBitmap.getWidth(), srcBitmap.getHeight());
	Rect rectDst = new Rect(rectSrc);
	XulUtils.offsetRect(rectDst, borderSize / 2, borderSize / 2);
	RectF rectF = new RectF(rectDst);
	if (roundRadius.length == 2) {
		float rY = roundRadius[1];
		float rX = roundRadius[0];
		canvas.drawRoundRect(rectF, rX, rY, paintSolid);
		canvas.drawBitmap(srcBitmap, rectSrc, rectDst, paintSrcIn);

		XulUtils.saveCanvasLayer(canvas, 0, 0, output.getWidth(), output.getHeight(), paintSolid, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
		paintShadow.setShadowLayer(shadowSize, 0, 0, shadowColor);
		canvas.drawRoundRect(rectF, rX, rY, paintShadow);
		canvas.drawRoundRect(rectF, rX, rY, paintDstOut);
		XulUtils.restoreCanvas(canvas);
	} else {
		RoundRectShape roundRectShape = new RoundRectShape(roundRadius, null, null);
		roundRectShape.resize(rectF.width(), rectF.height());

		XulUtils.saveCanvas(canvas);
		canvas.translate(rectF.left, rectF.top);
		roundRectShape.draw(canvas, paintSolid);
		canvas.translate(-rectF.left, -rectF.top);

		canvas.drawBitmap(srcBitmap, rectSrc, rectDst, paintSrcIn);
		XulUtils.saveCanvasLayer(canvas, 0, 0, output.getWidth(), output.getHeight(), paintSolid, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
		paintShadow.setShadowLayer(shadowSize, 0, 0, shadowColor);

		canvas.translate(rectF.left, rectF.top);
		roundRectShape.draw(canvas, paintShadow);
		roundRectShape.draw(canvas, paintDstOut);

		XulUtils.restoreCanvas(canvas);
		XulUtils.restoreCanvas(canvas);
	}

	canvas.setBitmap(null);
	return output;
}
 
Example 20
Project: FastAndroid   File: SwitchButton.java   View Source Code Vote up 2 votes
/**
 * 初始化参数
 */
private void initView(Context context, AttributeSet attrs) {
    TypedArray typedArray = null;
    if (attrs != null) {
        typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwitchButton);
    }

    shadowEffect = optBoolean(typedArray, R.styleable.SwitchButton_sb_shadow_effect, true);

    uncheckCircleColor = optColor(typedArray, R.styleable.SwitchButton_sb_uncheckcircle_color, 0XffAAAAAA);

    uncheckCircleWidth = optPixelSize(typedArray, R.styleable.SwitchButton_sb_uncheckcircle_width, dp2pxInt(1.5f));//dp2pxInt(1.5f);

    uncheckCircleOffsetX = dp2px(10);

    uncheckCircleRadius = optPixelSize(typedArray, R.styleable.SwitchButton_sb_uncheckcircle_radius, dp2px(4));//dp2px(4);

    checkedLineOffsetX = dp2px(4);
    checkedLineOffsetY = dp2px(4);

    shadowRadius = optPixelSize(typedArray, R.styleable.SwitchButton_sb_shadow_radius, dp2pxInt(2.5f));//dp2pxInt(2.5f);

    shadowOffset = optPixelSize(typedArray, R.styleable.SwitchButton_sb_shadow_offset, dp2pxInt(1.5f));//dp2pxInt(1.5f);

    shadowColor = optColor(typedArray, R.styleable.SwitchButton_sb_shadow_color, 0X33000000);//0X33000000;

    uncheckColor = optColor(typedArray, R.styleable.SwitchButton_sb_uncheck_color, 0XffDDDDDD);//0XffDDDDDD;

    checkedColor = optColor(typedArray, R.styleable.SwitchButton_sb_checked_color, 0Xff51d367);//0Xff51d367;

    borderWidth = optPixelSize(typedArray, R.styleable.SwitchButton_sb_border_width, dp2pxInt(1));//dp2pxInt(1);

    checkLineColor = optColor(typedArray, R.styleable.SwitchButton_sb_checkline_color, Color.WHITE);//Color.WHITE;

    checkLineWidth = optPixelSize(typedArray, R.styleable.SwitchButton_sb_checkline_width, dp2pxInt(1f));//dp2pxInt(1.0f);

    checkLineLength = dp2px(6);

    int buttonColor = optColor(typedArray, R.styleable.SwitchButton_sb_button_color, Color.WHITE);//Color.WHITE;

    int effectDuration = optInt(typedArray, R.styleable.SwitchButton_sb_effect_duration, 300);//300;

    isChecked = optBoolean(typedArray, R.styleable.SwitchButton_sb_checked, false);

    showIndicator = optBoolean(typedArray, R.styleable.SwitchButton_sb_show_indicator, true);

    background = optColor(typedArray, R.styleable.SwitchButton_sb_background, Color.WHITE);//Color.WHITE;

    enableEffect = optBoolean(typedArray, R.styleable.SwitchButton_sb_enable_effect, true);

    if (typedArray != null) {
        typedArray.recycle();
    }
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    buttonPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    buttonPaint.setColor(buttonColor);

    if (shadowEffect) {
        buttonPaint.setShadowLayer(shadowRadius, 0, shadowOffset, shadowColor);
    }

    viewState = new ViewState();
    beforeState = new ViewState();
    afterState = new ViewState();

    valueAnimator = ValueAnimator.ofFloat(0f, 1f);
    valueAnimator.setDuration(effectDuration);
    valueAnimator.setRepeatCount(0);

    valueAnimator.addUpdateListener(animatorUpdateListener);
    valueAnimator.addListener(animatorListener);

    super.setClickable(true);

    this.setPadding(0, 0, 0, 0);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
}