Mew v1.1.3版本的 MD5 值为:2c97fc89b634adccdf2e096067417e16

以下内容为反编译后的 BackgroundTaskGym.java 源代码,内容仅作参考


package cl.datacomputer.alejandrob.newgpsjoysticl.sqlite;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.util.Log;
import cl.datacomputer.alejandrob.newgpsjoysticl.sqlite.data.PokestopsContract;
import cz.msebera.android.httpclient.HttpResponse;
import cz.msebera.android.httpclient.NameValuePair;
import cz.msebera.android.httpclient.client.ClientProtocolException;
import cz.msebera.android.httpclient.client.HttpClient;
import cz.msebera.android.httpclient.client.entity.UrlEncodedFormEntity;
import cz.msebera.android.httpclient.client.methods.HttpPost;
import cz.msebera.android.httpclient.impl.client.DefaultHttpClient;
import cz.msebera.android.httpclient.message.BasicNameValuePair;
import cz.msebera.android.httpclient.util.EntityUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.InflaterInputStream;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class BackgroundTaskGym extends AsyncTask<String, Void, Void> {
    Context context;
    GymController gymController;
    private ProgressDialog prgDialog;
    ContentValues values = new ContentValues();

    public BackgroundTaskGym(Context context) {
        this.context = context;
        this.gymController = new GymController(context);
        this.prgDialog = new ProgressDialog(context);
    }

    @Override
    public Void doInBackground(String... params) {
        String method = params[0];
        if (method.equals("insert_gyms")) {
            updateSQLiteGymsPrueba(params[1]);
        }
        if (method.equals("update_gym")) {
            updateSQlitePruebaStatus(params[1]);
            return null;
        }
        return null;
    }

    private void updateSQlitePruebaStatus(String data) {
        SQLiteDatabase gyms = this.gymController.getWritableDatabase();
        try {
            JSONArray gym = new JSONArray(data);
            this.prgDialog.setMax(gym.length());
            gyms.beginTransaction();
            for (int i = 0; i < gym.length(); i++) {
                JSONObject gymObj = gym.getJSONObject(i);
                this.values = new ContentValues();
                this.values.put("enabled", gymObj.getString("enabled"));
                gyms.update("gym", this.values, "gym_id = ?", new String[]{gymObj.getString("gym_id")});
                this.prgDialog.setProgress(i);
            }
            gyms.setTransactionSuccessful();
        } catch (JSONException e) {
            e.printStackTrace();
        } finally {
            gyms.endTransaction();
        }
        this.prgDialog.setCancelable(true);
        Activity activity = (Activity) this.context;
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                BackgroundTaskGym.this.prgDialog.hide();
            }
        });
    }

    @Override
    protected void onPreExecute() {
        this.prgDialog.setCancelable(false);
        this.prgDialog.setMessage("Transferring Data from Remote Database DB. Please wait...");
        this.prgDialog.setProgressStyle(1);
        this.prgDialog.show();
    }

    private void updateSQLiteGymsPrueba(String response) {
        try {
            JSONObject jsonobj = new JSONObject(response);
            JSONArray arr = jsonobj.getJSONArray("gym");
            if (arr.length() != 0) {
                this.prgDialog.setMax(arr.length());
                SQLiteDatabase gyms = this.gymController.getWritableDatabase();
                gyms.beginTransaction();
                for (int i = 0; i < arr.length(); i++) {
                    try {
                        JSONObject obj = arr.getJSONObject(i);
                        this.values = new ContentValues();
                        this.values.put("gym_id", obj.get("gym_id").toString());
                        this.values.put(PokestopsContract.PokeStopEntry.nombre, obj.get(PokestopsContract.PokeStopEntry.nombre).toString());
                        this.values.put("team_id", obj.get("team_id").toString());
                        this.values.put("guard_pokemon_id", obj.get("guard_pokemon_id").toString());
                        this.values.put("gym_points", obj.get("gym_points").toString());
                        this.values.put("enabled", obj.get("enabled").toString());
                        this.values.put(PokestopsContract.PokeStopEntry.latitude, obj.get(PokestopsContract.PokeStopEntry.latitude).toString());
                        this.values.put(PokestopsContract.PokeStopEntry.longitude, obj.get(PokestopsContract.PokeStopEntry.longitude).toString());
                        this.values.put(PokestopsContract.PokeStopEntry.last_modified, obj.get(PokestopsContract.PokeStopEntry.last_modified).toString());
                        this.values.put("last_scanned", obj.get("last_scanned").toString());
                        this.values.put("num", obj.get("num").toString());
                        gyms.insert("gym", null, this.values);
                        this.prgDialog.setProgress(i);
                    } catch (Exception e) {
                        gyms.endTransaction();
                    } catch (Throwable th) {
                        gyms.endTransaction();
                        throw th;
                    }
                }
                gyms.setTransactionSuccessful();
                gyms.endTransaction();
            }
        } catch (JSONException e2) {
        }
        this.prgDialog.setCancelable(true);
        Activity activity = (Activity) this.context;
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                BackgroundTaskGym.this.prgDialog.hide();
            }
        });
    }

    private void updateSQLiteGyms(String mysqlGym, String sqliteGym, String ua) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://datacomputer.cl/rest/Sync/obtener_gyms.php");
        httppost.setHeader("User-Agent", ua);
        httppost.addHeader("User-Agent", ua);
        List<NameValuePair> nameValuePairs = new ArrayList<>(2);
        nameValuePairs.add(new BasicNameValuePair("rowsmysql", String.valueOf(mysqlGym)));
        nameValuePairs.add(new BasicNameValuePair("rowssqlite", String.valueOf(sqliteGym)));
        try {
            httppost.setEntity(new UrlEncodedFormEntity((List<? extends NameValuePair>) nameValuePairs));
            try {
                HttpResponse response = httpclient.execute(httppost);
                response.setHeader("User-Agent", ua);
                String responseBody = EntityUtils.toString(response.getEntity());
                JSONObject jsonobj = new JSONObject(responseBody);
                JSONArray arr = jsonobj.getJSONArray("gym");
                if (arr.length() != 0) {
                    SQLiteDatabase gyms = this.gymController.getWritableDatabase();
                    gyms.beginTransaction();
                    for (int i = 0; i < arr.length(); i++) {
                        try {
                            JSONObject obj = arr.getJSONObject(i);
                            this.values = new ContentValues();
                            this.values.put("gym_id", obj.get("gym_id").toString());
                            this.values.put(PokestopsContract.PokeStopEntry.nombre, obj.get(PokestopsContract.PokeStopEntry.nombre).toString());
                            this.values.put("team_id", obj.get("team_id").toString());
                            this.values.put("guard_pokemon_id", obj.get("guard_pokemon_id").toString());
                            this.values.put("gym_points", obj.get("gym_points").toString());
                            this.values.put("enabled", obj.get("enabled").toString());
                            this.values.put(PokestopsContract.PokeStopEntry.latitude, obj.get(PokestopsContract.PokeStopEntry.latitude).toString());
                            this.values.put(PokestopsContract.PokeStopEntry.longitude, obj.get(PokestopsContract.PokeStopEntry.longitude).toString());
                            this.values.put(PokestopsContract.PokeStopEntry.last_modified, obj.get(PokestopsContract.PokeStopEntry.last_modified).toString());
                            this.values.put("last_scanned", obj.get("last_scanned").toString());
                            this.values.put("num", obj.get("num").toString());
                            gyms.insert("gym", null, this.values);
                        } catch (Exception e) {
                            return;
                        } finally {
                            gyms.endTransaction();
                        }
                    }
                    gyms.setTransactionSuccessful();
                }
            } catch (ClientProtocolException e2) {
                e2.printStackTrace();
            } catch (IOException e3) {
                e3.printStackTrace();
            } catch (JSONException e4) {
            }
        } catch (UnsupportedEncodingException e5) {
            e5.printStackTrace();
        }
    }

    public static String unzipString(byte[] compressed) {
        try {
            byte[] input = new byte[compressed.length + 1];
            System.arraycopy(compressed, 0, input, 0, compressed.length);
            input[compressed.length] = 0;
            ByteArrayInputStream bin = new ByteArrayInputStream(input);
            InflaterInputStream in = new InflaterInputStream(bin);
            ByteArrayOutputStream bout = new ByteArrayOutputStream(512);
            while (true) {
                int b = in.read();
                if (b != -1) {
                    bout.write(b);
                } else {
                    bout.close();
                    String unzipped = bout.toString();
                    return unzipped;
                }
            }
        } catch (IOException io) {
            Log.i("ErrorDecompress", io.getMessage());
            return null;
        }
    }
}