Skip to content

Commit 2286e16

Browse files
committed
adding ProgressDialogBox for Downloading data
1 parent 78e0229 commit 2286e16

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/example/ritu/database1app/activity/MainActivity.java

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private class fetchData extends AsyncTask<Void, Void, String> {
8181
@Override
8282
protected void onPreExecute() {
8383
super.onPreExecute();
84+
UIUtil.startProgressDialog(MainActivity.this, "Downloading data....");
8485
}
8586

8687
@Override
@@ -154,6 +155,7 @@ protected String doInBackground(Void... params) {
154155
protected void onPostExecute(String s) {
155156
super.onPostExecute(s);
156157
adapter.notifyDataSetChanged();
158+
UIUtil.stopProgressDialog(MainActivity.this);
157159
}
158160
}
159161

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.example.ritu.database1app.activity;
2+
3+
import android.app.ProgressDialog;
4+
import android.content.Context;
5+
import android.util.Log;
6+
7+
/**
8+
* Created by ritu on 1/9/2018.
9+
*/
10+
//it has reusable code (class UIUtil )
11+
public class UIUtil {
12+
private static ProgressDialog mProgressDialog;
13+
private static Object mObject = new Object();
14+
15+
public static void startProgressDialog(Context context, String message) {
16+
try {
17+
synchronized (mObject) {
18+
if (mProgressDialog == null) {
19+
mProgressDialog = ProgressDialog.show(context, "", message);
20+
mProgressDialog.setIndeterminate(true);
21+
}
22+
}
23+
} catch (Exception e) {
24+
Log.e("Exception", "startProgressDialog ------------------------------: " + e.toString());
25+
e.printStackTrace();
26+
}
27+
}
28+
29+
public static void stopProgressDialog(Context context) {
30+
try {
31+
synchronized (mObject) {
32+
if (mProgressDialog != null && mProgressDialog.isShowing()) {
33+
mProgressDialog.dismiss();
34+
mProgressDialog = null;
35+
}
36+
}
37+
} catch (Exception e) {
38+
e.printStackTrace();
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)