master
lingyun 2 years ago
parent 759ef60a4e
commit 9a447733b0

@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

@ -0,0 +1 @@
Subproject commit 759ef60a4e1e9b83ba8e8486677ea7c01a1928cb

@ -0,0 +1 @@
/build

@ -0,0 +1,42 @@
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 33
defaultConfig {
applicationId "com.example.test"
minSdkVersion 16
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"app-debug.apk","properties":{}}]

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

@ -0,0 +1,12 @@
package com.example.storage;
import android.app.Application;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest {
public ApplicationTest() {
super(Application.class);
}
}

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.storage">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAG" />
<uses-permission
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
tools:ignore="ProtectedPermissions" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:icon="@drawable/nt1"
android:label="盲盒咖啡店"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".UserActivity" ></activity>
<activity android:name=".RegisterActivity" android:theme="@style/Theme.Design.NoActionBar" />
<activity android:exported="true" android:name=".LoginActivity" android:theme="@style/Theme.Design.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShoppingChannelActivity"
tools:ignore="Instantiatable" android:theme="@style/Theme.Design.NoActionBar" />
<activity
android:name=".ShoppingCartActivity"
tools:ignore="Instantiatable" android:theme="@style/Theme.Design.NoActionBar" />
<activity
android:name=".ShoppingDetailActivity"
tools:ignore="Instantiatable" android:theme="@style/Theme.Design.NoActionBar" />
</application>
</manifest>

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.storage">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAG" />
<uses-permission
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
tools:ignore="ProtectedPermissions" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".UserActivity"></activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShoppingChannelActivity"
tools:ignore="Instantiatable" />
<activity
android:name=".ShoppingCartActivity"
tools:ignore="Instantiatable" />
<activity
android:name=".ShoppingDetailActivity"
tools:ignore="Instantiatable" />
</application>
</manifest>

@ -0,0 +1,148 @@
package com.example.storage;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import java.util.Random;
/**
*
*/
public class Code {
/**
*
* 0 o O
* 1 i I l L
* 6 b
* 9 q
* c C G
* t 线
*/
private static final char[] CHARS = {
'2', '3', '4', '5', '7', '8',
'a', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm',
'n', 'p', 'r', 's', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'D', 'E', 'F', 'H', 'J', 'K', 'M',
'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
};
private static Code bmpCode;
public static Code getInstance() {
if(bmpCode == null)
bmpCode = new Code();
return bmpCode;
}
//default settings
//验证码默认随机数的个数
private static final int DEFAULT_CODE_LENGTH = 4;
//默认字体大小
private static final int DEFAULT_FONT_SIZE = 25;
//默认线条的条数
private static final int DEFAULT_LINE_NUMBER = 5;
//padding值
private static final int BASE_PADDING_LEFT = 10, RANGE_PADDING_LEFT = 15, BASE_PADDING_TOP = 15, RANGE_PADDING_TOP = 20;
//验证码的默认宽高
private static final int DEFAULT_WIDTH = 100, DEFAULT_HEIGHT = 40;
//settings decided by the layout xml
//canvas width and height
private int width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT;
//random word space and pading_top
private int base_padding_left = BASE_PADDING_LEFT, range_padding_left = RANGE_PADDING_LEFT,
base_padding_top = BASE_PADDING_TOP, range_padding_top = RANGE_PADDING_TOP;
//number of chars, lines; font size
private int codeLength = DEFAULT_CODE_LENGTH, line_number = DEFAULT_LINE_NUMBER, font_size = DEFAULT_FONT_SIZE;
//variables
private String code;
private int padding_left, padding_top;
private Random random = new Random();
//验证码图片
public Bitmap createBitmap() {
padding_left = 0;
Bitmap bp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bp);
code = createCode();
c.drawColor(Color.WHITE);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setTextSize(font_size);
//画验证码
for (int i = 0; i < code.length(); i++) {
randomTextStyle(paint);
randomPadding();
c.drawText(code.charAt(i) + "", padding_left, padding_top, paint);
}
//画线条
for (int i = 0; i < line_number; i++) {
drawLine(c, paint);
}
// c.save( Canvas.ALL_SAVE_FLAG );//保存
c.save();//保存
c.restore();//
return bp;
}
public String getCode() {
return code;
}
//生成验证码
private String createCode() {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < codeLength; i++) {
buffer.append(CHARS[random.nextInt(CHARS.length)]);
}
return buffer.toString();
}
//画干扰线
private void drawLine(Canvas canvas, Paint paint) {
int color = randomColor();
int startX = random.nextInt(width);
int startY = random.nextInt(height);
int stopX = random.nextInt(width);
int stopY = random.nextInt(height);
paint.setStrokeWidth(1);
paint.setColor(color);
canvas.drawLine(startX, startY, stopX, stopY, paint);
}
//生成随机颜色
private int randomColor() {
return randomColor(1);
}
private int randomColor(int rate) {
int red = random.nextInt(256) / rate;
int green = random.nextInt(256) / rate;
int blue = random.nextInt(256) / rate;
return Color.rgb(red, green, blue);
}
//随机生成文字样式,颜色,粗细,倾斜度
private void randomTextStyle(Paint paint) {
int color = randomColor();
paint.setColor(color);
paint.setFakeBoldText(random.nextBoolean()); //true为粗体false为非粗体
float skewX = random.nextInt(11) / 10;
skewX = random.nextBoolean() ? skewX : -skewX;
paint.setTextSkewX(skewX); //float类型参数负数表示右斜整数左斜
//paint.setUnderlineText(true); //true为下划线false为非下划线
//paint.setStrikeThruText(true); //true为删除线false为非删除线
}
//随机生成padding值
private void randomPadding() {
padding_left += base_padding_left + random.nextInt(range_padding_left);
padding_top = base_padding_top + random.nextInt(range_padding_top);
}
}

@ -0,0 +1,85 @@
package com.example.storage;
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
/**
*
*/
public class DBOpenHelper extends SQLiteOpenHelper {
/**
* AndroidSDKdb
*/
private SQLiteDatabase db;
/**
* context
* 1
* super(context,"db_test",null,1);
*
*
* db = getReadableDatabase();
*/
public DBOpenHelper(Context context){
super(context,"db_test",null,1);
db = getReadableDatabase();
}
/**
* class DBOpenHelper extends SQLiteOpenHelper
* abstract SQLiteOpenHelper abstract
* DBOpenHelper abstract
*
*
* onCreate()onUpgrade()
* @param db
*/
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE IF NOT EXISTS user(" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name TEXT," +
"password TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS user");
onCreate(db);
}
/**
*
* add()
* delete()
* update()
* getAllData()
*/
public void add(String name,String password){
db.execSQL("INSERT INTO user (name,password) VALUES(?,?)",new Object[]{name,password});
}
public void delete(String name,String password){
db.execSQL("DELETE FROM user WHERE name = AND password ="+name+password);
}
public void updata(String password){
db.execSQL("UPDATE user SET password = ?",new Object[]{password});
}
/**
* @return
*/
public ArrayList<User> getAllData(){
ArrayList<User> list = new ArrayList<User>();
Cursor cursor = db.query("user",null,null,null,null,null,"name DESC");
while(cursor.moveToNext()){
@SuppressLint("Range") String name = cursor.getString(cursor.getColumnIndex("name"));
@SuppressLint("Range") String password = cursor.getString(cursor.getColumnIndex("password"));
list.add(new User(name,password));
}
return list;
}
}

@ -0,0 +1,117 @@
package com.example.storage;
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.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
/**
* DBOpenHelper
* DBOpenHelper(extends SQLiteOpenHelper)
*
*
*/
private DBOpenHelper mDBOpenHelper;
private TextView mTvLoginactivityRegister;
private RelativeLayout mRlLoginactivityTop;
private EditText mEtLoginactivityUsername;
private EditText mEtLoginactivityPassword;
private LinearLayout mLlLoginactivityTwo;
private Button mBtLoginactivityLogin;
/**
* Activity onCreate()
*
* super.onCreate(savedInstanceState);
*
* setContentView(R.layout.activity_login);
* View layout Activity
* initView()
* DBOpenHelper
* mDBOpenHelper = new DBOpenHelper(this);
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
initView();
mDBOpenHelper = new DBOpenHelper(this);
}
/**
* onCreae()layout西
*
* Viewlayout Java
*/
private void initView() {
// 初始化控件
mBtLoginactivityLogin = findViewById(R.id.bt_loginactivity_login);
mTvLoginactivityRegister = findViewById(R.id.tv_loginactivity_register);
mRlLoginactivityTop = findViewById(R.id.rl_loginactivity_top);
mEtLoginactivityUsername = findViewById(R.id.et_loginactivity_username);
mEtLoginactivityPassword = findViewById(R.id.et_loginactivity_password);
mLlLoginactivityTwo = findViewById(R.id.ll_loginactivity_two);
// 设置点击事件监听器
mBtLoginactivityLogin.setOnClickListener(this);
mTvLoginactivityRegister.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
// 跳转到注册界面
case R.id.tv_loginactivity_register:
startActivity(new Intent(this, RegisterActivity.class));
finish();
break;
/**
*
*
*/
case R.id.bt_loginactivity_login:
String name = mEtLoginactivityUsername.getText().toString().trim();
String password = mEtLoginactivityPassword.getText().toString().trim();
if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(password)) {
ArrayList<User> data = mDBOpenHelper.getAllData();
boolean match = false;
for (int i = 0; i < data.size(); i++) {
User user = data.get(i);
if (name.equals(user.getName()) && password.equals(user.getPassword())) {
match = true;
break;
} else {
match = false;
}
}
if (match) {
Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, ShoppingCartActivity.class);
startActivity(intent);
finish();//销毁此Activity
} else {
Toast.makeText(this, "用户名或密码不正确,请重新输入", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "请输入你的用户名或密码", Toast.LENGTH_SHORT).show();
}
break;
}
}
}

