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