Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.retinax.metoo.UI;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.net.URI;
- import java.util.Calendar;
- import java.util.TimeZone;
- import java.util.regex.Pattern;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.ProgressDialog;
- import android.content.ContentValues;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.pm.ActivityInfo;
- import android.content.res.Configuration;
- import android.database.Cursor;
- import android.graphics.Bitmap;
- import android.graphics.Color;
- import android.graphics.PixelFormat;
- import android.net.Uri;
- import android.os.Bundle;
- import android.os.Environment;
- import android.os.Handler;
- import android.os.Message;
- import android.provider.MediaStore;
- import android.provider.MediaStore.Images;
- import android.provider.MediaStore.Images.Media;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowManager;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.Toast;
- import com.retinax.metoo.R;
- import com.retinax.metoo.API.Http;
- import com.retinax.metoo.API.sharedPreference;
- public class signup extends Activity {
- protected static final String LOG_TAG = "LOGIN SCREEN";
- String path , name;
- int USERNAME_ALREADY_EXISTS=5;
- Uri currImageURI = null;
- ImageView iv;
- Http hp;
- EditText user , pass , cpass , email;
- String username,password , email_string;
- private ProgressDialog progressDialog;
- Handler hd;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
- setContentView(R.layout.signup);
- hp = new Http();
- // get username and password from SQLite database
- //getUserInfo();
- user =(EditText)findViewById(R.id.username_value);
- pass =(EditText)findViewById(R.id.password_value);
- cpass =(EditText)findViewById(R.id.cpassword_value);
- email = (EditText)findViewById(R.id.email_value);
- hd = new Handler(){
- @Override
- public void dispatchMessage(Message msg) {
- // TODO Auto-generated method stub
- super.dispatchMessage(msg);
- switch(msg.what)
- {
- case 0: { user.setHintTextColor(Color.RED);
- pass.setHintTextColor(Color.RED);
- email.setHintTextColor(Color.RED);
- cpass.setHintTextColor(Color.RED);
- Toast.makeText( getApplicationContext(),
- "Fields in Red are Mandatory.",
- Toast.LENGTH_SHORT ).show();
- }
- break;
- case 1:{ progressDialog.dismiss();
- Toast.makeText( getApplicationContext(),
- "User Created Successfully",
- Toast.LENGTH_SHORT ).show();
- signup.this.finish();}
- break;
- case 5 :{
- progressDialog.dismiss();
- Toast.makeText( getApplicationContext(),
- "Username already exists.",
- Toast.LENGTH_SHORT ).show();
- // signup.this.finish();
- }
- case 6 :{
- progressDialog.dismiss();
- Toast.makeText( getApplicationContext(),
- "Email Already exists",
- Toast.LENGTH_SHORT ).show();
- // signup.this.finish();
- }
- break;
- case 7 :{
- progressDialog.dismiss();
- Toast.makeText( getApplicationContext(),
- "Confirm Password must match with Password.",
- Toast.LENGTH_SHORT ).show();
- // signup.this.finish();
- }
- }
- }
- };
- Button b1 , b2;
- iv = (ImageView)findViewById(R.id.image);
- b1 = (Button)findViewById(R.id.signup);
- b1.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- username = user.getEditableText().toString();
- password = pass.getEditableText().toString();
- email_string=email.getEditableText().toString();
- if(username.contains("<")||username.contains(">")||username.contains("'")||username.contains("\""))
- {
- Toast.makeText(getApplicationContext(), "Invalid Username, Enter only alphanumeric value", Toast.LENGTH_SHORT).show();
- }
- else if(password.contains(" ")||username.contains(" "))
- {
- Toast.makeText(getApplicationContext(), "Spaces are not allowed", Toast.LENGTH_SHORT).show();
- }
- // Log.e("username",""+username);
- else if(username=="")
- {
- Toast.makeText(getApplicationContext(), "Enter Username", Toast.LENGTH_SHORT).show();
- }
- else if(username.length()<5||username.length()>20)
- {
- Toast.makeText(getApplicationContext(), "Username must be 5 to 20 char long", Toast.LENGTH_SHORT).show();
- }
- else if(password=="")
- {
- Toast.makeText(getApplicationContext(), "Enter password", Toast.LENGTH_SHORT).show();
- }
- else if(password.length()<5||password.length()>20)
- {
- Toast.makeText(getApplicationContext(), "Password must be 5 to 20 char log", Toast.LENGTH_SHORT).show();
- }
- else
- signupAction();
- // if(checkEmail(email_string))
- // {
- // signupAction();
- // }
- // else
- // {
- // Toast.makeText(getApplicationContext(), "Email incorrect", Toast.LENGTH_SHORT).show();
- // }
- //
- // Intent myIntent = new Intent(signup.this, homeActivity.class);
- // startActivity(myIntent);
- }
- });
- // File imageDirectory = new File("1111.jpg");
- // if (!imageDirectory.isDirectory()) imageDirectory.mkdir();
- //
- // path = imageDirectory.toString().toLowerCase();
- //
- // File image = new File("1111.jpg");
- // if(image.exists())
- // {
- // image.delete();
- // }
- b2 = (Button)findViewById(R.id.takephotobutton);
- b2.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- final CharSequence[] items = {"From Gallery", "From Camera" };
- AlertDialog.Builder builder = new AlertDialog.Builder(signup.this);
- builder.setTitle("Add Picture");
- builder.setItems(items, new DialogInterface.OnClickListener() {
- // Click listener
- public void onClick(DialogInterface dialog, int item) {
- // Toast.makeText(getApplicationContext(), item +"", Toast.LENGTH_SHORT).show();
- if(item==0)
- {
- //from gallery
- Intent intent = new Intent();
- intent.setType("image/*");
- intent.setAction(Intent.ACTION_GET_CONTENT);
- startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
- }
- if(item==1)
- {
- // from camera
- Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
- startActivityForResult(intent, 0);
- // if(hasStorage(true))
- // {
- //
- // ContentValues values = new ContentValues();
- // values.put(Media.TITLE, "Image");
- // values.put(Images.Media.BUCKET_ID, path.hashCode());
- // values.put(Images.Media.BUCKET_DISPLAY_NAME,name);
- //
- // values.put(Images.Media.MIME_TYPE, "image/jpeg");
- // values.put(Media.DESCRIPTION, "Image capture by camera");
- // values.put("_data", "1111.jpg");
- // Uri uri = getContentResolver().insert( Media.EXTERNAL_CONTENT_URI , values);
- // Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
- //
- // i.putExtra(MediaStore.EXTRA_OUTPUT, uri);
- //
- // startActivityForResult(i, 0);
- // }
- // else
- // {
- //
- // Toast toast = Toast.makeText(signup.this, "No External Storage found",
- // Toast.LENGTH_SHORT);
- // toast.setGravity(Gravity.CLIP_VERTICAL, 0, 0);
- // toast.show();
- // }
- }
- }
- });
- AlertDialog alert = builder.create();
- //display dialog box
- alert.show();
- }
- });
- }
- private void signupAction() {
- // TODO Auto-generated method stub
- progressDialog = ProgressDialog.show(signup.this, null, getResources()
- .getString(R.string.loginProgressMessage), true);
- new Thread(){
- public void run(){
- String path = null;
- Log.e(getResources().getDrawable(R.drawable.default_dp)+"","DRAWABLE PATH");
- //Log.e("path of image",getRealPathFromURI(currImageURI));
- if(username.equals("")||password.equals("")||email_string.equals("")||cpass.getEditableText().toString().equals(""))
- {
- hd.sendEmptyMessage(0);
- progressDialog.dismiss();
- return;
- }
- if(!password.equals(cpass.getEditableText().toString()))
- {
- Log.e("password doesnt match","----------------------------");
- hd.sendEmptyMessage(7);
- progressDialog.dismiss();
- return;
- }
- if(currImageURI==null)
- {
- String g = hp.signup_no_photo(username, password, email_string);
- Log.i("Sign up",g);
- if(g.contains("username already exist"))
- {
- hd.sendEmptyMessage(5);
- }
- if(g.contains("email already exist"))
- {
- hd.sendEmptyMessage(6);
- }
- if(g.contains("SUCCESS"))
- {
- String splits[] = g.split("\\_");
- Log.i("SPLITTED STRING",splits[0]);
- Log.i("SPLITTED STRING",splits[1]);
- sharedPreference sp = new sharedPreference();
- sp.putdata(getApplicationContext(), "USERID", splits[2]);
- sp.putdata(getApplicationContext(), "ISLOGIN", "1");
- sp.putdata(getApplicationContext(), "USERNAME", username);
- signup.this.finish();
- Intent myIntent = new Intent(signup.this, homeActivity.class);
- startActivity(myIntent);
- hd.sendEmptyMessage(1);
- }
- // getResources().getDrawable(R.drawable.default_dp)
- // path =getRealPathFromURI("drawable/default_dp");
- }
- else
- {
- path = getRealPathFromURI(currImageURI);
- Log.i("username and password",username+"------"+password);
- String g = hp.uploadFile(password, username,email_string, path, getApplicationContext());
- Log.i(g,"OUTPUT");
- if(g.contains("username already exist"))
- {
- hd.sendEmptyMessage(5);
- }
- if(g.contains("email already exist"))
- {
- hd.sendEmptyMessage(6);
- }
- if(g.contains("SUCCESS"))
- {
- hd.sendEmptyMessage(1);
- }
- if(g.contains("SUCCESS"))
- {
- String splits[] = g.split("\\_");
- Log.i("SPLITTED STRING",splits[0]);
- Log.i("SPLITTED STRING",splits[1]);
- sharedPreference sp = new sharedPreference();
- sp.putdata(getApplicationContext(), "USERID", splits[2]);
- sp.putdata(getApplicationContext(), "ISLOGIN", "1");
- sp.putdata(getApplicationContext(), "USERNAME", username);
- signup.this.finish();
- Intent myIntent = new Intent(signup.this, homeActivity.class);
- startActivity(myIntent);
- hd.sendEmptyMessage(1);
- }
- }
- }
- }.start();
- }
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- }
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (resultCode == RESULT_OK) {
- if (requestCode == 1) {
- // currImageURI is the global variable I'm using to hold the content:// URI of the image
- currImageURI = data.getData();
- Log.i(currImageURI.toString(),"path");
- iv.setImageURI(currImageURI);
- }
- if(requestCode==0)
- {
- Log.i("IMAGE CAPTURED","IMAGE CAPTURED" );
- Bundle extras = data.getExtras();
- Bitmap b = (Bitmap) extras.get("data");
- currImageURI = data.getData();
- // Log.i(currImageURI.toString(),"path");
- iv.setImageBitmap(b);
- }
- }
- }
- @Override
- public void onAttachedToWindow() {
- // TODO Auto-generated method stub
- super.onAttachedToWindow();
- Window window = getWindow();
- window.setFormat(PixelFormat.RGBA_8888);
- }
- public String getRealPathFromURI(Uri contentUri) {
- // can post image
- String [] proj={MediaStore.Images.Media.DATA};
- Cursor cursor = managedQuery( contentUri,
- proj, // Which columns to return
- null, // WHERE clause; which rows to return (all rows)
- null, // WHERE clause selection arguments (none)
- null); // Order-by clause (ascending by name)
- int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
- cursor.moveToFirst();
- return cursor.getString(column_index);
- }
- public static boolean hasStorage(boolean requireWriteAccess) {
- String state = Environment.getExternalStorageState();
- if (Environment.MEDIA_MOUNTED.equals(state)) {
- return true;
- } else if (!requireWriteAccess
- && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
- return true;
- }
- return false;
- }
- private boolean checkEmail(String email) {
- return EMAIL_ADDRESS_PATTERN.matcher(email).matches();
- }
- public final Pattern EMAIL_ADDRESS_PATTERN = Pattern.compile(
- "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
- "\\@" +
- "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
- "(" +
- "\\." +
- "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
- ")+"
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement