Subversion Repositories SmartDukaan

Rev

Rev 22830 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22830 Rev 23184
Line 1... Line 1...
1
package com.saholic.profittill.main;
1
package com.saholic.profittill.main;
2
 
2
 
3
import android.annotation.SuppressLint;
3
import android.annotation.SuppressLint;
-
 
4
import android.annotation.TargetApi;
4
import android.app.Activity;
5
import android.app.Activity;
5
import android.app.AlertDialog;
6
import android.app.AlertDialog;
6
import android.app.Fragment;
7
import android.app.Fragment;
7
import android.app.ProgressDialog;
8
import android.app.ProgressDialog;
8
import android.content.BroadcastReceiver;
9
import android.content.BroadcastReceiver;
Line 10... Line 11...
10
import android.content.Context;
11
import android.content.Context;
11
import android.content.DialogInterface;
12
import android.content.DialogInterface;
12
import android.content.Intent;
13
import android.content.Intent;
13
import android.content.IntentFilter;
14
import android.content.IntentFilter;
14
import android.content.SharedPreferences;
15
import android.content.SharedPreferences;
-
 
16
import android.content.pm.PackageManager;
15
import android.content.pm.ResolveInfo;
17
import android.content.pm.ResolveInfo;
-
 
18
import android.database.Cursor;
16
import android.graphics.Bitmap;
19
import android.graphics.Bitmap;
-
 
20
import android.graphics.BitmapFactory;
-
 
21
import android.graphics.Canvas;
17
import android.graphics.Color;
22
import android.graphics.Color;
-
 
23
import android.graphics.Matrix;
-
 
24
import android.graphics.Paint;
18
import android.graphics.PorterDuff;
25
import android.graphics.PorterDuff;
19
import android.graphics.drawable.ColorDrawable;
26
import android.graphics.drawable.ColorDrawable;
20
import android.graphics.drawable.Drawable;
27
import android.graphics.drawable.Drawable;
-
 
28
import android.media.ExifInterface;
21
import android.net.ConnectivityManager;
29
import android.net.ConnectivityManager;
22
import android.net.Uri;
30
import android.net.Uri;
23
import android.os.AsyncTask;
31
import android.os.AsyncTask;
24
import android.os.Build;
32
import android.os.Build;
25
import android.os.Bundle;
33
import android.os.Bundle;
26
import android.os.Environment;
34
import android.os.Environment;
27
import android.os.Handler;
35
import android.os.Handler;
28
import android.os.Parcelable;
36
import android.os.Parcelable;
-
 
37
import android.provider.DocumentsContract;
29
import android.provider.MediaStore;
38
import android.provider.MediaStore;
30
import android.support.v4.os.AsyncTaskCompat;
39
import android.support.v4.os.AsyncTaskCompat;
31
import android.support.v7.app.ActionBar;
40
import android.support.v7.app.ActionBar;
32
import android.support.v7.app.AppCompatActivity;
41
import android.support.v7.app.AppCompatActivity;
33
import android.telephony.SmsMessage;
42
import android.telephony.SmsMessage;
Line 58... Line 67...
58
 
67
 
59
import com.google.android.gms.common.ConnectionResult;
68
import com.google.android.gms.common.ConnectionResult;
60
import com.google.android.gms.common.api.GoogleApiClient;
69
import com.google.android.gms.common.api.GoogleApiClient;
61
import com.google.android.gms.plus.Plus;
70
import com.google.android.gms.plus.Plus;
62
import com.google.firebase.iid.FirebaseInstanceId;
71
import com.google.firebase.iid.FirebaseInstanceId;
-
 
72
import com.kosalgeek.android.photoutil.CameraPhoto;
-
 
73
import com.kosalgeek.android.photoutil.GalleryPhoto;
-
 
