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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
package it.fedeloper.smartcharging.Controller;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewManager;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.*;
import it.fedeloper.smartcharging.Manager.PrefsManager;
import it.fedeloper.smartcharging.Manager.Utils;
import it.fedeloper.smartcharging.R;
import it.fedeloper.smartcharging.Service.EndPoint;
import it.fedeloper.smartcharging.Service.HttpClient;
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 RecensioneActivity extends AppCompatActivity {
    private static final int SELECT_PHOTO = 100;
    int idlocale = -1;
    Context c;
    int uploadingImages = 0;
    JSONArray jsonImg = new JSONArray();
    Map<ImageButton, Integer> mapLoading = new HashMap<ImageButton, Integer>();

    HashMap<ImageButton, String> filenames = new HashMap<>();
    JSONObject info ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recensione);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(R.string.recensione_title);

        c = this;
        Bundle b = getIntent().getExtras();

        try {
            info=( new JSONObject(b.getString("json")).getJSONObject("comment"));

            if (info!=null){
                ((EditText) findViewById(R.id.editText10)).setText(info.getString("descrizione"));
                ((RatingBar) findViewById(R.id.ratingBar4)).setRating((float) info.getDouble("voto"));
            }
/*
            new Thread(new Runnable() {
                public void run() {
                    JSONObject obj = new JSONObject();
                    try {


                        final JSONArray jArray = info.getJSONArray("imgs");

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {

                                for (int i = 0; i < jArray.length(); i++) {


                                    try {

                                        final String filename;
                                        filename = (String) jArray.get(i);


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

                                                final ImageButton image = new ImageButton(c);
                                                runOnUiThread(new Runnable() {
                                                    @Override
                                                    public void run() {

                                                        image.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                                        image.setLayoutParams(new LinearLayout.LayoutParams((int) convertDpToPixel(80), (int) convertDpToPixel(80)));
                                                        image.setBackgroundColor(getResources().getColor(R.color.btn_background));
                                                        ((LinearLayout) findViewById(R.id.imgs)).addView(image);
                                                        filenames.put(image, filename);
                                                        Animation aAnimation = (Animation) AnimationUtils.loadAnimation(c, R.anim.zoom);

                                                        image.startAnimation(aAnimation);
                                                    }
                                                });
                                                ((JSONArray)jsonImg).put(filename.substring(filename.lastIndexOf("/")+1));
                                                final Bitmap imgweb = Utils.getBitmapFromURL(filename);
                                                if (imgweb != null) {
                                                    runOnUiThread(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            image.clearAnimation();
                                                            image.setLayoutParams(new LinearLayout.LayoutParams((int) (convertDpToPixel(80) * imgweb.getWidth() / imgweb.getHeight()), (int) convertDpToPixel(80)));
                                                            Bitmap del = BitmapFactory.decodeResource(getResources(), R.drawable.delete);
                                                            image.setImageBitmap(Utils.mergeBitmaps(getOptimizedBitmap(imgweb, 300), del));

                                                            image.setOnClickListener(new View.OnClickListener() {
                                                                @Override
                                                                public void onClick(View v) {


                                                                    runOnUiThread(new Runnable() {
                                                                        @Override
                                                                        public void run() {

                                                                            Animation aAnimation = (Animation) AnimationUtils.loadAnimation(c, R.anim.rotation);

                                                                            image.startAnimation(aAnimation);
                                                                        }
                                                                    });


                                                                }
                                                            });

                                                        }
                                                    });
                                                }

                                            }
                                        }).start();


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


                                }


                            }
                        });


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

                }
            }).start();
*/



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

        ((TextView) findViewById(R.id.profile_name)).setText(b.getString("nome"));
        ((TextView) findViewById(R.id.profile_type)).setText(b.getString("tipologia"));

        idlocale = b.getInt("idlocale");
        if (MapActivity.mapCacheImage.containsKey(idlocale)) {
            ((ImageView) findViewById(R.id.profile_image)).setImageBitmap(MapActivity.mapCacheImage.get(idlocale));
        }
    }



    public float convertDpToPixel(float dp) {
        Resources resources = c.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        float px = dp * (metrics.densityDpi / 160f);
        return px;
    }

    Bitmap getOptimizedBitmap(Bitmap b, int maxms) {

        if (b.getWidth() > maxms)
            b = Bitmap.createScaledBitmap(b, b.getWidth() / (b.getWidth() / maxms), b.getHeight() / (b.getWidth() / maxms), false);


        if (b.getHeight() > maxms)
            b = Bitmap.createScaledBitmap(b, b.getWidth() / (b.getHeight() / maxms), b.getHeight() / (b.getHeight() / maxms), false);

        return b;
    }

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

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

                        image.setBackgroundColor(getResources().getColor(R.color.btn_background));
                        ((LinearLayout) findViewById(R.id.imgs)).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: {
                                            jsonImg.put(resp.getString("image_file"));
                                            mapLoading.put(image, jsonImg.length() - 1);
                                        }
                                        break;
                                        default: {
                                            sendFailed(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(getOptimizedBitmap(yourSelectedImage, 300), del));
                                        image.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {


                                                ArrayList<String> list = new ArrayList<String>();
                                                JSONArray jsonArray1 = (JSONArray) jsonImg;
                                                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
                                                jsonImg = new JSONArray(list);
                                                ((ViewManager) image.getParent()).removeView(image);
                                            }
                                        });
                                    }
                                });

                            }
                        }).start();

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

                }
                break;

        }
    }
