private void changeVoltage(final boolean isPlus) { final int prefsIndex = mCategory.getPreferenceCount(); CustomPreference pref; String value; boolean isCurrent = false; for (int i = 0; i < prefsIndex; i++) { pref = (CustomPreference) mCategory.getPreference(i); if (pref != null) { if (isVdd) { if (isPlus) { pref.setCustomSummaryKeyPlus(25000); } else { pref.setCustomSummaryKeyMinus(25000); } } else { if (isPlus) { pref.setCustomSummaryKeyPlus(25); } else { pref.setCustomSummaryKeyMinus(25); } } value = pref.getKey(); if (value != null) { isCurrent = value.equals(mValues[i]); } } } if (isCurrent) { mButtonLayout.setVisibility(View.GONE); } else { mButtonLayout.setVisibility(View.VISIBLE); } }
@Override protected String doInBackground(String... params) { try { mNames = VoltageUtils.get().getUvValues(true); mValues = VoltageUtils.get().getUvValues(false); } catch (Exception exc) { Logger.e(this, "UV ERROR: " + exc.getMessage()); return "ERROR"; } Logger.v(this, "UV TABLE: " + buildTable(mValues)); String name; CustomPreference pref; final int length = mNames.length; for (int i = 0; i < length; i++) { final int j = i; name = mNames[i]; pref = new CustomPreference(getActivity()); pref.setTitle(name); pref.areMilliVolts(millivolts); if (isVdd) { pref.setSummary(mValues[i]); } else { pref.setSummary(mValues[i] + " mV"); } pref.setKey(mValues[i]); mCategory.addPreference(pref); pref.setOnPreferenceClickListener( new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference p) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final LinearLayout ll = new LinearLayout(getActivity()); ll.setLayoutParams( new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); final EditText et = new EditText(getActivity()); final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(40, 40, 40, 40); params.gravity = Gravity.CENTER; final String val = p.getKey(); et.setLayoutParams(params); et.setRawInputType(InputType.TYPE_CLASS_NUMBER); et.setGravity(Gravity.CENTER_HORIZONTAL); et.setText(val); ll.addView(et); builder.setView(ll); builder.setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (et.getText() != null) { if (isVdd) { final String value = p.getTitle() + " " + et.getText().toString(); Utils.writeValue(VoltageUtils.UV_TABLE_FILE, value); p.setSummary(et.getText().toString()); p.setKey(et.getText().toString()); mValues[j] = p.getKey(); } else { final String value = et.getText().toString(); p.setSummary(value + " mV"); p.setKey(value); mValues[j] = value; Utils.writeValue(VoltageUtils.UV_TABLE_FILE, buildTable(mValues)); } } } }); final AlertDialog dialog = builder.create(); dialog.show(); final Window window = dialog.getWindow(); window.setLayout(800, LayoutParams.WRAP_CONTENT); return true; } }); } return "Executed"; }