List of usage examples for android.app ProgressDialog ProgressDialog
public ProgressDialog(Context context)
From source file:com.easemob.chatuidemo.activity.LoginActivity.java
/** * //from ww w .j av a2 s .com * * @param view */ public void login(View view) { pd = new ProgressDialog(LoginActivity.this); pd.setCanceledOnTouchOutside(false); pd.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { progressShow = false; } }); pd.setMessage(getString(R.string.Is_landing)); pd.show(); setWeLoginPost(); }
From source file:nmtysh.android.test.speedtest.SpeedTestActivity.java
private void runHttpClient() { final String url = urlEdit.getText().toString(); if (url == null || (!url.startsWith("http://") && !url.startsWith("https://"))) { list.add("URL error!"); adapter.notifyDataSetChanged();//ww w .j ava 2 s . co m return; } task = new AsyncTask<Void, Integer, Void>() { long startTime; ProgressDialog progress; // ?? @Override protected void onPreExecute() { super.onPreExecute(); progress = new ProgressDialog(SpeedTestActivity.this); progress.setMessage(getString(R.string.progress_message)); progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progress.setIndeterminate(false); progress.setCancelable(true); progress.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { task.cancel(true); } }); progress.setMax(10); progress.setProgress(0); progress.show(); startTime = System.currentTimeMillis(); } // ??? @Override protected Void doInBackground(Void... params) { // 10????? for (int i = 0; i < 10; i++) { HttpClient client = new DefaultHttpClient(); InputStreamReader in = null; // BufferedReader br = null; try { HttpGet get = new HttpGet(url); HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() < 400) { in = new InputStreamReader(response.getEntity().getContent()); // br = new BufferedReader(in); // while (br.readLine() != null) { long len = 0; while (in.read() != -1) { len++; } Log.i("HttpClient", len + " Bytes"); } } catch (IOException e) { } finally { /* * if (br != null) { try { br.close(); } catch * (IOException e) { } br = null; } */ if (in != null) { try { in.close(); } catch (IOException e) { } in = null; } // ? client.getConnectionManager().shutdown(); client = null; } publishProgress(i + 1); // Dos???????? try { Thread.sleep(1000); } catch (InterruptedException e) { } } return null; } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); if (progress == null) { return; } progress.setProgress(values[0]); } // @Override protected void onPostExecute(Void result) { long endTime = System.currentTimeMillis(); // progress.cancel(); progress = null; list.add("HttpClient:" + url + " " + (endTime - startTime) + "msec/10" + " " + (endTime - startTime) / 10 + "msec"); adapter.notifyDataSetChanged(); } @Override protected void onCancelled() { super.onCancelled(); progress.dismiss(); progress = null; } }.execute(); }
From source file:edu.csh.coursebrowser.CourseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_course); // Show the Up button in the action bar. this.getActionBar().setHomeButtonEnabled(false); map_item = new HashMap<String, Course>(); map = new ArrayList<String>(); Bundle args = this.getIntent().getExtras(); this.setTitle(args.getCharSequence("title")); try {//from ww w . ja v a2 s .co m JSONObject jso = new JSONObject(args.get("args").toString()); JSONArray jsa = new JSONArray(jso.getString("courses")); ListView lv = (ListView) this.findViewById(R.id.course_list); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map); for (int i = 0; i < jsa.length(); ++i) { String s = jsa.getString(i); JSONObject obj = new JSONObject(s); Course course = new Course(obj.getString("title"), obj.getString("department"), obj.getString("course"), obj.getString("description"), obj.getString("id")); addItem(course); Log.v("Added", course.toString()); } lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String s = ((TextView) arg1).getText().toString(); final Course course = map_item.get(s); new AsyncTask<String, String, String>() { ProgressDialog p; protected void onPreExecute() { p = new ProgressDialog(CourseActivity.this); p.setTitle("Fetching Info"); p.setMessage("Contacting Server..."); p.setCancelable(false); p.show(); } protected String doInBackground(String... dep) { String params = "action=getSections&course=" + course.id; Log.v("Params", params); URL url; String back = ""; try { url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax" + ".php"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(params); writer.flush(); String line; BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { Log.v("Back:", line); back += line; } writer.close(); reader.close(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); p.dismiss(); return null; } return back; } protected void onPostExecute(String s) { if (s == null || s == "") { new AlertError(CourseActivity.this, "IO Error!").show(); return; } try { JSONObject jso = new JSONObject(s); JSONArray jsa = new JSONArray(jso.getString("sections")); } catch (JSONException e) { e.printStackTrace(); new AlertError(CourseActivity.this, "Invalid JSON From Server").show(); p.dismiss(); return; } Intent intent = new Intent(CourseActivity.this, SectionsActivity.class); intent.putExtra("title", course.title); intent.putExtra("id", course.id); intent.putExtra("description", course.description); intent.putExtra("args", s); startActivity(intent); p.dismiss(); } }.execute(course.id); } }); } catch (JSONException e) { // TODO Auto-generated catch block new AlertError(this, "Invalid JSON"); e.printStackTrace(); } }
From source file:com.mytwitter.activity.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w ww. j ava 2 s .c o m*/ toolbar.setLogo(R.drawable.ic_action_twitter); fab = (FloatingActionButton) findViewById(R.id.fab); //toolbar.setDisplayUseLogoEnabled(true); //toolbar.setDisplayShowHomeEnabled(true); // Obtain the shared Tracker instance. TwitterApplication application = (TwitterApplication) getApplication(); mTracker = application.getDefaultTracker(); // Set screen name. mTracker.setScreenName("HomeActivity"); // Send a screen view. mTracker.send(new HitBuilders.ScreenViewBuilder().build()); myLayout = (LinearLayout) findViewById(R.id.my_tweet_layout); tweetIds = new ArrayList<Long>(); mProgressDialog = new ProgressDialog(HomeActivity.this); mProgressDialog.setIndeterminate(true); mProgressDialog.setMessage("Loading..."); mProgressDialog.setCancelable(false); mProgressDialog.setCanceledOnTouchOutside(false); mProgressDialog.show(); //https://twittercommunity.com/t/how-to-get-user-hometimeline/52826 very useful StatusesService statusesService = Twitter.getApiClient().getStatusesService(); statusesService.homeTimeline(30, null, null, null, null, null, null, new Callback<List<Tweet>>() { @Override public void success(Result<List<Tweet>> listResult) { if (mProgressDialog.isShowing() && mProgressDialog != null) mProgressDialog.dismiss(); List<Tweet> tweets = listResult.data; for (int i = 0; i < tweets.size(); i++) { Tweet id = tweets.get(i); tweetIds.add(Long.valueOf(id.getId()).longValue()); } loadAllTweets(); } @Override public void failure(TwitterException e) { Snackbar.make(myLayout, e.getMessage(), Snackbar.LENGTH_LONG).setAction("Action", null).show(); } }); fab.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession(); Intent intent = new ComposerActivity.Builder(HomeActivity.this).session(session).createIntent(); startActivity(intent); } }); /*Call<List<MyTweet>> cb = statusesService.homeTimeline(10,0,0,false,false,false,false,Callback<List<MyTweet>>*/ /*ArrayList<answers> _list=new ArrayList<answers>(); _list.add(new answers(0,2,144)); _list.add(new answers(1,2,50)); _list.add(new answers(2,3,14)); _list.add(new answers(3,6,152)); _list.add(new answers(4,7,10)); Gson gson = new Gson(); String listString = gson.toJson( _list, new TypeToken<ArrayList<answers>>() {}.getType()); try{ Gson gson = new GsonBuilder().create(); JsonArray jsonArray = gson.toJsonTree(_list).getAsJsonArray(); System.out.println("jsonArray: "+jsonArray); //JSONArray jsonArray = new JSONArray(listString); HashMap<String,String> searchFilters = new HashMap<>(); searchFilters.put("answers",jsonArray.toString()); Call<testBean> cb= RetrofitClient.StackyServices().loadtest(searchFilters); cb.enqueue(new retrofit2.Callback<testBean>() { @Override public void onResponse(Call<testBean> call, retrofit2.Response<testBean> response) { if (mProgressDialog.isShowing() && mProgressDialog != null) mProgressDialog.dismiss(); int statusCode = response.code(); if (response.isSuccessful()) { testBean finalRes = response.body(); //logger.debug("status: "+finalRes.getResponse().getstatus()); } else { // handle request errors yourself ResponseBody errorBody = response.errorBody(); } } @Override public void onFailure(Call<testBean> call, Throwable t) { // handle execution failures like no internet connectivity logger.debug("onFailure"); t.printStackTrace(); if (mProgressDialog.isShowing() && mProgressDialog != null) mProgressDialog.dismiss(); } }); }catch(Exception e){ e.printStackTrace(); }*/ /*Call<List<MyTweet>> cb= RetrofitClient.myHomeTweetsServices().getHomeTweetIds(); cb.enqueue(new retrofit2.Callback<List<MyTweet>>() { @Override public void onResponse(Call<List<MyTweet>> call, retrofit2.Response<List<MyTweet>> response) { if (mProgressDialog.isShowing() && mProgressDialog != null) mProgressDialog.dismiss(); int statusCode = response.code(); if (response.isSuccessful()) { List<MyTweet> Ids = response.body(); for (int i = 0; i < Ids.size(); i++) { MyTweet id = Ids.get(i); tweetIds.add(Long.valueOf(id.getId_str()).longValue()); //if (!id.getRetweeted()) { // tweetIds.add(Long.valueOf(id.getId_str()).longValue()); // } } loadAllTweets(); } else { // handle request errors yourself ResponseBody errorBody = response.errorBody(); } } @Override public void onFailure(Call<List<MyTweet>> call, Throwable t) { // handle execution failures like no internet connectivity logger.debug("onFailure"); t.printStackTrace(); if (mProgressDialog.isShowing() && mProgressDialog != null) mProgressDialog.dismiss(); } });*/ }
From source file:com.fabernovel.alertevoirie.NewsActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_PROGRESS: ProgressDialog pd = new ProgressDialog(this); pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); pd.setIndeterminate(true);//from www.j av a 2s . co m pd.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { removeDialog(DIALOG_PROGRESS); } }); pd.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { AVService.getInstance(NewsActivity.this).cancelTask(); finish(); } }); pd.setMessage(getString(R.string.ui_message_loading)); return pd; default: return super.onCreateDialog(id); } }
From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncAutoGetAlbumArtTask.java
public void onPreExecute() { super.onPreExecute(); pd = new ProgressDialog(mActivity); pd.setTitle(R.string.downloading_album_art); pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pd.setCancelable(false);/*from ww w . j a v a 2 s . c o m*/ pd.setCanceledOnTouchOutside(false); pd.setMessage(mContext.getResources().getString(R.string.scanning_for_missing_art)); pd.setButton(DialogInterface.BUTTON_NEGATIVE, mContext.getResources().getString(R.string.cancel), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); task.cancel(true); } }); pd.show(); }
From source file:com.newcell.calltext.wizards.impl.Basic.java
private void bindFields() { accountSync = (Preference) findPreference("sync"); accountDisplayName = (EditTextPreference) findPreference("display_name"); accountUserName = (EditTextPreference) findPreference("username"); accountServer = (EditTextPreference) findPreference("server"); accountPassword = (EditTextPreference) findPreference("password"); dialog = new ProgressDialog(context); // Open shared preferences for the app to retrieve AuthKey and AuthPass sharedPref = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE); prefEditor = sharedPref.edit();//www .j a va 2 s .c o m accountSync.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { /* * Old AuthKey/AuthPass method String temp_auth_key = sharedPref.getString(context.getString(R.string.preference_auth_key), ""); String temp_auth_pass = sharedPref.getString(context.getString(R.string.preference_auth_pass), ""); if(temp_auth_key == null || temp_auth_key == "" || temp_auth_pass == null || temp_auth_pass == "") { // User AuthKey and AuthPass preference files // don't exist, request them Log.i(TAG, "No user authentication key/password, starting REQUEST_AUTH..."); new AccountDownloader().execute(REQUEST_AUTH); } else { // User AuthKey and AuthPass preference files already exist, // just request account info Log.i(TAG, "User authentication key/password found, starting REQUEST_INFO..."); new AccountDownloader().execute(REQUEST_INFO); } * Old AuthKey/AuthPass method */ new AccountDownloader().execute(REQUEST_INFO); return true; } }); }
From source file:edu.csh.coursebrowser.DepartmentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_departments); // Show the Up button in the action bar. // getActionBar().setDisplayHomeAsUpEnabled(false); this.getActionBar().setHomeButtonEnabled(true); final Bundle b = this.getIntent().getExtras(); map_item = new HashMap<String, Department>(); map = new ArrayList<String>(); Bundle args = this.getIntent().getExtras(); this.setTitle(args.getCharSequence("from")); try {/* w w w . j a v a 2 s . c o m*/ JSONObject jso = new JSONObject(args.get("args").toString()); JSONArray jsa = new JSONArray(jso.getString("departments")); ListView lv = (ListView) this.findViewById(R.id.department_list); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, map); for (int i = 0; i < jsa.length(); ++i) { String s = jsa.getString(i); JSONObject obj = new JSONObject(s); Department dept = new Department(obj.getString("title"), obj.getString("id"), obj.getString("code")); addItem(dept); Log.v("Added", dept.toString()); } lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String s = ((TextView) arg1).getText().toString(); final Department department = map_item.get(s); new AsyncTask<String, String, String>() { ProgressDialog p; protected void onPreExecute() { p = new ProgressDialog(DepartmentActivity.this); p.setTitle("Fetching Info"); p.setMessage("Contacting Server..."); p.setCancelable(false); p.show(); } protected String doInBackground(String... dep) { String params = "action=getCourses&department=" + dep[0] + "&quarter=" + b.getString("qCode"); Log.v("Params", params); URL url; String back = ""; try { url = new URL("http://iota.csh.rit" + ".edu/schedule/js/browseAjax" + ".php"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(params); writer.flush(); String line; BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); while ((line = reader.readLine()) != null) { Log.v("Back:", line); back += line; } writer.close(); reader.close(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); p.dismiss(); return null; } return back; } protected void onPostExecute(String s) { if (s == null || s == "") { new AlertError(DepartmentActivity.this, "IO Error!").show(); return; } try { JSONObject jso = new JSONObject(s); JSONArray jsa = new JSONArray(jso.getString("courses")); } catch (JSONException e) { e.printStackTrace(); new AlertError(DepartmentActivity.this, "Invalid JSON From Server").show(); p.dismiss(); return; } Intent intent = new Intent(DepartmentActivity.this, CourseActivity.class); intent.putExtra("title", department.title); intent.putExtra("id", department.id); intent.putExtra("code", department.code); intent.putExtra("args", s); startActivity(intent); p.dismiss(); } }.execute(department.id); } }); } catch (JSONException e) { // TODO Auto-generated catch block new AlertError(this, "Invalid JSON"); e.printStackTrace(); } }
From source file:com.fabernovel.alertevoirie.ExistingIncidentsActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_PROGRESS: mPd = new ProgressDialog(this); mPd.setProgressStyle(ProgressDialog.STYLE_SPINNER); mPd.setIndeterminate(true);//from w w w . j a v a 2 s. c o m mPd.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { removeDialog(DIALOG_PROGRESS); } }); mPd.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { AVService.getInstance(ExistingIncidentsActivity.this).cancelTask(); finish(); } }); mPd.setMessage(getString(R.string.ui_message_loading)); return mPd; default: return super.onCreateDialog(id); } }
From source file:io.v.syncslides.SignInActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_in); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mAccountName = mPrefs.getString(SignInActivity.PREF_USER_ACCOUNT_NAME, ""); mProgressDialog = new ProgressDialog(this); if (mAccountName.isEmpty()) { mProgressDialog.setMessage("Signing in..."); mProgressDialog.show();/*from ww w . ja v a2 s . c o m*/ if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, REQUEST_CODE_ASK_PERMISSIONS); return; } pickAccount(); } else { finishActivity(); } }