Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea4b706b authored by Roman Birg's avatar Roman Birg Committed by Gerrit - the friendly Code Review server
Browse files

Settings: display Triggers inline with Profile actions



* Tapping them will open the proper trigger page
* Removed triggers icon

Change-Id: I9ea9c22eea7f3370f4c96519b83f6f83cdebaf88
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent d2c07bb9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -243,6 +243,8 @@
    <string name="profile_tabs_bluetooth">Bluetooth</string>
    <string name="profile_tabs_nfc">NFC</string>

    <string name="profile_triggers_header">Triggers which will activate this profile</string>

    <string name="profile_setup_setup_triggers_title">Step 1: Add triggers</string>
    <string name="profile_setup_setup_triggers_title_config">Modify triggers: <xliff:g id="profile_name">%1$s</xliff:g></string>

@@ -251,6 +253,8 @@

    <string name="no_bluetooth_triggers">No Bluetooth devices paired.\nTap to pair Bluetooth device before configuring triggers.</string>
    <string name="no_wifi_triggers">No Wi-Fi access points configured.\nTap to connect Wi-Fi before configuring triggers.</string>
    <string name="no_triggers_configured">No triggers configured. Tap to add more.</string>
    <string name="no_triggers_configured_nfc">Tap to setup a new NFC trigger.</string>

    <string name="profile_setup_setup_triggers_description">Please select triggers which will activate this profile</string>
    <string name="profile_setup_actions_description">Now configure what happens when the profile is activated</string>
+25 −18
Original line number Diff line number Diff line
@@ -63,6 +63,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;
@@ -130,6 +131,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()) {
@@ -174,6 +181,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);
@@ -184,13 +195,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);
        }
    }

@@ -200,17 +204,6 @@ public class SetupActionsFragment extends SettingsPreferenceFragment
            case MENU_REMOVE:
                requestRemoveProfileDialog();
                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);
    }
@@ -600,6 +593,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);
    }
}
+18 −2
Original line number Diff line number Diff line
@@ -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,10 +68,16 @@ 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);
@@ -81,13 +91,19 @@ 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);
+2 −1
Original line number Diff line number Diff line
@@ -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) {
+108 −0
Original line number Diff line number Diff line
/*
 * 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;
        }
    }
}