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.content.SharedPreferences;
- import android.media.MediaPlayer;
- import android.os.Bundle;
- import android.preference.PreferenceManager;
- 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 {
- private TextView textViewResult;
- private TextView textView2;
- private TextView textView3;
- private TextView textView4;
- MediaPlayer buttonSound;
- public String newString;
- public String newString2;
- public String newString3;
- public String newString4;
- public String risultato;
- final ArrayList<String> builder = new ArrayList<String>();
- private CheckBox check;
- private CheckBox check2;
- private CheckBox check3;
- private CheckBox check4;
- private CheckBox check5;
- private CheckBox check6;
- private ProgressDialog loading;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.popup3);
- 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));
- check = (CheckBox) findViewById(R.id.checkbox);
- check2 = (CheckBox) findViewById(R.id.checkBox2);
- check3 = (CheckBox) findViewById(R.id.checkBox3);
- check4 = (CheckBox) findViewById(R.id.checkBox4);
- check5 = (CheckBox) findViewById(R.id.checkBox5);
- check6 = (CheckBox) findViewById(R.id.checkBox6);
- isChecked("holacheck");
- isChecked("holacheck2");
- isChecked("holacheck3");
- isChecked("holacheck4");
- isChecked("holacheck5");
- isChecked("holacheck6");
- checkView(check, "holacheck");
- final CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox);
- checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (checkBox1.isChecked()) {
- KeySaver.saveShare(Popup1.this, "checkbox", checkBox1.isChecked());
- } else {
- KeySaver.removeKey(Popup1.this, "checkbox");
- }
- buttonSound.start();
- }
- });
- checkView(checkBox1, "holacheck2");
- final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
- checkBox2.setChecked(false);
- checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (checkBox2.isChecked()) {
- KeySaver.saveShare(Popup1.this, "checkbox2", checkBox2.isChecked());
- buttonSound.start();
- } else {
- buttonSound.start();
- }
- }
- });
- final CheckBox checkBox3 = (CheckBox) findViewById(R.id.checkBox2);
- checkBox3.setChecked(false);
- checkBox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (checkBox3.isChecked()) {
- builder.add((String.valueOf(newString3)));
- 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_LONG);
- mytoast.show();
- buttonSound.start();
- } else {
- builder.remove(String.valueOf(newString3));
- builder.remove("\n");
- 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_LONG);
- mytoast.show();
- buttonSound.start();
- }
- SharedPreferences pref3 = PreferenceManager.getDefaultSharedPreferences(Popup1.this); // 0 - for private mode
- SharedPreferences.Editor editor3 = pref3.edit();
- editor3.putBoolean("checkbox3", checkBox3.isChecked());
- editor3.commit();
- if (pref3.getBoolean("checkbox3", false) == true){
- checkBox3.setChecked(true);
- } else{
- checkBox3.setChecked(false);
- }
- }
- });
- final CheckBox checkBox4 = (CheckBox) findViewById(R.id.checkBox2);
- checkBox4.setChecked(false);
- checkBox4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (checkBox4.isChecked()) {
- builder.add((String.valueOf(newString4)));
- 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_LONG);
- mytoast.show();
- buttonSound.start();
- } else {
- builder.remove(String.valueOf(newString4));
- builder.remove("\n");
- 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_LONG);
- mytoast.show();
- buttonSound.start();
- }
- SharedPreferences pref4 = PreferenceManager.getDefaultSharedPreferences(Popup1.this); // 0 - for private mode
- SharedPreferences.Editor editor4 = pref4.edit();
- editor4.putBoolean("checkbox4", checkBox4.isChecked());
- editor4.commit();
- if (pref4.getBoolean("checkbox4", false) == true){
- checkBox4.setChecked(true);
- } else{
- checkBox4.setChecked(false);
- }
- }
- });
- final CheckBox checkBox5 = (CheckBox) findViewById(R.id.checkBox2);
- checkBox5.setChecked(false);
- checkBox5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (checkBox5.isChecked()) {
- KeySaver.saveShare(Popup1.this, "checkbox5", checkBox5.isChecked());
- buttonSound.start();
- }
- else {
- SharedPreferences pref5 = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
- SharedPreferences.Editor editor5 = pref5.edit();
- editor5.putBoolean("checkbox5", checkBox5.isChecked());
- editor5.commit();
- buttonSound.start();
- }
- }
- });
- final CheckBox checkBox6 = (CheckBox) findViewById(R.id.checkBox2);
- checkBox6.setChecked(false);
- checkBox6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (checkBox6.isChecked()) {
- 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_LONG);
- mytoast.show();
- buttonSound.start();
- } else {
- 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_LONG);
- mytoast.show();
- buttonSound.start();
- }
- SharedPreferences pref6 = PreferenceManager.getDefaultSharedPreferences(Popup1.this); // 0 - for private mode
- SharedPreferences.Editor editor6 = pref6.edit();
- editor6.putBoolean("checkbox6", checkBox6.isChecked());
- editor6.commit();
- if (pref6.getBoolean("checkbox6", false) == true){
- checkBox6.setChecked(true);
- } else{
- checkBox6.setChecked(false);
- }
- }
- });
- getData();
- }
- private void checkView(CheckBox view, final String key){
- view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (check.isChecked()) {
- KeySaver.saveShare(Popup1.this, key, check.isChecked());
- } else {
- KeySaver.removeKey(Popup1.this, key);
- }
- buttonSound.start();
- }
- });
- }
- public void isChecked(String key){
- if(check != null){
- if(KeySaver.isExist(Popup1.this, key)){
- check.setChecked(KeySaver.getBoolSavedShare(Popup1.this, key));
- }else{
- check.setChecked(false);
- }
- }
- }
- private 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);
- }
- private 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);
- String newString= (String)("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units:\t"+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU).toString();
- }
- private 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);
- String newString2= (String)("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units:\t"+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU).toString();
- }
- private 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);
- String newString3= (String)("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units:\t"+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU).toString();
- }
- private 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);
- String newString4= (String)("ID:\t"+ID+"\nPrice:\t" +Price+ "\nWeight/Units:\t"+ WeightUnits+"\nPrice per Weight/Units:\t"+PWU).toString();
- }
- @Override
- public void finish() {
- String risultato = builder.toString().replace("[", "").replace("]", "");
- // Prepare data intent
- Intent data = new Intent();
- data.putExtra("result", "papparapa. ");
- setResult(1, data );
- super.finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement