private void showUserHashDialog() { String userHash = NavigineApp.Settings.getString("user_hash", ""); LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.user_hash_dialog, null); _userEdit = (EditText) view.findViewById(R.id.user_hash_edit); _userEdit.setText(userHash); _userEdit.setTypeface(Typeface.MONOSPACE); // _userEdit.addTextChangedListener(new TextWatcher() // { // public void afterTextChanged(Editable s) { } // public void beforeTextChanged(CharSequence s, int start, int count, int after) { } // public void onTextChanged(CharSequence s, int start, int before, int count) // { // String text = _userEdit.getText().toString(); // int length = _userEdit.getText().length(); // // if (text.endsWith("-")) // return; // // if (count <= before) // return; // // if (length == 4 || length == 9 || length == 14) // { // _userEdit.setText((text + "-")); // _userEdit.setSelection(length + 1); // } // } // }); AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext); alertBuilder.setView(view); alertBuilder.setTitle("Enter user ID"); alertBuilder.setNegativeButton( getString(R.string.cancel_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int id) {} }); alertBuilder.setPositiveButton( getString(R.string.ok_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int id) { String userHash = _userEdit.getText().toString(); SharedPreferences.Editor editor = NavigineApp.Settings.edit(); editor.putString("user_hash", userHash); editor.commit(); NavigineApp.applySettings(); refreshMapList(); } }); AlertDialog dialog = alertBuilder.create(); dialog.setCanceledOnTouchOutside(false); dialog.show(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().setStatusBarColor(getResources().getColor(R.color.holo_blue_bright)); } listmain = new ArrayList<ConRecItem>(); tm = (EditText) findViewById(R.id.setext); final RecycleItemClickListener itemClickListener = new RecycleItemClickListener() { @Override public void onItemClick(View view, int position) { switch (position) { default: Intent intent = new Intent(searchActivity.this, conActivity.class); Data data = new Data(); File fl = new File("/storage/sdcard0/M++/data/slist.txt"); String spos = data.getData(fl, position + 1); int pos = Integer.valueOf(spos); intent.putExtra("pos", pos); startActivity(intent); break; } } }; int displayWidth = 0; int displayHeight = 0; DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); displayWidth = displayMetrics.widthPixels; displayHeight = displayMetrics.heightPixels; final int rpos = displayWidth / 320; listmain = new ArrayList<ConRecItem>(); ConRecAdapter adapter = new ConRecAdapter(listmain, itemClickListener); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler); recyclerView.setLayoutManager( new StaggeredGridLayoutManager(rpos, StaggeredGridLayoutManager.VERTICAL)); recyclerView.setAdapter(adapter); tm.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence p1, int p2, int p3, int p4) { // TODO: Implement this method } @Override public void onTextChanged(CharSequence p1, int p2, int p3, int p4) { // TODO: Implement this method } @Override public void afterTextChanged(Editable edit) { // TODO listmain = new ArrayList<ConRecItem>(); System.out.println("okokok"); File fs = new File("/storage/sdcard0/M++/data/fs_con.txt"); File fl = new File("/storage/sdcard0/M++/data/slist.txt"); String text = tm.getText().toString(); if (fs.exists()) { listmain = new ArrayList<ConRecItem>(); if (fl.exists()) { fl.delete(); } try { fl.createNewFile(); String reg = ".*" + text + ".*"; FileReader fr = new FileReader(fs); BufferedReader br = new BufferedReader(fr); String temp = null; String s = ""; while ((temp = br.readLine()) != null) { s += temp + "\n"; } String[] ss = s.split("\n"); for (int i = 0; i <= ss.length; i++) { try { if (ss[10 * i].matches(reg)) { ConRecItem p = new ConRecItem(ss[10 * i + 1], ss[10 * i]); listmain.add(p); String spos = String.valueOf(i); Data data = new Data(); data.writeData(fl, spos + "\n", false); } } catch (ArrayIndexOutOfBoundsException e) { } } ConRecAdapter adapter = new ConRecAdapter(listmain, itemClickListener); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler); recyclerView.setLayoutManager( new StaggeredGridLayoutManager(rpos, StaggeredGridLayoutManager.VERTICAL)); recyclerView.setAdapter(adapter); } catch (Exception e) { e.printStackTrace(); } } }; }); }