Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.content.SharedPreferences;

public class Main {
    public final static int THEME_SUN = 1;
    public final static int THEME_NIGHT = 2;

    public static int getSwitchDayNightMode(Context context) {
        int mode = getDayNightMode(context);
        return mode == THEME_SUN ? THEME_NIGHT : THEME_SUN;
    }

    public static int getDayNightMode(Context context) {
        SharedPreferences sharedPreferences = getSharedPreferences(context);
        return sharedPreferences.getInt("SUN_NIGHT_MODE", THEME_SUN);
    }

    private static SharedPreferences getSharedPreferences(Context context) {
        return context.getSharedPreferences("NightModeDemo", Context.MODE_APPEND);
    }
}