Advertisement
MDRams

Untitled

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