Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MainActiviy.java
- ======================
- package com.example.teacher.mysmarthome;
- 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.Toast;
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- EditText txtUser,txtPass;
- Button btnRegister;
- Context context;
- private final String TEST_USER="zeev";
- private final String TEST_PASS="12345";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer();
- }
- private void setPointer() {
- context=this;
- txtUser=findViewById(R.id.txtUser);
- txtPass=findViewById(R.id.txtPass);
- btnRegister=findViewById(R.id.btnRegister);
- btnRegister.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Toast.makeText(context, "Dude, please register", Toast.LENGTH_LONG).show();
- }
- });
- }
- public void btnLogin(View view)
- {
- //Toast.makeText(this, "Hello my brother from another mother", Toast.LENGTH_LONG).show();
- String myUser=txtUser.getText().toString();
- String myPass=txtPass.getText().toString();
- // TEST_USER==myUser - will not work, we need equals....
- }
- @Override
- public void onClick(View view) {
- switch (view.getId())
- {
- case R.id.btnAr:
- Toast.makeText(context, "Arabic", Toast.LENGTH_SHORT).show();
- break;
- case R.id.btnEn:
- Toast.makeText(context, "English", Toast.LENGTH_SHORT).show();
- break;
- case R.id.btnHe:
- Toast.makeText(context, "Hebrew", Toast.LENGTH_SHORT).show();
- break;
- case R.id.btnRu:
- Toast.makeText(context, "Russion", Toast.LENGTH_SHORT).show();
- break;
- default:
- Toast.makeText(context, "WTF?!?!?!?", Toast.LENGTH_SHORT).show();
- break;
- }
- }
- }
- 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:background="#ffffff">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:src="@drawable/logo_mysh"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical"
- android:gravity="center"
- android:layout_marginLeft="@dimen/edge"
- android:layout_marginRight="@dimen/edge">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/user_name"
- android:id="@+id/txtUser"/>
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/user_pass"
- android:id="@+id/txtPass"
- android:inputType="textPassword"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- android:layout_weight="1"
- android:layout_marginRight="@dimen/edge"
- android:layout_marginLeft="@dimen/edge"
- android:gravity="center">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnLogin"
- android:textSize="22sp"
- android:layout_margin="@dimen/edge"
- android:onClick="btnLogin"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnRegister"
- android:textSize="22sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnRegister"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="2dp"
- android:background="#000000"/>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- android:layout_weight="1">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnAr"
- android:textSize="16sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnAr"
- android:onClick="onClick"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnHE"
- android:textSize="16sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnHe"
- android:onClick="onClick"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnRu"
- android:textSize="16sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnRu"
- android:onClick="onClick"/>
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:background="#009fff"
- android:textColor="#ffffff"
- android:text="@string/btnEn"
- android:textSize="16sp"
- android:layout_margin="@dimen/edge"
- android:id="@+id/btnEn"
- android:onClick="onClick"/>
- </LinearLayout>
- </LinearLayout>
- </LinearLayout>
- strings.xml
- ===================
- <resources>
- <string name="app_name">MySmartHome</string>
- <string name="user_name">Enter user ID...</string>
- <string name="user_pass">Enter user password...</string>
- <string name="btnLogin">Login</string>
- <string name="btnRegister">Register</string>
- <string name="btnHE">עברית</string>
- <string name="btnRu">Rus</string>
- <string name="btnEn">Eng</string>
- <string name="btnAr">Arabic</string>
- </resources>
- dim.xml
- =============
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <dimen name="edge">16dp</dimen>
- </resources>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement