Search in sources :

Example 1 with CommonActivity

use of com.orgzly.android.ui.CommonActivity in project orgzly-android by orgzly.

the class DirectoryRepoFragment method onOpenBrowser.

private void onOpenBrowser() {
    boolean browserStarted = false;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        /*
             * Apparently some devices do not handle this intent.
             * Fallback to internal browser.
             */
        try {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
            getActivity().startActivityForResult(intent, ReposActivity.ACTION_OPEN_DOCUMENT_TREE_REQUEST_CODE);
            browserStarted = true;
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
        }
    }
    if (!browserStarted) {
        Activity activity = getActivity();
        if (activity != null) {
            /* Close the keyboard before opening the browser. */
            ActivityUtils.INSTANCE.closeSoftKeyboard(getActivity());
            /* Open internal browser. */
            ((CommonActivity) activity).runWithPermission(AppPermissions.Usage.LOCAL_REPO, this::startBrowserDelayed);
        }
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) ReposActivity(com.orgzly.android.ui.ReposActivity) CommonActivity(com.orgzly.android.ui.CommonActivity) Activity(android.app.Activity) Intent(android.content.Intent) CommonActivity(com.orgzly.android.ui.CommonActivity)

Aggregations

Activity (android.app.Activity)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 CommonActivity (com.orgzly.android.ui.CommonActivity)1 ReposActivity (com.orgzly.android.ui.ReposActivity)1