Example usage for android.net Uri fromParts

List of usage examples for android.net Uri fromParts

Introduction

In this page you can find the example usage for android.net Uri fromParts.

Prototype

public static Uri fromParts(String scheme, String ssp, String fragment) 

Source Link

Document

Creates an opaque Uri from the given components.

Usage

From source file:moe.johnny.tombstone.ui.PreventFragment.java

private boolean startActivity(int id, String packageName) {
    String action;//  w w w  .ja  v  a2s . co m
    if (id == R.string.app_info) {
        action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS;
    } else if (id == R.string.uninstall) {
        action = Intent.ACTION_DELETE;
    } else {
        return false;
    }
    mActivity.startActivity(new Intent(action, Uri.fromParts("package", packageName, null)));
    return true;
}

From source file:com.github.fi3te.iliasdownloader.view.IliasActivity.java

@Override
public boolean onNavigationItemSelected(final MenuItem menuItem) {
    pendingRunnable = new Runnable() {
        @Override/* w w  w .  j  av a 2 s .co m*/
        public void run() {
            switch (menuItem.getItemId()) {
            case R.id.ignore_list_item:
                if (!ilias.isRunning()) {
                    startActivity(new Intent(IliasActivity.this, BlockedFilesActivity.class));
                } else {
                    Snackbar.make(coordinatorLayout, R.string.synchronisation_is_running, Snackbar.LENGTH_SHORT)
                            .show();
                }
                break;
            case R.id.recommendation_item:
                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                        getResources().getString(R.string.app_name));
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                        getResources().getString(R.string.recommendation_text));
                startActivity(
                        Intent.createChooser(sharingIntent, getResources().getString(R.string.recommend_by)));
                break;
            case R.id.rating_item:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
                        "https://play.google.com/store/apps/details?id=com.github.fi3te.iliasdownloader")));
                break;
            case R.id.bug_report_item:
                String versionName = "X.X";
                try {
                    PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                    versionName = getResources().getString(R.string.version) + " " + packageInfo.versionName;
                } catch (PackageManager.NameNotFoundException e) {
                    e.printStackTrace();
                }
                Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                        Uri.fromParts("mailto", "fiete.wennier@gmail.com", null));
                emailIntent.putExtra(Intent.EXTRA_SUBJECT,
                        getResources().getString(R.string.app_name) + " " + versionName);
                startActivity(Intent.createChooser(emailIntent, "E-Mail"));
                break;
            case R.id.settings_item:
                startActivity(new Intent(IliasActivity.this, SettingsActivity.class));
                break;
            case R.id.login_item:
                startActivity(new Intent(IliasActivity.this, LoginActivity.class));
                break;
            case R.id.logout_item:
                if (ilias.logout()) {
                    updateNavigationView();
                } else {
                    Snackbar.make(coordinatorLayout, R.string.synchronisation_is_running, Snackbar.LENGTH_SHORT)
                            .show();
                }
                break;
            }
        }
    };
    drawerLayout.closeDrawers();
    return true;
}

From source file:net.networksaremadeofstring.rhybudd.RhybuddHome.java

private void ProcessDrawerClick(int position) {
    switch (position) {
    case SETTINGS: {
        Intent SettingsIntent = new Intent(RhybuddHome.this, SettingsFragment.class);
        this.startActivityForResult(SettingsIntent, 99);

    }/*from   w w w .  ja v a  2  s  .c  o m*/
        break;

    case CONFIGURERHYBUDDPUSH: {
        Intent PushSettingsIntent = new Intent(RhybuddHome.this, PushConfigActivity.class);
        this.startActivityForResult(PushSettingsIntent, ZenossAPI.ACTIVITYRESULT_PUSHCONFIG);
    }
        break;

    case HELP: {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse("http://wiki.zenoss.org/index.php?title=Rhybudd#Getting_Started"));
        startActivityForResult(i, 20);
    }
        break;

    case INFRASTRUCTURE: {
        Intent DeviceList = new Intent(RhybuddHome.this, ViewZenossDeviceListActivity.class);
        RhybuddHome.this.startActivityForResult(DeviceList, 20);
    }
        break;

    case GROUPS: {
        Intent GroupsIntent = new Intent(RhybuddHome.this, ViewZenossGroupsActivity.class);
        RhybuddHome.this.startActivityForResult(GroupsIntent, 20);
    }
        break;

    case MANAGEDATABASE: {
        Intent MangeDBIntent = new Intent(RhybuddHome.this, ManageDatabase.class);
        RhybuddHome.this.startActivityForResult(MangeDBIntent, 20);
    }
        break;

    case FEEDBACK: {
        try {
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", "Gareth@DataSift.com", null));
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback suggestion for Rhybudd");
            startActivity(Intent.createChooser(emailIntent, "Send feedback as email"));
        } catch (Exception e) {
            Toast.makeText(RhybuddHome.this,
                    "There was a problem launching your email client.\n\nPlease email Gareth@DataSift.com with your feedback.",
                    Toast.LENGTH_LONG).show();
        }
    }
        break;
    }

    // update selected item and title, then close the drawer
    //mDrawerList.setItemChecked(position, true);
    mDrawerLayout.closeDrawer(mDrawerList);
}

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

@Override
public boolean onPreferenceClick(Preference preference) {
    final String[] sort;
    MaterialDialog.Builder builder;// w  ww  .j a v a  2 s. c  o m

    switch (preference.getKey()) {
    case "columns":
        sort = getResources().getStringArray(R.array.columns);
        builder = new MaterialDialog.Builder(getActivity());
        builder.theme(utilsProvider.getAppTheme().getMaterialDialogTheme());
        builder.title(R.string.gridcolumnno);
        int current = Integer.parseInt(sharedPref.getString("columns", "-1"));
        current = current == -1 ? 0 : current;
        if (current != 0)
            current = current - 1;
        builder.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;
            }
        });
        builder.build().show();
        return true;
    case "theme":
        sort = getResources().getStringArray(R.array.theme);
        current = Integer.parseInt(sharedPref.getString("theme", "0"));
        builder = new MaterialDialog.Builder(getActivity());
        //builder.theme(utilsProvider.getAppTheme().getMaterialDialogTheme());
        builder.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
            @Override
            public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                utilsProvider.getThemeManager().setAppTheme(AppTheme.fromIndex(which)).save();

                Log.d("theme", AppTheme.fromIndex(which).name());

                dialog.dismiss();
                restartPC(getActivity());
                return true;
            }
        });
        builder.title(R.string.theme);
        builder.build().show();
        return true;
    case "sidebar_folders_enable":
        sharedPref.edit().putBoolean(PREFERENCE_SHOW_SIDEBAR_FOLDERS,
                !sharedPref.getBoolean(PREFERENCE_SHOW_SIDEBAR_FOLDERS, true)).apply();
        return true;
    case "sidebar_quickaccess_enable":
        sharedPref.edit().putBoolean(PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES,
                !sharedPref.getBoolean(PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES, true)).apply();
        return true;
    case PREFERENCE_SHOW_HIDDENFILES:
        setEnabledShortcuts();
        return false;
    case PREFERENCE_ROOTMODE:
        setEnabledShortcuts();

        /*
        boolean b = sharedPref.getBoolean("rootmode", false);
        if (b) {
            if (MainActivity.shellInteractive.isRunning()) {
                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;
    case "feedback":
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", "vishalmeham2@gmail.com", null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback : Amaze File Manager");
        startActivity(Intent.createChooser(emailIntent, getResources().getString(feedback)));
        return false;
    case PREFERENCE_KEY_ABOUT:
        startActivity(new Intent(getActivity(), AboutActivity.class));
        return false;
    case "plus_pic":
        if (gplus.isChecked()) {
            boolean b = MainActivityHelper.checkAccountsPermission(getActivity());
            if (!b)
                MainActivityHelper.requestAccountsPermission(getActivity());
        }
        return false;
    /*FROM HERE BE FRAGMENTS*/
    case "colors":
        ((PreferencesActivity) getActivity()).selectItem(PreferencesActivity.COLORS_PREFERENCE);
        return true;
    case "sidebar_folders":
        ((PreferencesActivity) getActivity()).selectItem(PreferencesActivity.FOLDERS_PREFERENCE);
        return true;
    case "sidebar_quickaccess":
        ((PreferencesActivity) getActivity()).selectItem(PreferencesActivity.QUICKACCESS_PREFERENCE);
        return true;
    case "advancedsearch":
        ((PreferencesActivity) getActivity()).selectItem(PreferencesActivity.ADVANCEDSEARCH_PREFERENCE);
        return true;
    }

    return false;
}

From source file:org.dmfs.webcal.MainActivity.java

@Override
protected boolean selectItem(long id) {
    if (id == mSelectedItemId) {
        super.selectItem(id);
        return true;
    }/*from www . j  a  v  a  2  s  .c o  m*/

    Fragment fragment = null;
    if (id == R.id.side_nav_favorite_calendars) {
        fragment = GenericListFragment.newInstance(
                CalendarContentContract.ContentItem.getStarredItemsContentUri(this),
                getString(R.string.side_nav_favorite_calendars), R.string.error_favorite_calendars_empty,
                GenericListFragment.PROJECTION2, true);
        mSelectedItemId = id;
        Analytics.event("fav-calendars", "menu", null, null, null, null);
    } else if (id == R.id.side_nav_my_calendars) {
        fragment = GenericListFragment.newInstance(
                CalendarContentContract.SubscribedCalendars.getContentUri(this),
                getString(R.string.side_nav_my_calendars), R.string.error_my_calendars_empty,
                GenericListFragment.PROJECTION, true);

        mSelectedItemId = id;
        Analytics.event("my-calendars", "menu", null, null, null, null);
    } else if (id == R.id.side_nav_all_calendars) {
        fragment = PagerFragment.newInstance(this, 0, getItemTitleById(id), -1);
        mSelectedItemId = id;
        Analytics.event("all-calendars", "menu", null, null, null, null);
    } else if (id == R.id.side_nav_faq) {
        Intent faqIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.faq_url)));
        startActivity(faqIntent);
        Analytics.event("faq", "menu", null, null, null, null);
    } else if (id == R.id.side_nav_feedback) {
        Analytics.event("feedback", "menu", null, null, null, null);
        PackageManager pm = getPackageManager();
        PackageInfo pi = null;
        try {
            pi = pm.getPackageInfo(getPackageName(), 0);
        } catch (NameNotFoundException e) {
            // that should not happen!
        }

        StringBuilder emailContent = new StringBuilder(256);
        emailContent.append("\r\n\r\n\r\n\r\n\r\n--------------\r\n");
        emailContent.append("app: ").append(getPackageName()).append("\r\n");
        emailContent.append("version: ").append(pi.versionName).append(" / ").append(pi.versionCode)
                .append("\r\n");
        emailContent.append("locale: ").append(Locale.getDefault().getLanguage()).append("\r\n");
        emailContent.append("location: ").append(Locale.getDefault().getCountry()).append("\r\n");
        emailContent.append("timezone: ").append(TimeZone.getDefault().getID()).append("\r\n");
        emailContent.append("device: ").append(android.os.Build.DEVICE).append("\r\n");
        emailContent.append("model: ").append(android.os.Build.MODEL).append("\r\n");
        emailContent.append("os version: ").append(android.os.Build.VERSION.RELEASE).append(" / ")
                .append(android.os.Build.VERSION.SDK_INT).append("\r\n");
        emailContent.append("firmware: ").append(android.os.Build.ID).append("\r\n");

        Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                Uri.fromParts("mailto", getString(R.string.contact_address), null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Contact");
        emailIntent.putExtra(Intent.EXTRA_TEXT, emailContent.toString());
        startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email)));
        // fragment = ContactFragment.newInstance();
    } else if (id == R.id.side_nav_settings) {
        Intent preferencesIntent = new Intent(this, PreferencesActivity.class);
        startActivity(preferencesIntent);
        Analytics.event("settings", "menu", "settings clicked", null, null, null);
    }

    if (fragment != null) {
        // drop backstack
        mFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.content, fragment);
        fragmentTransaction.commit();
    }

    super.selectItem(id);

    return fragment != null;
}

From source file:com.pdftron.pdf.controls.ReflowPagerAdapter.java

public void initialize() {
    // set loading file depending on night mode
    if (sIsNightMode) {
        mLoadingFile = NIGHT_MODE_LOADING_FILE;
    } else {//from  w  w  w . ja  va 2s.c om
        mLoadingFile = NORMAL_MODE_LOADING_FILE;
    }

    if (mWebViewRepository != null) {
        mWebViewRepository.reset();
    }

    ReflowWebView[] webViews = mWebViewRepository.getWebViews();
    for (final ReflowWebView webView : webViews) {
        webView.clearCache(true); // reset reading css file
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWillNotCacheDrawing(false);
        if (sIsNightMode) {
            webView.setBackgroundColor(Color.BLACK);
        } else {
            webView.setBackgroundColor(Color.WHITE);
        }
        webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        webView.loadUrl("about:blank");
        webView.setListener(this);

        webView.setWebChromeClient(new WebChromeClient()); // enable the use of methods like alert in javascript
        webView.setWebViewClient(new WebViewClient() {
            // now all links the user clicks load in your WebView
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
                Log.e(TAG, description + " url: " + failingUrl);
            }

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                super.onReceivedSslError(view, handler, error);
                Log.e(TAG, error.toString());
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.startsWith("file:///") && url.endsWith(".html")) {
                    int slashPos = url.lastIndexOf('/');
                    try {
                        int objNum = Integer.parseInt(url.substring(slashPos + 1, url.length() - 5));
                        int pageNum = 0;
                        for (int i = 1; i <= mPageCount; i++) {
                            try {
                                Page page = mDoc.getPage(i);
                                if (page.getSDFObj().getObjNum() == objNum) {
                                    pageNum = i;
                                    break;
                                }
                            } catch (Exception e) {
                            }
                        }
                        if (pageNum != 0) {
                            mViewPager.setCurrentItem(pageNum - 1);
                        }
                    } catch (NumberFormatException e) {
                        return true;
                    }
                } else {
                    if (url.startsWith("mailto:")
                            || android.util.Patterns.EMAIL_ADDRESS.matcher(url).matches()) {
                        if (url.startsWith("mailto:")) {
                            url = url.substring(7);
                        }
                        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", url, null));
                        mContext.startActivity(Intent.createChooser(intent,
                                mContext.getResources().getString(R.string.tools_misc_sendemail)));
                    } else {
                        // ACTION_VIEW needs the address to have http or https
                        if (!url.startsWith("https://") && !url.startsWith("http://")) {
                            url = "http://" + url;
                        }
                        if (DEBUG)
                            Log.d(TAG, url);
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                        mContext.startActivity(Intent.createChooser(intent,
                                mContext.getResources().getString(R.string.tools_misc_openwith)));
                    }
                }
                return true;
            }
        });
    }
}

From source file:com.scrachx.foodfacts.checker.ui.product.ProductActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case PermissionUtils.MY_PERMISSIONS_REQUEST_CAMERA:
    case PermissionUtils.MY_PERMISSIONS_REQUEST_STORAGE: {
        if (grantResults.length <= 0 || grantResults[0] != PERMISSION_GRANTED) {
            new MaterialDialog.Builder(this).title(R.string.permission_title)
                    .content(R.string.permission_denied).negativeText(R.string.txt_no)
                    .positiveText(R.string.txt_yes).onPositive((dialog, which) -> {
                        Intent intent = new Intent();
                        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        Uri uri = Uri.fromParts("package", getPackageName(), null);
                        intent.setData(uri);
                        startActivity(intent);
                    }).show();/*from ww  w.  jav a 2s .c om*/
        }
    }
    }
}

From source file:com.silentcircle.contacts.list.ShortcutIntentBuilder.java

private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData,
        String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) {
    Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    Bitmap bitmap = null;//w w w .j ava2  s.c o  m
    Uri phoneUri = null;
    if (Intent.ACTION_CALL.equals(shortcutAction)) {
        // Make the URI a direct tel: URI so that it will always continue to work
        phoneUri = Uri.fromParts(Constants.SCHEME_TEL, phoneNumber, null);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.badge_action_call);
        //        } else {
        //            phoneUri = Uri.fromParts(Constants.SCHEME_SMSTO, phoneNumber, null);
        //            bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel,
        //                    R.drawable.badge_action_sms);
    }

    Intent shortcutIntent = new Intent(shortcutAction, phoneUri);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);

    mListener.onShortcutIntentCreated(uri, intent);
}

From source file:com.tfc.webviewer.ui.WebViewerActivity.java

@Override
public void openEmail(String email) {
    Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null));
    startActivity(Intent.createChooser(intent, getString(R.string.email)));
}

From source file:cordova.plugins.Diagnostic.java

public void switchToAppSettings() {
    Log.d(TAG, "Switch to App Settings");
    Intent appIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", cordova.getActivity().getPackageName(), null);
    appIntent.setData(uri);// w w w . j  av  a 2  s  . c  om
    cordova.getActivity().startActivity(appIntent);
}