74
import com.kosalgeek.android.photoutil.ImageLoader;
63
import com.saholic.profittill.Constants.ProfitTillConstants;
75
import com.saholic.profittill.Constants.ProfitTillConstants;
64
import com.saholic.profittill.Database.OrderTransactionDetails;
76
import com.saholic.profittill.Database.OrderTransactionDetails;
65
import com.saholic.profittill.Network.NotificationCount;
77
import com.saholic.profittill.Network.NotificationCount;
66
import com.saholic.profittill.R;
78
import com.saholic.profittill.R;
67
import com.saholic.profittill.Utils.UtilityFunctions;
79
import com.saholic.profittill.Utils.UtilityFunctions;
Line 81... Line 93...
81
import org.apache.http.util.EntityUtils;
93
import org.apache.http.util.EntityUtils;
82
import org.json.JSONArray;
94
import org.json.JSONArray;
83
import org.json.JSONException;
95
import org.json.JSONException;
84
import org.json.JSONObject;
96
import org.json.JSONObject;
85
 
97
 
-
 
98
import java.io.BufferedOutputStream;
-
 
99
import java.io.ByteArrayOutputStream;
86
import java.io.File;
100
import java.io.File;
-
 
101
import java.io.FileNotFoundException;
-
 
102
import java.io.FileOutputStream;
87
import java.io.IOException;
103
import java.io.IOException;
88
import java.io.InputStream;
104
import java.io.InputStream;
-
 
105
import java.io.OutputStream;
89
import java.io.UnsupportedEncodingException;
106
import java.io.UnsupportedEncodingException;
90
import java.net.URISyntaxException;
107
import java.net.URISyntaxException;
91
import java.text.SimpleDateFormat;
108
import java.text.SimpleDateFormat;
92
import java.util.ArrayList;
109
import java.util.ArrayList;
93
import java.util.Date;
110
import java.util.Date;
Line 100... Line 117...
100
import java.util.regex.Matcher;
117
import java.util.regex.Matcher;
101
import java.util.regex.Pattern;
118
import java.util.regex.Pattern;
102
 
119
 
103
public class DealsHomeFragment extends Fragment implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
120
public class DealsHomeFragment extends Fragment implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
104
 
121
 
-
 
122
    private File storageDir;
-
 
123
    File photoFile = null;
-
 
124
 
105
    public DealsHomeFragment() {
125
    public DealsHomeFragment() {
106
 
126
 
107
    }
127
    }
108
 
128
 
109
    static boolean FLAG = false, REDIRECT = false, PAGE_LOAD = false, PAYTMFLAG = false, isPause = false, Flipkartflag = false;
129
    static boolean FLAG = false, REDIRECT = false, PAGE_LOAD = false, PAYTMFLAG = false, isPause = false, Flipkartflag = false;
Line 122... Line 142...
122
    LinkedList<ArrayList<NameValuePair>> orderLinkedList;
142
    LinkedList<ArrayList<NameValuePair>> orderLinkedList;
123
    SharedPreferences amazonData;
143
    SharedPreferences amazonData;
124
    String affliateUrl;
144
    String affliateUrl;
125
    String landingURL;
145
    String landingURL;
126
    String regId;
146
    String regId;
-
 
147
    String temp;
127
    String msg = "";
148
    String msg = "";
128
    ArrayList<NameValuePair> messageNameValuePair;
149
    ArrayList<NameValuePair> messageNameValuePair;
129
    boolean val = false;
150
    boolean val = false;
130
    String redirectUrls;
151
    String redirectUrls;
131
    String pageLoad;
152
    String pageLoad;
Line 149... Line 170...
149
    private static final String TAG = DealsHomeFragment.class.getSimpleName();
170
    private static final String TAG = DealsHomeFragment.class.getSimpleName();
150
    private String mCM;
171
    private String mCM;
151
    private ValueCallback<Uri> mUM;
172
    private ValueCallback<Uri> mUM;
152
    private ValueCallback<Uri[]> mUMA;
173
    private ValueCallback<Uri[]> mUMA;
153
    private final static int FCR=1;
174
    private final static int FCR=1;
