Ejemplo n.º 1
0
 @Override
 public void handleMessage(Message msg) {
   // TODO Auto-generated method stub
   super.handleMessage(msg);
   switch (msg.arg1) {
     case LOGINSUCCESS:
       mProgressDialog.dismiss();
       Toast.makeText(getApplicationContext(), "登陆成功", Toast.LENGTH_SHORT).show();
       Profile profile =
           new Profile(
               Integer.valueOf(((User) msg.obj).getProperty(1).toString()),
               ((User) msg.obj).getProperty(2).toString(),
               mPassWord.getText().toString(),
               null);
       UserProfileUtil.saveProfile(LoginActivity.this, profile);
       finish();
       break;
     case LOGINFAILE:
       mProgressDialog.dismiss();
       Toast.makeText(getApplicationContext(), "登录失败", Toast.LENGTH_SHORT).show();
       break;
   }
 }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    mUserName = (EditText) findViewById(R.id.etUsername);
    mPassWord = (EditText) findViewById(R.id.etPassword);
    mRigist = (Button) findViewById(R.id.btRegist);
    mLogin = (Button) findViewById(R.id.btLogin);

    mNodata = findViewById(R.id.nodatapopup);
    mNodataText = (TextView) mNodata.findViewById(R.id.prompt);
    mNodataText.setText("只有登录才能享受\n更好的服务哦亲!");

    mProfile = UserProfileUtil.readProfile(getApplicationContext());
    if (mProfile != null) { // 如果已经有保存了登录信息,则不必登录
      final AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage(R.string.haslogin);
      builder.setTitle(mProfile.getUsername());
      builder.setIcon(android.R.drawable.ic_dialog_info);
      builder.setCancelable(true);
      builder.setPositiveButton(
          R.string.btOK,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int i2) {
              dialog.dismiss();
              UserProfileUtil.saveProfile(getApplicationContext(), null);
              Toast.makeText(getApplicationContext(), "请进行登录", Toast.LENGTH_SHORT).show();
            }
          });
      builder.setNegativeButton(
          R.string.btBack,
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
              finish();
            }
          });
      builder.show();
    }

    mRigist.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
            startActivity(intent);
          }
        });

    mLogin.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            if (mUserName.getText().toString().trim().equals("")
                || mPassWord.getText().toString().trim().equals("")) {
              Toast.makeText(getApplicationContext(), "输入有误", Toast.LENGTH_SHORT).show();
            } else {
              mProgressDialog = new ProgressDialog(LoginActivity.this);
              mProgressDialog.setMessage("登录中……");
              mProgressDialog.setTitle(
                  LoginActivity.this.getResources().getString(R.string.app_name));
              mProgressDialog.show();
              Login();
            }
          }
        });
  }