private void createCustomUnitDialog() { AlertDialog.Builder builder = new AlertDialog. Builder(getActivity()); builder.setTitle("Create Custom Unit:"); builder.setNegativeButton(android.R.string.cancel, null); AlertDialog alert = builder.create(); alert.show(); }
/** * Helper function to build a dialog box that list overflow units not shown * on the screen. Dialog lists has a cancel button. * * @param title to display at top of dialog box * @param itemClickListener OnClickListener for when the user selects one of the * units in the dialog list */ private void createMoreUnitsDialog(CharSequence title, DialogInterface.OnClickListener itemClickListener) { Context context = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(title); builder.setItems(mUnitType.getUndisplayedUnitNames(mNumConvButtons), itemClickListener); builder.setNegativeButton(android.R.string.cancel, null); AlertDialog alert = builder.create(); alert.show(); }
/** * Helper function to build a list dialog box that has a search function * Dialog lists has a cancel button. * * @param hint hint that displays in the EditText search box * @param itemClickListener OnClickListener for when the user selects one * of the units in the dialog list */ private void createSearchDialog(CharSequence hint, AdapterView.OnItemClickListener itemClickListener) { Context context = getActivity(); mSearchDialogBuilder = new UnitSearchDialogBuilder(mUnitType); CalcActivity ca = (CalcActivity) getActivity(); //TODO not sure if the idleResource should be accessed this way... mSearchDialogBuilder.buildDialog(context, hint, ca.getIdlingResource(), itemClickListener); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int pos = getArguments().getInt(EXTRA_UNIT_TYPE_POS); mUnitType = Calculator.getCalculator(getActivity()).getUnitType(pos); mUnitType.setDynamicUnitCallback(this); }
UnitHistCurrency uhc = (UnitHistCurrency) mUnitType.getUnit(buttonPos); AlertDialog.Builder builder = new AlertDialog. Builder(getActivity()); builder.setTitle(getText(R.string.historical_dialog_title)); builder.setSingleChoiceItems(uhc.getPossibleYearsReversed(), uhc.getReversedYearIndex(),
private void tryConvert(int buttonPos) { //Clear color and arrows from previously selected convert buttons clearButtonSelection(); //Set select unit, also this will potentially call convert if we already have a selected unit boolean requestConvert = mUnitType.selectUnit(buttonPos); Calculator calc = Calculator.getCalculator(getActivity()); //unit previously selected, we pressed another, do a convert if (requestConvert){ calc.convertFromTo(mUnitType.getPrevUnit(), mUnitType.getCurrUnit()); clearButtonSelection(); } //unit not previously selected, now select one else if (mUnitType.isUnitSelected()){ // clear out solved flag calc.setSolved(false); //if expression was blank, add a highlighted "1" if (calc.isExpressionEmpty()){ //add in a 1 for user's convenience calc.parseKeyPressed("1"); //highlight it calc.setSelection(0, calc.toString().length()); } colorSelectedButton(); } //always update screen to add/remove unit from expression mCallback.updateScreen(true); }