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 17package com.android.gallery3d.photoeditor.actions; 18 19import android.view.LayoutInflater; 20import android.view.View; 21import android.view.ViewGroup; 22 23import com.android.gallery3d.R; 24import com.android.gallery3d.photoeditor.PhotoView; 25 26/** 27 * Factory to create tools that will be used by effect actions. 28 */ 29public class EffectToolFactory { 30 31 public enum ScalePickerType { 32 LIGHT, SHADOW, COLOR, GENERIC 33 } 34 35 private final ViewGroup effectToolPanel; 36 private final LayoutInflater inflater; 37 38 public EffectToolFactory(ViewGroup effectToolPanel, LayoutInflater inflater) { 39 this.effectToolPanel = effectToolPanel; 40 this.inflater = inflater; 41 } 42 43 private View createFullscreenTool(int toolId) { 44 // Create full screen effect tool on top of photo-view and place it within the same 45 // view group that contains photo-view. 46 View photoView = effectToolPanel.getRootView().findViewById(R.id.photo_view); 47 ViewGroup parent = (ViewGroup) photoView.getParent(); 48 FullscreenToolView view = (FullscreenToolView) inflater.inflate(toolId, parent, false); 49 view.setPhotoBounds(((PhotoView) photoView).getPhotoBounds()); 50 parent.addView(view, parent.indexOfChild(photoView) + 1); 51 return view; 52 } 53 54 private View createPanelTool(int toolId) { 55 View view = inflater.inflate(toolId, effectToolPanel, false); 56 effectToolPanel.addView(view, 0); 57 return view; 58 } 59 60 private int getScalePickerBackground(ScalePickerType type) { 61 switch (type) { 62 case LIGHT: 63 return R.drawable.photoeditor_scale_seekbar_light; 64 65 case SHADOW: 66 return R.drawable.photoeditor_scale_seekbar_shadow; 67 68 case COLOR: 69 return R.drawable.photoeditor_scale_seekbar_color; 70 } 71 return R.drawable.photoeditor_scale_seekbar_generic; 72 } 73 74 public ScaleSeekBar createScalePicker(ScalePickerType type) { 75 ScaleSeekBar scalePicker = (ScaleSeekBar) createPanelTool( 76 R.layout.photoeditor_scale_seekbar); 77 scalePicker.setBackgroundResource(getScalePickerBackground(type)); 78 return scalePicker; 79 } 80 81 public ColorSeekBar createColorPicker() { 82 return (ColorSeekBar) createPanelTool(R.layout.photoeditor_color_seekbar); 83 } 84 85 public DoodleView createDoodleView() { 86 return (DoodleView) createFullscreenTool(R.layout.photoeditor_doodle_view); 87 } 88 89 public TouchView createTouchView() { 90 return (TouchView) createFullscreenTool(R.layout.photoeditor_touch_view); 91 } 92 93 public FlipView createFlipView() { 94 return (FlipView) createFullscreenTool(R.layout.photoeditor_flip_view); 95 } 96 97 public RotateView createRotateView() { 98 return (RotateView) createFullscreenTool(R.layout.photoeditor_rotate_view); 99 } 100 101 public CropView createCropView() { 102 return (CropView) createFullscreenTool(R.layout.photoeditor_crop_view); 103 } 104} 105