Job Scheduler TARE page implementation

A Job Scheduler policy page is needed in the TARE developer options
settings to allow developers to both view and edit the current values of
all the factors under the job scheduler 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 wil pop up under it.

Bug: 191877052

Test: Manual (open Settings > System > Developer Options > TARE >
JobScheduler and verify all factors are there)

Change-Id: Icea6cda5e4b59d1736f85defcb9532839c3720f5
This commit is contained in:
alinasuarez
2021-07-26 21:04:16 +00:00
parent 32ef854a8d
commit 8073d4eb92
6 changed files with 261 additions and 6 deletions

View File

@@ -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)
};

View File

@@ -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);

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}