Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package yo.tantebestemmie;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.media.MediaPlayer;
- import android.os.Bundle;
- import android.util.DisplayMetrics;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.CheckBox;
- import android.widget.CompoundButton;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.android.volley.RequestQueue;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.toolbox.StringRequest;
- import com.android.volley.toolbox.Volley;
- import com.mkiisoft.keysaver.KeySaver;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- public class Popup1 extends Activity {
- public TextView textViewResult;
- public TextView textView2;
- public TextView textView3;
- public TextView textView4;
- MediaPlayer buttonSound;
- public String newString;
- public String newString2;
- public String newString3;
- public String newString4;
- public String newString5;
- public String newString6;
- public String risultato;
- public ArrayList<String> builder = new ArrayList<String>();
- public CheckBox check;
- public CheckBox check2;
- public CheckBox check3;
- public CheckBox check4;
- public CheckBox check5;
- public CheckBox check6;
- public ProgressDialog loading;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.popup1);
- textViewResult = (TextView) findViewById(R.id.textViewResult);
- textView2 = (TextView) findViewById(R.id.textView2);
- textView3 = (TextView) findViewById(R.id.textView3);
- textView4 = (TextView) findViewById(R.id.textView4);
- buttonSound = MediaPlayer.create(Popup1.this, R.raw.scribble);
- DisplayMetrics dm = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(dm);
- int width = dm.widthPixels;
- int height = dm.heightPixels;
- getWindow().setLayout((int) (width * 1.), (int) (height * .4));
- final CheckBox checkBox5 = (CheckBox) findViewById(R.id.checkBox5);
- checkView(checkBox5, "holacheck5", newString5);
- final CheckBox checkBox6 = (CheckBox) findViewById(R.id.checkBox6);
- checkView(checkBox6, "holacheck6", newString6);
- isChecked(checkBox5, "holacheck5");
- isChecked(checkBox6, "holacheck6");
- getData();
- }
- public void isChecked(final CheckBox view, String key){
- if(view != null){
- if(KeySaver.isExist(Popup1.this, key)){
- view.setChecked(KeySaver.getBoolSavedShare(Popup1.this, key));
- }else{
- view.setChecked(false);
- }
- }
- }
- public void getData() {
- loading = ProgressDialog.show(this,"Please wait...","Fetching...",false,false);
- StringRequest stringRequest = new StringRequest(Config.DATA_URL, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- loading.dismiss();
- showJSON(response);
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Toast.makeText(Popup1.this, error.getMessage().toString(), Toast.LENGTH_LONG).show();
- }
- });
- RequestQueue requestQueue = Volley.newRequestQueue(this);
- requestQueue.add(stringRequest);
- StringRequest stringRequest2 = new StringRequest(Config.DATA_URL2, new Response.Listener<String>() {
- @Override
- public void onResponse(String response2) {
- loading.dismiss();
- showJSON2(response2);
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Toast.makeText(Popup1.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
- }
- });
- RequestQueue requestQueue2 = Volley.newRequestQueue(this);
- requestQueue2.add(stringRequest2);
- StringRequest stringRequest3 = new StringRequest(Config.DATA_URL3, new Response.Listener<String>() {
- @Override
- public void onResponse(String response3) {
- loading.dismiss();
- showJSON3(response3);
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Toast.makeText(Popup1.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
- }
- });
- RequestQueue requestQueue3 = Volley.newRequestQueue(this);
- requestQueue3.add(stringRequest3);
- StringRequest stringRequest4 = new StringRequest(Config.DATA_URL4, new Response.Listener<String>() {
- @Override
- public void onResponse(String response4) {
- loading.dismiss();
- showJSON4(response4);
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Toast.makeText(Popup1.this,error.getMessage().toString(),Toast.LENGTH_LONG).show();
- }
- });
- RequestQueue requestQueue4 = Volley.newRequestQueue(this);
- requestQueue4.add(stringRequest4);
- }
- public void showJSON(String response){
- String ID="";
- String Price="";
- String WeightUnits = "";
- String PWU = "";
- try {
- JSONObject jsonObject = new JSONObject(response);
- JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
- JSONObject collegeData = result.getJSONObject(0);
- ID = collegeData.getString(Config.KEY_ID);
- Price = collegeData.getString(Config.KEY_Price);
- WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
- PWU = collegeData.getString(Config.KEY_PWU);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- textViewResult.setText("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units:\t" + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
- newString = String.valueOf("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units:\t" + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
- final CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox);
- checkView(checkBox1, "holacheck", newString);
- isChecked(checkBox1, "holacheck");
- }
- public void showJSON2(String response2){
- String ID="";
- String Price="";
- String WeightUnits = "";
- String PWU = "";
- try {
- JSONObject jsonObject = new JSONObject(response2);
- JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY2);
- JSONObject collegeData = result.getJSONObject(0);
- ID = collegeData.getString(Config.KEY_ID);
- Price = collegeData.getString(Config.KEY_Price);
- WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
- PWU = collegeData.getString(Config.KEY_PWU);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- textView2.setText("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units: " + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
- newString2 = String.valueOf("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units:\t" + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
- final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
- checkView(checkBox2, "holacheck2", newString2);
- isChecked(checkBox2, "holacheck2");
- }
- public void showJSON3(String response3){
- String ID="";
- String Price="";
- String WeightUnits = "";
- String PWU = "";
- try {
- JSONObject jsonObject = new JSONObject(response3);
- JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY3);
- JSONObject collegeData = result.getJSONObject(0);
- ID = collegeData.getString(Config.KEY_ID);
- Price = collegeData.getString(Config.KEY_Price);
- WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
- PWU = collegeData.getString(Config.KEY_PWU);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- textView3.setText("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units: "+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU);
- newString3 = String.valueOf("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units:\t" + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
- final CheckBox checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
- checkView(checkBox3, "holacheck3", newString3);
- isChecked(checkBox3, "holacheck3");
- }
- public void showJSON4(String response4){
- String ID="";
- String Price="";
- String WeightUnits = "";
- String PWU = "";
- try {
- JSONObject jsonObject = new JSONObject(response4);
- JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY4);
- JSONObject collegeData = result.getJSONObject(0);
- ID = collegeData.getString(Config.KEY_ID);
- Price = collegeData.getString(Config.KEY_Price);
- WeightUnits = collegeData.getString(Config.KEY_WeightUnits);
- PWU = collegeData.getString(Config.KEY_PWU);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- textView4.setText("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units: " + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
- newString4 = String.valueOf("ID:\t" + ID + "\nPrice:\t" + Price + "\nWeight/Units:\t" + WeightUnits + "\nPrice per Weight/Units:\t" + PWU);
- final CheckBox checkBox4 = (CheckBox) findViewById(R.id.checkBox4);
- checkView(checkBox4, "holacheck4", newString4);
- isChecked(checkBox4, "holacheck4");
- }
- public void checkView(final CheckBox view, final String key){
- view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (view.isChecked()) {
- KeySaver.saveShare(Popup1.this, key, check.isChecked());
- } else {
- KeySaver.removeKey(Popup1.this, key);
- }
- buttonSound.start();
- }
- });
- }
- public void checkView (final CheckBox view, final String key, final String newString) {
- view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (view.isChecked()) {
- KeySaver.saveShare(Popup1.this, key, view.isChecked());
- builder.add((String.valueOf(newString)));
- builder.add("\n");
- LayoutInflater inflater = getLayoutInflater();
- View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup)findViewById(R.id.toastcustom));
- ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item selected");
- Toast mytoast = new Toast(getBaseContext());
- mytoast.setView(layouttoast);
- mytoast.setDuration(Toast.LENGTH_SHORT);
- mytoast.show();
- } else {
- KeySaver.removeKey(Popup1.this, key);
- LayoutInflater inflater = getLayoutInflater();
- View layouttoast = inflater.inflate(R.layout.toastattempt, (ViewGroup)findViewById(R.id.toastcustom));
- ((TextView) layouttoast.findViewById(R.id.texttoast)).setText("Item deselected");
- Toast mytoast = new Toast(getBaseContext());
- mytoast.setView(layouttoast);
- mytoast.setDuration(Toast.LENGTH_SHORT);
- mytoast.show();
- }
- buttonSound.start();
- }
- });
- }
- @Override
- public void finish() {
- String risultato = builder.toString().replace("[", "").replace("]", "");
- // Prepare data intent
- Intent data = new Intent();
- data.putExtra("result", risultato);
- setResult(1, data );
- super.finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement