From dfc9292f73d9c4e3b532b08227de4a928fc08b3c Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Mon, 9 Jan 2012 19:02:24 +0400 Subject: [PATCH] utils --- .../org/solovyev/android/AndroidUtils.java | 31 +++++++++++++++++++ .../CalculatorPreferencesActivity.java | 6 ++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/solovyev/android/AndroidUtils.java b/src/main/java/org/solovyev/android/AndroidUtils.java index f41582a9..94029dcf 100644 --- a/src/main/java/org/solovyev/android/AndroidUtils.java +++ b/src/main/java/org/solovyev/android/AndroidUtils.java @@ -21,6 +21,7 @@ import com.google.ads.AdRequest; import com.google.ads.AdSize; import com.google.ads.AdView; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -153,5 +154,35 @@ public final class AndroidUtils { return adView; } + public static void processViewsOfType(@NotNull View view, @NotNull Class clazz, @NotNull ViewProcessor viewProcessor) { + processViewsOfType0(view, clazz, viewProcessor); + } + + public static void processViews(@NotNull View view, @NotNull ViewProcessor viewProcessor) { + processViewsOfType0(view, null, viewProcessor); + } + + private static void processViewsOfType0(@NotNull View view, @Nullable Class clazz, @NotNull ViewProcessor viewProcessor) { + if (view instanceof ViewGroup) { + final ViewGroup viewGroup = (ViewGroup) view; + + if (clazz == null || ViewGroup.class.isAssignableFrom(clazz)) { + //noinspection unchecked + viewProcessor.process((T) viewGroup); + } + + for (int index = 0; index < viewGroup.getChildCount(); index++) { + processViewsOfType0(viewGroup.getChildAt(index), clazz, viewProcessor); + } + } else if (clazz == null || view.getClass().isAssignableFrom(clazz)) { + //noinspection unchecked + viewProcessor.process((T) view); + } + } + + public static interface ViewProcessor { + void process(@NotNull V view); + } + } diff --git a/src/main/java/org/solovyev/android/calculator/CalculatorPreferencesActivity.java b/src/main/java/org/solovyev/android/calculator/CalculatorPreferencesActivity.java index 434f52ad..a8c50f1f 100644 --- a/src/main/java/org/solovyev/android/calculator/CalculatorPreferencesActivity.java +++ b/src/main/java/org/solovyev/android/calculator/CalculatorPreferencesActivity.java @@ -32,10 +32,10 @@ public class CalculatorPreferencesActivity extends PreferenceActivity implements addPreferencesFromResource(R.xml.main_preferences); - final Preference addFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY); + final Preference adFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY); if (!CalculatorApplication.isAdFree(this)) { - addFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + adFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { // check billing availability @@ -56,7 +56,7 @@ public class CalculatorPreferencesActivity extends PreferenceActivity implements } }); } else { - addFreePreference.setEnabled(false); + adFreePreference.setEnabled(false); } BillingController.registerObserver(this);