use of org.videolan.vlc.gui.view.ClickableSwitchPreference in project vlc-android by GeoffreyMetais.
the class PreferencesExtensions method createCheckboxes.
private void createCheckboxes() {
PackageManager pm = getActivity().getApplicationContext().getPackageManager();
for (int i = 0; i < mExtensions.size(); ++i) {
ExtensionListing extension = mExtensions.get(i);
ClickableSwitchPreference switchPreference = new ClickableSwitchPreference(preferenceScreen.getContext());
switchPreference.setTitle(extension.title());
switchPreference.setSummary(extension.description());
final String key = ExtensionsManager.EXTENSION_PREFIX + "_" + extension.componentName().getPackageName();
switchPreference.setKey(key);
int iconRes = extension.menuIcon();
Drawable extensionIcon = null;
if (iconRes != 0) {
try {
Resources res = pm.getResourcesForApplication(extension.componentName().getPackageName());
extensionIcon = res.getDrawable(extension.menuIcon());
} catch (PackageManager.NameNotFoundException e) {
}
}
if (extensionIcon != null)
switchPreference.setIcon(extensionIcon);
else
try {
switchPreference.setIcon(pm.getApplicationIcon(mExtensions.get(i).componentName().getPackageName()));
} catch (PackageManager.NameNotFoundException e) {
switchPreference.setIcon(R.drawable.icon);
}
final boolean checked = mSettings.getBoolean(key, false);
switchPreference.setChecked(checked);
preferenceScreen.addPreference(switchPreference);
switchPreference.setOnSwitchClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (((SwitchCompat) view).isChecked())
mSettings.edit().putBoolean(key, true).apply();
else
for (Map.Entry<String, ?> entry : mSettings.getAll().entrySet()) if (entry.getKey().startsWith(ExtensionsManager.EXTENSION_PREFIX + "_"))
mSettings.edit().putBoolean(entry.getKey(), false).apply();
}
});
count++;
}
if (count == 0) {
PreferenceCategory emptyCategory = new PreferenceCategory(preferenceScreen.getContext());
emptyCategory.setTitle(R.string.extensions_empty);
preferenceScreen.addPreference(emptyCategory);
}
}
use of org.videolan.vlc.gui.view.ClickableSwitchPreference in project vlc-android by videolan.
the class PreferencesExtensions method createCheckboxes.
private void createCheckboxes() {
PackageManager pm = getActivity().getApplicationContext().getPackageManager();
for (int i = 0; i < mExtensions.size(); ++i) {
ExtensionListing extension = mExtensions.get(i);
ClickableSwitchPreference switchPreference = new ClickableSwitchPreference(preferenceScreen.getContext());
switchPreference.setTitle(extension.title());
switchPreference.setSummary(extension.description());
final String key = ExtensionsManager.EXTENSION_PREFIX + "_" + extension.componentName().getPackageName();
switchPreference.setKey(key);
int iconRes = extension.menuIcon();
Drawable extensionIcon = null;
if (iconRes != 0) {
try {
Resources res = pm.getResourcesForApplication(extension.componentName().getPackageName());
extensionIcon = res.getDrawable(extension.menuIcon());
} catch (PackageManager.NameNotFoundException e) {
}
}
if (extensionIcon != null)
switchPreference.setIcon(extensionIcon);
else
try {
switchPreference.setIcon(pm.getApplicationIcon(mExtensions.get(i).componentName().getPackageName()));
} catch (PackageManager.NameNotFoundException e) {
switchPreference.setIcon(R.drawable.icon);
}
final boolean checked = mSettings.getBoolean(key, false);
switchPreference.setChecked(checked);
preferenceScreen.addPreference(switchPreference);
switchPreference.setOnSwitchClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (((SwitchCompat) view).isChecked())
mSettings.edit().putBoolean(key, true).apply();
else
for (Map.Entry<String, ?> entry : mSettings.getAll().entrySet()) if (entry.getKey().startsWith(ExtensionsManager.EXTENSION_PREFIX + "_"))
mSettings.edit().putBoolean(entry.getKey(), false).apply();
}
});
count++;
}
if (count == 0) {
PreferenceCategory emptyCategory = new PreferenceCategory(preferenceScreen.getContext());
emptyCategory.setTitle(R.string.extensions_empty);
preferenceScreen.addPreference(emptyCategory);
}
}
Aggregations