Initial commit
This commit is contained in:
parent
ad8f59500b
commit
8e933bb640
@ -11,6 +11,12 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.AppCompat.NoActionBar"
|
android:theme="@style/Theme.AppCompat.NoActionBar"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
|
<activity
|
||||||
|
android:name=".activity.ModifyPswActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".activity.SettingActivity"
|
||||||
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activity.LoginActivity"
|
android:name=".activity.LoginActivity"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
@ -3,21 +3,250 @@ package com.youxuegu;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.youxuegu.activity.LoginActivity;
|
import com.youxuegu.activity.LoginActivity;
|
||||||
import com.youxuegu.activity.RegisterActivity;
|
import com.youxuegu.activity.RegisterActivity;
|
||||||
|
import com.youxuegu.utils.UtilsHelper;
|
||||||
|
import com.youxuegu.view.MyInfoView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author YoVinchen
|
* @author YoVinchen
|
||||||
*/
|
*/
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
private FrameLayout mBodyLayout; //中间内容栏
|
||||||
|
public LinearLayout mBottomLayout; //底部按钮栏
|
||||||
|
private View mCourseBtn, mExercisesBtn, mMyInfoBtn;
|
||||||
|
private TextView tv_course, tv_exercises, tv_myInfo;
|
||||||
|
private ImageView iv_course, iv_exercises, iv_myInfo;
|
||||||
|
private TextView tv_back, tv_main_title;
|
||||||
|
private RelativeLayout rl_title_bar;
|
||||||
|
|
||||||
|
private MyInfoView mMyInfoView;
|
||||||
|
// private ExercisesView mExercisesView;
|
||||||
|
// private CourseView mCourseView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
|
init();
|
||||||
startActivity(intent);
|
setListener();
|
||||||
|
selectDisplayView(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取界面上的控件
|
||||||
|
*/
|
||||||
|
private void init() {
|
||||||
|
tv_back = findViewById(R.id.tv_back);
|
||||||
|
tv_main_title = findViewById(R.id.tv_main_title);
|
||||||
|
tv_main_title.setText("优学谷课程");
|
||||||
|
rl_title_bar = findViewById(R.id.title_bar);
|
||||||
|
rl_title_bar.setBackgroundColor(Color.parseColor("#30B4FF"));
|
||||||
|
tv_back.setVisibility(View.GONE);
|
||||||
|
mBodyLayout = findViewById(R.id.main_body);
|
||||||
|
mBottomLayout = findViewById(R.id.main_bottom_bar);
|
||||||
|
mCourseBtn = findViewById(R.id.bottom_bar_course_btn);
|
||||||
|
mExercisesBtn = findViewById(R.id.bottom_bar_exercises_btn);
|
||||||
|
mMyInfoBtn = findViewById(R.id.bottom_bar_myinfo_btn);
|
||||||
|
tv_course = findViewById(R.id.bottom_bar_text_course);
|
||||||
|
tv_exercises = findViewById(R.id.bottom_bar_text_exercises);
|
||||||
|
tv_myInfo = findViewById(R.id.bottom_bar_text_myinfo);
|
||||||
|
iv_course = findViewById(R.id.bottom_bar_image_course);
|
||||||
|
iv_exercises = findViewById(R.id.bottom_bar_image_exercises);
|
||||||
|
iv_myInfo = findViewById(R.id.bottom_bar_image_myinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置底部按钮未被选中时的状态
|
||||||
|
*/
|
||||||
|
private void setNotSelectedStatus() {
|
||||||
|
tv_course.setTextColor(Color.parseColor("#666666"));
|
||||||
|
tv_exercises.setTextColor(Color.parseColor("#666666"));
|
||||||
|
tv_myInfo.setTextColor(Color.parseColor("#666666"));
|
||||||
|
iv_course.setImageResource(R.drawable.main_course_icon);
|
||||||
|
iv_exercises.setImageResource(R.drawable.main_exercises_icon);
|
||||||
|
iv_myInfo.setImageResource(R.drawable.main_my_icon);
|
||||||
|
for (int i = 0; i < mBottomLayout.getChildCount(); i++) {
|
||||||
|
mBottomLayout.getChildAt(i).setSelected(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置底部按钮被选中时的状态
|
||||||
|
*/
|
||||||
|
private void setSelectedStatus(int index) {
|
||||||
|
switch (index) {
|
||||||
|
case 0:
|
||||||
|
mCourseBtn.setSelected(true);
|
||||||
|
iv_course.setImageResource(R.drawable.main_course_icon_selected);
|
||||||
|
tv_course.setTextColor(Color.parseColor("#0097F7"));
|
||||||
|
rl_title_bar.setVisibility(View.VISIBLE);
|
||||||
|
tv_main_title.setText("优学谷课程");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
mExercisesBtn.setSelected(true);
|
||||||
|
iv_exercises.setImageResource(R.drawable.main_exercises_icon_selected);
|
||||||
|
tv_exercises.setTextColor(Color.parseColor("#0097F7"));
|
||||||
|
rl_title_bar.setVisibility(View.VISIBLE);
|
||||||
|
tv_main_title.setText("优学谷习题");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
mMyInfoBtn.setSelected(true);
|
||||||
|
iv_myInfo.setImageResource(R.drawable.main_my_icon_selected);
|
||||||
|
tv_myInfo.setTextColor(Color.parseColor("#0097F7"));
|
||||||
|
rl_title_bar.setVisibility(View.GONE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 隐藏底部导航栏界面的中间部分视图
|
||||||
|
*/
|
||||||
|
private void hideAllView() {
|
||||||
|
for (int i = 0; i < mBodyLayout.getChildCount(); i++) {
|
||||||
|
mBodyLayout.getChildAt(i).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建视图
|
||||||
|
*/
|
||||||
|
private void createView(int viewIndex) {
|
||||||
|
switch (viewIndex) {
|
||||||
|
case 0:
|
||||||
|
//课程界面
|
||||||
|
// if (mCourseView == null) {
|
||||||
|
// mCourseView = new CourseView(this);
|
||||||
|
// mBodyLayout.addView(mCourseView.getView());
|
||||||
|
// } else {
|
||||||
|
// mCourseView.getView();
|
||||||
|
// }
|
||||||
|
// mCourseView.showView();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
//习题界面
|
||||||
|
// if (mExercisesView == null) {
|
||||||
|
// mExercisesView = new ExercisesView(this); //实例化ExercisesView类
|
||||||
|
// mBodyLayout.addView(mExercisesView.getView()); //将习题界面添加到底部导航栏的布局中
|
||||||
|
// } else {
|
||||||
|
// mExercisesView.getView(); //获取习题界面
|
||||||
|
// }
|
||||||
|
// mExercisesView.showView(); //显示习题界面
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
//"我"的界面
|
||||||
|
if (mMyInfoView == null) {
|
||||||
|
mMyInfoView = new MyInfoView(this);
|
||||||
|
//加载“我”的界面
|
||||||
|
mBodyLayout.addView(mMyInfoView.getView());
|
||||||
|
} else {
|
||||||
|
//获取“我”的界面
|
||||||
|
mMyInfoView.getView();
|
||||||
|
}
|
||||||
|
//显示“我”的界面
|
||||||
|
mMyInfoView.showView();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置底部按钮被选中时对应的界面中间部分视图
|
||||||
|
*/
|
||||||
|
private void selectDisplayView(int index) {
|
||||||
|
//隐藏所有视图
|
||||||
|
hideAllView();
|
||||||
|
//创建被选中按钮对应的视图
|
||||||
|
createView(index);
|
||||||
|
//设置被选中按钮的选中状态
|
||||||
|
setSelectedStatus(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置底部3个按钮的点击事件的监听器
|
||||||
|
*/
|
||||||
|
private void setListener() {
|
||||||
|
for (int i = 0; i < mBottomLayout.getChildCount(); i++) {
|
||||||
|
mBottomLayout.getChildAt(i).setOnClickListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
switch (v.getId()) {
|
||||||
|
//"课程"按钮的点击事件
|
||||||
|
case R.id.bottom_bar_course_btn:
|
||||||
|
setNotSelectedStatus();
|
||||||
|
selectDisplayView(0);
|
||||||
|
break;
|
||||||
|
//"习题"按钮的点击事件
|
||||||
|
case R.id.bottom_bar_exercises_btn:
|
||||||
|
setNotSelectedStatus();
|
||||||
|
selectDisplayView(1);
|
||||||
|
break;
|
||||||
|
//"我"的按钮的点击事件
|
||||||
|
case R.id.bottom_bar_myinfo_btn:
|
||||||
|
setNotSelectedStatus();
|
||||||
|
selectDisplayView(2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录第一次点击时的时间
|
||||||
|
*/
|
||||||
|
protected long exitTime;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||||
|
if ((System.currentTimeMillis() - exitTime) > 2000) {
|
||||||
|
Toast.makeText(MainActivity.this, "再按一次退出博学谷", Toast.LENGTH_SHORT).show();
|
||||||
|
//记录当前点击返回键的时间
|
||||||
|
exitTime = System.currentTimeMillis();
|
||||||
|
} else {
|
||||||
|
MainActivity.this.finish();
|
||||||
|
if (UtilsHelper.readLoginStatus(MainActivity.this)) {
|
||||||
|
//清除登录状态与用户名
|
||||||
|
UtilsHelper.clearLoginStatus(MainActivity.this);
|
||||||
|
}
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
if (data != null) {
|
||||||
|
//获取从设置界面或登录界面传递过来的登录状态
|
||||||
|
boolean isLogin = data.getBooleanExtra("isLogin", false);
|
||||||
|
//登录成功时显示课程界面
|
||||||
|
if (isLogin) {
|
||||||
|
setNotSelectedStatus();
|
||||||
|
selectDisplayView(0);
|
||||||
|
}
|
||||||
|
if (mMyInfoView != null) {
|
||||||
|
//登录成功或退出登录时根据isLogin的值设置"我"的界面
|
||||||
|
mMyInfoView.setLoginParams(isLogin);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package com.youxuegu.activity;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.youxuegu.R;
|
||||||
|
import com.youxuegu.utils.MD5Utils;
|
||||||
|
import com.youxuegu.utils.UtilsHelper;
|
||||||
|
|
||||||
|
public class ModifyPswActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
private TextView tv_main_title;
|
||||||
|
private TextView tv_back;
|
||||||
|
private EditText et_original_psw, et_new_psw, et_new_psw_again;
|
||||||
|
private Button btn_save;
|
||||||
|
private String originalPsw, newPsw, newPswAgain;
|
||||||
|
private String spOriginalPsw, userName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_modify_psw);
|
||||||
|
init();
|
||||||
|
userName = UtilsHelper.readLoginUserName(this);
|
||||||
|
spOriginalPsw = UtilsHelper.readPsw(this, userName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
tv_main_title = findViewById(R.id.tv_main_title);
|
||||||
|
tv_main_title.setText("修改密码");
|
||||||
|
tv_back = findViewById(R.id.tv_back);
|
||||||
|
et_original_psw = findViewById(R.id.et_original_psw);
|
||||||
|
et_new_psw = findViewById(R.id.et_new_psw);
|
||||||
|
et_new_psw_again = findViewById(R.id.et_new_psw_again);
|
||||||
|
btn_save = findViewById(R.id.btn_save);
|
||||||
|
tv_back.setOnClickListener(this);
|
||||||
|
btn_save.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
switch (view.getId()) {
|
||||||
|
case R.id.tv_back:
|
||||||
|
ModifyPswActivity.this.finish();
|
||||||
|
break;
|
||||||
|
case R.id.btn_save:
|
||||||
|
getEditString();
|
||||||
|
if (TextUtils.isEmpty(originalPsw)) {
|
||||||
|
Toast.makeText(ModifyPswActivity.this, "请输入原始密码", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
} else if (!MD5Utils.md5(originalPsw).equals(spOriginalPsw)) {
|
||||||
|
Toast.makeText(ModifyPswActivity.this, "输入的密码与原始密码不相同", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
} else if (MD5Utils.md5(newPsw).equals(spOriginalPsw)) {
|
||||||
|
Toast.makeText(ModifyPswActivity.this, "输入的新密码与原始密码不能相同", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
} else if (TextUtils.isEmpty(newPsw)) {
|
||||||
|
Toast.makeText(ModifyPswActivity.this, "请输入新密码", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
} else if (TextUtils.isEmpty(newPswAgain)) {
|
||||||
|
Toast.makeText(ModifyPswActivity.this, "请再次输入新密码", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
} else if (!newPsw.equals(newPswAgain)) {
|
||||||
|
Toast.makeText(ModifyPswActivity.this, "两次输入的新密码不一致", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Toast.makeText(ModifyPswActivity.this, "新密码设置成功", Toast.LENGTH_SHORT).show();
|
||||||
|
//保存新密码到SharedPreferences文件中
|
||||||
|
UtilsHelper.saveUserInfo(ModifyPswActivity.this, userName, newPsw);
|
||||||
|
Intent intent = new Intent(ModifyPswActivity.this, LoginActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
//关闭设置界面
|
||||||
|
SettingActivity.instance.finish();
|
||||||
|
//关闭修改密码界面
|
||||||
|
ModifyPswActivity.this.finish();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取界面输入框控件上的字符串
|
||||||
|
*/
|
||||||
|
private void getEditString() {
|
||||||
|
originalPsw = et_original_psw.getText().toString().trim();
|
||||||
|
newPsw = et_new_psw.getText().toString().trim();
|
||||||
|
newPswAgain = et_new_psw_again.getText().toString().trim();
|
||||||
|
}
|
||||||
|
}
|
75
app/src/main/java/com/youxuegu/activity/SettingActivity.java
Normal file
75
app/src/main/java/com/youxuegu/activity/SettingActivity.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package com.youxuegu.activity;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.youxuegu.R;
|
||||||
|
import com.youxuegu.utils.UtilsHelper;
|
||||||
|
|
||||||
|
public class SettingActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
private TextView tv_main_title;
|
||||||
|
private TextView tv_back;
|
||||||
|
private RelativeLayout rl_title_bar;
|
||||||
|
private RelativeLayout rl_modify_psw, rl_security_setting, rl_exit_login;
|
||||||
|
public static SettingActivity instance = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_setting);
|
||||||
|
instance = this;
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
tv_main_title = findViewById(R.id.tv_main_title);
|
||||||
|
tv_main_title.setText("设置");
|
||||||
|
tv_back = findViewById(R.id.tv_back);
|
||||||
|
rl_title_bar = findViewById(R.id.title_bar);
|
||||||
|
rl_title_bar.setBackgroundColor(Color.parseColor("#30B4FF"));
|
||||||
|
rl_modify_psw = findViewById(R.id.rl_modify_psw);
|
||||||
|
rl_security_setting = findViewById(R.id.rl_security_setting);
|
||||||
|
rl_exit_login = findViewById(R.id.rl_exit_login);
|
||||||
|
tv_back.setOnClickListener(this);
|
||||||
|
rl_modify_psw.setOnClickListener(this);
|
||||||
|
rl_security_setting.setOnClickListener(this);
|
||||||
|
rl_exit_login.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
switch (view.getId()) {
|
||||||
|
case R.id.tv_back:
|
||||||
|
this.finish();
|
||||||
|
break;
|
||||||
|
case R.id.rl_modify_psw:
|
||||||
|
//跳转到修改密码界面
|
||||||
|
Intent intent = new Intent(SettingActivity.this, ModifyPswActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
break;
|
||||||
|
case R.id.rl_security_setting:
|
||||||
|
//跳转到设置密保界面
|
||||||
|
// Intent securityIntent = new Intent(SettingActivity.this, FindPswActivity.class);
|
||||||
|
// securityIntent.putExtra("from", "security");
|
||||||
|
// startActivity(securityIntent);
|
||||||
|
break;
|
||||||
|
case R.id.rl_exit_login:
|
||||||
|
Toast.makeText(SettingActivity.this, "退出登录成功", Toast.LENGTH_SHORT).show();
|
||||||
|
//清除登录状态和登录时的用户名
|
||||||
|
UtilsHelper.clearLoginStatus(SettingActivity.this);
|
||||||
|
Intent data = new Intent();
|
||||||
|
data.putExtra("isLogin", false);
|
||||||
|
setResult(RESULT_OK, data);
|
||||||
|
SettingActivity.this.finish();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -59,4 +59,28 @@ public class UtilsHelper {
|
|||||||
//提交修改
|
//提交修改
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean readLoginStatus(Context context) {
|
||||||
|
SharedPreferences sp = context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
|
||||||
|
boolean isLogin = sp.getBoolean("isLogin", false);
|
||||||
|
return isLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearLoginStatus(Context context) {
|
||||||
|
SharedPreferences sp = context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
|
||||||
|
//获取编辑器
|
||||||
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
|
//清除登录状态
|
||||||
|
editor.putBoolean("isLogin", false);
|
||||||
|
//清除登录时的用户名
|
||||||
|
editor.putString("loginUserName", "");
|
||||||
|
//提交修改
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
|
public static String readLoginUserName(Context context) {
|
||||||
|
SharedPreferences sp = context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
|
||||||
|
//获取登录时用户名
|
||||||
|
String userName = sp.getString("loginUserName", "");
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
118
app/src/main/java/com/youxuegu/view/MyInfoView.java
Normal file
118
app/src/main/java/com/youxuegu/view/MyInfoView.java
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
package com.youxuegu.view;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.youxuegu.R;
|
||||||
|
import com.youxuegu.activity.LoginActivity;
|
||||||
|
import com.youxuegu.activity.SettingActivity;
|
||||||
|
import com.youxuegu.utils.UtilsHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YoVinchen
|
||||||
|
*/
|
||||||
|
public class MyInfoView implements View.OnClickListener {
|
||||||
|
public ImageView iv_head_icon;
|
||||||
|
private LinearLayout ll_head;
|
||||||
|
private RelativeLayout rl_course_history, rl_setting;
|
||||||
|
private TextView tv_user_name;
|
||||||
|
private Activity mContext;
|
||||||
|
private LayoutInflater mInflater;
|
||||||
|
private View mCurrentView;
|
||||||
|
//记录登录状态
|
||||||
|
private boolean isLogin = false;
|
||||||
|
|
||||||
|
public MyInfoView(Activity context) {
|
||||||
|
mContext = context;
|
||||||
|
mInflater = LayoutInflater.from(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initView() {
|
||||||
|
mCurrentView = mInflater.inflate(R.layout.main_view_myinfo, null);
|
||||||
|
ll_head = mCurrentView.findViewById(R.id.ll_head);
|
||||||
|
iv_head_icon = mCurrentView.findViewById(R.id.iv_head_icon);
|
||||||
|
rl_course_history = mCurrentView.findViewById(R.id.rl_course_history);
|
||||||
|
rl_setting = mCurrentView.findViewById(R.id.rl_setting);
|
||||||
|
tv_user_name = mCurrentView.findViewById(R.id.tv_user_name);
|
||||||
|
mCurrentView.setVisibility(View.VISIBLE);
|
||||||
|
//设置登录时界面控件的显示信息
|
||||||
|
setLoginParams(isLogin);
|
||||||
|
ll_head.setOnClickListener(this);
|
||||||
|
rl_course_history.setOnClickListener(this);
|
||||||
|
rl_setting.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
switch (view.getId()) {
|
||||||
|
case R.id.ll_head:
|
||||||
|
if (UtilsHelper.readLoginStatus(mContext)) {
|
||||||
|
//跳转到个人资料界面
|
||||||
|
// Intent intent = new Intent(mContext, UserInfoActivity.class);
|
||||||
|
// mContext.startActivity(intent);
|
||||||
|
} else {
|
||||||
|
//跳转到登录界面
|
||||||
|
Intent intent = new Intent(mContext, LoginActivity.class);
|
||||||
|
mContext.startActivityForResult(intent, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case R.id.rl_course_history:
|
||||||
|
// if (UtilsHelper.readLoginStatus(mContext)) {
|
||||||
|
// //跳转到播放记录界面
|
||||||
|
// Intent intent = new Intent(mContext, PlayHistoryActivity.class);
|
||||||
|
// mContext.startActivity(intent);
|
||||||
|
// } else {
|
||||||
|
// Toast.makeText(mContext, "您还未登录,请先登录",
|
||||||
|
// Toast.LENGTH_SHORT).show();
|
||||||
|
// }
|
||||||
|
break;
|
||||||
|
case R.id.rl_setting:
|
||||||
|
if (UtilsHelper.readLoginStatus(mContext)) {
|
||||||
|
//跳转到设置界面
|
||||||
|
Intent intent = new Intent(mContext, SettingActivity.class);
|
||||||
|
mContext.startActivityForResult(intent, 1);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(mContext, "您还未登录,请先登录",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置"我"的界面中用户名控件的显示信息
|
||||||
|
*/
|
||||||
|
public void setLoginParams(boolean isLogin) {
|
||||||
|
if (isLogin) {
|
||||||
|
tv_user_name.setText(UtilsHelper.readLoginUserName(mContext));
|
||||||
|
} else {
|
||||||
|
tv_user_name.setText("点击登录");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getView() {
|
||||||
|
//获取用户登录状态
|
||||||
|
isLogin = UtilsHelper.readLoginStatus(mContext);
|
||||||
|
if (mCurrentView == null) {
|
||||||
|
|
||||||
|
initView();
|
||||||
|
}
|
||||||
|
return mCurrentView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showView() {
|
||||||
|
if (mCurrentView == null) {
|
||||||
|
//初始化界面控件
|
||||||
|
initView();
|
||||||
|
}
|
||||||
|
//设置"我"的界面为显示状态
|
||||||
|
mCurrentView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 81 KiB |
37
app/src/main/res/layout/activity_modify_psw.xml
Normal file
37
app/src/main/res/layout/activity_modify_psw.xml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/register_bg"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:context=".activity.ModifyPswActivity">
|
||||||
|
<include layout="@layout/main_title_bar" />
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/et_original_psw"
|
||||||
|
style="@style/etRegisterStyle"
|
||||||
|
android:layout_marginTop="35dp"
|
||||||
|
android:background="@drawable/register_user_name_bg"
|
||||||
|
android:drawableLeft="@drawable/psw_icon"
|
||||||
|
android:hint="请输入原始密码" />
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/et_new_psw"
|
||||||
|
style="@style/etRegisterStyle"
|
||||||
|
android:background="@drawable/register_psw_bg"
|
||||||
|
android:drawableLeft="@drawable/psw_icon"
|
||||||
|
android:hint="请输入新密码"
|
||||||
|
android:inputType="textPassword" />
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/et_new_psw_again"
|
||||||
|
style="@style/etRegisterStyle"
|
||||||
|
android:background="@drawable/register_psw_again_bg"
|
||||||
|
android:drawableLeft="@drawable/psw_icon"
|
||||||
|
android:drawablePadding="10dp"
|
||||||
|
android:hint="请再次输入新密码"
|
||||||
|
android:inputType="textPassword" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_save"
|
||||||
|
style="@style/btnRegisterStyle"
|
||||||
|
android:text="保存" />
|
||||||
|
</LinearLayout>
|
43
app/src/main/res/layout/activity_setting.xml
Normal file
43
app/src/main/res/layout/activity_setting.xml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".activity.SettingActivity"
|
||||||
|
android:background="@android:color/white"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<include layout="@layout/main_title_bar" />
|
||||||
|
<View
|
||||||
|
style="@style/vMyinfoStyle"
|
||||||
|
android:layout_marginTop="15dp" />
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/rl_modify_psw"
|
||||||
|
style="@style/rlMyinfoStyle">
|
||||||
|
<TextView
|
||||||
|
style="@style/tvMyinfoStyle"
|
||||||
|
android:text="修改密码" />
|
||||||
|
<ImageView style="@style/ivMyinfoRightStyle" />
|
||||||
|
</RelativeLayout>
|
||||||
|
<View style="@style/vMyinfoStyle" />
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/rl_security_setting"
|
||||||
|
style="@style/rlMyinfoStyle">
|
||||||
|
<TextView
|
||||||
|
style="@style/tvMyinfoStyle"
|
||||||
|
android:text="设置密保" />
|
||||||
|
<ImageView style="@style/ivMyinfoRightStyle" />
|
||||||
|
</RelativeLayout>
|
||||||
|
<View style="@style/vMyinfoStyle" />
|
||||||
|
<View
|
||||||
|
style="@style/vMyinfoStyle"
|
||||||
|
android:layout_marginTop="15dp" />
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/rl_exit_login"
|
||||||
|
style="@style/rlMyinfoStyle">
|
||||||
|
<TextView
|
||||||
|
style="@style/tvMyinfoStyle"
|
||||||
|
android:text="退出登录" />
|
||||||
|
</RelativeLayout>
|
||||||
|
<View style="@style/vMyinfoStyle" />
|
||||||
|
</LinearLayout>
|
@ -12,14 +12,24 @@
|
|||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:background="@drawable/go_back_selector" />
|
android:background="@drawable/go_back_selector" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_main_title"
|
android:id="@+id/tv_main_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:layout_centerInParent="true" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_save"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:textColor="@color/white"
|
android:gravity="center"
|
||||||
android:textSize="20sp" />
|
android:textSize="16sp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:text="保存"
|
||||||
|
android:visibility="gone" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Loading…
Reference in New Issue
Block a user