Example usage for android.content Intent ACTION_PICK

List of usage examples for android.content Intent ACTION_PICK

Introduction

In this page you can find the example usage for android.content Intent ACTION_PICK.

Prototype

String ACTION_PICK

To view the source code for android.content Intent ACTION_PICK.

Click Source Link

Document

Activity Action: Pick an item from the data, returning what was selected.

Usage

From source file:com.kll.collect.android.activities.FormEntryActivity.java

/**
 * Returns the instance that was just filled out to the calling activity, if
 * requested./*from www  .ja v  a  2  s . co  m*/
 */
private void finishReturnInstance() {
    FormController formController = Collect.getInstance().getFormController();
    String action = getIntent().getAction();
    if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_EDIT.equals(action)) {
        // caller is waiting on a picked form
        String selection = InstanceColumns.INSTANCE_FILE_PATH + "=?";
        String[] selectionArgs = { formController.getInstancePath().getAbsolutePath() };
        Cursor c = null;
        try {
            c = getContentResolver().query(InstanceColumns.CONTENT_URI, null, selection, selectionArgs, null);
            if (c.getCount() > 0) {
                // should only be one...
                c.moveToFirst();
                String id = c.getString(c.getColumnIndex(InstanceColumns._ID));
                Uri instance = Uri.withAppendedPath(InstanceColumns.CONTENT_URI, id);
                setResult(RESULT_OK, new Intent().setData(instance));
            }
        } finally {
            if (c != null) {
                c.close();
            }
        }
    }
    finish();
}

From source file:org.telegram.ui.ChatActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case android.R.id.home:
        finishFragment();/*  w  ww. j  a  v  a  2s.co m*/
        break;
    case R.id.attach_photo: {
        try {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File image = Utilities.generatePicturePath();
            if (image != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
                currentPicturePath = image.getAbsolutePath();
            }
            startActivityForResult(takePictureIntent, 0);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        break;
    }
    case R.id.attach_gallery: {
        try {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, 1);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        break;
    }
    case R.id.attach_video: {
        try {
            Intent pickIntent = new Intent();
            pickIntent.setType("video/*");
            pickIntent.setAction(Intent.ACTION_GET_CONTENT);
            pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
            Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            File video = Utilities.generateVideoPath();
            if (video != null) {
                if (android.os.Build.VERSION.SDK_INT > 16) {
                    takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
                }
                takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
                currentPicturePath = video.getAbsolutePath();
            }
            Intent chooserIntent = Intent.createChooser(pickIntent, "");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takeVideoIntent });

            startActivityForResult(chooserIntent, 2);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        break;
    }
    case R.id.attach_location: {
        if (!isGoogleMapsInstalled()) {
            return true;
        }
        LocationActivity fragment = new LocationActivity();
        ((ApplicationActivity) parentActivity).presentFragment(fragment, "location", false);
        break;
    }
    case R.id.attach_document: {
        DocumentSelectActivity fragment = new DocumentSelectActivity();
        fragment.delegate = this;
        ((ApplicationActivity) parentActivity).presentFragment(fragment, "document", false);
        break;
    }
    }
    return true;
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

private void showPickContact(int requestCode) {
    Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
    boolean actionAvailable = getPackageManager().resolveActivity(intent, 0) != null;
    if (actionAvailable) {
        startActivityForResult(intent, requestCode);
    } else {/*  w  w  w  . j a va 2  s .com*/
        showNote(SafeSlinger.getUnsupportedFeatureString("Pick Contact"));
    }
}

From source file:kr.wdream.ui.ChatActivity.java

