Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MainActivity.java
- ==================
- package whatsapp.com.example.android.julian.myapplication;
- 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;
- MainActivity context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- //make a connection to BackEndLess
- Backendless.initApp(this,
- getResources().getString(R.string.app_id),
- getResources().getString(R.string.android_id),
- getResources().getString(R.string.app_v));
- setPointer();
- // loginUser();
- }
- private void setPointer()
- {
- //context
- this.context=this;
- //pointers
- btnLogin=(Button)findViewById(btnLogin);
- btnRegister=(Button)findViewById(btnRegister);
- txtName=(EditText)findViewById(R.id.txtName);
- txtPass=(EditText)findViewById(R.id.txtPass);
- ttlLogo=(TextView)findViewById(R.id.ttlLogo);
- ttlLogo.setText("Camel Studio");
- //listeners
- btnLogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- //check user name and password
- String uName=txtName.getText().toString();
- String 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;
- }
- //check login
- 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));
- }
- });
- }
- }
- Login.java
- ============
- package whatsapp.com.example.android.julian.myapplication;
- /**
- * Created by android on 22/12/2016.
- */
- public class Login {
- }
- AndroidManifest.xml
- =======================
- <?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>
- </application>
- </manifest>
- app
- ======
- 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'
- }
- activity_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;
- TextView txtView;
- Context context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- setPointer();
- }
- private void setPointer()
- {
- //context
- this.context=this;
- //pointers
- 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);
- txtView=(TextView)findViewById(R.id.txtView);
- txtView.setText("Camel Studio");
- //listeners
- 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(txtUname.getText().toString());
- newUser.setPassword(txtUpass.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;
- }
- }
- welcome.xml
- ===============
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:background="@drawable/rings"
- android:id="@+id/imageView3" />
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:background="@drawable/bar_micva"
- android:id="@+id/imageView4" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:background="@drawable/birthday" />
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:background="@drawable/brit"
- android:id="@+id/imageView" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:background="@drawable/work_party"
- android:id="@+id/imageView2" />
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:background="@drawable/ravakot" />
- </LinearLayout>
- </LinearLayout>
- activity_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="LOGO"
- 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>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement