Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.40 KB | None | 0 0
  1. MainActivity.java
  2. ==================
  3.  
  4. package whatsapp.com.example.android.julian.myapplication;
  5. import android.content.Intent;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.TextView;
  12. import android.widget.Toast;
  13.  
  14. import com.backendless.Backendless;
  15. import com.backendless.BackendlessUser;
  16. import com.backendless.async.callback.AsyncCallback;
  17. import com.backendless.exceptions.BackendlessFault;
  18.  
  19. public class MainActivity extends AppCompatActivity {
  20. Button btnLogin,btnRegister;
  21. EditText txtName,txtPass;
  22. TextView ttlLogo;
  23. MainActivity context;
  24.  
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_main);
  29.  
  30. //make a connection to BackEndLess
  31. Backendless.initApp(this,
  32. getResources().getString(R.string.app_id),
  33. getResources().getString(R.string.android_id),
  34. getResources().getString(R.string.app_v));
  35. setPointer();
  36. // loginUser();
  37. }
  38.  
  39.  
  40. private void setPointer()
  41. {
  42. //context
  43. this.context=this;
  44. //pointers
  45. btnLogin=(Button)findViewById(btnLogin);
  46. btnRegister=(Button)findViewById(btnRegister);
  47. txtName=(EditText)findViewById(R.id.txtName);
  48. txtPass=(EditText)findViewById(R.id.txtPass);
  49. ttlLogo=(TextView)findViewById(R.id.ttlLogo);
  50. ttlLogo.setText("Camel Studio");
  51.  
  52. //listeners
  53. btnLogin.setOnClickListener(new View.OnClickListener() {
  54. @Override
  55. public void onClick(View view) {
  56. //check user name and password
  57. String uName=txtName.getText().toString();
  58. String uPass=txtPass.getText().toString();
  59. if (uName.length()<1 || uPass.length()<1)
  60. {
  61. Toast.makeText(context, "you must provide user and password", Toast.LENGTH_SHORT).show();
  62. return;
  63. }
  64. //check login
  65. Backendless.UserService.login(uName, uPass, new AsyncCallback<BackendlessUser>() {
  66. @Override
  67. public void handleResponse(BackendlessUser response) {
  68. startActivity(new Intent(context,Login.class));
  69. }
  70.  
  71. @Override
  72. public void handleFault(BackendlessFault fault) {
  73. Toast.makeText(context, "Error:"+fault.getMessage(), Toast.LENGTH_SHORT).show();
  74. }
  75. });
  76. }
  77. });
  78. btnRegister.setOnClickListener(new View.OnClickListener() {
  79. @Override
  80. public void onClick(View view) {
  81. startActivity(new Intent(context,Register.class));
  82. }
  83. });
  84. }
  85. }
  86.  
  87.  
  88.  
  89. Login.java
  90. ============
  91. package whatsapp.com.example.android.julian.myapplication;
  92.  
  93. /**
  94. * Created by android on 22/12/2016.
  95. */
  96. public class Login {
  97. }
  98.  
  99.  
  100. AndroidManifest.xml
  101. =======================
  102. <?xml version="1.0" encoding="utf-8"?>
  103. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  104. package="whatsapp.com.example.android.julian.myapplication">
  105. <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  106. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
  107. <application
  108. android:allowBackup="true"
  109. android:icon="@mipmap/ic_launcher"
  110. android:label="@string/app_name"
  111. android:supportsRtl="true"
  112. android:theme="@style/AppTheme">
  113. <activity android:name=".MainActivity">
  114. <intent-filter>
  115. <action android:name="android.intent.action.MAIN" />
  116.  
  117. <category android:name="android.intent.category.LAUNCHER" />
  118. </intent-filter>
  119. </activity>
  120. <activity android:name=".Register"></activity>
  121. </application>
  122.  
  123. </manifest>
  124.  
  125.  
  126.  
  127. app
  128. ======
  129. apply plugin: 'com.android.application'
  130.  
  131. android {
  132. compileSdkVersion 25
  133. buildToolsVersion "25.0.1"
  134. defaultConfig {
  135. applicationId "whatsapp.com.example.android.julian.myapplication"
  136. minSdkVersion 19
  137. targetSdkVersion 25
  138. versionCode 1
  139. versionName "1.0"
  140. testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  141. }
  142. buildTypes {
  143. release {
  144. minifyEnabled false
  145. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  146. }
  147. }
  148. }
  149.  
  150. dependencies {
  151. compile fileTree(dir: 'libs', include: ['*.jar'])
  152. androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  153. exclude group: 'com.android.support', module: 'support-annotations'
  154. })
  155. compile 'com.android.support:appcompat-v7:25.0.0'
  156. compile 'com.android.support:design:25.0.0'
  157. testCompile 'junit:junit:4.12'
  158. compile 'com.backendless:backendless:3.0.20.1'
  159. }
  160.  
  161.  
  162. activity_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.  
  264. Register.java
  265. ===============
  266. package whatsapp.com.example.android.julian.myapplication;
  267.  
  268. import android.content.Context;
  269. import android.support.v7.app.AppCompatActivity;
  270. import android.os.Bundle;
  271. import android.view.View;
  272. import android.widget.Button;
  273. import android.widget.EditText;
  274. import android.widget.TextView;
  275. import android.widget.Toast;
  276.  
  277. import com.backendless.Backendless;
  278. import com.backendless.BackendlessUser;
  279. import com.backendless.async.callback.AsyncCallback;
  280. import com.backendless.exceptions.BackendlessFault;
  281.  
  282. public class Register extends AppCompatActivity {
  283. Button btnRegister,btnCancel;
  284. EditText txtUname,txtUpass,txtUpass2;
  285. TextView txtView;
  286. Context context;
  287.  
  288. @Override
  289. protected void onCreate(Bundle savedInstanceState) {
  290. super.onCreate(savedInstanceState);
  291. setContentView(R.layout.activity_register);
  292. setPointer();
  293. }
  294.  
  295. private void setPointer()
  296. {
  297. //context
  298. this.context=this;
  299. //pointers
  300. btnCancel=(Button)findViewById(R.id.btnCancel);
  301. btnRegister=(Button)findViewById(R.id.btnRegisterUser);
  302. txtUname=(EditText)findViewById(R.id.txtUserName);
  303. txtUpass=(EditText)findViewById(R.id.txtPassword2);
  304. txtUpass2=(EditText)findViewById(R.id.txtPassword3);
  305. txtView=(TextView)findViewById(R.id.txtView);
  306. txtView.setText("Camel Studio");
  307. //listeners
  308. btnCancel.setOnClickListener(new View.OnClickListener() {
  309. @Override
  310. public void onClick(View view) {
  311. finish();
  312. }
  313. });
  314. btnRegister.setOnClickListener(new View.OnClickListener() {
  315. @Override
  316. public void onClick(View view) {
  317. if (checkData())
  318. {
  319. BackendlessUser newUser = new BackendlessUser();
  320. newUser.setEmail(txtUname.getText().toString());
  321. newUser.setPassword(txtUpass.getText().toString());
  322. Backendless.UserService.register(newUser, new AsyncCallback<BackendlessUser>() {
  323. @Override
  324. public void handleResponse(BackendlessUser response) {
  325. Toast.makeText(context, "User Registred...", Toast.LENGTH_SHORT).show();
  326. finish();
  327. }
  328.  
  329. @Override
  330. public void handleFault(BackendlessFault fault) {
  331. Toast.makeText(context, "Error"+fault.getMessage(), Toast.LENGTH_SHORT).show();
  332. }
  333. });
  334. }
  335. }
  336. });
  337. }
  338.  
  339. private boolean checkData()
  340. {
  341. //if user update fields
  342. if (txtUname.getText().toString().length()<1 ||
  343. txtUpass2.getText().toString().length()<1 ||
  344. txtUpass.getText().toString().length()<1)
  345. {
  346. return false;
  347. }
  348.  
  349. //if password are equals
  350. if(!txtUpass.getText().toString().equals(txtUpass2.getText().toString()))
  351. {
  352. Toast.makeText(context, "Password not match..", Toast.LENGTH_SHORT).show();
  353. return false;
  354. }
  355.  
  356. return true;
  357. }
  358.  
  359. }
  360.  
  361.  
  362. welcome.xml
  363. ===============
  364. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  365. android:layout_width="match_parent"
  366. android:layout_height="match_parent"
  367. android:orientation="vertical">
  368.  
  369. <LinearLayout
  370. android:layout_width="match_parent"
  371. android:layout_height="match_parent"
  372. android:layout_weight="1">
  373.  
  374. <ImageView
  375. android:layout_width="match_parent"
  376. android:layout_height="match_parent"
  377. android:layout_weight="1"
  378. android:background="@drawable/rings"
  379. android:id="@+id/imageView3" />
  380.  
  381. <ImageView
  382. android:layout_width="match_parent"
  383. android:layout_height="match_parent"
  384. android:layout_weight="1"
  385. android:background="@drawable/bar_micva"
  386. android:id="@+id/imageView4" />
  387. </LinearLayout>
  388.  
  389. <LinearLayout
  390. android:layout_width="match_parent"
  391. android:layout_height="match_parent"
  392. android:layout_weight="1">
  393.  
  394. <ImageView
  395. android:layout_width="match_parent"
  396. android:layout_height="match_parent"
  397. android:layout_weight="1"
  398. android:background="@drawable/birthday" />
  399.  
  400. <ImageView
  401. android:layout_width="match_parent"
  402. android:layout_height="match_parent"
  403. android:layout_weight="1"
  404. android:background="@drawable/brit"
  405. android:id="@+id/imageView" />
  406. </LinearLayout>
  407.  
  408. <LinearLayout
  409. android:layout_width="match_parent"
  410. android:layout_height="match_parent"
  411. android:layout_weight="1">
  412.  
  413. <ImageView
  414. android:layout_width="match_parent"
  415. android:layout_height="match_parent"
  416. android:layout_weight="1"
  417. android:background="@drawable/work_party"
  418. android:id="@+id/imageView2" />
  419.  
  420. <ImageView
  421. android:layout_width="match_parent"
  422. android:layout_height="match_parent"
  423. android:layout_weight="1"
  424. android:background="@drawable/ravakot" />
  425. </LinearLayout>
  426.  
  427. </LinearLayout>
  428.  
  429.  
  430. activity_main.xml
  431. ===================
  432. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  433. android:layout_width="match_parent"
  434. android:layout_height="match_parent"
  435. android:orientation="vertical"
  436. android:layoutDirection="rtl"
  437. android:textDirection="rtl">
  438.  
  439. <LinearLayout
  440. android:layout_width="match_parent"
  441. android:layout_height="150dp"
  442. android:orientation="vertical">
  443.  
  444. <TextView
  445. android:layout_width="match_parent"
  446. android:layout_height="match_parent"
  447. android:gravity="center"
  448. android:text="LOGO"
  449. android:textSize="100sp">
  450.  
  451. </TextView>
  452. </LinearLayout>
  453.  
  454. <LinearLayout
  455. android:layout_width="match_parent"
  456. android:layout_height="100dp"
  457. android:orientation="vertical">
  458.  
  459. <EditText
  460. android:id="@+id/txtUserName"
  461. android:layout_width="match_parent"
  462. android:layout_height="wrap_content"
  463. android:hint="@string/enter_user_name"
  464. android:inputType="text"
  465. android:textSize="22sp" />
  466.  
  467. <EditText
  468. android:id="@+id/txtUserPassword"
  469. android:layout_width="match_parent"
  470. android:layout_height="wrap_content"
  471. android:hint="@string/enter_password"
  472.  
  473. android:textSize="22sp" />
  474. </LinearLayout>
  475.  
  476. <LinearLayout
  477. android:layout_width="match_parent"
  478. android:layout_height="150dp"
  479. android:orientation="vertical">
  480.  
  481. <Button
  482. android:layout_width="match_parent"
  483. android:layout_height="wrap_content"
  484. android:text="@string/btn_login"
  485. android:background="#00BFFF"
  486. android:textColor="#ffffff"
  487. android:textSize="32sp"
  488. android:id="@+id/btnLogin"
  489. android:layout_marginBottom="20dp"/>
  490.  
  491. <Button
  492. android:layout_width="match_parent"
  493. android:layout_height="wrap_content"
  494. android:text="@string/Register_button"
  495. android:background="#00BFFF"
  496. android:textColor="#ffffff"
  497. android:textSize="32sp"
  498. android:id="@+id/btnRegister"/>
  499. </LinearLayout>
  500.  
  501. <LinearLayout
  502. android:layout_width="match_parent"
  503. android:layout_height="match_parent"
  504. android:orientation="vertical">
  505.  
  506. </LinearLayout>
  507. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement