diff --git a/OrangeSale/app/src/main/java/com/example/orangesale_02/IndexActivity.java b/OrangeSale/app/src/main/java/com/example/orangesale_02/IndexActivity.java new file mode 100644 index 0000000..6ec2bec --- /dev/null +++ b/OrangeSale/app/src/main/java/com/example/orangesale_02/IndexActivity.java @@ -0,0 +1,120 @@ +package com.example.orangesale_02.activity; + +import android.app.Activity; +import android.app.FragmentTransaction; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.LinearLayout; + +import androidx.annotation.Nullable; + +import com.example.orangesale_02.R; +import com.example.orangesale_02.fragment.IndexFragment; +import com.example.orangesale_02.fragment.PearsonFragment; +import com.example.orangesale_02.fragment.ProductFragment; +import com.example.orangesale_02.fragment.ShoppingCartFragment; + +public class IndexActivity extends Activity implements View.OnClickListener { + private IndexFragment indexFragment; + private ProductFragment productFragment; + private ShoppingCartFragment shoppingCartFragment; + private PearsonFragment pearsonFragment; + private LinearLayout indexLine, productLine, shoppingCartLine, pearsonLine; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + init(); + initIndexFragment(); + } + + /** + * 组件初始化 + */ + private void init() { + indexLine = findViewById(R.id.content_index); + indexLine.setOnClickListener(this); + productLine = findViewById(R.id.content_product); + productLine.setOnClickListener(this); + shoppingCartLine = findViewById(R.id.content_cart); + shoppingCartLine.setOnClickListener(this); + pearsonLine = findViewById(R.id.content_pearson); + pearsonLine.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.content_index: + initIndexFragment(); + break; + case R.id.content_product: + initproductFragment(); + break; + case R.id.content_cart: + initshoppingCartFragment(); + break; + case R.id.content_pearson: + initpearsonFragment(); + break; + } + } + + /** + * 初始化首页Fragment + */ + private void initIndexFragment() { + //开启事务,fragment的控制是由事务来实现的 + FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (indexFragment == null) { + indexFragment = new IndexFragment(); + } + transaction.replace(R.id.main_content, indexFragment); + transaction.commit(); + } + + /** + * 初始化产品Fragment + */ + private void initproductFragment() { + //开启事务,fragment的控制是由事务来实现的 + FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (productFragment == null) { + productFragment = new ProductFragment(); + } + transaction.replace(R.id.main_content, productFragment); + transaction.commit(); + } + + /** + * 初始化购物车Fragment + */ + private void initshoppingCartFragment() { + //开启事务,fragment的控制是由事务来实现的 + FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (shoppingCartFragment == null) { + shoppingCartFragment = new ShoppingCartFragment(); + } + transaction.replace(R.id.main_content, shoppingCartFragment); + transaction.commit(); + } + + /** + * 初始化个人Fragment + */ + private void initpearsonFragment() { + //开启事务,fragment的控制是由事务来实现的 + FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (pearsonFragment == null) { + Intent intent = IndexActivity.this.getIntent(); + Bundle bundle = intent.getExtras(); + pearsonFragment = new PearsonFragment(); + pearsonFragment.setArguments(bundle); + } + transaction.replace(R.id.main_content, pearsonFragment); + transaction.commit(); + } + +} diff --git a/OrangeSale/app/src/main/java/com/example/orangesale_02/Adapter.java b/OrangeSale/app/src/main/java/com/example/orangesale_02/adapter/Adapter.java similarity index 100% rename from OrangeSale/app/src/main/java/com/example/orangesale_02/Adapter.java rename to OrangeSale/app/src/main/java/com/example/orangesale_02/adapter/Adapter.java diff --git a/OrangeSale/app/src/main/java/com/example/orangesale_02/adapter/ProductAdapter.java b/OrangeSale/app/src/main/java/com/example/orangesale_02/adapter/ProductAdapter.java new file mode 100644 index 0000000..af7a220 --- /dev/null +++ b/OrangeSale/app/src/main/java/com/example/orangesale_02/adapter/ProductAdapter.java @@ -0,0 +1,68 @@ +package com.example.orangesale_05.adapter; + +import android.content.Context; +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.orangesale_05.R; +import com.example.orangesale_05.entity.Product; + +import java.util.List; + +public class ProductAdapter extends BaseAdapter { + private List productList; + private LayoutInflater layoutInflater; + + public ProductAdapter(Context context, List productList) { + this.productList = productList; + this.layoutInflater = LayoutInflater.from(context); + } + + @Override + public int getCount() { + return productList.size(); + } + + @Override + public Object getItem(int position) { + return productList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + convertView = layoutInflater.inflate(R.layout.categoty_detail_content, null); + viewHolder = new ViewHolder(); + viewHolder.productImage = convertView.findViewById(R.id.category_product_image); + viewHolder.productName = convertView.findViewById(R.id.category_product_name); + viewHolder.productPrice = convertView.findViewById(R.id.category_product_price); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + Product product = productList.get(position); + Log.i("product", "getView: "+product.toString()); + if (product != null) { + viewHolder.productImage.setBackgroundResource(product.getImageUrlId()); + viewHolder.productName.setText(product.getProductName()); + viewHolder.productPrice.setText(String.valueOf(product.getProductPrice())); + } + return convertView; + } + + class ViewHolder { + ImageView productImage; + TextView productName, productPrice; + } +} diff --git a/OrangeSale/app/src/main/java/com/example/orangesale_02/OrangeUser.java b/OrangeSale/app/src/main/java/com/example/orangesale_02/entity/OrangeUser.java similarity index 100% rename from OrangeSale/app/src/main/java/com/example/orangesale_02/OrangeUser.java rename to OrangeSale/app/src/main/java/com/example/orangesale_02/entity/OrangeUser.java diff --git a/OrangeSale/app/src/main/java/com/example/orangesale_02/entity/Product.java b/OrangeSale/app/src/main/java/com/example/orangesale_02/entity/Product.java new file mode 100644 index 0000000..69453a8 --- /dev/null +++ b/OrangeSale/app/src/main/java/com/example/orangesale_02/entity/Product.java @@ -0,0 +1,43 @@ +package com.example.orangesale_05.entity; + +import java.math.BigDecimal; + +public class Product { + + public String getProductName() { + return productName; + } + + public void setProductName(String productName) { + this.productName = productName; + } + + public BigDecimal getProductPrice() { + return productPrice; + } + + public void setProductPrice(BigDecimal productPrice) { + this.productPrice = productPrice; + } + + public Integer getImageUrlId() { + return imageUrlId; + } + + public void setImageUrlId(Integer imageUrlId) { + this.imageUrlId = imageUrlId; + } + + private Integer imageUrlId; + private String productName; + private BigDecimal productPrice; + + @Override + public String toString() { + return "Product{" + + "imageUrlId=" + imageUrlId + + ", productName='" + productName + '\'' + + ", productPrice=" + productPrice + + '}'; + } +} diff --git a/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/IndexFragment.java b/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/IndexFragment.java new file mode 100644 index 0000000..8c52473 --- /dev/null +++ b/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/IndexFragment.java @@ -0,0 +1,109 @@ +package com.example.orangesale_05.fragment; + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.GridView; +import android.widget.LinearLayout; +import android.widget.SearchView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.orangesale_05.R; +import com.example.orangesale_05.adapter.ProductAdapter; +import com.example.orangesale_05.entity.Product; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +public class IndexFragment extends Fragment implements View.OnClickListener { + private SearchView searchView; + private LinearLayout orangeLine, youziLine, juziLine, xiguaLine, liLine, appleLine, lemonLine, mangguoLine; + private GridView gridView; + private List productList; + private ProductAdapter productAdapter; + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_index, container, false); + init(view); + return view; + } + + /** + * 初始化组件 + */ + private void init(View view) { + searchView = view.findViewById(R.id.searchView); + searchView.setOnClickListener(this); + orangeLine = view.findViewById(R.id.chengzi); + orangeLine.setOnClickListener(this); + youziLine = view.findViewById(R.id.youzi); + youziLine.setOnClickListener(this); + juziLine = view.findViewById(R.id.juzi); + juziLine.setOnClickListener(this); + xiguaLine = view.findViewById(R.id.xigua); + xiguaLine.setOnClickListener(this); + liLine = view.findViewById(R.id.li); + liLine.setOnClickListener(this); + lemonLine = view.findViewById(R.id.lemon); + lemonLine.setOnClickListener(this); + mangguoLine = view.findViewById(R.id.mangguo); + mangguoLine.setOnClickListener(this); + appleLine = view.findViewById(R.id.apple); + appleLine.setOnClickListener(this); + gridView = view.findViewById(R.id.index_famous_gridview); + initData(); + productAdapter = new ProductAdapter(getActivity(), productList); + gridView.setAdapter(productAdapter); + } + + + @Override + public void onClick(View v) { + + } + + /** + * 初始化商品数据 + */ + private void initData() { + productList = new ArrayList<>(); + Product product = new Product(); + product.setImageUrlId(R.drawable.juzip); + product.setProductName("橘子"); + product.setProductPrice(new BigDecimal("9.9")); + Product product1 = new Product(); + product1.setImageUrlId(R.drawable.orange); + product1.setProductName("橙子"); + product1.setProductPrice(new BigDecimal("29.9")); + Product product2 = new Product(); + product2.setImageUrlId(R.drawable.youzip); + product2.setProductName("柚子"); + product2.setProductPrice(new BigDecimal("19.9")); + Product product3 = new Product(); + product3.setImageUrlId(R.drawable.xiguap); + product3.setProductName("西瓜"); + product3.setProductPrice(new BigDecimal("19.9")); + Product product4 = new Product(); + product4.setImageUrlId(R.drawable.applep); + product4.setProductName("苹果"); + product4.setProductPrice(new BigDecimal("49.9")); + Product product5 = new Product(); + product5.setImageUrlId(R.drawable.lemonp); + product5.setProductName("柠檬"); + product5.setProductPrice(new BigDecimal("9.9")); + productList.add(product); + productList.add(product1); + productList.add(product2); + productList.add(product3); + productList.add(product4); + productList.add(product5); + + } +} diff --git a/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/PearsonFragment.java b/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/PearsonFragment.java new file mode 100644 index 0000000..687895d --- /dev/null +++ b/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/PearsonFragment.java @@ -0,0 +1,64 @@ +package com.example.orangesale_05.fragment; + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.orangesale_05.R; + +public class PearsonFragment extends Fragment implements View.OnClickListener { + private ImageView userIconImage; + private TextView usernameText, userSexText, userCityText; + private LinearLayout usernameLine, userSexline, userCityLine, userPayLine, userSettingLine, userGeneralLine; + + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_user, container, false); + init(view); + return view; + } + + /** + * 组件初始化 + */ + private void init(View view) { + userIconImage = view.findViewById(R.id.user_icon); + usernameText = view.findViewById(R.id.user_username); + userSexText = view.findViewById(R.id.user_sex); + userCityText = view.findViewById(R.id.user_city); + usernameLine = view.findViewById(R.id.user_username_line); + userSexline = view.findViewById(R.id.user_sex_line); + userCityLine = view.findViewById(R.id.user_city_line); + userPayLine = view.findViewById(R.id.user_pay); + userSettingLine = view.findViewById(R.id.user_setting); + userGeneralLine = view.findViewById(R.id.user_general); + setData(); + } + + /** + * 组件赋值 + */ + private void setData() { + Bundle bundle = getArguments(); + usernameText.setText(String.format("用户名:%s", bundle.getString("username"))); + userSexText.setText(String.format("性别:%s", bundle.getString("sex"))); + userCityText.setText(String.format("城市:%s", bundle.getString("city"))); + } + + @Override + public void onClick(View v) { + + } + + +} diff --git a/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/ProductFragment.java b/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/ProductFragment.java new file mode 100644 index 0000000..f8dab79 --- /dev/null +++ b/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/ProductFragment.java @@ -0,0 +1,21 @@ +package com.example.orangesale_05.fragment; + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.orangesale_05.R; + +public class ProductFragment extends Fragment { + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_product, container, false); + return view; + } +} diff --git a/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/ShoppingCartFragment.java b/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/ShoppingCartFragment.java new file mode 100644 index 0000000..46cc0e3 --- /dev/null +++ b/OrangeSale/app/src/main/java/com/example/orangesale_02/fragment/ShoppingCartFragment.java @@ -0,0 +1,21 @@ +package com.example.orangesale_05.fragment; + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.orangesale_05.R; + +public class ShoppingCartFragment extends Fragment { + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_shopping, container, false); + return view; + } +} diff --git a/OrangeSale/app/src/main/res/drawable-v24/shop_car.png b/OrangeSale/app/src/main/res/drawable-v24/shop_car.png deleted file mode 100644 index 8851375..0000000 Binary files a/OrangeSale/app/src/main/res/drawable-v24/shop_car.png and /dev/null differ diff --git a/OrangeSale/app/src/main/res/drawable-v24/xigua.png b/OrangeSale/app/src/main/res/drawable-v24/xigua.png deleted file mode 100644 index b6d8404..0000000 Binary files a/OrangeSale/app/src/main/res/drawable-v24/xigua.png and /dev/null differ diff --git a/OrangeSale/app/src/main/res/drawable/index.png b/OrangeSale/app/src/main/res/drawable/index.png new file mode 100644 index 0000000..cc1ec04 Binary files /dev/null and b/OrangeSale/app/src/main/res/drawable/index.png differ diff --git a/OrangeSale/app/src/main/res/drawable/index_menu.xml b/OrangeSale/app/src/main/res/drawable/index_menu.xml new file mode 100644 index 0000000..14636dd --- /dev/null +++ b/OrangeSale/app/src/main/res/drawable/index_menu.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OrangeSale/app/src/main/res/layout/content_index.xml b/OrangeSale/app/src/main/res/layout/content_index.xml new file mode 100644 index 0000000..7fa926d --- /dev/null +++ b/OrangeSale/app/src/main/res/layout/content_index.xml @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OrangeSale/app/src/main/res/layout/content_nav.xml b/OrangeSale/app/src/main/res/layout/content_nav.xml new file mode 100644 index 0000000..2b6b43b --- /dev/null +++ b/OrangeSale/app/src/main/res/layout/content_nav.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OrangeSale/app/src/main/res/layout/content_product.xml b/OrangeSale/app/src/main/res/layout/content_product.xml new file mode 100644 index 0000000..c946607 --- /dev/null +++ b/OrangeSale/app/src/main/res/layout/content_product.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/OrangeSale/app/src/main/res/layout/content_shopping.xml b/OrangeSale/app/src/main/res/layout/content_shopping.xml new file mode 100644 index 0000000..e152fbb --- /dev/null +++ b/OrangeSale/app/src/main/res/layout/content_shopping.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/OrangeSale/app/src/main/res/layout/index_famous.xml b/OrangeSale/app/src/main/res/layout/index_famous.xml new file mode 100644 index 0000000..b884b44 --- /dev/null +++ b/OrangeSale/app/src/main/res/layout/index_famous.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file