123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- package com.printer.demo.utils;
- import android.content.Context;
- import android.content.SharedPreferences;
- import android.text.format.Time;
- public class PrefUtils {
- public static final String PREF_NAME = "config";
- public static boolean getBoolean(Context ctx, String key, boolean defaultValue) {
- SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- return sp.getBoolean(key, defaultValue);
- }
- public static void setBoolean(Context ctx, String key, boolean value) {
- SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- sp.edit().putBoolean(key, value).commit();
- }
- public static String getString(Context ctx, String key, String defaultValue) {
- SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- return sp.getString(key, defaultValue);
- }
- public static void setString(Context ctx, String key, String value) {
- SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- sp.edit().putString(key, value).commit();
- }
- public static int getInt(Context ctx, String key, int defaultValue) {
- SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- return sp.getInt(key, defaultValue);
- }
- public static void setInt(Context ctx, String key, int value) {
- SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
- sp.edit().putInt(key, value).commit();
- }
- public static String getSystemTime() {
- Time t = new Time();
- t.setToNow();
- int year = t.year;
- int month = t.month + 1;
- int date = t.monthDay;
- int hour = t.hour;
- int minute = t.minute;
- int seconds = t.second;
- String tag = "AM";
- if (hour >= 12) {
- tag = "PM";
- }
- String time = date + "/" + month + "/" + year + " " + hour + ":" + minute + " " + tag;
- return time;
- }
- public static String getSystemTime2() {
- Time t = new Time();
- t.setToNow();
- int year = t.year;
- int month = t.month + 1;
- int date = t.monthDay;
- int hour = t.hour;
- int minute = t.minute;
- int seconds = t.second;
- String tag = "AM";
- if (hour >= 12) {
- tag = "PM";
- }
- String time;
- if (month < 10) {
- if (seconds >= 10) {
- time = year + "-0" + month + "-" + date + " " + hour + ":" + minute + ":" + seconds;
- } else {
- time = year + "-0" + month + "-" + date + " " + hour + ":" + minute + ":0" + seconds;
- }
- } else {
- if (seconds >= 10) {
- time = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + seconds;
- } else {
- time = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":0" + seconds;
- }
- }
- return time;
- }
- public static String getSystemTime3() {
- Time t = new Time();
- t.setToNow();
- int year = t.year;
- int month = t.month + 1;
- int date = t.monthDay;
- int hour = t.hour;
- int minute = t.minute;
- int seconds = t.second;
- String tag = "AM";
- if (hour >= 12) {
- tag = "PM";
- }
- String time;
- if (month < 10) {
- if (seconds >= 10) {
- time = year + "-0" + month + "-" + date;
- } else {
- time = year + "-0" + month + "-" + date;
- }
- } else {
- if (seconds >= 10) {
- time = year + "-" + month + "-" + date;
- } else {
- time = year + "-" + month + "-" + date;
- }
- }
- return time;
- }
- }
|