01 |
< style name = "CustomDialog" parent = "@android:style/Theme.Dialog" > |
02 |
< item name = "android:windowFrame" >@null</ item > |
03 |
< item name = "android:windowIsFloating" >true</ item > |
04 |
< item name = "android:windowContentOverlay" >@null</ item > |
05 |
< item name = "android:windowAnimationStyle" >@android:style/Animation.Dialog</ item > |
06 |
< item name = "android:windowSoftInputMode" >stateUnspecified|adjustPan</ item > |
07 |
</ style > |
08 |
|
09 |
< style name = "CustomProgressDialog" parent = "@style/CustomDialog" > |
10 |
< item name = "android:windowBackground" >@android:color/transparent</ item > |
11 |
< item name = "android:windowNoTitle" >true</ item > |
12 |
</ style > |
01 |
<? xml version = "1.0" encoding = "utf-8" ?> |
02 |
< LinearLayout |
03 |
xmlns:android = "http://schemas.android.com/apk/res/android" |
04 |
android:layout_width = "fill_parent" |
05 |
android:layout_height = "fill_parent" |
06 |
android:orientation = "horizontal" > |
07 |
< ImageView |
08 |
android:id = "@+id/loadingImageView" |
09 |
android:layout_width = "wrap_content" |
10 |
android:layout_height = "wrap_content" |
11 |
android:background = "@anim/progress_round" /> |
12 |
< TextView |
13 |
android:id = "@+id/id_tv_loadingmsg" |
14 |
android:layout_width = "wrap_content" |
15 |
android:layout_height = "wrap_content" |
16 |
android:layout_gravity = "center_vertical" |
17 |
android:textSize = "20dp" /> |
18 |
</ LinearLayout > |
01 |
<? xml version = "1.0" encoding = "utf-8" ?> |
02 |
< animation-list |
03 |
xmlns:android = "http://schemas.android.com/apk/res/android" |
04 |
android:oneshot = "false" > |
05 |
< item android:drawable = "@drawable/progress_1" android:duration = "200" /> |
06 |
< item android:drawable = "@drawable/progress_2" android:duration = "200" /> |
07 |
< item android:drawable = "@drawable/progress_3" android:duration = "200" /> |
08 |
< item android:drawable = "@drawable/progress_4" android:duration = "200" /> |
09 |
< item android:drawable = "@drawable/progress_5" android:duration = "200" /> |
10 |
< item android:drawable = "@drawable/progress_6" android:duration = "200" /> |
11 |
< item android:drawable = "@drawable/progress_7" android:duration = "200" /> |
12 |
< item android:drawable = "@drawable/progress_8" android:duration = "200" /> |
13 |
</ animation-list > |
01 |
/************************************************************************************** |
02 |
* [Project] |
03 |
* MyProgressDialog |
04 |
* [Package] |
05 |
* com.lxd.widgets |
06 |
* [FileName] |
07 |
* CustomProgressDialog.java |
08 |
* [Copyright] |
09 |
* Copyright 2012 LXD All Rights Reserved. |
10 |
* [History] |
11 |
* Version Date Author Record |
12 |
*-------------------------------------------------------------------------------------- |
13 |
* 1.0.0 2012-4-27 lxd ([email protected]) Create |
14 |
**************************************************************************************/ |
15 |
|
16 |
package com.lxd.widgets; |
17 |
|
18 |
|
19 |
import com.lxd.activity.R; |
20 |
|
21 |
import android.app.Dialog; |
22 |
import android.content.Context; |
23 |
import android.graphics.drawable.AnimationDrawable; |
24 |
import android.view.Gravity; |
25 |
import android.widget.ImageView; |
26 |
import android.widget.TextView; |
27 |
|
28 |
|
29 |
/******************************************************************** |
30 |
* [Summary] |
31 |
* TODO 请在此处简要描述此类所实现的功能。因为这项注释主要是为了在IDE环境中生成tip帮助,务必简明扼要 |
32 |
* [Remarks] |
33 |
* TODO 请在此处详细描述类的功能、调用方法、注意事项、以及与其它类的关系. |
34 |
*******************************************************************/ |
35 |
|
36 |
public class CustomProgressDialog extends Dialog { |
37 |
private Context context = null ; |
38 |
private static CustomProgressDialog customProgressDialog = null ; |
39 |
|
40 |
public CustomProgressDialog(Context context){ |
41 |
super (context); |
42 |
this .context = context; |
43 |
} |
44 |
|
45 |
public CustomProgressDialog(Context context, int theme) { |
46 |
super (context, theme); |
47 |
} |
48 |
|
49 |
public static CustomProgressDialog createDialog(Context context){ |
50 |
customProgressDialog = new CustomProgressDialog(context,R.style.CustomProgressDialog); |
51 |
customProgressDialog.setContentView(R.layout.customprogressdialog); |
52 |
customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER; |
53 |
|
54 |
return customProgressDialog; |
55 |
} |
56 |
|
57 |
public void onWindowFocusChanged( boolean hasFocus){ |
58 |
|
59 |
if (customProgressDialog == null ){ |
60 |
return ; |
61 |
} |
62 |
|
63 |
ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingImageView); |
64 |
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground(); |
65 |
animationDrawable.start(); |
66 |
} |
67 |
|
68 |
/** |
69 |
* |
70 |
* [Summary] |
71 |
* setTitile 标题 |
72 |
* @param strTitle |
73 |
* @return |
74 |
* |
75 |
*/ |
76 |
public CustomProgressDialog setTitile(String strTitle){ |
77 |
return customProgressDialog; |
78 |
} |
79 |
|
80 |
/** |
81 |
* |
82 |
* [Summary] |
83 |
* setMessage 提示内容 |
84 |
* @param strMessage |
85 |
* @return |
86 |
* |
87 |
*/ |
88 |
public CustomProgressDialog setMessage(String strMessage){ |
89 |
TextView tvMsg = (TextView)customProgressDialog.findViewById(R.id.id_tv_loadingmsg); |
90 |
|
91 |
if (tvMsg != null ){ |
92 |
tvMsg.setText(strMessage); |
93 |
} |
94 |
|
95 |
return customProgressDialog; |
96 |
} |
97 |
} |
01 |
package com.lxd.activity; |
02 |
|
03 |
import com.lxd.widgets.CustomProgressDialog; |
04 |
|
05 |
import android.app.Activity; |
06 |
import android.os.AsyncTask; |
07 |
import android.os.Bundle; |
08 |
import android.view.Window; |
09 |
import android.view.WindowManager; |
10 |
|
11 |
public class MainFrame extends Activity { |
12 |
private MainFrameTask mMainFrameTask = null ; |
13 |
private CustomProgressDialog progressDialog = null ; |
14 |
|
15 |
@Override |
16 |
public void onCreate(Bundle savedInstanceState) { |
17 |
super .onCreate(savedInstanceState); |
18 |
this .requestWindowFeature(Window.FEATURE_NO_TITLE); |
19 |
this .getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, |
20 |
WindowManager.LayoutParams.FLAG_FULLSCREEN); |
21 |
|
22 |
setContentView(R.layout.main); |
23 |
|
24 |
mMainFrameTask = new MainFrameTask( this ); |
25 |
mMainFrameTask.execute(); |
26 |
} |
27 |
|
28 |
@Override |
29 |
protected void onDestroy() { |
30 |
stopProgressDialog(); |
31 |
|
32 |
if (mMainFrameTask != null && !mMainFrameTask.isCancelled()){ |
33 |
mMainFrameTask.cancel( true ); |
34 |
} |
35 |
|
36 |
super .onDestroy(); |
37 |
} |
38 |
|
39 |
private void startProgressDialog(){ |
40 |
if (progressDialog == null ){ |
41 |
progressDialog = CustomProgressDialog.createDialog( this ); |
42 |
progressDialog.setMessage( "正在加载中..." ); |
43 |
} |
44 |
|
45 |
progressDialog.show(); |
46 |
} |
47 |
|
48 |
private void stopProgressDialog(){ |
49 |
if (progressDialog != null ){ |
50 |
progressDialog.dismiss(); |
51 |
progressDialog = null ; |
52 |
} |
53 |
} |
54 |
|
55 |
public class MainFrameTask extends AsyncTask<Integer, String, Integer>{ |
56 |
private MainFrame mainFrame = null ; |
57 |
|
58 |
public MainFrameTask(MainFrame mainFrame){ |
59 |
this .mainFrame = mainFrame; |
60 |
} |
61 |
|
62 |
@Override |
63 |
protected void onCancelled() { |
64 |
stopProgressDialog(); |
65 |
super .onCancelled(); |
66 |
} |
67 |
|
68 |
@Override |
69 |
protected Integer doInBackground(Integer... params) { |
70 |
|
71 |
try { |
72 |
Thread.sleep( 10 * 1000 ); |
73 |
} catch (InterruptedException e) { |
74 |
e.printStackTrace(); |
75 |
} |
76 |
return null ; |
77 |
} |
78 |
|
79 |
@Override |
80 |
protected void onPreExecute() { |
81 |
startProgressDialog(); |
82 |
} |
83 |
|
84 |
@Override |
85 |
protected void onPostExecute(Integer result) { |
86 |
stopProgressDialog(); |
87 |
} |
88 |
|
89 |
|
90 |
|
91 |
} |
92 |
} |