@Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    //
    //	this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main_login);

    mEtAccount = (EditText) findViewById(R.id.mainLoginEditAccount);
    mEtPassword = (EditText) findViewById(R.id.mainLoginEditPassword);
    mBtnLogin = (Button) findViewById(R.id.mainLoginBtn);
    mBtnRegister = (Button) findViewById(R.id.main_btn_register);

    /* this is to render the password edittext font to be default */
    mEtPassword.setTypeface(Typeface.DEFAULT);
    mEtPassword.setTransformationMethod(new PasswordTransformationMethod());

    mBtnLogin.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            MainActivity.this.tryLogin();
          }
        });

    mBtnRegister.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Intent intent0 = new Intent(MainActivity.this, RegisterActivity.class);
            startActivity(intent0);
          }
        });
  }
  private void showUserHashDialog() {
    String userHash = NavigineApp.Settings.getString("user_hash", "");

    LayoutInflater inflater = getLayoutInflater();
    View view = inflater.inflate(R.layout.user_hash_dialog, null);
    _userEdit = (EditText) view.findViewById(R.id.user_hash_edit);
    _userEdit.setText(userHash);
    _userEdit.setTypeface(Typeface.MONOSPACE);
    // _userEdit.addTextChangedListener(new TextWatcher()
    //  {
    //    public void afterTextChanged(Editable s) { }
    //    public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
    //    public void onTextChanged(CharSequence s, int start, int before, int count)
    //    {
    //      String text = _userEdit.getText().toString();
    //      int length  = _userEdit.getText().length();
    //
    //      if (text.endsWith("-"))
    //        return;
    //
    //      if (count <= before)
    //        return;
    //
    //      if (length == 4 || length == 9 || length == 14)
    //      {
    //        _userEdit.setText((text + "-"));
    //        _userEdit.setSelection(length + 1);
    //      }
    //    }
    //  });

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
    alertBuilder.setView(view);
    alertBuilder.setTitle("Enter user ID");
    alertBuilder.setNegativeButton(
        getString(R.string.cancel_button),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {}
        });

    alertBuilder.setPositiveButton(
        getString(R.string.ok_button),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dlg, int id) {
            String userHash = _userEdit.getText().toString();
            SharedPreferences.Editor editor = NavigineApp.Settings.edit();
            editor.putString("user_hash", userHash);
            editor.commit();
            NavigineApp.applySettings();
            refreshMapList();
          }
        });

    AlertDialog dialog = alertBuilder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
  }
  public void sendMessage(View view) {
    EditText et = (EditText) findViewById(R.id.editText1);
    final String msg = et.getText().toString();
    et.setText("");
    new Thread(
            new Runnable() {
              public void run() {
                Socket sock = null;
                try {
                  sock = new Socket(ipAddr, sendPort);
                  Log.v(
                      TAG,
                      "send sock: "
                          + sock.getInetAddress().getHostAddress()
                          + sock.isConnected()
                          + Integer.toString(sock.getPort()));
                } catch (UnknownHostException e) {
                  Log.v(ERRORTAG, "" + e.getMessage());
                  e.printStackTrace();
                } catch (IOException e) {
                  Log.v(ERRORTAG, "" + e.getMessage());
                  e.printStackTrace();
                }

                try {
                  PrintWriter out = new PrintWriter(sock.getOutputStream(), true);
                  out.println(msg);
                  updateTextView("<font color=\"#800000\"> <b>Sent: </b></font>" + msg);
                } catch (IOException e) {
                  Log.v(ERRORTAG, "" + e.getMessage());
                  e.printStackTrace();
                }
              }
            })
        .start();
  }
  public void tryLogin() {
    mName = mEtAccount.getText().toString();
    mPassword = mEtPassword.getText().toString();

    if (mName.equals("") || mPassword.length() < 5) { // Please Specify Your Name and Sex"
      Toast.makeText(
              MainActivity.this,
              "Please Specify Your Name and Password correctly",
              Toast.LENGTH_LONG)
          .show();
    } else {
      mUserInfo = new UserInfo(mName, 0, 0, 0, 0, 0, 0);

      /*  if mNetcon is connected already, close it first  */
      /*  here we use try because mNetCon might not have been instantiated yet  */
      /*			try {
      				NetConnect.getnetConnect().closeNetConnect();
      			} catch (Exception e) {}
      			try {
      				InitData.closeInitData();
      				FriendListInfo.closeFriendListInfo();
      				ChatServiceData.closeChatServiceData();
      			} catch (Exception e) {}
      */
      CloseAll.closeAll();
      /*  to establish a new connect  */

      NetworkService.getInstance().onInit(this);
      NetworkService.getInstance().setupConnection();
      if (NetworkService.getInstance().getIsConnected()) {
        String usrInfo =
            mUserInfo.toString()
                + GlobalStrings.signinDivider
                + mPassword
                + GlobalStrings.signinDivider;
        NetworkService.getInstance().sendUpload(GlobalMsgTypes.msgHandShake, usrInfo);
      } else {
        NetworkService.getInstance().closeConnection();
        Toast.makeText(this, "failed to connect to Server", Toast.LENGTH_LONG).show();
        return;
      }

      InitData initData = InitData.getInitData();
      initData.start();
      try {
        initData.join();
      } catch (Exception e) {
      }
      mUserInfo = initData.getUserInfo();

      Log.d(
          "connectedApp isonline : ",
          ""
              + mUserInfo.getIsOnline()
              + "+++++++++++++"
              + "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

      if (mUserInfo.getId() < 0) {
        Toast.makeText(this, "invalid username or password", Toast.LENGTH_SHORT).show();
        return;
      }

      Log.d(
          "connectedApp isonline : ",
          ""
              + mUserInfo.getIsOnline()
              + "+++++++++++++"
              + "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

      ConnectedApp connected_app0 = ConnectedApp.getInstance();
      //		    connected_app0.setConnect(mNetCon);
      connected_app0.setUserInfo(mUserInfo);
      connected_app0.clearListActivity();
      connected_app0.instantiateListActivity();

      Intent intent0 = new Intent(MainActivity.this, MainBodyActivity.class);
      //			intent0.putExtra("username", mUserInfo.getName());
      //			intent0.putExtra("usersex", mUserInfo.getSex());
      startActivity(intent0);

      finish();
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // new thread to create connection
    new Thread(
            new Runnable() {
              public void run() {
                String portStr = get_portStr();
                Log.v(TAG, portStr);

                if (portStr.equals("5554")) {
                  sendPort = 11112;
                } else if (portStr.equals("5556")) {
                  sendPort = 11108;
                } else Log.v(TAG, "AVD portStr is neither 5554 nor 5556");

                Log.v(
                    TAG,
                    "recvPort: "
                        + Integer.toString(recvPort)
                        + " sendPort: "
                        + Integer.toString(sendPort));
              }
            })
        .start();

    // listener embedded in this class only
    new Thread(
            new Runnable() {
              public void run() {
                Socket sock1 = null;
                DataInputStream din = null;
                ServerSocket servSocket = null;
                try {
                  servSocket = new ServerSocket(recvPort);
                  Log.v(TAG, "Server Socket port: " + Integer.toString(servSocket.getLocalPort()));
                } catch (IOException e) {
                  Log.v(ERRORTAG, "" + e.getMessage());
                  e.printStackTrace();
                }

                while (true) {
                  try {
                    sock1 = servSocket.accept();
                    Log.v(
                        TAG,
                        "sock1: "
                            + sock1.getInetAddress().getHostAddress()
                            + sock1.isConnected()
                            + Integer.toString(sock1.getLocalPort())
                            + Integer.toString(sock1.getPort()));
                    BufferedReader br =
                        new BufferedReader(new InputStreamReader(sock1.getInputStream()));
                    String str = br.readLine();
                    Log.v(TAG, "recvd msg: " + str);
                    updateTextView("<font color=\"#0000A0\"> <b>Rcvd: </b></font>" + str);
                  } catch (IOException e) {
                    Log.v(ERRORTAG, "" + e.getMessage());
                    e.printStackTrace();
                  } finally {
                    if (din != null)
                      try {
                        din.close();
                      } catch (IOException e) {
                        Log.v(ERRORTAG, "" + e.getMessage());
                        e.printStackTrace();
                      }
                    if (sock1 != null)
                      try {
                        sock1.close();
                      } catch (IOException e) {
                        Log.v(ERRORTAG, "" + e.getMessage());
                        e.printStackTrace();
                      }
                  }
                }
              }
            })
        .start();

    // now just create a thread to send a message
    final EditText editText = (EditText) findViewById(R.id.editText1);

    editText.setOnKeyListener(
        new OnKeyListener() {

          @Override
          public boolean onKey(View arg0, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
              sendMessage(arg0);
            }
            return false;
          }
        });
  }