ソースを参照

更新功能样式修改完成

huyuguo 4 年 前
コミット
11d614e785

+ 8 - 7
app/src/main/java/com/electric/chargingpile/activity/MainMapActivity.java

@ -128,6 +128,7 @@ import com.electric.chargingpile.util.ToastUtil;
128 128
import com.electric.chargingpile.util.Util;
129 129
import com.electric.chargingpile.util.ZhanDBHelper;
130 130
import com.electric.chargingpile.view.AlertDialogTwo;
131
import com.electric.chargingpile.view.AlertDialogUpdate;
131 132
import com.electric.chargingpile.view.SlideAdView;
132 133
import com.electric.chargingpile.view.UpdateDialog;
133 134
import com.google.gson.Gson;
@ -207,7 +208,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
207 208
    private MapView mapView;
208 209
    public static String back = "";
209 210
    private static AMap aMap;
210
    private AlertDialogTwo alterDialog;
211
    private AlertDialogUpdate alterDialog;
211 212
    public static boolean tag = false;
212 213
    public static String condition;
213 214
    public static int level;
@ -485,7 +486,8 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
485 486
                                if (key.length - 1 > 2) {
486 487
                                    dialogup_other();
487 488
                                } else {
488
                                    dialogup();
489
//                                    dialogup();
490
                                    dialogup_other();
489 491
                                }
490 492
                            }
491 493
@ -4011,8 +4013,8 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4011 4013
        int code = Integer.parseInt(now_versionCode);
4012 4014
        if (code - getVersionCode(getApplication()) > 0) {
4013 4015
4014
            new com.electric.chargingpile.view.AlertDialogTwo(MainMapActivity.this).builder()
4015
                    .setTitle("更新提示 V" + now_versionName)
4016
            new AlertDialogUpdate(MainMapActivity.this).builder()
4017
                    .setTitle("更新提示 " + now_versionName)
4016 4018
                    .setMsg(title.trim())
4017 4019
                    .setPositiveButton("更新", new View.OnClickListener() {
4018 4020
                        @Override
@ -4041,10 +4043,10 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4041 4043
    private void dialogup_other() {
4042 4044
        int code = Integer.parseInt(now_versionCode);
4043 4045
        if (code - getVersionCode(getApplication()) > 0) {
4044
            alterDialog = new AlertDialogTwo(MainMapActivity.this);
4046
            alterDialog = new AlertDialogUpdate(MainMapActivity.this);
4045 4047
4046 4048
            alterDialog.builder()
4047
                    .setTitle("更新提示 V" + now_versionName)
4049
                    .setTitle("更新提示 " + now_versionName)
4048 4050
                    .setMsg(title.trim())
4049 4051
                    .setPositiveButton("更新", new View.OnClickListener() {
4050 4052
                        @Override
@ -4122,7 +4124,6 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4122 4124
                    editor1.clear();
4123 4125
                    finish();
4124 4126
                    ProfileManager.getInstance().setSearchAddress(getApplicationContext(), "");
4125
//                    System.exit(0);
4126 4127
                    android.os.Process.killProcess(android.os.Process.myPid());
4127 4128
                }
4128 4129
            }).setCancelable(false).show();

+ 189 - 0
app/src/main/java/com/electric/chargingpile/view/AlertDialogUpdate.java

@ -0,0 +1,189 @@
1
package com.electric.chargingpile.view;
2
3
import android.app.Dialog;
4
import android.content.Context;
5
import android.view.Display;
6
import android.view.Gravity;
7
import android.view.LayoutInflater;
8
import android.view.View;
9
import android.view.View.OnClickListener;
10
import android.view.ViewTreeObserver;
11
import android.view.WindowManager;
12
import android.widget.Button;
13
import android.widget.FrameLayout;
14
import android.widget.ImageView;
15
import android.widget.LinearLayout;
16
import android.widget.LinearLayout.LayoutParams;
17
import android.widget.TextView;
18
19
import androidx.constraintlayout.widget.ConstraintLayout;
20
21
import com.electric.chargingpile.R;
22
import com.electric.chargingpile.activity.ChatContentListActivity;
23
import com.electric.chargingpile.application.MainApplication;
24
import com.electric.chargingpile.util.ScreenUtils;
25
26
public class AlertDialogUpdate {
27
    private Context context;
28
    private Dialog dialog;
29
    private LinearLayout lLayout_bg;
30
    private TextView txt_title;
31
    private TextView txt_msg;
32
    private Button btn_neg;
33
    private Button btn_pos;
34
    private Display display;
35
    private boolean showTitle = false;
36
    private boolean showMsg = false;
37
    private boolean showPosBtn = false;
38
    private boolean showNegBtn = false;
39
    private ImageView update_header;
40
41
    public AlertDialogUpdate(Context context) {
42
        this.context = context;
43
        WindowManager windowManager = (WindowManager) context
44
                .getSystemService(Context.WINDOW_SERVICE);
45
        display = windowManager.getDefaultDisplay();
46
    }
47
48
    public AlertDialogUpdate builder() {
49
        // 获取Dialog布局
50
        View view = LayoutInflater.from(context).inflate(R.layout.view_alterdialog_update, null);
51
52
        // 获取自定义Dialog布局中的控件
53
        lLayout_bg = (LinearLayout) view.findViewById(R.id.lLayout_bg);
54
        update_header = view.findViewById(R.id.update_header);
55
        txt_title = (TextView) view.findViewById(R.id.txt_title);
56
        txt_msg = (TextView) view.findViewById(R.id.txt_msg);
57
        btn_neg = (Button) view.findViewById(R.id.btn_neg);
58
        btn_neg.setVisibility(View.GONE);
59
        btn_pos = (Button) view.findViewById(R.id.btn_pos);
60
        btn_pos.setVisibility(View.GONE);
61
62
        // 定义Dialog布局和参数
63
        dialog = new Dialog(context, R.style.AlertDialogStyle);
64
        dialog.setContentView(view);
65
66
        int width = (int) (ScreenUtils.getScreenWidth(MainApplication.context) * 0.75);
67
        // 调整dialog背景大小
68
        lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams(width, LayoutParams.WRAP_CONTENT));
69
        int imageHeight = (int)(216.0/408.0*width);
70
        update_header.setLayoutParams(new ConstraintLayout.LayoutParams(width,imageHeight));
71
        return this;
72
    }
73
74
    public AlertDialogUpdate setTitle(String title) {
75
        showTitle = true;
76
        if ("".equals(title)) {
77
            txt_title.setText("标题");
78
        } else {
79
            txt_title.setText(title);
80
        }
81
        return this;
82
    }
83
84
    public AlertDialogUpdate setMsg(String msg) {
85
        showMsg = true;
86
        if ("".equals(msg)) {
87
            txt_msg.setText("内容");
88
        } else {
89
            txt_msg.setText(msg);
90
        }
91
        ViewTreeObserver vto = txt_msg.getViewTreeObserver();
92
        vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
93
            @Override
94
            public boolean onPreDraw() {
95
                int lineCount = txt_msg.getLineCount();
96
                if (lineCount == 1) {
97
                    txt_msg.setGravity(Gravity.CENTER);
98
                } else {
99
                    txt_msg.setGravity(Gravity.CENTER | Gravity.LEFT);
100
                }
101
                return true;
102
            }
103
        });
104
        return this;
105
    }
106
107
    public AlertDialogUpdate setCancelable(boolean cancel) {
108
        dialog.setCancelable(cancel);
109
        return this;
110
    }
111
112
    public AlertDialogUpdate setPositiveButton(String text, final OnClickListener listener) {
113
        showPosBtn = true;
114
        if ("".equals(text)) {
115
            btn_pos.setText("确定");
116
        } else {
117
            btn_pos.setText(text);
118
        }
119
        btn_pos.setOnClickListener(new OnClickListener() {
120
            @Override
121
            public void onClick(View v) {
122
                try {
123
                    listener.onClick(v);
124
                    dialog.dismiss();
125
                } catch (Exception e) {
126
                    e.printStackTrace();
127
                }
128
129
            }
130
        });
131
        return this;
132
    }
133
134
    public AlertDialogUpdate setNegativeButton(String text, final OnClickListener listener) {
135
        showNegBtn = true;
136
        if ("".equals(text)) {
137
            btn_neg.setText("取消");
138
        } else {
139
            btn_neg.setText(text);
140
        }
141
        btn_neg.setOnClickListener(new OnClickListener() {
142
            @Override
143
            public void onClick(View v) {
144
                listener.onClick(v);
145
                dialog.dismiss();
146
            }
147
        });
148
        return this;
149
    }
150
151
    private void setLayout() {
152
        if (!showPosBtn && !showNegBtn) {
153
            btn_pos.setText("确定");
154
            btn_pos.setVisibility(View.VISIBLE);
155
            btn_pos.setOnClickListener(new OnClickListener() {
156
                @Override
157
                public void onClick(View v) {
158
                    dialog.dismiss();
159
                }
160
            });
161
        }
162
163
        if (showPosBtn && showNegBtn) {
164
            btn_pos.setVisibility(View.VISIBLE);
165
            btn_neg.setVisibility(View.VISIBLE);
166
        }
167
168
        if (showPosBtn && !showNegBtn) {
169
            btn_pos.setVisibility(View.VISIBLE);
170
        }
171
172
        if (!showPosBtn && showNegBtn) {
173
            btn_neg.setVisibility(View.VISIBLE);
174
        }
175
    }
176
177
    public void show() {
178
        setLayout();
179
        dialog.show();
180
    }
181
182
    public boolean isShowing() {
183
        if (dialog.isShowing()) {
184
            return true;
185
        } else {
186
            return false;
187
        }
188
    }
189
}

BIN
app/src/main/res/drawable-hdpi/update_header.png


BIN
app/src/main/res/drawable-hdpi/update_new_icon.png


BIN
app/src/main/res/drawable-mdpi/update_header.png


BIN
app/src/main/res/drawable-mdpi/update_new_icon.png


BIN
app/src/main/res/drawable-xhdpi/update_header.png


BIN
app/src/main/res/drawable-xhdpi/update_new_icon.png


BIN
app/src/main/res/drawable-xxhdpi/update_header.png


BIN
app/src/main/res/drawable-xxhdpi/update_new_icon.png


BIN
app/src/main/res/drawable-xxxhdpi/update_header.png


BIN
app/src/main/res/drawable-xxxhdpi/update_new_icon.png


+ 11 - 0
app/src/main/res/drawable/update_alert_bottom_shape.xml

@ -0,0 +1,11 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:shape="rectangle">
4
    <!-- 圆角 -->
5
    <corners
6
        android:bottomLeftRadius="8dp"
7
        android:bottomRightRadius="8dp"/>
8
    <!-- 边框颜色 -->
9
    <!-- 填充色 -->
10
    <solid android:color="#FFFFFF" />
11
</shape>

+ 10 - 0
app/src/main/res/drawable/update_alert_left_btn_shape.xml

@ -0,0 +1,10 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:shape="rectangle">
4
    <!-- 圆角 -->
5
    <corners android:radius="4dp" />
6
    <!-- 边框颜色 -->
7
    <stroke android:width="0.6dp" android:color="#DEDEDE" />
8
    <!-- 填充色 -->
9
    <solid android:color="#FFFFFF" />
10
</shape>

+ 8 - 0
app/src/main/res/drawable/update_alert_right_btn_shape.xml

@ -0,0 +1,8 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:shape="rectangle">
4
    <!-- 圆角 -->
5
    <corners android:radius="4dp" />
6
    <!-- 填充色 -->
7
    <solid android:color="#31D9AF" />
8
</shape>

+ 103 - 0
app/src/main/res/layout/view_alterdialog_update.xml

@ -0,0 +1,103 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4
    xmlns:tools="http://schemas.android.com/tools"
5
    android:id="@+id/lLayout_bg"
6
    android:layout_width="272dp"
7
    android:layout_height="wrap_content"
8
    android:orientation="vertical">
9
10
    <androidx.constraintlayout.widget.ConstraintLayout
11
        android:layout_width="match_parent"
12
        android:layout_height="wrap_content">
13
14
        <View
15
            android:layout_width="match_parent"
16
            android:layout_height="50dp"
17
            android:background="@color/white"
18
            app:layout_constraintBottom_toBottomOf="parent" />
19
20
        <ImageView
21
            android:id="@+id/update_header"
22
            android:layout_width="match_parent"
23
            android:layout_height="wrap_content"
24
            android:scaleType="fitXY"
25
            android:src="@drawable/update_header"
26
            app:layout_constraintTop_toTopOf="parent" />
27
    </androidx.constraintlayout.widget.ConstraintLayout>
28
29
30
    <LinearLayout
31
        android:layout_width="match_parent"
32
        android:layout_height="wrap_content"
33
        android:background="@color/white"
34
        android:orientation="vertical">
35
36
        <LinearLayout
37
            android:layout_width="match_parent"
38
            android:layout_height="wrap_content"
39
            android:gravity="center_horizontal"
40
            android:orientation="horizontal"
41
            android:paddingTop="10dp">
42
43
            <TextView
44
                android:id="@+id/txt_title"
45
                android:layout_width="wrap_content"
46
                android:layout_height="wrap_content"
47
                android:textColor="#444444"
48
                android:textSize="15sp"
49
                tools:text="更新提示 3.5.2" />
50
51
            <ImageView
52
                android:layout_width="wrap_content"
53
                android:layout_height="wrap_content"
54
                android:layout_marginLeft="10dp"
55
                android:src="@drawable/update_new_icon" />
56
        </LinearLayout>
57
58
        <TextView
59
            android:id="@+id/txt_msg"
60
            android:layout_width="match_parent"
61
            android:layout_height="wrap_content"
62
            android:layout_marginLeft="18dp"
63
            android:layout_marginTop="12dp"
64
            android:layout_marginRight="18dp"
65
            android:gravity="center|left"
66
            android:textColor="#444444"
67
            android:textSize="13sp"
68
            tools:text="1-新增“聊聊”新能源车主社区版块。可以通过短图文和视频的方式,聊聊你的新能源汽车和生活\n\n2-修改已知BUG" />
69
    </LinearLayout>
70
71
    <LinearLayout
72
        android:layout_width="match_parent"
73
        android:layout_height="wrap_content"
74
        android:background="@drawable/update_alert_bottom_shape"
75
        android:gravity="center_horizontal"
76
        android:orientation="horizontal"
77
        android:paddingTop="30dp"
78
        android:paddingBottom="28dp">
79
80
        <Button
81
            android:id="@+id/btn_neg"
82
            android:layout_width="115dp"
83
            android:layout_height="35dp"
84
            android:layout_marginLeft="5dp"
85
            android:layout_marginRight="5dp"
86
            android:background="@drawable/update_alert_left_btn_shape"
87
            android:textColor="#999999"
88
            android:textSize="13sp"
89
            tools:text="忽略" />
90
91
        <Button
92
            android:id="@+id/btn_pos"
93
            android:layout_width="115dp"
94
            android:layout_height="35dp"
95
            android:layout_marginLeft="5dp"
96
            android:layout_marginRight="5dp"
97
            android:background="@drawable/update_alert_right_btn_shape"
98
            android:textColor="@color/white"
99
            android:textSize="13sp"
100
            tools:text="忽略" />
101
102
    </LinearLayout>
103
</LinearLayout>