PageRenderTime 183ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/MyCampus/app/src/main/java/com/example/maheshraja/mycampus/Activity/RegistrationActivity.java

https://gitlab.com/techgenius/mycampus
Java | 775 lines | 558 code | 135 blank | 82 comment | 94 complexity | bb38c2dd0b7bfcf6cb55643ade9dcef3 MD5 | raw file
  1. package com.example.maheshraja.mycampus.Activity;
  2. import android.app.Activity;
  3. import android.app.DatePickerDialog;
  4. import android.app.ProgressDialog;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.pm.PackageInfo;
  8. import android.content.pm.PackageManager;
  9. import android.graphics.Bitmap;
  10. import android.graphics.drawable.BitmapDrawable;
  11. import android.location.Location;
  12. import android.location.LocationManager;
  13. import android.net.Uri;
  14. import android.os.Build;
  15. import android.os.Bundle;
  16. import android.os.CountDownTimer;
  17. import android.provider.MediaStore;
  18. import android.support.v7.app.AppCompatActivity;
  19. import android.support.v7.widget.Toolbar;
  20. import android.telephony.TelephonyManager;
  21. import android.util.Log;
  22. import android.view.View;
  23. import android.widget.Button;
  24. import android.widget.DatePicker;
  25. import android.widget.EditText;
  26. import android.widget.ImageView;
  27. import android.widget.RadioButton;
  28. import android.widget.RadioGroup;
  29. import android.widget.Toast;
  30. import com.example.maheshraja.mycampus.R;
  31. import com.example.maheshraja.mycampus.asynctask.ImageAsyncTask;
  32. import com.example.maheshraja.mycampus.asynctask.MyAsyncTask;
  33. import com.example.maheshraja.mycampus.daos.UserDAO;
  34. import com.example.maheshraja.mycampus.database.DBHandler;
  35. import com.example.maheshraja.mycampus.dtos.DTO;
  36. import com.example.maheshraja.mycampus.dtos.UserDTO;
  37. import com.example.maheshraja.mycampus.listener.AsyncTaskCompleteListener;
  38. import com.example.maheshraja.mycampus.utility.MyConstants;
  39. import com.example.maheshraja.mycampus.utility.Utility;
  40. import com.google.android.gms.common.ConnectionResult;
  41. import com.google.android.gms.common.api.GoogleApiClient;
  42. import com.google.android.gms.location.LocationListener;
  43. import com.google.android.gms.location.LocationRequest;
  44. import com.google.android.gms.location.LocationServices;
  45. import org.json.JSONException;
  46. import org.json.JSONObject;
  47. import java.io.ByteArrayOutputStream;
  48. import java.io.File;
  49. import java.io.FileNotFoundException;
  50. import java.io.FileOutputStream;
  51. import java.io.IOException;
  52. import java.util.ArrayList;
  53. import java.util.Calendar;
  54. public class RegistrationActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
  55. private Button btnSubmit;
  56. private EditText userNameEdt, emailIdEdt, mobileNoEdt, passwordEdt, confPasswordEdt, addressEdt, dobEdt, uidEdt, locationEdt;
  57. private RadioGroup genderRadio;
  58. private Context context;
  59. private Toolbar mToolbar;
  60. private GoogleApiClient mGoogleApiClient;
  61. private LocationRequest mLocationRequest;
  62. private String TAG = "RegistrationActivity";
  63. private String location;
  64. private CountDownTimer mLocationCountDownTimer;
  65. private ProgressDialog dialog;
  66. protected final int COUNT_DOWN_TIME = 30000;
  67. protected final int COUNT_DOWN_TIME_INTERVAL = 1000;
  68. protected static boolean checkForLocation = true;
  69. private String current;
  70. private File mypath;
  71. private Uri uriSavedImage;
  72. private final int IMAGECAPTURE_ACTIVITY = 100;
  73. private String imgFilePath = "";
  74. private ImageView mCameraImg;
  75. @Override
  76. protected void onCreate(Bundle savedInstanceState) {
  77. super.onCreate(savedInstanceState);
  78. setContentView(R.layout.activity_registration);
  79. mToolbar = (Toolbar) findViewById(R.id.toolbar);
  80. setSupportActionBar(mToolbar);
  81. context = this;
  82. //Mint.initAndStartSession(RegistrationActivity.this, "89a68d2b");
  83. if (Utility.checkPlayServices(context)) {
  84. buildGoogleApiClient();
  85. }
  86. btnSubmit = (Button) findViewById(R.id.reg_submit);
  87. userNameEdt = (EditText) findViewById(R.id.reg_name);
  88. mobileNoEdt = (EditText) findViewById(R.id.reg_mobile);
  89. emailIdEdt = (EditText) findViewById(R.id.reg_email);
  90. addressEdt = (EditText) findViewById(R.id.reg_addr);
  91. uidEdt = (EditText) findViewById(R.id.reg_uid);
  92. locationEdt = (EditText) findViewById(R.id.reg_location);
  93. genderRadio = (RadioGroup) findViewById(R.id.reg_gender);
  94. passwordEdt = (EditText) findViewById(R.id.reg_password);
  95. confPasswordEdt = (EditText) findViewById(R.id.reg_conf_password);
  96. dobEdt = (EditText) findViewById(R.id.reg_dob);
  97. mCameraImg = (ImageView) findViewById(R.id.reg_profile_img);
  98. mCameraImg.setOnClickListener(new View.OnClickListener() {
  99. @Override
  100. public void onClick(View v) {
  101. // captureImage();
  102. dispatchTakePictureIntent();
  103. }
  104. });
  105. /*dobEdt.setOnClickListener(new View.OnClickListener() {
  106. @Override
  107. public void onClick(View v) {
  108. openDatePickerDailog();
  109. }
  110. });*/
  111. /*dobEdt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  112. @Override
  113. public void onFocusChange(View v, boolean hasFocus) {
  114. if(hasFocus){
  115. openDatePickerDailog();
  116. }
  117. }
  118. });*/
  119. btnSubmit.setOnClickListener(new View.OnClickListener() {
  120. @Override
  121. public void onClick(View v) {
  122. String validation = validateFields();
  123. if (validation == null) {
  124. if (location != null && !location.isEmpty()) {
  125. if (Utility.networkAvailability(context)) {
  126. // showProgress();
  127. registrationProcess();
  128. // loginProcess();
  129. } else {
  130. Utility.showAlert(context, null, getString(R.string.check_connection));
  131. }
  132. } else {
  133. getCurrentLocation(context);
  134. }
  135. } else {
  136. Utility.showAlert(context, "Alert", validation);
  137. }
  138. //uploadImage();
  139. }
  140. });
  141. }
  142. private void uploadImage() {
  143. ImageAsyncTask imageAsyncTask = new ImageAsyncTask(context, Utility.getFileDir(context)+ File.separator+Utility.getProfileImageURL(context), taskCompleteListener, MyConstants.IMG_CONNECTION_TIMEOUT, MyConstants.IMG_SOCKET_TIMEOUT);
  144. Utility.showProgressDialog(context);
  145. imageAsyncTask.execute(MyConstants.IMG_UPLOAD_URL);
  146. }
  147. private AsyncTaskCompleteListener taskCompleteListener = new AsyncTaskCompleteListener() {
  148. @Override
  149. public void onAsynComplete(String result) {
  150. if (result != null) {
  151. if(Utility.isJSONValid(result)){
  152. try {
  153. JSONObject object = new JSONObject(result);
  154. int code = object.optInt("code");
  155. if(code == 100){
  156. navigateApp();
  157. Utility.showAlert(context, null, "Updated Your Profile Successfully");
  158. }else if(code == 101){
  159. Utility.showAlert(context, null, "Failed Updated Your Profile");
  160. }else{
  161. Utility.showAlert(context, null, "Unknown response");
  162. }
  163. } catch (JSONException e) {
  164. e.printStackTrace();
  165. }
  166. }else{
  167. Utility.showAlert(context, null, "Invalid Response contact system admin");
  168. }
  169. } else {
  170. Utility.showAlert(context, "Network problem", "Check your internet connection");
  171. }
  172. Utility.hideProgressDialog();
  173. }
  174. };
  175. private void openDatePickerDailog() {
  176. Calendar c = Calendar.getInstance();
  177. MyDatePicker datePicker = new MyDatePicker();
  178. new DatePickerDialog(context, datePicker, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();
  179. }
  180. class MyDatePicker implements DatePickerDialog.OnDateSetListener {
  181. @Override
  182. public void onDateSet(DatePicker view, int year, int monthOfYear,
  183. int dayOfMonth) {
  184. dobEdt.setText("" + dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
  185. }
  186. }
  187. private void registrationProcess() {
  188. UserDTO dto = (UserDTO) getUserData();
  189. JSONObject reqJson = new JSONObject();
  190. try {
  191. reqJson.put("deviceid", Utility.getDeviceId(RegistrationActivity.this));
  192. reqJson.put("password", dto.getPassword());
  193. reqJson.put("address", dto.getAddress());
  194. reqJson.put("gender", dto.getGender());
  195. reqJson.put("latlan", dto.getLocation());
  196. reqJson.put("mailid", dto.getEmailId());
  197. reqJson.put("mobilenum", dto.getMobileNo());
  198. reqJson.put("name", dto.getName());
  199. reqJson.put("age", dto.getAge());
  200. reqJson.put("imei", getIMEINo(context));
  201. } catch (JSONException e) {
  202. e.printStackTrace();
  203. }catch (Exception e){
  204. }
  205. MyAsyncTask loginAsync = new MyAsyncTask(reqJson.toString(), completeListener, MyConstants.CONNECTION_TIMEOUT, MyConstants.SOCKET_TIMEOUT);
  206. Utility.showProgressDialog(context);
  207. loginAsync.execute(MyConstants.REG_URL);
  208. }
  209. private AsyncTaskCompleteListener completeListener = new AsyncTaskCompleteListener() {
  210. @Override
  211. public void onAsynComplete(String result) {
  212. if (result != null) {
  213. if(Utility.isJSONValid(result)){
  214. try {
  215. JSONObject object = new JSONObject(result);
  216. int code = object.optInt("code");
  217. if(code == 100){
  218. Utility.setAuthCode(object.optString("authcode"),RegistrationActivity.this);
  219. saveData(getUserData());
  220. uploadImage();
  221. return;
  222. }else if(code == 101){
  223. Utility.showAlert(context, null, "Failed Register");
  224. }else{
  225. Utility.showAlert(context, null, "Unknown response");
  226. }
  227. } catch (JSONException e) {
  228. e.printStackTrace();
  229. }
  230. }else{
  231. Utility.showAlert(context, null, "Invalid Response contact system admin");
  232. }
  233. } else {
  234. Utility.showAlert(context, "Network problem", "Check your internet connection");
  235. }
  236. Utility.hideProgressDialog();
  237. }
  238. };
  239. private String getURL() {
  240. DTO mainDTO = getUserData();
  241. UserDTO dto = (UserDTO) mainDTO;
  242. String str = "http://bighand.in/reg.php?name=" + dto.getName() + "&cellno=" + dto.getMobileNo() + "&gender=" + dto.getGender() + "&longitude=78.4006983&lattitude=17.4590091&emailid=" + dto.getEmailId() + "&deviseid=" + Utility.getDeviceId(RegistrationActivity.this);
  243. return str;
  244. }
  245. private void saveData(DTO userData) {
  246. context.deleteDatabase("security.db");
  247. UserDAO.getInstance().insert(userData, DBHandler.getInstance(context).getDBObject(1));
  248. //navigateApp();
  249. }
  250. private DTO getUserData() {
  251. UserDTO dto = new UserDTO();
  252. dto.setName(getText(userNameEdt));
  253. dto.setMobileNo(getText(mobileNoEdt));
  254. dto.setEmailId(getText(emailIdEdt));
  255. dto.setLocation(location);
  256. dto.setAddress(getText(addressEdt));
  257. dto.setuId(Utility.getDeviceId(context));
  258. dto.setGender(((RadioButton) findViewById(genderRadio.getCheckedRadioButtonId())).getText().toString().trim());
  259. dto.setPassword(getText(passwordEdt));
  260. dto.setAge(getText(dobEdt));
  261. return dto;
  262. }
  263. private String validateFields() {
  264. if (isTextEmpty(userNameEdt)) {
  265. return "Enter your name";
  266. }
  267. if (isTextEmpty(mobileNoEdt)) {
  268. return "Enter mobile number";
  269. }
  270. if (mobileNoEdt.getText().toString().trim().length() <= 9) {
  271. return "Enter valid mobile number";
  272. }
  273. if (isTextEmpty(emailIdEdt)) {
  274. return "Enter mail ID";
  275. }
  276. if(!isValidEmailAddress(getText(emailIdEdt))){
  277. return "Enter valid mail ID";
  278. }
  279. if (isTextEmpty(passwordEdt)) {
  280. return "Enter app password";
  281. }
  282. if (getText(passwordEdt).length() < 6) {
  283. return "Password should be minimum 6 characters";
  284. }
  285. if (isTextEmpty(confPasswordEdt)) {
  286. return "Enter confirm password";
  287. }
  288. if (!getText(passwordEdt).equals(getText(confPasswordEdt))) {
  289. return "Password and confirm password are not matching";
  290. }
  291. if (isTextEmpty(addressEdt)) {
  292. return "Enter Address";
  293. }
  294. /*if (isTextEmpty(uidEdt)) {
  295. return "Enter UID";
  296. }*/
  297. if (isTextEmpty(dobEdt)) {
  298. return "Select Date of birth";
  299. }
  300. /*if (isTextEmpty(locationEdt)) {
  301. return "Enter your location";
  302. }*/
  303. if(!(imgFilePath != null && !imgFilePath.trim().isEmpty())){
  304. return "Please capture profile photo";
  305. }
  306. return null;
  307. }
  308. public boolean isValidEmailAddress(String email) {
  309. String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
  310. java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
  311. java.util.regex.Matcher m = p.matcher(email);
  312. return m.matches();
  313. }
  314. /*private static boolean isValidEmailAddress(String email) {
  315. boolean result = true;
  316. try {
  317. InternetAddress emailAddr = new InternetAddress(email);
  318. emailAddr.validate();
  319. } catch (AddressException ex) {
  320. result = false;
  321. }
  322. return result;
  323. }*/
  324. private void navigateApp() {
  325. Intent intent = new Intent(RegistrationActivity.this, OTPActivity.class);
  326. intent.putExtra("email", getText(emailIdEdt));
  327. finish();
  328. startActivity(intent);
  329. }
  330. private boolean isTextEmpty(EditText editText) {
  331. if (!editText.getText().toString().trim().isEmpty())
  332. return false;
  333. else
  334. return true;
  335. }
  336. private String getText(EditText editText) {
  337. return editText.getText().toString().trim();
  338. }
  339. /**
  340. * Creating google api client object
  341. */
  342. protected synchronized void buildGoogleApiClient() {
  343. if (mGoogleApiClient == null) {
  344. mGoogleApiClient = new GoogleApiClient.Builder(context)
  345. .addConnectionCallbacks(this)
  346. .addOnConnectionFailedListener(this)
  347. .addApi(LocationServices.API).build();
  348. createLocationRequest();
  349. }
  350. }
  351. /**
  352. * Creating location request object
  353. */
  354. protected void createLocationRequest() {
  355. if (mLocationRequest == null) {
  356. mLocationRequest = new LocationRequest();
  357. mLocationRequest.setInterval(0);
  358. mLocationRequest.setFastestInterval(0);
  359. mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
  360. mLocationRequest.setSmallestDisplacement(0); // 10 meters
  361. }
  362. }
  363. @Override
  364. public void onConnectionFailed(ConnectionResult result) {
  365. Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode());
  366. }
  367. @Override
  368. public void onConnected(Bundle arg0) {
  369. if (location != null && location.length() > 0)
  370. return;
  371. try {
  372. Location loc = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
  373. if (loc != null) {
  374. location = "" + loc.getLatitude() + "," + loc.getLongitude();
  375. }
  376. } catch (SecurityException e) {
  377. e.printStackTrace();
  378. }
  379. LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  380. if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  381. startLocationUpdates();
  382. mLocationCountDownTimer = new CountDownTimer(COUNT_DOWN_TIME, COUNT_DOWN_TIME_INTERVAL) {
  383. @Override
  384. public void onTick(long millisUntilFinished) {
  385. }
  386. @Override
  387. public void onFinish() {
  388. try {
  389. stopLocationUpdates();
  390. Location loc = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
  391. if (loc != null) {
  392. location = "" + loc.getLatitude() + "," + loc.getLongitude();
  393. }
  394. } catch (SecurityException e) {
  395. }
  396. }
  397. };
  398. mLocationCountDownTimer.start();
  399. }
  400. }
  401. @Override
  402. public void onConnectionSuspended(int arg0) {
  403. mGoogleApiClient.connect();
  404. }
  405. /**
  406. * Starting the location updates
  407. */
  408. protected void startLocationUpdates() {
  409. try {
  410. if (mGoogleApiClient.isConnected())
  411. LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
  412. } catch (SecurityException e) {
  413. }
  414. }
  415. /**
  416. * Stopping location updates
  417. */
  418. protected void stopLocationUpdates() {
  419. if (mGoogleApiClient.isConnected())
  420. LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
  421. }
  422. @Override
  423. public void onLocationChanged(Location loc) {
  424. // Assign the new location
  425. //mLastLocation = location;
  426. if (loc != null) {
  427. location = "" + loc.getLatitude() + "," + loc.getLongitude();
  428. stopLocationUpdates();
  429. cancelLocationTimer();
  430. }
  431. }
  432. private void cancelLocationTimer() {
  433. if (mLocationCountDownTimer != null) {
  434. mLocationCountDownTimer.cancel();
  435. mLocationCountDownTimer = null;
  436. }
  437. }
  438. protected void getCurrentLocation(final Context context) {
  439. LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  440. if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  441. if (mGoogleApiClient != null) {
  442. if (mGoogleApiClient.isConnected()) {
  443. mGoogleApiClient.disconnect();
  444. }
  445. mGoogleApiClient.connect();
  446. }
  447. showProgressDialog();
  448. new CountDownTimer(COUNT_DOWN_TIME, COUNT_DOWN_TIME_INTERVAL) {
  449. @Override
  450. public void onTick(long millisUntilFinished) {
  451. if (location != null) {
  452. hideProgressDialog();
  453. Toast.makeText(context, MyConstants.GOT_LOCATION_MSG, Toast.LENGTH_SHORT).show();
  454. this.cancel();
  455. }
  456. }
  457. @Override
  458. public void onFinish() {
  459. hideProgressDialog();
  460. Toast.makeText(context, MyConstants.GOT_LOCATION_MSG, Toast.LENGTH_SHORT).show();
  461. checkForLocation = false;
  462. this.cancel();
  463. }
  464. }.start();
  465. } else {
  466. Utility.showAlertToOpenGPS(context);
  467. }
  468. }
  469. public void showProgressDialog() {
  470. dialog = new ProgressDialog(context);
  471. dialog.setCanceledOnTouchOutside(false);
  472. dialog.setCancelable(false);
  473. dialog.setMessage("Please wait...");
  474. dialog.show();
  475. }
  476. public void hideProgressDialog() {
  477. if (dialog != null) {
  478. dialog.dismiss();
  479. }
  480. }
  481. public void onStart() {
  482. super.onStart();
  483. if ((mGoogleApiClient != null) && (!mGoogleApiClient.isConnected())) {
  484. mGoogleApiClient.connect();
  485. }
  486. }
  487. public void onStop() {
  488. super.onStop();
  489. if ((mGoogleApiClient != null) && (mGoogleApiClient.isConnected())) {
  490. mGoogleApiClient.disconnect();
  491. }
  492. }
  493. private void dispatchTakePictureIntent() {
  494. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  495. startActivityForResult(intent, IMAGECAPTURE_ACTIVITY);
  496. /*Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  497. if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
  498. startActivityForResult(takePictureIntent, IMAGECAPTURE_ACTIVITY);
  499. }*/
  500. }
  501. private void captureImage() {
  502. File dir;
  503. if (Utility.getFileDir(context) != null && Utility.getFileDir(context).length() > 0) {
  504. dir = new File(Utility.getFileDir(context));
  505. } else {
  506. // File sdCard = Environment.getExternalStorageDirectory();
  507. PackageManager m = getPackageManager();
  508. String s = getPackageName();
  509. try {
  510. PackageInfo p = m.getPackageInfo(s, 0);
  511. s = p.applicationInfo.dataDir;
  512. } catch (PackageManager.NameNotFoundException e) {
  513. Log.w("yourtag", "Error Package name not found ", e);
  514. return;
  515. }
  516. File sdCard = new File(s);
  517. dir = new File(sdCard.getAbsolutePath() + "/iSave");
  518. if (!dir.exists()) {
  519. dir.mkdir();
  520. }
  521. Utility.setFileDir(dir.toString(), context);
  522. }
  523. String uniqueId = getText(emailIdEdt)+".png";
  524. current = uniqueId;
  525. mypath = new File(dir, current);
  526. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  527. uriSavedImage = Uri.fromFile(mypath);
  528. //intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
  529. if (hasImageCaptureBug()) {
  530. intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
  531. } else {
  532. intent.putExtra(MediaStore.EXTRA_OUTPUT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  533. }
  534. startActivityForResult(intent, IMAGECAPTURE_ACTIVITY);
  535. }
  536. public boolean hasImageCaptureBug() {
  537. // list of known devices that have the bug
  538. ArrayList<String> devices = new ArrayList<String>();
  539. devices.add("android-devphone1/dream_devphone/dream");
  540. devices.add("generic/sdk/generic");
  541. devices.add("vodafone/vfpioneer/sapphire");
  542. devices.add("tmobile/kila/dream");
  543. devices.add("verizon/voles/sholes");
  544. devices.add("google_ion/google_ion/sapphire");
  545. return devices.contains(android.os.Build.BRAND + "/" + android.os.Build.PRODUCT + "/"
  546. + android.os.Build.DEVICE);
  547. }
  548. @Override
  549. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  550. switch (requestCode) {
  551. case IMAGECAPTURE_ACTIVITY:
  552. if (requestCode == IMAGECAPTURE_ACTIVITY && resultCode == Activity.RESULT_OK) {
  553. Bitmap photo = (Bitmap) data.getExtras().get("data");
  554. BitmapDrawable bitmapDrawable = new BitmapDrawable(photo);
  555. mCameraImg.setImageDrawable(bitmapDrawable);
  556. try {
  557. File dir;
  558. if (Utility.getFileDir(RegistrationActivity.this) != null && Utility.getFileDir(RegistrationActivity.this).length() > 0) {
  559. dir = new File(Utility.getFileDir(RegistrationActivity.this));
  560. } else {
  561. PackageManager m = getPackageManager();
  562. String s = getPackageName();
  563. try {
  564. PackageInfo p = m.getPackageInfo(s, 0);
  565. s = p.applicationInfo.dataDir;
  566. } catch (PackageManager.NameNotFoundException e) {
  567. Log.w("yourtag", "Error Package name not found ", e);
  568. return;
  569. }
  570. File sdCard = new File(s);
  571. dir = new File(sdCard.getAbsolutePath() + "/iSave");
  572. if (!dir.exists()) {
  573. dir.mkdir();
  574. }
  575. Utility.setFileDir(dir.toString(), RegistrationActivity.this);
  576. } // boolean
  577. //status = isExternalStoragePresent();
  578. String uniqueId = Utility.getCurrentDate().replaceAll("/", "_") + "_" + System.currentTimeMillis() + ".png";
  579. current = uniqueId;
  580. System.out.println("current" + current);
  581. mypath = new File(dir, current);
  582. FileOutputStream mFileOutStream = new FileOutputStream(mypath);
  583. photo.compress(Bitmap.CompressFormat.PNG, MyConstants.photoQuality, mFileOutStream); // Converting to byte array
  584. ByteArrayOutputStream stream = new ByteArrayOutputStream();
  585. photo.compress(Bitmap.CompressFormat.JPEG, MyConstants.photoQuality, stream);
  586. imgFilePath = current;
  587. Utility.setProfileImageURL(current, RegistrationActivity.this);
  588. System.out.println("capture image ===" + mypath);
  589. mFileOutStream.flush();
  590. mFileOutStream.close();
  591. } catch (FileNotFoundException e) {
  592. e.printStackTrace();
  593. } catch (IOException e) {
  594. e.printStackTrace();
  595. }
  596. /*try {
  597. BitmapFactory.Options options = new BitmapFactory.Options();
  598. options.inSampleSize = 4;
  599. final Bitmap bitmap = BitmapFactory.decodeFile(
  600. uriSavedImage.getPath(), options);
  601. FileOutputStream mFileOutStream;
  602. try {
  603. mFileOutStream = new FileOutputStream(
  604. uriSavedImage.getPath());
  605. bitmap.compress(Bitmap.CompressFormat.PNG, 0, mFileOutStream);
  606. mFileOutStream.flush();
  607. mFileOutStream.close();
  608. imgFilePath = current;
  609. } catch (FileNotFoundException e) {
  610. e.printStackTrace();
  611. } catch (IOException e) {
  612. e.printStackTrace();
  613. }
  614. mCameraImg.setImageDrawable(new BitmapDrawable(bitmap));
  615. //pending
  616. //mCamera.setBackgroundDrawable(new BitmapDrawable(bitmap));
  617. } catch (Exception e) {
  618. e.printStackTrace();
  619. }*/
  620. }
  621. break;
  622. }
  623. }
  624. public static String getIMEINo(Context context){
  625. try {
  626. StringBuilder builder = new StringBuilder("");
  627. TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  628. if (Build.VERSION.SDK_INT >= 23) {
  629. builder.append(manager.getDeviceId(0));
  630. if (manager.getPhoneCount() == 2) {
  631. builder.append(";");
  632. builder.append(manager.getDeviceId(1));
  633. }
  634. }
  635. return builder.toString();
  636. }catch (Exception e){
  637. return null;
  638. }
  639. }
  640. }