HistoryItem.java revision b1402a5c3e1617867c58d32d1fe9782cf6de423f
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.view.View;
22import android.widget.CompoundButton;
23
24/**
25 *  Layout representing a history item in the classic history viewer.
26 */
27/* package */ class HistoryItem extends BookmarkItem {
28
29    private CompoundButton  mStar;      // Star for bookmarking
30    private CompoundButton.OnCheckedChangeListener  mListener;
31    /**
32     *  Create a new HistoryItem.
33     *  @param context  Context for this HistoryItem.
34     */
35    /* package */ HistoryItem(Context context) {
36        super(context);
37
38        mStar = (CompoundButton) findViewById(R.id.star);
39        mStar.setVisibility(View.VISIBLE);
40        mListener = new CompoundButton.OnCheckedChangeListener() {
41            public void onCheckedChanged(CompoundButton buttonView,
42                    boolean isChecked) {
43                if (isChecked) {
44                    // FIXME: For now, add at the root level.  Should we
45                    // open AddBookmark from here?
46                    Bookmarks.addBookmark(getContext(), true, mUrl, getName(), null, true, 0);
47                    LogTag.logBookmarkAdded(mUrl, "history");
48                } else {
49                    Bookmarks.removeFromBookmarks(getContext(),
50                            getContext().getContentResolver(), mUrl, getName());
51                }
52            }
53        };
54    }
55
56    /* package */ void copyTo(HistoryItem item) {
57        item.mTextView.setText(mTextView.getText());
58        item.mUrlText.setText(mUrlText.getText());
59        item.setIsBookmark(mStar.isChecked());
60        item.mImageView.setImageDrawable(mImageView.getDrawable());
61    }
62
63    /**
64     * Whether or not this item represents a bookmarked site
65     */
66    /* package */ boolean isBookmark() {
67        return mStar.isChecked();
68    }
69
70    /**
71     *  Set whether or not this represents a bookmark, and make sure the star
72     *  behaves appropriately.
73     */
74    /* package */ void setIsBookmark(boolean isBookmark) {
75        mStar.setOnCheckedChangeListener(null);
76        mStar.setChecked(isBookmark);
77        mStar.setOnCheckedChangeListener(mListener);
78    }
79}
80