1/* 2 * Copyright (C) 2014 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package com.android.mail.text; 19 20import android.text.TextPaint; 21import android.text.style.ClickableSpan; 22import android.view.View; 23 24/** 25 * A span that makes text look like a link. It uses link color and 26 * has no underline but clicking it does nothing.<p/> 27 * 28 * WARNING: this span will not work if the TextView it uses 29 * saves and restores its text since TextView can only save 30 * and restore {@link android.text.ParcelableSpan}s which 31 * can only be implemented by framework Spans. 32 */ 33public class LinkStyleSpan extends ClickableSpan { 34 35 /** 36 * The onclick listener invoked when the link is clicked. 37 */ 38 final View.OnClickListener mOnClickListener; 39 40 public LinkStyleSpan(View.OnClickListener onClickListener) { 41 mOnClickListener = onClickListener; 42 } 43 44 @Override 45 public void onClick(View widget) { 46 if (mOnClickListener != null) { 47 mOnClickListener.onClick(widget); 48 } 49 } 50 51 /** 52 * Makes the text in the link color and not underlined. 53 */ 54 @Override 55 public void updateDrawState(TextPaint ds) { 56 ds.setColor(ds.linkColor); 57 ds.setUnderlineText(false); 58 } 59} 60