List of usage examples for android.app ProgressDialog setIndeterminate
public void setIndeterminate(boolean indeterminate)
From source file:com.cerema.cloud2.ui.activity.Uploader.java
@Override protected Dialog onCreateDialog(final int id) { final AlertDialog.Builder builder = new Builder(this); switch (id) { case DIALOG_WAITING: final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme); pDialog.setIndeterminate(false); pDialog.setCancelable(false);/*ww w. j av a 2s . com*/ pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading)); pDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress); v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.color_accent), android.graphics.PorterDuff.Mode.MULTIPLY); } }); return pDialog; case DIALOG_NO_ACCOUNT: builder.setIcon(R.drawable.ic_warning); builder.setTitle(R.string.uploader_wrn_no_account_title); builder.setMessage( String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name))); builder.setCancelable(false); builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) { // using string value since in API7 this // constant is not defined // in API7 < this constant is defined in // Settings.ADD_ACCOUNT_SETTINGS // and Settings.EXTRA_AUTHORITIES Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT); intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() }); startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT); } else { // since in API7 there is no direct call for // account setup, so we need to // show our own AccountSetupAcricity, get // desired results and setup // everything for ourself Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class); startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT); } } }); builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return builder.create(); case DIALOG_MULTIPLE_ACCOUNT: CharSequence ac[] = new CharSequence[mAccountManager .getAccountsByType(MainApp.getAccountType()).length]; for (int i = 0; i < ac.length; ++i) { ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name, false); } builder.setTitle(R.string.common_choose_account); builder.setItems(ac, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]); onAccountSet(mAccountWasRestored); dialog.dismiss(); mAccountSelected = true; mAccountSelectionShowing = false; } }); builder.setCancelable(true); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mAccountSelectionShowing = false; dialog.cancel(); finish(); } }); return builder.create(); case DIALOG_NO_STREAM: builder.setIcon(R.drawable.ic_warning); builder.setTitle(R.string.uploader_wrn_no_content_title); builder.setMessage(R.string.uploader_wrn_no_content_text); builder.setCancelable(false); builder.setNegativeButton(R.string.common_cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return builder.create(); default: throw new IllegalArgumentException("Unknown dialog id: " + id); } }
From source file:com.eleybourn.bookcatalogue.utils.SimpleTaskQueueProgressFragment.java
/** * Create the underlying dialog//from ww w. jav a2s . co m */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { ProgressDialog dialog = new ProgressDialog(getActivity()); dialog.setCancelable(true); dialog.setCanceledOnTouchOutside(false); int msg = getArguments().getInt("title"); if (msg != 0) dialog.setMessage(getActivity().getString(msg)); final boolean isIndet = getArguments().getBoolean("isIndeterminate"); dialog.setIndeterminate(isIndet); if (isIndet) { dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); } else { dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); } // We can't use "this.requestUpdateProgress()" because getDialog() will still return null if (!isIndet) { dialog.setMax(mMax); dialog.setProgress(mProgress); if (mMessage != null) dialog.setMessage(mMessage); setDialogNumberFormat(dialog); } return dialog; }
From source file:projekt.substratum.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); startService(new Intent(this, ThemeService.class)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//w w w. ja v a 2s . co m getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(false); AccountHeader header = new AccountHeaderBuilder().withActivity(this) .withHeaderBackground(R.drawable.material_drawer_header_background).withProfileImagesVisible(false) .withSelectionListEnabledForSingleProfile(false).addProfiles(new ProfileDrawerItem() .withName(getString(R.string.drawer_name)).withEmail(BuildConfig.VERSION_NAME)) .withCurrentProfileHiddenInList(true).build(); final LibsSupportFragment fragment = new LibsBuilder().supportFragment(); if (References.checkOMS()) { drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(header) .withSavedInstance(savedInstanceState).withActionBarDrawerToggleAnimated(true) .addDrawerItems( new PrimaryDrawerItem().withName(R.string.nav_home) .withIcon(R.drawable.nav_theme_packs), new PrimaryDrawerItem().withName(R.string.nav_overlays) .withIcon(R.drawable.nav_overlays), new PrimaryDrawerItem().withName(R.string.nav_bootanim) .withIcon(R.drawable.nav_bootanim), new PrimaryDrawerItem().withName(R.string.nav_fonts).withIcon(R.drawable.nav_fonts), new PrimaryDrawerItem().withName(R.string.nav_sounds).withIcon(R.drawable.nav_sounds), new SectionDrawerItem().withName(R.string.nav_section_header_utilities), new PrimaryDrawerItem().withName(R.string.nav_overlay_manager) .withIcon(R.drawable.nav_overlay_manager), new PrimaryDrawerItem().withName(R.string.nav_manage).withIcon(R.drawable.nav_manage), new PrimaryDrawerItem().withName(R.string.nav_priorities) .withIcon(R.drawable.nav_drawer_priorities), new PrimaryDrawerItem().withName(R.string.nav_backup_restore) .withIcon(R.drawable.nav_drawer_profiles), new SectionDrawerItem().withName(R.string.nav_section_header_more), new SecondaryDrawerItem().withName(R.string.nav_troubleshooting) .withIcon(R.drawable.nav_troubleshooting), new SecondaryDrawerItem().withName(R.string.nav_team) .withIcon(R.drawable.nav_drawer_team), new SecondaryDrawerItem().withName(getString(R.string.nav_opensource)) .withIcon(R.drawable.nav_drawer_licenses), new SecondaryDrawerItem().withName(R.string.nav_settings) .withIcon(R.drawable.nav_drawer_settings)) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { if (drawerItem != null) { switch (position) { case 1: if (drawerSelected != position) { switchFragment(((References.checkOMS()) ? getString(R.string.app_name) : getString(R.string.legacy_app_name)), "HomeFragment"); drawerSelected = 1; } break; case 2: if (drawerSelected != position) { switchFragment(getString(R.string.nav_overlays), "OverlaysFragment"); drawerSelected = 2; } break; case 3: if (drawerSelected != position) { switchFragment(getString(R.string.nav_bootanim), "BootAnimationsFragment"); drawerSelected = 3; } break; case 4: if (drawerSelected != position) { switchFragment(getString(R.string.nav_fonts), "FontsFragment"); drawerSelected = 4; } break; case 5: if (drawerSelected != position) { switchFragment(getString(R.string.nav_sounds), "SoundsFragment"); drawerSelected = 5; } break; case 7: switchFragment(getString(R.string.nav_overlay_manager), "AdvancedManagerFragment"); drawerSelected = 7; break; case 8: switchFragment(getString(R.string.nav_manage), "ManageFragment"); drawerSelected = 8; break; case 9: switchFragment(getString(R.string.nav_priorities), "PriorityLoaderFragment"); drawerSelected = 9; break; case 10: switchFragment(getString(R.string.nav_backup_restore), "ProfileFragment"); drawerSelected = 10; break; case 12: if (drawerSelected != position) { switchFragment(getString(R.string.nav_troubleshooting), "TroubleshootingFragment"); drawerSelected = 12; } break; case 13: if (drawerSelected != position) { switchFragment(getString(R.string.nav_team), "TeamFragment"); drawerSelected = 13; } break; case 14: switchFragmentToLicenses(getString(R.string.nav_opensource), fragment); drawerSelected = 14; break; case 15: if (drawerSelected != position) { switchFragment(getString(R.string.nav_settings), "SettingsFragment"); drawerSelected = 15; } break; } } return false; } }).withSelectedItem(1).withSelectedItemByPosition(1).build(); } else { drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(header) .withSavedInstance(savedInstanceState).withActionBarDrawerToggleAnimated(true) .addDrawerItems( new PrimaryDrawerItem().withName(R.string.nav_home) .withIcon(R.drawable.nav_theme_packs), new PrimaryDrawerItem().withName(R.string.nav_overlays) .withIcon(R.drawable.nav_overlays), new PrimaryDrawerItem().withName(R.string.nav_sounds).withIcon(R.drawable.nav_sounds), new SectionDrawerItem().withName(R.string.nav_section_header_utilities), new PrimaryDrawerItem().withName(R.string.nav_overlay_manager) .withIcon(R.drawable.nav_overlay_manager), new PrimaryDrawerItem().withName(R.string.nav_manage).withIcon(R.drawable.nav_manage), new PrimaryDrawerItem().withName(R.string.nav_backup_restore) .withIcon(R.drawable.nav_drawer_profiles), new SectionDrawerItem().withName(R.string.nav_section_header_more), new SecondaryDrawerItem().withName(R.string.nav_troubleshooting) .withIcon(R.drawable.nav_troubleshooting), new SecondaryDrawerItem().withName(R.string.nav_team) .withIcon(R.drawable.nav_drawer_team), new SecondaryDrawerItem().withName(getString(R.string.nav_opensource)) .withIcon(R.drawable.nav_drawer_licenses), new SecondaryDrawerItem().withName(R.string.nav_settings) .withIcon(R.drawable.nav_drawer_settings)) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { if (drawerItem != null) { switch (position) { case 1: if (drawerSelected != position) { switchFragment(((References.checkOMS()) ? getString(R.string.app_name) : getString(R.string.legacy_app_name)), "HomeFragment"); drawerSelected = 1; } break; case 2: if (drawerSelected != position) { switchFragment(getString(R.string.nav_overlays), "OverlaysFragment"); drawerSelected = 2; } break; case 3: if (drawerSelected != position) { switchFragment(getString(R.string.nav_sounds), "SoundsFragment"); drawerSelected = 3; } break; case 5: switchFragment(getString(R.string.nav_overlay_manager), "AdvancedManagerFragment"); drawerSelected = 5; break; case 6: switchFragment(getString(R.string.nav_manage), "ManageFragment"); drawerSelected = 6; break; case 7: switchFragment(getString(R.string.nav_backup_restore), "ProfileFragment"); drawerSelected = 7; break; case 9: if (drawerSelected != position) { switchFragment(getString(R.string.nav_troubleshooting), "TroubleshootingFragment"); drawerSelected = 10; } break; case 10: if (drawerSelected != position) { switchFragment(getString(R.string.nav_team), "TeamFragment"); drawerSelected = 10; } break; case 11: switchFragmentToLicenses(getString(R.string.nav_opensource), fragment); drawerSelected = 11; break; case 12: if (drawerSelected != position) { switchFragment(getString(R.string.nav_settings), "SettingsFragment"); drawerSelected = 12; } break; } } return false; } }).withSelectedItem(1).withSelectedItemByPosition(1).build(); } if (!Root.requestRootAccess()) { final ProgressDialog mProgressDialog = new ProgressDialog(this, R.style.SubstratumBuilder_ActivityTheme); mProgressDialog.setIndeterminate(false); mProgressDialog.setCancelable(false); mProgressDialog.show(); mProgressDialog.setContentView(R.layout.root_rejected_loader); final float radius = 5; final View decorView = getWindow().getDecorView(); final View rootView = decorView.findViewById(android.R.id.content); final Drawable windowBackground = decorView.getBackground(); BlurView blurView = (BlurView) mProgressDialog.findViewById(R.id.blurView); blurView.setupWith(rootView).windowBackground(windowBackground) .blurAlgorithm(new RenderScriptBlur(this, true)).blurRadius(radius); final TextView textView = (TextView) mProgressDialog.findViewById(R.id.timer); CountDownTimer Count = new CountDownTimer(5000, 1000) { public void onTick(long millisUntilFinished) { if ((millisUntilFinished / 1000) > 1) { textView.setText(String.format(getString(R.string.root_rejected_timer_plural), (millisUntilFinished / 1000) + "")); } else { textView.setText(String.format(getString(R.string.root_rejected_timer_singular), (millisUntilFinished / 1000) + "")); } } public void onFinish() { mProgressDialog.dismiss(); finish(); } }; Count.start(); } permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE); permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_PHONE_STATE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.System.canWrite(getApplicationContext())) { Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + MainActivity.this.getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else { Log.d("SubstratumLogger", "Substratum was granted " + "'android.permission.WRITE_SETTINGS' " + "permissions for system runtime code execution."); } } if (permissionCheck == PackageManager.PERMISSION_GRANTED) { // permission already granted, allow the program to continue running File directory = new File(Environment.getExternalStorageDirectory(), "/.substratum/"); if (!directory.exists()) { directory.mkdirs(); } File cacheDirectory = new File(getCacheDir(), "/SubstratumBuilder/"); if (!cacheDirectory.exists()) { cacheDirectory.mkdirs(); } if (permissionCheck2 == PackageManager.PERMISSION_GRANTED) { // permission already granted, allow the program to continue running // Set the first option to start at app boot drawer.setSelectionAtPosition(1); } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_PHONE_STATE }, PERMISSIONS_REQUEST_READ_PHONE_STATE); } } else { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } // Now, let's grab root on the helper Intent rootIntent = new Intent(Intent.ACTION_MAIN); rootIntent.setAction("masquerade.substratum.INITIALIZE"); try { startActivity(rootIntent); } catch (RuntimeException re) { // Exception: At this point, Masquerade is not installed at all. } final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (References.checkOMS()) { if (!prefs.getBoolean("substratum_oms", true)) { Root.runCommand( "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/.substratum/"); Root.runCommand( "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/substratum/"); File directory = new File(Environment.getExternalStorageDirectory(), "/.substratum/"); if (!directory.exists()) { directory.mkdirs(); } } } else { if (prefs.getBoolean("substratum_oms", true)) { Root.runCommand( "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/.substratum/"); Root.runCommand( "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/substratum/"); File directory = new File(Environment.getExternalStorageDirectory(), "/.substratum/"); if (!directory.exists()) { directory.mkdirs(); } } } printFCMtoken(); }
From source file:org.alfresco.mobile.android.ui.operation.OperationWaitingDialogFragment.java
public Dialog onCreateDialog(final Bundle savedInstanceState) { if (getArguments() != null) { operationType = getArguments().getInt(ARGUMENT_TYPEID); intentId = getArguments().getString(ARGUMENT_INTENTID); iconId = getArguments().getInt(ARGUMENT_ICONID); title = getArguments().getString(ARGUMENT_TITLEID); message = getArguments().getString(ARGUMENT_MESSAGEID); parent = getArguments().getParcelable(ARGUMENT_NODEID); nbItems = getArguments().getInt(ARGUMENT_SIZE); operationId = getArguments().getString(ARGUMENT_OPERATIONID); }//w w w . j ava 2 s . co m ProgressDialog dialog = new ProgressDialog(getActivity()); if (iconId == 0) { iconId = R.drawable.ic_application_logo; } dialog.setIcon(iconId); dialog.setTitle(title); if (message == null) { message = getString(R.string.waiting_operations); } dialog.setMessage(message); boolean indeterminate = true; if (nbItems > 0) { dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setProgress(0); dialog.setMax(nbItems); indeterminate = false; } else { dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); } dialog.setIndeterminate(indeterminate); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (operationId != null) { Operator.with(getActivity()).cancel(operationId); } dialog.dismiss(); } }); getActivity().getLoaderManager().restartLoader(this.hashCode(), null, this); return dialog; }
From source file:fm.smart.r1.activity.ItemActivity.java
public void addToList(final String item_id) { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Adding item to study list ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread add = new Thread() { public void run() { ItemActivity.add_item_result = addItemToList(Main.default_study_list_id, item_id, ItemActivity.this); myOtherProgressDialog.dismiss(); ItemActivity.this.runOnUiThread(new Thread() { public void run() { final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create(); dialog.setTitle(ItemActivity.add_item_result.getTitle()); dialog.setMessage(ItemActivity.add_item_result.getMessage()); ItemActivity.add_item_result = null; dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }//from w w w . ja v a2 s .c o m }); dialog.show(); } }); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { add.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { add.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); closeMenu(); myOtherProgressDialog.show(); add.start(); }
From source file:com.synox.android.ui.activity.Uploader.java
@Override protected Dialog onCreateDialog(final int id) { final AlertDialog.Builder builder = new Builder(this); switch (id) { case DIALOG_WAITING: final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme); pDialog.setIndeterminate(false); pDialog.setCancelable(false);/*from ww w . ja va2s . co m*/ pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading)); pDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress); v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.accent), android.graphics.PorterDuff.Mode.MULTIPLY); } }); return pDialog; case DIALOG_NO_ACCOUNT: builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setTitle(R.string.uploader_wrn_no_account_title); builder.setMessage( String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name))); builder.setCancelable(false); builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) { // using string value since in API7 this // constatn is not defined // in API7 < this constatant is defined in // Settings.ADD_ACCOUNT_SETTINGS // and Settings.EXTRA_AUTHORITIES Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT); intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() }); startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT); } else { // since in API7 there is no direct call for // account setup, so we need to // show our own AccountSetupAcricity, get // desired results and setup // everything for ourself Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class); startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT); } } }); builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return builder.create(); case DIALOG_MULTIPLE_ACCOUNT: CharSequence ac[] = new CharSequence[mAccountManager .getAccountsByType(MainApp.getAccountType()).length]; for (int i = 0; i < ac.length; ++i) { ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name, false); } builder.setTitle(R.string.common_choose_account); builder.setItems(ac, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]); onAccountSet(mAccountWasRestored); dialog.dismiss(); mAccountSelected = true; mAccountSelectionShowing = false; } }); builder.setCancelable(true); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mAccountSelectionShowing = false; dialog.cancel(); finish(); } }); return builder.create(); case DIALOG_NO_STREAM: builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setTitle(R.string.uploader_wrn_no_content_title); builder.setMessage(R.string.uploader_wrn_no_content_text); builder.setCancelable(false); builder.setNegativeButton(R.string.common_cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return builder.create(); default: throw new IllegalArgumentException("Unknown dialog id: " + id); } }
From source file:fm.smart.r1.ItemActivity.java
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); // this should be called once image has been chosen by user // using requestCode to pass item id - haven't worked out any other way // to do it// w ww .java2 s . co m // if (requestCode == SELECT_IMAGE) if (resultCode == Activity.RESULT_OK) { // TODO check if user is logged in 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 = ItemActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("item_id", (String) item.getId()); startActivity(intent); // TODO in this case forcing the user to rechoose the image // seems a little // rude - should probably auto-submit here ... } else { // Bundle extras = data.getExtras(); // String sentence_id = (String) extras.get("sentence_id"); final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Uploading image ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread add_image = new Thread() { public void run() { // TODO needs to check for interruptibility String sentence_id = Integer.toString(requestCode); Uri selectedImage = data.getData(); // Bitmap bitmap = Media.getBitmap(getContentResolver(), // selectedImage); // ByteArrayOutputStream bytes = new // ByteArrayOutputStream(); // bitmap.compress(Bitmap.CompressFormat.JPEG, 40, // bytes); // ByteArrayInputStream fileInputStream = new // ByteArrayInputStream( // bytes.toByteArray()); // TODO Might have to save to file system first to get // this // to work, // argh! // could think of it as saving to cache ... // add image to sentence FileInputStream is = null; FileOutputStream os = null; File file = null; ContentResolver resolver = getContentResolver(); try { Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes); // ByteArrayInputStream bais = new // ByteArrayInputStream(bytes.toByteArray()); // FileDescriptor fd = // resolver.openFileDescriptor(selectedImage, // "r").getFileDescriptor(); // is = new FileInputStream(fd); String filename = "test.jpg"; File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE); file = new File(dir, filename); os = new FileOutputStream(file); // while (bais.available() > 0) { // / os.write(bais.read()); // } os.write(bytes.toByteArray()); os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (IOException e) { } } if (is != null) { try { is.close(); } catch (IOException e) { } } } // File file = new // File(Uri.decode(selectedImage.toString())); // ensure item is in users default list ItemActivity.add_item_result = new AddItemResult(Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item.getId(), null)); Result result = ItemActivity.add_item_result; if (ItemActivity.add_item_result.success() || ItemActivity.add_item_result.alreadyInList()) { // ensure sentence is in users default goal ItemActivity.add_sentence_goal_result = new AddSentenceResult( Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id, item.getId(), sentence_id, null)); result = ItemActivity.add_sentence_goal_result; if (ItemActivity.add_sentence_goal_result.success()) { String media_entity = "http://test.com/test.jpg"; String author = "tansaku"; String author_url = "http://smart.fm/users/tansaku"; Log.d("DEBUG-IMAGE-URI", selectedImage.toString()); ItemActivity.add_image_result = addImage(file, media_entity, author, author_url, "1", sentence_id, (String) item.getId(), Main.default_study_goal_id); result = ItemActivity.add_image_result; } } final Result display = result; myOtherProgressDialog.dismiss(); ItemActivity.this.runOnUiThread(new Thread() { public void run() { final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create(); dialog.setTitle(display.getTitle()); dialog.setMessage(display.getMessage()); dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (ItemActivity.add_image_result != null && ItemActivity.add_image_result.success()) { ItemListActivity.loadItem(ItemActivity.this, item.getId().toString()); } } }); dialog.show(); } }); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { add_image.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { add_image.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); closeMenu(); myOtherProgressDialog.show(); add_image.start(); } } }
From source file:bikebadger.RideFragment.java
public void SaveGPXFileOnNewThreadWithDialog(final String path) { final ProgressDialog pd = new ProgressDialog(getActivity()); pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); final File gpxFile = new File(path); pd.setMessage("Saving \"" + gpxFile.getName() + "\""); pd.setIndeterminate(true); pd.setCancelable(false);//from w w w.j a v a2 s .c om pd.show(); Thread mThread = new Thread() { @Override public void run() { mRideManager.ExportWaypointsTrack(); pd.dismiss(); if (mRideManager.mWaypoints != null) { getActivity().runOnUiThread(new Runnable() { public void run() { //Toast.makeText(getActivity(), "Hello", Toast.LENGTH_SHORT).show(); MyToast.Show(getActivity(), "\"" + gpxFile.getName() + "\" saved", Color.BLACK); } }); } } }; mThread.start(); }
From source file:com.xabber.android.ui.activity.ContactList.java
@Override protected Dialog onCreateDialog(int id) { super.onCreateDialog(id); switch (id) { case DIALOG_CLOSE_APPLICATION_ID: ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setMessage(getString(R.string.application_state_closing)); progressDialog.setOnCancelListener(new OnCancelListener() { @Override/*from w w w. j a va2s .c o m*/ public void onCancel(DialogInterface dialog) { finish(); } }); progressDialog.setIndeterminate(true); return progressDialog; default: return null; } }
From source file:bikebadger.RideFragment.java
public void OpenGPXFileOnNewThreadWithDialog(final String path) { final ProgressDialog pd = new ProgressDialog(getActivity()); pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); final File gpxFile = new File(path); pd.setMessage("Loading \"" + gpxFile.getName() + "\""); pd.setIndeterminate(true); pd.setCancelable(false);//from w w w. j av a 2 s . c om pd.show(); Thread mThread = new Thread() { @Override public void run() { mRideManager.OpenGPXFile(path); pd.dismiss(); if (mRideManager.mWaypoints != null) { getActivity().runOnUiThread(new Runnable() { public void run() { //Toast.makeText(getActivity(), "Hello", Toast.LENGTH_SHORT).show(); MyToast.Show(getActivity(), "\"" + gpxFile.getName() + "\" loaded (" + mRideManager.mWaypoints.size() + ")", Color.BLACK); } }); } } }; mThread.start(); }