diff options
author | Roman Birg <roman@cyngn.com> | 2015-01-06 17:20:27 -0800 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-26 16:11:13 -0700 |
commit | 1f8655e86a1d3b4325f857ec00e1d881ccced824 (patch) | |
tree | 2d61e6b94c30689e990d6c1077546d5900917f34 /src/com/android/settings/profiles | |
parent | 156df7e1a962e339ca7e69a467824b7e151379ee (diff) | |
download | packages_apps_Settings-1f8655e86a1d3b4325f857ec00e1d881ccced824.zip packages_apps_Settings-1f8655e86a1d3b4325f857ec00e1d881ccced824.tar.gz packages_apps_Settings-1f8655e86a1d3b4325f857ec00e1d881ccced824.tar.bz2 |
Settings: display Triggers inline with Profile actions
* Tapping them will open the proper trigger page
* Removed triggers icon
Change-Id: I9ea9c22eea7f3370f4c96519b83f6f83cdebaf88
Signed-off-by: Roman Birg <roman@cyngn.com>
Diffstat (limited to 'src/com/android/settings/profiles')
4 files changed, 153 insertions, 21 deletions
diff --git a/src/com/android/settings/profiles/SetupActionsFragment.java b/src/com/android/settings/profiles/SetupActionsFragment.java index 230d84a..ee04032 100644 --- a/src/com/android/settings/profiles/SetupActionsFragment.java +++ b/src/com/android/settings/profiles/SetupActionsFragment.java @@ -59,6 +59,7 @@ import com.android.settings.profiles.actions.item.Item; import com.android.settings.profiles.actions.item.LockModeItem; import com.android.settings.profiles.actions.item.ProfileNameItem; import com.android.settings.profiles.actions.item.RingModeItem; +import com.android.settings.profiles.actions.item.TriggerItem; import com.android.settings.profiles.actions.item.VolumeStreamItem; import java.util.ArrayList; @@ -126,6 +127,12 @@ public class SetupActionsFragment extends SettingsPreferenceFragment items.add(new Header(getString(R.string.profile_name_title))); items.add(new ProfileNameItem(mProfile)); + // triggers + items.add(new Header(getString(R.string.profile_triggers_header))); + items.add(generateTriggerItem(TriggerItem.WIFI)); + items.add(generateTriggerItem(TriggerItem.BLUETOOTH)); + items.add(generateTriggerItem(TriggerItem.NFC)); + // connection overrides items.add(new Header(getString(R.string.profile_connectionoverrides_title))); if (DeviceUtils.deviceSupportsBluetooth()) { @@ -170,6 +177,10 @@ public class SetupActionsFragment extends SettingsPreferenceFragment setHasOptionsMenu(true); } + private TriggerItem generateTriggerItem(int whichTrigger) { + return new TriggerItem(mProfile, whichTrigger); + } + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); @@ -180,13 +191,6 @@ public class SetupActionsFragment extends SettingsPreferenceFragment .setEnabled(true) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); - - menu.add(0, MENU_TRIGGERS, 0, R.string.profile_menu_triggers_title) - .setIcon(R.drawable.ic_location) - .setAlphabeticShortcut('t') - .setEnabled(true) - .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | - MenuItem.SHOW_AS_ACTION_WITH_TEXT); } } @@ -197,17 +201,6 @@ public class SetupActionsFragment extends SettingsPreferenceFragment mProfileManager.removeProfile(mProfile); finishFragment(); return true; - - case MENU_TRIGGERS: - Bundle args = new Bundle(); - args.putParcelable(ProfilesSettings.EXTRA_PROFILE, mProfile); - args.putBoolean(ProfilesSettings.EXTRA_NEW_PROFILE, false); - - SubSettings pa = (SubSettings) getActivity(); - pa.startPreferencePanel(SetupTriggersFragment.class.getCanonicalName(), args, - R.string.profile_profile_manage, null, null, 0); - - return true; } return super.onOptionsItemSelected(item); } @@ -560,6 +553,20 @@ public class SetupActionsFragment extends SettingsPreferenceFragment requestVolumeDialog(item.getStreamType(), item.getSettings()); } else if (itemAtPosition instanceof ProfileNameItem) { requestProfileName(); + } else if (itemAtPosition instanceof TriggerItem) { + TriggerItem item = (TriggerItem) itemAtPosition; + openTriggersFragment(item.getTriggerType()); } } + + private void openTriggersFragment(int openTo) { + Bundle args = new Bundle(); + args.putParcelable(ProfilesSettings.EXTRA_PROFILE, mProfile); + args.putBoolean(ProfilesSettings.EXTRA_NEW_PROFILE, false); + args.putInt(SetupTriggersFragment.EXTRA_INITIAL_PAGE, openTo); + + SubSettings pa = (SubSettings) getActivity(); + pa.startPreferencePanel(SetupTriggersFragment.class.getCanonicalName(), args, + R.string.profile_profile_manage, null, null, 0); + } } diff --git a/src/com/android/settings/profiles/SetupTriggersFragment.java b/src/com/android/settings/profiles/SetupTriggersFragment.java index dc88685..bd1f8ee 100644 --- a/src/com/android/settings/profiles/SetupTriggersFragment.java +++ b/src/com/android/settings/profiles/SetupTriggersFragment.java @@ -15,6 +15,7 @@ */ package com.android.settings.profiles; +import android.annotation.Nullable; import android.app.ActionBar; import android.app.Activity; import android.app.Profile; @@ -41,6 +42,9 @@ public class SetupTriggersFragment extends SettingsPreferenceFragment { ProfileManager mProfileManager; TriggerPagerAdapter mAdapter; boolean mNewProfileMode; + int mPreselectedItem; + + public static final String EXTRA_INITIAL_PAGE = "current_item"; private static final int REQUEST_SETUP_ACTIONS = 5; @@ -64,11 +68,17 @@ public class SetupTriggersFragment extends SettingsPreferenceFragment { if (getArguments() != null) { mProfile = getArguments().getParcelable(ProfilesSettings.EXTRA_PROFILE); mNewProfileMode = getArguments().getBoolean(ProfilesSettings.EXTRA_NEW_PROFILE, false); + mPreselectedItem = getArguments().getInt(EXTRA_INITIAL_PAGE, 0); } mProfileManager = (ProfileManager) getActivity().getSystemService(Context.PROFILE_SERVICE); } @Override + public void onResume() { + super.onResume(); + } + + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final ActionBar actionBar = getActivity().getActionBar(); @@ -82,12 +92,18 @@ public class SetupTriggersFragment extends SettingsPreferenceFragment { } @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + mPager.setCurrentItem(mPreselectedItem); + } + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View root = inflater.inflate(R.layout.fragment_setup_triggers, container, false); - ViewPager pager = (ViewPager) root.findViewById(R.id.view_pager); + mPager = (ViewPager) root.findViewById(R.id.view_pager); mAdapter = new TriggerPagerAdapter(getActivity(), getChildFragmentManager()); Bundle profileArgs = new Bundle(); @@ -107,7 +123,7 @@ public class SetupTriggersFragment extends SettingsPreferenceFragment { mAdapter.add(fragment.getFragmentClass(), profileArgs, fragment.getTitleRes()); } - pager.setAdapter(mAdapter); + mPager.setAdapter(mAdapter); PagerTabStrip tabs = (PagerTabStrip) root.findViewById(R.id.tabs); tabs.setTabIndicatorColorResource(R.color.theme_accent); diff --git a/src/com/android/settings/profiles/actions/ItemListAdapter.java b/src/com/android/settings/profiles/actions/ItemListAdapter.java index d09e0ee..793f28b 100644 --- a/src/com/android/settings/profiles/actions/ItemListAdapter.java +++ b/src/com/android/settings/profiles/actions/ItemListAdapter.java @@ -34,7 +34,8 @@ public class ItemListAdapter extends ArrayAdapter<Item> { NAME_ITEM, RINGMODE_ITEM, AIRPLANEMODE_ITEM, - LOCKSCREENMODE_ITEM + LOCKSCREENMODE_ITEM, + TRIGGER_ITEM } public ItemListAdapter(Context context, List<Item> items) { diff --git a/src/com/android/settings/profiles/actions/item/TriggerItem.java b/src/com/android/settings/profiles/actions/item/TriggerItem.java new file mode 100644 index 0000000..4ce6cbd --- /dev/null +++ b/src/com/android/settings/profiles/actions/item/TriggerItem.java @@ -0,0 +1,108 @@ +/* + * 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.actions.item; + +import android.app.Profile; +import android.util.StringBuilderPrinter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import com.android.settings.R; +import com.android.settings.profiles.actions.ItemListAdapter; + +import java.util.ArrayList; + +public class TriggerItem implements Item { + + // from Profile.TriggerType + public static final int WIFI = 0; + public static final int BLUETOOTH = 1; + // not in Profile.TriggerType, but we need it. + public static final int NFC = 2; + + Profile mProfile; + int mTriggerType; + + public TriggerItem(Profile profile, int whichTrigger) { + mProfile = profile; + mTriggerType = whichTrigger; + } + + @Override + public ItemListAdapter.RowType getRowType() { + return ItemListAdapter.RowType.TRIGGER_ITEM; + } + + @Override + public boolean isEnabled() { + return true; + } + + public int getTriggerType() { + return mTriggerType; + } + + @Override + public View getView(LayoutInflater inflater, View convertView, ViewGroup parent) { + View view; + if (convertView == null) { + view = inflater.inflate(R.layout.list_two_line_item, parent, false); + // Do some initialization + } else { + view = convertView; + } + + TextView text = (TextView) view.findViewById(R.id.title); + text.setText(getTitleString(mTriggerType)); + + + StringBuilder sb = new StringBuilder(); + ArrayList<Profile.ProfileTrigger> triggers = mProfile.getTriggersFromType(mTriggerType); + + for (int i = 0; i < triggers.size(); i++) { + sb.append(triggers.get(i).getName()); + if (i < (triggers.size() - 1)) { + sb.append("\n"); + } + } + + TextView desc = (TextView) view.findViewById(R.id.summary); + if (sb.length() == 0) { + if (mTriggerType == NFC) { + desc.setText(R.string.no_triggers_configured_nfc); + } else { + desc.setText(R.string.no_triggers_configured); + } + } else { + desc.setText(sb.toString()); + } + + return view; + } + + public static int getTitleString(int triggerType) { + switch (triggerType) { + case WIFI: + return R.string.profile_tabs_wifi; + case BLUETOOTH: + return R.string.profile_tabs_bluetooth; + case NFC: + return R.string.profile_tabs_nfc; + default: return 0; + } + } +} |