@ -0,0 +1,40 @@
package com.example.storage;
import java.util.HashMap;
import android.app.Application;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.util.Log;
public class MainApplication extends Application {
private final static String TAG = "MainApplication";
// 声明一个当前应用的静态实例
private static MainApplication mApp;
// 声明一个公共的图标映射对象,可当作全局变量使用
public HashMap<Long, Bitmap> mIconMap = new HashMap<Long, Bitmap>();
// 利用单例模式获取当前应用的唯一实例
public static MainApplication getInstance() {
return mApp;
}
@Override
public void onCreate() {
super.onCreate();
// 在打开应用时对静态的应用实例赋值
mApp = this;
Log.d(TAG, "onCreate");
}
@Override
public void onTerminate() {
Log.d(TAG, "onTerminate");
super.onTerminate();
}
}

@ -0,0 +1,102 @@
package com.example.storage;
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.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
private String realCode;
private DBOpenHelper mDBOpenHelper;
private Button mBtRegisteractivityRegister;
private RelativeLayout mRlRegisteractivityTop;
private ImageView mIvRegisteractivityBack;
private LinearLayout mLlRegisteractivityBody;
private EditText mEtRegisteractivityUsername;
private EditText mEtRegisteractivityPassword1;
private EditText mEtRegisteractivityPassword2;
private EditText mEtRegisteractivityPhonecodes;
private ImageView mIvRegisteractivityShowcode;
private RelativeLayout mRlRegisteractivityBottom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
initView();
mDBOpenHelper = new DBOpenHelper(this);
//将验证码用图片的形式显示出来
mIvRegisteractivityShowcode.setImageBitmap(Code.getInstance().createBitmap());
realCode = Code.getInstance().getCode().toLowerCase();
}
private void initView(){
mBtRegisteractivityRegister = findViewById(R.id.bt_registeractivity_register);
mRlRegisteractivityTop = findViewById(R.id.rl_registeractivity_top);
mIvRegisteractivityBack = findViewById(R.id.iv_registeractivity_back);
mLlRegisteractivityBody = findViewById(R.id.ll_registeractivity_body);
mEtRegisteractivityUsername = findViewById(R.id.et_registeractivity_username);
mEtRegisteractivityPassword1 = findViewById(R.id.et_registeractivity_password1);
mEtRegisteractivityPassword2 = findViewById(R.id.et_registeractivity_password2);
mEtRegisteractivityPhonecodes = findViewById(R.id.et_registeractivity_phoneCodes);
mIvRegisteractivityShowcode = findViewById(R.id.iv_registeractivity_showCode);
mRlRegisteractivityBottom = findViewById(R.id.rl_registeractivity_bottom);
/**
*
* top
*/
mIvRegisteractivityBack.setOnClickListener(this);
mIvRegisteractivityShowcode.setOnClickListener(this);
mBtRegisteractivityRegister.setOnClickListener(this);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.iv_registeractivity_back: //返回登录页面
Intent intent1 = new Intent(this, LoginActivity.class);
startActivity(intent1);
finish();
break;
case R.id.iv_registeractivity_showCode: //改变随机验证码的生成
mIvRegisteractivityShowcode.setImageBitmap(Code.getInstance().createBitmap());
realCode = Code.getInstance().getCode().toLowerCase();
break;
case R.id.bt_registeractivity_register: //注册按钮
//获取用户输入的用户名、密码、验证码
String username = mEtRegisteractivityUsername.getText().toString().trim();
String password = mEtRegisteractivityPassword2.getText().toString().trim();
String phoneCode = mEtRegisteractivityPhonecodes.getText().toString().toLowerCase();
//注册验证
if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password) && !TextUtils.isEmpty(phoneCode) ) {
if (phoneCode.equals(realCode)) {
//将用户名和密码加入到数据库中
mDBOpenHelper.add(username, password);
Intent intent2 = new Intent(this, LoginActivity.class);
startActivity(intent2);
finish();
Toast.makeText(this, "验证通过,注册成功", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "验证码错误,注册失败", Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(this, "未完善信息,注册失败", Toast.LENGTH_SHORT).show();
}
break;
}
}
}

@ -0,0 +1,382 @@
package com.example.storage;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.example.storage.bean.CartInfo;
import com.example.storage.bean.GoodsInfo;
import com.example.storage.database.CartDBHelper;
import com.example.storage.database.GoodsDBHelper;
import com.example.storage.util.FileUtil;
import com.example.storage.util.SharedUtil;
import java.util.ArrayList;
import java.util.HashMap;
@SuppressLint("SetTextI18n")
public class ShoppingCartActivity extends Activity implements OnClickListener {
private final static String TAG = "ShoppingCartActivity";
private ImageView iv_menu;
private TextView tv_count;
private TextView tv_total_price;
private LinearLayout ll_content;
private LinearLayout ll_cart;
private LinearLayout ll_empty;
private int mCount; // 购物车中的商品数量
private GoodsDBHelper mGoodsHelper; // 声明一个商品数据库的帮助器对象
private CartDBHelper mCartHelper; // 声明一个购物车数据库的帮助器对象
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_shopping_cart);
iv_menu = findViewById(R.id.iv_menu);
TextView tv_title = findViewById(R.id.tv_title);
tv_count = findViewById(R.id.tv_count);
tv_total_price = findViewById(R.id.tv_total_price);
ll_content = findViewById(R.id.ll_content);
ll_cart = findViewById(R.id.ll_cart);
ll_empty = findViewById(R.id.ll_empty);
iv_menu.setOnClickListener(this);
findViewById(R.id.btn_shopping_channel).setOnClickListener(this);
findViewById(R.id.btn_settle).setOnClickListener(this);
findViewById(R.id.btn_shopping_grzx).setOnClickListener(this);
iv_menu.setVisibility(View.VISIBLE);
tv_title.setText("盲盒咖啡店");
}
// 显示购物车图标中的商品数量
private void showCount(int count) {
mCount = count;
tv_count.setText("" + mCount);
if (mCount == 0) {
ll_content.setVisibility(View.GONE);
ll_cart.removeAllViews();
ll_empty.setVisibility(View.VISIBLE);
} else {
ll_content.setVisibility(View.VISIBLE);
ll_empty.setVisibility(View.GONE);
}
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.iv_menu) { // 点击了菜单图标
openOptionsMenu();
} else if (v.getId() == R.id.btn_shopping_channel) { // 点击了“商场”按钮
// 跳转到商场页面
Intent intent = new Intent(this, ShoppingChannelActivity.class);
startActivity(intent);
} else if (v.getId() == R.id.btn_settle) { // 点击了“结算”按钮
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("结算商品");
builder.setMessage("支付成功!");
builder.setPositiveButton("好的", null);
builder.create().show();
}
else if (v.getId() == R.id.btn_shopping_grzx) {
// 跳转到个人中心页面
Intent intent = new Intent(this, UserActivity.class);
startActivity(intent);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// 从menu_cart.xml中构建菜单界面布局
getMenuInflater().inflate(R.menu.menu_cart, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.menu_shopping) { // 点击了菜单项“去商场购物”
// 跳转到商场页面
Intent intent = new Intent(this, ShoppingChannelActivity.class);
startActivity(intent);
} else if (id == R.id.menu_clear) { // 点击了菜单项“清空购物车”
// 清空购物车数据库
mCartHelper.deleteAll();
ll_cart.removeAllViews();
// 把最新的商品数量写入共享参数
SharedUtil.getIntance(this).writeShared("count", "0");
// 显示最新的商品数量
showCount(0);
mCartGoods.clear();
mGoodsMap.clear();
Toast.makeText(this, "购物车已清空", Toast.LENGTH_SHORT).show();
} else if (id == R.id.menu_return) { // 点击了菜单项“返回”
finish();
}
return true;
}
// 声明一个根据视图编号查找商品信息的映射
private HashMap<Integer, CartInfo> mCartGoods = new HashMap<Integer, CartInfo>();
// 声明一个触发上下文菜单的视图对象
private View mContextView;
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
// 保存该商品行的视图,以便删除商品时一块从列表移除该行
mContextView = v;
// 从menu_goods.xml中构建菜单界面布局
getMenuInflater().inflate(R.menu.menu_goods, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
CartInfo info = mCartGoods.get(mContextView.getId());
int id = item.getItemId();
if (id == R.id.menu_detail) { // 点击了菜单项“查看商品详情”
// 跳转到查看商品详情页面
goDetail(info.goods_id);
} else if (id == R.id.menu_delete) { // 点击了菜单项“从购物车删除”
long goods_id = info.goods_id;
// 从购物车删除商品的数据库操作
mCartHelper.delete("goods_id=" + goods_id);
// 从购物车列表中删除该商品行
ll_cart.removeView(mContextView);
// 更新购物车中的商品数量
int left_count = mCount - info.count;
for (int i = 0; i < mCartArray.size(); i++) {
if (goods_id == mCartArray.get(i).goods_id) {
left_count = mCount - mCartArray.get(i).count;
mCartArray.remove(i);
break;
}
}
// 把最新的商品数量写入共享参数
SharedUtil.getIntance(this).writeShared("count", "" + left_count);
// 显示最新的商品数量
showCount(left_count);
Toast.makeText(this, "已从购物车删除" + mGoodsMap.get(goods_id).name, Toast.LENGTH_SHORT).show();
mGoodsMap.remove(goods_id);
refreshTotalPrice();
}
return true;
}
// 跳转到商品详情页面
private void goDetail(long rowid) {
Intent intent = new Intent(this, ShoppingDetailActivity.class);
intent.putExtra("goods_id", rowid);
startActivity(intent);
}
@Override
protected void onResume() {
super.onResume();
// 获取共享参数保存的购物车中的商品数量
mCount = Integer.parseInt(SharedUtil.getIntance(this).readShared("count", "0"));
showCount(mCount);
// 获取商品数据库的帮助器对象
mGoodsHelper = GoodsDBHelper.getInstance(this, 1);
// 打开商品数据库的写连接
mGoodsHelper.openWriteLink();
// 获取购物车数据库的帮助器对象
mCartHelper = CartDBHelper.getInstance(this, 1);
// 打开购物车数据库的写连接
mCartHelper.openWriteLink();
// 模拟从网络下载商品图片
downloadGoods();
// 展示购物车中的商品列表
showCart();
}
@Override
protected void onPause() {
super.onPause();
// 关闭商品数据库的数据库连接
mGoodsHelper.closeLink();
// 关闭购物车数据库的数据库连接
mCartHelper.closeLink();
}
// 声明一个起始的视图编号
private int mBeginViewId = 0x7F24FFF0;
// 声明一个购物车中的商品信息队列
private ArrayList<CartInfo> mCartArray = new ArrayList<CartInfo>();
// 声明一个根据商品编号查找商品信息的映射
private HashMap<Long, GoodsInfo> mGoodsMap = new HashMap<Long, GoodsInfo>();
// 展示购物车中的商品列表
private void showCart() {
// 查询购物车数据库中所有的商品记录
mCartArray = mCartHelper.query("1=1");
Log.d(TAG, "mCartArray.size()=" + mCartArray.size());
if (mCartArray == null || mCartArray.size() <= 0) {
return;
}
// 移除线性视图ll_cart下面的所有子视图
ll_cart.removeAllViews();
// 创建一个标题行的线性视图ll_row
LinearLayout ll_row = newLinearLayout(LinearLayout.HORIZONTAL, LayoutParams.WRAP_CONTENT);
ll_row.addView(newTextView(0, 2, Gravity.CENTER, "图片", Color.BLACK, 15));
ll_row.addView(newTextView(0, 3, Gravity.CENTER, "名称", Color.BLACK, 15));
ll_row.addView(newTextView(0, 1, Gravity.CENTER, "数量", Color.BLACK, 15));
ll_row.addView(newTextView(0, 1, Gravity.CENTER, "单价", Color.BLACK, 15));
ll_row.addView(newTextView(0, 1, Gravity.CENTER, "总价", Color.BLACK, 15));
// 把标题行添加到购物车列表
ll_cart.addView(ll_row);
for (int i = 0; i < mCartArray.size(); i++) {
final CartInfo info = mCartArray.get(i);
// 根据商品编号查询商品数据库中的商品记录
GoodsInfo goods = mGoodsHelper.queryById(info.goods_id);
Log.d(TAG, "name=" + goods.name + ",price=" + goods.price + ",desc=" + goods.desc);
mGoodsMap.put(info.goods_id, goods);
// 创建该商品行的水平线性视图,从左到右依次为商品小图、商品名称与描述、商品数量、商品单价、商品总价。
ll_row = newLinearLayout(LinearLayout.HORIZONTAL, LayoutParams.WRAP_CONTENT);
// 设置该线性视图的编号
ll_row.setId(mBeginViewId + i);
// 添加商品小图
ImageView iv_thumb = new ImageView(this);
LinearLayout.LayoutParams iv_params = new LinearLayout.LayoutParams(
0, LayoutParams.WRAP_CONTENT, 2);
iv_thumb.setLayoutParams(iv_params);
iv_thumb.setScaleType(ScaleType.FIT_CENTER);
iv_thumb.setImageBitmap(MainApplication.getInstance().mIconMap.get(info.goods_id));
ll_row.addView(iv_thumb);
// 添加商品名称与描述
LinearLayout ll_name = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
0, LayoutParams.MATCH_PARENT, 3);
ll_name.setLayoutParams(params);
ll_name.setOrientation(LinearLayout.VERTICAL);
ll_name.addView(newTextView(-3, 1, Gravity.LEFT, goods.name, Color.BLACK, 17));
ll_name.addView(newTextView(-3, 1, Gravity.LEFT, goods.desc, Color.GRAY, 12));
ll_row.addView(ll_name);
// 添加商品数量、单价和总价
ll_row.addView(newTextView(1, 1, Gravity.CENTER, "" + info.count, Color.BLACK, 17));
ll_row.addView(newTextView(1, 1, Gravity.RIGHT, "" + (int) goods.price, Color.BLACK, 15));
ll_row.addView(newTextView(1, 1, Gravity.RIGHT, "" + (int) (info.count * goods.price), Color.RED, 17));
// 给商品行添加点击事件
ll_row.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
goDetail(info.goods_id);
}
});
// 给商品行注册上下文菜单,为防止重复注册,这里先注销再注册
unregisterForContextMenu(ll_row);
registerForContextMenu(ll_row);
mCartGoods.put(ll_row.getId(), info);
// 往购物车列表添加该商品行
ll_cart.addView(ll_row);
}
// 重新计算购物车中的商品总金额
refreshTotalPrice();
}
// 重新计算购物车中的商品总金额
private void refreshTotalPrice() {
int total_price = 0;
for (CartInfo info : mCartArray) {
GoodsInfo goods = mGoodsMap.get(info.goods_id);
total_price += goods.price * info.count;
}
tv_total_price.setText("" + total_price);
}
// 创建一个线性视图的框架
private LinearLayout newLinearLayout(int orientation, int height) {
LinearLayout ll_new = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, height);
ll_new.setLayoutParams(params);
ll_new.setOrientation(orientation);
ll_new.setBackgroundColor(Color.WHITE);
return ll_new;
}
// 创建一个文本视图的模板
private TextView newTextView(int height, float weight, int gravity, String text, int textColor, int textSize) {
TextView tv_new = new TextView(this);
if (height == -3) { // 垂直排列
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, weight);
tv_new.setLayoutParams(params);
} else { // 水平排列
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
0, (height == 0) ? LayoutParams.WRAP_CONTENT : LayoutParams.MATCH_PARENT, weight);
tv_new.setLayoutParams(params);
}
tv_new.setText(text);
tv_new.setTextColor(textColor);
tv_new.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
tv_new.setGravity(Gravity.CENTER | gravity);
return tv_new;
}
private String mFirst = "true"; // 是否首次打开
// 模拟网络数据,初始化数据库中的商品信息
private void downloadGoods() {
// 获取共享参数保存的是否首次打开参数
mFirst = SharedUtil.getIntance(this).readShared("first", "true");
// 获取当前App的私有存储路径
String path = MainApplication.getInstance().getExternalFilesDir(
Environment.DIRECTORY_DOWNLOADS).toString() + "/";
if (mFirst.equals("true")) { // 如果是首次打开
ArrayList<GoodsInfo> goodsList = GoodsInfo.getDefaultList();
for (int i = 0; i < goodsList.size(); i++) {
GoodsInfo info = goodsList.get(i);
// 往商品数据库插入一条该商品的记录
long rowid = mGoodsHelper.insert(info);
info.rowid = rowid;
// 往全局内存写入商品小图
Bitmap thumb = BitmapFactory.decodeResource(getResources(), info.thumb);
MainApplication.getInstance().mIconMap.put(rowid, thumb);
String thumb_path = path + rowid + "_s.jpg";
FileUtil.saveImage(thumb_path, thumb);
info.thumb_path = thumb_path; // 往SD卡保存商品大图
Bitmap pic = BitmapFactory.decodeResource(getResources(), info.pic);
String pic_path = path + rowid + ".jpg";
FileUtil.saveImage(pic_path, pic);
pic.recycle();
info.pic_path = pic_path;
// 更新商品数据库中该商品记录的图片路径
mGoodsHelper.update(info);
}
} else { // 不是首次打开
// 查询商品数据库中所有商品记录
ArrayList<GoodsInfo> goodsArray = mGoodsHelper.query("1=1");
for (int i = 0; i < goodsArray.size(); i++) {
GoodsInfo info = goodsArray.get(i);
// 从指定路径读取图片文件的位图数据
Bitmap thumb = BitmapFactory.decodeFile(info.thumb_path);
// 把该位图对象保存到应用实例的全局变量中
MainApplication.getInstance().mIconMap.put(info.rowid, thumb);
}
}
// 把是否首次打开写入共享参数
SharedUtil.getIntance(this).writeShared("first", "false");
}
}

