admin
2024-01-26 c2d382d99ca506932985d1843d4371d6ed0203ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.video.youth.util;
 
import android.content.Context;
import android.content.SharedPreferences;
 
import com.lcjian.library.util.common.StringUtils;
import com.video.youth.entity.YouthModeChange;
 
import org.greenrobot.eventbus.EventBus;
 
 
public class YouthUtil {
 
    /**
     * 是否开启了青少年模式
     *
     * @param context
     * @return
     */
    public static boolean isOpenYouthMode(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean("open", false);
    }
 
    /**
     * 关闭青少年模式
     *
     * @param context
     */
    public static void openYouthMode(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("open", true);
        editor.commit();
        EventBus.getDefault().post(new YouthModeChange(true));
    }
 
    /**
     * 关闭青少年模式
     *
     * @param context
     */
    public static void closeYouthMode(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("open", false);
        editor.commit();
        EventBus.getDefault().post(new YouthModeChange(false));
    }
 
    /**
     * 设置密码
     *
     * @param context
     * @param pwd
     */
    public static void setPwd(Context context, String pwd) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("pwd", pwd);
        editor.commit();
    }
 
    /**
     * 密码是否正确
     *
     * @param context
     * @param pwd
     * @return
     */
    public static boolean isPwdRight(Context context, String pwd) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
        String old = sharedPreferences.getString("pwd", "");
        return old.equalsIgnoreCase(pwd);
    }
 
 
    /**
     * 是否设置了密码
     *
     * @param context
     * @return
     */
    public static boolean isSetPwd(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
        String old = sharedPreferences.getString("pwd", "");
        return !StringUtils.isBlank(old);
    }
 
 
}