/** * Creates a string that includes the preference name, layout id and widget layout id. If a * particular preference type uses 2 different resources, they will be treated as different view * types. */ private PreferenceLayout createPreferenceLayout(Preference preference, PreferenceLayout in) { PreferenceLayout pl = in != null ? in : new PreferenceLayout(); pl.name = preference.getClass().getName(); pl.resId = preference.getLayoutResource(); pl.widgetResId = preference.getWidgetLayoutResource(); return pl; }
private void syncMyPreferences() { synchronized (this) { if (mIsSyncing) { return; } mIsSyncing = true; } List<Preference> newPreferenceList = new ArrayList<>(mPreferenceListInternal.size()); flattenPreferenceGroup(newPreferenceList, mPreferenceGroup); mPreferenceListInternal = newPreferenceList; mPreferenceList = new ArrayList<>(mPreferenceListInternal.size()); // Copy only the visible preferences to the active list for (final Preference preference : mPreferenceListInternal) { if (preference.isVisible()) { mPreferenceList.add(preference); } } notifyDataSetChanged(); synchronized (this) { mIsSyncing = false; notifyAll(); } }
protected void updatePreference() throws Exception { try { timerProcesses.setDelay(preference.getProcessUpdateInterval() * 1000); timerResources.setDelay(Preference.getResourceUpdateinterval() * 1000); timerFileSystems.setDelay(preference.getFileSystemsUpdateInterval() * 1000); panelProcesses.setPreference(preference); panelResources.setPreference(preference); panelFileSystems.setPreference(preference); if (sshSession.isConnected()) { FileSystemInfo fileSystemInfo = FileSystemInfo.factory(sshSession); panelFileSystems.display(fileSystemInfo); ProcessInfo processinfo = ProcessInfo.factory(sshSession, sshUserInfo); panelProcesses.display(processinfo); } setProcessMenuItemsEnabled(); repaint(); } catch (Exception e) { e.printStackTrace(); throw e; } }
@Override public void onPreferenceVisibilityChange(Preference preference) { if (preference.isVisible()) { // The preference has become visible, we need to add it in the correct location. // Index (inferred) in mPreferenceList of the item preceding the newly visible pref int previousVisibleIndex = -1; for (final Preference pref : mPreferenceListInternal) { if (preference.equals(pref)) { break; } if (pref.isVisible()) { previousVisibleIndex++; } } // Insert this preference into the active list just after the previous visible entry mPreferenceList.add(previousVisibleIndex + 1, preference); notifyItemInserted(previousVisibleIndex + 1); } else { // The preference has become invisibile. Find it in the list and remove it. int removalIndex; final int listSize = mPreferenceList.size(); for (removalIndex = 0; removalIndex < listSize; removalIndex++) { if (preference.equals(mPreferenceList.get(removalIndex))) { break; } } mPreferenceList.remove(removalIndex); notifyItemRemoved(removalIndex); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getActivity(); mPreferences = PreferenceManager.getDefaultSharedPreferences(context); mPreferences.registerOnSharedPreferenceChangeListener(this); addPreferencesFromResource(R.layout.tools); mResidualFiles = findPreference(RESIDUAL_FILES); mOptimDB = findPreference(PREF_OPTIM_DB); long mStartTime = mPreferences.getLong(RESIDUAL_FILES, 0); mResidualFiles.setSummary(""); if (mStartTime > 0) mResidualFiles.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime)); mStartTime = mPreferences.getLong(PREF_OPTIM_DB, 0); mOptimDB.setSummary(""); if (mStartTime > 0) mOptimDB.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime)); if (Helpers.binExist("dd").equals(NOT_FOUND) || NO_FLASH) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("category_flash_img"); getPreferenceScreen().removePreference(hideCat); } if (Helpers.binExist("pm").equals(NOT_FOUND)) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("category_freezer"); getPreferenceScreen().removePreference(hideCat); } setRetainInstance(true); setHasOptionsMenu(true); }
public boolean isBetterThan(Solution s1, Solution s2) { // s1 e' migliore di s2???? int i = 1; boolean found = false, result = false; for (i = 0; !found && i < s1.getValue().length(); i++) { if ((s1.getValue()).charAt(i) != (s2.getValue()).charAt(i)) found = true; } i--; // System.out.println("cambia in pos: "+i); Vertex v = cpnet.getAdjList().get(i); if (v.getParents().isEmpty()) { result = (v.getPreferences().get(0).getIsAffirmedValue()) ? s1.getValue().charAt(i) == '1' : s1.getValue().charAt(i) == '0'; } else { System.out.println( "----------------" + s1.getValue() + "e meglio di " + s2.getValue() + "????"); // controlla preferenza padre String parentsPref = ""; // System.out.println("i parents di " + v.getID() + "sono: "); // for(Integer ii : v.getParents()) System.out.println(ii.toString()); // for(int k = 1; k < s1.getValue().length(); k++){ // System.out.println("guardo se " + cpnet.getAdjList().get(k).getID().toString() + " e // parent"); // if(v.getParents().contains(cpnet.getAdjList().get(k).getID())){ // parentsPref += s1.getValue().charAt(k); // System.out.println("new parent pref " + parentsPref); // } // } for (Integer k : v.getParents()) { // System.out.println("parent "+k); parentsPref += s1.getValue().charAt(k); } System.out.println("per " + v.getID() + " ottengo parentPref=" + parentsPref); for (Preference p : v.getPreferences()) { // System.out.println("preference considerata: " + p.toString()); if (p.getBinaryValue() == ListUtils.fromBinToInt(parentsPref)) { // System.out.println(p.getBinaryValue() + " e' uguale a " + // ListUtils.fromBinToInt(parentsPref)); System.out.println(p.toString()); result = (p.getIsAffirmedValue()) ? s1.getValue().charAt(i) == '1' : s1.getValue().charAt(i) == '0'; // System.out.println("trovata e i="+i); // System.out.println(s1.getValue().charAt(i) == '1'); // System.out.println(s1.getValue().charAt(i) == '0'); System.out.println(result); } } } // System.out.println(result); return result; }
private Preference cursorToPref(Cursor cursor) { Preference pref = new Preference(); pref.setId(cursor.getLong(0)); pref.setAppName(cursor.getString(1)); pref.setIsActive(cursor.getInt(2)); pref.setPrefValue(cursor.getString(3)); return pref; }
@Override protected void onRestoreInstanceState(Parcelable state) { if (state == null || !state.getClass().equals(SavedState.class)) { super.onRestoreInstanceState(state); return; } SavedState myState = (SavedState) state; super.onRestoreInstanceState(myState.getSuperState()); setChecked(myState.checked); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); File speech = new File(Config.SPEECH_PATH.concat("/A")); if (speech.exists() == false) { Preference pSpeech = findPreference("auto_speech"); pSpeech.setEnabled(false); } }
@Override protected void onRestoreInstanceState(Parcelable state) { if (!state.getClass().equals(SavedState.class)) { super.onRestoreInstanceState(state); return; } SavedState myState = (SavedState) state; super.onRestoreInstanceState(myState.getSuperState()); mProgress = myState.progress; mMax = myState.max; notifyChanged(); }
/** * onCreateView * * <p>handles the special case of the serverport entry which is an int.... */ @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); // prefs.registerOnSharedPreferenceChangeListener(this); for (String key : prefs.getAll().keySet()) { Preference pref = findPreference(key); if (pref == null) continue; if (key.equals("serverport")) pref.setSummary("" + prefs.getInt(key, 0)); else pref.setSummary(prefs.getString(key, key)); } return super.onCreateView(inflater, container, savedInstanceState); }
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(RESIDUAL_FILES)) { mResidualFiles.setSummary(""); final long mStartTime = sharedPreferences.getLong(key, 0); if (mStartTime > 0) mResidualFiles.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime)); } else if (key.equals(PREF_OPTIM_DB)) { mOptimDB.setSummary(""); final long mStartTime = sharedPreferences.getLong(key, 0); if (mStartTime > 0) mOptimDB.setSummary(DateUtils.getRelativeTimeSpanString(mStartTime)); } }
/** * onSharedPreferenceChanged not needed in my code, but still in case i have one listpreference, * its takes the selected entry to create the summary (planned when/if i add background images to * the buttons... */ @Override public void onSharedPreferenceChanged(SharedPreferences sharedPref, String key) { Preference pref = findPreference(key); // Log.d(TAG, "preference change for " + key + " " + pref.getTitle()); // pref.getTitle(); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummary(listPref.getEntry()); } else pref.setSummary(sharedPref.getString(key, key)); // MainActivity mainAct = (MainActivity) getContext(); // if(mainAct != null) mainAct.onSharedPreferenceChanged(sharedPref,key); }
public boolean checkPrefStatus(String appName) { Cursor cursor = database.query( "preferences", prefColumns, "appName = '" + appName + "'", null, null, null, null); cursor.moveToFirst(); Preference selPref = cursorToPref(cursor); if (selPref.isPrefActive() == 1) { cursor.close(); return true; } else { cursor.close(); return false; } }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { String prefName = preference.getKey(); if (prefName != null && prefName.equals("privacy.masterpassword.enabled")) { showDialog( (Boolean) newValue ? DIALOG_CREATE_MASTER_PASSWORD : DIALOG_REMOVE_MASTER_PASSWORD); return false; } else if (prefName != null && prefName.equals("browser.menu.showCharacterEncoding")) { setCharEncodingState(((String) newValue).equals("true")); } setPreference(prefName, newValue); if (preference instanceof ListPreference) { // We need to find the entry for the new value int newIndex = ((ListPreference) preference).findIndexOfValue((String) newValue); CharSequence newEntry = ((ListPreference) preference).getEntries()[newIndex]; ((ListPreference) preference).setSummary(newEntry); } else if (preference instanceof LinkPreference) { finish(); } else if (preference instanceof FontSizePreference) { final FontSizePreference fontSizePref = (FontSizePreference) preference; fontSizePref.setSummary(fontSizePref.getSavedFontSizeName()); } return true; }
private void bind(PreferenceGroup group) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); for (int i = 0; i < group.getPreferenceCount(); i++) { Preference p = group.getPreference(i); if (p instanceof PreferenceGroup) { bind((PreferenceGroup) p); } else { if (p instanceof CheckBoxPreference) {; } else { Object val = sp.getAll().get(p.getKey()); p.setSummary(val == null ? "" : ("" + val)); p.setOnPreferenceChangeListener(this); } } } }
/** * For each list dialog, we display the value selected in the "summary" text. When a new value is * selected from the list dialog, update the summary to the selected entry. */ public boolean onPreferenceChange(Preference preference, Object newValue) { ListPreference list = (ListPreference) preference; int index = list.findIndexOfValue((String) newValue); CharSequence entry = list.getEntries()[index]; preference.setSummary(entry); return true; }
@Override protected void onAttachedToHierarchy(PreferenceManager preferenceManager) { super.onAttachedToHierarchy(preferenceManager); preferenceManager.registerOnActivityResultListener(this); mRequestCode = preferenceManager.getNextRequestCode(); }
@Override public void uncaughtException(Thread thread, Throwable ex) { try { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); ex.printStackTrace(printWriter); String errorReport = String.format( "[%s]\nAndroidVersion=%s\nIMEI=%s\nID=%s\n%s", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()), VERSION.RELEASE, getIMEI(), Preference.getUsername(mAppContext), result.toString()); Log.e(LOGTAG, errorReport); File logFile = new File(mAppContext.getFilesDir(), LOG_FILE); FileWriter fw = new FileWriter(logFile, true); fw.write(errorReport); fw.flush(); fw.close(); } catch (Exception e) { e.printStackTrace(); } finally { android.os.Process.killProcess(android.os.Process.myPid()); } }
@Override public boolean onPreferenceChange(Preference p, Object newValue) { if (p instanceof CheckBoxPreference) {; } else { p.setSummary("" + newValue); } return true; }
/** {@inheritDoc} */ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (preference.getFragment() != null && getActivity() instanceof OnPreferenceStartFragmentCallback) { return ((OnPreferenceStartFragmentCallback) getActivity()) .onPreferenceStartFragment(this, preference); } return false; }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Preference annotation = method.getAnnotation(Preference.class); String key = annotation.value(); String defaultString = annotation.defaultString(); boolean defaultBoolean = annotation.defaultBoolean(); int defaultInt = annotation.defaultInt(); long defaultLong = annotation.defaultLong(); float defaultFloat = annotation.defaultFloat(); if (method.getReturnType().equals(StringEntry.class)) { return new StringEntry(preferences, key, defaultString); } else if (method.getReturnType().equals(FloatEntry.class)) { return new FloatEntry(preferences, key, defaultFloat); } else if (method.getReturnType().equals(LongEntry.class)) { return new LongEntry(preferences, key, defaultLong); } else if (method.getReturnType().equals(IntEntry.class)) { return new IntEntry(preferences, key, defaultInt); } else if (method.getReturnType().equals(BooleanEntry.class)) { return new BooleanEntry(preferences, key, defaultBoolean); } else if (method.getReturnType().equals(ObjectEntry.class)) { if (method.getGenericReturnType() instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) method.getGenericReturnType(); Class<?> type = (Class) parameterizedType.getActualTypeArguments()[0]; return new ObjectEntry<>(preferences, key, gson, type); } throw new RuntimeException("ObjectEntries must have a parameter"); } else { return null; } }
@Override protected void onBindView(View view) { super.onBindView(view); SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekbar); seekBar.setOnSeekBarChangeListener(this); seekBar.setMax(mMax); seekBar.setProgress(mProgress); seekBar.setEnabled(isEnabled()); }
public GrowthPush initialize( Context context, int applicationId, String secret, Environment environment, boolean debug) { if (this.context != null) return this; this.context = context; this.applicationId = applicationId; this.secret = secret; this.environment = environment; this.logger.setDebug(debug); Preference.getInstance().setContext(context); client = Preference.getInstance().fetchClient(); if (client != null && client.getApplicationId() != applicationId) this.clearClient(); return this; }
@Override protected void onClick() { super.onClick(); boolean newValue = !isChecked(); mSendClickAccessibilityEvent = true; if (!callChangeListener(newValue)) { return; } setChecked(newValue); }
/** * Recursive method used to descend down the xml hierarchy and instantiate items, instantiate * their children, and then call onFinishInflate(). */ private void rInflate(XmlPullParser parser, Preference parent, final AttributeSet attrs) throws XmlPullParserException, IOException { final int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } final String name = parser.getName(); if (INTENT_TAG_NAME.equals(name)) { final Intent intent; try { intent = Intent.parseIntent(getContext().getResources(), parser, attrs); } catch (IOException e) { XmlPullParserException ex = new XmlPullParserException("Error parsing preference"); ex.initCause(e); throw ex; } parent.setIntent(intent); } else if (EXTRA_TAG_NAME.equals(name)) { getContext().getResources().parseBundleExtra(EXTRA_TAG_NAME, attrs, parent.getExtras()); try { skipCurrentTag(parser); } catch (IOException e) { XmlPullParserException ex = new XmlPullParserException("Error parsing preference"); ex.initCause(e); throw ex; } } else { final Preference item = createItemFromTag(name, attrs); ((PreferenceGroup) parent).addItemFromInflater(item); rInflate(parser, item, attrs); } } }
// create a new ImageView for each item referenced by the Adapter public View getView(int position, View convertView, ViewGroup parent) { // ImageView imageView; Button tempBut; int multiple; String spinnerarray[]; spinnerarray = new String[4]; spinnerarray[0] = "1x"; spinnerarray[1] = "2x"; spinnerarray[2] = "3x"; spinnerarray[3] = "5x"; if (convertView == null) { // if it's not recycled, initialize some attributes tempBut = new Button(mContext); tempBut.setLayoutParams( new GridView.LayoutParams(DigitDexterityActivity.bsize, DigitDexterityActivity.bsize)); tempBut.setOnClickListener(mOnButtonClick); tempBut.setPadding(8, 8, 8, 8); } else { tempBut = (Button) convertView; } tempBut.setId(1000 + DigitDexterityActivity.location[position]); multiple = spinnerarray[((int) Preference.getMultiples(mContext).charAt(0)) - 48].charAt(0) - 48; if (DigitDexterityActivity.butenable[DigitDexterityActivity.location[position]] == 0) { tempBut.setEnabled(false); } else { tempBut.setEnabled(true); } if (Preference.getRoman(mContext)) { tempBut.setText( DigitDexterityActivity.romans[ (DigitDexterityActivity.location[position] + 1) * multiple]); } else { tempBut.setText(Integer.toString((DigitDexterityActivity.location[position] + 1) * multiple)); } tempBut.setTypeface(null, Typeface.BOLD); tempBut.setTextSize(20); return tempBut; }
/** * Create the "Select Instruments For Each Track " lists. The list of possible instruments is in * MidiFile.java. */ private void createInstrumentPrefs(PreferenceScreen root) { PreferenceCategory selectInstrTitle = new PreferenceCategory(this); selectInstrTitle.setTitle(R.string.select_instruments_per_track); root.addPreference(selectInstrTitle); selectInstruments = new ListPreference[options.tracks.length]; for (int i = 0; i < options.instruments.length; i++) { selectInstruments[i] = new ListPreference(this); selectInstruments[i].setOnPreferenceChangeListener(this); selectInstruments[i].setEntries(MidiFile.Instruments); selectInstruments[i].setEntryValues(MidiFile.Instruments); selectInstruments[i].setTitle("Track " + i); selectInstruments[i].setValueIndex(options.instruments[i]); selectInstruments[i].setSummary(selectInstruments[i].getEntry()); root.addPreference(selectInstruments[i]); } setAllToPiano = new Preference(this); setAllToPiano.setTitle(R.string.set_all_to_piano); setAllToPiano.setOnPreferenceClickListener(this); root.addPreference(setAllToPiano); }
private void handleField(Field field) { Annotation[] annotations = field.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation.annotationType().isAssignableFrom(Preference.class)) { Preference preferenceAnnotation = (Preference) annotation; if (!preferenceAnnotation.enabled()) { return; } if (!preferenceAnnotation.name().isEmpty()) { mFieldsPreferencesMap.put(preferenceAnnotation.name(), field); return; } } } mFieldsPreferencesMap.put(field.getName(), field); }
private void flattenPreferenceGroup(List<Preference> preferences, PreferenceGroup group) { group.sortPreferences(); final int groupSize = group.getPreferenceCount(); for (int i = 0; i < groupSize; i++) { final Preference preference = group.getPreference(i); preferences.add(preference); addPreferenceClassName(preference); if (preference instanceof PreferenceGroup) { final PreferenceGroup preferenceAsGroup = (PreferenceGroup) preference; if (preferenceAsGroup.isOnSameScreenAsChildren()) { flattenPreferenceGroup(preferences, preferenceAsGroup); } } preference.setOnPreferenceChangeInternalListener(this); } }