add never to Screen timeout

packages/apps/Settings / res/values/arrays.xml

<string-array name="screen_timeout_entries">
        <item>15 seconds</item>
        <item>30 seconds</item>
        <item>1 minute</item>
        <item>2 minutes</item>
        <item>5 minutes</item>
        <item>10 minutes</item>
        <item>30 minutes</item>
        <item>Never</item>
    </string-array>

    <!-- Do not translate. -->
    <string-array name="screen_timeout_values" translatable="false">
        <!-- Do not translate. -->
        <item>15000</item>
        <!-- Do not translate. -->
        <item>30000</item>
        <!-- Do not translate. -->
        <item>60000</item>
        <!-- Do not translate. -->
        <item>120000</item>
        <!-- Do not translate. -->
        <item>300000</item>
        <!-- Do not translate. -->
        <item>600000</item>
        <!-- Do not translate. -->
        <item>1800000</item>
        <!-- Do not translate. -->
        <item>-1</item>
    </string-array>

packages/apps/Settings / src/com/android/settings/display/TimeoutPreferenceController.java

    @Override
    public void updateState(Preference preference) {
        final TimeoutListPreference timeoutListPreference = (TimeoutListPreference) preference;
        long currentTimeout = Settings.System.getLong(mContext.getContentResolver(),
                SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE);
        if (currentTimeout == Integer.MAX_VALUE) {
            currentTimeout = -1;
        }

        timeoutListPreference.setValue(String.valueOf(currentTimeout));

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        try {
            int value = Integer.parseInt((String) newValue);
            updateTimeoutPreferenceDescription((TimeoutListPreference) preference, value);
            if (value == -1) { value = Integer.MAX_VALUE; }
            Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
        } catch (NumberFormatException e) {
            Log.e(TAG, "could not persist screen timeout setting", e);
        }
        return true;
    }

    private void updateTimeoutPreferenceDescription(TimeoutListPreference preference,
            long currentTimeout) {
        final CharSequence[] entries = preference.getEntries();
        final CharSequence[] values = preference.getEntryValues();
        final String summary;
        if (preference.isDisabledByAdmin()) {
            summary = mContext.getString(com.android.settings.R.string.disabled_by_policy_title);
        } else {
            final CharSequence timeoutDescription = getTimeoutDescription(
                    currentTimeout, entries, values);
            if (currentTimeout == -1) {
                summary = entries[values.length - 1].toString();
            } else {
                summary = timeoutDescription == null
                        ? ""
                        : mContext.getString(R.string.screen_timeout_summary, timeoutDescription);
            }

        }
        preference.setSummary(summary);
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
g_timeout_add函数是GLib库中的一个函数,用于在指定的时间间隔后执行一个回调函数。 其函数原型如下: ``` guint g_timeout_add(guint interval, GSourceFunc function, gpointer data); ``` 其中,参数interval表示时间间隔(以毫秒为单位),function表示要执行的回调函数,data表示传递给回调函数的数据。 g_timeout_add函数的返回值是一个guint类型的ID,可以通过该ID来取消定时器。 使用g_timeout_add函数的步骤如下: 1. 编写一个回调函数,该函数会在指定的时间间隔后被调用。 2. 调用g_timeout_add函数并传入回调函数、时间间隔和传递给回调函数的数据。 3. 在适当的时候,可以通过返回的ID取消定时器。 例如,以下代码演示了如何每隔1秒钟输出一次“Hello World”: ``` #include <glib.h> #include <stdio.h> gboolean print_hello(gpointer data) { printf("Hello World\n"); return TRUE; } int main() { guint timer_id = g_timeout_add(1000, print_hello, NULL); // 程序会在5秒钟后退出 g_timeout_add(5000, gtk_main_quit, NULL); gtk_main(); g_source_remove(timer_id); return 0; } ``` 在上述代码中,我们首先定义了一个回调函数print_hello,该函数会输出“Hello World”。然后,我们调用g_timeout_add函数来每隔1秒钟执行一次该回调函数。最后,我们调用g_source_remove函数来取消定时器。 需要注意的是,g_timeout_add函数并不是精确的定时器。如果回调函数执行的时间超过了设定的时间间隔,那么下一次回调函数的执行时间会被推迟。因此,在使用g_timeout_add函数时,应该尽量减少回调函数执行时间,以保证定时器的精度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值