Merge "Job Scheduler TARE page implementation"
This commit is contained in:
committed by
Android (Google) Code Review
commit
a59a192625
@@ -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" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
|
@@ -13704,6 +13704,39 @@
|
||||
<!-- An event type denoting that an app was interacted with in some way by the user
|
||||
[CHAR LIMIT=40]-->
|
||||
<string name="tare_other_interaction">Other User Interaction</string>
|
||||
<!-- Title for the initiation of a max priority job by an app as defined in the JobScheduler
|
||||
API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_max_start">Job Max Start</string>
|
||||
<!-- Title for the process of carrying out of a max priority job by an app as defined in the
|
||||
JobScheduler API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_max_running">Job Max Running</string>
|
||||
<!-- Title for the initiation of a high priority job by an app as defined in the JobScheduler
|
||||
API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_high_start">Job High Start</string>
|
||||
<!-- Title for the process of carrying out of a high priority job by an app as defined in the
|
||||
JobScheduler API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_high_running">Job High Running</string>
|
||||
<!-- Title for the initiation of a default priority job by an app as defined in the JobScheduler
|
||||
API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_default_start">Job Default Start</string>
|
||||
<!-- Title for the process of carrying out of a default priority job by an app as defined in the
|
||||
JobScheduler API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_default_running">Job Default Running</string>
|
||||
<!-- Title for the initiation of a low priority job by an app as defined in the JobScheduler
|
||||
API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_low_start">Job Low Start</string>
|
||||
<!-- Title for the process of carrying out of a low priority job by an app as defined in the
|
||||
JobScheduler API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_low_running">Job Low Running</string>
|
||||
<!-- Title for the initiation of a minimum priority job by an app as defined in the JobScheduler
|
||||
API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_min_start">Job Min Start</string>
|
||||
<!-- Title for the process of carrying out of a minimum priority job by an app as defined in the
|
||||
JobScheduler API [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_min_running">Job Min Running</string>
|
||||
<!-- Title for the penalty an app receives for letting a job use the maximum execution time and
|
||||
time out [CHAR LIMIT=40]-->
|
||||
<string name="tare_job_timeout_penalty">Job Timeout Penalty</string>
|
||||
<!-- Titles for the minimum satiated credit balances for different types of apps
|
||||
(per battery cycle). Satiated means battery is fully charged. [CHAR LIMIT=40]-->
|
||||
<string-array name="tare_min_satiated_balance_subfactors" translatable="false">
|
||||
@@ -13724,7 +13757,7 @@
|
||||
<!-- Various AlarmManager alarms with different costs to produce and price paid by apps
|
||||
if they want to produce these alarms. Alarm in this context refers to the possible alarm cases
|
||||
in AlarmManager. [CHAR LIMIT=40]-->
|
||||
<string-array name="tare_actions_subfactors" translatable="false">
|
||||
<string-array name="tare_alarm_manager_actions" translatable="false">
|
||||
<item>@string/tare_wakeup_exact_idle</item>
|
||||
<item>@string/tare_wakeup_inexact_idle</item>
|
||||
<item>@string/tare_wakeup_exact</item>
|
||||
@@ -13745,9 +13778,25 @@
|
||||
<item>@string/tare_widget_interaction</item>
|
||||
<item>@string/tare_other_interaction</item>
|
||||
</string-array>
|
||||
<!-- Various JobScheduler tasks with different costs to produce and willingness to pay by apps
|
||||
if they want to carry out these different tasks [CHAR LIMIT=40]-->
|
||||
<string-array name="tare_job_scheduler_actions" translatable="false">
|
||||
<item>@string/tare_job_max_start</item>
|
||||
<item>@string/tare_job_max_running</item>
|
||||
<item>@string/tare_job_high_start</item>
|
||||
<item>@string/tare_job_high_running</item>
|
||||
<item>@string/tare_job_default_start</item>
|
||||
<item>@string/tare_job_default_running</item>
|
||||
<item>@string/tare_job_low_start</item>
|
||||
<item>@string/tare_job_low_running</item>
|
||||
<item>@string/tare_job_min_start</item>
|
||||
<item>@string/tare_job_min_running</item>
|
||||
<item>@string/tare_job_timeout_penalty</item>
|
||||
</string-array>
|
||||
<!-- Array used to populate dropdown menu with the different policies in the TARE
|
||||
settings [CHAR LIMIT=40]-->
|
||||
<string-array name="tare_policies" translatable="false">
|
||||
<item>@string/tare_alarmmanager</item>
|
||||
<item>@string/tare_jobscheduler</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@@ -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)
|
||||
};
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user