@ -0,0 +1,203 @@
package com.example.storage;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.storage.bean.CartInfo;
import com.example.storage.bean.GoodsInfo;
import com.example.storage.database.CartDBHelper;
import com.example.storage.database.GoodsDBHelper;
import com.example.storage.util.DateUtil;
import com.example.storage.util.SharedUtil;
import com.example.storage.util.Utils;
import java.util.ArrayList;
@SuppressLint("SetTextI18n")
public class ShoppingChannelActivity extends AppCompatActivity implements OnClickListener {
private TextView tv_count;
private LinearLayout ll_channel;
private int mCount; // 购物车中的商品数量
private GoodsDBHelper mGoodsHelper; // 声明一个商品数据库的帮助器对象
private CartDBHelper mCartHelper; // 声明一个购物车数据库的帮助器对象
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shopping_channel);
TextView tv_title = findViewById(R.id.tv_title);
tv_count = findViewById(R.id.tv_count);
ll_channel = findViewById(R.id.ll_channel);
findViewById(R.id.iv_cart).setOnClickListener(this);
tv_title.setText("盲盒咖啡店");
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.iv_cart) { // 点击了购物车图标
// 跳转到购物车页面
Intent intent = new Intent(this, ShoppingCartActivity.class);
startActivity(intent);
}
}
// 把指定编号的商品添加到购物车
private void addToCart(long goods_id) {
mCount++;
tv_count.setText("" + mCount);
// 把购物车中的商品数量写入共享参数
SharedUtil.getIntance(this).writeShared("count", "" + mCount);
// 根据商品编号查询购物车数据库中的商品记录
CartInfo info = mCartHelper.queryByGoodsId(goods_id);
if (info != null) { // 购物车已存在该商品记录
info.count++; // 该商品的数量加一
info.update_time = DateUtil.getNowDateTime("");
// 更新购物车数据库中的商品记录信息
mCartHelper.update(info);
} else { // 购物车不存在该商品记录
info = new CartInfo();
info.goods_id = goods_id;
info.count = 1;
info.update_time = DateUtil.getNowDateTime("");
// 往购物车数据库中添加一条新的商品记录
mCartHelper.insert(info);
}
}
@Override
protected void onResume() {
super.onResume();
// 获取共享参数保存的购物车中的商品数量
mCount = Integer.parseInt(SharedUtil.getIntance(this).readShared("count", "0"));
tv_count.setText("" + mCount);
// 获取商品数据库的帮助器对象
mGoodsHelper = GoodsDBHelper.getInstance(this, 1);
// 打开商品数据库的读连接
mGoodsHelper.openReadLink();
// 获取购物车数据库的帮助器对象
mCartHelper = CartDBHelper.getInstance(this, 1);
// 打开购物车数据库的写连接
mCartHelper.openWriteLink();
// 展示商品列表
showGoods();
}
@Override
protected void onPause() {
super.onPause();
// 关闭商品数据库的数据库连接
mGoodsHelper.closeLink();
// 关闭购物车数据库的数据库连接
mCartHelper.closeLink();
}
private LayoutParams mFullParams, mHalfParams;
private void showGoods() {
// 移除线性布局ll_channel下面的所有子视图
ll_channel.removeAllViews();
// mFullParams这个布局参数的宽度占了一整行
mFullParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
// mHalfParams这个布局参数的宽度与其它布局平均分
mHalfParams = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
// 给mHalfParams设置四周的空白距离
mHalfParams.setMargins(Utils.dip2px(this, 2), Utils.dip2px(this, 2), Utils.dip2px(this, 2), Utils.dip2px(this, 2));
// 创建一行的线性布局
LinearLayout ll_row = newLinearLayout(LinearLayout.HORIZONTAL, 0);
// 查询商品数据库中的所有商品记录
ArrayList<GoodsInfo> goodsArray = mGoodsHelper.query("1=1");
int i = 0;
for (; i < goodsArray.size(); i++) {
final GoodsInfo info = goodsArray.get(i);
// 创建一个商品项的垂直线性布局,从上到下依次列出商品标题、商品图片、商品价格
LinearLayout ll_goods = newLinearLayout(LinearLayout.VERTICAL, 1);
ll_goods.setBackgroundColor(Color.WHITE);
// 添加商品标题
TextView tv_name = new TextView(this);
tv_name.setLayoutParams(mFullParams);
tv_name.setGravity(Gravity.CENTER);
tv_name.setText(info.name);
tv_name.setTextColor(Color.BLACK);
tv_name.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
ll_goods.addView(tv_name);
// 添加商品小图
ImageView iv_thumb = new ImageView(this);
iv_thumb.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, Utils.dip2px(this, 150)));
iv_thumb.setScaleType(ScaleType.FIT_CENTER);
iv_thumb.setImageBitmap(MainApplication.getInstance().mIconMap.get(info.rowid));
iv_thumb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ShoppingChannelActivity.this, ShoppingDetailActivity.class);
intent.putExtra("goods_id", info.rowid);
startActivity(intent);
}
});
ll_goods.addView(iv_thumb);
// 添加商品价格
LinearLayout ll_bottom = newLinearLayout(LinearLayout.HORIZONTAL, 0);
TextView tv_price = new TextView(this);
tv_price.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
tv_price.setGravity(Gravity.CENTER);
tv_price.setText("" + (int) info.price);
tv_price.setTextColor(Color.RED);
tv_price.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
ll_bottom.addView(tv_price);
// 添加购物车按钮
Button btn_add = new Button(this);
btn_add.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 3));
btn_add.setGravity(Gravity.CENTER);
btn_add.setText("加入购物车");
btn_add.setTextColor(Color.BLACK);
btn_add.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
btn_add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
addToCart(info.rowid);
Toast.makeText(ShoppingChannelActivity.this,
"已添加一份" + info.name + "到购物车", Toast.LENGTH_SHORT).show();
}
});
ll_bottom.addView(btn_add);
ll_goods.addView(ll_bottom);
// 把商品项添加到该行上
ll_row.addView(ll_goods);
// 每行放两个商品项,所以放满两个商品后,就要重新创建下一行的线性视图
if (i % 2 == 1) {
ll_channel.addView(ll_row);
ll_row = newLinearLayout(LinearLayout.HORIZONTAL, 0);
}
}
// 最后一行只有一个商品项则补上一个空白格然后把最后一行添加到ll_channel
if (i % 2 == 0) {
ll_row.addView(newLinearLayout(LinearLayout.VERTICAL, 1));
ll_channel.addView(ll_row);
}
}
// 创建一个线性视图的框架
private LinearLayout newLinearLayout(int orientation, int weight) {
LinearLayout ll_new = new LinearLayout(this);
ll_new.setLayoutParams((weight == 0) ? mFullParams : mHalfParams);
ll_new.setOrientation(orientation);
return ll_new;
}
}

@ -0,0 +1,123 @@
package com.example.storage;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.storage.bean.CartInfo;
import com.example.storage.bean.GoodsInfo;
import com.example.storage.database.CartDBHelper;
import com.example.storage.database.GoodsDBHelper;
import com.example.storage.util.DateUtil;
import com.example.storage.util.SharedUtil;
@SuppressLint("SetTextI18n")
public class ShoppingDetailActivity extends AppCompatActivity implements OnClickListener {
private TextView tv_title;
private TextView tv_count;
private TextView tv_goods_price;
private TextView tv_goods_desc;
private ImageView iv_goods_pic;
private int mCount; // 购物车中的商品数量
private long mGoodsId; // 当前商品的商品编号
private GoodsDBHelper mGoodsHelper; // 声明一个商品数据库的帮助器对象
private CartDBHelper mCartHelper; // 声明一个购物车数据库的帮助器对象
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shopping_detail);
tv_title = findViewById(R.id.tv_title);
tv_count = findViewById(R.id.tv_count);
tv_goods_price = findViewById(R.id.tv_goods_price);
tv_goods_desc = findViewById(R.id.tv_goods_desc);
iv_goods_pic = findViewById(R.id.iv_goods_pic);
findViewById(R.id.iv_cart).setOnClickListener(this);
findViewById(R.id.btn_add_cart).setOnClickListener(this);
// 获取共享参数保存的购物车中的商品数量
mCount = Integer.parseInt(SharedUtil.getIntance(this).readShared("count", "0"));
tv_count.setText("" + mCount);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.iv_cart) { // 点击了购物车图标
// 跳转到购物车页面
Intent intent = new Intent(this, ShoppingCartActivity.class);
startActivity(intent);
} else if (v.getId() == R.id.btn_add_cart) { // 点击了“添加”按钮
// 把该商品添加到购物车
addToCart(mGoodsId);
Toast.makeText(this, "成功添加至购物车", Toast.LENGTH_SHORT).show();
}
}
// 把指定编号的商品添加到购物车
private void addToCart(long goods_id) {
mCount++;
tv_count.setText("" + mCount);
// 把购物车中的商品数量写入共享参数
SharedUtil.getIntance(this).writeShared("count", "" + mCount);
// 根据商品编号查询购物车中的商品记录
CartInfo info = mCartHelper.queryByGoodsId(goods_id);
if (info != null) { // 购物车已存在该商品记录
info.count++; // 该商品的数量加一
info.update_time = DateUtil.getNowDateTime("");
// 更新购物车数据库中的商品记录信息
mCartHelper.update(info);
} else { // 购物车不存在该商品记录
info = new CartInfo();
info.goods_id = goods_id;
info.count = 1;
info.update_time = DateUtil.getNowDateTime("");
// 往购物车数据库中添加一条新的商品记录
mCartHelper.insert(info);
}
}
@Override
protected void onResume() {
super.onResume();
// 获取商品数据库的帮助器对象
mGoodsHelper = GoodsDBHelper.getInstance(this, 1);
// 打开商品数据库的读连接
mGoodsHelper.openReadLink();
// 获取购物车数据库的帮助器对象
mCartHelper = CartDBHelper.getInstance(this, 1);
// 打开购物车数据库的写连接
mCartHelper.openWriteLink();
// 展示商品详情
showDetail();
}
@Override
protected void onPause() {
super.onPause();
// 关闭商品数据库的数据库连接
mGoodsHelper.closeLink();
// 关闭购物车数据库的数据库连接
mCartHelper.closeLink();
}
private void showDetail() {
mGoodsId = getIntent().getLongExtra("goods_id", 0L);
if (mGoodsId > 0) {
GoodsInfo info = mGoodsHelper.queryById(mGoodsId);
tv_title.setText(info.name);
tv_goods_desc.setText(info.desc);
tv_goods_price.setText("" + info.price);
Bitmap pic = BitmapFactory.decodeFile(info.pic_path);
iv_goods_pic.setImageBitmap(pic);
}
}
}

