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.xorcode.andtweet.TweetListActivity.java

/**
 * Listener that checks for clicks on the main list view.
 * //from  ww  w.  ja va 2 s  . c  om
 * @param adapterView
 * @param view
 * @param position
 * @param id
 */
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    if (MyLog.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "onItemClick, id=" + id);
    }
    if (id <= 0) {
        return;
    }
    Uri uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, id);
    String action = getIntent().getAction();
    if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
        if (MyLog.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "onItemClick, setData=" + uri);
        }
        setResult(RESULT_OK, new Intent().setData(uri));
    } else {
        if (MyLog.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "onItemClick, startActivity=" + uri);
        }
        startActivity(new Intent(Intent.ACTION_VIEW, uri));
    }
}

From source file:com.money.manager.ex.common.CategoryListFragment.java

public CategoryExpandableListAdapter getAdapter(Cursor data) {
    if (data == null)
        return null;

    mCategories.clear();/*from  ww  w  .j  a va 2  s  .c o m*/
    mSubCategories.clear();
    mPositionToExpand.clear();
    // create core and fixed string filter to highlight
    Core core = new Core(getActivity().getApplicationContext());
    String filter = mCurFilter != null ? mCurFilter.replace("%", "") : "";

    int key = -1;
    List<QueryCategorySubCategory> listSubCategories = null;

    // reset cursor if getting back on the fragment.
    if (data.getPosition() > 0) {
        data.moveToPosition(Constants.NOT_SET);
    }

    while (data.moveToNext()) {
        if (key != data.getInt(data.getColumnIndex(QueryCategorySubCategory.CATEGID))) {
            // check if listCategories > 0
            if (mCategories.size() > 0 && listSubCategories != null) {
                mSubCategories.put(mCategories.get(mCategories.size() - 1), listSubCategories);
            }
            // update key
            key = data.getInt(data.getColumnIndex(QueryCategorySubCategory.CATEGID));

            // create instance category
            Category category = new Category();
            category.setId(data.getInt(data.getColumnIndex(QueryCategorySubCategory.CATEGID)));
            category.setName(core
                    .highlight(filter, data.getString(data.getColumnIndex(QueryCategorySubCategory.CATEGNAME)))
                    .toString());

            // add list
            mCategories.add(category);
            listSubCategories = new ArrayList<>();
        }

        if (data.getInt(data.getColumnIndex(QueryCategorySubCategory.SUBCATEGID)) != Constants.NOT_SET) {
            QueryCategorySubCategory subCategory = new QueryCategorySubCategory(getActivity());
            // subcategory
            subCategory.setSubCategId(data.getInt(data.getColumnIndex(QueryCategorySubCategory.SUBCATEGID)));
            subCategory.setSubcategoryName(core.highlight(filter,
                    data.getString(data.getColumnIndex(QueryCategorySubCategory.SUBCATEGNAME))));
            subCategory.setCategId(data.getInt(data.getColumnIndex(QueryCategorySubCategory.CATEGID)));
            subCategory.setCategName(core.highlight(filter,
                    data.getString(data.getColumnIndex(QueryCategorySubCategory.CATEGNAME))));
            // add to hashmap
            listSubCategories.add(subCategory);
            // check if expand group
            if (!TextUtils.isEmpty(filter)) {
                String normalizedText = Normalizer
                        .normalize(subCategory.getSubcategoryName(), Normalizer.Form.NFD)
                        .replaceAll("\\p{InCombiningDiacriticalMarks}+", "").toLowerCase();
                if ((normalizedText.indexOf(filter) >= 0)
                        && (!mPositionToExpand.contains(mCategories.size() - 1))) {
                    mPositionToExpand.add(mCategories.size() - 1);
                }
            }
        }
    }
    if (mCategories.size() > 0 && listSubCategories != null) {
        mSubCategories.put(mCategories.get(mCategories.size() - 1), listSubCategories);
    }

    boolean showSelector = mAction.equals(Intent.ACTION_PICK);
    CategoryExpandableListAdapter adapter = new CategoryExpandableListAdapter(getActivity(), mLayout,
            mCategories, mSubCategories, showSelector);
    adapter.setIdChildChecked(mIdGroupChecked, mIdChildChecked);
    return adapter;
}

