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:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java

private void showVideoFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("video/*");

    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {//from  ww w  .j a  va 2  s .  c om
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), VIDEO_REQUEST);
    } catch (android.content.ActivityNotFoundException ex) {
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
    }
}

From source file:ch.luklanis.esscan.history.HistoryActivity.java

@Override
public boolean handleMessage(Message message) {
    int msgId = 0;

    switch (message.what) {
    case R.id.history_menu_send_dta_email: {
        Uri dtaFileUri = (Uri) message.obj;
        if (dtaFileUri != null) {
            try {
                startActivity(createMailIntent(dtaFileUri));
                return true;
            } catch (Exception ex) {
                msgId = R.string.msg_no_email_client;
            }// w  w  w  . j a  v a2s  .  com
        }
    }
        break;
    case R.id.history_menu_send_dta_other: {
        Uri dtaFileUri = (Uri) message.obj;
        if (dtaFileUri != null) {
            startActivity(Intent.createChooser(createShareIntent(dtaFileUri), "Send with..."));
            return true;
        }
    }
        break;
    case R.id.history_menu_send_dta_save:
        break;
    case R.id.es_send_succeeded: {
        mSendingProgressDialog.dismiss();

        HistoryItem historyItem = historyFragment.getHistoryItemOnPosition(message.arg1);

        if (historyItem != null) {
            String filename = getResources().getString(R.string.history_item_sent);
            historyItem.update(new HistoryItem.Builder(historyItem).setDtaFile(filename).create());
            mHistoryManager.updateHistoryItemFileName(historyItem.getItemId(), filename);

            //historyFragment.updatePosition(message.arg1, historyItem);
            historyFragment.dataChanged();

            PsDetailFragment fragment = (PsDetailFragment) getFragmentManager()
                    .findFragmentById(R.id.ps_detail_container);

            if (fragment != null) {
                fragment.getHistoryItem().update(historyItem);
                fragment.updateDtaFilename(fragment.getView());
            }
        }

        msgId = R.string.msg_coderow_sent;
    }
        break;
    case R.id.es_send_failed:
        mSendingProgressDialog.dismiss();
        msgId = R.string.msg_coderow_not_sent;
        break;
    }

    if (msgId != 0) {
        Toast toast = Toast.makeText(getApplicationContext(), msgId, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.BOTTOM, 0, 0);
        toast.show();
        return true;
    }

    return false;
}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

