use of android.support.v7.preference.Preference in project carat by amplab.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CaratApplication.setMain(this);
tracker = Tracker.getInstance();
// track user clicks (taps)
tracker.trackUser("caratstarted");
if (!CaratApplication.isInternetAvailable()) {
EnableInternetDialogFragment dialog = new EnableInternetDialogFragment();
dialog.show(getSupportFragmentManager(), "dialog");
}
/*
* Activity.getWindow.requestFeature() should get invoked only before
* setContentView(), otherwise it will cause an app crash The progress
* bar doesn't get displayed when there is no update in progress
*/
getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
// Log.d(TAG, "about to set the layout");
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
setTitleNormal();
// read and load the preferences specified in our xml preference file
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
// Log.d(TAG, "about to initialize fragments");
preInittializeFragments();
// Log.d(TAG, "done with fragment initialization");
/*
* Before using the field "fullVersion", first invoke setTitleNormal()
* or setFullVersion() to set this field
*/
mDrawerItems = getResources().getStringArray(R.array.drawer_items);
List<Item> items = new ArrayList<Item>();
// items.add(new NavDrawerListHeader("Main"));
items.add(new ListItem(mDrawerItems[0]));
items.add(new ListItem(mDrawerItems[1]));
items.add(new ListItem(mDrawerItems[2]));
items.add(new ListItem(mDrawerItems[3]));
items.add(new ListItem(mDrawerItems[4]));
items.add(new NavDrawerListHeader(""));
items.add(new ListItem(mDrawerItems[5]));
items.add(new ListItem(mDrawerItems[6]));
TextArrayAdapter adapter = new TextArrayAdapter(this, items);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
mDrawerList.setAdapter(adapter);
// mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mDrawerItems));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close) {
/* "close drawer" description for accessibility */
public void onDrawerClosed(View view) {
//getSupportActionBar().setTitle(mTitle);
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mTitle);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
// Enable ActionBar app icon to behave as action to toggle navigation drawer
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
if (savedInstanceState == null) {
selectItem(0);
}
setTitleNormal();
// Uncomment the following to enable listening on local port 8080:
/*
* try {
* HelloServer h = new HelloServer();
* } catch (IOException e) {
* e.printStackTrace();
* }
*/
}
use of android.support.v7.preference.Preference in project Shuttle by timusus.
the class SettingsFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().supportInvalidateOptionsMenu();
mTintManager = new SystemBarTintManager(getActivity());
if (getArguments() != null) {
mPrefResId = getArguments().getInt(PREF_RES_ID);
} else {
mPrefResId = R.xml.settings_headers;
}
// Load the preferences from an XML resource
addPreferencesFromResource(mPrefResId);
mPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
final Preference chooseTabsPreference = findPreference("pref_tab_chooser");
if (chooseTabsPreference != null) {
chooseTabsPreference.setOnPreferenceClickListener(preference -> {
RecyclerView recyclerView = (RecyclerView) LayoutInflater.from(getContext()).inflate(R.layout.dialog_tab_chooser, null);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
TabsAdapter tabsAdapter = new TabsAdapter(getContext());
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(tabsAdapter::moveItem, (fromPosition, toPosition) -> tabsAdapter.updatePreferences(), () -> {
}));
itemTouchHelper.attachToRecyclerView(recyclerView);
tabsAdapter.setListener(new TabsAdapter.TabListener() {
@Override
public void onItemClick(View v, int position, CategoryItem categoryItem) {
categoryItem.setChecked(!categoryItem.isChecked());
com.simplecity.amp_library.utils.AnalyticsManager.logTabVisibilityChanged(categoryItem.isChecked(), categoryItem.title);
tabsAdapter.notifyItemChanged(position);
tabsAdapter.updatePreferences();
}
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
itemTouchHelper.startDrag(viewHolder);
}
});
recyclerView.setAdapter(tabsAdapter);
DialogUtils.getBuilder(getContext()).title(R.string.pref_title_choose_tabs).customView(recyclerView, false).positiveText(R.string.button_done).onPositive((materialDialog, dialogAction) -> {
DialogUtils.createRestartDialog(getActivity());
materialDialog.dismiss();
}).show();
return true;
});
}
final Preference colorPickerPreference = findPreference("pref_theme_highlight_color");
if (colorPickerPreference != null) {
colorPickerPreference.setOnPreferenceClickListener(preference -> {
int selectedColor = mPrefs.getInt("pref_theme_highlight_color", -1);
DialogUtils.showColorPickerDialog(this, selectedColor, color -> mPrefs.edit().putInt("pref_theme_highlight_color", color).apply());
return true;
});
}
final Preference accentPickerPreference = findPreference("pref_theme_accent_color");
if (accentPickerPreference != null) {
accentPickerPreference.setOnPreferenceClickListener(preference -> {
int selectedColor = mPrefs.getInt("pref_theme_accent_color", -1);
DialogUtils.showColorPickerDialog(this, selectedColor, ColorPalette.getAccentColors(), ColorPalette.getAccentColorsSub(), color -> mPrefs.edit().putInt("pref_theme_accent_color", color).apply());
return true;
});
}
mListener = (sharedPreferences, key) -> {
if (key.equals("pref_theme_highlight_color") || key.equals("pref_theme_accent_color") || key.equals("pref_theme_white_accent")) {
ThemeUtils.setTheme(getActivity());
ThemeUtils.themeActionBar((SettingsActivity) getActivity());
ThemeUtils.themeStatusBar(getActivity(), mTintManager);
getListView().invalidate();
themeUIElements();
for (int i = 0, size = getListView().getChildCount(); i < size; i++) {
View view = getListView().getChildAt(i);
ThemeUtils.updateThemableViews(view);
}
}
if (key.equals("pref_theme_base") || key.equals("pref_default_page")) {
DialogUtils.createRestartDialog(getActivity());
}
};
final Preference restartPreference = findPreference("pref_restart");
if (restartPreference != null) {
restartPreference.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(getActivity(), MainActivity.class);
ComponentName componentNAme = intent.getComponent();
Intent mainIntent = IntentCompat.makeRestartActivityTask(componentNAme);
startActivity(mainIntent);
return true;
});
}
final CheckBoxPreference showLockscreenArtworkPreference = (CheckBoxPreference) findPreference(SettingsManager.KEY_SHOW_LOCKSCREEN_ARTWORK);
if (showLockscreenArtworkPreference != null) {
showLockscreenArtworkPreference.setOnPreferenceClickListener(preference -> {
MusicUtils.toggleLockscreenArtwork();
return false;
});
}
final Preference downloadArtworkPreference = findPreference("pref_download_artwork");
if (downloadArtworkPreference != null) {
downloadArtworkPreference.setOnPreferenceClickListener(preference -> {
DialogUtils.showDownloadWarningDialog(getActivity(), (materialDialog, dialogAction) -> {
Intent intent = new Intent(getContext(), ArtworkDownloadService.class);
ShuttleApplication.getInstance().startService(intent);
});
return true;
});
}
final Preference deleteArtworkPreference = findPreference("pref_delete_artwork");
if (deleteArtworkPreference != null) {
deleteArtworkPreference.setOnPreferenceClickListener(preference -> {
DialogUtils.getBuilder(getActivity()).title(getString(R.string.pref_title_delete_artwork)).icon(DrawableUtils.themeLightOrDark(getActivity(), getResources().getDrawable(R.drawable.ic_dialog_alert))).content(getString(R.string.delete_artwork_confirmation_dialog)).positiveText(getString(R.string.button_ok)).onPositive((materialDialog, dialogAction) -> {
Glide.get(getContext()).clearMemory();
ShuttleUtils.execute(new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Glide.get(getContext()).clearDiskCache();
return null;
}
});
}).negativeText(getString(R.string.cancel)).show();
return true;
});
}
final Preference downloadSimpleLastFmScrobbler = findPreference("pref_download_simple_lastfm_scrobbler");
if (downloadSimpleLastFmScrobbler != null) {
if (ShuttleUtils.isAmazonBuild()) {
PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("pref_key_simple_lastfm_scrobble_settings");
if (preferenceGroup != null) {
preferenceGroup.removePreference(downloadSimpleLastFmScrobbler);
}
} else {
downloadSimpleLastFmScrobbler.setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.adam.aslfms")));
}
}
final Preference about = findPreference("pref_about");
if (about != null) {
about.setOnPreferenceClickListener(preference -> {
View customView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_changelog, null);
WebView webView = (WebView) customView.findViewById(R.id.webView);
int themeType = ThemeUtils.getThemeType(getActivity());
webView.setBackgroundColor(getResources().getColor(android.R.color.transparent));
if (themeType == ThemeUtils.ThemeType.TYPE_LIGHT || themeType == ThemeUtils.ThemeType.TYPE_SOLID_LIGHT) {
webView.loadUrl("file:///android_asset/web/info.html");
} else {
webView.loadUrl("file:///android_asset/web/info_dark.html");
}
DialogUtils.getBuilder(getActivity()).title(R.string.pref_title_about).customView(customView, false).negativeText(R.string.close).show();
AnalyticsManager.logChangelogViewed();
return true;
});
}
final Preference upgrade = findPreference("pref_upgrade");
if (upgrade != null) {
if (ShuttleUtils.isUpgraded()) {
SettingsFragment.this.getPreferenceScreen().removePreference(upgrade);
}
upgrade.setOnPreferenceClickListener(preference -> {
DialogUtils.showUpgradeDialog(getActivity(), (materialDialog, dialogAction) -> {
if (ShuttleUtils.isAmazonBuild()) {
ShuttleUtils.openShuttleLink(getActivity(), "com.simplecity.amp_pro");
} else {
AnalyticsManager.logUpgrade(AnalyticsManager.UpgradeType.UPGRADE);
((SettingsActivity) getActivity()).purchasePremiumUpgrade();
}
});
return true;
});
}
final Preference viewBlacklist = findPreference("pref_blacklist_view");
if (viewBlacklist != null) {
viewBlacklist.setOnPreferenceClickListener(preference -> {
DialogUtils.showBlacklistDialog(getActivity());
return true;
});
}
final Preference viewWhitelist = findPreference("pref_whitelist_view");
if (viewWhitelist != null) {
viewWhitelist.setOnPreferenceClickListener(preference -> {
DialogUtils.showWhitelistDialog(getActivity());
return true;
});
}
final Preference clearBlacklist = findPreference("pref_blacklist_clear");
if (clearBlacklist != null) {
clearBlacklist.setOnPreferenceClickListener(preference -> {
BlacklistHelper.deleteAllSongs();
Toast.makeText(getActivity(), R.string.blacklist_deleted, Toast.LENGTH_SHORT).show();
return true;
});
}
final Preference clearWhitelist = findPreference("pref_whitelist_clear");
if (clearWhitelist != null) {
clearWhitelist.setOnPreferenceClickListener(preference -> {
WhitelistHelper.deleteAllFolders();
Toast.makeText(getActivity(), R.string.whitelist_deleted, Toast.LENGTH_SHORT).show();
return true;
});
}
final CheckBoxPreference ignoreEmbeddedArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_IGNORE_EMBEDDED_ARTWORK);
if (ignoreEmbeddedArtwork != null) {
ignoreEmbeddedArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
showArtworkPreferenceDialog();
return true;
});
}
final CheckBoxPreference ignoreFolderArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_IGNORE_FOLDER_ARTWORK);
if (ignoreFolderArtwork != null) {
ignoreFolderArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
showArtworkPreferenceDialog();
return true;
});
}
final CheckBoxPreference preferEmbeddedArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_PREFER_EMBEDDED_ARTWORK);
if (preferEmbeddedArtwork != null) {
preferEmbeddedArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
showArtworkPreferenceDialog();
return true;
});
}
final CheckBoxPreference ignoreMediaStoreArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_IGNORE_MEDIASTORE_ART);
if (ignoreMediaStoreArtwork != null) {
ignoreMediaStoreArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
showArtworkPreferenceDialog();
return true;
});
}
final CheckBoxPreference preferLastFmArtwork = (CheckBoxPreference) findPreference(SettingsManager.KEY_PREFER_LAST_FM);
if (preferLastFmArtwork != null) {
preferLastFmArtwork.setOnPreferenceChangeListener((preference, newValue) -> {
showArtworkPreferenceDialog();
return true;
});
}
final Preference restorePurchases = findPreference("pref_restore_purchases");
if (ShuttleUtils.isAmazonBuild() || ShuttleUtils.isUpgraded()) {
PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("support_group");
if (preferenceGroup != null) {
preferenceGroup.removePreference(restorePurchases);
}
} else if (restorePurchases != null) {
restorePurchases.setOnPreferenceClickListener(preference -> {
((SettingsActivity) getActivity()).restorePurchases();
return true;
});
}
final Preference versionPreference = findPreference("pref_version");
if (versionPreference != null) {
versionPreference.setSummary("Shuttle Music Player " + BuildConfig.VERSION_NAME + (ShuttleUtils.isUpgraded() ? " (Upgraded)" : " (Free)"));
}
final Preference faqPreference = findPreference("pref_faq");
if (faqPreference != null) {
faqPreference.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.shuttlemusicplayer.com/#faq"));
startActivity(intent);
return true;
});
}
final Preference gplusPreference = findPreference("pref_gplus");
if (gplusPreference != null) {
gplusPreference.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://plus.google.com/communities/112365043563095486408"));
startActivity(intent);
return true;
});
}
final Preference ratePreference = findPreference("pref_rate");
if (ratePreference != null) {
ratePreference.setOnPreferenceClickListener(preference -> {
final String appPackageName = getActivity().getPackageName();
ShuttleUtils.openShuttleLink(getActivity(), appPackageName);
SettingsManager.getInstance().setHasRated();
return true;
});
}
final CheckBoxPreference openOnClickPreference = (CheckBoxPreference) findPreference("pref_open_now_playing_on_click");
if (openOnClickPreference != null) {
if (!ShuttleUtils.isTablet()) {
PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("display_group");
if (preferenceGroup != null) {
preferenceGroup.removePreference(openOnClickPreference);
}
}
}
if (!ShuttleUtils.hasLollipop()) {
PreferenceScreen preferenceScreen = getPreferenceScreen();
if (preferenceScreen != null) {
Preference notificationPreference = preferenceScreen.findPreference("pref_category_notifications");
if (notificationPreference != null) {
preferenceScreen.removePreference(notificationPreference);
}
}
}
}
use of android.support.v7.preference.Preference in project NetGuard by M66B.
the class ActivityMain method onSharedPreferenceChanged.
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
if ("enabled".equals(name)) {
// Get enabled
boolean enabled = prefs.getBoolean(name, false);
// Display disabled warning
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
// Check switch state
SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
if (swEnabled.isChecked() != enabled)
swEnabled.setChecked(enabled);
} else if ("whitelist_wifi".equals(name) || "screen_on".equals(name) || "screen_wifi".equals(name) || "whitelist_other".equals(name) || "screen_other".equals(name) || "whitelist_roaming".equals(name) || "show_user".equals(name) || "show_system".equals(name) || "show_nointernet".equals(name) || "show_disabled".equals(name) || "sort".equals(name) || "imported".equals(name)) {
updateApplicationList(null);
final LinearLayout llWhitelist = (LinearLayout) findViewById(R.id.llWhitelist);
boolean screen_on = prefs.getBoolean("screen_on", true);
boolean whitelist_wifi = prefs.getBoolean("whitelist_wifi", false);
boolean whitelist_other = prefs.getBoolean("whitelist_other", false);
boolean hintWhitelist = prefs.getBoolean("hint_whitelist", true);
llWhitelist.setVisibility(!(whitelist_wifi || whitelist_other) && screen_on && hintWhitelist ? View.VISIBLE : View.GONE);
} else if ("manage_system".equals(name)) {
invalidateOptionsMenu();
updateApplicationList(null);
LinearLayout llSystem = (LinearLayout) findViewById(R.id.llSystem);
boolean system = prefs.getBoolean("manage_system", false);
boolean hint = prefs.getBoolean("hint_system", true);
llSystem.setVisibility(!system && hint ? View.VISIBLE : View.GONE);
} else if ("theme".equals(name) || "dark_theme".equals(name))
recreate();
}
use of android.support.v7.preference.Preference in project NetGuard by M66B.
the class ActivityLog method onSharedPreferenceChanged.
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
if ("log".equals(name)) {
// Get enabled
boolean log = prefs.getBoolean(name, false);
// Display disabled warning
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE);
// Check switch state
SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
if (swEnabled.isChecked() != log)
swEnabled.setChecked(log);
ServiceSinkhole.reload("changed " + name, ActivityLog.this);
}
}
use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ToggleFeaturePreferenceFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(getActivity());
setPreferenceScreen(preferenceScreen);
mSummaryPreference = new Preference(getPrefContext()) {
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
view.setDividerAllowedAbove(false);
view.setDividerAllowedBelow(false);
final TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
summaryView.setText(getSummary());
sendAccessibilityEvent(summaryView);
}
private void sendAccessibilityEvent(View view) {
// Since the view is still not attached we create, populate,
// and send the event directly since we do not know when it
// will be attached and posting commands is not as clean.
AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());
if (accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain();
event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
view.onInitializeAccessibilityEvent(event);
view.dispatchPopulateAccessibilityEvent(event);
accessibilityManager.sendAccessibilityEvent(event);
}
}
};
mSummaryPreference.setSelectable(false);
mSummaryPreference.setPersistent(false);
mSummaryPreference.setLayoutResource(R.layout.text_description_preference);
preferenceScreen.addPreference(mSummaryPreference);
}
Aggregations