diff options
author | Roman Birg <roman@cyngn.com> | 2014-09-17 10:37:05 -0700 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-26 16:11:13 -0700 |
commit | 6455208e1334114881be837cfbc26d3ae06f9ce3 (patch) | |
tree | 219d326bff3a7a8d451f10f08fc31fe8b27fbe44 /src/com/android/settings/profiles/TriggerPagerAdapter.java | |
parent | 0f8cf2c7f9ebf6ce40f905a3090b47ad6a87d0bc (diff) | |
download | packages_apps_Settings-6455208e1334114881be837cfbc26d3ae06f9ce3.zip packages_apps_Settings-6455208e1334114881be837cfbc26d3ae06f9ce3.tar.gz packages_apps_Settings-6455208e1334114881be837cfbc26d3ae06f9ce3.tar.bz2 |
Settings: squash of new profile UI for cm-12.0
Additions for cm-12.0:
- removed expanded desktop
- added add profile FAB
- updated tabs for meterial style
- added enabler switch bar
Squashed commits:
-------------------------------
Settings: refactor Profiles to be more user friendly
* Remove the notion of Profile app groups
* Rearrange profile setup flow, now we first present the user with ways
which will trigger the profile, then allow them to set what happens when
the profile is triggered.
Change-Id: I2870df894046cd43c21c67991fb5efc9c3fec837
Signed-off-by: Roman Birg <roman@cyngn.com>
Settings: cleanup new profiles UI
* cleanup old code
* for configuring profiles, add options to modify triggers and remove
the profile
* remove separate activity
* don't hardcode padding pixel sizes
Change-Id: I6b1d05c9f918714249411006c7562496e2a7539e
Signed-off-by: Roman Birg <roman@cyngn.com>
Profiles: fix expanded desktop settings not applying
Change-Id: Ia523145bf47bfc189c29b035ad5ec6e053cf9296
Settings: Fix profiles volume override summary.
Change-Id: I499cfb3006a7fc7b5e931ac854a7437f5d141523
Settings: fix Profiles expanded desktop choice mapping
Change-Id: Ib96811a0c268ca68a7b9732283c5abc142d143a4
Signed-off-by: Roman Birg <roman@cyngn.com>
Settings: add "Untouched" ring mode option in profiles
Change-Id: I4ac2d63119b328533217104a799cb0660ecddfb9
Signed-off-by: Roman Birg <roman@cyngn.com>
Settings: profiles: fix volume streams override behavior
Before we would always assume to override the stream, but that is not
always the case. Add a checkbox to turn the override on and off.
Signed-off-by: Roman Birg <roman@cyngn.com>
Change-Id: Ic1a58d59a9e514d4c2ccf376191ac7989bbead26
Diffstat (limited to 'src/com/android/settings/profiles/TriggerPagerAdapter.java')
-rw-r--r-- | src/com/android/settings/profiles/TriggerPagerAdapter.java | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/src/com/android/settings/profiles/TriggerPagerAdapter.java b/src/com/android/settings/profiles/TriggerPagerAdapter.java new file mode 100644 index 0000000..cfd7fff --- /dev/null +++ b/src/com/android/settings/profiles/TriggerPagerAdapter.java @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2014 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.profiles; + + +import android.app.Activity; +import android.app.Fragment; +import android.app.FragmentManager; +import android.os.Bundle; +import android.support.v13.app.FragmentPagerAdapter; +import android.util.SparseArray; +import android.view.ViewGroup; + +import com.android.settings.R; +import com.android.settings.profiles.triggers.BluetoothTriggerFragment; +import com.android.settings.profiles.triggers.NfcTriggerFragment; +import com.android.settings.profiles.triggers.WifiTriggerFragment; +import com.google.android.collect.Lists; + +import java.lang.ref.WeakReference; +import java.util.List; + +/** + * A {@link android.support.v4.app.FragmentPagerAdapter} class for swiping between playlists, recent, + * artists, albums, songs, and genre {@link android.support.v4.app.Fragment}s on phones.<br/> + */ +public class TriggerPagerAdapter extends FragmentPagerAdapter { + + private final SparseArray<WeakReference<Fragment>> mFragmentArray = + new SparseArray<WeakReference<Fragment>>(); + + private final List<Holder> mHolderList = Lists.newArrayList(); + + private final Activity mFragmentActivity; + + private int mCurrentPage; + + /** + * Constructor of <code>PagerAdatper<code> + * + * @param activity The {@link android.support.v4.app.FragmentActivity} of the + * {@link android.support.v4.app.Fragment}. + * @param fm the FragmentManager to use. + */ + public TriggerPagerAdapter(Activity activity, FragmentManager fm) { + super(fm); + mFragmentActivity = activity; + } + + /** + * Method that adds a new fragment class to the viewer (the fragment is + * internally instantiate) + * + * @param className The full qualified name of fragment class. + * @param params The instantiate params. + */ + @SuppressWarnings("synthetic-access") + public void add(final Class<? extends Fragment> className, final Bundle params, + final int titleResId) { + final Holder mHolder = new Holder(); + mHolder.mClassName = className.getName(); + mHolder.mParams = params; + mHolder.mTitleResId = titleResId; + + final int mPosition = mHolderList.size(); + mHolderList.add(mPosition, mHolder); + notifyDataSetChanged(); + } + + /** + * Method that returns the {@link android.support.v4.app.Fragment} in the argument + * position. + * + * @param position The position of the fragment to return. + * @return Fragment The {@link android.support.v4.app.Fragment} in the argument position. + */ + public Fragment getFragment(final int position) { + final WeakReference<Fragment> mWeakFragment = mFragmentArray.get(position); + if (mWeakFragment != null && mWeakFragment.get() != null) { + return mWeakFragment.get(); + } + return getItem(position); + } + + /** + * {@inheritDoc} + */ + @Override + public Object instantiateItem(final ViewGroup container, final int position) { + final Fragment mFragment = (Fragment)super.instantiateItem(container, position); + final WeakReference<Fragment> mWeakFragment = mFragmentArray.get(position); + if (mWeakFragment != null) { + mWeakFragment.clear(); + } + mFragmentArray.put(position, new WeakReference<Fragment>(mFragment)); + return mFragment; + } + + /** + * {@inheritDoc} + */ + @Override + public Fragment getItem(final int position) { + final Holder mCurrentHolder = mHolderList.get(position); + final Fragment mFragment = Fragment.instantiate(mFragmentActivity, + mCurrentHolder.mClassName, mCurrentHolder.mParams); + return mFragment; + } + + /** + * {@inheritDoc} + */ + @Override + public void destroyItem(final ViewGroup container, final int position, final Object object) { + super.destroyItem(container, position, object); + final WeakReference<Fragment> mWeakFragment = mFragmentArray.get(position); + if (mWeakFragment != null) { + mWeakFragment.clear(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public int getCount() { + return mHolderList.size(); + } + + /** + * {@inheritDoc} + */ + @Override + public CharSequence getPageTitle(final int position) { + return mFragmentActivity.getString(mHolderList.get(position).mTitleResId); + } + + /** + * Method that returns the current page position. + * + * @return int The current page. + */ + public int getCurrentPage() { + return mCurrentPage; + } + + /** + * Method that sets the current page position. + * + * @param currentPage The current page. + */ + protected void setCurrentPage(final int currentPage) { + mCurrentPage = currentPage; + } + + /** + * An enumeration of all the main fragments supported. + */ + public enum TriggerFragments { + /** + * The artist fragment + */ + WIFI(WifiTriggerFragment.class, R.string.profile_tabs_wifi), + /** + * The album fragment + */ + BLUETOOTH(BluetoothTriggerFragment.class, R.string.profile_tabs_bluetooth), + /** + * The song fragment + */ + NFC(NfcTriggerFragment.class, R.string.profile_tabs_nfc); + + private Class<? extends Fragment> mFragmentClass; + private int mNameRes; + + /** + * Constructor of <code>MusicFragments</code> + * + * @param fragmentClass The fragment class + */ + private TriggerFragments(final Class<? extends Fragment> fragmentClass, int nameRes) { + mFragmentClass = fragmentClass; + mNameRes = nameRes; + } + + /** + * Method that returns the fragment class. + * + * @return Class<? extends Fragment> The fragment class. + */ + public Class<? extends Fragment> getFragmentClass() { + return mFragmentClass; + } + + public int getTitleRes() { return mNameRes; } + } + + /** + * A private class with information about fragment initialization + */ + private final static class Holder { + String mClassName; + int mTitleResId; + Bundle mParams; + } +} |