Search in sources :

Example 61 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class ChromeDownloadDelegate method requestFileAccess.

@CalledByNative
private void requestFileAccess(final long callbackId) {
    if (mTab == null || mTab.getWindowAndroid() == null) {
        // TODO(tedchoc): Show toast (only when activity is alive).
        DownloadController.getInstance().onRequestFileAccessResult(callbackId, false);
        return;
    }
    final String storagePermission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
    final Activity activity = mTab.getWindowAndroid().getActivity().get();
    if (activity == null) {
        DownloadController.getInstance().onRequestFileAccessResult(callbackId, false);
    } else if (mTab.getWindowAndroid().canRequestPermission(storagePermission)) {
        View view = activity.getLayoutInflater().inflate(R.layout.update_permissions_dialog, null);
        TextView dialogText = (TextView) view.findViewById(R.id.text);
        dialogText.setText(R.string.missing_storage_permission_download_education_text);
        final PermissionCallback permissionCallback = new PermissionCallback() {

            @Override
            public void onRequestPermissionsResult(String[] permissions, int[] grantResults) {
                DownloadController.getInstance().onRequestFileAccessResult(callbackId, grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED);
            }
        };
        AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogTheme).setView(view).setPositiveButton(R.string.infobar_update_permissions_button_text, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int id) {
                if (mTab == null) {
                    dialog.cancel();
                    return;
                }
                mTab.getWindowAndroid().requestPermissions(new String[] { storagePermission }, permissionCallback);
            }
        }).setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                DownloadController.getInstance().onRequestFileAccessResult(callbackId, false);
            }
        });
        builder.create().show();
    } else if (!mTab.getWindowAndroid().isPermissionRevokedByPolicy(storagePermission)) {
        nativeLaunchPermissionUpdateInfoBar(mTab, storagePermission, callbackId);
    } else {
        // TODO(tedchoc): Show toast.
        DownloadController.getInstance().onRequestFileAccessResult(callbackId, false);
    }
}
Also used : DialogInterface(android.content.DialogInterface) ChromeActivity(org.chromium.chrome.browser.ChromeActivity) Activity(android.app.Activity) View(android.view.View) TextView(android.widget.TextView) PermissionCallback(org.chromium.ui.base.WindowAndroid.PermissionCallback) TextView(android.widget.TextView) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 62 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class ChromeMediaRouter method detachRoute.

/**
     * Notifies the specified route that it's not attached to the web page anymore.
     * @param routeId the id of the route that was detached.
     */
@CalledByNative
public void detachRoute(String routeId) {
    MediaRouteProvider provider = mRouteIdsToProviders.get(routeId);
    if (provider == null)
        return;
    provider.detachRoute(routeId);
    mRouteIdsToProviders.remove(routeId);
}
Also used : CastMediaRouteProvider(org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 63 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class ChromeMediaRouter method stopObservingMediaSinks.

/**
     * Stops background monitoring for available media sinks compatible with the given
     * |sourceUrn|
     * @param sourceId a URL passed to {@link #startObservingMediaSinks(String)} before.
     */
@CalledByNative
public void stopObservingMediaSinks(String sourceId) {
    for (MediaRouteProvider provider : mRouteProviders) {
        provider.stopObservingMediaSinks(sourceId);
    }
    mSinksPerSource.remove(sourceId);
    mSinksPerSourcePerProvider.remove(sourceId);
}
Also used : CastMediaRouteProvider(org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 64 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class ChromeMediaRouter method sendBinaryMessage.

/**
     * Sends a binary message to the specified route.
     * @param routeId The id of the route to send the message to.
     * @param data The binary message to send.
     * @param callbackId The id of the result callback tracked by the native side.
     */
@CalledByNative
public void sendBinaryMessage(String routeId, byte[] data, int callbackId) {
    MediaRouteProvider provider = mRouteIdsToProviders.get(routeId);
    if (provider == null) {
        nativeOnMessageSentResult(mNativeMediaRouterAndroid, false, callbackId);
        return;
    }
    provider.sendBinaryMessage(routeId, data, callbackId);
}
Also used : CastMediaRouteProvider(org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 65 with CalledByNative

use of org.chromium.base.annotations.CalledByNative in project AndroidChromium by JackyAndroid.

the class ChromeMediaRouter method create.

/**
     * Initializes the media router and its providers.
     * @param nativeMediaRouterAndroid the handler for the native counterpart of this instance
     * @param applicationContext the application context to use to obtain system APIs
     * @return an initialized {@link ChromeMediaRouter} instance
     */
@CalledByNative
public static ChromeMediaRouter create(long nativeMediaRouterAndroid, Context applicationContext) {
    ChromeMediaRouter router = new ChromeMediaRouter(nativeMediaRouterAndroid);
    MediaRouteProvider provider = sRouteProviderBuilder.create(applicationContext, router);
    if (provider != null)
        router.addMediaRouteProvider(provider);
    return router;
}
Also used : CastMediaRouteProvider(org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider) CalledByNative(org.chromium.base.annotations.CalledByNative)

Aggregations

CalledByNative (org.chromium.base.annotations.CalledByNative)74 Activity (android.app.Activity)11 Context (android.content.Context)11 Intent (android.content.Intent)10 CastMediaRouteProvider (org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider)8 DownloadNotifier (org.chromium.chrome.browser.download.DownloadNotifier)6 View (android.view.View)5 TextView (android.widget.TextView)5 DownloadInfo (org.chromium.chrome.browser.download.DownloadInfo)5 SuppressLint (android.annotation.SuppressLint)4 PackageManager (android.content.pm.PackageManager)4 Bitmap (android.graphics.Bitmap)4 Paint (android.graphics.Paint)4 ScrollView (android.widget.ScrollView)4 ActivityManager (android.app.ActivityManager)3 ImageView (android.widget.ImageView)3 LinearLayout (android.widget.LinearLayout)3 VisibleForTesting (org.chromium.base.VisibleForTesting)3 Account (android.accounts.Account)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2