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.rks.musicx.misc.utils.Helper.java

@NonNull
public static Intent imagePicker(Context context) {
    if (permissionManager.isExternalReadStorageGranted(context)) {
        Intent chooser = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        chooser.setType("image/*");
        Intent intent = Intent.createChooser(chooser, "Choose image");
        return intent;
    } else {/*w w w . j  a  v  a 2  s . c o  m*/
        Toast.makeText(context, "Permission grant failed", Toast.LENGTH_SHORT).show();
        return null;
    }
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void video_click() {
    AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
    dialog.setTitle("Video");
    dialog.setMessage("Record a video?");

    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override//from w  w  w  . ja v a 2s  .  c  o  m
        public void onClick(DialogInterface dialog, int which) {

            if (GTConstants.videoFeed.equalsIgnoreCase("dvtel")) {
                //Launch the DVTel program - TruWitness
                Intent intent = getPackageManager().getLaunchIntentForPackage("com.dvtel.mobilecam");
                if (intent != null) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            } else if (GTConstants.videoFeed.equalsIgnoreCase("milestone")) {
                //Launch the DVTel program - TruWitness
                Intent intent = getPackageManager().getLaunchIntentForPackage("com.milestonesys.mobile");
                if (intent != null) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            } else {
                // Launch an intent to capture video from MediaStore
                Intent takeVideoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);

                String path = GTConstants.sendfileFolder + Utility.createFileName() + ".mpeg";
                file_name = path;

                File file = new File(path);
                Uri outputFileUri = Uri.fromFile(file);
                takeVideoIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, outputFileUri);
                startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);
            }
        }
    });

    dialog.setNeutralButton("View", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            galleryIntent = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(galleryIntent, ACTIVITY_SELECT_VIDEO);
        }
    });

    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    dialog.show();
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void camera_click() {
    AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
    dialog.setTitle("Camera");
    dialog.setMessage("Snap a Picture?");

    dialog.setPositiveButton("Snap", new DialogInterface.OnClickListener() {
        @Override//  ww w  . j a  v  a2 s. co  m
        public void onClick(DialogInterface dialog, int which) {
            try {
                //Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                String path = GTConstants.sendfileFolder + Utility.createFileName() + ".jpg";
                file_name = path;

                File file = new File(path);
                Uri outputFileUri = Uri.fromFile(file);
                cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, outputFileUri);
                startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
            } catch (Exception e) {

            }
        }
    });

    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
    });

    dialog.setNeutralButton("View", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            galleryIntent = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(galleryIntent, ACTIVITY_SELECT_IMAGE);
        }
    });
    dialog.show();
}

From source file:com.dwdesign.tweetings.activity.ComposeActivity.java

private void pickImage() {
    final Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    try {/*from www.  jav a 2s  .  c o  m*/
        startActivityForResult(i, REQUEST_PICK_IMAGE);
    } catch (final ActivityNotFoundException e) {
        showErrorToast(this, null, e, false);
    }
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * Check whether an application exists that handles the pick activity.
 *
 * @return//  ww w. j  av  a  2s  . c om
 */
private boolean addLocationAlertPossible() {

    // Test whether intent exists for picking a location:
    PackageManager pm = getPackageManager();
    Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("geo:"));
    List<ResolveInfo> resolve_pick_location = pm.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    /*
     * for (int i = 0; i < resolve_pick_location.size(); i++) { Log.d(TAG,
     * "Activity name: " + resolve_pick_location.get(i).activityInfo.name);
     * }
     */

    // Check whether adding alerts is possible.
    intent = new Intent(Intent.ACTION_VIEW, Alert.Generic.CONTENT_URI);
    List<ResolveInfo> resolve_view_alerts = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

    boolean pick_location_possible = (resolve_pick_location.size() > 0);
    boolean view_alerts_possible = (resolve_view_alerts.size() > 0);
    if (debug) {
        Log.d(TAG, "Pick location possible: " + pick_location_possible);
    }
    if (debug) {
        Log.d(TAG, "View alerts possible: " + view_alerts_possible);
    }
    if (pick_location_possible && view_alerts_possible) {
        return true;
    }

    return false;
}

From source file:org.cryptsecure.Utility.java

/**
 * Select attachment.//from  w  w  w .j  a va 2 s . co m
 * 
 * @param activity
 *            the activity
 */
public static void selectFromGallery(Activity activity) {
    Intent intent = new Intent();
    if (Build.VERSION.SDK_INT >= 19) {
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        activity.startActivityForResult(Intent.createChooser(intent, "Select Attachment"),
                Utility.SELECT_PICTURE);

    } else {
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);
        activity.startActivityForResult(Intent.createChooser(intent, "Select Attachment"),
                Utility.SELECT_PICTURE);
    }
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Summons.NewSummon.java

private void galleryIntent() {
    if (btnClicked == summonimg) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);//
        startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE_summonimgn);
    } else if (btnClicked == complianceimg) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);//
        startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE_complianceimg);
    }// w  w  w .  j a v a  2s . c om
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    super.onContextItemSelected(item);
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case MENU_MARK_ITEM:
        markItem(menuInfo.position);//from   www . j a  va2s.  c o m
        break;
    case MENU_EDIT_ITEM:
        editItem(menuInfo.position, EditItemDialog.FieldType.ITEMNAME);
        break;
    case MENU_REMOVE_ITEM_FROM_LIST:
        removeItemFromList(menuInfo.position);
        break;
    case MENU_DELETE_ITEM:
        deleteItemDialog(menuInfo.position);
        break;
    case MENU_MOVE_ITEM:
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_PICK);
        intent.setData(ShoppingContract.Lists.CONTENT_URI);
        startActivityForResult(intent, REQUEST_PICK_LIST);
        mMoveItemPosition = menuInfo.position;
        break;
    case MENU_COPY_ITEM:
        copyItem(menuInfo.position);
        break;
    case MENU_ITEM_STORES:
        editItemStores(menuInfo.position);
        break;
    }

    return true;
}

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

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.icn_message_send:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        String message = messageText.getText().toString();
        Message msjNew = new Message();
        Calendar fecha = Calendar.getInstance();
        String id = u.id + contact.idContacto + fecha.getTimeInMillis()
                + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);

        msjNew.mensajeId = id;//from  www.  jav  a2  s .c  o  m
        msjNew.emisor = u.id;
        msjNew.receptor = contact.idContacto;
        msjNew.mensaje = message;
        msjNew.emisorEmail = u.email;
        msjNew.receptorEmail = contact.email;
        msjNew.emisorLang = u.lang;
        msjNew.receptorLang = contact.lang;
        msjNew.emitedAt = fecha.getTimeInMillis();
        msjNew.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_TEXT));
        if (tiempoMensaje)
            msjNew.delay = temporizadorSeek.getValue();
        else
            msjNew.delay = 0;
        msjNew.translation = translate;
        if (SpeakSocket.mSocket != null)
            if (SpeakSocket.mSocket.connected()) {
                msjNew.status = 1;
            } else {
                msjNew.status = -1;
            }

        msjNew.save();
        Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjNew.receptor).executeSingle();
        if (chat == null) {
            Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.receptor)
                    .executeSingle();
            Chats newChat = new Chats();
            newChat.mensajeId = msjNew.mensajeId;
            newChat.idContacto = msjNew.receptor;
            newChat.isLockedConversation = false;
            newChat.lastStatus = msjNew.status;
            newChat.email = msjNew.receptorEmail;
            if (contact != null) {
                newChat.photo = contact.photo;
                newChat.fullName = contact.fullName;
                newChat.lang = contact.lang;
                newChat.screenName = contact.screenName;
                newChat.photoload = true;
                newChat.phone = contact.phone;
            } else {
                newChat.photo = null;
                newChat.photoload = false;
                newChat.fullName = msjNew.receptorEmail;
                newChat.lang = msjNew.receptorLang;
                newChat.screenName = msjNew.receptorEmail;
                newChat.phone = null;
            }
            newChat.emitedAt = msjNew.emitedAt;
            newChat.notRead = 0;
            newChat.lastMessage = msjNew.mensaje;
            newChat.show = true;
            newChat.save();
        } else {
            if (!chat.photoload) {
                Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.emisor)
                        .executeSingle();
                if (contact != null) {
                    chat.photo = contact.photo;
                    chat.photoload = true;
                } else {
                    chat.photo = null;
                    chat.photoload = false;
                }
            }
            chat.mensajeId = msjNew.mensajeId;
            chat.lastStatus = msjNew.status;
            chat.emitedAt = msjNew.emitedAt;
            chat.notRead = 0;
            chat.lastMessage = msjNew.mensaje;
            chat.save();
        }
        messageText.setText("");
        showNewMessage(msjNew);
        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:
        translate = !translate;
        if (translate)
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_red));
        else
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_gray));
        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);
        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();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, 1);
        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);
        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.add_to_contacts:
        try {
            JSONArray jsonArr = new JSONArray();
            JSONObject jsonObj = new JSONObject();
            jsonObj.put(C.c_id_contact, contact.idContacto);
            RequestParams params = new RequestParams();
            params.put("contacts", jsonArr.put(jsonObj));
            addToContacts(params);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case R.id.adjunt_photo:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        File imagesFolder = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
        imagesFolder.mkdirs();
        adjuntLayout.setVisibility(View.GONE);
        dateToCamera = Calendar.getInstance().getTimeInMillis();
        File image = new File(imagesFolder, dateToCamera + ".png");
        Uri uriSavedImage = Uri.fromFile(image);
        Intent pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
        startActivityForResult(pictureActionIntent, 23);
        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:org.odk.collect.android.activities.FormEntryActivity.java

/**
 * Returns the instance that was just filled out to the calling activity, if
 * requested./*from w  ww .j a  va  2s.  c  o  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
        Cursor c = null;
        try {
            c = new InstancesDao()
                    .getInstancesCursorForFilePath(formController.getInstancePath().getAbsolutePath());
            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();
}