blob: 4e60073cfde11cb3ae5fb74552c64f8525f91ae9 [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
33 protected TextView mTextView;
34 protected TextView mUrlText;
35 protected ImageView mImageView;
36 protected String mUrl;
Ben Murdoch9907efc2009-10-28 13:22:46 +000037 protected String mTitle;
The Android Open Source Project0c908882009-03-03 19:32:16 -080038
39 /**
40 * Instantiate a bookmark item, including a default favicon.
41 *
42 * @param context The application context for the item.
43 */
44 BookmarkItem(Context context) {
45 super(context);
46
47 LayoutInflater factory = LayoutInflater.from(context);
48 factory.inflate(R.layout.history_item, this);
49 mTextView = (TextView) findViewById(R.id.title);
50 mUrlText = (TextView) findViewById(R.id.url);
51 mImageView = (ImageView) findViewById(R.id.favicon);
52 View star = findViewById(R.id.star);
53 star.setVisibility(View.GONE);
54 }
55
56 /**
57 * Copy this BookmarkItem to item.
58 * @param item BookmarkItem to receive the info from this BookmarkItem.
59 */
60 /* package */ void copyTo(BookmarkItem item) {
61 item.mTextView.setText(mTextView.getText());
62 item.mUrlText.setText(mUrlText.getText());
63 item.mImageView.setImageDrawable(mImageView.getDrawable());
64 }
65
66 /**
67 * Return the name assigned to this bookmark item.
68 */
69 /* package */ String getName() {
Ben Murdoch9907efc2009-10-28 13:22:46 +000070 return mTitle;
The Android Open Source Project0c908882009-03-03 19:32:16 -080071 }
72
73 /**
74 * Return the TextView which holds the name of this bookmark item.
75 */
76 /* package */ TextView getNameTextView() {
77 return mTextView;
78 }
79
80 /* package */ String getUrl() {
81 return mUrl;
82 }
83
84 /**
85 * Set the favicon for this item.
86 *
87 * @param b The new bitmap for this item.
88 * If it is null, will use the default.
89 */
90 /* package */ void setFavicon(Bitmap b) {
91 if (b != null) {
92 mImageView.setImageBitmap(b);
93 } else {
94 mImageView.setImageResource(R.drawable.app_web_browser_sm);
95 }
96 }
97
John Reck0ce8a942011-01-14 19:57:09 -080098 void setFaviconBackground(Drawable d) {
99 mImageView.setBackgroundDrawable(d);
100 }
101
The Android Open Source Project0c908882009-03-03 19:32:16 -0800102 /**
103 * Set the new name for the bookmark item.
104 *
105 * @param name The new name for the bookmark item.
106 */
107 /* package */ void setName(String name) {
Ben Murdoch9907efc2009-10-28 13:22:46 +0000108 if (name == null) {
109 return;
110 }
111
112 mTitle = name;
113
114 if (name.length() > BrowserSettings.MAX_TEXTVIEW_LEN) {
115 name = name.substring(0, BrowserSettings.MAX_TEXTVIEW_LEN);
116 }
117
The Android Open Source Project0c908882009-03-03 19:32:16 -0800118 mTextView.setText(name);
119 }
120
121 /**
122 * Set the new url for the bookmark item.
123 * @param url The new url for the bookmark item.
124 */
125 /* package */ void setUrl(String url) {
Ben Murdoch9907efc2009-10-28 13:22:46 +0000126 if (url == null) {
127 return;
128 }
129
The Android Open Source Project0c908882009-03-03 19:32:16 -0800130 mUrl = url;
Ben Murdoch9907efc2009-10-28 13:22:46 +0000131
132 if (url.length() > BrowserSettings.MAX_TEXTVIEW_LEN) {
133 url = url.substring(0, BrowserSettings.MAX_TEXTVIEW_LEN);
134 }
135
136 mUrlText.setText(url);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800137 }
138}