Loading res/values/strings.xml +40 −23 Original line number Diff line number Diff line Loading @@ -13731,18 +13731,26 @@ translate "maximum balance when device is fully charged" instead. Balance is the same meaning as having money in a bank account. Balance in our feature is the amount of Android Resource Credits an app can have. Android Resource Credits are a form of payment used by apps to be able to perform tasks. [CHAR LIMIT=40]--> perform tasks. [CHAR LIMIT=80]--> <string name="tare_max_satiated_balance">Maximum Satiated Balance</string> <!-- Title for the TARE policy factor that determines the maximum credits in circulation between all the apps [CHAR LIMIT=40]--> <string name="tare_max_circulation">Maximum Circulation</string> <!-- Title for the TARE policy factor that determines the minimum credits an app can have in one battery life cycle. Satiated means battery is fully charged; If this is not easily translatable, translate "minimum balance when device is fully charged" instead. Balance is the same meaning as having money in a bank account. Balance in our feature is the amount of Android Resource Credits an app can have. Android Resource Credits are a form of payment used by apps to be able to perform tasks. [CHAR LIMIT=40]--> <string name="tare_min_satiated_balance">Minimum Satiated Balance</string> <!-- Title for the TARE policy factors that affect how many credits an app may have. Balance in this context is the same as "bank balance" or "account balance" (ie. how much "money" may be in a bank account). [CHAR LIMIT=55]--> <string name="tare_balances">Balances</string> <!-- Title for the TARE section to modify consumption limits. "Consumption" refers to the idea using resources that are not replenished. [CHAR LIMIT=55]--> <string name="tare_consumption_limits">Consumption Limits</string> <!-- Title for the TARE policy factor that determines the initial maximum amount of credits that can be consumed by all the apps [CHAR LIMIT=80]--> <string name="tare_initial_consumption_limit">Initial Consumption Limit</string> <!-- Title for the TARE policy factor that determines the maximum consumption limit the system can have [CHAR LIMIT=80]--> <string name="tare_hard_consumption_limit">Maximum Consumption Limit</string> <!-- Titles for the consumption limits factors. [CHAR LIMIT=40]--> <string-array name="tare_consumption_limit_subfactors" translatable="false"> <item>@string/tare_initial_consumption_limit</item> <item>@string/tare_hard_consumption_limit</item> </string-array> <!-- Title for the various modifiers that alter the cost of TARE tasks based on battery status (charging, power save mode, etc.) [CHAR LIMIT=40]--> <string name="tare_modifiers">Modifiers</string> Loading Loading @@ -13778,14 +13786,6 @@ <string name="tare_nonwakeup_inexact" translatable="false">Inexact NonWakeup Alarm</string> <!-- Title for the AlarmClock alarm set via AlarmManager.setAlarmClock() [CHAR LIMIT=50]--> <string name="tare_alarm_clock" translatable="false">AlarmClock</string> <!-- Exempted apps are those apps exempted from most power saving features. [CHAR LIMIT=50]--> <string name="tare_exempted">Exempted</string> <!-- A headless system app is a preinstalled app that does not have any activities/UI that the user can interact with. [CHAR LIMIT=50]--> <string name="tare_headless_app">Headless System App</string> <!-- Other apps are those apps interacted with by users that are not exempted or headless system apps. [CHAR LIMIT=50]--> <string name="tare_other_app">Other App</string> <!-- Top activity means an app is in the TOP android process state and is thus visible to the user[CHAR LIMIT=50]--> <string name="tare_top_activity">Top Activity</string> Loading Loading @@ -13842,12 +13842,29 @@ <!-- Title for the penalty an app receives for letting a job use the maximum execution time and time out [CHAR LIMIT=50]--> <string name="tare_job_timeout_penalty">Job Timeout Penalty</string> <!-- Title for the TARE factor that determines the minimum credits an app should have when the device is fully charged. "Satiated" in this context means that the battery is fully charged. Balance is the same meaning as having money in a bank account. Exempted apps are those apps exempted from most power saving features. [CHAR LIMIT=80]--> <string name="tare_min_balance_exempted">Minimum Satiated Balance (Exempted)</string> <!-- Title for the TARE factor that determines the minimum credits an app should have when the device is fully charged. "Satiated" in this context means that the battery is fully charged. Balance is the same meaning as having money in a bank account. A headless system app is a preinstalled app that does not have any activities/UI that the user can interact with. [CHAR LIMIT=80]--> <string name="tare_min_balance_headless_app">Minimum Satiated Balance (Headless System App)</string> <!-- Title for the TARE factor that determines the minimum credits an app should have when the device is fully charged. "Satiated" in this context means that the battery is fully charged. Balance is the same meaning as having money in a bank account. Remaining apps are those apps that don't fit into predefined categories. [CHAR LIMIT=80]--> <string name="tare_min_balance_other_app">Minimum Satiated Balance (Remaining Apps)</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"> <item>@string/tare_exempted</item> <item>@string/tare_headless_app</item> <item>@string/tare_other_app</item> <string-array name="tare_app_balance_subfactors" translatable="false"> <item>@string/tare_max_satiated_balance</item> <item>@string/tare_min_balance_exempted</item> <item>@string/tare_min_balance_headless_app</item> <item>@string/tare_min_balance_other_app</item> </string-array> <!-- Various modifier subfactors that alter the cost of TARE tasks depending on what battery state the device is in [CHAR LIMIT=50]--> src/com/android/settings/development/tare/AlarmManagerFragment.java +72 −107 Original line number Diff line number Diff line Loading @@ -15,17 +15,16 @@ */ package com.android.settings.development.tare; import android.annotation.Nullable; import android.app.Fragment; import android.app.tare.EconomyManager; 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; Loading @@ -33,130 +32,96 @@ 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 { public class AlarmManagerFragment extends Fragment implements TareFactorController.DataChangeListener { private TareFactorController mFactorController; private TareFactorExpandableListAdapter mExpandableListAdapter; private String[] mGroups; private String[][] mChildren; private String[][] mKeys; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFactorController = TareFactorController.getInstance(getContext()); populateArrays(); } @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(); mExpandableListAdapter = new TareFactorExpandableListAdapter( mFactorController, LayoutInflater.from(getActivity()), mGroups, mChildren, mKeys); elv.setGroupIndicator(null); elv.setAdapter(expListAdapter); elv.setAdapter(mExpandableListAdapter); 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(); final String key = mExpandableListAdapter.getKey(groupPosition, childPosition); mFactorController.createDialog(key).show(getFragmentManager(), key); 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_alarm_manager_actions), mResources.getStringArray(R.array.tare_rewards_subfactors) }; public SavedTabsListAdapter() { mInflater = LayoutInflater.from(getActivity()); } @Override public int getGroupCount() { return mGroups.length; public void onStart() { super.onStart(); mFactorController.registerListener(this); } @Override public int getChildrenCount(int groupPosition) { return mChildren[groupPosition].length; public void onStop() { mFactorController.unregisterListener(this); super.onStop(); } @Override public Object getGroup(int groupPosition) { return mGroups[groupPosition]; public void onDataChanged() { mExpandableListAdapter.notifyDataSetChanged(); } @Override public Object getChild(int groupPosition, int childPosition) { return mChildren[groupPosition][childPosition]; } @Override public long getGroupId(int groupPosition) { return groupPosition; } private void populateArrays() { final Resources resources = getResources(); @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"); mGroups = new String[]{ resources.getString(R.string.tare_consumption_limits), resources.getString(R.string.tare_balances), // resources.getString(R.string.tare_modifiers), // resources.getString(R.string.tare_actions), // resources.getString(R.string.tare_rewards) }; return convertView; } mChildren = new String[][]{ resources.getStringArray(R.array.tare_consumption_limit_subfactors), resources.getStringArray(R.array.tare_app_balance_subfactors), // TODO: support // resources.getStringArray(R.array.tare_modifiers_subfactors), // resources.getStringArray(R.array.tare_alarm_manager_actions), // resources.getStringArray(R.array.tare_rewards_subfactors) }; @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } mKeys = new String[][]{ { EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT, EconomyManager.KEY_AM_HARD_CONSUMPTION_LIMIT }, { EconomyManager.KEY_AM_MAX_SATIATED_BALANCE, EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED, EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP, EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP }, // {}, // {}, // {}, }; } } src/com/android/settings/development/tare/DropdownActivity.java +0 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ public class DropdownActivity extends Activity { 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); Loading src/com/android/settings/development/tare/JobSchedulerFragment.java +73 −108 Original line number Diff line number Diff line Loading @@ -15,17 +15,16 @@ */ package com.android.settings.development.tare; import android.annotation.Nullable; import android.app.Fragment; import android.app.tare.EconomyManager; 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; Loading @@ -33,131 +32,97 @@ 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 { public class JobSchedulerFragment extends Fragment implements TareFactorController.DataChangeListener { private TareFactorController mFactorController; private TareFactorExpandableListAdapter mExpandableListAdapter; private String[] mGroups; private String[][] mChildren; private String[][] mKeys; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFactorController = TareFactorController.getInstance(getContext()); populateArrays(); } @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(); mExpandableListAdapter = new TareFactorExpandableListAdapter( mFactorController, LayoutInflater.from(getActivity()), mGroups, mChildren, mKeys); elv.setGroupIndicator(null); elv.setAdapter(expListAdapter); elv.setAdapter(mExpandableListAdapter); 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(); final String key = mExpandableListAdapter.getKey(groupPosition, childPosition); mFactorController.createDialog(key).show(getFragmentManager(), key); 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; return v; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; public void onStart() { super.onStart(); mFactorController.registerListener(this); } @Override public boolean hasStableIds() { return true; public void onStop() { mFactorController.unregisterListener(this); super.onStop(); } @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; public void onDataChanged() { mExpandableListAdapter.notifyDataSetChanged(); } @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); private void populateArrays() { final Resources resources = getResources(); // TODO: Replace these hardcoded values with either default or user inputted TARE values factor.setText(getChild(groupPosition, childPosition).toString()); value.setText("500"); mGroups = new String[]{ resources.getString(R.string.tare_consumption_limits), resources.getString(R.string.tare_balances), // mResources.getString(R.string.tare_modifiers), // mResources.getString(R.string.tare_actions), // mResources.getString(R.string.tare_rewards) }; return convertView; } mChildren = new String[][]{ resources.getStringArray(R.array.tare_consumption_limit_subfactors), resources.getStringArray(R.array.tare_app_balance_subfactors), // TODO: support // mResources.getStringArray(R.array.tare_modifiers_subfactors), // mResources.getStringArray(R.array.tare_job_scheduler_actions), // mResources.getStringArray(R.array.tare_rewards_subfactors) }; @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } mKeys = new String[][]{ { EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT, EconomyManager.KEY_JS_HARD_CONSUMPTION_LIMIT }, { EconomyManager.KEY_JS_MAX_SATIATED_BALANCE, EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_EXEMPTED, EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP, EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_OTHER_APP }, // {}, // {}, // {}, }; } } src/com/android/settings/development/tare/TareFactorController.java +92 −29 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
res/values/strings.xml +40 −23 Original line number Diff line number Diff line Loading @@ -13731,18 +13731,26 @@ translate "maximum balance when device is fully charged" instead. Balance is the same meaning as having money in a bank account. Balance in our feature is the amount of Android Resource Credits an app can have. Android Resource Credits are a form of payment used by apps to be able to perform tasks. [CHAR LIMIT=40]--> perform tasks. [CHAR LIMIT=80]--> <string name="tare_max_satiated_balance">Maximum Satiated Balance</string> <!-- Title for the TARE policy factor that determines the maximum credits in circulation between all the apps [CHAR LIMIT=40]--> <string name="tare_max_circulation">Maximum Circulation</string> <!-- Title for the TARE policy factor that determines the minimum credits an app can have in one battery life cycle. Satiated means battery is fully charged; If this is not easily translatable, translate "minimum balance when device is fully charged" instead. Balance is the same meaning as having money in a bank account. Balance in our feature is the amount of Android Resource Credits an app can have. Android Resource Credits are a form of payment used by apps to be able to perform tasks. [CHAR LIMIT=40]--> <string name="tare_min_satiated_balance">Minimum Satiated Balance</string> <!-- Title for the TARE policy factors that affect how many credits an app may have. Balance in this context is the same as "bank balance" or "account balance" (ie. how much "money" may be in a bank account). [CHAR LIMIT=55]--> <string name="tare_balances">Balances</string> <!-- Title for the TARE section to modify consumption limits. "Consumption" refers to the idea using resources that are not replenished. [CHAR LIMIT=55]--> <string name="tare_consumption_limits">Consumption Limits</string> <!-- Title for the TARE policy factor that determines the initial maximum amount of credits that can be consumed by all the apps [CHAR LIMIT=80]--> <string name="tare_initial_consumption_limit">Initial Consumption Limit</string> <!-- Title for the TARE policy factor that determines the maximum consumption limit the system can have [CHAR LIMIT=80]--> <string name="tare_hard_consumption_limit">Maximum Consumption Limit</string> <!-- Titles for the consumption limits factors. [CHAR LIMIT=40]--> <string-array name="tare_consumption_limit_subfactors" translatable="false"> <item>@string/tare_initial_consumption_limit</item> <item>@string/tare_hard_consumption_limit</item> </string-array> <!-- Title for the various modifiers that alter the cost of TARE tasks based on battery status (charging, power save mode, etc.) [CHAR LIMIT=40]--> <string name="tare_modifiers">Modifiers</string> Loading Loading @@ -13778,14 +13786,6 @@ <string name="tare_nonwakeup_inexact" translatable="false">Inexact NonWakeup Alarm</string> <!-- Title for the AlarmClock alarm set via AlarmManager.setAlarmClock() [CHAR LIMIT=50]--> <string name="tare_alarm_clock" translatable="false">AlarmClock</string> <!-- Exempted apps are those apps exempted from most power saving features. [CHAR LIMIT=50]--> <string name="tare_exempted">Exempted</string> <!-- A headless system app is a preinstalled app that does not have any activities/UI that the user can interact with. [CHAR LIMIT=50]--> <string name="tare_headless_app">Headless System App</string> <!-- Other apps are those apps interacted with by users that are not exempted or headless system apps. [CHAR LIMIT=50]--> <string name="tare_other_app">Other App</string> <!-- Top activity means an app is in the TOP android process state and is thus visible to the user[CHAR LIMIT=50]--> <string name="tare_top_activity">Top Activity</string> Loading Loading @@ -13842,12 +13842,29 @@ <!-- Title for the penalty an app receives for letting a job use the maximum execution time and time out [CHAR LIMIT=50]--> <string name="tare_job_timeout_penalty">Job Timeout Penalty</string> <!-- Title for the TARE factor that determines the minimum credits an app should have when the device is fully charged. "Satiated" in this context means that the battery is fully charged. Balance is the same meaning as having money in a bank account. Exempted apps are those apps exempted from most power saving features. [CHAR LIMIT=80]--> <string name="tare_min_balance_exempted">Minimum Satiated Balance (Exempted)</string> <!-- Title for the TARE factor that determines the minimum credits an app should have when the device is fully charged. "Satiated" in this context means that the battery is fully charged. Balance is the same meaning as having money in a bank account. A headless system app is a preinstalled app that does not have any activities/UI that the user can interact with. [CHAR LIMIT=80]--> <string name="tare_min_balance_headless_app">Minimum Satiated Balance (Headless System App)</string> <!-- Title for the TARE factor that determines the minimum credits an app should have when the device is fully charged. "Satiated" in this context means that the battery is fully charged. Balance is the same meaning as having money in a bank account. Remaining apps are those apps that don't fit into predefined categories. [CHAR LIMIT=80]--> <string name="tare_min_balance_other_app">Minimum Satiated Balance (Remaining Apps)</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"> <item>@string/tare_exempted</item> <item>@string/tare_headless_app</item> <item>@string/tare_other_app</item> <string-array name="tare_app_balance_subfactors" translatable="false"> <item>@string/tare_max_satiated_balance</item> <item>@string/tare_min_balance_exempted</item> <item>@string/tare_min_balance_headless_app</item> <item>@string/tare_min_balance_other_app</item> </string-array> <!-- Various modifier subfactors that alter the cost of TARE tasks depending on what battery state the device is in [CHAR LIMIT=50]-->
src/com/android/settings/development/tare/AlarmManagerFragment.java +72 −107 Original line number Diff line number Diff line Loading @@ -15,17 +15,16 @@ */ package com.android.settings.development.tare; import android.annotation.Nullable; import android.app.Fragment; import android.app.tare.EconomyManager; 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; Loading @@ -33,130 +32,96 @@ 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 { public class AlarmManagerFragment extends Fragment implements TareFactorController.DataChangeListener { private TareFactorController mFactorController; private TareFactorExpandableListAdapter mExpandableListAdapter; private String[] mGroups; private String[][] mChildren; private String[][] mKeys; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFactorController = TareFactorController.getInstance(getContext()); populateArrays(); } @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(); mExpandableListAdapter = new TareFactorExpandableListAdapter( mFactorController, LayoutInflater.from(getActivity()), mGroups, mChildren, mKeys); elv.setGroupIndicator(null); elv.setAdapter(expListAdapter); elv.setAdapter(mExpandableListAdapter); 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(); final String key = mExpandableListAdapter.getKey(groupPosition, childPosition); mFactorController.createDialog(key).show(getFragmentManager(), key); 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_alarm_manager_actions), mResources.getStringArray(R.array.tare_rewards_subfactors) }; public SavedTabsListAdapter() { mInflater = LayoutInflater.from(getActivity()); } @Override public int getGroupCount() { return mGroups.length; public void onStart() { super.onStart(); mFactorController.registerListener(this); } @Override public int getChildrenCount(int groupPosition) { return mChildren[groupPosition].length; public void onStop() { mFactorController.unregisterListener(this); super.onStop(); } @Override public Object getGroup(int groupPosition) { return mGroups[groupPosition]; public void onDataChanged() { mExpandableListAdapter.notifyDataSetChanged(); } @Override public Object getChild(int groupPosition, int childPosition) { return mChildren[groupPosition][childPosition]; } @Override public long getGroupId(int groupPosition) { return groupPosition; } private void populateArrays() { final Resources resources = getResources(); @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"); mGroups = new String[]{ resources.getString(R.string.tare_consumption_limits), resources.getString(R.string.tare_balances), // resources.getString(R.string.tare_modifiers), // resources.getString(R.string.tare_actions), // resources.getString(R.string.tare_rewards) }; return convertView; } mChildren = new String[][]{ resources.getStringArray(R.array.tare_consumption_limit_subfactors), resources.getStringArray(R.array.tare_app_balance_subfactors), // TODO: support // resources.getStringArray(R.array.tare_modifiers_subfactors), // resources.getStringArray(R.array.tare_alarm_manager_actions), // resources.getStringArray(R.array.tare_rewards_subfactors) }; @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } mKeys = new String[][]{ { EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT, EconomyManager.KEY_AM_HARD_CONSUMPTION_LIMIT }, { EconomyManager.KEY_AM_MAX_SATIATED_BALANCE, EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED, EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP, EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP }, // {}, // {}, // {}, }; } }
src/com/android/settings/development/tare/DropdownActivity.java +0 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,6 @@ public class DropdownActivity extends Activity { 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); Loading
src/com/android/settings/development/tare/JobSchedulerFragment.java +73 −108 Original line number Diff line number Diff line Loading @@ -15,17 +15,16 @@ */ package com.android.settings.development.tare; import android.annotation.Nullable; import android.app.Fragment; import android.app.tare.EconomyManager; 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; Loading @@ -33,131 +32,97 @@ 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 { public class JobSchedulerFragment extends Fragment implements TareFactorController.DataChangeListener { private TareFactorController mFactorController; private TareFactorExpandableListAdapter mExpandableListAdapter; private String[] mGroups; private String[][] mChildren; private String[][] mKeys; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFactorController = TareFactorController.getInstance(getContext()); populateArrays(); } @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(); mExpandableListAdapter = new TareFactorExpandableListAdapter( mFactorController, LayoutInflater.from(getActivity()), mGroups, mChildren, mKeys); elv.setGroupIndicator(null); elv.setAdapter(expListAdapter); elv.setAdapter(mExpandableListAdapter); 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(); final String key = mExpandableListAdapter.getKey(groupPosition, childPosition); mFactorController.createDialog(key).show(getFragmentManager(), key); 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; return v; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; public void onStart() { super.onStart(); mFactorController.registerListener(this); } @Override public boolean hasStableIds() { return true; public void onStop() { mFactorController.unregisterListener(this); super.onStop(); } @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; public void onDataChanged() { mExpandableListAdapter.notifyDataSetChanged(); } @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); private void populateArrays() { final Resources resources = getResources(); // TODO: Replace these hardcoded values with either default or user inputted TARE values factor.setText(getChild(groupPosition, childPosition).toString()); value.setText("500"); mGroups = new String[]{ resources.getString(R.string.tare_consumption_limits), resources.getString(R.string.tare_balances), // mResources.getString(R.string.tare_modifiers), // mResources.getString(R.string.tare_actions), // mResources.getString(R.string.tare_rewards) }; return convertView; } mChildren = new String[][]{ resources.getStringArray(R.array.tare_consumption_limit_subfactors), resources.getStringArray(R.array.tare_app_balance_subfactors), // TODO: support // mResources.getStringArray(R.array.tare_modifiers_subfactors), // mResources.getStringArray(R.array.tare_job_scheduler_actions), // mResources.getStringArray(R.array.tare_rewards_subfactors) }; @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } mKeys = new String[][]{ { EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT, EconomyManager.KEY_JS_HARD_CONSUMPTION_LIMIT }, { EconomyManager.KEY_JS_MAX_SATIATED_BALANCE, EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_EXEMPTED, EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP, EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_OTHER_APP }, // {}, // {}, // {}, }; } }
src/com/android/settings/development/tare/TareFactorController.java +92 −29 File changed.Preview size limit exceeded, changes collapsed. Show changes