1 /* 2 * Copyright (C) 2014 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.camera.widget; 18 19 import android.content.Context; 20 import android.content.res.Configuration; 21 import android.util.AttributeSet; 22 import android.view.View; 23 import android.widget.CheckBox; 24 import android.widget.CompoundButton; 25 import android.widget.FrameLayout; 26 27 import com.android.camera2.R; 28 29 public class LocationDialogLayout extends FrameLayout { 30 31 public interface LocationTaggingSelectionListener { onLocationTaggingSelected(boolean selected)32 public void onLocationTaggingSelected(boolean selected); 33 } 34 35 private View mConfirmButton; 36 private CheckBox mCheckBox; 37 private int mLastOrientation; 38 private LocationTaggingSelectionListener mListener; 39 private boolean mCheckBoxChecked = true; 40 LocationDialogLayout(Context context, AttributeSet attributeSet)41 public LocationDialogLayout(Context context, AttributeSet attributeSet) { 42 super(context, attributeSet); 43 mLastOrientation = context.getResources().getConfiguration().orientation; 44 } 45 46 @Override onFinishInflate()47 public void onFinishInflate() { 48 updateViewReference(); 49 } 50 51 @Override onConfigurationChanged(Configuration config)52 public void onConfigurationChanged(Configuration config) { 53 super.onConfigurationChanged(config); 54 // TODO: Extract the orientation checking logic in a super class as it 55 // is also used in the aspect ratio dialog. 56 if (config.orientation == mLastOrientation) { 57 return; 58 } 59 mLastOrientation = config.orientation; 60 removeAllViews(); 61 inflate(getContext(), R.layout.location_dialog_content, this); 62 updateViewReference(); 63 } 64 updateViewReference()65 private void updateViewReference() { 66 mCheckBox = (CheckBox) findViewById(R.id.check_box); 67 mCheckBox.setChecked(mCheckBoxChecked); 68 mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 69 @Override 70 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 71 mCheckBoxChecked = isChecked; 72 } 73 }); 74 75 mConfirmButton = findViewById(R.id.confirm_button); 76 mConfirmButton.setOnClickListener(new OnClickListener() { 77 @Override 78 public void onClick(View v) { 79 if (mListener != null) { 80 mListener.onLocationTaggingSelected(mCheckBoxChecked); 81 } 82 } 83 }); 84 } 85 setLocationTaggingSelectionListener(LocationTaggingSelectionListener listener)86 public void setLocationTaggingSelectionListener(LocationTaggingSelectionListener listener) { 87 mListener = listener; 88 } 89 90 } 91