MDRams

Untitled

Nov 16th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.07 KB | None | 0 0
  1. public class Popup1 extends Activity {
  2.  
  3. public TextView textView1;
  4. public TextView textView2;
  5. public TextView textView3;
  6. public TextView textView4;
  7. MediaPlayer buttonSound;
  8. public String newString;
  9. public String newString2;
  10. public String newString3;
  11. public String newString4;
  12. public String newString5;
  13. public String newString6;
  14. public ArrayList<String> builder = new ArrayList<String>();
  15.  
  16. public CheckBox check;
  17. public CheckBox check2;
  18. public CheckBox check3;
  19. public CheckBox check4;
  20. public CheckBox check5;
  21. public CheckBox check6;
  22.  
  23.  
  24. ImageView circle = (ImageView) findViewById(R.id.circle);
  25.  
  26.  
  27.  
  28.  
  29. public ProgressDialog loading;
  30.  
  31. @Override
  32. public void onCreate(Bundle savedInstanceState) {
  33.  
  34. super.onCreate(savedInstanceState);
  35. setContentView(R.layout.popup1);
  36.  
  37. textView1 = (TextView) findViewById(R.id.textViewResult);
  38. textView2 = (TextView) findViewById(R.id.textView2);
  39. textView3 = (TextView) findViewById(R.id.textView3);
  40. textView4 = (TextView) findViewById(R.id.textView4);
  41.  
  42. buttonSound = MediaPlayer.create(Popup1.this, R.raw.scribble);
  43.  
  44. DisplayMetrics dm = new DisplayMetrics();
  45. getWindowManager().getDefaultDisplay().getMetrics(dm);
  46.  
  47. int width = dm.widthPixels;
  48. int height = dm.heightPixels;
  49. getWindow().setLayout((int) (width * 1.), (int) (height * .4));
  50.  
  51.  
  52.  
  53.  
  54. circle.setActivated(!circle.isActivated());
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. final CheckBox checkBox5 = (CheckBox) findViewById(R.id.checkBox5);
  62. checkView(checkBox5, "holacheck5", newString5);
  63.  
  64. final CheckBox checkBox6 = (CheckBox) findViewById(R.id.checkBox6);
  65. checkView(checkBox6, "holacheck6", newString6);
  66.  
  67.  
  68.  
  69.  
  70.  
  71. isChecked(checkBox5, "holacheck5");
  72. isChecked(checkBox6, "holacheck6");
  73.  
  74. getData();
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. public void isChecked(final CheckBox view, String key){
  84. if(view != null){
  85. if(KeySaver.isExist(Popup1.this, key)){
  86. view.setChecked(KeySaver.getBoolSavedShare(Popup1.this, key));
  87.  
  88. circle.setActivated(!circle.isActivated());
  89. }else{
  90. view.setChecked(false);
  91. }
  92. }
  93. }
  94.  
  95. public void getData() {
  96.  
  97. loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,false);
  98.  
  99. StringRequest stringRequest = new StringRequest(Config.DATA_URL, new Response.Listener<String>() {
  100. @Override
  101. public void onResponse(String response) {
  102. loading.dismiss();
  103.  
  104.  
  105. showJSON(response);
  106. }
  107. },
  108. new Response.ErrorListener() {
  109. @Override
  110. public void onErrorResponse(VolleyError error) {
  111. Toast.makeText(Popup1.this, error.getMessage().toString(), Toast.LENGTH_SHORT).show();
  112. }
  113. });
  114.  
  115. RequestQueue requestQueue = Volley.newRequestQueue(this);
  116. requestQueue.add(stringRequest);
  117.  
  118. StringRequest stringRequest2 = new StringRequest(Config.DATA_URL2, new Response.Listener<String>() {
  119. @Override
  120. public void onResponse(String response2) {
  121. loading.dismiss();
  122.  
  123.  
  124. showJSON2(response2);
  125. }
  126. },
  127. new Response.ErrorListener() {
  128. @Override
  129. public void onErrorResponse(VolleyError error) {
  130. Toast.makeText(Popup1.this,error.getMessage().toString(),Toast.LENGTH_SHORT).show();
  131. }
  132. });
  133.  
  134. RequestQueue requestQueue2 = Volley.newRequestQueue(this);
  135. requestQueue2.add(stringRequest2);
  136.  
  137. StringRequest stringRequest3 = new StringRequest(Config.DATA_URL3, new Response.Listener<String>() {
  138. @Override
  139. public void onResponse(String response3) {
  140. loading.dismiss();
  141.  
  142.  
  143. showJSON3(response3);
  144. }
  145. },
  146. new Response.ErrorListener() {
  147. @Override
  148. public void onErrorResponse(VolleyError error) {
  149. Toast.makeText(Popup1.this,error.getMessage().toString(),Toast.LENGTH_SHORT).show();
  150. }
  151. });
  152.  
  153. RequestQueue requestQueue3 = Volley.newRequestQueue(this);
  154. requestQueue3.add(stringRequest3);
  155.  
  156. StringRequest stringRequest4 = new StringRequest(Config.DATA_URL4, new Response.Listener<String>() {
  157. @Override
  158. public void onResponse(String response4) {
  159. loading.dismiss();
  160.  
  161.  
  162. showJSON4(response4);
  163. }
  164. },
  165. new Response.ErrorListener() {
  166. @Override
  167. public void onErrorResponse(VolleyError error) {
  168. Toast.makeText(Popup1.this,error.getMessage().toString(),Toast.LENGTH_SHORT).show();
  169. }
  170. });
  171.  
  172. RequestQueue requestQueue4 = Volley.newRequestQueue(this);
  173. requestQueue4.add(stringRequest4);
  174.  
  175. }
  176.  
  177. public void showJSON(String response){
  178. String ID="";
  179. String Price="";
  180. String WeightUnits = "";
  181. String PWU = "";
  182. try {
  183. JSONObject jsonObject = new JSONObject(response);
  184. JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
  185. JSONObject collegeData = result.getJSONObject(0);
  186. ID = collegeData.getString(Config.KEY_ID);
  187. Price = collegeData.getString(Config.KEY_Price);
  188. WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
  189. PWU = collegeData.getString(Config.KEY_PWU);
  190.  
  191.  
  192.  
  193. } catch (JSONException e) {
  194. e.printStackTrace();
  195. }
  196. textView1.setText("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units:\t" + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
  197.  
  198. newString = String.valueOf("ID:\t" + ID + ",Price:\t" + Price + ", Weight/Units:\t" + WeightUnits + ", Price per Weight/Units:\t" + PWU + ".\n");
  199.  
  200. final CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox);
  201. checkView(checkBox1, "holacheck", newString);
  202. isChecked(checkBox1, "holacheck");
  203.  
  204.  
  205.  
  206.  
  207.  
  208. }
  209.  
  210. public void showJSON2(String response2){
  211. String ID="";
  212. String Price="";
  213. String WeightUnits = "";
  214. String PWU = "";
  215. try {
  216. JSONObject jsonObject = new JSONObject(response2);
  217. JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY2);
  218. JSONObject collegeData = result.getJSONObject(0);
  219. ID = collegeData.getString(Config.KEY_ID);
  220. Price = collegeData.getString(Config.KEY_Price);
  221. WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
  222. PWU = collegeData.getString(Config.KEY_PWU);
  223.  
  224.  
  225. } catch (JSONException e) {
  226. e.printStackTrace();
  227. }
  228. textView2.setText("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units: " + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
  229.  
  230. newString2 = String.valueOf("ID:\t" + ID + ",Price:\t" + Price + ", Weight/Units:\t" + WeightUnits + ", Price per Weight/Units:\t" + PWU + ".\n");
  231.  
  232. final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
  233. checkView(checkBox2, "holacheck2", newString2);
  234.  
  235. isChecked(checkBox2, "holacheck2");
  236.  
  237.  
  238.  
  239.  
  240. }
  241.  
  242. public void showJSON3(String response3){
  243. String ID="";
  244. String Price="";
  245. String WeightUnits = "";
  246. String PWU = "";
  247. try {
  248. JSONObject jsonObject = new JSONObject(response3);
  249. JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY3);
  250. JSONObject collegeData = result.getJSONObject(0);
  251. ID = collegeData.getString(Config.KEY_ID);
  252. Price = collegeData.getString(Config.KEY_Price);
  253. WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
  254. PWU = collegeData.getString(Config.KEY_PWU);
  255.  
  256.  
  257. } catch (JSONException e) {
  258. e.printStackTrace();
  259. }
  260. textView3.setText("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units: "+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU);
  261.  
  262. newString3 = String.valueOf("ID:\t" + ID + ",Price:\t" + Price + ", Weight/Units:\t" + WeightUnits + ", Price per Weight/Units:\t" + PWU + ".\n");
  263.  
  264. final CheckBox checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
  265. checkView(checkBox3, "holacheck3", newString3);
  266.  
  267. isChecked(checkBox3, "holacheck3");
  268.  
  269.  
  270. }
  271.  
  272. public void showJSON4(String response4){
  273. String ID="";
  274. String Price="";
  275. String WeightUnits = "";
  276. String PWU = "";
  277. try {
  278. JSONObject jsonObject = new JSONObject(response4);
  279. JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY4);
  280. JSONObject collegeData = result.getJSONObject(0);
  281. ID = collegeData.getString(Config.KEY_ID);
  282. Price = collegeData.getString(Config.KEY_Price);
  283. WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
  284. PWU = collegeData.getString(Config.KEY_PWU);
  285.  
  286.  
  287. } catch (JSONException e) {
  288. e.printStackTrace();
  289. }
  290. textView4.setText("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units: " + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
  291.  
  292. newString4 = String.valueOf("ID:\t" + ID + ",Price:\t" + Price + ", Weight/Units:\t" + WeightUnits + ", Price per Weight/Units:\t" + PWU + ".\n");
  293.  
  294. final CheckBox checkBox4 = (CheckBox) findViewById(R.id.checkBox4);
  295. checkView(checkBox4, "holacheck4", newString4);
  296.  
  297. isChecked(checkBox4, "holacheck4");
  298. }
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305. public void checkView(final CheckBox view, final String key){
  306. view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  307. @Override
  308. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  309.  
  310. if (view.isChecked()) {
  311. KeySaver.saveShare(Popup1.this, key, check.isChecked());
  312. ((AnimationDrawable) circle.getBackground()).start();
  313. ((AnimationDrawable) circle.getBackground()).start();
  314. circle.setActivated(!circle.isActivated());
  315. } else {
  316. KeySaver.removeKey(Popup1.this, key);
  317. ((AnimationDrawable) circle.getBackground()).start();
  318. circle.setActivated(!circle.isActivated());
  319. }
  320. buttonSound.start();
  321. }
  322. });
  323. }
  324.  
  325. public void checkView (final CheckBox view, final String key, final String newString) {
  326. view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  327. @Override
  328. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  329.  
  330. if (view.isChecked()) {
  331. KeySaver.saveShare(Popup1.this, key, view.isChecked());
  332. builder.add((String.valueOf(newString)));
  333. builder.add("\n");
  334. LayoutInflater inflater = getLayoutInflater();
  335. View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup) findViewById(R.id.toastcustom));
  336. ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item selected");
  337. Toast mytoast = new Toast(getBaseContext());
  338. mytoast.setView(layouttoast);
  339. mytoast.setDuration(Toast.LENGTH_SHORT);
  340. mytoast.show();
  341. ((AnimationDrawable) circle.getBackground()).start();
  342. circle.setActivated(!circle.isActivated());
  343. } else {
  344. KeySaver.removeKey(Popup1.this, key);
  345. LayoutInflater inflater = getLayoutInflater();
  346. View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup) findViewById(R.id.toastcustom));
  347. ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item deselected");
  348. Toast mytoast = new Toast(getBaseContext());
  349. mytoast.setView(layouttoast);
  350. mytoast.setDuration(Toast.LENGTH_SHORT);
  351. mytoast.show();
  352. ((AnimationDrawable) circle.getBackground()).start();
  353. circle.setActivated(!circle.isActivated());
  354. }
  355.  
  356. buttonSound.start();
  357. }
  358. });
  359. }
  360.  
  361.  
  362.  
  363.  
  364. @Override
  365. public void finish() {
  366. String risultato = builder.toString().replace("[", "").replace("]", "");
  367. // Prepare data intent
  368. Intent data = new Intent();
  369. data.putExtra("result", risultato);
  370. setResult(1, data);
  371. super.finish();
  372. }
  373.  
  374.  
  375.  
  376.  
  377.  
  378. }
Advertisement
Add Comment
Please, Sign In to add comment