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

Commit 5801049a authored by DvTonder's avatar DvTonder Committed by Ricardo Cerqueira
Browse files

Forward port Quiet Hours settings

Change-Id: I57ad089a2b2f7d6ed3df773ca69ad67f7b8fe185

Conflicts:
	res/values/strings.xml
	src/com/android/settings/SoundSettings.java
parent 49cb04c2
Loading
Loading
Loading
Loading
+80 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="center_vertical">

        <LinearLayout
            android:id="@+id/start_time"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:clickable="true"
            android:focusable="true"
            android:background="?android:attr/selectableItemBackground">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingLeft="16dip"
                android:paddingTop="6dip"
                android:text="@string/start_time_title"
                android:focusable="false"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/start_time_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="vertical"
                android:paddingBottom="6dip"
                android:focusable="false"
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </LinearLayout>

        <View
            android:layout_width="1dip"
            android:layout_height="match_parent"
            android:layout_marginTop="5dip"
            android:layout_marginBottom="5dip"
            android:background="@android:drawable/divider_horizontal_dark" />

        <LinearLayout
            android:id="@+id/end_time"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:clickable="true"
            android:focusable="true"
            android:background="?android:attr/selectableItemBackground">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingLeft="16dip"
                android:paddingTop="6dip"
                android:text="@string/end_time_title"
                android:focusable="false"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/end_time_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:orientation="vertical"
                android:paddingBottom="6dip"
                android:focusable="false"
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </LinearLayout>

</LinearLayout>
+35 −0
Original line number Diff line number Diff line
@@ -4914,6 +4914,41 @@
    <string name="root_access_adb">ADB only</string>
    <string name="root_access_all">Apps and ADB</string>

    <!-- CYANOGENMOD EDITS START -->

    <string name="ok">OK</string>

    <!-- Quiet hours -->
    <string name="quiet_hours_title">Quiet hours</string>
    <string name="quiet_hours_summary">Configure the hours the device should be quiet</string>
    <string name="quiet_hours_note_title">Note</string>
    <string name="quiet_hours_note_summary">Incoming calls will behave like usual during quiet hours</string>
    <string name="quiet_hours_enabled">Enable quiet hours</string>
    <string name="quiet_hours_enabled_on">Quiet hours will be enforced</string>
    <string name="quiet_hours_enabled_off">Notifications will function as normal</string>
    <string name="quiet_hours_start">Start of quiet hours</string>
    <string name="quiet_hours_start_summary">When to start enforcing quiet hours</string>
    <string name="quiet_hours_end">End of quiet hours</string>
    <string name="quiet_hours_end_summary">When to stop enforcing quiet hours</string>
    <string name="quiet_hours_mute">Mute notifications</string>
    <string name="quiet_hours_mute_on">No sounds will be played</string>
    <string name="quiet_hours_mute_off">Sounds will play like normal</string>
    <string name="quiet_hours_still">Disable vibrations</string>
    <string name="quiet_hours_still_on">Device will not vibrate</string>
    <string name="quiet_hours_still_off">Device will vibrate normally</string>
    <string name="quiet_hours_dim">Disable notification light</string>
    <string name="quiet_hours_dim_on">Notification light will be disabled</string>
    <string name="quiet_hours_dim_off">Notification light will function as normal</string>
    <string name="quiet_hours_haptic">Disable haptic feedback</string>
    <string name="quiet_hours_haptic_on">Haptic feedback will be disabled</string>
    <string name="quiet_hours_haptic_off">Haptic feedback will function as normal</string>
    <string name="quiet_hours_active_from">Active from</string>
    <string name="quiet_hours_active_to">to</string>

    <!-- time range preference -->
    <string name="start_time_title">Start</string>
    <string name="end_time_title">End</string>

    <!-- About phone screen,  setting option name-->
    <string name="mod_version">CyanogenMod version</string>
    <string name="mod_version_default">Unknown</string>
+68 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2012 The CyanogenMod 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.
-->

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/quiet_hours_title"
    xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">

    <Preference
        android:key="quiet_hours_note"
        style="?android:preferenceInformationStyle"
        android:title="@string/quiet_hours_note_title"
        android:summary="@string/quiet_hours_note_summary"
        android:selectable="false" />

    <CheckBoxPreference
        android:key="quiet_hours_enabled"
        android:title="@string/quiet_hours_enabled"
        android:summaryOn="@string/quiet_hours_enabled_on"
        android:summaryOff="@string/quiet_hours_enabled_off"
        android:defaultValue="false" />

    <com.android.settings.cyanogenmod.TimeRangePreference
        android:key="quiet_hours_timerange"
        android:dependency="quiet_hours_enabled" />

    <CheckBoxPreference
        android:key="quiet_hours_mute"
        android:title="@string/quiet_hours_mute"
        android:summaryOn="@string/quiet_hours_mute_on"
        android:summaryOff="@string/quiet_hours_mute_off"
        android:dependency="quiet_hours_enabled" />

    <CheckBoxPreference
        android:key="quiet_hours_haptic"
        android:title="@string/quiet_hours_haptic"
        android:summaryOn="@string/quiet_hours_haptic_on"
        android:summaryOff="@string/quiet_hours_haptic_off"
        android:dependency="quiet_hours_enabled" />

    <CheckBoxPreference
        android:key="quiet_hours_still"
        android:title="@string/quiet_hours_still"
        android:summaryOn="@string/quiet_hours_still_on"
        android:summaryOff="@string/quiet_hours_still_off"
        android:dependency="quiet_hours_enabled" />

    <CheckBoxPreference
        android:key="quiet_hours_dim"
        android:title="@string/quiet_hours_dim"
        android:summaryOn="@string/quiet_hours_dim_on"
        android:summaryOff="@string/quiet_hours_dim_off"
        android:dependency="quiet_hours_enabled" />

</PreferenceScreen>
 No newline at end of file
+7 −1
Original line number Diff line number Diff line
@@ -33,6 +33,12 @@
                android:targetClass="com.android.musicfx.ControlPanelPicker" />
    </Preference>

    <!-- Quiet hours -->
    <PreferenceScreen
            android:key="quiet_hours"
            android:fragment="com.android.settings.cyanogenmod.QuietHours"
            android:title="@string/quiet_hours_title" />

    <PreferenceCategory
            android:key="category_calls_and_notification"
            android:title="@string/sound_category_call_ringtone_vibrate_title"/>
+52 −0
Original line number Diff line number Diff line
@@ -46,8 +46,11 @@ import android.preference.PreferenceScreen;
import android.provider.MediaStore;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.format.DateFormat;
import android.util.Log;

import java.util.Date;
import java.util.Calendar;
import java.util.List;

public class SoundSettings extends SettingsPreferenceFragment implements
@@ -75,6 +78,8 @@ public class SoundSettings extends SettingsPreferenceFragment implements
    private static final String KEY_DOCK_AUDIO_SETTINGS = "dock_audio";
    private static final String KEY_DOCK_SOUNDS = "dock_sounds";
    private static final String KEY_DOCK_AUDIO_MEDIA_ENABLED = "dock_audio_media_enabled";
    private static final String KEY_QUIET_HOURS = "quiet_hours";


    private static final String[] NEED_VOICE_CAPABILITY = {
            KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS,
@@ -92,6 +97,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements
    private CheckBoxPreference mLockSounds;
    private Preference mRingtonePreference;
    private Preference mNotificationPreference;
    private PreferenceScreen mQuietHours;

    private Runnable mRingtoneLookupRunnable;

@@ -150,6 +156,16 @@ public class SoundSettings extends SettingsPreferenceFragment implements
            getPreferenceScreen().removePreference(findPreference(KEY_RING_VOLUME));
        }

        mQuietHours = (PreferenceScreen) findPreference(KEY_QUIET_HOURS);
        if (Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_ENABLED, 0) == 1) {
            mQuietHours.setSummary(getString(R.string.quiet_hours_active_from) + " " +
                    returnTime(Settings.System.getString(resolver, Settings.System.QUIET_HOURS_START))
                    + " " + getString(R.string.quiet_hours_active_to) + " " +
                    returnTime(Settings.System.getString(resolver, Settings.System.QUIET_HOURS_END)));
        } else {
            mQuietHours.setSummary(getString(R.string.quiet_hours_summary));
        }

        mVibrateWhenRinging = (CheckBoxPreference) findPreference(KEY_VIBRATE);
        mVibrateWhenRinging.setPersistent(false);
        mVibrateWhenRinging.setChecked(Settings.System.getInt(resolver,
@@ -233,6 +249,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements
    public void onResume() {
        super.onResume();

        updateState(true);
        lookupRingtoneNames();

        IntentFilter filter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
@@ -246,6 +263,21 @@ public class SoundSettings extends SettingsPreferenceFragment implements
        getActivity().unregisterReceiver(mReceiver);
    }

    // updateState in fact updates the UI to reflect the system state
    private void updateState(boolean force) {
        if (getActivity() == null) return;
        ContentResolver resolver = getContentResolver();

        if (Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_ENABLED, 0) == 1) {
            mQuietHours.setSummary(getString(R.string.quiet_hours_active_from) + " " +
                    returnTime(Settings.System.getString(resolver, Settings.System.QUIET_HOURS_START))
                    + " " + getString(R.string.quiet_hours_active_to) + " " +
                    returnTime(Settings.System.getString(resolver, Settings.System.QUIET_HOURS_END)));
        } else {
            mQuietHours.setSummary(getString(R.string.quiet_hours_summary));
        }
    }

    private void updateRingtoneName(int type, Preference preference, int msg) {
        if (preference == null) return;
        Context context = getActivity();
@@ -336,7 +368,11 @@ public class SoundSettings extends SettingsPreferenceFragment implements
        } else if (preference == mDockAudioMediaEnabled) {
            Settings.Global.putInt(getContentResolver(), Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
                    mDockAudioMediaEnabled.isChecked() ? 1 : 0);
        } else {
            // If we didn't handle it, let preferences handle it.
            return super.onPreferenceTreeClick(preferenceScreen, preference);
        }

        return true;
    }

@@ -355,6 +391,22 @@ public class SoundSettings extends SettingsPreferenceFragment implements
        return true;
    }

    private String returnTime(String t) {
        if (t == null || t.equals("")) {
            return "";
        }
        int hr = Integer.parseInt(t.trim());
        int mn = hr;

        hr = hr / 60;
        mn = mn % 60;
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, hr);
        cal.set(Calendar.MINUTE, mn);
        Date date = cal.getTime();
        return DateFormat.getTimeFormat(getActivity().getApplicationContext()).format(date);
    }

    @Override
    protected int getHelpResource() {
        return R.string.help_url_sound;
Loading