private void processSelectedAttach(int which) {
    if (which == attach_photo || which == attach_gallery || which == attach_document || which == attach_video) {
        String action;/*from   w  w w . j av a  2  s.c  om*/
        if (currentChat != null) {
            if (currentChat.participants_count > MessagesController.getInstance().groupBigSize) {
                if (which == attach_photo || which == attach_gallery) {
                    action = "bigchat_upload_photo";
                } else {
                    action = "bigchat_upload_document";
                }
            } else {
                if (which == attach_photo || which == attach_gallery) {
                    action = "chat_upload_photo";
                } else {
                    action = "chat_upload_document";
                }
            }
        } else {
            if (which == attach_photo || which == attach_gallery) {
                action = "pm_upload_photo";
            } else {
                action = "pm_upload_document";
            }
        }
        if (!MessagesController.isFeatureEnabled(action, ChatActivity.this)) {
            return;
        }
    }

    if (which == attach_photo) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity()
                .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 19);
            return;
        }
        try {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File image = AndroidUtilities.generatePicturePath();
            if (image != null) {
                if (Build.VERSION.SDK_INT >= 24) {
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(
                            getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image));
                    takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                } else {
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
                }
                currentPicturePath = image.getAbsolutePath();
            }
            startActivityForResult(takePictureIntent, 0);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    } else if (which == attach_gallery) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    4);
            return;
        }
        PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(false,
                currentEncryptedChat == null
                        || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46,
                true, ChatActivity.this);
        fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
            @Override
            public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions,
                    ArrayList<ArrayList<TLRPC.InputDocument>> masks,
                    ArrayList<MediaController.SearchImage> webPhotos) {
                SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, replyingMessageObject,
                        captions, masks);
                SendMessagesHelper.prepareSendingPhotosSearch(webPhotos, dialog_id, replyingMessageObject);
                showReplyPanel(false, null, null, null, false, true);
                DraftQuery.cleanDraft(dialog_id, true);
            }

            @Override
            public void startPhotoSelectActivity() {
                try {
                    Intent videoPickerIntent = new Intent();
                    videoPickerIntent.setType("video/*");
                    videoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
                    videoPickerIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1536));

                    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("image/*");
                    Intent chooserIntent = Intent.createChooser(photoPickerIntent, null);
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { videoPickerIntent });

                    startActivityForResult(chooserIntent, 1);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }

            @Override
            public boolean didSelectVideo(String path) {
                if (Build.VERSION.SDK_INT >= 16) {
                    return !openVideoEditor(path, true, true);
                } else {
                    SendMessagesHelper.prepareSendingVideo(path, 0, 0, 0, 0, null, dialog_id,
                            replyingMessageObject, null);
                    showReplyPanel(false, null, null, null, false, true);
                    DraftQuery.cleanDraft(dialog_id, true);
                    return true;
                }
            }
        });
        presentFragment(fragment);
    } else if (which == attach_video) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity()
                .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 20);
            return;
        }
        try {
            Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            File video = AndroidUtilities.generateVideoPath();
            if (video != null) {
                if (Build.VERSION.SDK_INT >= 24) {
                    takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(
                            getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", video));
                    takeVideoIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                } else if (Build.VERSION.SDK_INT >= 18) {
                    takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
                }
                takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1536));
                currentPicturePath = video.getAbsolutePath();
            }
            startActivityForResult(takeVideoIntent, 2);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    } else if (which == attach_location) {
        if (!AndroidUtilities.isGoogleMapsInstalled(ChatActivity.this)) {
            return;
        }
        LocationActivity fragment = new LocationActivity();
        fragment.setDelegate(new LocationActivity.LocationActivityDelegate() {
            @Override
            public void didSelectLocation(TLRPC.MessageMedia location) {
                SendMessagesHelper.getInstance().sendMessage(location, dialog_id, replyingMessageObject, null,
                        null);
                moveScrollToLastMessage();
                showReplyPanel(false, null, null, null, false, true);
                DraftQuery.cleanDraft(dialog_id, true);
                if (paused) {
                    scrollToTopOnResume = true;
                }
            }
        });
        presentFragment(fragment);
    } else if (which == attach_document) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    4);
            return;
        }
        DocumentSelectActivity fragment = new DocumentSelectActivity();
        fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() {
            @Override
            public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files) {
                activity.finishFragment();
                SendMessagesHelper.prepareSendingDocuments(files, files, null, null, dialog_id,
                        replyingMessageObject);
                showReplyPanel(false, null, null, null, false, true);
                DraftQuery.cleanDraft(dialog_id, true);
            }

            @Override
            public void startDocumentSelectActivity() {
                try {
                    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("*/*");
                    startActivityForResult(photoPickerIntent, 21);
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        });
        presentFragment(fragment);
    } else if (which == attach_audio) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    4);
            return;
        }
        AudioSelectActivity fragment = new AudioSelectActivity();
        fragment.setDelegate(new AudioSelectActivity.AudioSelectActivityDelegate() {
            @Override
            public void didSelectAudio(ArrayList<MessageObject> audios) {
                SendMessagesHelper.prepareSendingAudioDocuments(audios, dialog_id, replyingMessageObject);
                showReplyPanel(false, null, null, null, false, true);
                DraftQuery.cleanDraft(dialog_id, true);
            }
        });
        presentFragment(fragment);
    } else if (which == attach_contact) {
        if (Build.VERSION.SDK_INT >= 23) {
            if (getParentActivity().checkSelfPermission(
                    Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
                getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, 5);
                return;
            }
        }
        try {
            Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
            intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
            startActivityForResult(intent, 31);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    }
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.icn_message_send:
        String message = messageText.getText().toString();
        MsgGroups msgGroup = new MsgGroups();
        try {/*  w  w  w . j a v a2s .  c  o  m*/
            Calendar fecha = Calendar.getInstance();
            JSONArray targets = new JSONArray();
            JSONArray contactos = new JSONArray(grupo.targets);
            String contactosId = null;
            if (SpeakSocket.mSocket != null) {
                if (SpeakSocket.mSocket.connected()) {
                    for (int i = 0; i < contactos.length(); i++) {
                        JSONObject contacto = contactos.getJSONObject(i);
                        JSONObject newContact = new JSONObject();
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", contacto.getString("name")).executeSingle();
                        if (contact != null) {
                            if (!contact.idContacto.equals(u.id)) {
                                if (translate)
                                    newContact.put("lang", contact.lang);
                                else
                                    newContact.put("lang", u.lang);
                                newContact.put("name", contact.idContacto);
                                newContact.put("screen_name", contact.screenName);
                                newContact.put("status", 1);
                                contactosId += contact.idContacto;
                                targets.put(targets.length(), newContact);
                            }
                        }
                    }
                } else {
                    for (int i = 0; i < contactos.length(); i++) {
                        JSONObject contacto = contactos.getJSONObject(i);
                        JSONObject newContact = new JSONObject();
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", contacto.getString("name")).executeSingle();
                        if (contact != null) {
                            if (!contact.idContacto.equals(u.id)) {
                                if (translate)
                                    newContact.put("lang", contact.lang);
                                else
                                    newContact.put("lang", u.lang);
                                newContact.put("name", contact.idContacto);
                                newContact.put("screen_name", contact.screenName);
                                newContact.put("status", -1);
                                contactosId += contact.idContacto;
                                targets.put(targets.length(), newContact);
                            }
                        }
                    }
                }
            }
            msgGroup.grupoId = grupo.grupoId;
            msgGroup.mensajeId = u.id + grupo.grupoId + fecha.getTimeInMillis()
                    + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
            msgGroup.emisor = u.id;
            msgGroup.receptores = targets.toString();
            msgGroup.mensaje = message;
            msgGroup.emisorEmail = u.email;
            msgGroup.emisorLang = u.lang;
            msgGroup.translation = translate;
            msgGroup.emitedAt = fecha.getTimeInMillis();
            msgGroup.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_TEXT));
            if (tiempoMensaje) {
                msgGroup.delay = temporizadorSeek.getValue();
            } else {
                msgGroup.delay = 0;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        msgGroup.save();
        messageText.setText("");
        showNewMessage(msgGroup);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        tiempoMensaje = false;
        break;
    case R.id.message_text:
        SharedPreferences settings = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings.getInt("INPUTKEY", 0) == 0) {
            customKeyboardLayout.setVisibility(View.GONE);
            customKeyboardAudio.setVisibility(View.GONE);
            keyboardLayout.setVisibility(View.GONE);
            isShowCustomKeyboard = false;
            if (tiempoMensaje) {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
            } else {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
            }
            isShowKeyboard = true;
        } else {
            if (!isShowKeyboard) {
                if (!isShowCustomKeyboard) {
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                } else {
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                }
            }
        }
        break;
    case R.id.icn_message_translate:
        if (translate)
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_red));
        else
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_gray));
        //initAdapter();
        break;
    case R.id.icn_message_clock:
        tiempoMensaje = false;
        temporizadorAcept.setVisibility(View.INVISIBLE);
        temporizadorSeek.setInitPosition(0);
        SharedPreferences settings1 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings1.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardAudio.setVisibility(View.GONE);
            if (!customKeyboardLayout.isShown()) {
                customKeyboardLayout.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
                tiempoMensaje = false;
                if (tiempoMensaje) {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
            }
        }
        break;
    case R.id.temporizador_cancel:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        temporizadorSeek.setInitPosition(0);
        isShowCustomKeyboard = false;
        tiempoMensaje = false;
        break;
    case R.id.temporizador_acept:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        temporizadorSeek.setInitPosition(15);
        isShowCustomKeyboard = false;
        tiempoMensaje = true;
        if (!isShowKeyboard) {
            if (!isShowCustomKeyboard) {
                messagesListScroll.setVerticalScrollBarEnabled(false);
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                ((MainActivity) activity).setOnBackPressedListener(null);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            } else {
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                ((MainActivity) activity).setOnBackPressedListener(null);
                messagesListScroll.setVerticalScrollBarEnabled(false);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id._1:
        temporizadorSeek.setInitPosition(15);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._2:
        temporizadorSeek.setInitPosition(30);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._3:
        temporizadorSeek.setInitPosition(45);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._4:
        temporizadorSeek.setInitPosition(60);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._5:
        temporizadorSeek.setInitPosition(75);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._6:
        temporizadorSeek.setInitPosition(90);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._7:
        temporizadorSeek.setInitPosition(105);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._8:
        temporizadorSeek.setInitPosition(120);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._9:
        temporizadorSeek.setInitPosition(135);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._10:
        temporizadorSeek.setInitPosition(150);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._11:
        temporizadorSeek.setInitPosition(165);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._12:
        temporizadorSeek.setInitPosition(180);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id.adjunt_image:
        System.gc();
        getFragmentManager().beginTransaction().replace(R.id.container3, CreatePollFragment.newInstance(grupo))
                .addToBackStack(null).commit();
        ((MainActivity) activity).setOnBackPressedListener(null);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_contact:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(i, 34);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_audio:
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        AnimatorSet set3 = new AnimatorSet();
        set3.playTogether(ObjectAnimator.ofFloat(adjuntLayout, "alpha", 1, 0));
        set3.setDuration(200).start();
        SharedPreferences settings2 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings2.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set4 = new AnimatorSet();
                set4.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set4.setDuration(220).start();
                set4.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set5 = new AnimatorSet();
                set5.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set5.setDuration(220).start();
                set5.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardLayout.setVisibility(View.GONE);
            if (!customKeyboardAudio.isShown()) {
                customKeyboardAudio.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id.adjunt_photo:
        System.gc();
        choosePicture();
        break;
    case R.id.adjunt_video:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent videoPickerIntent = new Intent(Intent.ACTION_PICK);
        videoPickerIntent.setType("video/*");
        startActivityForResult(videoPickerIntent, 18);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_location:
        adjuntLayout.setVisibility(View.GONE);
        hideKeyBoard();
        menuAdjunt = false;
        milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        List<String> allProviders = milocManager.getAllProviders();
        boolean gpsProvider = false;
        boolean netProvider = false;
        for (String providerName : allProviders) {
            if (providerName.equals(LocationManager.GPS_PROVIDER)) {
                gpsProvider = true;
            }
            if (providerName.equals(LocationManager.NETWORK_PROVIDER)) {
                netProvider = true;
            }
        }
        checkCountryLocation(gpsProvider, netProvider);
        break;
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public void openGallery(final ActionListener response, int type) {
    if (!isGalleryTypeSupported(type)) {
        throw new IllegalArgumentException("Gallery type " + type + " not supported on this platform.");
    }/*from   w w  w  .  j a  va2  s.co m*/
    if (getActivity() == null) {
        throw new RuntimeException("Cannot open galery in background mode");
    }
    if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
            "This is required to browse the photos")) {
        return;
    }
    if (editInProgress()) {
        stopEditing(true);
    }
    final boolean multi;
    switch (type) {
    case Display.GALLERY_ALL_MULTI:
        multi = true;
        type = Display.GALLERY_ALL;
        break;
    case Display.GALLERY_VIDEO_MULTI:
        multi = true;
        type = Display.GALLERY_VIDEO;
        break;
    case Display.GALLERY_IMAGE_MULTI:
        multi = true;
        type = Display.GALLERY_IMAGE;
        break;
    case -9998:
        multi = true;
        type = -9999;
        break;
    default:
        multi = false;
    }

    callback = new EventDispatcher();
    callback.addListener(response);
    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    if (multi) {
        galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    }
    if (type == Display.GALLERY_VIDEO) {
        galleryIntent.setType("video/*");
    } else if (type == Display.GALLERY_IMAGE) {
        galleryIntent.setType("image/*");
    } else if (type == Display.GALLERY_ALL) {
        galleryIntent.setType("image/* video/*");
    } else if (type == -9999) {
        galleryIntent = new Intent();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
            galleryIntent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        } else {
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
        }
        galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);

        // set MIME type for image
        galleryIntent.setType("*/*");
        galleryIntent.putExtra(Intent.EXTRA_MIME_TYPES,
                Display.getInstance().getProperty("android.openGallery.accept", "*/*").split(","));
    } else {
        galleryIntent.setType("*/*");
    }
    this.getActivity().startActivityForResult(galleryIntent, multi ? OPEN_GALLERY_MULTI : OPEN_GALLERY);
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