/*
    public void addimage(View v) {
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, SELECT_PHOTO);
    }
*/
    public void sendclick() {

        if ( Utils.isNetworkConnected(c))
        {

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

                        TextView descrizioneTextView = (TextView) findViewById(R.id.editText10);
                        String descrizione = descrizioneTextView.getText().toString();

                        if(descrizione.equals("")){
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(RecensioneActivity.this, R.string.recensione_error, Toast.LENGTH_LONG).show();
                                }
                            });
                            return;
                        }

                        obj.put("local_id", idlocale);
                        obj.put("user_id", PrefsManager.getId(c));
                        obj.put("voto", ((RatingBar) findViewById(R.id.ratingBar4)).getRating());
                        obj.put("descrizione", ((TextView) findViewById(R.id.editText10)).getText());
                        obj.put("token", PrefsManager.getToken(c));
                        obj.put("imgs", jsonImg);

                        final JSONObject resp = HttpClient.SendHttpPostAsync(EndPoint.MAIN_END_POINT + "/add_commento.php", obj);
                        // resp.getInt("id"); ID COMMENTO
                        if (resp.getInt("return") == 0) {
                        try
                        {
                            if (MapActivity.mapCacheRecensioni.containsKey(idlocale))
                            {
                                MapActivity.mapCacheRecensioni.remove(idlocale);
                            }
                        }catch (Exception e){}

                           sendSuccesfully();
                        } else {
                            sendFailed(getString(R.string.retry_before));
                        }

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

                }
            }).start();
        }

    }


    private void sendSuccesfully() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {

                Toast.makeText(RecensioneActivity.this, R.string.thank_to, Toast.LENGTH_LONG).show();

                finish();
            }
        });


    }

    private void sendFailed(final String error) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                AlertDialog.Builder dlgAlert = new AlertDialog.Builder(c);
                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 clickTextView(View v)
    {


        EditText textView = (EditText ) findViewById(R.id.editText10);
        textView.requestFocus();
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(textView, InputMethodManager.SHOW_IMPLICIT);
    }

    @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_recensione, menu);
        return true;
    }

    @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.send_review) {
            sendclick();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

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

Diff revisions: vs.
Revision Author Commited Message
762 Diff Diff FFontana picture FFontana Fri 18 Sep, 2015 16:18:57 +0000
705 Diff Diff FFontana picture FFontana Mon 07 Sep, 2015 15:42:18 +0000
703 Diff Diff FFontana picture FFontana Mon 07 Sep, 2015 15:22:49 +0000
664 Diff Diff FFontana picture FFontana Fri 04 Sep, 2015 08:31:36 +0000
647 Diff Diff MStefanelli picture MStefanelli Wed 02 Sep, 2015 08:00:13 +0000

me

629 Diff Diff MStefanelli picture MStefanelli Tue 01 Sep, 2015 09:23:02 +0000

SuperCommit

599 Diff Diff MStefanelli picture MStefanelli Fri 28 Aug, 2015 07:16:44 +0000
578 Diff Diff MStefanelli picture MStefanelli Thu 27 Aug, 2015 08:20:02 +0000

me

542 Diff Diff FFontana picture FFontana Mon 24 Aug, 2015 21:40:56 +0000
531 MStefanelli picture MStefanelli Mon 24 Aug, 2015 11:18:03 +0000

WE