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.content.Context; 19 import android.text.Spanned; 20 import android.text.method.LinkMovementMethod; 21 import android.widget.TextView; 22 23 import com.android.managedprovisioning.R; 24 import com.android.managedprovisioning.common.ClickableSpanFactory; 25 import com.android.managedprovisioning.common.HtmlToSpannedParser; 26 import com.android.managedprovisioning.preprovisioning.WebActivity; 27 import com.android.managedprovisioning.preprovisioning.terms.TermsDocument; 28 29 /** 30 * Utils for adapters displaying terms 31 */ 32 final class TermsAdapterUtils { 33 34 /** 35 * Populate a given text view with the contents of the term 36 * 37 * @param context the calling activity's context 38 * @param contentTextView text view to display the term contents 39 * @param disclaimer the term document that contains the contents 40 */ populateContentTextView(Context context, TextView contentTextView, TermsDocument disclaimer, ClickableSpanFactory clickableSpanFactory)41 public static void populateContentTextView(Context context, TextView contentTextView, 42 TermsDocument disclaimer, ClickableSpanFactory clickableSpanFactory) { 43 HtmlToSpannedParser htmlToSpannedParser = new HtmlToSpannedParser( 44 clickableSpanFactory, 45 url -> WebActivity.createIntent(context, url)); 46 Spanned content = htmlToSpannedParser.parseHtml(disclaimer.getContent()); 47 contentTextView.setText(content); 48 contentTextView.setContentDescription( 49 context.getResources().getString(R.string.section_content, disclaimer.getHeading(), 50 content)); 51 // makes html links clickable 52 contentTextView.setMovementMethod(LinkMovementMethod.getInstance()); 53 } 54 TermsAdapterUtils()55 private TermsAdapterUtils() { 56 } 57 } 58