Commit 92beb983161805c7cfbb39321e4c791306fc3520
1 parent
e18ab61a
Exists in
yxb_dev
and in
2 other branches
no message
Showing
16 changed files
with
1235 additions
and
5 deletions
Show diff stats
app/src/main/java/com/shunzhi/parent/AppConfig.java
... | ... | @@ -47,6 +47,7 @@ public class AppConfig { |
47 | 47 | public static String BASE_URL="http://campus.myjxt.com/"; |
48 | 48 | public static String BASE_URL_ORDER="http://parent.myjxt.com/"; |
49 | 49 | public static String BASE_URL_FILE="http://manage.myjxt.com"; |
50 | + public static final String url_version = BASE_URL + "api/Common/AppVersion?appType=3"; | |
50 | 51 | |
51 | 52 | |
52 | 53 | //默认日志保存的路径 |
... | ... | @@ -61,6 +62,7 @@ public class AppConfig { |
61 | 62 | |
62 | 63 | private static AppConfig appConfig = null; |
63 | 64 | private static Context mContext = null; |
65 | + public static String url_apk="http://update.myjxt.com/zh_parent.apk"; | |
64 | 66 | |
65 | 67 | public static AppConfig getAppConfig(Context context) { |
66 | 68 | if (appConfig == null) { | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +package com.shunzhi.parent.api; | |
2 | + | |
3 | +import com.google.gson.JsonObject; | |
4 | + | |
5 | +import io.reactivex.Observable; | |
6 | +import retrofit2.http.GET; | |
7 | + | |
8 | +/** | |
9 | + * Created by ToaHanDong on 2018/3/26. | |
10 | + */ | |
11 | + | |
12 | +public interface IsUpdate { | |
13 | + | |
14 | + @GET("api/Common/AppVersion?appType=4") | |
15 | + Observable<JsonObject> isUpdateVersion(); | |
16 | + | |
17 | +} | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +package com.shunzhi.parent.bean; | |
2 | + | |
3 | +import java.io.Serializable; | |
4 | + | |
5 | +/** | |
6 | + * Created by xf on 2015/9/23. | |
7 | + */ | |
8 | +public class Version implements Serializable { | |
9 | + public String verNo; | |
10 | + public String content; | |
11 | + public String inTime; | |
12 | + | |
13 | +} | |
14 | + | ... | ... |
app/src/main/java/com/shunzhi/parent/manager/UpdateManager.java
0 → 100644
... | ... | @@ -0,0 +1,375 @@ |
1 | +package com.shunzhi.parent.manager; | |
2 | + | |
3 | +import android.app.Dialog; | |
4 | +import android.content.Context; | |
5 | +import android.content.DialogInterface; | |
6 | +import android.content.DialogInterface.OnClickListener; | |
7 | +import android.os.Environment; | |
8 | +import android.os.Handler; | |
9 | +import android.os.Message; | |
10 | +import android.support.v7.app.AlertDialog; | |
11 | +import android.view.LayoutInflater; | |
12 | +import android.view.View; | |
13 | +import android.widget.ProgressBar; | |
14 | +import android.widget.TextView; | |
15 | +import android.widget.Toast; | |
16 | + | |
17 | +import com.google.gson.Gson; | |
18 | +import com.google.gson.JsonObject; | |
19 | +import com.share.mvpsdk.RxManager; | |
20 | +import com.share.mvpsdk.helper.RetrofitCreateHelper; | |
21 | +import com.share.mvpsdk.helper.RxHelper; | |
22 | +import com.share.mvpsdk.utils.ToastUtils; | |
23 | +import com.shunzhi.parent.AppConfig; | |
24 | +import com.shunzhi.parent.R; | |
25 | +import com.shunzhi.parent.api.IsUpdate; | |
26 | +import com.shunzhi.parent.bean.Version; | |
27 | +import com.shunzhi.parent.util.CloseUtils; | |
28 | +import com.shunzhi.parent.util.SystemHelper; | |
29 | +import com.shunzhi.parent.util.Utils; | |
30 | +import com.shunzhi.parent.views.MyVersionDialog; | |
31 | + | |
32 | +import java.io.File; | |
33 | +import java.io.FileOutputStream; | |
34 | +import java.io.IOException; | |
35 | +import java.io.InputStream; | |
36 | +import java.net.HttpURLConnection; | |
37 | +import java.net.MalformedURLException; | |
38 | +import java.net.URL; | |
39 | +import java.text.SimpleDateFormat; | |
40 | +import java.util.HashMap; | |
41 | + | |
42 | +import io.reactivex.functions.Consumer; | |
43 | +import timber.log.Timber; | |
44 | + | |
45 | +public class UpdateManager { | |
46 | + | |
47 | + AlertDialog dialogShowCheckingDialog; | |
48 | + /** | |
49 | + * 是否正在检查更新 | |
50 | + */ | |
51 | + public boolean ischeckingForUpdate = false; | |
52 | + /* 下载中 */ | |
53 | + private static final int DOWNLOAD = 1; | |
54 | + /* 下载结束 */ | |
55 | + private static final int DOWNLOAD_FINISH = 2; | |
56 | + /** | |
57 | + * 是否人为打断检查更新状态 | |
58 | + */ | |
59 | + private boolean isChechingInterrupted = false; | |
60 | + /** | |
61 | + * 结束正在获取更新 | |
62 | + */ | |
63 | + /* 保存解析的XML信息 */ | |
64 | + static HashMap<String, String> mHashMap; | |
65 | + /* 下载保存路径 */ | |
66 | + private String mSavePath; | |
67 | + /* 记录进度条数量 */ | |
68 | + private int progress; | |
69 | + /* 是否取消更新 */ | |
70 | + private static boolean cancelUpdate = false; | |
71 | + | |
72 | + private static Context mContext; | |
73 | + /* 更新进度条 */ | |
74 | + private ProgressBar mProgress; | |
75 | + private TextView mProgressText; | |
76 | + private Dialog mDownloadDialog; | |
77 | + double serviceCode = 1; | |
78 | + int versionCode = 1; | |
79 | + | |
80 | + //mHandler | |
81 | +//region | |
82 | + private Handler mHandler = new Handler() { | |
83 | + public void handleMessage(Message msg) { | |
84 | + switch (msg.what) { | |
85 | + // 正在下载 | |
86 | + case DOWNLOAD: | |
87 | + // 设置进度条位置 | |
88 | + mProgress.setProgress(progress); | |
89 | + mProgressText.setText(progress + "%"); | |
90 | + break; | |
91 | + case DOWNLOAD_FINISH: | |
92 | + mDownloadDialog.dismiss(); | |
93 | + File apkfile = new File(mSavePath, mHashMap.get("name")); | |
94 | + SystemHelper.installAPK(mContext, apkfile.toString()); | |
95 | + break; | |
96 | + default: | |
97 | + break; | |
98 | + } | |
99 | + } | |
100 | + }; | |
101 | + | |
102 | + //endregion | |
103 | + private UpdateManager() { | |
104 | + mHashMap = new HashMap<String, String>(); | |
105 | + mHashMap.put("url", AppConfig.url_apk); | |
106 | + mHashMap.put("name", "XSTApp.apk"); | |
107 | + | |
108 | + } | |
109 | + | |
110 | + public UpdateManager(Context context) { | |
111 | + this.mContext = null; | |
112 | + this.mContext = context; | |
113 | + //获取更新版本和url | |
114 | + mHashMap = new HashMap<String, String>(); | |
115 | + mHashMap.put("url", AppConfig.url_apk); | |
116 | + mHashMap.put("name", "XSTApp.apk"); | |
117 | + | |
118 | + } | |
119 | + | |
120 | + /** | |
121 | + * 检查软件是否有更新版本 | |
122 | + * | |
123 | + * @return | |
124 | + */ | |
125 | + String date = ""; | |
126 | + | |
127 | + /** | |
128 | + * @param shouldInterruptDialogShow 是否显示打断检查更新的对话框 | |
129 | + */ | |
130 | + RxManager rxManager=new RxManager(); | |
131 | + public void isUpdate(final boolean shouldInterruptDialogShow) { | |
132 | + date = new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date()); | |
133 | + // 获取当前软件版本 | |
134 | + if (!ischeckingForUpdate) { | |
135 | + isChechingInterrupted = false; | |
136 | + if (shouldInterruptDialogShow) showCheckingDialog(mContext); | |
137 | + ischeckingForUpdate = true; | |
138 | + versionCode = SystemHelper.getAppVersionCode(mContext); | |
139 | + rxManager.register( RetrofitCreateHelper.getInstance().createApi(IsUpdate.class,AppConfig.BASE_URL) | |
140 | + .isUpdateVersion().compose(RxHelper.<JsonObject>rxSchedulerHelper()).subscribe(new Consumer<JsonObject>() { | |
141 | + @Override | |
142 | + public void accept(JsonObject jsonObject) throws Exception { | |
143 | + try { | |
144 | + Gson gson=new Gson(); | |
145 | + Version version=gson.fromJson(jsonObject.get("data").getAsJsonObject().toString(),Version.class); | |
146 | + serviceCode = Double.parseDouble(version.verNo); | |
147 | + double currentVersion = serviceCode / 100; | |
148 | + Timber.d("66666%s","currentVersion="+currentVersion+"serviceCode="+serviceCode+"versionCode="+versionCode); | |
149 | + if ((serviceCode > versionCode) && ischeckingForUpdate && !isChechingInterrupted) { | |
150 | + showNoticeDialog(currentVersion, version.content, isChechingInterrupted); | |
151 | + } else if (!(serviceCode > versionCode) && shouldInterruptDialogShow && !isChechingInterrupted) { | |
152 | + Toast.makeText(mContext, "已经是最新版本啦!", Toast.LENGTH_SHORT).show(); | |
153 | + mContext = null; | |
154 | + } | |
155 | + | |
156 | + }catch (Exception e){ | |
157 | + e.printStackTrace(); | |
158 | + }finally { | |
159 | + ischeckingForUpdate = false; | |
160 | + } | |
161 | + } | |
162 | + }, new Consumer<Throwable>() { | |
163 | + @Override | |
164 | + public void accept(Throwable throwable) throws Exception { | |
165 | + ToastUtils.showToast("更新失败:"+throwable.toString()); | |
166 | + } | |
167 | + })); | |
168 | + | |
169 | +// Timber.d("sign:%s", Utils.getSignStr()); | |
170 | + /*Ion.with(mContext) | |
171 | + .load(Constants.url_version) | |
172 | + .setHeader("sign", Utils.getSignStr()) | |
173 | + .setTimeout(5000) | |
174 | + .asJsonObject() | |
175 | + .setCallback(new FutureCallback<JsonObject>() { | |
176 | + @Override | |
177 | + public void onCompleted(Exception e, JsonObject result) { | |
178 | + try { | |
179 | + Timber.i("exception : %s",e); | |
180 | + Timber.i("result : %s", result); | |
181 | + if (dialogShowCheckingDialog != null) | |
182 | + dialogShowCheckingDialog.dismiss(); | |
183 | + Gson gson = new Gson(); | |
184 | + String s = gson.toJson(result.getAsJsonObject("data")); | |
185 | + Version serverVersion = gson.fromJson(s, new TypeToken<Version>() { | |
186 | + }.getType()); | |
187 | + serviceCode = Double.parseDouble(serverVersion.verNo); | |
188 | + double currentVersion = serviceCode / 100; | |
189 | + if ((serviceCode > versionCode) && ischeckingForUpdate && !isChechingInterrupted) { | |
190 | + showNoticeDialog(currentVersion, serverVersion.content, isChechingInterrupted); | |
191 | + } else if (!(serviceCode > versionCode) && shouldInterruptDialogShow && !isChechingInterrupted) { | |
192 | + Toast.makeText(mContext, "已经是最新版本啦!", Toast.LENGTH_SHORT).show(); | |
193 | + mContext = null; | |
194 | + } | |
195 | + } catch (Exception ee) { | |
196 | + ee.printStackTrace(); | |
197 | + if (shouldInterruptDialogShow) | |
198 | + Toast.makeText(mContext, "版本检测失败", Toast.LENGTH_LONG).show(); | |
199 | + mContext = null; | |
200 | + } finally { | |
201 | + ischeckingForUpdate = false; | |
202 | + } | |
203 | + } | |
204 | + });*/ | |
205 | + } | |
206 | + } | |
207 | + | |
208 | + | |
209 | + public UpdateManager setContext(Context ctx) { | |
210 | + mContext = ctx; | |
211 | + return this; | |
212 | + } | |
213 | + | |
214 | + public static UpdateManager getInstance() { | |
215 | + | |
216 | + return SingletonHolder.sInstance; | |
217 | + } | |
218 | + | |
219 | + private static class SingletonHolder { | |
220 | + private static final UpdateManager sInstance = new UpdateManager(); | |
221 | + } | |
222 | + | |
223 | + /** | |
224 | + * 显示软件更新对话框 | |
225 | + */ | |
226 | + public void showNoticeDialog(double serviceCode, String content, Boolean isInterrupted) { | |
227 | + final MyVersionDialog dialog = new MyVersionDialog(mContext, "V" + serviceCode, "10.1M", | |
228 | + content, R.style.dialog, new MyVersionDialog.OnCustomDialogListener() { | |
229 | + @Override | |
230 | + public void clickSure() { | |
231 | + showDownloadDialog(); | |
232 | + } | |
233 | + | |
234 | + @Override | |
235 | + public void clickCancel() { | |
236 | + mContext = null; | |
237 | + } | |
238 | + }); | |
239 | + dialog.setCanceledOnTouchOutside(false); | |
240 | + if (!dialog.isShowing()) | |
241 | + dialog.show(); | |
242 | + ischeckingForUpdate = false; | |
243 | + } | |
244 | + | |
245 | + private void showCheckingDialog(Context ctx) { | |
246 | + dialogShowCheckingDialog = Utils.styleDialogBuilder(ctx) | |
247 | + .setMessage("正在检查更新...") | |
248 | + .setTitle("提示") | |
249 | + .setNegativeButton("取消", new OnClickListener() { | |
250 | + @Override | |
251 | + public void onClick(DialogInterface dialog, int which) { | |
252 | + isChechingInterrupted = true; | |
253 | + mContext = null; | |
254 | + dialog.dismiss(); | |
255 | + } | |
256 | + }).create(); | |
257 | + dialogShowCheckingDialog.setCanceledOnTouchOutside(false); | |
258 | + if (!dialogShowCheckingDialog.isShowing()) { | |
259 | + dialogShowCheckingDialog.show(); | |
260 | + } | |
261 | + } | |
262 | + | |
263 | + /** | |
264 | + * 显示软件下载对话框 | |
265 | + */ | |
266 | + private void showDownloadDialog() { | |
267 | + // 构造软件下载对话框 | |
268 | + AlertDialog.Builder builder = Utils.styleDialogBuilder(mContext); | |
269 | + builder.setTitle("更新中"); | |
270 | + // 给下载对话框增加进度条 | |
271 | + final LayoutInflater inflater = LayoutInflater.from(mContext); | |
272 | + View v = inflater.inflate(R.layout.progress_dialog, null); | |
273 | + mProgress = (ProgressBar) v.findViewById(R.id.pbar); | |
274 | + mProgressText = (TextView) v.findViewById(R.id.txt_wait); | |
275 | + builder.setView(v); | |
276 | + // 取消更新 | |
277 | + builder.setNegativeButton("取消", new OnClickListener() { | |
278 | + @Override | |
279 | + public void onClick(DialogInterface dialog, int which) { | |
280 | + dialog.dismiss(); | |
281 | + // 设置取消状态 | |
282 | + File APKfile = new File(mSavePath); | |
283 | + //FileUtil.deleteFile(APKfile, APKfile + "/" + mHashMap.get("name")); | |
284 | + cancelUpdate = true; | |
285 | + } | |
286 | + }); | |
287 | + mDownloadDialog = builder.create(); | |
288 | + mDownloadDialog.setCanceledOnTouchOutside(false); | |
289 | + mDownloadDialog.show(); | |
290 | + // 现在文件 | |
291 | + downloadApk(); | |
292 | + } | |
293 | + | |
294 | + /** | |
295 | + * 下载apk文件 | |
296 | + */ | |
297 | + private void downloadApk() { | |
298 | + // 启动新线程下载软件 | |
299 | + cancelUpdate = false; | |
300 | + downloadApkThread downloadThread = new downloadApkThread(); | |
301 | + downloadThread.start(); | |
302 | + } | |
303 | + | |
304 | + /** | |
305 | + * 下载文件线程 | |
306 | + * | |
307 | + * @author coolszy | |
308 | + * @date 2012-4-26 | |
309 | + * @blog http://blog.92coding.com | |
310 | + */ | |
311 | + private class downloadApkThread extends Thread { | |
312 | + HttpURLConnection conn = null; | |
313 | + InputStream is = null; | |
314 | + FileOutputStream fos = null; | |
315 | + | |
316 | + @Override | |
317 | + public void run() { | |
318 | + //cancelUpdate = false; | |
319 | + try { | |
320 | + // 判断SD卡是否存在,并且是否具有读写权限 | |
321 | + if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { | |
322 | + // 获得存储卡的路径 | |
323 | + String sdpath = Environment.getExternalStorageDirectory() + "/"; | |
324 | + mSavePath = sdpath + "download"; | |
325 | + URL url = new URL(mHashMap.get("url")); | |
326 | + // 创建连接 | |
327 | + conn = (HttpURLConnection) url.openConnection(); | |
328 | + conn.connect(); | |
329 | + // 获取文件大小 | |
330 | + int length = conn.getContentLength();//服务端要设置 content length属性 | |
331 | + // 创建输入流 | |
332 | + is = conn.getInputStream(); | |
333 | + | |
334 | + File file = new File(mSavePath); | |
335 | + // 判断文件目录是否存在 | |
336 | + if (!file.exists()) { | |
337 | + if (!file.mkdir()) file.mkdirs();//创建文件失败,则创建文件夹 | |
338 | + } | |
339 | + File apkFile = new File(mSavePath, mHashMap.get("name")); | |
340 | + fos = new FileOutputStream(apkFile); | |
341 | + int count = 0; | |
342 | + // 缓存 | |
343 | + byte buf[] = new byte[1024]; | |
344 | + // 写入到文件中 | |
345 | + while (!cancelUpdate) { | |
346 | + int numread = is.read(buf); | |
347 | + count += numread; | |
348 | + progress = (int) (((float) count / length) * 100);// 计算进度条位置 | |
349 | + mHandler.sendEmptyMessage(DOWNLOAD);// 更新进度 | |
350 | + if (numread <= 0) { | |
351 | + // 下载完成 | |
352 | + mHandler.sendEmptyMessage(DOWNLOAD_FINISH); | |
353 | + break; | |
354 | + } | |
355 | + // 写入文件 | |
356 | + fos.write(buf, 0, numread); | |
357 | + } // 点击取消就停止下载. | |
358 | + | |
359 | + } | |
360 | + } catch (MalformedURLException e) { | |
361 | + Timber.d(e + ""); | |
362 | + e.printStackTrace(); | |
363 | + } catch (IOException e) { | |
364 | + Timber.d(e + ""); | |
365 | + e.printStackTrace(); | |
366 | + } finally { | |
367 | + conn.disconnect(); | |
368 | + CloseUtils.closeQuietly(fos, is); | |
369 | + } | |
370 | + // 取消下载对话框显示 | |
371 | + Thread.currentThread().interrupt(); | |
372 | + rxManager.unSubscribe(); | |
373 | + } | |
374 | + } | |
375 | +} | ... | ... |
app/src/main/java/com/shunzhi/parent/ui/fragment/MineFragment.java
... | ... | @@ -24,6 +24,7 @@ import com.shunzhi.parent.bean.message.PHMessageSession; |
24 | 24 | import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; |
25 | 25 | import com.shunzhi.parent.contract.mine.MineContract; |
26 | 26 | import com.shunzhi.parent.manager.MessageManager; |
27 | +import com.shunzhi.parent.manager.UpdateManager; | |
27 | 28 | import com.shunzhi.parent.presenter.mine.MinePresenter; |
28 | 29 | import com.shunzhi.parent.ui.activity.LoginAndRegistActivity; |
29 | 30 | import com.shunzhi.parent.ui.activity.MyChildActivity; |
... | ... | @@ -36,8 +37,9 @@ import com.shunzhi.parent.ui.activity.orderdetail.OrderDetailActivity; |
36 | 37 | public class MineFragment extends BaseMVPCompatFragment<LoginAndRegisterContract.LoginPresenter, LoginAndRegisterContract.ILoginModel> |
37 | 38 | implements MineContract.IMineView, View.OnClickListener { |
38 | 39 | |
39 | - LinearLayout childlayout, personinfo, layout_orderDetail, layout_order, layout_cache, layout_about, layout_feedback, top_layout, layout_afterLogin | |
40 | - ,layout_message; | |
40 | + LinearLayout childlayout, personinfo, layout_orderDetail, layout_order, layout_cache, | |
41 | + layout_about, layout_feedback, top_layout, layout_afterLogin | |
42 | + ,layout_message,layout_update; | |
41 | 43 | |
42 | 44 | RoundedImageView user_photo; |
43 | 45 | TextView user_name, user_mobile, tvExit, binding_state,tvMessageCount; |
... | ... | @@ -66,6 +68,9 @@ public class MineFragment extends BaseMVPCompatFragment<LoginAndRegisterContract |
66 | 68 | layout_feedback = view.findViewById(R.id.layout_feedback); |
67 | 69 | tvMessageCount=view.findViewById(R.id.tvMessageCount); |
68 | 70 | layout_message=view.findViewById(R.id.layout_message); |
71 | + layout_update=view.findViewById(R.id.layout_update); | |
72 | + | |
73 | + layout_update.setOnClickListener(this); | |
69 | 74 | layout_message.setOnClickListener(this); |
70 | 75 | layout_about.setOnClickListener(this); |
71 | 76 | layout_feedback.setOnClickListener(this); |
... | ... | @@ -164,6 +169,9 @@ startNewActivity(MesageActivity.class); |
164 | 169 | WebViewActivity.getInstance(getActivity(), AppConfig.BASE_URL_ORDER + "FeedBack.aspx?userid=" + AppConfig.getAppConfig(AppContext.getInstance()).get(AppConfig.USER_ID), -1); |
165 | 170 | |
166 | 171 | break; |
172 | + case R.id.layout_update: | |
173 | + UpdateManager.getInstance().setContext(getContext()).isUpdate(true); | |
174 | + break; | |
167 | 175 | default: |
168 | 176 | break; |
169 | 177 | } | ... | ... |
app/src/main/java/com/shunzhi/parent/ui/fragment/loginandregistfragment/LoginAndRegistFragment.java
... | ... | @@ -146,8 +146,8 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist |
146 | 146 | getActivity().finish(); |
147 | 147 | } else if (type == 1) { |
148 | 148 | PopupWindow popupWindow = new PopupWindow(); |
149 | - popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); | |
150 | - popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | |
149 | + popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); | |
150 | + popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT); | |
151 | 151 | backgroundAlpha(0.5f); |
152 | 152 | View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_view, null); |
153 | 153 | TextView dialogInfo = view.findViewById(R.id.dialog_info); |
... | ... | @@ -294,7 +294,6 @@ public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegist |
294 | 294 | } |
295 | 295 | }; |
296 | 296 | |
297 | - | |
298 | 297 | public void backgroundAlpha(float bgAlpha) { |
299 | 298 | WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes(); |
300 | 299 | lp.alpha = bgAlpha; //0.0-1.0 | ... | ... |
app/src/main/java/com/shunzhi/parent/util/CloseUtils.java
0 → 100644
... | ... | @@ -0,0 +1,33 @@ |
1 | +package com.shunzhi.parent.util; | |
2 | + | |
3 | +import android.support.annotation.Nullable; | |
4 | + | |
5 | +import java.io.Closeable; | |
6 | +import java.io.IOException; | |
7 | + | |
8 | +/** | |
9 | + * Created by zdf on 2016/1/20. | |
10 | + */ | |
11 | +public class CloseUtils { | |
12 | + private CloseUtils() { | |
13 | + } | |
14 | + | |
15 | + /** | |
16 | + * | |
17 | + * @param closeable 所有实现Closeable接口的类的实例(常用有输入、输出流、Cursor等) | |
18 | + * @return 关闭成功 | |
19 | + */ | |
20 | + public static boolean closeQuietly(@Nullable Closeable... closeable) { | |
21 | + if (closeable != null && closeable.length > 0) { | |
22 | + try { | |
23 | + for (Closeable c : closeable) { | |
24 | + if (c != null) c.close(); | |
25 | + } | |
26 | + } catch (IOException e) { | |
27 | + e.printStackTrace(); | |
28 | + return false; | |
29 | + } | |
30 | + } | |
31 | + return true; | |
32 | + } | |
33 | +} | ... | ... |
app/src/main/java/com/shunzhi/parent/util/SystemHelper.java
0 → 100644
... | ... | @@ -0,0 +1,420 @@ |
1 | +/** | |
2 | + * ClassName: MyApp.java | |
3 | + * created on 2013-1-24 | |
4 | + * Copyrights 2013-1-24 hjgang All rights reserved. | |
5 | + * site: http://t.qq.com/hjgang2012 | |
6 | + * email: hjgang@yahoo.cn | |
7 | + */ | |
8 | +package com.shunzhi.parent.util; | |
9 | + | |
10 | +import android.Manifest; | |
11 | +import android.annotation.TargetApi; | |
12 | +import android.app.Activity; | |
13 | +import android.content.ContentResolver; | |
14 | +import android.content.Context; | |
15 | +import android.content.Intent; | |
16 | +import android.content.Intent.ShortcutIconResource; | |
17 | +import android.content.pm.PackageInfo; | |
18 | +import android.content.pm.PackageManager; | |
19 | +import android.database.Cursor; | |
20 | +import android.net.ConnectivityManager; | |
21 | +import android.net.NetworkInfo; | |
22 | +import android.net.NetworkInfo.State; | |
23 | +import android.net.Uri; | |
24 | +import android.os.Build; | |
25 | +import android.support.v4.app.ActivityCompat; | |
26 | +import android.telephony.TelephonyManager; | |
27 | +import android.util.DisplayMetrics; | |
28 | +import android.view.Window; | |
29 | +import android.view.WindowManager; | |
30 | + | |
31 | +import com.shunzhi.parent.R; | |
32 | + | |
33 | +import java.io.File; | |
34 | +import java.sql.Timestamp; | |
35 | +import java.text.ParseException; | |
36 | +import java.text.SimpleDateFormat; | |
37 | +import java.util.Date; | |
38 | + | |
39 | +import timber.log.Timber; | |
40 | + | |
41 | + | |
42 | +/** | |
43 | + * 获取系统信息的工具类 | |
44 | + * @author hjgang | |
45 | + */ | |
46 | +public class SystemHelper { | |
47 | + private SystemHelper() { | |
48 | + } | |
49 | + | |
50 | + /** | |
51 | + * 创建本应用的桌面快捷方式<br/> | |
52 | + * 注意:需要添加权限<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> | |
53 | + * @param | |
54 | + */ | |
55 | + public static void createShortcut(Context context, Class<?> clazz) { | |
56 | + Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); | |
57 | + | |
58 | + //快捷方式的名称 | |
59 | + shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name)); | |
60 | + shortcut.putExtra("duplicate", false); //不允许重复创建 | |
61 | + | |
62 | + Intent localIntent2 = new Intent(context, clazz); | |
63 | + localIntent2.setAction(Intent.ACTION_MAIN); | |
64 | + localIntent2.addCategory(Intent.CATEGORY_LAUNCHER); | |
65 | + | |
66 | + shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, localIntent2);//指定快捷方式要启动的Activity类型 | |
67 | + | |
68 | + //快捷方式的图标 | |
69 | + ShortcutIconResource iconResource = ShortcutIconResource.fromContext(context, R.drawable.logo); | |
70 | + shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); | |
71 | + | |
72 | + context.sendBroadcast(shortcut); | |
73 | + } | |
74 | + | |
75 | + /** | |
76 | + * 字符串转换成date | |
77 | + * @param time | |
78 | + * @return | |
79 | + */ | |
80 | + public static Date getDateTime1(String time) { | |
81 | + Date newtime = null; | |
82 | + SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | |
83 | + try { | |
84 | + if (time != null && !time.equals("0")) { | |
85 | + newtime = sdfDateFormat.parse(time); | |
86 | + } | |
87 | + } catch (Exception err) { | |
88 | + | |
89 | + } | |
90 | + return newtime; | |
91 | + } | |
92 | + | |
93 | + /** | |
94 | + * 将字符串转为 时间戳 | |
95 | + * @param time | |
96 | + * @return | |
97 | + */ | |
98 | + public static String getTimestamp(String time) { | |
99 | + Date newtime = null; | |
100 | + SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | |
101 | + try { | |
102 | + if (time != null && !time.equals("0")) { | |
103 | + newtime = sdfDateFormat.parse(time); | |
104 | + } | |
105 | + } catch (Exception err) { | |
106 | + | |
107 | + } | |
108 | + return newtime.getTime() + ""; | |
109 | + } | |
110 | + | |
111 | + /** | |
112 | + * 将时间戳转为 字符串 | |
113 | + * yyyy-MM-dd HH:mm | |
114 | + * */ | |
115 | + public static String getTimeStr(String time) { | |
116 | + | |
117 | + String newtime = null; | |
118 | + SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | |
119 | + if (time != null && !time.equals("0")) { | |
120 | + newtime = sdfDateFormat.format(new Timestamp(Long.parseLong(time))); | |
121 | + } | |
122 | + return newtime; | |
123 | + } | |
124 | + | |
125 | + /** | |
126 | + * 将时间戳转为 字符串 | |
127 | + * yyyy-MM-dd | |
128 | + * */ | |
129 | + public static String getTimeStr3(String time) { | |
130 | + String newtime = null; | |
131 | + SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd"); | |
132 | + if (time != null && !time.equals("0")) { | |
133 | + newtime = sdfDateFormat.format(new Date(Long.parseLong(time) * 1000)); | |
134 | + } | |
135 | + return newtime; | |
136 | + } | |
137 | + | |
138 | + // 将字符串转为时间戳 | |
139 | + public static String getTime(String time) { | |
140 | + SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日hh时mm分"); | |
141 | + Date date = null; | |
142 | + if (time == null || "".equals(time) || "null".equals(time)) { | |
143 | + return "0"; | |
144 | + } | |
145 | + if (time.contains("年")) { | |
146 | + int year = Integer.parseInt(time.substring(0, time.indexOf("年"))); | |
147 | + if (year <= 1970) { | |
148 | + return "0"; | |
149 | + } | |
150 | + } | |
151 | + try { | |
152 | + date = format.parse(time); | |
153 | + } catch (ParseException e) { | |
154 | + e.printStackTrace(); | |
155 | + return null; | |
156 | + } | |
157 | + return date.getTime() / 1000 + ""; | |
158 | + } | |
159 | + | |
160 | + // 将字符串转为时间戳 | |
161 | + public static String getTime2(String time) { | |
162 | + SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日"); | |
163 | + Date date = null; | |
164 | + if (time == null || "".equals(time) || "null".equals(time)) { | |
165 | + return "0"; | |
166 | + } | |
167 | + int year = Integer.parseInt(time.substring(0, time.indexOf("年"))); | |
168 | + if (year <= 1970) { | |
169 | + return "0"; | |
170 | + } | |
171 | + try { | |
172 | + date = format.parse(time); | |
173 | + } catch (ParseException e) { | |
174 | + e.printStackTrace(); | |
175 | + } | |
176 | + return date.getTime() / 1000 + ""; | |
177 | + } | |
178 | + | |
179 | + /** | |
180 | + * @author LuoB. | |
181 | + * @param oldTime 较小的时间 | |
182 | + * @param newTime 较大的时间 (如果为空 默认当前时间 ,表示和当前时间相比) | |
183 | + * @return -1 :同一天. 0:昨天 . 1 :至少是前天. | |
184 | + * @throws ParseException 转换异常 | |
185 | + */ | |
186 | + public static int isYeaterday(Date oldTime, Date newTime) throws ParseException { | |
187 | + if (newTime == null) { | |
188 | + newTime = new Date(); | |
189 | + } | |
190 | + //将下面的 理解成 yyyy-MM-dd 00:00:00 更好理解点 | |
191 | + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | |
192 | + String todayStr = format.format(newTime); | |
193 | + Date today = format.parse(todayStr); | |
194 | + //昨天 86400000=24*60*60*1000 一天 | |
195 | + if ((today.getTime() - oldTime.getTime()) > 0 && (today.getTime() - oldTime.getTime()) <= 86400000) { | |
196 | + return 0; | |
197 | + } else if ((today.getTime() - oldTime.getTime()) <= 0) { //至少是今天 | |
198 | + return -1; | |
199 | + } else { //至少是前天 | |
200 | + return 1; | |
201 | + } | |
202 | + } | |
203 | + | |
204 | + /** | |
205 | + * 检查是否已经创建了桌面快捷方式<br/> | |
206 | + * 注意:需要添加权限<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/> | |
207 | + * @param context | |
208 | + * @return | |
209 | + */ | |
210 | + public static boolean hasShortCut(Context context) { | |
211 | + String url = ""; | |
212 | + if (Build.VERSION.SDK_INT < 8) { | |
213 | + url = "content://com.android.launcher.settings/favorites?notify=true"; | |
214 | + } else { | |
215 | + url = "content://com.android.launcher2.settings/favorites?notify=true"; | |
216 | + } | |
217 | + ContentResolver resolver = context.getContentResolver(); | |
218 | + Cursor cursor = resolver.query(Uri.parse(url), null, "title=?", | |
219 | + new String[]{context.getString(R.string.app_name)}, null); | |
220 | + | |
221 | + if (cursor != null && cursor.moveToFirst()) { | |
222 | + cursor.close(); | |
223 | + return true; | |
224 | + } | |
225 | + | |
226 | + return false; | |
227 | + } | |
228 | + | |
229 | + /** | |
230 | + * 获取当前机器的屏幕信息对象<br/> | |
231 | + * 另外:通过android.os.Build类可以获取当前系统的相关信息 | |
232 | + * | |
233 | + * @param context | |
234 | + * @return | |
235 | + */ | |
236 | + public static DisplayMetrics getScreenInfo(Context context) { | |
237 | + WindowManager windowManager = (WindowManager) context | |
238 | + .getSystemService(Context.WINDOW_SERVICE); | |
239 | + DisplayMetrics dm = new DisplayMetrics(); | |
240 | + windowManager.getDefaultDisplay().getMetrics(dm); | |
241 | + // dm.widthPixels;//寬度 | |
242 | + // dm.heightPixels; //高度 | |
243 | + // dm.density; //密度 | |
244 | + return dm; | |
245 | + } | |
246 | + | |
247 | + public static int dip2px(Context context, double dipValue) { | |
248 | + final float scale = context.getResources().getDisplayMetrics().density; | |
249 | + return (int) (dipValue * scale + 0.5f); | |
250 | + } | |
251 | + | |
252 | + public static int px2dip(Context context, double pxValue) { | |
253 | + final float scale = context.getResources().getDisplayMetrics().density; | |
254 | + return (int) (pxValue / scale + 0.5f); | |
255 | + } | |
256 | + | |
257 | + /** | |
258 | + * 获取手机号<br/> | |
259 | + * 注意:需要添加权限<uses-permission | |
260 | + * android:name="android.permission.READ_PHONE_STATE"/>。另外很多手机不能获取到当前手机号 | |
261 | + * | |
262 | + * @param context | |
263 | + * @return | |
264 | + */ | |
265 | + public static String getMobileNumber(Context context) { | |
266 | + TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); | |
267 | + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { | |
268 | + // TODO: Consider calling | |
269 | + // ActivityCompat#requestPermissions | |
270 | + // here to request the missing permissions, and then overriding | |
271 | + // public void onRequestPermissionsResult(int requestCode, String[] permissions, | |
272 | + // int[] grantResults) | |
273 | + // to handle the case where the user grants the permission. See the documentation | |
274 | + // for ActivityCompat#requestPermissions for more details. | |
275 | + } | |
276 | + String deviceid = tm.getDeviceId();//获取智能设备唯一编号 | |
277 | + String te1 = tm.getLine1Number();//获取本机号码 | |
278 | + String imei = tm.getSimSerialNumber();//获得SIM卡的序号 | |
279 | + String imsi = tm.getSubscriberId();//得到用户Id | |
280 | + return tm.getLine1Number(); | |
281 | + } | |
282 | + | |
283 | + /** | |
284 | + * 检测当前的网络连接是否可用<br/> | |
285 | + * 注意:需要添加权限<uses-permission | |
286 | + * android:name="android.permission.ACCESS_NETWORK_STATE"/> | |
287 | + * | |
288 | + * @param context | |
289 | + * @return | |
290 | + */ | |
291 | + public static boolean isConnected(Context context) { | |
292 | + boolean flag = false; | |
293 | + try { | |
294 | + ConnectivityManager connManager = (ConnectivityManager) context | |
295 | + .getSystemService(Context.CONNECTIVITY_SERVICE); | |
296 | + if (null != connManager) { | |
297 | + NetworkInfo info = connManager.getActiveNetworkInfo(); | |
298 | + if (null != info && info.isAvailable()) { | |
299 | + flag = true; | |
300 | + } | |
301 | + } | |
302 | + } catch (Exception e) { | |
303 | + Timber.d(e + ""); | |
304 | + } | |
305 | + return flag; | |
306 | + } | |
307 | + | |
308 | + /** | |
309 | + * 检测当前网络连接的类型<br/> | |
310 | + * 注意:需要添加权限<uses-permission | |
311 | + * android:name="android.permission.ACCESS_NETWORK_STATE"/> | |
312 | + * | |
313 | + * @param context | |
314 | + * @return 返回0代表GPRS网络;返回1,代表WIFI网络;返回-1代表网络不可用 | |
315 | + */ | |
316 | + public static int getNetworkType(Context context) { | |
317 | + int code = -1; | |
318 | + try { | |
319 | + ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
320 | + if (null != connManager) { | |
321 | + State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); | |
322 | + if (State.CONNECTED == state) { | |
323 | + code = ConnectivityManager.TYPE_WIFI; | |
324 | + } else { | |
325 | + state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); | |
326 | + if (State.CONNECTED == state) { | |
327 | + code = ConnectivityManager.TYPE_MOBILE; | |
328 | + } | |
329 | + } | |
330 | + } | |
331 | + } catch (Exception e) { | |
332 | + Timber.d(e + ""); | |
333 | + } | |
334 | + return code; | |
335 | + } | |
336 | + | |
337 | + /** | |
338 | + * 返回当前程序版本代码,如:1 | |
339 | + * @param context | |
340 | + * @return 当前程序版本代码 | |
341 | + */ | |
342 | + public static int getAppVersionCode(Context context) { | |
343 | + int versionCode = -1; | |
344 | + try { | |
345 | + PackageManager pm = context.getApplicationContext().getPackageManager(); | |
346 | + PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); | |
347 | + versionCode = pi.versionCode; | |
348 | + | |
349 | + } catch (Exception e) { | |
350 | + Timber.d("66666%s" ,e.toString()+ ""); | |
351 | + } | |
352 | + return versionCode; | |
353 | + } | |
354 | + | |
355 | + /** | |
356 | + * 返回当前程序版本名,如:1.0.1 | |
357 | + * | |
358 | + * @param context | |
359 | + * @return 当前程序版本名 | |
360 | + */ | |
361 | + public static String getAppVersionName(Context context) { | |
362 | + String versionName = ""; | |
363 | + try { | |
364 | + PackageManager pm = context.getPackageManager(); | |
365 | + PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); | |
366 | + versionName = pi.versionName; | |
367 | + | |
368 | + } catch (Exception e) { | |
369 | + e.printStackTrace(); | |
370 | + } | |
371 | + return versionName; | |
372 | + } | |
373 | + | |
374 | + /** | |
375 | + * 安装指定的APK文件,主要用于本应用程序的更新 | |
376 | + * | |
377 | + * @param context | |
378 | + * @param apk | |
379 | + * apk文件的全路径名 | |
380 | + */ | |
381 | + public static void installAPK(Context context, String apk) { | |
382 | + Intent intent = new Intent(Intent.ACTION_VIEW); | |
383 | + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
384 | + intent.setDataAndType(Uri.fromFile(new File(apk)), "application/vnd.android.package-archive"); | |
385 | + context.startActivity(intent); | |
386 | + android.os.Process.killProcess(android.os.Process.myPid()); | |
387 | + } | |
388 | + | |
389 | + public static void remoteAPK(Context context) { | |
390 | + Uri packageURI = Uri.parse("package:net.shunzhi"); | |
391 | + Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI); | |
392 | + context.startActivity(uninstallIntent); | |
393 | + } | |
394 | + | |
395 | +// public static void setSystemBar(Context context, boolean on, int color) { | |
396 | +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | |
397 | +// SystemHelper.setTranslucentStatus(context, on); | |
398 | +// SystemBarTintManager mTintManager = new SystemBarTintManager((Activity) context); | |
399 | +// mTintManager.setStatusBarTintEnabled(true); | |
400 | +// //mTintManager.setNavigationBarTintEnabled(true); | |
401 | +// mTintManager.setStatusBarTintResource(color); | |
402 | +// | |
403 | +// //SystemBarTintManager.SystemBarConfig config = mTintManager.getConfig(); | |
404 | +// //listViewDrawer.setPadding(0, config.getPixelInsetTop(true), 0, config.getPixelInsetBottom()); | |
405 | +// } | |
406 | +// } | |
407 | + | |
408 | + @TargetApi(19) | |
409 | + public static void setTranslucentStatus(Context context, boolean on) { | |
410 | + Window win = ((Activity) context).getWindow(); | |
411 | + WindowManager.LayoutParams winParams = win.getAttributes(); | |
412 | + final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; | |
413 | + if (on) { | |
414 | + winParams.flags |= bits; | |
415 | + } else { | |
416 | + winParams.flags &= ~bits; | |
417 | + } | |
418 | + win.setAttributes(winParams); | |
419 | + } | |
420 | +} | ... | ... |
app/src/main/java/com/shunzhi/parent/util/Utils.java
1 | 1 | package com.shunzhi.parent.util; |
2 | 2 | |
3 | +import android.content.Context; | |
4 | +import android.support.v7.app.AlertDialog; | |
5 | + | |
6 | +import com.shunzhi.parent.R; | |
7 | + | |
3 | 8 | public class Utils { |
4 | 9 | private Utils() {} |
5 | 10 | |
... | ... | @@ -33,4 +38,8 @@ public class Utils { |
33 | 38 | return ""; |
34 | 39 | } |
35 | 40 | |
41 | + public static AlertDialog.Builder styleDialogBuilder(Context context) { | |
42 | + return new AlertDialog.Builder(context, R.style.AlertDialogCustom); | |
43 | + } | |
44 | + | |
36 | 45 | } | ... | ... |
app/src/main/java/com/shunzhi/parent/views/MyVersionDialog.java
0 → 100644
... | ... | @@ -0,0 +1,94 @@ |
1 | +package com.shunzhi.parent.views; | |
2 | +import android.app.Dialog; | |
3 | +import android.content.Context; | |
4 | +import android.content.res.Resources; | |
5 | +import android.os.Bundle; | |
6 | +import android.text.method.ScrollingMovementMethod; | |
7 | +import android.util.DisplayMetrics; | |
8 | +import android.view.Gravity; | |
9 | +import android.view.View; | |
10 | +import android.view.Window; | |
11 | +import android.view.WindowManager; | |
12 | +import android.widget.Button; | |
13 | +import android.widget.TextView; | |
14 | + | |
15 | +import com.shunzhi.parent.R; | |
16 | + | |
17 | + | |
18 | +/** | |
19 | + * 自定义dialog | |
20 | + * @author Mr.Xu | |
21 | + * | |
22 | + */ | |
23 | +public class MyVersionDialog extends Dialog { | |
24 | + //定义回调事件,用于dialog的点击事件 | |
25 | + public interface OnCustomDialogListener{ | |
26 | + public void clickSure(); | |
27 | + public void clickCancel(); | |
28 | + } | |
29 | + | |
30 | + private OnCustomDialogListener customDialogListener; | |
31 | + String version = "",size="",content =""; | |
32 | + public MyVersionDialog(Context context, String pVerion, String pSize, String pContent, int style, OnCustomDialogListener customDialogListener) { | |
33 | + super(context, style); | |
34 | + this.customDialogListener = customDialogListener; | |
35 | + version = pVerion; | |
36 | + size = pSize; | |
37 | + content = pContent; | |
38 | + Window window = getWindow(); | |
39 | + WindowManager.LayoutParams params = window.getAttributes(); | |
40 | + //set width,height by density and gravity | |
41 | + float density = getDensity(context); | |
42 | + params.width = (int) (300*density); | |
43 | + params.height = (int) (90*density); | |
44 | + params.gravity = Gravity.CENTER; | |
45 | + | |
46 | + | |
47 | + //WindowManager.LayoutParams p = getWindow().getAttributes(); //获取对话框当前的参数值 | |
48 | + //Display d = window.getDefaultDisplay(); //为获取屏幕宽、高 | |
49 | + //p.height = (int) (d.getHeight() * 0.6); //高度设置为屏幕的0.6 | |
50 | + //p.width = (int) (d.getWidth() * 0.95); //宽度设置为屏幕的0.95 | |
51 | + | |
52 | + window.setAttributes(params); | |
53 | + | |
54 | + } | |
55 | + private float getDensity(Context context) { | |
56 | + Resources resources = context.getResources(); | |
57 | + DisplayMetrics dm = resources.getDisplayMetrics(); | |
58 | + return dm.density; | |
59 | + } | |
60 | + @Override | |
61 | + protected void onCreate(Bundle savedInstanceState) { | |
62 | + super.onCreate(savedInstanceState); | |
63 | + setContentView(R.layout.myversiondialog); | |
64 | + Button clickBtn = (Button) findViewById(R.id.btnSure); | |
65 | + clickBtn.setOnClickListener(clickListener); | |
66 | + Button clearBtn = (Button) findViewById(R.id.btnCancel); | |
67 | + clearBtn.setOnClickListener(clearListener); | |
68 | + | |
69 | + TextView txtVersionNum = (TextView) findViewById(R.id.txtVersionNum); | |
70 | + txtVersionNum.setText(version); | |
71 | + | |
72 | + TextView txtSizeNum = (TextView) findViewById(R.id.txtSizeNum); | |
73 | + txtSizeNum.setText(size); | |
74 | + | |
75 | + TextView txtContent = (TextView) findViewById(R.id.txtContent); | |
76 | + txtContent.setText(content); | |
77 | + txtContent.setMovementMethod(ScrollingMovementMethod.getInstance()) ; | |
78 | + } | |
79 | + | |
80 | + private View.OnClickListener clickListener = new View.OnClickListener() { | |
81 | + @Override | |
82 | + public void onClick(View v) { | |
83 | + customDialogListener.clickSure(); | |
84 | + MyVersionDialog.this.dismiss(); | |
85 | + } | |
86 | + }; | |
87 | + private View.OnClickListener clearListener = new View.OnClickListener() { | |
88 | + @Override | |
89 | + public void onClick(View v) { | |
90 | + customDialogListener.clickCancel(); | |
91 | + MyVersionDialog.this.dismiss(); | |
92 | + } | |
93 | + }; | |
94 | +} | ... | ... |
6.55 KB
app/src/main/res/layout/fragment_mine.xml
... | ... | @@ -272,6 +272,38 @@ |
272 | 272 | android:background="@color/bottomline" /> |
273 | 273 | |
274 | 274 | <LinearLayout |
275 | + android:id="@+id/layout_update" | |
276 | + android:layout_width="match_parent" | |
277 | + android:layout_height="?android:actionBarSize" | |
278 | + android:gravity="center_vertical" | |
279 | + | |
280 | + > | |
281 | + | |
282 | + <TextView | |
283 | + android:layout_width="25dp" | |
284 | + android:layout_height="25dp" | |
285 | + android:layout_marginLeft="15dp" | |
286 | + android:layout_marginRight="30dp" | |
287 | + android:background="@drawable/update" /> | |
288 | + | |
289 | + <TextView | |
290 | + android:layout_width="wrap_content" | |
291 | + android:layout_height="wrap_content" | |
292 | + android:layout_gravity="center_vertical" | |
293 | + android:layout_weight="1" | |
294 | + android:text="版本更新" | |
295 | + android:textSize="@dimen/txtsize_title" /> | |
296 | + | |
297 | + </LinearLayout> | |
298 | + | |
299 | + <TextView | |
300 | + android:layout_width="match_parent" | |
301 | + android:layout_height="0.5dp" | |
302 | + android:layout_marginLeft="15dp" | |
303 | + android:layout_marginRight="15dp" | |
304 | + android:background="@color/bottomline" /> | |
305 | + | |
306 | + <LinearLayout | |
275 | 307 | android:id="@+id/layout_cache" |
276 | 308 | android:layout_width="match_parent" |
277 | 309 | android:layout_height="?android:actionBarSize" | ... | ... |
app/src/main/res/layout/fragment_start.xml
... | ... | @@ -0,0 +1,180 @@ |
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
3 | + android:id="@+id/layoutRoot" | |
4 | + android:layout_width="250dp" | |
5 | + android:layout_height="wrap_content" | |
6 | + android:background="@drawable/shape_radius8_whit" | |
7 | + android:orientation="vertical" | |
8 | + android:windowIsFloating="true"> | |
9 | + | |
10 | + | |
11 | + <RelativeLayout | |
12 | + android:id="@+id/layoutTitle" | |
13 | + android:layout_width="fill_parent" | |
14 | + android:layout_height="50dp"> | |
15 | + | |
16 | + <TextView | |
17 | + android:id="@+id/txtTitle" | |
18 | + android:layout_width="wrap_content" | |
19 | + android:layout_height="wrap_content" | |
20 | + android:layout_centerInParent="true" | |
21 | + android:text="发现新版本" | |
22 | + android:textColor="@color/textColor" | |
23 | + android:textSize="@dimen/textSize18" /> | |
24 | + | |
25 | + <View | |
26 | + android:layout_width="fill_parent" | |
27 | + android:layout_height="1dp" | |
28 | + android:layout_alignParentBottom="true" | |
29 | + android:layout_alignParentLeft="true" | |
30 | + android:layout_alignParentStart="false" | |
31 | + android:background="@color/textColor" /> | |
32 | + | |
33 | + </RelativeLayout> | |
34 | + | |
35 | + <LinearLayout | |
36 | + android:id="@+id/layoutContent" | |
37 | + android:layout_width="fill_parent" | |
38 | + android:layout_height="wrap_content" | |
39 | + android:orientation="vertical" | |
40 | + android:padding="10dp"> | |
41 | + | |
42 | + | |
43 | + <RelativeLayout | |
44 | + android:id="@+id/layoutVersion" | |
45 | + android:layout_width="match_parent" | |
46 | + android:layout_height="20dp"> | |
47 | + | |
48 | + <TextView | |
49 | + android:id="@+id/txtVersion" | |
50 | + android:layout_width="wrap_content" | |
51 | + android:layout_height="wrap_content" | |
52 | + android:layout_alignParentLeft="true" | |
53 | + android:layout_centerVertical="true" | |
54 | + android:text="新版本:" | |
55 | + android:textColor="@color/textColor" | |
56 | + android:textSize="@dimen/size_dp_14" /> | |
57 | + | |
58 | + <TextView | |
59 | + android:id="@+id/txtVersionNum" | |
60 | + android:layout_width="wrap_content" | |
61 | + android:layout_height="wrap_content" | |
62 | + android:layout_centerVertical="true" | |
63 | + android:layout_toRightOf="@+id/txtVersion" | |
64 | + android:text="V1.1.1" | |
65 | + android:textColor="@color/textColor" | |
66 | + android:textSize="@dimen/size_dp_14" /> | |
67 | + </RelativeLayout> | |
68 | + | |
69 | + <RelativeLayout | |
70 | + android:visibility="gone" | |
71 | + android:id="@+id/layoutSize" | |
72 | + android:layout_width="match_parent" | |
73 | + android:layout_height="20dp"> | |
74 | + | |
75 | + <TextView | |
76 | + android:id="@+id/txtSize" | |
77 | + android:layout_width="wrap_content" | |
78 | + android:layout_height="wrap_content" | |
79 | + android:layout_alignParentLeft="true" | |
80 | + android:layout_centerVertical="true" | |
81 | + android:text="新版本大小:" | |
82 | + android:textColor="@color/textColor" | |
83 | + android:textSize="@dimen/size_dp_14" /> | |
84 | + | |
85 | + <TextView | |
86 | + android:id="@+id/txtSizeNum" | |
87 | + android:layout_width="wrap_content" | |
88 | + android:layout_height="wrap_content" | |
89 | + android:layout_centerVertical="true" | |
90 | + android:layout_toRightOf="@+id/txtSize" | |
91 | + android:text="24.86M" | |
92 | + android:textColor="@color/textColor" | |
93 | + android:textSize="@dimen/size_dp_14" /> | |
94 | + </RelativeLayout> | |
95 | + | |
96 | + <TextView | |
97 | + android:id="@+id/txtUpdate" | |
98 | + android:layout_width="wrap_content" | |
99 | + android:layout_height="wrap_content" | |
100 | + android:layout_below="@+id/dlgTtile" | |
101 | + android:layout_centerHorizontal="true" | |
102 | + android:text="更新内容" | |
103 | + android:textColor="@color/textColor" | |
104 | + android:textSize="@dimen/size_dp_14" /> | |
105 | + | |
106 | + <TextView | |
107 | + android:id="@+id/txtContent" | |
108 | + android:layout_width="fill_parent" | |
109 | + android:layout_height="wrap_content" | |
110 | + android:layout_below="@+id/dlgTtile" | |
111 | + android:layout_centerHorizontal="true" | |
112 | + android:layout_marginTop="5dp" | |
113 | + android:maxHeight="100dp" | |
114 | + android:maxLines="4" | |
115 | + android:scrollbars="vertical" | |
116 | + android:text="这是确定消息" | |
117 | + android:textColor="@color/textColor" | |
118 | + android:textSize="@dimen/size_dp_14" /> | |
119 | + | |
120 | + </LinearLayout> | |
121 | + | |
122 | + <RelativeLayout | |
123 | + android:id="@+id/layoutBottom" | |
124 | + android:layout_width="fill_parent" | |
125 | + android:layout_height="35dp" | |
126 | + android:layout_marginBottom="10dp"> | |
127 | + | |
128 | + <Button | |
129 | + android:id="@+id/btnSure" | |
130 | + android:layout_width="wrap_content" | |
131 | + android:layout_height="wrap_content" | |
132 | + android:layout_centerVertical="true" | |
133 | + android:layout_marginRight="10dp" | |
134 | + android:layout_toLeftOf="@+id/line2" | |
135 | + android:layout_weight="1" | |
136 | + android:background="@color/xueqing_blue" | |
137 | + android:gravity="center" | |
138 | + android:paddingBottom="5dp" | |
139 | + android:paddingLeft="16dp" | |
140 | + android:paddingRight="16dp" | |
141 | + android:paddingTop="5dp" | |
142 | + android:text="立即更新" | |
143 | + android:textColor="@color/white" | |
144 | + android:textSize="@dimen/size_dp_14" /> | |
145 | + | |
146 | + <Button | |
147 | + android:id="@+id/btnCancel" | |
148 | + android:layout_width="wrap_content" | |
149 | + android:layout_height="wrap_content" | |
150 | + android:layout_alignParentBottom="false" | |
151 | + android:layout_alignParentEnd="false" | |
152 | + android:layout_alignParentRight="false" | |
153 | + android:layout_centerVertical="true" | |
154 | + android:layout_marginLeft="10dp" | |
155 | + android:layout_toRightOf="@+id/line2" | |
156 | + android:layout_weight="1" | |
157 | + android:background="@color/textBlue" | |
158 | + android:gravity="center" | |
159 | + android:paddingBottom="5dp" | |
160 | + android:paddingLeft="16dp" | |
161 | + android:paddingRight="16dp" | |
162 | + android:paddingTop="5dp" | |
163 | + android:text="以后再说" | |
164 | + android:textColor="@color/white" | |
165 | + android:textSize="@dimen/size_dp_14" /> | |
166 | + | |
167 | + <View | |
168 | + android:id="@+id/line2" | |
169 | + android:layout_width="0dp" | |
170 | + android:layout_height="50dp" | |
171 | + android:layout_alignParentTop="true" | |
172 | + android:layout_centerHorizontal="true" | |
173 | + android:layout_centerVertical="true" | |
174 | + android:layout_weight="0" | |
175 | + android:background="@color/gray" /> | |
176 | + | |
177 | + </RelativeLayout> | |
178 | + | |
179 | + | |
180 | +</LinearLayout> | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
3 | + android:layout_width="fill_parent" | |
4 | + android:layout_height="fill_parent" | |
5 | + android:layout_gravity="center" | |
6 | + android:gravity="center" | |
7 | + android:orientation="vertical"> | |
8 | + <ProgressBar | |
9 | + android:id="@+id/pbar" | |
10 | + style="?android:attr/progressBarStyleHorizontal" | |
11 | + android:layout_width="300dp" | |
12 | + android:layout_height="wrap_content" | |
13 | + android:max="100" | |
14 | + android:progress="0" /> | |
15 | + | |
16 | + <TextView | |
17 | + android:id="@+id/txt_wait" | |
18 | + android:layout_width="wrap_content" | |
19 | + android:layout_height="wrap_content" | |
20 | + android:layout_gravity="center" | |
21 | + android:layout_marginTop="8.0dip" | |
22 | + android:focusable="false" | |
23 | + android:singleLine="true" | |
24 | + android:text="加载中..." | |
25 | + android:textColor="@color/textColor" | |
26 | + android:textSize="12.0sp" /> | |
27 | + | |
28 | +</LinearLayout> | ... | ... |
app/src/main/res/values/styles.xml
... | ... | @@ -8,6 +8,24 @@ |
8 | 8 | <item name="colorAccent">@color/colorAccent</item> |
9 | 9 | </style> |
10 | 10 | |
11 | + <style name="dialog" parent="Theme.AppCompat.Light.Dialog.Alert"> | |
12 | + <item name="colorPrimary">@color/colorPrimary</item> | |
13 | + <item name="colorAccent">@color/colorAccent</item> | |
14 | + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
15 | + <item name="android:windowFrame">@null</item> | |
16 | + <item name="android:windowIsFloating">true</item> | |
17 | + <item name="android:windowIsTranslucent">false</item> | |
18 | + <item name="android:windowNoTitle">true</item> | |
19 | + <item name="android:background">@android:color/transparent</item> | |
20 | + <item name="android:windowBackground">@android:color/transparent</item> | |
21 | + <item name="android:backgroundDimEnabled">true</item> | |
22 | + </style> | |
23 | + | |
24 | + <style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert"> | |
25 | + <item name="colorPrimary">@color/colorPrimary</item> | |
26 | + <item name="colorAccent">@color/colorAccent</item> | |
27 | + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
28 | + </style> | |
11 | 29 | |
12 | 30 | <style name="TextView_Wrap_16"> |
13 | 31 | <item name="android:layout_width">wrap_content</item> | ... | ... |