List of usage examples for android.content Intent CATEGORY_OPENABLE
String CATEGORY_OPENABLE
To view the source code for android.content Intent CATEGORY_OPENABLE.
Click Source Link
From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java
/** * Get image from photo library.//from w ww. j a v a 2 s . c o m * * @param quality * Compression quality hint (0-100: 0=low quality & high * compression, 100=compress of max quality) * @param srcType * The album to get image from. * @param returnType * Set the type of image to return. */ // TODO: Images selected from SDCARD don't display correctly, but from // CAMERA ALBUM do! public void getImage(int srcType, int returnType) { final int srcTypeFinal = srcType; final int returnTypeFinal = returnType; String[] choices = { "Upload a Photo", "Upload a Video" }; AlertDialog.Builder builder = new AlertDialog.Builder(this.cordova.getActivity()); builder.setItems(choices, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Log.d(LOG_TAG, "Index #" + which + " chosen."); Intent intent = new Intent(); if (which == 0) { // set up photo intent WsiCameraLauncher.this.mediaType = PICTURE; intent.setType("image/*"); } else if (which == 1) { // set up video intent WsiCameraLauncher.this.mediaType = VIDEO; intent.setType("video/*"); } else { WsiCameraLauncher.this.failPicture("Selection cancelled."); return; } intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); if (WsiCameraLauncher.this.cordova != null) { WsiCameraLauncher.this.cordova.startActivityForResult((CordovaPlugin) WsiCameraLauncher.this, Intent.createChooser(intent, new String("Pick")), (srcTypeFinal + 1) * 16 + returnTypeFinal + 1); } } }); builder.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) { dialog.cancel(); WsiCameraLauncher.this.failPicture("Selection cancelled."); return true; } return false; } }); builder.show(); }
From source file:jackpal.androidterm.TermPreferences.java
@SuppressLint("NewApi") private void doPrefsPicker() { AlertDialog.Builder bld = new AlertDialog.Builder(this); bld.setIcon(android.R.drawable.ic_dialog_info); bld.setMessage(this.getString(R.string.prefs_dialog_rw)); bld.setNeutralButton(this.getString(R.string.prefs_write), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss();/* w w w. ja v a 2 s . c o m*/ confirmWritePrefs(); } }); bld.setPositiveButton(this.getString(R.string.prefs_read), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("text/xml"); startActivityForResult(intent, REQUEST_PREFS_READ_PICKER); } }); bld.setNegativeButton(this.getString(android.R.string.no), null); bld.create().show(); }
From source file:com.vuze.android.remote.AndroidUtils.java
public static void openFileChooser(Activity activity, String mimeType, int requestCode) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(mimeType);/*from ww w.j a va 2 s . c o m*/ intent.addCategory(Intent.CATEGORY_OPENABLE); // special intent for Samsung file manager Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA"); sIntent.putExtra("CONTENT_TYPE", mimeType); sIntent.addCategory(Intent.CATEGORY_DEFAULT); Intent chooserIntent; if (activity.getPackageManager().resolveActivity(sIntent, 0) != null) { chooserIntent = Intent.createChooser(sIntent, "Open file"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent }); } else { chooserIntent = Intent.createChooser(intent, "Open file"); } if (chooserIntent != null) { try { activity.startActivityForResult(chooserIntent, requestCode); return; } catch (android.content.ActivityNotFoundException ex) { } } Toast.makeText(activity.getApplicationContext(), activity.getResources().getString(R.string.no_file_chooser), Toast.LENGTH_SHORT).show(); }
From source file:com.remobile.camera.CameraLauncher.java
/** * Get image from photo library./*from ww w . j a va2 s . c om*/ * * @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) * @param srcType The album to get image from. * @param returnType Set the type of image to return. * @param encodingType */ // TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do! // TODO: Images from kitkat filechooser not going into crop function public void getImage(int srcType, int returnType, int encodingType) { Intent intent = new Intent(); String title = GET_PICTURE; croppedUri = null; if (this.mediaType == PICTURE) { intent.setType("image/*"); if (this.allowEdit) { intent.setAction(Intent.ACTION_PICK); intent.putExtra("crop", "true"); if (targetWidth > 0) { intent.putExtra("outputX", targetWidth); } if (targetHeight > 0) { intent.putExtra("outputY", targetHeight); } if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) { intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); } File photo = createCaptureFile(encodingType); croppedUri = Uri.fromFile(photo); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, croppedUri); } else { intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } } else if (this.mediaType == VIDEO) { intent.setType("video/*"); title = GET_VIDEO; intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } else if (this.mediaType == ALLMEDIA) { // I wanted to make the type 'image/*, video/*' but this does not work on all versions // of android so I had to go with the wildcard search. intent.setType("*/*"); title = GET_All; intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } if (this.cordova != null) { this.cordova.startActivityForResult((CordovaPlugin) this, Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1); } }
From source file:mgks.os.webview.MainActivity.java
@SuppressLint({ "SetJavaScriptEnabled", "WrongViewCast" }) @Override// w ww . j av a2 s . com protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.w("READ_PERM = ", Manifest.permission.READ_EXTERNAL_STORAGE); Log.w("WRITE_PERM = ", Manifest.permission.WRITE_EXTERNAL_STORAGE); //Prevent the app from being started again when it is still alive in the background if (!isTaskRoot()) { finish(); return; } setContentView(R.layout.activity_main); asw_view = findViewById(R.id.msw_view); final SwipeRefreshLayout pullfresh = findViewById(R.id.pullfresh); if (ASWP_PULLFRESH) { pullfresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { pull_fresh(); pullfresh.setRefreshing(false); } }); asw_view.getViewTreeObserver() .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { if (asw_view.getScrollY() == 0) { pullfresh.setEnabled(true); } else { pullfresh.setEnabled(false); } } }); } else { pullfresh.setRefreshing(false); pullfresh.setEnabled(false); } if (ASWP_PBAR) { asw_progress = findViewById(R.id.msw_progress); } else { findViewById(R.id.msw_progress).setVisibility(View.GONE); } asw_loading_text = findViewById(R.id.msw_loading_text); Handler handler = new Handler(); //Launching app rating request if (ASWP_RATINGS) { handler.postDelayed(new Runnable() { public void run() { get_rating(); } }, 1000 * 60); //running request after few moments } //Getting basic device information get_info(); //Getting GPS location of device if given permission if (ASWP_LOCATION && !check_permission(1)) { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, loc_perm); } get_location(); //Webview settings; defaults are customized for best performance WebSettings webSettings = asw_view.getSettings(); if (!ASWP_OFFLINE) { webSettings.setJavaScriptEnabled(ASWP_JSCRIPT); } webSettings.setSaveFormData(ASWP_SFORM); webSettings.setSupportZoom(ASWP_ZOOM); webSettings.setGeolocationEnabled(ASWP_LOCATION); webSettings.setAllowFileAccess(true); webSettings.setAllowFileAccessFromFileURLs(true); webSettings.setAllowUniversalAccessFromFileURLs(true); webSettings.setUseWideViewPort(true); webSettings.setDomStorageEnabled(true); asw_view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return true; } }); asw_view.setHapticFeedbackEnabled(false); asw_view.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) { if (!check_permission(2)) { ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE }, file_perm); } else { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setMimeType(mimeType); String cookies = CookieManager.getInstance().getCookie(url); request.addRequestHeader("cookie", cookies); request.addRequestHeader("User-Agent", userAgent); request.setDescription(getString(R.string.dl_downloading)); request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType)); request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType)); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); assert dm != null; dm.enqueue(request); Toast.makeText(getApplicationContext(), getString(R.string.dl_downloading2), Toast.LENGTH_LONG) .show(); } } }); if (Build.VERSION.SDK_INT >= 21) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark)); asw_view.setLayerType(View.LAYER_TYPE_HARDWARE, null); webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } else if (Build.VERSION.SDK_INT >= 19) { asw_view.setLayerType(View.LAYER_TYPE_HARDWARE, null); } asw_view.setVerticalScrollBarEnabled(false); asw_view.setWebViewClient(new Callback()); //Rendering the default URL aswm_view(ASWV_URL, false); asw_view.setWebChromeClient(new WebChromeClient() { //Handling input[type="file"] requests for android API 16+ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { if (ASWP_FUPLOAD) { asw_file_message = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType(ASWV_F_TYPE); if (ASWP_MULFILE) { i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); } startActivityForResult(Intent.createChooser(i, getString(R.string.fl_chooser)), asw_file_req); } } //Handling input[type="file"] requests for android API 21+ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (check_permission(2) && check_permission(3)) { if (ASWP_FUPLOAD) { if (asw_file_path != null) { asw_file_path.onReceiveValue(null); } asw_file_path = filePathCallback; Intent takePictureIntent = null; if (ASWP_CAMUPLOAD) { takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(MainActivity.this.getPackageManager()) != null) { File photoFile = null; try { photoFile = create_image(); takePictureIntent.putExtra("PhotoPath", asw_cam_message); } catch (IOException ex) { Log.e(TAG, "Image file creation failed", ex); } if (photoFile != null) { asw_cam_message = "file:" + photoFile.getAbsolutePath(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } else { takePictureIntent = null; } } } Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT); if (!ASWP_ONLYCAM) { contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE); contentSelectionIntent.setType(ASWV_F_TYPE); if (ASWP_MULFILE) { contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); } } 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, getString(R.string.fl_chooser)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray); startActivityForResult(chooserIntent, asw_file_req); } return true; } else { get_file(); return false; } } //Getting webview rendering progress @Override public void onProgressChanged(WebView view, int p) { if (ASWP_PBAR) { asw_progress.setProgress(p); if (p == 100) { asw_progress.setProgress(0); } } } // overload the geoLocations permissions prompt to always allow instantly as app permission was granted previously public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { if (Build.VERSION.SDK_INT < 23 || check_permission(1)) { // location permissions were granted previously so auto-approve callback.invoke(origin, true, false); } else { // location permissions not granted so request them ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, loc_perm); } } }); if (getIntent().getData() != null) { String path = getIntent().getDataString(); /* If you want to check or use specific directories or schemes or hosts Uri data = getIntent().getData(); String scheme = data.getScheme(); String host = data.getHost(); List<String> pr = data.getPathSegments(); String param1 = pr.get(0); */ aswm_view(path, false); } }
From source file:com.orange.ocara.ui.activity.ListAuditActivity.java
private void createNewDocument(String path) { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(/*from ww w . jav a2 s . co m*/ MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(path))); startActivityForResult(intent, ACTION_CREATE_NEW_DOCUMENT); }
From source file:org.csploit.android.plugins.LoginCracker.java
public void onCreate(Bundle savedInstanceState) { SharedPreferences themePrefs = getSharedPreferences("THEME", 0); Boolean isDark = themePrefs.getBoolean("isDark", false); if (isDark)/*from www. ja va 2 s.c om*/ setTheme(R.style.DarkTheme); else setTheme(R.style.AppTheme); super.onCreate(savedInstanceState); if (!System.getCurrentTarget().hasOpenPorts()) new FinishDialog(getString(R.string.warning), getString(R.string.no_open_ports), this).show(); final ArrayList<String> ports = new ArrayList<String>(); for (Port port : System.getCurrentTarget().getOpenPorts()) ports.add(Integer.toString(port.getNumber())); mProtocolAdapter = new ProtocolAdapter(); mPortSpinner = (Spinner) findViewById(R.id.portSpinner); mPortSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ports)); mPortSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) { String port = (String) adapter.getItemAtPosition(position); int protocolIndex = mProtocolAdapter.getIndexByPort(port); if (protocolIndex != -1) mProtocolSpinner.setSelection(protocolIndex); } public void onNothingSelected(AdapterView<?> arg0) { } }); mProtocolSpinner = (Spinner) findViewById(R.id.protocolSpinner); mProtocolSpinner.setAdapter(new ProtocolAdapter()); mProtocolSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) { int portIndex = mProtocolAdapter.getPortIndexByProtocol(position); if (portIndex != -1) mPortSpinner.setSelection(portIndex); } public void onNothingSelected(AdapterView<?> arg0) { } }); mCharsetSpinner = (Spinner) findViewById(R.id.charsetSpinner); mCharsetSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, CHARSETS)); mCharsetSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) { if (CHARSETS_MAPPING[position] == null) { new InputDialog(getString(R.string.custom_charset), getString(R.string.enter_chars_wanted), LoginCracker.this, new InputDialogListener() { @Override public void onInputEntered(String input) { input = input.trim(); if (!input.isEmpty()) mCustomCharset = "aA1" + input; else { mCustomCharset = null; mCharsetSpinner.setSelection(0); } } }).show(); } else mCustomCharset = null; } public void onNothingSelected(AdapterView<?> arg0) { } }); mUserSpinner = (Spinner) findViewById(R.id.userSpinner); mUserSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, USERNAMES)); mUserSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) { String user = (String) adapter.getItemAtPosition(position); if (user != null && user.equals("-- ADD --")) { new InputDialog(getString(R.string.add_username), getString(R.string.enter_username), LoginCracker.this, new InputDialogListener() { @Override public void onInputEntered(String input) { USERNAMES = Arrays.copyOf(USERNAMES, USERNAMES.length + 1); USERNAMES[USERNAMES.length - 1] = "-- ADD --"; USERNAMES[USERNAMES.length - 2] = input; mUserSpinner.setAdapter(new ArrayAdapter<String>(LoginCracker.this, android.R.layout.simple_spinner_item, USERNAMES)); mUserSpinner.setSelection(USERNAMES.length - 2); } }).show(); } } public void onNothingSelected(AdapterView<?> arg0) { } }); mMaxSpinner = (Spinner) findViewById(R.id.maxSpinner); mMaxSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, LENGTHS)); mMinSpinner = (Spinner) findViewById(R.id.minSpinner); mMinSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, LENGTHS)); mStartButton = (FloatingActionButton) findViewById(R.id.startFAB); mStatusText = (TextView) findViewById(R.id.statusText); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mActivity = (ProgressBar) findViewById(R.id.activity); mProgressBar.setMax(100); mReceiver = new AttemptReceiver(); mStartButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mRunning) { setStoppedState(); } else { setStartedState(); } } }); mWordlistPicker = new Intent(); mWordlistPicker.addCategory(Intent.CATEGORY_OPENABLE); mWordlistPicker.setType("text/*"); mWordlistPicker.setAction(Intent.ACTION_GET_CONTENT); if (Build.VERSION.SDK_INT >= 11) mWordlistPicker.putExtra(Intent.EXTRA_LOCAL_ONLY, true); }
From source file:ru.innopolis.architecture.gstar.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mUsername = ANONYMOUS;/*from ww w . j a v a2 s. c o m*/ // Initialize Firebase Auth mFirebaseAuth = FirebaseAuth.getInstance(); mFirebaseUser = mFirebaseAuth.getCurrentUser(); if (mFirebaseUser == null) { // Not signed in, launch the Sign In activity startActivity(new Intent(this, SignInActivity.class)); finish(); return; } else { mUsername = mFirebaseUser.getDisplayName(); mPhotoUrl = mFirebaseUser.getPhotoUrl().toString(); } mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API).build(); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView); mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager.setStackFromEnd(true); mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference(); mFirebaseAdapter = new FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder>(FriendlyMessage.class, R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) { @Override protected FriendlyMessage parseSnapshot(DataSnapshot snapshot) { FriendlyMessage friendlyMessage = super.parseSnapshot(snapshot); if (friendlyMessage != null) { friendlyMessage.setId(snapshot.getKey()); } return friendlyMessage; } @Override protected void populateViewHolder(final MessageViewHolder viewHolder, FriendlyMessage friendlyMessage, int position) { mProgressBar.setVisibility(ProgressBar.INVISIBLE); if (friendlyMessage.getText() != null) { viewHolder.messageTextView.setText(friendlyMessage.getText()); viewHolder.messageTextView.setVisibility(TextView.VISIBLE); viewHolder.messageImageView.setVisibility(ImageView.GONE); } else { String imageUrl = friendlyMessage.getImageUrl(); if (imageUrl.startsWith("gs://")) { StorageReference storageReference = FirebaseStorage.getInstance() .getReferenceFromUrl(imageUrl); storageReference.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() { @Override public void onComplete(@NonNull Task<Uri> task) { if (task.isSuccessful()) { String downloadUrl = task.getResult().toString(); Glide.with(viewHolder.messageImageView.getContext()).load(downloadUrl) .into(viewHolder.messageImageView); } else { Log.w(TAG, "Getting download url was not successful.", task.getException()); } } }); } else { Glide.with(viewHolder.messageImageView.getContext()).load(friendlyMessage.getImageUrl()) .into(viewHolder.messageImageView); } viewHolder.messageImageView.setVisibility(ImageView.VISIBLE); viewHolder.messageTextView.setVisibility(TextView.GONE); } viewHolder.messengerTextView.setText(friendlyMessage.getName()); if (friendlyMessage.getPhotoUrl() == null) { viewHolder.messengerImageView.setImageDrawable( ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_account_circle_black_36dp)); } else { Glide.with(MainActivity.this).load(friendlyMessage.getPhotoUrl()) .into(viewHolder.messengerImageView); } if (friendlyMessage.getText() != null) { // write this message to the on-device index FirebaseAppIndex.getInstance().update(getMessageIndexable(friendlyMessage)); } // log a view action on it FirebaseUserActions.getInstance().end(getMessageViewAction(friendlyMessage)); } }; mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { super.onItemRangeInserted(positionStart, itemCount); int friendlyMessageCount = mFirebaseAdapter.getItemCount(); int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition(); // If the recycler view is initially being loaded or the user is at the bottom of the list, scroll // to the bottom of the list to show the newly added message. if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1) && lastVisiblePosition == (positionStart - 1))) { mMessageRecyclerView.scrollToPosition(positionStart); } } }); mMessageRecyclerView.setLayoutManager(mLinearLayoutManager); mMessageRecyclerView.setAdapter(mFirebaseAdapter); // Initialize Firebase Measurement. mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); // Initialize Firebase Remote Config. mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); // Define Firebase Remote Config Settings. FirebaseRemoteConfigSettings firebaseRemoteConfigSettings = new FirebaseRemoteConfigSettings.Builder() .setDeveloperModeEnabled(true).build(); // Define default config values. Defaults are used when fetched config values are not // available. Eg: if an error occurred fetching values from the server. Map<String, Object> defaultConfigMap = new HashMap<>(); defaultConfigMap.put("friendly_msg_length", 100L); // Apply config settings and default values. mFirebaseRemoteConfig.setConfigSettings(firebaseRemoteConfigSettings); mFirebaseRemoteConfig.setDefaults(defaultConfigMap); // Fetch remote config. fetchConfig(); mMessageEditText = (EditText) findViewById(R.id.messageEditText); mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter( mSharedPreferences.getInt(CodelabPreferences.FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) }); mMessageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (charSequence.toString().trim().length() > 0) { mSendButton.setEnabled(true); } else { mSendButton.setEnabled(false); } } @Override public void afterTextChanged(Editable editable) { } }); mAddMessageImageView = (ImageView) findViewById(R.id.addMessageImageView); mAddMessageImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(intent, REQUEST_IMAGE); } }); mSendButton = (Button) findViewById(R.id.sendButton); mSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl, null); mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(friendlyMessage); mMessageEditText.setText(""); mFirebaseAnalytics.logEvent(MESSAGE_SENT_EVENT, null); } }); }
From source file:org.thezero.qrfi.SuperAwesomeCardFragment.java
public void selectFromGallery() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, GALLERY_INTENT_CALLED); } else {/*w w w . j av a2 s . c o m*/ Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(intent, GALLERY_KITKAT_INTENT_CALLED); } }
From source file:com.cordova.photo.CameraLauncher.java
/** * Get image from photo library.//from ww w . j a va 2s . c o m * * @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) * @param srcType The album to get image from. * @param returnType Set the type of image to return. * @param encodingType */ // TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do! // TODO: Images from kitkat filechooser not going into crop function public void getImage(int srcType, int returnType, int encodingType) { Intent intent = new Intent(); String title = GET_PICTURE; croppedUri = null; if (this.mediaType == PICTURE) { intent.setType("image/*"); if (this.allowEdit) { intent.setAction(Intent.ACTION_PICK); intent.putExtra("crop", "true"); if (targetWidth > 0) { intent.putExtra("outputX", targetWidth); } if (targetHeight > 0) { intent.putExtra("outputY", targetHeight); } if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) { intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); } File photo = createCaptureFile(encodingType); croppedUri = Uri.fromFile(photo); intent.putExtra(MediaStore.EXTRA_OUTPUT, croppedUri); } else { intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } } else if (this.mediaType == VIDEO) { intent.setType("video/*"); title = GET_VIDEO; intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } else if (this.mediaType == ALLMEDIA) { // I wanted to make the type 'image/*, video/*' but this does not work on all versions // of android so I had to go with the wildcard search. intent.setType("*/*"); title = GET_All; intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } if (this.activity != null) { this.activity.startActivityForResult(Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1); } }