Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SuppressLint("ShowToast")
- class TheTask extends AsyncTask<String,Void,Void>
- {
- JSONArray jsonobject;
- private MainActivity a;
- ProgressDialog pDialog;
- AppPreferences appPrefs;
- public TheTask(MainActivity a){
- this.a = a;
- pDialog = new ProgressDialog(a);
- appPrefs = new AppPreferences(a.getApplicationContext());
- }
- protected void onPreExecute()
- {
- super.onPreExecute();
- pDialog.setMessage("Conectando...");
- pDialog.setCancelable(false);
- pDialog.show();
- }
- protected Void doInBackground(String ...params)
- {
- jsonobject = JSONfunctions.getJSONfromURL(params[0]);
- return null;
- }
- @SuppressLint({ "CommitPrefEdits", "ShowToast" })
- protected void onPostExecute(Void result)
- {
- super.onPostExecute(result);
- pDialog.setMessage("Descifrando...");
- JSONArray excellent = this.getBack();
- if(excellent != null){
- JSONObject rec = null;
- int id = 0;
- String WebCode = "";
- String IntCode = "";
- try{
- rec = excellent.getJSONObject(0);
- id = rec.getInt("Valid");
- WebCode = rec.getString("WebCode");
- IntCode = rec.getString("InternalCode");
- }catch(Exception e){
- //
- }
- String IIntCode = appPrefs.getInternalCode();
- String IWebCode = appPrefs.getExternalCode();
- boolean IValidity = appPrefs.getValidity();
- if(IIntCode.equals(IntCode) && IWebCode.equals(WebCode) && !IValidity){
- //editor.putBoolean(MainActivity.VALIDITY, true);
- //editor.commit();
- appPrefs.setValidity(true);
- Toast.makeText(a, "Registrado!", 2000).show();
- }else if(!IIntCode.equals(IntCode) && (WebCode.equals("") || WebCode.equals(IWebCode))){
- //editor.putString(MainActivity.EXTERNAL_CODE, "Invalid");
- //editor.commit();
- appPrefs.setExternalCode("Invalid");
- Toast.makeText(a, "Codigo invalido", 2000).show();
- }
- }else{
- Toast.makeText(a, "Codigo invalido", 2000).show();
- }
- pDialog.dismiss();
- a.uCodes();
- a.checkForNext();
- }
- public JSONArray getBack(){
- return jsonobject;
- }
- }
- public void showAlert(){
- final MainActivity a = this;
- AlertDialog.Builder alert = new AlertDialog.Builder(this);
- alert.setTitle("Activación");
- alert.setMessage("Introduzca codigo de activación: ");
- final EditText input = new EditText(this);
- alert.setView(input);
- alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton){
- //editor.putString(EXTERNAL_CODE, input.getText().toString());
- //editor.commit();
- appPrefs.setExternalCode(input.getText().toString());
- uCodes();
- String webpage = "http://www.mobileservices.es/app/confirmcode.php?wc=" + extCode + "&ic=" + intCode;
- TheTask task = new TheTask(a);
- task.execute(webpage);;
- }
- });
- alert.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement