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 onClick(View inButton) { boolean isErr = false; if (mTitle.getText().toString().length() == 0) { mTitle.setError("Required"); mTitle.setEms(10); isErr = true; } if (mDesc.getText().toString().length() == 0) { mDesc.setActivated(true); mDesc.setError("Required"); isErr = true; } if (inButton.getId() == openWeb.getId()) web.setVisibility(View.VISIBLE); else if (inButton.getId() == mAvail.getId()) startActivity(new Intent(this, CheckActivity.class)); else if (inButton.getId() == mBack.getId()) finish(); else if (inButton.getId() == mSub.getId()) { AlertDialog.Builder al = new AlertDialog.Builder(this); if (isErr) return; else al.setTitle("Continue?") .setIcon(R.drawable.ornament) .setMessage("Your listing is going to be submitted to your chosen category.") .setPositiveButton( "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int x) { payment = new ArrayList<String>(); if (mCard.isChecked()) payment.add("Card"); if (mCheck.isChecked()) payment.add("Check"); if (mOnline.isChecked()) payment.add("Online"); if (mCash.isChecked()) payment.add("Cash"); // Toast.makeText(getApplicationContext(), payment.toString(), // Toast.LENGTH_LONG).show(); Intent intent = new Intent(getApplicationContext(), StartActivity.class); intent.putExtra("Payment", payment); intent.putExtra("Category", mChosenCategory); intent.putExtra("Title", mTitle.getText().toString()); intent.putExtra("Price", mPrice.getText().toString()); intent.putExtra("Description", mDesc.getText().toString()); intent.putExtra("Location", mLocation.getText().toString()); intent.putExtra("Photo", jpegData); startActivity(intent); } }) .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface d, int x) {} }) .show(); } else startActivityForResult( new Intent(this, com.lightbox.android.camera.activities.Camera.class), REQ); }
@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(); } } }; }); }