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

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


package cl.datacomputer.alejandrob.newgpsjoysticl;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.Toast;
import cl.datacomputer.alejandrob.newgpsjoysticl.sqlite.data.PokestopsContract;
import com.facebook.internal.NativeProtocol;
import com.facebook.internal.ServerProtocol;
import com.facebook.share.internal.ShareConstants;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import cz.msebera.android.httpclient.Header;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;

public class AdministratorFragment extends Fragment {
    SimpleAdapter adapter;
    SimpleAdapter adapter2;
    List<Map<String, String>> list;
    List<Map<String, String>> list2;
    ArrayList<Solicitud> solicitudesGym;
    ArrayList<Solicitud> solicitudesStop;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.administrator_layout, container, false);
        TabHost host = (TabHost) view.findViewById(R.id.tabHostAdmin);
        this.solicitudesStop = new ArrayList<>();
        this.solicitudesGym = new ArrayList<>();
        this.list = new ArrayList();
        this.list2 = new ArrayList();
        getDatos(host, view);
        return view;
    }

    public void getDatos(final TabHost host, final View view) {
        AsyncHttpClient clientRequest = new AsyncHttpClient();
        String ua = new WebView(getContext()).getSettings().getUserAgentString();
        clientRequest.setUserAgent(ua);
        RequestParams params = new RequestParams();
        AsyncHttpClient prueba = new AsyncHttpClient();
        prueba.setUserAgent(ua);
        prueba.post("http://datacomputer.cl/rest/Sync/ver_solicitudesAddToJson.php", params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                try {
                    JSONObject objectJson = new JSONObject(new String(responseBody, "UTF-8"));
                    JSONArray jsonArray = objectJson.getJSONArray("datos");
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject b = jsonArray.getJSONObject(i);
                        Solicitud sol = new Solicitud(b.getInt(ShareConstants.WEB_DIALOG_PARAM_ID), b.getString(PokestopsContract.PokeStopEntry.nombre), b.getString("correo"), b.getString("nombredato"), b.getString("tipo"), b.getString("latitud"), b.getString("longitud"), b.getString("fechacreacion"), b.getString("fechafinalizacion"), b.getString("estado"));
                        if (b.getString("tipo").equals("1")) {
                            AdministratorFragment.this.solicitudesStop.add(sol);
                        } else if (b.getString("tipo").equals("2")) {
                            AdministratorFragment.this.solicitudesGym.add(sol);
                        }
                    }
                    AdministratorFragment.this.inicializarTabHost(host, view);
                } catch (Exception e) {
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                if (statusCode == 404) {
                    Toast.makeText(AdministratorFragment.this.getContext(), "Requested resource not found", 1).show();
                } else if (statusCode == 500) {
                    Toast.makeText(AdministratorFragment.this.getContext(), "Something went wrong at server end", 1).show();
                } else {
                    Toast.makeText(AdministratorFragment.this.getContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]", 1).show();
                }
            }
        });
    }

    public void inicializarTabHost(TabHost host, View view) {
        host.setup();
        ListView mListView = (ListView) view.findViewById(R.id.list_1);
        ListView mListView2 = (ListView) view.findViewById(R.id.list_2);
        int count = this.solicitudesStop.size();
        for (int i = 0; i < count; i++) {
            Map<String, String> map = new HashMap<>();
            map.put("Name", "ID: " + this.solicitudesStop.get(i).getId() + "\nNombre: " + this.solicitudesStop.get(i).getNombredato());
            map.put("Lat", this.solicitudesStop.get(i).getLatitud());
            map.put("Lng", this.solicitudesStop.get(i).getLongitud());
            this.list.add(map);
        }
        int count2 = this.solicitudesGym.size();
        for (int i2 = 0; i2 < count2; i2++) {
            Map<String, String> map2 = new HashMap<>();
            map2.put("Name", "ID: " + this.solicitudesGym.get(i2).getId() + "\nNombre: " + this.solicitudesGym.get(i2).getNombredato());
            map2.put("Lat", this.solicitudesGym.get(i2).getLatitud());
            map2.put("Lng", this.solicitudesGym.get(i2).getLongitud());
            this.list2.add(map2);
        }
        this.adapter = new SimpleAdapter(getContext(), this.list, R.layout.list_item_admin, new String[]{"Name", "Lat", "Lng"}, new int[]{R.id.title, R.id.lat, R.id.lng});
        this.adapter2 = new SimpleAdapter(getContext(), this.list2, R.layout.list_item_admin, new String[]{"Name", "Lat", "Lng"}, new int[]{R.id.title, R.id.lat, R.id.lng});
        mListView.setAdapter((ListAdapter) this.adapter);
        mListView2.setAdapter((ListAdapter) this.adapter2);
        TabHost.TabSpec spec = host.newTabSpec("Tab One");
        spec.setContent(R.id.tab1);
        spec.setIndicator("Request Pokestop");
        host.addTab(spec);
        TabHost.TabSpec spec2 = host.newTabSpec("Tab Two");
        spec2.setContent(R.id.tab2);
        spec2.setIndicator("Request Gym");
        host.addTab(spec2);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView parent, View view2, int position, long id) {
                AdministratorFragment.this.iniciarServicio(AdministratorFragment.this.list.get(position).get("Lat"), AdministratorFragment.this.list.get(position).get("Lng"));
            }
        });
        mListView2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView parent, View view2, int position, long id) {
                AdministratorFragment.this.iniciarServicio(AdministratorFragment.this.list2.get(position).get("Lat"), AdministratorFragment.this.list2.get(position).get("Lng"));
            }
        });
        mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view2, int position, long id) {
                AdministratorFragment.this.alertOpcionesLong(position, 1);
                return true;
            }
        });
        mListView2.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view2, int position, long id) {
                AdministratorFragment.this.alertOpcionesLong(position, 2);
                return true;
            }
        });
    }

    public void alertOpcionesLong(final int position, final int tipo) {
        CharSequence[] colors = {"Add & Finish Request", "Cancel Request"};
        AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getContext(), 2131493060));
        builder.setTitle("Choose an option");
        builder.setItems(colors, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                    case 0:
                        AdministratorFragment.this.addAndFinish(position, tipo);
                        return;
                    case 1:
                        AdministratorFragment.this.rechazarPeticion(position, tipo);
                        return;
                    default:
                        return;
                }
            }
        });
        builder.show();
    }

    public void addAndFinish(final int position, final int tipo) {
        AsyncHttpClient clientRequest = new AsyncHttpClient();
        String ua = new WebView(getContext()).getSettings().getUserAgentString();
        clientRequest.setUserAgent(ua);
        RequestParams params = new RequestParams();
        switch (tipo) {
            case 1:
                params.put(NativeProtocol.WEB_DIALOG_ACTION, ServerProtocol.DIALOG_RETURN_SCOPES_TRUE);
                params.put(ShareConstants.WEB_DIALOG_PARAM_ID, this.solicitudesStop.get(position).getId());
                params.put(PokestopsContract.PokeStopEntry.nombre, this.solicitudesStop.get(position).getNombre());
                params.put("correo", this.solicitudesStop.get(position).getCorreo());
                params.put("nombredato", this.solicitudesStop.get(position).getNombredato());
                params.put("tipo", this.solicitudesStop.get(position).getTipo());
                params.put("latitud", this.solicitudesStop.get(position).getLatitud());
                params.put("longitud", this.solicitudesStop.get(position).getLongitud());
                params.put("fechacreacion", this.solicitudesStop.get(position).getFechacreacion());
                params.put("estado", "In Process");
                break;
            case 2:
                params.put(NativeProtocol.WEB_DIALOG_ACTION, ServerProtocol.DIALOG_RETURN_SCOPES_TRUE);
                params.put(ShareConstants.WEB_DIALOG_PARAM_ID, this.solicitudesGym.get(position).getId());
                params.put(PokestopsContract.PokeStopEntry.nombre, this.solicitudesGym.get(position).getNombre());
                params.put("correo", this.solicitudesGym.get(position).getCorreo());
                params.put("nombredato", this.solicitudesGym.get(position).getNombredato());
                params.put("tipo", this.solicitudesGym.get(position).getTipo());
                params.put("latitud", this.solicitudesGym.get(position).getLatitud());
                params.put("longitud", this.solicitudesGym.get(position).getLongitud());
                params.put("fechacreacion", this.solicitudesGym.get(position).getFechacreacion());
                params.put("estado", "In Process");
                break;
        }
        AsyncHttpClient prueba = new AsyncHttpClient();
        prueba.setUserAgent(ua);
        prueba.get("http://datacomputer.cl/rest/Sync/ver_solicitudesAdd.php", params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                try {
                    switch (tipo) {
                        case 1:
                            AdministratorFragment.this.list.remove(position);
                            AdministratorFragment.this.adapter.notifyDataSetChanged();
                            break;
                        case 2:
                            AdministratorFragment.this.list2.remove(position);
                            AdministratorFragment.this.adapter2.notifyDataSetChanged();
                            break;
                    }
                } catch (Exception e) {
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                if (statusCode == 404) {
                    Toast.makeText(AdministratorFragment.this.getContext(), "Requested resource not found", 1).show();
                } else if (statusCode == 500) {
                    Toast.makeText(AdministratorFragment.this.getContext(), "Something went wrong at server end", 1).show();
                } else {
                    Toast.makeText(AdministratorFragment.this.getContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]", 1).show();
                }
            }
        });
    }

    public void rechazarPeticion(final int position, final int tipo) {
        AsyncHttpClient clientRequest = new AsyncHttpClient();
        String ua = new WebView(getContext()).getSettings().getUserAgentString();
        clientRequest.setUserAgent(ua);
        RequestParams params = new RequestParams();
        switch (tipo) {
            case 1:
                params.put("cancelar", ServerProtocol.DIALOG_RETURN_SCOPES_TRUE);
                params.put(ShareConstants.WEB_DIALOG_PARAM_ID, this.solicitudesStop.get(position).getId());
                params.put(PokestopsContract.PokeStopEntry.nombre, this.solicitudesStop.get(position).getNombre());
                params.put("correo", this.solicitudesStop.get(position).getCorreo());
                params.put("nombredato", this.solicitudesStop.get(position).getNombredato());
                params.put("tipo", this.solicitudesStop.get(position).getTipo());
                params.put("latitud", this.solicitudesStop.get(position).getLatitud());
                params.put("longitud", this.solicitudesStop.get(position).getLongitud());
                params.put("fechacreacion", this.solicitudesStop.get(position).getFechacreacion());
                params.put("estado", "In Process");
                break;
            case 2:
                params.put("cancelar", ServerProtocol.DIALOG_RETURN_SCOPES_TRUE);
                params.put(ShareConstants.WEB_DIALOG_PARAM_ID, this.solicitudesGym.get(position).getId());
                params.put(PokestopsContract.PokeStopEntry.nombre, this.solicitudesGym.get(position).getNombre());
                params.put("correo", this.solicitudesGym.get(position).getCorreo());
                params.put("nombredato", this.solicitudesGym.get(position).getNombredato());
                params.put("tipo", this.solicitudesGym.get(position).getTipo());
                params.put("latitud", this.solicitudesGym.get(position).getLatitud());
                params.put("longitud", this.solicitudesGym.get(position).getLongitud());
                params.put("fechacreacion", this.solicitudesGym.get(position).getFechacreacion());
                params.put("estado", "In Process");
                break;
        }
        AsyncHttpClient prueba = new AsyncHttpClient();
        prueba.setUserAgent(ua);
        prueba.get("http://datacomputer.cl/rest/Sync/ver_solicitudesAdd.php", params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                try {
                    switch (tipo) {
                        case 1:
                            AdministratorFragment.this.list.remove(position);
                            AdministratorFragment.this.adapter.notifyDataSetChanged();
                            break;
                        case 2:
                            AdministratorFragment.this.list2.remove(position);
                            AdministratorFragment.this.adapter2.notifyDataSetChanged();
                            break;
                    }
                } catch (Exception e) {
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                if (statusCode == 404) {
                    Toast.makeText(AdministratorFragment.this.getContext(), "Requested resource not found", 1).show();
                } else if (statusCode == 500) {
                    Toast.makeText(AdministratorFragment.this.getContext(), "Something went wrong at server end", 1).show();
                } else {
                    Toast.makeText(AdministratorFragment.this.getContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]", 1).show();
                }
            }
        });
    }

    public void iniciarServicio(String latitud, String longitud) {
        Log.i("LatLng", "Lat: " + latitud + ", Lng: " + longitud);
        Intent nuevoUno = new Intent(getContext(), (Class<?>) VentanaFlotante.class);
        getContext().stopService(nuevoUno);
        SharedPreferences.Editor ed = ((MainActivity) getActivity()).getSharedpreferences().edit();
        try {
            ed.putString(PokestopsContract.PokeStopEntry.latitude, latitud);
            ed.putString(PokestopsContract.PokeStopEntry.longitude, longitud);
        } catch (Exception e) {
        }
        if (((MainActivity) getActivity()).getSharedpreferences().getString("velocidadX1", "").isEmpty()) {
            ed.putString("velocidadX1", String.valueOf(10));
        }
        ed.commit();
        Intent nuevoDos = new Intent(getContext(), (Class<?>) VentanaFlotante.class);
        Bundle b = new Bundle();
        b.putString("displayName", ((MainActivity) getActivity()).getUser().getDisplayName());
        b.putString("correo", ((MainActivity) getActivity()).getUser().getEmail());
        nuevoDos.putExtras(b);
        getActivity().startService(nuevoDos);
    }
}