URLSpan.java revision d24b8183b93e781080b2c16c487e60d51c12da31
1/* 2 * Copyright (C) 2006 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 17package android.text.style; 18 19import android.content.Intent; 20import android.net.Uri; 21import android.os.Parcel; 22import android.text.ParcelableSpan; 23import android.text.TextUtils; 24import android.view.View; 25 26public class URLSpan extends ClickableSpan implements ParcelableSpan { 27 28 private final String mURL; 29 30 public URLSpan(String url) { 31 mURL = url; 32 } 33 34 public URLSpan(Parcel src) { 35 mURL = src.readString(); 36 } 37 38 public int getSpanTypeId() { 39 return TextUtils.URL_SPAN; 40 } 41 42 public int describeContents() { 43 return 0; 44 } 45 46 public void writeToParcel(Parcel dest, int flags) { 47 dest.writeString(mURL); 48 } 49 50 public String getURL() { 51 return mURL; 52 } 53 54 @Override 55 public void onClick(View widget) { 56 Uri uri = Uri.parse(getURL()); 57 Intent intent = new Intent(Intent.ACTION_VIEW, uri); 58 intent.addCategory(Intent.CATEGORY_BROWSABLE); 59 widget.getContext().startActivity(intent); 60 } 61} 62