This commit is contained in:
Sergey Solovyev 2012-01-09 19:02:24 +04:00
parent 03081abb85
commit dfc9292f73
2 changed files with 34 additions and 3 deletions

View File

@ -21,6 +21,7 @@ import com.google.ads.AdRequest;
import com.google.ads.AdSize; import com.google.ads.AdSize;
import com.google.ads.AdView; import com.google.ads.AdView;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@ -153,5 +154,35 @@ public final class AndroidUtils {
return adView; return adView;
} }
public static <T> void processViewsOfType(@NotNull View view, @NotNull Class<T> clazz, @NotNull ViewProcessor<T> viewProcessor) {
processViewsOfType0(view, clazz, viewProcessor);
}
public static void processViews(@NotNull View view, @NotNull ViewProcessor<View> viewProcessor) {
processViewsOfType0(view, null, viewProcessor);
}
private static <T> void processViewsOfType0(@NotNull View view, @Nullable Class<T> clazz, @NotNull ViewProcessor<T> 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<V> {
void process(@NotNull V view);
}
} }

View File

@ -32,10 +32,10 @@ public class CalculatorPreferencesActivity extends PreferenceActivity implements
addPreferencesFromResource(R.xml.main_preferences); 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)) { if (!CalculatorApplication.isAdFree(this)) {
addFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { adFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
// check billing availability // check billing availability
@ -56,7 +56,7 @@ public class CalculatorPreferencesActivity extends PreferenceActivity implements
} }
}); });
} else { } else {
addFreePreference.setEnabled(false); adFreePreference.setEnabled(false);
} }
BillingController.registerObserver(this); BillingController.registerObserver(this);