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