实现购物车

master
unknown 2 years ago
parent 12febe759f
commit fd9a7289cc

@ -31,7 +31,8 @@ public class OrangeProductController {
* @return
*/
@RequestMapping(value = "/searchById", method = RequestMethod.POST)
public Map<String, Object> searchProductById(String productId) {
public Map<String, Object> searchProductById(@RequestBody String productId) {
System.out.println(productId);
OrangeProduct orangeProduct = productService.selectById(Integer.valueOf(productId));
Map<String, Object> map = new HashMap<>();
if (Objects.isNull(orangeProduct)) {

@ -1,8 +1,15 @@
package com.orangesale.cn.controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.orangesale.cn.entity.OrangeProduct;
import com.orangesale.cn.entity.OrangeShoppingCart;
import com.orangesale.cn.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author zhijun
@ -12,4 +19,62 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/orange/shoppingCart")
@CrossOrigin
public class OrangeShoppingCartController {
@Autowired
private ShoppingCartService shoppingCartService;
@RequestMapping(value = "/insert", method = RequestMethod.POST)
public Map<String, Object> insertCart(@RequestBody OrangeShoppingCart shoppingCart) {
Integer insertFlag = shoppingCartService.insertCart(shoppingCart);
Map<String, Object> map = new HashMap<>();
if (insertFlag <= 0) {
map.put("flag", false);
map.put("msg", "error");
return map;
}
map.put("flag", true);
map.put("msg", "insert success");
return map;
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public Map<String, Object> updateCart(@RequestBody OrangeShoppingCart shoppingCart) {
Integer updateFlag = shoppingCartService.updateCart(shoppingCart);
Map<String, Object> map = new HashMap<>();
if (updateFlag <= 0) {
map.put("flag", false);
map.put("msg", "error");
return map;
}
map.put("flag", true);
map.put("msg", "update success");
return map;
}
@RequestMapping(value = "/search", method = RequestMethod.GET)
public Map<String, Object> searchCart() {
List<OrangeShoppingCart> carts = shoppingCartService.selectAll();
Map<String, Object> map = new HashMap<>();
if (CollectionUtils.isEmpty(carts)) {
map.put("flag", false);
map.put("msg", "search error");
return map;
}
map.put("flag", true);
map.put("data", carts);
return map;
}
@RequestMapping(value = "/searchByUserId", method = RequestMethod.POST)
public Map<String, Object> searchCartByUserId(@RequestBody String userId) {
List<OrangeShoppingCart> list = shoppingCartService.selectByUserId(Integer.valueOf(userId));
Map<String, Object> map = new HashMap<>();
if (list==null) {
map.put("flag", false);
map.put("msg", "error");
return map;
}
map.put("flag", true);
map.put("data", list);
return map;
}
}

@ -1,11 +1,24 @@
package com.orangesale.cn.mapper;
import com.orangesale.cn.entity.OrangeShoppingCart;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* @Author zhijun
* @Date 2019/12/13
*/
@Mapper
public interface ShoppingCartMapper {
// 新增商品到购物车
public int insertCart(OrangeShoppingCart cart);
// 购物车商品数量
public int updateCart(OrangeShoppingCart cart);
// 查询购物车中所有商品
public List<OrangeShoppingCart> selectAll();
public List<OrangeShoppingCart> selectByUserId(Integer UserId);
}

@ -1,12 +1,34 @@
package com.orangesale.cn.service;
import com.orangesale.cn.entity.OrangeShoppingCart;
import com.orangesale.cn.mapper.ShoppingCartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author zhijun
* @Date 2019/12/13
*/
@Service
public class ShoppingCartService {
@Autowired
private ShoppingCartMapper shoppingCartMapper;
public int insertCart(OrangeShoppingCart cart){
return shoppingCartMapper.insertCart(cart);
}
public int updateCart(OrangeShoppingCart cart){
return shoppingCartMapper.updateCart(cart);
}
public List<OrangeShoppingCart> selectAll(){
return shoppingCartMapper.selectAll();
}
public List<OrangeShoppingCart> selectByUserId(Integer userId){
return shoppingCartMapper.selectByUserId(userId);
}
}

@ -15,4 +15,7 @@ spring.jackson.time-zone=GMT+8
uploadFilePath=D:/uploaded/
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=200MB
spring.servlet.multipart.max-request-size=200MB
logging.level.com.orangesale.cn.mapper=debug

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.orangesale.cn.mapper.ShoppingCartMapper">
<insert id="insertCart">
insert into orange_shoppingcart values (null,#{userId},#{productId},#{num})
</insert>
<update id="updateCart">
update orange_shoppingcart
set id=#{id}
</update>
<select id="selectAll" resultType="com.orangesale.cn.entity.OrangeShoppingCart">
select * from orange_shoppingcart
</select>
<select id="selectByUserId" resultType="com.orangesale.cn.entity.OrangeShoppingCart">
select * from orange_shoppingcart where user_id = #{userId}
</select>
</mapper>

@ -40,4 +40,5 @@ dependencies {
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'
implementation 'com.github.zzz40500:android-shapeLoadingView:1.0.3.2'
}

@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
@ -15,22 +14,14 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:targetApi="31">
<service
android:name=".service.MessageService"
android:exported="false"></service>
android:exported="false" />
<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" />
@ -40,6 +31,13 @@
<activity
android:name=".activity.registerActivity"
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>
</application>
</manifest>

@ -18,6 +18,7 @@ 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 com.example.test.utils.Address;
import java.io.IOException;
@ -29,6 +30,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Address.getImgIp("http:// :8081/uploaded/watermelon.png");
init();
}
@ -107,6 +109,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
bundle.putString("password",result.getPassword());
bundle.putString("sex",result.getSex());
bundle.putString("city",result.getCity());
bundle.putInt("id",result.getId());
intent.putExtras(bundle);
startActivity(intent);
}else{

@ -8,74 +8,71 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import com.example.test.R;
import com.example.test.adapter.homeNavigationBottomAdapter;
import com.example.test.entity.cart;
import com.example.test.entity.message;
import com.example.test.entity.product;
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.netrequest.cartOkHttp;
import com.example.test.netrequest.productOkHttp;
import com.example.test.service.MessageService;
import com.example.test.utils.Address;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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
};
public final int Navigation = 5;
private List<Bitmap> bitmapsList = new ArrayList<>();
private String[] names;
private double[] prices;
private String names[] = {"橙子","柚子","橘子","西瓜","香梨","苹果","柠檬","芒果"};
private double prices[] = {9.9,29.3,19.7,5.7,6.7,10.9,15.9,29.9};
private int [] ids;
private int position;
private navigationHomeFragment homeFragment = new navigationHomeFragment();
private navigationGoodFragment goodFragment = new navigationGoodFragment();
private navigationCartFragment cartFragment = new navigationCartFragment();
private navigationPersonFragment personFragment = new navigationPersonFragment();
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 FragmentManager getManager() {
return manager;
}
public int[] getImgs() {
return imgs;
}
public FragmentManager manager = getSupportFragmentManager();
private Bundle extras;
public String[] getNames() {
return names;
public int[] getIds() {
return ids;
}
public double[] getPrices() {
return prices;
public Handler getHandler() {
return handler;
}
public int[] getSectionImgs() {
@ -90,6 +87,51 @@ public class homeActivity extends AppCompatActivity {
return extras;
}
public List<Bitmap> getBitmapsList() {
return bitmapsList;
}
public void setBitmapsList(List<Bitmap> bitmapsList) {
this.bitmapsList = bitmapsList;
}
public String[] getNames() {
return names;
}
public void setNames(String[] names) {
this.names = names;
}
public double[] getPrices() {
return prices;
}
public void setPrices(double[] prices) {
this.prices = prices;
}
private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message message) {
switch (message.what){
case Good:
navigationGoodFragment goodFragment1 = (navigationGoodFragment) manager.findFragmentById(R.id.navigation_section);
goodFragment1.initGridview();
return true;
case Cart:
// 添加商品进购物车
Map<String,Object> map = (Map<String, Object>) message.obj;
position = (Integer) map.get("position");
new Thread(insertData).start();
case Navigation:
initNavigation();
changeFragment(homeFragment);
return true;
}
return false;
}
});
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -97,23 +139,29 @@ public class homeActivity extends AppCompatActivity {
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());
// initNavigation();
initData();
// 默认加载
}
public void initData() {
Thread thread = new Thread(getProducts);
thread.start();
}
public void initFragment(Fragment fragment){
public void changeFragment(Fragment fragment){
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.navigation_section,fragment);
transaction.commit();
}
protected void init(){
//初始化底端导航栏
protected void initNavigation(){
//初始化底端导航栏
GridView navigation = (GridView)findViewById(R.id.home_navigation_bottom_gridview);
homeNavigationBottomAdapter navigationAdapter = new homeNavigationBottomAdapter(sectionImgs,sectionNames,this);
navigation.setAdapter(navigationAdapter);
@ -122,21 +170,76 @@ public class homeActivity extends AppCompatActivity {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
initFragment(new navigationHomeFragment());
changeFragment(homeFragment);
break;
case 1:
initFragment(new navigationGoodFragment());
changeFragment(goodFragment);
break;
case 2:
initFragment(new navigationCartFragment());
changeFragment(cartFragment);
break;
case 3:
initFragment(new navigationPersonFragment());
changeFragment(personFragment);
break;
}
}
});
}
}
//获取产品信息
Runnable getProducts = 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<>();
List<Integer> idsList = new ArrayList<>();
if(products!=null){
for (product p : products) {
namesList.add(p.getName());
pricesList.add(p.getPrice());
String url = Address.getImgIp(p.getImgUrl());
bitmapsList.add(http.getImg(url));
idsList.add(p.getId());
}
names = namesList.toArray(new String[0]);
prices = pricesList.stream().mapToDouble(Double::doubleValue).toArray();
// bitmaps = bitmapsList.toArray(new Bitmap[0]);
ids = idsList.stream().mapToInt(Integer::intValue).toArray();
Message message1 = new Message();
message1.what = Navigation;
handler.sendMessage(message1);
}else
{
Message msg = new Message();
msg.what = 0;
handler.sendMessage(msg);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
Runnable insertData = new Runnable() {
@Override
public void run() {
cart c = new cart(null,extras.getInt("id"),ids[position],1);
cartOkHttp okHttp = new cartOkHttp();
try {
boolean b = okHttp.insertCart(c);
if(!b){
Looper.prepare();
Toast.makeText(homeActivity.this,"添加失败",Toast.LENGTH_SHORT).show();
Looper.loop();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}

@ -0,0 +1,81 @@
package com.example.test.adapter;
import android.content.Context;
import android.graphics.Bitmap;
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.cart;
import java.util.ArrayList;
import java.util.List;
public class cartAdapter extends BaseAdapter {
private List<Bitmap> bitmaps;
private List<String> names;
private List<Double> prices;
private List<Integer> nums;
private Context context;
public cartAdapter(List<Bitmap> bitmaps, List<String> names, List<Double> prices, List<Integer> nums, Context context) {
this.bitmaps = bitmaps;
this.names = names;
this.prices = prices;
this.nums = nums;
this.context = context;
}
@Override
public int getCount() {
return bitmaps.size();
}
@Override
public Object getItem(int i) {
List<Object> list = new ArrayList<>();
list.add(bitmaps.get(i));
list.add(names.get(i));
list.add(prices.get(i));
list.add(nums.get(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.cart_listview_item,null);
holder.ivImg = convertView.findViewById(R.id.cart_good_img);
holder.tvName = convertView.findViewById(R.id.cart_good_name);
holder.tvPrice = convertView.findViewById(R.id.cart_good_price);
holder.tvNum = convertView.findViewById(R.id.cart_good_num);
convertView.setTag(holder);
}else {
holder = (viewHolder) convertView.getTag();
}
// holder.ivImg.setImageResource(imgs[position]);
holder.ivImg.setImageBitmap(bitmaps.get(i));
holder.tvName.setText(names.get(i));
holder.tvPrice.setText(prices.get(i)+"");
holder.tvNum.setText(nums.get(i)+"");
return convertView;
}
static class viewHolder{
ImageView ivImg;
TextView tvName;
TextView tvPrice;
TextView tvNum;
}
}

@ -2,7 +2,10 @@ package com.example.test.adapter;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -23,19 +26,22 @@ public class homeGoodsFruitAdapter extends BaseAdapter {
private double prices[];
private List<Bitmap> bitmaps;
private Context context;
private Handler handler;
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) {
public homeGoodsFruitAdapter(List<Bitmap> bitmaps, String[] names, double[] prices, Context context, Handler handler) {
this.bitmaps = bitmaps;
this.names = names;
this.prices = prices;
this.context = context;
this.handler = handler;
}
@Override
@ -67,6 +73,18 @@ public class homeGoodsFruitAdapter extends BaseAdapter {
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);
holder.ivCart = convertView.findViewById(R.id.navigation_cart);
holder.ivCart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Map<String, Object> cartItem = new HashMap<>();
cartItem.put("position",position);
Message message = new Message();
message.what = 3;
message.obj = cartItem;
handler.sendMessage(message);
}
});
convertView.setTag(holder);
}else {
holder = (viewHolder) convertView.getTag();
@ -83,5 +101,6 @@ public class homeGoodsFruitAdapter extends BaseAdapter {
ImageView ivImg;
TextView tvName;
TextView tvPrice;
ImageView ivCart;
}
}

@ -0,0 +1,50 @@
package com.example.test.entity;
public class cart {
private Integer id;
private Integer userId;
private Integer productId;
private Integer num;
public cart(Integer id, Integer userId, Integer productId, Integer num) {
this.id = id;
this.userId = userId;
this.productId = productId;
this.num = num;
}
public cart() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
}

@ -1,33 +1,108 @@
package com.example.test.fragment;
import android.graphics.Bitmap;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;
import com.example.test.R;
import com.example.test.activity.homeActivity;
import com.example.test.adapter.cartAdapter;
import com.example.test.entity.cart;
import com.example.test.entity.product;
import com.example.test.netrequest.cartOkHttp;
import com.example.test.netrequest.productOkHttp;
import com.example.test.utils.Address;
public class navigationCartFragment extends Fragment {
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class navigationCartFragment extends Fragment {
private View view;
private View cartView;
private homeActivity activity;
private static List<Bitmap> bitmaps = new ArrayList<>();
private static List<String> names = new ArrayList<>();
private static List<Double> prices = new ArrayList<>();
private static List<Integer> nums = new ArrayList<>();
//加载动画 有东西的购物车 空的购物车
private int[] pages={R.layout.navigation_cart_loading,R.layout.navigation_cart, R.layout.navigation_cart_empty};
private static int index=0;
private ListView listView;
@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);
view = inflater.inflate(pages[index], container, false);
cartView = inflater.inflate(pages[1],null);
activity = (homeActivity) getActivity();
new Thread(getCartItem).start();
if(index==1){
initListview();
}else if(index==2){
goShopping();
}
return view;
}
private void goShopping() {
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());
activity.changeFragment(new navigationGoodFragment());
}
});
return view;
}
public void initListview(){
if(listView == null) {
listView = (ListView) cartView.findViewById(R.id.navigation_cart_listview);
}
listView.setAdapter(new cartAdapter(bitmaps,names,prices,nums,activity));
}
Runnable getCartItem = new Runnable() {
@Override
public void run() {
cartOkHttp cartOkHttp1 = new cartOkHttp();
productOkHttp productOkHttp1 = new productOkHttp();
try {
int userId = (Integer)activity.getBundle().get("id");
List<cart> carts = cartOkHttp1.selectByUserId(userId);
if(carts.size()==0){
index = 2;
activity.changeFragment(new navigationCartFragment());
//跳转到购物车为空页面
}else{
// 将获取到的数据分别添加到集合中
for (cart cart : carts) {
product p = productOkHttp1.getProductById(cart.getProductId());
names.add(p.getName());
String url = Address.getImgIp(p.getImgUrl());
Bitmap img = productOkHttp1.getImg(url);
bitmaps.add(img);
prices.add(p.getPrice());
nums.add(cart.getNum());
}
index = 1;
activity.changeFragment(new navigationCartFragment());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}

@ -1,12 +1,18 @@
package com.example.test.fragment;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -20,6 +26,7 @@ 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 com.example.test.utils.Address;
import java.io.IOException;
import java.util.ArrayList;
@ -37,6 +44,7 @@ public class navigationGoodFragment extends Fragment {
private homeActivity activity;
private View view;
private Handler handler;
private GridView goodGridview;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -45,52 +53,58 @@ public class navigationGoodFragment extends 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();
goodGridview = (GridView) view.findViewById(R.id.navigation_good_gridview);
initSpinner();
initData();
initGridview();
return view;
}
public void initView() {
GridView goodGridview = (GridView) view.findViewById(R.id.navigation_good_gridview);
homeGoodsFruitAdapter adapter = new homeGoodsFruitAdapter(bitmapsList, names, prices, activity);
public void initGridview() {
homeGoodsFruitAdapter adapter = new homeGoodsFruitAdapter(bitmapsList, names, prices, activity,handler);
goodGridview.setAdapter(adapter);
}
public void initSpinner(){
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);
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) {
}
});
DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
spinner.setDropDownWidth(metrics.widthPixels);
}
public void initData(){
names = activity.getNames();
prices = activity.getPrices();
bitmapsList = activity.getBitmapsList();
}
public void handleData(List<product> list, productOkHttp http) throws IOException {
List<String> namesList = new ArrayList<>();
@ -99,7 +113,8 @@ public class navigationGoodFragment extends Fragment {
for (product p : list) {
namesList.add(p.getName());
pricesList.add(p.getPrice());
bitmapsList.add(http.getImg(p.getImgUrl()));
String url = Address.getImgIp(p.getImgUrl());
bitmapsList.add(http.getImg(url));
}
names = namesList.toArray(new String[0]);
prices = pricesList.stream().mapToDouble(Double::doubleValue).toArray();
@ -115,68 +130,13 @@ public class navigationGoodFragment extends Fragment {
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);
}
handleData(products,http);
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -188,38 +148,20 @@ public class navigationGoodFragment extends Fragment {
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);
}
handleData(products,productOkHttp);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
// Runnable runnable3 = new Runnable() {
// @Override
// public void run() {
//
// }
// };
Runnable runnable3 = new Runnable() {
@Override
public void run() {
}
};
// 价格排序

