blob: e7f37a55eb2a8d4d235a30b12290ac89781c661e [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
2 * Copyright (C) 2008 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 com.android.browser;
18
19import android.content.Context;
20import android.graphics.Bitmap;
John Reck0ce8a942011-01-14 19:57:09 -080021import android.graphics.drawable.Drawable;
The Android Open Source Project0c908882009-03-03 19:32:16 -080022import android.view.LayoutInflater;
23import android.view.View;
24import android.widget.ImageView;
25import android.widget.LinearLayout;
26import android.widget.TextView;
27
28/**
29 * Custom layout for an item representing a bookmark in the browser.
30 */
31class BookmarkItem extends LinearLayout {
32
John Reck35e9dd62011-04-25 09:01:54 -070033 final static int MAX_TEXTVIEW_LEN = 80;
34
The Android Open Source Project0c908882009-03-03 19:32:16 -080035 protected TextView mTextView;
36 protected TextView mUrlText;
37 protected ImageView mImageView;
38 protected String mUrl;
Ben Murdoch9907efc2009-10-28 13:22:46 +000039 protected String mTitle;
The Android Open Source Project0c908882009-03-03 19:32:16 -080040
41 /**
42 * Instantiate a bookmark item, including a default favicon.
43 *
44 * @param context The application context for the item.
45 */
46 BookmarkItem(Context context) {
47 super(context);
48
49 LayoutInflater factory = LayoutInflater.from(context);
50 factory.inflate(R.layout.history_item, this);
51 mTextView = (TextView) findViewById(R.id.title);
52 mUrlText = (TextView) findViewById(R.id.url);
53 mImageView = (ImageView) findViewById(R.id.favicon);
54 View star = findViewById(R.id.star);
55 star.setVisibility(View.GONE);
56 }
57
58 /**
59 * Copy this BookmarkItem to item.
60 * @param item BookmarkItem to receive the info from this BookmarkItem.
61 */
62 /* package */ void copyTo(BookmarkItem item) {
63 item.mTextView.setText(mTextView.getText());
64 item.mUrlText.setText(mUrlText.getText());
65 item.mImageView.setImageDrawable(mImageView.getDrawable());
66 }
67
John Reck778bd2e2011-04-13 12:30:01 -070068 public void startMarquee() {
69 mTextView.setSelected(true);
70 mUrlText.setSelected(true);
71 }
72
73 public void stopMarquee() {
74 mTextView.setSelected(false);
75 mUrlText.setSelected(false);
76 }
77
The Android Open Source Project0c908882009-03-03 19:32:16 -080078 /**
79 * Return the name assigned to this bookmark item.
80 */
81 /* package */ String getName() {
Ben Murdoch9907efc2009-10-28 13:22:46 +000082 return mTitle;
The Android Open Source Project0c908882009-03-03 19:32:16 -080083 }
84
85 /**
86 * Return the TextView which holds the name of this bookmark item.
87 */
88 /* package */ TextView getNameTextView() {
89 return mTextView;
90 }
91
92 /* package */ String getUrl() {
93 return mUrl;
94 }
95
96 /**
97 * Set the favicon for this item.
98 *
99 * @param b The new bitmap for this item.
100 * If it is null, will use the default.
101 */
102 /* package */ void setFavicon(Bitmap b) {
103 if (b != null) {
104 mImageView.setImageBitmap(b);
105 } else {
106 mImageView.setImageResource(R.drawable.app_web_browser_sm);
107 }
108 }
109
John Reck0ce8a942011-01-14 19:57:09 -0800110 void setFaviconBackground(Drawable d) {
111 mImageView.setBackgroundDrawable(d);
112 }
113
The Android Open Source Project0c908882009-03-03 19:32:16 -0800114 /**
115 * Set the new name for the bookmark item.
116 *
117 * @param name The new name for the bookmark item.
118 */
119 /* package */ void setName(String name) {
Ben Murdoch9907efc2009-10-28 13:22:46 +0000120 if (name == null) {
121 return;
122 }
123
124 mTitle = name;
125
John Reck35e9dd62011-04-25 09:01:54 -0700126 if (name.length() > MAX_TEXTVIEW_LEN) {
127 name = name.substring(0, MAX_TEXTVIEW_LEN);
Ben Murdoch9907efc2009-10-28 13:22:46 +0000128 }
129
The Android Open Source Project0c908882009-03-03 19:32:16 -0800130 mTextView.setText(name);
131 }
132
133 /**
134 * Set the new url for the bookmark item.
135 * @param url The new url for the bookmark item.
136 */
137 /* package */ void setUrl(String url) {
Ben Murdoch9907efc2009-10-28 13:22:46 +0000138 if (url == null) {
139 return;
140 }
141
The Android Open Source Project0c908882009-03-03 19:32:16 -0800142 mUrl = url;
Ben Murdoch9907efc2009-10-28 13:22:46 +0000143
John Reck35e9dd62011-04-25 09:01:54 -0700144 if (url.length() > MAX_TEXTVIEW_LEN) {
145 url = url.substring(0, MAX_TEXTVIEW_LEN);
Ben Murdoch9907efc2009-10-28 13:22:46 +0000146 }
147
148 mUrlText.setText(url);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800149 }
150}