java發送郵件示例講授。本站提示廣大學習愛好者:(java發送郵件示例講授)文章只能為提供參考,不一定能成為您想要的結果。以下是java發送郵件示例講授正文
本文實例為年夜家分享了Android帶有記住暗碼功效的上岸界面完成代碼,供年夜家參考,詳細內容以下
1、設計思緒
重要采取SharedPreferences來保留用戶數據,本Demo沒有經由加密,一切一旦Android體系被ROOT的話,其他用戶便可以檢查用戶的公有目次,暗碼文件就很不平安。所以真正運用在軟件下面的,必定要經由加密才保留,可以選擇MD5加密。
SharedPreferences引見可以參看這篇博文:http://www.jb51.net/article/84859.htm
TextWatcher的引見可以參看這篇博文:http://www.jb51.net/article/84865.htm
2、功效引見
默許勾選“記住暗碼”復選框,點擊“上岸”按鈕,一旦勝利上岸,就保留用戶名和暗碼到SharedPreferences文件中。
用戶名輸出時,經由過程TextWatcher赓續去讀取用戶數據,主動提醒響應的“用戶名”,選擇了用戶名以後,就會讀取SharedPreferences的文件,然後主動完成暗碼的輸出。
3、後果圖
4、代碼:具體都在正文外面了
/*author: conowen
* date: 2012.4.2
*
*/
package com.conowen.remeberPwd;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class RemeberPwdActivity extends Activity {
AutoCompleteTextView cardNumAuto;
EditText passwordET;
Button logBT;
CheckBox savePasswordCB;
SharedPreferences sp;
String cardNumStr;
String passwordStr;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cardNumAuto = (AutoCompleteTextView) findViewById(R.id.cardNumAuto);
passwordET = (EditText) findViewById(R.id.passwordET);
logBT = (Button) findViewById(R.id.logBT);
sp = this.getSharedPreferences("passwordFile", MODE_PRIVATE);
savePasswordCB = (CheckBox) findViewById(R.id.savePasswordCB);
savePasswordCB.setChecked(true);// 默許為記住暗碼
cardNumAuto.setThreshold(1);// 輸出1個字母就開端主動提醒
passwordET.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
// 隱蔽暗碼為InputType.TYPE_TEXT_VARIATION_PASSWORD,也就是0x81
// 顯示暗碼為InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD,也就是0x91
cardNumAuto.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
String[] allUserName = new String[sp.getAll().size()];// sp.getAll().size()前往的是有若干個鍵值對
allUserName = sp.getAll().keySet().toArray(new String[0]);
// sp.getAll()前往一張hash map
// keySet()獲得的是a set of the keys.
// hash map是由key-value構成的
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
RemeberPwdActivity.this,
android.R.layout.simple_dropdown_item_1line,
allUserName);
cardNumAuto.setAdapter(adapter);// 設置數據適配器
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
passwordET.setText(sp.getString(cardNumAuto.getText()
.toString(), ""));// 主動輸出暗碼
}
});
// 上岸
logBT.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cardNumStr = cardNumAuto.getText().toString();
passwordStr = passwordET.getText().toString();
if (!((cardNumStr.equals("test")) && (passwordStr
.equals("test")))) {
Toast.makeText(RemeberPwdActivity.this, "暗碼毛病,請從新輸出",
Toast.LENGTH_SHORT).show();
} else {
if (savePasswordCB.isChecked()) {// 上岸勝利才保留暗碼
sp.edit().putString(cardNumStr, passwordStr).commit();
}
Toast.makeText(RemeberPwdActivity.this, "上岸勝利,正在獲得用戶數據……",
Toast.LENGTH_SHORT).show();
// 跳轉到另外一個Activity
// do something
}
}
});
}
}
結構文件:main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="簡略上岸DEMO" android:textSize="25px" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical" > <LinearLayout android:layout_width="250dip" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="15dp" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="fill_parent" android:layout_height="80px" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="40px" android:orientation="horizontal" > <TextView android:id="@+id/tv_account" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:text="用 戶 名:" android:textSize="15px" /> <AutoCompleteTextView android:id="@+id/cardNumAuto" android:layout_width="fill_parent" android:layout_height="40px" > </AutoCompleteTextView> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="40px" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:text="用戶暗碼:" android:textSize="15px" /> <EditText android:id="@+id/passwordET" android:layout_width="fill_parent" android:layout_height="40px" > </EditText> </LinearLayout> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <CheckBox android:id="@+id/savePasswordCB" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="記住暗碼" > </CheckBox> <Button android:id="@+id/logBT" android:layout_width="100px" android:layout_height="wrap_content" android:layout_marginLeft="40dp" android:layout_marginRight="10dp" android:text="登錄" > </Button> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout>
SharedPreferences文件,在/data/data/包名/shared_prefs文件夾上面
<?xml version='1.0' encoding='utf-8' standalone='yes' ?> <map> <string name="test">test</string> <string name="test2">test</string> <string name="test1">test</string> </map>
以上就是本文的全體內容,願望對年夜家進修Android軟件編程有所贊助。