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.ContextWrapper;
import android.content.SharedPreferences;

public class Main {
    private static final float DEFAULT_UPPER = 1.0f;
    private static final float DEFAULT_LOWER = 0.05f;
    private static final String PREF_NAME = "nvcclient";
    protected static float upperBrightness = DEFAULT_UPPER;
    protected static float lowerBrightness = DEFAULT_LOWER;

    public static void loadConfigurationFromSharedPreferences(Context context) {
        upperBrightness = getPreference(context, "upper_brightness", DEFAULT_UPPER);
        lowerBrightness = getPreference(context, "lower_brightness", DEFAULT_LOWER);
    }

    public static boolean getPreference(Context context, String key, boolean defaultValue) {
        SharedPreferences pref = getPreferences(context);
        return pref.getBoolean(key, defaultValue);
    }

    public static float getPreference(Context context, String key, float defaultValue) {
        SharedPreferences pref = getPreferences(context);
        return pref.getFloat(key, defaultValue);
    }

    public static int getPreference(Context context, String key, int defaultValue) {
        SharedPreferences pref = getPreferences(context);
        return pref.getInt(key, defaultValue);
    }

    public static long getPreference(Context context, String key, long defaultValue) {
        SharedPreferences pref = getPreferences(context);
        return pref.getLong(key, defaultValue);
    }

    public static String getPreference(Context context, String key, String defaultValue) {
        SharedPreferences pref = getPreferences(context);
        String value = pref.getString(key, defaultValue);
        if (value.length() == 0) {
            value = defaultValue;
        }
        return value;
    }

    public static SharedPreferences getPreferences(Context context) {
        return new ContextWrapper(context).getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    }
}