Example usage for android.content Intent createChooser

List of usage examples for android.content Intent createChooser

Introduction

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

Prototype

public static Intent createChooser(Intent target, CharSequence title) 

Source Link

Document

Convenience function for creating a #ACTION_CHOOSER Intent.

Usage

From source file:net.bytten.comicviewer.ComicViewerActivity.java

public void shareComicImage() {
    if (comicInfo == null || comicInfo.getImage() == null) {
        toast("No image loaded.");
        return;// w  ww . j a v a 2s. c om
    }

    new Utility.CancellableAsyncTaskWithProgressDialog<Uri, File>(getStringAppName()) {
        Throwable e;

        @Override
        protected File doInBackground(Uri... params) {
            try {
                File file = new File(getApplicationContext().getExternalCacheDir(),
                        comicDef.getComicTitleAbbrev() + "-" + params[0].getLastPathSegment());
                Utility.blockingSaveFile(file, params[0]);
                return file;

            } catch (InterruptedException ex) {
                return null;
            } catch (Throwable ex) {
                e = ex;
                return null;
            }
        }

        @Override
        protected void onPostExecute(File result) {
            super.onPostExecute(result);
            if (result != null && e == null) {

                try {
                    Uri uri = Uri.fromFile(result);
                    Intent intent = new Intent(Intent.ACTION_SEND, null);
                    intent.setType(Utility.getContentType(uri));
                    intent.putExtra(Intent.EXTRA_STREAM, uri);
                    startActivity(Intent.createChooser(intent, "Share image..."));
                    return;
                } catch (MalformedURLException ex) {
                    e = ex;
                } catch (IOException ex) {
                    e = ex;
                }
            }
            e.printStackTrace();
            failed("Couldn't save attachment: " + e);
        }

    }.start(this, "Saving image...", new Uri[] { comicInfo.getImage() });
}

From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java

/**
 * Export data.//from ww w . j  av  a  2s .  com
 * 
 * @param descr
 *            description of the exported rule set
 * @param fn
 *            one of the predefined file names from {@link DataProvider}.
 */
private void exportData(final String descr, final String fn) {
    if (descr == null) {
        final EditText et = new EditText(this);
        Builder builder = new Builder(this);
        builder.setView(et);
        builder.setCancelable(true);
        builder.setTitle(R.string.export_rules_descr);
        builder.setNegativeButton(android.R.string.cancel, null);
        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                Preferences.this.exportData(et.getText().toString(), fn);
            }
        });
        builder.show();
    } else {
        final ProgressDialog d = new ProgressDialog(this);
        d.setIndeterminate(true);
        d.setMessage(this.getString(R.string.export_progr));
        d.setCancelable(false);
        d.show();

        // run task in background
        final AsyncTask<Void, Void, String> task = // .
                new AsyncTask<Void, Void, String>() {
                    @Override
                    protected String doInBackground(final Void... params) {
                        if (fn.equals(DataProvider.EXPORT_RULESET_FILE)) {
                            return DataProvider.backupRuleSet(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_LOGS_FILE)) {
                            return DataProvider.backupLogs(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_NUMGROUPS_FILE)) {
                            return DataProvider.backupNumGroups(Preferences.this, descr);
                        } else if (fn.equals(DataProvider.EXPORT_HOURGROUPS_FILE)) {
                            return DataProvider.backupHourGroups(Preferences.this, descr);
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(final String result) {
                        Log.d(TAG, "export:\n" + result);
                        System.out.println("\n" + result);
                        d.dismiss();
                        if (result != null && result.length() > 0) {
                            Uri uri = null;
                            int resChooser = -1;
                            if (fn.equals(DataProvider.EXPORT_RULESET_FILE)) {
                                uri = DataProvider.EXPORT_RULESET_URI;
                                resChooser = R.string.export_rules_;
                            } else if (fn.equals(DataProvider.EXPORT_LOGS_FILE)) {
                                uri = DataProvider.EXPORT_LOGS_URI;
                                resChooser = R.string.export_logs_;
                            } else if (fn.equals(DataProvider.EXPORT_NUMGROUPS_FILE)) {
                                uri = DataProvider.EXPORT_NUMGROUPS_URI;
                                resChooser = R.string.export_numgroups_;
                            } else if (fn.equals(DataProvider.EXPORT_HOURGROUPS_FILE)) {
                                uri = DataProvider.EXPORT_HOURGROUPS_URI;
                                resChooser = R.string.export_hourgroups_;
                            }
                            final Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType(DataProvider.EXPORT_MIMETYPE);
                            intent.putExtra(Intent.EXTRA_STREAM, uri);
                            intent.putExtra(Intent.EXTRA_SUBJECT, // .
                                    "Call Meter 3G export");
                            intent.addCategory(Intent.CATEGORY_DEFAULT);

                            try {
                                final File d = Environment.getExternalStorageDirectory();
                                final File f = new File(d, DataProvider.PACKAGE + File.separator + fn);
                                f.mkdirs();
                                if (f.exists()) {
                                    f.delete();
                                }
                                f.createNewFile();
                                FileWriter fw = new FileWriter(f);
                                fw.append(result);
                                fw.close();
                                // call an exporting app with the uri to the
                                // preferences
                                Preferences.this.startActivity(
                                        Intent.createChooser(intent, Preferences.this.getString(resChooser)));
                            } catch (IOException e) {
                                Log.e(TAG, "error writing export file", e);
                                Toast.makeText(Preferences.this, R.string.err_export_write, Toast.LENGTH_LONG)
                                        .show();
                            }
                        }
                    }
                };
        task.execute((Void) null);
    }
}

From source file:com.danvelazco.fbwrapper.activity.BaseFacebookWebViewActivity.java

/**
 * {@inheritDoc}/*from   w w  w. j  a v  a 2  s.c o m*/
 */
@Override
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
    Logger.d(LOG_TAG, "openFileChooser()");
    mUploadMessage = uploadMsg;
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("image/*");
    startActivityForResult(Intent.createChooser(i, getString(R.string.upload_file_choose)),
            RESULT_CODE_FILE_UPLOAD);
}

From source file:ac.robinson.ticqr.TicQRActivity.java

private void sendOrder() {
    try {/*  w  ww.j ava 2s .c  om*/
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", TextUtils.isEmpty(mDestinationEmail) ? "" : mDestinationEmail, null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject));
        emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_body, mEmailContents));
        startActivity(Intent.createChooser(emailIntent, getString(R.string.email_prompt)));
    } catch (ActivityNotFoundException e) {
        // copy to clipboard instead if no email client found
        String clipboardText = getString(R.string.email_backup_sender,
                TextUtils.isEmpty(mDestinationEmail) ? "" : mDestinationEmail,
                getString(R.string.email_body, mEmailContents));

        // see: http://stackoverflow.com/a/11012443
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            @SuppressLint("ServiceCast")
            @SuppressWarnings("deprecation")
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            clipboard.setText(clipboardText);
        } else {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip = android.content.ClipData
                    .newPlainText(getString(R.string.email_subject), clipboardText);
            clipboard.setPrimaryClip(clip);
        }

        Toast.makeText(TicQRActivity.this, getString(R.string.hint_no_email_client), Toast.LENGTH_LONG).show();
    }
}

From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedPost.java

public static void onActionMenuItemSelected(final RedditPreparedPost post, final AppCompatActivity activity,
        final Action action) {

    switch (action) {

    case UPVOTE://from w  ww.j  av  a  2  s .co  m
        post.action(activity, RedditAPI.ACTION_UPVOTE);
        break;

    case DOWNVOTE:
        post.action(activity, RedditAPI.ACTION_DOWNVOTE);
        break;

    case UNVOTE:
        post.action(activity, RedditAPI.ACTION_UNVOTE);
        break;

    case SAVE:
        post.action(activity, RedditAPI.ACTION_SAVE);
        break;

    case UNSAVE:
        post.action(activity, RedditAPI.ACTION_UNSAVE);
        break;

    case HIDE:
        post.action(activity, RedditAPI.ACTION_HIDE);
        break;

    case UNHIDE:
        post.action(activity, RedditAPI.ACTION_UNHIDE);
        break;
    case EDIT:
        final Intent editIntent = new Intent(activity, CommentEditActivity.class);
        editIntent.putExtra("commentIdAndType", post.src.getIdAndType());
        editIntent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText()));
        editIntent.putExtra("isSelfPost", true);
        activity.startActivity(editIntent);
        break;

    case DELETE:
        new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm)
                .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        post.action(activity, RedditAPI.ACTION_DELETE);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();
        break;

    case REPORT:

        new AlertDialog.Builder(activity).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        post.action(activity, RedditAPI.ACTION_REPORT);
                        // TODO update the view to show the result
                        // TODO don't forget, this also hides
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case EXTERNAL: {
        final Intent intent = new Intent(Intent.ACTION_VIEW);
        String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl()
                : post.src.getUrl();
        intent.setData(Uri.parse(url));
        activity.startActivity(intent);
        break;
    }

    case SELFTEXT_LINKS: {

        final HashSet<String> linksInComment = LinkHandler
                .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText()));

        if (linksInComment.isEmpty()) {
            General.quickToast(activity, R.string.error_toast_no_urls_in_self);

        } else {

            final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]);

            final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src.getSrc());
                    dialog.dismiss();
                }
            });

            final AlertDialog alert = builder.create();
            alert.setTitle(R.string.action_selftext_links);
            alert.setCanceledOnTouchOutside(true);
            alert.show();
        }

        break;
    }

    case SAVE_IMAGE: {

        ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                new SaveImageCallback(activity, post.src.getUrl()));
        break;
    }

    case SHARE: {

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, post.src.getTitle());
        mailer.putExtra(Intent.EXTRA_TEXT, post.src.getUrl());
        activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share)));
        break;
    }

    case SHARE_COMMENTS: {

        final boolean shareAsPermalink = PrefsUtility.pref_behaviour_share_permalink(activity,
                PreferenceManager.getDefaultSharedPreferences(activity));

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.src.getTitle());
        if (shareAsPermalink) {
            mailer.putExtra(Intent.EXTRA_TEXT,
                    Constants.Reddit.getNonAPIUri(post.src.getPermalink()).toString());
        } else {
            mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit
                    .getNonAPIUri(Constants.Reddit.PATH_COMMENTS + post.src.getIdAlone()).toString());
        }
        activity.startActivity(
                Intent.createChooser(mailer, activity.getString(R.string.action_share_comments)));
        break;
    }

    case SHARE_IMAGE: {

        ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                new ShareImageCallback(activity, post.src.getUrl()));

        break;
    }

    case COPY: {

        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        manager.setText(post.src.getUrl());
        break;
    }

    case GOTO_SUBREDDIT: {

        try {
            final Intent intent = new Intent(activity, PostListingActivity.class);
            intent.setData(SubredditPostListURL.getSubreddit(post.src.getSubreddit()).generateJsonUri());
            activity.startActivityForResult(intent, 1);

        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show();
        }

        break;
    }

    case USER_PROFILE:
        LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.getAuthor()).toString());
        break;

    case PROPERTIES:
        PostPropertiesDialog.newInstance(post.src.getSrc()).show(activity.getSupportFragmentManager(), null);
        break;

    case COMMENTS:
        ((PostSelectionListener) activity).onPostCommentsSelected(post);

        new Thread() {
            @Override
            public void run() {
                post.markAsRead(activity);
            }
        }.start();

        break;

    case LINK:
        ((PostSelectionListener) activity).onPostSelected(post);
        break;

    case COMMENTS_SWITCH:
        if (!(activity instanceof MainActivity))
            activity.finish();
        ((PostSelectionListener) activity).onPostCommentsSelected(post);
        break;

    case LINK_SWITCH:
        if (!(activity instanceof MainActivity))
            activity.finish();
        ((PostSelectionListener) activity).onPostSelected(post);
        break;

    case ACTION_MENU:
        showActionMenu(activity, post);
        break;

    case REPLY:
        final Intent intent = new Intent(activity, CommentReplyActivity.class);
        intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, post.src.getIdAndType());
        intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY, post.src.getUnescapedSelfText());
        activity.startActivity(intent);
        break;

    case BACK:
        activity.onBackPressed();
        break;

    case PIN:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity,
                    PreferenceManager.getDefaultSharedPreferences(activity));
            if (!pinnedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_pinned_subreddits_add(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName);
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_pinned, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }

        break;

    case UNPIN:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity,
                    PreferenceManager.getDefaultSharedPreferences(activity));
            if (pinnedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_pinned_subreddits_remove(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName);
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_not_pinned, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;

    case BLOCK:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity,
                    PreferenceManager.getDefaultSharedPreferences(activity));
            if (!blockedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_blocked_subreddits_add(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName);
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_blocked, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;

    case UNBLOCK:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity,
                    PreferenceManager.getDefaultSharedPreferences(activity));
            if (blockedSubreddits.contains(subredditCanonicalName)) {
                PrefsUtility.pref_blocked_subreddits_remove(activity,
                        PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName);
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_not_blocked, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;

    case SUBSCRIBE:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager
                    .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount());

            if (subMan.getSubscriptionState(
                    subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.NOT_SUBSCRIBED) {
                subMan.subscribe(subredditCanonicalName, activity);
                Toast.makeText(activity, R.string.options_subscribing, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;

    case UNSUBSCRIBE:

        try {
            String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit());
            RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager
                    .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount());
            if (subMan.getSubscriptionState(
                    subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) {
                subMan.unsubscribe(subredditCanonicalName, activity);
                Toast.makeText(activity, R.string.options_unsubscribing, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(activity, R.string.mainmenu_toast_not_subscribed, Toast.LENGTH_SHORT).show();
            }
        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            throw new RuntimeException(e);
        }
        break;
    }
}

From source file:com.danvelazco.fbwrapper.activity.BaseFacebookWebViewActivity.java

/**
 * {@inheritDoc}/*from   ww  w.  j a v a  2  s. c om*/
 */
@SuppressLint("NewApi")
@Override
public boolean openFileChooser(ValueCallback<Uri[]> filePathCallback,
        WebChromeClient.FileChooserParams fileChooserParams) {
    try {
        Logger.d(LOG_TAG, "openFileChooser()");
        mUploadMessageLollipop = filePathCallback;
        startActivityForResult(
                Intent.createChooser(fileChooserParams.createIntent(), getString(R.string.upload_file_choose)),
                RESULT_CODE_FILE_UPLOAD_LOLLIPOP);
        return true;
    } catch (ActivityNotFoundException e) {
        mUploadMessageLollipop = null;
        return false;
    }
}

From source file:gr.scify.newsum.ui.SearchViewActivity.java

private void Sendmail() {
    TextView title = (TextView) findViewById(R.id.title);
    String emailSubject = title.getText().toString();

    // track the Send mail action
    if (getAnalyticsPref()) {
        EasyTracker.getTracker().sendEvent(SHARING_ACTION, "Send Mail", emailSubject, 0l);
    }//from   w  w  w .  ja v  a 2s  .  c  om
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("text/html");
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "NewSum app : " + emailSubject);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(sText));
    startActivity(Intent.createChooser(emailIntent, "Email:"));

}

