Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4ce2971 authored by Greg Ross's avatar Greg Ross Committed by Michael Bestas
Browse files

DeskClock: Simplify action menu

Move the screen saver action menu item into the main clock settings
page and create a new "Screen saver" group that continas it as well
as a link to the clock's screen saver settings, and a link to the
daydream settings as well.

Change-Id: I3ce018dc043a1144c9cee056f14be4dfc8a82f03
parent 1bc23736
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -105,4 +105,19 @@
        <item>00FF00</item>
        <item>0000FF</item>
    </string-array>

    <!-- Header in the preferences settings for the section pertaining to screen saver -->
    <string name="screensaver_settings_title">Screen saver</string>
    <!-- Label for the screen saver preview in settings -->
    <string name="screensaver_preview">Preview</string>
    <!-- Summary for the screen saver preview in settings -->
    <string name="screensaver_preview_summary">Starts the screen saver immediately</string>
    <!-- Label for the screen saver settings in settings -->
    <string name="screensaver_change_settings">Settings</string>
    <!-- Summary for the screen saver settings in settings -->
    <string name="screensaver_change_settings_summary">Opens Clock\'s screen saver settings</string>
    <!-- Label for the screen saver settings in settings -->
    <string name="screensaver_daydream_settings">Select/enable screen saver</string>
    <!-- Summary for the screen saver settings in settings -->
    <string name="screensaver_daydream_settings_summary">Opens the main screen saver settings</string>
</resources>
+24 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
     Copyright (C) 2023 The LineageOS Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
@@ -56,6 +57,29 @@
            app:iconSpaceReserved="false" />
    </PreferenceCategory>

    <PreferenceCategory
        android:title="@string/screensaver_settings_title"
        app:iconSpaceReserved="false">

        <Preference
            android:key="screensaver_preview"
            android:title="@string/screensaver_preview"
            android:summary="@string/screensaver_preview_summary"
            app:iconSpaceReserved="false" />

        <Preference
            android:key="screensaver_settings"
            android:title="@string/screensaver_change_settings"
            android:summary="@string/screensaver_change_settings_summary"
            app:iconSpaceReserved="false" />

        <Preference
            android:key="screensaver_daydream_settings"
            android:title="@string/screensaver_daydream_settings"
            android:summary="@string/screensaver_daydream_settings_summary"
            app:iconSpaceReserved="false" />
    </PreferenceCategory>

    <PreferenceCategory
        android:title="@string/alarm_settings"
        app:iconSpaceReserved="false">
+2 −3
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 * Copyright (C) 2020-2023 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -46,7 +47,6 @@ import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;

import com.android.deskclock.actionbarmenu.MenuItemControllerFactory;
import com.android.deskclock.actionbarmenu.NightModeMenuItemController;
import com.android.deskclock.actionbarmenu.OptionsMenuManager;
import com.android.deskclock.actionbarmenu.SettingsMenuItemController;
import com.android.deskclock.data.DataModel;
@@ -160,8 +160,7 @@ public class DeskClock extends BaseActivity
        }

        // Configure the menu item controllers add behavior to the toolbar.
        mOptionsMenuManager.addMenuItemController(
                new NightModeMenuItemController(this), new SettingsMenuItemController(this));
        mOptionsMenuManager.addMenuItemController(new SettingsMenuItemController(this));
        mOptionsMenuManager.addMenuItemController(
                MenuItemControllerFactory.getInstance().buildMenuItemControllers(this));

+0 −64
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.deskclock.actionbarmenu;

import static android.view.Menu.NONE;

import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;

import com.android.deskclock.R;
import com.android.deskclock.ScreensaverActivity;
import com.android.deskclock.events.Events;

/**
 * {@link MenuItemController} for controlling night mode display.
 */
public final class NightModeMenuItemController implements MenuItemController {

    private static final int NIGHT_MODE_MENU_RES_ID = R.id.menu_item_night_mode;

    private final Context mContext;

    public NightModeMenuItemController(Context context) {
        mContext = context;
    }

    @Override
    public int getId() {
        return NIGHT_MODE_MENU_RES_ID;
    }

    @Override
    public void onCreateOptionsItem(Menu menu) {
        menu.add(NONE, NIGHT_MODE_MENU_RES_ID, NONE, R.string.menu_item_night_mode)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    @Override
    public void onPrepareOptionsItem(MenuItem item) {
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        mContext.startActivity(new Intent(mContext, ScreensaverActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .putExtra(Events.EXTRA_EVENT_LABEL, R.string.label_deskclock));
        return true;
    }
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 * Copyright (C) 2022-2023 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -35,10 +36,12 @@ import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.TwoStatePreference;

import com.android.deskclock.R;
import com.android.deskclock.ScreensaverActivity;
import com.android.deskclock.Utils;
import com.android.deskclock.data.DataModel;
import com.android.deskclock.data.TimeZones;
import com.android.deskclock.data.Weekdays;
import com.android.deskclock.events.Events;
import com.android.deskclock.ringtone.RingtonePickerActivity;
import com.android.deskclock.widget.CollapsingToolbarBaseActivity;

@@ -58,6 +61,9 @@ public final class SettingsActivity extends CollapsingToolbarBaseActivity {
    public static final String KEY_HOME_TZ = "home_time_zone";
    public static final String KEY_AUTO_HOME_CLOCK = "automatic_home_clock";
    public static final String KEY_DATE_TIME = "date_time";
    public static final String KEY_SCREENSAVER_SETTINGS = "screensaver_settings";
    public static final String KEY_SCREENSAVER_PREVIEW = "screensaver_preview";
    public static final String KEY_SCREENSAVER_DAYDREAM_SETTINGS = "screensaver_daydream_settings";
    public static final String KEY_VOLUME_BUTTONS = "volume_button_setting";
    public static final String KEY_WEEK_START = "week_start";
    public static final String KEY_FLIP_ACTION = "flip_action";
@@ -175,6 +181,23 @@ public final class SettingsActivity extends CollapsingToolbarBaseActivity {
            }

            switch (pref.getKey()) {
                case KEY_SCREENSAVER_DAYDREAM_SETTINGS:
                    final Intent dialogSSMainSettingsIntent = new Intent(
                            Settings.ACTION_DREAM_SETTINGS);
                    dialogSSMainSettingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(dialogSSMainSettingsIntent);
                    return true;
                case KEY_SCREENSAVER_PREVIEW:
                    context.startActivity(new Intent(context, ScreensaverActivity.class)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                            .putExtra(Events.EXTRA_EVENT_LABEL, R.string.label_deskclock));
                    return true;
                case KEY_SCREENSAVER_SETTINGS:
                    final Intent dialogSSSettingsIntent = new Intent(context,
                            ScreensaverSettingsActivity.class);
                    dialogSSSettingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(dialogSSSettingsIntent);
                    return true;
                case KEY_DATE_TIME:
                    final Intent dialogIntent = new Intent(Settings.ACTION_DATE_SETTINGS);
                    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -259,6 +282,16 @@ public final class SettingsActivity extends CollapsingToolbarBaseActivity {
            final Preference dateAndTimeSetting = findPreference(KEY_DATE_TIME);
            dateAndTimeSetting.setOnPreferenceClickListener(this);

            final Preference screensaverSettings = findPreference(KEY_SCREENSAVER_SETTINGS);
            screensaverSettings.setOnPreferenceClickListener(this);

            final Preference screensaverMainSettings =
                    findPreference(KEY_SCREENSAVER_DAYDREAM_SETTINGS);
            screensaverMainSettings.setOnPreferenceClickListener(this);

            final Preference screensaverPreview = findPreference(KEY_SCREENSAVER_PREVIEW);
            screensaverPreview.setOnPreferenceClickListener(this);

            final SimpleMenuPreference weekStartPref = findPreference(KEY_WEEK_START);
            // Set the default value programmatically
            final Weekdays.Order weekdayOrder = DataModel.getDataModel().getWeekdayOrder();