List of usage examples for android.preference PreferenceCategory setKey
public void setKey(String key)
From source file:com.probam.updater.activity.GooActivity.java
@SuppressWarnings("deprecation") @Override/*from w w w. ja v a 2s . c om*/ protected void onCreate(Bundle savedInstanceState) { boolean useDarkTheme = ManagerFactory.getPreferencesManager(this).isDarkTheme(); setTheme(useDarkTheme ? R.style.DarkTheme : R.style.AppTheme); super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.empty_pref_screen); PreferenceScreen pScreen = getPreferenceScreen(); mInfos = new HashMap<String, PackageInfo>(); if (CURRENT_NAVIGATION == null) { Preference preference = null; preference = new Preference(this); preference.getExtras().putBoolean("BROWSING_ALL", false); preference.getExtras().putBoolean("FOLDER", true); preference.getExtras().putString("PATH", "/devs"); preference.setKey(Constants.GOO_SEARCH_URL + "/devs&ro_board=" + mDevice); preference.setTitle(R.string.goo_browse_all_compatible); pScreen.addPreference(preference); preference = new Preference(this); preference.getExtras().putBoolean("BROWSING_ALL", true); preference.getExtras().putBoolean("FOLDER", true); preference.getExtras().putString("PATH", "/devs"); preference.setKey(Constants.GOO_SEARCH_URL + "/devs"); preference.setTitle(R.string.goo_browse_all); pScreen.addPreference(preference); preference = new Preference(this); preference.getExtras().putBoolean("BROWSING_ALL", false); preference.getExtras().putBoolean("FOLDER", false); preference.getExtras().putString("PATH", ""); preference.setKey("watchlist"); preference.setTitle(R.string.goo_browse_watchlist); pScreen.addPreference(preference); } else { if ("watchlist".equals(CURRENT_FOLDER)) { PreferenceCategory category = new PreferenceCategory(this); category.setKey("category"); category.setTitle( getResources().getString(R.string.goo_category_title, new Object[] { CURRENT_FOLDER })); pScreen.addPreference(category); refreshWatchlist(); } else { PreferenceCategory category = new PreferenceCategory(this); category.setTitle( getResources().getString(R.string.goo_category_title, new Object[] { CURRENT_FOLDER })); pScreen.addPreference(category); try { JSONObject object = (JSONObject) new JSONTokener(CURRENT_NAVIGATION).nextValue(); JSONArray list = object.getJSONArray("list"); for (int i = 0; i < list.length(); i++) { JSONObject result = list.getJSONObject(i); String fileName = result.optString("filename"); if (fileName != null && !"".equals(fileName.trim())) { String path = result.optString("path"); if (!BROWSING_ALL && !mDevice.equals(result.optString("ro_board"))) { continue; } GooPackage info = new GooPackage(result, -1); mInfos.put(path, info); Preference preference = new Preference(this); preference.getExtras().putBoolean("FOLDER", false); preference.setKey(path); preference.setTitle(fileName); preference.setSummary(path); category.addPreference(preference); } else { String folder = result.optString("folder"); String folderName = folder.substring(folder.lastIndexOf("/") + 1); Preference preference = new FolderPreference(this, folder, false); preference.getExtras().putBoolean("BROWSING_ALL", BROWSING_ALL); preference.getExtras().putBoolean("FOLDER", true); preference.getExtras().putString("PATH", folder); if (!BROWSING_ALL) { preference.setKey(Constants.GOO_SEARCH_URL + folder + "&ro_board=" + mDevice); } else { preference.setKey(Constants.GOO_SEARCH_URL + folder); } preference.setTitle(folderName); preference.setSummary(folder); category.addPreference(preference); } } } catch (Exception ex) { ex.printStackTrace(); Toast.makeText(this, R.string.goo_browse_error, Toast.LENGTH_LONG).show(); } } } if (DIALOG != null) DIALOG.dismiss(); DIALOG = null; ListView listView = getListView(); listView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { ListView listView = (ListView) parent; ListAdapter listAdapter = listView.getAdapter(); Object obj = listAdapter.getItem(position); if (obj != null && obj instanceof View.OnLongClickListener) { View.OnLongClickListener longListener = (View.OnLongClickListener) obj; return longListener.onLongClick(view); } return false; } }); }
From source file:com.aokp.romcontrol.github.tasks.DisplayProjectsListTask.java
private void addPropertiesToPreference(PreferenceCategory mProject, JSONObject projectsObject) { try {/*ww w.j a v a2 s .c o m*/ // extract info about each project final String projectName = projectsObject.getString("name"); String projectDescription = projectsObject.getString("description"); int githubProjectId = projectsObject.getInt("id"); // apply info to our preference screen mProject.setKey(projectName); if (projectDescription.contains("") || projectDescription == null) { mProject.setTitle(projectName); mProject.setSummary(projectDescription); } else { mProject.setTitle(projectDescription); mProject.setSummary(projectName); } mProject.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference p) { FragmentTransaction transaction = mFragmentManager.beginTransaction(); CommitsFragment commitFragment = new CommitsFragment(mAlertDialog, projectName); transaction.addToBackStack(null); transaction.replace(mId, commitFragment, projectName); transaction.commit(); return true; } }); } catch (JSONException badJsonRequest) { Log.e(TAG, "failed to parse required info about project", badJsonRequest); } }