/*** Encapsulate the ProecssDialog dialog box **/public class LoadDialog extends ProgressDialog {private String title = ""; private String message = "loading data .... "; public LoadDialog (Context context, int theme) {super (context, theme );} /*** use the default title and content to create the dialog box * @ param context */public LoadDialog (Context context) {super (context); initDialog ();} /*** create a dialog box with the specified title and content * @ param context * @ param title * @ param message */public LoadDialog (Context context, String title, String message) {super (context); if (title! = Null) {this. title = title;} if (message! = Null) {this. message = message;} initDialog ();}/*** parameters in the initialization dialog box. The default dialog box cannot cancel */public void initDialog () {setTitle (title ); setMessage (message); setProgressStyle (ProgressDialog. STYLE_SPINNER); setCancelable (false);}/*** open the dialog box, set the callback method, and pass the class template, method name, and parameter list for the business method to be executed. * @ param callback method, this method is called back after the dialog box is closed, obtain the returned data * @ param serviceClass class template for executing the Business method * @ param method the method name for executing the Business method * @ param params parameter list for executing the Business method */public void execute (callback callback, class serviceClass, String method, Object... params) {super. show (); ServiceAysnTask task = new serviceaysntask(callback,serviceclass,method=task.exe cute (params);}/*** Callback method interface **/public interface Callback {public void getResult (Map map );} /*** Thread class for communication with remote services * @ author BDK * AsyncTask asynchronous task */private class ServiceAysnTask extends AsyncTask
{Private Class serviceClass; private String method; private Callback callback; public ServiceAysnTask (Callback callback, Class serviceClass, String method) {this. callback = callback; this. serviceClass = serviceClass; this. method = method ;}@ Overrideprotected Map doInBackground (Object... params) {Map resultMap = null; try {Object obj = serviceClass. newInstance (); // creates a Class template object Class [] paramTypes = new Class [params. length]; for (int I = 0; I <paramTypes. length; I ++) {paramTypes [I] = params [I]. getClass () ;}// obtain Method m = serviceClass based on the class template. getMethod (method, paramTypes); resultMap = (Map) m. invoke (obj, params);} catch (Exception e) {e. printStackTrace ();} LoadDialog. this. cancel (); return resultMap;} @ Overrideprotected void onPostExecute (Map result) {super. onPostExecute (result); if (result = null) {Toast. makeText (LoadDialog. this. getContext (), "Network Communication exception", Toast. LENGTH_LONG ). show (); return;} callback. getResult (result );}}}