/** Binds the android versions to the dropdrown pop up view */ private void bindAndroidVersions() { hideToolTip(); final Dialog dialog = new Dialog(AddDeviceActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.pop_up_android_versions); final ListView list = (ListView) dialog.findViewById(R.id.list); list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); final List<AndroidHistory> androidVersionList = mDbHelper.getAndroidVersions(" ASC "); AndroidVersionsAdapter adapter = new AndroidVersionsAdapter( ShowCaseApp.getAppContext(), R.layout.individual_row_android_versions, androidVersionList); list.setAdapter(adapter); list.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { list.setPressed(true); dialog.dismiss(); mAndroidVersionId = androidVersionList.get(position).getAndroidId(); mEtAndroidVersion.setText(androidVersionList.get(position).getName()); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); } }); dialog.setCancelable(true); dialog.show(); }
private void validateSubmit() { hideToolTip(); if (CustomInputValidator.checkError(mEtDeviceName)) return; if (CustomInputValidator.checkError(mEtDeviceDesc)) return; if (CustomInputValidator.checkError(mEtAndroidVersion)) return; Devices device = new Devices(); device.setAndroidId(mAndroidVersionId); device.setDeviceDesc(mEtDeviceDesc.getText().toString().trim()); device.setDeviceName(mEtDeviceName.getText().toString().trim()); device.setImageURL(""); if (RestClient.isNetworkAvailable()) { mDbHelper.insertNewDevice(device); Call call = new RestClient().getApiService().addDevice(device); call.enqueue( new Callback() { @Override public void onResponse(Response response, Retrofit retrofit) { if (response.errorBody() == null) { Toast.makeText( ShowCaseApp.getAppContext(), "Device added successfully!", Toast.LENGTH_LONG) .show(); onBackPressed(); } } @Override public void onFailure(Throwable t) {} }); } else { Toast.makeText( ShowCaseApp.getAppContext(), ShowCaseApp.getAppContext().getResources().getString(R.string.no_internet), Toast.LENGTH_LONG) .show(); } }
private void initView() { mEtDeviceName = (MaterialEditText) findViewById(R.id.etDeviceName); mEtDeviceDesc = (MaterialEditText) findViewById(R.id.etDeviceDescription); mEtAndroidVersion = (MaterialEditText) findViewById(R.id.etAndroidVersion); mLinDeviceName = (LinearLayout) findViewById(R.id.linDeviceName); mLinDeviceDesc = (LinearLayout) findViewById(R.id.linDeviceDescription); mLinAndroidVersion = (LinearLayout) findViewById(R.id.linAndroidVersion); mEtAndroidVersion.setOnClickListener(this); mEtDeviceName.addTextChangedListener(new CustomInputValidator(mEtDeviceName)); mEtDeviceName.setOnFocusChangeListener(AddDeviceActivity.this); mEtDeviceDesc.setFilters(new InputFilter[] {new InputFilter.LengthFilter(256)}); mEtDeviceDesc.addTextChangedListener(new CustomInputValidator(mEtDeviceDesc)); mEtDeviceDesc.setOnFocusChangeListener(AddDeviceActivity.this); mDbHelper = DBHelper.getInstance(ShowCaseApp.getAppContext()); }