Add TARE button and homepage to developer options.

A TARE button is needed in the developer options in settings to allow
users and developers to change the default settings it will come with.
When clicked, it opens an activity of the TARE homepage with a toggle
and the two policies (Alarm Manager and Job Scheduler) to choose between. It also contains a revert to default settings button.

Bug: 191876567

Test: Manual (open Settings > System > Developer Options > TARE and
verify tabs and menus are there)

Change-Id: Id14bc9c1dcbaaf2aeb74ba7efb0168ab424f5d0c
This commit is contained in:
alinasuarez
2021-07-14 18:59:31 +00:00
parent 0e371c63ae
commit 6ffa9dad04
5 changed files with 153 additions and 0 deletions

View File

@@ -1465,6 +1465,10 @@
android:value="true" />
</activity>
<activity android:name=".development.tare.TareHomePage"
android:label="@string/tare_settings"
android:exported="false" />
<activity android:name="SetFullBackupPassword"
android:label="@string/local_backup_password_title"
android:exported="false" />

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".development.tare.TareHomePage">
<Switch
android:id="@+id/on_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="On"
android:background="?android:attr/colorBackground"/>
<TextView
android:id="@+id/alarm_manager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:clickable="true"
android:text="@string/tare_alarm_manager"
android:textColor="?android:attr/textColorSecondary"/>
<TextView
android:id="@+id/job_scheduler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:clickable="true"
android:text="@string/tare_job_scheduler"
android:textColor="?android:attr/textColorSecondary"/>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider" />
<Button
android:id="@+id/revert_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:onClick="revertSettings"
android:text="@string/tare_revert"/>
</LinearLayout>

View File

@@ -13576,4 +13576,17 @@
<string name="bluetooth_connect_access_dialog_negative">Don\u2019t connect</string>
<!-- Strings for Dialog connect button -->
<string name="bluetooth_connect_access_dialog_positive">Connect</string>
<!-- Title for the button to edit The Android Resource Economy settings. [CHAR LIMIT=NONE] -->
<string name="tare_title" translatable="false">TARE</string>
<!-- TARE settings title in developer options; TARE" is not translatable but "settings" is [CHAR LIMIT=40] -->
<string name="tare_settings">TARE Settings</string>
<!-- Allows user to revert the TARE settings to their default values [CHAR LIMIT=40] -->
<string name="tare_revert">Revert to Default Settings</string>
<!-- Allows user to view Alarm Manager policy factors [CHAR LIMIT=40]-->
<string name="tare_alarm_manager">Alarm Manager</string>
<!-- Allows user to view Job Scheduler policy factors [CHAR LIMIT=40]-->
<string name="tare_job_scheduler">Job Scheduler</string>
<!-- Toast notifying the developer that settings were reverted to their default [CHAR LIMIT=40]-->
<string name="tare_settings_reverted_toast">Settings reverted to default.</string>
</resources>

View File

@@ -606,6 +606,14 @@
android:title="@string/inactive_apps_title"
android:fragment="com.android.settings.fuelgauge.InactiveApps" />
<Preference
android:key="tare"
android:title="@string/tare_title" >
<intent
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.development.tare.TareHomePage" />
</Preference>
<SwitchPreference
android:key="force_allow_on_external"
android:title="@string/force_allow_on_external"

View File

@@ -0,0 +1,65 @@
/*
* 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.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.android.settings.R;
/** Class for creating the TARE homepage in settings*/
public class TareHomePage extends Activity {
private Switch mOnSwitch;
private Button mRevButton;
private TextView mAlarmManagerView;
private TextView mJobSchedulerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tare_homepage);
mOnSwitch = findViewById(R.id.on_switch);
mRevButton = findViewById(R.id.revert_button);
mAlarmManagerView = findViewById(R.id.alarm_manager);
mJobSchedulerView = findViewById(R.id.job_scheduler);
// TODO: Set the status of the buttons based on the current status
mOnSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mRevButton.setEnabled(isChecked);
mAlarmManagerView.setEnabled(isChecked);
mJobSchedulerView.setEnabled(isChecked);
}
});
}
/** 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
public void revertSettings(View v) {
Toast.makeText(this, R.string.tare_settings_reverted_toast, Toast.LENGTH_LONG).show();
}
}