-
 
175
    GalleryPhoto galleryPhoto;
-
 
176
    CameraPhoto cameraPhoto;
154
    boolean doubleBackToExitPressedOnce = false;
177
    boolean doubleBackToExitPressedOnce = false;
155
    String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
178
    String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
156
 
179
 
157
    @Override
180
    @Override
158
    public void onCreate(Bundle savedInstanceState) {
181
    public void onCreate(Bundle savedInstanceState) {
Line 205... Line 228...
205
        TestinAgent.init(getActivity());
228
        TestinAgent.init(getActivity());
206
        int InstanceId =  DealsHomeFragment.class.hashCode();
229
        int InstanceId =  DealsHomeFragment.class.hashCode();
207
        AppCompatActivity activity = (AppCompatActivity) getActivity();
230
        AppCompatActivity activity = (AppCompatActivity) getActivity();
208
        ActionBar actionBar = activity.getSupportActionBar();
231
        ActionBar actionBar = activity.getSupportActionBar();
209
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
232
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
-
 
233
        galleryPhoto = new GalleryPhoto(getActivity());
-
 
234
        cameraPhoto = new CameraPhoto(getActivity());
210
        final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
235
        final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
211
        upArrow.setColorFilter(getResources().getColor(R.color.grey_black), PorterDuff.Mode.SRC_ATOP);
236
        upArrow.setColorFilter(getResources().getColor(R.color.grey_black), PorterDuff.Mode.SRC_ATOP);
212
        actionBar.setHomeAsUpIndicator(upArrow);
237
        actionBar.setHomeAsUpIndicator(upArrow);
213
        actionBar.setDisplayShowCustomEnabled(true);
238
        actionBar.setDisplayShowCustomEnabled(true);
214
        actionBar.setDisplayShowTitleEnabled(false);
239
        actionBar.setDisplayShowTitleEnabled(false);
Line 312... Line 337...
312
                        WebChromeClient.FileChooserParams fileChooserParams){
337
                        WebChromeClient.FileChooserParams fileChooserParams){
313
                    if(mUMA != null){
338
                    if(mUMA != null){
314
                        mUMA.onReceiveValue(null);
339
                        mUMA.onReceiveValue(null);
315
                    }
340
                    }
316
                    mUMA = filePathCallback;
341
                    mUMA = filePathCallback;
317
                    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
342
                    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE );
318
                    if(takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null){
343
                    if(takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null){
319
                        File photoFile = null;
-
 
320
                        try{
344
                        try{
321
                            photoFile = createImageFile();
345
                            photoFile = createImageFile();
322
                            takePictureIntent.putExtra("PhotoPath", mCM);
346
                            takePictureIntent.putExtra("PhotoPath", mCM);
323
                        }catch(IOException ex){
347
                        }catch(IOException ex){
324
                            Log.e(TAG, "Image file creation failed", ex);
348
                            Log.e(TAG, "Image file creation failed", ex);
325
                        }
349
                        }
326
                        if(photoFile != null){
350
                        if(photoFile != null){
327
                            mCM = "file:" + photoFile.getAbsolutePath();
351
                            mCM = "file:" + photoFile.getAbsolutePath();
328
                            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
352
                           takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
329
                        }else{
353
                        }else{
330
                            takePictureIntent = null;
354
                            takePictureIntent = null;
331
                        }
355
                        }
332
                    }
356
                    }
333
                    Intent contentSelectionIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
357
                    Intent contentSelectionIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
Line 1079... Line 1103...
1079
       }
1103
       }
1080
    // Create an image file
1104
    // Create an image file
1081
      private File createImageFile() throws IOException{
1105
      private File createImageFile() throws IOException{
1082
        @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1106
        @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1083
        String imageFileName = "img_"+timeStamp+"_";
1107
        String imageFileName = "img_"+timeStamp+"_";
1084
        File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
1108
          storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
1085
        return File.createTempFile(imageFileName,".jpg",storageDir);
1109
        return File.createTempFile(imageFileName,".jpg",storageDir);
1086
      }
1110
      }
