List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:it.feio.android.omninotes.DetailFragment.java
private void displayLocationDialog() { PermissionsHelper.requestPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION, R.string.permission_coarse_location, snackBarPlaceholder, () -> GeocodeHelper.getLocation(new OnGeoUtilResultListener() { @Override// w w w. ja va2 s. c om public void onAddressResolved(String address) { } @Override public void onCoordinatesResolved(Location location, String address) { } @Override public void onLocationUnavailable() { mainActivity.showMessage(R.string.location_not_found, ONStyle.ALERT); } @Override public void onLocationRetrieved(Location location) { if (location == null) { return; } if (!ConnectionManager.internetAvailable(mainActivity)) { noteTmp.setLatitude(location.getLatitude()); noteTmp.setLongitude(location.getLongitude()); onAddressResolved(""); return; } LayoutInflater inflater = mainActivity.getLayoutInflater(); View v = inflater.inflate(R.layout.dialog_location, null); final AutoCompleteTextView autoCompView = (AutoCompleteTextView) v .findViewById(R.id.auto_complete_location); autoCompView.setHint(getString(R.string.search_location)); autoCompView.setAdapter( new PlacesAutoCompleteAdapter(mainActivity, R.layout.simple_text_layout)); final MaterialDialog dialog = new MaterialDialog.Builder(mainActivity) .customView(autoCompView, false).positiveText(R.string.use_current_location) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog materialDialog) { if (TextUtils.isEmpty(autoCompView.getText().toString())) { noteTmp.setLatitude(location.getLatitude()); noteTmp.setLongitude(location.getLongitude()); // GeocodeHelper.getAddressFromCoordinates(location, mFragment); } else { GeocodeHelper.getCoordinatesFromAddress( autoCompView.getText().toString(), mFragment); } } }).build(); autoCompView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.length() != 0) { dialog.setActionButton(DialogAction.POSITIVE, getString(R.string.confirm)); } else { dialog.setActionButton(DialogAction.POSITIVE, getString(R.string.use_current_location)); } } @Override public void afterTextChanged(Editable s) { } }); dialog.show(); } })); }
From source file:com.annanovas.bestprice.DashBoardEditActivity.java
private void generateAreaRecyclerView() { myDB.open();//from ww w. jav a2 s . c om areaArrayList = myDB.getAllAreas(); areaObjectArrayListForSearch.addAll(areaArrayList); if (areaId != 0) { for (int i = 0; i < areaObjectArrayListForSearch.size(); i++) { if (areaObjectArrayListForSearch.get(i).getId() == areaId) { AreaObject loop = areaObjectArrayListForSearch.get(i); loop.setChecked(true); areaObjectArrayListForSearch.set(i, loop); break; } } } areaAdapter = new AreaAdapter(DashBoardEditActivity.this, areaObjectArrayListForSearch); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(DashBoardEditActivity.this); areaRecyclerView.setLayoutManager(linearLayoutManager); areaRecyclerView.setItemAnimator(new DefaultItemAnimator()); areaRecyclerView.setAdapter(areaAdapter); areaRecyclerView.setNestedScrollingEnabled(false); myDB.close(); areaRecyclerView.addOnItemTouchListener(new AreaAdapter.RecyclerTouchListener(getApplicationContext(), areaRecyclerView, new AreaAdapter.ClickListener() { @Override public void onClick(View view, int position) { for (int i = 0; i < areaObjectArrayListForSearch.size(); i++) { if (areaObjectArrayListForSearch.get(i).getChecked()) { AreaObject loop = areaObjectArrayListForSearch.get(i); loop.setChecked(false); areaObjectArrayListForSearch.set(i, loop); areaAdapter.notifyItemChanged(i); // showLog(productsObjectArrayListForSearch.get(i).getName() + " selected" + productsObjectArrayListForSearch.get(i).getIsChecked()); } } AreaObject areaObject = areaObjectArrayListForSearch.get(position); areaObject.setChecked(true); areaObjectArrayListForSearch.set(position, areaObject); areaAdapter.notifyItemChanged(position); areaId = areaObject.getId(); tvSelectedArea.setText(areaObject.getName()); } @Override public void onLongClick(View view, int position) { } })); etAreaSearch.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String newText = s.toString(); ArrayList<AreaObject> newListArea = new ArrayList<>(); for (AreaObject areaItem : areaArrayList) { String name = areaItem.getName().toLowerCase(); if (name.contains(newText)) { newListArea.add(areaItem); } } areaObjectArrayListForSearch.clear(); areaObjectArrayListForSearch.addAll(newListArea); areaAdapter.setFilter(newListArea); } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.annanovas.bestprice.DashBoardEditActivity.java
private void generateProductRecyclerView() { myDB.open();/*w w w .j a v a 2 s. c o m*/ productsObjectArrayList = myDB.getAllProducts(); productsObjectArrayListForSearch.addAll(productsObjectArrayList); if (selectedProductIdList.size() != 0) { for (int i = 0; i < selectedProductIdList.size(); i++) { selectedProductList.add(myDB.getProductName(Integer.parseInt(selectedProductIdList.get(i)))); } tvSelectedProduct.setText(TextUtils.join(", ", selectedProductList)); for (int i = 0; i < productsObjectArrayListForSearch.size(); i++) { String cellId = String.valueOf(productsObjectArrayListForSearch.get(i).getId()); if (selectedProductIdList.contains(cellId)) { ProductsObject loop = productsObjectArrayListForSearch.get(i); loop.setIsChecked(true); productsObjectArrayListForSearch.set(i, loop); } } generateBrandRecyclerView(); } productAdapter = new ProductAdapter(DashBoardEditActivity.this, productsObjectArrayListForSearch); LinearLayoutManager linearLayoutManager4 = new LinearLayoutManager(DashBoardEditActivity.this); productRecyclerView.setLayoutManager(linearLayoutManager4); productRecyclerView.setItemAnimator(new DefaultItemAnimator()); productRecyclerView.setAdapter(productAdapter); productRecyclerView.setNestedScrollingEnabled(false); myDB.close(); productRecyclerView.addOnItemTouchListener(new ProductAdapter.RecyclerTouchListener(getApplicationContext(), productRecyclerView, new ProductAdapter.ClickListener() { @Override public void onClick(View view, int position) { ProductsObject productsObject = productsObjectArrayListForSearch.get(position); String cellId = String.valueOf(productsObject.getId()); if (selectedProductIdList.contains(cellId)) { selectedProductIdList.remove(cellId); selectedProductList.remove(productsObject.getName()); productsObject.setIsChecked(false); } else { int totalId = selectedProductIdList.size(); selectedProductIdList.add(totalId, cellId); selectedProductList.add(totalId, productsObject.getName()); productsObject.setIsChecked(true); } productsObjectArrayListForSearch.set(position, productsObject); productAdapter.notifyItemChanged(position); tvSelectedProduct.setText(TextUtils.join(", ", selectedProductList)); chosenBrandIdList.clear(); chosenBrandList.clear(); tvDealerShipWith.setText(""); generateBrandRecyclerView(); } @Override public void onLongClick(View view, int position) { } })); etProductSearch.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String newText = s.toString(); ArrayList<ProductsObject> newList4 = new ArrayList<>(); for (ProductsObject productsObjectItem : productsObjectArrayList) { String name = productsObjectItem.getName().toLowerCase(); if (name.contains(newText)) { newList4.add(productsObjectItem); } } productsObjectArrayListForSearch.clear(); productsObjectArrayListForSearch.addAll(newList4); productAdapter.notifyDataSetChanged(); //productAdapter.setFilter(newList4); } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.annanovas.bestprice.DashBoardEditActivity.java
private void generateBrandRecyclerView() { sectionAdapter = new SectionedRecyclerViewAdapter(); myDB.open();//from ww w .j a va 2s . c om for (int i = 0; i < selectedProductIdList.size(); i++) { chosenBrandList.add(new ArrayList<String>()); ArrayList<BrandObject> brandArrayList = myDB.getAllBrands(selectedProductIdList.get(i)); showLog("Size " + chosenBrandIdList.size()); if (chosenBrandIdList.size() != 0) { for (int j = 0; j < brandArrayList.size(); j++) { String cellId = String.valueOf(brandArrayList.get(j).getId()); if (chosenBrandIdList.contains(cellId)) { BrandObject loop = brandArrayList.get(j); loop.setChecked(true); brandArrayList.set(j, loop); chosenBrandList.get(i).add(loop.getName()); showLog("Brand " + loop.getName()); } } } String sectionTag = String.format("section%sTag", getRandomStringNumber()); sectionAdapter.addSection(sectionTag, new BrandSectionAdapter(i, getApplicationContext(), sectionTag, selectedProductList.get(i), brandArrayList)); } if (chosenBrandIdList.size() != 0) { brandName = ""; for (int i = 0; i < chosenBrandList.size(); i++) { if (chosenBrandList.get(i).size() > 0) { //brandName += productTypeList[i] + ":" + TextUtils.join(", ", chosenBrandList.get(i)) + "\n"; brandName += selectedProductList.get(i) + ":" + TextUtils.join(", ", chosenBrandList.get(i)) + "\n"; showLog("Product " + selectedProductList.get(i)); } } tvDealerShipWith.setText(brandName); } myDB.close(); LinearLayoutManager linearLayoutManager3 = new LinearLayoutManager(DashBoardEditActivity.this); brandRecyclerView.setLayoutManager(linearLayoutManager3); brandRecyclerView.setItemAnimator(new DefaultItemAnimator()); brandRecyclerView.setAdapter(sectionAdapter); brandRecyclerView.setNestedScrollingEnabled(false); etBrandSearch.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String newText = s.toString(); for (Section section : sectionAdapter.getSectionsMap().values()) { if (section instanceof FilterableSection) { ((FilterableSection) section).filter(newText); } } sectionAdapter.notifyDataSetChanged(); } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
public void initSearchbar() { final ListView searchListView = (ListView) mainArView.findViewById(R.id.ar_mixview_search_list); searchbar = (LinearLayout) mainArView.findViewById(R.id.ar_mixview_searchbar); hideSearchbar = (Button) mainArView.findViewById(R.id.ar_mixview_hide_searchbar); searchBtn = (Button) mainArView.findViewById(R.id.ar_mixview_search); searchBtn.setOnClickListener(new View.OnClickListener() { @Override/*from w w w .j a va 2 s . c om*/ public void onClick(View view) { parentButtonView.setVisibility(View.GONE); searchbar.setVisibility(View.VISIBLE); } }); hideSearchbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { searchbar.setVisibility(View.GONE); parentButtonView.setVisibility(View.VISIBLE); } }); searchText = (EditText) mainArView.findViewById(R.id.ar_mixview_search_text); searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, android.view.KeyEvent event) { switch (actionId) { case EditorInfo.IME_ACTION_SEARCH: String queryString = searchText.getText().toString(); Intent intent = new Intent(context, SearchKeywordListActivity.class); intent.putExtra("searchName", queryString); InputMethodManager imm = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mainArView.getWindowToken(), 0); mainArView.setVisibility(View.GONE); ((Activity) context).startActivityForResult(intent, SEARCH_LIST); break; default: Toast.makeText(context, "", Toast.LENGTH_LONG).show(); return false; } return true; } }); TextWatcher watcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(final CharSequence charSequence, int i, int i1, int i2) { new Thread(new Runnable() { @Override public void run() { String queryString = searchText.getText().toString(); try { List<ARMarker> searchList = null; String encodedQueryString = URLEncoder.encode(queryString, "UTF-8"); String tempCallbackUrl = "http://ac.map.naver.com/ac?q=" + encodedQueryString + "&st=10&r_lt=10&r_format=json"; String rawData = new NaverHttpHandler().execute(tempCallbackUrl).get(); Log.i("rawData", rawData); JSONObject root = new JSONObject(rawData); JSONArray dataArray = root.getJSONArray("items"); JSONArray locationData = dataArray.getJSONArray(0); Log.i("dataArray", locationData.toString()); final ArrayList<String> list = new ArrayList<>(); for (int index = 0; index < locationData.length(); index++) list.add(locationData.getString(index).substring(2, locationData.getString(index).length() - 2)); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { SearchViewAdapter adapter = new SearchViewAdapter(inflater); adapter.setDataList(list); adapter.setCurrentText(charSequence.toString()); searchListView.setAdapter(adapter); searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String queryString = list.get(i); searchText.setText(queryString); } }); } }); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } }).start(); } @Override public void afterTextChanged(Editable editable) { } }; searchText.addTextChangedListener(watcher); }
From source file:com.ichi2.anki.NoteEditor.java
private void initFieldEditText(FieldEditText editText, final int index, String[] values, Typeface customTypeface, boolean enabled) { String name = values[0];//ww w . java 2s.co m String content = values[1]; editText.init(index, name, content); if (customTypeface != null) { editText.setTypeface(customTypeface); } // Listen for changes in the first field so we can re-check duplicate status. editText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { mFieldEdited = true; if (index == 0) { duplicateCheck(); } } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); editText.setEnabled(enabled); }
From source file:fiskinfoo.no.sintef.fiskinfoo.MyToolsFragment.java
private void setupTextChangedListenerOnHeaderDate(final TextView headerDate, final String currentDate, final Button arrowRightButton) { headerDate.addTextChangedListener(new TextWatcher() { @Override//ww w. java2 s . c o m public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { //generateDiaryTableDataOnCurrentlySelectedDate(rootView, headerDate, haulLogSpecies, speciesHeader, haulLogLayout); if (!headerDate.getText().toString().equals(currentDate)) { arrowRightButton.setVisibility(View.VISIBLE); } } }); }
From source file:com.mantz_it.rfanalyzer.ui.activity.MainActivity.java
public void showRecordingDialog() { if (!running || scheduler == null || demodulator == null || source == null) { toaster.showLong("Analyzer must be running to start recording"); return;/*from w ww .j ava2s. c o m*/ } // Check for the WRITE_EXTERNAL_STORAGE permission: if (ContextCompat.checkSelfPermission(this, "android.permission.WRITE_EXTERNAL_STORAGE") != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { "android.permission.WRITE_EXTERNAL_STORAGE" }, PERMISSION_REQUEST_RECORDING_WRITE_FILES); return; // wait for the permission response (handled in onRequestPermissionResult()) } final String externalDir = Environment.getExternalStorageDirectory().getAbsolutePath(); final int[] supportedSampleRates = rxSampleRate.getSupportedSampleRates(); final double maxFreqMHz = rxFrequency.getMax() / 1000000f; // max frequency of the source in MHz final int sourceType = Integer.parseInt(preferences.getString(getString(R.string.pref_sourceType), "1")); final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US); // Get references to the GUI components: final ScrollView view = (ScrollView) this.getLayoutInflater().inflate(R.layout.start_recording, null); final EditText et_filename = (EditText) view.findViewById(R.id.et_recording_filename); final EditText et_frequency = (EditText) view.findViewById(R.id.et_recording_frequency); final Spinner sp_sampleRate = (Spinner) view.findViewById(R.id.sp_recording_sampleRate); final TextView tv_fixedSampleRateHint = (TextView) view.findViewById(R.id.tv_recording_fixedSampleRateHint); final CheckBox cb_stopAfter = (CheckBox) view.findViewById(R.id.cb_recording_stopAfter); final EditText et_stopAfter = (EditText) view.findViewById(R.id.et_recording_stopAfter); final Spinner sp_stopAfter = (Spinner) view.findViewById(R.id.sp_recording_stopAfter); // Setup the sample rate spinner: final ArrayAdapter<Integer> sampleRateAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); for (int sampR : supportedSampleRates) sampleRateAdapter.add(sampR); sampleRateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_sampleRate.setAdapter(sampleRateAdapter); // Add listener to the frequency textfield, the sample rate spinner and the checkbox: et_frequency.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (et_frequency.getText().length() == 0) return; double freq = Double.parseDouble(et_frequency.getText().toString()); if (freq < maxFreqMHz) freq = freq * 1000000; et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_" + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq"); } }); sp_sampleRate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (et_frequency.getText().length() == 0) return; double freq = Double.parseDouble(et_frequency.getText().toString()); if (freq < maxFreqMHz) freq = freq * 1000000; et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_" + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq"); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); cb_stopAfter.setOnCheckedChangeListener((buttonView, isChecked) -> { et_stopAfter.setEnabled(isChecked); sp_stopAfter.setEnabled(isChecked); }); // Set default frequency, sample rate and stop after values: et_frequency.setText(Long.toString(analyzerSurface.getVirtualFrequency())); int sampleRateIndex = 0; int lastSampleRate = preferences.getInt(getString(R.string.pref_recordingSampleRate), 1000000); for (; sampleRateIndex < supportedSampleRates.length; sampleRateIndex++) { if (supportedSampleRates[sampleRateIndex] >= lastSampleRate) break; } if (sampleRateIndex >= supportedSampleRates.length) sampleRateIndex = supportedSampleRates.length - 1; sp_sampleRate.setSelection(sampleRateIndex); cb_stopAfter.toggle(); // just to trigger the listener at least once! cb_stopAfter.setChecked(preferences.getBoolean(getString(R.string.pref_recordingStopAfterEnabled), false)); et_stopAfter.setText( Integer.toString(preferences.getInt(getString(R.string.pref_recordingStopAfterValue), 10))); sp_stopAfter.setSelection(preferences.getInt(getString(R.string.pref_recordingStopAfterUnit), 0)); // disable sample rate selection if demodulation is running: if (demodulationMode != Demodulator.DEMODULATION_OFF) { sampleRateAdapter.add(rxSampleRate.get()); // add the current sample rate in case it's not already in the list sp_sampleRate.setSelection(sampleRateAdapter.getPosition(rxSampleRate.get())); // select it sp_sampleRate.setEnabled(false); // disable the spinner tv_fixedSampleRateHint.setVisibility(View.VISIBLE); } // Show dialog: new AlertDialog.Builder(this).setTitle("Start recording").setView(view) .setPositiveButton("Record", (dialog, whichButton) -> { String filename = et_filename.getText().toString(); final int stopAfterUnit = sp_stopAfter.getSelectedItemPosition(); final int stopAfterValue = Integer.parseInt(et_stopAfter.getText().toString()); //todo check filename // Set the frequency in the source: if (et_frequency.getText().length() == 0) return; double freq = Double.parseDouble(et_frequency.getText().toString()); if (freq < maxFreqMHz) freq = freq * 1000000; if (freq <= rxFrequency.getMax() && freq >= rxFrequency.getMin()) rxFrequency.set((long) freq); else { toaster.showLong("Frequency is invalid!"); return; } // Set the sample rate (only if demodulator is off): if (demodulationMode == Demodulator.DEMODULATION_OFF) rxSampleRate.set((Integer) sp_sampleRate.getSelectedItem()); // Open file and start recording: recordingFile = new File(externalDir + "/" + RECORDING_DIR + "/" + filename); recordingFile.getParentFile().mkdir(); // Create directory if it does not yet exist try { scheduler.startRecording(new BufferedOutputStream(new FileOutputStream(recordingFile))); } catch (FileNotFoundException e) { Log.e(LOGTAG, "showRecordingDialog: File not found: " + recordingFile.getAbsolutePath()); } // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putInt(getString(R.string.pref_recordingSampleRate), (Integer) sp_sampleRate.getSelectedItem()); edit.putBoolean(getString(R.string.pref_recordingStopAfterEnabled), cb_stopAfter.isChecked()); edit.putInt(getString(R.string.pref_recordingStopAfterValue), stopAfterValue); edit.putInt(getString(R.string.pref_recordingStopAfterUnit), stopAfterUnit); edit.apply(); analyzerSurface.setRecordingEnabled(true); updateActionBar(); // if stopAfter was selected, start thread to supervise the recording: if (cb_stopAfter.isChecked()) { final String recorderSuperviserName = "Supervisor Thread"; Thread supervisorThread = new Thread(() -> { Log.i(LOGTAG, "recording_superviser: Supervisor Thread started. (Thread: " + recorderSuperviserName + ")"); try { long startTime = System.currentTimeMillis(); boolean stop = false; // We check once per half a second if the stop criteria is met: Thread.sleep(500); while (recordingFile != null && !stop) { switch (stopAfterUnit) { // see arrays.xml - recording_stopAfterUnit case 0: /* MB */ if (recordingFile.length() / 1000000 >= stopAfterValue) stop = true; break; case 1: /* GB */ if (recordingFile.length() / 1000000000 >= stopAfterValue) stop = true; break; case 2: /* sec */ if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000) stop = true; break; case 3: /* min */ if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000 * 60) stop = true; break; } } // stop recording: stopRecording(); } catch (InterruptedException e) { // todo: shouldn't we call stopRecording() here? how about finally{}? Log.e(LOGTAG, "recording_superviser: Interrupted!"); } catch (NullPointerException e) { Log.e(LOGTAG, "recording_superviser: Recording file is null!"); } Log.i(LOGTAG, "recording_superviser: Supervisor Thread stopped. (Thread: " + recorderSuperviserName + ")"); }, recorderSuperviserName); supervisorThread.start(); } }).setNegativeButton("Cancel", (dialog, whichButton) -> { // do nothing }).show().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); }
From source file:com.haibison.android.anhuu.FragmentFiles.java
/** * Confirms user to create new directory. *///from w w w.j a va 2 s . c o m private void showNewDirectoryCreationDialog() { final AlertDialog dialog = Dlg.newAlertDlg(getActivity()); View view = getLayoutInflater(null).inflate(R.layout.anhuu_f5be488d_simple_text_input_view, null); final EditText textFile = (EditText) view.findViewById(R.id.anhuu_f5be488d_text1); textFile.setHint(R.string.anhuu_f5be488d_hint_folder_name); textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { UI.showSoftKeyboard(v, false); dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick(); return true; } return false; } }); dialog.setView(view); dialog.setTitle(R.string.anhuu_f5be488d_cmd_new_folder); dialog.setIcon(android.R.drawable.ic_menu_add); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final String name = textFile.getText().toString().trim(); if (!FileUtils.isFilenameValid(name)) { Dlg.toast(getActivity(), getString(R.string.anhuu_f5be488d_pmsg_filename_is_invalid, name), Dlg.LENGTH_SHORT); return; } new LoadingDialog<Void, Void, Uri>(getActivity(), false) { @Override protected Uri doInBackground(Void... params) { return getActivity().getContentResolver().insert( BaseFile.genContentUriBase(getCurrentLocation().getAuthority()).buildUpon() .appendPath(getCurrentLocation().getLastPathSegment()) .appendQueryParameter(BaseFile.PARAM_NAME, name) .appendQueryParameter(BaseFile.PARAM_FILE_TYPE, Integer.toString(BaseFile.FILE_TYPE_DIRECTORY)) .build(), null); }// doInBackground() @Override protected void onPostExecute(Uri result) { super.onPostExecute(result); if (result != null) { Dlg.toast(getActivity(), getString(R.string.anhuu_f5be488d_msg_done), Dlg.LENGTH_SHORT); } else Dlg.toast(getActivity(), getString(R.string.anhuu_f5be488d_pmsg_cannot_create_folder, name), Dlg.LENGTH_SHORT); }// onPostExecute() }.execute(); }// onClick() }); dialog.show(); UI.showSoftKeyboard(textFile, true); final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonOk.setEnabled(false); textFile.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { /* * Do nothing. */ }// onTextChanged() @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { /* * Do nothing. */ }// beforeTextChanged() @Override public void afterTextChanged(Editable s) { buttonOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim())); }// afterTextChanged() }); }