blob: a70dd4f76649112369446d3e8df5b58e8fd1d248 [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;
21import android.view.LayoutInflater;
22import android.view.View;
23import android.widget.ImageView;
24import android.widget.LinearLayout;
25import android.widget.TextView;
26
27/**
28 * Custom layout for an item representing a bookmark in the browser.
29 */
30class BookmarkItem extends LinearLayout {
31
32 protected TextView mTextView;
33 protected TextView mUrlText;
34 protected ImageView mImageView;
35 protected String mUrl;
36
37 /**
38 * Instantiate a bookmark item, including a default favicon.
39 *
40 * @param context The application context for the item.
41 */
42 BookmarkItem(Context context) {
43 super(context);
44
45 LayoutInflater factory = LayoutInflater.from(context);
46 factory.inflate(R.layout.history_item, this);
47 mTextView = (TextView) findViewById(R.id.title);
48 mUrlText = (TextView) findViewById(R.id.url);
49 mImageView = (ImageView) findViewById(R.id.favicon);
50 View star = findViewById(R.id.star);
51 star.setVisibility(View.GONE);
52 }
53
54 /**
55 * Copy this BookmarkItem to item.
56 * @param item BookmarkItem to receive the info from this BookmarkItem.
57 */
58 /* package */ void copyTo(BookmarkItem item) {
59 item.mTextView.setText(mTextView.getText());
60 item.mUrlText.setText(mUrlText.getText());
61 item.mImageView.setImageDrawable(mImageView.getDrawable());
62 }
63
64 /**
65 * Return the name assigned to this bookmark item.
66 */
67 /* package */ String getName() {
68 return mTextView.getText().toString();
69 }
70
71 /**
72 * Return the TextView which holds the name of this bookmark item.
73 */
74 /* package */ TextView getNameTextView() {
75 return mTextView;
76 }
77
78 /* package */ String getUrl() {
79 return mUrl;
80 }
81
82 /**
83 * Set the favicon for this item.
84 *
85 * @param b The new bitmap for this item.
86 * If it is null, will use the default.
87 */
88 /* package */ void setFavicon(Bitmap b) {
89 if (b != null) {
90 mImageView.setImageBitmap(b);
91 } else {
92 mImageView.setImageResource(R.drawable.app_web_browser_sm);
93 }
94 }
95
96 /**
97 * Set the new name for the bookmark item.
98 *
99 * @param name The new name for the bookmark item.
100 */
101 /* package */ void setName(String name) {
102 mTextView.setText(name);
103 }
104
105 /**
106 * Set the new url for the bookmark item.
107 * @param url The new url for the bookmark item.
108 */
109 /* package */ void setUrl(String url) {
110 mUrlText.setText(url);
111 mUrl = url;
112 }
113}