Home | History | Annotate | Download | only in browser
      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                     LogTag.logBookmarkAdded(mUrl, "history");
     51                 } else {
     52                     Bookmarks.removeFromBookmarks(mContext,
     53                             mContext.getContentResolver(), mUrl, getName());
     54                 }
     55             }
     56         };
     57     }
     58 
     59     /* package */ void copyTo(HistoryItem item) {
     60         item.mTextView.setText(mTextView.getText());
     61         item.mUrlText.setText(mUrlText.getText());
     62         item.setIsBookmark(mStar.isChecked());
     63         item.mImageView.setImageDrawable(mImageView.getDrawable());
     64     }
     65 
     66     /**
     67      * Whether or not this item represents a bookmarked site
     68      */
     69     /* package */ boolean isBookmark() {
     70         return mStar.isChecked();
     71     }
     72 
     73     /**
     74      *  Set whether or not this represents a bookmark, and make sure the star
     75      *  behaves appropriately.
     76      */
     77     /* package */ void setIsBookmark(boolean isBookmark) {
     78         mStar.setOnCheckedChangeListener(null);
     79         mStar.setChecked(isBookmark);
     80         mStar.setOnCheckedChangeListener(mListener);
     81     }
     82 }
     83