From 0d21544a1af1b7a77a5990f1418c54d22a72b5d1 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Tue, 12 Jun 2012 23:28:58 +0200 Subject: Gallery2: Check privative effects Gallery2 has 2 effects (FaceTan and Facelift) from the privative gapps. If gapps is not present, Gallery2 gets into a FC when click on this effects. This patch checks if the permission "com.google.android.media.effects" exists and hide this 2 effects if permission not exists Patch 2: Use EffectFactory.isEffectSupported to detect if filters exists Patch 3: Make isPresent method from effect classes a static method Patch 4: Change actions classes for static calling to effects classes Change-Id: I8f6b59e57e504114835ab3283f65a72b4f6774a8 --- src/com/android/gallery3d/photoeditor/EffectsBar.java | 9 +++++++-- .../gallery3d/photoeditor/actions/EffectAction.java | 9 +++++++++ .../gallery3d/photoeditor/actions/FaceTanAction.java | 6 +++++- .../gallery3d/photoeditor/actions/FaceliftAction.java | 6 +++++- .../gallery3d/photoeditor/filters/FaceTanFilter.java | 15 ++++++++++++++- .../gallery3d/photoeditor/filters/FaceliftFilter.java | 14 +++++++++++++- 6 files changed, 53 insertions(+), 6 deletions(-) (limited to 'src/com/android/gallery3d/photoeditor') diff --git a/src/com/android/gallery3d/photoeditor/EffectsBar.java b/src/com/android/gallery3d/photoeditor/EffectsBar.java index 40754040c..1510c2f01 100644 --- a/src/com/android/gallery3d/photoeditor/EffectsBar.java +++ b/src/com/android/gallery3d/photoeditor/EffectsBar.java @@ -74,8 +74,13 @@ public class EffectsBar extends LinearLayout { 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)); + for (int i = effects.getChildCount()-1; i >= 0; i--) { + EffectAction effect = (EffectAction) effects.getChildAt(i); + if( !effect.isPresent() ){ + effects.removeViewAt(i); + continue; + } + setupEffectListener(effect); } scrollView.addView(effects); scrollView.scrollTo(0, 0); diff --git a/src/com/android/gallery3d/photoeditor/actions/EffectAction.java b/src/com/android/gallery3d/photoeditor/actions/EffectAction.java index 6c6a893e3..c8e5d7d59 100644 --- a/src/com/android/gallery3d/photoeditor/actions/EffectAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/EffectAction.java @@ -148,6 +148,15 @@ public abstract class EffectAction extends LinearLayout { */ protected abstract void doEnd(); + /** + * Checks if the action effect is present in the system. + * + * @return boolean true if an action effect is present in the system and can be loaded + */ + public boolean isPresent() { + return true; + } + /** * Done callback for executing top filter changes. */ diff --git a/src/com/android/gallery3d/photoeditor/actions/FaceTanAction.java b/src/com/android/gallery3d/photoeditor/actions/FaceTanAction.java index a82f33079..dd7df1899 100644 --- a/src/com/android/gallery3d/photoeditor/actions/FaceTanAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/FaceTanAction.java @@ -37,7 +37,6 @@ public class FaceTanAction extends EffectAction { @Override public void doBegin() { final FaceTanFilter filter = new FaceTanFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.GENERIC); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @@ -59,4 +58,9 @@ public class FaceTanAction extends EffectAction { public void doEnd() { scalePicker.setOnScaleChangeListener(null); } + + @Override + public boolean isPresent() { + return FaceTanFilter.isPresent(); + } } diff --git a/src/com/android/gallery3d/photoeditor/actions/FaceliftAction.java b/src/com/android/gallery3d/photoeditor/actions/FaceliftAction.java index 90d4e0c72..2cf71c0b0 100644 --- a/src/com/android/gallery3d/photoeditor/actions/FaceliftAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/FaceliftAction.java @@ -37,7 +37,6 @@ public class FaceliftAction extends EffectAction { @Override public void doBegin() { final FaceliftFilter filter = new FaceliftFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.GENERIC); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @@ -59,4 +58,9 @@ public class FaceliftAction extends EffectAction { public void doEnd() { scalePicker.setOnScaleChangeListener(null); } + + @Override + public boolean isPresent() { + return FaceliftFilter.isPresent(); + } } diff --git a/src/com/android/gallery3d/photoeditor/filters/FaceTanFilter.java b/src/com/android/gallery3d/photoeditor/filters/FaceTanFilter.java index c52bb8848..b7a1cf1c7 100644 --- a/src/com/android/gallery3d/photoeditor/filters/FaceTanFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/FaceTanFilter.java @@ -17,6 +17,7 @@ package com.android.gallery3d.photoeditor.filters; import android.media.effect.Effect; +import android.media.effect.EffectFactory; import com.android.gallery3d.photoeditor.Photo; @@ -27,10 +28,22 @@ public class FaceTanFilter extends AbstractScaleFilter { public static final Creator CREATOR = creatorOf(FaceTanFilter.class); + private static final String EFFECT_FACE_TANNING = "com.google.android.media.effect.effects.FaceTanningEffect"; + @Override public void process(Photo src, Photo dst) { - Effect effect = getEffect("com.google.android.media.effect.effects.FaceTanningEffect"); + Effect effect = getEffect(EFFECT_FACE_TANNING); effect.setParameter("blend", scale); effect.apply(src.texture(), src.width(), src.height(), dst.texture()); } + + /** + * Checks if the effect is present in the system. + * + * @return boolean true if an effect is present in the system and can be loaded + */ + public static boolean isPresent() { + return EffectFactory.isEffectSupported(EFFECT_FACE_TANNING); + } + } diff --git a/src/com/android/gallery3d/photoeditor/filters/FaceliftFilter.java b/src/com/android/gallery3d/photoeditor/filters/FaceliftFilter.java index c6ad84b80..3e4fad206 100644 --- a/src/com/android/gallery3d/photoeditor/filters/FaceliftFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/FaceliftFilter.java @@ -17,6 +17,7 @@ package com.android.gallery3d.photoeditor.filters; import android.media.effect.Effect; +import android.media.effect.EffectFactory; import com.android.gallery3d.photoeditor.Photo; @@ -27,10 +28,21 @@ public class FaceliftFilter extends AbstractScaleFilter { public static final Creator CREATOR = creatorOf(FaceliftFilter.class); + private static final String EFFECT_FACELIFT = "com.google.android.media.effect.effects.FaceliftEffect"; + @Override public void process(Photo src, Photo dst) { - Effect effect = getEffect("com.google.android.media.effect.effects.FaceliftEffect"); + Effect effect = getEffect(EFFECT_FACELIFT); effect.setParameter("blend", scale); effect.apply(src.texture(), src.width(), src.height(), dst.texture()); } + + /** + * Checks if the effect is present in the system. + * + * @return boolean true if an effect is present in the system and can be loaded + */ + public static boolean isPresent() { + return EffectFactory.isEffectSupported(EFFECT_FACELIFT); + } } -- cgit v1.2.3