Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Home extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.activity_home);
- }
- public void userRegister(View view){
- startActivity(new Intent(this,Register.class));
- }
- public void userLogin(View view){
- }
- public class FontTextView extends TextView {
- public FontTextView(Context context) {
- super(context);
- Typeface face=Typeface.createFromAsset(context.getAssets(), "Rockwell.ttf");
- this.setTypeface(face);
- }
- public FontTextView(Context context, AttributeSet attrs) {
- super(context, attrs);
- Typeface face=Typeface.createFromAsset(context.getAssets(), "Rockwell.ttf");
- this.setTypeface(face);
- }
- public FontTextView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- Typeface face=Typeface.createFromAsset(context.getAssets(), "Rockwell.ttf");
- this.setTypeface(face);
- }
- protected void onDraw (Canvas canvas) {
- super.onDraw(canvas);
- }
- }
- public class Register extends Activity {
- private EditText etFirstname, etLastname, etNickname, etUsername, etPassword, etConfirmPassword, etPhone, etEmail;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- etFirstname = (EditText) findViewById(R.id.etFirstname);
- etLastname = (EditText) findViewById(R.id.etLastname);
- etNickname = (EditText) findViewById(R.id.etNickname);
- etUsername = (EditText) findViewById(R.id.etUsername);
- etPassword = (EditText) findViewById(R.id.etPassword);
- etConfirmPassword = (EditText) findViewById(R.id.etConfirmPassword);
- etPhone = (EditText) findViewById(R.id.etPhone);
- etEmail = (EditText) findViewById(R.id.etEmail);
- }
- public void bRegister(View v) {
- String firstname = etFirstname.getText().toString();
- String lastname = etLastname.getText().toString();
- String nickname = etNickname.getText().toString();
- String username = etUsername.getText().toString();
- String password = etPassword.getText().toString();
- String confirmpassword = etConfirmPassword.getText().toString();
- String phone = etPhone.getText().toString();
- String email = etEmail.getText().toString();
- Toast.makeText(this, "Signing up...", Toast.LENGTH_SHORT).show();
- new RegisterActivity(this).execute(firstname, lastname, nickname, username, password, confirmpassword, phone, email);
- private EditText etFirstname, etLastname, etNickname, etUsername, etPassword, etConfirmPassword, etPhone, etEmail;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- etFirstname = (EditText) findViewById(R.id.etFirstname);
- etLastname = (EditText) findViewById(R.id.etLastname);
- etNickname = (EditText) findViewById(R.id.etNickname);
- etUsername = (EditText) findViewById(R.id.etUsername);
- etPassword = (EditText) findViewById(R.id.etPassword);
- etConfirmPassword = (EditText) findViewById(R.id.etConfirmPassword);
- etPhone = (EditText) findViewById(R.id.etPhone);
- etEmail = (EditText) findViewById(R.id.etEmail);
- }
- public void bRegister(View v) {
- String firstname = etFirstname.getText().toString();
- String lastname = etLastname.getText().toString();
- String nickname = etNickname.getText().toString();
- String username = etUsername.getText().toString();
- String password = etPassword.getText().toString();
- String confirmpassword = etConfirmPassword.getText().toString();
- String phone = etPhone.getText().toString();
- String email = etEmail.getText().toString();
- Toast.makeText(this, "Signing up...", Toast.LENGTH_SHORT).show();
- new RegisterActivity(this).execute(firstname, lastname, nickname, username, password, confirmpassword, phone, email);
- }
- public class RegisterActivity extends AsyncTask<String, Void, String> {
- private Context context;
- public RegisterActivity(Context context) {
- this.context = context;
- }
- protected void onPreExecute() {
- }
- @Override
- protected String doInBackground(String... arg0) {
- String firstname = arg0[0];
- String lastname = arg0[1];
- String nickname = arg0[2];
- String username = arg0[3];
- String password = arg0[4];
- String confirmpassword = arg0[5];
- String phone = arg0[6];
- String email = arg0[7];
- String link;
- String data;
- BufferedReader bufferedReader;
- String result;
- try {
- data = "&firstname=" + URLEncoder.encode(firstname, "UTF-8");
- data += "&lastname=" + URLEncoder.encode(lastname, "UTF-8");
- data += "&nickname=" + URLEncoder.encode(nickname, "UTF-8");
- data += "&username=" + URLEncoder.encode(username, "UTF-8");
- data += "&password=" + URLEncoder.encode(password, "UTF-8");
- data += "&confirmpassword=" + URLEncoder.encode(confirmpassword, "UTF-8");
- data += "&username=" + URLEncoder.encode(username, "UTF-8");
- data += "&phone=" + URLEncoder.encode(phone, "UTF-8");
- data += "&email=" + URLEncoder.encode(email, "UTF-8");
- link = "https://49.151.4.22/RemindMePHP/Register.php" + data;
- URL url = new URL(link);
- HttpURLConnection con = (HttpURLConnection) url.openConnection();
- bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
- result = bufferedReader.readLine();
- return result;
- } catch (Exception e) {
- return new String("Exception: " + e.getMessage());
- }
- }
- @Override
- protected void onPostExecute(String result) {
- String jsonStr = result;
- if (jsonStr != null) {
- try {
- JSONObject jsonObj = new JSONObject(jsonStr);
- String query_result = jsonObj.getString("query_result");
- if (query_result.equals("SUCCESS")) {
- Toast.makeText(context, "Data inserted successfully. Signup successful.", Toast.LENGTH_SHORT).show();
- } else if (query_result.equals("FAILURE")) {
- Toast.makeText(context, "Data could not be inserted. Signup failed.", Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(context, "Couldn't connect to remote database.", Toast.LENGTH_SHORT).show();
- }
- } catch (JSONException e) {
- e.printStackTrace();
- Toast.makeText(context, "Error parsing JSON data.", Toast.LENGTH_SHORT).show();
- }
- } else {
- Toast.makeText(context, "Couldn't get any JSON data.", Toast.LENGTH_SHORT).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement