Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package it.fedeloper.smartcharging;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.Locale;

public class SetPositionLocaleActivity extends FragmentActivity    {
    private GoogleMap map;

    private static final long MIN_TIME = 400;
    private static final float MIN_DISTANCE = 1000;
    private Double lat;
    private Double lon;
    Context c;
    int idlocale;
private TextView txt;
    Geocoder geoCoder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_position_locale);
       geoCoder =new Geocoder(this);
       txt= ((TextView) findViewById(R.id.editText9));
        map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
c=this;

        Bundle b = new Bundle();
        b = getIntent().getExtras();

        idlocale= b.getInt("idlocale");
        EditText addressView = (EditText) findViewById(R.id.editText9);
        addressView.setImeOptions(EditorInfo.IME_ACTION_DONE);
        addressView.setOnEditorActionListener(new TextView.OnEditorActionListener()
        {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
            {
                String input;
                if(actionId == EditorInfo.IME_ACTION_DONE)
                {
                    showclick(null);
                    return true;
                }
                return false;
            }
        });
        MyLocation.LocationResult locationResult = new MyLocation.LocationResult(){
            @Override
            public void gotLocation(Location location){
                final LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
                lat=location.getLatitude();
                lon=location.getLongitude();
                Address a=   MyLocation.getAddress(c,location);
                if (a!=null)
                {
                    String s = a.getFeatureName() + ", " + a.getLocality() +", " + a.getAdminArea() + ", " + a.getCountryName();
                    txt.setText(s);

                }

                final CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 17);




                   runOnUiThread(new Runnable() {
                    public void run() {
                        map.animateCamera(cameraUpdate);
                        map.addMarker(new MarkerOptions()
                                .position(latLng)
                                .title("Io"));
                    }
                });





            }
        };

        MyLocation.getLocation(this, locationResult);  }



    public void selclick(View v)
    {
        new Thread(new Runnable() { public void run() {
            JSONObject obj = new JSONObject();
            try {
           Log.e("id localeeeeeeeee", String.valueOf(PrefsManager.getId(c)));
                obj.put("id",idlocale);
                obj.put("lat", lat);
                obj.put("lon", lon);
                obj.put("token", PrefsManager.getToken(c));
                obj.put("indirizzo", txt.getText());

                JSONObject resp=  HttpClient.SendHttpPost("http://svm19842.vps.tagadab.it:8084/smartcharging"+MainActivity.path+"/set_position.php", obj);
                int code = resp.getInt("return");



                switch(code)
                {
                    case 0:{  setSuccesfully();             }break;
                       default:
                    { setFailed("Server Error"); }
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
        }).start();
    }
private  void setSuccesfully()
{
    PrefsManager.InsertThePosition(c);
    Intent i = new Intent( SetPositionLocaleActivity.this, SelectionActivity.class);
    startActivity(i);
    finish();
}
    private void setFailed(final String error) {
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                AlertDialog.Builder dlgAlert = new AlertDialog.Builder(SetPositionLocaleActivity.this);
                dlgAlert.setMessage(error);
                dlgAlert.setTitle(getString(R.string.errore_msg));
                dlgAlert.setPositiveButton("OK", null);
                dlgAlert.setCancelable(true);
                dlgAlert.setPositiveButton("Ok",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                //dismiss the dialog
                            }
                        });
                dlgAlert.create().show();
            }
        });


    }


    public void showclick(View v)
    {

        new Thread(new Runnable() { public void run() {
            JSONObject obj = new JSONObject();
            try {

                try {
                    URL url = new URL("http://maps.googleapis.com/maps/api/geocode/json?address=" + txt.getText().toString() + "&sensor=true");
                    String nullFragment = null;
                    URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), nullFragment);
                    System.out.println("URI " + uri.toString() + " is OK");



                    JSONObject resp=  HttpClient.SendHttpPost(uri.toString()  , obj);

                    Log.e("0", resp.getJSONArray("results").getJSONObject(0).toString());
                    Log.e("0", resp.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").toString());
                    Log.e("0", resp.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("location").toString());

                    JSONObject o=resp.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("location");
                    Double lat=o.getDouble("lat");
                    Double lng=o.getDouble("lng");

                    final LatLng   latLng=new LatLng(lat,lng);
                    if (latLng!=null)
                    {
                        runOnUiThread(new Runnable() {
                            public void run() {
                                CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 17);
                                map.animateCamera(cameraUpdate);
                                map.addMarker(new MarkerOptions()
                                        .position(latLng)
                                        .title("Io"));
                            }
                        });



                    }
                    else
                    {
                        AlertDialog.Builder adb = new AlertDialog.Builder(c);
                        adb.setTitle("Google Map");
                        adb.setMessage("Inserisci un indirizzo corretto");
                        adb.setPositiveButton("chiudi" ,null);
                        adb.show();
                    }

                } catch (MalformedURLException e) {
                    System.out.println("URL " + txt.getText().toString() + " is a malformed URL");
                } catch (URISyntaxException e) {
                    System.out.println("URI " + txt.getText().toString() + " is a malformed URL");
                }









            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
        }).start();




    }


}

Commits for Nextrek/Android/SmartCharging/SmartCharging/app/src/main/java/it/fedeloper/smartcharging/SetPositionLocaleActivity.java

Diff revisions: vs.
Revision Author Commited Message
515 Diff Diff FFontana picture FFontana Thu 20 Aug, 2015 14:19:35 +0000
506 Diff Diff FFontana picture FFontana Wed 19 Aug, 2015 17:39:12 +0000
505 Diff Diff FFontana picture FFontana Wed 19 Aug, 2015 08:54:46 +0000
314 Diff Diff FFontana picture FFontana Tue 14 Jul, 2015 08:40:09 +0000
246 Diff Diff FFontana picture FFontana Thu 09 Jul, 2015 16:11:36 +0000
191 Diff Diff FFontana picture FFontana Tue 30 Jun, 2015 11:06:55 +0000
190 Diff Diff FFontana picture FFontana Sun 28 Jun, 2015 16:25:05 +0000
187 FFontana picture FFontana Wed 24 Jun, 2015 14:16:44 +0000