@ -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,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="jbr-11" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveExternalAnnotations" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1 @@
|
||||
/build
|
@ -0,0 +1,43 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.example.test'
|
||||
compileSdk 33
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.example.test"
|
||||
minSdk 27
|
||||
targetSdk 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
debuggable true
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation group: 'com.alibaba', name: 'fastjson', version: '1.2.12'
|
||||
implementation "com.squareup.okhttp3:okhttp:4.2.2"
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
implementation 'com.github.crazyandcoder:citypicker:6.0.2'
|
||||
}
|
@ -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,26 @@
|
||||
package com.example.test;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.example.test", appContext.getPackageName());
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:targetApi="31">
|
||||
<service
|
||||
android:name=".service.MessageService"
|
||||
android:exported="false"></service>
|
||||
|
||||
<activity
|
||||
android:name=".activity.fruitActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".activity.homeActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".activity.registerActivity"
|
||||
android:exported="false" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,123 @@
|
||||
package com.example.test;
|
||||
|
||||
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.test.activity.homeActivity;
|
||||
import com.example.test.activity.registerActivity;
|
||||
import com.example.test.dao.UserDatabase;
|
||||
import com.example.test.entity.user;
|
||||
import com.example.test.netrequest.userOkHttp;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
private Button registerButton, loginButton;
|
||||
private EditText usernameText, paswdEdit;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.login);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()){
|
||||
case R.id.register:
|
||||
Intent intent = new Intent(this, registerActivity.class);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case R.id.login:
|
||||
// loginCheck();
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.start();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void loginCheck() {
|
||||
String name = usernameText.getText().toString();
|
||||
String pass = paswdEdit.getText().toString();
|
||||
if(name.isEmpty()||pass.isEmpty()){
|
||||
Toast.makeText(this,"用户名或密码为空",Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
UserDatabase db = new UserDatabase(this, "orange");
|
||||
SQLiteDatabase readdb = db.getReadableDatabase();
|
||||
Cursor cursor = db.select(readdb, "user",null,"username=? and password=?",new String[]{name,pass},null,null,null);
|
||||
|
||||
if(cursor.getCount()!=0){
|
||||
cursor.moveToNext();
|
||||
Intent intent = new Intent(this, homeActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("username",cursor.getString(1));
|
||||
bundle.putString("sex",cursor.getString(3));
|
||||
bundle.putString("address",cursor.getString(4));
|
||||
cursor.close();
|
||||
readdb.close();
|
||||
intent.putExtras(bundle);
|
||||
startActivity(intent);
|
||||
}else {
|
||||
Toast.makeText(this,"用户名或密码有误",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void init(){
|
||||
registerButton = findViewById(R.id.register);
|
||||
registerButton.setOnClickListener(this);
|
||||
loginButton = findViewById(R.id.login);
|
||||
loginButton.setOnClickListener(this);
|
||||
usernameText = findViewById(R.id.username);
|
||||
paswdEdit = findViewById(R.id.password);
|
||||
}
|
||||
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String name = usernameText.getText().toString();
|
||||
String pass = paswdEdit.getText().toString();
|
||||
userOkHttp userOkHttp = new userOkHttp();
|
||||
user u = new user();
|
||||
u.setUsername(name);
|
||||
u.setPassword(pass);
|
||||
try {
|
||||
user result = userOkHttp.login(u);
|
||||
if(result!=null){
|
||||
Intent intent = new Intent(MainActivity.this, homeActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("username",result.getUsername());
|
||||
bundle.putString("password",result.getPassword());
|
||||
bundle.putString("sex",result.getSex());
|
||||
bundle.putString("city",result.getCity());
|
||||
intent.putExtras(bundle);
|
||||
startActivity(intent);
|
||||
}else{
|
||||
Looper.prepare();
|
||||
Toast.makeText(MainActivity.this,"用户名或密码错误",Toast.LENGTH_SHORT).show();
|
||||
Looper.loop();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
package com.example.test.activity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
|
||||
import com.example.test.R;
|
||||
import com.example.test.adapter.homeNavigationBottomAdapter;
|
||||
import com.example.test.fragment.navigationCartFragment;
|
||||
import com.example.test.fragment.navigationGoodFragment;
|
||||
import com.example.test.fragment.navigationHomeFragment;
|
||||
import com.example.test.fragment.navigationPersonFragment;
|
||||
import com.example.test.service.MessageService;
|
||||
|
||||
public class homeActivity extends AppCompatActivity {
|
||||
public final int Home = 1;
|
||||
public final int Good = 2;
|
||||
public final int Cart = 3;
|
||||
public final int Person = 4;
|
||||
private int imgs[]={R.drawable.home_kind_orange1,R.drawable.home_kind_grapefruit,
|
||||
R.drawable.home_kind_orange,R.drawable.home_kind_watermelon,
|
||||
R.drawable.home_kind_pear,R.drawable.home_kind_apple,
|
||||
R.drawable.home_kind_lemon,R.drawable.home_kind_mango
|
||||
};
|
||||
|
||||
private String names[] = {"橙子","柚子","橘子","西瓜","香梨","苹果","柠檬","芒果"};
|
||||
|
||||
private double prices[] = {9.9,29.3,19.7,5.7,6.7,10.9,15.9,29.9};
|
||||
|
||||
private int sectionImgs[] = {R.drawable.section_home,R.drawable.section_good,
|
||||
R.drawable.section_cart,R.drawable.section_mine};
|
||||
private String sectionNames[] ={"首页","商品","购物车","我"};
|
||||
|
||||
private FragmentManager manager = getSupportFragmentManager();
|
||||
private Bundle extras;
|
||||
private Handler handler = new Handler(new Handler.Callback() {
|
||||
@Override
|
||||
public boolean handleMessage(@NonNull Message message) {
|
||||
switch (message.what){
|
||||
case Home:
|
||||
navigationHomeFragment homeFragment = (navigationHomeFragment) manager.findFragmentById(R.id.navigation_section);
|
||||
homeFragment.init();
|
||||
return true;
|
||||
case Good:
|
||||
navigationGoodFragment goodFragment = (navigationGoodFragment) manager.findFragmentById(R.id.navigation_section);
|
||||
goodFragment.initView();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
public Handler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public int[] getImgs() {
|
||||
return imgs;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public double[] getPrices() {
|
||||
return prices;
|
||||
}
|
||||
|
||||
public int[] getSectionImgs() {
|
||||
return sectionImgs;
|
||||
}
|
||||
|
||||
public String[] getSectionNames() {
|
||||
return sectionNames;
|
||||
}
|
||||
|
||||
public Bundle getBundle(){
|
||||
return extras;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.navigation);
|
||||
Intent service = new Intent(homeActivity.this, MessageService.class);
|
||||
startService(service);
|
||||
Log.i("start service","start");
|
||||
Intent intent = getIntent();
|
||||
extras = intent.getExtras();
|
||||
init();
|
||||
initFragment(new navigationHomeFragment());
|
||||
|
||||
}
|
||||
|
||||
public void initFragment(Fragment fragment){
|
||||
FragmentTransaction transaction = manager.beginTransaction();
|
||||
transaction.replace(R.id.navigation_section,fragment);
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
protected void init(){
|
||||
|
||||
//初始化底端导航栏
|
||||
GridView navigation = (GridView)findViewById(R.id.home_navigation_bottom_gridview);
|
||||
homeNavigationBottomAdapter navigationAdapter = new homeNavigationBottomAdapter(sectionImgs,sectionNames,this);
|
||||
navigation.setAdapter(navigationAdapter);
|
||||
navigation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
switch (position){
|
||||
case 0:
|
||||
initFragment(new navigationHomeFragment());
|
||||
break;
|
||||
case 1:
|
||||
initFragment(new navigationGoodFragment());
|
||||
|
||||
break;
|
||||
case 2:
|
||||
initFragment(new navigationCartFragment());
|
||||
|
||||
break;
|
||||
case 3:
|
||||
initFragment(new navigationPersonFragment());
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,209 @@
|
||||
package com.example.test.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.test.MainActivity;
|
||||
import com.example.test.R;
|
||||
import com.example.test.dao.UserDatabase;
|
||||
import com.example.test.entity.user;
|
||||
import com.example.test.netrequest.userOkHttp;
|
||||
import com.lljjcoder.Interface.OnCityItemClickListener;
|
||||
import com.lljjcoder.bean.CityBean;
|
||||
import com.lljjcoder.bean.DistrictBean;
|
||||
import com.lljjcoder.bean.ProvinceBean;
|
||||
import com.lljjcoder.citywheel.CityConfig;
|
||||
import com.lljjcoder.style.citypickerview.CityPickerView;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class registerActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
|
||||
private EditText userEdit;
|
||||
private EditText passEdit;
|
||||
private EditText paEdit;
|
||||
private RadioGroup sexBut;
|
||||
private TextView adressText;
|
||||
private String sex ="男";
|
||||
private Button regBut;
|
||||
CityPickerView citypv;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.register);
|
||||
init();
|
||||
}
|
||||
|
||||
public void init(){
|
||||
citypv = new CityPickerView();
|
||||
citypv.init(this);
|
||||
initConfig();
|
||||
citypv.setOnCityItemClickListener(new OnCityItemClickListener() {
|
||||
@Override
|
||||
public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
|
||||
String pro = province.getName();
|
||||
String ci = city.getName();
|
||||
String dis = district.getName();
|
||||
adressText.setText(String.format("%s %s %s",pro,ci,dis));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
}
|
||||
});
|
||||
userEdit = findViewById(R.id.reg_username);
|
||||
passEdit = findViewById(R.id.reg_password);
|
||||
paEdit = findViewById(R.id.reg_apassword);
|
||||
adressText = findViewById(R.id.reg_adress);
|
||||
adressText.setOnClickListener(this);
|
||||
sexBut = findViewById(R.id.reg_sex);
|
||||
sexBut.setOnCheckedChangeListener(this);
|
||||
regBut = findViewById(R.id.reg_register);
|
||||
regBut.setOnClickListener(this);
|
||||
}
|
||||
|
||||
private void initConfig() {
|
||||
CityConfig cityConfig = new CityConfig.Builder()
|
||||
.title("选择城市")//标题
|
||||
.titleTextSize(18)//标题文字大小
|
||||
.titleTextColor("#585858")//标题文字颜 色
|
||||
.titleBackgroundColor("#E9E9E9")//标题栏背景色
|
||||
.confirTextColor("#585858")//确认按钮文字颜色
|
||||
.confirmText("ok")//确认按钮文字
|
||||
.confirmTextSize(16)//确认按钮文字大小
|
||||
.cancelTextColor("#585858")//取消按钮文字颜色
|
||||
.cancelText("cancel")//取消按钮文字
|
||||
.cancelTextSize(16)//取消按钮文字大小
|
||||
.setCityWheelType(CityConfig.WheelType.PRO_CITY_DIS)//显示类,只显示省份一级,显示省市两级还是显示省市区三级
|
||||
.showBackground(true)//是否显示半透明背景
|
||||
.visibleItemsCount(7)//显示item的数量
|
||||
.province("浙江省")//默认显示的省份
|
||||
.city("杭州市")//默认显示省份下面的城市
|
||||
.district("滨江区")//默认显示省市下面的区县数据
|
||||
.provinceCyclic(true)//省份滚轮是否可以循环滚动
|
||||
.cityCyclic(true)//城市滚轮是否可以循环滚动
|
||||
.districtCyclic(true)//区县滚轮是否循环滚动
|
||||
.drawShadows(false)//滚轮不显示模糊效果
|
||||
.setLineColor("#03a9f4")//中间横线的颜色
|
||||
.setLineHeigh(5)//中间横线的高度
|
||||
.setShowGAT(true)//是否显示港澳台数据,默认不显示
|
||||
.build();
|
||||
citypv.setConfig(cityConfig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()){
|
||||
case R.id.reg_adress:
|
||||
citypv.showCityPicker();
|
||||
break;
|
||||
case R.id.reg_register:
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//利用sqlite数据库验证用户名和密码
|
||||
private void check() {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
String username = userEdit.getText().toString();
|
||||
String password = passEdit.getText().toString();
|
||||
String apassword = paEdit.getText().toString();
|
||||
String adress = adressText.getText().toString();
|
||||
if(password.equals(apassword)){
|
||||
if(username.isEmpty()||username.isEmpty()){
|
||||
Toast.makeText(this,"用户名或密码为空",Toast.LENGTH_SHORT).show();
|
||||
}else {
|
||||
if(adress.equals("")||adress.equals("地址选择"))
|
||||
Toast.makeText(this,"未选择地址",Toast.LENGTH_SHORT).show();
|
||||
else{
|
||||
UserDatabase db = new UserDatabase(this, "orange");
|
||||
SQLiteDatabase writedb = db.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("username",username);
|
||||
values.put("password",password);
|
||||
values.put("adress",adress);
|
||||
values.put("sex",sex);
|
||||
db.insert(writedb,"user",values);
|
||||
writedb.close();
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Toast.makeText(this,"两次密码不一致",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
//根据用户选择来改变sex的值
|
||||
sex = R.id.reg_male==checkedId?"男":"女";
|
||||
}
|
||||
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent intent = new Intent(registerActivity.this, MainActivity.class);
|
||||
String username = userEdit.getText().toString();
|
||||
String password = passEdit.getText().toString();
|
||||
String apassword = paEdit.getText().toString();
|
||||
String adress = adressText.getText().toString();
|
||||
if(password.equals(apassword)){
|
||||
if(username.isEmpty()||username.isEmpty()){
|
||||
Looper.prepare();
|
||||
Toast.makeText(registerActivity.this,"用户名或密码为空",Toast.LENGTH_SHORT).show();
|
||||
Looper.loop();
|
||||
}else {
|
||||
if(adress.equals("")||adress.equals("地址选择")) {
|
||||
Looper.prepare();
|
||||
Toast.makeText(registerActivity.this, "未选择地址", Toast.LENGTH_SHORT).show();
|
||||
Looper.loop();
|
||||
}
|
||||
else{
|
||||
user u = new user();
|
||||
u.setUsername(username);
|
||||
u.setPassword(password);
|
||||
userOkHttp http = new userOkHttp();
|
||||
try {
|
||||
boolean register = http.register(u);
|
||||
if(register)
|
||||
{
|
||||
startActivity(intent);
|
||||
}else{
|
||||
Looper.prepare();
|
||||
Toast.makeText(registerActivity.this, "注册失败", Toast.LENGTH_SHORT).show();
|
||||
Looper.loop();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Looper.prepare();
|
||||
Toast.makeText(registerActivity.this,"两次密码不一致",Toast.LENGTH_SHORT).show();
|
||||
Looper.loop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.example.test.activity;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.test.MainActivity;
|
||||
import com.example.test.R;
|
||||
|
||||
public class userActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
private TextView userText;
|
||||
private TextView sexText;
|
||||
private TextView adressText;
|
||||
private Button logoutBut;
|
||||
private View shoppingView;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.content_user);
|
||||
display();
|
||||
}
|
||||
|
||||
private void display() {
|
||||
Intent intent = getIntent();
|
||||
Bundle bundle = intent.getExtras();
|
||||
String username = "账号:"+bundle.getString("username");
|
||||
String sex = "性别:"+bundle.getString("sex");
|
||||
String adress = "城市:"+bundle.getString("adress");
|
||||
userText = findViewById(R.id.user_username);
|
||||
userText.setText(username);
|
||||
sexText = findViewById(R.id.user_sex);
|
||||
sexText.setText(sex);
|
||||
adressText = findViewById(R.id.user_city);
|
||||
adressText.setText(adress);
|
||||
logoutBut = findViewById(R.id.logout);
|
||||
logoutBut.setOnClickListener(this);
|
||||
shoppingView = findViewById(R.id.user_shopping_line);
|
||||
shoppingView.setOnClickListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId())
|
||||
{
|
||||
case R.id.logout:
|
||||
logout();
|
||||
break;
|
||||
case R.id.user_shopping_line:
|
||||
goShopping();
|
||||
}
|
||||
}
|
||||
|
||||
protected void goShopping() {
|
||||
Intent intent = new Intent(this, fruitActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
protected void logout() {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.example.test.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.test.R;
|
||||
import com.example.test.entity.fruitContent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class fruitContentAdapter extends BaseAdapter {
|
||||
private Holder holder;
|
||||
private fruitContent fruitContents[];
|
||||
private Context context;
|
||||
|
||||
public fruitContentAdapter() {
|
||||
}
|
||||
|
||||
public fruitContentAdapter(fruitContent fruitContents[], Context context) {
|
||||
this.fruitContents = fruitContents;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fruitContents.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
return fruitContents[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
public void setBackgroundColor(int position,String color){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int i, View convertview, ViewGroup viewGroup) {
|
||||
holder = new fruitContentAdapter.Holder();
|
||||
fruitContent content = fruitContents[i];
|
||||
if(convertview==null){
|
||||
convertview = LayoutInflater.from(context).inflate(R.layout.fruit_content_item,null);
|
||||
holder.iv_img = convertview.findViewById(R.id.fruit_content_img);
|
||||
holder.tv_name = convertview.findViewById(R.id.fruit_content_name);
|
||||
holder.tv_desc = convertview.findViewById(R.id.fruit_content_desc);
|
||||
holder.tv_tag = convertview.findViewById(R.id.fruit_content_tag);
|
||||
holder.tv_price = convertview.findViewById(R.id.fruit_content_price);
|
||||
convertview.setTag(holder);
|
||||
}else {
|
||||
holder = (fruitContentAdapter.Holder) convertview.getTag();
|
||||
}
|
||||
holder.iv_img.setImageResource(content.getImg());
|
||||
holder.tv_name.setText(content.getName());
|
||||
// holder.tv_name.getPaint().setFakeBoldText(true);
|
||||
holder.tv_desc.setText(content.getDesc());
|
||||
if(content.getTag()==1)
|
||||
holder.tv_tag.setText("爆款直降");
|
||||
holder.tv_price.setText(content.getPrice()+"");
|
||||
return convertview;
|
||||
}
|
||||
static class Holder{
|
||||
ImageView iv_img;
|
||||
TextView tv_name;
|
||||
TextView tv_desc;
|
||||
TextView tv_tag;
|
||||
TextView tv_price;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.example.test.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.test.R;
|
||||
import com.example.test.entity.fruitKind;
|
||||
import com.example.test.fragment.fruitKindFragment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class fruitKindAdapter extends BaseAdapter {
|
||||
private List<fruitKind> fruitKinds;
|
||||
private Context context;
|
||||
private Holder holder;
|
||||
private int selected_item=0;
|
||||
|
||||
public fruitKindAdapter() {
|
||||
}
|
||||
|
||||
public fruitKindAdapter(List<fruitKind> fruitKinds, Context context) {
|
||||
this.fruitKinds = fruitKinds;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fruitKinds.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
return fruitKinds.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int i, View convertview, ViewGroup viewGroup) {
|
||||
fruitKind kind = fruitKinds.get(i);
|
||||
if(convertview==null){
|
||||
holder = new Holder();
|
||||
// Log.i("init",i+" "+convertview);
|
||||
convertview = LayoutInflater.from(context).inflate(R.layout.fruit_kind_item,null);
|
||||
if(i == 0){
|
||||
convertview.setBackgroundResource(R.color.gray);
|
||||
}
|
||||
holder.iv_img = convertview.findViewById(R.id.kind_img);
|
||||
holder.tv_name = convertview.findViewById(R.id.kind_name);
|
||||
if(kind.getImg()!=0)
|
||||
holder.iv_img.setImageResource(kind.getImg());
|
||||
holder.tv_name.setText(kind.getName());
|
||||
convertview.setTag(holder);
|
||||
}else {
|
||||
holder = (Holder) convertview.getTag();
|
||||
holder.iv_img.setImageResource(kind.getImg());
|
||||
holder.tv_name.setText(kind.getName());
|
||||
fruitKindFragment fruitKindFragment = new fruitKindFragment();
|
||||
int selected_item = fruitKindFragment.getSelected_item();
|
||||
if(i!=selected_item)
|
||||
convertview.setBackgroundResource(R.color.white);
|
||||
else
|
||||
convertview.setBackgroundResource(R.color.gray);
|
||||
//Log.i("after",i+" "+convertview);
|
||||
|
||||
|
||||
}
|
||||
return convertview;
|
||||
}
|
||||
static class Holder{
|
||||
ImageView iv_img;
|
||||
TextView tv_name;
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.example.test.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.test.R;
|
||||
import com.example.test.entity.product;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class homeFruitKindAdapter extends BaseAdapter {
|
||||
private int imgs[] = {};
|
||||
private String names[];
|
||||
private List<Bitmap> bitmaps;
|
||||
private Context context;
|
||||
|
||||
|
||||
public homeFruitKindAdapter(int[] imgs, String[] names, Context context) {
|
||||
this.imgs = imgs;
|
||||
this.names = names;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public homeFruitKindAdapter(List<Bitmap>bitmaps,String names[], Context context) {
|
||||
this.bitmaps = bitmaps;
|
||||
this.names = names;
|
||||
this.context = context;
|
||||
}
|
||||
@Override
|
||||
public int getCount() {
|
||||
return names.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
// int img= imgs[i];
|
||||
String name = names[i];
|
||||
List<Object> fruit = new ArrayList<>();
|
||||
// fruit.add(img);
|
||||
fruit.add(bitmaps.get(i));
|
||||
fruit.add(name);
|
||||
return fruit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int i, View ConvertView, ViewGroup viewGroup) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.home_fruit_kind_item,null);
|
||||
ImageView img = view.findViewById(R.id.home_fruit_kind_img);
|
||||
TextView name = view.findViewById(R.id.home_fruit_kind_name);
|
||||
// img.setImageResource(imgs[i]);
|
||||
img.setImageBitmap(bitmaps.get(i));
|
||||
name.setText(names[i]);
|
||||
return view;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.example.test.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.telephony.SmsManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.test.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class homeGoodsFruitAdapter extends BaseAdapter {
|
||||
private int imgs[]=null;
|
||||
private String names[];
|
||||
private double prices[];
|
||||
private List<Bitmap> bitmaps;
|
||||
private Context context;
|
||||
|
||||
public homeGoodsFruitAdapter(int[] imgs, String[] names, double[] prices, Context context) {
|
||||
this.imgs = imgs;
|
||||
this.names = names;
|
||||
this.prices = prices;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public homeGoodsFruitAdapter(List<Bitmap> bitmaps, String[] names, double[] prices, Context context) {
|
||||
this.bitmaps = bitmaps;
|
||||
this.names = names;
|
||||
this.prices = prices;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return names.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
Map<String, Object> fruit = new HashMap<>();
|
||||
// fruit.put("img",imgs[position]);
|
||||
fruit.put("bitmap",bitmaps.get(position));
|
||||
fruit.put("name",names[position]);
|
||||
fruit.put("price",prices[position]);
|
||||
return fruit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
viewHolder holder;
|
||||
if(convertView==null){
|
||||
holder = new viewHolder();
|
||||
convertView = LayoutInflater.from(context).inflate(R.layout.home_goods_fruit_item,null);
|
||||
holder.ivImg = convertView.findViewById(R.id.home_goods_fruit_img);
|
||||
holder.tvName = convertView.findViewById(R.id.home_goods_fruit_name);
|
||||
holder.tvPrice = convertView.findViewById(R.id.home_goods_fruit_price);
|
||||
convertView.setTag(holder);
|
||||
}else {
|
||||
holder = (viewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
// holder.ivImg.setImageResource(imgs[position]);
|
||||
holder.ivImg.setImageBitmap(bitmaps.get(position));
|
||||
holder.tvName.setText(names[position]);
|
||||
holder.tvPrice.setText(prices[position]+"");
|
||||
return convertView;
|
||||
}
|
||||
|
||||
static class viewHolder{
|
||||
ImageView ivImg;
|
||||
TextView tvName;
|
||||
TextView tvPrice;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.example.test.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.test.R;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class homeNavigationBottomAdapter extends BaseAdapter {
|
||||
private int imgs[];
|
||||
private String names[];
|
||||
private Context context;
|
||||
|
||||
public homeNavigationBottomAdapter(int[] imgs, String[] names, Context context) {
|
||||
this.imgs = imgs;
|
||||
this.names = names;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return imgs.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
Map<String, Object> section = new HashMap<>();
|
||||
section.put("img",imgs[position]);
|
||||
section.put("name",names[position]);
|
||||
return section;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
viewHolder holder;
|
||||
if(convertView==null){
|
||||
holder = new viewHolder();
|
||||
convertView = LayoutInflater.from(context).inflate(R.layout.home_navigation_bottom_item,null);
|
||||
holder.ivImg = convertView.findViewById(R.id.home_navigation_bottom_img);
|
||||
holder.tvName = convertView.findViewById(R.id.home_navigation_bottom_name);
|
||||
convertView.setTag(holder);
|
||||
}else {
|
||||
holder = (viewHolder) convertView.getTag();
|
||||
}
|
||||
holder.ivImg.setImageResource(imgs[position]);
|
||||
holder.tvName.setText(names[position]);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
static class viewHolder{
|
||||
ImageView ivImg;
|
||||
TextView tvName;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.example.test.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.test.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class spinnerAdapter extends BaseAdapter {
|
||||
private int imgs[];
|
||||
private String descs[];
|
||||
private Context context;
|
||||
|
||||
public spinnerAdapter() {
|
||||
}
|
||||
|
||||
public spinnerAdapter(int[] imgs, String[] descs, Context context) {
|
||||
this.imgs = imgs;
|
||||
this.descs = descs;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return imgs.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
list.add(imgs[i]);
|
||||
list.add(descs[i]);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int i, View convertView, ViewGroup viewGroup) {
|
||||
viewHolder holder;
|
||||
if(convertView==null){
|
||||
holder = new viewHolder();
|
||||
convertView = LayoutInflater.from(context).inflate(R.layout.navigation_good_spinner_item,null);
|
||||
holder.ivImg = convertView.findViewById(R.id.good_spinner_img);
|
||||
holder.tvDesc = convertView.findViewById(R.id.good_spinner_desc);
|
||||
convertView.setTag(holder);
|
||||
}else {
|
||||
holder = (viewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
holder.ivImg.setImageResource(imgs[i]);
|
||||
holder.tvDesc.setText(descs[i]);
|
||||
return convertView;
|
||||
}
|
||||
static class viewHolder{
|
||||
ImageView ivImg;
|
||||
TextView tvDesc;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.example.test.dao;
|
||||
|
||||
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 androidx.annotation.Nullable;
|
||||
|
||||
public class UserDatabase extends SQLiteOpenHelper {
|
||||
public UserDatabase(@Nullable Context context, @Nullable String name) {
|
||||
super(context, name,null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase sqLiteDatabase) {
|
||||
String sql = "create table user(id integer primary key autoincrement,username varchar(20),password varchar(20),sex varchar(20),adress varchar(20),phoneNumber char(11))";
|
||||
sqLiteDatabase.execSQL(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
|
||||
|
||||
}
|
||||
public void insert(SQLiteDatabase sqLiteDatabase, String table, ContentValues values){
|
||||
sqLiteDatabase.insert(table,null,values);
|
||||
// sqLiteDatabase.close();
|
||||
}
|
||||
|
||||
public void delete(SQLiteDatabase sqLiteDatabase,String table,String name,String []args){
|
||||
sqLiteDatabase.delete(table,name,args);
|
||||
// sqLiteDatabase.close();
|
||||
}
|
||||
|
||||
public Cursor select(SQLiteDatabase sqLiteDatabase,String table,String columns[],String selection,String selectionArgs[],String grunpBy,String having,String orderBy){
|
||||
// Cursor cursor = sqLiteDatabase.query(table,null,null,null,null,null,null);
|
||||
Cursor cursor = sqLiteDatabase.query(table,null,selection,selectionArgs,grunpBy,having,orderBy);
|
||||
return cursor;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.example.test.entity;
|
||||
|
||||
public class fruit {
|
||||
private String name;
|
||||
private double price;
|
||||
|
||||
public fruit() {
|
||||
}
|
||||
|
||||
public fruit(String name, double price) {
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.example.test.entity;
|
||||
|
||||
public class fruitContent {
|
||||
private int img;
|
||||
private String name;
|
||||
private String desc;
|
||||
private int tag;
|
||||
private double price;
|
||||
|
||||
public fruitContent() {
|
||||
}
|
||||
|
||||
public fruitContent(int img, String name, String desc, int tag, double price) {
|
||||
this.img = img;
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.tag = tag;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public int getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public void setImg(int img) {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public int getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(int tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.example.test.entity;
|
||||
|
||||
public class fruitKind {
|
||||
private String name;
|
||||
private int img;
|
||||
|
||||
public fruitKind() {
|
||||
}
|
||||
|
||||
public fruitKind(String name, int img) {
|
||||
this.name = name;
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public void setImg(int img) {
|
||||
this.img = img;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.example.test.entity;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class message {
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Timestamp getSendTime() {
|
||||
return sendTime;
|
||||
}
|
||||
|
||||
public void setSendTime(Timestamp sendTime) {
|
||||
this.sendTime = sendTime;
|
||||
}
|
||||
|
||||
public String getUsed() {
|
||||
return used;
|
||||
}
|
||||
|
||||
public void setUsed(String used) {
|
||||
this.used = used;
|
||||
}
|
||||
|
||||
private Integer id;
|
||||
private String content;
|
||||
private Timestamp sendTime;
|
||||
private String used;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OrangeMessage{" +
|
||||
"id=" + id +
|
||||
", content='" + content + '\'' +
|
||||
", sendTime=" + sendTime +
|
||||
", used='" + used + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.example.test.entity;
|
||||
|
||||
public class product {
|
||||
private int id;
|
||||
private String name;
|
||||
private double price;
|
||||
private String imgUrl;
|
||||
|
||||
public product() {
|
||||
}
|
||||
|
||||
public product(int id, String name, double price, String imgUrl) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
this.imgUrl = imgUrl;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getImgUrl() {
|
||||
return imgUrl;
|
||||
}
|
||||
|
||||
public void setImgUrl(String imgUrl) {
|
||||
this.imgUrl = imgUrl;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.example.test.entity;
|
||||
|
||||
public class user {
|
||||
private String username;
|
||||
private String password;
|
||||
private String sex;
|
||||
private String city;
|
||||
private int id;
|
||||
|
||||
public user() {
|
||||
}
|
||||
|
||||
public user(String username, String password, String sex, String city, int id) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.sex = sex;
|
||||
this.city = city;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.example.test.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.example.test.R;
|
||||
import com.example.test.activity.fruitActivity;
|
||||
import com.example.test.adapter.fruitContentAdapter;
|
||||
import com.example.test.entity.fruitContent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class fruitContentFragment extends Fragment {
|
||||
private View view;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
view= inflater.inflate(R.layout.fragment_fruit_content, container, false);
|
||||
fruitActivity activity=(fruitActivity)getActivity();
|
||||
List<fruitContent[]> fruitContents = activity.getFruitContents();
|
||||
show(fruitContents.get(0));
|
||||
return view;
|
||||
}
|
||||
public void show(fruitContent fruitContents[]){
|
||||
ListView listView = view.findViewById(R.id.fruit_content_listview);
|
||||
listView.setDivider(null);
|
||||
fruitContentAdapter adapter = new fruitContentAdapter(fruitContents,getActivity());
|
||||
listView.setAdapter(adapter);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.example.test.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.example.test.R;
|
||||
import com.example.test.activity.homeActivity;
|
||||
|
||||
public class navigationCartFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.navigation_cart, container, false);
|
||||
Button button = view.findViewById(R.id.navigation_cart_shopping);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
homeActivity activity = (homeActivity)getActivity();
|
||||
activity.initFragment(new navigationGoodFragment());
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
package com.example.test.fragment;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.example.test.R;
|
||||
import com.example.test.activity.homeActivity;
|
||||
import com.example.test.adapter.homeGoodsFruitAdapter;
|
||||
import com.example.test.adapter.spinnerAdapter;
|
||||
import com.example.test.entity.product;
|
||||
import com.example.test.netrequest.productOkHttp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class navigationGoodFragment extends Fragment {
|
||||
private int imgs[];
|
||||
private List<Bitmap> bitmapsList = new ArrayList<>();
|
||||
private String names[];
|
||||
private double prices[];
|
||||
private homeActivity activity;
|
||||
private View view;
|
||||
private Handler handler;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
view = inflater.inflate(R.layout.navigation_good, container, false);
|
||||
activity = (homeActivity) getActivity();
|
||||
handler = activity.getHandler();
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.start();
|
||||
// initData();
|
||||
// initView();
|
||||
return view;
|
||||
}
|
||||
|
||||
public void initView() {
|
||||
GridView goodGridview = (GridView) view.findViewById(R.id.navigation_good_gridview);
|
||||
homeGoodsFruitAdapter adapter = new homeGoodsFruitAdapter(bitmapsList, names, prices, activity);
|
||||
goodGridview.setAdapter(adapter);
|
||||
Spinner spinner = (Spinner) view.findViewById(R.id.navigation_good_spinner);
|
||||
spinnerAdapter spinnerAdapter = new spinnerAdapter(new int[]{R.drawable.all, R.drawable.time, R.drawable.sale, R.drawable.price},
|
||||
new String[]{"全部商品", "按上市时间排序", "按销量排序", "按价格排序"}, activity);
|
||||
spinner.setAdapter(spinnerAdapter);
|
||||
// spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
// @Override
|
||||
// public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
// switch (i) {
|
||||
// case 0:
|
||||
// Thread thread1 = new Thread(runnable1);
|
||||
// thread1.start();
|
||||
// break;
|
||||
// case 1:
|
||||
// Thread thread2 = new Thread(runnable2);
|
||||
// thread2.start();
|
||||
// break;
|
||||
// case 2:
|
||||
//// 暂时不支持
|
||||
// break;
|
||||
// case 3:
|
||||
// Thread thread4 = new Thread(runnable4);
|
||||
// thread4.start();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNothingSelected(AdapterView<?> adapterView) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
spinner.setDropDownHorizontalOffset(0);
|
||||
spinner.setDropDownVerticalOffset(30);
|
||||
}
|
||||
|
||||
|
||||
public void handleData(List<product> list, productOkHttp http) throws IOException {
|
||||
List<String> namesList = new ArrayList<>();
|
||||
List<Double> pricesList = new ArrayList<>();
|
||||
if (list != null) {
|
||||
for (product p : list) {
|
||||
namesList.add(p.getName());
|
||||
pricesList.add(p.getPrice());
|
||||
bitmapsList.add(http.getImg(p.getImgUrl()));
|
||||
}
|
||||
names = namesList.toArray(new String[0]);
|
||||
prices = pricesList.stream().mapToDouble(Double::doubleValue).toArray();
|
||||
// bitmaps = bitmapsList.toArray(new Bitmap[0]);
|
||||
Message msg = new Message();
|
||||
msg.what = activity.Good;
|
||||
handler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = new Message();
|
||||
msg.what = 0;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
protected void initData() {
|
||||
imgs = activity.getImgs();
|
||||
names = activity.getNames();
|
||||
prices = activity.getPrices();
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
productOkHttp http = new productOkHttp();
|
||||
try {
|
||||
List<product> products = http.getProduct();
|
||||
List<String> namesList = new ArrayList<>();
|
||||
List<Double> pricesList = new ArrayList<>();
|
||||
if (products != null) {
|
||||
for (product p : products) {
|
||||
namesList.add(p.getName());
|
||||
pricesList.add(p.getPrice());
|
||||
bitmapsList.add(http.getImg(p.getImgUrl()));
|
||||
}
|
||||
names = namesList.toArray(new String[0]);
|
||||
prices = pricesList.stream().mapToDouble(Double::doubleValue).toArray();
|
||||
// bitmaps = bitmapsList.toArray(new Bitmap[0]);
|
||||
Message msg = new Message();
|
||||
msg.what = activity.Good;
|
||||
handler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = new Message();
|
||||
msg.what = 0;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Runnable runnable1 = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
productOkHttp http = new productOkHttp();
|
||||
try {
|
||||
List<product> products = http.getProduct();
|
||||
List<String> namesList = new ArrayList<>();
|
||||
List<Double> pricesList = new ArrayList<>();
|
||||
if (products != null) {
|
||||
for (product p : products) {
|
||||
namesList.add(p.getName());
|
||||
pricesList.add(p.getPrice());
|
||||
bitmapsList.add(http.getImg(p.getImgUrl()));
|
||||
}
|
||||
names = namesList.toArray(new String[0]);
|
||||
prices = pricesList.stream().mapToDouble(Double::doubleValue).toArray();
|
||||
// bitmaps = bitmapsList.toArray(new Bitmap[0]);
|
||||
Message msg = new Message();
|
||||
msg.what = activity.Good;
|
||||
handler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = new Message();
|
||||
msg.what = 0;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
Runnable runnable2 = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
productOkHttp productOkHttp = new productOkHttp();
|
||||
try {
|
||||
List<product> products = productOkHttp.getProductOrderByTime();
|
||||
List<String> namesList = new ArrayList<>();
|
||||
List<Double> pricesList = new ArrayList<>();
|
||||
if (products != null) {
|
||||
for (product p : products) {
|
||||
namesList.add(p.getName());
|
||||
pricesList.add(p.getPrice());
|
||||
bitmapsList.add(productOkHttp.getImg(p.getImgUrl()));
|
||||
}
|
||||
names = namesList.toArray(new String[0]);
|
||||
prices = pricesList.stream().mapToDouble(Double::doubleValue).toArray();
|
||||
// bitmaps = bitmapsList.toArray(new Bitmap[0]);
|
||||
Message msg = new Message();
|
||||
msg.what = activity.Good;
|
||||
handler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = new Message();
|
||||
msg.what = 0;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Runnable runnable3 = new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
//
|
||||
// }
|
||||
// };
|
||||
|
||||
|
||||
// 价格排序
|
||||
Runnable runnable4 = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
productOkHttp productOkHttp = new productOkHttp();
|
||||
try {
|
||||
List<product> products = productOkHttp.getProductOrderByPrice();
|
||||
handleData(products, productOkHttp);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package com.example.test.fragment;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.GridView;
|
||||
|
||||
import com.example.test.R;
|
||||
import com.example.test.activity.homeActivity;
|
||||
import com.example.test.adapter.homeFruitKindAdapter;
|
||||
import com.example.test.adapter.homeGoodsFruitAdapter;
|
||||
import com.example.test.entity.product;
|
||||
import com.example.test.netrequest.productOkHttp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class navigationHomeFragment extends Fragment {
|
||||
private String names[] = {};
|
||||
private int imgs[] = {};
|
||||
private double prices[] = {};
|
||||
private List<Bitmap> bitmapsList = new ArrayList<>();
|
||||
private homeActivity activity;
|
||||
private View view;
|
||||
private Handler handler;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.start();
|
||||
view = inflater.inflate(R.layout.navigation_home, container, false);
|
||||
activity =(homeActivity)getActivity();
|
||||
handler = activity.getHandler();
|
||||
//initData();
|
||||
// init(view);
|
||||
return view;
|
||||
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
names = activity.getNames();
|
||||
imgs = activity.getImgs();
|
||||
prices = activity.getPrices();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
//初始化商品种类
|
||||
GridView kindGridview = (GridView)view.findViewById(R.id.fruit_kind_gridview);
|
||||
// homeFruitKindAdapter kindAdapter = new homeFruitKindAdapter(imgs,names,activity);
|
||||
homeFruitKindAdapter kindAdapter = new homeFruitKindAdapter(bitmapsList,names,activity);
|
||||
kindGridview.setAdapter(kindAdapter);
|
||||
|
||||
|
||||
//初始化热门商品下的水果
|
||||
GridView fruitGridview = (GridView) view.findViewById(R.id.home_goods_fruit_gridview);
|
||||
// homeGoodsFruitAdapter fruitAdapter = new homeGoodsFruitAdapter(imgs,names,prices,activity);
|
||||
homeGoodsFruitAdapter fruitAdapter = new homeGoodsFruitAdapter(bitmapsList,names,prices,activity);
|
||||
fruitGridview.setAdapter(fruitAdapter);
|
||||
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int index = 0;
|
||||
productOkHttp http = new productOkHttp();
|
||||
try {
|
||||
List<product> products = http.getProduct();
|
||||
List<String> namesList = new ArrayList<>();
|
||||
List<Double> pricesList = new ArrayList<>();
|
||||
if(products!=null){
|
||||
for (product p : products) {
|
||||
namesList.add(p.getName());
|
||||
pricesList.add(p.getPrice());
|
||||
bitmapsList.add(http.getImg(p.getImgUrl()));
|
||||
}
|
||||
names = namesList.toArray(new String[0]);
|
||||
prices = pricesList.stream().mapToDouble(Double::doubleValue).toArray();
|
||||
// bitmaps = bitmapsList.toArray(new Bitmap[0]);
|
||||
Message msg = new Message();
|
||||
msg.what = activity.Home;
|
||||
handler.sendMessage(msg);
|
||||
}else
|
||||
{
|
||||
Message msg = new Message();
|
||||
msg.what = 0;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.example.test.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.test.R;
|
||||
import com.example.test.activity.homeActivity;
|
||||
|
||||
|
||||
public class navigationPersonFragment extends Fragment {
|
||||
|
||||
private TextView tvName;
|
||||
private TextView tvSex;
|
||||
private TextView tvCity;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.content_user, container, false);
|
||||
homeActivity activity = (homeActivity)getActivity();
|
||||
Bundle bundle = activity.getBundle();
|
||||
String username = bundle.getString("username");
|
||||
String sex = bundle.getString("sex");
|
||||
String city = bundle.getString("city");
|
||||
tvName = view.findViewById(R.id.user_username);
|
||||
tvSex = view.findViewById(R.id.user_sex);
|
||||
tvCity = view.findViewById(R.id.user_city);
|
||||
tvName.setText("用户名:"+username);
|
||||
tvSex.setText("性别:"+sex);
|
||||
tvCity.setText("城市:"+city);
|
||||
return view;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.example.test.netrequest;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.example.test.entity.message;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class messageOkHttp {
|
||||
public message getMessage() throws IOException {
|
||||
// 获取消息
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://192.168.43.226:8081/orange/message/consumeMessage")
|
||||
.build();
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
JSONObject jsonObject = JSON.parseObject(response.body().string());
|
||||
message data = JSON.parseObject(jsonObject.getString("data"), message.class);
|
||||
|
||||
// 将获取到的消息设为已用
|
||||
Request comsume = new Request.Builder()
|
||||
.url("http://192.168.43.226:8081/orange/message/updateMessage")
|
||||
.build();
|
||||
Response execute = okHttpClient.newCall(comsume).execute();
|
||||
return data;
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package com.example.test.netrequest;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.example.test.entity.product;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class productOkHttp {
|
||||
|
||||
public Bitmap getImg(String imgUrl) throws IOException {
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url(imgUrl)
|
||||
// .addHeader("Connection", "keep-alive")
|
||||
.build();
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
byte[] bytes = Objects.requireNonNull(response.body()).bytes();
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
||||
response.body().close();
|
||||
return bitmap;
|
||||
|
||||
}
|
||||
//获取商品
|
||||
public List<product> getProduct() throws IOException {
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://192.168.43.226:8081/orange/product/search")
|
||||
.build();
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
JSONObject jsonObject = JSON.parseObject(response.body().string());
|
||||
String data = jsonObject.getString("data");
|
||||
List<product> products = JSON.parseObject(data, new TypeReference<List<product>>() {
|
||||
});
|
||||
response.body().close();
|
||||
return products;
|
||||
}
|
||||
|
||||
//按时间排序
|
||||
public List<product> getProductOrderByTime() throws IOException {
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://192.168.43.226:8081/orange/product/time")
|
||||
.build();
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
JSONObject jsonObject = JSON.parseObject(response.body().string());
|
||||
String data = jsonObject.getString("data");
|
||||
List<product> products = JSON.parseObject(data, new TypeReference<List<product>>() {
|
||||
});
|
||||
return products;
|
||||
}
|
||||
// 价格排序
|
||||
public List<product> getProductOrderByPrice() throws IOException {
|
||||
OkHttpClient okHttpClient = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://192.168.43.226:8081/orange/product/price")
|
||||
.build();
|
||||
Response response = okHttpClient.newCall(request).execute();
|
||||
JSONObject jsonObject = JSON.parseObject(response.body().string());
|
||||
String data = jsonObject.getString("data");
|
||||
List<product> products = JSON.parseObject(data, new TypeReference<List<product>>() {
|
||||
});
|
||||
return products;
|
||||
}
|
||||
|
||||
// 上传图片
|
||||
public boolean uploadImg(byte[] bytes) throws IOException {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
|
||||
.addFormDataPart("file", "baixiangguo.png", RequestBody.create(bytes)).build();
|
||||
Request request = new Request.Builder()
|
||||
.url("http://192.168.43.226:8081/orange/product/uploadCover")
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Response response = client.newCall(request).execute();
|
||||
Log.i("response", response.body().toString());
|
||||
if (response.isSuccessful()) {
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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>
|
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 700 B |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 368 B |
After Width: | Height: | Size: 233 B |
After Width: | Height: | Size: 14 KiB |
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="false">
|
||||
<shape>
|
||||
<solid android:color="#EFB81C" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_pressed="true">
|
||||
<shape>
|
||||
<solid android:color="#c0c0c0" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="false">
|
||||
<shape>
|
||||
<solid android:color="#c0c0c0" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_pressed="true">
|
||||
<shape>
|
||||
<solid android:color="#c0c0c0" />
|
||||
<corners android:radius="10dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 801 B |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 790 B |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 448 B |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 608 B |
@ -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>
|
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 6.0 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 787 B |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 347 B |
After Width: | Height: | Size: 468 B |
After Width: | Height: | Size: 897 B |
After Width: | Height: | Size: 909 B |
After Width: | Height: | Size: 557 B |
After Width: | Height: | Size: 918 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 453 B |
After Width: | Height: | Size: 7.8 KiB |
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="#FFFFFF"/>
|
||||
<corners android:radius="2dip"/>
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="#FFFFFF"
|
||||
/>
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<bitmap android:src="@drawable/arrow_down" android:gravity="end"/>
|
||||
</item>
|
||||
</layer-list>
|
After Width: | Height: | Size: 799 B |
After Width: | Height: | Size: 891 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 402 B |
After Width: | Height: | Size: 5.9 KiB |