From source file:com.annanovas.bestprice.DashBoardEditActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dash_board_edit);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w w  w .  j a  va2 s.co  m*/
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    //        chosenBrandList.add(new ArrayList<String>());
    //        chosenBrandList.add(new ArrayList<String>());
    //        chosenBrandList.add(new ArrayList<String>());

    etAddress = (EditText) findViewById(R.id.et_address);
    etEmail = (EditText) findViewById(R.id.et_email);
    etShopName = (EditText) findViewById(R.id.et_shop_name);
    etDrivingLicense = (EditText) findViewById(R.id.et_driving_licence);
    etNid = (EditText) findViewById(R.id.et_nid);
    etExperience = (EditText) findViewById(R.id.et_experience);
    etFirstName = (EditText) findViewById(R.id.et_first_name);
    etMiddleName = (EditText) findViewById(R.id.et_middle_name);
    etLastName = (EditText) findViewById(R.id.et_last_name);
    etPhoneNumber = (EditText) findViewById(R.id.et_phone);
    tvAddress = (TextView) findViewById(R.id.tv_address);
    tvArea = (TextView) findViewById(R.id.tv_area);
    tvDealerShip = (LinearLayout) findViewById(R.id.tv_dealership);
    tvDealerShipWith = (TextView) findViewById(R.id.tv_dealership_content);
    tvSelectedProduct = (TextView) findViewById(R.id.tv_select_product_content);
    tvProduct = (LinearLayout) findViewById(R.id.tv_select_product);
    buttonSubmit = (Button) findViewById(R.id.button_submit);
    areaLayout = (LinearLayout) findViewById(R.id.layout_area);
    brandLayout = (LinearLayout) findViewById(R.id.layout_brand);
    productLayout = (LinearLayout) findViewById(R.id.layout_product);
    layoutCamera = (LinearLayout) findViewById(R.id.layout_camera);
    layoutGallery = (LinearLayout) findViewById(R.id.layout_gallery);
    userImage = (ImageView) findViewById(R.id.iv_user_image);
    areaRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_area);
    brandRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_brand);
    productRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_product);
    etProductSearch = (EditText) findViewById(R.id.et_product_name);
    etBrandSearch = (EditText) findViewById(R.id.et_brand_name);
    etAreaSearch = (EditText) findViewById(R.id.et_area_name);
    layoutSearchArea = (LinearLayout) findViewById(R.id.layout_search_area);
    layoutSearchProduct = (LinearLayout) findViewById(R.id.layout_search_product);
    layoutSearchBrand = (LinearLayout) findViewById(R.id.layout_search_brand);
    tvSelectedBrand = (TextView) findViewById(R.id.tv_selected_brand);
    tvSelectedArea = (TextView) findViewById(R.id.tv_setect_area);
    ivArrow1 = (ImageView) findViewById(R.id.iv_arrow1);
    ivArrow2 = (ImageView) findViewById(R.id.iv_arrow2);
    ivArrow3 = (ImageView) findViewById(R.id.iv_arrow3);
    ivArrow4 = (ImageView) findViewById(R.id.iv_arrow4);

    myDB = MyDatabaseManager.getInstance(getApplicationContext());
    sharedPreferences = getSharedPreferences(AppGlobal.MY_PREFS_NAME, MODE_PRIVATE);

    userType = sharedPreferences.getInt("user_type", 1);

    int imageDimen = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
            getResources().getDimension(R.dimen.size_150dp), getResources().getDisplayMetrics());

    myDB.open();
    Cursor cursor = myDB.getUserInfo(userType, sharedPreferences.getString("user_phone_number", ""));
    if (userType == AppGlobal.CAR_OWNER) {
        userImage.setImageResource(R.drawable.ic_car_owner);
        tvAddress.setVisibility(View.VISIBLE);
        etAddress.setVisibility(View.VISIBLE);
        tvArea.setVisibility(View.VISIBLE);
        areaLayout.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));

                if (cursor.getString(cursor.getColumnIndex("address")) != null
                        && !cursor.getString(cursor.getColumnIndex("address")).equals("null")) {
                    etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                }

                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname")));
                areaId = cursor.getInt(cursor.getColumnIndex("area_id"));
                if (areaId != 0) {
                    tvSelectedArea.setText(myDB.getAreaName(areaId));
                } else {
                    tvSelectedArea.setText(getResources().getString(R.string.select_area));
                }

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }
            }
        }
        cursor.close();

        generateAreaRecyclerView();

    } else if (userType == AppGlobal.SUPPLIER) {
        tvAddress.setVisibility(View.VISIBLE);
        etAddress.setVisibility(View.VISIBLE);
        tvDealerShip.setVisibility(View.VISIBLE);
        tvProduct.setVisibility(View.VISIBLE);
        tvArea.setVisibility(View.VISIBLE);
        brandLayout.setVisibility(View.VISIBLE);
        productLayout.setVisibility(View.VISIBLE);
        areaLayout.setVisibility(View.VISIBLE);
        etShopName.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));
                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname")));
                etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                areaId = cursor.getInt(cursor.getColumnIndex("area_id"));
                if (areaId != 0) {
                    tvSelectedArea.setText(myDB.getAreaName(areaId));
                } else {
                    tvSelectedArea.setText(getResources().getString(R.string.select_area));
                }
                selectedProductIdList = myDB.getSelectedProductList(cursor.getInt(cursor.getColumnIndex("id")));
                chosenBrandIdList = myDB.getSelectedBrandList(cursor.getInt(cursor.getColumnIndex("id")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_supplier);
                }
            }
        }
        cursor.close();

        generateAreaRecyclerView();
        generateProductRecyclerView();

    } else if (userType == AppGlobal.DRIVER) {
        etDrivingLicense.setVisibility(View.VISIBLE);
        etNid.setVisibility(View.VISIBLE);
        etExperience.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));
                etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etDrivingLicense.setText(cursor.getString(cursor.getColumnIndex("drivinglicence")));
                etNid.setText(cursor.getString(cursor.getColumnIndex("nid")));
                etExperience.setText(cursor.getString(cursor.getColumnIndex("yearofexperience")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }
            }
        }
        cursor.close();

    } else if (userType == AppGlobal.SHOP_WORKER) {
        etShopName.setVisibility(View.VISIBLE);
        etNid.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                etFirstName.setText(cursor.getString(cursor.getColumnIndex("firstname")));
                etMiddleName.setText(cursor.getString(cursor.getColumnIndex("middlename")));
                etLastName.setText(cursor.getString(cursor.getColumnIndex("lastname")));
                etAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                etPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                etEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                etShopName.setText(cursor.getString(cursor.getColumnIndex("shopname")));
                etNid.setText(cursor.getString(cursor.getColumnIndex("nid")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getApplicationContext())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }
            }
        }
        cursor.close();
    }
    myDB.close();

    areaLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (layoutSearchArea.getVisibility() == View.GONE) {
                layoutSearchArea.setVisibility(View.VISIBLE);
                areaRecyclerView.setVisibility(View.VISIBLE);
                ivArrow2.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow));
            } else {
                layoutSearchArea.setVisibility(View.GONE);
                areaRecyclerView.setVisibility(View.GONE);
                ivArrow2.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow));
            }
        }
    });

    brandLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (selectedProductIdList.size() == 0) {
                Toast.makeText(getApplicationContext(), R.string.add_product, Toast.LENGTH_SHORT).show();
                return;
            }
            if (layoutSearchBrand.getVisibility() == View.GONE) {
                layoutSearchBrand.setVisibility(View.VISIBLE);
                brandRecyclerView.setVisibility(View.VISIBLE);
                ivArrow3.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow));
            } else {
                layoutSearchBrand.setVisibility(View.GONE);
                brandRecyclerView.setVisibility(View.GONE);
                ivArrow3.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow));
            }
        }
    });

    productLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (layoutSearchProduct.getVisibility() == View.GONE) {
                layoutSearchProduct.setVisibility(View.VISIBLE);
                productRecyclerView.setVisibility(View.VISIBLE);
                ivArrow1.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_up_arrow));
            } else {
                layoutSearchProduct.setVisibility(View.GONE);
                productRecyclerView.setVisibility(View.GONE);
                ivArrow1.setImageDrawable(
                        ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_down_arrow));
            }
        }
    });

    layoutCamera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                File file = createImageFile();
                imageUri = String.valueOf(file);
                // showLog(imageUri);
                Uri photoURI = FileProvider.getUriForFile(getApplicationContext(),
                        BuildConfig.APPLICATION_ID + ".provider", file);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(intent, REQUEST_CAMERA);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    layoutGallery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            intent.setType("image/*");
            startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
        }
    });

    buttonSubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            progressDialog = new ProgressDialog(DashBoardEditActivity.this);
            progressDialog.setMessage(getResources().getString(R.string.please_wait));
            progressDialog.setCancelable(false);
            progressDialog.show();
            UpdateUserInfo updateUserInfo = new UpdateUserInfo(getApplicationContext());
            updateUserInfo.signUpListener = DashBoardEditActivity.this;
            //viewEnable(false);

            if (userType == AppGlobal.CAR_OWNER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }
                if (etAddress.getText().length() == 0) {
                    etAddress.setError(getResources().getString(R.string.enter_address));
                    hasError = true;
                }
                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("district_id", "1");
                params.put("area_id", String.valueOf(areaId));
                params.put("address", etAddress.getText().toString());
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                updateUserInfo.parseData(params, "updateCarOwnerInfo");
            } else if (userType == AppGlobal.SUPPLIER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }
                if (etShopName.getText().length() == 0) {
                    etShopName.setError(getResources().getString(R.string.enter_shop_name));
                    hasError = true;
                }
                if (etAddress.getText().length() == 0) {
                    etAddress.setError(getResources().getString(R.string.enter_address));
                    hasError = true;
                }

                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("district_id", "1");
                params.put("area_id", String.valueOf(areaId));
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                params.put("shopname", etShopName.getText().toString());
                params.put("address", etAddress.getText().toString());
                for (int i = 0; i < selectedProductIdList.size(); i++) {
                    params.put("products[" + i + "]", selectedProductIdList.get(i));
                }
                for (int i = 0; i < chosenBrandIdList.size(); i++) {
                    params.put("brands[" + i + "]", chosenBrandIdList.get(i));
                }
                updateUserInfo.parseData(params, "updateSupplierInfo");
            } else if (userType == AppGlobal.DRIVER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                boolean hasDrivingLicenseNoError = false;
                boolean hasNidNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }

                if (etDrivingLicense.getText().length() == 0) {
                    etDrivingLicense.setError(getResources().getString(R.string.enter_driving_licence));
                    hasError = true;
                    hasDrivingLicenseNoError = true;
                }

                if (!hasDrivingLicenseNoError && etDrivingLicense.getText().length() != 15) {
                    etDrivingLicense.setError(getResources().getString(R.string.enter_valid_driving_licence));
                    hasError = true;
                }
                if (etNid.getText().length() == 0) {
                    etNid.setError(getResources().getString(R.string.enter_nid_no));
                    hasError = true;
                    hasNidNoError = true;
                }
                if (!hasNidNoError && etNid.getText().length() != 17) {
                    etNid.setError(getResources().getString(R.string.enter_valid_nid));
                    hasError = true;
                }

                if (etExperience.getText().length() == 0) {
                    etExperience.setError(getResources().getString(R.string.enter_year_of_experience));
                    hasError = true;
                }

                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("drivinglicence", etDrivingLicense.getText().toString());
                params.put("nid", etNid.getText().toString());
                params.put("yearofexperience", etExperience.getText().toString());
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                updateUserInfo.parseData(params, "updateDriverInfo");
            } else if (userType == AppGlobal.SHOP_WORKER) {
                boolean hasError = false;
                boolean hasPhoneNoError = false;
                if (etFirstName.getText().length() == 0) {
                    etFirstName.setError(getResources().getString(R.string.enter_first_name));
                    hasError = true;
                }
                if (etLastName.getText().length() == 0) {
                    etLastName.setError(getResources().getString(R.string.enter_last_name));
                    hasError = true;
                }
                if (etPhoneNumber.getText().length() == 0) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_phone_no));
                    hasError = true;
                    hasPhoneNoError = true;
                }
                if (!hasPhoneNoError && etPhoneNumber.getText().length() != 11) {
                    etPhoneNumber.setError(getResources().getString(R.string.enter_valid_phone_no));
                    hasError = true;
                }
                if (etEmail.getText().length() != 0
                        && !Patterns.EMAIL_ADDRESS.matcher(etEmail.getText().toString()).matches()) {
                    etEmail.setError(getResources().getString(R.string.enter_valid_email));
                    hasError = true;
                }

                if (etNid.getText().length() == 0) {
                    etNid.setError(getResources().getString(R.string.enter_nid_no));
                    hasError = true;
                }

                if (etShopName.getText().length() == 0) {
                    etShopName.setError(getResources().getString(R.string.enter_shop_name));
                    hasError = true;
                }

                if (hasError) {
                    if (progressDialog.isShowing())
                        progressDialog.dismiss();
                    return;
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("authentication", AppGlobal.authentication);
                params.put("api_token", sharedPreferences.getString("api_token", ""));
                params.put("phone", etPhoneNumber.getText().toString());
                params.put("firstname", etFirstName.getText().toString());
                if (!etMiddleName.getText().toString().equals("")) {
                    params.put("middlename", etMiddleName.getText().toString());
                }
                params.put("lastname", etLastName.getText().toString());
                params.put("nid", etNid.getText().toString());
                params.put("shopname", etShopName.getText().toString());
                if (!etEmail.getText().toString().equals("")) {
                    params.put("email", etEmail.getText().toString());
                }
                if (!image.equals("")) {
                    params.put("image", image);
                }
                updateUserInfo.parseData(params, "updateWorkerInfo");
            }
        }
    });
}

From source file:de.electricdynamite.pasty.ClipboardFragment.java

@SuppressLint("NewApi")
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    ClipboardItem Item = mItems.get(info.position);
    switch (menuItemIndex) {
    case PastySharedStatics.ITEM_CONTEXTMENU_COPY_ID:
        // Copy without exit selected
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSherlockActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            Item.copyToClipboard(clipboard);
            clipboard = null;/*from  w ww  .  ja v  a 2  s.  co m*/
        } else {
            ClipboardManager clipboard = (ClipboardManager) getSherlockActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            Item.copyToClipboard(clipboard);
            clipboard = null;
        }
        Toast.makeText(getSherlockActivity().getApplicationContext(), getString(R.string.item_copied),
                Toast.LENGTH_LONG).show();

        break;
    case PastySharedStatics.ITEM_CONTEXTMENU_SHARE_ID:
        // Share to another app
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, Item.getText());
        startActivity(Intent.createChooser(shareIntent, getString(R.string.app_share_from_pasty)));
        break;
    case PastySharedStatics.ITEM_CONTEXTMENU_DELETE_ID:
        // Delete selected
        mAdapter.delete(info.position);
        break;
    case PastySharedStatics.ITEM_CONTEXTMENU_OPEN_ID:
        /* If the clicked item was originally linkified, we
        * fire an ACTION_VIEW intent.
        */
        String url = Item.getText();
        if (!URLUtil.isValidUrl(url))
            url = "http://" + url;
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
        break;
    }
    return true;
}

From source file:com.wikitude.virtualhome.AugmentedActivity.java

public void setBkgImage() {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
}