List of usage examples for android.app ProgressDialog setOnCancelListener
public void setOnCancelListener(@Nullable OnCancelListener listener)
From source file:com.piusvelte.sonet.core.SonetNotifications.java
@Override public boolean onContextItemSelected(final MenuItem item) { if (item.getItemId() == CLEAR) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() { @Override//from w w w.j a va 2s . c o m protected Void doInBackground(Void... arg0) { // clear all notifications ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); SonetNotifications.this.getContentResolver().update( Notifications.getContentUri(SonetNotifications.this), values, Notifications._ID + "=?", new String[] { Long.toString(((AdapterContextMenuInfo) item.getMenuInfo()).id) }); return null; } @Override protected void onPostExecute(Void result) { if (loadingDialog.isShowing()) { loadingDialog.dismiss(); } SonetNotifications.this.finish(); } }; 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(); } return super.onContextItemSelected(item); // clear }
From source file:com.shafiq.myfeedle.core.MyfeedleNotifications.java
@Override public boolean onContextItemSelected(final MenuItem item) { if (item.getItemId() == CLEAR) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() { @Override// w w w.j a va 2s.c o m protected Void doInBackground(Void... arg0) { // clear all notifications ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); MyfeedleNotifications.this.getContentResolver().update( Notifications.getContentUri(MyfeedleNotifications.this), values, Notifications._ID + "=?", new String[] { Long.toString(((AdapterContextMenuInfo) item.getMenuInfo()).id) }); return null; } @Override protected void onPostExecute(Void result) { if (loadingDialog.isShowing()) { loadingDialog.dismiss(); } MyfeedleNotifications.this.finish(); } }; 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(); } return super.onContextItemSelected(item); // clear }
From source file:xj.property.activity.HXBaseActivity.MainActivity.java
/** * ??dialog/*w ww. j a v a2 s. c o m*/ */ private void showConflictDialog() { isConflictDialogShow = true; final UserInfoDetailBean detailBean = PreferencesUtil.getLoginInfo(getApplication()); username = detailBean.getUsername(); password = detailBean.getPassword(); final XJUserInfoBean bean = new XJUserInfoBean(); bean.setInfo(detailBean); if (xjpushManager != null) { xjpushManager.unregisterLoginedPushService(); } else { xjpushManager = new XJPushManager(this); xjpushManager.unregisterLoginedPushService(); } // boolean flag= PushManager.getInstance().unBindAlias(MainActivity.this, PreferencesUtil.getLoginInfo(MainActivity.this).getEmobId()); // Log.i("onion","flag"+flag); XjApplication.getInstance().logout(new EMCallBack() { @Override public void onSuccess() { runOnUiThread(new Runnable() { @Override public void run() { refreshUI(); refreshNewBangBiUI(); } }); } @Override public void onError(int i, String s) { } @Override public void onProgress(int i, String s) { } }); PreferencesUtil.Logout(MainActivity.this); if (!MainActivity.this.isFinishing()) { // clear up global variables try { final Dialog dialog = new Dialog(MainActivity.this, R.style.MyDialogStyle); dialog.setContentView(R.layout.dialog_conflict); TextView tv_cancle = (TextView) dialog.findViewById(R.id.tv_cancle); TextView tv_relogin = (TextView) dialog.findViewById(R.id.tv_relogin); tv_cancle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { conflictBuilder = null; dialog.dismiss(); index = 0; updateUnreadLabel(); startActivity(new Intent(MainActivity.this, MainActivity.class)); // finish(); } }); tv_relogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final ProgressDialog pd = new ProgressDialog(MainActivity.this, ProgressDialog.THEME_HOLO_LIGHT); pd.setCanceledOnTouchOutside(false); pd.setCancelable(false); pd.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { progressShow = false; } }); progressShow = true; pd.setMessage("..."); if (pd != null && !MainActivity.this.isFinishing()) pd.show(); //??? // getuser((int) detailBean.getCommunityId(),detailBean.getEmobId()); UserUtils.reLoginUser(MainActivity.this, username, password, new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case Config.LoginUserComplete: if (progressShow) pd.dismiss(); dialog.dismiss(); startActivity(new Intent(MainActivity.this, MainActivity.class)); isConflict = false; // boolean flag = PushManager.getInstance().bindAlias(MainActivity.this, PreferencesUtil.getLoginInfo(MainActivity.this).getEmobId()); PushManager.getInstance().turnOnPush(MainActivity.this); if (xjpushManager == null) { xjpushManager = new XJPushManager(getmContext()); } xjpushManager.registerLoginedPushService(); break; case Config.LoginUserFailure: if (progressShow && !MainActivity.this.isFinishing()) { pd.dismiss(); Toast.makeText(MainActivity.this, "?", Toast.LENGTH_SHORT) .show(); } break; default: pd.setMessage(".."); break; } } }); /* UserUtils.loginEMChat(MainActivity.this, username, bean, new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case Config.LoginUserComplete: if (progressShow) pd.dismiss(); dialog.dismiss(); UserUtils.appLogin(MainActivity.this,PushManager.getInstance().getClientid(MainActivity.this), PreferencesUtil.getLoginInfo(MainActivity.this).getUsername()); startActivity(new Intent(MainActivity.this, MainActivity.class)); isConflict=false; boolean flag= PushManager.getInstance().bindAlias(MainActivity.this, PreferencesUtil.getLoginInfo(MainActivity.this).getEmobId()); PushManager.getInstance().turnOnPush(MainActivity.this); break; case Config.LoginUserFailure: if (progressShow && !MainActivity.this.isFinishing()) { pd.dismiss(); Toast.makeText(MainActivity.this, "?", Toast.LENGTH_SHORT).show(); } break; default: pd.setMessage(".."); break; } } });*/ } }); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0)); dialog.setCancelable(false); dialog.show(); isConflict = true; } catch (Exception e) { EMLog.e(TAG, "---------color conflictBuilder error" + e.getMessage()); } } }
From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == FilePicker.PICK_FILE_REQUEST) { if (resultCode == RESULT_OK) { String filePath = data.getStringExtra(FilePicker.EXTRA_FILE_PATH); if (TextUtils.isEmpty(filePath)) { showToast("No file was choosen."); return; }/*from ww w. j ava 2 s . c o m*/ File file = new File(filePath); final ProgressDialog uploadProgressDialog = new ProgressDialog(SkyDriveActivity.this); uploadProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); uploadProgressDialog.setMessage("Uploading..."); uploadProgressDialog.setCancelable(true); uploadProgressDialog.show(); final LiveOperation operation = mClient.uploadAsync(mCurrentFolderId, file.getName(), file, new LiveUploadOperationListener() { @Override public void onUploadProgress(int totalBytes, int bytesRemaining, LiveOperation operation) { int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining); uploadProgressDialog.setProgress(percentCompleted); } @Override public void onUploadFailed(LiveOperationException exception, LiveOperation operation) { uploadProgressDialog.dismiss(); showToast(exception.getMessage()); } @Override public void onUploadCompleted(LiveOperation operation) { uploadProgressDialog.dismiss(); JSONObject result = operation.getResult(); if (result.has(JsonKeys.ERROR)) { JSONObject error = result.optJSONObject(JsonKeys.ERROR); String message = error.optString(JsonKeys.MESSAGE); String code = error.optString(JsonKeys.CODE); showToast(code + ": " + message); return; } loadFolder(mCurrentFolderId); } }); uploadProgressDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { operation.cancel(); } }); } } }
From source file:fm.smart.r1.CreateExampleActivity.java
public void onClick(View v) { EditText exampleInput = (EditText) findViewById(R.id.create_example_sentence); EditText translationInput = (EditText) findViewById(R.id.create_example_translation); EditText exampleTransliterationInput = (EditText) findViewById(R.id.sentence_transliteration); EditText translationTransliterationInput = (EditText) findViewById(R.id.translation_transliteration); final String example = exampleInput.getText().toString(); final String translation = translationInput.getText().toString(); if (TextUtils.isEmpty(example) || TextUtils.isEmpty(translation)) { Toast t = Toast.makeText(this, "Example and translation are required fields", 150); t.setGravity(Gravity.CENTER, 0, 0); t.show();// w w w .j a v a 2 s . c o m } else { final String example_language_code = Utils.LANGUAGE_MAP.get(example_language); final String translation_language_code = Utils.LANGUAGE_MAP.get(translation_language); final String example_transliteration = exampleTransliterationInput.getText().toString(); final String translation_transliteration = translationTransliterationInput.getText().toString(); if (LoginActivity.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid // navigation // back to this? LoginActivity.return_to = CreateExampleActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("goal_id", goal_id); LoginActivity.params.put("item_id", item_id); LoginActivity.params.put("example", example); LoginActivity.params.put("translation", translation); LoginActivity.params.put("example_language", example_language); LoginActivity.params.put("translation_language", translation_language); LoginActivity.params.put("example_transliteration", example_transliteration); LoginActivity.params.put("translation_transliteration", translation_transliteration); startActivity(intent); } else { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Creating Example ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread create_example = new Thread() { public void run() { // TODO make this interruptable .../*if // (!this.isInterrupted())*/ try { // TODO failures here could derail all ... CreateExampleActivity.add_item_goal_result = new AddItemResult( Main.lookup.addItemToGoal(Main.transport, goal_id, item_id, null)); Result result = null; try { result = Main.lookup.createExample(Main.transport, translation, translation_language_code, translation, null, null, null); JSONObject json = new JSONObject(result.http_response); String text = json.getString("text"); String translation_id = json.getString("id"); result = Main.lookup.createExample(Main.transport, example, example_language_code, example_transliteration, translation_id, item_id, goal_id); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } CreateExampleActivity.create_example_result = new CreateExampleResult(result); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } myOtherProgressDialog.dismiss(); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { create_example.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { create_example.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); myOtherProgressDialog.show(); create_example.start(); } } }
From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java
@Override protected Dialog onCreateDialog(final int id, final Bundle bundle) { Dialog dialog = null;/* w w w .jav a2 s. c om*/ switch (id) { case DIALOG_DOWNLOAD_ID: { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Download").setMessage("This file will be downloaded to the sdcard.") .setPositiveButton("OK", new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final ProgressDialog progressDialog = new ProgressDialog(SkyDriveActivity.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMessage("Downloading..."); progressDialog.setCancelable(true); progressDialog.show(); String fileId = bundle.getString(JsonKeys.ID); String name = bundle.getString(JsonKeys.NAME); File file = new File(Environment.getExternalStorageDirectory(), name); final LiveDownloadOperation operation = mClient.downloadAsync(fileId + "/content", file, new LiveDownloadOperationListener() { @Override public void onDownloadProgress(int totalBytes, int bytesRemaining, LiveDownloadOperation operation) { int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining); progressDialog.setProgress(percentCompleted); } @Override public void onDownloadFailed(LiveOperationException exception, LiveDownloadOperation operation) { progressDialog.dismiss(); showToast(exception.getMessage()); } @Override public void onDownloadCompleted(LiveDownloadOperation operation) { progressDialog.dismiss(); showToast("File downloaded."); } }); progressDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { operation.cancel(); } }); } }).setNegativeButton("Cancel", new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); dialog = builder.create(); break; } } if (dialog != null) { dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { removeDialog(id); } }); } return dialog; }
From source file:de.da_sense.moses.client.AvailableFragment.java
/** * FIXME: The ProgressDialog doesn't show up. Handles installing APK from * the Server.//w ww. j a v a 2 s .c om * * @param app * the App to download and install */ protected void handleInstallApp(ExternalApplication app) { final ProgressDialog progressDialog = new ProgressDialog(WelcomeActivity.getInstance()); Log.d(TAG, "progressDialog = " + progressDialog); final ApkDownloadManager downloader = new ApkDownloadManager(app, WelcomeActivity.getInstance().getApplicationContext(), // getActivity().getApplicationContext(), new ExecutableForObject() { @Override public void execute(final Object o) { if (o instanceof Integer) { WelcomeActivity.getInstance().runOnUiThread(new Runnable() { @Override public void run() { if (totalSize == -1) { totalSize = (Integer) o / 1024; progressDialog.setMax(totalSize); } else { progressDialog.incrementProgressBy( ((Integer) o / 1024) - progressDialog.getProgress()); } } }); /* * They were : Runnable runnable = new Runnable() { * Integer temporary = (Integer) o / 1024; * * @Override public void run() { if (totalSize == * -1) { totalSize = temporary; * progressDialog.setMax(totalSize); } else { * progressDialog .incrementProgressBy( temporary - * progressDialog.getProgress()); } } }; * getActivity().runOnUiThread(runnable); */ } } }); progressDialog.setTitle(getString(R.string.downloadingApp)); progressDialog.setMessage(getString(R.string.pleaseWait)); progressDialog.setMax(0); progressDialog.setProgress(0); progressDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { downloader.cancel(); } }); progressDialog.setCancelable(true); progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (progressDialog.isShowing()) progressDialog.cancel(); } }); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); Observer observer = new Observer() { @Override public void update(Observable observable, Object data) { if (downloader.getState() == ApkDownloadManager.State.ERROR) { // error downloading if (progressDialog.isShowing()) { progressDialog.dismiss(); } showMessageBoxErrorDownloading(downloader); } else if (downloader.getState() == ApkDownloadManager.State.ERROR_NO_CONNECTION) { // error with connection if (progressDialog.isShowing()) { progressDialog.dismiss(); } showMessageBoxErrorNoConnection(downloader); } else if (downloader.getState() == ApkDownloadManager.State.FINISHED) { // success if (progressDialog.isShowing()) { progressDialog.dismiss(); } installDownloadedApk(downloader.getDownloadedApk(), downloader.getExternalApplicationResult()); } } }; downloader.addObserver(observer); totalSize = -1; // progressDialog.show(); FIXME: commented out in case it throws an // error downloader.start(); }
From source file:nf.frex.android.FrexActivity.java
private void setWallpaper() { final WallpaperManager wallpaperManager = WallpaperManager.getInstance(FrexActivity.this); final int desiredWidth = wallpaperManager.getDesiredMinimumWidth(); final int desiredHeight = wallpaperManager.getDesiredMinimumHeight(); final Image image = view.getImage(); final int imageWidth = image.getWidth(); final int imageHeight = image.getHeight(); final boolean useDesiredSize = desiredWidth > imageWidth || desiredHeight > imageHeight; DialogInterface.OnClickListener noListener = new DialogInterface.OnClickListener() { @Override//from w ww . j a v a 2s . com public void onClick(DialogInterface dialog, int which) { // ok } }; if (useDesiredSize) { showYesNoDialog(this, R.string.set_wallpaper, getString(R.string.wallpaper_compute_msg, desiredWidth, desiredHeight), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final Image wallpaperImage; try { wallpaperImage = new Image(desiredWidth, desiredHeight); } catch (OutOfMemoryError e) { alert(getString(R.string.out_of_memory)); return; } final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this); Generator.ProgressListener progressListener = new Generator.ProgressListener() { int numLines; @Override public void onStarted(int numTasks) { } @Override public void onSomeLinesComputed(int taskId, int line1, int line2) { numLines += 1 + line2 - line1; progressDialog.setProgress(numLines); } @Override public void onStopped(boolean cancelled) { progressDialog.dismiss(); if (!cancelled) { setWallpaper(wallpaperManager, wallpaperImage); } } }; final Generator wallpaperGenerator = new Generator(view.getGeneratorConfig(), SettingsActivity.NUM_CORES, progressListener); DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (progressDialog.isShowing()) { progressDialog.dismiss(); } wallpaperGenerator.cancel(); } }; progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setCancelable(true); progressDialog.setMax(desiredHeight); progressDialog.setOnCancelListener(cancelListener); progressDialog.show(); Arrays.fill(wallpaperImage.getValues(), FractalView.MISSING_VALUE); wallpaperGenerator.start(wallpaperImage, false); } }, noListener, null); } else { showYesNoDialog(this, R.string.set_wallpaper, getString(R.string.wallpaper_replace_msg), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setWallpaper(wallpaperManager, image); } }, noListener, null); } }
From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java
/** Called when the activity is first created. */ @Override//from ww w . j ava 2 s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_unifiednav); detectedAPs = (TextView) findViewById(R.id.detectedAPs); textFloor = (TextView) findViewById(R.id.textFloor); progressBar = (ProgressBar) findViewById(R.id.progressBar); textDebug = (TextView) findViewById(R.id.textDebug); if (AnyplaceAPI.DEBUG_MESSAGES) textDebug.setVisibility(View.VISIBLE); ActionBar actionBar = getSupportActionBar(); actionBar.setHomeButtonEnabled(true); userData = new AnyUserData(); SimpleWifiManager.getInstance().startScan(); sensorsMain = new SensorsMain(getApplicationContext()); movementDetector = new MovementDetector(); sensorsMain.addListener(movementDetector); sensorsStepCounter = new SensorsStepCounter(getApplicationContext(), sensorsMain); lpTracker = new TrackerLogicPlusIMU(movementDetector, sensorsMain, sensorsStepCounter); // lpTracker = new TrackerLogic(sensorsMain); floorSelector = new Algo1Radiomap(getApplicationContext()); mAnyplaceCache = AnyplaceCache.getInstance(this); visiblePois = new VisiblePois(); setUpMapIfNeeded(); // setup the trackme button overlaid in the map btnTrackme = (ImageButton) findViewById(R.id.btnTrackme); btnTrackme.setImageResource(R.drawable.dark_device_access_location_off); isTrackingErrorBackground = true; btnTrackme.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final GeoPoint gpsLoc = userData.getLocationGPSorIP(); if (gpsLoc != null) { AnyplaceCache mAnyplaceCache = AnyplaceCache.getInstance(UnifiedNavigationActivity.this); mAnyplaceCache.loadWorldBuildings(new FetchBuildingsTaskListener() { @Override public void onSuccess(String result, List<BuildingModel> buildings) { final FetchNearBuildingsTask nearest = new FetchNearBuildingsTask(); nearest.run(buildings, gpsLoc.lat, gpsLoc.lng, 200); if (nearest.buildings.size() > 0 && (userData.getSelectedBuildingId() == null || !userData.getSelectedBuildingId().equals(nearest.buildings.get(0).buid))) { floorSelector.Stop(); final FloorSelector floorSelectorAlgo1 = new Algo1Server(getApplicationContext()); final ProgressDialog floorSelectorDialog = new ProgressDialog( UnifiedNavigationActivity.this); floorSelectorDialog.setIndeterminate(true); floorSelectorDialog.setTitle("Detecting floor"); floorSelectorDialog.setMessage("Please be patient..."); floorSelectorDialog.setCancelable(true); floorSelectorDialog.setCanceledOnTouchOutside(false); floorSelectorDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { floorSelectorAlgo1.Destoy(); bypassSelectBuildingActivity(nearest.buildings.get(0), "0", false); } }); class Callback implements ErrorAnyplaceFloorListener, FloorAnyplaceFloorListener { @Override public void onNewFloor(String floor) { floorSelectorAlgo1.Destoy(); if (floorSelectorDialog.isShowing()) { floorSelectorDialog.dismiss(); bypassSelectBuildingActivity(nearest.buildings.get(0), floor, false); } } @Override public void onFloorError(Exception ex) { floorSelectorAlgo1.Destoy(); if (floorSelectorDialog.isShowing()) { floorSelectorDialog.dismiss(); bypassSelectBuildingActivity(nearest.buildings.get(0), "0", false); } } } Callback callback = new Callback(); floorSelectorAlgo1.addListener((FloorAnyplaceFloorListener) callback); floorSelectorAlgo1.addListener((ErrorAnyplaceFloorListener) callback); // Show Dialog floorSelectorDialog.show(); floorSelectorAlgo1.Start(gpsLoc.lat, gpsLoc.lng); } else { focusUserLocation(); // Clear cancel request lastFloor = null; floorSelector.RunNow(); lpTracker.reset(); } } @Override public void onErrorOrCancel(String result) { } }, UnifiedNavigationActivity.this, false); } else { focusUserLocation(); // Clear cancel request lastFloor = null; floorSelector.RunNow(); lpTracker.reset(); } } }); btnFloorUp = (ImageButton) findViewById(R.id.btnFloorUp); btnFloorUp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!userData.isFloorSelected()) { Toast.makeText(getBaseContext(), "Load a map before tracking can be used!", Toast.LENGTH_SHORT) .show(); return; } BuildingModel b = userData.getSelectedBuilding(); if (b == null) { return; } if (userData.isNavBuildingSelected()) { // Move to start/destination poi's floor String floor_number; List<PoisNav> puids = userData.getNavPois(); // Check start and destination floor number if (!puids.get(puids.size() - 1).floor_number.equals(puids.get(0).floor_number)) { if (userData.getSelectedFloorNumber().equals(puids.get(puids.size() - 1).floor_number)) { floor_number = puids.get(0).floor_number; } else { floor_number = puids.get(puids.size() - 1).floor_number; } FloorModel floor = b.getFloorFromNumber(floor_number); if (floor != null) { bypassSelectBuildingActivity(b, floor); return; } } } // Move one floor up int index = b.getSelectedFloorIndex(); if (b.checkIndex(index + 1)) { bypassSelectBuildingActivity(b, b.getFloors().get(index + 1)); } } }); btnFloorDown = (ImageButton) findViewById(R.id.btnFloorDown); btnFloorDown.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!userData.isFloorSelected()) { Toast.makeText(getBaseContext(), "Load a map before tracking can be used!", Toast.LENGTH_SHORT) .show(); return; } BuildingModel b = userData.getSelectedBuilding(); if (b == null) { return; } if (userData.isNavBuildingSelected()) { // Move to start/destination poi's floor String floor_number; List<PoisNav> puids = userData.getNavPois(); // Check start and destination floor number if (!puids.get(puids.size() - 1).floor_number.equals(puids.get(0).floor_number)) { if (userData.getSelectedFloorNumber().equals(puids.get(puids.size() - 1).floor_number)) { floor_number = puids.get(0).floor_number; } else { floor_number = puids.get(puids.size() - 1).floor_number; } FloorModel floor = b.getFloorFromNumber(floor_number); if (floor != null) { bypassSelectBuildingActivity(b, floor); return; } } } // Move one floor down int index = b.getSelectedFloorIndex(); if (b.checkIndex(index - 1)) { bypassSelectBuildingActivity(b, b.getFloors().get(index - 1)); } } }); /* * Create a new location client, using the enclosing class to handle callbacks. */ // Create the LocationRequest object mLocationRequest = LocationRequest.create(); // Use high accuracy mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Set the update interval to 2 seconds mLocationRequest.setInterval(2000); // Set the fastest update interval to 1 second mLocationRequest.setFastestInterval(1000); mLocationClient = new LocationClient(this, this, this); // declare that this is the first time this Activity launched so make // the automatic building selection mAutomaticGPSBuildingSelection = true; // get/set settings PreferenceManager.setDefaultValues(this, SHARED_PREFS_ANYPLACE, MODE_PRIVATE, R.xml.preferences_anyplace, true); SharedPreferences preferences = getSharedPreferences(SHARED_PREFS_ANYPLACE, MODE_PRIVATE); preferences.registerOnSharedPreferenceChangeListener(this); lpTracker.setAlgorithm(preferences.getString("TrackingAlgorithm", "WKNN")); // handle the search intent handleIntent(getIntent()); }
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 ww w. j ava 2 s .c om*/ 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(); } } } } }