• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.widget.ImageView;
24 import android.widget.LinearLayout;
25 import android.widget.TextView;
26 
27 /**
28  *  Custom layout for an item representing a bookmark in the browser.
29  */
30 class 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      */
BookmarkItem(Context context)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      */
copyTo(BookmarkItem item)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      */
getName()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      */
getNameTextView()74     /* package */ TextView getNameTextView() {
75         return mTextView;
76     }
77 
getUrl()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      */
setFavicon(Bitmap b)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      */
setName(String name)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      */
setUrl(String url)109     /* package */ void setUrl(String url) {
110         mUrlText.setText(url);
111         mUrl = url;
112     }
113 }
114