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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
package it.fedeloper.smartcharging.Controller;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import it.fedeloper.smartcharging.Service.EndPoint;
import it.fedeloper.smartcharging.Service.HttpClient;
import it.fedeloper.smartcharging.Manager.PrefsManager;
import it.fedeloper.smartcharging.R;
import it.fedeloper.smartcharging.Manager.Utils;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ByteArrayBody;
import org.apache.http.entity.mime.content.ContentBody;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class SettingSelectionActivity extends FragmentActivity {
    public static JSONArray arr;
    Context c;
    Activity a;
    JSONArray jsonArray = new JSONArray();
    Map<ImageButton, Integer> mapLoading = new HashMap<ImageButton, Integer>();
    int uploadingImages = 0;
LinearLayout linearAdd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_selection);
        c = this;
        a = this;
        linearAdd=((LinearLayout) findViewById(R.id.linearlocal));
        ArrayAdapter adapter = ArrayAdapter.createFromResource(
                this, R.array.type_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        ((Spinner) findViewById(R.id.spinner3)).setAdapter(adapter);

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

                    obj.put("token", PrefsManager.getToken(c));
                    obj.put("user_id", PrefsManager.getId(c));

                    JSONObject resp = HttpClient.SendHttpPostAsync(EndPoint.MAIN_END_POINT +"/get_locals_by_user.php", obj);


                    arr = resp.getJSONArray("locals");

                    for (int i = 0; i < arr.length(); i++) {
                        JSONObject jo = arr.getJSONObject(i);
                        final View item = LayoutInflater.from(c).inflate(R.layout.local_item, null);
                        ((TextView) item.findViewById(R.id.textname)).setText(jo.getString("nomelocale"));
                        ((TextView) item.findViewById(R.id.textid)).setText(String.valueOf(i + 1));
                   final int i_=i;
                       item.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                Intent i = new Intent(SettingSelectionActivity.this, ManagerActivity.class);
                                i.putExtra("i", i_);
                                startActivity(i);

                            }
                        });

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                ((ViewGroup) a.findViewById(R.id.linear2)).addView(item);
                            }
                        });
                    }

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


            }
        }).start();


    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_setting_selection, menu);
        return true;
    }

    public void addclick(View v) {
        if (linearAdd.getVisibility()==View.GONE)
        {
            linearAdd.setVisibility(View.VISIBLE);
        }
        else
        {
            addLocal();
        }

    }

    private void addLocal() {
        new Thread(new Runnable() {
            public void run() {

                JSONObject obj = new JSONObject();
                try {
                    Log.e("òfòsdkjdoigdofjgdl", "3a");
                    final String nomelocale = ((EditText) findViewById(R.id.editText13)).getText().toString();
                    final String tel = ((EditText) findViewById(R.id.editText178)).getText().toString();
                    final String email = ((EditText) findViewById(R.id.editText17)).getText().toString();
                    final String descrizione = ((EditText) findViewById(R.id.editText16)).getText().toString();

                    final int tipologia = ((Spinner) findViewById(R.id.spinner3)).getSelectedItemPosition();

                    obj.put("user_id", PrefsManager.getId(c));
                    obj.put("nomelocale", nomelocale);
                    obj.put("descrizione", descrizione);
                    obj.put("tipologia", tipologia);
                    obj.put("telefono", tel);
                    obj.put("lat", "");
                    obj.put("lon", "");
                    obj.put("indirizzo", "");
                    obj.put("email", email);
                    obj.put("imgs", jsonArray);
                    obj.put("sito", ((EditText) findViewById(R.id.editText14)).getText().toString());
                    //obj.put("sito", "erer");
                    obj.put("token", PrefsManager.getToken(c));


                    Log.e("òfòsdkjdoigdofjgdl", "4a");
                    JSONObject resp = HttpClient.SendHttpPostAsync(EndPoint.MAIN_END_POINT + "/add_locale.php", obj);
                    int code = resp.getInt("return");
                    Log.e("òfòsdkjdoigdofjgdl", "5a");

                    switch (code) {
                        case 0: {

                            String s1 = resp.getString("local_id");
                            Log.e("òfòsdkjdoigdofjgdl", s1);
                            PrefsManager.addLocal(c, s1, nomelocale);
                            Log.e("òfòsdkjdoigdofjgdl", "6a");

                            PrefsManager.setLocaleType(c);







                            Intent i = new Intent(SettingSelectionActivity.this, SetPositionLocaleActivity.class);
                            i.putExtra("idlocale", resp.getInt("local_id"));
                            startActivity(i);
finish();

                        }
                        break;
                        case 1: {
                            registerFailed(getString(R.string.username_busy));
                        }
                        break;
                        case 2: {
                            registerFailed(getString(R.string.email_busy));
                        }
                        break;
                        default: {
                            registerFailed("Server Error");
                        }
                    }

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

    private void registerFailed(final String error) {
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                AlertDialog.Builder dlgAlert = new AlertDialog.Builder(SettingSelectionActivity.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 addimage(View v) {
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, 1000);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
        super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

        switch (requestCode) {
            case 1000:
                if (resultCode == RESULT_OK) {
                    Uri selectedImage = imageReturnedIntent.getData();
                    InputStream imageStream = null;
                    try {
                        imageStream = getContentResolver().openInputStream(selectedImage);
                        final Bitmap yourSelectedImage = Utils.getOptimizedBitmap(BitmapFactory.decodeStream(imageStream), 2000);
                        final ImageButton image = new ImageButton(c);
                        image.setScaleType(ImageView.ScaleType.FIT_CENTER);
                        image.setLayoutParams(new LinearLayout.LayoutParams((int) Utils.dpToPx(80, c), (int) Utils.dpToPx(80, c)));
                        image.setImageBitmap(Utils.getOptimizedBitmap(yourSelectedImage, 300));

                        image.setBackgroundColor(getResources().getColor(R.color.btn_background));
                        ((LinearLayout) findViewById(R.id.linearLayout122)).addView(image);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Animation aAnimation = (Animation) AnimationUtils.loadAnimation(c, R.anim.zoom);

                                image.startAnimation(aAnimation);

                            }
                        });
                        new Thread(new Runnable() {
                            public void run() {

                                uploadingImages++;

                                MultipartEntity mpEntity = new MultipartEntity();

                                try {


                                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                    yourSelectedImage.compress(Bitmap.CompressFormat.JPEG, 75, baos);
                                    byte[] imageBytes = baos.toByteArray();

                                    ContentBody bab = new ByteArrayBody(imageBytes, "file.jpeg");

                                    mpEntity.addPart("image_file", bab);

                                    JSONObject resp = HttpClient.SendHttpPostDirect(EndPoint.MAIN_END_POINT + "/upload_image.php", mpEntity);
                                    int id = resp.getInt("return");
                                    switch (id) {
                                        case 0: {
                                            jsonArray.put(resp.getString("image_file"));
                                            mapLoading.put(image, jsonArray.length() - 1);
                                        }
                                        break;
                                        default: {
                                            registerFailed(getString(R.string.avatar_error));
                                        }
                                    }


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

                                }

                                uploadingImages--;
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        image.clearAnimation();

                                        Bitmap del = BitmapFactory.decodeResource(getResources(), R.drawable.delete);

                                        image.setImageBitmap(Utils.mergeBitmaps(Utils.getOptimizedBitmap(yourSelectedImage, 300), del));
                                        image.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {


                                                ArrayList<String> list = new ArrayList<String>();
                                                JSONArray jsonArray1 = (JSONArray) jsonArray;
                                                int len = jsonArray1.length();
                                                if (jsonArray1 != null) {
                                                    for (int i = 0; i < len; i++) {
                                                        try {
                                                            list.add(jsonArray1.get(i).toString());
                                                        } catch (JSONException e) {
                                                            e.printStackTrace();
                                                        }
                                                    }
                                                }
//Remove the element from arraylist
                                                list.remove(mapLoading.get(image));
//Recreate JSON Array
                                                jsonArray = new JSONArray(list);
                                                ((ViewManager) image.getParent()).removeView(image);
                                            }
                                        });
                                    }
                                });

                            }
                        }).start();

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

                }
                break;

        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
525 Diff Diff FFontana picture FFontana Sat 22 Aug, 2015 11:08:25 +0000
524 Diff Diff FFontana picture FFontana Sat 22 Aug, 2015 10:47:42 +0000
521 Diff Diff MStefanelli picture MStefanelli Fri 21 Aug, 2015 12:38:59 +0000
518 Diff Diff FFontana picture FFontana Thu 20 Aug, 2015 14:36:46 +0000
506 Diff Diff FFontana picture FFontana Wed 19 Aug, 2015 17:39:12 +0000
505 FFontana picture FFontana Wed 19 Aug, 2015 08:54:46 +0000