private void choosePicture() {
    if (cameraDialog == null) {
        LayoutInflater dialogInflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View dialogView = dialogInflater.inflate(R.layout.dialog_camera_gallery, null);
        TextView camera = (TextView) dialogView.findViewById(R.id.dialog_camera);
        TextView gallery = (TextView) dialogView.findViewById(R.id.dialog_gallery);
        TFCache.apply(activity, camera, TFCache.TF_SPEAKALL);
        TFCache.apply(activity, gallery, TFCache.TF_SPEAKALL);
        final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView)
                .setCancelable(true);/* w w  w .ja  v a  2  s . c  o  m*/
        cameraDialog = dialogBuilder.show();
        camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cameraDialog.dismiss();
                dontClose = true;
                ((MainActivity) activity).dontClose = true;
                hideKeyBoard();
                File imagesFolder = new File(
                        Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
                imagesFolder.mkdirs();
                menuAdjunt = false;
                adjuntLayout.setVisibility(View.GONE);
                dateToCamera = Calendar.getInstance().getTimeInMillis();
                File image = new File(imagesFolder, dateToCamera + ".png");
                Uri uriSavedImage = Uri.fromFile(image);
                pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                startActivityForResult(pictureActionIntent, 23);
            }
        });
        gallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cameraDialog.dismiss();
                dontClose = true;
                ((MainActivity) activity).dontClose = true;
                hideKeyBoard();
                menuAdjunt = false;
                adjuntLayout.setVisibility(View.GONE);
                pictureActionIntent = new Intent(Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(pictureActionIntent, 1);
            }
        });
        cameraDialog.setCanceledOnTouchOutside(true);
    } else {
        cameraDialog.show();
    }
}

