@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); if (created) { // Prevent overwriting attributes that are already set return; } else { created = true; } if (getArguments() != null) { ip = getArguments().getString(ARG_IP); type = TcpConnectionManager.ReceiverType.valueOf(getArguments().getString(ARG_TYPE)); menu = getArguments().getInt(ARG_MENU); } else { Log.e(LOG_TAG, "onCreate: getArguments()==null"); ip = ""; type = TcpConnectionManager.ReceiverType.UNSPECIFIED; menu = 0; } tcpConnectionManager = TcpConnectionManager.getInstance(getActivity().getApplicationContext()); connection = tcpConnectionManager.requireConnection(this); }
public void setValues(String ip, TcpConnectionManager.ReceiverType type, int menu) { this.ip = ip; this.type = type; this.menu = menu; connection = tcpConnectionManager.requireConnection(this); int[] spinnerMenus = TcpConnectionManager.getDropdownMenuSubmenus(getResources(), type); String[] spinnerCommands = TcpConnectionManager.getDropdownMenuCommandValues(getResources(), type); String[] spinnerResponses = TcpConnectionManager.getDropdownMenuResponseValues(getResources(), type); String[] spinnerReadables = TcpConnectionManager.getDropdownMenuNames(getResources(), type); if (spinnerMenus.length != spinnerCommands.length || spinnerMenus.length != spinnerResponses.length || spinnerMenus.length != spinnerReadables.length) { Log.e(LOG_TAG, "setValues: Array lengths don't match"); return; } for (int i = 0; i < spinnerMenus.length; i++) { if (spinnerMenus[i] == menu) { responseClassifier = spinnerResponses[i]; command = spinnerCommands[i]; submenuReadable = spinnerReadables[i]; break; } } setSpinnerContent(); }
private void setSpinnerContent() { ArrayList<String> list = new ArrayList<>(); spinnerItemNames = TcpConnectionManager.getCommandNameArray(getResources(), connection, menu, false); spinnerItemValues = TcpConnectionManager.getCommandValueArray(getResources(), connection, menu); list.addAll(Arrays.asList(spinnerItemNames)); if (Util.SCREENSHOT) { if (list.isEmpty()) { spinnerItemValues = new String[] {""}; } else { list.remove(0); } list.add(0, getString(R.string.fragment_spinner)); } adapter = new ArrayAdapter<>(getActivity(), R.layout.support_simple_spinner_dropdown_item, list); spinner.setAdapter(adapter); updateUI(connection.getBufferedInformation(responseClassifier)); }
@Override public void onDestroy() { super.onDestroy(); tcpConnectionManager.stopUpdate(this); }