@ -0,0 +1,32 @@
package com.example.storage;
/**
* Created by littlecurl 2018/6/24
*/
public class User {
private String name; //用户名
private String password; //密码
public User(String name, String password) {
this.name = name;
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", password='" + password + '\'' +
'}';
}
}

@ -0,0 +1,22 @@
package com.example.storage;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class UserActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user);
getSupportActionBar().setTitle("个人中心");
}
public void Jumping(View view) {
Intent intent = new Intent(UserActivity.this, LoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}

@ -0,0 +1,17 @@
package com.example.storage.bean;
public class CartInfo {
public long rowid;
public int xuhao;
public long goods_id;
public int count;
public String update_time;
public CartInfo() {
rowid = 0L;
xuhao = 0;
goods_id = 0L;
count = 0;
update_time = "";
}
}

@ -0,0 +1,83 @@
package com.example.storage.bean;
import com.example.storage.R;
import java.util.ArrayList;
public class GoodsInfo {
public long rowid; // 行号
public int xuhao; // 序号1
public String name; // 名称
public String desc; // 描述
public float price; // 价格
public String thumb_path; // 图的保存路径
public String pic_path; // 图的保存路径
public int thumb; // 图的资源编号
public int pic; // 图的资源编号
public GoodsInfo() {
rowid = 0L;
xuhao = 0;
name = "";
desc = "";
price = 0;
thumb_path = "";
pic_path = "";
thumb = 0;
pic = 0;
}
// 声明一个商品的名称数组
private static String[] mNameArray = {
"来杯拿铁", "一杯咖啡", "神秘美式", "饮品+甜点套餐", "随便奶茶", "不知味气泡水"
};
// 声明一个商品的描述数组
private static String[] mDescArray = {
"来杯拿铁\n 欢迎来开盲盒啦!\n" +
"杯型:大杯\n" +
"温度: 热、冷、常温\n" ,
"一杯咖啡\n选择困难症的福音来啦本店都是好喝的咖啡不知道选那种咖啡的选择我店家会给你搭配一杯的\n " +
"杯型: 咱们家只有大杯哦!\n" +
"温度:热、冷、常温三种哦!\n",
"神秘美式\n我是很神秘的美式哦可以颠覆你对美式的想象哦\n"+
"杯型: 咱们家只有大杯哦!\n"+
"温度:热、冷、常温三种哦!\n",
"饮品+甜点套餐\n 生活必须要多来一点甜甜的!\n" +
"杯型: 咱们家只有大杯哦!\n" +
"温度:热、冷、常温三种哦!\n",
"随便奶茶\n 当你想喝奶茶却不知道选什么奶茶的时候就选我好啦!\n" +
"杯型: 咱们家只有大杯哦!\n" +
"温度:热、冷、常温三种哦!\n",
"不知味气泡水\n 各种水果与气泡水碰撞在一起会是什么味道呢!\n" +
"杯型: 咱们家只有大杯哦!\n" +
"温度:热、冷、常温三种哦!\n",
};
// 声明一个商品的价格数组
private static float[] mPriceArray = {18, 18, 16, 25, 16, 15};
// 声明一个商品的小图数组
private static int[] mThumbArray = {
R.drawable.nt1, R.drawable.cf1, R.drawable.ms1,
R.drawable.td4, R.drawable.nc1, R.drawable.qps1
};
// 声明一个商品的大图数组
private static int[] mPicArray = {
R.drawable.ntall, R.drawable.cfall, R.drawable.msall,
R.drawable.tdall, R.drawable.ncall, R.drawable.qpsall
};
// 获取默认的信息列表
public static ArrayList<GoodsInfo> getDefaultList() {
ArrayList<GoodsInfo> goodsList = new ArrayList<GoodsInfo>();
for (int i = 0; i < mNameArray.length; i++) {
GoodsInfo info = new GoodsInfo();
info.name = mNameArray[i];
info.desc = mDescArray[i];
info.price = mPriceArray[i];
info.thumb = mThumbArray[i];
info.pic = mPicArray[i];
goodsList.add(info);
}
return goodsList;
}
}

@ -0,0 +1,190 @@
package com.example.storage.database;
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.example.storage.bean.CartInfo;
@SuppressLint("DefaultLocale")
public class CartDBHelper extends SQLiteOpenHelper {
private static final String TAG = "CartDBHelper";
private static final String DB_NAME = "cart.db"; // 数据库的名称
private static final int DB_VERSION = 1; // 数据库的版本号
private static CartDBHelper mHelper = null; // 数据库帮助器的实例
private SQLiteDatabase mDB = null; // 数据库的实例
private static final String TABLE_NAME = "cart_info"; // 表的名称
private CartDBHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
private CartDBHelper(Context context, int version) {
super(context, DB_NAME, null, version);
}
// 利用单例模式获取数据库帮助器的唯一实例
public static CartDBHelper getInstance(Context context, int version) {
if (version > 0 && mHelper == null) {
mHelper = new CartDBHelper(context, version);
} else if (mHelper == null) {
mHelper = new CartDBHelper(context);
}
return mHelper;
}
// 打开数据库的读连接
public SQLiteDatabase openReadLink() {
if (mDB == null || !mDB.isOpen()) {
mDB = mHelper.getReadableDatabase();
}
return mDB;
}
// 打开数据库的写连接
public SQLiteDatabase openWriteLink() {
if (mDB == null || !mDB.isOpen()) {
mDB = mHelper.getWritableDatabase();
}
return mDB;
}
// 关闭数据库连接
public void closeLink() {
if (mDB != null && mDB.isOpen()) {
mDB.close();
mDB = null;
}
}
// 创建数据库,执行建表语句
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG, "onCreate");
String drop_sql = "DROP TABLE IF EXISTS " + TABLE_NAME + ";";
Log.d(TAG, "drop_sql:" + drop_sql);
db.execSQL(drop_sql);
String create_sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " ("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ "goods_id LONG NOT NULL," + "count INTEGER NOT NULL,"
+ "update_time VARCHAR NOT NULL"
+ ");";
Log.d(TAG, "create_sql:" + create_sql);
db.execSQL(create_sql);
}
// 修改数据库,执行表结构变更语句
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
// 根据指定条件删除表记录
public int delete(String condition) {
// 执行删除记录动作,该语句返回删除记录的数目
return mDB.delete(TABLE_NAME, condition, null);
}
// 删除该表的所有记录
public int deleteAll() {
// 执行删除记录动作,该语句返回删除记录的数目
return mDB.delete(TABLE_NAME, "1=1", null);
}
// 往该表添加一条记录
public long insert(CartInfo info) {
ArrayList<CartInfo> infoArray = new ArrayList<CartInfo>();
infoArray.add(info);
return insert(infoArray);
}
// 往该表添加多条记录
public long insert(ArrayList<CartInfo> infoArray) {
long result = -1;
for (CartInfo info : infoArray) {
Log.d(TAG, "goods_id=" + info.goods_id + ", count=" + info.count);
// 如果存在相同rowid的记录则更新记录
if (info.rowid > 0) {
String condition = String.format("rowid='%d'", info.rowid);
update(info, condition);
result = info.rowid;
continue;
}
// 不存在唯一性重复的记录,则插入新记录
ContentValues cv = new ContentValues();
cv.put("goods_id", info.goods_id);
cv.put("count", info.count);
cv.put("update_time", info.update_time);
// 执行插入记录动作,该语句返回插入记录的行号
result = mDB.insert(TABLE_NAME, "", cv);
// 添加成功后返回行号,失败后返回-1
if (result == -1) {
return result;
}
}
return result;
}
// 根据条件更新指定的表记录
public int update(CartInfo info, String condition) {
ContentValues cv = new ContentValues();
cv.put("goods_id", info.goods_id);
cv.put("count", info.count);
cv.put("update_time", info.update_time);
// 执行更新记录动作,该语句返回记录更新的数目
return mDB.update(TABLE_NAME, cv, condition, null);
}
public int update(CartInfo info) {
// 执行更新记录动作,该语句返回记录更新的数目
return update(info, "rowid=" + info.rowid);
}
// 根据指定条件查询记录,并返回结果数据队列
public ArrayList<CartInfo> query(String condition) {
String sql = String.format("select rowid,_id,goods_id,count,update_time" +
" from %s where %s;", TABLE_NAME, condition);
Log.d(TAG, "query sql: " + sql);
ArrayList<CartInfo> infoArray = new ArrayList<CartInfo>();
// 执行记录查询动作,该语句返回结果集的游标
Cursor cursor = mDB.rawQuery(sql, null);
// 循环取出游标指向的每条记录
while (cursor.moveToNext()) {
CartInfo info = new CartInfo();
info.rowid = cursor.getLong(0);
info.xuhao = cursor.getInt(1);
info.goods_id = cursor.getLong(2);
info.count = cursor.getInt(3);
info.update_time = cursor.getString(4);
infoArray.add(info);
}
cursor.close(); // 查询完毕,关闭游标
return infoArray;
}
// 根据行号查询指定记录
public CartInfo queryById(long rowid) {
CartInfo info = null;
ArrayList<CartInfo> infoArray = query(String.format("rowid='%d'", rowid));
if (infoArray.size() > 0) {
info = infoArray.get(0);
}
return info;
}
// 根据商品编号查询指定记录
public CartInfo queryByGoodsId(long goods_id) {
CartInfo info = null;
ArrayList<CartInfo> infoArray = query(String.format("goods_id='%d'", goods_id));
if (infoArray.size() > 0) {
info = infoArray.get(0);
}
return info;
}
}

