Add night display pref controllers and change UX

- Convert NightDisplaySettings to a DashboardFragment
- Add preference controllers for all Night Display settings
- Change UX for activation from a toggle to a button

Bug: 73739388
Bug: 69912911
Test: make -j100 and make RunSettingsRoboTests -j100
Change-Id: Ia173f16207ba59bf57eb7546cbb1e2dbca67b063
This commit is contained in:
Christine Franks
2018-03-16 16:33:18 -07:00
parent 7b36ccdd9b
commit d67ec89c4b
21 changed files with 1119 additions and 187 deletions

View File

@@ -19,25 +19,20 @@ import androidx.preference.SwitchPreference;
import android.util.AttributeSet;
import com.android.internal.app.ColorDisplayController;
import com.android.settings.R;
import java.text.DateFormat;
import java.time.LocalTime;
import java.util.Calendar;
import java.util.TimeZone;
public class NightDisplayPreference extends SwitchPreference
implements ColorDisplayController.Callback {
private ColorDisplayController mController;
private DateFormat mTimeFormatter;
private NightDisplayTimeFormatter mTimeFormatter;
public NightDisplayPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mController = new ColorDisplayController(context);
mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
mTimeFormatter = new NightDisplayTimeFormatter(context);
}
@Override
@@ -59,53 +54,6 @@ public class NightDisplayPreference extends SwitchPreference
mController.setListener(null);
}
private String getFormattedTimeString(LocalTime localTime) {
final Calendar c = Calendar.getInstance();
c.setTimeZone(mTimeFormatter.getTimeZone());
c.set(Calendar.HOUR_OF_DAY, localTime.getHour());
c.set(Calendar.MINUTE, localTime.getMinute());
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return mTimeFormatter.format(c.getTime());
}
private void updateSummary() {
final Context context = getContext();
final boolean isActivated = mController.isActivated();
final int autoMode = mController.getAutoMode();
final String autoModeSummary;
switch (autoMode) {
default:
case ColorDisplayController.AUTO_MODE_DISABLED:
autoModeSummary = context.getString(isActivated
? R.string.night_display_summary_on_auto_mode_never
: R.string.night_display_summary_off_auto_mode_never);
break;
case ColorDisplayController.AUTO_MODE_CUSTOM:
if (isActivated) {
autoModeSummary = context.getString(
R.string.night_display_summary_on_auto_mode_custom,
getFormattedTimeString(mController.getCustomEndTime()));
} else {
autoModeSummary = context.getString(
R.string.night_display_summary_off_auto_mode_custom,
getFormattedTimeString(mController.getCustomStartTime()));
}
break;
case ColorDisplayController.AUTO_MODE_TWILIGHT:
autoModeSummary = context.getString(isActivated
? R.string.night_display_summary_on_auto_mode_twilight
: R.string.night_display_summary_off_auto_mode_twilight);
break;
}
final int summaryFormatResId = isActivated ? R.string.night_display_summary_on
: R.string.night_display_summary_off;
setSummary(context.getString(summaryFormatResId, autoModeSummary));
}
@Override
public void onActivated(boolean activated) {
updateSummary();
@@ -125,4 +73,8 @@ public class NightDisplayPreference extends SwitchPreference
public void onCustomEndTimeChanged(LocalTime endTime) {
updateSummary();
}
private void updateSummary() {
setSummary(mTimeFormatter.getAutoModeTimeSummary(getContext(), mController));
}
}