2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package com.android.browser;
20 import android.content.Context;
21 import android.graphics.Bitmap;
22 import android.provider.Browser;
23 import android.view.View;
24 import android.widget.CompoundButton;
25 import android.widget.ImageView;
26 import android.widget.TextView;
29 * Layout representing a history item in the classic history viewer.
31 /* package */ class HistoryItem extends BookmarkItem {
33 private CompoundButton mStar; // Star for bookmarking
34 private CompoundButton.OnCheckedChangeListener mListener;
36 * Create a new HistoryItem.
37 * @param context Context for this HistoryItem.
39 /* package */ HistoryItem(Context context) {
42 mStar = (CompoundButton) findViewById(R.id.star);
43 mStar.setVisibility(View.VISIBLE);
44 mListener = new CompoundButton.OnCheckedChangeListener() {
45 public void onCheckedChanged(CompoundButton buttonView,
48 Bookmarks.addBookmark(mContext,
49 mContext.getContentResolver(), mUrl, getName(), null, true);
51 Bookmarks.removeFromBookmarks(mContext,
52 mContext.getContentResolver(), mUrl, getName());
58 /* package */ 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());
66 * Whether or not this item represents a bookmarked site
68 /* package */ boolean isBookmark() {
69 return mStar.isChecked();
73 * Set whether or not this represents a bookmark, and make sure the star
74 * behaves appropriately.
76 /* package */ void setIsBookmark(boolean isBookmark) {
77 mStar.setOnCheckedChangeListener(null);
78 mStar.setChecked(isBookmark);
79 mStar.setOnCheckedChangeListener(mListener);