Java 类android.graphics.drawable.PaintDrawable 实例源码

项目:Ariana    文件:Ariana.java   
public static Drawable drawable(final int[] colorBoxes, final float[] position, final GradientAngle gradientAngle) {
    ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            AngleCoordinate ac = AngleCoordinate.getAngleCoordinate(gradientAngle, width, height);
            LinearGradient linearGradient = new LinearGradient(ac.x1, ac.y1, ac.x2, ac.y2,
                    colorBoxes,
                    position,
                    Shader.TileMode.REPEAT);
            return linearGradient;
        }
    };
    PaintDrawable paint = new PaintDrawable();
    paint.setShape(new RectShape());
    paint.setShaderFactory(shaderFactory);
    return paint;
}
项目:InsanityRadio-Android    文件:ActionBarButtonBackground.java   
public ActionBarButtonBackground(int accentHeight, int strokeWidth, Integer strokeColor, Integer accentColor, Integer fillColor, Integer highlightColor, ActionBarOptions.ColorLayout colorLayout) {
    super(new Drawable[] { 
            new PaintDrawable((strokeColor == null) ? DEFAULT_STROKE_COLOR : strokeColor),  
            new PaintDrawable((accentColor == null) ? DEFAULT_ACCENT_COLOR : accentColor), 
            new PaintDrawable((highlightColor == null) ? DEFAULT_HIGHLIGHT_COLOR : highlightColor),
            new PaintDrawable((fillColor == null) ? DEFAULT_FILL_COLOR : fillColor)});


    if(colorLayout.equals(ColorLayout.TOP)) {
        setLayerInset(1, strokeWidth, strokeWidth, 0, 0);
        setLayerInset(2, strokeWidth, accentHeight+strokeWidth, 0, 0);
        setLayerInset(3, strokeWidth, accentHeight+strokeWidth, 0, strokeWidth);
    }
    else {
        setLayerInset(1, strokeWidth, 0, 0, strokeWidth);
        setLayerInset(2, strokeWidth, 0, 0, accentHeight+strokeWidth);
        setLayerInset(3, strokeWidth, strokeWidth, 0, accentHeight+strokeWidth);
    }
}
项目:InsanityRadio-Android    文件:ActionBarButtonBackground.java   
public ActionBarButtonBackground(int accentHeight, int strokeWidth, Integer strokeColor, Integer accentColor, Integer fillColor, Integer highlightColor, ActionBarOptions.ColorLayout colorLayout) {
    super(new Drawable[] { 
            new PaintDrawable((strokeColor == null) ? DEFAULT_STROKE_COLOR : strokeColor),  
            new PaintDrawable((accentColor == null) ? DEFAULT_ACCENT_COLOR : accentColor), 
            new PaintDrawable((highlightColor == null) ? DEFAULT_HIGHLIGHT_COLOR : highlightColor),
            new PaintDrawable((fillColor == null) ? DEFAULT_FILL_COLOR : fillColor)});


    if(colorLayout.equals(ColorLayout.TOP)) {
        setLayerInset(1, strokeWidth, strokeWidth, 0, 0);
        setLayerInset(2, strokeWidth, accentHeight+strokeWidth, 0, 0);
        setLayerInset(3, strokeWidth, accentHeight+strokeWidth, 0, strokeWidth);
    }
    else {
        setLayerInset(1, strokeWidth, 0, 0, strokeWidth);
        setLayerInset(2, strokeWidth, 0, 0, accentHeight+strokeWidth);
        setLayerInset(3, strokeWidth, strokeWidth, 0, accentHeight+strokeWidth);
    }
}
项目:NyaungUConverter    文件:FlatUI.java   
/**
 * Returns a suitable drawable for ActionBar with theme colors.
 *
 * @param theme        selected theme
 * @param dark         boolean for choosing dark colors or primary colors
 * @param borderBottom bottom border width
 * @return drawable to be used in ActionBar
 */