@ -0,0 +1,186 @@
package com.example.storage.database;
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.example.storage.bean.GoodsInfo;
@SuppressLint("DefaultLocale")
public class GoodsDBHelper extends SQLiteOpenHelper {
private static final String TAG = "GoodsDBHelper";
private static final String DB_NAME = "goods.db"; // 数据库的名称
private static final int DB_VERSION = 1; // 数据库的版本号
private static GoodsDBHelper mHelper = null; // 数据库帮助器的实例
private SQLiteDatabase mDB = null; // 数据库的实例
private static final String TABLE_NAME = "goods_info"; // 表的名称
private GoodsDBHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
private GoodsDBHelper(Context context, int version) {
super(context, DB_NAME, null, version);
}
// 利用单例模式获取数据库帮助器的唯一实例
public static GoodsDBHelper getInstance(Context context, int version) {
if (version > 0 && mHelper == null) {
mHelper = new GoodsDBHelper(context, version);
} else if (mHelper == null) {
mHelper = new GoodsDBHelper(context);
}
return mHelper;
}
// 打开数据库的读连接
public SQLiteDatabase openReadLink() {
if (mDB == null || !mDB.isOpen()) {
mDB = mHelper.getReadableDatabase();
}
return mDB;
}
// 打开数据库的写连接
public SQLiteDatabase openWriteLink() {
if (mDB == null || !mDB.isOpen()) {
mDB = mHelper.getWritableDatabase();
}
return mDB;
}
// 关闭数据库连接
public void closeLink() {
if (mDB != null && mDB.isOpen()) {
mDB.close();
mDB = null;
}
}
// 创建数据库,执行建表语句
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG, "onCreate");
String drop_sql = "DROP TABLE IF EXISTS " + TABLE_NAME + ";";
Log.d(TAG, "drop_sql:" + drop_sql);
db.execSQL(drop_sql);
String create_sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " ("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ "name VARCHAR NOT NULL," + "desc VARCHAR NOT NULL,"
+ "price FLOAT NOT NULL," + "thumb_path VARCHAR NOT NULL,"
+ "pic_path VARCHAR NOT NULL"
+ ");";
Log.d(TAG, "create_sql:" + create_sql);
db.execSQL(create_sql);
}
// 修改数据库,执行表结构变更语句
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
// 根据指定条件删除表记录
public int delete(String condition) {
// 执行删除记录动作,该语句返回删除记录的数目
return mDB.delete(TABLE_NAME, condition, null);
}
// 删除该表的所有记录
public int deleteAll() {
// 执行删除记录动作,该语句返回删除记录的数目
return mDB.delete(TABLE_NAME, "1=1", null);
}
// 往该表添加一条记录
public long insert(GoodsInfo info) {
ArrayList<GoodsInfo> infoArray = new ArrayList<GoodsInfo>();
infoArray.add(info);
return insert(infoArray);
}
// 往该表添加多条记录
public long insert(ArrayList<GoodsInfo> infoArray) {
long result = -1;
for (GoodsInfo info : infoArray) {
// 如果存在相同rowid的记录则更新记录
if (info.rowid > 0) {
String condition = String.format("rowid='%d'", info.rowid);
update(info, condition);
result = info.rowid;
continue;
}
// 不存在唯一性重复的记录,则插入新记录
ContentValues cv = new ContentValues();
cv.put("name", info.name);
cv.put("desc", info.desc);
cv.put("price", info.price);
cv.put("thumb_path", info.thumb_path);
cv.put("pic_path", info.pic_path);
// 执行插入记录动作,该语句返回插入记录的行号
result = mDB.insert(TABLE_NAME, "", cv);
// 添加成功后返回行号,失败后返回-1
if (result == -1) {
return result;
}
}
return result;
}
// 根据条件更新指定的表记录
public int update(GoodsInfo info, String condition) {
ContentValues cv = new ContentValues();
cv.put("name", info.name);
cv.put("desc", info.desc);
cv.put("price", info.price);
cv.put("thumb_path", info.thumb_path);
cv.put("pic_path", info.pic_path);
// 执行更新记录动作,该语句返回记录更新的数目
return mDB.update(TABLE_NAME, cv, condition, null);
}
public int update(GoodsInfo info) {
// 执行更新记录动作,该语句返回记录更新的数目
return update(info, "rowid=" + info.rowid);
}
// 根据指定条件查询记录,并返回结果数据队列
public ArrayList<GoodsInfo> query(String condition) {
String sql = String.format("select rowid,_id,name,desc,price,thumb_path,pic_path" +
" from %s where %s;", TABLE_NAME, condition);
Log.d(TAG, "query sql: " + sql);
ArrayList<GoodsInfo> infoArray = new ArrayList<GoodsInfo>();
// 执行记录查询动作,该语句返回结果集的游标
Cursor cursor = mDB.rawQuery(sql, null);
// 循环取出游标指向的每条记录
while (cursor.moveToNext()) {
GoodsInfo info = new GoodsInfo();
info.rowid = cursor.getLong(0);
info.xuhao = cursor.getInt(1);
info.name = cursor.getString(2);
info.desc = cursor.getString(3);
info.price = cursor.getFloat(4);
info.thumb_path = cursor.getString(5);
info.pic_path = cursor.getString(6);
infoArray.add(info);
}
cursor.close(); // 查询完毕,关闭游标
return infoArray;
}
// 根据行号查询指定记录
public GoodsInfo queryById(long rowid) {
GoodsInfo info = null;
ArrayList<GoodsInfo> infoArray = query(String.format("rowid='%d'", rowid));
if (infoArray.size() > 0) {
info = infoArray.get(0);
}
return info;
}
}

