相關閱讀:Android拍照上傳程序的xml配置文件 http://www.linuxidc.com/Linux/2011-11/47618.htm
1、LoginWindow.java --登錄窗口
- package com.hemi.rhet;
-
- import com.hemi.rhet.R;
-
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
-
- public class LoginWindow extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- System.out.println("enter LoginWindow.onCreate()!");
-
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.login_window);
-
- mUserName = (EditText)findViewById(R.id.username);
- mUserPasswd = (EditText)findViewById(R.id.userpasswd);
-
- cbx_cmwap = (CheckBox) findViewById(R.id.cbx_cmwap);
-
- loginButton = (Button) findViewById(R.id.login_button);
- exitButton = (Button) findViewById(R.id.exit_button);
-
- loginBtnListener = new View.OnClickListener() {
- public void onClick(View view) {
- LoginWindow.isCmwap = cbx_cmwap.isChecked();
-
- if (view == loginButton) {
- launchFetion();
- } else if(view == exitButton) {
- finish();
- }
- }
- };
-
- loginButton.setOnClickListener(loginBtnListener);
- exitButton.setOnClickListener(loginBtnListener);
- }
-
- private void launchFetion() {
- Intent i = new Intent(this, FuncSelector.class);
- i.putExtra(KEY_LOGIN_NAME, mUserName.getText().toString());
- i.putExtra(KEY_LOGIN_PASSWD, mUserPasswd.getText().toString());
- i.putExtra(KEY_LOGIN_TYPE, cbx_cmwap.isChecked());
-
- startActivity(i);
- }
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent msg) {
- // System.out.println("enter onKeyDown() in LoginWindow!");
- //
- // if (null != loginBtnListener) {
- // View aview = getCurrentFocus();
- // loginBtnListener.onClick(aview);
- // }
- return false;
- }
-
- private Button loginButton, exitButton;
- private EditText mUserName;
- private EditText mUserPasswd;
- private CheckBox cbx_cmwap;
-
- private OnClickListener loginBtnListener;
-
- public static final String KEY_LOGIN_NAME = "login_name";
- public static final String KEY_LOGIN_PASSWD = "login_passwd";
- public static final String KEY_LOGIN_TYPE = "login_type";
-
- public static boolean isCmwap = false;
- }
2. FuncSelector.java -- 功能模塊選擇窗口
- package com.hemi.rhet;
-
- import java.util.ArrayList;
- import java.util.HashMap;
-
- import com.hemi.rhet.R;
-
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.GridView;
- import android.widget.SimpleAdapter;
- import android.widget.AdapterView.OnItemClickListener;
-
- public class FuncSelector extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- Log.i("info", "enter LoginWindow.onCreate()!");
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.func_selector);
-
- initFuncGrids();
- }
-
- private void initFuncGrids() {
- GridView funcSeleView = (GridView) findViewById(R.id.func_selector);
-
- // 生成動態數組,並且轉入數據
- ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
-
- HashMap<String, Object> map = new HashMap<String, Object>();
- map.put("ItemImage", R.drawable.photo_upload); // 添加圖像資源的ID
- map.put("ItemText", getString(R.string.photo_upload)); // 按序號做ItemText
- lstImageItem.add(map);
-
- map = new HashMap<String, Object>();
- map.put("ItemImage", R.drawable.icon);
- map.put("ItemText", getString(R.string.sys_config));
- lstImageItem.add(map);
-
- for (int i = 1; i <= 10; i++) {
- map = new HashMap<String, Object>();
- map.put("ItemImage", R.drawable.icon); // 添加圖像資源的ID
- map.put("ItemText", "NO." + String.valueOf(i)); // 按序號做ItemText
- lstImageItem.add(map);
- }
-
- // 生成適配器的ImageItem <====> 動態數組的元素,兩者一一對應
- SimpleAdapter saImageItems = new SimpleAdapter(this, // 沒什麼解釋
- lstImageItem,// 數據來源
- R.layout.night_item,// night_item的XML實現
-
- // 動態數組與ImageItem對應的子項
- new String[] { "ItemImage", "ItemText" },
-
- // ImageItem的XML文件裡面的一個ImageView,兩個TextView ID
- new int[] {R.id.ItemImage,R.id.ItemText});
- //null);
-
- // 添加並且顯示
- funcSeleView.setAdapter(saImageItems);
- //saImageItems.notifyDataSetChanged();
-
- // 添加消息處理
- funcSeleView.setOnItemClickListener(new ItemClickListener());
- }
-
- public boolean onCreateOptionsMenu(Menu menu) {
- super.onCreateOptionsMenu(menu);
- menu.add(0, EXIT_ID,0, R.string.back_button);
-
- return true;
- }
-
- //@Override
- public boolean onMenuItemSelected(int featureId, MenuItem item) {
- boolean result = true;
-
- switch(item.getItemId()) {
- case EXIT_ID:
- this.finish();
- break;
-
- default:
- result = super.onMenuItemSelected(featureId, item);
- break;
- }
-
- return result;
- }
-
- // 當AdapterView被單擊(觸摸屏或者鍵盤),則返回的Item單擊事件
- class ItemClickListener implements OnItemClickListener {
- public void onItemClick(AdapterView<?> arg0,// The AdapterView where the
- // click happened
- View arg1,// The view within the AdapterView that was clicked
- int arg2,// The position of the view in the adapter
- long arg3// The row id of the item that was clicked
- ) {
- // 在本例中arg2=arg3
- HashMap<String, Object> item = (HashMap<String, Object>) arg0
- .getItemAtPosition(arg2);
-
- String tmpStr = (String) item.get("ItemText");
- //item.put("ItemText", tmpStr + tmpStr.substring(tmpStr.length() - 1));
-
- // 顯示所選Item的ItemText
- // setTitle((String)item.get("ItemText"));
- Log.i("info", (String) item.get("ItemText"));
-
- ((SimpleAdapter) arg0.getAdapter()).notifyDataSetChanged();
-
- Intent i;
- switch (arg2) {
- case 0:
- i = new Intent();
- i.setClass(FuncSelector.this, PhotoUpload.class);
- startActivity(i);
- break;
-
- case 1:
- i = new Intent();
- i.setClass(FuncSelector.this, ConfigWindow.class);
- startActivity(i);
- break;
-
- default:
- break;
- }
- }
-
- }
-
- private static final int TAKE_PHOTO_ID = Menu.FIRST;
- private static final int UPLOAD_PHOTO_ID = Menu.FIRST + 1;
- private static final int EXIT_ID = Menu.FIRST + 3;
-
- }//FuncSelector