1087
 
1111
 
1088
 
1112
 
1089
 
1113
 
1090
 
1114
 
1091
    @Override
1115
    @Override
1092
    public void onActivityResult(int requestCode, int resultCode, Intent intent){
1116
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
1093
        super.onActivityResult(requestCode, resultCode, intent);
1117
        super.onActivityResult(requestCode, resultCode, intent);
-
 
1118
 
1094
        if(Build.VERSION.SDK_INT >= 21){
1119
        if(Build.VERSION.SDK_INT >= 21) {
1095
            Uri[] results = null;
-
 
1096
            //Check if response is positive
1120
            //Check if response is positive
1097
            if(resultCode== Activity.RESULT_OK){
1121
            if(resultCode == Activity.RESULT_OK) {
1098
                if(requestCode == FCR){
1122
                if(requestCode == FCR) {
1099
                    if(null == mUMA){
1123
                    if(null == mUMA) {
1100
                        return;
1124
                        return;
1101
                    }
1125
                    }
1102
                    if(intent == null){
1126
                    if (intent == null) {
1103
                        //Capture Photo if no image available
1127
                        //Capture Photo if no image available
1104
                        if(mCM != null){
1128
                        if (mCM != null) {
1105
                            results = new Uri[]{Uri.parse(mCM)};
-
 
1106
                        }
-
 
1107
                    }else{
-
 
1108
                        String dataString = intent.getDataString();
-
 
1109
                        if(dataString != null){
-
 
1110
                            results = new Uri[]{Uri.parse(dataString)};
1129
                            new ImageCompression().execute(photoFile.getPath());
1111
                        }
1130
                        }
-
 
1131
                    } else {
-
 
1132
 
-
 
1133
                        Uri dataString = intent.getData();
-
 
1134
                        String newPath=getRealPathFromURI_API19(getActivity(), dataString);
-
 
1135
 
-
 
1136
                        new ImageCompression().execute(newPath);
1112
                    }
1137
                    }
1113
                }
1138
                }
1114
            }
1139
            }
1115
            mUMA.onReceiveValue(results);
-
 
1116
            mUMA = null;
-
 
1117
        }else{
1140
        } else {
1118
            if(requestCode == FCR){
1141
            if (requestCode == FCR) {
1119
                if(null == mUM) return;
1142
                if (null == mUM) return;
1120
                Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
1143
                Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
1121
                mUM.onReceiveValue(result);
1144
                mUM.onReceiveValue(result);
1122
                mUM = null;
1145
                mUM = null;
1123
            }
1146
            }
1124
        }
1147
        }
-
 
1148
        if (resultCode != Activity.RESULT_OK) {
-
 
1149
            mUMA.onReceiveValue(null);
-
 
1150
            mUMA =null;
-
 
1151
        }
-
 
1152
 
-
 
1153
    }
-
 
1154
 
-
 
1155
    @TargetApi(Build.VERSION_CODES.KITKAT)
-
 
1156
    public static String getRealPathFromURI_API19(Context context, Uri uri){
-
 
1157
        String filePath = "";
-
 
1158
        String wholeID = null;
-
 
1159
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
-
 
1160
            wholeID = DocumentsContract.getDocumentId(uri);
-
 
1161
        }
-
 
1162
 
-
 
1163
        // Split at colon, use second item in the array
-
 
1164
        String id = wholeID.split(":")[1];
-
 
1165
 
-
 
1166
        String[] column = { MediaStore.Images.Media.DATA };
-
 
1167
 
-
 
1168
        // where id is equal to
-
 
1169
        String sel = MediaStore.Images.Media._ID + "=?";
-
 
1170
 
-
 
1171
        Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
-
 
1172
                column, sel, new String[]{ id }, null);
-
 
1173
 
-
 
1174
        int columnIndex = cursor.getColumnIndex(column[0]);