From source file:org.telegram.ui.PassportActivity.java

private void processSelectedAttach(int which) {
    if (which == attach_photo) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity()
                .checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.CAMERA }, 19);
            return;
        }//w  w w  .ja va  2s.com
        try {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File image = AndroidUtilities.generatePicturePath();
            if (image != null) {
                if (Build.VERSION.SDK_INT >= 24) {
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(
                            getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", image));
                    takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                } else {
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
                }
                currentPicturePath = image.getAbsolutePath();
            }
            startActivityForResult(takePictureIntent, 0);
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else if (which == attach_gallery) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    4);
            return;
        }
        PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(0, false, false, null);
        fragment.setCurrentAccount(currentAccount);
        fragment.setMaxSelectedPhotos(getMaxSelectedDocuments());
        fragment.setAllowSearchImages(false);
        fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
            @Override
            public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos) {
                processSelectedFiles(photos);
            }

            @Override
            public void startPhotoSelectActivity() {
                try {
                    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("image/*");
                    startActivityForResult(photoPickerIntent, 1);
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
        });
        presentFragment(fragment);
    } else if (which == attach_document) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            getParentActivity().requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    4);
            return;
        }
        DocumentSelectActivity fragment = new DocumentSelectActivity(false);
        fragment.setCurrentAccount(currentAccount);
        fragment.setCanSelectOnlyImageFiles(true);
        fragment.setMaxSelectedFiles(getMaxSelectedDocuments());
        fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() {
            @Override
            public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files) {
                activity.finishFragment();
                ArrayList<SendMessagesHelper.SendingMediaInfo> arrayList = new ArrayList<>();
                for (int a = 0, count = files.size(); a < count; a++) {
                    SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
                    info.path = files.get(a);
                    arrayList.add(info);
                }
                processSelectedFiles(arrayList);
            }

            @Override
            public void startDocumentSelectActivity() {
                try {
                    Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
                    if (Build.VERSION.SDK_INT >= 18) {
                        photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                    }
                    photoPickerIntent.setType("*/*");
                    startActivityForResult(photoPickerIntent, 21);
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
        });
        presentFragment(fragment);
    }
}