1 /* 2 * Copyright 2018, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.managedprovisioning.preprovisioning.terms.adapters; 17 18 import android.annotation.ColorInt; 19 import android.content.Context; 20 import android.text.Spanned; 21 import android.text.method.LinkMovementMethod; 22 import android.widget.TextView; 23 24 import com.android.managedprovisioning.R; 25 import com.android.managedprovisioning.common.ClickableSpanFactory; 26 import com.android.managedprovisioning.common.HtmlToSpannedParser; 27 import com.android.managedprovisioning.preprovisioning.WebActivity; 28 import com.android.managedprovisioning.preprovisioning.terms.TermsDocument; 29 30 /** 31 * Utils for adapters displaying terms 32 */ 33 final class TermsAdapterUtils { 34 35 /** 36 * Populate a given text view with the contents of the term 37 * 38 * @param context the calling activity's context 39 * @param contentTextView text view to display the term contents 40 * @param disclaimer the term document that contains the contents 41 */ populateContentTextView(Context context, TextView contentTextView, TermsDocument disclaimer, @ColorInt int statusBarColor)42 public static void populateContentTextView(Context context, TextView contentTextView, 43 TermsDocument disclaimer, @ColorInt int statusBarColor) { 44 HtmlToSpannedParser htmlToSpannedParser = new HtmlToSpannedParser( 45 new ClickableSpanFactory(context.getColor(R.color.blue_text)), 46 url -> WebActivity.createIntent(context, url, statusBarColor)); 47 Spanned content = htmlToSpannedParser.parseHtml(disclaimer.getContent()); 48 contentTextView.setText(content); 49 contentTextView.setContentDescription( 50 context.getResources().getString(R.string.section_content, disclaimer.getHeading(), 51 content)); 52 // makes html links clickable 53 contentTextView.setMovementMethod(LinkMovementMethod.getInstance()); 54 } 55 TermsAdapterUtils()56 private TermsAdapterUtils() { 57 } 58 } 59