10c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project/* 20c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 30c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * 40c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 50c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * you may not use this file except in compliance with the License. 60c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * You may obtain a copy of the License at 70c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * 80c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 90c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * 100c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software 110c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 120c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * See the License for the specific language governing permissions and 140c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * limitations under the License. 150c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project */ 160c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project 170c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project 180c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Projectpackage com.android.browser; 190c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project 200c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Projectimport android.content.Context; 210c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Projectimport android.graphics.Bitmap; 220c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Projectimport android.provider.Browser; 230c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Projectimport android.view.View; 240c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Projectimport android.widget.CompoundButton; 250c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Projectimport android.widget.ImageView; 260c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Projectimport android.widget.TextView; 270c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project 280c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project/** 290c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * Layout representing a history item in the classic history viewer. 300c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project */ 310c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project/* package */ class HistoryItem extends BookmarkItem { 320c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project 330c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project private CompoundButton mStar; // Star for bookmarking 340c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project private CompoundButton.OnCheckedChangeListener mListener; 350c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project /** 360c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * Create a new HistoryItem. 370c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * @param context Context for this HistoryItem. 380c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project */ 390c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project /* package */ HistoryItem(Context context) { 400c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project super(context); 410c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project 420c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project mStar = (CompoundButton) findViewById(R.id.star); 430c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project mStar.setVisibility(View.VISIBLE); 440c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project mListener = new CompoundButton.OnCheckedChangeListener() { 450c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project public void onCheckedChanged(CompoundButton buttonView, 460c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project boolean isChecked) { 470c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project if (isChecked) { 48e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Bookmarks.addBookmark(mContext, 49aac7aa6fcfcb519755987ec126be066323f589c8Ben Murdoch mContext.getContentResolver(), mUrl, getName(), null, true); 500a1d838ccd16ac08300bb8ac89b61ee0c956a49bKristian Monsen LogTag.logBookmarkAdded(mUrl, "history"); 510c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project } else { 52e372c02c732cf0881c21eb8423454a555e8fc75cLeon Scroggins Bookmarks.removeFromBookmarks(mContext, 53c95261955cf08f30b484b6a229c4bcff42c645ceAndrei Popescu mContext.getContentResolver(), mUrl, getName()); 540c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project } 550c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project } 560c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project }; 570c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project } 580c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project 59186e593776c396bde3d720addd6f6842fe880a7cLeon Scroggins /* package */ void copyTo(HistoryItem item) { 600c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project item.mTextView.setText(mTextView.getText()); 610c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project item.mUrlText.setText(mUrlText.getText()); 620c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project item.setIsBookmark(mStar.isChecked()); 630c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project item.mImageView.setImageDrawable(mImageView.getDrawable()); 640c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project } 650c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project 660c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project /** 67186e593776c396bde3d720addd6f6842fe880a7cLeon Scroggins * Whether or not this item represents a bookmarked site 68186e593776c396bde3d720addd6f6842fe880a7cLeon Scroggins */ 69186e593776c396bde3d720addd6f6842fe880a7cLeon Scroggins /* package */ boolean isBookmark() { 70186e593776c396bde3d720addd6f6842fe880a7cLeon Scroggins return mStar.isChecked(); 71186e593776c396bde3d720addd6f6842fe880a7cLeon Scroggins } 72186e593776c396bde3d720addd6f6842fe880a7cLeon Scroggins 73186e593776c396bde3d720addd6f6842fe880a7cLeon Scroggins /** 740c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * Set whether or not this represents a bookmark, and make sure the star 750c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project * behaves appropriately. 760c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project */ 77186e593776c396bde3d720addd6f6842fe880a7cLeon Scroggins /* package */ void setIsBookmark(boolean isBookmark) { 780c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project mStar.setOnCheckedChangeListener(null); 790c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project mStar.setChecked(isBookmark); 800c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project mStar.setOnCheckedChangeListener(mListener); 810c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project } 820c90888c75eed12f6e2e14a9044faf50bd4af8edThe Android Open Source Project} 83