15b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar/* 25b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * Copyright (C) 2015 The Android Open Source Project 35b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * 45b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License"); 55b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * you may not use this file except in compliance with the License. 65b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * You may obtain a copy of the License at 75b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * 85b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * http://www.apache.org/licenses/LICENSE-2.0 95b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * 105b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * Unless required by applicable law or agreed to in writing, software 115b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS, 125b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * See the License for the specific language governing permissions and 145b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar * limitations under the License. 155b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar */ 165b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar 175b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyarpackage com.example.android.supportv7.widget.util; 185b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar 195b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyarimport android.support.v7.widget.RecyclerView; 205b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyarimport android.view.View; 215b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyarimport android.widget.CheckBox; 225b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyarimport android.widget.CompoundButton; 235b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar 245b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyarpublic class ConfigViewHolder extends RecyclerView.ViewHolder 255b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar implements CompoundButton.OnCheckedChangeListener { 265b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar 275b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar private CheckBox mCheckBox; 285b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar 295b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar private ConfigToggle mConfigToggle; 305b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar 315b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar public ConfigViewHolder(View itemView) { 325b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar super(itemView); 335b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar mCheckBox = (CheckBox) itemView; 345b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar mCheckBox.setOnCheckedChangeListener(this); 355b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar } 365b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar 375b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar public void bind(ConfigToggle toggle) { 385b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar mConfigToggle = toggle; 395b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar mCheckBox.setText(toggle.getText()); 405b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar mCheckBox.setChecked(toggle.isChecked()); 415b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar } 425b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar 435b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar @Override 445b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 455b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar if (mConfigToggle != null) { 465b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar mConfigToggle.onChange(isChecked); 475b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar } 485b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar } 495b611d45d8d84bd604e6ce855f9520499ff89b68Yigit Boyar} 50