/WebVox/src/com/marvin/webvox/BookmarkItem.java

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