@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.measure_settings, container, false); getDialog().setTitle(R.string.action_measure_unit); metric = (RadioButton) v.findViewById(R.id.metric); british = (RadioButton) v.findViewById(R.id.british); measure_unit = (RadioGroup) v.findViewById(R.id.measure_unit); save = (Button) v.findViewById(R.id.settingdialog_save); cancel = (Button) v.findViewById(R.id.settingdialog_cancel); if (prefEditor.getMeasureUnit()) british.toggle(); else metric.toggle(); save.setOnClickListener( new View.OnClickListener() { @Override public void onClick(final View v) { if (measure_unit.getCheckedRadioButtonId() == R.id.metric) prefEditor.saveMeasureUnit(false); else prefEditor.saveMeasureUnit(true); dismiss(); } }); cancel.setOnClickListener( new View.OnClickListener() { @Override public void onClick(final View v) { dismiss(); } }); return v; }
public GraphView.GraphViewData[] initWeightData(List<ItemModel> itemDataList) { GraphView.GraphViewData[] vdata = new GraphView.GraphViewData[itemDataList.size()]; for (int i = 0; i < itemDataList.size(); i++) { String s = itemDataList.get(i).getQuantity(); double weight = 0; String re1 = "(\\d{1,3})"; // Integer Number 1 String re2 = "(.*?)"; // Non-greedy match on filler String re3 = "([a-z]{2,})"; // Variable Name 1 String re4 = "(.*?)"; // Non-greedy match on filler String re5 = "(\\d{1,3})"; // Integer Number 1 String re6 = "(.*?)"; // Non-greedy match on filler String re7 = "(([a-z]{1,}))"; // Variable Name 1*/ Pattern p = Pattern.compile( re1 + re2 + re3 + re4 + re5 + re6 + re7, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); Matcher m = p.matcher(s); if (m.find()) { String val_1 = m.group(1); String empty1 = m.group(2); String txt1 = m.group(3); String empty2 = m.group(4); String val_2 = m.group(5); String empty3 = m.group(6); String txt2 = m.group(7); if (prefEditor.getMeasureUnit()) { // if current unit is british if (m.group(3).startsWith("kg")) weight = (Integer.valueOf(val_1) * 1000 + Integer.valueOf(val_2)) * 0.002205F; // 1g=0.002205ft if (m.group(3).startsWith("lb")) weight = Integer.valueOf(val_1) + (Integer.valueOf(val_2) * 0.0625F); // 1oz=0.0625lb } else { // current unit is metric if (m.group(3).startsWith("kg")) weight = (Integer.valueOf(val_1) * 1000 + Integer.valueOf(val_2)) * 0.001; if (m.group(3).startsWith("lb")) weight = ((Integer.valueOf(val_1)) * 16 + Integer.valueOf(val_2)) * 0.02835F; // 1oz=0.02835kg } weight = (int) (weight * 100); weight = weight / 100; } vdata[i] = new GraphView.GraphViewData(i, weight); } return vdata; }