用户增加img属性,用来在用户界面实现头像选取和摄像,并同步到Study页面上
This commit is contained in:
parent
a7001f6d84
commit
c05b935a0c
|
@ -51,5 +51,10 @@ dependencies {
|
|||
implementation ("com.squareup.retrofit2:retrofit:2.9.0")
|
||||
implementation ("com.squareup.retrofit2:converter-gson:2.9.0")
|
||||
implementation("org.greenrobot:eventbus:3.3.1")
|
||||
implementation ("io.github.lucksiege:pictureselector:v3.11.2")
|
||||
implementation ("io.github.lucksiege:compress:v3.11.2")
|
||||
implementation ("io.github.lucksiege:ucrop:v3.11.2")
|
||||
implementation ("io.github.lucksiege:camerax:v3.11.2")
|
||||
implementation ("com.github.bumptech.glide:glide:4.15.1")
|
||||
|
||||
}
|
|
@ -1,7 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<queries package="${applicationId}">
|
||||
<intent>
|
||||
<action android:name="android.media.action.IMAGE_CAPTURE">
|
||||
|
||||
</action>
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.media.action.ACTION_VIDEO_CAPTURE">
|
||||
|
||||
</action>
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
|
|
@ -63,11 +63,11 @@ public class ChangePasswordActivity extends AppCompatActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
DBTools dbTools = new DBTools(ChangePasswordActivity.this,"test",null,1);//数据库的名字
|
||||
DBTools dbTools = new DBTools(ChangePasswordActivity.this,"tests",null,1);//数据库的名字
|
||||
SQLiteDatabase sqLiteDatabase = dbTools.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put("password",userPassword);
|
||||
sqLiteDatabase.update("user", contentValues,
|
||||
sqLiteDatabase.update("users", contentValues,
|
||||
"phone=?", new String[]{phoneNumber});
|
||||
|
||||
Intent intent = new Intent(ChangePasswordActivity.this, LoginMainActivity.class);
|
||||
|
|
|
@ -15,7 +15,7 @@ public class DBTools extends SQLiteOpenHelper {
|
|||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
//创建数据库和表
|
||||
db.execSQL("create table user(id integer primary key autoincrement,phone varchar(20),password varchar(20) )");
|
||||
db.execSQL("create table users(id integer primary key autoincrement,phone varchar(20),password varchar(20),img varchar(50))");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -71,12 +71,13 @@ public class EnrollActivity extends AppCompatActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
DBTools dbTools = new DBTools(EnrollActivity.this,"test",null,1);//数据库的名字
|
||||
DBTools dbTools = new DBTools(EnrollActivity.this,"tests",null,1);//数据库的名字
|
||||
SQLiteDatabase sqLiteDatabase = dbTools.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put("phone",phoneNumber);
|
||||
contentValues.put("password",userPassword);
|
||||
sqLiteDatabase.insert("user",null,contentValues);
|
||||
contentValues.put("img", "");
|
||||
sqLiteDatabase.insert("users",null,contentValues);
|
||||
|
||||
Intent intent = new Intent(EnrollActivity.this, LoginMainActivity.class);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
package com.example.liyueling_final;
|
||||
|
||||
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.luck.picture.lib.engine.ImageEngine;
|
||||
import com.luck.picture.lib.utils.ActivityCompatHelper;
|
||||
|
||||
|
||||
public class GlideEngine implements ImageEngine {
|
||||
|
||||
/**
|
||||
* 加载图片
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 资源url
|
||||
* @param imageView 图片承载控件
|
||||
*/
|
||||
@Override
|
||||
public void loadImage(Context context, String url, ImageView imageView) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadImage(Context context, ImageView imageView, String url, int maxWidth, int maxHeight) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.override(maxWidth, maxHeight)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载相册目录封面
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 图片路径
|
||||
* @param imageView 承载图片ImageView
|
||||
*/
|
||||
@Override
|
||||
public void loadAlbumCover(Context context, String url, ImageView imageView) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.override(180, 180)
|
||||
.sizeMultiplier(0.5f)
|
||||
.transform(new CenterCrop(), new RoundedCorners(8))
|
||||
.placeholder(R.drawable.ic_launcher_background)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载图片列表图片
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param url 图片路径
|
||||
* @param imageView 承载图片ImageView
|
||||
*/
|
||||
@Override
|
||||
public void loadGridImage(Context context, String url, ImageView imageView) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context)
|
||||
.load(url)
|
||||
.override(200, 200)
|
||||
.centerCrop()
|
||||
.placeholder(R.drawable.ic_launcher_background)
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseRequests(Context context) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).pauseRequests();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeRequests(Context context) {
|
||||
if (!ActivityCompatHelper.assertValidRequest(context)) {
|
||||
return;
|
||||
}
|
||||
Glide.with(context).resumeRequests();
|
||||
}
|
||||
|
||||
private GlideEngine() {
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
static final GlideEngine instance = new GlideEngine();
|
||||
}
|
||||
|
||||
public static GlideEngine createGlideEngine() {
|
||||
return InstanceHolder.instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ public class LoginMainActivity extends AppCompatActivity {
|
|||
animator2.setDuration(1000);
|
||||
animator2.start();
|
||||
|
||||
DBTools dbTools = new DBTools(LoginMainActivity.this, "test", null, 1);//数据库的名字
|
||||
DBTools dbTools = new DBTools(LoginMainActivity.this, "tests", null, 1);//数据库的名字
|
||||
SQLiteDatabase sqLiteDatabase = dbTools.getWritableDatabase();
|
||||
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class LoginMainActivity extends AppCompatActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
Cursor cursor = sqLiteDatabase.query("user", new String[]{"id", "phone", "password"},
|
||||
Cursor cursor = sqLiteDatabase.query("users", new String[]{"id", "phone", "password","img"},
|
||||
"phone=?", new String[]{phoneNumber}, null, null, null);
|
||||
while (cursor.moveToNext()) {
|
||||
if (cursor != null && cursor.getString(cursor.getColumnIndex("password")).equals(userPassword)) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
.add(R.id.constraintLayoutmainmajor,studyFragment)
|
||||
.commit();
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.constraintLayoutmainmajor,userFragment)
|
||||
.add(R.id.constraintLayoutmainmajor,userFragment, "user_fragment_tag")
|
||||
.commit();
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.constraintLayoutmainmajor,typeFragment)
|
||||
|
|
|
@ -1,17 +1,26 @@
|
|||
package com.example.liyueling_final;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class StudyFragment extends Fragment {
|
||||
TextView textView;
|
||||
ImageView imageView;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
@ -21,6 +30,28 @@ public class StudyFragment extends Fragment {
|
|||
String username = getArguments().getString("username");
|
||||
textView = view.findViewById(R.id.username);
|
||||
textView.setText(username);
|
||||
|
||||
DBTools dbTools = new DBTools(getActivity(), "tests", null, 1);//数据库的名字
|
||||
SQLiteDatabase sqLiteDatabase = dbTools.getWritableDatabase();
|
||||
Cursor cursor = sqLiteDatabase.query("users", new String[]{"id", "phone", "password","img"},
|
||||
"phone=?", new String[]{username}, null, null, null);
|
||||
while (cursor.moveToNext()) {
|
||||
int imgIndex = cursor.getColumnIndex("img");
|
||||
String img = cursor.getString(imgIndex);
|
||||
if (img != null && !img.isEmpty()) {
|
||||
imageView = view.findViewById(R.id.pphoto);
|
||||
Glide.with(getActivity())
|
||||
.load(img)
|
||||
.into(imageView);
|
||||
UserFragment userFragment = (UserFragment) getActivity().getSupportFragmentManager().findFragmentByTag("user_fragment_tag");
|
||||
if (userFragment != null) {
|
||||
userFragment.updateUI(username,img);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
constraintLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
|
@ -1,25 +1,98 @@
|
|||
package com.example.liyueling_final;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.luck.picture.lib.basic.PictureSelector;
|
||||
import com.luck.picture.lib.config.SelectMimeType;
|
||||
import com.luck.picture.lib.entity.LocalMedia;
|
||||
import com.luck.picture.lib.interfaces.OnResultCallbackListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class UserFragment extends Fragment {
|
||||
TextView textView;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_user, container, false);
|
||||
|
||||
ImageView imageView = view.findViewById(R.id.photo);
|
||||
|
||||
String username = getArguments().getString("username");
|
||||
textView = view.findViewById(R.id.username);
|
||||
textView.setText(username);
|
||||
|
||||
DBTools dbTools = new DBTools(getActivity(), "tests", null, 1);//数据库的名字
|
||||
SQLiteDatabase sqLiteDatabase = dbTools.getWritableDatabase();
|
||||
Cursor cursor = sqLiteDatabase.query("users", new String[]{"id", "phone", "password","img"},
|
||||
"phone=?", new String[]{username}, null, null, null);
|
||||
while (cursor.moveToNext()) {
|
||||
int imgIndex = cursor.getColumnIndex("img");
|
||||
String img = cursor.getString(imgIndex);
|
||||
if (img != null && !img.isEmpty()) {
|
||||
Glide.with(getActivity())
|
||||
.load(img)
|
||||
.into(imageView);
|
||||
}
|
||||
}
|
||||
view.findViewById(R.id.photo).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
PictureSelector.create(getActivity())
|
||||
.openGallery(SelectMimeType.ofImage())
|
||||
.setImageEngine(GlideEngine.createGlideEngine())
|
||||
.forResult(new OnResultCallbackListener<LocalMedia>() {
|
||||
@Override
|
||||
public void onResult(ArrayList<LocalMedia> result) {
|
||||
Log.i("test", result.get(0).getRealPath());
|
||||
Glide.with(getActivity())
|
||||
.load(Uri.fromFile(new File(result.get(0).getRealPath())))
|
||||
.into(imageView);
|
||||
|
||||
DBTools dbTools = new DBTools(getActivity(),"tests",null,1);//数据库的名字
|
||||
SQLiteDatabase sqLiteDatabase = dbTools.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put("img",Uri.fromFile(new File(result.get(0).getRealPath())).toString());
|
||||
sqLiteDatabase.update("users", contentValues,
|
||||
"phone=?", new String[]{username});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void updateUI(String username,String img) {
|
||||
DBTools dbTools = new DBTools(getActivity(),"tests",null,1);//数据库的名字
|
||||
SQLiteDatabase sqLiteDatabase = dbTools.getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put("img",img);
|
||||
sqLiteDatabase.update("users", contentValues,
|
||||
"phone=?", new String[]{username});
|
||||
}
|
||||
}
|
|
@ -172,7 +172,7 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:text="2017年加入,我要好好学习天天向上~"
|
||||
android:textColor="#7C7B7B"
|
||||
app:layout_constraintStart_toEndOf="@+id/imageView13"
|
||||
app:layout_constraintStart_toEndOf="@+id/pphoto"
|
||||
app:layout_constraintTop_toBottomOf="@+id/username" />
|
||||
|
||||
<TextView
|
||||
|
@ -184,11 +184,11 @@
|
|||
android:text="mooc1500271962727"
|
||||
android:textSize="17dp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toEndOf="@+id/imageView13"
|
||||
app:layout_constraintTop_toTopOf="@+id/imageView13" />
|
||||
app:layout_constraintStart_toEndOf="@+id/pphoto"
|
||||
app:layout_constraintTop_toTopOf="@+id/pphoto" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView13"
|
||||
android:id="@+id/pphoto"
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginStart="24dp"
|
||||
|
|
|
@ -194,7 +194,7 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:text="正使用“微信账号”登陆"
|
||||
android:textColor="#7C7B7B"
|
||||
app:layout_constraintStart_toEndOf="@+id/imageView13"
|
||||
app:layout_constraintStart_toEndOf="@+id/pphoto"
|
||||
app:layout_constraintTop_toBottomOf="@+id/username" />
|
||||
|
||||
<TextView
|
||||
|
@ -206,11 +206,11 @@
|
|||
android:text="mooc1500271962727"
|
||||
android:textSize="17dp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toEndOf="@+id/imageView13"
|
||||
app:layout_constraintTop_toTopOf="@+id/imageView13" />
|
||||
app:layout_constraintStart_toEndOf="@+id/pphoto"
|
||||
app:layout_constraintTop_toTopOf="@+id/pphoto" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView13"
|
||||
android:id="@+id/pphoto"
|
||||
android:layout_width="90dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginStart="32dp"
|
||||
|
@ -240,7 +240,7 @@
|
|||
app:layout_constraintTop_toTopOf="@+id/textView50" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView56"
|
||||
android:id="@+id/photo"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginStart="37dp"
|
||||
|
|
Loading…
Reference in New Issue