Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AndroidManifest
- =======================
- <uses-permission android:name="android.permission.CALL_PHONE" />
- MainActivity.java
- =====================
- public class MainActivity extends AppCompatActivity {
- EditText txtUserName;
- EditText txtUserPass;
- TextView lblMsg;
- final String MY_USER="zeev";
- final String MY_PASS="12345";
- private int totalTry=5;
- Context context;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer();
- }
- private void setPointer()
- {
- context=this;
- txtUserName=(EditText)findViewById(R.id.txtUserName);
- txtUserPass=(EditText)findViewById(R.id.txtUserPassword);
- lblMsg=(TextView)findViewById(R.id.lblMsg);
- }
- public void btnClick(View view)
- {
- String getUser=txtUserName.getText().toString();
- String getPass=txtUserPass.getText().toString();
- if (totalTry==0) {
- Toast.makeText(MainActivity.this, "You are an idiot!!", Toast.LENGTH_SHORT).show();
- return;
- }
- if (getUser.equals(MY_USER) && getPass.equals(MY_PASS))
- {
- //lblMsg.setText("User loged...");
- Intent myIntent = new Intent(this,Welcome.class);
- startActivity(myIntent);
- //startActivity(new Intent(this,Welcome.class));
- finish();
- }
- else
- {
- totalTry--;
- Toast.makeText(MainActivity.this, "you have "+totalTry+" times", Toast.LENGTH_LONG).show();
- }
- }
- }
- 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="@drawable/my_background">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:orientation="vertical">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:src="@drawable/google"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="150dp"
- android:orientation="vertical">
- <EditText
- android:id="@+id/txtUserName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Enter your name...."
- android:inputType="text"
- android:textSize="22sp" />
- <EditText
- android:id="@+id/txtUserPassword"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="Enter Password..."
- android:inputType="textPassword"
- android:textSize="22sp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="70dp"
- android:orientation="vertical">
- <Button
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="Login"
- android:background="#91E0FF"
- android:textColor="#ffffff"
- android:textSize="32sp"
- android:onClick="btnClick"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:textSize="32sp"
- android:text="MY LOGIN SYSTEM V1"
- android:gravity="center"
- android:id="@+id/lblMsg"/>
- </LinearLayout>
- </LinearLayout>
- Welcome.java
- =================
- public class Welcome extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.welcome);
- //utlTest.showMsg(this);
- //create the number we want by String !!!!
- String posted_by = "048772538";
- //create string that is trimmed
- String uri = "tel:" + posted_by.trim() ;
- //create implicty intent of dial
- Intent intent = new Intent(Intent.ACTION_DIAL);
- //sending data to implicity intent
- intent.setData(Uri.parse(uri));
- //start the activity......
- startActivity(intent);
- }
- }
- welcome.xml
- ====================
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@drawable/my_background">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="WELCOME"
- android:textSize="50sp"
- android:gravity="center"
- />
- </LinearLayout>
- utlTest.java
- ======================
- public class utlTest {
- public static void showMsg(Context context)
- {
- Toast.makeText(context, "Hello michal!!!", Toast.LENGTH_LONG).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement