• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 package com.android.gallery3d.ingest.ui;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.widget.CheckBox;
22 import android.widget.Checkable;
23 import android.widget.CompoundButton;
24 import android.widget.CompoundButton.OnCheckedChangeListener;
25 import android.widget.RelativeLayout;
26 
27 import com.android.gallery3d.R;
28 import com.android.gallery3d.ingest.adapter.CheckBroker;
29 
30 public class MtpFullscreenView extends RelativeLayout implements Checkable,
31     CompoundButton.OnCheckedChangeListener, CheckBroker.OnCheckedChangedListener {
32 
33     private MtpImageView mImageView;
34     private CheckBox mCheckbox;
35     private int mPosition = -1;
36     private CheckBroker mBroker;
37 
MtpFullscreenView(Context context)38     public MtpFullscreenView(Context context) {
39         super(context);
40     }
41 
MtpFullscreenView(Context context, AttributeSet attrs)42     public MtpFullscreenView(Context context, AttributeSet attrs) {
43         super(context, attrs);
44     }
45 
MtpFullscreenView(Context context, AttributeSet attrs, int defStyle)46     public MtpFullscreenView(Context context, AttributeSet attrs, int defStyle) {
47         super(context, attrs, defStyle);
48     }
49 
50     @Override
onFinishInflate()51     protected void onFinishInflate() {
52         super.onFinishInflate();
53         mImageView = (MtpImageView) findViewById(R.id.ingest_fullsize_image);
54         mCheckbox = (CheckBox) findViewById(R.id.ingest_fullsize_image_checkbox);
55         mCheckbox.setOnCheckedChangeListener(this);
56     }
57 
58     @Override
isChecked()59     public boolean isChecked() {
60         return mCheckbox.isChecked();
61     }
62 
63     @Override
setChecked(boolean checked)64     public void setChecked(boolean checked) {
65         mCheckbox.setChecked(checked);
66     }
67 
68     @Override
toggle()69     public void toggle() {
70         mCheckbox.toggle();
71     }
72 
73     @Override
onDetachedFromWindow()74     public void onDetachedFromWindow() {
75         setPositionAndBroker(-1, null);
76         super.onDetachedFromWindow();
77     }
78 
getImageView()79     public MtpImageView getImageView() {
80         return mImageView;
81     }
82 
getPosition()83     public int getPosition() {
84         return mPosition;
85     }
86 
setPositionAndBroker(int position, CheckBroker b)87     public void setPositionAndBroker(int position, CheckBroker b) {
88         if (mBroker != null) {
89             mBroker.unregisterOnCheckedChangeListener(this);
90         }
91         mPosition = position;
92         mBroker = b;
93         if (mBroker != null) {
94             setChecked(mBroker.isItemChecked(position));
95             mBroker.registerOnCheckedChangeListener(this);
96         }
97     }
98 
99     @Override
onCheckedChanged(CompoundButton arg0, boolean isChecked)100     public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
101         if (mBroker != null) mBroker.setItemChecked(mPosition, isChecked);
102     }
103 
104     @Override
onCheckedChanged(int position, boolean isChecked)105     public void onCheckedChanged(int position, boolean isChecked) {
106         if (position == mPosition) {
107             setChecked(isChecked);
108         }
109     }
110 
111     @Override
onBulkCheckedChanged()112     public void onBulkCheckedChanged() {
113         if(mBroker != null) setChecked(mBroker.isItemChecked(mPosition));
114     }
115 }
116