Search in sources :

Example 11 with CalledByNative

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

the class ChromeHttpAuthHandler method showDialog.

@CalledByNative
private void showDialog(WindowAndroid windowAndroid) {
    if (windowAndroid == null) {
        cancel();
    }
    Activity activity = windowAndroid.getActivity().get();
    if (activity == null) {
        cancel();
    }
    LoginPrompt authDialog = new LoginPrompt(activity, this);
    setAutofillObserver(authDialog);
    authDialog.show();
}
Also used : Activity(android.app.Activity) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 12 with CalledByNative

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

the class IntentHelper method sendEmail.

/**
     * Triggers a send email intent.  If no application has registered to receive these intents,
     * this will fail silently.  If an email is not specified and the device has exactly one
     * account and the account name matches the email format, the email is set to the account name.
     *
     * @param context The context for issuing the intent.
     * @param email The email address to send to.
     * @param subject The subject of the email.
     * @param body The body of the email.
     * @param chooserTitle The title of the activity chooser.
     * @param fileToAttach The file name of the attachment.
     */
@CalledByNative
static void sendEmail(Context context, String email, String subject, String body, String chooserTitle, String fileToAttach) {
    if (TextUtils.isEmpty(email)) {
        Account[] accounts = AccountManagerHelper.get(context).getGoogleAccounts();
        if (accounts != null && accounts.length == 1 && Patterns.EMAIL_ADDRESS.matcher(accounts[0].name).matches()) {
            email = accounts[0].name;
        }
    }
    Intent send = new Intent(Intent.ACTION_SEND);
    send.setType("message/rfc822");
    if (!TextUtils.isEmpty(email))
        send.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
    send.putExtra(Intent.EXTRA_SUBJECT, subject);
    send.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
    if (!TextUtils.isEmpty(fileToAttach)) {
        File fileIn = new File(fileToAttach);
        Uri fileUri;
        // instead.
        try {
            fileUri = ContentUriUtils.getContentUriFromFile(context, fileIn);
        } catch (IllegalArgumentException ex) {
            fileUri = Uri.fromFile(fileIn);
        }
        send.putExtra(Intent.EXTRA_STREAM, fileUri);
    }
    try {
        Intent chooser = Intent.createChooser(send, chooserTitle);
        // we start this activity outside the main activity.
        chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(chooser);
    } catch (android.content.ActivityNotFoundException ex) {
    // If no app handles it, do nothing.
    }
}
Also used : Account(android.accounts.Account) Intent(android.content.Intent) File(java.io.File) Uri(android.net.Uri) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 13 with CalledByNative

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

the class OfflinePageNotificationBridge method notifyDownloadProgress.

/**
     * Called by offline page backend to notify the user of download progress.
     * @param context Context to show notifications.
     * @param guid GUID of a request to download a page related to the notification.
     * @param url URL of the page to download.
     * @param startTime Time of the request.
     * @param displayName Name to be displayed on notification.
     */
@CalledByNative
public static void notifyDownloadProgress(Context context, String guid, String url, long startTime, String displayName) {
    DownloadNotifier notifier = getDownloadNotifier(context);
    if (notifier == null)
        return;
    DownloadInfo downloadInfo = new DownloadInfo.Builder().setIsOfflinePage(true).setDownloadGuid(guid).setFileName(displayName).setFilePath(url).setPercentCompleted(-1).setIsOffTheRecord(false).setIsResumable(true).setTimeRemainingInMillis(0).build();
    notifier.notifyDownloadProgress(downloadInfo, startTime, false);
}
Also used : DownloadNotifier(org.chromium.chrome.browser.download.DownloadNotifier) DownloadInfo(org.chromium.chrome.browser.download.DownloadInfo) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 14 with CalledByNative

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

the class OfflinePageNotificationBridge method notifyDownloadInterrupted.

/**
     * Update download notification to interrupted.
     * @param context Context to show notifications.
     * @param guid GUID of a request to download a page related to the notification.
     * @param displayName Name to be displayed on notification.
     */
@CalledByNative
public static void notifyDownloadInterrupted(Context context, String guid, String displayName) {
    DownloadNotifier notifier = getDownloadNotifier(context);
    if (notifier == null)
        return;
    DownloadInfo downloadInfo = new DownloadInfo.Builder().setIsOfflinePage(true).setDownloadGuid(guid).setFileName(displayName).setIsResumable(true).build();
    notifier.notifyDownloadInterrupted(downloadInfo, true);
}
Also used : DownloadNotifier(org.chromium.chrome.browser.download.DownloadNotifier) DownloadInfo(org.chromium.chrome.browser.download.DownloadInfo) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 15 with CalledByNative

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

the class DomDistillerUIUtils method reportFeedbackWithWebContents.

/**
     * A static method for native code to open the external feedback form UI.
     * @param webContents The WebContents containing the distilled content.
     * @param url The URL to report feedback for.
     * @param good True if the feedback is good and false if not.
     */
@CalledByNative
public static void reportFeedbackWithWebContents(WebContents webContents, String url, final boolean good) {
    ThreadUtils.assertOnUiThread();
    // TODO(mdjones): It would be better to get the WebContents from the manager so that the
    // native code does not need to depend on RenderFrame.
    Activity activity = getActivityFromWebContents(webContents);
    if (activity == null)
        return;
    if (sFeedbackReporter == null) {
        ChromeApplication application = (ChromeApplication) activity.getApplication();
        sFeedbackReporter = application.createFeedbackReporter();
    }
    FeedbackCollector.create(activity, Profile.getLastUsedProfile(), url, new FeedbackCollector.FeedbackResult() {

        @Override
        public void onResult(FeedbackCollector collector) {
            String quality = good ? DISTILLATION_QUALITY_GOOD : DISTILLATION_QUALITY_BAD;
            collector.add(DISTILLATION_QUALITY_KEY, quality);
            sFeedbackReporter.reportFeedback(collector);
        }
    });
}
Also used : ChromeApplication(org.chromium.chrome.browser.ChromeApplication) Activity(android.app.Activity) FeedbackCollector(org.chromium.chrome.browser.feedback.FeedbackCollector) 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