OSDN Git Service

Deprecate fill_parent and introduce match_parent.
[android-x86/packages-apps-Browser.git] / src / com / android / browser / HistoryItem.java
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  
18 package com.android.browser;
19
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;
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(), null, true);
50                 } else {
51                     Bookmarks.removeFromBookmarks(mContext,
52                             mContext.getContentResolver(), mUrl, getName());
53                 }
54             }
55         };
56     }
57     
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());
63     }
64
65     /**
66      * Whether or not this item represents a bookmarked site
67      */
68     /* package */ boolean isBookmark() {
69         return mStar.isChecked();
70     }
71
72     /**
73      *  Set whether or not this represents a bookmark, and make sure the star
74      *  behaves appropriately.
75      */
76     /* package */ void setIsBookmark(boolean isBookmark) {
77         mStar.setOnCheckedChangeListener(null);
78         mStar.setChecked(isBookmark);
79         mStar.setOnCheckedChangeListener(mListener);
80     }
81 }