Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.java
- ====
- package whatsapp.com.example.android.julian.myapplication;
- import android.content.Context;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.backendless.Backendless;
- import com.backendless.BackendlessUser;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- public class MainActivity extends AppCompatActivity {
- Button btnLogin, btnRegister;
- EditText txtName, txtPass;
- TextView ttlLogo;
- Context context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Backendless.initApp(this,
- getResources().getString(R.string.app_id),
- getResources().getString(R.string.android_id),
- getResources().getString(R.string.app_v));
- setPointer();
- }
- public void setPointer() {
- this.context = this;
- btnLogin = (Button) findViewById(R.id.btnLogin);
- btnRegister = (Button) findViewById(R.id.btnRegister);
- txtName = (EditText) findViewById(R.id.txtUserName);
- txtPass = (EditText) findViewById(R.id.txtUserPassword);
- btnLogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- String uName, uPass;
- uName = txtName.getText().toString();
- uPass = txtPass.getText().toString();
- if (uName.length() < 1 || uPass.length() < 1) {
- Toast.makeText(context, "you must provide user and password", Toast.LENGTH_SHORT).show();
- return;
- }
- Backendless.UserService.login(uName, uPass, new AsyncCallback<BackendlessUser>() {
- @Override
- public void handleResponse(BackendlessUser response) {
- startActivity(new Intent(context, Login.class));
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- Toast.makeText(context, "Error:" + fault.getMessage(), Toast.LENGTH_SHORT).show();
- }
- });
- }
- });
- btnRegister.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(context, Register.class));
- }
- });
- }
- }
- main.xml
- =======
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:layoutDirection="rtl"
- android:textDirection="rtl">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:text="google"
- android:textSize="100sp">
- </TextView>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="100dp"
- android:orientation="vertical">
- <EditText
- android:id="@+id/txtUserName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/enter_user_name"
- android:inputType="text"
- android:textSize="22sp" />
- <EditText
- android:id="@+id/txtUserPassword"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/enter_password"
- android:textSize="22sp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:orientation="vertical">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/btn_login"
- android:background="#00BFFF"
- android:textColor="#ffffff"
- android:textSize="32sp"
- android:id="@+id/btnLogin"
- android:layout_marginBottom="20dp"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/Register_button"
- android:background="#00BFFF"
- android:textColor="#ffffff"
- android:textSize="32sp"
- android:id="@+id/btnRegister"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- </LinearLayout>
- </LinearLayout>
- =======
- register.xml
- =======
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layoutDirection="rtl"
- android:textDirection="rtl">
- <EditText
- android:id="@+id/txtUserName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/enter_user_name"
- />
- <EditText
- android:id="@+id/txtEmail"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtUserName"
- android:hint="@string/enter_email" />
- <EditText
- android:id="@+id/txtPhone"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtEmail"
- android:hint="@string/enter_your_phone_number" />
- <EditText
- android:id="@+id/txtPassword2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtPhone"
- android:hint="@string/enter_password" />
- <EditText
- android:id="@+id/txtPassword3"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtPassword2"
- android:hint="@string/confirm_password" />
- <CheckBox
- android:id="@+id/checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/btnRegisterUser"
- android:layout_marginTop="10sp"
- android:text="אני מסכים" />
- <TextView
- android:id="@+id/txtView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/btnCancel"
- android:textColor="@color/colorPrimary"
- android:layout_marginRight="10sp"
- android:text="תנאי השימוש"
- android:textSize="15sp"
- />
- <Button
- android:id="@+id/btnRegisterUser"
- android:layout_width="150dp"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtPassword3"
- android:layout_marginTop="35dp"
- android:text="@string/Register_button" />
- <Button
- android:id="@+id/btnCancel"
- android:layout_width="150dp"
- android:layout_height="wrap_content"
- android:layout_below="@id/txtPassword3"
- android:layout_marginTop="35dp"
- android:layout_toEndOf="@id/btnRegisterUser"
- android:text="@string/btn_cancel" />
- </RelativeLayout>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="20dp"
- android:gravity="center"
- android:text="הרשמה"
- android:textSize="32sp" />
- </LinearLayout>
- ======
- register.java
- ========
- package whatsapp.com.example.android.julian.myapplication;
- import android.content.Context;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.backendless.Backendless;
- import com.backendless.BackendlessUser;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- public class Register extends AppCompatActivity {
- Button btnRegister, btnCancel;
- EditText txtUname, txtUpass, txtUpass2, uEmail, uPhone;
- TextView txtView;
- Context context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- setPointer();
- }
- private void setPointer() {
- this.context = this;
- uPhone = (EditText) findViewById(R.id.txtPhone);
- btnCancel = (Button) findViewById(R.id.btnCancel);
- btnRegister = (Button) findViewById(R.id.btnRegisterUser);
- txtUname = (EditText) findViewById(R.id.txtUserName);
- txtUpass = (EditText) findViewById(R.id.txtPassword2);
- txtUpass2 = (EditText) findViewById(R.id.txtPassword3);
- uEmail = (EditText) findViewById(R.id.txtEmail);
- txtView = (TextView) findViewById(R.id.txtView);
- btnCancel.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- finish();
- }
- });
- btnRegister.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (checkData()) {
- BackendlessUser newUser = new BackendlessUser();
- newUser.setEmail(uEmail.getText().toString());
- newUser.setPassword(txtUpass.getText().toString());
- newUser.setProperty("phone_number",uPhone.getText().toString());
- newUser.setProperty("user_name",txtUname.getText().toString());
- Backendless.UserService.register(newUser, new AsyncCallback<BackendlessUser>() {
- @Override
- public void handleResponse(BackendlessUser response) {
- Toast.makeText(context, "User Registred...", Toast.LENGTH_SHORT).show();
- finish();
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- Toast.makeText(context, "Error" + fault.getMessage(), Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
- });
- }
- private boolean checkData() {
- //if user update fields
- if (txtUname.getText().toString().length() < 1 ||
- txtUpass2.getText().toString().length() < 1 ||
- txtUpass.getText().toString().length() < 1)
- {
- return false;
- }
- //if password are equals
- if (!txtUpass.getText().toString().equals(txtUpass2.getText().toString())) {
- Toast.makeText(context, "Password not match..", Toast.LENGTH_SHORT).show();
- return false;
- }
- return true;
- }
- }
- =====
- login.java
- ======
- package whatsapp.com.example.android.julian.myapplication;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- public class Login extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.wellcome);
- }
- }
- ======
- string
- ======
- <resources>
- <string name="app_name">My Application</string>
- <string name="enter_user_name">הכנס/י שם משתמש....</string>
- <string name="enter_email">הכנס/י דואר אלקטרוני...</string>
- <string name="enter_your_phone_number">הכנס/י מספר נייד....</string>
- <string name="enter_password">הכנס/י סיסמא...</string>
- <string name="confirm_password">אשר/י סיסמא..</string>
- <string name="title_activity_register">Register</string>
- <string name="Register_button">הרשמה</string>
- <string name="btn_cancel">ביטול</string>
- <string name="btn_login">כניסה</string>
- <string name="app_id">66A2E76C-4E40-6695-FFCF-CD56DC334D00
- </string>
- <string name="app_v">v1</string>
- <string name="android_id">F554F240-A498-DC21-FFEC-792D1D8D1C00
- </string>
- </resources>
- ======
- build.grable
- ======
- apply plugin: 'com.android.application'
- android {
- compileSdkVersion 25
- buildToolsVersion "25.0.1"
- defaultConfig {
- applicationId "whatsapp.com.example.android.julian.myapplication"
- minSdkVersion 19
- targetSdkVersion 25
- versionCode 1
- versionName "1.0"
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- }
- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
- exclude group: 'com.android.support', module: 'support-annotations'
- })
- compile 'com.android.support:appcompat-v7:25.0.0'
- compile 'com.android.support:design:25.0.0'
- testCompile 'junit:junit:4.12'
- compile 'com.backendless:backendless:3.0.20.1'
- }
- ======
- manifest
- ======
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="whatsapp.com.example.android.julian.myapplication">
- <uses-permission android:name="android.permission.INTERNET"></uses-permission>
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name=".Register" />
- <activity android:name=".Login" />
- </application>
- </manifest>
- =======
- byAdam
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement