/**
*
* @author Alex
* @version 2014-7-31 5:25:45
*
*/
public class Loginactivity extends Activity {
private EditText name;
Private EditText Pass;
Private CheckBox Isremenber;
Private CheckBox isloginself;
Private Button Longin;
Private ProgressDialog Mdialog;
/** called when the activity is first created. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Name= (EditText) Findviewbyid (r.id.et_name);
Pass= (EditText) Findviewbyid (R.id.et_pass);
Isremenber= (CheckBox) Findviewbyid (R.id.isremenber);
isloginself= (CheckBox) Findviewbyid (r.id.isloginself);
Longin= (Button) Findviewbyid (R.id.longin);
Final sharedpreferences pre=getsharedpreferences ("Longinvalue", mode_world_writeable);
if (pre!=null) {
Remember the password
if (Pre.getboolean ("ISRMB", false) ==true) {
Name.settext (pre.getstring ("name", null));
Pass.settext (pre.getstring ("pass", null));
Isremenber.setchecked (TRUE);
}
if (Pre.getboolean ("Islgs", false) ==true) {
Isloginself.setchecked (TRUE);
Creatdialog ();
New Thread () {
public void Run () {
try {
Thread.Sleep (3000);
if (mdialog.isshowing ()) {
Mdialog.dismiss ();
}
Intent intent2=new Intent (loginactivity.this,show.class);
StartActivity (Intent2);
} catch (Exception e) {
Todo:handle exception
}
}
}.start ();
}
}
Isremenber.setoncheckedchangelistener (New Oncheckedchangelistener () {
@Override
public void OnCheckedChanged (Compoundbutton buttonview, Boolean isChecked) {
TODO auto-generated Method Stub
if (isremenber.ischecked () ==false) {
Isloginself.setchecked (FALSE);
}
}
});
Isloginself.setoncheckedchangelistener (New Oncheckedchangelistener () {
@Override
public void OnCheckedChanged (Compoundbutton buttonview, Boolean isChecked) {
TODO auto-generated Method Stub
Isremenber.setchecked (TRUE);
}
});
Longin.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
if (!name.gettext (). ToString (). Equals ("") &&!pass.gettext (). ToString (). Equals ("")) {
if (isloginself.ischecked ()) {
Pre.edit (). Putboolean ("ISRMB", True). Putboolean ("Islgs", True). Putstring ("name", Name.gettext (). toString ())
. putstring ("Pass", Pass.gettext (). toString ()). commit ();
}else{
if (isremenber.ischecked ()) {
Pre.edit (). Putboolean ("ISRMB", True). Putboolean ("Islgs", false). Putstring ("name", Name.gettext (). toString ())
. putstring ("Pass", Pass.gettext (). toString ()). commit ();
}else{
Pre.edit (). Putboolean ("ISRMB", false). Putboolean ("Islgs", false). Putstring ("name", Name.gettext (). toString ())
. putstring ("Pass", Pass.gettext (). toString ()). commit ();
}
}
Intent intent=new Intent (loginactivity.this,show.class);
StartActivity (Intent);
}else{
Toast.maketext (Getapplicationcontext (), "password or account cannot be empty!" ", Toast.length_long). Show ();
}
}
});
}
private void Creatdialog () {
Mdialog=new ProgressDialog (this);
Mdialog.settitle ("in Verification");
Mdialog.setmessage ("Landing please later");
Mdialog.setindeterminate (TRUE);
Mdialog.setcancelable (TRUE);
Mdialog.show ();
}
}
Import android.app.Activity;
Import Android.os.Bundle;
public class Show extends activity{
@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Setcontentview (r.layout.show);
}
}
<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Alex.sias.com"
Android:versioncode= "1"
Android:versionname= "1.0" >
<USES-SDK android:minsdkversion= "8"/>
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE" >
</uses-permission>
<application
android:icon= "@drawable/icon"
Android:label= "@string/app_name"
Android:theme= "@android: Style/theme.notitlebar.fullscreen" >
<activity
Android:name= ". Loginactivity "
Android:label= "@string/app_name" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name= "Show" >
</activity>
</application>
</manifest>
Use of two layout files
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:background= "@drawable/chat_bg_default"
>
<textview
android:layout_height= "50DP"
Android:layout_width= "Fill_parent"
android:gravity= "Center"
Android:textsize= "24SP"
android:text= "Login Screen"
Android:textcolor= "@color/white"
android:background= "@drawable/song_index_item_bg"/>
<imageview
Android:id= "@+id/iv"
android:layout_height= "220DP"
Android:layout_width= "230DP"
android:layout_margintop= "110DP"
android:src= "@drawable/background"
Android:layout_centerhorizontal= "true"
Android:scaletype= "Fitxy"/>
<textview
Android:id= "@+id/tv_name"
android:layout_height= "Wrap_content"
Android:layout_width= "Wrap_content"
Android:textsize= "15SP"
android:layout_margintop= "7DP"
android:text= "Account Number:"
android:layout_alignleft= "@+id/iv"
android:layout_aligntop= "@+id/iv"
android:layout_marginleft= "7DP"
Android:textcolor= "@color/green"/>
<edittext
Android:id= "@+id/et_name"
android:layout_height= "25DP"
Android:layout_width= "210DP"
android:layout_margintop= "7DP"
android:layout_below= "@+id/tv_name"
android:background= "@drawable/shape"
android:layout_alignleft= "@+id/tv_name"/>
<textview
Android:id= "@+id/tv_pass"
android:layout_height= "Wrap_content"
Android:layout_width= "Wrap_content"
Android:textsize= "15SP"
android:text= "Password:"
android:layout_alignleft= "@+id/tv_name"
android:layout_below= "@+id/et_name"
android:layout_margintop= "7DP"
Android:textcolor= "@color/green"/>
<edittext
Android:id= "@+id/et_pass"
android:layout_height= "25DP"
Android:layout_width= "210DP"
android:background= "@drawable/shape"
android:layout_margintop= "7DP"
android:layout_below= "@+id/tv_pass"
android:layout_alignleft= "@+id/tv_name"/>
<checkbox
Android:id= "@+id/isremenber"
android:layout_height= "Wrap_content"
Android:layout_width= "Wrap_content"
android:layout_alignleft= "@+id/tv_name"
android:layout_margintop= "10DP"
android:text= "Remember Password"
Android:textsize= "11SP"
Android:textcolor= "@color/huise"
android:layout_below= "@+id/et_pass"
android:button= "@drawable/mycheckbox"/>
<checkbox
Android:id= "@+id/isloginself"
android:layout_height= "Wrap_content"
Android:layout_width= "Wrap_content"
android:layout_alignright= "@+id/et_name"
android:layout_margintop= "10DP"
android:text= "Automatic Login"
Android:textsize= "11SP"
Android:textcolor= "@color/huise"
android:layout_below= "@+id/et_pass"
android:button= "@drawable/mycheckbox"/>
<button
Android:id= "@+id/longin"
android:layout_height= "25DP"
Android:layout_width= "210DP"
android:layout_below= "@+id/isloginself"
android:layout_alignleft= "@+id/et_pass"
android:layout_margintop= "10DP"
android:text= "Login"
android:gravity= "Center"
android:background= "@drawable/loginbtn"/>
</RelativeLayout>
<?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= "@color/white" >
<textview
android:layout_height= "Fill_parent"
Android:layout_width= "Fill_parent"
android:text= "Hey!"
Android:textsize= "40SP"
android:gravity= "Center"/>
</LinearLayout>