admin
2021-08-19 6f07cf3ce7ccb37911f5c755b7833732fb8eee64
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
package com.hanju.video.app.ui.mine;
 
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.bumptech.glide.Glide;
import com.hanju.video.app.util.HanJuConstant;
import com.lcjian.library.util.common.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.hanju.video.app.R;
import com.hanju.video.app.entity.SDCardEntity;
import com.hanju.video.app.ui.BaseActivity;
import com.hanju.video.app.ui.login.PersonInfoActivity;
import com.hanju.video.app.ui.main.MineFragment;
import com.hanju.video.app.util.SDCardUtil;
import com.hanju.video.app.util.XGPush;
import com.hanju.video.app.util.ui.StatusBarUtil;
import com.hanju.video.app.widget.BadgeView;
import com.ysh.wpc.appupdate.AppUpdate;
 
import java.util.Map;
 
public class SettingsActivity extends BaseActivity implements OnClickListener,
        OnCheckedChangeListener {
 
    private TextView tv_top_bar_left;
    private TextView tv_top_bar_middle;
    private TextView tv_version_name;// 版本号
 
    private CheckBox chb_only_wifi_download;
    private RelativeLayout rl_clear_cache;
    private RelativeLayout rl_about_us;
    private RelativeLayout rl_check_update;// 检查更新
    private RelativeLayout rl_disclaimer;
    private RelativeLayout rl_user_agreement;//用户协议
    private RelativeLayout rl_privacy_policy;//隐私条款
 
    private Button btn_exit;// 离开按钮
    private View view_sdcard;
    private TextView tv_mobile;
    private TextView tv_sdcard;
    private CheckBox cb_mobile;
    private CheckBox cb_sdcard;
 
    private void chageSize(TextView tv, int start, int end) {
        SpannableStringBuilder spanBuilder = new SpannableStringBuilder(tv
                .getText().toString());
 
        spanBuilder.setSpan(new TextAppearanceSpan(null, 0, getResources()
                        .getDimensionPixelSize(R.dimen.alphabet_size), null, null),
                start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        tv.setText(spanBuilder);
    }
 
    /**
     * 初始化内存显示
     */
    private void initStorageView() {
        tv_mobile.setText("手机存储: 总量:"
                + SDCardUtil.getSotrageSize(SDCardUtil
                .getTotalExternalMemorySize() / (1024 * 1024))
                + "   可用:"
                + SDCardUtil.getSotrageSize(SDCardUtil
                .getAvailableExternalMemorySize() / (1024 * 1024)));
        chageSize(tv_mobile, 5, tv_mobile.getText().length());
        SDCardEntity entity = SDCardUtil.getSDCardPath(this);
        if (entity == null) {// 没有外部存储卡
            view_sdcard.setVisibility(View.GONE);
            cb_mobile.setVisibility(View.GONE);
        } else {
            tv_sdcard.setText("SD卡存储: 总量:"
                    + SDCardUtil.getSotrageSize(entity.getTotalSize()
                    / (1024 * 1024))
                    + "   可用:"
                    + SDCardUtil.getSotrageSize(entity.getAvailableSize()
                    / (1024 * 1024)));
            chageSize(tv_sdcard, 6, tv_sdcard.getText().length());
            view_sdcard.setVisibility(View.VISIBLE);
            cb_mobile.setVisibility(View.VISIBLE);
            if (SDCardUtil.getDeaultStorage(this) == SDCardUtil.STORAGE_SDCARD) {
                cb_sdcard.setChecked(true);
                cb_mobile.setChecked(false);
            } else {
                cb_sdcard.setChecked(false);
                cb_mobile.setChecked(true);
            }
        }
    }
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings_activity);
 
        view_sdcard = findViewById(R.id.rl_storage_sdcard);
        tv_mobile = findViewById(R.id.tv_storage_mobile);
        tv_sdcard = findViewById(R.id.tv_storage_sdcard);
        cb_mobile = findViewById(R.id.cb_storage_mobile);
        cb_sdcard = findViewById(R.id.cb_storage_sdcard);
        cb_mobile.setOnCheckedChangeListener(this);
        cb_sdcard.setOnCheckedChangeListener(this);
 
        tv_top_bar_left = findViewById(R.id.tv_top_bar_left);
        tv_top_bar_middle = findViewById(R.id.tv_top_bar_middle);
        tv_top_bar_middle.setText("设置");
 
        tv_top_bar_left.setOnClickListener(this);
 
        chb_only_wifi_download = findViewById(R.id.chb_only_wifi_download);
        rl_clear_cache = findViewById(R.id.rl_clear_cache);
        rl_disclaimer = findViewById(R.id.rl_disclaimer);
        rl_about_us = findViewById(R.id.rl_about_us);
        rl_check_update = findViewById(R.id.rl_check_update);
        rl_user_agreement = findViewById(R.id.rl_user_agreement);
        rl_privacy_policy = findViewById(R.id.rl_privacy_policy);
        rl_check_update = findViewById(R.id.rl_check_update);
        tv_version_name = findViewById(R.id.tv_version_name);
        btn_exit = findViewById(R.id.setting_btn_exit);
 
        btn_exit.setOnClickListener(this);
        rl_clear_cache.setOnClickListener(this);
        rl_disclaimer.setOnClickListener(this);
        rl_about_us.setOnClickListener(this);
        rl_check_update.setOnClickListener(this);
        rl_user_agreement.setOnClickListener(this);
        rl_privacy_policy.setOnClickListener(this);
        findViewById(R.id.rl_my_info).setOnClickListener(this);
 
        StatusBarUtil.init(this);
 
        final SharedPreferences settings = getSharedPreferences("settings",
                Context.MODE_PRIVATE);
        chb_only_wifi_download.setChecked(settings.getBoolean(
                "only_wifi_download", true));
        chb_only_wifi_download
                .setOnCheckedChangeListener(new OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView,
                                                 boolean isChecked) {
                        settings.edit()
                                .putBoolean("only_wifi_download", isChecked)
                                .commit();
                    }
                });
        initStorageView();
        tv_version_name.setText("版本号:" + getVersionName(this));
        // 离开按钮是否显示
        if (StringUtils.isEmpty(getSharedPreferences("user",
                Context.MODE_PRIVATE).getString("LoginUid", ""))) {// 如果为空字符
            btn_exit.setVisibility(View.GONE);
        }
    }
 
    /***
     * 获取版本号
     */
    public static String getVersionName(Context context) {
        try {
            PackageInfo pi = context.getPackageManager().getPackageInfo(
                    context.getPackageName(), 0);
            return pi.versionName;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
            return "";
        }
    }
 
    @Override
    public void onResume() {
        super.onResume();
        BadgeView mBadge = new BadgeView(this, tv_version_name);
        mBadge.setBackgroundResource(R.drawable.ic_red_dot);
        mBadge.setTextSize(1);
        mBadge.setText("");
        SharedPreferences preferences = this.getSharedPreferences("update",
                Context.MODE_PRIVATE);
        boolean mStatus = preferences.getBoolean("status", false);
        if (mStatus) {
            mBadge.show();
        } else {
            mBadge.hide();
        }
        MobclickAgent.onPageStart("设置页");
    }
 
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("设置页");
        AppUpdate.destoryAppUpdate();
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.setting_btn_exit:// 点击离开
                if (isFinishing())
                    return;
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("确定要退出登录吗?")
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog,
                                                        int which) {
                                        if (UMShareAPI.get(SettingsActivity.this).isAuthorize(SettingsActivity.this, SHARE_MEDIA.QQ))
                                            UMShareAPI.get(SettingsActivity.this).deleteOauth(SettingsActivity.this, SHARE_MEDIA.QQ, authListener);
 
                                        Editor edit = getSharedPreferences("user",
                                                Context.MODE_PRIVATE).edit();
                                        edit.putString("LoginUid", "");
                                        edit.putBoolean("PushType", false);
                                        edit.commit();
                                        MineFragment.isLogin = false;// 改为未登录状态
                                        XGPush.unRegisterPush(SettingsActivity.this);
                                        finish();
                                    }
                                });
                builder.create().show();
                break;
            case R.id.rl_check_update:// 点击检查更新c81e728d9d4c2f636f067f89cc14862c
                initialer.run();
                break;
            case R.id.tv_top_bar_left: {
                finish();
            }
            break;
            case R.id.rl_clear_cache: {
                if (isFinishing())
                    return;
                AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
                builder2.setMessage("确定清空图片缓存?")
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog,
                                                        int which) {
                                        new Thread(new Runnable() {
                                            @Override
                                            public void run() {
                                                Glide.get(SettingsActivity.this)
                                                        .clearDiskCache();
                                            }
                                        }).start();
                                        ImageLoader.getInstance().clearDiskCache();
                                        Toast.makeText(SettingsActivity.this,
                                                "缓存已清空", Toast.LENGTH_SHORT).show();
                                    }
                                });
                builder2.create().show();
            }
            break;
            case R.id.rl_disclaimer: {
                Intent intent = new Intent(this, BrowserActivity.class);
                intent.putExtra("url", HanJuConstant.HOST + "/BuWan/"
                        + "api_disclaimer.jsp?package=" + getPackageName());
                startActivity(intent);
            }
            break;
            case R.id.rl_user_agreement: {//用户协议
                Intent intent = new Intent(this, BrowserActivity.class);
                intent.putExtra("url", HanJuConstant.USER_AGREEMENT);
                startActivity(intent);
            }
            break;
            case R.id.rl_privacy_policy: {//隐私条款
                Intent intent = new Intent(this, BrowserActivity.class);
                intent.putExtra("url", HanJuConstant.PRIVACY_POLICY);
                startActivity(intent);
            }
            break;
            case R.id.rl_about_us: {
                Intent intent = new Intent(this, AboutUsActivity.class);
                startActivity(intent);
            }
            break;
 
            case R.id.rl_my_info: {
                Intent intent = new Intent(this, PersonInfoActivity.class);
                startActivity(intent);
            }
 
            break;
            default:
                break;
        }
    }
 
    private Runnable initialer = new Runnable() {
 
        @Override
        public void run() {
            AppUpdate.setAppUpdateKey(HanJuConstant.UPDATE_ID);
            AppUpdate.setAppUpdateActivity(SettingsActivity.this, true);
            AppUpdate.initAppUpdate();
        }
    };
 
 
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (buttonView.getId() == R.id.cb_storage_mobile) {
            if (isChecked) {
                SDCardUtil.setDeaultStorage(this, SDCardUtil.STORAGE_MOBILE);
                cb_sdcard.setChecked(false);
            }
        } else {
            if (isChecked) {
                SDCardUtil.setDeaultStorage(this, SDCardUtil.STORAGE_SDCARD);
                cb_mobile.setChecked(false);
            }
        }
 
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        AppUpdate.destoryAppUpdate();
    }
 
 
    UMAuthListener authListener = new UMAuthListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
        }
 
        @Override
        public void onComplete(SHARE_MEDIA platform, int action, final Map<String, String> data) {
//            Toast.makeText(SettingsActivity.this, "退出登录成功", Toast.LENGTH_LONG).show();
        }
 
        @Override
        public void onError(SHARE_MEDIA platform, int action, Throwable t) {
            Toast.makeText(SettingsActivity.this, "退出登录失败", Toast.LENGTH_LONG).show();
        }
 
        @Override
        public void onCancel(SHARE_MEDIA platform, int action) {
            Toast.makeText(SettingsActivity.this, "退出登录取消", Toast.LENGTH_LONG).show();
        }
    };
}