Search in sources :

Example 36 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class ChromeTabbedActivity method maybeMergeTabs.

/**
     * Merges tabs from a second ChromeTabbedActivity instance if necesssary and calls
     * finishAndRemoveTask() on the other activity.
     */
@TargetApi(Build.VERSION_CODES.M)
@VisibleForTesting
public void maybeMergeTabs() {
    if (!FeatureUtilities.isTabModelMergingEnabled())
        return;
    Class<?> otherWindowActivityClass = MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(this);
    // 1. Find the other activity's task if it's still running so that it can be removed from
    //    Android recents.
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
    ActivityManager.AppTask otherActivityTask = null;
    for (ActivityManager.AppTask task : appTasks) {
        if (task.getTaskInfo() == null || task.getTaskInfo().baseActivity == null)
            continue;
        String baseActivity = task.getTaskInfo().baseActivity.getClassName();
        if (baseActivity.equals(otherWindowActivityClass.getName())) {
            otherActivityTask = task;
        }
    }
    if (otherActivityTask != null) {
        for (WeakReference<Activity> activityRef : ApplicationStatus.getRunningActivities()) {
            Activity activity = activityRef.get();
            if (activity == null)
                continue;
            // starts, causing some duplicate work to be done. Avoid the redundancy.
            if (activity.getClass().equals(otherWindowActivityClass)) {
                ((ChromeTabbedActivity) activity).saveState();
                break;
            }
        }
        // 3. Kill the other activity's task to remove it from Android recents.
        otherActivityTask.finishAndRemoveTask();
    }
    // 4. Ask TabPersistentStore to merge state.
    RecordUserAction.record("Android.MergeState.Live");
    mTabModelSelectorImpl.mergeState();
    setMergedInstanceTaskId(getTaskId());
}
Also used : AppTask(android.app.ActivityManager.AppTask) AppTask(android.app.ActivityManager.AppTask) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity) FirstRunActivity(org.chromium.chrome.browser.firstrun.FirstRunActivity) Activity(android.app.Activity) ActivityManager(android.app.ActivityManager) VisibleForTesting(org.chromium.base.VisibleForTesting) TargetApi(android.annotation.TargetApi)

Example 37 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class BluetoothChooserDialog method show.

/**
     * Show the BluetoothChooserDialog.
     */
@VisibleForTesting
void show() {
    // Emphasize the origin.
    Profile profile = Profile.getLastUsedProfile();
    SpannableString origin = new SpannableString(mOrigin);
    OmniboxUrlEmphasizer.emphasizeUrl(origin, mActivity.getResources(), profile, mSecurityLevel, false, true, true);
    // Construct a full string and replace the origin text with emphasized version.
    SpannableString title = new SpannableString(mActivity.getString(R.string.bluetooth_dialog_title, mOrigin));
    int start = title.toString().indexOf(mOrigin);
    TextUtils.copySpansFrom(origin, 0, origin.length(), Object.class, title, start);
    String message = mActivity.getString(R.string.bluetooth_not_found);
    SpannableString noneFound = SpanApplier.applySpans(message, new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));
    SpannableString searching = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_searching), new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));
    String positiveButton = mActivity.getString(R.string.bluetooth_confirm_button);
    SpannableString statusIdleNoneFound = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_not_seeing_it_idle_none_found), new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));
    SpannableString statusActive = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_not_seeing_it), new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));
    SpannableString statusIdleSomeFound = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_not_seeing_it_idle_some_found), new SpanInfo("<link1>", "</link1>", new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)), new SpanInfo("<link2>", "</link2>", new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));
    ItemChooserDialog.ItemChooserLabels labels = new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive, statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels);
    mActivity.registerReceiver(mLocationModeBroadcastReceiver, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
    mIsLocationModeChangedReceiverRegistered = true;
}
Also used : SpannableString(android.text.SpannableString) IntentFilter(android.content.IntentFilter) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) SpannableString(android.text.SpannableString) Profile(org.chromium.chrome.browser.profiles.Profile) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 38 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class BluetoothChooserDialog method notifyAdapterTurnedOff.

