diff options
author | Yuli Huang <yuli@google.com> | 2011-10-18 12:42:50 +0800 |
---|---|---|
committer | Yuli Huang <yuli@google.com> | 2011-10-18 13:10:10 +0800 |
commit | b5c54b675f6216659b04904661e39dc1b84cb403 (patch) | |
tree | d6f2bd57496a1d212a662e8022554aee70ee4bde /src/com/android/gallery3d/photoeditor/EffectsBar.java | |
parent | b289d441eb5af97ac8716479831b1a2c5fe2e878 (diff) | |
download | android_packages_apps_Gallery2-b5c54b675f6216659b04904661e39dc1b84cb403.tar.gz android_packages_apps_Gallery2-b5c54b675f6216659b04904661e39dc1b84cb403.tar.bz2 android_packages_apps_Gallery2-b5c54b675f6216659b04904661e39dc1b84cb403.zip |
Fix b/5403449.
1. Extract code that recreates/restores ActionBar as RestorableView, and
make both ActionBar and EffectsMenu extend RestorableView.
2. Fix effects-menu buttons too close to each other.
3. Remove effects-menu buttons' highlight animations to look more
responsive.
Change-Id: I68e5bdcde702e611ccced5e169852c0e58a949fc
Diffstat (limited to 'src/com/android/gallery3d/photoeditor/EffectsBar.java')
-rw-r--r-- | src/com/android/gallery3d/photoeditor/EffectsBar.java | 76 |
1 files changed, 33 insertions, 43 deletions
diff --git a/src/com/android/gallery3d/photoeditor/EffectsBar.java b/src/com/android/gallery3d/photoeditor/EffectsBar.java index 6e3178e1a..acb22b6e6 100644 --- a/src/com/android/gallery3d/photoeditor/EffectsBar.java +++ b/src/com/android/gallery3d/photoeditor/EffectsBar.java @@ -33,46 +33,55 @@ import com.android.gallery3d.photoeditor.actions.EffectToolFactory; */ public class EffectsBar extends LinearLayout { + private final LayoutInflater inflater; private FilterStack filterStack; - private LayoutInflater inflater; + private EffectsMenu effectsMenu; private View effectsGallery; private ViewGroup effectToolPanel; private EffectAction activeEffect; public EffectsBar(Context context, AttributeSet attrs) { super(context, attrs); + inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void initialize(FilterStack filterStack) { this.filterStack = filterStack; - inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - setupMenuToggle(R.id.exposure_button, R.layout.photoeditor_effects_exposure); - setupMenuToggle(R.id.artistic_button, R.layout.photoeditor_effects_artistic); - setupMenuToggle(R.id.color_button, R.layout.photoeditor_effects_color); - setupMenuToggle(R.id.fix_button, R.layout.photoeditor_effects_fix); - - setEnabled(false); - } - - private void setupMenuToggle(int toggleId, final int effectsId) { - final View toggle = findViewById(toggleId); - toggle.setOnClickListener(new View.OnClickListener() { + effectsMenu = (EffectsMenu) findViewById(R.id.effects_menu); + effectsMenu.setOnToggleListener(new EffectsMenu.OnToggleListener() { @Override - public void onClick(View v) { - // Toggle off to exit effects gallery that is showing. Or toggle on to show effects - // gallery after exiting an active effect if applicable. - exit((toggle.isSelected() && (effectsGallery != null)) ? null : new Runnable() { + public boolean onToggle(boolean isSelected, final int effectsId) { + // Create and show effects-gallery only if the clicked toggle isn't selected or it's + // selected but showing an active effect instead of effects-gallery. Set the clicked + // toggle selected only when its effects-gallery will be created and shown. + boolean select = !isSelected || (effectsGallery == null); + exit(select ? new Runnable() { @Override public void run() { - toggle.setSelected(true); - showEffectsGallery(effectsId); + createEffectsGallery(effectsId); } - }); + } : null); + return select; } }); + + setEnabled(false); + } + + private void createEffectsGallery(int effectsId) { + // Inflate scrollable effects-gallery and desired effects into effects-bar. + effectsGallery = inflater.inflate(R.layout.photoeditor_effects_gallery, this, false); + ViewGroup scrollView = (ViewGroup) effectsGallery.findViewById(R.id.scroll_view); + ViewGroup effects = (ViewGroup) inflater.inflate(effectsId, scrollView, false); + for (int i = 0; i < effects.getChildCount(); i++) { + setupEffectListener((EffectAction) effects.getChildAt(i)); + } + scrollView.addView(effects); + scrollView.scrollTo(0, 0); + addView(effectsGallery, 0); } private void setupEffectListener(final EffectAction effect) { @@ -86,8 +95,8 @@ public class EffectsBar extends LinearLayout { exitEffectsGallery(); // Create effect tool panel first before the factory could create tools within. createEffectToolPanel(); - activeEffect.begin( - filterStack, new EffectToolFactory(effectToolPanel, inflater)); + activeEffect.begin(filterStack, + new EffectToolFactory(effectToolPanel, inflater)); } } @@ -105,23 +114,10 @@ public class EffectsBar extends LinearLayout { addView(effectToolPanel, 0); } - private void showEffectsGallery(int effectsId) { - // Inflate scrollable effects-gallery and desired effects into effects-bar. - effectsGallery = inflater.inflate(R.layout.photoeditor_effects_gallery, this, false); - ViewGroup scrollView = (ViewGroup) effectsGallery.findViewById(R.id.scroll_view); - ViewGroup effects = (ViewGroup) inflater.inflate(effectsId, scrollView, false); - for (int i = 0; i < effects.getChildCount(); i++) { - setupEffectListener((EffectAction) effects.getChildAt(i)); - } - scrollView.addView(effects); - scrollView.scrollTo(0, 0); - addView(effectsGallery, 0); - } - private boolean exitEffectsGallery() { if (effectsGallery != null) { if (activeEffect != null) { - // Detach the active effect from effects-gallery that could be recycled by gc. + // Detach the active effect to prevent it stopping effects-gallery from gc. ViewGroup scrollView = (ViewGroup) effectsGallery.findViewById(R.id.scroll_view); ((ViewGroup) scrollView.getChildAt(0)).removeView(activeEffect); } @@ -165,13 +161,7 @@ public class EffectsBar extends LinearLayout { */ public boolean exit(final Runnable runnableOnDone) { // Exit effects-menu selected states. - ViewGroup menu = (ViewGroup) findViewById(R.id.effects_menu); - for (int i = 0; i < menu.getChildCount(); i++) { - View toggle = menu.getChildAt(i); - if (toggle.isSelected()) { - toggle.setSelected(false); - } - } + effectsMenu.clearSelected(); if (exitActiveEffect(runnableOnDone)) { return true; |