public static Drawable getActionBarDrawable(Activity activity, int theme, boolean dark, float borderBottom) {
    int[] colors = activity.getResources().getIntArray(theme);

    int color1 = colors[2];
    int color2 = colors[1];

    if (dark) {
        color1 = colors[1];
        color2 = colors[0];
    }

    borderBottom = dipToPx(activity, borderBottom);

    PaintDrawable front = new PaintDrawable(color1);
    PaintDrawable bottom = new PaintDrawable(color2);
    Drawable[] d = {bottom, front};
    LayerDrawable drawable = new LayerDrawable(d);
    drawable.setLayerInset(1, 0, 0, 0, (int) borderBottom);
    return drawable;
}
项目:Genius-Android    文件:Ui.java   
/**
 * Returns a suitable drawable for ActionBar with theme colors.
 *
 * @param theme        selected theme
 * @param dark         boolean for choosing dark colors or primary colors
 * @param borderBottom bottom border width
 * @return drawable to be used in ActionBar
 */
public static Drawable getActionBarDrawable(Activity activity, int theme, boolean dark, float borderBottom) {
    int[] colors = activity.getResources().getIntArray(theme);

    int color1 = colors[2];
    int color2 = colors[1];

    if (dark) {
        color1 = colors[1];
        color2 = colors[0];
    }

    borderBottom = dipToPx(activity, borderBottom);

    PaintDrawable front = new PaintDrawable(color1);
    PaintDrawable bottom = new PaintDrawable(color2);
    Drawable[] d = {bottom, front};
    LayerDrawable drawable = new LayerDrawable(d);
    drawable.setLayerInset(1, 0, 0, 0, (int) borderBottom);
    return drawable;
}
项目:Genius-Android    文件:GeniusUI.java   
/**
 * Returns a suitable drawable for ActionBar with theme colors.
 *
 * @param theme        selected theme
 * @param dark         boolean for choosing dark colors or primary colors
 * @param borderBottom bottom border width
 * @return drawable to be used in ActionBar
 */
public static Drawable getActionBarDrawable(Activity activity, int theme, boolean dark, float borderBottom) {
    int[] colors = activity.getResources().getIntArray(theme);

    int color1 = colors[2];
    int color2 = colors[1];

    if (dark) {
        color1 = colors[1];
        color2 = colors[0];
    }

    borderBottom = dipToPx(activity, borderBottom);

    PaintDrawable front = new PaintDrawable(color1);
    PaintDrawable bottom = new PaintDrawable(color2);
    Drawable[] d = {bottom, front};
    LayerDrawable drawable = new LayerDrawable(d);
    drawable.setLayerInset(1, 0, 0, 0, (int) borderBottom);
    return drawable;
}
项目:GreenDamFileExploere    文件:FlatUI.java   
/**
 * Returns a suitable drawable for ActionBar with theme colors.
 *
 * @param theme        selected theme
 * @param dark         boolean for choosing dark colors or primary colors
 * @param borderBottom bottom border width
 * @return drawable to be used in ActionBar
 */
public static Drawable getActionBarDrawable(Activity activity, int theme, boolean dark, float borderBottom) {
    int[] colors = activity.getResources().getIntArray(theme);

    int color1 = colors[2];
    int color2 = colors[1];

    if (dark) {
        color1 = colors[1];
        color2 = colors[0];
    }

    borderBottom = dipToPx(activity, borderBottom);

    PaintDrawable front = new PaintDrawable(color1);
    PaintDrawable bottom = new PaintDrawable(color2);
    Drawable[] d = {bottom, front};
    LayerDrawable drawable = new LayerDrawable(d);
    drawable.setLayerInset(1, 0, 0, 0, (int) borderBottom);
    return drawable;
}
项目:indoorlib    文件:MapScrollView.java   
/**
 * @param context
 * @param zoomController
 */
private void makeZoomLabel(Context context, ZoomButtonsController zoomController) {
    ViewGroup container = zoomController.getContainer();
    View controls = zoomController.getZoomControls();
    LayoutParams p0 = controls.getLayoutParams();
    container.removeView(controls);
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    mZoomLabel = new TextView(context);
    mZoomLabel.setPadding(12, 0, 12, 0);
    mZoomLabel.setTypeface(Typeface.DEFAULT_BOLD);
    mZoomLabel.setTextColor(0xff000000);
    PaintDrawable d = new PaintDrawable(0xeeffffff);
    d.setCornerRadius(6);
    mZoomLabel.setBackgroundDrawable(d);
    mZoomLabel.setTextSize(20);
    mZoomLabel.setGravity(Gravity.CENTER_HORIZONTAL);
    LinearLayout.LayoutParams p1 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    p1.gravity = Gravity.CENTER_HORIZONTAL;
    layout.addView(mZoomLabel, p1);
    layout.addView(controls);
    container.addView(layout, p0);
}
项目:Demos    文件:FillBlankView.java   
@Override
public void onClick(final View widget) {
    View view = LayoutInflater.from(context).inflate(R.layout.layout_input, null);
    final EditText etInput = (EditText) view.findViewById(R.id.et_answer);
    Button btnFillBlank = (Button) view.findViewById(R.id.btn_fill_blank);

    // 显示原有答案
    String oldAnswer = answerList.get(position);
    if (!TextUtils.isEmpty(oldAnswer)) {
        etInput.setText(oldAnswer);
        etInput.setSelection(oldAnswer.length());
    }

    final PopupWindow popupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT, dp2px(40));
    // 获取焦点
    popupWindow.setFocusable(true);
    // 为了防止弹出菜单获取焦点之后,点击Activity的其他组件没有响应
    popupWindow.setBackgroundDrawable(new PaintDrawable());
    // 设置PopupWindow在软键盘的上方
    popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    // 弹出PopupWindow
    popupWindow.showAtLocation(tvContent, Gravity.BOTTOM, 0, 0);

    btnFillBlank.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // 填写答案
            String answer = etInput.getText().toString();
            fillAnswer(answer, position);
            popupWindow.dismiss();
        }
    });

    // 显示软键盘
    InputMethodManager inputMethodManager =
            (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
项目:TreebolicLib    文件:SplitPaneLayout.java   
/**
 * Basic constructor
 *
 * @param context context
 */
public SplitPaneLayout(final Context context)
{
    super(context);

    this.orientation = SplitPaneLayout.ORIENTATION_HORIZONTAL;
    this.splitterPositionPercent = 0.5f;
    this.splitterPosition = Integer.MIN_VALUE;
    this.splitterDrawable = new PaintDrawable(SPLITTER_COLOR);
    this.splitterDraggingDrawable = new PaintDrawable(SPLITTER_DRAG_COLOR);
}
项目:InsanityRadio-Android    文件:CommentListItemBackgroundFactory.java   
protected Drawable makeDefaultBackground() {
    PaintDrawable shadow = new PaintDrawable(bottomColor);
    PaintDrawable highlight = new PaintDrawable(topColor);
    PaintDrawable surface = new PaintDrawable(bgColor);
    LayerDrawable layers = new LayerDrawable(new Drawable[] {shadow, highlight, surface});

    layers.setLayerInset(0, 0, 0, 0, 0);
    layers.setLayerInset(1, 0, 0, 0, 1);
    layers.setLayerInset(2, 0, 1, 0, 1);

    return layers;
}
项目:BlendedBackground    文件:Gradient.java   
private Drawable createDrawableFrom(ShapeDrawable.ShaderFactory sf) {
    PaintDrawable p = new PaintDrawable();
    p.setShape(new RectShape());
    p.setShaderFactory(sf);

    return p;
}
项目:DiaryMemo    文件:DrawNoteList.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_draw);
    findViewById(R.id.btn_add).setOnClickListener(this);
    list_menu = (LinearLayout) findViewById(R.id.list_menu);
    list_menu.setVisibility(View.GONE);
    findViewById(R.id.btn_edit).setOnClickListener(this);
    findViewById(R.id.btn_share).setOnClickListener(this);
    findViewById(R.id.btn_setting).setOnClickListener(this);
    findViewById(R.id.btn_check).setOnClickListener(this);
    findViewById(R.id.btn_delete).setOnClickListener(this);
    findViewById(R.id.btn_notemain).setOnClickListener(this);

    mTodoList = new ArrayList<DrawNoteList_Row>();
    selectedPosition = -1;

    PaintDrawable d = new PaintDrawable(Color.TRANSPARENT);
    getListView().setSelector(d);

    //서비스 해제
    AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(DrawNoteList.this, DrawNoteNotification.class);
    PendingIntent pi = PendingIntent.getService(DrawNoteList.this, 0, intent, 0);
    am.cancel(pi);
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancelAll();
}
项目:igcparser    文件:FlightPreviewActivity.java   
public PaintDrawable getColorScala() {
    ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(width, height, 0, 0,
                    new int[]{
                            getResources().getColor(R.color.altitude_0_100),
                            getResources().getColor(R.color.altitude_100_300),
                            getResources().getColor(R.color.altitude_300_500),
                            getResources().getColor(R.color.altitude_500_1000),
                            getResources().getColor(R.color.altitude_1000_1500),
                            getResources().getColor(R.color.altitude_1500_2000),
                            getResources().getColor(R.color.altitude_2000_2500),
                            getResources().getColor(R.color.altitude_more_than_2500)},
                    new float[]{
                            0, 0.07f, 0.14f, 0.28f, 0.42f, 0.56f, 0.7f, 0.84f},
                    Shader.TileMode.REPEAT);
            return linearGradient;
        }
    };

    PaintDrawable paint = new PaintDrawable();
    paint.setShape(new RectShape());
    paint.setShaderFactory(shaderFactory);

    return paint;
}
项目:InsanityRadio-Android    文件:CommentListItemBackgroundFactory.java   
protected Drawable makeDefaultBackground() {
    PaintDrawable shadow = new PaintDrawable(bottomColor);
    PaintDrawable highlight = new PaintDrawable(topColor);
    PaintDrawable surface = new PaintDrawable(bgColor);
    LayerDrawable layers = new LayerDrawable(new Drawable[] {shadow, highlight, surface});

    layers.setLayerInset(0, 0, 0, 0, 0);
    layers.setLayerInset(1, 0, 0, 0, 1);
    layers.setLayerInset(2, 0, 1, 0, 1);

    return layers;
}
项目:FMTech    文件:ActionBarHelper.java   
private static Drawable getBackgroundColorDrawable(int paramInt)
{
  SoftReference localSoftReference = (SoftReference)sBackgroundCache.get(Integer.valueOf(paramInt));
  if ((localSoftReference == null) || (localSoftReference.get() == null))
  {
    localSoftReference = new SoftReference(new PaintDrawable(paramInt));
    sBackgroundCache.put(Integer.valueOf(paramInt), localSoftReference);
  }
  return (Drawable)localSoftReference.get();
}
项目:FMTech    文件:DetailsSummary.java   
public void setThumbnailMode(int paramInt)
{
  int i = 1;
  int j;
  if (this.mThumbnailMode != paramInt)
  {
    this.mThumbnailMode = paramInt;
    j = getResources().getColor(2131689753);
    if (this.mThumbnailMode != i) {
      break label77;
    }
    if (i == 0) {
      break label82;
    }
    setBackgroundDrawable(new InsetDrawable(new PaintDrawable(j), 0, this.mThumbnailVerticalPeek, 0, 0));
  }
  for (;;)
  {
    ViewCompat.setPaddingRelative(this, 0, 0, 0, 0);
    requestLayout();
    return;
    label77:
    i = 0;
    break;
    label82:
    setBackgroundColor(j);
  }
}
项目:FMTech    文件:PlayCardViewBase.java   
public void draw(Canvas paramCanvas)
{
  super.draw(paramCanvas);
  int i = getWidth();
  int j = getHeight();
  if (this.mToDisplayAsDisabled)
  {
    if (this.mDisabledDrawable == null) {
      this.mDisabledDrawable = new PaintDrawable(getResources().getColor(R.color.play_dismissed_overlay));
    }
    this.mDisabledDrawable.setBounds(0, 0, i, j);
    this.mDisabledDrawable.draw(paramCanvas);
  }
}
项目:kora    文件:ColorButton.java   
protected void init()
{
    mPaintDrawable = new PaintDrawable();
    mPaintDrawable.setCornerRadius(4);
    mPaintDrawable.setBounds(0, 0, 30, 25);
    setCompoundDrawables(mPaintDrawable, null, null, null);

    setText(R.string.colorButtonText);

    setOnClickListener(listener);
}
项目:QuizUpWinner    文件:RoundDialogFrame.java   
@TargetApi(16)
private void ˊ()
{
  this. = new PaintDrawable();
  this..getPaint().setColor(this.ˊ);
  this..setPadding(this.ˎ, this.ˋ, this.ˎ, this.ˋ);
  this..setCornerRadius(this.ˏ);
  if (Build.VERSION.SDK_INT < 16)
  {
    setBackgroundDrawable(this.);
    return;
  }
  setBackground(this.);
}
项目:ilearnrw-reader    文件:SideSelector.java   
public void init(){
    drawable = new PaintDrawable();
    paint = drawable.getPaint();
    paint.setTextSize(30);
    paint.setTextAlign(Paint.Align.CENTER);
    drawable.setCornerRadius(15);
    setBackground(drawable);
}
项目:music_player    文件:ScrimUtil.java   
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtil.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}
项目:Quran    文件:QuranDisplayHelper.java   
public static PaintDrawable getPaintDrawable(int startX, int endX) {
  PaintDrawable drawable = new PaintDrawable();
  drawable.setShape(new RectShape());
  drawable.setShaderFactory(getShaderFactory(startX, endX));
  return drawable;
}
项目:buildAPKsSamples    文件:Home.java   
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ApplicationInfo info = mApplications.get(position);

    if (convertView == null) {
        final LayoutInflater inflater = getLayoutInflater();
        convertView = inflater.inflate(R.layout.application, parent, false);
    }

    Drawable icon = info.icon;

    if (!info.filtered) {
        //final Resources resources = getContext().getResources();
        int width = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);
        int height = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);

        final int iconWidth = icon.getIntrinsicWidth();
        final int iconHeight = icon.getIntrinsicHeight();

        if (icon instanceof PaintDrawable) {
            PaintDrawable painter = (PaintDrawable) icon;
            painter.setIntrinsicWidth(width);
            painter.setIntrinsicHeight(height);
        }

        if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) {
            final float ratio = (float) iconWidth / iconHeight;

            if (iconWidth > iconHeight) {
                height = (int) (width / ratio);
            } else if (iconHeight > iconWidth) {
                width = (int) (height * ratio);
            }

            final Bitmap.Config c =
                    icon.getOpacity() != PixelFormat.OPAQUE ?
                        Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
            final Bitmap thumb = Bitmap.createBitmap(width, height, c);
            final Canvas canvas = new Canvas(thumb);
            canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0));
            // Copy the old bounds to restore them later
            // If we were to do oldBounds = icon.getBounds(),
            // the call to setBounds() that follows would
            // change the same instance and we would lose the
            // old bounds
            mOldBounds.set(icon.getBounds());
            icon.setBounds(0, 0, width, height);
            icon.draw(canvas);
            icon.setBounds(mOldBounds);
            icon = info.icon = new BitmapDrawable(thumb);
            info.filtered = true;
        }
    }

    final TextView textView = (TextView) convertView.findViewById(R.id.label);
    textView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
    textView.setText(info.title);

    return convertView;
}
项目:iosched-reader    文件:UIUtils.java   
/**
 * This helper method creates a 'nice' scrim or background protection for layering text over
 * an image. This non-linear scrim is less noticable than a linear or constant one.
 *
 * Borrowed from github.com/romannurik/muzei
 *
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        double x = i * 1f / (numStops - 1);
        double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
        stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
项目:TreebolicLib    文件:SplitPaneLayout.java   
private void extractAttributes(@NonNull final Context context, @Nullable final AttributeSet attrs)
{
    if (attrs != null)
    {
        final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.SplitPaneLayout);

        // misc
        this.orientation = array.getInt(R.styleable.SplitPaneLayout_orientation, 0);
        this.splitterSize = array.getDimensionPixelSize(R.styleable.SplitPaneLayout_splitterSize, context.getResources().getDimensionPixelSize(R.dimen.spl_default_splitter_size));
        this.splitterMovable = array.getBoolean(R.styleable.SplitPaneLayout_splitterMovable, true);

        // position
        TypedValue value = array.peekValue(R.styleable.SplitPaneLayout_splitterPosition);
        if (value != null)
        {
            if (value.type == TypedValue.TYPE_DIMENSION)
            {
                this.splitterPosition = array.getDimensionPixelSize(R.styleable.SplitPaneLayout_splitterPosition, Integer.MIN_VALUE);
                this.splitterPositionPercent = -1;
            }
            else if (value.type == TypedValue.TYPE_FRACTION)
            {
                this.splitterPositionPercent = array.getFraction(R.styleable.SplitPaneLayout_splitterPosition, 100, 100, 50) * 0.01f;
                this.splitterPosition = Integer.MIN_VALUE;
            }
        }
        else
        {
            this.splitterPosition = Integer.MIN_VALUE;
            this.splitterPositionPercent = 0.5f;
        }

        // backgrounds
        value = array.peekValue(R.styleable.SplitPaneLayout_splitterBackground);
        if (value != null)
        {
            if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING)
            {
                this.splitterDrawable = array.getDrawable(R.styleable.SplitPaneLayout_splitterBackground);
            }
            else if (value.type == TypedValue.TYPE_INT_COLOR_ARGB8 || value.type == TypedValue.TYPE_INT_COLOR_ARGB4 || value.type == TypedValue.TYPE_INT_COLOR_RGB8 || value.type == TypedValue.TYPE_INT_COLOR_RGB4)
            {
                this.splitterDrawable = new PaintDrawable(array.getColor(R.styleable.SplitPaneLayout_splitterBackground, 0xFF000000));
            }
        }
        value = array.peekValue(R.styleable.SplitPaneLayout_splitterDraggingBackground);
        if (value != null)
        {
            if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING)
            {
                this.splitterDraggingDrawable = array.getDrawable(R.styleable.SplitPaneLayout_splitterDraggingBackground);
            }
            else if (value.type == TypedValue.TYPE_INT_COLOR_ARGB8 || value.type == TypedValue.TYPE_INT_COLOR_ARGB4 || value.type == TypedValue.TYPE_INT_COLOR_RGB8 || value.type == TypedValue.TYPE_INT_COLOR_RGB4)
            {
                this.splitterDraggingDrawable = new PaintDrawable(array.getColor(R.styleable.SplitPaneLayout_splitterDraggingBackground, SPLITTER_DRAG_COLOR));
            }
        }
        else
        {
            this.splitterDraggingDrawable = new PaintDrawable(SPLITTER_DRAG_COLOR);
        }
        array.recycle();
    }
}
项目:smconf-android    文件:UIUtils.java   
/**
 * This helper method creates a 'nice' scrim or background protection for layering text over
 * an image. This non-linear scrim is less noticable than a linear or constant one.
 *
 * Borrowed from github.com/romannurik/muzei
 *
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        double x = i * 1f / (numStops - 1);
        double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
        stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
项目:xowa_android    文件:GradientUtil.java   
public static Drawable getCubicGradient(int baseColor, int gravity) {
    PaintDrawable drawable = new PaintDrawable();
    drawable.setShape(new RectShape());
    setCubicGradient(drawable, baseColor, gravity);
    return drawable;
}
项目:xowa_android    文件:GradientUtil.java   
/**
 * Create a cubic gradient by using a compound gradient composed of a series of linear
 * gradients with intermediate color values.
 * adapted from: https://github.com/romannurik/muzei/blob/master/main/src/main/java/com/google/android/apps/muzei/util/ScrimUtil.java
 * @param baseColor The color from which the gradient starts (the ending color is transparent).
 * @param gravity Where the gradient should start from. Note: when making horizontal gradients,
 *                remember to use START/END, instead of LEFT/RIGHT.
 */
public static void setCubicGradient(PaintDrawable drawable, int baseColor, int gravity) {
    final int[] stopColors = new int[GRADIENT_NUM_STOPS];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < GRADIENT_NUM_STOPS; i++) {
        float x = i * 1f / (GRADIENT_NUM_STOPS - 1);
        float opacity = MathUtil.constrain((float) Math.pow(x, GRADIENT_POWER), 0.0f, 1.0f);
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.START:
            x0 = 1;
            x1 = 0;
            break;
        case Gravity.END:
            x0 = 0;
            x1 = 1;
            break;
        default:
            x0 = 0;
            x1 = 0;
            break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            y0 = 1;
            y1 = 0;
            break;
        case Gravity.BOTTOM:
            y0 = 0;
            y1 = 1;
            break;
        default:
            y0 = 0;
            y1 = 0;
            break;
    }

    drawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width * x0, height * y0, width * x1, height * y1,
                                      stopColors, null, Shader.TileMode.CLAMP);
        }
    });
}
项目:StatusBarColorManager    文件:ScrimUtil.java   
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtil.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}
项目:Amumu    文件:ScrimUtil.java   
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(@ColorInt int baseColor,
                                                      int numStops,
                                                      int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtils.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = ColorUtils.modifyAlpha(baseColor, (int) (alpha * opacity));
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:
            x0 = 1;
            x1 = 0;
            break;
        case Gravity.RIGHT:
            x0 = 0;
            x1 = 1;
            break;
        default:
            x0 = 0;
            x1 = 0;
            break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            y0 = 1;
            y1 = 0;
            break;
        case Gravity.BOTTOM:
            y0 = 0;
            y1 = 1;
            break;
        default:
            y0 = 0;
            y1 = 0;
            break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
项目:2015-Google-I-O-app    文件:UIUtils.java   
/**
 * This helper method creates a 'nice' scrim or background protection for layering text over
 * an image. This non-linear scrim is less noticable than a linear or constant one.
 *
 * Borrowed from github.com/romannurik/muzei
 *
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        double x = i * 1f / (numStops - 1);
        double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
        stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
项目:DialogUtils    文件:ScrimUtil.java   
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {

    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;

    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }

    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
       /* float opacity = MathUtil.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);*/
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}
项目:android-proguards    文件:ScrimUtil.java   
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(@ColorInt int baseColor,
                                                      int numStops,
                                                      int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtils.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = ColorUtils.modifyAlpha(baseColor, (int) (alpha * opacity));
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:
            x0 = 1;
            x1 = 0;
            break;
        case Gravity.RIGHT:
            x0 = 0;
            x1 = 1;
            break;
        default:
            x0 = 0;
            x1 = 0;
            break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            y0 = 1;
            y1 = 0;
            break;
        case Gravity.BOTTOM:
            y0 = 0;
            y1 = 1;
            break;
        default:
            y0 = 0;
            y1 = 0;
            break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
项目:OldDriver-master    文件:ScrimUtil.java   
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(@ColorInt int baseColor,
                                                      int numStops,
                                                      int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtils.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = ColorUtils.modifyAlpha(baseColor, (int) (alpha * opacity));
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:
            x0 = 1;
            x1 = 0;
            break;
        case Gravity.RIGHT:
            x0 = 0;
            x1 = 1;
            break;
        default:
            x0 = 0;
            x1 = 0;
            break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            y0 = 1;
            y1 = 0;
            break;
        case Gravity.BOTTOM:
            y0 = 0;
            y1 = 1;
            break;
        default:
            y0 = 0;
            y1 = 0;
            break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
项目:FMTech    文件:UIUtils.java   
/**
 * This helper method creates a 'nice' scrim or background protection for layering text over
 * an image. This non-linear scrim is less noticable than a linear or constant one.
 *
 * Borrowed from github.com/romannurik/muzei
 *
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        double x = i * 1f / (numStops - 1);
        double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
        stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
项目:AndroidLiveWallpaperHelloWorld    文件:ScrimUtil.java   
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtil.constrain(0, 1, FloatMath.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
项目:JJCamera    文件:UIUtils.java   
/**
 * This helper method creates a 'nice' scrim or background protection for layering text over
 * an image. This non-linear scrim is less noticable than a linear or constant one.
 *
 * Borrowed from github.com/romannurik/muzei
 *
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        double x = i * 1f / (numStops - 1);
        double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
        stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:  x0 = 1; x1 = 0; break;
        case Gravity.RIGHT: x0 = 0; x1 = 1; break;
        default:            x0 = 0; x1 = 0; break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:    y0 = 1; y1 = 0; break;
        case Gravity.BOTTOM: y0 = 0; y1 = 1; break;
        default:             y0 = 0; y1 = 0; break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}
项目:NyaungUConverter    文件:FlatSeekBar.java   
private void init(AttributeSet attrs) {

        if (attributes == null)
            attributes = new Attributes(this, getResources());

        if (attrs != null) {
            TypedArray a = getContext().obtainStyledAttributes(attrs, com.cengalabs.flatui.R.styleable.fl_FlatSeekBar);

            // getting common attributes
            int customTheme = a.getResourceId(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_theme, Attributes.DEFAULT_THEME);
            attributes.setThemeSilent(customTheme, getResources());

            attributes.setSize(a.getDimensionPixelSize(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_size, Attributes.DEFAULT_SIZE_PX));

            a.recycle();
        }

        // setting thumb
        PaintDrawable thumb = new PaintDrawable(attributes.getColor(0));
        thumb.setCornerRadius(attributes.getSize() * 9 / 8);
        thumb.setIntrinsicWidth(attributes.getSize() * 9 / 4);
        thumb.setIntrinsicHeight(attributes.getSize() * 9 / 4);
        setThumb(thumb);

        // progress
        PaintDrawable progress = new PaintDrawable(attributes.getColor(1));
        progress.setCornerRadius(attributes.getSize());
        progress.setIntrinsicHeight(attributes.getSize());
        progress.setIntrinsicWidth(attributes.getSize());
        progress.setDither(true);
        ClipDrawable progressClip = new ClipDrawable(progress, Gravity.LEFT, ClipDrawable.HORIZONTAL);

        // secondary progress
        PaintDrawable secondary = new PaintDrawable(attributes.getColor(2));
        secondary.setCornerRadius(attributes.getSize());
        secondary.setIntrinsicHeight(attributes.getSize());
        ClipDrawable secondaryProgressClip = new ClipDrawable(secondary, Gravity.LEFT, ClipDrawable.HORIZONTAL);

        // background
        PaintDrawable background = new PaintDrawable(attributes.getColor(3));
        background.setCornerRadius(attributes.getSize());
        background.setIntrinsicHeight(attributes.getSize());

        // applying drawable
        LayerDrawable ld = (LayerDrawable) getProgressDrawable();
        ld.setDrawableByLayerId(R.id.background, background);
        ld.setDrawableByLayerId(R.id.progress, progressClip);
        ld.setDrawableByLayerId(R.id.secondaryProgress, secondaryProgressClip);
    }
项目:plaid    文件:ScrimUtil.java   
/**
 * Creates an approximated cubic gradient using a multi-stop linear gradient. See
 * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
 * details.
 */
public static Drawable makeCubicGradientScrimDrawable(@ColorInt int baseColor,
                                                      int numStops,
                                                      int gravity) {
    numStops = Math.max(numStops, 2);

    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());

    final int[] stopColors = new int[numStops];

    int alpha = Color.alpha(baseColor);

    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtils.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = ColorUtils.modifyAlpha(baseColor, (int) (alpha * opacity));
    }

    final float x0, x1, y0, y1;
    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:
            x0 = 1;
            x1 = 0;
            break;
        case Gravity.RIGHT:
            x0 = 0;
            x1 = 1;
            break;
        default:
            x0 = 0;
            x1 = 0;
            break;
    }
    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            y0 = 1;
            y1 = 0;
            break;
        case Gravity.BOTTOM:
            y0 = 0;
            y1 = 1;
            break;
        default:
            y0 = 0;
            y1 = 0;
            break;
    }

    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient linearGradient = new LinearGradient(
                    width * x0,
                    height * y0,
                    width * x1,
                    height * y1,
                    stopColors, null,
                    Shader.TileMode.CLAMP);
            return linearGradient;
        }
    });

    return paintDrawable;
}