@Override
public Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_REMINDER_CONTACTS_SERVICE_FAILED_LICENSING:
        AlertDialog.Builder buildersvc = new AlertDialog.Builder(this);
        buildersvc.setMessage(//from  w ww . j  a v a 2  s .  com
                "The Reminder Contact Service add-on that you've got installed is not a licensed version");
        buildersvc.setCancelable(false)
                .setNeutralButton(R.string.msg_cus, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        String[] mailto = { "info@intelligentreminder.com", "" };
                        Intent sendIntent = new Intent(Intent.ACTION_SEND);
                        sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
                        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "".toString());
                        sendIntent.putExtra(Intent.EXTRA_TEXT, "".toString());
                        sendIntent.setType("text/plain");
                        startActivity(Intent.createChooser(sendIntent, "Send EMail..."));
                    }
                }).setPositiveButton(R.string.msg_register, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                        if (INeedToo.IS_ANDROID_VERSION) {
                            String uri = getString(R.string.indeedtopayforservice);
                            Intent ii3 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                            startActivity(ii3);
                        } else {
                            Uri uri = Uri.parse(
                                    "http://www.amazon.com/gp/mas/dl/android?p=com.mibr.android.remindercontacts");
                            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                            startActivity(intent);
                        }

                        isReminderContactsAvailable = true;
                        iDidReminderContacts = false;
                    }
                }).setNegativeButton(R.string.msg_cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        AlertDialog alert = buildersvc.create();
        return alert;

    case DOING_SAMPLE_NEEDS_DIALOG:
        if (allItems == null) {
            return null;
        }
        dialogDoingSamples = new Dialog(this);
        dialogDoingSamples.setOwnerActivity(this);
        dialogDoingSamples.setContentView(R.layout.ineedvoiceprogress);
        dialogDoingSamples.setTitle("Working ...");
        ((Button) dialogDoingSamples.findViewById(R.id.needvoiceprogress_cancel)).setEnabled(true);
        ((Button) dialogDoingSamples.findViewById(R.id.needvoiceprogress_ok)).setEnabled(false);
        ;
        //         dialogDoingSamples.show();
        ArrayList stuff = new ArrayList();
        stuff.add(dialogDoingSamples);
        stuff.add(getApplicationContext());
        stuff.add(this);
        stuff.add(getLocationManager());
        stuff.add(getDbAdapter());
        stuff.add(allItems.get(whereImAtInAllItems));
        stuff.add(new Integer(1));
        new NeedByVoiceProgress().execute(stuff);
        return dialogDoingSamples;

    case DIALOG_SAMPLES:
        Dialog aDialog = null;
        AlertDialog.Builder builder2;
        LayoutInflater inflater2 = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout2 = inflater2.inflate(R.layout.ineedsamples, (ViewGroup) findViewById(R.id.hijklmnop));
        builder2 = new AlertDialog.Builder(this);
        builder2.setView(layout2);
        builder2.setTitle("Build Sample Data Set");
        builder2.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                allItems = new ArrayList<ArrayList<String>>();
                Boolean doit = false;
                StringBuilder sb = new StringBuilder();
                StringBuilder sb2 = new StringBuilder();
                StringBuilder sb3 = new StringBuilder();
                int cnt = 0;
                Boolean dw = false;
                ArrayList<String> jdmatchesSS = null;
                ;
                sb.append("I need Print Cartridges description HP 28 and 48 ");
                if (mWalmart != null && mWalmart.isChecked()) {
                    sb.append(" location Walmart ");
                    dw = true;
                }
                if (mWalgreens != null && mWalgreens.isChecked()) {
                    sb.append(" location Walgreens ");
                    dw = true;
                }
                if (dw) { // they checked something
                    doit = true;
                    jdmatchesSS = new ArrayList<String>();
                    jdmatchesSS.add(sb.toString());
                    allItems.add(jdmatchesSS);
                    cnt++;
                }
                if (mSevenEleven != null && mSevenEleven.isChecked()) {
                    sb3.append("I need Energy Drink description Red Bull location 7-Eleven ");
                    ArrayList<String> jdmatches = new ArrayList<String>();
                    jdmatches.add(sb3.toString());
                    allItems.add(jdmatches);
                    cnt++;
                    doit = true;
                }

                if (mStarbucks != null && mStarbucks.isChecked()) {
                    sb2.append("I need Coffee description French Roast location Starbucks");
                    ArrayList<String> jdmatches = new ArrayList<String>();
                    jdmatches.add(sb2.toString());
                    allItems.add(jdmatches);
                    cnt++;
                    doit = true;
                }
                if (doit) {
                    whereImAtInAllItems = 0;
                    INeedToo.this.showDialog(DOING_SAMPLE_NEEDS_DIALOG);
                }

            }
        });
        mWalmart = (CheckBox) layout2.findViewById(R.id.BuildWalmart);
        mWalgreens = (CheckBox) layout2.findViewById(R.id.BuildWalgreens);
        mSevenEleven = (CheckBox) layout2.findViewById(R.id.Build7Eleven);
        mStarbucks = (CheckBox) layout2.findViewById(R.id.BuildStarbucks);

        aDialog = builder2.create();
        return aDialog;

    case DIALOG_SPLASH:
        /*
        jdd=new Dialog(mContext);
        jdd.setContentView(R.layout.ineed2splash);
        jdd.setTitle("W E L C O M E");
        */

        AlertDialog.Builder builder;
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.ineed2splashv2,
                (ViewGroup) findViewById(R.id.ScrollView01lmnop2));
        builder = new AlertDialog.Builder(this);

        builder.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                if (mWantSample != null) {
                    if (mWantSample.isChecked()) {
                        showDialog(DIALOG_SAMPLES);
                    }
                }
            }
        });
        builder.setTitle("W E L C O M E");
        if (getDbAdapter().thereAreSomeLocationsOnSystem()) {
            LinearLayout ll = (LinearLayout) layout.findViewById(R.id.CreateDefaultValues);
            ll.setVisibility(View.INVISIBLE);
        } else {
            mWantSample = (CheckBox) layout.findViewById(R.id.BuildDefaultValues);
        }
        builder.setView(layout);
        jdd = builder.create();
        //Button butt=(Button)jdd.findViewById(R.id.Button01);
        /*butt.setOnClickListener(new View.OnClickListener() {
                   
           @Override
           public void onClick(View v) {
              jdd.cancel();
           }
        });
        */
        break;
    default:
        return null;
    }
    return jdd;

}

