The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.graphics.Bitmap; |
John Reck | 0ce8a94 | 2011-01-14 19:57:09 -0800 | [diff] [blame] | 21 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 22 | import android.view.LayoutInflater; |
| 23 | import android.view.View; |
| 24 | import android.widget.ImageView; |
| 25 | import android.widget.LinearLayout; |
| 26 | import android.widget.TextView; |
| 27 | |
| 28 | /** |
| 29 | * Custom layout for an item representing a bookmark in the browser. |
| 30 | */ |
| 31 | class BookmarkItem extends LinearLayout { |
| 32 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 33 | final static int MAX_TEXTVIEW_LEN = 80; |
| 34 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 35 | protected TextView mTextView; |
| 36 | protected TextView mUrlText; |
| 37 | protected ImageView mImageView; |
| 38 | protected String mUrl; |
Ben Murdoch | 9907efc | 2009-10-28 13:22:46 +0000 | [diff] [blame] | 39 | protected String mTitle; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 40 | |
| 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 Reck | 778bd2e | 2011-04-13 12:30:01 -0700 | [diff] [blame] | 68 | 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 Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 78 | /** |
| 79 | * Return the name assigned to this bookmark item. |
| 80 | */ |
| 81 | /* package */ String getName() { |
Ben Murdoch | 9907efc | 2009-10-28 13:22:46 +0000 | [diff] [blame] | 82 | return mTitle; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 83 | } |
| 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 Reck | 0ce8a94 | 2011-01-14 19:57:09 -0800 | [diff] [blame] | 110 | void setFaviconBackground(Drawable d) { |
| 111 | mImageView.setBackgroundDrawable(d); |
| 112 | } |
| 113 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 114 | /** |
| 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 Murdoch | 9907efc | 2009-10-28 13:22:46 +0000 | [diff] [blame] | 120 | if (name == null) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | mTitle = name; |
| 125 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 126 | if (name.length() > MAX_TEXTVIEW_LEN) { |
| 127 | name = name.substring(0, MAX_TEXTVIEW_LEN); |
Ben Murdoch | 9907efc | 2009-10-28 13:22:46 +0000 | [diff] [blame] | 128 | } |
| 129 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 130 | 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 Murdoch | 9907efc | 2009-10-28 13:22:46 +0000 | [diff] [blame] | 138 | if (url == null) { |
| 139 | return; |
| 140 | } |
| 141 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 142 | mUrl = url; |
Ben Murdoch | 9907efc | 2009-10-28 13:22:46 +0000 | [diff] [blame] | 143 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 144 | if (url.length() > MAX_TEXTVIEW_LEN) { |
| 145 | url = url.substring(0, MAX_TEXTVIEW_LEN); |
Ben Murdoch | 9907efc | 2009-10-28 13:22:46 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | mUrlText.setText(url); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 149 | } |
| 150 | } |