-
 
1175
 
-
 
1176
        if (cursor.moveToFirst()) {
-
 
1177
            filePath = cursor.getString(columnIndex);
-
 
1178
        }
-
 
1179
        cursor.close();
-
 
1180
        return filePath;
-
 
1181
    }
-
 
1182
 
-
 
1183
 
-
 
1184
    public class ImageCompression extends AsyncTask<String, Void, Void> {
-
 
1185
 
-
 
1186
        private static final float maxHeight = 800.0f;
-
 
1187
        private static final float maxWidth = 800.0f;
-
 
1188
        private File imageFile = null;
-
 
1189
        private Context context;
-
 
1190
        Uri[] results = null;
-
 
1191
 
-
 
1192
        @Override
-
 
1193
        protected void onPreExecute() {
-
 
1194
            super.onPreExecute();
-
 
1195
 
-
 
1196
            //making progress dialog visible
-
 
1197
            //showProgressBar();
-
 
1198
        }
-
 
1199
 
-
 
1200
        @Override
-
 
1201
        protected Void doInBackground(String... strings) {
-
 
1202
            try {
-
 
1203
                if (strings.length == 0 || strings[0] == null)
-
 
1204
                    return null;
-
 
1205
                //obtaining image array after the required image is compressed
-
 
1206
                imageFile = compressImage(strings[0]);
-
 
1207
            } catch (Exception e) {
-
 
1208
//                CrashLogs.crashLogger(e);
-
 
1209
            }
-
 
1210
            return null;
-
 
1211
        }
-
 
1212
 
-
 
1213
        @Override
-
 
1214
        protected void onPostExecute(Void aVoid) {
-
 
1215
            super.onPostExecute(aVoid);
-
 
1216
            try {
-
 
1217
                //sending data to server using multipart request
-
 
1218
                //sendMultiPartRequest(imageArray);
-
 
1219
 
-
 
1220
                if(imageFile !=null){
-
 
1221
 
-
 
1222
                    results = new Uri[]{Uri.fromFile(imageFile)};
-
 
1223
                    mUMA.onReceiveValue(results);
-
 
1224
                    mUMA = null;
-
 
1225
                }
-
 
1226
 
-
 
1227
            } catch (Exception e) {
-
 
1228
                //CrashLogs.crashLogger(e);
-
 
1229
            }
-
 
1230
        }
-
 
1231
 
-
 
1232
        //process to compress image to send it to the server
-
 
1233
        public File compressImage(String imagePath) {
-
 
1234
            Bitmap scaledBitmap = null;
-
 
1235
 
-
 
1236
            BitmapFactory.Options options = new BitmapFactory.Options();
-
 
1237
            options.inJustDecodeBounds = true;
-
 
1238
            Bitmap bmp = BitmapFactory.decodeFile(imagePath, options);
-
 
1239
 
-
 
1240
            int actualHeight = options.outHeight;
-
 
1241
            int actualWidth = options.outWidth;
-
 
1242
 
-
 
1243
            float imgRatio = (float) actualWidth / (float) actualHeight;
-
 
1244
            float maxRatio = maxWidth / maxHeight;
-
 
1245
 
-
 
1246
            if (actualHeight > maxHeight || actualWidth > maxWidth) {
-
 
1247
                if (imgRatio < maxRatio) {
-
 
1248
                    imgRatio = maxHeight / actualHeight;
-
 
1249
                    actualWidth = (int) (imgRatio * actualWidth);
-
 
1250
                    actualHeight = (int) maxHeight;
-
 
1251
                } else if (imgRatio > maxRatio) {
-
 
1252
                    imgRatio = maxWidth / actualWidth;
-
 
1253
                    actualHeight = (int) (imgRatio * actualHeight);
-
 
1254
                    actualWidth = (int) maxWidth;
-
 
1255
                } else {
-
 
1256
                    actualHeight = (int) maxHeight;
-
 
1257
                    actualWidth = (int) maxWidth;
-
 
1258
                }
-
 
1259
            }
-
 
1260
 
-
 
1261
            options.inSampleSize = calculateInSampleSize(options, actualWidth, actualHeight);
-
 
1262
            options.inJustDecodeBounds = false;
-
 
1263
            options.inDither = false;
-
 
1264
            options.inPurgeable = true;
-
 
1265
            options.inInputShareable = true;
-
 
1266
            options.inTempStorage = new byte[16 * 1024];
-
 
1267
 
-
 
1268
            try {
-
 
1269
                bmp = BitmapFactory.decodeFile(imagePath, options);
-
 
1270
            } catch (OutOfMemoryError exception) {
-
 
1271
//                CrashLogs.crashLogger(exception);
-
 
1272
 
-
 
1273
            }
-
 
1274
            try {
-
 
1275
                scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.RGB_565);
-
 
1276
            } catch (OutOfMemoryError exception) {
-
 
1277
//                CrashLogs.crashLogger(exception);
-
 
1278
            }
-
 
1279
 
-
 
1280
            float ratioX = actualWidth / (float) options.outWidth;
-
 
1281
            float ratioY = actualHeight / (float) options.outHeight;
-
 
1282
            float middleX = actualWidth / 2.0f;
-
 
1283
            float middleY = actualHeight / 2.0f;
-
 
1284
 
-
 
1285
            Matrix scaleMatrix = new Matrix();
-
 
1286
            scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
-
 
1287
 
-
 
1288
            Canvas canvas = new Canvas(scaledBitmap);
-
 
1289
            canvas.setMatrix(scaleMatrix);
-
 
1290
            canvas.drawBitmap(bmp, middleX - bmp.getWidth() / 2, middleY - bmp.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG));
