reformat code & optimize import & reorder entries
This commit is contained in:
@ -6,159 +6,158 @@ import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
|
||||
public class CardRelativeLayout extends RelativeLayout {
|
||||
|
||||
private Drawable mLeftDrawable, mRightDrawable, topDrawable, bottomDrawable;
|
||||
private Drawable leftTopDrawable, rightTopDrawable, leftBottomDrawable, rightBottomDrawable;
|
||||
private Drawable mLeftDrawable, mRightDrawable, topDrawable, bottomDrawable;
|
||||
private Drawable leftTopDrawable, rightTopDrawable, leftBottomDrawable, rightBottomDrawable;
|
||||
|
||||
private int mLeft, mTop, mRight, mBottom;
|
||||
private int mLeft, mTop, mRight, mBottom;
|
||||
|
||||
private boolean isTran, isReverse;
|
||||
private boolean isTran, isReverse;
|
||||
|
||||
public CardRelativeLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
public CardRelativeLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public CardRelativeLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
public CardRelativeLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public CardRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
public CardRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
setWillNotDraw(false);
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
setWillNotDraw(false);
|
||||
|
||||
if (attrs != null) {
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CardLayout);
|
||||
mLeft = ta.getDimensionPixelSize(R.styleable.CardLayout_left, 0);
|
||||
mTop = ta.getDimensionPixelSize(R.styleable.CardLayout_top, 0);
|
||||
mRight = ta.getDimensionPixelSize(R.styleable.CardLayout_right, 0);
|
||||
mBottom = ta.getDimensionPixelSize(R.styleable.CardLayout_bottom, 0);
|
||||
isTran = ta.getBoolean(R.styleable.CardLayout_tran, false);
|
||||
isReverse = ta.getBoolean(R.styleable.CardLayout_reverse, true);
|
||||
ta.recycle();
|
||||
}
|
||||
if (attrs != null) {
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CardLayout);
|
||||
mLeft = ta.getDimensionPixelSize(R.styleable.CardLayout_left, 0);
|
||||
mTop = ta.getDimensionPixelSize(R.styleable.CardLayout_top, 0);
|
||||
mRight = ta.getDimensionPixelSize(R.styleable.CardLayout_right, 0);
|
||||
mBottom = ta.getDimensionPixelSize(R.styleable.CardLayout_bottom, 0);
|
||||
isTran = ta.getBoolean(R.styleable.CardLayout_tran, false);
|
||||
isReverse = ta.getBoolean(R.styleable.CardLayout_reverse, true);
|
||||
ta.recycle();
|
||||
}
|
||||
|
||||
if (isTran) {
|
||||
mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left);
|
||||
topDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_top);
|
||||
mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right);
|
||||
bottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_bottom);
|
||||
if (isTran) {
|
||||
mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left);
|
||||
topDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_top);
|
||||
mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right);
|
||||
bottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_bottom);
|
||||
|
||||
leftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left_top_square);
|
||||
rightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right_top_square);
|
||||
leftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left_bottom_square);
|
||||
rightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right_bottom_square);
|
||||
} else {
|
||||
mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_left);
|
||||
topDrawable = getContext().getResources().getDrawable(R.drawable.frame_top);
|
||||
mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_right);
|
||||
bottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_bottom);
|
||||
leftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left_top_square);
|
||||
rightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right_top_square);
|
||||
leftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_left_bottom_square);
|
||||
rightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_tran_right_bottom_square);
|
||||
} else {
|
||||
mLeftDrawable = getContext().getResources().getDrawable(R.drawable.frame_left);
|
||||
topDrawable = getContext().getResources().getDrawable(R.drawable.frame_top);
|
||||
mRightDrawable = getContext().getResources().getDrawable(R.drawable.frame_right);
|
||||
bottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_bottom);
|
||||
|
||||
leftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_top_square);
|
||||
rightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_top_square);
|
||||
leftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_bottom_square);
|
||||
rightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_bottom_square);
|
||||
}
|
||||
}
|
||||
leftTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_top_square);
|
||||
rightTopDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_top_square);
|
||||
leftBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_left_bottom_square);
|
||||
rightBottomDrawable = getContext().getResources().getDrawable(R.drawable.frame_right_bottom_square);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (!isReverse) {
|
||||
if (mLeft != 0) {
|
||||
if (mLeftDrawable != null) {
|
||||
mLeftDrawable.setBounds(0, mTop, mLeft, getHeight() - mBottom);
|
||||
mLeftDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
if (mRight != 0) {
|
||||
if (mRightDrawable != null) {
|
||||
mRightDrawable.setBounds(getWidth() - mRight, mTop, getWidth(), getHeight() - mBottom);
|
||||
mRightDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mTop != 0) {
|
||||
if (isReverse) {
|
||||
if (leftBottomDrawable != null) {
|
||||
leftBottomDrawable.setBounds(0, 0, mLeft, mTop);
|
||||
leftBottomDrawable.draw(canvas);
|
||||
}
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (!isReverse) {
|
||||
if (mLeft != 0) {
|
||||
if (mLeftDrawable != null) {
|
||||
mLeftDrawable.setBounds(0, mTop, mLeft, getHeight() - mBottom);
|
||||
mLeftDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
if (mRight != 0) {
|
||||
if (mRightDrawable != null) {
|
||||
mRightDrawable.setBounds(getWidth() - mRight, mTop, getWidth(), getHeight() - mBottom);
|
||||
mRightDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mTop != 0) {
|
||||
if (isReverse) {
|
||||
if (leftBottomDrawable != null) {
|
||||
leftBottomDrawable.setBounds(0, 0, mLeft, mTop);
|
||||
leftBottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (bottomDrawable != null) {
|
||||
bottomDrawable.setBounds(mLeft, 0, getWidth() - mRight, mTop);
|
||||
bottomDrawable.draw(canvas);
|
||||
}
|
||||
if (bottomDrawable != null) {
|
||||
bottomDrawable.setBounds(mLeft, 0, getWidth() - mRight, mTop);
|
||||
bottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (rightBottomDrawable != null) {
|
||||
rightBottomDrawable.setBounds(getWidth() - mRight, 0, getWidth(), mTop);
|
||||
rightBottomDrawable.draw(canvas);
|
||||
}
|
||||
} else {
|
||||
if (leftTopDrawable != null) {
|
||||
leftTopDrawable.setBounds(0, 0, mLeft, mTop);
|
||||
leftTopDrawable.draw(canvas);
|
||||
}
|
||||
if (rightBottomDrawable != null) {
|
||||
rightBottomDrawable.setBounds(getWidth() - mRight, 0, getWidth(), mTop);
|
||||
rightBottomDrawable.draw(canvas);
|
||||
}
|
||||
} else {
|
||||
if (leftTopDrawable != null) {
|
||||
leftTopDrawable.setBounds(0, 0, mLeft, mTop);
|
||||
leftTopDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (topDrawable != null) {
|
||||
topDrawable.setBounds(mLeft, 0, getWidth() - mRight, mTop);
|
||||
topDrawable.draw(canvas);
|
||||
}
|
||||
if (topDrawable != null) {
|
||||
topDrawable.setBounds(mLeft, 0, getWidth() - mRight, mTop);
|
||||
topDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (rightTopDrawable != null) {
|
||||
rightTopDrawable.setBounds(getWidth() - mRight, 0, getWidth(), mTop);
|
||||
rightTopDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mBottom != 0) {
|
||||
if (isReverse) {
|
||||
if (leftTopDrawable != null) {
|
||||
leftTopDrawable.setBounds(0, getHeight() - mBottom, mLeft, getHeight());
|
||||
leftTopDrawable.draw(canvas);
|
||||
}
|
||||
if (rightTopDrawable != null) {
|
||||
rightTopDrawable.setBounds(getWidth() - mRight, 0, getWidth(), mTop);
|
||||
rightTopDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mBottom != 0) {
|
||||
if (isReverse) {
|
||||
if (leftTopDrawable != null) {
|
||||
leftTopDrawable.setBounds(0, getHeight() - mBottom, mLeft, getHeight());
|
||||
leftTopDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (topDrawable != null) {
|
||||
topDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight());
|
||||
topDrawable.draw(canvas);
|
||||
}
|
||||
if (topDrawable != null) {
|
||||
topDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight());
|
||||
topDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (rightTopDrawable != null) {
|
||||
rightTopDrawable.setBounds(getWidth() - mRight, getHeight() - mBottom, getWidth(), getHeight());
|
||||
rightTopDrawable.draw(canvas);
|
||||
}
|
||||
} else {
|
||||
if (leftBottomDrawable != null) {
|
||||
leftBottomDrawable.setBounds(0, getHeight() - mBottom, mLeft, getHeight());
|
||||
leftBottomDrawable.draw(canvas);
|
||||
}
|
||||
if (rightTopDrawable != null) {
|
||||
rightTopDrawable.setBounds(getWidth() - mRight, getHeight() - mBottom, getWidth(), getHeight());
|
||||
rightTopDrawable.draw(canvas);
|
||||
}
|
||||
} else {
|
||||
if (leftBottomDrawable != null) {
|
||||
leftBottomDrawable.setBounds(0, getHeight() - mBottom, mLeft, getHeight());
|
||||
leftBottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (bottomDrawable != null) {
|
||||
bottomDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight());
|
||||
bottomDrawable.draw(canvas);
|
||||
}
|
||||
if (bottomDrawable != null) {
|
||||
bottomDrawable.setBounds(mLeft, getHeight() - mBottom, getWidth() - mRight, getHeight());
|
||||
bottomDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
if (rightBottomDrawable != null) {
|
||||
rightBottomDrawable.setBounds(getWidth() - mRight, getHeight() - mBottom, getWidth(), getHeight());
|
||||
rightBottomDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rightBottomDrawable != null) {
|
||||
rightBottomDrawable.setBounds(getWidth() - mRight, getHeight() - mBottom, getWidth(), getHeight());
|
||||
rightBottomDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setmBottom(int mBottom) {
|
||||
this.mBottom = mBottom;
|
||||
}
|
||||
public void setmBottom(int mBottom) {
|
||||
this.mBottom = mBottom;
|
||||
}
|
||||
|
||||
public void setmTop(int mTop) {
|
||||
this.mTop = mTop;
|
||||
}
|
||||
public void setmTop(int mTop) {
|
||||
this.mTop = mTop;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user