HistoryItem.java revision e372c02c732cf0881c21eb8423454a555e8fc75c
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 18package com.android.browser; 19 20import android.content.Context; 21import android.graphics.Bitmap; 22import android.provider.Browser; 23import android.view.View; 24import android.widget.CompoundButton; 25import android.widget.ImageView; 26import android.widget.TextView; 27 28/** 29 * Layout representing a history item in the classic history viewer. 30 */ 31/* package */ class HistoryItem extends BookmarkItem { 32 33 private CompoundButton mStar; // Star for bookmarking 34 private CompoundButton.OnCheckedChangeListener mListener; 35 /** 36 * Create a new HistoryItem. 37 * @param context Context for this HistoryItem. 38 */ 39 /* package */ HistoryItem(Context context) { 40 super(context); 41 42 mStar = (CompoundButton) findViewById(R.id.star); 43 mStar.setVisibility(View.VISIBLE); 44 mListener = new CompoundButton.OnCheckedChangeListener() { 45 public void onCheckedChanged(CompoundButton buttonView, 46 boolean isChecked) { 47 if (isChecked) { 48 Bookmarks.addBookmark(mContext, 49 mContext.getContentResolver(), mUrl, getName()); 50 } else { 51 Bookmarks.removeFromBookmarks(mContext, 52 mContext.getContentResolver(), mUrl); 53 } 54 } 55 }; 56 } 57 58 void copyTo(HistoryItem item) { 59 item.mTextView.setText(mTextView.getText()); 60 item.mUrlText.setText(mUrlText.getText()); 61 item.setIsBookmark(mStar.isChecked()); 62 item.mImageView.setImageDrawable(mImageView.getDrawable()); 63 } 64 65 /** 66 * Set whether or not this represents a bookmark, and make sure the star 67 * behaves appropriately. 68 */ 69 void setIsBookmark(boolean isBookmark) { 70 mStar.setOnCheckedChangeListener(null); 71 mStar.setChecked(isBookmark); 72 mStar.setOnCheckedChangeListener(mListener); 73 } 74} 75