From source file:com.example.zf_android.activity.MerchantEdit.java

private void show3Dialog(int type, final String uri) {
    AlertDialog.Builder builder = new AlertDialog.Builder(MerchantEdit.this);
    final String[] items = getResources().getStringArray(R.array.apply_detail_view);

    MerchantEdit.this.type = type;
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override/*www.j a v  a  2 s .c om*/
        public void onClick(DialogInterface dialog, int which) {

            switch (which) {
            case 0: {

                AlertDialog.Builder build = new AlertDialog.Builder(MerchantEdit.this);
                LayoutInflater factory = LayoutInflater.from(MerchantEdit.this);
                final View textEntryView = factory.inflate(R.layout.show_view, null);
                build.setView(textEntryView);
                final ImageView view = (ImageView) textEntryView.findViewById(R.id.imag);
                //               ImageCacheUtil.IMAGE_CACHE.get(uri, view);
                ImageLoader.getInstance().displayImage(uri, view, options);
                build.create().show();
                break;
            }

            case 1: {

                Intent intent;
                if (Build.VERSION.SDK_INT < 19) {
                    intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("image/*");
                } else {
                    intent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                }
                startActivityForResult(intent, REQUEST_UPLOAD_IMAGE);
                break;
            }
            case 2: {
                String state = Environment.getExternalStorageState();
                if (state.equals(Environment.MEDIA_MOUNTED)) {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    File outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                    if (!outDir.exists()) {
                        outDir.mkdirs();
                    }
                    File outFile = new File(outDir, System.currentTimeMillis() + ".jpg");
                    photoPath = outFile.getAbsolutePath();
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outFile));
                    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
                    startActivityForResult(intent, REQUEST_TAKE_PHOTO);
                } else {
                    CommonUtil.toastShort(MerchantEdit.this, getString(R.string.toast_no_sdcard));
                }
                break;
            }
            }
        }
    });

    builder.show();
}

From source file:org.andstatus.app.msg.TimelineActivity.java

public void onItemClick(AdapterView<?> adapterView, final View view, final int position, final long id) {
    if (id <= 0) {
        if (MyLog.isVerboseEnabled()) {
            MyLog.v(this, "onItemClick, position=" + position + "; id=" + id + "; view=" + view);
        }/*from   w w  w . j  a va 2s. c  o  m*/
        return;
    }

    new AsyncTask<Void, Void, Uri>() {

        @Override
        protected Uri doInBackground(Void... params) {
            long linkedUserId = getLinkedUserIdFromCursor(position);
            MyAccount ma = MyContextHolder.get().persistentAccounts().getAccountForThisMessage(id, linkedUserId,
                    mListParametersNew.myAccountUserId, false);
            if (MyLog.isVerboseEnabled()) {
                MyLog.v(this, "onItemClick, position=" + position + "; id=" + id + "; view=" + view
                        + "; linkedUserId=" + linkedUserId + " account=" + ma.getAccountName());
            }
            return MatchedUri.getTimelineItemUri(ma.getUserId(), mListParametersNew.getTimelineType(),
                    mListParametersNew.isTimelineCombined(), mListParametersNew.getSelectedUserId(), id);
        }

        @Override
        protected void onPostExecute(Uri uri) {
            String action = getIntent().getAction();
            if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
                if (MyLog.isLoggable(this, MyLog.DEBUG)) {
                    MyLog.d(this, "onItemClick, setData=" + uri);
                }
                setResult(RESULT_OK, new Intent().setData(uri));
            } else {
                if (MyLog.isLoggable(this, MyLog.DEBUG)) {
                    MyLog.d(this, "onItemClick, startActivity=" + uri);
                }
                startActivity(MyAction.VIEW_CONVERSATION.getIntent(uri));
            }
        }

    }.execute();
}

From source file:hku.fyp14017.blencode.ui.fragment.LookFragment.java

public void addLookChooseImage() {
    Intent intent = new Intent(Intent.ACTION_PICK);

    Bundle bundleForPocketCode = new Bundle();
    bundleForPocketCode.putString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT, "");
    bundleForPocketCode.putString(Constants.EXTRA_PICTURE_NAME_POCKET_PAINT,
            getString(hku.fyp14017.blencode.R.string.default_look_name));

    intent.setType("image/*");
    intent.putExtras(bundleForPocketCode);

    Intent chooser = Intent.createChooser(intent,
            getString(hku.fyp14017.blencode.R.string.select_look_from_gallery));
    startActivityForResult(chooser, LookController.REQUEST_SELECT_OR_DRAW_IMAGE);
}

From source file:com.bf.zxd.zhuangxudai.my.fragment.CompanyApplyFragment.java

private void allPhoto() {
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, ALL_PHOTO);
}

From source file:com.grass.caishi.cc.activity.AdAddActivity.java

/**
 * ?// w w w.  j av  a  2 s  .  c om
 */
public void selectPicFromLocal() {
    Intent intent;
    if (Build.VERSION.SDK_INT < 19) {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
    } else {
        intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    }
    startActivityForResult(intent, REQUEST_CODE_IMAGES);
}

From source file:org.catrobat.catroid.ui.fragment.LookFragment.java

public void addLookChooseImage() {
    Intent intent = new Intent(Intent.ACTION_PICK);

    Bundle bundleForPocketCode = new Bundle();
    bundleForPocketCode.putString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT, "");
    bundleForPocketCode.putString(Constants.EXTRA_PICTURE_NAME_POCKET_PAINT,
            getString(R.string.default_look_name));

    intent.setType("image/*");
    intent.putExtras(bundleForPocketCode);

    Intent chooser = Intent.createChooser(intent, getString(R.string.select_look_from_gallery));
    startActivityForResult(chooser, LookController.REQUEST_SELECT_OR_DRAW_IMAGE);
}

From source file:com.afrozaar.jazzfestreporting.MainActivity.java

public void pickFile(View view) {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType("video/*");
    startActivityForResult(intent, RESULT_PICK_IMAGE_CROP);
}

From source file:com.todoroo.astrid.actfm.EditPeopleControlSet.java

private void setUpListeners() {

    assignedList.setOnItemClickListener(new OnItemClickListener() {
        @Override/*from w w  w .  j  a  v a 2 s  .  c  o  m*/
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
            AssignedToUser user = (AssignedToUser) assignedList.getAdapter().getItem(position);

            if (user.user.has(CONTACT_CHOOSER_USER)) {
                Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                fragment.startActivityForResult(intent, TaskEditFragment.REQUEST_CODE_CONTACT);
                return;
            }

            assignedDisplay.setText(user.toString());
            assignedCustom.setText(""); //$NON-NLS-1$
            selected = position;
            refreshDisplayView();
            DialogUtilities.dismissDialog(activity, dialog);
        }

    });

    assignedClear.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            assignedCustom.setText(""); //$NON-NLS-1$
            selected = 0;
            assignedList.setItemChecked(selected, true);
        }
    });

    //        sharedWithContainer.setOnAddNewPerson(new OnAddNewPersonListener() {
    //            @Override
    //            public void textChanged(String text) {
    //                getSharedWithView().findViewById(R.id.share_additional).setVisibility(View.VISIBLE);
    //                if(text.indexOf('@') > -1) {
    ////                    getSharedWithView().findViewById(R.id.tag_label).setVisibility(View.VISIBLE);
    ////                    getSharedWithView().findViewById(R.id.tag_name).setVisibility(View.VISIBLE);
    //                }
    //            }
    //        });
    //
    //        sharedWithRow.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                sharedWithDialog.show();
    //            }
    //        });
}