utils
This commit is contained in:
parent
03081abb85
commit
dfc9292f73
@ -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 <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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user