use of android.graphics.drawable.GradientDrawable in project android_frameworks_base by crdroidandroid.
the class MLand method reset.
public void reset() {
L("reset");
final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]);
sky.setDither(true);
setBackground(sky);
mFlipped = frand() > 0.5f;
setScaleX(mFlipped ? -1 : 1);
int i = getChildCount();
while (i-- > 0) {
final View v = getChildAt(i);
if (v instanceof GameView) {
removeViewAt(i);
}
}
mObstaclesInPlay.clear();
mCurrentPipeId = 0;
mWidth = getWidth();
mHeight = getHeight();
boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25;
if (showingSun) {
final Star sun = new Star(getContext());
sun.setBackgroundResource(R.drawable.sun);
final int w = getResources().getDimensionPixelSize(R.dimen.sun_size);
sun.setTranslationX(frand(w, mWidth - w));
if (mTimeOfDay == DAY) {
sun.setTranslationY(frand(w, (mHeight * 0.66f)));
sun.getBackground().setTint(0);
} else {
sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w));
sun.getBackground().setTintMode(PorterDuff.Mode.SRC_ATOP);
sun.getBackground().setTint(0xC0FF8000);
}
addView(sun, new LayoutParams(w, w));
}
if (!showingSun) {
final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT;
final float ff = frand();
if ((dark && ff < 0.75f) || ff < 0.5f) {
final Star moon = new Star(getContext());
moon.setBackgroundResource(R.drawable.moon);
moon.getBackground().setAlpha(dark ? 255 : 128);
moon.setScaleX(frand() > 0.5 ? -1 : 1);
moon.setRotation(moon.getScaleX() * frand(5, 30));
final int w = getResources().getDimensionPixelSize(R.dimen.sun_size);
moon.setTranslationX(frand(w, mWidth - w));
moon.setTranslationY(frand(w, mHeight - w));
addView(moon, new LayoutParams(w, w));
}
}
final int mh = mHeight / 6;
final boolean cloudless = frand() < 0.25;
final int N = 20;
for (i = 0; i < N; i++) {
final float r1 = frand();
final Scenery s;
if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) {
s = new Star(getContext());
} else if (r1 < 0.6 && !cloudless) {
s = new Cloud(getContext());
} else {
switch(mScene) {
case SCENE_ZRH:
s = new Mountain(getContext());
break;
case SCENE_TX:
s = new Cactus(getContext());
break;
case SCENE_CITY:
default:
s = new Building(getContext());
break;
}
s.z = (float) i / N;
// no more shadows for these things
//s.setTranslationZ(PARAMS.SCENERY_Z * (1+s.z));
// buildings move proportional to their distance
s.v = 0.85f * s.z;
if (mScene == SCENE_CITY) {
s.setBackgroundColor(Color.GRAY);
s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh);
}
final int c = (int) (255f * s.z);
final Drawable bg = s.getBackground();
if (bg != null)
bg.setColorFilter(Color.rgb(c, c, c), PorterDuff.Mode.MULTIPLY);
}
final LayoutParams lp = new LayoutParams(s.w, s.h);
if (s instanceof Building) {
lp.gravity = Gravity.BOTTOM;
} else {
lp.gravity = Gravity.TOP;
final float r = frand();
if (s instanceof Star) {
lp.topMargin = (int) (r * r * mHeight);
} else {
lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2;
}
}
addView(s, lp);
s.setTranslationX(frand(-lp.width, mWidth + lp.width));
}
for (Player p : mPlayers) {
// put it back!
addView(p);
p.reset();
}
realignPlayers();
if (mAnim != null) {
mAnim.cancel();
}
mAnim = new TimeAnimator();
mAnim.setTimeListener(new TimeAnimator.TimeListener() {
@Override
public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) {
step(t, dt);
}
});
}
use of android.graphics.drawable.GradientDrawable in project android-toolbox by Knickedi.
the class TabManagerView method generateDefaultTabProgrammatically.
private View generateDefaultTabProgrammatically() {
DefaultLayoutSetup setup = mDefaultLayoutSetup;
FrameLayout imageContainer = new FrameLayout(getContext());
LinearLayout.LayoutParams icp = new LinearLayout.LayoutParams(setup.image + setup.overlayOffset * 2, LayoutParams.WRAP_CONTENT);
icp.gravity = Gravity.CENTER_HORIZONTAL;
imageContainer.setLayoutParams(icp);
ProgressBar busy = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleSmall);
FrameLayout.LayoutParams bp = new FrameLayout.LayoutParams(setup.overlay, setup.overlay + setup.border);
busy.setLayoutParams(bp);
busy.setId(android.R.id.icon1);
busy.setVisibility(View.GONE);
busy.setPadding(0, 0, 0, setup.border);
ImageView status = new ImageView(getContext());
FrameLayout.LayoutParams sp = new FrameLayout.LayoutParams(setup.overlay, setup.overlay + setup.border);
sp.gravity = Gravity.RIGHT | Gravity.TOP;
status.setLayoutParams(sp);
status.setId(android.R.id.icon2);
status.setVisibility(View.GONE);
status.setPadding(0, 0, 0, setup.border);
ImageView image = new ImageView(getContext());
FrameLayout.LayoutParams ip = new FrameLayout.LayoutParams(setup.image, setup.image + setup.border + setup.overlayOffset);
ip.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
image.setLayoutParams(ip);
image.setId(android.R.id.icon);
image.setVisibility(View.GONE);
image.setPadding(0, setup.overlayOffset, 0, setup.border);
imageContainer.addView(image);
imageContainer.addView(busy);
imageContainer.addView(status);
LinearLayout tab = new LinearLayout(getContext());
tab.setOrientation(LinearLayout.VERTICAL);
tab.setGravity(Gravity.BOTTOM);
tab.setPadding(setup.border, setup.border, setup.border, 0);
TextView title = new TextView(getContext());
LinearLayout.LayoutParams tp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
tp.gravity = Gravity.CENTER_HORIZONTAL;
tp.bottomMargin = setup.border;
title.setLayoutParams(tp);
title.setEllipsize(TruncateAt.MARQUEE);
title.setSingleLine(true);
title.setId(android.R.id.title);
title.setVisibility(View.GONE);
title.setTextColor(new ColorStateList(new int[][] { { android.R.attr.state_selected }, { android.R.attr.state_pressed }, {} }, setup.titleColors));
StateListDrawable background = new StateListDrawable();
background.addState(new int[] { android.R.attr.state_selected }, new GradientDrawable(setup.selectedOrientation, setup.selectedColors));
background.addState(new int[] { android.R.attr.state_pressed }, new GradientDrawable(setup.pressedOrientation, setup.pressedColors));
background.addState(new int[] {}, new GradientDrawable(setup.normalOrientation, setup.noramlColors));
tab.addView(imageContainer);
tab.addView(title);
tab.setBackgroundDrawable(background);
return tab;
}
use of android.graphics.drawable.GradientDrawable in project android_frameworks_base by crdroidandroid.
the class VolumeDialog method setVolumeStroke.
public void setVolumeStroke() {
mVolumeDialogStroke = Settings.System.getInt(mContext.getContentResolver(), Settings.System.VOLUME_DIALOG_STROKE, 0);
mCustomStrokeColor = Settings.System.getInt(mContext.getContentResolver(), Settings.System.VOLUME_DIALOG_STROKE_COLOR, mContext.getResources().getColor(R.color.system_accent_color));
mCustomStrokeThickness = Settings.System.getInt(mContext.getContentResolver(), Settings.System.VOLUME_DIALOG_STROKE_THICKNESS, 4);
mCustomCornerRadius = Settings.System.getInt(mContext.getContentResolver(), Settings.System.VOLUME_DIALOG_CORNER_RADIUS, 10);
mCustomDashWidth = Settings.System.getInt(mContext.getContentResolver(), Settings.System.VOLUME_DIALOG_STROKE_DASH_WIDTH, 0);
mCustomDashGap = Settings.System.getInt(mContext.getContentResolver(), Settings.System.VOLUME_DIALOG_STROKE_DASH_GAP, 10);
final GradientDrawable volumeDialogGd = new GradientDrawable();
if (mVolumeDialogStroke == 0) {
// Disable by setting border thickness to 0
volumeDialogGd.setColor(mContext.getResources().getColor(R.color.system_primary_color));
volumeDialogGd.setStroke(0, mContext.getResources().getColor(R.color.system_accent_color));
volumeDialogGd.setCornerRadius(mCustomCornerRadius);
mDialogView.setBackground(volumeDialogGd);
} else if (mVolumeDialogStroke == 1) {
// use accent color for border
volumeDialogGd.setColor(mContext.getResources().getColor(R.color.system_primary_color));
volumeDialogGd.setStroke(mCustomStrokeThickness, mContext.getResources().getColor(R.color.system_accent_color), mCustomDashWidth, mCustomDashGap);
} else if (mVolumeDialogStroke == 2) {
// use custom border color
volumeDialogGd.setColor(mContext.getResources().getColor(R.color.system_primary_color));
volumeDialogGd.setStroke(mCustomStrokeThickness, mCustomStrokeColor, mCustomDashWidth, mCustomDashGap);
}
if (mVolumeDialogStroke != 0) {
volumeDialogGd.setCornerRadius(mCustomCornerRadius);
mDialogView.setBackground(volumeDialogGd);
}
}
use of android.graphics.drawable.GradientDrawable in project android_frameworks_base by AOSPA.
the class MLand method reset.
public void reset() {
L("reset");
final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]);
sky.setDither(true);
setBackground(sky);
mFlipped = frand() > 0.5f;
setScaleX(mFlipped ? -1 : 1);
int i = getChildCount();
while (i-- > 0) {
final View v = getChildAt(i);
if (v instanceof GameView) {
removeViewAt(i);
}
}
mObstaclesInPlay.clear();
mCurrentPipeId = 0;
mWidth = getWidth();
mHeight = getHeight();
boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25;
if (showingSun) {
final Star sun = new Star(getContext());
sun.setBackgroundResource(R.drawable.sun);
final int w = getResources().getDimensionPixelSize(R.dimen.sun_size);
sun.setTranslationX(frand(w, mWidth - w));
if (mTimeOfDay == DAY) {
sun.setTranslationY(frand(w, (mHeight * 0.66f)));
sun.getBackground().setTint(0);
} else {
sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w));
sun.getBackground().setTintMode(PorterDuff.Mode.SRC_ATOP);
sun.getBackground().setTint(0xC0FF8000);
}
addView(sun, new LayoutParams(w, w));
}
if (!showingSun) {
final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT;
final float ff = frand();
if ((dark && ff < 0.75f) || ff < 0.5f) {
final Star moon = new Star(getContext());
moon.setBackgroundResource(R.drawable.moon);
moon.getBackground().setAlpha(dark ? 255 : 128);
moon.setScaleX(frand() > 0.5 ? -1 : 1);
moon.setRotation(moon.getScaleX() * frand(5, 30));
final int w = getResources().getDimensionPixelSize(R.dimen.sun_size);
moon.setTranslationX(frand(w, mWidth - w));
moon.setTranslationY(frand(w, mHeight - w));
addView(moon, new LayoutParams(w, w));
}
}
final int mh = mHeight / 6;
final boolean cloudless = frand() < 0.25;
final int N = 20;
for (i = 0; i < N; i++) {
final float r1 = frand();
final Scenery s;
if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) {
s = new Star(getContext());
} else if (r1 < 0.6 && !cloudless) {
s = new Cloud(getContext());
} else {
switch(mScene) {
case SCENE_ZRH:
s = new Mountain(getContext());
break;
case SCENE_TX:
s = new Cactus(getContext());
break;
case SCENE_CITY:
default:
s = new Building(getContext());
break;
}
s.z = (float) i / N;
// no more shadows for these things
//s.setTranslationZ(PARAMS.SCENERY_Z * (1+s.z));
// buildings move proportional to their distance
s.v = 0.85f * s.z;
if (mScene == SCENE_CITY) {
s.setBackgroundColor(Color.GRAY);
s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh);
}
final int c = (int) (255f * s.z);
final Drawable bg = s.getBackground();
if (bg != null)
bg.setColorFilter(Color.rgb(c, c, c), PorterDuff.Mode.MULTIPLY);
}
final LayoutParams lp = new LayoutParams(s.w, s.h);
if (s instanceof Building) {
lp.gravity = Gravity.BOTTOM;
} else {
lp.gravity = Gravity.TOP;
final float r = frand();
if (s instanceof Star) {
lp.topMargin = (int) (r * r * mHeight);
} else {
lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2;
}
}
addView(s, lp);
s.setTranslationX(frand(-lp.width, mWidth + lp.width));
}
for (Player p : mPlayers) {
// put it back!
addView(p);
p.reset();
}
realignPlayers();
if (mAnim != null) {
mAnim.cancel();
}
mAnim = new TimeAnimator();
mAnim.setTimeListener(new TimeAnimator.TimeListener() {
@Override
public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) {
step(t, dt);
}
});
}
use of android.graphics.drawable.GradientDrawable in project BookReader by JustWayward.
the class OverlappedWidget method drawCurrentPageShadow.
@Override
protected void drawCurrentPageShadow(Canvas canvas) {
canvas.save();
GradientDrawable shadow;
if (actiondownX > mScreenWidth >> 1) {
shadow = mBackShadowDrawableLR;
shadow.setBounds((int) (mScreenWidth + touch_down - 5), 0, (int) (mScreenWidth + touch_down + 5), mScreenHeight);
} else {
shadow = mBackShadowDrawableRL;
shadow.setBounds((int) (touch_down - 5), 0, (int) (touch_down + 5), mScreenHeight);
}
shadow.draw(canvas);
try {
canvas.restore();
} catch (Exception e) {
}
}
Aggregations