Advertisement
MDRams

Untitled

Nov 13th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.42 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.content.SharedPreferences;
  7. import android.media.MediaPlayer;
  8. import android.os.Bundle;
  9. import android.preference.PreferenceManager;
  10. import android.util.DisplayMetrics;
  11. import android.view.LayoutInflater;
  12. import android.view.View;
  13. import android.view.ViewGroup;
  14. import android.widget.CheckBox;
  15. import android.widget.CompoundButton;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18.  
  19. import com.android.volley.RequestQueue;
  20. import com.android.volley.Response;
  21. import com.android.volley.VolleyError;
  22. import com.android.volley.toolbox.StringRequest;
  23. import com.android.volley.toolbox.Volley;
  24. import com.mkiisoft.keysaver.KeySaver;
  25.  
  26. import org.json.JSONArray;
  27. import org.json.JSONException;
  28. import org.json.JSONObject;
  29.  
  30. import java.util.ArrayList;
  31.  
  32.  
  33. public class Popup1 extends Activity {
  34.  
  35. private TextView textViewResult;
  36. private TextView textView2;
  37. private TextView textView3;
  38. private TextView textView4;
  39. MediaPlayer buttonSound;
  40. public String newString;
  41. public String newString2;
  42. public String newString3;
  43. public String newString4;
  44. public String risultato;
  45. final ArrayList<String> builder = new ArrayList<String>();
  46.  
  47. private CheckBox check;
  48. private CheckBox check2;
  49. private CheckBox check3;
  50. private CheckBox check4;
  51. private CheckBox check5;
  52. private CheckBox check6;
  53.  
  54. private ProgressDialog loading;
  55.  
  56. @Override
  57. protected void onCreate(Bundle savedInstanceState) {
  58.  
  59. super.onCreate(savedInstanceState);
  60. setContentView(R.layout.popup3);
  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. check = (CheckBox) findViewById(R.id.checkbox);
  78. check2 = (CheckBox) findViewById(R.id.checkBox2);
  79. check3 = (CheckBox) findViewById(R.id.checkBox3);
  80. check4 = (CheckBox) findViewById(R.id.checkBox4);
  81. check5 = (CheckBox) findViewById(R.id.checkBox5);
  82. check6 = (CheckBox) findViewById(R.id.checkBox6);
  83.  
  84. isChecked("holacheck");
  85. isChecked("holacheck2");
  86. isChecked("holacheck3");
  87. isChecked("holacheck4");
  88. isChecked("holacheck5");
  89. isChecked("holacheck6");
  90.  
  91.  
  92. checkView(check, "holacheck");
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. final CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox);
  106.  
  107.  
  108. checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  109. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  110. if (checkBox1.isChecked()) {
  111. KeySaver.saveShare(Popup1.this, "checkbox", checkBox1.isChecked());
  112.  
  113. } else {
  114. KeySaver.removeKey(Popup1.this, "checkbox");
  115. }
  116. buttonSound.start();
  117.  
  118. }
  119. });
  120.  
  121. checkView(checkBox1, "holacheck2");
  122.  
  123.  
  124. final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
  125. checkBox2.setChecked(false);
  126.  
  127. checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  128. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  129. if (checkBox2.isChecked()) {
  130. KeySaver.saveShare(Popup1.this, "checkbox2", checkBox2.isChecked());
  131. buttonSound.start();
  132. } else {
  133. buttonSound.start();
  134. }
  135. }
  136. });
  137.  
  138.  
  139.  
  140. final CheckBox checkBox3 = (CheckBox) findViewById(R.id.checkBox2);
  141. checkBox3.setChecked(false);
  142.  
  143. checkBox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  144. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  145. if (checkBox3.isChecked()) {
  146. builder.add((String.valueOf(newString3)));
  147. builder.add("\n");
  148. LayoutInflater inflater = getLayoutInflater();
  149. View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup) findViewById(R.id.toastcustom));
  150. ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item selected");
  151. Toast mytoast = new Toast(getBaseContext());
  152. mytoast.setView(layouttoast);
  153. mytoast.setDuration(Toast.LENGTH_LONG);
  154. mytoast.show();
  155. buttonSound.start();
  156. } else {
  157. builder.remove(String.valueOf(newString3));
  158. builder.remove("\n");
  159.  
  160. LayoutInflater inflater = getLayoutInflater();
  161. View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup) findViewById(R.id.toastcustom));
  162. ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item deselected");
  163. Toast mytoast = new Toast(getBaseContext());
  164. mytoast.setView(layouttoast);
  165. mytoast.setDuration(Toast.LENGTH_LONG);
  166. mytoast.show();
  167. buttonSound.start();
  168. }
  169. SharedPreferences pref3 = PreferenceManager.getDefaultSharedPreferences(Popup1.this); // 0 - for private mode
  170. SharedPreferences.Editor editor3 = pref3.edit();
  171. editor3.putBoolean("checkbox3", checkBox3.isChecked());
  172. editor3.commit();
  173. if (pref3.getBoolean("checkbox3", false) == true){
  174. checkBox3.setChecked(true);
  175. } else{
  176. checkBox3.setChecked(false);
  177. }
  178. }
  179. });
  180.  
  181.  
  182. final CheckBox checkBox4 = (CheckBox) findViewById(R.id.checkBox2);
  183. checkBox4.setChecked(false);
  184.  
  185. checkBox4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  186. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  187. if (checkBox4.isChecked()) {
  188. builder.add((String.valueOf(newString4)));
  189. builder.add("\n");
  190. LayoutInflater inflater = getLayoutInflater();
  191. View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup) findViewById(R.id.toastcustom));
  192. ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item selected");
  193. Toast mytoast = new Toast(getBaseContext());
  194. mytoast.setView(layouttoast);
  195. mytoast.setDuration(Toast.LENGTH_LONG);
  196. mytoast.show();
  197. buttonSound.start();
  198. } else {
  199. builder.remove(String.valueOf(newString4));
  200. builder.remove("\n");
  201.  
  202. LayoutInflater inflater = getLayoutInflater();
  203. View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup) findViewById(R.id.toastcustom));
  204. ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item deselected");
  205. Toast mytoast = new Toast(getBaseContext());
  206. mytoast.setView(layouttoast);
  207. mytoast.setDuration(Toast.LENGTH_LONG);
  208. mytoast.show();
  209. buttonSound.start();
  210. }
  211. SharedPreferences pref4 = PreferenceManager.getDefaultSharedPreferences(Popup1.this); // 0 - for private mode
  212. SharedPreferences.Editor editor4 = pref4.edit();
  213. editor4.putBoolean("checkbox4", checkBox4.isChecked());
  214. editor4.commit();
  215. if (pref4.getBoolean("checkbox4", false) == true){
  216. checkBox4.setChecked(true);
  217. } else{
  218. checkBox4.setChecked(false);
  219. }
  220. }
  221. });
  222.  
  223.  
  224.  
  225. final CheckBox checkBox5 = (CheckBox) findViewById(R.id.checkBox2);
  226. checkBox5.setChecked(false);
  227.  
  228. checkBox5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  229. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  230. if (checkBox5.isChecked()) {
  231. KeySaver.saveShare(Popup1.this, "checkbox5", checkBox5.isChecked());
  232. buttonSound.start();
  233. }
  234. else {
  235. SharedPreferences pref5 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  236. SharedPreferences.Editor editor5 = pref5.edit();
  237. editor5.putBoolean("checkbox5", checkBox5.isChecked());
  238. editor5.commit();
  239. buttonSound.start();
  240. }
  241.  
  242.  
  243. }
  244. });
  245.  
  246.  
  247.  
  248. final CheckBox checkBox6 = (CheckBox) findViewById(R.id.checkBox2);
  249. checkBox6.setChecked(false);
  250.  
  251. checkBox6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  252. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  253. if (checkBox6.isChecked()) {
  254. LayoutInflater inflater = getLayoutInflater();
  255. View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup) findViewById(R.id.toastcustom));
  256. ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item selected");
  257. Toast mytoast = new Toast(getBaseContext());
  258. mytoast.setView(layouttoast);
  259. mytoast.setDuration(Toast.LENGTH_LONG);
  260. mytoast.show();
  261. buttonSound.start();
  262. } else {
  263.  
  264. LayoutInflater inflater = getLayoutInflater();
  265. View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup) findViewById(R.id.toastcustom));
  266. ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item deselected");
  267. Toast mytoast = new Toast(getBaseContext());
  268. mytoast.setView(layouttoast);
  269. mytoast.setDuration(Toast.LENGTH_LONG);
  270. mytoast.show();
  271. buttonSound.start();
  272. }
  273.  
  274. SharedPreferences pref6 = PreferenceManager.getDefaultSharedPreferences(Popup1.this); // 0 - for private mode
  275. SharedPreferences.Editor editor6 = pref6.edit();
  276. editor6.putBoolean("checkbox6", checkBox6.isChecked());
  277. editor6.commit();
  278. if (pref6.getBoolean("checkbox6", false) == true){
  279. checkBox6.setChecked(true);
  280. } else{
  281. checkBox6.setChecked(false);
  282. }
  283.  
  284.  
  285. }
  286. });
  287.  
  288.  
  289. getData();
  290.  
  291.  
  292.  
  293.  
  294.  
  295. }
  296.  
  297.  
  298. private void checkView(CheckBox view, final String key){
  299. view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  300. @Override
  301. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  302.  
  303. if (check.isChecked()) {
  304. KeySaver.saveShare(Popup1.this, key, check.isChecked());
  305. } else {
  306. KeySaver.removeKey(Popup1.this, key);
  307. }
  308. buttonSound.start();
  309. }
  310. });
  311. }
  312.  
  313.  
  314.  
  315.  
  316. public void isChecked(String key){
  317. if(check != null){
  318. if(KeySaver.isExist(Popup1.this, key)){
  319. check.setChecked(KeySaver.getBoolSavedShare(Popup1.this, key));
  320. }else{
  321. check.setChecked(false);
  322. }
  323. }
  324. }
  325.  
  326. private void getData() {
  327.  
  328. loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,false);
  329.  
  330. StringRequest stringRequest = new StringRequest(Config.DATA_URL, new Response.Listener<String>() {
  331. @Override
  332. public void onResponse(String response) {
  333. loading.dismiss();
  334.  
  335.  
  336. showJSON(response);
  337. }
  338. },
  339. new Response.ErrorListener() {
  340. @Override
  341. public void onErrorResponse(VolleyError error) {
  342. Toast.makeText(Popup1.this, error.getMessage().toString(), Toast.LENGTH_LONG).show();
  343. }
  344. });
  345.  
  346. RequestQueue requestQueue = Volley.newRequestQueue(this);
  347. requestQueue.add(stringRequest);
  348.  
  349. StringRequest stringRequest2 = new StringRequest(Config.DATA_URL2, new Response.Listener<String>() {
  350. @Override
  351. public void onResponse(String response2) {
  352. loading.dismiss();
  353.  
  354.  
  355. showJSON2(response2);
  356. }
  357. },
  358. new Response.ErrorListener() {
  359. @Override
  360. public void onErrorResponse(VolleyError error) {
  361. Toast.makeText(Popup1.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
  362. }
  363. });
  364.  
  365. RequestQueue requestQueue2 = Volley.newRequestQueue(this);
  366. requestQueue2.add(stringRequest2);
  367.  
  368. StringRequest stringRequest3 = new StringRequest(Config.DATA_URL3, new Response.Listener<String>() {
  369. @Override
  370. public void onResponse(String response3) {
  371. loading.dismiss();
  372.  
  373.  
  374. showJSON3(response3);
  375. }
  376. },
  377. new Response.ErrorListener() {
  378. @Override
  379. public void onErrorResponse(VolleyError error) {
  380. Toast.makeText(Popup1.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
  381. }
  382. });
  383.  
  384. RequestQueue requestQueue3 = Volley.newRequestQueue(this);
  385. requestQueue3.add(stringRequest3);
  386.  
  387. StringRequest stringRequest4 = new StringRequest(Config.DATA_URL4, new Response.Listener<String>() {
  388. @Override
  389. public void onResponse(String response4) {
  390. loading.dismiss();
  391.  
  392.  
  393. showJSON4(response4);
  394. }
  395. },
  396. new Response.ErrorListener() {
  397. @Override
  398. public void onErrorResponse(VolleyError error) {
  399. Toast.makeText(Popup1.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
  400. }
  401. });
  402.  
  403. RequestQueue requestQueue4 = Volley.newRequestQueue(this);
  404. requestQueue4.add(stringRequest4);
  405.  
  406. }
  407.  
  408. private void showJSON(String response){
  409. String ID="";
  410. String Price="";
  411. String WeightUnits = "";
  412. String PWU = "";
  413. try {
  414. JSONObject jsonObject = new JSONObject(response);
  415. JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
  416. JSONObject collegeData = result.getJSONObject(0);
  417. ID = collegeData.getString(Config.KEY_ID);
  418. Price = collegeData.getString(Config.KEY_Price);
  419. WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
  420. PWU = collegeData.getString(Config.KEY_PWU);
  421.  
  422.  
  423. } catch (JSONException e) {
  424. e.printStackTrace();
  425. }
  426. textViewResult.setText("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units:\t" + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
  427.  
  428. String newString= (String)("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units:\t"+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU).toString();
  429. }
  430.  
  431. private void showJSON2(String response2){
  432. String ID="";
  433. String Price="";
  434. String WeightUnits = "";
  435. String PWU = "";
  436. try {
  437. JSONObject jsonObject = new JSONObject(response2);
  438. JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY2);
  439. JSONObject collegeData = result.getJSONObject(0);
  440. ID = collegeData.getString(Config.KEY_ID);
  441. Price = collegeData.getString(Config.KEY_Price);
  442. WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
  443. PWU = collegeData.getString(Config.KEY_PWU);
  444.  
  445.  
  446. } catch (JSONException e) {
  447. e.printStackTrace();
  448. }
  449. textView2.setText("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units: "+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU);
  450.  
  451. String newString2= (String)("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units:\t"+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU).toString();
  452.  
  453. }
  454.  
  455. private void showJSON3(String response3){
  456. String ID="";
  457. String Price="";
  458. String WeightUnits = "";
  459. String PWU = "";
  460. try {
  461. JSONObject jsonObject = new JSONObject(response3);
  462. JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY3);
  463. JSONObject collegeData = result.getJSONObject(0);
  464. ID = collegeData.getString(Config.KEY_ID);
  465. Price = collegeData.getString(Config.KEY_Price);
  466. WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
  467. PWU = collegeData.getString(Config.KEY_PWU);
  468.  
  469.  
  470. } catch (JSONException e) {
  471. e.printStackTrace();
  472. }
  473. textView3.setText("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units: "+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU);
  474.  
  475. String newString3= (String)("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units:\t"+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU).toString();
  476.  
  477. }
  478.  
  479. private void showJSON4(String response4){
  480. String ID="";
  481. String Price="";
  482. String WeightUnits = "";
  483. String PWU = "";
  484. try {
  485. JSONObject jsonObject = new JSONObject(response4);
  486. JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY4);
  487. JSONObject collegeData = result.getJSONObject(0);
  488. ID = collegeData.getString(Config.KEY_ID);
  489. Price = collegeData.getString(Config.KEY_Price);
  490. WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
  491. PWU = collegeData.getString(Config.KEY_PWU);
  492.  
  493.  
  494. } catch (JSONException e) {
  495. e.printStackTrace();
  496. }
  497. textView4.setText("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units: "+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU);
  498.  
  499. String newString4= (String)("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units:\t"+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU).toString();
  500.  
  501. }
  502.  
  503. @Override
  504. public void finish() {
  505. String risultato = builder.toString().replace("[", "").replace("]", "");
  506. // Prepare data intent
  507. Intent data = new Intent();
  508. data.putExtra("result", "papparapa. ");
  509. setResult(1, data );
  510. super.finish();
  511. }
  512.  
  513. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement