Java tutorial
package com.cybussolutions.wikki.afri_pay; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.DatePickerDialog; import android.app.Dialog; import android.app.DialogFragment; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.text.TextWatcher; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; import android.view.View.OnTouchListener; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.DatePicker; import android.widget.EditText; import android.widget.ImageView; import android.widget.RadioGroup; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import com.android.volley.AuthFailureError; import com.android.volley.DefaultRetryPolicy; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.Volley; import com.cybussolutions.wikki.afri_pay.Networking.SMSCode; import com.cybussolutions.wikki.afri_pay.Networking.SigningUp; import com.cybussolutions.wikki.afri_pay.Networking.onStart; import com.cybussolutions.wikki.afri_pay.Objects.Countrieslist; import com.cybussolutions.wikki.afri_pay.Utils.CheckConnection; import com.cybussolutions.wikki.afri_pay.Utils.DataBase; import com.cybussolutions.wikki.afri_pay.Utils.FieldValidator; import com.cybussolutions.wikki.afri_pay.Utils.ScalingUtilities; import com.koushikdutta.async.future.FutureCallback; import com.koushikdutta.ion.Ion; import com.koushikdutta.ion.ProgressCallback; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.ResponseHandler; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileDescriptor; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.concurrent.ExecutionException; @TargetApi(Build.VERSION_CODES.HONEYCOMB) public class SignUp extends AppCompatActivity { public String response; private ArrayList<Countrieslist> CountriesObjects; private ArrayList<String> CountriesName; // public static boolean username = true; // public static boolean open = false; Button buttonchoose; // ImageView imageView; String id = null; // String type=null; // String documentType,documentid,Expirydate; // RadioGroup doctype; // String value,typeid; Spinner country; // public static TextView SelectedDateView; EditText password, re_password, firstname, lastname, mobile, email; TextView countrycode; // for gender RadioGroup gender; String genderText = ""; String title = ""; private static final int MY_SOCKET_TIMEOUT_MS = 10000; String res = null; ProgressDialog ringProgressDialog; // int TAKE_PHOTO_CODE = 0; // public static Uri uri = null; // private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100; // public static final int MEDIA_TYPE_IMAGE = 1; // boolean flag = false; // private Bitmap bmp; // boolean imagechanged = false; // private int pick_image_req=1; // Bitmap bitmap; // Uri filepath; /* public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { int minMonth,minDay,minYear; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the current date as the default date in the picker final Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); minYear=year; minMonth=month+1; minDay=day; updateDisplay(minYear,minMonth,minDay); // Create a new instance of DatePickerDialog and return it return new DatePickerDialog(getActivity(), this, minYear, minMonth, minDay); } public void onDateSet(DatePicker view, int year, int month, int day) { view.setMinDate(Calendar.getInstance().getTimeInMillis()); Calendar userAge = new GregorianCalendar(year,month,day); Calendar minAdultAge = new GregorianCalendar(); minAdultAge.add(Calendar.YEAR,0); if (minAdultAge.after(userAge) ) { new DialogBox(getActivity(), "Your Document Seems to be Expired.", "", "Alert!"); } else{ SelectedDateView.setText(" "+(month + 1)+"-"+(day)+"-"+(year)); } } private void updateDisplay(int year, int month, int day) { // TODO Auto-generated method stub SelectedDateView.setText(" "+(month + 1)+"-"+(day)+"-"+(year)); } }*/ @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_up); this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); android.support.v7.app.ActionBar ab = getSupportActionBar(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Enable the Up button if (ab != null) { ab.setHomeAsUpIndicator(R.drawable.ic_back); ab.setDisplayHomeAsUpEnabled(true); ab.setTitle("Registration"); } // BugSenseHandler.initAndStartSession(this, "1c9ce82c"); // chromeHelpPopup = new ChromeHelpPopup(SignUp.this, "Password should contain capital and small alphabets, one number and one special character. Example: Cybus@12"); // SelectedDateView = (TextView) findViewById(R.id.DatePickerInput); // imageView=(ImageView)findViewById(R.id.signup_imageView); firstname = (EditText) findViewById(R.id.signup_firstName); lastname = (EditText) findViewById(R.id.signup_lastName); email = (EditText) findViewById(R.id.signup_email); mobile = (EditText) findViewById(R.id.signup_mobile); gender = (RadioGroup) findViewById(R.id.genderRG); gender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.mrRB: { genderText = "Male"; title = "Mr"; break; } case R.id.missRB: { genderText = "Female"; title = "Miss"; break; } case R.id.mrsRB: { genderText = "Female"; title = "Mrs"; break; } default: { break; } } } }); // idNo=(EditText) findViewById(R.id.signup_idNum); /* buttonchoose=(Button) findViewById(R.id.uploadimage); buttonchoose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // openGallery(v); } });*/ try { Button b = (Button) findViewById(R.id.signup_register); if (b != null) { b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub submit(v); } }); } Button cancel = (Button) findViewById(R.id.signup_cancel); if (cancel != null) { cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); } } catch (Exception e) { e.printStackTrace(); } /* doctype=(RadioGroup) findViewById(R.id.signup_doctype); doctype.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.signup_passport: value = "Passport"; typeid="5"; break; case R.id.signup_license: value = "Driving License"; typeid="4"; break; } } });*/ String COmpare = "United Kingdom"; CountriesObjects = new ArrayList<>(); CountriesName = new ArrayList<>(); DataBase DataBase = new DataBase(SignUp.this); CountriesObjects = DataBase.getCountriesDB(""); for (int i = 0; i < CountriesObjects.size(); i++) { CountriesName.add(CountriesObjects.get(i).getCountry_name()); } country = (Spinner) findViewById(R.id.signup_countries_spinner); ArrayAdapter adapter201 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, CountriesName); country.setAdapter(adapter201); if (!COmpare.equals(null)) { int spinnerPosition = adapter201.getPosition(COmpare); country.setSelection(spinnerPosition); } country.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub // InputMethodManager inputMethodManager = (InputMethodManager) // getSystemService(Activity.INPUT_METHOD_SERVICE); // inputMethodManager.hideSoftInputFromWindow(getCurrentFocus() // .getWindowToken(), 0); return false; } }); country.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long arg3) { // TODO Auto-generated method stub countrycode = (TextView) findViewById(R.id.signup_code); countrycode.setText("+" + CountriesObjects.get(pos).getCalling_code()); countrycode.setEnabled(false); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); // user_name = (EditText) findViewById(R.id.signup_userName); password = (EditText) findViewById(R.id.signup_password); re_password = (EditText) findViewById(R.id.signup_confirmpassword); re_password.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub EditText e = (EditText) findViewById(R.id.signup_password); String pass = e.getText().toString(); TextView d = (TextView) findViewById(R.id.matchPassword); if (!pass.contentEquals(s)) { d.setText("Passwords Do not Match"); d.setVisibility(View.VISIBLE); } else { d.setVisibility(View.GONE); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); } public void submit(View v) { //signupVolley(); /* ringProgressDialog = ProgressDialog.show(this, "", "please wait", true); ringProgressDialog.setCancelable(false); ringProgressDialog.show();*/ SigningUp newForm = new SigningUp(this); String Fname, Lname, Password, Email, CountryCode, number, confirm, Country; Fname = firstname.getText().toString(); Lname = lastname.getText().toString(); // Username = user_name.getText().toString(); Password = password.getText().toString(); Email = email.getText().toString(); CountryCode = countrycode.getText().toString(); number = mobile.getText().toString(); confirm = re_password.getText().toString(); /* if(imageView.getDrawable() == null) { image = ""; } else { image="12345"; } if (doctype.getCheckedRadioButtonId() == -1) { radio = ""; } else { radio = "12345"; } */ Country = country.getSelectedItem().toString(); int index = CountriesName.indexOf(Country); String countryID = CountriesObjects.get(index).getId(); // String res = null; if (Password.equalsIgnoreCase("Cybus@12")) { new DialogBox(this, "Example Password cannot be used as a password", "", "Alert!"); return; } try { if (CheckConnection.checkStatus(this) && FieldValidator.lengthValidator(this, title, 2, 10, "Title") && FieldValidator.lengthValidator(this, Fname, 3, 20, "First Name") && FieldValidator.lengthValidator(this, Lname, 3, 20, "Last Name") && FieldValidator.lengthValidator(this, countryID, 1, 20, "Country") && FieldValidator.lengthValidator(this, CountryCode, 1, 20, "Country") && FieldValidator.match(this, Password, confirm) && FieldValidator.lengthValidator(this, Email, 0, 100, "Email") && FieldValidator.ValidateEmail(this, Email) && FieldValidator.lengthValidator(this, CountryCode, 2, 4, "Carrier Code") && FieldValidator.lengthValidator(this, number, 10, 11, "Mobile Number") && FieldValidator.lengthValidator(this, Password, 5, 20, "Password") && FieldValidator.lengthValidator(this, confirm, 5, 20, "Confirm Password") // && FieldValidator.lengthValidator(this, image, 0, 11, "Image") // && FieldValidator.lengthValidator(this, radio, 0, 11, "Type Of Document") // && FieldValidator.lengthValidator(this, idNo.getText().toString(), 0, 100, "ID Of Document") // && FieldValidator.lengthValidator(this, SelectedDateView.getText().toString(), 0, 100, "Expiry Date") ) { res = newForm .execute(Fname, Lname, Password, CountryCode, number, Email, countryID, genderText, title) .get(); // ringProgressDialog.dismiss(); } if (!CheckConnection.checkStatus(this)) { new DialogBox(this, "No Network Found", "", "Alert!"); } else if (!(res == null)) { if (res.contains("Registered Sucessfully")) { String sms_sent_response = ""; SMSCode tempSmsCode = new SMSCode(this); sms_sent_response = tempSmsCode.execute(String.valueOf(LoginActivity.session_id)).get(); if (sms_sent_response.equals("true")) { new DialogBox(this, res, "7", "Alert! Sms code sent! Please save it for first time login"); } } else if (res.equalsIgnoreCase("exception")) { new DialogBox(this, "Unable to complete your request.", "", "Alert!"); } else if (res.equalsIgnoreCase("A user is already registered with this email.")) { new DialogBox(this, "A user is already registered with this email.", "", "Alert!"); } else if (!res.isEmpty()) { new DialogBox(this, res, "", "Alert!"); } else if (res.isEmpty() && CheckConnection.checkStatus(this)) { new DialogBox(this, "Some error occurred", "", "Alert!"); } } } catch (InterruptedException e1) { e1.printStackTrace(); } catch (ExecutionException e1) { e1.printStackTrace(); } } private void signupVolley() { final String Fname, Lname, Password, Email, CountryCode, number, confirm, Country; Fname = firstname.getText().toString(); Lname = lastname.getText().toString(); // Username = user_name.getText().toString(); Password = password.getText().toString(); Email = email.getText().toString(); CountryCode = countrycode.getText().toString(); number = mobile.getText().toString(); confirm = re_password.getText().toString(); /* if(imageView.getDrawable() == null) { image = ""; } else { image="12345"; } if (doctype.getCheckedRadioButtonId() == -1) { radio = ""; } else { radio = "12345"; } */ Country = country.getSelectedItem().toString(); int index = CountriesName.indexOf(Country); final String countryID = CountriesObjects.get(index).getId(); // String res = null; if (Password.equalsIgnoreCase("Cybus@12")) { new DialogBox(this, "Example Password cannot be used as a password", "", "Alert!"); return; } if (CheckConnection.checkStatus(this) && FieldValidator.lengthValidator(this, title, 2, 10, "Title") && FieldValidator.lengthValidator(this, Fname, 3, 20, "First Name") && FieldValidator.lengthValidator(this, Lname, 3, 20, "Last Name") && FieldValidator.lengthValidator(this, countryID, 1, 20, "Country") && FieldValidator.lengthValidator(this, CountryCode, 1, 20, "Country") && FieldValidator.match(this, Password, confirm) && FieldValidator.lengthValidator(this, Email, 0, 100, "Email") && FieldValidator.ValidateEmail(this, Email) && FieldValidator.lengthValidator(this, CountryCode, 2, 4, "Carrier Code") && FieldValidator.lengthValidator(this, number, 10, 11, "Mobile Number") && FieldValidator.lengthValidator(this, Password, 5, 20, "Password") && FieldValidator.lengthValidator(this, confirm, 5, 20, "Confirm Password") // && FieldValidator.lengthValidator(this, image, 0, 11, "Image") // && FieldValidator.lengthValidator(this, radio, 0, 11, "Type Of Document") // && FieldValidator.lengthValidator(this, idNo.getText().toString(), 0, 100, "ID Of Document") // && FieldValidator.lengthValidator(this, SelectedDateView.getText().toString(), 0, 100, "Expiry Date") ) { if (!FieldValidator.checkPasswordStrength(Password).equals("Very Poor Password") && !FieldValidator.checkPasswordStrength(Password).equals("Poor Password") && !FieldValidator.checkPasswordStrength(Password).equals("Normal Password") && isDataEntered()) { StringRequest request = new StringRequest(Request.Method.POST, LoginActivity.currentSession.base_url + "home/register_user_cp/", new Response.Listener<String>() { @Override public void onResponse(String response) { res = response; if (response.contains("unable to allocate memory for pool")) { res = "Exception"; } if (response.contains("logout")) { res = "Exception"; } if (!CheckConnection.checkStatus(getApplication().getApplicationContext())) { new DialogBox(SignUp.this, "No Network Found", "", "Alert!"); } else if (!(res == null)) { if (!res.equals("false2") && !res.equals("A user is already registered with this email.") && !res.isEmpty()) { String sms_sent_response = ""; SMSCode tempSmsCode = new SMSCode(SignUp.this); try { sms_sent_response = tempSmsCode.execute(res).get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } if (sms_sent_response.equals("true")) { new DialogBox(SignUp.this, res, "7", "Alert! Sms code sent! Please save it for first time login"); } } else if (res.equalsIgnoreCase("exception")) { new DialogBox(SignUp.this, "Unable to complete your request.", "", "Alert!"); } else if (res .equalsIgnoreCase("A user is already registered with this email.")) { new DialogBox(SignUp.this, "A user is already registered with this email.", "", "Alert!"); } else if (res.isEmpty() && CheckConnection.checkStatus(SignUp.this)) { new DialogBox(SignUp.this, "Some error occurred", "", "Alert!"); } } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(SignUp.this, error.toString(), Toast.LENGTH_SHORT).show(); } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> params = new HashMap<>(); String mobile = CountryCode + number; params.put("firstName", Fname); params.put("lastName", Lname); params.put("password", Password); params.put("Mobile", mobile); params.put("email", Email); params.put("country_id", countryID); params.put("gender", genderText); params.put("Title", title); return params; } }; request.setRetryPolicy(new DefaultRetryPolicy(MY_SOCKET_TIMEOUT_MS, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext()); requestQueue.add(request); } } else { new DialogBox(this, "Your password is not strong enough to be used. Try using a combination of Uppercase/Lowercase letters, numbers and special chrachters.", "", "Alert!"); } } public boolean isDataEntered() { boolean dataEntered = true; if (country.getSelectedItem().toString() == null) { new DialogBox(this, "Select Country", "", "Field Empty"); } return dataEntered; } /* public void openGallery(View v) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1); } private File getOutputMediaFile(int type) { String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date(type)); File file = null; try { String fileName = Uri.parse(timeStamp).getLastPathSegment(); file = File.createTempFile(fileName, ".jpg", this.getExternalCacheDir()); } catch (IOException e) { new DialogBox(this, "There was an error initializing camera", "", "Error"); } return file; } private Uri getOutputMediaFileUri(int type) { return Uri.fromFile(getOutputMediaFile(type)); } public String getPath(Uri uri) { if (uri == null) { return null; } String[] projection = { MediaStore.MediaColumns.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } return uri.getPath(); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == 1) { uri = null; Uri selectedImageUri = null; if (Build.VERSION.SDK_INT < 19) { uri = null; selectedImageUri = data.getData(); String selectedImagePath = getPath(selectedImageUri); if (selectedImagePath != null) { bmp = BitmapFactory.decodeFile(selectedImagePath); ImageView img = (ImageView) findViewById(R.id.signup_imageView); Bitmap temp = com.cybussolutions.wikki.afri_pay.Utils.ScalingUtilities .createScaledBitmap(bmp, 640, 480, ScalingUtilities.ScalingLogic.FIT); img.setImageBitmap(temp); uri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); img.setVisibility(View.VISIBLE); imagechanged = true; } else { new DialogBox(this, "No image selected", "", "Alert!"); } } else { ParcelFileDescriptor parcelFileDescriptor; try { imagechanged = true; selectedImageUri = data.getData(); parcelFileDescriptor = getContentResolver().openFileDescriptor(selectedImageUri, "r"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor); parcelFileDescriptor.close(); uri = selectedImageUri; bmp = com.cybussolutions.wikki.afri_pay.Utils.ScalingUtilities.createScaledBitmap(image, 1024, 768, ScalingUtilities.ScalingLogic.FIT); imageView.setImageBitmap(bmp); bmp = image; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } public boolean uploadImage() throws FileNotFoundException { final ProgressDialog bar = new ProgressDialog(this); bar.setMessage("UpLoading Document.."); bar.setProgressStyle(ProgressDialog.STYLE_SPINNER); bar.setCancelable(true); bar.show(); if (bmp == null) { new DialogBox(this, "Please Select a Image to Upload.", "", "Alert!"); return false; } else if (bmp.isRecycled()) { new DialogBox(this, "This image cannot be selected. Please use another image.", "", "Alert!"); return false; } else if (CheckConnection.checkStatus(getApplicationContext())) { ByteArrayOutputStream bmpStream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.JPEG, 100, bmpStream); byte[] byte_arr = bmpStream.toByteArray(); // bmp.recycle(); FileOutputStream outputStream; File f = null; try { SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss"); String date = sdf.format(new Date()); f = new File(getCacheDir(), date + ".jpg"); outputStream = new FileOutputStream(f); outputStream.write(byte_arr); outputStream.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (LoginActivity.currentSession.loggedin == false) { StringBuilder sb = new StringBuilder(); id = sb.append(LoginActivity.session_id).toString(); type=typeid.toString(); documentType=value.toString(); documentid=idNo.getText().toString(); Expirydate=SelectedDateView.getText().toString().trim(); StringTokenizer st = new StringTokenizer(Expirydate,"-"); String day = "00", month = "00", year = "0000"; if (st.hasMoreTokens()) { month = st.nextToken(); } if (st.hasMoreTokens()) { day = st.nextToken(); } if (st.hasMoreTokens()) { year = st.nextToken(); } Expirydate= year + "-" + month + "-" + day; } else { id = LoginActivity.currentSession.newProfile.getUserID(); type=typeid.toString(); documentType=value.toString(); documentid=idNo.getText().toString(); Expirydate=SelectedDateView.getText().toString().trim(); StringTokenizer st = new StringTokenizer(Expirydate,"-"); String day = "00", month = "00", year = "0000"; if (st.hasMoreTokens()) { month = st.nextToken(); } if (st.hasMoreTokens()) { day = st.nextToken(); } if (st.hasMoreTokens()) { year = st.nextToken(); } Expirydate= year + "-" + month + "-" + day; } Ion.with(this, LoginActivity.currentSession.base_url + "home/upload_cp/docs").uploadProgressHandler(new ProgressCallback() { @Override public void onProgress(long downloaded, long total) { // TODO Auto-generated method stub } }).setMultipartParameter("id", id).setMultipartParameter("type_id",type).setMultipartParameter("doc_Name",documentType) .setMultipartParameter("idnumber",documentid).setMultipartParameter("expirydate",Expirydate) .setMultipartFile("file", f).asString() .setCallback(new FutureCallback<String>() { @Override public void onCompleted(Exception e, String result) { // TODO Auto-generated method stub if (!result.contains("warning") || !result.contains("error")) { bar.dismiss(); } else { bar.dismiss(); new DialogBox(SignUp.this, "Something went wrong while uploading the image.", "", "Alert!"); } } }); imagechanged = false; } else { new DialogBox(this, "No Network Found.", "", "Alert!"); return false; } return true; } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (uri != null) { outState.putString("cameraImageUri", uri.toString()); } } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.containsKey("cameraImageUri")) { uri = Uri.parse(savedInstanceState.getString("cameraImageUri")); } } public void showDatePickerDialog(View v){ DialogFragment newFragment=new DatePickerFragment(); newFragment.show(getFragmentManager(), "datePicker"); }*/ }