diff options
18 files changed, 227 insertions, 9 deletions
diff --git a/res/drawable-hdpi/ic_apply_apply.png b/res/drawable-hdpi/ic_apply_apply.png Binary files differnew file mode 100644 index 0000000..47a83f4 --- /dev/null +++ b/res/drawable-hdpi/ic_apply_apply.png diff --git a/res/drawable-hdpi/ic_apply_cancel.png b/res/drawable-hdpi/ic_apply_cancel.png Binary files differnew file mode 100644 index 0000000..dcf4ee2 --- /dev/null +++ b/res/drawable-hdpi/ic_apply_cancel.png diff --git a/res/drawable-mdpi/ic_apply_apply.png b/res/drawable-mdpi/ic_apply_apply.png Binary files differnew file mode 100644 index 0000000..2ba22c2 --- /dev/null +++ b/res/drawable-mdpi/ic_apply_apply.png diff --git a/res/drawable-mdpi/ic_apply_cancel.png b/res/drawable-mdpi/ic_apply_cancel.png Binary files differnew file mode 100644 index 0000000..70cd1cb --- /dev/null +++ b/res/drawable-mdpi/ic_apply_cancel.png diff --git a/res/drawable-xhdpi/ic_apply_apply.png b/res/drawable-xhdpi/ic_apply_apply.png Binary files differnew file mode 100644 index 0000000..440de29 --- /dev/null +++ b/res/drawable-xhdpi/ic_apply_apply.png diff --git a/res/drawable-xhdpi/ic_apply_cancel.png b/res/drawable-xhdpi/ic_apply_cancel.png Binary files differnew file mode 100644 index 0000000..fb675b1 --- /dev/null +++ b/res/drawable-xhdpi/ic_apply_cancel.png diff --git a/res/drawable-xxhdpi/ic_apply_apply.png b/res/drawable-xxhdpi/ic_apply_apply.png Binary files differnew file mode 100644 index 0000000..deee90d --- /dev/null +++ b/res/drawable-xxhdpi/ic_apply_apply.png diff --git a/res/drawable-xxhdpi/ic_apply_cancel.png b/res/drawable-xxhdpi/ic_apply_cancel.png Binary files differnew file mode 100644 index 0000000..1dcc184 --- /dev/null +++ b/res/drawable-xxhdpi/ic_apply_cancel.png diff --git a/res/drawable/apply_cancel_bg.xml b/res/drawable/apply_cancel_bg.xml new file mode 100644 index 0000000..f367f0e --- /dev/null +++ b/res/drawable/apply_cancel_bg.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + + <item android:state_pressed="true" android:drawable="@drawable/apply_circle_bg" /> + <item android:drawable="@android:color/transparent" /> + +</selector>
\ No newline at end of file diff --git a/res/drawable/apply_circle_bg.xml b/res/drawable/apply_circle_bg.xml new file mode 100644 index 0000000..5451bd7 --- /dev/null +++ b/res/drawable/apply_circle_bg.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> + +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="oval"> + + <solid android:color="@color/apply_layout_button_bg_color"/> + +</shape>
\ No newline at end of file diff --git a/res/layout/apply_theme_layout.xml b/res/layout/apply_theme_layout.xml new file mode 100644 index 0000000..225192c --- /dev/null +++ b/res/layout/apply_theme_layout.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="utf-8"?> + +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/apply_theme_layout" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:visibility="gone" + android:background="@color/apply_layout_background"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="132dp" + android:layout_gravity="top|center_horizontal" + android:gravity="center" + android:textStyle="bold" + android:textSize="20sp" + android:textColor="@color/apply_layout_text_color" + android:textAllCaps="true" + android:text="@string/apply_theme_layout_title"/> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center"> + + <ImageView + android:id="@+id/apply_cancel" + android:layout_width="72dp" + android:layout_height="72dp" + android:layout_gravity="center_vertical" + android:clickable="true" + android:src="@drawable/ic_apply_cancel" + android:scaleType="center" + android:background="@drawable/apply_cancel_bg"/> + + <View + android:layout_width="2dp" + android:layout_height="56dp" + android:layout_gravity="center_vertical" + android:background="@color/apply_layout_separator_color" + android:layout_marginStart="31dp" + android:layout_marginEnd="31dp"/> + + <ImageView + android:id="@+id/apply_apply" + android:layout_width="72dp" + android:layout_height="72dp" + android:layout_gravity="center_vertical" + android:clickable="true" + android:src="@drawable/ic_apply_apply" + android:scaleType="center" + android:background="@drawable/apply_cancel_bg"/> + + </LinearLayout> + +</FrameLayout>
\ No newline at end of file diff --git a/res/layout/fragment_pager_list.xml b/res/layout/fragment_pager_list.xml index 818aaf9..aa1a1df 100644 --- a/res/layout/fragment_pager_list.xml +++ b/res/layout/fragment_pager_list.xml @@ -6,7 +6,7 @@ android:layout_height="match_parent" android:paddingStart="@dimen/collapsed_theme_page_padding" android:paddingEnd="@dimen/collapsed_theme_page_padding"> - <ScrollView android:id="@android:id/list" + <com.cyngn.theme.widget.LockableScrollView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="@dimen/collapsed_theme_page_padding_top" @@ -42,6 +42,7 @@ <include layout="@layout/icon_card"/> <include layout="@layout/navbar_card"/> </LinearLayout> + <include layout="@layout/apply_theme_layout"/> <ImageView android:id="@+id/loading_view" android:layout_width="match_parent" @@ -154,5 +155,5 @@ android:layout_height="@*android:dimen/system_bar_height" /> </LinearLayout> </LinearLayout> - </ScrollView> + </com.cyngn.theme.widget.LockableScrollView> </LinearLayout>
\ No newline at end of file diff --git a/res/values/colors.xml b/res/values/colors.xml index 038f0fb..7787938 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -50,4 +50,9 @@ <color name="shop_themes_text_color">#01579b</color> <color name="shop_themes_divider_color">#b8b8b8</color> + <color name="apply_layout_background">#cd000000</color> + <color name="apply_layout_text_color">#ffffff</color> + <color name="apply_layout_separator_color">#ffffff</color> + <color name="apply_layout_button_bg_color">#66ffffff</color> + </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index 590ba4f..bcbd084 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -56,4 +56,6 @@ <string name="audible_title_none">None</string> + <string name="apply_theme_layout_title">Apply</string> + </resources> diff --git a/src/android/support/v4/view/ThemeViewPager.java b/src/android/support/v4/view/ThemeViewPager.java index d4054b7..d3577e7 100644 --- a/src/android/support/v4/view/ThemeViewPager.java +++ b/src/android/support/v4/view/ThemeViewPager.java @@ -56,7 +56,8 @@ public class ThemeViewPager extends ViewPager { if (!mExpanded && isEnabled() && !mIsAnimating) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: - intercept = !isTouching(R.id.customize, ev) && !isTouching(R.id.overflow, ev); + intercept = !isTouching(R.id.customize, ev) && !isTouching(R.id.overflow, ev) + && !isTouching(R.id.apply_theme_layout, ev); break; } } diff --git a/src/com/cyngn/theme/chooser/ChooserActivity.java b/src/com/cyngn/theme/chooser/ChooserActivity.java index 6dac264..776b793 100644 --- a/src/com/cyngn/theme/chooser/ChooserActivity.java +++ b/src/com/cyngn/theme/chooser/ChooserActivity.java @@ -269,6 +269,14 @@ public class ChooserActivity extends FragmentActivity mPager.setEnabled(true); } + public void lockPager() { + mPager.setEnabled(false); + } + + public void unlockPager() { + mPager.setEnabled(true); + } + public ComponentSelector getComponentSelector() { return mSelector; } @@ -361,7 +369,12 @@ public class ChooserActivity extends FragmentActivity }); setAnimatingStateAndScheduleFinish(); } else { - super.onBackPressed(); + final ThemeFragment f = getCurrentFragment(); + if (f.isShowingApplyThemeLayout()) { + f.hideApplyThemeLayout(); + } else { + super.onBackPressed(); + } } } @@ -388,7 +401,12 @@ public class ChooserActivity extends FragmentActivity private View.OnClickListener mPagerClickListener = new View.OnClickListener() { @Override public void onClick(View v) { - expand(); + ThemeFragment f = getCurrentFragment(); + if (f instanceof MyThemeFragment) { + expand(); + } else { + f.showApplyThemeLayout(); + } } }; diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java index 5f865c8..b9bfed7 100644 --- a/src/com/cyngn/theme/chooser/ThemeFragment.java +++ b/src/com/cyngn/theme/chooser/ThemeFragment.java @@ -52,6 +52,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.ViewPropertyAnimator; import android.view.ViewTreeObserver; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; @@ -62,7 +63,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupMenu; import android.widget.ProgressBar; -import android.widget.ScrollView; import android.widget.Space; import android.widget.TextView; import android.widget.Toast; @@ -75,6 +75,7 @@ import com.cyngn.theme.util.ThemedTypefaceHelper; import com.cyngn.theme.util.TypefaceHelperCache; import com.cyngn.theme.util.Utils; import com.cyngn.theme.widget.BootAniImageView; +import com.cyngn.theme.widget.LockableScrollView; import java.io.File; import java.io.IOException; @@ -111,6 +112,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb public static final int ANIMATE_TITLE_OUT_DURATION = 400; public static final int ANIMATE_PROGRESS_OUT_DURATION = 400; public static final int ANIMATE_TITLE_IN_DURATION = 500; + public static final int ANIMATE_APPLY_LAYOUT_DURATION = 300; public static final int REQUEST_UNINSTALL = 1; // Request code public static final String CURRENTLY_APPLIED_THEME = "currently_applied_theme"; @@ -162,7 +164,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb protected Typeface mTypefaceNormal; protected int mBatteryStyle; - protected ScrollView mScrollView; + protected LockableScrollView mScrollView; protected ViewGroup mScrollContent; protected ViewGroup mPreviewContent; // Contains icons, font, nav/status etc. Not wallpaper protected View mLoadingView; @@ -227,6 +229,10 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb protected Cursor mCurrentCursor; protected int mCurrentLoaderId; + protected View mApplyThemeLayout; + protected View mApplyButton; + protected View mCancelButton; + static ThemeFragment newInstance(String pkgName) { ThemeFragment f = new ThemeFragment(); Bundle args = new Bundle(); @@ -275,7 +281,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_pager_list, container, false); - mScrollView = (ScrollView) v.findViewById(android.R.id.list); + mScrollView = (LockableScrollView) v.findViewById(android.R.id.list); mScrollContent = (ViewGroup) mScrollView.getChildAt(0); mPreviewContent = (ViewGroup) v.findViewById(R.id.preview_container); mLoadingView = v.findViewById(R.id.loading_view); @@ -354,7 +360,9 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb mCustomize = (ImageView) v.findViewById(R.id.customize); mCustomize.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - ((ChooserActivity) getActivity()).expand(); + if (!isShowingApplyThemeLayout()) { + ((ChooserActivity) getActivity()).expand(); + } } }); @@ -367,6 +375,12 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb int translationY = getDistanceToMoveBelowScreen(mAdditionalCards); mAdditionalCards.setTranslationY(translationY); + mApplyThemeLayout = v.findViewById(R.id.apply_theme_layout); + mApplyButton = mApplyThemeLayout.findViewById(R.id.apply_apply); + mApplyButton.setOnClickListener(mApplyCancelClickListener); + mCancelButton = mApplyThemeLayout.findViewById(R.id.apply_cancel); + mCancelButton.setOnClickListener(mApplyCancelClickListener); + getLoaderManager().initLoader(LOADER_ID_ALL, null, this); setupCardClickListeners(v); @@ -1509,6 +1523,7 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb private View.OnClickListener mCardClickListener = new View.OnClickListener() { @Override public void onClick(View v) { + if (isShowingApplyThemeLayout()) return; if (mActiveCardId > 0) { // need to fade the newly selected card in if another was currently selected. ((ComponentCardView) v).animateCardFadeIn(); @@ -1521,6 +1536,17 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb } }; + private View.OnClickListener mApplyCancelClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + if (v == mApplyButton) { + hideApplyThemeLayout(true); + } else if (v == mCancelButton) { + hideApplyThemeLayout(); + } + } + }; + private OnItemClickedListener mOnComponentItemClicked = new OnItemClickedListener() { @Override public void onItemClicked(String pkgName) { @@ -1683,6 +1709,55 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb set.start(); } + public boolean isShowingApplyThemeLayout() { + return mApplyThemeLayout.getVisibility() == View.VISIBLE; + } + + public void showApplyThemeLayout() { + if (mApplyThemeLayout.getVisibility() == View.VISIBLE) return; + ((ChooserActivity) getActivity()).lockPager(); + mScrollView.setScrollingEnabled(false); + ViewPropertyAnimator anim = mApplyThemeLayout.animate(); + mApplyThemeLayout.setVisibility(View.VISIBLE); + mApplyThemeLayout.setAlpha(0f); + anim.setListener(null); + anim.setDuration(ANIMATE_APPLY_LAYOUT_DURATION); + anim.alpha(1f).start(); + } + public void hideApplyThemeLayout() { + hideApplyThemeLayout(false); + } + + /** + * Hides the apply theme layout overlay and can apply the selected theme + * when the animation is finished. + * @param applyThemeWhenFinished If true, the current theme will be applied. + */ + private void hideApplyThemeLayout(final boolean applyThemeWhenFinished) { + ((ChooserActivity) getActivity()).unlockPager(); + mScrollView.setScrollingEnabled(true); + ViewPropertyAnimator anim = mApplyThemeLayout.animate(); + mApplyThemeLayout.setVisibility(View.VISIBLE); + anim.setDuration(ANIMATE_APPLY_LAYOUT_DURATION); + anim.alpha(0f).start(); + anim.setListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) {} + + @Override + public void onAnimationEnd(Animator animation) { + mApplyThemeLayout.setVisibility(View.GONE); + if (applyThemeWhenFinished) applyTheme(); + } + + @Override + public void onAnimationCancel(Animator animation) {} + + @Override + public void onAnimationRepeat(Animator animation) {} + }); + } + public void fadeInCards() { for (int i = 0; i < mCardIdsToComponentTypes.size(); i++) { final int key = mCardIdsToComponentTypes.keyAt(i); diff --git a/src/com/cyngn/theme/widget/LockableScrollView.java b/src/com/cyngn/theme/widget/LockableScrollView.java new file mode 100644 index 0000000..0986384 --- /dev/null +++ b/src/com/cyngn/theme/widget/LockableScrollView.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2014 The Cyanogen, Inc + */ +package com.cyngn.theme.widget; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.widget.ScrollView; + +public class LockableScrollView extends ScrollView { + private boolean mScrollingEnabled = true; + + public LockableScrollView(Context context) { + this(context, null); + } + + public LockableScrollView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public LockableScrollView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public void setScrollingEnabled(boolean enabled) { + mScrollingEnabled = enabled; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + return mScrollingEnabled && super.onInterceptTouchEvent(ev); + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + switch (ev.getAction()) { + case MotionEvent.ACTION_DOWN: + return mScrollingEnabled && super.onTouchEvent(ev); + default: + return super.onTouchEvent(ev); + } + } +} |