Home | History | Annotate | Download | only in browser
      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     protected String      mTitle;
     37 
     38     /**
     39      *  Instantiate a bookmark item, including a default favicon.
     40      *
     41      *  @param context  The application context for the item.
     42      */
     43     BookmarkItem(Context context) {
     44         super(context);
     45 
     46         LayoutInflater factory = LayoutInflater.from(context);
     47         factory.inflate(R.layout.history_item, this);
     48         mTextView = (TextView) findViewById(R.id.title);
     49         mUrlText = (TextView) findViewById(R.id.url);
     50         mImageView = (ImageView) findViewById(R.id.favicon);
     51         View star = findViewById(R.id.star);
     52         star.setVisibility(View.GONE);
     53     }
     54 
     55     /**
     56      *  Copy this BookmarkItem to item.
     57      *  @param item BookmarkItem to receive the info from this BookmarkItem.
     58      */
     59     /* package */ void copyTo(BookmarkItem item) {
     60         item.mTextView.setText(mTextView.getText());
     61         item.mUrlText.setText(mUrlText.getText());
     62         item.mImageView.setImageDrawable(mImageView.getDrawable());
     63     }
     64 
     65     /**
     66      * Return the name assigned to this bookmark item.
     67      */
     68     /* package */ String getName() {
     69         return mTitle;
     70     }
     71 
     72     /**
     73      * Return the TextView which holds the name of this bookmark item.
     74      */
     75     /* package */ TextView getNameTextView() {
     76         return mTextView;
     77     }
     78 
     79     /* package */ String getUrl() {
     80         return mUrl;
     81     }
     82 
     83     /**
     84      *  Set the favicon for this item.
     85      *
     86      *  @param b    The new bitmap for this item.
     87      *              If it is null, will use the default.
     88      */
     89     /* package */ void setFavicon(Bitmap b) {
     90         if (b != null) {
     91             mImageView.setImageBitmap(b);
     92         } else {
     93             mImageView.setImageResource(R.drawable.app_web_browser_sm);
     94         }
     95     }
     96 
     97     /**
     98      *  Set the new name for the bookmark item.
     99      *
    100      *  @param name The new name for the bookmark item.
    101      */
    102     /* package */ void setName(String name) {
    103         if (name == null) {
    104             return;
    105         }
    106 
    107         mTitle = name;
    108 
    109         if (name.length() > BrowserSettings.MAX_TEXTVIEW_LEN) {
    110             name = name.substring(0, BrowserSettings.MAX_TEXTVIEW_LEN);
    111         }
    112 
    113         mTextView.setText(name);
    114     }
    115 
    116     /**
    117      *  Set the new url for the bookmark item.
    118      *  @param url  The new url for the bookmark item.
    119      */
    120     /* package */ void setUrl(String url) {
    121         if (url == null) {
    122             return;
    123         }
    124 
    125         mUrl = url;
    126 
    127         if (url.length() > BrowserSettings.MAX_TEXTVIEW_LEN) {
    128             url = url.substring(0, BrowserSettings.MAX_TEXTVIEW_LEN);
    129         }
    130 
    131         mUrlText.setText(url);
    132     }
    133 }
    134