@ -4,33 +4,46 @@ import android.graphics.Bitmap;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
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.cart;
import com.example.test.entity.message;
import com.example.test.entity.product;
import com.example.test.netrequest.cartOkHttp;
import com.example.test.netrequest.productOkHttp;
import com.example.test.utils.Address;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class navigationHomeFragment extends Fragment {
private String names[] = {};
private int imgs[] = {};
private double prices[] = {};
private List<Bitmap> bitmapsList = new ArrayList<>();
private int ids[];
private homeActivity activity;
private int productIDNow;
private View view;
private Handler handler;
@ -38,69 +51,81 @@ public class navigationHomeFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
Thread thread = new Thread(runnable);
thread.start();
Log.i("home", this + "");
view = inflater.inflate(R.layout.navigation_home, container, false);
activity =(homeActivity)getActivity();
activity = (homeActivity) getActivity();
handler = activity.getHandler();
//initData();
// init(view);
initData();
initGridview();
return view;
}
private void initData() {
names = activity.getNames();
imgs = activity.getImgs();
prices = activity.getPrices();
}
public void init() {
public void initGridview() {
//初始化商品种类
GridView kindGridview = (GridView)view.findViewById(R.id.fruit_kind_gridview);
GridView kindGridview = (GridView) view.findViewById(R.id.fruit_kind_gridview);
// homeFruitKindAdapter kindAdapter = new homeFruitKindAdapter(imgs,names,activity);
homeFruitKindAdapter kindAdapter = new homeFruitKindAdapter(bitmapsList,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);
homeGoodsFruitAdapter fruitAdapter = new homeGoodsFruitAdapter(bitmapsList, names, prices, activity,handler);
fruitGridview.setAdapter(fruitAdapter);
fruitGridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.i("shopping",view+"");
switch (view.getId()){
case R.id.navigation_cart:
Log.i("listener","enter");
// 将商品显示在购物车中
productIDNow = ids[i];
Message message = new Message();
message.what = activity.Cart;
Map<String, Object> map = new HashMap<>();
map.put("img",bitmapsList.get(i));
map.put("name",names[i]);
map.put("price",prices[i]);
message.obj = map;
handler.sendMessage(message);
// 将信息添加至数据库
Thread thread = new Thread(insertCart);
thread.start();
}
}
});
}
Runnable runnable = new Runnable() {
public void initData() {
names = activity.getNames();
prices = activity.getPrices();
bitmapsList = activity.getBitmapsList();
ids = activity.getIds();
}
Runnable insertCart = new Runnable() {
@Override
public void run() {
int index = 0;
productOkHttp http = new productOkHttp();
cartOkHttp OkHttp = new cartOkHttp();
cart c = new cart(null,activity.getBundle().getInt("id"),productIDNow,1);
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);
boolean b = OkHttp.insertCart(c);
if(!b){
Looper.prepare();
Toast.makeText(activity,"添加失败",Toast.LENGTH_SHORT).show();
Looper.loop();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}
}

@ -0,0 +1,73 @@
package com.example.test.netrequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.example.test.entity.cart;
import com.example.test.utils.Address;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import okhttp3.ConnectionPool;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class cartOkHttp {
private OkHttpClient okHttpClient = new OkHttpClient();
public List<cart> selectAll() throws IOException {
Request request = new Request.Builder()
.url("http://" + Address.ip + ":8081/orange/shoppingCart/search")
.build();
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(response.body().string());
String data = jsonObject.getString("data");
List<cart> carts = JSON.parseObject(data, new TypeReference<List<cart>>() {
});
return carts;
}
public List<cart> selectByUserId(int userId) throws IOException {
RequestBody requestBody = RequestBody.create(userId+"",MediaType.parse("application/json;charset=UTF-8"));
Request request = new Request.Builder()
.url("http://" + Address.ip + ":8081/orange/shoppingCart/searchByUserId")
.post(requestBody)
.build();
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(response.body().string());
String data = jsonObject.getString("data");
List<cart> carts = JSON.parseObject(data, new TypeReference<List<cart>>() {
});
return carts;
}
public boolean insertCart(cart c) throws IOException {
String data = JSONObject.toJSONString(c);
RequestBody requestBody = RequestBody.create(data,MediaType.parse("application/json;charset=UTF-8"));
Request request = new Request.Builder()
.url("http://"+Address.ip+":8081/orange/shoppingCart/insert")
.post(requestBody)
.build();
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(response.body().string());
return jsonObject.getBoolean("flag");
}
public boolean updateCart(cart c) throws IOException {
OkHttpClient client = new OkHttpClient();
String data = JSONObject.toJSONString(c);
RequestBody requestBody = RequestBody.create(data,MediaType.parse("application/json;charset=UTF-8"));
Request request = new Request.Builder()
.url("http://"+Address.ip+":8081/orange/shoppingCart/update")
.post(requestBody)
.build();
Response response = client.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(response.body().string());
return jsonObject.getBoolean("flag");
}
}

@ -3,10 +3,10 @@ package com.example.test.netrequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.test.entity.message;
import com.example.test.utils.Address;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
@ -15,16 +15,16 @@ public class messageOkHttp {
public message getMessage() throws IOException {
// 获取消息
OkHttpClient okHttpClient = new OkHttpClient();
message data = null;
Request request = new Request.Builder()
.url("http://192.168.43.226:8081/orange/message/consumeMessage")
.url("http://"+ Address.ip+":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);
data = JSON.parseObject(jsonObject.getString("data"), message.class);
// 将获取到的消息设为已用
Request comsume = new Request.Builder()
.url("http://192.168.43.226:8081/orange/message/updateMessage")
.url("http://"+Address.ip+":8081/orange/message/updateMessage")
.build();
Response execute = okHttpClient.newCall(comsume).execute();
return data;

@ -8,12 +8,13 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.example.test.entity.product;
import com.example.test.utils.Address;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@ -21,9 +22,8 @@ import okhttp3.RequestBody;
import okhttp3.Response;
public class productOkHttp {
private OkHttpClient okHttpClient = new OkHttpClient();
public Bitmap getImg(String imgUrl) throws IOException {
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder()
.url(imgUrl)
// .addHeader("Connection", "keep-alive")
@ -35,26 +35,41 @@ public class productOkHttp {
return bitmap;
}
public product getProductById(int productId) throws IOException {
RequestBody requestBody = RequestBody.create(productId+"", MediaType.parse("application/json;charset=UTF-8"));
Request request = new Request.Builder()
.url("http://"+ Address.ip +":8081/orange/product/searchById")
.post(requestBody)
.build();
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(response.body().string());
String data = jsonObject.getString("data");
product p = JSON.parseObject(data, product.class);
return p;
}
//获取商品
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")
.url("http://"+ Address.ip +":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")
.url("http://"+Address.ip+":8081/orange/product/time")
.build();
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(response.body().string());
@ -65,9 +80,8 @@ public class productOkHttp {
}
// 价格排序
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")
.url("http://"+Address.ip+":8081/orange/product/price")
.build();
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(response.body().string());
@ -79,20 +93,16 @@ public class productOkHttp {
// 上传图片
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")
.url("http://"+Address.ip+":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;
}
Response response = okHttpClient.newCall(request).execute();
JSONObject jsonObject = JSON.parseObject(response.body().string());
return jsonObject.getBoolean("flag");
}

@ -2,7 +2,9 @@ package com.example.test.netrequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.test.MainActivity;
import com.example.test.entity.user;
import com.example.test.utils.Address;
import java.io.IOException;
@ -22,7 +24,7 @@ public class userOkHttp {
MediaType type = MediaType.parse("application/json;charset=utf-8");
RequestBody requestBody = RequestBody.create(JSONString, type);
Request request = new Request.Builder()
.url("http://192.168.43.226:8081/orange/user/login")
.url("http://"+ Address.ip+":8081/orange/user/login")
.post(requestBody)
.build();
Response response = okHttpClient.newCall(request).execute();
@ -38,7 +40,7 @@ public class userOkHttp {
MediaType type = MediaType.parse("application/jsoncharset=utf-8");
RequestBody requestBody = RequestBody.create(jsonString, type);
Request request = new Request.Builder()
.url("http://192.168.43.226:8081/orange/user/register")
.url("http://"+Address.ip+":8081/orange/user/register")
.post(requestBody)
.build();
Response response = okHttpClient.newCall(request).execute();

@ -0,0 +1,19 @@
package com.example.test.utils;
import android.util.Log;
public class Address {
public static String ip = "192.168.64.1";
public static String getImgIp(String url){
StringBuilder sb = new StringBuilder();
String[] result = url.split(" ");
for (int i = 0; i < result.length; i++) {
if(i==1){
sb.append(ip).append(result[i]);
}else{
sb.append(result[i]);
}
}
return sb.toString();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 891 B

After

Width:  |  Height:  |  Size: 775 B

@ -0,0 +1,9 @@
<?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"
tools:context=".utils.address">
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<ImageView
android:id="@+id/cart_good_img"
android:layout_width="100dp"
android:layout_height="120dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="vertical">
<TextView
android:id="@+id/cart_good_name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="30dp"
android:gravity="center"/>
<TextView
android:id="@+id/cart_good_price"
android:layout_width="match_parent"
android:layout_height="30dp"
android:textSize="20dp"
android:gravity="center"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="220dp">
<ImageButton
android:id="@+id/cart_good_add"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/add"
android:layout_gravity="center"
android:background="@color/white"/>
<TextView
android:id="@+id/cart_good_num"
android:layout_width="40dp"
android:layout_height="40dp"
android:textSize="25dp"
android:gravity="center"/>
<ImageButton
android:id="@+id/cart_good_minus"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="@drawable/reduce"
android:background="@color/white"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

@ -15,10 +15,21 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="20dp"/>
<TextView
android:id="@+id/home_goods_fruit_price"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="20dp"/>
android:gravity="center">
<TextView
android:id="@+id/home_goods_fruit_price"
android:layout_marginLeft="30dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="20dp"/>
<ImageView
android:id="@+id/navigation_cart"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/cart"/>
</LinearLayout>
</LinearLayout>

@ -4,53 +4,8 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white">
<LinearLayout
<ListView
android:id="@+id/navigation_cart_listview"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/orange">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:src="@drawable/arrow_right"
android:rotation="180"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="购物车"
android:layout_weight="10"
android:gravity="center"
android:textColor="@color/white"
android:textSize="20dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingTop="150dp">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/cart"
android:layout_marginBottom="10dp"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="购物车是空的~"
android:textSize="20dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center"/>
<Button
android:id="@+id/navigation_cart_shopping"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="去逛逛"
android:textSize="20dp"
android:background="@color/orange"
android:layout_gravity="center"/>
</LinearLayout>
android:layout_height="wrap_content"/>
</LinearLayout>

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/orange">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:src="@drawable/arrow_right"
android:rotation="180"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="购物车"
android:layout_weight="10"
android:gravity="center"
android:textColor="@color/white"
android:textSize="20dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingTop="150dp">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/cart"
android:layout_marginBottom="10dp"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="购物车是空的~"
android:textSize="20dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center"/>
<Button
android:id="@+id/navigation_cart_shopping"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="去逛逛"
android:textSize="20dp"
android:background="@color/orange"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>

@ -0,0 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="@color/white">
<com.mingle.widget.LoadingView
android:id="@+id/loadView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>

@ -4,10 +4,11 @@
android:layout_height="match_parent">
<ImageView
android:id="@+id/good_spinner_img"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/all"
android:layout_marginRight="10dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_gravity="center"/>
<TextView
android:id="@+id/good_spinner_desc"

@ -2,4 +2,5 @@
<string name="app_name">用户注册</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="ip">192.168.1.126</string>
</resources>
Loading…
Cancel
Save