@ -0,0 +1,39 @@
package com.example.storage.util;
import android.annotation.SuppressLint;
import android.text.TextUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
*/
@SuppressLint("SimpleDateFormat")
public class DateUtil {
public static String getNowDateTime(String formatStr) {
String format = formatStr;
if (TextUtils.isEmpty(format)) {
format = "yyyyMMddHHmmss";
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date());
}
public static String getNowTime() {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
return sdf.format(new Date());
}
public static String getNowTimeDetail() {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
return sdf.format(new Date());
}
public static String formatDate(long time) {
Date date = new Date(time);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
}

@ -0,0 +1,133 @@
package com.example.storage.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Locale;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class FileUtil {
// 把字符串保存到指定路径的文本文件
public static void saveText(String path, String txt) {
try {
// 根据指定文件路径构建文件输出流对象
FileOutputStream fos = new FileOutputStream(path);
// 把字符串写入文件输出流
fos.write(txt.getBytes());
// 关闭文件输出流
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// 从指定路径的文本文件中读取内容字符串
public static String openText(String path) {
String readStr = "";
try {
// 根据指定文件路径构建文件输入流对象
FileInputStream fis = new FileInputStream(path);
byte[] b = new byte[fis.available()];
// 从文件输入流读取字节数组
fis.read(b);
// 把字节数组转换为字符串
readStr = new String(b);
// 关闭文件输入流
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
// 返回文本文件中的文本字符串
return readStr;
}
// 把位图数据保存到指定路径的图片文件
public static void saveImage(String path, Bitmap bitmap) {
try {
// 根据指定文件路径构建缓存输出流对象
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(path));
// 把位图数据压缩到缓存输出流中
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
// 完成缓存输出流的写入动作
bos.flush();
// 关闭缓存输出流
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// 从指定路径的图片文件中读取位图数据
public static Bitmap openImage(String path) {
Bitmap bitmap = null;
try {
// 根据指定文件路径构建缓存输入流对象
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(path));
// 从缓存输入流中解码位图数据
bitmap = BitmapFactory.decodeStream(bis);
bis.close(); // 关闭缓存输入流
} catch (Exception e) {
e.printStackTrace();
}
// 返回图片文件中的位图数据
return bitmap;
}
public static ArrayList<File> getFileList(String path, String[] extendArray) {
ArrayList<File> displayedContent = new ArrayList<File>();
File[] files = null;
File directory = new File(path);
if (extendArray != null && extendArray.length > 0) {
FilenameFilter fileFilter = getTypeFilter(extendArray);
files = directory.listFiles(fileFilter);
} else {
files = directory.listFiles();
}
if (files != null) {
for (File f : files) {
if (!f.isDirectory() && !f.isHidden()) {
displayedContent.add(f);
}
}
}
return displayedContent;
}
public static FilenameFilter getTypeFilter(String[] extendArray) {
final ArrayList<String> fileExtensions = new ArrayList<String>();
for (int i = 0; i < extendArray.length; i++) {
fileExtensions.add(extendArray[i]);
}
FilenameFilter fileNameFilter = new FilenameFilter() {
@Override
public boolean accept(File directory, String fileName) {
boolean matched = false;
File f = new File(String.format("%s/%s",
directory.getAbsolutePath(), fileName));
matched = f.isDirectory();
if (!matched) {
for (String s : fileExtensions) {
s = String.format(".{0,}\\%s$", s);
s = s.toUpperCase(Locale.getDefault());
fileName = fileName.toUpperCase(Locale.getDefault());
matched = fileName.matches(s);
if (matched) {
break;
}
}
}
return matched;
}
};
return fileNameFilter;
}
}

@ -0,0 +1,33 @@
package com.example.storage.util;
import android.content.Context;
import android.content.SharedPreferences;
// 这是共享参数的工具类,统一对共享参数的读写操作
public class SharedUtil {
private static SharedUtil mUtil; // 声明一个共享参数工具类的实例
private static SharedPreferences mShared; // 声明一个共享参数的实例
// 通过单例模式获取共享参数工具类的唯一实例
public static SharedUtil getIntance(Context ctx) {
if (mUtil == null) {
mUtil = new SharedUtil();
}
// 从share.xml中获取共享参数对象
mShared = ctx.getSharedPreferences("share", Context.MODE_PRIVATE);
return mUtil;
}
// 把配对信息写入共享参数
public void writeShared(String key, String value) {
SharedPreferences.Editor editor = mShared.edit(); // 获得编辑器的对象
editor.putString(key, value); // 添加一个指定键名的字符串参数
editor.commit(); // 提交编辑器中的修改
}
// 根据键名到共享参数中查找对应的值对象
public String readShared(String key, String defaultValue) {
return mShared.getString(key, defaultValue);
}
}

@ -0,0 +1,56 @@
package com.example.storage.util;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;
/**
*
*/
public class Utils {
// 根据手机的分辨率从 dp 的单位 转成为 px(像素)
public static int dip2px(Context context, float dpValue) {
// 获取当前手机的像素密度
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f); // 四舍五入取整
}
// 根据手机的分辨率从 px(像素) 的单位 转成为 dp
public static int px2dip(Context context, float pxValue) {
// 获取当前手机的像素密度
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f); // 四舍五入取整
}
// 获得屏幕的宽度
public static int getScreenWidth(Context ctx) {
// 从系统服务中获取窗口管理器
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
// 从默认显示器中获取显示参数保存到dm对象中
wm.getDefaultDisplay().getMetrics(dm);
return dm.widthPixels; // 返回屏幕的宽度数值
}
// 获得屏幕的高度
public static int getScreenHeight(Context ctx) {
// 从系统服务中获取窗口管理器
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
// 从默认显示器中获取显示参数保存到dm对象中
wm.getDefaultDisplay().getMetrics(dm);
return dm.heightPixels; // 返回屏幕的高度数值
}
// 获得屏幕的像素密度
public static float getScreenDensity(Context ctx) {
// 从系统服务中获取窗口管理器
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
// 从默认显示器中获取显示参数保存到dm对象中
wm.getDefaultDisplay().getMetrics(dm);
return dm.density; // 返回屏幕的像素密度数值
}
}

@ -0,0 +1,55 @@
package com.example.storage.util;
import android.app.Activity;
import android.content.Context;
import android.text.InputFilter;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import java.lang.reflect.Field;
/**
*
*/
public class ViewUtil {
// 获取编辑框的最大长度,通过反射机制调用隐藏方法
public static int getMaxLength(EditText et) {
int length = 0;
try {
InputFilter[] inputFilters = et.getFilters();
for (InputFilter filter : inputFilters) {
Class<?> c = filter.getClass();
if (c.getName().equals("android.text.InputFilter$LengthFilter")) {
Field[] f = c.getDeclaredFields();
for (Field field : f) {
if (field.getName().equals("mMax")) {
field.setAccessible(true);
length = (Integer) field.get(filter);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return length;
}
public static void hideAllInputMethod(Activity act) {
// 从系统服务中获取输入法管理器
InputMethodManager imm = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) { // 软键盘如果已经打开则关闭之
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
}
public static void hideOneInputMethod(Activity act, View v) {
// 从系统服务中获取输入法管理器
InputMethodManager imm = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE);
// 关闭屏幕上的输入法软键盘
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 B

@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/check_choose"/>
<item android:drawable="@drawable/check_unchoose"/>
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<stroke android:width="3dp" android:color="@color/green_500"/>
<corners android:radius="20dp" />
</shape>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/shape_edit_focus"/>
<item android:drawable="@drawable/shape_edit_normal"/>
</selector>

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#008577"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--默认情况下是一个带圆角,蓝色背景,白色边框的矩形-->
<!--第二种方法-->
<item android:state_window_focused="false">
<shape android:shape="rectangle">
<!--圆角-->
<corners android:radius="5dp" />
<!--填充颜色-->
<solid android:color="@color/color_minefragment_top" />
<!--描边-->
<stroke android:width="1dp" android:color="#fff" />
</shape>
</item>
<!--单击时是一个带圆角,绿色背景,白色边框的矩形-->
<item android:state_pressed="true">
<shape android:shape="rectangle">
<!--圆角-->
<corners android:radius="5dp" />
<!--填充颜色-->
<solid android:color="#008B8B" />
<!--描边-->
<stroke android:width="1dp" android:color="#fff" />
</shape>
</item>
</selector>

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#ff0000ff" />
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
</shape>

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#ffaaaaaa" />
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp" />
</shape>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#ff6666" />
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 KiB

@ -0,0 +1,228 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
这里把整个Activity_login的布局设置成相对布局
因为相对布局比较灵活,想咋放咋放
看代码,上来就是三个 xmlnsxml这仨字母认识ns这俩字母是namespace的缩写
正是有了这些namespace的声明才能在不同的xml中使用相同的id名
而不会造成使用时的冲突2
-->
<RelativeLayout
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/bg1"
tools:context=".LoginActivity"
>
<!--
整体是相对布局,
在整体上方放三个东西,这三个东西也是相对布局
合在一起称为一个top
一个返回箭头 ←
两个文字显示 登录 注册
也就是说 login界面的上方长这个样子
← 登录 注册
下面是具体代码
-->
<RelativeLayout
android:id="@+id/rl_loginactivity_top"
android:layout_width="match_parent"
android:layout_height="70dp" >
<ImageView
android:id="@+id/iv_loginactivity_back"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_left_back"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:clickable="true"
android:onClick="onClick"
android:visibility="gone"
/>
<TextView
android:id="@+id/tv_loginactivity_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#fff"
android:textSize="20dp"
android:layout_toRightOf="@+id/iv_loginactivity_back"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
/>
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/tv_loginactivity_login"
android:text="咖啡"
android:textColor="#fff"
android:textSize="20dp" />
<TextView
android:id="@+id/tv_loginactivity_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
android:textColor="#fff"
android:textSize="20dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:clickable="true"
android:onClick="onClick"
/>
</RelativeLayout>
<!--
顶部三个东西摆放好之后
就该来摆放登录时候的两个文本输入框了
用户名
密码
这个明显的是LinerLayout
LinerLayout必须指明orientation 方向 要么垂直vertical 要么水平 horizontal
这里显然是垂直vertical
-->
<LinearLayout
android:id="@+id/ll_loginactivity_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@+id/rl_loginactivity_top"
android:layout_marginTop="50dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="@drawable/log4"
android:layout_marginBottom="30dp"
/>
<LinearLayout
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_loginactivity_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="20sp"
android:text="用户名:" />
<EditText
android:id="@+id/et_loginactivity_username"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#E4E0E0"
android:textColor="@color/black"
android:hint="手机号/邮箱/用户名"/>
</LinearLayout>
<LinearLayout
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_loginactivity_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="@color/black"
android:text="密 码:"/>
<EditText
android:id="@+id/et_loginactivity_password"
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="登录密码"
android:background="#E4E0E0"
android:textColor="@color/black"
android:inputType="textPassword"/>
</LinearLayout>
</LinearLayout>
<!--
填好用户名、密码后,就该点击登录按钮了
注意最后有一句: android:onClick="onClick"
这是应用了一个开源库详细信息在loginActivity.java 中有注释
-->
<Button
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:id="@+id/bt_loginactivity_login"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/ll_loginactivity_two"
android:layout_marginTop="10dp"
android:background="@color/brown"
android:text="登 录"
android:textSize="20sp"
android:textColor="#fff"
android:gravity="center"
android:onClick="onClick"
/>
<!--
为了App的人性化
想到有以下三种无法密码登录的异常处理情况
一、密码错误,重新输入
二、忘记密码,重新修改密码
三、不想注册,通过短信验证登录
密码输错了,重新输入,这个没啥说的
忘记密码应该以一个可以点击的文字出现在登录按钮的左下方
短信验证登录也以一个可以点击的文字出现在登录按钮的右下方
-->
<TextView
android:id="@+id/tv_loginactivity_forget"
android:text="忘记密码"
android:textSize="15sp"
android:textColor="#f00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginVertical="50dp"
android:layout_below="@+id/bt_loginactivity_login"
android:layout_alignLeft="@+id/bt_loginactivity_login"
/>
<TextView
android:id="@+id/tv_loginactivity_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="验证码登录"
android:textSize="15sp"
android:textColor="#f00"
android:layout_marginRight="50dp"
android:layout_marginVertical="50dp"
android:layout_below="@+id/bt_loginactivity_login"
android:layout_alignRight="@+id/bt_loginactivity_login"
/>
<!--
当然QQ、微信、微博、GitHub...在当今如此火热
登录的时候完全可以免注册
直接使用第三方登录
-->
<TextView
android:id="@+id/tv_loginactivity_else"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_loginactivity_forget"
android:layout_centerVertical="true"
android:layout_marginVertical="20dp"
android:layout_marginTop="500dp"
android:gravity="center"
android:text="----------------第三方登录----------------"
android:textSize="10sp"
android:textColor="@color/black"
/>
</RelativeLayout>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,202 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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/bg1"
>
<RelativeLayout
android:id="@+id/rl_registeractivity_top"
android:layout_width="match_parent"
android:layout_height="70dp"
>
<ImageView
android:id="@+id/iv_registeractivity_back"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_left_back"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:clickable="true"
android:onClick="onClick"
/>
<TextView
android:id="@+id/tv_registeractivity_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
android:textColor="#fff"
android:textSize="20dp"
android:layout_toRightOf="@+id/iv_registeractivity_back"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
/>
<TextView
android:id="@+id/tv_registeractivity_myname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="230dp"
android:layout_toRightOf="@+id/tv_registeractivity_register"
android:text="咖啡"
android:textColor="#fff"
android:textSize="20dp" />
</RelativeLayout>
<LinearLayout
android:id="@+id/ll_registeractivity_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@+id/rl_registeractivity_top"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
<!-- 第一个文本编辑框 输入用户名 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="30dp">
<TextView
android:id="@+id/tv_registeractivity_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="用户名:"/>
<EditText
android:id="@+id/et_registeractivity_username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="请输入用户名"
android:textColor="@color/black"
android:background="#E4E0E0"
android:gravity="center_vertical"
android:layout_marginLeft="10dp"
/>
</LinearLayout>
<!-- 第二个文本编辑框 输入密码 -->
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_registeractivity_password1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="密 码:"/>
<EditText
android:id="@+id/et_registeractivity_password1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:layout_marginLeft="10dp"
android:background="#E4E0E0"
android:textColor="@color/black"
android:inputType="textPassword"
android:hint="请输入密码" />
</LinearLayout>
<!-- 第三个文本编辑框 再次输入密码 -->
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_registeractivity_password2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="密 码:"/>
<EditText
android:id="@+id/et_registeractivity_password2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="请再次输入密码"
android:textColor="@color/black"
android:gravity="center_vertical"
android:background="#E4E0E0"
android:layout_marginLeft="10dp"
android:inputType="textPassword"
/>
</LinearLayout>
<!-- 验证码部分 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<!-- 第四个文本编辑框 输入验证码 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_registeractivity_phoneCodes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="验证码:"/>
<EditText
android:id="@+id/et_registeractivity_phoneCodes"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#E4E0E0"
android:textColor="@color/black"
android:hint="请输入4位验证码" />
<ImageView
android:id="@+id/iv_registeractivity_showCode"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_weight="1.5"
android:clickable="true"
android:onClick="onClick"
android:layout_marginTop="-10dp"
/>
</LinearLayout>
</LinearLayout>
<!-- 注册按钮 -->
<Button
android:id="@+id/bt_registeractivity_register"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:background="@drawable/selector_loginactivity_button"
android:textColor="#fff"
android:text="注册"
android:onClick="onClick"
android:layout_marginTop="40dp"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/rl_registeractivity_bottom"
android:layout_marginTop="10dp"
>
<TextView
android:layout_centerInParent="true"
android:text="注册即代表同意《用户协议》"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>

@ -0,0 +1,93 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg5"
android:orientation="vertical">
<include layout="@layout/activity_shopping_title"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<LinearLayout
android:id="@+id/ll_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:id="@+id/ll_cart"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|right"
android:text="总金额:"
android:textColor="@color/black"
android:textSize="17sp"/>
<TextView
android:id="@+id/tv_total_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center|left"
android:textColor="@color/red"
android:textSize="25sp"/>
<Button
android:id="@+id/btn_settle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="结算"
android:textColor="@color/black"
android:textSize="20sp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
android:layout_marginTop="100dp"
android:gravity="center"
android:text="哎呀,购物车空空如也,快去选购商品吧"
android:textColor="@color/black"
android:textSize="17sp"/>
<Button
android:id="@+id/btn_shopping_channel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="盲盒咖啡店"
android:textColor="@color/black"
android:textSize="17sp"/>
<Button
android:id="@+id/btn_shopping_grzx"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="去个人中心"
android:textColor="@color/black"
android:textSize="17sp"/>
</LinearLayout>
</FrameLayout>
</ScrollView>
</LinearLayout>

@ -0,0 +1,23 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg5"
android:orientation="vertical" >
<include layout="@layout/activity_shopping_title" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="@+id/ll_channel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>

@ -0,0 +1,51 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg5"
android:orientation="vertical" >
<include layout="@layout/activity_shopping_title" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_goods_pic"
android:layout_width="match_parent"
android:layout_height="350dp"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/tv_goods_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/red"
android:textSize="22sp" />
<TextView
android:id="@+id/tv_goods_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="15sp" />
<Button
android:id="@+id/btn_add_cart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="加入购物车"
android:textColor="@color/black"
android:textSize="17sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>

@ -0,0 +1,50 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/bule"
>
<ImageView android:id="@+id/iv_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:scaleType="fitCenter"
android:src="@drawable/menu"
android:visibility="gone"/>
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerInParent="true"
android:text="购 物 车"
android:gravity="center"
android:textColor="#fff"
android:textSize="25sp"
android:textStyle="bold" />
<ImageView
android:id="@+id/iv_cart"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:scaleType="fitCenter"
android:src="@drawable/cart" />
<TextView
android:id="@+id/tv_count"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/iv_cart"
android:layout_marginLeft="-20dp"
android:gravity="center"
android:background="@drawable/shape_oval_red"
android:text="0"
android:textColor="@color/white"
android:textSize="15sp" />
</LinearLayout>

@ -0,0 +1,211 @@
<?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:gravity="center"
android:background="@drawable/bg1"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView4"
android:layout_width="match_parent"
android:layout_height="90dp"
android:src="@drawable/daifukuan" />
<TextView
android:id="@+id/tv_dfk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="待付款"
android:textColor="#050505"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView5"
android:layout_width="match_parent"
android:layout_height="90dp"
android:src="@drawable/daishouhuo" />
<TextView
android:id="@+id/tv_dfh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="待发货"
android:textColor="#050505"
android:textSize="20sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView6"
android:layout_width="match_parent"
android:layout_height="90dp"
android:src="@drawable/pingjia" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="待评价"
android:textColor="#050505"
android:textSize="20sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView7"
android:layout_width="match_parent"
android:layout_height="90dp"
android:src="@drawable/shouhou" />
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="售后"
android:textColor="#050505"
android:textSize="20sp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_weight="4"
android:orientation="vertical"
android:padding="5dp">
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:backgroundTint="@color/white"
android:gravity="center_vertical"
android:text="收货地址"
android:textSize="20sp"
android:textColor="@color/black"
tools:background="f39ad2" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:backgroundTint="@color/white"
android:gravity="center_vertical"
android:text="账户和安全"
android:textSize="20sp"
android:textColor="@color/black"
tools:background="f39ad2" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:backgroundTint="@color/white"
android:gravity="center_vertical"
android:text="支付"
android:textSize="20sp"
android:textColor="@color/black"
tools:background="f39ad2" />
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:backgroundTint="@color/white"
android:gravity="center_vertical"
android:text="消息通知"
android:textSize="20sp"
android:textColor="@color/black"
tools:background="f39ad2" />
<Button
android:id="@+id/button9"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:backgroundTint="@color/white"
android:gravity="center_vertical"
android:text="隐私"
android:textSize="20sp"
android:textColor="@color/black"
tools:background="f39ad2" />
<Button
android:id="@+id/button10"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:backgroundTint="@color/white"
android:gravity="center_vertical"
android:text="通用"
android:textSize="20sp"
android:textColor="@color/black"
tools:background="f39ad2"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:id="@+id/btn_tuichu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:layout_weight="1"
android:text="退出登录"
android:textSize="20sp"
android:onClick="Jumping"/>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,19 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_shopping"
android:orderInCategory="1"
android:title="去商场购物"
/>
<item
android:id="@+id/menu_clear"
android:orderInCategory="2"
android:title="清空购物车"/>
<item
android:id="@+id/menu_return"
android:orderInCategory="9"
android:title="返回"/>
</menu>

@ -0,0 +1,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_detail"
android:orderInCategory="1"
android:title="查看商品详情"/>
<item
android:id="@+id/menu_delete"
android:orderInCategory="2"
android:title="从购物车删除"/>
</menu>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save