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

Commit 3d43d0a8 authored by Danny Baumann's avatar Danny Baumann Committed by Michael Bestas
Browse files

Localize screen timeout toast.

Change-Id: Ic167ead9a218ae3cb887c2b70257024e3b5bbbc5
parent 94cd3e4c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,4 +35,5 @@
    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-Zubehör"</string>
    <string name="label_view" msgid="6304565553218192990">"Anzeigen"</string>
    <string name="always_use_accessory" msgid="1210954576979621596">"Standardmäßig für dieses USB-Zubehör verwenden"</string>
    <string name="powerwidget_screen_timeout_toast">Bildschirm-Timeout ist jetzt %1$d %2$s</string>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -38,4 +38,6 @@
    <string name="title_usb_accessory" msgid="4966265263465181372">"Αξεσουάρ USB"</string>
    <string name="label_view" msgid="6304565553218192990">"Προβολή"</string>
    <string name="always_use_accessory" msgid="1210954576979621596">"Χρήση από προεπιλογή για αυτό το εξάρτημα USB"</string>

    <string name="powerwidget_screen_timeout_toast">Χρονικό όριο οθόνης: %1$d %2$s</string>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -38,4 +38,6 @@
    <string name="title_usb_accessory" msgid="4966265263465181372">"Accessoire USB"</string>
    <string name="label_view" msgid="6304565553218192990">"Afficher"</string>
    <string name="always_use_accessory" msgid="1210954576979621596">"Utiliser par défaut pour cet accessoire USB"</string>

    <string name="powerwidget_screen_timeout_toast">Veille de l\'écran réglée à : %1$d %2$s</string>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -72,4 +72,5 @@
    <!-- Checkbox label for USB accessory dialogs.  [CHAR LIMIT=50] -->
    <string name="always_use_accessory">Use by default for this USB accessory</string>

    <string name="powerwidget_screen_timeout_toast">Screen timeout set to: %1$d %2$s</string>
</resources>
+34 −21
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import com.android.systemui.R;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.Uri;
import android.provider.Settings;
import android.view.Gravity;
@@ -108,8 +109,8 @@ public class ScreenTimeoutButton extends PowerButton {
        }

        // inform users of how long the timeout is now
        mToast = Toast.makeText(context, "Screen timeout set to: " + timeoutToString(screenTimeout),
                Toast.LENGTH_LONG);
        final String toast = makeTimeoutToastString(context, screenTimeout);
        mToast = Toast.makeText(context, toast, Toast.LENGTH_LONG);
        mToast.setGravity(Gravity.CENTER, mToast.getXOffset() / 2, mToast.getYOffset() / 2);
        mToast.show();
    }
@@ -128,29 +129,41 @@ public class ScreenTimeoutButton extends PowerButton {
        return true;
    }

    private static int getScreenTimeout(Context context) {
        return Settings.System.getInt(
                context.getContentResolver(),
                Settings.System.SCREEN_OFF_TIMEOUT, 0);
    }
    private String makeTimeoutToastString(Context context, int timeout) {
        Resources res = context.getResources();
        int resId;

    private static String timeoutToString(int timeout) {
        String[] tags = new String[] {
                "second(s)",
                "minute(s)",
                "hour(s)"
            };
        /* ms -> seconds */
        timeout /= 1000;

        // default to however many seconds we have
        int tmp = (timeout / 1000);
        String sTimeout = tmp + " " + tags[0];
        if (timeout >= 60 && timeout % 60 == 0) {
            /* seconds -> minutes */
            timeout /= 60;
            if (timeout >= 60 && timeout % 60 == 0) {
                /* minutes -> hours */
                timeout /= 60;
                resId = timeout == 1
                        ? com.android.internal.R.string.hour
                        : com.android.internal.R.string.hours;
            } else {
                resId = timeout == 1
                        ? com.android.internal.R.string.minute
                        : com.android.internal.R.string.minutes;
            }
        } else {
            resId = timeout == 1
                    ? com.android.internal.R.string.second
                    : com.android.internal.R.string.seconds;
        }

        for(int i = 1; i < tags.length && tmp >= 60; i++) {
            tmp /= (60 * i);
            sTimeout = tmp + " " + tags[i];
        return res.getString(R.string.powerwidget_screen_timeout_toast,
                timeout, res.getString(resId));
    }

        return sTimeout;
    private static int getScreenTimeout(Context context) {
        return Settings.System.getInt(
                context.getContentResolver(),
                Settings.System.SCREEN_OFF_TIMEOUT, 0);
    }

    private static int getCurrentCMMode(Context context) {