Search in sources :

Example 1 with ActivityStateListener

use of org.chromium.base.ApplicationStatus.ActivityStateListener in project AndroidChromium by JackyAndroid.

the class PermissionUpdateInfoBarDelegate method requestPermissions.

@CalledByNative
private void requestPermissions() {
    WindowAndroid windowAndroid = mContentViewCore.getWindowAndroid();
    if (windowAndroid == null) {
        nativeOnPermissionResult(mNativePtr, false);
        return;
    }
    boolean canRequestAllPermissions = true;
    for (int i = 0; i < mAndroidPermisisons.length; i++) {
        canRequestAllPermissions &= (windowAndroid.hasPermission(mAndroidPermisisons[i]) || windowAndroid.canRequestPermission(mAndroidPermisisons[i]));
    }
    if (canRequestAllPermissions) {
        windowAndroid.requestPermissions(mAndroidPermisisons, this);
    } else {
        Activity activity = windowAndroid.getActivity().get();
        if (activity == null) {
            nativeOnPermissionResult(mNativePtr, false);
            return;
        }
        mActivityStateListener = new ActivityStateListener() {

            @Override
            public void onActivityStateChange(Activity activity, int newState) {
                if (newState == ActivityState.DESTROYED) {
                    ApplicationStatus.unregisterActivityStateListener(this);
                    mActivityStateListener = null;
                    nativeOnPermissionResult(mNativePtr, false);
                } else if (newState == ActivityState.RESUMED) {
                    ApplicationStatus.unregisterActivityStateListener(this);
                    mActivityStateListener = null;
                    notifyPermissionResult();
                }
            }
        };
        ApplicationStatus.registerStateListenerForActivity(mActivityStateListener, activity);
        Intent settingsIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        settingsIntent.setData(Uri.parse("package:" + windowAndroid.getApplicationContext().getPackageName()));
        settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(settingsIntent);
    }
}
Also used : ActivityStateListener(org.chromium.base.ApplicationStatus.ActivityStateListener) Activity(android.app.Activity) Intent(android.content.Intent) WindowAndroid(org.chromium.ui.base.WindowAndroid) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 2 with ActivityStateListener

use of org.chromium.base.ApplicationStatus.ActivityStateListener in project AndroidChromium by JackyAndroid.

the class DownloadPage method initialize.

@Override
protected void initialize(Activity activity, final Tab tab) {
    ThreadUtils.assertOnUiThread();
    mManager = new DownloadManagerUi(activity, tab.isIncognito(), activity.getComponentName());
    mManager.setBasicNativePage(this);
    mTitle = activity.getString(R.string.download_manager_ui_all_downloads);
    // #destroy() unregisters the ActivityStateListener to avoid checking for externally removed
    // downloads after the downloads page is closed. This requires each DownloadPage to have its
    // own ActivityStateListener. If multiple tabs are showing the downloads page, multiple
    // requests to check for externally removed downloads will be issued when the activity is
    // resumed.
    mActivityStateListener = new ActivityStateListener() {

        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.RESUMED) {
                DownloadUtils.checkForExternallyRemovedDownloads(mManager.getBackendProvider(), tab.isIncognito());
            }
        }
    };
    ApplicationStatus.registerStateListenerForActivity(mActivityStateListener, activity);
}
Also used : ActivityStateListener(org.chromium.base.ApplicationStatus.ActivityStateListener) Activity(android.app.Activity) DownloadManagerUi(org.chromium.chrome.browser.download.ui.DownloadManagerUi)

Example 3 with ActivityStateListener

use of org.chromium.base.ApplicationStatus.ActivityStateListener in project AndroidChromium by JackyAndroid.

the class PrintShareActivity method enablePrintShareOption.

/**
     * Enable the print sharing option.
     *
     * @param activity The activity that will be triggering the share action.  The activitiy's
     *                 state will be tracked to disable the print option when the share operation
     *                 has been completed.
     * @param callback The callback to be triggered after the print option has been enabled.  This
     *                 may or may not be synchronous depending on whether this will require
     *                 interacting with the Android framework.
     */
public static void enablePrintShareOption(final Activity activity, final Runnable callback) {
    ThreadUtils.assertOnUiThread();
    if (sStateListener == null) {
        sStateListener = new ActivityStateListener() {

            @Override
            public void onActivityStateChange(Activity activity, int newState) {
                if (newState == ActivityState.PAUSED)
                    return;
                unregisterActivity(activity);
            }
        };
    }
    ApplicationStatus.registerStateListenerForAllActivities(sStateListener);
    boolean wasEmpty = sPendingShareActivities.isEmpty();
    sPendingShareActivities.add(activity);
    if (wasEmpty) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                if (sPendingShareActivities.isEmpty())
                    return null;
                activity.getPackageManager().setComponentEnabledSetting(new ComponentName(activity, PrintShareActivity.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                return null;
            }

            @Override
            protected void onPostExecute(Void result) {
                callback.run();
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        callback.run();
    }
}
Also used : ActivityStateListener(org.chromium.base.ApplicationStatus.ActivityStateListener) ChromeActivity(org.chromium.chrome.browser.ChromeActivity) AppCompatActivity(android.support.v7.app.AppCompatActivity) Activity(android.app.Activity) ComponentName(android.content.ComponentName)

Aggregations

Activity (android.app.Activity)3 ActivityStateListener (org.chromium.base.ApplicationStatus.ActivityStateListener)3 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 ChromeActivity (org.chromium.chrome.browser.ChromeActivity)1 DownloadManagerUi (org.chromium.chrome.browser.download.ui.DownloadManagerUi)1 WindowAndroid (org.chromium.ui.base.WindowAndroid)1