├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── encodings.xml
├── modules.xml
├── gradle.xml
├── compiler.xml
├── misc.xml
└── findbugs-idea.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── x.png
│ │ │ │ ├── book_1.jpeg
│ │ │ │ ├── book_2.jpg
│ │ │ │ ├── book_3.jpg
│ │ │ │ ├── book_4.jpg
│ │ │ │ ├── book_5.jpg
│ │ │ │ ├── book_6.jpg
│ │ │ │ ├── book_7.jpg
│ │ │ │ ├── book_8.jpg
│ │ │ │ ├── pill_1.jpg
│ │ │ │ ├── pill_2.jpg
│ │ │ │ ├── pill_3.jpg
│ │ │ │ ├── pill_4.jpg
│ │ │ │ ├── pill_5.jpg
│ │ │ │ ├── book_icon.png
│ │ │ │ ├── category.png
│ │ │ │ ├── foot_icon.png
│ │ │ │ ├── foot_wash.jpg
│ │ │ │ ├── healthy_1.jpg
│ │ │ │ ├── healthy_2.jpg
│ │ │ │ ├── healthy_3.jpg
│ │ │ │ ├── healthy_4.jpg
│ │ │ │ ├── healthy_5.jpg
│ │ │ │ ├── healthy_6.jpg
│ │ │ │ ├── healthy_7.jpg
│ │ │ │ ├── pill_icon.png
│ │ │ │ ├── healthy_book.jpg
│ │ │ │ ├── shoppingcart.png
│ │ │ │ └── detail_shopping_cart.png
│ │ │ ├── drawable-hdpi
│ │ │ │ └── sms_item.9.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_shopping_cart_black_48dp.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_shopping_cart_black_48dp.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_shopping_cart_black_48dp.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_shopping_cart_black_48dp.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_base.xml
│ │ │ │ ├── fragment_healthy.xml
│ │ │ │ ├── activity_all.xml
│ │ │ │ ├── activity_category_details.xml
│ │ │ │ ├── activity_shopping_cart.xml
│ │ │ │ ├── item_fragment_healthy.xml
│ │ │ │ ├── item_category.xml
│ │ │ │ ├── item_shopping_cart.xml
│ │ │ │ ├── activity_product_details.xml
│ │ │ │ └── popup_add_to_cart.xml
│ │ │ ├── menu
│ │ │ │ ├── menu_main.xml
│ │ │ │ ├── menu_base.xml
│ │ │ │ ├── menu_shopping_cart.xml
│ │ │ │ ├── menu_category_details.xml
│ │ │ │ └── menu_product_details.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── drawable
│ │ │ │ └── shape_pop.xml
│ │ │ └── anim
│ │ │ │ ├── activity_bottom_to_top.xml
│ │ │ │ ├── activity_top_to_bottom.xml
│ │ │ │ └── cart.xml
│ │ ├── java
│ │ │ └── io
│ │ │ │ └── github
│ │ │ │ └── sunxu3074
│ │ │ │ └── shoppoingdemo
│ │ │ │ ├── db
│ │ │ │ ├── ProductReaderContract.java
│ │ │ │ └── ProductReadDbHelper.java
│ │ │ │ ├── consts
│ │ │ │ └── ConstUtils.java
│ │ │ │ ├── adapter
│ │ │ │ ├── PagerAdapter.java
│ │ │ │ ├── CategoryAdapter.java
│ │ │ │ └── HealthyAdapter.java
│ │ │ │ ├── Entity
│ │ │ │ ├── ShoppingCartEntity.java
│ │ │ │ ├── HealthyEntity.java
│ │ │ │ └── CategoryEntity.java
│ │ │ │ ├── activity
│ │ │ │ ├── BaseActivity.java
│ │ │ │ ├── AllActivity.java
│ │ │ │ ├── CategoryDetailsActivity.java
│ │ │ │ ├── ShoppingCartActivity.java
│ │ │ │ └── ProductDetailsActivity.java
│ │ │ │ └── fragment
│ │ │ │ ├── FootWashFragment.java
│ │ │ │ ├── PillFragment.java
│ │ │ │ └── BookFragment.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── io
│ │ └── github
│ │ └── sunxu3074
│ │ └── shoppoingdemo
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── settings.gradle
├── preview.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── .gitattributes
├── gradle.properties
├── LICENSE
├── gradlew.bat
├── gradlew
└── ShoppingDemo.iml
/.idea/.name:
--------------------------------------------------------------------------------
1 | ShoppingDemo
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/preview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/preview.gif
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/x.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/book_1.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/book_1.jpeg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/book_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/book_2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/book_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/book_3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/book_4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/book_4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/book_5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/book_5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/book_6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/book_6.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/book_7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/book_7.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/book_8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/book_8.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/pill_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/pill_1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/pill_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/pill_2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/pill_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/pill_3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/pill_4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/pill_4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/pill_5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/pill_5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/sms_item.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-hdpi/sms_item.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/book_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/book_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/category.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/category.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/foot_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/foot_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/foot_wash.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/foot_wash.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/healthy_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/healthy_1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/healthy_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/healthy_2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/healthy_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/healthy_3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/healthy_4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/healthy_4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/healthy_5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/healthy_5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/healthy_6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/healthy_6.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/healthy_7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/healthy_7.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/pill_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/pill_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/healthy_book.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/healthy_book.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/shoppingcart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/shoppingcart.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #a10c0002
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/detail_shopping_cart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/drawable-xhdpi/detail_shopping_cart.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_shopping_cart_black_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_shopping_cart_black_48dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_shopping_cart_black_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_shopping_cart_black_48dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_shopping_cart_black_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_shopping_cart_black_48dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_shopping_cart_black_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sunxu3074/ShoppingCartDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_shopping_cart_black_48dp.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ShoppingDemo
2 | 简单实现类似于淘宝的购物车功能
3 |
4 | ### 效果图
5 |
6 |
7 |
8 | ### 功能实现
9 |
10 | - 数据存储在手机数据库内
11 | - UI用到了TabLayout,CardView
12 |
13 | ### TODO
14 |
15 | - 图片展示的滚动效果实现
16 | - 美化UI
17 | - 自定义ActionBar
18 |
19 | ### 用法
20 |
21 | - File->New-> Import Project即可.
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_base.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_pop.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/activity_bottom_to_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/activity_top_to_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
12 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/io/github/sunxu3074/shoppoingdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_base.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_shopping_cart.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_category_details.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ShoppoingDemo
3 |
4 | 健康产品
5 | 设置
6 | 产品列表
7 | 产品详情
8 | AddToCartActivity
9 | 我的购物车
10 | BaseActivity
11 | 设置
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\zhangyan\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_healthy.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_product_details.xml:
--------------------------------------------------------------------------------
1 |
15 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_all.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.0"
6 |
7 | defaultConfig {
8 | applicationId "io.github.sunxu3074.shoppoingdemo"
9 | minSdkVersion 16
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:23.0.0'
25 | compile 'com.android.support:cardview-v7:23.1.0'
26 | compile 'com.android.support:design:22.2.0'
27 | compile 'com.android.support:support-v4:23.1.0'
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/db/ProductReaderContract.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.db;
2 |
3 | import android.provider.BaseColumns;
4 |
5 | /**
6 | * Created by zhangyan on 2015/10/29.
7 | */
8 | public final class ProductReaderContract {
9 |
10 | public ProductReaderContract() {
11 | }
12 |
13 | public static abstract class ProductEntry implements BaseColumns {
14 | public static final String TABLE_NAME = "entry";
15 | public static final String COLUMN_NAME_ENTRY_ID = "product_id";
16 | public static final String COLUMN_NAME_CATEGORY = "category";
17 | public static final String COLUMN_NAME_NUMBER = "number";
18 | public static final String COLUMN_NAME_PRICE = "price";
19 | public static final String COLUMN_NAME_NAME = "name";
20 | // public static final String COLUMN_NAME_IMG = "imgurl";
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/consts/ConstUtils.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.consts;
2 |
3 | import io.github.sunxu3074.shoppoingdemo.R;
4 |
5 | /**
6 | * Created by zhangyan on 2015/10/26.
7 | */
8 | public class ConstUtils {
9 |
10 | public static final String ALLACTIVITY_KEY_POSITION = "allactivity_key_position";
11 |
12 | public static final int[] CATEGORY_PICTURES = {
13 | R.drawable.foot_wash,
14 | R.drawable.healthy_5,
15 | R.drawable.healthy_book,
16 | };
17 |
18 | public static final int[][] PICTURES = {{R.drawable.foot_wash}, {R.drawable.pill_1, R
19 | .drawable.pill_2, R.drawable.pill_3, R.drawable.pill_4, R.drawable.pill_5,},
20 | {R.drawable.book_1, R.drawable.book_2, R.drawable.book_3, R.drawable.book_4, R
21 | .drawable.book_5, R.drawable.book_6, R.drawable.book_7, R.drawable.book_8,}};
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 taken
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_category_details.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
21 |
22 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/adapter/PagerAdapter.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentStatePagerAdapter;
6 |
7 | import io.github.sunxu3074.shoppoingdemo.fragment.BookFragment;
8 | import io.github.sunxu3074.shoppoingdemo.fragment.FootWashFragment;
9 | import io.github.sunxu3074.shoppoingdemo.fragment.PillFragment;
10 |
11 | /**
12 | * Created by zhangyan on 2015/11/3.
13 | */
14 | public class PagerAdapter extends FragmentStatePagerAdapter {
15 |
16 | private int number;
17 |
18 | public PagerAdapter(FragmentManager fm,int number) {
19 | super(fm);
20 | this.number = number;
21 | }
22 |
23 | @Override
24 | public Fragment getItem(int position) {
25 | switch (position) {
26 | case 0:
27 | FootWashFragment tab1 = new FootWashFragment();
28 | return tab1;
29 | case 1:
30 | PillFragment tab2 = new PillFragment();
31 | return tab2;
32 | case 2:
33 | BookFragment tab3 = new BookFragment();
34 | return tab3;
35 | }
36 | return null;
37 | }
38 |
39 | @Override
40 | public int getCount() {
41 | return number;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | 1.7
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/cart.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
13 |
22 |
23 |
24 |
31 |
32 |
37 |
38 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
31 |
32 |
36 |
37 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/Entity/ShoppingCartEntity.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.Entity;
2 |
3 | /**
4 | * Created by zhangyan on 2015/10/29.
5 | */
6 | public class ShoppingCartEntity {
7 |
8 | private String id ;
9 | private String name;
10 | private String category;
11 | private int price;
12 | private int number ;
13 | private int imgUrl;
14 |
15 | public ShoppingCartEntity(String id, String name, String category, int price, int number,
16 | int imgUrl) {
17 | this.id = id;
18 | this.name = name;
19 | this.category = category;
20 | this.price = price;
21 | this.number = number;
22 | this.imgUrl = imgUrl;
23 | }
24 |
25 | public String getId() {
26 | return id;
27 | }
28 |
29 | public void setId(String id) {
30 | this.id = id;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | public void setName(String name) {
38 | this.name = name;
39 | }
40 |
41 | public String getCategory() {
42 | return category;
43 | }
44 |
45 | public void setCategory(String category) {
46 | this.category = category;
47 | }
48 |
49 | public int getPrice() {
50 | return price;
51 | }
52 |
53 | public void setPrice(int price) {
54 | this.price = price;
55 | }
56 |
57 | public int getNumber() {
58 | return number;
59 | }
60 |
61 | public void setNumber(int number) {
62 | this.number = number;
63 | }
64 |
65 | public int getImgUrl() {
66 | return imgUrl;
67 | }
68 |
69 | public void setImgUrl(int imgUrl) {
70 | this.imgUrl = imgUrl;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/Entity/HealthyEntity.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.Entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by zhangyan on 2015/10/27.
7 | */
8 | public class HealthyEntity implements Serializable{
9 | private String id;
10 | private String name;
11 | private String details;
12 | private int price;
13 | private int number;
14 | private int imgUrl ;
15 | //TODO 加一个产品种类
16 | // private String category;
17 |
18 | public int getImgUrl() {
19 | return imgUrl;
20 | }
21 |
22 | public void setImgUrl(int imgUrl) {
23 | this.imgUrl = imgUrl;
24 | }
25 |
26 | public HealthyEntity(String id, String name, String details, int price, int number, int
27 | imgUrl) {
28 | this.id = id;
29 | this.name = name;
30 | this.details = details;
31 | this.price = price;
32 | this.number = number;
33 | this.imgUrl = imgUrl;
34 | }
35 |
36 | public String getId() {
37 | return id;
38 | }
39 |
40 | public void setId(String id) {
41 | this.id = id;
42 | }
43 |
44 | public String getName() {
45 | return name;
46 | }
47 |
48 | public void setName(String name) {
49 | this.name = name;
50 | }
51 |
52 | public String getDetails() {
53 | return details;
54 | }
55 |
56 | public void setDetails(String details) {
57 | this.details = details;
58 | }
59 |
60 | public int getPrice() {
61 | return price;
62 | }
63 |
64 | public void setPrice(int price) {
65 | this.price = price;
66 | }
67 |
68 | public int getNumber() {
69 | return number;
70 | }
71 |
72 | public void setNumber(int number) {
73 | this.number = number;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.activity;
2 |
3 | import android.graphics.drawable.ColorDrawable;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBar;
6 | import android.support.v7.app.ActionBarActivity;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 |
10 | import io.github.sunxu3074.shoppoingdemo.R;
11 |
12 | public class BaseActivity extends ActionBarActivity {
13 |
14 | private static final int ACTIONBAR_BACKGROUND = R.color.actionbar_background;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_base);
20 |
21 | initActionBar();
22 |
23 | }
24 |
25 | private void initActionBar() {
26 |
27 | ActionBar actionBar = getSupportActionBar();
28 | actionBar.setBackgroundDrawable(new ColorDrawable(ACTIONBAR_BACKGROUND));
29 | //google的actionbar是分为上下两栏显示的,上面的代码只能设置顶部actionbar的背景色,
30 | //为了让下面的背景色一致,还需要添加一行代码:
31 | actionBar.setSplitBackgroundDrawable(new ColorDrawable(ACTIONBAR_BACKGROUND));
32 | }
33 |
34 | @Override
35 | public boolean onCreateOptionsMenu(Menu menu) {
36 | // Inflate the menu; this adds items to the action bar if it is present.
37 | getMenuInflater().inflate(R.menu.menu_base, menu);
38 | return true;
39 | }
40 |
41 | @Override
42 | public boolean onOptionsItemSelected(MenuItem item) {
43 | // Handle action bar item clicks here. The action bar will
44 | // automatically handle clicks on the Home/Up button, so long
45 | // as you specify a parent activity in AndroidManifest.xml.
46 | int id = item.getItemId();
47 |
48 | //noinspection SimplifiableIfStatement
49 | if (id == R.id.action_settings) {
50 | return true;
51 | }
52 |
53 | return super.onOptionsItemSelected(item);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/db/ProductReadDbHelper.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.db;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | /**
8 | * Created by zhangyan on 2015/10/29.
9 | */
10 | public class ProductReadDbHelper extends SQLiteOpenHelper {
11 |
12 | public static final int DATABASE_VERSION = 1;
13 | public static final String DATABASE_NAME = "ProductReader.db";
14 |
15 | private static final String TEXT_TYPE = " TEXT";
16 | private static final String COMMA_SEP = ",";
17 | private static final String SQL_CREATE_ENTRIES =
18 | "CREATE TABLE " + ProductReaderContract.ProductEntry.TABLE_NAME + " (" +
19 | ProductReaderContract.ProductEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT" +
20 | COMMA_SEP +
21 | ProductReaderContract.ProductEntry.COLUMN_NAME_ENTRY_ID + TEXT_TYPE +
22 | COMMA_SEP +
23 | ProductReaderContract.ProductEntry.COLUMN_NAME_CATEGORY + TEXT_TYPE +
24 | " default 健康产品" +
25 | COMMA_SEP +
26 | ProductReaderContract.ProductEntry.COLUMN_NAME_NUMBER + TEXT_TYPE + " default " +
27 | "0" +
28 | COMMA_SEP +
29 | ProductReaderContract.ProductEntry.COLUMN_NAME_PRICE + TEXT_TYPE + " default " +
30 | "1000" +
31 | COMMA_SEP +
32 | ProductReaderContract.ProductEntry.COLUMN_NAME_NAME + TEXT_TYPE + " default " +
33 | "健康产品系列1" +
34 | " )";
35 |
36 |
37 | public ProductReadDbHelper(Context context) {
38 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
39 | }
40 |
41 | @Override
42 | public void onCreate(SQLiteDatabase db) {
43 | db.execSQL(SQL_CREATE_ENTRIES);
44 | }
45 |
46 | @Override
47 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/Entity/CategoryEntity.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.Entity;
2 |
3 | /**
4 | * Created by zhangyan on 2015/10/21.
5 | */
6 | public class CategoryEntity {
7 |
8 | private String name;
9 | private String imgUrl;
10 | private String details;
11 | private String id ;
12 |
13 | @Override
14 | public String toString() {
15 | return "CategoryEntity{" +
16 | "name='" + name + '\'' +
17 | ", imgUrl='" + imgUrl + '\'' +
18 | ", details='" + details + '\'' +
19 | ", id='" + id + '\'' +
20 | ", price=" + price +
21 | ", number=" + number +
22 | '}';
23 | }
24 |
25 | private int price;
26 |
27 | public CategoryEntity() {
28 |
29 | }
30 |
31 | private int number;
32 |
33 | public CategoryEntity(String name, String imgUrl, String details, String id, int price, int
34 | number) {
35 | this.name = name;
36 | this.imgUrl = imgUrl;
37 | this.details = details;
38 | this.id = id;
39 | this.price = price;
40 | this.number = number;
41 | }
42 |
43 | public void setName(String name) {
44 | this.name = name;
45 | }
46 |
47 | public void setImgUrl(String imgUrl) {
48 | this.imgUrl = imgUrl;
49 | }
50 |
51 | public void setDetails(String details) {
52 | this.details = details;
53 | }
54 |
55 | public void setId(String id) {
56 | this.id = id;
57 | }
58 |
59 | public void setPrice(int price) {
60 | this.price = price;
61 | }
62 |
63 | public void setNumber(int number) {
64 | this.number = number;
65 | }
66 |
67 | public String getName() {
68 | return name;
69 | }
70 |
71 | public String getImgUrl() {
72 | return imgUrl;
73 | }
74 |
75 | public String getDetails() {
76 | return details;
77 | }
78 |
79 | public String getId() {
80 | return id;
81 | }
82 |
83 | public int getPrice() {
84 | return price;
85 | }
86 |
87 | public int getNumber() {
88 | return number;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
12 |
13 |
19 |
20 |
24 |
25 |
26 |
35 |
36 |
47 |
48 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_shopping_cart.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
22 |
23 |
30 |
37 |
43 |
52 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/adapter/CategoryAdapter.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import io.github.sunxu3074.shoppoingdemo.Entity.CategoryEntity;
15 | import io.github.sunxu3074.shoppoingdemo.R;
16 | import io.github.sunxu3074.shoppoingdemo.consts.ConstUtils;
17 |
18 | /**
19 | * Created by zhangyan on 2015/10/21.
20 | */
21 | public class CategoryAdapter extends BaseAdapter {
22 |
23 | private LayoutInflater mLayoutInflater;
24 | private List mDatas = new ArrayList<>();
25 |
26 | public CategoryAdapter(Context context,List mDatas) {
27 | mLayoutInflater = LayoutInflater.from(context);
28 | this.mDatas = mDatas;
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return mDatas.size();
34 | }
35 |
36 | @Override
37 | public Object getItem(int position) {
38 | return mDatas.get(position);
39 | }
40 |
41 | @Override
42 | public long getItemId(int position) {
43 | return position;
44 | }
45 | @Override
46 | public View getView(int position, View convertView, ViewGroup parent) {
47 | ViewHolder viewHolder ;
48 | if(convertView == null) {
49 | convertView = mLayoutInflater.inflate(R.layout.item_category, parent, false);
50 | viewHolder = new ViewHolder();
51 | viewHolder.label = (TextView) convertView.findViewById(R.id.item_category_name);
52 | viewHolder.details = (TextView) convertView.findViewById(R.id.item_category_details);
53 | viewHolder.image = (ImageView) convertView.findViewById(R.id.item_category_img);
54 | convertView.setTag(viewHolder);
55 | }else {
56 | viewHolder = (ViewHolder) convertView.getTag();
57 | }
58 | CategoryEntity entity = (CategoryEntity) getItem(position);
59 | viewHolder.label.setText(entity.getName());
60 | viewHolder.details.setText(entity.getDetails());
61 | viewHolder.image.setImageResource(ConstUtils.CATEGORY_PICTURES[Integer.parseInt(entity.getImgUrl())-1]);
62 | return convertView;
63 | }
64 | static class ViewHolder{
65 | TextView label,details;
66 | ImageView image;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/adapter/HealthyAdapter.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import io.github.sunxu3074.shoppoingdemo.Entity.HealthyEntity;
15 | import io.github.sunxu3074.shoppoingdemo.R;
16 | import io.github.sunxu3074.shoppoingdemo.consts.ConstUtils;
17 |
18 | /**
19 | * Created by zhangyan on 2015/10/27.
20 | */
21 | public class HealthyAdapter extends BaseAdapter {
22 |
23 | private Context context;
24 | private List mDatas = new ArrayList<>();
25 |
26 | public HealthyAdapter(Context context, List mDatas) {
27 | this.context = context;
28 | this.mDatas = mDatas;
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return mDatas.size();
34 | }
35 |
36 | @Override
37 | public Object getItem(int position) {
38 | return mDatas.get(position);
39 | }
40 |
41 | @Override
42 | public long getItemId(int position) {
43 | return position;
44 | }
45 |
46 | @Override
47 | public View getView(int position, View convertView, ViewGroup parent) {
48 | ViewHolder holder = null;
49 | if (convertView == null) {
50 | convertView = LayoutInflater.from(context).inflate(R.layout.item_fragment_healthy, parent,
51 | false);
52 | holder = new ViewHolder();
53 | holder.img = (ImageView) convertView.findViewById(R.id.item_fragment_img);
54 | holder.price = (TextView) convertView.findViewById(R.id.item_fragment_price);
55 | holder.number = (TextView) convertView.findViewById(R.id.item_fragment_number);
56 | holder.details = (TextView) convertView.findViewById(R.id.item_fragment_healthy_details);
57 | convertView.setTag(holder);
58 | }
59 | else {
60 | holder = (ViewHolder) convertView.getTag();
61 | }
62 | HealthyEntity entity = (HealthyEntity) getItem(position);
63 | holder.img.setImageResource(entity.getImgUrl());
64 | holder.price.setText("¥"+entity.getPrice());
65 | holder.number.setText("已售出"+entity.getNumber()+"件");
66 | holder.details.setText(entity.getDetails());
67 | return convertView;
68 | }
69 |
70 | static class ViewHolder {
71 | ImageView img;
72 | TextView price, number, details;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/fragment/FootWashFragment.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.AdapterView;
11 | import android.widget.ListView;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import io.github.sunxu3074.shoppoingdemo.Entity.HealthyEntity;
17 | import io.github.sunxu3074.shoppoingdemo.R;
18 | import io.github.sunxu3074.shoppoingdemo.activity.ProductDetailsActivity;
19 | import io.github.sunxu3074.shoppoingdemo.adapter.HealthyAdapter;
20 |
21 | /**
22 | * Created by zhangyan on 2015/10/26.
23 | */
24 | public class FootWashFragment extends Fragment {
25 |
26 | private ListView mListView;
27 |
28 | private List mDatas = new ArrayList<>();
29 |
30 | private HealthyAdapter mAdapter;
31 |
32 | @Nullable
33 | @Override
34 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
35 | savedInstanceState) {
36 | return inflater.inflate(R.layout.fragment_healthy, container, false);
37 | }
38 |
39 | @Override
40 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
41 | super.onActivityCreated(savedInstanceState);
42 | initViews();
43 | addListeners();
44 | initDatas();
45 | }
46 |
47 | /**
48 | * 初始化数据
49 | */
50 | private void initDatas() {
51 | mDatas.add(new HealthyEntity("10001", "足浴盆",
52 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者", 1000, 159, R.drawable.foot_wash));
53 | mAdapter = new HealthyAdapter(getActivity(), mDatas);
54 | mListView.setAdapter(mAdapter);
55 |
56 | }
57 |
58 | private void addListeners() {
59 |
60 | mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
61 | @Override
62 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
63 | HealthyAdapter adapter = (HealthyAdapter) parent.getAdapter();
64 | HealthyEntity entity = (HealthyEntity) adapter.getItem(position);
65 | Intent intent = new Intent(getActivity(), ProductDetailsActivity.class);
66 | intent.putExtra("entity", entity);
67 | getActivity().startActivity(intent);
68 | }
69 | });
70 | }
71 |
72 | private void initViews() {
73 |
74 | mListView = (ListView) getView().findViewById(R.id.fragment_healthy_lv);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_fragment_healthy.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
12 |
17 |
23 |
34 |
40 |
41 |
50 |
51 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_category.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
21 |
22 |
30 |
31 |
32 |
33 |
39 |
40 |
50 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/activity/AllActivity.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 | import android.view.View;
8 | import android.widget.AdapterView;
9 | import android.widget.ListView;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | import io.github.sunxu3074.shoppoingdemo.Entity.CategoryEntity;
15 | import io.github.sunxu3074.shoppoingdemo.R;
16 | import io.github.sunxu3074.shoppoingdemo.adapter.CategoryAdapter;
17 | import io.github.sunxu3074.shoppoingdemo.consts.ConstUtils;
18 |
19 | public class AllActivity extends BaseActivity {
20 |
21 | private ListView mListView;
22 | private List mDatas = new ArrayList<>();
23 | private CategoryAdapter mAdapter;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_all);
29 |
30 | initViews();
31 | initData();
32 | addListeners();
33 | }
34 |
35 | private void addListeners() {
36 |
37 | mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
38 | @Override
39 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
40 | Intent intent = new Intent(getApplication(), CategoryDetailsActivity.class);
41 | intent.putExtra(ConstUtils.ALLACTIVITY_KEY_POSITION, position);
42 | startActivity(intent);
43 | }
44 | });
45 | }
46 |
47 | private void initData() { /* 构造假数据*/
48 | mDatas.add(new CategoryEntity("保健产品", "1",
49 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者",
50 | "000001", 1000, 159));
51 | mDatas.add(new CategoryEntity("丸剂", "2",
52 | "免疫调节作用,延缓衰老作用,改变记忆作用,促进生长发育作用,抗疲劳作用,减肥作用,抑制肿瘤作用", "000002", 1000, 159));
53 | mDatas.add(new CategoryEntity("书籍", "3",
54 | "八卦象素的配方及应用、拔罐疗法,不生病的智慧,科普从头到脚说健康,养心的妙药", "000003", 1000, 159));
55 |
56 |
57 | mAdapter = new CategoryAdapter(this, mDatas);
58 | mListView.setAdapter(mAdapter);
59 |
60 | }
61 |
62 | private void initViews() {
63 |
64 | mListView = (ListView) findViewById(R.id.all_lv);
65 | }
66 |
67 | @Override
68 | public boolean onCreateOptionsMenu(Menu menu) {
69 | // Inflate the menu; this adds items to the action bar if it is present.
70 | getMenuInflater().inflate(R.menu.menu_main, menu);
71 | return true;
72 | }
73 |
74 | @Override
75 | public boolean onOptionsItemSelected(MenuItem item) {
76 | // Handle action bar item clicks here. The action bar will
77 | // automatically handle clicks on the Home/Up button, so long
78 | // as you specify a parent activity in AndroidManifest.xml.
79 | int id = item.getItemId();
80 |
81 |
82 | //noinspection SimplifiableIfStatement
83 | if (id == R.id.action_settings) {
84 | return true;
85 | }
86 |
87 | return super.onOptionsItemSelected(item);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/fragment/PillFragment.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.AdapterView;
11 | import android.widget.ListView;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import io.github.sunxu3074.shoppoingdemo.Entity.HealthyEntity;
17 | import io.github.sunxu3074.shoppoingdemo.R;
18 | import io.github.sunxu3074.shoppoingdemo.activity.ProductDetailsActivity;
19 | import io.github.sunxu3074.shoppoingdemo.adapter.HealthyAdapter;
20 |
21 | /**
22 | * Created by zhangyan on 2015/10/26.
23 | */
24 | public class PillFragment extends Fragment {
25 |
26 | private ListView mListView;
27 |
28 | private List mDatas = new ArrayList<>();
29 |
30 | private HealthyAdapter mAdapter;
31 |
32 | @Nullable
33 | @Override
34 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
35 | savedInstanceState) {
36 | return inflater.inflate(R.layout.fragment_healthy, container, false);
37 | }
38 |
39 | @Override
40 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
41 | super.onActivityCreated(savedInstanceState);
42 | initViews();
43 | addListeners();
44 | initDatas();
45 | }
46 |
47 | /**
48 | * 初始化数据
49 | */
50 | private void initDatas() {
51 | mDatas.add(new HealthyEntity("20001", "大山楂丸",
52 | "免疫调节作用,延缓衰老作用,改变记忆作用,促进生长发育作用,抗疲劳作用,减肥作用,抑制肿瘤作用", 320, 159, R.drawable.pill_1));
53 | mDatas.add(new HealthyEntity("20002", "六神丸",
54 | "免疫调节作用,延缓衰老作用,改变记忆作用,促进生长发育作用,抗疲劳作用,减肥作用,抑制肿瘤作用", 99, 122, R.drawable.pill_2));
55 | mDatas.add(new HealthyEntity("20003", "六味地黄丸",
56 | "免疫调节作用,延缓衰老作用,改变记忆作用,促进生长发育作用,抗疲劳作用,减肥作用,抑制肿瘤作用", 120, 151, R.drawable.pill_3));
57 | mDatas.add(new HealthyEntity("20004", "牛黄清心丸(局方)",
58 | "免疫调节作用,延缓衰老作用,改变记忆作用,促进生长发育作用,抗疲劳作用,减肥作用,抑制肿瘤作用", 520, 139, R.drawable.pill_4));
59 | mDatas.add(new HealthyEntity("20005", "壮筋续骨丸",
60 | "免疫调节作用,延缓衰老作用,改变记忆作用,促进生长发育作用,抗疲劳作用,减肥作用,抑制肿瘤作用", 280, 289, R.drawable.pill_5));
61 |
62 | mAdapter = new HealthyAdapter(getActivity(), mDatas);
63 | mListView.setAdapter(mAdapter);
64 |
65 | }
66 |
67 | private void addListeners() {
68 |
69 | mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
70 | @Override
71 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
72 | HealthyAdapter adapter = (HealthyAdapter) parent.getAdapter();
73 | HealthyEntity entity = (HealthyEntity) adapter.getItem(position);
74 | Intent intent = new Intent(getActivity(), ProductDetailsActivity.class);
75 | intent.putExtra("entity", entity);
76 | getActivity().startActivity(intent);
77 | }
78 | });
79 | }
80 |
81 | private void initViews() {
82 |
83 | mListView = (ListView) getView().findViewById(R.id.fragment_healthy_lv);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_shopping_cart.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
27 |
28 |
34 |
35 |
40 |
41 |
47 |
48 |
58 |
59 |
66 |
76 |
77 |
78 |
79 |
80 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/fragment/BookFragment.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.fragment;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.AdapterView;
11 | import android.widget.ListView;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import io.github.sunxu3074.shoppoingdemo.Entity.HealthyEntity;
17 | import io.github.sunxu3074.shoppoingdemo.R;
18 | import io.github.sunxu3074.shoppoingdemo.activity.ProductDetailsActivity;
19 | import io.github.sunxu3074.shoppoingdemo.adapter.HealthyAdapter;
20 |
21 | /**
22 | * Created by zhangyan on 2015/10/26.
23 | */
24 | public class BookFragment extends Fragment {
25 |
26 | private ListView mListView;
27 |
28 | private List mDatas = new ArrayList<>();
29 |
30 | private HealthyAdapter mAdapter;
31 |
32 | @Nullable
33 | @Override
34 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
35 | savedInstanceState) {
36 | return inflater.inflate(R.layout.fragment_healthy, container, false);
37 | }
38 |
39 | @Override
40 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
41 | super.onActivityCreated(savedInstanceState);
42 | initViews();
43 | addListeners();
44 | initDatas();
45 | }
46 | /**
47 | * 初始化数据
48 | */
49 | private void initDatas() {
50 | mDatas.add(new HealthyEntity("30001", "90%的薬不能吃",
51 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者", 92, 123, R.drawable.book_1));
52 | mDatas.add(new HealthyEntity("30002", "关心中老年人的健康",
53 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者", 34, 159, R.drawable.book_2));
54 | mDatas.add(new HealthyEntity("30003", "科舟求健",
55 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者", 45, 55, R.drawable.book_3));
56 | mDatas.add(new HealthyEntity("30004", "吃的百科",
57 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者", 36, 25, R.drawable.book_4));
58 | mDatas.add(new HealthyEntity("30005", "一辈子做纤柔女人",
59 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者", 77, 78, R.drawable.book_5));
60 | mDatas.add(new HealthyEntity("30006","最伟大排毒术",
61 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者", 19, 104, R.drawable.book_6));
62 | mDatas.add(new HealthyEntity("30007", "速食主义",
63 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者", 27, 23, R.drawable.book_7));
64 | mDatas.add(new HealthyEntity("30008", "我们到底应该怎么吃",
65 | "作用范围:失眠,神经衰弱,神经紧张的人,气血循环不良,体虚呆滞者,四肢麻痹,腰酸背痛之人士,肠胃功能不佳,消化不良之人士,运动不足,年长体弱,手脚冰冷者", 48, 88, R.drawable.book_8));
66 |
67 | mAdapter = new HealthyAdapter(getActivity(), mDatas);
68 | mListView.setAdapter(mAdapter);
69 |
70 | }
71 |
72 | private void addListeners() {
73 |
74 | mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
75 | @Override
76 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
77 | HealthyAdapter adapter = (HealthyAdapter) parent.getAdapter();
78 | HealthyEntity entity = (HealthyEntity) adapter.getItem(position);
79 | Intent intent = new Intent(getActivity(), ProductDetailsActivity.class);
80 | intent.putExtra("entity", entity);
81 | getActivity().startActivity(intent);
82 | }
83 | });
84 | }
85 |
86 | private void initViews() {
87 |
88 | mListView = (ListView) getView().findViewById(R.id.fragment_healthy_lv);
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_product_details.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
24 |
25 |
32 |
33 |
42 |
43 |
51 |
52 |
53 |
64 |
65 |
66 |
74 |
75 |
82 |
83 |
87 |
88 |
97 |
98 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/popup_add_to_cart.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
23 |
24 |
29 |
30 |
41 |
42 |
53 |
54 |
55 |
56 |
57 |
64 |
65 |
66 |
67 |
72 |
73 |
78 |
79 |
87 |
88 |
89 |
99 |
100 |
110 |
111 |
122 |
123 |
124 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/activity/CategoryDetailsActivity.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.activity;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.os.Bundle;
5 | import android.support.design.widget.TabLayout;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentPagerAdapter;
8 | import android.support.v4.view.ViewPager;
9 | import android.text.Spannable;
10 | import android.text.SpannableString;
11 | import android.text.style.ImageSpan;
12 | import android.util.Log;
13 | import android.view.Menu;
14 | import android.view.MenuItem;
15 |
16 | import io.github.sunxu3074.shoppoingdemo.R;
17 | import io.github.sunxu3074.shoppoingdemo.consts.ConstUtils;
18 | import io.github.sunxu3074.shoppoingdemo.fragment.BookFragment;
19 | import io.github.sunxu3074.shoppoingdemo.fragment.FootWashFragment;
20 | import io.github.sunxu3074.shoppoingdemo.fragment.PillFragment;
21 |
22 | public class CategoryDetailsActivity extends BaseActivity {
23 |
24 |
25 |
26 | private TabLayout mTabLayout;
27 | private ViewPager mViewPager;
28 |
29 | private String[] mTitles = new String[]{"保健产品", "丸剂", "书籍",};
30 |
31 | /**
32 | * 记录当前的position
33 | */
34 | private int currentPosition;
35 |
36 | private int[] icons = {R.drawable.foot_icon, R.drawable.pill_icon, R.drawable.book_icon};
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_category_details);
42 |
43 | initViews();
44 |
45 | }
46 |
47 | private void initViews() {
48 |
49 | mViewPager = (ViewPager) findViewById(R.id.activity_category_viewpager);
50 | mViewPager.setOffscreenPageLimit(3);
51 | mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
52 | @Override
53 | public Fragment getItem(int position) {
54 | Log.d("position", position+"");
55 | if (position == 0) {
56 | return new FootWashFragment();
57 | } else if (position == 1) {
58 | return new PillFragment();
59 | } else if (position == 2) {
60 | return new BookFragment();
61 | }
62 | return null;
63 | }
64 |
65 | @Override
66 | public int getCount() {
67 | return mTitles.length;
68 | }
69 |
70 | @Override
71 | public CharSequence getPageTitle(int position) {
72 | // Generate title based on item position
73 | Drawable d = getResources().getDrawable(icons[position]);
74 | d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
75 |
76 | // Replace blank spaces with image icon
77 | SpannableString sb = new SpannableString(" " + mTitles[position]);
78 | ImageSpan imageSpan = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
79 | sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
80 | return sb;
81 | }
82 |
83 | });
84 |
85 | //TODO
86 | currentPosition = getIntent().getIntExtra(ConstUtils.ALLACTIVITY_KEY_POSITION, 0);
87 | mTabLayout = (TabLayout) findViewById(R.id.activity_category_tablayout);
88 | mTabLayout.setupWithViewPager(mViewPager);
89 |
90 | // mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
91 |
92 | /*
93 | mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
94 | @Override
95 | public void onTabSelected(TabLayout.Tab tab) {
96 | Log.d("tab position", tab.getPosition() + "");
97 | // mViewPager.setCurrentItem(tab.getPosition());
98 | // mTabLayout.getTabAt(tab.getPosition()).select();
99 | }
100 |
101 | @Override
102 | public void onTabUnselected(TabLayout.Tab tab) {
103 |
104 | }
105 |
106 | @Override
107 | public void onTabReselected(TabLayout.Tab tab) {
108 |
109 | }
110 | });
111 | */
112 | //TabLayout.TabLayoutOnPageChangeListener 中记录了tab被点击怎么goto的方法..
113 | mTabLayout.getTabAt(currentPosition).select();
114 |
115 | }
116 |
117 | @Override
118 | public boolean onCreateOptionsMenu(Menu menu) {
119 | // Inflate the menu; this adds items to the action bar if it is present.
120 | getMenuInflater().inflate(R.menu.menu_category_details, menu);
121 | return true;
122 | }
123 |
124 | @Override
125 | public boolean onOptionsItemSelected(MenuItem item) {
126 | // Handle action bar item clicks here. The action bar will
127 | // automatically handle clicks on the Home/Up button, so long
128 | // as you specify a parent activity in AndroidManifest.xml.
129 | int id = item.getItemId();
130 |
131 | //noinspection SimplifiableIfStatement
132 | if (id == R.id.action_settings) {
133 | return true;
134 | }
135 |
136 | return super.onOptionsItemSelected(item);
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/activity/ShoppingCartActivity.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.activity;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.database.sqlite.SQLiteDatabase;
6 | import android.os.Bundle;
7 | import android.os.Handler;
8 | import android.os.Message;
9 | import android.view.LayoutInflater;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.BaseAdapter;
15 | import android.widget.Button;
16 | import android.widget.CheckBox;
17 | import android.widget.CompoundButton;
18 | import android.widget.ImageView;
19 | import android.widget.ListView;
20 | import android.widget.TextView;
21 |
22 | import java.util.ArrayList;
23 | import java.util.HashMap;
24 |
25 | import io.github.sunxu3074.shoppoingdemo.Entity.ShoppingCartEntity;
26 | import io.github.sunxu3074.shoppoingdemo.R;
27 | import io.github.sunxu3074.shoppoingdemo.consts.ConstUtils;
28 | import io.github.sunxu3074.shoppoingdemo.db.ProductReadDbHelper;
29 | import io.github.sunxu3074.shoppoingdemo.db.ProductReaderContract;
30 |
31 | public class ShoppingCartActivity extends BaseActivity {
32 |
33 | private static final int MSG_WHAT = 0x223;
34 |
35 | private ListView mListView;
36 | /**
37 | * 结算
38 | */
39 | private Button mBtnClearing;
40 |
41 | private TextView mTVTotal;
42 |
43 | private CheckBox mCheckBox;
44 |
45 | /**
46 | * 合计
47 | */
48 | private int mTotalMoney = 0;
49 | private int mTotalChecked = 0;
50 |
51 |
52 | private ArrayList mDatas = new ArrayList<>();
53 |
54 | private ProductReadDbHelper mDbHelper = new ProductReadDbHelper(this);
55 |
56 | private ShoppingCartAdapter mAdapter;
57 |
58 | private Handler mHandler = new Handler() {
59 | @Override
60 | public void handleMessage(Message msg) {
61 | int what = msg.what;
62 | switch (what) {
63 | case MSG_WHAT:
64 | mAdapter = new ShoppingCartAdapter(getApplication(), mDatas);
65 | mListView.setAdapter(mAdapter);
66 | addListeners();
67 | break;
68 | }
69 | }
70 | };
71 |
72 | @Override
73 |
74 | protected void onCreate(Bundle savedInstanceState) {
75 | super.onCreate(savedInstanceState);
76 | setContentView(R.layout.activity_shopping_cart);
77 |
78 | initViews();
79 | initDatas();
80 | }
81 |
82 | private void addListeners() {
83 |
84 | mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
85 | @Override
86 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
87 | HashMap map = new HashMap();
88 | for (int i = 0; i < mDatas.size() ; i++) {
89 | map.put(i, isChecked);
90 | }
91 | mAdapter.setmMaps(map);
92 | mAdapter.notifyDataSetChanged();
93 | }
94 | });
95 | }
96 |
97 | private void initViews() {
98 |
99 | mListView = (ListView) findViewById(R.id.lv_shopping_cart_activity);
100 | mBtnClearing = (Button) findViewById(R.id.btn_activity_shopping_cart_clearing);
101 | mTVTotal = (TextView) findViewById(R.id.tv_activity_shopping_cart_total);
102 | mCheckBox = (CheckBox) findViewById(R.id.cb_activity_shopping_cart);
103 |
104 | }
105 |
106 | private void initDatas() {
107 |
108 | final SQLiteDatabase db = mDbHelper.getReadableDatabase();
109 | final Cursor cursor = db.query(ProductReaderContract.ProductEntry.TABLE_NAME, null, null,
110 | null,
111 | null, null, null);
112 |
113 | new Thread() {
114 | @Override
115 | public void run() {
116 | if (cursor != null) {
117 | for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
118 | String id = cursor.getString(cursor.getColumnIndex
119 | (ProductReaderContract.ProductEntry
120 | .COLUMN_NAME_ENTRY_ID));
121 | String name = cursor.getString(cursor.getColumnIndex
122 | (ProductReaderContract.ProductEntry
123 | .COLUMN_NAME_NAME));
124 | ;
125 | String category = cursor.getString(cursor.getColumnIndex
126 | (ProductReaderContract.ProductEntry
127 | .COLUMN_NAME_CATEGORY));
128 | int price = Integer.parseInt(cursor.getString(cursor.getColumnIndex
129 | (ProductReaderContract.ProductEntry.COLUMN_NAME_PRICE)));
130 | int number = Integer.parseInt(cursor.getString(cursor.getColumnIndex
131 | (ProductReaderContract.ProductEntry.COLUMN_NAME_NUMBER)));
132 | ShoppingCartEntity entity = new ShoppingCartEntity(id, name, category,
133 | price, number, Integer.parseInt(id));
134 | mDatas.add(entity);
135 | }
136 | if (cursor != null) {
137 | cursor.close();
138 | }
139 | if (db != null && db.isOpen()) {
140 | db.close();
141 | }
142 | Message message = Message.obtain();
143 | message.what = MSG_WHAT;
144 | mHandler.sendMessage(message);
145 | }
146 | }
147 | }.start();
148 | }
149 |
150 | @Override
151 | public boolean onCreateOptionsMenu(Menu menu) {
152 | // Inflate the menu; this adds items to the action bar if it is present.
153 | getMenuInflater().inflate(R.menu.menu_shopping_cart, menu);
154 | return true;
155 | }
156 |
157 | @Override
158 | public boolean onOptionsItemSelected(MenuItem item) {
159 | // Handle action bar item clicks here. The action bar will
160 | // automatically handle clicks on the Home/Up button, so long
161 | // as you specify a parent activity in AndroidManifest.xml.
162 | int id = item.getItemId();
163 |
164 | //noinspection SimplifiableIfStatement
165 | if (id == R.id.action_settings) {
166 | return true;
167 | }
168 |
169 | return super.onOptionsItemSelected(item);
170 | }
171 |
172 | private class ShoppingCartAdapter extends BaseAdapter {
173 |
174 | private LayoutInflater mInflater;
175 | private ArrayList mDatas = new ArrayList<>();
176 | private ViewHolder holder;
177 |
178 | public HashMap mMaps = new HashMap<>();
179 |
180 | public HashMap getMap() {
181 | return mMaps;
182 | }
183 |
184 | public void setmMaps(HashMap mMaps){
185 | this.mMaps = mMaps;
186 | }
187 |
188 |
189 | public ShoppingCartAdapter(Context context, ArrayList mDatas) {
190 | mInflater = LayoutInflater.from(context);
191 | this.mDatas = mDatas;
192 | for (int i = 0; i < mDatas.size() ; i++) {
193 | mMaps.put(i, false);
194 | }
195 | }
196 |
197 | @Override
198 | public int getCount() {
199 | return mDatas.size();
200 | }
201 |
202 | @Override
203 | public Object getItem(int position) {
204 | return mDatas.get(position);
205 | }
206 |
207 | @Override
208 | public long getItemId(int position) {
209 | return position;
210 | }
211 |
212 | @Override
213 | public View getView(int position, View convertView, ViewGroup parent) {
214 | holder = null;
215 | if (convertView == null) {
216 | holder = new ViewHolder();
217 | convertView = mInflater.inflate(R.layout.item_shopping_cart, parent, false);
218 | holder.cb = (CheckBox) convertView.findViewById(R.id.cb_item_shopping_cart);
219 | holder.name = (TextView) convertView.findViewById(R.id.tv_item_shopping_cart_name);
220 | holder.category = (TextView) convertView.findViewById(R.id
221 | .tv_item_shopping_cart_category);
222 | holder.price = (TextView) convertView.findViewById(R.id
223 | .tv_item_shopping_cart_price);
224 | holder.number = (TextView) convertView.findViewById(R.id
225 | .tv_item_shopping_cart_number);
226 | holder.img = (ImageView) convertView.findViewById(R.id
227 | .img_item_shopping_cart_number);
228 | convertView.setTag(holder);
229 | } else {
230 | holder = (ViewHolder) convertView.getTag();
231 | }
232 |
233 | final ShoppingCartEntity entity = (ShoppingCartEntity) getItem(position);
234 | holder.category.setText(entity.getCategory());
235 | holder.name.setText(entity.getName());
236 | holder.price.setText(entity.getPrice() + "");
237 | holder.number.setText("x" + entity.getNumber());
238 | holder.img.setImageResource(ConstUtils.PICTURES[entity.getImgUrl() / 10000 -
239 | 1][entity.getImgUrl() % 10000 - 1]);
240 | holder.cb.setChecked(getMap().get(position));
241 |
242 | holder.cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
243 | @Override
244 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
245 | if (isChecked) {
246 | mTotalMoney += entity.getNumber() * entity.getPrice();
247 | mTotalChecked++;
248 | } else {
249 | mTotalChecked--;
250 | mTotalMoney -= entity.getNumber() * entity.getPrice();
251 | }
252 | mBtnClearing.setText("结算(" + mTotalChecked + ")");
253 | mTVTotal.setText("合计:¥" + mTotalMoney);
254 | }
255 | });
256 |
257 | return convertView;
258 | }
259 |
260 | class ViewHolder {
261 | CheckBox cb;
262 | ImageView img;
263 | TextView name, category, price, number;
264 | }
265 | }
266 |
267 | }
268 |
--------------------------------------------------------------------------------
/ShoppingDemo.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
38 |
39 |
40 |
209 |
210 |
211 |
222 |
223 |
224 |
--------------------------------------------------------------------------------
/.idea/findbugs-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
13 |
14 |
31 |
32 |
33 |
202 |
203 |
204 |
215 |
216 |
217 |
224 |
225 |
226 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/sunxu3074/shoppoingdemo/activity/ProductDetailsActivity.java:
--------------------------------------------------------------------------------
1 | package io.github.sunxu3074.shoppoingdemo.activity;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Intent;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.drawable.ColorDrawable;
10 | import android.os.Bundle;
11 | import android.os.Handler;
12 | import android.os.Message;
13 | import android.support.v7.app.ActionBar;
14 | import android.view.Gravity;
15 | import android.view.LayoutInflater;
16 | import android.view.Menu;
17 | import android.view.MenuItem;
18 | import android.view.View;
19 | import android.view.WindowManager;
20 | import android.widget.Button;
21 | import android.widget.ImageView;
22 | import android.widget.PopupWindow;
23 | import android.widget.TextView;
24 | import android.widget.Toast;
25 |
26 | import io.github.sunxu3074.shoppoingdemo.Entity.HealthyEntity;
27 | import io.github.sunxu3074.shoppoingdemo.R;
28 | import io.github.sunxu3074.shoppoingdemo.db.ProductReadDbHelper;
29 | import io.github.sunxu3074.shoppoingdemo.db.ProductReaderContract;
30 |
31 | public class ProductDetailsActivity extends BaseActivity {
32 |
33 | private static final int QUERY_YES = 0x100;
34 | private static final int QUERY_NO = 0x101;
35 |
36 | private static boolean ISQUERYED = false;
37 |
38 | private HealthyEntity entity;
39 |
40 | private TextView mTVDetails;
41 | private TextView mTVList;
42 | private TextView mTVNumber;
43 | private TextView mTVPopDetails;
44 | private TextView mTVPrice;
45 | private TextView mTVTopPrice;
46 | private TextView mTVPopCategory;
47 |
48 | private Button mBtnAddToCart;
49 | private Button mBtnMinute;
50 | private Button mBtnPlus;
51 |
52 | private View mPop;
53 |
54 | private PopupWindow mPopupWindow;
55 |
56 | private ImageView mImgDetails;
57 | private ImageView mImgClose;
58 | private ImageView mImgIcon;
59 |
60 | private Button mBtnOK;
61 |
62 | /**
63 | * PopupWindow是否打开
64 | */
65 | private boolean isPopOpened;
66 |
67 | /**
68 | * 购买商品的数量
69 | */
70 | private int number = 1;
71 |
72 | private Handler handler = new Handler() {
73 | @Override
74 | public void handleMessage(Message msg) {
75 | int what = msg.what;
76 | switch (what) {
77 | case QUERY_YES:
78 | int number = (int) msg.obj;
79 | updateDatebase(number);
80 | break;
81 | case QUERY_NO:
82 | insert2Sqlite();
83 | break;
84 | }
85 | }
86 | };
87 |
88 | private SQLiteDatabase db;
89 |
90 |
91 | @Override
92 | protected void onCreate(Bundle savedInstanceState) {
93 | super.onCreate(savedInstanceState);
94 | setContentView(R.layout.activity_product_details);
95 |
96 | ActionBar actionBar = getSupportActionBar();
97 | actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#33000000")));
98 | //google的actionbar是分为上下两栏显示的,上面的代码只能设置顶部actionbar的背景色,
99 | //为了让下面的背景色一致,还需要添加一行代码:
100 | actionBar.setSplitBackgroundDrawable(new ColorDrawable(Color.parseColor("#33000000")));
101 |
102 | initViews();
103 | initDatas();
104 | addListeners();
105 | }
106 |
107 | private void addListeners() {
108 | mBtnAddToCart.setOnClickListener(new View.OnClickListener() {
109 | @Override
110 | public void onClick(View v) {
111 | if (isPopOpened == false) {
112 | setWindowBehind(true);
113 | mPopupWindow.setAnimationStyle(R.style.PopupWindowStyle);
114 | mPopupWindow.showAtLocation(mImgDetails, Gravity.BOTTOM, 0, 0);
115 | isPopOpened = true;
116 |
117 | }
118 | }
119 | });
120 |
121 | mBtnOK.setOnClickListener(new View.OnClickListener() {
122 | @Override
123 | public void onClick(View v) {
124 |
125 | //TODO 发送请求到后台
126 | // 保存产品信息到数据库
127 |
128 | queryDatebase();
129 |
130 | Toast.makeText(getApplication(), "您已经成功添加到购物车~", Toast.LENGTH_LONG).show();
131 |
132 | if (isPopOpened == true) {
133 | setWindowBehind(false);
134 | mPopupWindow.dismiss();
135 | isPopOpened = false;
136 | }
137 | }
138 | });
139 |
140 | mImgClose.setOnClickListener(new View.OnClickListener() {
141 | @Override
142 | public void onClick(View v) {
143 | if (isPopOpened == true) {
144 | setWindowBehind(false);
145 | mPopupWindow.dismiss();
146 | isPopOpened = false;
147 | }
148 | }
149 | });
150 |
151 | mBtnPlus.setOnClickListener(new View.OnClickListener() {
152 | @Override
153 | public void onClick(View v) {
154 | ++number;
155 | mTVNumber.setText(number + "");
156 | }
157 | });
158 |
159 | mBtnMinute.setOnClickListener(new View.OnClickListener() {
160 | @Override
161 | public void onClick(View v) {
162 | if (number != 1) {
163 | number--;
164 | mTVNumber.setText(number + "");
165 | }
166 | }
167 | });
168 |
169 | }
170 |
171 | /**
172 | * 插入数据库
173 | */
174 | private void insert2Sqlite() {
175 |
176 | // 购买数量 number
177 | // 购买种类
178 | int price = entity.getPrice(); // 购买价格
179 | String id = entity.getId(); // 购买id
180 | String category = "保健产品";
181 | if (Integer.parseInt(id) > 30000) {
182 | category = "书籍";
183 | } else if (Integer.parseInt(id) > 20000) {
184 | category = "丸剂";
185 | } else {
186 | category = "保健产品";
187 | }
188 | String name = entity.getName(); // 购买名称
189 |
190 | ProductReadDbHelper mDbHelper = new ProductReadDbHelper(getApplication());
191 | db = mDbHelper.getWritableDatabase();
192 |
193 | ContentValues values = new ContentValues();
194 | values.put(ProductReaderContract.ProductEntry.COLUMN_NAME_ENTRY_ID, id);
195 | values.put(ProductReaderContract.ProductEntry.COLUMN_NAME_PRICE, price + "");
196 | values.put(ProductReaderContract.ProductEntry.COLUMN_NAME_NAME, name);
197 | values.put(ProductReaderContract.ProductEntry.COLUMN_NAME_NUMBER, number + "");
198 | values.put(ProductReaderContract.ProductEntry.COLUMN_NAME_CATEGORY, category);
199 |
200 | long rawID = -1;
201 |
202 | rawID = db.insert(
203 | ProductReaderContract.ProductEntry.TABLE_NAME,
204 | null,
205 | values);
206 |
207 | Toast.makeText(getApplication(), "rawID = " + rawID, Toast.LENGTH_LONG).show();
208 | }
209 |
210 | /**
211 | * 查询数据库
212 | */
213 | private void queryDatebase() {
214 | // String[] projection = {
215 | // ProductReaderContract.ProductEntry.COLUMN_NAME_ENTRY_ID,
216 | // ProductReaderContract.ProductEntry.COLUMN_NAME_NUMBER,
217 | // };
218 |
219 | ISQUERYED = false;
220 |
221 | ProductReadDbHelper mDbHelper = new ProductReadDbHelper(getApplication());
222 | db = mDbHelper.getWritableDatabase();
223 |
224 | Cursor c = null;
225 | try {
226 | String selection = ProductReaderContract.ProductEntry.COLUMN_NAME_ENTRY_ID + " = ?";
227 | String[] selectionArgs = new String[]{entity.getId()};
228 | c = db.query(
229 | ProductReaderContract.ProductEntry.TABLE_NAME, // The table to query
230 | // projection, // The columns to return
231 | null,
232 | selection, // The columns for the WHERE clause
233 | selectionArgs, // The values for the WHERE clause
234 | null, // don't group the rows
235 | null, // don't filter by row groups
236 | null // The sort order
237 | );
238 |
239 | if (c != null) {
240 | for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
241 | String itemId = c.getString(c.getColumnIndex(ProductReaderContract.ProductEntry
242 | .COLUMN_NAME_ENTRY_ID));
243 | int number = Integer.parseInt(c.getString(c.getColumnIndex(ProductReaderContract
244 | .ProductEntry
245 | .COLUMN_NAME_NUMBER)));
246 | if (itemId.equals(entity.getId())) {
247 | Toast.makeText(getApplication(), "true", Toast.LENGTH_LONG).show();
248 | ISQUERYED = true;
249 | Message message = Message.obtain();
250 | message.what = QUERY_YES;
251 | message.obj = number;
252 | handler.sendMessage(message);
253 | }
254 | }
255 | }
256 | if (!ISQUERYED) {
257 | Message message = Message.obtain();
258 | message.what = QUERY_NO;
259 | handler.sendMessage(message);
260 | }
261 | } finally {
262 | if (c != null) {
263 | c.close();
264 | }
265 | }
266 |
267 | }
268 |
269 |
270 | /**
271 | * 更新数据库
272 | */
273 | private void updateDatebase(int sqlNumber) {
274 |
275 | sqlNumber += number;// 购买数量
276 |
277 | // New value for one column
278 | ContentValues values = new ContentValues();
279 | values.put(ProductReaderContract.ProductEntry.COLUMN_NAME_NUMBER, sqlNumber + "");
280 |
281 | // Which row to update, based on the ID
282 | String selection = ProductReaderContract.ProductEntry.COLUMN_NAME_ENTRY_ID + " LIKE ?";
283 | String[] selectionArgs = {String.valueOf(entity.getId())};
284 |
285 | int count = db.update(
286 | ProductReaderContract.ProductEntry.TABLE_NAME,
287 | values,
288 | selection,
289 | selectionArgs);
290 | Toast.makeText(getApplication(), "count = " + count + "/r/n number=" + sqlNumber, Toast
291 | .LENGTH_LONG).show();
292 | }
293 |
294 |
295 | private void initViews() {
296 | mTVList = (TextView) findViewById(R.id.tv_activity_product_details_list);
297 | mTVDetails = (TextView) findViewById(R.id.tv_activity_product_details_details);
298 | mBtnAddToCart = (Button) findViewById(R.id.btn_activity_product_details_add_to_cart);
299 | mImgDetails = (ImageView) findViewById(R.id.img_activity_product);
300 | mTVTopPrice = (TextView) findViewById(R.id.tv_activity_product_details_price);
301 |
302 | mPop = LayoutInflater.from(this).inflate(R.layout.popup_add_to_cart, null);
303 | mImgIcon = (ImageView) mPop.findViewById(R.id.img_pop_icon);
304 | mBtnOK = (Button) mPop.findViewById(R.id.btn_pop_ok);
305 | mBtnMinute = (Button) mPop.findViewById(R.id.btn_pop_minute);
306 | mBtnPlus = (Button) mPop.findViewById(R.id.btn_pop_plus);
307 | mImgClose = (ImageView) mPop.findViewById(R.id.img_pop_close);
308 | mTVNumber = (TextView) mPop.findViewById(R.id.tv_pop_number);
309 | mTVPopDetails = (TextView) mPop.findViewById(R.id.tv_pop_details);
310 | mTVPrice = (TextView) mPop.findViewById(R.id.tv_pop_price);
311 | mTVPopCategory = (TextView) mPop.findViewById(R.id.tv_pop_category);
312 | mPopupWindow = new PopupWindow(mPop, getWindow().getAttributes().width, 1080);
313 | }
314 |
315 | private void initDatas() {
316 |
317 | entity = (HealthyEntity) getIntent().getSerializableExtra("entity");
318 |
319 | String category = "";
320 | mImgDetails.setImageResource(entity.getImgUrl());
321 | mTVDetails.setText(entity.getDetails());
322 | mTVTopPrice.setText("¥" + entity.getPrice());
323 | mTVPrice.setText("¥" + entity.getPrice());
324 | mTVPopDetails.setText(entity.getDetails());
325 | mTVList.setText("¥" + (entity.getPrice() + 900));
326 | mImgIcon.setImageResource(entity.getImgUrl());
327 | if (Integer.parseInt(entity.getId()) / 10000 == 1) {
328 | category = "保健产品";
329 | } else if (Integer.parseInt(entity.getId()) / 10000 == 2) {
330 | category = "丸剂";
331 | } else {
332 | category = "书籍";
333 | }
334 | mTVPopCategory.setText(category);
335 | mTVList.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
336 |
337 | }
338 |
339 | @Override
340 | public boolean onCreateOptionsMenu(Menu menu) {
341 | // Inflate the menu; this adds items to the action bar if it is present.
342 | getMenuInflater().inflate(R.menu.menu_product_details, menu);
343 | return true;
344 | }
345 |
346 | @Override
347 | public boolean onOptionsItemSelected(MenuItem item) {
348 | // Handle action bar item clicks here. The action bar will
349 | // automatically handle clicks on the Home/Up button, so long
350 | // as you specify a parent activity in AndroidManifest.xml.
351 | int id = item.getItemId();
352 |
353 | //noinspection SimplifiableIfStatement
354 | if (id == R.id.action_settings) {
355 | return true;
356 | } else if (id == R.id.action_shopping) {
357 | Intent intent = new Intent(getApplication(), ShoppingCartActivity.class);
358 | startActivity(intent);
359 | }
360 |
361 | return super.onOptionsItemSelected(item);
362 | }
363 |
364 | @Override
365 | public void onBackPressed() {
366 |
367 | if (isPopOpened) {
368 | setWindowBehind(false);
369 | mPopupWindow.dismiss();
370 | isPopOpened = false;
371 | return;
372 | }
373 | super.onBackPressed();
374 | }
375 |
376 | @Override
377 | protected void onDestroy() {
378 | super.onDestroy();
379 | if (isPopOpened) {
380 | setWindowBehind(false);
381 | mPopupWindow.dismiss();
382 | isPopOpened = false;
383 | mPopupWindow = null;
384 | }
385 |
386 | if (db != null && db.isOpen()) {
387 | db.close();
388 | db = null;
389 | }
390 | }
391 |
392 | private void setWindowBehind(boolean isSetWindowBehind) {
393 | final WindowManager.LayoutParams lp = getWindow().getAttributes();
394 | if (isSetWindowBehind) {
395 | lp.alpha = 0.3f;
396 | } else {
397 | lp.alpha = 1.0f;
398 | }
399 | handler.postDelayed(new Runnable() {
400 | @Override
401 | public void run() {
402 | getWindow().setAttributes(lp);
403 | }
404 | }, 300);
405 |
406 | }
407 |
408 | }
409 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
118 |
119 |
120 |
289 |
290 |
291 |
302 |
303 |
304 |
--------------------------------------------------------------------------------