From source file:br.com.anteros.vendas.gui.AnexoCadastroActivity.java

/**
 * Seleciona um arquivo do tipo imagem para anexar
 *///from   w  ww. j  av a2s .com
private void selecionarImagem() {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Selecione"), SELECIONAR_ARQUIVO);
}

From source file:cn.ttyhuo.view.UserView.java

/**
 * // w  w  w  . j  av  a2  s .c om
 * @param context 
 * @param activityTitle Activity??
 * @param msgTitle ?
 * @param msgText ?
 * @param imgPath ?null
 */
public static void shareMsg(Context context, String activityTitle, String msgTitle, String msgText, File f) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    if (f == null || !f.exists() || !f.isFile()) {
        intent.setType("text/plain"); // 
    } else {
        intent.setType("image/png");
        Uri u = Uri.fromFile(f);
        //Uri u = Uri.parse(imgPath);
        intent.putExtra(Intent.EXTRA_STREAM, u);
    }
    intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);
    intent.putExtra(Intent.EXTRA_TEXT, msgText);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(Intent.createChooser(intent, activityTitle));
}

From source file:com.amaze.filemanager.fragments.preference_fragments.Preffrag.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceUtils.reset();//from  w w w  .  j  a  v a 2  s  . c  o m
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    final int th1 = Integer.parseInt(sharedPref.getString("theme", "0"));
    theme = th1 == 2 ? PreferenceUtils.hourOfDay() : th1;
    findPreference("donate").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            ((com.amaze.filemanager.activities.Preferences) getActivity()).donate();
            return false;
        }
    });
    findPreference("columns").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            final String[] sort = getResources().getStringArray(R.array.columns);
            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.title(R.string.gridcolumnno);
            int current = Integer.parseInt(sharedPref.getString("columns", "-1"));
            current = current == -1 ? 0 : current;
            if (current != 0)
                current = current - 1;
            a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    sharedPref.edit().putString("columns", "" + (which != 0 ? sort[which] : "" + -1)).commit();
                    dialog.dismiss();
                    return true;
                }
            });
            a.build().show();
            return true;
        }
    });

    findPreference("theme").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            String[] sort = getResources().getStringArray(R.array.theme);
            int current = Integer.parseInt(sharedPref.getString("theme", "0"));
            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    sharedPref.edit().putString("theme", "" + which).commit();
                    dialog.dismiss();
                    restartPC(getActivity());
                    return true;
                }
            });
            a.title(R.string.theme);
            a.build().show();
            return true;
        }
    });
    findPreference("colors").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            ((com.amaze.filemanager.activities.Preferences) getActivity()).selectItem(1);
            return true;
        }
    });

    final CheckBx rootmode = (CheckBx) findPreference("rootmode");
    rootmode.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            boolean b = sharedPref.getBoolean("rootmode", false);
            if (b) {
                if (RootTools.isAccessGiven()) {
                    rootmode.setChecked(true);

                } else {
                    rootmode.setChecked(false);

                    Toast.makeText(getActivity(), getResources().getString(R.string.rootfailure),
                            Toast.LENGTH_LONG).show();
                }
            } else {
                rootmode.setChecked(false);

            }

            return false;
        }
    });

    // Authors
    Preference preference4 = (Preference) findPreference("authors");
    preference4.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            skin = PreferenceUtils.getPrimaryColorString(sharedPref);
            int fab_skin = Color.parseColor(PreferenceUtils.getAccentString(sharedPref));
            if (theme == 1)
                a.theme(Theme.DARK);

            a.positiveText(R.string.close);
            a.positiveColor(fab_skin);
            LayoutInflater layoutInflater = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = layoutInflater.inflate(R.layout.authors, null);
            a.customView(view, true);
            a.title(R.string.authors);
            a.callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog materialDialog) {

                    materialDialog.cancel();
                }

                @Override
                public void onNegative(MaterialDialog materialDialog) {

                }
            });
            /*a.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.cancel();
            }
            });*/
            a.build().show();

            final Intent intent = new Intent(Intent.ACTION_VIEW);

            TextView googlePlus1 = (TextView) view.findViewById(R.id.googlePlus1);
            googlePlus1.setTextColor(Color.parseColor(skin));
            TextView googlePlus2 = (TextView) view.findViewById(R.id.googlePlus2);
            googlePlus2.setTextColor(Color.parseColor(skin));
            TextView git1 = (TextView) view.findViewById(R.id.git1);
            git1.setTextColor(Color.parseColor(skin));
            TextView git2 = (TextView) view.findViewById(R.id.git2);
            git2.setTextColor(Color.parseColor(skin));

            googlePlus1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.setData(Uri.parse("https://plus.google.com/u/0/110424067388738907251/"));
                    startActivity(intent);
                }
            });
            googlePlus2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.setData(Uri.parse("https://plus.google.com/+VishalNehra/"));
                    startActivity(intent);
                }
            });
            git1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.setData(Uri.parse("https://github.com/arpitkh96"));
                    startActivity(intent);
                }
            });
            git2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.setData(Uri.parse("https://github.com/vishal0071"));
                    startActivity(intent);
                }
            });

            // icon credits
            TextView textView = (TextView) view.findViewById(R.id.icon_credits);
            textView.setMovementMethod(LinkMovementMethod.getInstance());
            textView.setLinksClickable(true);
            textView.setText(Html.fromHtml(getActivity().getString(R.string.icon_credits)));

            return false;
        }
    });

    // Changelog
    Preference preference1 = (Preference) findPreference("changelog");
    preference1.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.title(R.string.changelog);
            a.content(Html.fromHtml(getActivity().getString(R.string.changelog_version_9)
                    + getActivity().getString(R.string.changelog_change_9)
                    + getActivity().getString(R.string.changelog_version_8)
                    + getActivity().getString(R.string.changelog_change_8)
                    + getActivity().getString(R.string.changelog_version_7)
                    + getActivity().getString(R.string.changelog_change_7)
                    + getActivity().getString(R.string.changelog_version_6)
                    + getActivity().getString(R.string.changelog_change_6)
                    + getActivity().getString(R.string.changelog_version_5)
                    + getActivity().getString(R.string.changelog_change_5)
                    + getActivity().getString(R.string.changelog_version_4)
                    + getActivity().getString(R.string.changelog_change_4)
                    + getActivity().getString(R.string.changelog_version_3)
                    + getActivity().getString(R.string.changelog_change_3)
                    + getActivity().getString(R.string.changelog_version_2)
                    + getActivity().getString(R.string.changelog_change_2)
                    + getActivity().getString(R.string.changelog_version_1)
                    + getActivity().getString(R.string.changelog_change_1)));
            a.negativeText(R.string.close);
            a.positiveText(R.string.fullChangelog);
            int fab_skin = Color.parseColor(PreferenceUtils.getAccentString(sharedPref));
            a.positiveColor(fab_skin);
            a.negativeColor(fab_skin);
            a.callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog materialDialog) {

                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://github.com/arpitkh96/AmazeFileManager/commits/master"));
                    startActivity(intent);
                }

                @Override
                public void onNegative(MaterialDialog materialDialog) {

                    materialDialog.cancel();
                }
            }).build().show();
            return false;
        }
    });

    // Open Source Licenses
    Preference preference2 = (Preference) findPreference("os");
    //Defining dialog layout
    final Dialog dialog = new Dialog(getActivity(),
            android.R.style.Theme_Holo_Light_DialogWhenLarge_NoActionBar);
    //dialog.setTitle("Open-Source Licenses");
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    final View dialog_view = inflater.inflate(R.layout.open_source_licenses, null);
    dialog.setContentView(dialog_view);

    preference2.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {

            WebView wv = (WebView) dialog_view.findViewById(R.id.webView1);
            PreferenceUtils preferenceUtils = new PreferenceUtils();
            wv.loadData(PreferenceUtils.LICENCE_TERMS, "text/html", null);
            dialog.show();
            return false;
        }
    });

    // Feedback
    Preference preference3 = (Preference) findPreference("feedback");
    preference3.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", "arpitkh96@gmail.com", null));
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback : Amaze File Manager");
            Toast.makeText(getActivity(), getActivity().getFilesDir().getPath(), Toast.LENGTH_SHORT).show();
            File f = new File(getActivity().getExternalFilesDir("internal"), "log.txt");
            if (f.exists()) {
                emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
            }
            startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.feedback)));
            return false;
        }
    });

    // rate
    Preference preference5 = (Preference) findPreference("rate");
    preference5.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent1 = new Intent(Intent.ACTION_VIEW);
            intent1.setData(Uri.parse("market://details?id=com.amaze.filemanager"));
            startActivity(intent1);
            return false;
        }
    });

    // studio
    Preference studio = findPreference("studio");
    studio.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            COUNT++;
            if (COUNT >= 5) {
                if (toast != null)
                    toast.cancel();
                toast = Toast.makeText(getActivity(), "Studio Mode : " + COUNT, Toast.LENGTH_SHORT);
                toast.show();

                sharedPref.edit().putInt("studio", Integer.parseInt(Integer.toString(COUNT) + "000")).apply();
            } else {
                sharedPref.edit().putInt("studio", 0).apply();
            }
            return false;
        }
    });

    // G+
    gplus = (CheckBx) findPreference("plus_pic");
    gplus.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (gplus.isChecked()) {
                boolean b = checkGplusPermission();
                if (!b)
                    requestGplusPermission();
            }
            return false;
        }
    });
    if (BuildConfig.IS_VERSION_FDROID)
        gplus.setEnabled(false);

    // Colored navigation bar
}

