List of usage examples for android.content Intent ACTION_GET_CONTENT
String ACTION_GET_CONTENT
To view the source code for android.content Intent ACTION_GET_CONTENT.
Click Source Link
From source file:com.layer.atlas.messenger.AtlasMessagesScreen.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.uiHandler = new Handler(); this.app = (MessengerApp) getApplication(); setContentView(R.layout.atlas_screen_messages); boolean convIsNew = getIntent().getBooleanExtra(EXTRA_CONVERSATION_IS_NEW, false); String convUri = getIntent().getStringExtra(EXTRA_CONVERSATION_URI); if (convUri != null) { Uri uri = Uri.parse(convUri);/*from w w w. jav a 2 s . c om*/ conv = app.getLayerClient().getConversation(uri); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(convUri.hashCode()); // Clear notifications for this Conversation } participantsPicker = (AtlasParticipantPicker) findViewById(R.id.atlas_screen_messages_participants_picker); participantsPicker.init(new String[] { app.getLayerClient().getAuthenticatedUserId() }, app.getParticipantProvider()); if (convIsNew) { participantsPicker.setVisibility(View.VISIBLE); } messageComposer = (AtlasMessageComposer) findViewById(R.id.atlas_screen_messages_message_composer); messageComposer.init(app.getLayerClient(), conv); messageComposer.setListener(new AtlasMessageComposer.Listener() { public boolean beforeSend(Message message) { boolean conversationReady = ensureConversationReady(); if (!conversationReady) return false; // push preparePushMetadata(message); return true; } }); messageComposer.registerMenuItem("Photo", new OnClickListener() { public void onClick(View v) { if (!ensureConversationReady()) return; Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); String fileName = "cameraOutput" + System.currentTimeMillis() + ".jpg"; photoFile = new File(getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES), fileName); final Uri outputUri = Uri.fromFile(photoFile); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); if (debug) Log.w(TAG, "onClick() requesting photo to file: " + fileName + ", uri: " + outputUri); startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA); } }); messageComposer.registerMenuItem("Image", new OnClickListener() { public void onClick(View v) { if (!ensureConversationReady()) return; // in onCreate or any event where your want the user to select a file Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_CODE_GALLERY); } }); messageComposer.registerMenuItem("Location", new OnClickListener() { public void onClick(View v) { if (!ensureConversationReady()) return; if (lastKnownLocation == null) { Toast.makeText(v.getContext(), "Inserting Location: Location is unknown yet", Toast.LENGTH_SHORT).show(); return; } String locationString = "{\"lat\":" + lastKnownLocation.getLatitude() + ", \"lon\":" + lastKnownLocation.getLongitude() + "}"; MessagePart part = app.getLayerClient().newMessagePart(Atlas.MIME_TYPE_ATLAS_LOCATION, locationString.getBytes()); Message message = app.getLayerClient().newMessage(Arrays.asList(part)); preparePushMetadata(message); conv.send(message); if (debug) Log.w(TAG, "onSendLocation() loc: " + locationString); } }); messagesList = (AtlasMessagesList) findViewById(R.id.atlas_screen_messages_messages_list); messagesList.init(app.getLayerClient(), app.getParticipantProvider()); if (USE_QUERY) { Query<Message> query = Query.builder(Message.class) .predicate(new Predicate(Message.Property.CONVERSATION, Predicate.Operator.EQUAL_TO, conv)) .sortDescriptor(new SortDescriptor(Message.Property.POSITION, SortDescriptor.Order.ASCENDING)) .build(); messagesList.setQuery(query); } else { messagesList.setConversation(conv); } messagesList.setItemClickListener(new ItemClickListener() { public void onItemClick(Cell cell) { if (Atlas.MIME_TYPE_ATLAS_LOCATION.equals(cell.messagePart.getMimeType())) { String jsonLonLat = new String(cell.messagePart.getData()); JSONObject json; try { json = new JSONObject(jsonLonLat); double lon = json.getDouble("lon"); double lat = json.getDouble("lat"); Intent openMapIntent = new Intent(Intent.ACTION_VIEW); String uriString = String.format(Locale.ENGLISH, "geo:%f,%f?z=%d&q=%f,%f", lat, lon, 18, lat, lon); final Uri geoUri = Uri.parse(uriString); openMapIntent.setData(geoUri); if (openMapIntent.resolveActivity(getPackageManager()) != null) { startActivity(openMapIntent); if (debug) Log.w(TAG, "onItemClick() starting Map: " + uriString); } else { if (debug) Log.w(TAG, "onItemClick() No Activity to start Map: " + geoUri); } } catch (JSONException ignored) { } } else if (cell instanceof ImageCell) { Intent intent = new Intent(AtlasMessagesScreen.this.getApplicationContext(), AtlasImageViewScreen.class); app.setParam(intent, cell); startActivity(intent); } } }); typingIndicator = (AtlasTypingIndicator) findViewById(R.id.atlas_screen_messages_typing_indicator); typingIndicator.init(conv, new AtlasTypingIndicator.DefaultTypingIndicatorCallback(app.getParticipantProvider())); // location manager for inserting locations: this.locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); prepareActionBar(); }
From source file:com.smc.jobs4smcyouth.Fragments.Print.PrintLayoutFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(com.smc.jobs4smcyouth.R.layout.fragment_print_layout, container, false);/* w w w. ja v a2 s . com*/ filePickerLayout = (RelativeLayout) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.filePickerLayout); RadioGroup layoutRadioGroup = (RadioGroup) inflatedView .findViewById(com.smc.jobs4smcyouth.R.id.layoutRadioGroup); layoutRadioGroup.setOnCheckedChangeListener(this); onCheckedChanged(layoutRadioGroup, layoutRadioGroup.getCheckedRadioButtonId()); RadioGroup layoutMarginRadioGroup = (RadioGroup) inflatedView .findViewById(com.smc.jobs4smcyouth.R.id.layoutMarginRadioGroup); layoutMarginRadioGroup.setOnCheckedChangeListener(this); onCheckedChanged(layoutMarginRadioGroup, layoutMarginRadioGroup.getCheckedRadioButtonId()); SwitchCompat metricsSwitch = (SwitchCompat) inflatedView .findViewById(com.smc.jobs4smcyouth.R.id.metricsRadioGroup); metricsSwitch.setOnCheckedChangeListener(this); onCheckedChanged(metricsSwitch, metricsSwitch.isChecked()); RadioGroup contentRadioGroup = (RadioGroup) inflatedView .findViewById(com.smc.jobs4smcyouth.R.id.contentRadioGroup); contentRadioGroup.setOnCheckedChangeListener(this); onCheckedChanged(contentRadioGroup, contentRadioGroup.getCheckedRadioButtonId()); RadioGroup deviceIdRadioGroup = (RadioGroup) inflatedView .findViewById(com.smc.jobs4smcyouth.R.id.deviceIdRadioGroup); deviceIdRadioGroup.setOnCheckedChangeListener(this); onCheckedChanged(deviceIdRadioGroup, deviceIdRadioGroup.getCheckedRadioButtonId()); tagText = (EditText) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.tagEditText); valueText = (EditText) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.valueEditText); LinearLayout customData = (LinearLayout) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.customData); showCustomData = customData.getVisibility() == View.VISIBLE; FloatingActionButton printButton = (FloatingActionButton) inflatedView .findViewById(com.smc.jobs4smcyouth.R.id.printBtn); printButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { continueButtonClicked(v); } }); Button buttonPick = (Button) inflatedView.findViewById(com.smc.jobs4smcyouth.R.id.buttonPick); buttonPick.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(getContentMimeType()); startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICKFILE_RESULT_CODE); } }); mediaSize5x7 = new PrintAttributes.MediaSize("na_5x7_5x7in", "5 x 7", 5000, 7000); return inflatedView; }
From source file:it.feio.android.omninotes.SettingsFragment.java
@SuppressWarnings("deprecation") @Override/*from w w w. jav a 2 s . c o m*/ public void onResume() { super.onResume(); // Export notes Preference export = findPreference("settings_export_data"); if (export != null) { export.setOnPreferenceClickListener(arg0 -> { // Inflate layout LayoutInflater inflater = getActivity().getLayoutInflater(); View v = inflater.inflate(R.layout.dialog_backup_layout, null); // Finds actually saved backups names PermissionsHelper.requestPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_external_storage, activity.findViewById(R.id.crouton_handle), () -> export(v)); return false; }); } // Import notes Preference importData = findPreference("settings_import_data"); if (importData != null) { importData.setOnPreferenceClickListener(arg0 -> { // Finds actually saved backups names PermissionsHelper.requestPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE, R.string.permission_external_storage, activity.findViewById(R.id.crouton_handle), this::importNotes); return false; }); } // Import notes from Springpad export zip file Preference importFromSpringpad = findPreference("settings_import_from_springpad"); if (importFromSpringpad != null) { importFromSpringpad.setOnPreferenceClickListener(arg0 -> { Intent intent; intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("application/zip"); if (!IntentChecker.isAvailable(getActivity(), intent, null)) { Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT) .show(); return false; } startActivityForResult(intent, SPRINGPAD_IMPORT); return false; }); } // Preference syncWithDrive = findPreference("settings_backup_drive"); // importFromSpringpad.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference arg0) { // Intent intent; // intent = new Intent(Intent.ACTION_GET_CONTENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // intent.setType("application/zip"); // if (!IntentChecker.isAvailable(getActivity(), intent, null)) { // Crouton.makeText(getActivity(), R.string.feature_not_available_on_this_device, // ONStyle.ALERT).show(); // return false; // } // startActivityForResult(intent, SPRINGPAD_IMPORT); // return false; // } // }); // Swiping action final SwitchPreference swipeToTrash = (SwitchPreference) findPreference("settings_swipe_to_trash"); if (swipeToTrash != null) { if (prefs.getBoolean("settings_swipe_to_trash", false)) { swipeToTrash.setChecked(true); swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); swipeToTrash.setChecked(false); } swipeToTrash.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); } swipeToTrash.setChecked((Boolean) newValue); return false; }); } // Show uncategorized notes in menu final SwitchPreference showUncategorized = (SwitchPreference) findPreference( Constants.PREF_SHOW_UNCATEGORIZED); if (showUncategorized != null) { showUncategorized.setOnPreferenceChangeListener((preference, newValue) -> { showUncategorized.setChecked((Boolean) newValue); return false; }); } // Show Automatically adds location to new notes final SwitchPreference autoLocation = (SwitchPreference) findPreference(Constants.PREF_AUTO_LOCATION); if (autoLocation != null) { autoLocation.setOnPreferenceChangeListener((preference, newValue) -> { autoLocation.setChecked((Boolean) newValue); return false; }); } // Maximum video attachment size final EditTextPreference maxVideoSize = (EditTextPreference) findPreference("settings_max_video_size"); if (maxVideoSize != null) { String maxVideoSizeValue = prefs.getString("settings_max_video_size", getString(R.string.not_set)); maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(maxVideoSizeValue)); maxVideoSize.setOnPreferenceChangeListener((preference, newValue) -> { maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(newValue)); prefs.edit().putString("settings_max_video_size", newValue.toString()).commit(); return false; }); } // Set notes' protection password Preference password = findPreference("settings_password"); if (password != null) { password.setOnPreferenceClickListener(preference -> { Intent passwordIntent = new Intent(getActivity(), PasswordActivity.class); startActivity(passwordIntent); return false; }); } // Use password to grant application access final SwitchPreference passwordAccess = (SwitchPreference) findPreference("settings_password_access"); if (passwordAccess != null) { if (prefs.getString(Constants.PREF_PASSWORD, null) == null) { passwordAccess.setEnabled(false); passwordAccess.setChecked(false); } else { passwordAccess.setEnabled(true); } passwordAccess.setOnPreferenceChangeListener((preference, newValue) -> { BaseActivity.requestPassword(getActivity(), passwordConfirmed -> { if (passwordConfirmed) { passwordAccess.setChecked((Boolean) newValue); } }); return false; }); } // Languages ListPreference lang = (ListPreference) findPreference("settings_language"); if (lang != null) { String languageName = getResources().getConfiguration().locale.getDisplayName(); lang.setSummary(languageName.substring(0, 1).toUpperCase(getResources().getConfiguration().locale) + languageName.substring(1, languageName.length())); lang.setOnPreferenceChangeListener((preference, value) -> { OmniNotes.updateLanguage(getActivity(), value.toString()); MiscUtils.restartApp(getActivity().getApplicationContext(), MainActivity.class); return false; }); } // Text size final ListPreference textSize = (ListPreference) findPreference("settings_text_size"); if (textSize != null) { int textSizeIndex = textSize.findIndexOfValue(prefs.getString("settings_text_size", "default")); String textSizeString = getResources().getStringArray(R.array.text_size)[textSizeIndex]; textSize.setSummary(textSizeString); textSize.setOnPreferenceChangeListener((preference, newValue) -> { int textSizeIndex1 = textSize.findIndexOfValue(newValue.toString()); String checklistString = getResources().getStringArray(R.array.text_size)[textSizeIndex1]; textSize.setSummary(checklistString); prefs.edit().putString("settings_text_size", newValue.toString()).commit(); textSize.setValueIndex(textSizeIndex1); return false; }); } // Application's colors final ListPreference colorsApp = (ListPreference) findPreference("settings_colors_app"); if (colorsApp != null) { int colorsAppIndex = colorsApp .findIndexOfValue(prefs.getString("settings_colors_app", Constants.PREF_COLORS_APP_DEFAULT)); String colorsAppString = getResources().getStringArray(R.array.colors_app)[colorsAppIndex]; colorsApp.setSummary(colorsAppString); colorsApp.setOnPreferenceChangeListener((preference, newValue) -> { int colorsAppIndex1 = colorsApp.findIndexOfValue(newValue.toString()); String colorsAppString1 = getResources().getStringArray(R.array.colors_app)[colorsAppIndex1]; colorsApp.setSummary(colorsAppString1); prefs.edit().putString("settings_colors_app", newValue.toString()).commit(); colorsApp.setValueIndex(colorsAppIndex1); return false; }); } // Checklists final ListPreference checklist = (ListPreference) findPreference("settings_checked_items_behavior"); if (checklist != null) { int checklistIndex = checklist .findIndexOfValue(prefs.getString("settings_checked_items_behavior", "0")); String checklistString = getResources().getStringArray(R.array.checked_items_behavior)[checklistIndex]; checklist.setSummary(checklistString); checklist.setOnPreferenceChangeListener((preference, newValue) -> { int checklistIndex1 = checklist.findIndexOfValue(newValue.toString()); String checklistString1 = getResources() .getStringArray(R.array.checked_items_behavior)[checklistIndex1]; checklist.setSummary(checklistString1); prefs.edit().putString("settings_checked_items_behavior", newValue.toString()).commit(); checklist.setValueIndex(checklistIndex1); return false; }); } // Widget's colors final ListPreference colorsWidget = (ListPreference) findPreference("settings_colors_widget"); if (colorsWidget != null) { int colorsWidgetIndex = colorsWidget .findIndexOfValue(prefs.getString("settings_colors_widget", Constants.PREF_COLORS_APP_DEFAULT)); String colorsWidgetString = getResources().getStringArray(R.array.colors_widget)[colorsWidgetIndex]; colorsWidget.setSummary(colorsWidgetString); colorsWidget.setOnPreferenceChangeListener((preference, newValue) -> { int colorsWidgetIndex1 = colorsWidget.findIndexOfValue(newValue.toString()); String colorsWidgetString1 = getResources() .getStringArray(R.array.colors_widget)[colorsWidgetIndex1]; colorsWidget.setSummary(colorsWidgetString1); prefs.edit().putString("settings_colors_widget", newValue.toString()).commit(); colorsWidget.setValueIndex(colorsWidgetIndex1); return false; }); } // Notification snooze delay final EditTextPreference snoozeDelay = (EditTextPreference) findPreference( "settings_notification_snooze_delay"); if (snoozeDelay != null) { String snooze = prefs.getString("settings_notification_snooze_delay", Constants.PREF_SNOOZE_DEFAULT); snooze = TextUtils.isEmpty(snooze) ? Constants.PREF_SNOOZE_DEFAULT : snooze; snoozeDelay.setSummary(String.valueOf(snooze) + " " + getString(R.string.minutes)); snoozeDelay.setOnPreferenceChangeListener((preference, newValue) -> { String snoozeUpdated = TextUtils.isEmpty(String.valueOf(newValue)) ? Constants.PREF_SNOOZE_DEFAULT : String.valueOf(newValue); snoozeDelay.setSummary(snoozeUpdated + " " + getString(R.string.minutes)); prefs.edit().putString("settings_notification_snooze_delay", snoozeUpdated).apply(); return false; }); } // NotificationServiceListener shortcut final Preference norificationServiceListenerPreference = findPreference( "settings_notification_service_listener"); if (norificationServiceListenerPreference != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { getPreferenceScreen().removePreference(norificationServiceListenerPreference); } } // Changelog Preference changelog = findPreference("settings_changelog"); if (changelog != null) { changelog.setOnPreferenceClickListener(arg0 -> { AnalyticsHelper.trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_changelog"); new MaterialDialog.Builder(activity).customView(R.layout.activity_changelog, false) .positiveText(R.string.ok).build().show(); return false; }); // Retrieval of installed app version to write it as summary PackageInfo pInfo; String versionString = ""; try { pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); versionString = pInfo.versionName; } catch (NameNotFoundException e) { Log.e(Constants.TAG, "Error retrieving version", e); } changelog.setSummary(versionString); } // Settings reset Preference resetData = findPreference("reset_all_data"); if (resetData != null) { resetData.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(activity).content(R.string.reset_all_data_confirmation) .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { prefs.edit().clear().commit(); File db = getActivity().getDatabasePath(Constants.DATABASE_NAME); StorageHelper.delete(getActivity(), db.getAbsolutePath()); File attachmentsDir = StorageHelper.getAttachmentDir(getActivity()); StorageHelper.delete(getActivity(), attachmentsDir.getAbsolutePath()); File cacheDir = StorageHelper.getCacheDir(getActivity()); StorageHelper.delete(getActivity(), cacheDir.getAbsolutePath()); MiscUtils.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Instructions Preference instructions = findPreference("settings_tour_show_again"); if (instructions != null) { instructions.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(getActivity()) .content(getString(R.string.settings_tour_show_again_summary) + "?") .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog materialDialog) { AnalyticsHelper.trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_tour_show_again"); prefs.edit().putBoolean(Constants.PREF_TOUR_COMPLETE, false).commit(); MiscUtils.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Donations // Preference donation = findPreference("settings_donation"); // if (donation != null) { // donation.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // // ArrayList<ImageAndTextItem> options = new ArrayList<ImageAndTextItem>(); // options.add(new ImageAndTextItem(R.drawable.ic_paypal, getString(R.string.paypal))); // options.add(new ImageAndTextItem(R.drawable.ic_bitcoin, getString(R.string.bitcoin))); // // alertDialogBuilder // .setAdapter(new ImageAndTextAdapter(getActivity(), options), // new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // switch (which) { // case 0: // Intent intentPaypal = new Intent(Intent.ACTION_VIEW); // intentPaypal.setData(Uri.parse(getString(R.string.paypal_url))); // startActivity(intentPaypal); // break; // case 1: // Intent intentBitcoin = new Intent(Intent.ACTION_VIEW); // intentBitcoin.setData(Uri.parse(getString(R.string.bitcoin_url))); // startActivity(intentBitcoin); // break; // } // } // }); // // // // create alert dialog // AlertDialog alertDialog = alertDialogBuilder.create(); // // show it // alertDialog.show(); // return false; // } // }); // } }
From source file:com.dycody.android.idealnote.SettingsFragment.java
@SuppressWarnings("deprecation") @Override/* w ww .j a v a 2 s. com*/ public void onResume() { super.onResume(); // Export notes Preference export = findPreference("settings_export_data"); if (export != null) { export.setOnPreferenceClickListener(arg0 -> { // Inflate layout LayoutInflater inflater = getActivity().getLayoutInflater(); View v = inflater.inflate(R.layout.dialog_backup_layout, null); // Finds actually saved backups names PermissionsHelper.requestPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_external_storage, activity.findViewById(R.id.crouton_handle), () -> export(v)); return false; }); } // Import notes Preference importData = findPreference("settings_import_data"); if (importData != null) { importData.setOnPreferenceClickListener(arg0 -> { importNotes(); return false; }); } // Import notes from Springpad export zip file Preference importFromSpringpad = findPreference("settings_import_from_springpad"); if (importFromSpringpad != null) { importFromSpringpad.setOnPreferenceClickListener(arg0 -> { Intent intent; intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("application/zip"); if (!IntentChecker.isAvailable(getActivity(), intent, null)) { Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT) .show(); return false; } startActivityForResult(intent, SPRINGPAD_IMPORT); return false; }); } // Preference syncWithDrive = findPreference("settings_backup_drive"); // importFromSpringpad.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference arg0) { // Intent intent; // intent = new Intent(Intent.ACTION_GET_CONTENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // intent.setType("application/zip"); // if (!IntentChecker.isAvailable(getActivity(), intent, null)) { // Crouton.makeText(getActivity(), R.string.feature_not_available_on_this_device, // ONStyle.ALERT).show(); // return false; // } // startActivityForResult(intent, SPRINGPAD_IMPORT); // return false; // } // }); // Swiping action final SwitchPreference swipeToTrash = (SwitchPreference) findPreference("settings_swipe_to_trash"); if (swipeToTrash != null) { if (prefs.getBoolean("settings_swipe_to_trash", false)) { swipeToTrash.setChecked(true); swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); swipeToTrash.setChecked(false); } swipeToTrash.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); } swipeToTrash.setChecked((Boolean) newValue); return false; }); } // Show uncategorized notes in menu final SwitchPreference showUncategorized = (SwitchPreference) findPreference( Constants.PREF_SHOW_UNCATEGORIZED); if (showUncategorized != null) { showUncategorized.setOnPreferenceChangeListener((preference, newValue) -> { showUncategorized.setChecked((Boolean) newValue); return false; }); } // Show Automatically adds location to new notes final SwitchPreference autoLocation = (SwitchPreference) findPreference(Constants.PREF_AUTO_LOCATION); if (autoLocation != null) { autoLocation.setOnPreferenceChangeListener((preference, newValue) -> { autoLocation.setChecked((Boolean) newValue); return false; }); } // Maximum video attachment size final EditTextPreference maxVideoSize = (EditTextPreference) findPreference("settings_max_video_size"); if (maxVideoSize != null) { String maxVideoSizeValue = prefs.getString("settings_max_video_size", getString(R.string.not_set)); maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(maxVideoSizeValue)); maxVideoSize.setOnPreferenceChangeListener((preference, newValue) -> { maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(newValue)); prefs.edit().putString("settings_max_video_size", newValue.toString()).commit(); return false; }); } // Set notes' protection password Preference password = findPreference("settings_password"); if (password != null) { password.setOnPreferenceClickListener(preference -> { Intent passwordIntent = new Intent(getActivity(), PasswordActivity.class); startActivity(passwordIntent); return false; }); } // Use password to grant application access final SwitchPreference passwordAccess = (SwitchPreference) findPreference("settings_password_access"); if (passwordAccess != null) { if (prefs.getString(Constants.PREF_PASSWORD, null) == null) { passwordAccess.setEnabled(false); passwordAccess.setChecked(false); } else { passwordAccess.setEnabled(true); } passwordAccess.setOnPreferenceChangeListener((preference, newValue) -> { PasswordHelper.requestPassword(getActivity(), passwordConfirmed -> { if (passwordConfirmed) { passwordAccess.setChecked((Boolean) newValue); } }); return false; }); } // Languages ListPreference lang = (ListPreference) findPreference("settings_language"); if (lang != null) { String languageName = getResources().getConfiguration().locale.getDisplayName(); lang.setSummary(languageName.substring(0, 1).toUpperCase(getResources().getConfiguration().locale) + languageName.substring(1, languageName.length())); lang.setOnPreferenceChangeListener((preference, value) -> { IdealNote.updateLanguage(getActivity(), value.toString()); SystemHelper.restartApp(getActivity().getApplicationContext(), MainActivity.class); return false; }); } // Text size final ListPreference textSize = (ListPreference) findPreference("settings_text_size"); if (textSize != null) { int textSizeIndex = textSize.findIndexOfValue(prefs.getString("settings_text_size", "default")); String textSizeString = getResources().getStringArray(R.array.text_size)[textSizeIndex]; textSize.setSummary(textSizeString); textSize.setOnPreferenceChangeListener((preference, newValue) -> { int textSizeIndex1 = textSize.findIndexOfValue(newValue.toString()); String checklistString = getResources().getStringArray(R.array.text_size)[textSizeIndex1]; textSize.setSummary(checklistString); prefs.edit().putString("settings_text_size", newValue.toString()).commit(); textSize.setValueIndex(textSizeIndex1); return false; }); } // Application's colors final ListPreference colorsApp = (ListPreference) findPreference("settings_colors_app"); if (colorsApp != null) { int colorsAppIndex = colorsApp .findIndexOfValue(prefs.getString("settings_colors_app", Constants.PREF_COLORS_APP_DEFAULT)); String colorsAppString = getResources().getStringArray(R.array.colors_app)[colorsAppIndex]; colorsApp.setSummary(colorsAppString); colorsApp.setOnPreferenceChangeListener((preference, newValue) -> { int colorsAppIndex1 = colorsApp.findIndexOfValue(newValue.toString()); String colorsAppString1 = getResources().getStringArray(R.array.colors_app)[colorsAppIndex1]; colorsApp.setSummary(colorsAppString1); prefs.edit().putString("settings_colors_app", newValue.toString()).commit(); colorsApp.setValueIndex(colorsAppIndex1); return false; }); } // Checklists final ListPreference checklist = (ListPreference) findPreference("settings_checked_items_behavior"); if (checklist != null) { int checklistIndex = checklist .findIndexOfValue(prefs.getString("settings_checked_items_behavior", "0")); String checklistString = getResources().getStringArray(R.array.checked_items_behavior)[checklistIndex]; checklist.setSummary(checklistString); checklist.setOnPreferenceChangeListener((preference, newValue) -> { int checklistIndex1 = checklist.findIndexOfValue(newValue.toString()); String checklistString1 = getResources() .getStringArray(R.array.checked_items_behavior)[checklistIndex1]; checklist.setSummary(checklistString1); prefs.edit().putString("settings_checked_items_behavior", newValue.toString()).commit(); checklist.setValueIndex(checklistIndex1); return false; }); } // Widget's colors final ListPreference colorsWidget = (ListPreference) findPreference("settings_colors_widget"); if (colorsWidget != null) { int colorsWidgetIndex = colorsWidget .findIndexOfValue(prefs.getString("settings_colors_widget", Constants.PREF_COLORS_APP_DEFAULT)); String colorsWidgetString = getResources().getStringArray(R.array.colors_widget)[colorsWidgetIndex]; colorsWidget.setSummary(colorsWidgetString); colorsWidget.setOnPreferenceChangeListener((preference, newValue) -> { int colorsWidgetIndex1 = colorsWidget.findIndexOfValue(newValue.toString()); String colorsWidgetString1 = getResources() .getStringArray(R.array.colors_widget)[colorsWidgetIndex1]; colorsWidget.setSummary(colorsWidgetString1); prefs.edit().putString("settings_colors_widget", newValue.toString()).commit(); colorsWidget.setValueIndex(colorsWidgetIndex1); return false; }); } // Notification snooze delay final EditTextPreference snoozeDelay = (EditTextPreference) findPreference( "settings_notification_snooze_delay"); if (snoozeDelay != null) { String snooze = prefs.getString("settings_notification_snooze_delay", Constants.PREF_SNOOZE_DEFAULT); snooze = TextUtils.isEmpty(snooze) ? Constants.PREF_SNOOZE_DEFAULT : snooze; snoozeDelay.setSummary(String.valueOf(snooze) + " " + getString(R.string.minutes)); snoozeDelay.setOnPreferenceChangeListener((preference, newValue) -> { String snoozeUpdated = TextUtils.isEmpty(String.valueOf(newValue)) ? Constants.PREF_SNOOZE_DEFAULT : String.valueOf(newValue); snoozeDelay.setSummary(snoozeUpdated + " " + getString(R.string.minutes)); prefs.edit().putString("settings_notification_snooze_delay", snoozeUpdated).apply(); return false; }); } // NotificationServiceListener shortcut final Preference norificationServiceListenerPreference = findPreference( "settings_notification_service_listener"); if (norificationServiceListenerPreference != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { getPreferenceScreen().removePreference(norificationServiceListenerPreference); } } // Changelog Preference changelog = findPreference("settings_changelog"); if (changelog != null) { changelog.setOnPreferenceClickListener(arg0 -> { ((IdealNote) getActivity().getApplication()).getAnalyticsHelper() .trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_changelog"); new MaterialDialog.Builder(activity).customView(R.layout.activity_changelog, false) .positiveText(R.string.ok).build().show(); return false; }); // Retrieval of installed app version to write it as summary PackageInfo pInfo; String versionString = ""; try { pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); versionString = pInfo.versionName + getString(R.string.version_postfix); } catch (NameNotFoundException e) { Log.e(Constants.TAG, "Error retrieving version", e); } changelog.setSummary(versionString); } // Settings reset Preference resetData = findPreference("reset_all_data"); if (resetData != null) { resetData.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(activity).content(R.string.reset_all_data_confirmation) .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { prefs.edit().clear().commit(); File db = getActivity().getDatabasePath(Constants.DATABASE_NAME); StorageHelper.delete(getActivity(), db.getAbsolutePath()); File attachmentsDir = StorageHelper.getAttachmentDir(getActivity()); StorageHelper.delete(getActivity(), attachmentsDir.getAbsolutePath()); File cacheDir = StorageHelper.getCacheDir(getActivity()); StorageHelper.delete(getActivity(), cacheDir.getAbsolutePath()); SystemHelper.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Instructions Preference instructions = findPreference("settings_tour_show_again"); if (instructions != null) { instructions.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(getActivity()) .content(getString(R.string.settings_tour_show_again_summary) + "?") .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog materialDialog) { ((IdealNote) getActivity().getApplication()).getAnalyticsHelper() .trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_tour_show_again"); prefs.edit().putBoolean(Constants.PREF_TOUR_COMPLETE, false).commit(); SystemHelper.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Donations // Preference donation = findPreference("settings_donation"); // if (donation != null) { // donation.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // // ArrayList<ImageAndTextItem> options = new ArrayList<ImageAndTextItem>(); // options.add(new ImageAndTextItem(R.drawable.ic_paypal, getString(R.string.paypal))); // options.add(new ImageAndTextItem(R.drawable.ic_bitcoin, getString(R.string.bitcoin))); // // alertDialogBuilder // .setAdapter(new ImageAndTextAdapter(getActivity(), options), // new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // switch (which) { // case 0: // Intent intentPaypal = new Intent(Intent.ACTION_VIEW); // intentPaypal.setData(Uri.parse(getString(R.string.paypal_url))); // startActivity(intentPaypal); // break; // case 1: // Intent intentBitcoin = new Intent(Intent.ACTION_VIEW); // intentBitcoin.setData(Uri.parse(getString(R.string.bitcoin_url))); // startActivity(intentBitcoin); // break; // } // } // }); // // // // create alert dialog // AlertDialog alertDialog = alertDialogBuilder.create(); // // show it // alertDialog.show(); // return false; // } // }); // } }
From source file:it.rignanese.leo.slimtwitter.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setup the sharedPreferences savedPreferences = PreferenceManager.getDefaultSharedPreferences(this); setContentView(R.layout.activity_main); //setup the floating button FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override/* www . j a v a 2 s. co m*/ public void onClick(View view) { webViewTwitter.scrollTo(0, 0);//scroll up } }); // setup the refresh layout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); swipeRefreshLayout.setColorSchemeResources(R.color.officialAzureTwitter, R.color.darkAzureSlimTwitterTheme);// set the colors swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refreshPage();//reload the page swipeRefresh = true; } }); // setup the webView webViewTwitter = (WebView) findViewById(R.id.webView); setUpWebViewDefaults(webViewTwitter);//set the settings goHome();//load homepage //WebViewClient that is the client callback. webViewTwitter.setWebViewClient(new WebViewClient() {//advanced set up // when there isn't a connetion public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { String summary = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body><h1 " + "style='text-align:center; padding-top:15%;'>" + getString(R.string.titleNoConnection) + "</h1> <h3 style='text-align:center; padding-top:1%; font-style: italic;'>" + getString(R.string.descriptionNoConnection) + "</h3> <h5 style='text-align:center; padding-top:80%; opacity: 0.3;'>" + getString(R.string.awards) + "</h5></body></html>"; webViewTwitter.loadData(summary, "text/html; charset=utf-8", "utf-8");//load a custom html page noConnectionError = true; swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing } // when I click in a external link public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url == null || url.contains("twitter.com")) { //url is ok return false; } else { //if the link doesn't contain 'twitter.com', open it using the browser startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } } //START management of loading @Override public void onPageFinished(WebView view, String url) { swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing super.onPageFinished(view, url); } //END management of loading }); //WebChromeClient for handling all chrome functions. webViewTwitter.setWebChromeClient(new WebChromeClient() { //to upload files //thanks to gauntface //https://github.com/GoogleChrome/chromium-webview-samples public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { if (mFilePathCallback != null) { mFilePathCallback.onReceiveValue(null); } mFilePathCallback = filePathCallback; Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getBaseContext().getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null; try { photoFile = createImageFile(); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); } catch (IOException ex) { // Error occurred while creating the File } // Continue only if the File was successfully created if (photoFile != null) { mCameraPhotoPath = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType("image/*"); Intent[] intentArray; if (takePictureIntent != null) { intentArray = new Intent[] { takePictureIntent }; } else { intentArray = new Intent[0]; } Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER); chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent); chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE); return true; } }); }
From source file:com.kinvey.samples.statusshare.StatusShare.java
/** * This method wraps the code to kick off the "chooser" intent, which allows user to select where to select image from *///from ww w .j a v a2s. co m public void startFilePicker() { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE); }
From source file:com.renard.ocr.documents.creation.NewDocumentActivity.java
protected void startGallery() { mAnalytics.startGallery();//from w ww .j a va2s . c o m cameraPicUri = null; Intent i; if (Build.VERSION.SDK_INT >= 19) { i = new Intent(Intent.ACTION_GET_CONTENT, null); i.addCategory(Intent.CATEGORY_OPENABLE); i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); i.setType("image/*"); i.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "image/png", "image/jpg", "image/jpeg" }); } else { i = new Intent(Intent.ACTION_GET_CONTENT, null); i.setType("image/png,image/jpg, image/jpeg"); } Intent chooser = Intent.createChooser(i, getString(R.string.image_source)); try { startActivityForResult(chooser, REQUEST_CODE_PICK_PHOTO); } catch (ActivityNotFoundException e) { Toast.makeText(this, R.string.no_gallery_found, Toast.LENGTH_LONG).show(); } }
From source file:com.android.settings.users.EditUserPhotoController.java
private boolean canChoosePhoto() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); return mImageView.getContext().getPackageManager().queryIntentActivities(intent, 0).size() > 0; }
From source file:com.survivingwithandroid.pegboard.DreamPinsActivity.java
public void onBackgroundSelected() { LayoutInflater inf = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inf.inflate(R.layout.popbkg_layout, null, false); final PopupWindow pw = new PopupWindow(v); pw.setFocusable(true);//from w w w . ja va 2 s . c o m pw.setWidth(RelativeLayout.LayoutParams.WRAP_CONTENT); pw.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT); TextView changeTxt = (TextView) v.findViewById(R.id.dlgChange); TextView resetTxt = (TextView) v.findViewById(R.id.dlgReset); TextView cancelTxt = (TextView) v.findViewById(R.id.dlgCancel); cancelTxt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pw.dismiss(); } }); resetTxt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pw.dismiss(); pinTableFrag.setBackground(R.drawable.tilebkg); } }); changeTxt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pw.dismiss(); // Start a new Intent to get the picture from the Gallery Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, SELECT_PICTURE); } }); pw.showAtLocation(v, Gravity.CENTER, 0, 0); }
From source file:com.truemind.selidpic_v20.ui.GalleryActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case MY_PERMISSION_REQUEST_STORAGE: // if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { /** Access granted (Permission granted)*/ Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE); } else {//w w w .ja va2s . c o m /** Access denied (user denied permission)*/ CommonDialog dialog = new CommonDialog(); dialog.setOnCloseListener(new CommonDialog.OnCloseListener() { @Override public void onClose(DialogInterface dialog, int which, Object data) { if (which == 1) { finish(); } } }); dialog.showDialog(this, "? .", false); } } }