use of android.graphics.drawable.ShapeDrawable in project android_frameworks_base by ParanoidAndroid.
the class ProgressBar method tileify.
/**
* Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i), (id == R.id.progress || id == R.id.secondaryProgress));
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = in.getStateCount();
for (int i = 0; i < numStates; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
} else if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
}
use of android.graphics.drawable.ShapeDrawable in project AndroidTraining by mixi-inc.
the class IcsProgressBar method tileify.
/**
* Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
private Drawable tileify(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress));
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else /* else if (drawable instanceof StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = in.getStateCount();
for (int i = 0; i < numStates; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
}*/
if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (mSampleTile == null) {
mSampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
}
return drawable;
}
use of android.graphics.drawable.ShapeDrawable in project FloatingActionButton by Clans.
the class Label method createRectDrawable.
private Drawable createRectDrawable(int color) {
RoundRectShape shape = new RoundRectShape(new float[] { mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius }, null, null);
ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
shapeDrawable.getPaint().setColor(color);
return shapeDrawable;
}
use of android.graphics.drawable.ShapeDrawable in project FreeFlow by Comcast.
the class DefaultSectionAdapter method getItemView.
@Override
@SuppressWarnings(value = { "deprecation" })
public View getItemView(int section, int position, View convertView, ViewGroup parent) {
TextView tv = null;
if (convertView != null) {
tv = (TextView) convertView;
} else {
tv = new TextView(context);
RectShape rs = new RectShape();
ShapeDrawable sd = new BottomBorderBackground(rs, Color.WHITE, Color.GRAY);
tv.setBackgroundDrawable(sd);
tv.setPadding(20, 0, 0, 0);
tv.setGravity(Gravity.CENTER_VERTICAL);
}
tv.setLayoutParams(new LayoutParams(300, itemHeight));
tv.setText("s" + section + " p" + position);
return tv;
}
use of android.graphics.drawable.ShapeDrawable in project Timber by naman14.
the class PlayTransition method createAnimator.
@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) {
if (startValues == null || endValues == null) {
return null;
}
Rect startBounds = (Rect) startValues.values.get(PROPERTY_BOUNDS);
Rect endBounds = (Rect) endValues.values.get(PROPERTY_BOUNDS);
if (startBounds == null || endBounds == null || startBounds.equals(endBounds)) {
return null;
}
Bitmap startImage = (Bitmap) startValues.values.get(PROPERTY_IMAGE);
Drawable startBackground = new BitmapDrawable(sceneRoot.getContext().getResources(), startImage);
final View startView = addViewToOverlay(sceneRoot, startImage.getWidth(), startImage.getHeight(), startBackground);
Drawable shrinkingBackground = new ColorDrawable(mColor);
final View shrinkingView = addViewToOverlay(sceneRoot, startImage.getWidth(), startImage.getHeight(), shrinkingBackground);
int[] sceneRootLoc = new int[2];
sceneRoot.getLocationInWindow(sceneRootLoc);
int[] startLoc = (int[]) startValues.values.get(PROPERTY_POSITION);
int startTranslationX = startLoc[0] - sceneRootLoc[0];
int startTranslationY = startLoc[1] - sceneRootLoc[1];
startView.setTranslationX(startTranslationX);
startView.setTranslationY(startTranslationY);
shrinkingView.setTranslationX(startTranslationX);
shrinkingView.setTranslationY(startTranslationY);
final View endView = endValues.view;
float startRadius = calculateMaxRadius(shrinkingView);
int minRadius = Math.min(calculateMinRadius(shrinkingView), calculateMinRadius(endView));
ShapeDrawable circleBackground = new ShapeDrawable(new OvalShape());
circleBackground.getPaint().setColor(mColor);
final View circleView = addViewToOverlay(sceneRoot, minRadius * 2, minRadius * 2, circleBackground);
float circleStartX = startLoc[0] - sceneRootLoc[0] + ((startView.getWidth() - circleView.getWidth()) / 2);
float circleStartY = startLoc[1] - sceneRootLoc[1] + ((startView.getHeight() - circleView.getHeight()) / 2);
circleView.setTranslationX(circleStartX);
circleView.setTranslationY(circleStartY);
circleView.setVisibility(View.INVISIBLE);
shrinkingView.setAlpha(0f);
endView.setAlpha(0f);
Animator shrinkingAnimator = createCircularReveal(shrinkingView, startRadius, minRadius);
shrinkingAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
shrinkingView.setVisibility(View.INVISIBLE);
startView.setVisibility(View.INVISIBLE);
circleView.setVisibility(View.VISIBLE);
}
});
Animator startAnimator = createCircularReveal(startView, startRadius, minRadius);
Animator fadeInAnimator = ObjectAnimator.ofFloat(shrinkingView, View.ALPHA, 0, 1);
AnimatorSet shrinkFadeSet = new AnimatorSet();
shrinkFadeSet.playTogether(shrinkingAnimator, startAnimator, fadeInAnimator);
int[] endLoc = (int[]) endValues.values.get(PROPERTY_POSITION);
float circleEndX = endLoc[0] - sceneRootLoc[0] + ((endView.getWidth() - circleView.getWidth()) / 2);
float circleEndY = endLoc[1] - sceneRootLoc[1] + ((endView.getHeight() - circleView.getHeight()) / 2);
Path circlePath = getPathMotion().getPath(circleStartX, circleStartY, circleEndX, circleEndY);
Animator circleAnimator = ObjectAnimator.ofFloat(circleView, View.TRANSLATION_X, View.TRANSLATION_Y, circlePath);
final View growingView = addViewToOverlay(sceneRoot, endView.getWidth(), endView.getHeight(), shrinkingBackground);
growingView.setVisibility(View.INVISIBLE);
float endTranslationX = endLoc[0] - sceneRootLoc[0];
float endTranslationY = endLoc[1] - sceneRootLoc[1];
growingView.setTranslationX(endTranslationX);
growingView.setTranslationY(endTranslationY);
float endRadius = calculateMaxRadius(endView);
circleAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
circleView.setVisibility(View.INVISIBLE);
growingView.setVisibility(View.VISIBLE);
endView.setAlpha(1f);
}
});
Animator fadeOutAnimator = ObjectAnimator.ofFloat(growingView, View.ALPHA, 1, 0);
Animator endAnimator = createCircularReveal(endView, minRadius, endRadius);
Animator growingAnimator = createCircularReveal(growingView, minRadius, endRadius);
growingAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
sceneRoot.getOverlay().remove(startView);
sceneRoot.getOverlay().remove(shrinkingView);
sceneRoot.getOverlay().remove(circleView);
sceneRoot.getOverlay().remove(growingView);
}
});
AnimatorSet growingFadeSet = new AnimatorSet();
growingFadeSet.playTogether(fadeOutAnimator, endAnimator, growingAnimator);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playSequentially(shrinkFadeSet, circleAnimator, growingFadeSet);
return animatorSet;
}
Aggregations