@VisibleForTesting
@CalledByNative
void notifyAdapterTurnedOff() {
    SpannableString adapterOffMessage = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_adapter_off), new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.ADAPTER_OFF, mActivity)));
    SpannableString adapterOffStatus = SpanApplier.applySpans(mActivity.getString(R.string.bluetooth_adapter_off_help), new SpanInfo("<link>", "</link>", new BluetoothClickableSpan(LinkType.ADAPTER_OFF_HELP, mActivity)));
    mItemChooserDialog.setErrorState(adapterOffMessage, adapterOffStatus);
}
Also used : SpannableString(android.text.SpannableString) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) VisibleForTesting(org.chromium.base.VisibleForTesting) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 39 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class UsbChooserDialog method show.

/**
     * Shows the UsbChooserDialog.
     *
     * @param activity Activity which is used for launching a dialog.
     * @param origin The origin for the site wanting to connect to the USB device.
     * @param securityLevel The security level of the connection to the site wanting to connect to
     *                      the USB device. For valid values see SecurityStateModel::SecurityLevel.
     */
@VisibleForTesting
void show(Activity activity, String origin, int securityLevel) {
    // Emphasize the origin.
    Profile profile = Profile.getLastUsedProfile();
    SpannableString originSpannableString = new SpannableString(origin);
    OmniboxUrlEmphasizer.emphasizeUrl(originSpannableString, activity.getResources(), profile, securityLevel, false, /* isInternalPage */
    true, /* useDarkColors */
    true);
    // Construct a full string and replace the origin text with emphasized version.
    SpannableString title = new SpannableString(activity.getString(R.string.usb_chooser_dialog_prompt, origin));
    int start = title.toString().indexOf(origin);
    TextUtils.copySpansFrom(originSpannableString, 0, originSpannableString.length(), Object.class, title, start);
    String searching = "";
    String noneFound = activity.getString(R.string.usb_chooser_dialog_no_devices_found_prompt);
    SpannableString statusActive = SpanApplier.applySpans(activity.getString(R.string.usb_chooser_dialog_footnote_text), new SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {

        @Override
        public void onClick(View view) {
            if (mNativeUsbChooserDialogPtr == 0) {
                return;
            }
            nativeLoadUsbHelpPage(mNativeUsbChooserDialogPtr);
            // Get rid of the highlight background on selection.
            view.invalidate();
        }
    }));
    SpannableString statusIdleNoneFound = statusActive;
    SpannableString statusIdleSomeFound = statusActive;
    String positiveButton = activity.getString(R.string.usb_chooser_dialog_connect_button_text);
    ItemChooserDialog.ItemChooserLabels labels = new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive, statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(activity, this, labels);
}
Also used : SpannableString(android.text.SpannableString) NoUnderlineClickableSpan(org.chromium.ui.text.NoUnderlineClickableSpan) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) SpannableString(android.text.SpannableString) View(android.view.View) Profile(org.chromium.chrome.browser.profiles.Profile) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 40 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class MinidumpUploadService method createUploadIntent.

/**
     * Creates an intent that when started will find all minidumps, and try to upload them.
     *
     * @param minidumpFile the minidump file to upload.
     * @return an Intent to use to start the service.
     */
@VisibleForTesting
public static Intent createUploadIntent(Context context, File minidumpFile, File logfile) {
    Intent intent = new Intent(context, MinidumpUploadService.class);
    intent.setAction(ACTION_UPLOAD);
    intent.putExtra(FILE_TO_UPLOAD_KEY, minidumpFile.getAbsolutePath());
    intent.putExtra(UPLOAD_LOG_KEY, logfile.getAbsolutePath());
    return intent;
}
Also used : Intent(android.content.Intent) VisibleForTesting(org.chromium.base.VisibleForTesting)

Aggregations

VisibleForTesting (org.chromium.base.VisibleForTesting)52 Intent (android.content.Intent)6 IOException (java.io.IOException)6 SharedPreferences (android.content.SharedPreferences)5 JSONObject (org.json.JSONObject)4 PendingIntent (android.app.PendingIntent)3 SpannableString (android.text.SpannableString)3 BufferedReader (java.io.BufferedReader)3 Matcher (java.util.regex.Matcher)3 CalledByNative (org.chromium.base.annotations.CalledByNative)3 AccountManagerHelper (org.chromium.components.signin.AccountManagerHelper)3 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)3 SuppressLint (android.annotation.SuppressLint)2 IntentFilter (android.content.IntentFilter)2 Paint (android.graphics.Paint)2 File (java.io.File)2 FileReader (java.io.FileReader)2 HttpURLConnection (java.net.HttpURLConnection)2 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2