diff options
Diffstat (limited to 'src')
3 files changed, 71 insertions, 8 deletions
diff --git a/src/com/cyngn/theme/perapptheming/PerAppThemeListLayout.java b/src/com/cyngn/theme/perapptheming/PerAppThemeListLayout.java index e27adad..a1a753d 100644 --- a/src/com/cyngn/theme/perapptheming/PerAppThemeListLayout.java +++ b/src/com/cyngn/theme/perapptheming/PerAppThemeListLayout.java @@ -46,7 +46,7 @@ public class PerAppThemeListLayout extends FrameLayout { super(context, attrs, defStyleAttr); final Resources res = getResources(); float width = res.getDimension(R.dimen.theme_list_width); - float height = res.getDimension(R.dimen.theme_list_height); + float height = res.getDimension(R.dimen.theme_list_max_height); mMaxRadius = (float) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); mRevealPath = new Path(); diff --git a/src/com/cyngn/theme/perapptheming/PerAppThemeListView.java b/src/com/cyngn/theme/perapptheming/PerAppThemeListView.java new file mode 100644 index 0000000..646cb49 --- /dev/null +++ b/src/com/cyngn/theme/perapptheming/PerAppThemeListView.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2015 Cyanogen, Inc. + */ +package com.cyngn.theme.perapptheming; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.widget.ListView; +import com.cyngn.theme.chooser.R; + +public class PerAppThemeListView extends ListView { + private int mMinHeight; + private int mMaxHeight; + + public PerAppThemeListView(Context context) { + this(context, null); + } + + public PerAppThemeListView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public PerAppThemeListView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View); + mMinHeight = a.getDimensionPixelSize(com.android.internal.R.styleable.View_minHeight, 0); + a.recycle(); + + a = context.obtainStyledAttributes(attrs, R.styleable.PerAppThemeListView); + mMaxHeight = a.getDimensionPixelSize(R.styleable.PerAppThemeListView_maxHeight, 0); + a.recycle(); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + // let the super do the heavy lifting and then we'll cap the values to any max and/or min + // values that were defined in the layout + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + int measuredWidth = getMeasuredWidth(); + int measuredHeight = getMeasuredHeight(); + int newHeight = measuredHeight; + if (mMaxHeight > 0) { + newHeight = Math.min(measuredHeight, mMaxHeight); + } + if (mMinHeight > 0) { + newHeight = Math.max(newHeight, mMinHeight); + } + if (newHeight != measuredHeight) { + setMeasuredDimension(measuredWidth, newHeight); + } + } +} diff --git a/src/com/cyngn/theme/perapptheming/PerAppThemingWindow.java b/src/com/cyngn/theme/perapptheming/PerAppThemingWindow.java index 0edf074..0c17ebc 100644 --- a/src/com/cyngn/theme/perapptheming/PerAppThemingWindow.java +++ b/src/com/cyngn/theme/perapptheming/PerAppThemingWindow.java @@ -630,7 +630,8 @@ public class PerAppThemingWindow extends Service implements OnTouchListener, }); animator.addListener(new Animator.AnimatorListener() { @Override - public void onAnimationStart(Animator animation) {} + public void onAnimationStart(Animator animation) { + } @Override public void onAnimationEnd(Animator animation) { @@ -638,10 +639,12 @@ public class PerAppThemingWindow extends Service implements OnTouchListener, } @Override - public void onAnimationCancel(Animator animation) {} + public void onAnimationCancel(Animator animation) { + } @Override - public void onAnimationRepeat(Animator animation) {} + public void onAnimationRepeat(Animator animation) { + } }); animator.start(); mThemeApplyingView.animate() @@ -653,7 +656,15 @@ public class PerAppThemingWindow extends Service implements OnTouchListener, int thirdHeight = getScreenHeight() / 3; // use the center of the fab to decide where to place the list int fabLocationY = mParams.y + mDraggableIconImage.getHeight() / 2; - int listHeight = getResources().getDimensionPixelSize(R.dimen.theme_list_height); + int listHeight = mThemeList.getMeasuredHeight(); + if (listHeight <= 0) { + // not measured yet so let's force that + int width = getResources().getDimensionPixelSize(R.dimen.theme_list_width); + int height = getResources().getDimensionPixelSize(R.dimen.theme_list_max_height); + mThemeList.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.AT_MOST), + View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.AT_MOST)); + listHeight = mThemeList.getMeasuredHeight(); + } // If we're in the top 1/3 of the screen position the top of the list with the top // of the fab. Second 3rd will position the list so that it is vertically centered @@ -664,13 +675,11 @@ public class PerAppThemingWindow extends Service implements OnTouchListener, } else if (fabLocationY < thirdHeight * 2) { mListParams.topMargin = fabLocationY - listHeight / 2; } else { - mListParams.topMargin = mParams.y + mDraggableIconImage.getHeight() - - getResources().getDimensionPixelSize(R.dimen.theme_list_height); + mListParams.topMargin = mParams.y + mDraggableIconImage.getHeight() - listHeight; } mListParams.gravity = Gravity.TOP | (listSide == LIST_ON_LEFT_SIDE ? Gravity.LEFT : Gravity.RIGHT); mThemeList.setLayoutParams(mListParams); - mThemeList.requestLayout(); } private AdapterView.OnItemClickListener mThemeClickedListener = |