Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package enkay.avbio.Activities;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.database.Cursor;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.net.Uri;
- import android.os.Build;
- import android.provider.MediaStore;
- import android.support.design.widget.Snackbar;
- import android.support.design.widget.TextInputEditText;
- import android.support.design.widget.TextInputLayout;
- import android.support.v4.app.ActivityCompat;
- import android.support.v4.widget.NestedScrollView;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.support.v7.widget.AppCompatButton;
- import android.support.v7.widget.AppCompatImageView;
- import android.support.v7.widget.AppCompatTextView;
- import android.util.Log;
- import android.view.View;
- import android.widget.ImageView;
- import android.widget.Toast;
- import java.io.ByteArrayOutputStream;
- import enkay.avbio.Helper.InputValidation;
- import enkay.avbio.Manifest;
- import enkay.avbio.Model.User;
- import enkay.avbio.R;
- import enkay.avbio.Sql.DatabaseHelper;
- public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{
- private final AppCompatActivity activity = RegisterActivity.this;
- private TextInputLayout textInputLayoutName;
- private TextInputLayout textInputLayoutEmail;
- private TextInputLayout TextInputLayoutPassword;
- private TextInputLayout textInputLayoutConfirmPassword;
- //private TextInputLayout textInputLayoutAddress;
- private TextInputLayout textInputLayoutCompanyName;
- private TextInputLayout textInputLayoutCompanyAddress;
- private TextInputLayout textInputLayoutGstNo;
- private TextInputLayout textInputLayoutPanNo;
- private NestedScrollView nestedScrollView;
- private TextInputEditText textInputEditTextName;
- private TextInputEditText textInputEditTextEmail;
- private TextInputEditText textInputEditTextPassword;
- private TextInputEditText textInputEditTextConfirmPassword;
- //private TextInputEditText textInputEditTextAddress;
- private TextInputEditText textInputEditTextCompanyName;
- private TextInputEditText textInputEditTextCompanyAddress;
- private TextInputEditText textInputEditTextGstNo;
- private TextInputEditText textInputEditTextPanNo;
- private ImageView img;
- private AppCompatButton appCompatButton;
- private AppCompatTextView appCompatTextView;
- private AppCompatTextView appCompatTextView2;
- private InputValidation inputValidation;
- private DatabaseHelper databaseHelper;
- private User user;
- private static int RESULT_LOAD_IMG = 1;
- String imgDecodableString;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- initViews();
- initListeners();
- initObjects();
- }
- private void initViews() {
- textInputLayoutName = (TextInputLayout) findViewById(R.id.TextInputLayoutName);
- textInputLayoutEmail = (TextInputLayout) findViewById(R.id.TextInputLayoutEmail);
- TextInputLayoutPassword = (TextInputLayout) findViewById(R.id.TextInputLayoutPassword);
- textInputLayoutConfirmPassword = (TextInputLayout) findViewById(R.id.TextInputLayoutConfirmPassword);
- // textInputLayoutAddress = (TextInputLayout) findViewById(R.id.TextInputLayoutAddress);
- textInputLayoutCompanyName=(TextInputLayout)findViewById(R.id.TextInputLayoutCompanyName);
- textInputLayoutCompanyAddress=(TextInputLayout)findViewById(R.id.TextInputLayoutCompanyAddress);
- textInputLayoutGstNo=(TextInputLayout)findViewById(R.id.TextInputLayoutGstNo);
- textInputLayoutPanNo=(TextInputLayout)findViewById(R.id.TextInputLayoutPanNo);
- textInputEditTextName = (TextInputEditText) findViewById(R.id.TextInputEditTextName);
- textInputEditTextEmail = (TextInputEditText) findViewById(R.id.TextInputEditTextEmail);
- textInputEditTextPassword = (TextInputEditText) findViewById(R.id.TextInputEditTextPassword);
- textInputEditTextConfirmPassword = (TextInputEditText) findViewById(R.id.TextInputEditTextConfirmPassword);
- // textInputEditTextAddress = (TextInputEditText) findViewById(R.id.TextInputEditTextAddress);
- textInputEditTextCompanyName = (TextInputEditText) findViewById(R.id.TextInputEditTextCompanyName);
- textInputEditTextCompanyAddress = (TextInputEditText) findViewById(R.id.TextInputEditTextCompanyAddress);
- textInputEditTextGstNo=(TextInputEditText)findViewById(R.id.TextInputEditTextGstNo);
- textInputEditTextPanNo=(TextInputEditText)findViewById(R.id.TextInputEditTextPanNo);
- appCompatTextView=(AppCompatTextView)findViewById(R.id.txt) ;
- nestedScrollView=(NestedScrollView)findViewById(R.id.newscroll);
- appCompatButton=(AppCompatButton)findViewById(R.id.appCompatButtonregister);
- appCompatTextView2=(AppCompatTextView)findViewById(R.id.textViewLinkLogin);
- appCompatTextView2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v)
- {
- Intent mv=new Intent(getApplicationContext(),LoginActivity.class);
- startActivity(mv);
- }
- });
- }
- private void initListeners()
- {
- appCompatButton.setOnClickListener(this);
- appCompatTextView.setOnClickListener(this);
- }
- private void initObjects()
- {
- inputValidation = new InputValidation(activity);
- databaseHelper = new DatabaseHelper(activity);
- user=new User();
- }
- @Override
- public void onClick(View view)
- {
- switch(view.getId())
- {
- case R.id.appCompatButtonregister:
- postDataToSQlite();
- break;
- case R.id.txt:
- finish();
- break;
- }
- }
- private void postDataToSQlite()
- {
- if (!inputValidation.isInputEditTextFilled(textInputEditTextName,textInputLayoutName,getString(R.string.error_message_name)))
- {
- return;
- }
- if (!inputValidation.isInputEditTextEmail(textInputEditTextEmail,textInputLayoutEmail,getString(R.string.error_message_email)))
- {
- return;
- }
- if (!inputValidation.isInputEditTextFilled(textInputEditTextEmail,textInputLayoutEmail,getString(R.string.error_message_email)))
- {
- return;
- }
- if (!inputValidation.isInputEditTextFilled(textInputEditTextPassword,textInputLayoutConfirmPassword,getString(R.string.error_message_password)))
- {
- return;
- }
- // if (!inputValidation.isInputEditTextAdress(textInputEditTextAddress,textInputLayoutAddress,getString(R.string.error_valid_address)))
- // {
- // return;
- // }
- if (!inputValidation.isInputEditTextCompanyName(textInputEditTextCompanyName,textInputLayoutCompanyName,getString(R.string.error_valid_Company_name)))
- {
- return;
- }
- if (!inputValidation.isInputEditTextCompanyAddress(textInputEditTextCompanyAddress,textInputLayoutCompanyAddress,getString(R.string.error_valid_Company_address)))
- {
- return;
- }
- if (!inputValidation.isInputEditTextGstNo(textInputEditTextGstNo,textInputLayoutGstNo,getString(R.string.error_valid_gst_no)))
- {
- return;
- }
- if (!inputValidation.isInputEditTextPanNo(textInputEditTextPanNo,textInputLayoutPanNo,getString(R.string.error_valid_pan_no)))
- {
- return;
- }
- if (!inputValidation.isInputEditTextMatches(textInputEditTextPassword,textInputEditTextConfirmPassword,textInputLayoutConfirmPassword,getString(R.string.error_password_match)))
- {
- return;
- }
- if (!databaseHelper.checkUser(textInputEditTextEmail.getText().toString().trim())){
- user.setName(textInputEditTextName.getText().toString().trim());
- user.setEmail(textInputEditTextEmail.getText().toString().trim());
- user.setPasswod(textInputEditTextPassword.getText().toString().trim());
- // user.setAddress(textInputEditTextAddress.getText().toString());
- user.setCompanyName(textInputEditTextCompanyName.getText().toString().trim());
- user.setCompanyAddress(textInputEditTextCompanyAddress.getText().toString().trim());
- user.setGstNo(textInputEditTextGstNo.getText().toString().trim());
- user.setPanNo(textInputEditTextPanNo.getText().toString().trim());
- user.setImageByte(imageData);
- databaseHelper.addUser(user);
- Snackbar.make(nestedScrollView,getString(R.string.success_message),Snackbar.LENGTH_LONG);
- emptyInputEditText();
- }else
- {
- Snackbar.make(nestedScrollView,getString(R.string.text_email_exists),Snackbar.LENGTH_LONG);
- }
- }
- private void emptyInputEditText()
- {
- textInputEditTextName.setText(null);
- textInputEditTextEmail.setText(null);
- textInputEditTextPassword.setText(null);
- textInputEditTextConfirmPassword.setText(null);
- //textInputEditTextAddress.setText(null);
- textInputEditTextCompanyName.setText(null);
- textInputEditTextCompanyAddress.setText(null);
- textInputEditTextGstNo.setText(null);
- textInputEditTextPanNo.setText(null);
- }
- byte[] imageData;
- public void ChangeLogo(View view)
- {
- // Create intent to Open Image applications like Gallery, Google Photos
- Intent galleryIntent=new Intent(Intent.ACTION_PICK,
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
- // Start the Intent
- if(isStoragePermissionGranted())
- startActivityForResult(galleryIntent,RESULT_LOAD_IMG);
- else {
- //Toast.makeText(activity, "Permission not granted", Toast.LENGTH_SHORT).show();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, 101);
- }
- }
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- // When an Image is picked
- if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
- && null != data) {
- // Get the Image from data
- pickImage(data);
- }
- else {
- Toast.makeText(this, "You haven't picked Image",
- Toast.LENGTH_LONG).show();
- }
- }
- @Override
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- if(grantResults[0]== PackageManager.PERMISSION_GRANTED){
- Log.v(TAG,"Permission: "+permissions[0]+ "was "+grantResults[0]);
- //resume tasks needing this permission
- Intent galleryIntent=new Intent(Intent.ACTION_PICK,
- MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
- startActivityForResult(galleryIntent,RESULT_LOAD_IMG);
- }
- else
- Toast.makeText(activity, "Permission not granted", Toast.LENGTH_SHORT).show();
- }
- private void pickImage(Intent data){
- try {
- Uri selectedImage = data.getData();
- String[] filePathColumn = {MediaStore.Images.Media.DATA};
- // Get the cursor
- Cursor cursor = getContentResolver().query(selectedImage,
- filePathColumn, null, null, null);
- // Move to first row
- cursor.moveToFirst();
- int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
- imgDecodableString = cursor.getString(columnIndex);
- cursor.close();
- AppCompatImageView imgView = (AppCompatImageView) findViewById(R.id.img);
- // Set the Image in ImageView after decoding the String
- Bitmap bitmap = BitmapFactory
- .decodeFile(imgDecodableString);
- imgView.setImageBitmap(bitmap);
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.PNG, 50, bout);
- imageData = bout.toByteArray();
- }
- catch (Exception e) {
- Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
- .show();
- Log.e("TAG", "onActivityResult: error = "+e.toString());
- e.printStackTrace();
- }
- }
- String TAG = RegisterActivity.class.getCanonicalName();
- public boolean isStoragePermissionGranted() {
- if (Build.VERSION.SDK_INT >= 23) {
- if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
- == PackageManager.PERMISSION_GRANTED) {
- Log.v(TAG,"Permission is granted");
- return true;
- } else {
- Log.v(TAG,"Permission is revoked");
- // ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
- return false;
- }
- }
- else { //permission is automatically granted on sdk<23 upon installation
- Log.v(TAG,"Permission is granted");
- return true;
- }
- }
- }
Add Comment
Please, Sign In to add comment