public void init(){
edt_uname = (EditText) findViewById(R.id.edt_uname);
edt_phone = (EditText) findViewById(R.id.edt_phone);
edt_pass = (EditText) findViewById(R.id.edt_pass);
edt_conf_pass = (EditText) findViewById(R.id.edt_conf_pass);
edt_email = (EditText) findViewById(R.id.edt_email);
upload_display_image = (ImageView) findViewById(R.id.imgView);
btn_registration = (Button) findViewById(R.id.btn_registration);
btn_registration.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if(cm.getActiveNetworkInfo() != null){
r_uname = edt_uname.getText().toString();
r_phone = edt_phone.getText().toString();
r_pass = edt_pass.getText().toString();
r_conf_pass = edt_conf_pass.getText().toString();
r_email = edt_email.getText().toString();
if (edt_uname.length() > 0 && edt_phone.length() > 0 && edt_phone.length()==10 && edt_pass.length() > 0 && edt_pass.length()>=4 && edt_conf_pass.length() > 0 && edt_email.length() > 0 && isValidEmail(r_email))
{
if(edt_pass.getText().toString().equals(edt_conf_pass.getText().toString())) {
if (filePath != null) {
uploadImage = getStringImage(bitmap);
Register_database();
} else {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(registration.this);
alertDialog.setTitle("Alert");
alertDialog.setMessage("Please Select Image");
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
dialog.cancel();
}
});
alertDialog.show();
}
}
else {
edt_conf_pass.requestFocus();
edt_conf_pass.setError("Password And Confirm Passsword Does Not Match ");
}
}
else {
if (r_uname.length() == 0)
{
edt_uname.requestFocus();
edt_uname.setError("Enter User Name");
}
else if (r_phone.length() <=0) {
edt_phone.requestFocus();
edt_phone.setError("Enter Phone Number");
}
else if (r_phone.length() < 10) {
edt_phone.requestFocus();
edt_phone.setError("Enter Must Be 10 Digit");
}
else if (r_pass.length() <= 0)
{
edt_pass.requestFocus();
edt_pass.setError("Enter Password ");
}
else if(r_pass.length() < 4)
{
edt_pass.requestFocus();
edt_pass.setError("Enter Password Must Be 5 char");
}
else if (r_conf_pass.length() <= 0) {
edt_conf_pass.requestFocus();
edt_conf_pass.setError("Enter Confirm Password");
}
else if (!edt_pass.getText().toString().equals(edt_conf_pass.getText().toString())) //conform password velidation textviee nu id levu {
// else if (r_conf_pass.length() < 5) { edt_conf_pass.requestFocus();
edt_conf_pass.setError("Password And Confirm Password Does Not Match");
}
else if (edt_email.length()<=0)
{
edt_email.requestFocus();
edt_email.setError("Enter Email");
}
else if (!isValidEmail(r_email))
{
edt_email.requestFocus();
edt_email.setError("Enter valid Email");
}
}
}else {
Toast.makeText(getApplicationContext(), "Please Check Internet Connection", Toast.LENGTH_SHORT).show();
}
}
});
//display button selected Image======================
Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View arg0) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
});
//clode image code ==========================}
@Overridepublic boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
//image feach from storeg media========================
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
upload_display_image.setImageBitmap(bitmap);
bitmap = Bitmap.createScaledBitmap(bitmap, 250, 250, false);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public String getStringImage(Bitmap bmp) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
/*close image code===========================*/
public final static boolean isValidEmail(CharSequence uname) {
return !TextUtils.isEmpty(uname) && android.util.Patterns.EMAIL_ADDRESS.matcher(uname).matches();
}
public void Register_database() {
final ProgressDialog loading = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
loading.setMessage("Loading");
loading.show();
loading.setCancelable(true);
loading.setCanceledOnTouchOutside(false);
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(BASE_URL) //Setting the Root URL .build();
AppConfig.insert_record api = adapter.create(AppConfig.insert_record.class);
api.insertData(
edt_uname.getText().toString(),
edt_phone.getText().toString(),
edt_pass.getText().toString(),
edt_conf_pass.getText().toString(),
edt_email.getText().toString(),
uploadImage,
new Callback<Response>() {
@Override public void success(Response result, Response response) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
String resp;
resp = reader.readLine();
Log.d("success", "" + resp);
JSONObject jObj = new JSONObject(resp);
int success = jObj.getInt("success");
if (success == 1) {
loading.dismiss();
Toast.makeText(getApplicationContext(), "Successfully Registration", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish();
} else {
loading.dismiss();
Toast.makeText(getApplicationContext(), "Your Mobile Already Registreed Plese Try Another Mobile", Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
Log.d("Exception", e.toString());
} catch (JSONException e) {
Log.d("JsonException", e.toString());
}
}
@Override public void failure(RetrofitError error) {
Toast.makeText(registration.this,"Check Your Internet Connection", Toast.LENGTH_LONG).show();
}
}
);
}
========================
public interface insert_record {
@FormUrlEncoded @POST("/status/user_registration.php")
void insertData(
@Field("user_name") String edt_uname,
@Field("user_mobile_no") String edt_phone,
@Field("user_password") String edt_pass,
@Field("user_confirm_password") String edt_conf_pass,
@Field("user_email") String edt_email,
@Field("user_image") String uploadImage,
Callback<Response> callback);
}
Comments
Post a Comment