A lot of fixes and small changes

This commit is contained in:
Karim Abou Zeid 2015-05-29 21:24:11 +02:00
commit 865f72e5bb
33 changed files with 360 additions and 479 deletions

View file

@ -7,17 +7,17 @@ import android.widget.ImageView;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public class HeightAndWidthFitSquarePlaceLeftRightImageView extends ImageView {
public class HeightWidthFitSquareImageView extends ImageView {
public HeightAndWidthFitSquarePlaceLeftRightImageView(Context context) {
public HeightWidthFitSquareImageView(Context context) {
super(context);
}
public HeightAndWidthFitSquarePlaceLeftRightImageView(Context context, AttributeSet attrs) {
public HeightWidthFitSquareImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public HeightAndWidthFitSquarePlaceLeftRightImageView(Context context, AttributeSet attrs, int defStyle) {
public HeightWidthFitSquareImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

View file

@ -44,8 +44,6 @@ public class PlayPauseDrawable extends Drawable {
private float width;
private float height;
private final float fallBackWidth;
private final float fallBackHeight;
private float progress;
private boolean isPlay;
@ -61,8 +59,6 @@ public class PlayPauseDrawable extends Drawable {
pauseBarWidth = res.getDimensionPixelSize(R.dimen.pause_bar_width);
pauseBarHeight = res.getDimensionPixelSize(R.dimen.pause_bar_height);
pauseBarDistance = res.getDimensionPixelSize(R.dimen.pause_bar_distance);
fallBackWidth = res.getDimensionPixelSize(R.dimen.fab_icon_bound_width);
fallBackHeight = res.getDimensionPixelSize(R.dimen.fab_icon_bound_height);
}
@Override
@ -71,9 +67,6 @@ public class PlayPauseDrawable extends Drawable {
if (bounds.width() > 0 && bounds.height() > 0) {
width = bounds.width();
height = bounds.height();
} else {
width = fallBackWidth;
height = fallBackHeight;
}
}

View file

@ -1,126 +0,0 @@
package com.kabouzeid.gramophone.views;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import com.kabouzeid.gramophone.R;
/**
* A layout that draws something in the insets passed to {@link #fitSystemWindows(Rect)}, i.e. the area above UI chrome
* (status and navigation bars, overlay action bars).
*/
public class ScrimInsetsFrameLayout extends FrameLayout {
private Drawable mInsetForeground;
private Rect mInsets;
private Rect mTempRect = new Rect();
private OnInsetsCallback mOnInsetsCallback;
public ScrimInsetsFrameLayout(Context context) {
super(context);
init(context, null, 0);
}
public ScrimInsetsFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle) {
final TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.ScrimInsetsView, defStyle, 0);
if (a == null) {
return;
}
mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsView_insetForeground);
a.recycle();
setWillNotDraw(true);
}
@Override
protected boolean fitSystemWindows(Rect insets) {
mInsets = new Rect(insets);
setWillNotDraw(mInsetForeground == null);
ViewCompat.postInvalidateOnAnimation(this);
if (mOnInsetsCallback != null) {
mOnInsetsCallback.onInsetsChanged(insets);
}
return true; // consume insets
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
int width = getWidth();
int height = getHeight();
if (mInsets != null && mInsetForeground != null) {
int sc = canvas.save();
canvas.translate(getScrollX(), getScrollY());
// Top
mTempRect.set(0, 0, width, mInsets.top);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
// Bottom
mTempRect.set(0, height - mInsets.bottom, width, height);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
// Left
mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
// Right
mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
canvas.restoreToCount(sc);
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mInsetForeground != null) {
mInsetForeground.setCallback(this);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mInsetForeground != null) {
mInsetForeground.setCallback(null);
}
}
/**
* Allows the calling container to specify a callback for custom processing when insets change (i.e. when
* {@link #fitSystemWindows(Rect)} is called. This is useful for setting padding on UI elements based on
* UI chrome insets (e.g. a Google Map or a ListView). When using with ListView or GridView, remember to set
* clipToPadding to false.
*/
public void setOnInsetsCallback(OnInsetsCallback onInsetsCallback) {
mOnInsetsCallback = onInsetsCallback;
}
public static interface OnInsetsCallback {
public void onInsetsChanged(Rect insets);
}
}

View file

@ -8,17 +8,18 @@ import android.widget.ImageView;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public class SquareIfPlaceLeftRightImageView extends ImageView {
public class SquareIfPlaceImageView extends ImageView {
private boolean forceSquare = false;
public SquareIfPlaceLeftRightImageView(Context context) {
public SquareIfPlaceImageView(Context context) {
super(context);
}
public SquareIfPlaceLeftRightImageView(Context context, AttributeSet attrs) {
public SquareIfPlaceImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareIfPlaceLeftRightImageView(Context context, AttributeSet attrs, int defStyle) {
public SquareIfPlaceImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@ -27,9 +28,17 @@ public class SquareIfPlaceLeftRightImageView extends ImageView {
final int small = Math.min(widthMeasureSpec, heightMeasureSpec);
final int large = Math.max(widthMeasureSpec, heightMeasureSpec);
if (View.MeasureSpec.getSize(large) > View.MeasureSpec.getSize(small) * 1.5)
if (forceSquare) super.onMeasure(small, small);
else if (View.MeasureSpec.getSize(large) > View.MeasureSpec.getSize(small) * 1.5)
super.onMeasure(small, small);
else super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public void forceSquare(boolean force) {
if (forceSquare != force) {
forceSquare = force;
invalidate();
}
}
}