diff --git a/res/layout/tare_homepage.xml b/res/layout/tare_homepage.xml index 23c9c6b8ace..2c184d23b65 100644 --- a/res/layout/tare_homepage.xml +++ b/res/layout/tare_homepage.xml @@ -46,7 +46,8 @@ android:padding="20dp" android:clickable="true" android:text="@string/tare_jobscheduler" - android:textColor="?android:attr/textColorSecondary" /> + android:textColor="?android:attr/textColorSecondary" + android:onClick="launchJobSchedulerPage" /> Other User Interaction + + Job Max Start + + Job Max Running + + Job High Start + + Job High Running + + Job Default Start + + Job Default Running + + Job Low Start + + Job Low Running + + Job Min Start + + Job Min Running + + Job Timeout Penalty @@ -13724,7 +13757,7 @@ - + @string/tare_wakeup_exact_idle @string/tare_wakeup_inexact_idle @string/tare_wakeup_exact @@ -13745,9 +13778,25 @@ @string/tare_widget_interaction @string/tare_other_interaction + + + @string/tare_job_max_start + @string/tare_job_max_running + @string/tare_job_high_start + @string/tare_job_high_running + @string/tare_job_default_start + @string/tare_job_default_running + @string/tare_job_low_start + @string/tare_job_low_running + @string/tare_job_min_start + @string/tare_job_min_running + @string/tare_job_timeout_penalty + @string/tare_alarmmanager + @string/tare_jobscheduler diff --git a/src/com/android/settings/development/tare/AlarmManagerFragment.java b/src/com/android/settings/development/tare/AlarmManagerFragment.java index edc7576e05d..dbc4e588c8d 100644 --- a/src/com/android/settings/development/tare/AlarmManagerFragment.java +++ b/src/com/android/settings/development/tare/AlarmManagerFragment.java @@ -82,7 +82,7 @@ public class AlarmManagerFragment extends Fragment { {}, 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_alarm_manager_actions), mResources.getStringArray(R.array.tare_rewards_subfactors) }; diff --git a/src/com/android/settings/development/tare/DropdownActivity.java b/src/com/android/settings/development/tare/DropdownActivity.java index ffddf041daf..c1a11fa7e3e 100644 --- a/src/com/android/settings/development/tare/DropdownActivity.java +++ b/src/com/android/settings/development/tare/DropdownActivity.java @@ -18,6 +18,7 @@ package com.android.settings.development.tare; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; @@ -34,15 +35,26 @@ import com.android.settings.R; public class DropdownActivity extends Activity { private Fragment mAlarmManagerFragment; + private Fragment mJobSchedulerFragment; private Spinner mSpinner; + static final String EXTRA_POLICY = "policy"; + static final int POLICY_ALARM_MANAGER = 0; + static final int POLICY_JOB_SCHEDULER = 1; + private static final int DEFAULT_POLICY = POLICY_ALARM_MANAGER; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tare_dropdown_page); + // Determines what policy fragment to open up to + Intent intent = getIntent(); + int policy = intent.getIntExtra(EXTRA_POLICY, DEFAULT_POLICY); + mSpinner = findViewById(R.id.spinner); mAlarmManagerFragment = new AlarmManagerFragment(); + mJobSchedulerFragment = new JobSchedulerFragment(); String[] policies = getResources().getStringArray(R.array.tare_policies); @@ -51,11 +63,14 @@ public class DropdownActivity extends Activity { arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinner.setAdapter(arrayAdapter); + mSpinner.setSelection(policy); + selectFragment(policy); + mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int position, long id) { - openFragment(mAlarmManagerFragment); + selectFragment(position); } @Override @@ -64,7 +79,21 @@ public class DropdownActivity extends Activity { }); } - /** Selects the correct policy fragment to display */ + /** Selects the correct policy fragment to display based on user selection */ + private void selectFragment(int policy) { + switch (policy) { + case POLICY_ALARM_MANAGER: + openFragment(mAlarmManagerFragment); + break; + case POLICY_JOB_SCHEDULER: + openFragment(mJobSchedulerFragment); + break; + default: + openFragment(mAlarmManagerFragment); + } + } + + /** Opens the correct policy fragment */ private void openFragment(Fragment fragment) { FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.frame_layout, fragment); diff --git a/src/com/android/settings/development/tare/JobSchedulerFragment.java b/src/com/android/settings/development/tare/JobSchedulerFragment.java new file mode 100644 index 00000000000..5a7f4a9e5fc --- /dev/null +++ b/src/com/android/settings/development/tare/JobSchedulerFragment.java @@ -0,0 +1,163 @@ +/* + * 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 JobScheduler fragment to display all the JobScheduler factors + * when the JobScheduler policy is chosen in the dropdown TARE menu. + */ +public class JobSchedulerFragment 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 JobScheduler factors within the + * JobScheduler 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_job_scheduler_actions), + 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/TareHomePage.java b/src/com/android/settings/development/tare/TareHomePage.java index 7a9cb49d7db..12e8427f120 100644 --- a/src/com/android/settings/development/tare/TareHomePage.java +++ b/src/com/android/settings/development/tare/TareHomePage.java @@ -16,6 +16,10 @@ package com.android.settings.development.tare; +import static com.android.settings.development.tare.DropdownActivity.EXTRA_POLICY; +import static com.android.settings.development.tare.DropdownActivity.POLICY_ALARM_MANAGER; +import static com.android.settings.development.tare.DropdownActivity.POLICY_JOB_SCHEDULER; + import android.app.Activity; import android.content.Intent; import android.os.Bundle; @@ -66,6 +70,15 @@ public class TareHomePage extends Activity { /** 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)); + Intent i = new Intent(getApplicationContext(), DropdownActivity.class); + i.putExtra(EXTRA_POLICY, POLICY_ALARM_MANAGER); + startActivity(i); + } + + /** Opens up the JobScheduler TARE policy page with its factors to view and edit */ + public void launchJobSchedulerPage(View v) { + Intent i = new Intent(getApplicationContext(), DropdownActivity.class); + i.putExtra(EXTRA_POLICY, POLICY_JOB_SCHEDULER); + startActivity(i); } }