package com.google.android.hello;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#c7c7c7"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Login" />
<EditText
android:maxLines="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
id="@+id/login" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Pin code" />
<EditText
android:maxLines="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
id="@+id/pin" />
EditText editLogin;
EditText editPassword;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
editLogin = ((EditText) this.findViewById(R.id.login));
editPin = ((EditText) this.findViewById(R.id.pin));
editPin.setOnClickListener(this);
}
package com.google.android.hello;
//
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;
public class HelloAndroid extends Activity implements View.OnClickListener{
EditText editLogin;
EditText editPin;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
editLogin = ((EditText) this.findViewById(R.id.login));
editPin = ((EditText) this.findViewById(R.id.pin));
editPin.setOnClickListener(this);
}
public void onClick(View v) {
// , xml shake.xml
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
//
NotificationManager nm = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
// pass
String pass = editPin.getText().toString();
// 4
if( pass.length() == 4)
{
// , - "Welcome + "
nm.notifyWithText(R.id.login,
"Welcome "+editLogin.getText().toString(),
NotificationManager.LENGTH_SHORT, null);
//
Intent intent = new Intent();
intent.setClass(HelloAndroid.this, WelcomeAndroid.class);
startActivity(intent);
// Activity
finish();
}
else
{
// -
editPin.startAnimation(shake);
// "Wrong pin, must be 4 digits"
nm.notifyWithText(R.id.login,
"Wrong pin, must be 4 digits",
NotificationManager.LENGTH_SHORT, null);
//
editPin.setText("");
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#c7c7c7"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Welcome Android" />
<?xml version="1.0" encoding="utf-8"?>
<CycleInterpolator
xmlns:android=http://schemas.android.com/apk/res/android android:cycles="7" />
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android=http://schemas.android.com/apk/res/android android:fromXDelta="0"
android:toXDelta="10"
android:duration="1000"
android:interpolator="@anim/cycle_7" />
<activity class=".WelcomeAndroid" android:label="@string/app_name">
Source: https://habr.com/ru/post/16386/
All Articles