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.view.View; 22 import android.widget.CheckBox; 23 import android.widget.CompoundButton; 24 import android.widget.FrameLayout; 25 26 import com.android.camera2.R; 27 28 /** 29 * Displays a dialog that allows people to choose whether they like to enable 30 * location recording or not. Please instantiate this class programmatically. 31 */ 32 public class LocationDialogLayout extends FrameLayout { 33 34 public interface LocationDialogListener { onConfirm(boolean locationRecordingEnabled)35 public void onConfirm(boolean locationRecordingEnabled); 36 } 37 38 private LocationDialogListener mListener; 39 private CheckBox mCheckBox; 40 private View mConfirmButton; 41 private int mLastOrientation; 42 private boolean mLocationRecordingEnabled; 43 44 /** 45 * Constructs a new LocationDialogLayout object. 46 * 47 * @param context The application context. 48 * @param defaultLocationRecordingEnabled Whether to enable location 49 * recording by default. 50 */ LocationDialogLayout(Context context, boolean defaultLocationRecordingEnabled)51 public LocationDialogLayout(Context context, boolean defaultLocationRecordingEnabled) { 52 super(context); 53 mLocationRecordingEnabled = defaultLocationRecordingEnabled; 54 mLastOrientation = context.getResources().getConfiguration().orientation; 55 setBackgroundResource(R.color.fullscreen_dialog_background_color); 56 inflate(context, R.layout.location_dialog_content, this); 57 updateSubviewReferences(); 58 } 59 setListener(LocationDialogListener listener)60 public void setListener(LocationDialogListener listener) { 61 mListener = listener; 62 } 63 64 @Override onConfigurationChanged(Configuration config)65 public void onConfigurationChanged(Configuration config) { 66 super.onConfigurationChanged(config); 67 if (config.orientation == mLastOrientation) { 68 return; 69 } 70 mLastOrientation = config.orientation; 71 72 removeAllViews(); 73 inflate(getContext(), R.layout.location_dialog_content, this); 74 updateSubviewReferences(); 75 } 76 updateSubviewReferences()77 private void updateSubviewReferences() { 78 mCheckBox = (CheckBox) findViewById(R.id.check_box); 79 mCheckBox.setChecked(mLocationRecordingEnabled); 80 mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 81 @Override 82 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 83 mLocationRecordingEnabled = isChecked; 84 } 85 }); 86 87 mConfirmButton = findViewById(R.id.confirm_button); 88 mConfirmButton.setOnClickListener(new OnClickListener() { 89 @Override 90 public void onClick(View v) { 91 if (mListener != null) { 92 mListener.onConfirm(mLocationRecordingEnabled); 93 } 94 } 95 }); 96 } 97 } 98