From aef6ac288919ecf2718380ff6aaf4c7db5e0733d Mon Sep 17 00:00:00 2001 From: alinasuarez Date: Fri, 30 Jul 2021 20:25:19 +0000 Subject: [PATCH] Alarm Manager policy TARE page implementation An alarm manager policy page is needed in the TARE developer option settings to allow developers to both view and edit the current values of all the factors under the alarm manager policy. The page uses a dropdown so that the user can easily switch between the different policies. For the factors with subfactors, the user simply clicks on the factor and the subfactors will pop up under it. Bug: 191876714 Bug: 191876567 Test: Manual (open Settings > System > Developer Options > TARE > Alarm Manger and verify all factors are there) Change-Id: Ie036e26df80947d23041bedfd5b1385e48069b6b --- AndroidManifest.xml | 3 + res/layout/tare_child_item.xml | 23 +++ res/layout/tare_dropdown_page.xml | 27 +++ res/layout/tare_homepage.xml | 12 +- res/layout/tare_policy_fragment.xml | 11 ++ res/values/strings.xml | 124 +++++++++++++- .../tare/AlarmManagerFragment.java | 162 ++++++++++++++++++ .../development/tare/DropdownActivity.java | 73 ++++++++ .../development/tare/TareHomePage.java | 12 +- 9 files changed, 435 insertions(+), 12 deletions(-) create mode 100644 res/layout/tare_child_item.xml create mode 100644 res/layout/tare_dropdown_page.xml create mode 100644 res/layout/tare_policy_fragment.xml create mode 100644 src/com/android/settings/development/tare/AlarmManagerFragment.java create mode 100644 src/com/android/settings/development/tare/DropdownActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 07abb75eaf3..788dba881fa 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1485,6 +1485,9 @@ android:label="@string/tare_settings" android:exported="false" /> + + diff --git a/res/layout/tare_child_item.xml b/res/layout/tare_child_item.xml new file mode 100644 index 00000000000..0f146078988 --- /dev/null +++ b/res/layout/tare_child_item.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/res/layout/tare_dropdown_page.xml b/res/layout/tare_dropdown_page.xml new file mode 100644 index 00000000000..79931e88938 --- /dev/null +++ b/res/layout/tare_dropdown_page.xml @@ -0,0 +1,27 @@ + + + + + \ No newline at end of file diff --git a/res/layout/tare_homepage.xml b/res/layout/tare_homepage.xml index df12b7c8661..23c9c6b8ace 100644 --- a/res/layout/tare_homepage.xml +++ b/res/layout/tare_homepage.xml @@ -18,7 +18,6 @@ + android:background="?android:attr/colorBackground" /> + android:textColor="?android:attr/textColorSecondary" /> + android:textColor="?android:attr/textColorSecondary" /> - + android:text="@string/tare_revert" /> + diff --git a/res/layout/tare_policy_fragment.xml b/res/layout/tare_policy_fragment.xml new file mode 100644 index 00000000000..e3eadd4ef8e --- /dev/null +++ b/res/layout/tare_policy_fragment.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 759fe95c6c3..1a30159f45e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -13618,7 +13618,7 @@ translated. "TARE" is not translatable. [CHAR LIMIT=NONE] --> TARE + translated. [CHAR LIMIT=40] --> TARE Settings Revert to Default Settings @@ -13629,7 +13629,125 @@ JobScheduler - + Settings reverted to default. + + Maximum Satiated Balance + + Maximum Circulation + + Minimum Satiated Balance + + Modifiers + + Actions + + Rewards + + + Allow While Idle Exact Wakeup Alarm + + + Allow While Idle Inexact Wakeup Alarm + + Exact Wakeup Alarm + + Inexact Wakeup Alarm + + + Allow While Idle Exact NonWakeup Alarm + + Exact NonWakeup Alarm + + + Allow While Idle Inexact NonWakeup Alarm + + Inexact NonWakeup Alarm + + AlarmClock + + Exempted + + Headless System App + + Other App + + Top Activity + + Notification Seen + + Notification Seen Within 15 Minutes + + Notification Interaction + + Widget Interaction + + Other User Interaction + + + @string/tare_exempted + @string/tare_headless_app + @string/tare_other_app + + + + Charging + + Doze + Power Save Mode + + Process State + + + + @string/tare_wakeup_exact_idle + @string/tare_wakeup_inexact_idle + @string/tare_wakeup_exact + @string/tare_wakeup_inexact + @string/tare_nonwakeup_exact_idle + @string/tare_nonwakeup_exact + @string/tare_nonwakeup_inexact_idle + @string/tare_nonwakeup_inexact + @string/tare_alarm_clock + + + + @string/tare_top_activity + @string/tare_notification_seen + @string/tare_notification_seen_15_min + @string/tare_notification_interaction + @string/tare_widget_interaction + @string/tare_other_interaction + + + + @string/tare_alarmmanager + diff --git a/src/com/android/settings/development/tare/AlarmManagerFragment.java b/src/com/android/settings/development/tare/AlarmManagerFragment.java new file mode 100644 index 00000000000..edc7576e05d --- /dev/null +++ b/src/com/android/settings/development/tare/AlarmManagerFragment.java @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2021 The Android Open Source 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.development.tare; + +import android.app.Fragment; +import android.content.res.Resources; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseExpandableListAdapter; +import android.widget.ExpandableListView; +import android.widget.ExpandableListView.OnChildClickListener; +import android.widget.TextView; +import android.widget.Toast; + +import com.android.settings.R; + +/** + * Creates the AlarmManager fragment to display all the AlarmManager factors + * when the AlarmManager policy is chosen in the dropdown TARE menu. + */ +public class AlarmManagerFragment extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.tare_policy_fragment, null); + ExpandableListView elv = (ExpandableListView) v.findViewById(R.id.factor_list); + final SavedTabsListAdapter expListAdapter = new SavedTabsListAdapter(); + elv.setGroupIndicator(null); + elv.setAdapter(expListAdapter); + elv.setOnChildClickListener(new OnChildClickListener() { + public boolean onChildClick(ExpandableListView parent, View v, + int groupPosition, int childPosition, long id) { + final String selected = + (String) expListAdapter.getChild(groupPosition, childPosition); + Toast.makeText(getActivity(), selected, Toast.LENGTH_SHORT).show(); + return true; + } + }); + return v; + } + + /** + * Creates the expandable list containing all AlarmManager factors within the + * AlarmManager fragment. + */ + public class SavedTabsListAdapter extends BaseExpandableListAdapter { + + private final LayoutInflater mInflater; + private Resources mResources = getActivity().getResources(); + + private String[] mGroups = { + mResources.getString(R.string.tare_max_circulation), + mResources.getString(R.string.tare_max_satiated_balance), + mResources.getString(R.string.tare_min_satiated_balance), + mResources.getString(R.string.tare_modifiers), + mResources.getString(R.string.tare_actions), + mResources.getString(R.string.tare_rewards) + }; + + /* + * First two are empty arrays because the first two factors have no subfactors (no + * children). + */ + private String[][] mChildren = { + {}, + {}, + mResources.getStringArray(R.array.tare_min_satiated_balance_subfactors), + mResources.getStringArray(R.array.tare_modifiers_subfactors), + mResources.getStringArray(R.array.tare_actions_subfactors), + mResources.getStringArray(R.array.tare_rewards_subfactors) + }; + + public SavedTabsListAdapter() { + mInflater = LayoutInflater.from(getActivity()); + } + + @Override + public int getGroupCount() { + return mGroups.length; + } + + @Override + public int getChildrenCount(int groupPosition) { + return mChildren[groupPosition].length; + } + + @Override + public Object getGroup(int groupPosition) { + return mGroups[groupPosition]; + } + + @Override + public Object getChild(int groupPosition, int childPosition) { + return mChildren[groupPosition][childPosition]; + } + + @Override + public long getGroupId(int groupPosition) { + return groupPosition; + } + + @Override + public long getChildId(int groupPosition, int childPosition) { + return childPosition; + } + + @Override + public boolean hasStableIds() { + return true; + } + + @Override + public View getGroupView(int groupPosition, boolean isExpanded, View convertView, + ViewGroup parent) { + if (convertView == null) { + convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false); + } + TextView factor = (TextView) convertView.findViewById(android.R.id.text1); + factor.setText(getGroup(groupPosition).toString()); + return convertView; + } + + @Override + public View getChildView(int groupPosition, int childPosition, boolean isLastChild, + View convertView, ViewGroup parent) { + // Here a custom child item is used instead of android.R.simple_list_item_2 because it + // is more customizable for this specific UI + if (convertView == null) { + convertView = mInflater.inflate(R.layout.tare_child_item, null); + } + TextView factor = (TextView) convertView.findViewById(R.id.factor); + TextView value = (TextView) convertView.findViewById(R.id.factor_number); + + // TODO: Replace these hardcoded values with either default or user inputted TARE values + factor.setText(getChild(groupPosition, childPosition).toString()); + value.setText("500"); + + return convertView; + } + + @Override + public boolean isChildSelectable(int groupPosition, int childPosition) { + return true; + } + } +} diff --git a/src/com/android/settings/development/tare/DropdownActivity.java b/src/com/android/settings/development/tare/DropdownActivity.java new file mode 100644 index 00000000000..ffddf041daf --- /dev/null +++ b/src/com/android/settings/development/tare/DropdownActivity.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2021 The Android Open Source 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.development.tare; + +import android.app.Activity; +import android.app.Fragment; +import android.app.FragmentTransaction; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; + +import com.android.settings.R; + +/** + * Dropdown activity to allow for the user to easily switch between the different TARE + * policies in the developer options of settings. Depending on what is chosen, the fragment + * containing that specific policies' factors will be generated. + */ +public class DropdownActivity extends Activity { + + private Fragment mAlarmManagerFragment; + private Spinner mSpinner; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.tare_dropdown_page); + + mSpinner = findViewById(R.id.spinner); + mAlarmManagerFragment = new AlarmManagerFragment(); + + String[] policies = getResources().getStringArray(R.array.tare_policies); + + ArrayAdapter arrayAdapter = new ArrayAdapter<>(DropdownActivity.this, + android.R.layout.simple_list_item_1, policies); + arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mSpinner.setAdapter(arrayAdapter); + + mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, + long id) { + openFragment(mAlarmManagerFragment); + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + } + + /** Selects the correct policy fragment to display */ + private void openFragment(Fragment fragment) { + FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); + fragmentTransaction.replace(R.id.frame_layout, fragment); + fragmentTransaction.commit(); + } +} diff --git a/src/com/android/settings/development/tare/TareHomePage.java b/src/com/android/settings/development/tare/TareHomePage.java index 747b2466a29..7a9cb49d7db 100644 --- a/src/com/android/settings/development/tare/TareHomePage.java +++ b/src/com/android/settings/development/tare/TareHomePage.java @@ -17,6 +17,7 @@ package com.android.settings.development.tare; import android.app.Activity; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; @@ -28,7 +29,7 @@ import android.widget.Toast; import com.android.settings.R; -/** Class for creating the TARE homepage in settings*/ +/** Class for creating the TARE homepage in settings */ public class TareHomePage extends Activity { private Switch mOnSwitch; private Button mRevButton; @@ -57,9 +58,14 @@ public class TareHomePage extends Activity { }); } - /** This method should revert the TARE settings to the original default settings */ - // TODO: Establish default TARE values and make this method revert all settings back to default + /** Reverts the TARE settings to the original default settings */ + // TODO: Establish default TARE values and make this method revert all settings back to default. public void revertSettings(View v) { Toast.makeText(this, R.string.tare_settings_reverted_toast, Toast.LENGTH_LONG).show(); } + + /** Opens up the AlarmManager TARE policy page with its factors to view and edit */ + public void launchAlarmManagerPage(View v) { + startActivity(new Intent(getApplicationContext(), DropdownActivity.class)); + } }