diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml new file mode 100644 index 0000000..760be05 --- /dev/null +++ b/main/AndroidManifest.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/java/com/example/test1/Database.java b/main/java/com/example/test1/Database.java new file mode 100644 index 0000000..df3b1a7 --- /dev/null +++ b/main/java/com/example/test1/Database.java @@ -0,0 +1,69 @@ +package com.example.test1; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.os.Bundle; + +import androidx.annotation.Nullable; + +public class Database extends SQLiteOpenHelper{ + public Database(@Nullable Context context) { + super(context, "orange.db3", null, 1); + } + + @Override + public void onCreate(SQLiteDatabase db) { + //创建用户表 + String sql = "create table orange_user(id integer primary key autoincrement, username varchar(50), password varchar(50),sex varchar(10),city carchar(50))"; + db.execSQL(sql); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + } + + /** + * 插入数据 + * + * @param sqLiteDatabase + * @param username + * @param password + * @param sex + * @param city + */ + public void insertUser(SQLiteDatabase sqLiteDatabase, String username, String password, String sex, String city) { + ContentValues contentValues = new ContentValues(); + contentValues.put("username", username); + contentValues.put("password", password); + contentValues.put("sex", sex); + contentValues.put("city", city); + sqLiteDatabase.insert("orange_user", null, contentValues); + sqLiteDatabase.close(); + } + + /** + * 查询数据 + * + * @param sqLiteDatabase + * @param bundle + * @return + */ + public Bundle queryUserInfo(SQLiteDatabase sqLiteDatabase, Bundle bundle) { + String username = bundle.getString("username"); + Cursor cursor = sqLiteDatabase.rawQuery("select * from orange_user where username=?", new String[]{username}); + if (cursor != null) { + while (cursor.moveToNext()) { + bundle.putString("sex", cursor.getString(3)); + bundle.putString("city", cursor.getString(4)); + } + } + cursor.close(); + sqLiteDatabase.close(); + return bundle; + } +} + diff --git a/main/java/com/example/test1/Fragment.java b/main/java/com/example/test1/Fragment.java new file mode 100644 index 0000000..c148b15 --- /dev/null +++ b/main/java/com/example/test1/Fragment.java @@ -0,0 +1,43 @@ +package com.example.test1; + +import android.os.Bundle; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; + +public class Fragment extends FragmentActivity { + + private String tilte[]={"秀珍","小河","厘普","张田中","多栋"}; + private String settingText[][]={{"秀珍"," 秀珍是微博漫画作者暹罗厘普创作的漫画人物之一。秀珍是一个捉摸不透、精神不稳定的粉红兔子。爱吃麦当劳,喜欢人类,最怕暹罗厘普说它罗圈腿。"}, + {"小河"," 小河是微博漫画作者暹罗厘普创作的漫画人物之一。小河是一个嘴巴大大、脚掌大大的鹈鹕。小河见到张田中的第一眼差点把它当小零食吃掉,说话只会“呱呱呱”,喜欢啃秀珍的脑袋,可能是重庆鹈鹕吧。"}, + {"厘普"," 厘普是微博漫画作者暹罗厘普创作的漫画人物之一。厘普是一个阴阳怪气、爱打退堂鼓的暹罗猫猫。爱拉屎,爱耍酷,跟多栋是猫朋狗友,两个人天天干些奇奇怪怪的事。"}, + {"张田中"," 张田中是微博漫画作者暹罗厘普创作的漫画人物之一。张田中是一个从超市死里逃生的胡萝卜,田中有些内向,只跟秀珍玩。咱也不知道一个胡萝卜怎么喜欢和兔子玩,hhhhhh……"}, + {"多栋"," 多栋是微博漫画作者暹罗厘普创作的漫画人物之一。多栋是一个下三白、爱摆烂的比格犬。爱吃肯德基,爱吃罐罐的,喜欢和厘普打架。"}}; + //获取标题数组的方法 + public String[] getTilte(){ + + return tilte; + } + //获取标题和内容 + public String[][] getSettingText(){ + + return settingText; + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.fragment); + //创建Fragment + SetTitleFragment titleFragment=new SetTitleFragment(); + SetContentFragment setcontentFragment=new SetContentFragment(); + //获取事物 + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction transaction = fragmentManager.beginTransaction(); + //添加Fragment + transaction.replace(R.id.settitle,titleFragment); + transaction.replace(R.id.setcontent,setcontentFragment); + //提交事物 + transaction.commit(); + } +} + diff --git a/main/java/com/example/test1/IndexActivity.java b/main/java/com/example/test1/IndexActivity.java new file mode 100644 index 0000000..856a967 --- /dev/null +++ b/main/java/com/example/test1/IndexActivity.java @@ -0,0 +1,120 @@ +package com.example.test1; + +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.test1.fragment.IndexFragment; +import com.example.test1.fragment.PearsonFragment; +import com.example.test1.fragment.ProductFragment; +import com.example.test1.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/main/java/com/example/test1/LoginActivity.java b/main/java/com/example/test1/LoginActivity.java new file mode 100644 index 0000000..7d9eddc --- /dev/null +++ b/main/java/com/example/test1/LoginActivity.java @@ -0,0 +1,30 @@ +package com.example.test1; + +import androidx.appcompat.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.content.Intent; +import android.widget.Button; +import android.widget.*; + +public class LoginActivity extends AppCompatActivity { + Button button = null; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.user_login); + button = (Button)findViewById(R.id.register); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + intent.setClass(LoginActivity.this,RegisterActivity.class); + startActivity(intent); + } + }); + } + +} + + diff --git a/main/java/com/example/test1/MainActivity.java b/main/java/com/example/test1/MainActivity.java new file mode 100644 index 0000000..3527ddc --- /dev/null +++ b/main/java/com/example/test1/MainActivity.java @@ -0,0 +1,76 @@ +package com.example.test1; + +import android.content.Intent; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +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.user_login); + + init(); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.register: + Intent intent = new Intent(MainActivity.this, RegisterActivity.class); + startActivity(intent); + break; + case R.id.login: + //注册时,我们引入了数据库,登录这里可以通过数据库进行验证,验证跳转到首页,不通过进行提示 + if (validateLogin()) { + Intent intent1 = new Intent(MainActivity.this, IndexActivity.class); + Bundle bundle = new Bundle(); + Database orangeDatabase = new Database(MainActivity.this); + bundle.putString("username", usernameText.getText().toString()); + bundle = orangeDatabase.queryUserInfo(orangeDatabase.getReadableDatabase(), bundle); + intent1.putExtras(bundle); + startActivity(intent1); + } else { + Toast.makeText(MainActivity.this, "账号或者密码错误", Toast.LENGTH_SHORT).show(); + } + break; + } + } + + //界面组件初始化 + private void init() { + usernameText = findViewById(R.id.username); + paswdEdit = findViewById(R.id.password); + loginButton = findViewById(R.id.login); + loginButton.setOnClickListener(this); + registerButton = findViewById(R.id.register); + registerButton.setOnClickListener(this); + } + + /** + * 登录验证 + * + * @return + */ + private boolean validateLogin() { + String username = usernameText.getText().toString(); + String password = paswdEdit.getText().toString(); + Database Database = new Database(MainActivity.this); + SQLiteDatabase sqLiteDatabase = Database.getReadableDatabase(); + Cursor cursor = sqLiteDatabase.rawQuery("select * from orange_user where username=? and password=?", new String[]{username, password}); + if (cursor.getCount() > 0) { + return true; + } + return false; + } +} diff --git a/main/java/com/example/test1/Product.java b/main/java/com/example/test1/Product.java new file mode 100644 index 0000000..53260f5 --- /dev/null +++ b/main/java/com/example/test1/Product.java @@ -0,0 +1,43 @@ +package com.example.test1; + +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 + + '}'; + } +} \ No newline at end of file diff --git a/main/java/com/example/test1/ProductAdapter.java b/main/java/com/example/test1/ProductAdapter.java new file mode 100644 index 0000000..45fc97e --- /dev/null +++ b/main/java/com/example/test1/ProductAdapter.java @@ -0,0 +1,66 @@ +package com.example.test1; + +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 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.category_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/main/java/com/example/test1/RegisterActivity.java b/main/java/com/example/test1/RegisterActivity.java new file mode 100644 index 0000000..f6a1fdb --- /dev/null +++ b/main/java/com/example/test1/RegisterActivity.java @@ -0,0 +1,134 @@ +package com.example.test1; + +import androidx.appcompat.app.AppCompatActivity; + +import android.annotation.SuppressLint; +import android.content.ContentValues; +import android.os.Bundle; +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 android.content.Intent; +import android.database.sqlite.SQLiteDatabase; + +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; + +public class RegisterActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener{ + private Button btn; + private EditText reg_username; + private EditText reg_password; + private EditText reg_sure_password; + private RadioGroup sex; + private String sexStr="男"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.register); + init(); + showCityPicker(); + } + + private void init(){ + btn = (Button) findViewById(R.id.button); + reg_username = (EditText) findViewById(R.id.reg_username); + reg_password = (EditText) findViewById(R.id.reg_password); + reg_sure_password = (EditText) findViewById(R.id.reg_sure_password); + sex= findViewById(R.id.sex); + sex.setOnCheckedChangeListener(this); + + btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String username = reg_username.getText().toString(); + String password = reg_password.getText().toString(); + String surepassword = reg_sure_password.getText().toString(); + if(password.equals(surepassword)){ + if(!username.equals("")|| !password.equals("")){ + + Bundle bundle = new Bundle(); + bundle.putString("username",username); + bundle.putString("password",password); + bundle.putString("sex",sexStr); + Database orangeDatabase = new Database(RegisterActivity.this); + SQLiteDatabase sqLiteDatabase = orangeDatabase.getWritableDatabase(); + insertData(sqLiteDatabase, bundle); + Intent intent = new Intent(RegisterActivity.this, IndexActivity.class); + intent.putExtras(bundle); + startActivity(intent); + }else{ + Toast.makeText(RegisterActivity.this,"账号或密码未填写",Toast.LENGTH_SHORT).show(); + } + }else{ + Toast.makeText(RegisterActivity.this,"两次密码输入不一致",Toast.LENGTH_SHORT).show(); + } + } + }); + } + + + public void showCityPicker(){ + + final CityPickerView cityPicker=new CityPickerView(); + cityPicker.init(this); + CityConfig cityConfig = new CityConfig.Builder() + .province("湖南省")//默认显示的省份 + .city("常德市")//默认显示省份下面的城市 + .district("武陵区")//默认显示省市下面的区县数据 + .build(); + cityPicker.setConfig(cityConfig); + + final EditText editCity=findViewById(R.id.edit_city); + + //点击监听 + editCity.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + cityPicker.setOnCityItemClickListener(new OnCityItemClickListener() { + @SuppressLint("SetTextI18n") + @Override + //点击确定 + public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) { + Toast.makeText(RegisterActivity.this,province+" - "+city+" - "+district,Toast.LENGTH_LONG).show(); + editCity.setText(province+" - "+city+" - "+district); + } + @Override + //点击取消 + public void onCancel() { + } + }); + cityPicker.showCityPicker(); + } + }); + } + + @Override + public void onCheckedChanged(RadioGroup group,int checkedId){ + sexStr=checkedId == R.id.reg_man?"男":"女"; + } + + + /** + * 插入数据库的值 + * + * @param sqLiteDatabase + * @param bundle + */ + private void insertData(SQLiteDatabase sqLiteDatabase, Bundle bundle) { + ContentValues contentValues = new ContentValues(); + contentValues.put("username", bundle.getString("username")); + contentValues.put("password", bundle.getString("password")); + contentValues.put("sex", bundle.getString("sex")); + contentValues.put("city", bundle.getString("city")); + sqLiteDatabase.insert("orange_user", null, contentValues); + sqLiteDatabase.close(); + } +} \ No newline at end of file diff --git a/main/java/com/example/test1/SetContentFragment.java b/main/java/com/example/test1/SetContentFragment.java new file mode 100644 index 0000000..0604749 --- /dev/null +++ b/main/java/com/example/test1/SetContentFragment.java @@ -0,0 +1,40 @@ +package com.example.test1; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +public class SetContentFragment extends Fragment{ + private View view; + private TextView text1,text2; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + //获取布局文件 + view=inflater.inflate(R.layout.content_layout,container,false); + if (view!=null){ + init(); + } + //获取activity中设置的文字 + setText(((com.example.test1.Fragment)getActivity()).getSettingText()[0]); + return view; + } + private void init() { + + text1=(TextView)view.findViewById(R.id.show_title); + text2=(TextView)view.findViewById(R.id.show_content); + } + public void setText(String[] text) { + Log.i("news",text[0]); + text1.setText(text[0]); + text2.setText(text[1]); + } +} diff --git a/main/java/com/example/test1/SetTitleFragment.java b/main/java/com/example/test1/SetTitleFragment.java new file mode 100644 index 0000000..401c323 --- /dev/null +++ b/main/java/com/example/test1/SetTitleFragment.java @@ -0,0 +1,77 @@ +package com.example.test1; +import android.os.Bundle; + +import androidx.fragment.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.BaseAdapter; +import android.widget.ListView; +import android.widget.TextView; + + +public class SetTitleFragment extends Fragment { + + private View view; + private String[] title; + private String[][] contents; + private ListView listView; + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + view=inflater.inflate(R.layout.title_layout,container,false); + com.example.test1.Fragment activity=(com.example.test1.Fragment) getActivity(); + title=activity.getTilte(); + contents=activity.getSettingText(); + if (view!=null){ + init(); + } + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + //通过activity实例获取另一个Fragment对象 + SetContentFragment content=(SetContentFragment)((com.example.test1.Fragment)getActivity()) + .getSupportFragmentManager().findFragmentById(R.id.setcontent); + content.setText(contents[i]); + + } + }); + return view; + } + + private void init() { + listView=(ListView)view.findViewById(R.id.titlelist); + if (title!=null){ + listView.setAdapter(new MyAdapter()); + } + } + //适配器 + class MyAdapter extends BaseAdapter { + + @Override + public int getCount() { + return title.length; + } + + @Override + public Object getItem(int i) { + return title[i]; + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View view, ViewGroup viewGroup) { + view=View.inflate(getActivity(),R.layout.title_item_layout,null); + TextView titletext=(TextView)view.findViewById(R.id.titles); + titletext.setText(title[i]); + return view; + } + } +} \ No newline at end of file diff --git a/main/java/com/example/test1/User_Activity.java b/main/java/com/example/test1/User_Activity.java new file mode 100644 index 0000000..009601d --- /dev/null +++ b/main/java/com/example/test1/User_Activity.java @@ -0,0 +1,40 @@ +package com.example.test1; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.content.Intent; +import android.widget.Button; +import android.widget.*; + +public class User_Activity extends Activity{ + Button button = null; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.content_user); + + button = (Button)findViewById(R.id.button); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + intent.setClass(User_Activity.this,LoginActivity.class); + startActivity(intent); + } + }); + + button = (Button)findViewById(R.id.p1); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + intent.setClass(User_Activity.this,Fragment.class); + startActivity(intent); + } + }); + } + +} \ No newline at end of file diff --git a/main/java/com/example/test1/fragment/IndexFragment.java b/main/java/com/example/test1/fragment/IndexFragment.java new file mode 100644 index 0000000..413fcea --- /dev/null +++ b/main/java/com/example/test1/fragment/IndexFragment.java @@ -0,0 +1,111 @@ +package com.example.test1.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.test1.Product; +import com.example.test1.ProductAdapter; +import com.example.test1.R; + +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.suanxiang); + product.setProductName("蒜香"); + product.setProductPrice(new BigDecimal("2999.00")); + Product product1 = new Product(); + product1.setImageUrlId(R.drawable.xiuxiu); + product1.setProductName("咻咻"); + product1.setProductPrice(new BigDecimal("2999.00")); + Product product2 = new Product(); + product2.setImageUrlId(R.drawable.mommy); + product2.setProductName("mommy"); + product2.setProductPrice(new BigDecimal("1999.00")); + Product product3 = new Product(); + product3.setImageUrlId(R.drawable.chanjie); + product3.setProductName("蝉姐"); + product3.setProductPrice(new BigDecimal("1999.00")); + Product product4 = new Product(); + product4.setImageUrlId(R.drawable.yuanbao); + product4.setProductName("元宝"); + product4.setProductPrice(new BigDecimal("9999.00")); + Product product5 = new Product(); + product5.setImageUrlId(R.drawable.furong); + product5.setProductName("芙蓉"); + product5.setProductPrice(new BigDecimal("9999.00")); + productList.add(product); + productList.add(product1); + productList.add(product2); + productList.add(product3); + productList.add(product4); + productList.add(product5); + + } + } + + diff --git a/main/java/com/example/test1/fragment/PearsonFragment.java b/main/java/com/example/test1/fragment/PearsonFragment.java new file mode 100644 index 0000000..aaaf5fd --- /dev/null +++ b/main/java/com/example/test1/fragment/PearsonFragment.java @@ -0,0 +1,33 @@ +package com.example.test1.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.test1.R; + + +public class PearsonFragment extends Fragment implements View.OnClickListener { + + @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); + return view; + } + + @Override + public void onClick(View v) { + + } + + +} diff --git a/main/java/com/example/test1/fragment/ProductFragment.java b/main/java/com/example/test1/fragment/ProductFragment.java new file mode 100644 index 0000000..72ffc27 --- /dev/null +++ b/main/java/com/example/test1/fragment/ProductFragment.java @@ -0,0 +1,21 @@ +package com.example.test1.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.test1.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/main/java/com/example/test1/fragment/ShoppingCartFragment.java b/main/java/com/example/test1/fragment/ShoppingCartFragment.java new file mode 100644 index 0000000..f449e6d --- /dev/null +++ b/main/java/com/example/test1/fragment/ShoppingCartFragment.java @@ -0,0 +1,21 @@ +package com.example.test1.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.test1.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/main/res/drawable-v24/ic_launcher_foreground.xml b/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/main/res/drawable/animal.png b/main/res/drawable/animal.png new file mode 100644 index 0000000..14a5dd8 Binary files /dev/null and b/main/res/drawable/animal.png differ diff --git a/main/res/drawable/app_background.xml b/main/res/drawable/app_background.xml new file mode 100644 index 0000000..6da9cbc --- /dev/null +++ b/main/res/drawable/app_background.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/arrow_down.png b/main/res/drawable/arrow_down.png new file mode 100644 index 0000000..6d95bb5 Binary files /dev/null and b/main/res/drawable/arrow_down.png differ diff --git a/main/res/drawable/arrow_left.png b/main/res/drawable/arrow_left.png new file mode 100644 index 0000000..365afe0 Binary files /dev/null and b/main/res/drawable/arrow_left.png differ diff --git a/main/res/drawable/arrow_right.png b/main/res/drawable/arrow_right.png new file mode 100644 index 0000000..84ded85 Binary files /dev/null and b/main/res/drawable/arrow_right.png differ diff --git a/main/res/drawable/background.xml b/main/res/drawable/background.xml new file mode 100644 index 0000000..6d9cdac --- /dev/null +++ b/main/res/drawable/background.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/background1.xml b/main/res/drawable/background1.xml new file mode 100644 index 0000000..07f4e2e --- /dev/null +++ b/main/res/drawable/background1.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/caodi.png b/main/res/drawable/caodi.png new file mode 100644 index 0000000..96b745a Binary files /dev/null and b/main/res/drawable/caodi.png differ diff --git a/main/res/drawable/chanjie.jpg b/main/res/drawable/chanjie.jpg new file mode 100644 index 0000000..3be42ff Binary files /dev/null and b/main/res/drawable/chanjie.jpg differ diff --git a/main/res/drawable/chaorenqiang.png b/main/res/drawable/chaorenqiang.png new file mode 100644 index 0000000..2201147 Binary files /dev/null and b/main/res/drawable/chaorenqiang.png differ diff --git a/main/res/drawable/chatu.png b/main/res/drawable/chatu.png new file mode 100644 index 0000000..935afc3 Binary files /dev/null and b/main/res/drawable/chatu.png differ diff --git a/main/res/drawable/city.png b/main/res/drawable/city.png new file mode 100644 index 0000000..790fb2b Binary files /dev/null and b/main/res/drawable/city.png differ diff --git a/main/res/drawable/furong.jpg b/main/res/drawable/furong.jpg new file mode 100644 index 0000000..2fa7b71 Binary files /dev/null and b/main/res/drawable/furong.jpg differ diff --git a/main/res/drawable/gouwuche.png b/main/res/drawable/gouwuche.png new file mode 100644 index 0000000..7337339 Binary files /dev/null and b/main/res/drawable/gouwuche.png differ diff --git a/main/res/drawable/ic_launcher_background.xml b/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/main/res/drawable/index.png b/main/res/drawable/index.png new file mode 100644 index 0000000..cc1ec04 Binary files /dev/null and b/main/res/drawable/index.png differ diff --git a/main/res/drawable/index_menu.xml b/main/res/drawable/index_menu.xml new file mode 100644 index 0000000..14636dd --- /dev/null +++ b/main/res/drawable/index_menu.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/liubian.jpg b/main/res/drawable/liubian.jpg new file mode 100644 index 0000000..c07af83 Binary files /dev/null and b/main/res/drawable/liubian.jpg differ diff --git a/main/res/drawable/mommy.jpg b/main/res/drawable/mommy.jpg new file mode 100644 index 0000000..0be4e29 Binary files /dev/null and b/main/res/drawable/mommy.jpg differ diff --git a/main/res/drawable/orange.png b/main/res/drawable/orange.png new file mode 100644 index 0000000..70e8db8 Binary files /dev/null and b/main/res/drawable/orange.png differ diff --git a/main/res/drawable/remen.png b/main/res/drawable/remen.png new file mode 100644 index 0000000..5b75523 Binary files /dev/null and b/main/res/drawable/remen.png differ diff --git a/main/res/drawable/setting.png b/main/res/drawable/setting.png new file mode 100644 index 0000000..34c2f2f Binary files /dev/null and b/main/res/drawable/setting.png differ diff --git a/main/res/drawable/shangpin.png b/main/res/drawable/shangpin.png new file mode 100644 index 0000000..f9abfdd Binary files /dev/null and b/main/res/drawable/shangpin.png differ diff --git a/main/res/drawable/shape.xml b/main/res/drawable/shape.xml new file mode 100644 index 0000000..d89ffbc --- /dev/null +++ b/main/res/drawable/shape.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/shape1.xml b/main/res/drawable/shape1.xml new file mode 100644 index 0000000..ba52fea --- /dev/null +++ b/main/res/drawable/shape1.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/shouye.png b/main/res/drawable/shouye.png new file mode 100644 index 0000000..b6a0fb4 Binary files /dev/null and b/main/res/drawable/shouye.png differ diff --git a/main/res/drawable/shuiguo.png b/main/res/drawable/shuiguo.png new file mode 100644 index 0000000..d316137 Binary files /dev/null and b/main/res/drawable/shuiguo.png differ diff --git a/main/res/drawable/suanxiang.jpg b/main/res/drawable/suanxiang.jpg new file mode 100644 index 0000000..371c644 Binary files /dev/null and b/main/res/drawable/suanxiang.jpg differ diff --git a/main/res/drawable/sunce.jpg b/main/res/drawable/sunce.jpg new file mode 100644 index 0000000..79132fc Binary files /dev/null and b/main/res/drawable/sunce.jpg differ diff --git a/main/res/drawable/title.png b/main/res/drawable/title.png new file mode 100644 index 0000000..3c8da49 Binary files /dev/null and b/main/res/drawable/title.png differ diff --git a/main/res/drawable/tupian1.png b/main/res/drawable/tupian1.png new file mode 100644 index 0000000..0a18c59 Binary files /dev/null and b/main/res/drawable/tupian1.png differ diff --git a/main/res/drawable/tupian2.png b/main/res/drawable/tupian2.png new file mode 100644 index 0000000..c80421d Binary files /dev/null and b/main/res/drawable/tupian2.png differ diff --git a/main/res/drawable/user_acount.png b/main/res/drawable/user_acount.png new file mode 100644 index 0000000..d63c5f6 Binary files /dev/null and b/main/res/drawable/user_acount.png differ diff --git a/main/res/drawable/user_general.png b/main/res/drawable/user_general.png new file mode 100644 index 0000000..1a122fe Binary files /dev/null and b/main/res/drawable/user_general.png differ diff --git a/main/res/drawable/user_pay.png b/main/res/drawable/user_pay.png new file mode 100644 index 0000000..4f62e53 Binary files /dev/null and b/main/res/drawable/user_pay.png differ diff --git a/main/res/drawable/user_sex.png b/main/res/drawable/user_sex.png new file mode 100644 index 0000000..da0e318 Binary files /dev/null and b/main/res/drawable/user_sex.png differ diff --git a/main/res/drawable/wo.png b/main/res/drawable/wo.png new file mode 100644 index 0000000..0b70cdb Binary files /dev/null and b/main/res/drawable/wo.png differ diff --git a/main/res/drawable/xiuxiu.jpg b/main/res/drawable/xiuxiu.jpg new file mode 100644 index 0000000..f0d5e94 Binary files /dev/null and b/main/res/drawable/xiuxiu.jpg differ diff --git a/main/res/drawable/yuanbao.jpg b/main/res/drawable/yuanbao.jpg new file mode 100644 index 0000000..b90d63a Binary files /dev/null and b/main/res/drawable/yuanbao.jpg differ diff --git a/main/res/drawable/zuoci.jpg b/main/res/drawable/zuoci.jpg new file mode 100644 index 0000000..2510522 Binary files /dev/null and b/main/res/drawable/zuoci.jpg differ diff --git a/main/res/layout/activity_main.xml b/main/res/layout/activity_main.xml new file mode 100644 index 0000000..ecb57a2 --- /dev/null +++ b/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/category_detail.xml b/main/res/layout/category_detail.xml new file mode 100644 index 0000000..9fbbaba --- /dev/null +++ b/main/res/layout/category_detail.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/main/res/layout/category_detail_content.xml b/main/res/layout/category_detail_content.xml new file mode 100644 index 0000000..00eb7d3 --- /dev/null +++ b/main/res/layout/category_detail_content.xml @@ -0,0 +1,30 @@ + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/content_category.xml b/main/res/layout/content_category.xml new file mode 100644 index 0000000..f3c7876 --- /dev/null +++ b/main/res/layout/content_category.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/content_index.xml b/main/res/layout/content_index.xml new file mode 100644 index 0000000..41fe17b --- /dev/null +++ b/main/res/layout/content_index.xml @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/content_layout.xml b/main/res/layout/content_layout.xml new file mode 100644 index 0000000..afa5d9f --- /dev/null +++ b/main/res/layout/content_layout.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/content_nav.xml b/main/res/layout/content_nav.xml new file mode 100644 index 0000000..a44ada2 --- /dev/null +++ b/main/res/layout/content_nav.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/content_product.xml b/main/res/layout/content_product.xml new file mode 100644 index 0000000..7bbae25 --- /dev/null +++ b/main/res/layout/content_product.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/main/res/layout/content_shopping.xml b/main/res/layout/content_shopping.xml new file mode 100644 index 0000000..a15b12d --- /dev/null +++ b/main/res/layout/content_shopping.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/main/res/layout/content_user.xml b/main/res/layout/content_user.xml new file mode 100644 index 0000000..cdbc43d --- /dev/null +++ b/main/res/layout/content_user.xml @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +