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;
}
java类android.graphics.drawable.PaintDrawable的实例源码
Ariana.java 文件源码
项目:Ariana
阅读 30
收藏 0
点赞 0
评论 0
ActionBarButtonBackground.java 文件源码
项目:InsanityRadio-Android
阅读 22
收藏 0
点赞 0
评论 0
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);
}
}
ActionBarButtonBackground.java 文件源码
项目:InsanityRadio-Android
阅读 22
收藏 0
点赞 0
评论 0
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);
}
}
FlatUI.java 文件源码
项目:NyaungUConverter
阅读 18
收藏 0
点赞 0
评论 0
/**
* 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;
}
Ui.java 文件源码
项目:Genius-Android
阅读 34
收藏 0
点赞 0
评论 0
/**
* 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;
}
GeniusUI.java 文件源码
项目:Genius-Android
阅读 21
收藏 0
点赞 0
评论 0
/**
* 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;
}
FlatUI.java 文件源码
项目:GreenDamFileExploere
阅读 21
收藏 0
点赞 0
评论 0
/**
* 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;
}
MapScrollView.java 文件源码
项目:indoorlib
阅读 20
收藏 0
点赞 0
评论 0
/**
* @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);
}
FillBlankView.java 文件源码
项目:Demos
阅读 30
收藏 0
点赞 0
评论 0
@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);
}
SplitPaneLayout.java 文件源码
项目:TreebolicLib
阅读 17
收藏 0
点赞 0
评论 0
/**
* 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);
}
CommentListItemBackgroundFactory.java 文件源码
项目:InsanityRadio-Android
阅读 20
收藏 0
点赞 0
评论 0
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;
}
Gradient.java 文件源码
项目:BlendedBackground
阅读 23
收藏 0
点赞 0
评论 0
private Drawable createDrawableFrom(ShapeDrawable.ShaderFactory sf) {
PaintDrawable p = new PaintDrawable();
p.setShape(new RectShape());
p.setShaderFactory(sf);
return p;
}
DrawNoteList.java 文件源码
项目:DiaryMemo
阅读 21
收藏 0
点赞 0
评论 0
@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();
}
FlightPreviewActivity.java 文件源码
项目:igcparser
阅读 21
收藏 0
点赞 0
评论 0
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;
}
CommentListItemBackgroundFactory.java 文件源码
项目:InsanityRadio-Android
阅读 19
收藏 0
点赞 0
评论 0
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;
}
ActionBarHelper.java 文件源码
项目:FMTech
阅读 27
收藏 0
点赞 0
评论 0
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();
}
DetailsSummary.java 文件源码
项目:FMTech
阅读 16
收藏 0
点赞 0
评论 0
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);
}
}
PlayCardViewBase.java 文件源码
项目:FMTech
阅读 19
收藏 0
点赞 0
评论 0
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);
}
}
ColorButton.java 文件源码
项目:kora
阅读 26
收藏 0
点赞 0
评论 0
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);
}
RoundDialogFrame.java 文件源码
项目:QuizUpWinner
阅读 21
收藏 0
点赞 0
评论 0
@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.ᐝ);
}
SideSelector.java 文件源码
项目:ilearnrw-reader
阅读 23
收藏 0
点赞 0
评论 0
public void init(){
drawable = new PaintDrawable();
paint = drawable.getPaint();
paint.setTextSize(30);
paint.setTextAlign(Paint.Align.CENTER);
drawable.setCornerRadius(15);
setBackground(drawable);
}
ScrimUtil.java 文件源码
项目:music_player
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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;
}
QuranDisplayHelper.java 文件源码
项目:Quran
阅读 28
收藏 0
点赞 0
评论 0
public static PaintDrawable getPaintDrawable(int startX, int endX) {
PaintDrawable drawable = new PaintDrawable();
drawable.setShape(new RectShape());
drawable.setShaderFactory(getShaderFactory(startX, endX));
return drawable;
}
Home.java 文件源码
项目:buildAPKsSamples
阅读 28
收藏 0
点赞 0
评论 0
@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;
}
UIUtils.java 文件源码
项目:iosched-reader
阅读 41
收藏 0
点赞 0
评论 0
/**
* 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;
}
SplitPaneLayout.java 文件源码
项目:TreebolicLib
阅读 25
收藏 0
点赞 0
评论 0
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();
}
}
UIUtils.java 文件源码
项目:smconf-android
阅读 23
收藏 0
点赞 0
评论 0
/**
* 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;
}
GradientUtil.java 文件源码
项目:xowa_android
阅读 19
收藏 0
点赞 0
评论 0
public static Drawable getCubicGradient(int baseColor, int gravity) {
PaintDrawable drawable = new PaintDrawable();
drawable.setShape(new RectShape());
setCubicGradient(drawable, baseColor, gravity);
return drawable;
}
GradientUtil.java 文件源码
项目:xowa_android
阅读 20
收藏 0
点赞 0
评论 0
/**
* 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);
}
});
}
ScrimUtil.java 文件源码
项目:StatusBarColorManager
阅读 22
收藏 0
点赞 0
评论 0
/**
* 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;
}