Guest User

Untitled

a guest
Nov 8th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:app="http://schemas.android.com/apk/res-auto"
  5. xmlns:tools="http://schemas.android.com/tools"
  6. android:orientation="horizontal"
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. tools:context="com.example.batuhan.qrcodereader.ActivityUserProfile"
  10.  
  11. android:paddingLeft="16dp"
  12. android:paddingRight="16dp"
  13. android:paddingTop="16dp"
  14. android:paddingBottom="16dp">
  15. </Relativelayout>
  16.  
  17. public class ActivityUserProfile extends AppCompatActivity {
  18.  
  19.  
  20. private ZXingScannerView scannerView;
  21.  
  22.  
  23. public static final String LOGIN_URL = "http://www.HHH.com/QR_Users_Select.php";
  24.  
  25. public static final String KEY_USERNAME = "username";
  26. public static final String KEY_PASSWORD = "password";
  27.  
  28.  
  29. private TextView txt_ViewUsername;
  30. public static EditText edt_Productname;
  31. public static EditText edt_Productcode;
  32. public static EditText edt_Productweight;
  33. public static EditText edt_Productprice;
  34.  
  35. private Button btn_addToCart;
  36. private Button btn_Scan;
  37. private Button btn_seeProd;
  38.  
  39. String resultCode;
  40.  
  41. public String prodName;
  42. public String prodCode;
  43. public String prodWeight;
  44. public String prodPrice;
  45.  
  46. @Override
  47. protected void onCreate(Bundle savedInstanceState) {
  48. super.onCreate(savedInstanceState);
  49. setContentView(R.layout.activity_user_profile);
  50.  
  51. txt_ViewUsername = (TextView) findViewById(R.id.txt_ViewUsername);
  52. edt_Productname = (EditText) findViewById(R.id.edt_ProdName);
  53. edt_Productcode = (EditText) findViewById(R.id.edt_ProdCode);
  54. edt_Productweight= (EditText) findViewById(R.id.edt_ProdWeight);
  55. edt_Productprice = (EditText) findViewById(R.id.edt_ProdPrice);
  56.  
  57. edt_Productcode.setEnabled(true);
  58. edt_Productname.setEnabled(true);
  59. edt_Productweight.setEnabled(true);
  60. edt_Productprice.setEnabled(true);
  61.  
  62. Intent i = getIntent();
  63. txt_ViewUsername.setText("Sayın "+ i.getStringExtra(ActivityUserProfile.KEY_USERNAME) +" marketimize hoşgeldiniz.");
  64.  
  65.  
  66.  
  67. btn_Scan = (Button) findViewById(R.id.btn_scan);
  68. btn_Scan.setOnClickListener(new OnClickListener() {
  69. @Override
  70. public void onClick(View v) {
  71. scanCode();
  72.  
  73. }
  74. });
  75.  
  76.  
  77. btn_seeProd = (Button) findViewById(R.id.btn_seeProd);
  78. btn_seeProd.setOnClickListener(new OnClickListener() {
  79. @Override
  80. public void onClick(View v) {
  81.  
  82. Intent intent = new Intent(getApplicationContext(),ProductView.class);
  83. startActivity(intent);
  84. }
  85. });
  86.  
  87.  
  88.  
  89.  
  90. btn_addToCart = (Button) findViewById(R.id.btn_addToCart);
  91. btn_addToCart.setOnClickListener(new OnClickListener() {
  92. @Override
  93. public void onClick(View v) {
  94.  
  95. ...
  96. }
  97. });
  98. }
  99.  
  100. public void scanCode()
  101. {
  102. scannerView = new ZXingScannerView(this);
  103. scannerView.setResultHandler(new ZXingScannerResultHandler());
  104.  
  105. setContentView(scannerView);
  106. scannerView.startCamera();
  107.  
  108. }
  109. @Override
  110. public void onPause(){
  111. super.onPause();
  112.  
  113.  
  114. if (scannerView != null) {
  115. scannerView.stopCamera();
  116. scannerView = null;
  117. }
  118.  
  119.  
  120. }
  121.  
  122.  
  123.  
  124. public class ZXingScannerResultHandler implements ZXingScannerView.ResultHandler
  125. {
  126. @Override
  127. public void handleResult(Result result){
  128. try{
  129.  
  130. resultCode = result.getText();
  131. Log.i("Bilgi","ResultCode -> "+resultCode );
  132. setContentView(R.layout.activity_user_profile);
  133. scannerView.removeAllViews();
  134. scannerView.stopCamera();
  135.  
  136. String [] chars = resultCode.split(":");
  137. Log.i("counter",chars.length+"");
  138. Log.i("company",chars[1]);
  139.  
  140. prodName = chars[1];
  141. prodCode = chars[3];
  142. prodWeight =chars[5];
  143. prodPrice = chars[7];
  144.  
  145.  
  146.  
  147. EditText product_name_text = (EditText) findViewById(R.id.edt_ProdName);
  148. EditText product_code_text = (EditText) findViewById(R.id.edt_ProdCode);
  149. EditText product_weight_text= (EditText) findViewById(R.id.edt_ProdWeight);
  150. EditText product_price_text = (EditText) findViewById(R.id.edt_ProdPrice);
  151.  
  152. product_name_text.setText(prodName);
  153. product_code_text.setText(prodCode);
  154. product_weight_text.setText(String.valueOf(prodWeight));
  155. product_price_text.setText(String.valueOf(prodPrice));
  156.  
  157. } catch (NullPointerException nu) {
  158. Toast.makeText(ActivityUserProfile.this,"Gelen data düzenli değil!",Toast.LENGTH_LONG).show();
  159. } catch (Exception ex){
  160. Toast.makeText(ActivityUserProfile.this,"Okuyucuda problem oluştu!",Toast.LENGTH_LONG).show();
  161. Log.e("errors",ex.getMessage());
  162. }
  163. }
  164. }
Add Comment
Please, Sign In to add comment