Advertisement
Guest User

Untitled

a guest
Dec 26th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.30 KB | None | 0 0
  1. main.java
  2. ====
  3. package whatsapp.com.example.android.julian.myapplication;
  4.  
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14.  
  15. import com.backendless.Backendless;
  16. import com.backendless.BackendlessUser;
  17. import com.backendless.async.callback.AsyncCallback;
  18. import com.backendless.exceptions.BackendlessFault;
  19.  
  20. public class MainActivity extends AppCompatActivity {
  21.     Button btnLogin, btnRegister;
  22.     EditText txtName, txtPass;
  23.     TextView ttlLogo;
  24.     Context context;
  25.  
  26.     @Override
  27.     protected void onCreate(Bundle savedInstanceState) {
  28.         super.onCreate(savedInstanceState);
  29.         setContentView(R.layout.activity_main);
  30.  
  31.  
  32.         Backendless.initApp(this,
  33.                 getResources().getString(R.string.app_id),
  34.                 getResources().getString(R.string.android_id),
  35.                 getResources().getString(R.string.app_v));
  36.         setPointer();
  37.  
  38.     }
  39.  
  40.  
  41.     public void setPointer() {
  42.  
  43.         this.context = this;
  44.  
  45.         btnLogin = (Button) findViewById(R.id.btnLogin);
  46.         btnRegister = (Button) findViewById(R.id.btnRegister);
  47.         txtName = (EditText) findViewById(R.id.txtUserName);
  48.         txtPass = (EditText) findViewById(R.id.txtUserPassword);
  49.         btnLogin.setOnClickListener(new View.OnClickListener() {
  50.             @Override
  51.             public void onClick(View view) {
  52.                 String uName, uPass;
  53.                 uName = txtName.getText().toString();
  54.                 uPass = txtPass.getText().toString();
  55.                 if (uName.length() < 1 || uPass.length() < 1) {
  56.                     Toast.makeText(context, "you must provide user and password", Toast.LENGTH_SHORT).show();
  57.                     return;
  58.                 }
  59.  
  60.                 Backendless.UserService.login(uName, uPass, new AsyncCallback<BackendlessUser>() {
  61.                     @Override
  62.                     public void handleResponse(BackendlessUser response) {
  63.                         startActivity(new Intent(context, Login.class));
  64.                     }
  65.  
  66.                     @Override
  67.                     public void handleFault(BackendlessFault fault) {
  68.                         Toast.makeText(context, "Error:" + fault.getMessage(), Toast.LENGTH_SHORT).show();
  69.                     }
  70.                 });
  71.             }
  72.         });
  73.  
  74.         btnRegister.setOnClickListener(new View.OnClickListener() {
  75.             @Override
  76.             public void onClick(View view) {
  77.                 startActivity(new Intent(context, Register.class));
  78.             }
  79.         });
  80.     }
  81. }
  82.  
  83. main.xml
  84. =======
  85. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  86.     android:layout_width="match_parent"
  87.     android:layout_height="match_parent"
  88.     android:orientation="vertical"
  89.     android:layoutDirection="rtl"
  90.     android:textDirection="rtl">
  91.  
  92.     <LinearLayout
  93.         android:layout_width="match_parent"
  94.         android:layout_height="150dp"
  95.         android:orientation="vertical">
  96.  
  97.         <TextView
  98.             android:layout_width="match_parent"
  99.             android:layout_height="match_parent"
  100.             android:gravity="center"
  101.             android:text="google"
  102.             android:textSize="100sp">
  103.  
  104.         </TextView>
  105.     </LinearLayout>
  106.  
  107.     <LinearLayout
  108.         android:layout_width="match_parent"
  109.         android:layout_height="100dp"
  110.         android:orientation="vertical">
  111.  
  112.         <EditText
  113.             android:id="@+id/txtUserName"
  114.             android:layout_width="match_parent"
  115.             android:layout_height="wrap_content"
  116.             android:hint="@string/enter_user_name"
  117.             android:inputType="text"
  118.             android:textSize="22sp" />
  119.  
  120.         <EditText
  121.             android:id="@+id/txtUserPassword"
  122.             android:layout_width="match_parent"
  123.             android:layout_height="wrap_content"
  124.             android:hint="@string/enter_password"
  125.  
  126.             android:textSize="22sp" />
  127.     </LinearLayout>
  128.  
  129.     <LinearLayout
  130.         android:layout_width="match_parent"
  131.         android:layout_height="150dp"
  132.         android:orientation="vertical">
  133.  
  134.         <Button
  135.             android:layout_width="match_parent"
  136.             android:layout_height="wrap_content"
  137.             android:text="@string/btn_login"
  138.             android:background="#00BFFF"
  139.             android:textColor="#ffffff"
  140.             android:textSize="32sp"
  141.             android:id="@+id/btnLogin"
  142.             android:layout_marginBottom="20dp"/>
  143.  
  144.         <Button
  145.             android:layout_width="match_parent"
  146.             android:layout_height="wrap_content"
  147.             android:text="@string/Register_button"
  148.             android:background="#00BFFF"
  149.             android:textColor="#ffffff"
  150.             android:textSize="32sp"
  151.             android:id="@+id/btnRegister"/>
  152.     </LinearLayout>
  153.  
  154.     <LinearLayout
  155.         android:layout_width="match_parent"
  156.         android:layout_height="match_parent"
  157.         android:orientation="vertical">
  158.  
  159.     </LinearLayout>
  160. </LinearLayout>
  161. =======
  162. register.xml
  163. =======
  164. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  165.     android:layout_width="match_parent"
  166.     android:layout_height="match_parent"
  167.     android:orientation="vertical">
  168.  
  169.     <RelativeLayout
  170.         android:layout_width="match_parent"
  171.         android:layout_height="match_parent"
  172.         android:layoutDirection="rtl"
  173.         android:textDirection="rtl">
  174.  
  175.         <EditText
  176.             android:id="@+id/txtUserName"
  177.             android:layout_width="match_parent"
  178.             android:layout_height="wrap_content"
  179.             android:hint="@string/enter_user_name"
  180.  
  181.             />
  182.  
  183.         <EditText
  184.             android:id="@+id/txtEmail"
  185.             android:layout_width="match_parent"
  186.             android:layout_height="wrap_content"
  187.             android:layout_below="@id/txtUserName"
  188.             android:hint="@string/enter_email" />
  189.  
  190.         <EditText
  191.             android:id="@+id/txtPhone"
  192.             android:layout_width="match_parent"
  193.             android:layout_height="wrap_content"
  194.             android:layout_below="@id/txtEmail"
  195.             android:hint="@string/enter_your_phone_number" />
  196.  
  197.         <EditText
  198.             android:id="@+id/txtPassword2"
  199.             android:layout_width="match_parent"
  200.             android:layout_height="wrap_content"
  201.             android:layout_below="@id/txtPhone"
  202.             android:hint="@string/enter_password" />
  203.  
  204.         <EditText
  205.             android:id="@+id/txtPassword3"
  206.             android:layout_width="match_parent"
  207.             android:layout_height="wrap_content"
  208.             android:layout_below="@id/txtPassword2"
  209.             android:hint="@string/confirm_password" />
  210.  
  211.         <CheckBox
  212.             android:id="@+id/checkbox"
  213.             android:layout_width="wrap_content"
  214.             android:layout_height="wrap_content"
  215.             android:layout_below="@+id/btnRegisterUser"
  216.             android:layout_marginTop="10sp"
  217.             android:text="אני מסכים" />
  218.  
  219.         <TextView
  220.             android:id="@+id/txtView"
  221.             android:layout_width="wrap_content"
  222.             android:layout_height="wrap_content"
  223.             android:layout_below="@+id/btnCancel"
  224.             android:textColor="@color/colorPrimary"
  225.             android:layout_marginRight="10sp"
  226.             android:text="תנאי השימוש"
  227.             android:textSize="15sp"
  228.  
  229.  
  230.             />
  231.  
  232.         <Button
  233.             android:id="@+id/btnRegisterUser"
  234.             android:layout_width="150dp"
  235.             android:layout_height="wrap_content"
  236.             android:layout_below="@id/txtPassword3"
  237.             android:layout_marginTop="35dp"
  238.             android:text="@string/Register_button" />
  239.  
  240.         <Button
  241.             android:id="@+id/btnCancel"
  242.             android:layout_width="150dp"
  243.             android:layout_height="wrap_content"
  244.             android:layout_below="@id/txtPassword3"
  245.             android:layout_marginTop="35dp"
  246.             android:layout_toEndOf="@id/btnRegisterUser"
  247.             android:text="@string/btn_cancel" />
  248.  
  249.  
  250.     </RelativeLayout>
  251.  
  252.     <TextView
  253.         android:layout_width="match_parent"
  254.         android:layout_height="wrap_content"
  255.         android:layout_marginTop="20dp"
  256.         android:gravity="center"
  257.         android:text="הרשמה"
  258.         android:textSize="32sp" />
  259.  
  260. </LinearLayout>
  261.  
  262. ======
  263. register.java
  264. ========
  265. package whatsapp.com.example.android.julian.myapplication;
  266.  
  267. import android.content.Context;
  268. import android.support.v7.app.AppCompatActivity;
  269. import android.os.Bundle;
  270. import android.view.View;
  271. import android.widget.Button;
  272. import android.widget.EditText;
  273. import android.widget.TextView;
  274. import android.widget.Toast;
  275.  
  276. import com.backendless.Backendless;
  277. import com.backendless.BackendlessUser;
  278. import com.backendless.async.callback.AsyncCallback;
  279. import com.backendless.exceptions.BackendlessFault;
  280.  
  281. public class Register extends AppCompatActivity {
  282.     Button btnRegister, btnCancel;
  283.     EditText txtUname, txtUpass, txtUpass2, uEmail, uPhone;
  284.     TextView txtView;
  285.     Context context;
  286.  
  287.     @Override
  288.     protected void onCreate(Bundle savedInstanceState) {
  289.         super.onCreate(savedInstanceState);
  290.         setContentView(R.layout.activity_register);
  291.         setPointer();
  292.     }
  293.  
  294.     private void setPointer() {
  295.  
  296.         this.context = this;
  297.         uPhone = (EditText) findViewById(R.id.txtPhone);
  298.         btnCancel = (Button) findViewById(R.id.btnCancel);
  299.         btnRegister = (Button) findViewById(R.id.btnRegisterUser);
  300.         txtUname = (EditText) findViewById(R.id.txtUserName);
  301.         txtUpass = (EditText) findViewById(R.id.txtPassword2);
  302.         txtUpass2 = (EditText) findViewById(R.id.txtPassword3);
  303.         uEmail = (EditText) findViewById(R.id.txtEmail);
  304.         txtView = (TextView) findViewById(R.id.txtView);
  305.  
  306.         btnCancel.setOnClickListener(new View.OnClickListener() {
  307.             @Override
  308.             public void onClick(View view) {
  309.                 finish();
  310.             }
  311.         });
  312.         btnRegister.setOnClickListener(new View.OnClickListener() {
  313.             @Override
  314.             public void onClick(View view) {
  315.                 if (checkData()) {
  316.                     BackendlessUser newUser = new BackendlessUser();
  317.                     newUser.setEmail(uEmail.getText().toString());
  318.                     newUser.setPassword(txtUpass.getText().toString());
  319.                     newUser.setProperty("phone_number",uPhone.getText().toString());
  320.                 newUser.setProperty("user_name",txtUname.getText().toString());
  321.                     Backendless.UserService.register(newUser, new AsyncCallback<BackendlessUser>() {
  322.                         @Override
  323.                         public void handleResponse(BackendlessUser response) {
  324.                             Toast.makeText(context, "User Registred...", Toast.LENGTH_SHORT).show();
  325.                             finish();
  326.                         }
  327.  
  328.                         @Override
  329.                         public void handleFault(BackendlessFault fault) {
  330.                             Toast.makeText(context, "Error" + fault.getMessage(), Toast.LENGTH_SHORT).show();
  331.                         }
  332.                     });
  333.                 }
  334.             }
  335.         });
  336.     }
  337.  
  338.     private boolean checkData() {
  339.         //if user update fields
  340.         if (txtUname.getText().toString().length() < 1 ||
  341.                 txtUpass2.getText().toString().length() < 1 ||
  342.                 txtUpass.getText().toString().length() < 1)
  343.  
  344.         {
  345.             return false;
  346.         }
  347.  
  348.         //if password are equals
  349.         if (!txtUpass.getText().toString().equals(txtUpass2.getText().toString())) {
  350.             Toast.makeText(context, "Password not match..", Toast.LENGTH_SHORT).show();
  351.             return false;
  352.         }
  353.  
  354.         return true;
  355.     }
  356.  
  357. }
  358. =====
  359. login.java
  360. ======
  361. package whatsapp.com.example.android.julian.myapplication;
  362.  
  363. import android.support.v7.app.AppCompatActivity;
  364. import android.os.Bundle;
  365.  
  366. public class Login extends AppCompatActivity {
  367.  
  368.     @Override
  369.     protected void onCreate(Bundle savedInstanceState) {
  370.         super.onCreate(savedInstanceState);
  371.         setContentView(R.layout.wellcome);
  372.     }
  373. }
  374.  
  375.  
  376.  
  377. ======
  378. string
  379. ======
  380. <resources>
  381.     <string name="app_name">My Application</string>
  382.     <string name="enter_user_name">הכנס/י שם משתמש....</string>
  383.     <string name="enter_email">הכנס/י דואר אלקטרוני...</string>
  384.     <string name="enter_your_phone_number">הכנס/י מספר נייד....</string>
  385.     <string name="enter_password">הכנס/י סיסמא...</string>
  386.     <string name="confirm_password">אשר/י סיסמא..</string>
  387.     <string name="title_activity_register">Register</string>
  388.     <string name="Register_button">הרשמה</string>
  389. <string name="btn_cancel">ביטול</string>
  390.     <string name="btn_login">כניסה</string>
  391.     <string name="app_id">66A2E76C-4E40-6695-FFCF-CD56DC334D00
  392. </string>
  393.     <string name="app_v">v1</string>
  394.     <string name="android_id">F554F240-A498-DC21-FFEC-792D1D8D1C00
  395. </string>
  396. </resources>
  397.  
  398. ======
  399. build.grable
  400. ======
  401. apply plugin: 'com.android.application'
  402.  
  403. android {
  404.     compileSdkVersion 25
  405.     buildToolsVersion "25.0.1"
  406.     defaultConfig {
  407.         applicationId "whatsapp.com.example.android.julian.myapplication"
  408.         minSdkVersion 19
  409.         targetSdkVersion 25
  410.         versionCode 1
  411.         versionName "1.0"
  412.         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  413.     }
  414.     buildTypes {
  415.         release {
  416.             minifyEnabled false
  417.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  418.         }
  419.     }
  420. }
  421.  
  422. dependencies {
  423.     compile fileTree(dir: 'libs', include: ['*.jar'])
  424.     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  425.         exclude group: 'com.android.support', module: 'support-annotations'
  426.     })
  427.     compile 'com.android.support:appcompat-v7:25.0.0'
  428.     compile 'com.android.support:design:25.0.0'
  429.     testCompile 'junit:junit:4.12'
  430.     compile 'com.backendless:backendless:3.0.20.1'
  431. }
  432. ======
  433. manifest
  434. ======
  435. <?xml version="1.0" encoding="utf-8"?>
  436. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  437.     package="whatsapp.com.example.android.julian.myapplication">
  438. <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  439.   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
  440.     <application
  441.         android:allowBackup="true"
  442.         android:icon="@mipmap/ic_launcher"
  443.         android:label="@string/app_name"
  444.         android:supportsRtl="true"
  445.         android:theme="@style/AppTheme">
  446.         <activity android:name=".MainActivity">
  447.             <intent-filter>
  448.                 <action android:name="android.intent.action.MAIN" />
  449.  
  450.                 <category android:name="android.intent.category.LAUNCHER" />
  451.             </intent-filter>
  452.         </activity>
  453.         <activity android:name=".Register" />
  454.         <activity android:name=".Login" />
  455.  
  456.     </application>
  457.  
  458. </manifest>
  459. =======
  460. byAdam
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement