团队冲刺第三天
1.今天修补了一下之前的bug。之前的问题是。偶尔会出现定位失败。并且光标不显示的问题。
最后发现是因为android版本6.0以上的用户。在使用百度定位的时候需要一些另外的权限,并且代码本身不能自己设置的问题。最后完美解决。
主要是对百度定位的相关api的了解不够全面。明天将会主要用来研究怎样实现运动轨迹的显示。
具体的解决代码如下:
private static final int REQUEST_CODE = 1; private void requestRunTimePermission() { if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,Manifest.permission.ACCESS_COARSE_LOCATION) || ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,Manifest.permission.ACCESS_FINE_LOCATION) || ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,Manifest.permission.WRITE_EXTERNAL_STORAGE) || ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,Manifest.permission.READ_PHONE_STATE)) { /* * 如果没有获得过用户的权限许可,则向用户申请 */ Snackbar.make(MainActivity.this.findViewById(R.id.butttonunder2), "定位", Snackbar.LENGTH_INDEFINITE).setAction("权限申请", new View.OnClickListener() { @Override public void onClick(View view) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_PHONE_STATE },REQUEST_CODE); } }).show(); } else { /* * 如果已经获得过用户的权限许可了,则直接申请运行时权限即可 */ ActivityCompat.requestPermissions(MainActivity.this, new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_PHONE_STATE },REQUEST_CODE); } }
2.今天算是小有成就,完成了我自己第一部分任务的所有内容,包括注册登录的所有功能,以及一些小的细节,过程中遇到了一些问题,但都不是什么大的问题,相对昨天来说轻松了不少,下面是一些效果图以及主要代码
package com.login; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; import com.example.keeprunning1.R; import com.register.RegisterActivity; import com.user.User; import com.user.UserOperator; public class LoginActivity extends Activity implements View.OnClickListener { private EditText etLoginUsername; private EditText etLoginPwd; private Button btLoginSubmit; private Button btLoginRegister; private CheckBox cbRememberLogin; private TextView tvLoginForgetPwd; private UserOperator muserOperator; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); muserOperator = new UserOperator(this); initView(); } public void initView() { etLoginUsername = (EditText) findViewById(R.id.et_login_username); etLoginPwd = (EditText) findViewById(R.id.et_login_pwd); btLoginSubmit = (Button) findViewById(R.id.bt_login_submit); btLoginRegister = (Button) findViewById(R.id.bt_login_register); cbRememberLogin = (CheckBox) findViewById(R.id.cb_remember_login); tvLoginForgetPwd = (TextView) findViewById(R.id.tv_login_forget_pwd); btLoginSubmit.setOnClickListener(this); btLoginRegister.setOnClickListener(this); //判断是否记住过密码,如果上次登录记住过密码,则显示密码 etLoginUsername.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) {//获得焦点 } else { String username = etLoginUsername.getText().toString().trim(); if (!TextUtils.isEmpty(username)) { User bean = muserOperator.isExit(username); if (bean!= null) { String usercheck = bean.usercheck; String userpsw = bean.userpsw; Log.d("volley", usercheck); if (usercheck.equals("1")) { Log.d("volley", userpsw); etLoginPwd.setText(userpsw); cbRememberLogin.setChecked(true); } } else { etLoginUsername.setText(""); etLoginUsername.setHint("账户不存在,请先注册"); } } else { etLoginUsername.setHint("请输入用户名"); } } } }); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bt_login_register: startActivityForResult(new Intent(this, RegisterActivity.class), 0x11); break; case R.id.bt_login_submit: String username = etLoginUsername.getText().toString().trim(); String userpsw = etLoginPwd.getText().toString().trim(); if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(userpsw)) { User bean = muserOperator.isExit(username); // String userpsws = bean.userpsw; // Log.d("volley", userpsws); if (bean != null && bean.userpsw.equals(userpsw)) { if (cbRememberLogin.isChecked()) { String usercheck = "1"; User beans = new User(username, usercheck); muserOperator.isRemPsw(beans); }else{ String usercheck = "0"; User beans = new User(username, usercheck); muserOperator.isRemPsw(beans); } Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(this, RegisterActivity.class); startActivity(intent); finish(); } else { Toast.makeText(this, "密码错误", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(this, "请将信息填写完整", Toast.LENGTH_SHORT).show(); } break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 0x11 && resultCode == 0x11) { Bundle bundle = data.getExtras(); String username = bundle.getString("username"); String password = bundle.getString("password"); etLoginPwd.setText(password); etLoginUsername.setText(username); } } }
3.今天的我毫无成就感,自我忏悔了一番,这就是不从头好好学习的结果,半路截取知识和代码真的太累了。
修改了两个多小时的bug,昨天的问题依旧没有解决,突然间感觉之前写的都是无用的代码,只能靠双休从头来补了。加油吧!