From source file:alaindc.memenguage.View.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override//from w ww.  j a va 2 s  .co m
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_home) {

    } else if (id == R.id.nav_settings) {
        Intent settingsActivity = new Intent(this, SettingsActivity.class);
        startActivity(settingsActivity);
    } else if (id == R.id.nav_send) {

        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, R.style.MyDialogTheme);
        builder.setTitle("Upload Database").setMessage("Are you sure?")
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        progressDialog.setTitle("Upload");
                        progressDialog.setMessage("Uploading to server... please wait");
                        progressDialog.show();
                        ServerRequests.uploadFile(personId,
                                getApplicationContext().getDatabasePath(Constants.DBNAME),
                                getApplicationContext());
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).create().show();

    } else if (id == R.id.nav_get) {

        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, R.style.MyDialogTheme);
        builder.setTitle("Download Database").setMessage("Are you sure?")
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        progressDialog.setTitle("Download");
                        progressDialog.setMessage("Downloading from server... please wait");
                        progressDialog.show();
                        ServerRequests.downloadFile(personId,
                                getApplicationContext().getDatabasePath(Constants.DBNAME),
                                getApplicationContext());
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).create().show();

    } else if (id == R.id.nav_share) {
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = "Memenguage, the best app on the world! Maybe.";
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Memento mori!");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, "Share via"));
    } else if (id == R.id.nav_signin) {
        Intent signinintent = new Intent(this, SignInActivity.class);
        signinintent.setAction(Constants.SIGNIN_LOGOUT);
        startActivity(signinintent);
    } else if (id == R.id.nav_play) {
        Intent playActivity = new Intent(this, PlayActivity.class);
        startActivity(playActivity);
    } else if (id == R.id.nav_stats) {
        Intent statsActivity = new Intent(this, StatsActivity.class);
        startActivity(statsActivity);
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.njlabs.amrita.aid.aums.AumsResourcesActivity.java

private void openFile(File file, String fileName) {
    Intent fileOpenIntent = new Intent(Intent.ACTION_VIEW);
    fileOpenIntent.setData(Uri.fromFile(file));
    Intent fileChooserIntent = Intent.createChooser(fileOpenIntent, "Open " + fileName + " with:");
    startActivity(fileChooserIntent);//from   w w w.  j a va 2s  .  c  om

}

From source file:com.dycody.android.idealnote.MainActivity.java

/**
 * Notes sharing/*from   w w  w. java2 s. c o  m*/
 */
public void shareNote(Note note) {

    String titleText = note.getTitle();

    String contentText = titleText + System.getProperty("line.separator") + note.getContent();

    Intent shareIntent = new Intent();
    // Prepare sharing intent with only text
    if (note.getAttachmentsList().size() == 0) {
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");

        // Intent with single image attachment
    } else if (note.getAttachmentsList().size() == 1) {
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType(note.getAttachmentsList().get(0).getMime_type());
        shareIntent.putExtra(Intent.EXTRA_STREAM, note.getAttachmentsList().get(0).getUri());

        // Intent with multiple images
    } else if (note.getAttachmentsList().size() > 1) {
        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<>();
        // A check to decide the mime type of attachments to share is done here
        HashMap<String, Boolean> mimeTypes = new HashMap<>();
        for (Attachment attachment : note.getAttachmentsList()) {
            uris.add(attachment.getUri());
            mimeTypes.put(attachment.getMime_type(), true);
        }
        // If many mime types are present a general type is assigned to intent
        if (mimeTypes.size() > 1) {
            shareIntent.setType("*/*");
        } else {
            shareIntent.setType((String) mimeTypes.keySet().toArray()[0]);
        }

        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    }
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
    shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);

    startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.share_message_chooser)));
}