List of usage examples for android.app ProgressDialog ProgressDialog
public ProgressDialog(Context context)
From source file:org.starfishrespect.myconsumption.android.ui.AddSensorActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_sensor); Toolbar toolbar = getActionBarToolbar(); getSupportActionBar().setTitle(getString(R.string.title_add_sensor)); toolbar.setNavigationIcon(R.drawable.ic_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override//from w w w. ja va 2 s .co m public void onClick(View view) { Intent intent = getParentActivityIntent(); startActivity(intent); finish(); } }); spinnerSensorType = (Spinner) findViewById(R.id.spinnerSensorType); editTextSensorName = (EditText) findViewById(R.id.editTextSensorName); layoutSensorSpecificSettings = (LinearLayout) findViewById(R.id.layoutSensorSpecificSettings); buttonCreateSensor = (Button) findViewById(R.id.buttonCreateSensor); if (getIntent().getExtras() != null) { Bundle b = getIntent().getExtras(); if (b.containsKey("edit")) { try { editSensor = SingleInstance.getDatabaseHelper().getSensorDao().queryForId(b.getString("edit")); edit = true; editTextSensorName.setText(editSensor.getName()); sensorTypes = new String[1]; sensorTypes[0] = editSensor.getType(); layoutSensorSpecificSettings.removeAllViews(); selectedSensorType = sensorTypes[0].toLowerCase(); sensorView = SensorViewFactory.makeView(AddSensorActivity.this, selectedSensorType); sensorView.setEditMode(true); layoutSensorSpecificSettings.addView(sensorView); buttonCreateSensor.setText(R.string.button_edit_sensor); } catch (SQLException e) { finish(); } } } spinnerSensorType.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, sensorTypes)); if (!edit) { spinnerSensorType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { layoutSensorSpecificSettings.removeAllViews(); selectedSensorType = sensorTypes[position].toLowerCase(); sensorView = SensorViewFactory.makeView(AddSensorActivity.this, selectedSensorType); layoutSensorSpecificSettings.addView(sensorView); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); buttonCreateSensor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!MiscFunctions.isOnline(AddSensorActivity.this)) { MiscFunctions.makeOfflineDialog(AddSensorActivity.this).show(); return; } if (editTextSensorName.getText().toString().equals("") || !sensorView.areSettingsValid()) { new AlertDialog.Builder(AddSensorActivity.this).setTitle(R.string.dialog_title_error) .setMessage("You must fill all the fields in order to add a sensor !") .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); return; } new AsyncTask<Void, Boolean, Void>() { private ProgressDialog waitingDialog; @Override protected void onPreExecute() { waitingDialog = new ProgressDialog(AddSensorActivity.this); waitingDialog.setTitle(R.string.dialog_title_loading); waitingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); waitingDialog.setMessage( getResources().getString(R.string.dialog_message_loading_creating_sensor)); waitingDialog.show(); } @Override protected Void doInBackground(Void... params) { publishProgress(create()); return null; } @Override protected void onProgressUpdate(Boolean... values) { for (boolean b : values) { if (b) { new AlertDialog.Builder(AddSensorActivity.this) .setTitle(R.string.dialog_title_information) .setMessage(R.string.dialog_message_information_sensor_added) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); setResult(RESULT_OK); Intent intent = new Intent(AddSensorActivity.this, ChartActivity.class); intent.putExtra(Config.EXTRA_FIRST_LAUNCH, true); startActivity(intent); } }) .show(); } else { new AlertDialog.Builder(AddSensorActivity.this) .setTitle(R.string.dialog_title_error) .setMessage(R.string.dialog_message_error_sensor_not_added) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .show(); } } } @Override protected void onPostExecute(Void aVoid) { waitingDialog.dismiss(); } }.execute(); } }); } else { buttonCreateSensor.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AsyncTask<Void, Boolean, Void>() { private ProgressDialog waitingDialog; @Override protected void onPreExecute() { waitingDialog = new ProgressDialog(AddSensorActivity.this); waitingDialog.setTitle(R.string.dialog_title_loading); waitingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); waitingDialog.setMessage( getResources().getString(R.string.dialog_message_loading_editing_sensor)); waitingDialog.show(); } @Override protected Void doInBackground(Void... params) { publishProgress(edit()); return null; } @Override protected void onProgressUpdate(Boolean... values) { for (boolean b : values) { if (b) { new AlertDialog.Builder(AddSensorActivity.this) .setTitle(R.string.dialog_title_information) .setMessage(R.string.dialog_message_information_sensor_edited) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); setResult(Activity.RESULT_OK); finish(); } }) .show(); } else { new AlertDialog.Builder(AddSensorActivity.this) .setTitle(R.string.dialog_title_error) .setMessage(R.string.dialog_message_error_sensor_not_added) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .show(); } } } @Override protected void onPostExecute(Void aVoid) { waitingDialog.dismiss(); } }.execute(); } }); } }
From source file:com.clearcenter.mobile_demo.mdAuthenticatorActivity.java
protected Dialog onCreateDialog(int id) { final ProgressDialog dialog = new ProgressDialog(this); dialog.setMessage(getText(R.string.login_activity_authenticating)); dialog.setIndeterminate(true);/*from w ww. j a va2 s. c om*/ dialog.setCancelable(true); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { Log.i(TAG, "user cancelling authentication"); if (auth_task != null) { auth_task.cancel(true); } } }); // We save off the progress dialog in a field so that we can dismiss // it later. We can't just call dismissDialog(0) because the system // can lose track of our dialog if there's an orientation change. progress_dialog = dialog; return dialog; }
From source file:fm.smart.r1.CreateSoundActivity.java
public void onClick(View v) { String threegpfile_name = "test.3gp_amr"; String amrfile_name = "test.amr"; File dir = this.getDir("sounds", MODE_WORLD_READABLE); final File threegpfile = new File(dir, threegpfile_name); File amrfile = new File(dir, amrfile_name); String path = threegpfile.getAbsolutePath(); Log.d("CreateSoundActivity", path); Log.d("CreateSoundActivity", (String) button.getText()); if (button.getText().equals("Start")) { try {//from w w w . j ava2 s . c o m recorder = new MediaRecorder(); // ContentValues values = new ContentValues(3); // // values.put(MediaStore.MediaColumns.TITLE, "test"); // values.put(MediaStore.MediaColumns.DATE_ADDED, // System.currentTimeMillis()); // values.put(MediaStore.MediaColumns.MIME_TYPE, // MediaRecorder.OutputFormat.THREE_GPP); // // ContentResolver contentResolver = new ContentResolver(this); // // Uri base = MediaStore.Audio.INTERNAL_CONTENT_URI; // Uri newUri = contentResolver.insert(base, values); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); recorder.prepare(); button.setText("Stop"); recorder.start(); } catch (Exception e) { Log.w(TAG, e); } } else { FileOutputStream os = null; FileInputStream is = null; try { recorder.stop(); recorder.release(); // Now the object cannot be reused button.setEnabled(false); // ThreegpReader tr = new ThreegpReader(threegpfile); // os = new FileOutputStream(amrfile); // tr.extractAmr(os); is = new FileInputStream(threegpfile); playSound(is.getFD()); final String media_entity = "http://test.com/test.mp3"; final String author = "tansaku"; final String author_url = "http://smart.fm/users/tansaku"; if (LoginActivity.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); LoginActivity.return_to = CreateSoundActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("item_id", item_id); LoginActivity.params.put("goal_id", goal_id); LoginActivity.params.put("id", id); LoginActivity.params.put("to_record", to_record); LoginActivity.params.put("sound_type", sound_type); startActivity(intent); } else { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Creating Sound ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread create_sound = new Thread() { public void run() { // TODO make this interruptable .../*if // (!this.isInterrupted())*/ CreateSoundActivity.create_sound_result = createSound(threegpfile, media_entity, author, author_url, "1", item_id, id, to_record); // this will also ensure item is in goal, but this // should be sentence // submission if we are handling sentence sound. if (sound_type.equals(Integer.toString(R.id.cue_sound))) { CreateSoundActivity.add_item_result = new AddItemResult( Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item_id, CreateSoundActivity.create_sound_result.sound_id)); } else { // ensure item is in goal CreateSoundActivity.add_item_result = new AddItemResult(Main.lookup .addItemToGoal(Main.transport, Main.default_study_goal_id, item_id, null)); CreateSoundActivity.add_sentence_result = new AddSentenceResult( Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id, item_id, id, CreateSoundActivity.create_sound_result.sound_id)); } myOtherProgressDialog.dismiss(); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { create_sound.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { create_sound.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); myOtherProgressDialog.show(); create_sound.start(); } } catch (Exception e) { Log.w(TAG, e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (is != null) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
From source file:cn.kangeqiu.kq.activity.LoginActivity.java
public void WeiboLogin(View v) { progressShow = true;//from ww w .j a va 2s .c o m pd = new ProgressDialog(LoginActivity.this); pd.setCanceledOnTouchOutside(false); pd.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { progressShow = false; } }); pd.setMessage("??"); pd.show(); login(SHARE_MEDIA.SINA); }
From source file:com.shafiq.myfeedle.core.SelectFriends.java
protected void loadFriends() { mFriends.clear();/*from ww w. ja v a 2 s.c om*/ // SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND, Entities.ESID}, new int[]{R.id.profile, R.id.name, R.id.selected}); SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[] { Entities.FRIEND, Entities.ESID }, new int[] { R.id.name, R.id.selected }); setListAdapter(sa); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Long, String, Boolean> asyncTask = new AsyncTask<Long, String, Boolean>() { @Override protected Boolean doInBackground(Long... params) { boolean loadList = false; MyfeedleCrypto myfeedleCrypto = MyfeedleCrypto.getInstance(getApplicationContext()); // load the session Cursor account = getContentResolver().query(Accounts.getContentUri(SelectFriends.this), new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SERVICE }, Accounts._ID + "=?", new String[] { Long.toString(params[0]) }, null); if (account.moveToFirst()) { mToken = myfeedleCrypto.Decrypt(account.getString(0)); mSecret = myfeedleCrypto.Decrypt(account.getString(1)); mService = account.getInt(2); } account.close(); String response; switch (mService) { case TWITTER: break; case FACEBOOK: if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FACEBOOK_FRIENDS, FACEBOOK_BASE_URL, Saccess_token, mToken)))) != null) { try { JSONArray friends = new JSONObject(response).getJSONArray(Sdata); for (int i = 0, l = friends.length(); i < l; i++) { JSONObject f = friends.getJSONObject(i); HashMap<String, String> newFriend = new HashMap<String, String>(); newFriend.put(Entities.ESID, f.getString(Sid)); newFriend.put(Entities.PROFILE, String.format(FACEBOOK_PICTURE, f.getString(Sid))); newFriend.put(Entities.FRIEND, f.getString(Sname)); // need to alphabetize if (mFriends.isEmpty()) mFriends.add(newFriend); else { String fullName = f.getString(Sname); int spaceIdx = fullName.lastIndexOf(" "); String newFirstName = null; String newLastName = null; if (spaceIdx == -1) newFirstName = fullName; else { newFirstName = fullName.substring(0, spaceIdx++); newLastName = fullName.substring(spaceIdx); } List<HashMap<String, String>> newFriends = new ArrayList<HashMap<String, String>>(); for (int i2 = 0, l2 = mFriends.size(); i2 < l2; i2++) { HashMap<String, String> oldFriend = mFriends.get(i2); if (newFriend == null) { newFriends.add(oldFriend); } else { fullName = oldFriend.get(Entities.FRIEND); spaceIdx = fullName.lastIndexOf(" "); String oldFirstName = null; String oldLastName = null; if (spaceIdx == -1) oldFirstName = fullName; else { oldFirstName = fullName.substring(0, spaceIdx++); oldLastName = fullName.substring(spaceIdx); } if (newFirstName == null) { newFriends.add(newFriend); newFriend = null; } else { int comparison = oldFirstName.compareToIgnoreCase(newFirstName); if (comparison == 0) { // compare firstnames if (newLastName == null) { newFriends.add(newFriend); newFriend = null; } else if (oldLastName != null) { comparison = oldLastName.compareToIgnoreCase(newLastName); if (comparison == 0) { newFriends.add(newFriend); newFriend = null; } else if (comparison > 0) { newFriends.add(newFriend); newFriend = null; } } } else if (comparison > 0) { newFriends.add(newFriend); newFriend = null; } } newFriends.add(oldFriend); } } if (newFriend != null) newFriends.add(newFriend); mFriends = newFriends; } } loadList = true; } catch (JSONException e) { Log.e(TAG, e.toString()); } } break; case MYSPACE: break; case LINKEDIN: break; case FOURSQUARE: break; case IDENTICA: break; case GOOGLEPLUS: break; case CHATTER: break; } return loadList; } @Override protected void onPostExecute(Boolean loadList) { if (loadList) { // SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND}, new int[]{R.id.profile, R.id.name}); SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[] { Entities.FRIEND, Entities.ESID }, new int[] { R.id.name, R.id.selected }); sa.setViewBinder(mViewBinder); setListAdapter(sa); } if (loadingDialog.isShowing()) loadingDialog.dismiss(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(mAccountId); }
From source file:com.androidquery.simplefeed.base.BaseActivity.java
public ProgressDialog makeProgressDialog(String message) { ProgressDialog dialog = new ProgressDialog(this); dialog.setIndeterminate(true);/* w w w. j a v a 2 s . co m*/ dialog.setCancelable(true); dialog.setInverseBackgroundForced(false); dialog.setCanceledOnTouchOutside(true); dialog.setMessage(message); return dialog; }
From source file:com.example.scrumptious.SelectionFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View view = inflater.inflate(R.layout.selection, container, false); profilePictureView = (ProfilePictureView) view.findViewById(R.id.selection_profile_pic); profilePictureView.setCropped(true); announceButton = (TextView) view.findViewById(R.id.announce_text); shareButton = (ShareButton) view.findViewById(R.id.share_button); messageButton = (SendButton) view.findViewById(R.id.message_button); listView = (ListView) view.findViewById(R.id.selection_list); photoThumbnail = (ImageView) view.findViewById(R.id.selected_image); announceProgressDialog = new ProgressDialog(getActivity()); announceProgressDialog.setMessage(getString(R.string.progress_dialog_text)); if (MessageDialog.canShow(ShareOpenGraphContent.class)) { messageButton.setVisibility(View.VISIBLE); }// w w w. j ava 2s . c o m announceButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handleAnnounce(); } }); messageButton.registerCallback(callbackManager, shareCallback); messageButton.setFragment(this); shareButton.registerCallback(callbackManager, shareCallback); shareButton.setFragment(this); profilePictureView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (AccessToken.getCurrentAccessToken() != null) { activity.showSettingsFragment(); } else { activity.showSplashFragment(); } } }); init(savedInstanceState); updateWithToken(AccessToken.getCurrentAccessToken()); return view; }
From source file:net.stefanopallicca.android.awsmonitor.MainActivity.java
/** * Registers the application with GCM servers asynchronously. * <p>//w w w . ja v a2s . co m * Stores the registration ID and the app versionCode in the application's * shared preferences. * @return */ private void registerInBackground() { new AsyncTask<Void, Void, String>() { ProgressDialog pd; @Override protected void onPreExecute() { pd = new ProgressDialog(MainActivity.this); pd.setTitle("Processing..."); pd.setMessage("Please wait."); pd.setCancelable(false); pd.setIndeterminate(true); pd.show(); } @Override protected String doInBackground(Void... params) { String msg = ""; try { if (gcm == null) { gcm = GoogleCloudMessaging.getInstance(context); } regid = gcm.register(SENDER_ID); //msg = "Device registered, registration ID=" + regid; // Persist the regID - no need to register again. storeRegistrationId(context, regid); /** * Send regid to GSN server */ try { if (server.sendRegistrationIdToBackend(regid)) msg = "ok"; else msg = "ko"; } catch (HttpException e) { msg = "ko"; } } catch (IOException ex) { msg = "ko"; } return msg; } @Override protected void onPostExecute(String msg) { //mDisplay.append(msg + "\n"); if (msg == "ok") { Context context = getApplicationContext(); CharSequence text = getString(R.string.device_registered) + " " + MainActivity.this._sharedPref.getString("pref_server_url", "") + ":" + MainActivity.this._sharedPref.getString("pref_server_port", ""); int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.show(); } else { Context context = getApplicationContext(); CharSequence text = getString(R.string.error_connecting) + " " + MainActivity.this._sharedPref.getString("pref_server_url", "") + ":" + MainActivity.this._sharedPref.getString("pref_server_port", ""); int duration = Toast.LENGTH_LONG; Toast toast = Toast.makeText(context, text, duration); toast.show(); } pd.cancel(); launchMainApp(); } }.execute(null, null, null); }
From source file:com.taw.gotothere.GoToThereActivity.java
@Override public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate()"); super.onCreate(savedInstanceState); setContentView(R.layout.main);/* ww w . j a va 2s . c om*/ startupChecks(); initMapView(); markerImageView = (ImageView) findViewById(R.id.marker_button); directionsImageView = (ImageView) findViewById(R.id.directions_button); // Directions button initially disabled; if we're restoring state later // on, this may get overridden directionsImageView.setEnabled(false); searchTextView = (TextView) findViewById(R.id.location); progress = new ProgressDialog(this); progress.setMessage(getResources().getString(R.string.directions_text)); registerReceiver(); handleIntent(getIntent(), savedInstanceState); }
From source file:jp.envision.android.cloudfingerpaint.CloudFingerPaint.java
@Override public boolean onOptionsItemSelected(MenuItem item) { mPaint.setXfermode(null);/*ww w. java 2 s . c o m*/ mPaint.setAlpha(0xFF); switch (item.getItemId()) { case COLOR_MENU_ID: new ColorPickerDialog(this, this, mPaint.getColor()).show(); return true; case PRINT_MENU_ID: progressDialog = new ProgressDialog(this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage("???s..."); progressDialog.setCancelable(true); progressDialog.show(); (new Thread(runnable)).start(); return true; case EMBOSS_MENU_ID: if (mPaint.getMaskFilter() != mEmboss) { mPaint.setMaskFilter(mEmboss); } else { mPaint.setMaskFilter(null); } return true; case BLUR_MENU_ID: if (mPaint.getMaskFilter() != mBlur) { mPaint.setMaskFilter(mBlur); } else { mPaint.setMaskFilter(null); } return true; case ERASE_MENU_ID: mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); return true; case SRCATOP_MENU_ID: mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); mPaint.setAlpha(0x80); return true; case CLEAR_MENU_ID: Log.d(TAG, "Clear canvas."); myView.clear_all(); return true; } return super.onOptionsItemSelected(item); }