toggles car mode - Android Android OS

Android examples for Android OS:System Model

Description

toggles car mode

Demo Code


//package com.java2s;

import android.app.UiModeManager;

import android.content.Context;

import android.content.res.Configuration;

public class Main {
    /**// ww w .j av a2 s  .  c om
     * toggles car mode
     *
     * @param context
     * @param enable
     * @param alwaysActivate
     */
    public static void setCarModeEnabled(Context context, boolean enable,
            boolean alwaysActivate) {
        UiModeManager uiManager = (UiModeManager) context
                .getSystemService(Context.UI_MODE_SERVICE);
        if (alwaysActivate
                || (enable && uiManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_CAR)) {
            uiManager.enableCarMode(UiModeManager.MODE_NIGHT_AUTO
                    | UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME);
        } else if (!enable
                && uiManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR) {
            uiManager
                    .disableCarMode(UiModeManager.DISABLE_CAR_MODE_GO_HOME);
        }
    }
}

Related Tutorials