Search in sources :

Example 6 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo 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 7 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo in project AndroidChromium by JackyAndroid.

the class LightweightFirstRunActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)) {
        completeFirstRunExperience();
    }
    setContentView(LayoutInflater.from(LightweightFirstRunActivity.this).inflate(R.layout.lightweight_fre_tos, null));
    NoUnderlineClickableSpan clickableTermsSpan = new NoUnderlineClickableSpan() {

        @Override
        public void onClick(View widget) {
            EmbedContentViewActivity.show(LightweightFirstRunActivity.this, R.string.terms_of_service_title, R.string.chrome_terms_of_service_url);
        }
    };
    NoUnderlineClickableSpan clickablePrivacySpan = new NoUnderlineClickableSpan() {

        @Override
        public void onClick(View widget) {
            EmbedContentViewActivity.show(LightweightFirstRunActivity.this, R.string.privacy_notice_title, R.string.chrome_privacy_notice_url);
        }
    };
    ((TextView) findViewById(R.id.lightweight_fre_tos_and_privacy)).setText(SpanApplier.applySpans(getString(R.string.lightweight_fre_tos_and_privacy), new SpanInfo("<LINK1>", "</LINK1>", clickableTermsSpan), new SpanInfo("<LINK2>", "</LINK2>", clickablePrivacySpan)));
    ((TextView) findViewById(R.id.lightweight_fre_tos_and_privacy)).setMovementMethod(LinkMovementMethod.getInstance());
    ((Button) findViewById(R.id.lightweight_fre_terms_accept)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            sGlue.acceptTermsOfService(false);
            completeFirstRunExperience();
        }
    });
    ((Button) findViewById(R.id.lightweight_fre_cancel)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            abortFirstRunExperience();
        }
    });
}
Also used : Button(android.widget.Button) NoUnderlineClickableSpan(org.chromium.ui.text.NoUnderlineClickableSpan) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) TextView(android.widget.TextView) View(android.view.View)

Example 8 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo in project AndroidChromium by JackyAndroid.

the class ToSAndUMAFirstRunFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mAcceptButton = (Button) view.findViewById(R.id.terms_accept);
    mSendReportCheckBox = (CheckBox) view.findViewById(R.id.send_report_checkbox);
    mTosAndPrivacy = (TextView) view.findViewById(R.id.tos_and_privacy);
    mAcceptButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getPageDelegate().acceptTermsOfService(mSendReportCheckBox.isChecked());
        }
    });
    if (ChromeVersionInfo.isOfficialBuild()) {
        int paddingStart = getResources().getDimensionPixelSize(R.dimen.fre_tos_checkbox_padding);
        ApiCompatibilityUtils.setPaddingRelative(mSendReportCheckBox, ApiCompatibilityUtils.getPaddingStart(mSendReportCheckBox) + paddingStart, mSendReportCheckBox.getPaddingTop(), ApiCompatibilityUtils.getPaddingEnd(mSendReportCheckBox), mSendReportCheckBox.getPaddingBottom());
        mSendReportCheckBox.setChecked(FirstRunActivity.DEFAULT_METRICS_AND_CRASH_REPORTING);
    } else {
        mSendReportCheckBox.setVisibility(View.GONE);
    }
    mTosAndPrivacy.setMovementMethod(LinkMovementMethod.getInstance());
    NoUnderlineClickableSpan clickableTermsSpan = new NoUnderlineClickableSpan() {

        @Override
        public void onClick(View widget) {
            if (!isAdded())
                return;
            getPageDelegate().showEmbedContentViewActivity(R.string.terms_of_service_title, R.string.chrome_terms_of_service_url);
        }
    };
    NoUnderlineClickableSpan clickablePrivacySpan = new NoUnderlineClickableSpan() {

        @Override
        public void onClick(View widget) {
            if (!isAdded())
                return;
            getPageDelegate().showEmbedContentViewActivity(R.string.privacy_notice_title, R.string.chrome_privacy_notice_url);
        }
    };
    mTosAndPrivacy.setText(SpanApplier.applySpans(getString(R.string.fre_tos_and_privacy), new SpanInfo("<LINK1>", "</LINK1>", clickableTermsSpan), new SpanInfo("<LINK2>", "</LINK2>", clickablePrivacySpan)));
}
Also used : NoUnderlineClickableSpan(org.chromium.ui.text.NoUnderlineClickableSpan) OnClickListener(android.view.View.OnClickListener) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) TextView(android.widget.TextView) View(android.view.View)

Example 9 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo in project AndroidChromium by JackyAndroid.

the class SearchEnginePromoDialog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Do not allow this dialog to be reconstructed because it requires native side loaded.
    if (savedInstanceState != null) {
        dismiss();
        return;
    }
    setContentView(R.layout.search_engine_promo);
    View keepGoogleButton = findViewById(R.id.keep_google_button);
    View okButton = findViewById(R.id.ok_button);
    keepGoogleButton.setOnClickListener(this);
    okButton.setOnClickListener(this);
    TextView textView = (TextView) findViewById(R.id.description);
    SpannableString description = SpanApplier.applySpans(getContext().getString(R.string.sogou_explanation), new SpanInfo("<link>", "</link>", mSpan));
    textView.setText(description);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
}
Also used : SpannableString(android.text.SpannableString) TextView(android.widget.TextView) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) TextView(android.widget.TextView) View(android.view.View)

Example 10 with SpanInfo

use of org.chromium.ui.text.SpanApplier.SpanInfo in project AndroidChromium by JackyAndroid.

the class SearchEngineAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (convertView == null) {
        view = mLayoutInflater.inflate(R.layout.search_engine, null);
    }
    view.setOnClickListener(this);
    view.setTag(position);
    // TODO(finnur): There's a tinting bug in the AppCompat lib (see http://crbug.com/474695),
    // which causes the first radiobox to always appear selected, even if it is not. It is being
    // addressed, but in the meantime we should use the native RadioButton instead.
    RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutton);
    // On Lollipop this removes the redundant animation ring on selection but on older versions
    // it would cause the radio button to disappear.
    // TODO(finnur): Remove the encompassing if statement once we go back to using the AppCompat
    // control.
    final boolean selected = position == mSelectedSearchEnginePosition;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        radioButton.setBackgroundResource(0);
    }
    radioButton.setChecked(selected);
    TextView description = (TextView) view.findViewById(R.id.description);
    TemplateUrl templateUrl = mSearchEngines.get(position);
    Resources resources = mContext.getResources();
    description.setText(templateUrl.getShortName());
    // To improve the explore-by-touch experience, the radio button is hidden from accessibility
    // and instead, "checked" or "not checked" is read along with the search engine's name, e.g.
    // "google.com checked" or "google.com not checked".
    radioButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    description.setAccessibilityDelegate(new AccessibilityDelegate() {

        @Override
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            event.setChecked(selected);
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setCheckable(true);
            info.setChecked(selected);
        }
    });
    TextView link = (TextView) view.findViewById(R.id.link);
    link.setVisibility(selected ? View.VISIBLE : View.GONE);
    if (selected) {
        ForegroundColorSpan linkSpan = new ForegroundColorSpan(ApiCompatibilityUtils.getColor(resources, R.color.pref_accent_color));
        if (LocationUtils.getInstance().isSystemLocationSettingEnabled()) {
            String message = mContext.getString(locationEnabled(position, true) ? R.string.search_engine_location_allowed : R.string.search_engine_location_blocked);
            SpannableString messageWithLink = new SpannableString(message);
            messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0);
            link.setText(messageWithLink);
        } else {
            link.setText(SpanApplier.applySpans(mContext.getString(R.string.android_location_off), new SpanInfo("<link>", "</link>", linkSpan)));
        }
        link.setOnClickListener(this);
    }
    return view;
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) SpanInfo(org.chromium.ui.text.SpanApplier.SpanInfo) RadioButton(android.widget.RadioButton) SpannableString(android.text.SpannableString) View(android.view.View) TextView(android.widget.TextView) SpannableString(android.text.SpannableString) TemplateUrl(org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl) AccessibilityDelegate(android.view.View.AccessibilityDelegate) TextView(android.widget.TextView) Resources(android.content.res.Resources)

Aggregations

SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)15 View (android.view.View)10 SpannableString (android.text.SpannableString)9 TextView (android.widget.TextView)9 NoUnderlineClickableSpan (org.chromium.ui.text.NoUnderlineClickableSpan)5 Intent (android.content.Intent)4 Context (android.content.Context)3 Uri (android.net.Uri)3 ClickableSpan (android.text.style.ClickableSpan)3 VisibleForTesting (org.chromium.base.VisibleForTesting)3 Resources (android.content.res.Resources)2 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)2 ForegroundColorSpan (android.text.style.ForegroundColorSpan)2 OnClickListener (android.view.View.OnClickListener)2 Profile (org.chromium.chrome.browser.profiles.Profile)2 IntentFilter (android.content.IntentFilter)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 TextPaint (android.text.TextPaint)1 TypefaceSpan (android.text.style.TypefaceSpan)1