-
 
1291
 
-
 
1292
            if (bmp != null) {
-
 
1293
                bmp.recycle();
-
 
1294
            }
-
 
1295
 
-
 
1296
            ExifInterface exif;
-
 
1297
            try {
-
 
1298
                exif = new ExifInterface(imagePath);
-
 
1299
                int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
-
 
1300
                Matrix matrix = new Matrix();
-
 
1301
                if (orientation == 6) {
-
 
1302
                    matrix.postRotate(90);
-
 
1303
                } else if (orientation == 3) {
-
 
1304
                    matrix.postRotate(180);
-
 
1305
                } else if (orientation == 8) {
-
 
1306
                    matrix.postRotate(270);
-
 
1307
                }
-
 
1308
                scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true);
-
 
1309
            } catch (IOException e) {
-
 
1310
//                CrashLogs.crashLogger(e);
-
 
1311
            }
-
 
1312
            File outputFile = null;
-
 
1313
            try {
-
 
1314
 
-
 
1315
 
-
 
1316
                outputFile = getOutputMediaFile(temp);
-
 
1317
 
-
 
1318
                try {
-
 
1319
                    FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
-
 
1320
                    scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fileOutputStream);
-
 
1321
                    fileOutputStream.flush();
-
 
1322
                    fileOutputStream.close();
-
 
1323
                } catch (Exception e) {
-
 
1324
//                    CrashLogs.crashLogger(e);
-
 
1325
                }
-
 
1326
            } catch (Exception e) {
-
 
1327
//                CrashLogs.crashLogger(e);
-
 
1328
            }
-
 
1329
            /*try {
-
 
1330
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-
 
1331
                scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream);
-
 
1332
                return byteArrayOutputStream.toByteArray();
-
 
1333
            } catch (Exception e) {
-
 
1334
//                CrashLogs.crashLogger(e);
-
 
1335
            }*/
-
 
1336
            return outputFile;
-
 
1337
        }
-
 
1338
 
-
 
1339
        /*
-
 
1340
        * method to calculate inSample size(used while compressing the image).
-
 
1341
        * */
-
 
1342
        public int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
-
 
1343
            int inSampleSize = 1;
