wjc
2023-06-02 dac1f2838830dbe6f7ae791cc4563a00c4c5fe92
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
package com.hdl.photovoltaic.base;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
 
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
 
import com.hdl.photovoltaic.listener.BaseView;
import com.hdl.photovoltaic.utils.AppManagerUtils;
 
 
public abstract class BaseActivity extends AppCompatActivity implements BaseView {
 
    protected Activity _mActivity;
 
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        _mActivity = this;
        Object content = getContentView();
        //添加Activity到堆栈
        AppManagerUtils.getAppManager().addActivity(this);
        if (content instanceof Integer) {
            setContentView((int) content);
        } else if (content instanceof View) {
            setContentView((View) content);
        } else {
            throw new RuntimeException("getContentView() should be a @LayoutRes or a View");
        }
        onBindView(savedInstanceState);
 
    }
 
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
 
    }
 
    /**
     * 显示View
     *
     * @param view
     */
    public void setViewVisible(View view) {
        if (view.getVisibility() != View.VISIBLE) {
            view.setVisibility(View.VISIBLE);
        }
    }
 
    /**
     * 隐藏View
     *
     * @param view
     */
    protected void setViewGone(View view) {
        if (view.getVisibility() != View.GONE) {
            view.setVisibility(View.GONE);
        }
    }
 
    /**
     * 简单的跳转Activity
     *
     * @param clazz
     */
    protected void startActivity(Class<?> clazz) {
        Intent intent = new Intent(this, clazz);
        startActivity(intent);
 
    }
 
    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public int dip2px(float dpValue) {
        final float scale = getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
 
    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    public int px2dip(float pxValue) {
        final float scale = getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }
 
 
}