List of usage examples for android.widget RadioButton isChecked
@ViewDebug.ExportedProperty @Override public boolean isChecked()
From source file:com.example.android.aerotoolbox.MainActivity.java
public void AtmosphereCalculate(View view) { int labels[] = { R.id.atmosphere_h_output, R.id.atmosphere_P_output, R.id.atmosphere_T_output, R.id.atmosphere_rho_output, R.id.atmosphere_mu_output, R.id.atmosphere_a_output }; int labelsm[] = { R.id.atmosphere_h_outputm, R.id.atmosphere_P_outputm, R.id.atmosphere_T_outputm, R.id.atmosphere_rho_outputm, R.id.atmosphere_mu_outputm, R.id.atmosphere_a_outputm }; int labelsr[] = { R.id.atmosphere_P_ratio_output, R.id.atmosphere_T_ratio_output, R.id.atmosphere_rho_ratio_output }; int titles[] = { R.id.atmosphere_english_label, R.id.atmosphere_metric_label, R.id.atmosphere_ratio_label }; String title_string[] = getResources().getStringArray(R.array.atmosphere_title_array); String prefixes[] = getResources().getStringArray(R.array.atmosphere_array); String prefixes_r[] = getResources().getStringArray(R.array.atmosphere_ratio_array); String[] suffix = { "ft", "psf", "R", "lb/ft^3", "lb s/ft^2", "ft/s" }; String[] suffixm = { "m", "Pa", "K", "kg/m^3", "Pa s", "m/s" }; String[] suffixr = { "", "", "" }; Double input;/*from w w w. j ava 2 s . com*/ RadioButton radio_h, radio_P, radio_T, radio_rho, radio_mu; int index; Atmosphere atmos = new Atmosphere(); EditText text; Spinner spinner; double P_sl = 2116.2; double rho_sl = 0.0023769; double T_sl = 518.67; double mu_sl = 3.737e-7; double P_cut = 2527; double rho_cut = 0.002744; double T_cut = 536.47; double mu_cut = 3.83587e-7; try { radio_h = (RadioButton) findViewById(R.id.radio_atmosphere_h); radio_P = (RadioButton) findViewById(R.id.radio_atmosphere_P); radio_T = (RadioButton) findViewById(R.id.radio_atmosphere_T); radio_rho = (RadioButton) findViewById(R.id.radio_atmosphere_rho); radio_mu = (RadioButton) findViewById(R.id.radio_atmosphere_mu); if (radio_h.isChecked()) { double h_multiply[] = { 3.2808399, 1, 1. / 12. }; text = (EditText) findViewById(R.id.atmosphere_h_input); input = Double.parseDouble(text.getText().toString().trim()); spinner = (Spinner) findViewById(R.id.atmosphere_spinner_height); index = spinner.getSelectedItemPosition(); input = h_multiply[index] * input; if (input < -5000) { ShowToast("Input height too low"); return; } else { if (input > 160000) { ShowToast( "Warning: input altitude is higher than upper stratosphere, results may be invalid."); } atmos.CalculateFromHeight(input); } } else if (radio_P.isChecked()) { double p_multiply[] = { 2116.2 / 101325.0, 144.0, 1.0 }; text = (EditText) findViewById(R.id.atmosphere_pressure_input); input = Double.parseDouble(text.getText().toString().trim()); spinner = (Spinner) findViewById(R.id.atmosphere_spinner_pressure); index = spinner.getSelectedItemPosition(); input = p_multiply[index] * input; if (input > P_cut) { ShowToast("Pressure input not attainable in the standard atmosphere"); return; } else if (input <= 0) { ShowToast("Pressure must be greater than 0 (vacuum)"); } else { if (input < 24) { ShowToast("Warning: input pressure is near vacuum, results may be invalid"); } atmos.P_to_h(input); } } else if (radio_T.isChecked()) { double t_subtract[] = { 0, -273.15, 0, -459.67 }; double t_multiply[] = { 1.8, 1.8, 1.0, 1.0 }; spinner = (Spinner) findViewById(R.id.atmosphere_spinner_temperature); index = spinner.getSelectedItemPosition(); text = (EditText) findViewById(R.id.atmosphere_temperature_input); input = Double.parseDouble(text.getText().toString().trim()); input = t_multiply[index] * (input - t_subtract[index]); if (input < .75189 * T_sl || input > T_cut) { ShowToast("Input temperature not attainable in the standard atmosphere"); return; } else { atmos.T_to_h(input); } } else if (radio_rho.isChecked()) { double[] density_multiply = { 0.0023769 / 1.225, 1, 0.0023769 / 0.0765 }; spinner = (Spinner) findViewById(R.id.atmosphere_spinner_density); index = spinner.getSelectedItemPosition(); text = (EditText) findViewById(R.id.atmosphere_density_input); input = Double.parseDouble(text.getText().toString().trim()); input = density_multiply[index] * input; if (input > rho_cut) { ShowToast("Density input not attainable in the standard atmosphere"); return; } else if (input <= 0) { ShowToast("Density must be greater than 0"); return; } else { if (input < 1e-6) { ShowToast("Warning: input density is near vacuum, results may be invalid"); } atmos.rho_to_h(input); } } else if (radio_mu.isChecked()) { double[] viscosity_multiply = { 1.0 / 47.880106020829835, 1 }; spinner = (Spinner) findViewById(R.id.atmosphere_spinner_viscosity); index = spinner.getSelectedItemPosition(); text = (EditText) findViewById(R.id.atmosphere_mu_input); input = Double.parseDouble(text.getText().toString().trim()); input = viscosity_multiply[index] * input; if (input > mu_cut) { ShowToast("Viscosity not attainable in the standard atmosphere"); return; } else if (input < 2.9689e-7) { ShowToast("Viscosity input not attainable in the standard atmosphere"); return; } else { atmos.mu_to_h(input); } } else { return; } } catch (NumberFormatException e) { return; } double[] values = atmos.values_english(); //h, P, T, rho, mu, a, P_ratio, T_ratio, rho_ratio double[] valuesm = atmos.values_metric(); double[] valuesr = atmos.values_ratio(); if (values[0] < -5000) { ShowToast("Elevation too low" + values[0]); return; } AtmosphereSetMessage(prefixes, suffix, labels, values, titles[0], title_string[0]); AtmosphereSetMessage(prefixes, suffixm, labelsm, valuesm, titles[1], title_string[1]); AtmosphereSetMessage(prefixes_r, suffixr, labelsr, valuesr, titles[2], title_string[2]); }
From source file:com.example.android.aerotoolbox.MainActivity.java
public void NormalCalculate(View view) { double values[]; double M1, M2, p21, pt21, pt2p1, t21, rho21; NormalValues OutputValues;/*from w w w .jav a2 s . co m*/ RadioButton radio_m1, radio_m2, radio_p21, radio_pt21, radio_pt2p1, radio_t21, radio_rho21; EditText text; int labels[] = { R.id.normal_m1_output, R.id.normal_m2_output, R.id.normal_p21_output, R.id.normal_pt21_output, R.id.normal_pt2p1_output, R.id.normal_t21_output, R.id.normal_rho21_output }; String prefixes[] = getResources().getStringArray(R.array.normal_array); //int title = R.id.normal_label; try { radio_m1 = (RadioButton) findViewById(R.id.normal_radio_m1); radio_m2 = (RadioButton) findViewById(R.id.normal_radio_m2); radio_p21 = (RadioButton) findViewById(R.id.normal_radio_p21); radio_pt21 = (RadioButton) findViewById(R.id.normal_radio_pt21); radio_pt2p1 = (RadioButton) findViewById(R.id.normal_radio_pt2p1); radio_t21 = (RadioButton) findViewById(R.id.normal_radio_t21); radio_rho21 = (RadioButton) findViewById(R.id.normal_radio_rho21); if (radio_m1.isChecked()) { text = (EditText) findViewById(R.id.normal_m1_input); M1 = Double.parseDouble(text.getText().toString().trim()); if (M1 < 1) { ShowToast("Upstream Mach number must be greater than 1"); return; } } else if (radio_m2.isChecked()) { text = (EditText) findViewById(R.id.normal_m2_input); M2 = Double.parseDouble(text.getText().toString().trim()); if (M2 > 1) { ShowToast("Downstream Mach number must be less than 1"); return; } if (M2 < 0.377964474) { ShowToast("Downstream Mach number must be greater 1/sqrt(7)=.3780"); return; } M1 = Math.sqrt((M2 * M2 + 5) / (7 * M2 * M2 - 1)); } else if (radio_p21.isChecked()) { text = (EditText) findViewById(R.id.normal_p21_input); p21 = Double.parseDouble(text.getText().toString().trim()); if (p21 < 1) { ShowToast("Static pressure ratio must be greater than 1"); return; } M1 = Math.sqrt((6 * p21 + 1) / 7); } else if (radio_pt21.isChecked()) { text = (EditText) findViewById(R.id.normal_pt21_input); pt21 = Double.parseDouble(text.getText().toString().trim()); if (pt21 > 1) { ShowToast("Total pressure ratio must be less than 1"); return; } M1 = AeroCalc.Normal_pt21(1.01, pt21, 1e-10, 100); } else if (radio_pt2p1.isChecked()) { text = (EditText) findViewById(R.id.normal_pt2p1_input); pt2p1 = Double.parseDouble(text.getText().toString().trim()); if (pt2p1 < 1.892929159) { ShowToast("Value must be greater than Pt/P for sonic flow, ~1.8929"); return; } M1 = AeroCalc.Normal_pt2p1(1.01, pt2p1, 1e-10, 40); } else if (radio_t21.isChecked()) { text = (EditText) findViewById(R.id.normal_t21_input); t21 = Double.parseDouble(text.getText().toString().trim()); if (t21 < 1) { ShowToast("Static temperature ratio must be greater than 1"); return; } M1 = Math.sqrt((18 * t21 + 6 * Math.sqrt(9 * t21 * t21 - 17 * t21 + 9) - 17) / 7); } else if (radio_rho21.isChecked()) { text = (EditText) findViewById(R.id.normal_rho21_input); rho21 = Double.parseDouble(text.getText().toString().trim()); if (rho21 < 1) { ShowToast("density ratio must be greater than 1"); return; } if (rho21 >= 6) { ShowToast("Theoretical limit of density ratio is 6"); return; } M1 = Math.sqrt(-(5 * rho21) / (rho21 - 6)); } else { return; // Nothing checked } OutputValues = new NormalValues(M1); values = OutputValues.values(); NormalSetMessage(prefixes, labels, values); } catch (NumberFormatException e) { return; } }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to the user for the browser bookmarks. Allow the user to add a * browser bookmark to an existing row or a new row. * /* w w w .j a v a2 s.c o m*/ * @param context */ public static void displayAddBrowserBookmark(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.add_browser_bookmarks_list); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); } }); ListView listView = (ListView) dialog.findViewById(R.id.list); final ArrayList<BookmarkInfo> bookmarks = loadBookmarks(context); Collections.sort(bookmarks, new Comparator<BookmarkInfo>() { @Override public int compare(BookmarkInfo lhs, BookmarkInfo rhs) { return lhs.getTitle().toLowerCase().compareTo(rhs.getTitle().toLowerCase()); } }); listView.setAdapter(new BookmarkAdapter(context, bookmarks)); listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { // run in thread since network logic needed to get bookmark icon new Thread(new Runnable() { public void run() { // if the new row radio button is selected, the user must enter // a name for the new row String name = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && name.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } boolean currentRow = !newRadioButton.isChecked(); try { BookmarkInfo bookmark = (BookmarkInfo) parent.getAdapter().getItem(position); int rowId = 0; int rowPosition = 0; if (currentRow) { rowId = context.getCurrentGalleryId(); ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId); rowPosition = items.size(); // in last // position // for selected // row } else { rowId = (int) RowsTable.insertRow(context, name, 0, RowInfo.FAVORITE_TYPE); rowPosition = 0; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(bookmark.getUrl())); Uri uri = Uri.parse(bookmark.getUrl()); Log.d(LOG_TAG, "host=" + uri.getScheme() + "://" + uri.getHost()); String icon = Utils.getWebSiteIcon(context, "http://" + uri.getHost()); Log.d(LOG_TAG, "icon1=" + icon); if (icon == null) { // try base host address int count = StringUtils.countMatches(uri.getHost(), "."); if (count > 1) { int index = uri.getHost().indexOf('.'); String baseHost = uri.getHost().substring(index + 1); icon = Utils.getWebSiteIcon(context, "http://" + baseHost); Log.d(LOG_TAG, "icon2=" + icon); } } ItemsTable.insertItem(context, rowId, rowPosition, bookmark.getTitle(), intent, icon, DatabaseHelper.SHORTCUT_TYPE); } catch (Exception e) { Log.e(LOG_TAG, "displayAddBrowserBookmark", e); } // need to do this on UI thread context.getHandler().post(new Runnable() { public void run() { context.showCover(false); dialog.dismiss(); context.reloadAllGalleries(); } }); if (currentRow) { Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK); } else { Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK_WITH_ROW); } } }).start(); } }); listView.setDrawingCacheEnabled(true); listView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_BROWSER_BOOKMARK); }
From source file:com.kunze.androidlocaltodo.TaskListActivity.java
private void ShowTaskDialog(Task task, OnClickListener okListener) { LayoutInflater inflater = this.getLayoutInflater(); View dlgView = inflater.inflate(R.layout.dialog_task, null); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(dlgView);//from ww w .j a va2s .c om builder.setTitle("Task"); final TextView nameEdit = (TextView) dlgView.findViewById(R.id.task_name_edit); nameEdit.setText(task.mName); final TextView descriptionEdit = (TextView) dlgView.findViewById(R.id.task_description_edit); descriptionEdit.setText(task.mDescription); final TextView dueDateView = (TextView) dlgView.findViewById(R.id.task_due_date); SetFriendlyDueDateText(dueDateView, task.mDueDate); Button dueDateButton = (Button) dlgView.findViewById(R.id.task_due_date_choose); final Calendar dueDate = task.mDueDate; final Task thisTask = task; dueDateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ShowDueDateDialog(dueDate, new OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int id) { Dialog dlg = (Dialog) dialogInterface; DatePicker datePicker = (DatePicker) dlg.findViewById(R.id.due_date_calendar); Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); thisTask.mDueDate = calendar; SetFriendlyDueDateText(dueDateView, thisTask.mDueDate); } }); } }); final CheckBox repeatCheck = (CheckBox) dlgView.findViewById(R.id.repeat); repeatCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { View dialog = (View) buttonView.getParent(); SetRepeatVisibility(dialog, isChecked); } }); Boolean repeat = task.mRepeatUnit != Task.RepeatUnit.NONE; repeatCheck.setChecked(repeat); SetRepeatVisibility(dlgView, repeat); final EditText repeatTimeEdit = (EditText) dlgView.findViewById(R.id.repeat_time); repeatTimeEdit.setText(Integer.toString(task.mRepeatTime)); final Spinner repeatUnitSpinner = (Spinner) dlgView.findViewById(R.id.repeat_unit); String[] repeatUnits = { "Days", "Weeks", "Months", "Years" }; repeatUnitSpinner .setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, repeatUnits)); int repeatUnitPos = 0; switch (task.mRepeatUnit) { case DAYS: repeatUnitPos = 0; break; case WEEKS: repeatUnitPos = 1; break; case MONTHS: repeatUnitPos = 2; break; case YEARS: repeatUnitPos = 3; break; case NONE: repeatUnitPos = 0; } repeatUnitSpinner.setSelection(repeatUnitPos); final RadioButton repeatFromComplete = (RadioButton) dlgView.findViewById(R.id.repeat_from_complete); final RadioButton repeatFromDue = (RadioButton) dlgView.findViewById(R.id.repeat_from_due); if (task.mRepeatFromComplete) { repeatFromComplete.setChecked(true); } else { repeatFromDue.setChecked(true); } // Here's a trick: We cascade the OnClick listeners so we can extract // the dialog contents into the task before calling the second listener. final OnClickListener userListener = okListener; final Task myTask = task; OnClickListener cascadedListener = new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { myTask.mName = nameEdit.getText().toString(); myTask.mDescription = descriptionEdit.getText().toString(); myTask.mRepeatUnit = Task.RepeatUnit.NONE; if (repeatCheck.isChecked()) { switch (repeatUnitSpinner.getSelectedItemPosition()) { case 0: myTask.mRepeatUnit = Task.RepeatUnit.DAYS; break; case 1: myTask.mRepeatUnit = Task.RepeatUnit.WEEKS; break; case 2: myTask.mRepeatUnit = Task.RepeatUnit.MONTHS; break; case 3: myTask.mRepeatUnit = Task.RepeatUnit.YEARS; break; } myTask.mRepeatTime = Integer.parseInt(repeatTimeEdit.getText().toString()); myTask.mRepeatFromComplete = repeatFromComplete.isChecked(); } userListener.onClick(dialog, which); } }; builder.setNegativeButton("Cancel", null); builder.setPositiveButton("OK", cascadedListener); builder.show(); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to allow user to select which row to add the shortcut. For * TV channels let the user change the channel name. * /* www .java 2s . co m*/ * @see InstallShortcutReceiver * * @param context * @param name * @param icon * @param uri */ public static void displayShortcutsRowSelection(final Launcher context, final String name, final String icon, final String uri) { if (uri == null) { return; } final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); final boolean isChannel = uri.startsWith("tv"); dialog.setContentView(R.layout.select_row); final TextView channelTextView = (TextView) dialog.findViewById(R.id.channelText); final EditText channelNameEditText = (EditText) dialog.findViewById(R.id.channelName); if (isChannel) { channelTextView.setVisibility(View.VISIBLE); channelNameEditText.setVisibility(View.VISIBLE); channelNameEditText.setText(name); } final TextView selectTextView = (TextView) dialog.findViewById(R.id.selectText); selectTextView.setText(context.getString(R.string.dialog_select_row, name)); final Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); spinner.setVisibility(View.GONE); } }); List<String> list = new ArrayList<String>(); final ArrayList<RowInfo> rows = RowsTable.getRows(context); if (rows != null) { for (RowInfo row : rows) { list.add(row.getTitle()); } } ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(context, R.layout.simple_spinner_item, list); dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(dataAdapter); Button buttonYes = (Button) dialog.findViewById(R.id.buttonOk); buttonYes.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String shortcutName = name; try { if (isChannel) { String channelName = channelNameEditText.getText().toString().trim(); if (channelName.length() == 0) { channelNameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_channel_name_alert)); return; } shortcutName = channelName; } // if the new row radio button is selected, the user must // enter a name for the new row String rowName = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && rowName.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } boolean currentRow = !newRadioButton.isChecked(); int rowId = 0; int rowPosition = 0; if (currentRow) { if (rows != null) { String selectedRow = (String) spinner.getSelectedItem(); for (RowInfo row : rows) { if (row.getTitle().equals(selectedRow)) { rowId = row.getId(); ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId); rowPosition = items.size(); // in last // position // for selected // row break; } } } } else { rowId = (int) RowsTable.insertRow(context, rowName, 0, RowInfo.FAVORITE_TYPE); rowPosition = 0; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(uri)); ItemsTable.insertItem(context, rowId, rowPosition, shortcutName, intent, icon, DatabaseHelper.SHORTCUT_TYPE); Toast.makeText(context, context.getString(R.string.shortcut_installed, shortcutName), Toast.LENGTH_SHORT).show(); context.reloadAllGalleries(); if (currentRow) { Analytics.logEvent(Analytics.ADD_SHORTCUT); } else { Analytics.logEvent(Analytics.ADD_SHORTCUT_WITH_ROW); } } catch (Exception e) { Log.d(LOG_TAG, "onClick", e); } context.showCover(false); dialog.dismiss(); } }); Button buttonNo = (Button) dialog.findViewById(R.id.buttonCancel); buttonNo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { context.showCover(false); dialog.dismiss(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_SHORTCUT); }
From source file:com.adithya321.sharesanalysis.fragments.PurchaseShareFragment.java
@Nullable @Override//from www . ja v a 2 s .com public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false); databaseHandler = new DatabaseHandler(getContext()); sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view); emptyTV = (TextView) root.findViewById(R.id.empty); arrow = (ImageView) root.findViewById(R.id.arrow); setRecyclerViewAdapter(); FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab); addPurchaseFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Add Share Purchase"); dialog.setContentView(R.layout.dialog_add_share_purchase); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name); List<String> nseList = ShareUtils.getNseList(getContext()); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_dropdown_item_1line, nseList); name.setAdapter(arrayAdapter); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); for (Share share : sharesList) { shares.add(share.getName()); } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new); RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing); if (shares.size() == 0) existingRB.setVisibility(View.GONE); (newRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE); } }); (existingRB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { name.setVisibility(View.GONE); spinner.setVisibility(View.VISIBLE); } }); Calendar calendar = Calendar.getInstance(); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(this); Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn); addPurchaseBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Share share = new Share(); share.setId(databaseHandler.getNextKey("share")); share.setPurchases(new RealmList<Purchase>()); Purchase purchase = new Purchase(); purchase.setId(databaseHandler.getNextKey("purchase")); if (newRB.isChecked()) { String sName = name.getText().toString().trim(); if (sName.equals("")) { Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show(); return; } else { share.setName(sName); purchase.setName(sName); } } String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); share.setDateOfInitialPurchase(date); purchase.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); try { purchase.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } EditText price = (EditText) dialog.findViewById(R.id.buying_price); try { purchase.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show(); return; } purchase.setType("buy"); if (newRB.isChecked()) { if (!databaseHandler.addShare(share, purchase)) { Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show(); return; } } else { purchase.setName(spinner.getSelectedItem().toString()); databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase); } setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); return root; }
From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java
private void processOnClickListenerForKey(final int key) { if (IMAGE_BUTTON_TEXT == key) { } else if (IMAGE_BUTTON_BUTTONS == key) { hideKeyboard();// w w w . j a v a2s .c o m try { Intent intent = new Intent(mActivity, SendMessageButtonActivity.class); intent.putExtra(SendMessageButtonActivity.CANNED_BUTTONS, Pickler.getPickleFromObject(mCannedButtons)); long[] primitiveLongArray = new long[mButtons.size()]; Long[] longArray = mButtons.toArray(new Long[mButtons.size()]); for (int i = 0; i < longArray.length; i++) { primitiveLongArray[i] = longArray[i].longValue(); } intent.putExtra(SendMessageButtonActivity.BUTTONS, primitiveLongArray); mActivity.startActivityForResult(intent, PICK_BUTTON); } catch (Exception e) { L.bug(e); } } else if (IMAGE_BUTTON_PICTURE == key) { hideKeyboard(); getNewPicture(); } else if (IMAGE_BUTTON_VIDEO == key) { hideKeyboard(); getNewVideo(); } else if (IMAGE_BUTTON_PRIORITY == key) { hideKeyboard(); final View dialog = mActivity.getLayoutInflater().inflate(R.layout.msg_priority_picker, null); final RadioButton priorityNormalBtn = ((RadioButton) dialog.findViewById(R.id.priority_normal)); final RadioButton priorityHighBtn = ((RadioButton) dialog.findViewById(R.id.priority_high)); final RadioButton priorityUrgentBtn = ((RadioButton) dialog.findViewById(R.id.priority_urgent)); final RadioButton priorityUrgentWithAlarmBtn = ((RadioButton) dialog .findViewById(R.id.priority_urgent_with_alarm)); priorityNormalBtn.setChecked(false); priorityHighBtn.setChecked(false); priorityUrgentBtn.setChecked(false); priorityUrgentWithAlarmBtn.setChecked(false); if (mPriority == Message.PRIORITY_HIGH) { priorityHighBtn.setChecked(true); } else if (mPriority == Message.PRIORITY_URGENT) { priorityUrgentBtn.setChecked(true); } else if (mPriority == Message.PRIORITY_URGENT_WITH_ALARM) { priorityUrgentWithAlarmBtn.setChecked(true); } else { priorityNormalBtn.setChecked(true); } String title = mActivity.getString(R.string.priority); SafeDialogClick onPositiveClick = new SafeDialogClick() { @Override public void safeOnClick(DialogInterface di, int id) { if (priorityHighBtn.isChecked()) { mPriority = Message.PRIORITY_HIGH; } else if (priorityUrgentBtn.isChecked()) { mPriority = Message.PRIORITY_URGENT; } else if (priorityUrgentWithAlarmBtn.isChecked()) { mPriority = Message.PRIORITY_URGENT_WITH_ALARM; } else { mPriority = Message.PRIORITY_NORMAL; } initImageButtonsNavigation(); } }; UIUtils.showDialog(mActivity, title, null, R.string.ok, onPositiveClick, R.string.cancel, null, dialog); } else if (IMAGE_BUTTON_STICKY == key) { hideKeyboard(); final View dialog = mActivity.getLayoutInflater().inflate(R.layout.msg_sticky_picker, null); final RadioButton stickyDisabled = ((RadioButton) dialog.findViewById(R.id.sticky_disabled)); final RadioButton stickyEnabled = ((RadioButton) dialog.findViewById(R.id.sticky_enabled)); stickyEnabled.setChecked(mIsSticky); stickyDisabled.setChecked(!mIsSticky); String title = mActivity.getString(R.string.sticky); SafeDialogClick onPositiveClick = new SafeDialogClick() { @Override public void safeOnClick(DialogInterface di, int id) { mIsSticky = stickyEnabled.isChecked(); initImageButtonsNavigation(); } }; UIUtils.showDialog(mActivity, title, null, R.string.ok, onPositiveClick, R.string.cancel, null, dialog); } else if (IMAGE_BUTTON_MORE == key) { hideKeyboard(); final View dialog = mActivity.getLayoutInflater().inflate(R.layout.msg_more_picker, null); final ListView pickMsgMore = (ListView) dialog.findViewById(R.id.pick_msg_more); List<PickMoreItem> items = new ArrayList<>(); for (int i = mMaxImageButtonsOnScreen - 1; i < mImageButtons.size(); i++) { int k = mImageButtons.get(i); String t = ""; if (k == IMAGE_BUTTON_TEXT) { t = mActivity.getString(R.string.title_message); } else if (k == IMAGE_BUTTON_BUTTONS) { t = mActivity.getString(R.string.title_buttons); } else if (k == IMAGE_BUTTON_PICTURE) { t = mActivity.getString(R.string.title_new_message_image); } else if (k == IMAGE_BUTTON_VIDEO) { t = mActivity.getString(R.string.title_new_message_video); } else if (k == IMAGE_BUTTON_PRIORITY) { t = mActivity.getString(R.string.priority); } else if (k == IMAGE_BUTTON_STICKY) { t = mActivity.getString(R.string.sticky); } else { L.d("Could not find more text for key: " + key); } items.add(new PickMoreItem(k, getImageResourceForKey(k), t)); } pickMsgMore.setAdapter(new ListAdapter(mActivity, items)); String title = mActivity.getString(R.string.more); String negativeCaption = mActivity.getString(R.string.cancel); final AlertDialog alertDialog = UIUtils.showDialog(mActivity, title, null, null, null, negativeCaption, null, dialog); pickMsgMore.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { alertDialog.dismiss(); PickMoreItem item = (PickMoreItem) view.getTag(); processOnClickListenerForKey(item.imageButtonKey); } }); } else { L.d("Could not find processOnClickListener for key: " + key); } }
From source file:org.glucosio.android.activity.MainActivity.java
public void showExportCsvDialog() { final Dialog exportDialog = new Dialog(MainActivity.this, R.style.GlucosioTheme); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(exportDialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.WRAP_CONTENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; exportDialog.setContentView(R.layout.dialog_export); exportDialog.getWindow().setAttributes(lp); exportDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); exportDialog.getWindow().setDimAmount(0.5f); exportDialog.show();/*from ww w .j a v a 2 s.co m*/ exportDialogDateFrom = (TextView) exportDialog.findViewById(R.id.activity_export_date_from); exportDialogDateTo = (TextView) exportDialog.findViewById(R.id.activity_export_date_to); exportRangeButton = (RadioButton) exportDialog.findViewById(R.id.activity_export_range); final RadioButton exportAllButton = (RadioButton) exportDialog.findViewById(R.id.activity_export_all); final TextView exportButton = (TextView) exportDialog.findViewById(R.id.dialog_export_add); final TextView cancelButton = (TextView) exportDialog.findViewById(R.id.dialog_export_cancel); exportRangeButton.setChecked(true); exportDialogDateFrom.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar now = Calendar.getInstance(); DatePickerDialog dpd = DatePickerDialog.newInstance(MainActivity.this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dpd.show(getFragmentManager(), "fromDateDialog"); dpd.setMaxDate(now); } }); exportDialogDateTo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar now = Calendar.getInstance(); DatePickerDialog dpd = DatePickerDialog.newInstance(MainActivity.this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dpd.show(getFragmentManager(), "toDateDialog"); dpd.setMaxDate(now); } }); exportRangeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean isChecked = exportRangeButton.isChecked(); exportDialogDateFrom.setEnabled(true); exportDialogDateTo.setEnabled(true); exportAllButton.setChecked(!isChecked); } }); exportAllButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean isChecked = exportAllButton.isChecked(); exportDialogDateFrom.setEnabled(false); exportDialogDateTo.setEnabled(false); exportRangeButton.setChecked(!isChecked); exportButton.setEnabled(true); } }); exportButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (validateExportDialog()) { exportPresenter.onExportClicked(exportAllButton.isChecked()); exportDialog.dismiss(); } else { showSnackBar(getResources().getString(R.string.dialog_error), Snackbar.LENGTH_LONG); } } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { exportDialog.dismiss(); } }); }
From source file:net.zorgblub.typhon.fragment.LibraryFragment.java
private void showImportDialog() { AlertDialog.Builder builder;//www . j a v a 2s .c o m LayoutInflater inflater = PlatformUtil.getLayoutInflater(getActivity()); final View layout = inflater.inflate(R.layout.import_dialog, null); final RadioButton scanSpecific = (RadioButton) layout.findViewById(R.id.radioScanFolder); final TextView folder = (TextView) layout.findViewById(R.id.folderToScan); final CheckBox copyToLibrary = (CheckBox) layout.findViewById(R.id.copyToLib); final Button browseButton = (Button) layout.findViewById(R.id.browseButton); Option<File> storageBase = config.getStorageBase(); if (isEmpty(storageBase)) { return; } folder.setOnClickListener(v -> scanSpecific.setChecked(true)); // Copy scan settings from the prefs copyToLibrary.setChecked(config.getCopyToLibraryOnScan()); scanSpecific.setChecked(config.getUseCustomScanFolder()); folder.setText(config.getScanFolder()); builder = new AlertDialog.Builder(getActivity()); builder.setView(layout); this.intentCallBack = (int resultCode, Intent data) -> { if (resultCode == Activity.RESULT_OK && data != null) { folder.setText(data.getData().getPath()); } }; browseButton.setOnClickListener(v -> { scanSpecific.setChecked(true); Intent intent = new Intent(getActivity(), FileBrowseActivity.class); intent.setData(Uri.parse(folder.getText().toString())); startActivityForResult(intent, 0); }); builder.setTitle(R.string.import_books); builder.setPositiveButton(android.R.string.ok, (dialog, which) -> { dialog.dismiss(); /* Update settings */ config.setUseCustomScanFolder(scanSpecific.isChecked()); config.setCopyToLibraryOnScan(copyToLibrary.isChecked()); File folderToScan; if (scanSpecific.isChecked()) { String path = folder.getText().toString(); folderToScan = new File(path); config.setScanFolder(path); /* update custom path only if used */ } else { File default_storage = storageBase.unsafeGet(); folderToScan = new File(default_storage.getAbsolutePath()); } startImport(folderToScan, copyToLibrary.isChecked()); }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); }
From source file:com.mobicage.rogerthat.SendMessageButtonActivity.java
private void addButton() { final View dialog = getLayoutInflater().inflate(R.layout.new_button_dialog, null); final TextInputLayout captionViewLayout = (TextInputLayout) dialog.findViewById(R.id.button_caption); mCaptionView = captionViewLayout.getEditText(); mActionView = (EditText) dialog.findViewById(R.id.button_action); final ImageButton actionHelpButton = (ImageButton) dialog.findViewById(R.id.action_help_button); final RadioButton noneRadio = (RadioButton) dialog.findViewById(R.id.action_none); final RadioButton telRadio = (RadioButton) dialog.findViewById(R.id.action_tel); final RadioButton geoRadio = (RadioButton) dialog.findViewById(R.id.action_geo); final RadioButton wwwRadio = (RadioButton) dialog.findViewById(R.id.action_www); final int iconColor = LookAndFeelConstants.getPrimaryIconColor(SendMessageButtonActivity.this); noneRadio.setChecked(true);//from w w w. java 2s . com mActionView.setVisibility(View.GONE); actionHelpButton.setVisibility(View.GONE); noneRadio.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mActionView.setVisibility(View.GONE); actionHelpButton.setVisibility(View.GONE); } }); telRadio.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mActionView.setText(""); mActionView.setVisibility(View.VISIBLE); mActionView.setInputType(InputType.TYPE_CLASS_PHONE); actionHelpButton.setVisibility(View.VISIBLE); actionHelpButton.setImageDrawable(new IconicsDrawable(mService, FontAwesome.Icon.faw_address_book_o) .color(iconColor).sizeDp(24)); } }); geoRadio.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mActionView.setText(""); mActionView.setVisibility(View.VISIBLE); mActionView.setInputType(InputType.TYPE_CLASS_TEXT); actionHelpButton.setVisibility(View.VISIBLE); actionHelpButton.setImageDrawable( new IconicsDrawable(mService, FontAwesome.Icon.faw_map_marker).color(iconColor).sizeDp(24)); } }); wwwRadio.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mActionView.setText("http://"); mActionView.setVisibility(View.VISIBLE); mActionView.setInputType(InputType.TYPE_CLASS_TEXT); actionHelpButton.setVisibility(View.GONE); } }); actionHelpButton.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { if (telRadio.isChecked()) { Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI); startActivityForResult(intent, PICK_CONTACT); } else if (geoRadio.isChecked()) { Intent intent = new Intent(SendMessageButtonActivity.this, GetLocationActivity.class); startActivityForResult(intent, GET_LOCATION); } } }); String message = getString(R.string.create_button_title); String positiveCaption = getString(R.string.ok); String negativeCaption = getString(R.string.cancel); SafeDialogClick positiveClick = new SafeDialogClick() { @Override public void safeOnClick(DialogInterface di, int id) { String caption = mCaptionView.getText().toString(); if ("".equals(caption.trim())) { UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.caption_required)); return; } CannedButton cannedButton; if (!noneRadio.isChecked()) { String actionText = mActionView.getText().toString(); if ("".equals(caption.trim())) { UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid)); return; } if (telRadio.isChecked()) { actionText = "tel://" + actionText; } else if (geoRadio.isChecked()) { actionText = "geo://" + actionText; } Matcher action = actionPattern.matcher(actionText); if (!action.matches()) { UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid)); return; } cannedButton = new CannedButton(caption, "".equals(action.group(2)) ? null : action.group()); } else { cannedButton = new CannedButton(caption, null); } mCannedButtons.add(cannedButton); cannedButton.setSelected(true); mCannedButtonAdapter.notifyDataSetChanged(); mButtons.add(cannedButton.getId()); di.dismiss(); } }; AlertDialog alertDialog = UIUtils.showDialog(SendMessageButtonActivity.this, null, message, positiveCaption, positiveClick, negativeCaption, null, dialog); alertDialog.setCanceledOnTouchOutside(true); }