冲刺day10

DateViewUtils.java
package timeline.lizimumu.com.t.util;

import android.content.Context;

import androidx.core.content.ContextCompat;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;

import java.util.Calendar;

import timeline.lizimumu.com.t.R;

public class DateViewUtils {

    private static DateViewUtils instance;
    private static float lineSpacingMultiplier = 2F;  // 条目间距倍数 默认1.6
    private static final String EMPTY = "";    // 空字符串

    private DateViewUtils() {
    }


    public static DateViewUtils getInstance() {
        if (instance == null) {
            synchronized (DateViewUtils.class) {
                if (instance == null) {
                    instance = new DateViewUtils();
                }
            }
        }
        return instance;
    }


    /**
     * 获取未来的日期,(从当天到endTime)
     *
     * @param mContext
     * @param listener
     */
    public void getAfterDateView(Context mContext, OnTimeSelectListener listener) {
        Calendar startDate = Calendar.getInstance(); // 最小值
        Calendar endDate = Calendar.getInstance(); // 最大值
        endDate.add(Calendar.HOUR_OF_DAY, 12);
        getDateView(mContext, listener, startDate, endDate);
    }


    /**
     * 获取通用的样式
     *
     * @param listener 回调监听
     * @param start    开始
     * @param end      结束
     */
    public void getDateView(Context mContext, OnTimeSelectListener listener, Calendar start, Calendar end) {
        // 日期选择器
        TimePickerView pvTime = new TimePickerBuilder(mContext, listener)
                .isCyclic(false)  //是否循环滚动
                .setType(new boolean[]{true, true, true, true, true, false})   // 只显示年月日
                .isCenterLabel(true)  // 每项item全部都带有label
                .setContentTextSize(20)    // 滚轮文字大小
                .setTitleBgColor(ContextCompat.getColor(mContext, R.color.bg_b1b1b2))  // 标题背景颜色
                .setCancelColor(ContextCompat.getColor(mContext, R.color.text_666666)) // 取消按钮文字颜色
                .setSubmitColor(ContextCompat.getColor(mContext, R.color.text_037BFF))   // 确定按钮文字颜色
                .setDividerColor(ContextCompat.getColor(mContext, R.color.divide_c6c6c6))  // 分隔线颜色
                .setRangDate(start, end)
                .setOutSideCancelable(false)
                .setLabel(EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY)
//                .setDate(select)   // 默认选中
                .setLineSpacingMultiplier(lineSpacingMultiplier)
                .build();
        pvTime.show();
    }

}

PreferenceManager.java

package timeline.lizimumu.com.t.util;

import android.content.Context;
import android.content.SharedPreferences;


public class PreferenceManager {

    public static final String PREF_SETTINGS_HIDE_SYSTEM_APPS = "hide_system_apps";
    public static final String PREF_SETTINGS_HIDE_UNINSTALL_APPS = "hide_uninstall_apps";
    public static final String PREF_LIST_SORT = "sort_list";
    public static final String FCM_ID = "fcm_id";
    private static final String PREF_NAME = "preference_application";

    private static PreferenceManager mManager;
    private static SharedPreferences mShare;

    private PreferenceManager() {
    }

    public static void init(Context context) {
        mManager = new PreferenceManager();
        mShare = context.getApplicationContext().getSharedPreferences(PREF_NAME, 0);
    }

    public static PreferenceManager getInstance() {
        return mManager;
    }

    public void putBoolean(String key, boolean value) {
        mShare.edit().putBoolean(key, value).apply();
    }

    public void putInt(String key, int value) {
        mShare.edit().putInt(key, value).apply();
    }

    public boolean getBoolean(String key) {
        return mShare.getBoolean(key, false);
    }

    public int getInt(String key) {
        return mShare.getInt(key, 0);
    }

    public boolean getUninstallSettings(String key) {
        return mShare.getBoolean(key, true);
    }

    public boolean getSystemSettings(String key) {
        return mShare.getBoolean(key, true);
    }

    public void putString(String key, String value) {
        mShare.edit().putString(key, value).apply();
    }

    public String getString(String key) {
        return mShare.getString(key, "");
    }
}

 

posted @ 2022-04-23 20:00  椅念琼  阅读(37)  评论(0编辑  收藏  举报