-
 
1344
            try {
-
 
1345
                final int height = options.outHeight;
-
 
1346
                final int width = options.outWidth;
-
 
1347
 
-
 
1348
 
-
 
1349
                if (height > reqHeight || width > reqWidth) {
-
 
1350
                    final int heightRatio = Math.round((float) height / (float) reqHeight);
-
 
1351
                    final int widthRatio = Math.round((float) width / (float) reqWidth);
-
 
1352
                    inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
-
 
1353
                }
-
 
1354
                final float totalPixels = width * height;
-
 
1355
                final float totalReqPixelsCap = reqWidth * reqHeight * 2;
-
 
1356
 
-
 
1357
                while (totalPixels / (inSampleSize * inSampleSize) > totalReqPixelsCap) {
-
 
1358
                    inSampleSize++;
-
 
1359
                }
-
 
1360
 
-
 
1361
                return inSampleSize;
-
 
1362
            } catch (Exception e) {
-
 
1363
 
-
 
1364
//                CrashLogs.crashLogger(e);
-
 
1365
                return inSampleSize;
-
 
1366
            }
-
 
1367
        }
-
 
1368
    }
-
 
1369
 
-
 
1370
    public static final String IMAGE_DIRECTORY_NAME = "ProfitMandi";
-
 
1371
 
-
 
1372
    public File getOutputMediaFile(String name) {
-
 
1373
        // External sdcard location
-
 
1374
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
-
 
1375
        File mediaStorageDir = new File(
-
 
1376
                Environment
-
 
1377
                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
-
 
1378
                IMAGE_DIRECTORY_NAME);
-
 
1379
        // Create the storage directory if it does not exist
-
 
1380
        if (!mediaStorageDir.exists()) {
-
 
1381
            if (!mediaStorageDir.mkdirs()) {
-
 
1382
                return null;
-
 
1383
            }
-
 
1384
        }
-
 
1385
        File mediaFile;
-
 
1386
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
-
 
1387
                + name +timeStamp+ ".jpg");
-
 
1388
        return mediaFile;
1125
    }
1389
    }
1126
 
1390
 
-
 
1391
 
1127
    private void processFlipkartHtml() {
1392
    private void processFlipkartHtml() {
1128
        FlipkartWebview fkView = new FlipkartWebview();
1393
        FlipkartWebview fkView = new FlipkartWebview();
1129
        amazonOrderHistoryWebView = new WebView(webView.getContext());
1394
        amazonOrderHistoryWebView = new WebView(webView.getContext());
1130
        amazonOrderHistoryWebView.setVisibility(View.GONE);
1395
        amazonOrderHistoryWebView.setVisibility(View.GONE);
1131
        String post=apiData.getString("flipkart.response.url","https://www.flipkart.com/rv/accounts");
1396
        String post=apiData.getString("flipkart.response.url","https://www.flipkart.com/rv/accounts");
Line 1484... Line 1749...
1484
            try{
1749
            try{
1485
                if (mGoogleApiClient.isConnected()) {
1750
                if (mGoogleApiClient.isConnected()) {
1486
                    Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
1751
                    Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
1487
                    mGoogleApiClient.disconnect();
1752
                    mGoogleApiClient.disconnect();
1488
                    mGoogleApiClient.connect();
1753
                    mGoogleApiClient.connect();
1489
                    webView.clearHistory();
-
 
1490
                    webView.removeAllViews();
-
 
1491
                    webView.clearView();
-
 
1492
                    webView.destroy();
-
 
1493
                    userDataEditor.clear().commit();
1754
                    userDataEditor.clear().commit();
1494
                    startActivity(new Intent(getActivity(), LoginActivity.class));
1755
                    startActivity(new Intent(getActivity(), LoginActivity.class));
1495
                }
1756
                }
1496
                else{
1757
                else{
1497
                    if(!mGoogleApiClient.isConnected()){
1758
                    if(!mGoogleApiClient.isConnected()){