1 /* 2 * Copyright (C) 2010 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.photoeditor; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.View; 22 import android.view.ViewGroup; 23 24 import com.android.gallery3d.R; 25 26 /** 27 * Effects menu that contains toggles mapping to corresponding groups of effects. 28 */ 29 public class EffectsMenu extends RestorableView { 30 31 /** 32 * Listener of toggle changes. 33 */ 34 public interface OnToggleListener { 35 36 /** 37 * Listens to the selected status and mapped effects-id of the clicked toggle. 38 * 39 * @return true to make the toggle selected; otherwise, make it unselected. 40 */ 41 boolean onToggle(boolean isSelected, int effectsId); 42 } 43 44 public EffectsMenu(Context context, AttributeSet attrs) { 45 super(context, attrs); 46 } 47 48 @Override 49 protected int childLayoutId() { 50 return R.layout.photoeditor_effects_menu; 51 } 52 53 public void setOnToggleListener(OnToggleListener listener) { 54 setToggleRunnalbe(listener, R.id.exposure_button, R.layout.photoeditor_effects_exposure); 55 setToggleRunnalbe(listener, R.id.artistic_button, R.layout.photoeditor_effects_artistic); 56 setToggleRunnalbe(listener, R.id.color_button, R.layout.photoeditor_effects_color); 57 setToggleRunnalbe(listener, R.id.fix_button, R.layout.photoeditor_effects_fix); 58 } 59 60 private void setToggleRunnalbe(final OnToggleListener listener, final int toggleId, 61 final int effectsId) { 62 setClickRunnable(toggleId, new Runnable() { 63 64 @Override 65 public void run() { 66 boolean selected = findViewById(toggleId).isSelected(); 67 setViewSelected(toggleId, listener.onToggle(selected, effectsId)); 68 } 69 }); 70 } 71 72 public void clearSelected() { 73 ViewGroup menu = (ViewGroup) findViewById(R.id.toggles); 74 for (int i = 0; i < menu.getChildCount(); i++) { 75 View toggle = menu.getChildAt(i); 76 if (toggle.isSelected()) { 77 setViewSelected(toggle.getId(), false); 78 } 79 } 80 } 81 } 82