├── .gitignore
├── README.md
├── app
├── build.gradle
├── libs
│ └── achartengine-1.1.0.jar
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ ├── bmi.html
│ └── bmr.html
│ ├── java
│ └── com
│ │ └── jhuster
│ │ └── eweightscale
│ │ ├── AboutActivity.java
│ │ ├── ChartActivity.java
│ │ ├── CommonUtil.java
│ │ ├── Configuration.java
│ │ ├── DataActivity.java
│ │ ├── MainActivity.java
│ │ ├── MoreActivity.java
│ │ ├── PersonalActivity.java
│ │ ├── SettingActivity.java
│ │ ├── SquareActivity.java
│ │ ├── WeightData.java
│ │ ├── WeightDataAdapter.java
│ │ ├── WhatActivity.java
│ │ ├── chart
│ │ ├── ChartAdapter.java
│ │ ├── ChartFolder.java
│ │ ├── ChartTable.java
│ │ ├── DayChartAdapter.java
│ │ ├── MonthChartAdapter.java
│ │ └── YearChartAdapter.java
│ │ ├── core
│ │ ├── DateHelper.java
│ │ ├── WeightDB.java
│ │ └── WeightDBHelper.java
│ │ └── widget
│ │ ├── ChartDateSelector.java
│ │ ├── ChartModeSelector.java
│ │ ├── InputDialog.java
│ │ ├── SearchDialog.java
│ │ └── SquareItemWidget.java
│ └── res
│ ├── color
│ └── tablehost_text_selector.xml
│ ├── drawable-hdpi
│ ├── blue_btn_normal.9.png
│ ├── blue_btn_pressed.9.png
│ ├── content_bg.9.png
│ ├── data_bg.9.png
│ ├── ic_action_add.png
│ ├── ic_action_search.png
│ ├── ic_goicon.png
│ ├── ic_green.png
│ ├── ic_launcher.png
│ ├── ic_red.png
│ ├── ic_yellow.png
│ ├── icon_chart.png
│ ├── icon_chart_s.png
│ ├── icon_data.png
│ ├── icon_data_s.png
│ ├── icon_more.png
│ ├── icon_more_s.png
│ ├── icon_search.png
│ ├── icon_square.png
│ ├── icon_square_s.png
│ └── img_about_app.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── drawable
│ ├── actionbar_bg.xml
│ ├── blue_btn_selector.xml
│ ├── item_click_selector.xml
│ ├── menu_chart_selector.xml
│ ├── menu_data_selector.xml
│ ├── menu_more_selector.xml
│ ├── menu_square_selector.xml
│ ├── shape_bg.xml
│ └── timestamp_bg.xml
│ ├── layout
│ ├── activity_about.xml
│ ├── activity_chart.xml
│ ├── activity_data.xml
│ ├── activity_main.xml
│ ├── activity_more.xml
│ ├── activity_personal.xml
│ ├── activity_setting.xml
│ ├── activity_square.xml
│ ├── activity_what.xml
│ ├── dialog_input_weight.xml
│ ├── dialog_search.xml
│ ├── widget_birthday_selecter.xml
│ ├── widget_chartdate_selector.xml
│ ├── widget_height_input.xml
│ ├── widget_search_input.xml
│ ├── widget_search_mode_selecter.xml
│ ├── widget_setting_item.xml
│ ├── widget_sex_selecter.xml
│ ├── widget_square_item.xml
│ └── widget_weight_item.xml
│ ├── menu
│ ├── data_menu.xml
│ └── menu_actions.xml
│ ├── values-v11
│ └── styles.xml
│ ├── values-v14
│ └── styles.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshots
├── download.png
└── home.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.ap_
3 |
4 | # files for the dex VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 |
10 | # generated files
11 | bin/
12 | gen/
13 |
14 | # Local configuration file (sdk path, etc)
15 | local.properties
16 |
17 | # Proguard folder generated by Eclipse
18 | proguard/
19 |
20 | # Ignore gradle files
21 | .gradle/
22 | build/
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 | .settings/
28 |
29 | # Intellij project files
30 | *.iml
31 | *.ipr
32 | *.iws
33 | .idea/
34 |
35 | # Mac system files
36 | .DS_Store
37 |
38 | *.keystore
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 体重档案
2 |
3 | 一款可以记录和查询体重的应用,功能介绍如下
4 |
5 | > * 支持体重数据的添加、删除、查询等功能
6 | > * 动态生成体重曲线图,支持手势缩放
7 | > * 实时计算BMI值,并进行诊断,给出健康体重范围
8 |
9 | ## 应用截图
10 |
11 |
12 |
13 | ## 文章介绍
14 |
15 | [我的Android开源项目:体重档案](http://ticktick.blog.51cto.com/823160/1687127)
16 |
17 | ## 下载地址
18 |
19 | - [本站下载](http://www.jhuster.com/app/EWeightScale/EWeightScale.apk)
20 |
21 | - [安卓市场](http://apk.hiapk.com/appinfo/com.jhuster.eweightscale)
22 |
23 | - [360手机助手](http://zhushou.360.cn/detail/index/soft_id/3073776?recrefer=SE_D_%E4%BD%93%E9%87%8D%E6%A1%A3%E6%A1%88#nogo)
24 |
25 | - [百度手机助手](http://shouji.baidu.com/soft/item?docid=7904186&from=as&f=search_app_%E4%BD%93%E9%87%8D%E6%A1%A3%E6%A1%88%40list_1_title%401%40header_all_input)
26 |
27 | - **二维码扫描**
28 |
29 |
30 |
31 | Thanks
32 | ----------
33 |
34 | 谢谢你的关注,欢迎提供建议和意见,联系方式:lujun.hust@gmail.com
35 |
36 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.jhuster.eweightscale"
9 | minSdkVersion 11
10 | targetSdkVersion 23
11 | }
12 |
13 | buildTypes {
14 | release {
15 | minifyEnabled true
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile files('libs/achartengine-1.1.0.jar')
23 | }
24 |
--------------------------------------------------------------------------------
/app/libs/achartengine-1.1.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/libs/achartengine-1.1.0.jar
--------------------------------------------------------------------------------
/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 /opt/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/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
27 |
29 |
31 |
33 |
35 |
37 |
39 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/assets/bmi.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/assets/bmi.html
--------------------------------------------------------------------------------
/app/src/main/assets/bmr.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/assets/bmr.html
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/AboutActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import android.app.Activity;
14 | import android.os.Bundle;
15 | import android.view.MenuItem;
16 |
17 | public class AboutActivity extends Activity {
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | getActionBar().setDisplayHomeAsUpEnabled(true);
23 | getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
24 | setContentView(R.layout.activity_about);
25 | getActionBar().setTitle(getString(R.string.activity_title_about));
26 | }
27 |
28 | @Override
29 | public boolean onOptionsItemSelected(MenuItem item) {
30 | switch (item.getItemId()) {
31 | case android.R.id.home:
32 | finish();
33 | default:
34 | break;
35 | }
36 | return true;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/ChartActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import android.app.Activity;
14 | import android.os.Bundle;
15 | import android.view.KeyEvent;
16 | import android.view.View;
17 | import android.widget.LinearLayout;
18 | import android.widget.TextView;
19 |
20 | import com.jhuster.eweightscale.Configuration.OnChartModeChangeListener;
21 | import com.jhuster.eweightscale.chart.ChartAdapter;
22 | import com.jhuster.eweightscale.chart.DayChartAdapter;
23 | import com.jhuster.eweightscale.chart.MonthChartAdapter;
24 | import com.jhuster.eweightscale.chart.ChartFolder;
25 | import com.jhuster.eweightscale.chart.YearChartAdapter;
26 | import com.jhuster.eweightscale.core.WeightDB;
27 | import com.jhuster.eweightscale.core.WeightDB.OnDBDataChangeListener;
28 | import com.jhuster.eweightscale.widget.ChartDateSelector;
29 | import com.jhuster.eweightscale.widget.ChartDateSelector.OnDateSelectedListener;
30 |
31 | public class ChartActivity extends Activity implements OnDateSelectedListener,OnChartModeChangeListener,OnDBDataChangeListener {
32 |
33 | private TextView mNoDataTips;
34 | private ChartDateSelector mDateSeletor;
35 | private ChartFolder mChartFolder;
36 | private ChartAdapter mChartAdapter;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_chart);
42 |
43 | mNoDataTips = (TextView) findViewById(R.id.NoDataTipView);
44 | LinearLayout mChartLayout = (LinearLayout)findViewById(R.id.ChartLinearLayout);
45 | mChartFolder = new ChartFolder(mChartLayout);
46 |
47 | mDateSeletor = new ChartDateSelector(findViewById(R.id.WidgetChartDateSelector));
48 | mDateSeletor.setChartMode(Configuration.getChartMode());
49 | mDateSeletor.setOnDateSelectedListener(this);
50 | onDateSelected();
51 |
52 | Configuration.setOnChartModeChangeListener(this);
53 | }
54 |
55 | @Override
56 | public void onResume() {
57 | super.onResume();
58 | WeightDB.getInstance().setOnDBDataChangeListener(this);
59 | }
60 |
61 | @Override
62 | public void onPause() {
63 | WeightDB.getInstance().setOnDBDataChangeListener(null);
64 | super.onPause();
65 | }
66 |
67 | @Override
68 | public void onDateSelected() {
69 | switch(mDateSeletor.getChartMode()) {
70 | case CommonUtil.ChartModeYear:
71 | mChartAdapter = new YearChartAdapter();
72 | break;
73 | case CommonUtil.ChartModeMonth:
74 | mChartAdapter = new MonthChartAdapter(mDateSeletor.getSelectYear());
75 | break;
76 | case CommonUtil.ChartModeDay:
77 | mChartAdapter = new DayChartAdapter(mDateSeletor.getSelectYear(),mDateSeletor.getSelectMonth());
78 | break;
79 | default:
80 | break;
81 | }
82 | mChartFolder.setChartAdapter(mChartAdapter);
83 | onChartViewUpdate();
84 | }
85 |
86 | @Override
87 | public void onDBDataChanged() {
88 | onChartViewUpdate();
89 | }
90 |
91 | @Override
92 | public void onChartModeChanged(int chartmode) {
93 | mDateSeletor.setChartMode(chartmode);
94 | onDateSelected();
95 | }
96 |
97 | protected void onChartViewUpdate() {
98 | mChartFolder.invalidate();
99 | mNoDataTips.setVisibility(mChartAdapter.isEmpty()?View.VISIBLE:View.GONE);
100 | }
101 |
102 | @Override
103 | public boolean onKeyDown(int keyCode, KeyEvent event) {
104 | if (keyCode == KeyEvent.KEYCODE_BACK) {
105 | if (!CommonUtil.onExitProcess(this)) {
106 | return true;
107 | }
108 | }
109 | return super.onKeyDown(keyCode, event);
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/CommonUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import java.text.DecimalFormat;
14 | import android.content.Context;
15 | import android.widget.Toast;
16 |
17 | public class CommonUtil {
18 |
19 | public static final int MinYear = 2013;
20 | public static final int MaxYear = 2020;
21 | public static final String YearUnit = "年";
22 |
23 | public static final int MinMonth = 1;
24 | public static final int MaxMonth = 12;
25 | public static final String MonthUnit = "月";
26 |
27 | public static final int MinDay = 1;
28 | public static final int MaxDay = 31;
29 | public static final String DayUnit = "号";
30 |
31 | public static final int ChartModeYear = 0;
32 | public static final int ChartModeMonth = 1;
33 | public static final int ChartModeDay = 2;
34 |
35 | public static final int UserSexMale = 0;
36 | public static final int UserSexFemale = 1;
37 |
38 | private static final int BACK_KEY_EXIT_TIME_PEROID = 1000;
39 | private static long mLastBackKeyPressedTime = 0;
40 |
41 | public static double calculateBMI(double weight, double height) {
42 | DecimalFormat format = new DecimalFormat("0.00");
43 | double result = weight/(height*height)*10000;
44 | return Double.valueOf(format.format(result).toString());
45 | }
46 |
47 | public static double calculateBMR(int sex, double weight, double height, int age) {
48 | double result = 0.0;
49 | DecimalFormat format = new DecimalFormat("0.00");
50 | if (sex == UserSexMale) {
51 | result = 655 + (9.6*weight) + (1.8*height) - (4.7*age);
52 | }
53 | else {
54 | result = 66 + (13.8*weight) + (5.0*height) - (6.8*age);
55 | }
56 | return Double.valueOf(format.format(result).toString());
57 | }
58 |
59 | public static double calculateMinWeight(double height) {
60 | DecimalFormat format = new DecimalFormat("0.0");
61 | double result = 18.5*height*height/10000;
62 | return Double.valueOf(format.format(result).toString());
63 | }
64 |
65 | public static double calculateMaxWeight(double height) {
66 | DecimalFormat format = new DecimalFormat("0.0");
67 | double result = 24.0*height*height/10000;
68 | return Double.valueOf(format.format(result).toString());
69 | }
70 |
71 | public static boolean onExitProcess(Context context) {
72 | if (System.currentTimeMillis() - mLastBackKeyPressedTime > BACK_KEY_EXIT_TIME_PEROID) {
73 | mLastBackKeyPressedTime = System.currentTimeMillis();
74 | Toast.makeText(context,context.getString(R.string.another_press_to_exit), Toast.LENGTH_SHORT).show();
75 | return false;
76 | }
77 | return true;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/Configuration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import java.util.Calendar;
14 | import android.content.Context;
15 | import android.content.SharedPreferences;
16 | import android.preference.PreferenceManager;
17 |
18 | public class Configuration {
19 |
20 | public static final String CONFIG_FIRST_START = "isFirstStart";
21 |
22 | public static final String CONFIG_USER_SEX = "sex";
23 | public static final String CONFIG_USER_AGE_YEAR = "age_year";
24 | public static final String CONFIG_USER_AGE_MONTH = "age_month";
25 | public static final String CONFIG_USER_AGE_DAY = "age_day";
26 | public static final String CONFIG_USER_HEIGHT = "usr_height";
27 | public static final String CONFIG_CHART_MODE = "x_base";
28 | public static final String CONFIG_CONTINUOUS_DAYS = "continuous_days";
29 |
30 | private static SharedPreferences mSharedPreferences;
31 | private static OnChartModeChangeListener mChartModeChangeListener;
32 |
33 | public static interface OnChartModeChangeListener {
34 | public void onChartModeChanged(int chartmode);
35 | }
36 |
37 | public static void initialize(Context context) {
38 | mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
39 | }
40 |
41 | public static void setOnChartModeChangeListener(OnChartModeChangeListener listener) {
42 | mChartModeChangeListener = listener;
43 | }
44 |
45 | public static boolean isFirstStart() {
46 | return mSharedPreferences.getBoolean(CONFIG_FIRST_START,true);
47 | }
48 |
49 | public static void setFirstStart(boolean isFirstStart) {
50 | SharedPreferences.Editor edit = mSharedPreferences.edit();
51 | edit.putBoolean(CONFIG_FIRST_START, isFirstStart);
52 | edit.commit();
53 | }
54 |
55 | public static void setUserSex(int sex) {
56 | SharedPreferences.Editor edit = mSharedPreferences.edit();
57 | edit.putInt(CONFIG_USER_SEX, sex);
58 | edit.commit();
59 | }
60 |
61 | public static int getUserSex() {
62 | return mSharedPreferences.getInt(CONFIG_USER_SEX, CommonUtil.UserSexMale);
63 | }
64 |
65 | public static void setUserBirthday(int year, int month, int day) {
66 | SharedPreferences.Editor edit = mSharedPreferences.edit();
67 | edit.putInt(CONFIG_USER_AGE_YEAR, year);
68 | edit.putInt(CONFIG_USER_AGE_MONTH, month);
69 | edit.putInt(CONFIG_USER_AGE_DAY, day);
70 | edit.commit();
71 | }
72 |
73 | public static int getUserBirthdayYear() {
74 | return mSharedPreferences.getInt(CONFIG_USER_AGE_YEAR,Calendar.getInstance().get(Calendar.YEAR));
75 | }
76 |
77 | public static int getUserBirthdayMonth() {
78 | return mSharedPreferences.getInt(CONFIG_USER_AGE_MONTH,Calendar.getInstance().get(Calendar.MONTH) + 1);
79 | }
80 |
81 | public static int getUserBirthdayDay() {
82 | return mSharedPreferences.getInt(CONFIG_USER_AGE_DAY,Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
83 | }
84 |
85 | public static int getUserAge() {
86 | return Calendar.getInstance().get(Calendar.YEAR) - getUserBirthdayYear();
87 | }
88 |
89 | public static void setUserHeight(String height) {
90 | SharedPreferences.Editor edit = mSharedPreferences.edit();
91 | edit.putString(CONFIG_USER_HEIGHT, height);
92 | edit.commit();
93 | }
94 |
95 | public static double getUserHeight() {
96 | String heightStr = mSharedPreferences.getString(CONFIG_USER_HEIGHT, "");
97 | if ("".equals(heightStr)) {
98 | return 0;
99 | }
100 | return Double.valueOf(heightStr);
101 | }
102 |
103 | public static void setContinousDays(int days) {
104 | SharedPreferences.Editor edit = mSharedPreferences.edit();
105 | edit.putInt(CONFIG_CONTINUOUS_DAYS,days);
106 | edit.commit();
107 | }
108 |
109 | public static int getContinousDays() {
110 | return mSharedPreferences.getInt(CONFIG_CONTINUOUS_DAYS,0);
111 | }
112 |
113 | public static void setChartMode(int chartmode) {
114 | if (chartmode!=getChartMode()) {
115 | SharedPreferences.Editor edit = mSharedPreferences.edit();
116 | edit.putInt(CONFIG_CHART_MODE, chartmode);
117 | edit.commit();
118 | if (mChartModeChangeListener!=null) {
119 | mChartModeChangeListener.onChartModeChanged(chartmode);
120 | }
121 | }
122 | }
123 |
124 | public static int getChartMode() {
125 | return mSharedPreferences.getInt(CONFIG_CHART_MODE, CommonUtil.ChartModeDay);
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/DataActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import java.text.DecimalFormat;
14 |
15 | import com.jhuster.eweightscale.core.WeightDB;
16 | import com.jhuster.eweightscale.core.WeightDB.OnDBDataChangeListener;
17 | import com.jhuster.eweightscale.core.WeightDBHelper;
18 |
19 | import android.app.Activity;
20 | import android.os.Bundle;
21 | import android.view.ContextMenu;
22 | import android.view.KeyEvent;
23 | import android.view.MenuInflater;
24 | import android.view.MenuItem;
25 | import android.view.View;
26 | import android.view.ContextMenu.ContextMenuInfo;
27 | import android.widget.AdapterView;
28 | import android.widget.LinearLayout;
29 | import android.widget.ListView;
30 | import android.widget.AdapterView.OnItemLongClickListener;
31 | import android.widget.TextView;
32 |
33 | public class DataActivity extends Activity implements OnDBDataChangeListener {
34 |
35 | private LinearLayout mDataSummary;
36 | private TextView mTextContinuousDays;
37 | private TextView mTextReduceWeek;
38 | private TextView mTextReduceMonth;
39 | private ListView mWeightListView;
40 | private int mSelectedPosition = -1;
41 | private WeightDataAdapter mWeightDataAdapter;
42 | private String mCondition = null;
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_data);
48 |
49 | mDataSummary = (LinearLayout)findViewById(R.id.DataSummary);
50 |
51 | mCondition = getIntent().getStringExtra("Condition");
52 | if (mCondition != null && !"".equals(mCondition)) {
53 | getActionBar().setDisplayHomeAsUpEnabled(true);
54 | getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
55 | getActionBar().setTitle(getString(R.string.activity_title_search_result));
56 | mDataSummary.setVisibility(View.GONE);
57 | }
58 |
59 | mTextContinuousDays = (TextView)findViewById(R.id.TextContinuousDays);
60 | mTextReduceWeek = (TextView)findViewById(R.id.TextReduceWeek);
61 | mTextReduceMonth = (TextView)findViewById(R.id.TextReduceMonth);
62 | updateDataSummary();
63 |
64 | mWeightListView = (ListView)findViewById(R.id.WeightDataListView);
65 | mWeightDataAdapter = new WeightDataAdapter(this,mCondition);
66 | mWeightListView.setAdapter(mWeightDataAdapter);
67 | registerForContextMenu(mWeightListView);
68 |
69 | OnItemLongClickListener longListener = new OnItemLongClickListener() {
70 | public boolean onItemLongClick(AdapterView> parent, View view,int position, long id) {
71 | mSelectedPosition = position;
72 | mWeightListView.showContextMenu();
73 | return true;
74 |
75 | }
76 | };
77 | mWeightListView.setOnItemLongClickListener(longListener);
78 | }
79 |
80 | @Override
81 | public void onResume() {
82 | super.onResume();
83 | WeightDB.getInstance().setOnDBDataChangeListener(this);
84 | }
85 |
86 | @Override
87 | public void onPause() {
88 | super.onPause();
89 | WeightDB.getInstance().setOnDBDataChangeListener(null);
90 | }
91 |
92 | @Override
93 | public void onDBDataChanged() {
94 | mWeightDataAdapter.notifyDataSetChanged();
95 | updateDataSummary();
96 | }
97 |
98 | protected void updateDataSummary() {
99 | mTextContinuousDays.setText(WeightDBHelper.getContinuousDays()+"天");
100 | Double reduced = 0.0;
101 | reduced = WeightDBHelper.getWeightReduceThisWeek();
102 | if (reduced > 0) {
103 | mTextReduceWeek.setText("+" + new DecimalFormat("0.00").format(reduced) + " kg");
104 | }
105 | else {
106 | mTextReduceWeek.setText(reduced + " kg");
107 | }
108 | reduced = WeightDBHelper.getWeightReduceThisMonth();
109 | if (reduced > 0) {
110 | mTextReduceMonth.setText("+" + new DecimalFormat("0.00").format(reduced) + " kg");
111 | }
112 | else {
113 | mTextReduceMonth.setText(reduced + " kg");
114 | }
115 | }
116 |
117 | @Override
118 | public boolean onOptionsItemSelected(MenuItem item) {
119 | switch (item.getItemId()) {
120 | case android.R.id.home:
121 | finish();
122 | default:
123 | break;
124 | }
125 | return true;
126 | }
127 |
128 | @Override
129 | public void onCreateContextMenu(ContextMenu menu,View v,ContextMenuInfo menuInfo) {
130 | super.onCreateContextMenu(menu, v, menuInfo);
131 | MenuInflater inflater = getMenuInflater();
132 | inflater.inflate(R.menu.data_menu, menu);
133 | }
134 |
135 | @Override
136 | public boolean onContextItemSelected(MenuItem item) {
137 | switch(item.getItemId()) {
138 | case R.id.DataDelete:
139 | if (mSelectedPosition != -1) {
140 | WeightDB.getInstance().delete(mSelectedPosition,mCondition);
141 | }
142 | return true;
143 | case R.id.DataClear:
144 | WeightDB.getInstance().clear(mCondition);
145 | return true;
146 | default:
147 | return super.onContextItemSelected(item);
148 | }
149 | }
150 |
151 | @Override
152 | public boolean onKeyDown(int keyCode, KeyEvent event) {
153 | if (keyCode == KeyEvent.KEYCODE_BACK) {
154 | if (mCondition == null || "".equals(mCondition)) {
155 | if (!CommonUtil.onExitProcess(this)) {
156 | return true;
157 | }
158 | }
159 | }
160 | return super.onKeyDown(keyCode, event);
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import java.util.Calendar;
14 |
15 | import com.jhuster.eweightscale.core.WeightDB;
16 | import com.jhuster.eweightscale.core.WeightDB.Weight;
17 | import com.jhuster.eweightscale.core.WeightDBHelper;
18 | import com.jhuster.eweightscale.widget.InputDialog;
19 | import com.jhuster.eweightscale.widget.SearchDialog;
20 |
21 | import android.os.Bundle;
22 | import android.view.Menu;
23 | import android.view.MenuItem;
24 | import android.widget.RadioGroup;
25 | import android.widget.TabHost;
26 | import android.widget.RadioGroup.OnCheckedChangeListener;
27 | import android.app.TabActivity;
28 | import android.content.DialogInterface;
29 | import android.content.DialogInterface.OnClickListener;
30 | import android.content.Intent;
31 |
32 | @SuppressWarnings("deprecation")
33 | public class MainActivity extends TabActivity implements OnCheckedChangeListener {
34 |
35 | private static final String TAB_TAG_CHART = "iChart";
36 | private static final String TAB_TAG_DATAS = "iDatas";
37 | private static final String TAB_TAG_SQUARE = "iSquare";
38 | private static final String TAB_TAG_MORE = "iMore";
39 |
40 | private TabHost mTabHost;
41 | private SearchDialog mSearchWeightDailog;
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | getActionBar().setDisplayHomeAsUpEnabled(false);
47 | getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
48 | setContentView(R.layout.activity_main);
49 |
50 | Configuration.initialize(this);
51 | WeightDB.getInstance().open(getApplicationContext());
52 |
53 | RadioGroup mMainTab=(RadioGroup)findViewById(R.id.main_tab);
54 | mMainTab.setOnCheckedChangeListener(this);
55 |
56 | mTabHost = getTabHost();
57 |
58 | Intent iChart = new Intent(this, ChartActivity.class);
59 | mTabHost.addTab(mTabHost.newTabSpec(TAB_TAG_CHART)
60 | .setIndicator(getResources().getString(R.string.menu_chart), getResources().getDrawable(R.drawable.menu_chart_selector))
61 | .setContent(iChart));
62 |
63 | Intent iDatas = new Intent(this, DataActivity.class);
64 | mTabHost.addTab(mTabHost.newTabSpec(TAB_TAG_DATAS)
65 | .setIndicator(getResources().getString(R.string.menu_data), getResources().getDrawable(R.drawable.menu_data_selector))
66 | .setContent(iDatas));
67 |
68 | Intent iSquare = new Intent(this,SquareActivity.class);
69 | mTabHost.addTab(mTabHost.newTabSpec(TAB_TAG_SQUARE)
70 | .setIndicator(getResources().getString(R.string.menu_more), getResources().getDrawable(R.drawable.menu_more_selector))
71 | .setContent(iSquare));
72 |
73 | Intent iMore = new Intent(this,MoreActivity.class);
74 | mTabHost.addTab(mTabHost.newTabSpec(TAB_TAG_MORE)
75 | .setIndicator(getResources().getString(R.string.menu_more), getResources().getDrawable(R.drawable.menu_more_selector))
76 | .setContent(iMore));
77 |
78 | if (Configuration.isFirstStart()) {
79 | addTestData();
80 | }
81 | }
82 |
83 | @Override
84 | protected void onDestroy() {
85 | WeightDB.getInstance().close();
86 | super.onDestroy();
87 | }
88 |
89 | @Override
90 | protected void onPause() {
91 | super.onPause();
92 | }
93 |
94 | @Override
95 | protected void onResume() {
96 | super.onResume();
97 | }
98 |
99 | @Override
100 | public boolean onCreateOptionsMenu(Menu menu) {
101 | return super.onCreateOptionsMenu(menu);
102 | }
103 |
104 | @Override
105 | public boolean onPrepareOptionsMenu(Menu menu) {
106 | menu.clear();
107 | if (mTabHost.getCurrentTabTag().equals(TAB_TAG_DATAS)) {
108 | getMenuInflater().inflate(R.menu.menu_actions, menu);
109 | }
110 | return super.onPrepareOptionsMenu(menu);
111 | }
112 |
113 | @Override
114 | public boolean onOptionsItemSelected(MenuItem item) {
115 | switch (item.getItemId()) {
116 | case R.id.action_search:
117 | onClickSearch();
118 | break;
119 | case R.id.action_add:
120 | onClickAddData();
121 | break;
122 | default:
123 | break;
124 | }
125 | return super.onOptionsItemSelected(item);
126 | }
127 |
128 | @Override
129 | public void onCheckedChanged(RadioGroup group, int checkedId) {
130 | switch(checkedId){
131 | case R.id.MenuButtonChart:
132 | this.mTabHost.setCurrentTabByTag(TAB_TAG_CHART);
133 | break;
134 | case R.id.MenuButtonDatas:
135 | this.mTabHost.setCurrentTabByTag(TAB_TAG_DATAS);
136 | break;
137 | case R.id.MenuButtonSquare:
138 | this.mTabHost.setCurrentTabByTag(TAB_TAG_SQUARE);
139 | break;
140 | case R.id.MenuButtonMore:
141 | this.mTabHost.setCurrentTabByTag(TAB_TAG_MORE);
142 | break;
143 | default:
144 | break;
145 | }
146 | invalidateOptionsMenu();
147 | }
148 |
149 | protected void addTestData() {
150 | Calendar calendar = Calendar.getInstance();
151 | Double value = 55.0;
152 | for (int i=0; i<5; i++) {
153 | value = value + 2.0;
154 | calendar.add(Calendar.DAY_OF_MONTH, -1);
155 | Weight weight = new Weight();
156 | weight.value = String.valueOf(value);
157 | weight.date = calendar.getTimeInMillis();
158 | WeightDB.getInstance().insert(weight);
159 | }
160 | for (int i=5; i<10; i++) {
161 | value = value - 3.0;
162 | calendar.add(Calendar.DAY_OF_MONTH, -1);
163 | Weight weight = new Weight();
164 | weight.value = String.valueOf(value);
165 | weight.date = calendar.getTimeInMillis();
166 | WeightDB.getInstance().insert(weight);
167 | }
168 | Configuration.setContinousDays(10);
169 | Configuration.setFirstStart(false);
170 | }
171 |
172 | protected void onClickAddData() {
173 | final InputDialog dlg = new InputDialog(this);
174 | dlg.setOnClickListener(new OnClickListener() {
175 | @Override
176 | public void onClick(DialogInterface dialog, int which) {
177 | if (which == DialogInterface.BUTTON_POSITIVE) {
178 | Weight weight = new Weight();
179 | weight.value = String.format("%-4s",dlg.getInputValue());
180 | weight.date = Calendar.getInstance().getTimeInMillis();
181 | WeightDBHelper.addContinuousDays();
182 | WeightDB.getInstance().insert(weight);
183 | }
184 | }
185 | });
186 | dlg.show();
187 | }
188 |
189 | protected void onClickSearch() {
190 |
191 | if (mSearchWeightDailog != null) {
192 | mSearchWeightDailog.show();
193 | return;
194 | }
195 |
196 | mSearchWeightDailog = new SearchDialog(this);
197 | mSearchWeightDailog.setOnClickListener(new OnClickListener() {
198 | @Override
199 | public void onClick(DialogInterface dialog, int which) {
200 | if (which == DialogInterface.BUTTON_POSITIVE) {
201 | String condition = mSearchWeightDailog.getSearchCondition();
202 | Intent intent = new Intent(MainActivity.this,DataActivity.class);
203 | intent.putExtra("Condition",condition);
204 | startActivity(intent);
205 | }
206 | }
207 | });
208 | mSearchWeightDailog.show();
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/MoreActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import android.app.Activity;
14 | import android.content.Intent;
15 | import android.os.Bundle;
16 | import android.view.KeyEvent;
17 | import android.view.View;
18 | import android.view.View.OnClickListener;
19 | import android.widget.RelativeLayout;
20 | import android.widget.TextView;
21 |
22 | public class MoreActivity extends Activity implements OnClickListener {
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_more);
28 |
29 | addSettingItem(R.id.MoreAccount,getString(R.string.more_account));
30 |
31 | addSettingItem(R.id.MoreBackupOrRestore,getString(R.string.more_backup_restore));
32 | addSettingItem(R.id.MoreSetting,getString(R.string.more_setting));
33 |
34 | addSettingItem(R.id.MoreWhatBMI,getString(R.string.more_what_bmi));
35 | addSettingItem(R.id.MoreWhatBMR,getString(R.string.more_what_bmr));
36 |
37 | addSettingItem(R.id.MoreAboutUs,getString(R.string.more_about));
38 | }
39 |
40 | protected void addSettingItem(int layout_id, String title) {
41 | RelativeLayout layout = (RelativeLayout)findViewById(layout_id);
42 | ((TextView)layout.findViewById(R.id.SettingItemTitle)).setText(title);
43 | layout.setOnClickListener(this);
44 | }
45 |
46 | @Override
47 | public void onClick(View v) {
48 | Intent intent = null;
49 | switch (v.getId()) {
50 | case R.id.MoreAccount:
51 | intent = new Intent(this,PersonalActivity.class);
52 | startActivity(intent);
53 | break;
54 | case R.id.MoreBackupOrRestore:
55 | break;
56 | case R.id.MoreSetting:
57 | intent = new Intent(this,SettingActivity.class);
58 | startActivity(intent);
59 | break;
60 | case R.id.MoreWhatBMI:
61 | intent = new Intent(this,WhatActivity.class);
62 | intent.putExtra("What", "BMI");
63 | startActivity(intent);
64 | break;
65 | case R.id.MoreWhatBMR:
66 | intent = new Intent(this,WhatActivity.class);
67 | intent.putExtra("What", "BMR");
68 | startActivity(intent);
69 | break;
70 | case R.id.MoreAboutUs:
71 | intent = new Intent(this,AboutActivity.class);
72 | startActivity(intent);
73 | break;
74 | default:
75 | return;
76 | }
77 | }
78 |
79 | @Override
80 | public boolean onKeyDown(int keyCode, KeyEvent event) {
81 | if (keyCode == KeyEvent.KEYCODE_BACK) {
82 | if (!CommonUtil.onExitProcess(this)) {
83 | return true;
84 | }
85 | }
86 | return super.onKeyDown(keyCode, event);
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/PersonalActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import java.util.Calendar;
14 |
15 | import android.app.Activity;
16 | import android.os.Bundle;
17 | import android.view.MenuItem;
18 | import android.view.View;
19 | import android.widget.DatePicker;
20 | import android.widget.DatePicker.OnDateChangedListener;
21 | import android.widget.EditText;
22 | import android.widget.RadioGroup;
23 | import android.widget.TextView;
24 | import android.widget.Toast;
25 |
26 | public class PersonalActivity extends Activity implements OnDateChangedListener {
27 |
28 | public static final String TITLE = "个人信息";
29 | public static final String SAVE_MSG = "信息保存成功!";
30 |
31 | private RadioGroup mRadioGroup;
32 | private DatePicker mDatePicker;
33 | private TextView mBirthdayText;
34 | private EditText mHeightEditText;
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | getActionBar().setDisplayHomeAsUpEnabled(true);
40 | getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
41 | setContentView(R.layout.activity_personal);
42 | getActionBar().setTitle(TITLE);
43 |
44 | mRadioGroup = (RadioGroup) findViewById(R.id.PersonalSex);
45 | mDatePicker = (DatePicker) findViewById(R.id.PersonalAgePicker);
46 | mBirthdayText = (TextView) findViewById(R.id.BirthdayValue);
47 | mHeightEditText = (EditText)findViewById(R.id.WidgetHeightInputEdit);
48 |
49 | int year,month,day;
50 |
51 | year = Configuration.getUserBirthdayYear();
52 | month = Configuration.getUserBirthdayMonth();
53 | day = Configuration.getUserBirthdayDay();
54 |
55 | mDatePicker.init(year,month,day,this);
56 | mDatePicker.setMaxDate(Calendar.getInstance().getTimeInMillis());
57 |
58 | String birthday = year + "-" + month + "-" + day;
59 | mBirthdayText.setText(birthday);
60 |
61 | int sex = Configuration.getUserSex();
62 | if (sex == CommonUtil.UserSexFemale) {
63 | mRadioGroup.check(R.id.RadioFemale);
64 | }
65 |
66 | if (Configuration.getUserHeight() != 0.0) {
67 | String height = String.valueOf(Configuration.getUserHeight());
68 | mHeightEditText.setText(height);
69 | }
70 | }
71 |
72 | @Override
73 | public boolean onOptionsItemSelected(MenuItem item) {
74 | switch (item.getItemId()) {
75 | case android.R.id.home:
76 | finish();
77 | default:
78 | break;
79 | }
80 | return true;
81 | }
82 |
83 | public void onClickSaveInfo(View v) {
84 | if (R.id.RadioMale == mRadioGroup.getCheckedRadioButtonId()) {
85 | Configuration.setUserSex(CommonUtil.UserSexMale);
86 | }
87 | else {
88 | Configuration.setUserSex(CommonUtil.UserSexFemale);
89 | }
90 | Configuration.setUserBirthday(mDatePicker.getYear(), mDatePicker.getMonth(), mDatePicker.getDayOfMonth());
91 | Configuration.setUserHeight(mHeightEditText.getText().toString());
92 | Toast.makeText(this, SAVE_MSG, Toast.LENGTH_SHORT).show();
93 | }
94 |
95 | @Override
96 | public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
97 | monthOfYear = monthOfYear+1;
98 | String birthday = year + "-" + monthOfYear + "-" + dayOfMonth;
99 | mBirthdayText.setText(birthday);
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/SettingActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import com.jhuster.eweightscale.widget.ChartModeSelector;
14 | import com.jhuster.eweightscale.widget.ChartModeSelector.OnDateModeSelectListener;
15 | import android.app.Activity;
16 | import android.os.Bundle;
17 | import android.view.MenuItem;
18 | import android.widget.RadioGroup;
19 |
20 | public class SettingActivity extends Activity implements OnDateModeSelectListener {
21 |
22 | public static final String TITLE = "系统设置";
23 | public static final String XAXIS_TITLE = "X轴坐标:";
24 |
25 | private ChartModeSelector mDateModeSelector;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | getActionBar().setDisplayHomeAsUpEnabled(true);
31 | getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
32 | setContentView(R.layout.activity_setting);
33 | getActionBar().setTitle(TITLE);
34 |
35 | mDateModeSelector = new ChartModeSelector((RadioGroup)findViewById(R.id.SettingDateMode),XAXIS_TITLE);
36 | mDateModeSelector.setRadioChecked(Configuration.getChartMode());
37 | mDateModeSelector.setOnDateModeSelectListener(this);
38 | }
39 |
40 | @Override
41 | public boolean onOptionsItemSelected(MenuItem item) {
42 | switch (item.getItemId()) {
43 | case android.R.id.home:
44 | finish();
45 | default:
46 | break;
47 | }
48 | return true;
49 | }
50 |
51 | @Override
52 | public void onRadioYearSelected() {
53 | Configuration.setChartMode(CommonUtil.ChartModeYear);
54 | }
55 |
56 | @Override
57 | public void onRadioMonthSelected() {
58 | Configuration.setChartMode(CommonUtil.ChartModeMonth);
59 | }
60 |
61 | @Override
62 | public void onRadioDaySelected() {
63 | Configuration.setChartMode(CommonUtil.ChartModeDay);
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/SquareActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import com.jhuster.eweightscale.core.WeightDB;
14 | import com.jhuster.eweightscale.core.WeightDB.Weight;
15 | import com.jhuster.eweightscale.widget.SquareItemWidget;
16 | import android.app.Activity;
17 | import android.os.Bundle;
18 | import android.view.KeyEvent;
19 | import android.view.View;
20 | import android.widget.TextView;
21 |
22 | public class SquareActivity extends Activity {
23 |
24 | public static final String BMI_THIN_WEIGHT = "偏瘦";
25 | public static final String BMI_NICE_WEIGHT = "完美";
26 | public static final String BMI_FAT_WEIGHT = "偏胖";
27 | public static final String BMI_BIG_WEIGHT = "肥胖";
28 |
29 | private SquareItemWidget mWeightItem;
30 | private SquareItemWidget mBMIItem;
31 | private SquareItemWidget mBMRItem;
32 | private SquareItemWidget mResultItem;
33 | private SquareItemWidget mDestWeight;
34 | private TextView mPersonalTips;
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_square);
40 |
41 | mPersonalTips = (TextView)findViewById(R.id.PersionalTips);
42 | mWeightItem = new SquareItemWidget(findViewById(R.id.SquareWeightItem),
43 | getString(R.string.square_weight));
44 | mBMIItem = new SquareItemWidget(findViewById(R.id.SquareBMIItem),
45 | getString(R.string.square_bmi));
46 | mBMRItem = new SquareItemWidget(findViewById(R.id.SquareBMRItem),
47 | getString(R.string.square_bmr));
48 | mResultItem = new SquareItemWidget(findViewById(R.id.SquareResult),
49 | getString(R.string.square_result));
50 | mDestWeight = new SquareItemWidget(findViewById(R.id.SquareDestWeight),
51 | getString(R.string.square_dest_weight));
52 | }
53 |
54 | public void onResume() {
55 | super.onResume();
56 | onSquareUpdate();
57 | }
58 |
59 | protected void onSquareUpdate() {
60 |
61 | //判断是否有体重数据
62 | Weight weight = WeightDB.getInstance().get(0);
63 | if (weight == null) {
64 | mPersonalTips.setText(getString(R.string.no_data));
65 | mPersonalTips.setVisibility(View.VISIBLE);
66 | mWeightItem.setItemValue("");
67 | mBMIItem.setItemValue("");
68 | mBMRItem.setItemValue("");
69 | mDestWeight.setItemValue("");
70 | mResultItem.setItemValue("");
71 | return;
72 | }
73 |
74 | //判断个人信息是否填写好了
75 | double height = Configuration.getUserHeight();
76 | int age = Configuration.getUserAge();
77 | if (height <= 0.0 || age <= 0) {
78 | mPersonalTips.setText(getString(R.string.personalTips));
79 | mPersonalTips.setVisibility(View.VISIBLE);
80 | }
81 | else {
82 | mPersonalTips.setVisibility(View.GONE);
83 | }
84 |
85 | //显示BMI指标分析结果
86 | WeightData weightdata = new WeightData(weight);
87 | mWeightItem.setItemValue(weightdata.getWeightStr());
88 | String bmi = weightdata.getBMIValue();
89 | if (!"".equals(bmi)) {
90 | mBMIItem.setItemValue(bmi);
91 | double BMI = Double.valueOf(bmi);
92 | if (BMI < 18.5) {
93 | mResultItem.setItemValue(BMI_THIN_WEIGHT);
94 | }
95 | else if (BMI >= 18.5 && BMI < 24) {
96 | mResultItem.setItemValue(BMI_NICE_WEIGHT);
97 | }
98 | else if (BMI >= 24 && BMI < 28) {
99 | mResultItem.setItemValue(BMI_FAT_WEIGHT);
100 | }
101 | else {
102 | mResultItem.setItemValue(BMI_BIG_WEIGHT);
103 | }
104 | }
105 |
106 | //显示目标体重
107 | if (height != 0) {
108 | double HEIGHT = Double.valueOf(height);
109 | String destWeight = CommonUtil.calculateMinWeight(HEIGHT) + "kg" +
110 | "~" + CommonUtil.calculateMaxWeight(HEIGHT) + "kg";
111 | mDestWeight.setItemValue(destWeight);
112 | }
113 |
114 | //显示BMR
115 | int bmr_age = Configuration.getUserAge();
116 | double bmr_height = Configuration.getUserHeight();
117 | int bmr_sex = Configuration.getUserSex();
118 | if (bmr_age!=0 && !"".equals(weight) && bmr_height!= 0) {
119 | double bmr_weight = Double.valueOf(weightdata.getWeightValue());
120 | String bmrStr = CommonUtil.calculateBMR(bmr_sex, bmr_weight, bmr_height, bmr_age) + "千卡";
121 | mBMRItem.setItemValue(bmrStr);
122 | }
123 | }
124 |
125 | @Override
126 | public boolean onKeyDown(int keyCode, KeyEvent event) {
127 | if (keyCode == KeyEvent.KEYCODE_BACK) {
128 | if (!CommonUtil.onExitProcess(this)) {
129 | return true;
130 | }
131 | }
132 | return super.onKeyDown(keyCode, event);
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/WeightData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import java.text.DecimalFormat;
14 |
15 | import com.jhuster.eweightscale.core.DateHelper;
16 | import com.jhuster.eweightscale.core.WeightDB.Weight;
17 |
18 | public class WeightData {
19 |
20 | private static final String WEIGHT_SUFFIX = "kg";
21 | private static final String BMI_PREFIX = "BMI: ";
22 |
23 | public String mWeightValue;
24 | public long mRecordDate;
25 |
26 | public WeightData(Weight weight) {
27 | mWeightValue = weight.value;
28 | mRecordDate = weight.date;
29 | }
30 |
31 | public String getWeightValue() {
32 | return mWeightValue;
33 | }
34 |
35 | public String getWeightStr() {
36 | String result = String.format("%-4s", mWeightValue);
37 | return (result + " " + WEIGHT_SUFFIX);
38 | }
39 |
40 | public String getBMIStr() {
41 | return (BMI_PREFIX + getBMIValue());
42 | }
43 |
44 | public String getWeekStr() {
45 | return DateHelper.getWeekStr(mRecordDate);
46 | }
47 |
48 | public String getDateStr() {
49 | return DateHelper.getDateStr(mRecordDate);
50 | }
51 |
52 | public String getBMIValue() {
53 | double height = Configuration.getUserHeight();
54 | if (height == 0.0) {
55 | return "0.00";
56 | }
57 | double bmi = CommonUtil.calculateBMI(Double.valueOf(mWeightValue), height);
58 | return new DecimalFormat("0.00").format(bmi).toString();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/WeightDataAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import com.jhuster.eweightscale.R;
14 | import com.jhuster.eweightscale.core.WeightDB;
15 | import com.jhuster.eweightscale.core.WeightDB.Weight;
16 |
17 | import android.content.Context;
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import android.widget.BaseAdapter;
22 | import android.widget.LinearLayout;
23 | import android.widget.TextView;
24 |
25 | public class WeightDataAdapter extends BaseAdapter {
26 |
27 | private Context mContext;
28 | private String mCondition = null;
29 |
30 | protected class ViewHolder {
31 | TextView mWeightWeek;
32 | TextView mWeightData;
33 | TextView mWeightBMI;
34 | TextView mWeightValue;
35 | }
36 |
37 | public WeightDataAdapter(Context context,String condition) {
38 | mContext = context;
39 | mCondition = condition;
40 | }
41 |
42 | @Override
43 | public int getCount() {
44 | return WeightDB.getInstance().size(mCondition);
45 | }
46 |
47 | @Override
48 | public Object getItem(int position) {
49 | return WeightDB.getInstance().get(position,mCondition);
50 | }
51 |
52 | @Override
53 | public long getItemId(int position) {
54 | return ((Weight)getItem(position)).key;
55 | }
56 |
57 | @Override
58 | public View getView(int position, View convertView, ViewGroup parent) {
59 |
60 | if (convertView == null) {
61 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
62 | convertView = (LinearLayout)inflater.inflate(R.layout.widget_weight_item, null);
63 | ViewHolder holder = new ViewHolder();
64 | holder.mWeightWeek = (TextView)convertView.findViewById(R.id.WeightWeek);
65 | holder.mWeightData = (TextView)convertView.findViewById(R.id.WeightData);
66 | holder.mWeightBMI = (TextView)convertView.findViewById(R.id.WeightBMI);
67 | holder.mWeightValue = (TextView)convertView.findViewById(R.id.WeightValue);
68 | convertView.setTag(holder);
69 | }
70 |
71 | Weight weight = (Weight)getItem(position);
72 | if (weight != null) {
73 | WeightData data = new WeightData(weight);
74 | ViewHolder holder = (ViewHolder)convertView.getTag();
75 | holder.mWeightWeek.setText(data.getWeekStr());
76 | holder.mWeightData.setText(data.getDateStr());
77 | holder.mWeightBMI.setText(data.getBMIStr());
78 | holder.mWeightValue.setText(data.getWeightStr());
79 | }
80 |
81 | return convertView;
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/WhatActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale;
12 |
13 | import android.app.Activity;
14 | import android.os.Bundle;
15 | import android.view.MenuItem;
16 | import android.webkit.WebView;
17 |
18 | public class WhatActivity extends Activity {
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 |
24 | getActionBar().setDisplayHomeAsUpEnabled(true);
25 | getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
26 | setContentView(R.layout.activity_what);
27 |
28 | String what = getIntent().getExtras().getString("What");
29 | if (what == null) {
30 | return;
31 | }
32 |
33 | WebView what_content = (WebView) findViewById(R.id.WhatWebView);
34 | what_content.getSettings().setDefaultTextEncodingName("gbk");
35 | if ("BMI".equals(what)) {
36 | getActionBar().setTitle(getString(R.string.more_what_bmi));
37 | what_content.loadUrl("file:///android_asset/" + "bmi.html");
38 | }
39 | else if ("BMR".equals(what)) {
40 | getActionBar().setTitle(getString(R.string.more_what_bmr));
41 | what_content.loadUrl("file:///android_asset/" + "bmr.html");
42 | }
43 | else {}
44 | }
45 |
46 | @Override
47 | public boolean onOptionsItemSelected(MenuItem item) {
48 | switch (item.getItemId()) {
49 | case android.R.id.home:
50 | finish();
51 | default:
52 | break;
53 | }
54 | return true;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/chart/ChartAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.chart;
12 |
13 | public abstract class ChartAdapter {
14 | public abstract boolean isEmpty();
15 | public abstract int getMinXScale(); //最小x刻度
16 | public abstract int getMaxXScale(); //最大x刻度
17 | public abstract String getXScaleUnit(); //x刻度的单位
18 | public abstract double getYScale(int x); //获取指定x刻度的y值
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/chart/ChartFolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.chart;
12 |
13 | import org.achartengine.ChartFactory;
14 | import org.achartengine.GraphicalView;
15 | import org.achartengine.model.XYMultipleSeriesDataset;
16 | import org.achartengine.renderer.XYMultipleSeriesRenderer;
17 | import android.graphics.Color;
18 | import android.graphics.Paint.Align;
19 | import android.view.ViewGroup;
20 |
21 | /**
22 | * 图表容器,可以添加多张表(@see ChartTable)
23 | */
24 | public class ChartFolder {
25 |
26 | public static final String TAG = ChartFolder.class.getSimpleName();
27 |
28 | public static final String TABLE_TIPS = "体重曲线----X轴:日期,Y轴:体重(kg)";
29 |
30 | private GraphicalView mChartView;
31 | private ChartTable mChartTable;
32 | private ChartAdapter mChartAdapter;
33 | private ViewGroup mParentView;
34 |
35 | public ChartFolder(ViewGroup parent) {
36 | mParentView = parent;
37 | }
38 |
39 | public void setChartAdapter(ChartAdapter adapter) {
40 | mChartAdapter = adapter;
41 | draw(adapter.getMinXScale(),adapter.getMaxXScale(),adapter.getXScaleUnit());
42 | }
43 |
44 | public void invalidate() {
45 | if (mChartAdapter==null) {
46 | return;
47 | }
48 | mChartTable.clear();
49 | for (int i=mChartAdapter.getMinXScale(); i 10) {
97 | render.setXAxisMax(min+10);
98 | }
99 | else {
100 | render.setXAxisMax(min+4);
101 | }
102 |
103 | //如果要自定义X轴坐标Label,则必须设置为0
104 | render.setXLabels(0);
105 | for (int i=min; i<=max; i++) {
106 | render.addXTextLabel(i, i+unit);
107 | }
108 |
109 | render.setPanEnabled(true);
110 | render.setZoomEnabled(true);
111 | render.setPanLimits(new double[]{min-1,max+1,-1,100});
112 | render.setZoomLimits(new double[]{min-1,max+1,-1,100});
113 |
114 | mChartTable = new ChartTable(TABLE_TIPS);
115 | datasheet.addSeries(mChartTable.getSeries());
116 | render.addSeriesRenderer(mChartTable.getRender());
117 |
118 | if (mChartView!=null) {
119 | mParentView.removeView(mChartView);
120 | }
121 |
122 | mChartView = ChartFactory.getLineChartView(mParentView.getContext(), datasheet, render);
123 |
124 | mParentView.addView(mChartView, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
125 | mParentView.invalidate();
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/chart/ChartTable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.chart;
12 |
13 | import org.achartengine.chart.PointStyle;
14 | import org.achartengine.model.XYSeries;
15 | import org.achartengine.renderer.XYSeriesRenderer;
16 |
17 | /**
18 | * 图表类,根据添加的元数据绘制曲线图
19 | */
20 | public class ChartTable {
21 |
22 | private XYSeries mSeries;
23 | private XYSeriesRenderer mRender;
24 |
25 | public ChartTable(String title) {
26 | mSeries = new XYSeries(title);
27 | mRender = new XYSeriesRenderer();
28 | mRender.setPointStyle(PointStyle.CIRCLE);
29 | mRender.setFillPoints(true);
30 | mRender.setDisplayChartValues(true);
31 | mRender.setDisplayChartValuesDistance(5);
32 | mRender.setChartValuesTextSize(15);
33 | }
34 |
35 | public void add(double x, double y) {
36 | if (!ignore(x,y)) {
37 | mSeries.add(x, y);
38 | }
39 | }
40 |
41 | public void remove(int index) {
42 | mSeries.remove(index);
43 | }
44 |
45 | public void clear() {
46 | mSeries.clear();
47 | }
48 |
49 | public boolean ignore(double x, double y) {
50 | if (x==0.0 || y==0.0) {
51 | return true;
52 | }
53 | return false;
54 | }
55 |
56 | public XYSeries getSeries() {
57 | return mSeries;
58 | }
59 |
60 | public XYSeriesRenderer getRender() {
61 | return mRender;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/chart/DayChartAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.chart;
12 |
13 | import com.jhuster.eweightscale.CommonUtil;
14 | import com.jhuster.eweightscale.core.WeightDBHelper;
15 |
16 | public class DayChartAdapter extends ChartAdapter {
17 |
18 | private int mChartYear;
19 | private int mChartMonth;
20 |
21 | public DayChartAdapter(int year,int month) {
22 | mChartYear = year;
23 | mChartMonth = month;
24 | }
25 |
26 | @Override
27 | public boolean isEmpty() {
28 | return WeightDBHelper.isEmpty(mChartYear, mChartMonth);
29 | }
30 |
31 | @Override
32 | public double getYScale(int day) {
33 | return WeightDBHelper.getWeightAverage(mChartYear,mChartMonth,day);
34 | }
35 |
36 | @Override
37 | public int getMinXScale() {
38 | return CommonUtil.MinDay;
39 | }
40 |
41 | @Override
42 | public int getMaxXScale() {
43 | return CommonUtil.MaxDay;
44 | }
45 |
46 | @Override
47 | public String getXScaleUnit() {
48 | return CommonUtil.DayUnit;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/chart/MonthChartAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.chart;
12 |
13 | import com.jhuster.eweightscale.CommonUtil;
14 | import com.jhuster.eweightscale.core.WeightDBHelper;
15 |
16 | public class MonthChartAdapter extends ChartAdapter {
17 |
18 | private int mChartYear;
19 |
20 | public MonthChartAdapter(int year) {
21 | mChartYear = year;
22 | }
23 |
24 | @Override
25 | public boolean isEmpty() {
26 | return WeightDBHelper.isEmpty(mChartYear);
27 | }
28 |
29 | @Override
30 | public double getYScale(int month) {
31 | return WeightDBHelper.getWeightAverage(mChartYear, month-1);
32 | }
33 |
34 | @Override
35 | public int getMinXScale() {
36 | return CommonUtil.MinMonth;
37 | }
38 |
39 | @Override
40 | public int getMaxXScale() {
41 | return CommonUtil.MaxMonth;
42 | }
43 |
44 | @Override
45 | public String getXScaleUnit() {
46 | return CommonUtil.MonthUnit;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/chart/YearChartAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.chart;
12 |
13 | import com.jhuster.eweightscale.CommonUtil;
14 | import com.jhuster.eweightscale.core.WeightDBHelper;
15 |
16 | public class YearChartAdapter extends ChartAdapter {
17 |
18 | @Override
19 | public boolean isEmpty() {
20 | return WeightDBHelper.isEmpty();
21 | }
22 |
23 | @Override
24 | public double getYScale(int year) {
25 | return WeightDBHelper.getWeightAverage(year);
26 | }
27 |
28 | @Override
29 | public int getMinXScale() {
30 | return CommonUtil.MinYear;
31 | }
32 |
33 | @Override
34 | public int getMaxXScale() {
35 | return CommonUtil.MaxYear;
36 | }
37 |
38 | @Override
39 | public String getXScaleUnit() {
40 | return CommonUtil.YearUnit;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/core/DateHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.core;
12 |
13 | import java.text.SimpleDateFormat;
14 | import java.util.Calendar;
15 | import java.util.GregorianCalendar;
16 | import java.util.Locale;
17 |
18 | public class DateHelper {
19 |
20 | protected static final String DISPLAY_WEEK_FORMAT = "EEEE";
21 | protected static final String DISPLAY_DATE_FORMAT = "yyyy年MM月dd日";
22 | protected static final String DISPLAY_FULL_FORMAT = "yyyy年MM月dd日 EEEE HH点mm分";
23 |
24 | public static class DatePeriod {
25 | public long begin;
26 | public long end;
27 | public DatePeriod(long begin,long end) {
28 | this.begin = begin;
29 | this.end = end;
30 | }
31 | }
32 |
33 | public static Calendar getToday() {
34 | return Calendar.getInstance();
35 | }
36 |
37 | public static Calendar getYestday() {
38 | Calendar calendar = Calendar.getInstance();
39 | calendar.add(GregorianCalendar.DAY_OF_MONTH,-1);
40 | return calendar;
41 | }
42 |
43 | public static Calendar getDayOfLastWeek() {
44 | Calendar calendar = Calendar.getInstance();
45 | calendar.add(Calendar.WEEK_OF_YEAR,-1);
46 | return calendar;
47 | }
48 |
49 | public static Calendar getDayOfLastMonth() {
50 | Calendar calendar = Calendar.getInstance();
51 | calendar.add(Calendar.MONTH,-1);
52 | return calendar;
53 | }
54 |
55 | public static Calendar getCalendar(int year,int month,int day) {
56 | Calendar calendar = Calendar.getInstance();
57 | calendar.set(year, month, day);
58 | return calendar;
59 | }
60 |
61 | public static DatePeriod getYearPeriod(int year) {
62 | Calendar calendar = new GregorianCalendar(year,0,0);
63 | long begin = calendar.getTimeInMillis();
64 | calendar.add(GregorianCalendar.YEAR,1);
65 | long end = calendar.getTimeInMillis();
66 | return new DatePeriod(begin,end);
67 | }
68 |
69 | public static DatePeriod getMonthPeriod(int year,int month) {
70 | Calendar calendar = new GregorianCalendar(year,month,1);
71 | long begin = calendar.getTimeInMillis();
72 | calendar.add(GregorianCalendar.MONTH,1);
73 | long end = calendar.getTimeInMillis();
74 | return new DatePeriod(begin,end);
75 | }
76 |
77 | public static DatePeriod getDatePeriod(int year,int month,int day) {
78 | Calendar calendar = new GregorianCalendar(year,month,day);
79 | long begin = calendar.getTimeInMillis();
80 | calendar.add(GregorianCalendar.DAY_OF_MONTH,1);
81 | long end = calendar.getTimeInMillis();
82 | return new DatePeriod(begin,end);
83 | }
84 |
85 | public static DatePeriod getDatePeriod(Calendar calendar) {
86 | return getDatePeriod(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),
87 | calendar.get(Calendar.DAY_OF_MONTH));
88 | }
89 |
90 | public static DatePeriod getWeekPeriod(Calendar calendar) {
91 | calendar.setFirstDayOfWeek(Calendar.MONDAY);
92 | calendar.set(Calendar.DAY_OF_WEEK,calendar.getFirstDayOfWeek());
93 | calendar.set(Calendar.HOUR,0);
94 | calendar.set(Calendar.MINUTE,0);
95 | calendar.set(Calendar.SECOND,0);
96 | long begin = calendar.getTimeInMillis();
97 | calendar.add(Calendar.WEEK_OF_YEAR,1);
98 | long end = calendar.getTimeInMillis();
99 | return new DatePeriod(begin,end);
100 | }
101 |
102 | public static DatePeriod getMonthPeriod(Calendar calendar) {
103 | calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),1);
104 | calendar.set(Calendar.HOUR,0);
105 | calendar.set(Calendar.MINUTE,0);
106 | calendar.set(Calendar.SECOND,0);
107 | long begin = calendar.getTimeInMillis();
108 | calendar.add(GregorianCalendar.MONTH,1);
109 | long end = calendar.getTimeInMillis();
110 | return new DatePeriod(begin,end);
111 | }
112 |
113 | public static String getWeekStr(long milliseconds) {
114 | return new SimpleDateFormat(DISPLAY_WEEK_FORMAT,Locale.CHINA).format(milliseconds);
115 | }
116 |
117 | public static String getDateStr(long milliseconds) {
118 | return new SimpleDateFormat(DISPLAY_DATE_FORMAT,Locale.CHINA).format(milliseconds);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/core/WeightDB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.core;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import android.content.ContentValues;
17 | import android.content.Context;
18 | import android.database.Cursor;
19 | import android.database.SQLException;
20 | import android.database.sqlite.SQLiteDatabase;
21 | import android.database.sqlite.SQLiteOpenHelper;
22 | import android.util.Log;
23 |
24 | public class WeightDB {
25 |
26 | protected static final String TAG = WeightDB.class.getSimpleName();
27 |
28 | protected static final int DB_VERSION = 1;
29 | protected static final String DB_NAME = "weight_db";
30 | protected static final String DB_PRIMARY_KEY = "_id";
31 | protected static final String DB_TABLE_NAME = "weight";
32 |
33 | protected static final String DB_TABLE_COLUMN_WEIGHT = "weight";
34 | protected static final String DB_TABLE_COLUMN_DATE = "record_date";
35 |
36 | protected static final String DB_DEFAULT_ORDERBY = DB_TABLE_COLUMN_DATE + " DESC";
37 |
38 | protected DatabaseHelper mDBHelper;
39 | protected SQLiteDatabase mDB;
40 | protected OnDBDataChangeListener mDBDataChangeListener;
41 |
42 | protected static final WeightDB mInstance = new WeightDB();
43 |
44 | private final String DB_TABLE_CREATE_SQL = "create table " + DB_TABLE_NAME + " (_id integer primary key autoincrement, "
45 | + DB_TABLE_COLUMN_WEIGHT + " text not null, "
46 | + DB_TABLE_COLUMN_DATE + " integer);";
47 |
48 | public interface OnDBDataChangeListener {
49 | public void onDBDataChanged();
50 | }
51 |
52 | public static class Weight {
53 | public long key = -1;
54 | public String value;
55 | public long date;
56 | }
57 |
58 | protected class DatabaseHelper extends SQLiteOpenHelper {
59 | public DatabaseHelper(Context context,String dbName, int dbVersion) {
60 | super(context, dbName , null, dbVersion);
61 | }
62 | @Override
63 | public void onCreate(SQLiteDatabase db) {
64 | db.execSQL(DB_TABLE_CREATE_SQL);
65 | }
66 | @Override
67 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
68 | db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE_NAME);
69 | onCreate(db);
70 | }
71 | }
72 |
73 | private WeightDB() {};
74 |
75 | public static WeightDB getInstance() {
76 | return mInstance;
77 | }
78 |
79 | public void setOnDBDataChangeListener(OnDBDataChangeListener listener) {
80 | mDBDataChangeListener = listener;
81 | if (listener!=null) {
82 | listener.onDBDataChanged();
83 | }
84 | }
85 |
86 | public boolean open(Context context) {
87 | try {
88 | mDBHelper = new DatabaseHelper(context,DB_NAME,DB_VERSION);
89 | mDB = mDBHelper.getWritableDatabase();
90 | }
91 | catch(SQLException e) {
92 | e.printStackTrace();
93 | return false;
94 | }
95 | return true;
96 | }
97 |
98 | public void close() {
99 | mDB.close();
100 | mDBHelper.close();
101 | }
102 |
103 | public String makeCondition(int position) {
104 | long key = getkey(position,null);
105 | if (key == -1) {
106 | return null;
107 | }
108 | String condition = DB_PRIMARY_KEY + "=" + "\'" + key + "\'";
109 | return condition;
110 | }
111 |
112 | public String makeCondition(int position,String condition) {
113 | long key = getkey(position,condition);
114 | if (key == -1) {
115 | return null;
116 | }
117 | String conditions = DB_PRIMARY_KEY + "=" + "\'" + key + "\'";
118 | return conditions;
119 | }
120 |
121 | public String makeCondition(long startdate,long enddate) {
122 | String condition = DB_TABLE_COLUMN_DATE + " >= " + startdate + " AND ";
123 | condition += (DB_TABLE_COLUMN_DATE + " < " + enddate);
124 | return condition;
125 | }
126 |
127 | public String makeCondition(String condition1,String condition2) {
128 | String condition = condition1 + " AND " + condition2;
129 | return condition;
130 | }
131 |
132 | public int size() {
133 | return size(null);
134 | }
135 |
136 | public int size(String condition) {
137 | Cursor mCursor = mDB.query(DB_TABLE_NAME,new String[]{DB_PRIMARY_KEY},condition,null,null,null,
138 | null, null);
139 | int size = mCursor.getCount();
140 | mCursor.close();
141 | return size;
142 | }
143 |
144 | public boolean insert(Weight weight) {
145 | ContentValues values = new ContentValues();
146 | values.put(DB_TABLE_COLUMN_WEIGHT, weight.value);
147 | values.put(DB_TABLE_COLUMN_DATE, weight.date);
148 | weight.key = mDB.insert(DB_TABLE_NAME,null,values);
149 | if (weight.key == -1) {
150 | Log.e(TAG,"db insert fail!");
151 | return false;
152 | }
153 | if (mDBDataChangeListener!=null) {
154 | mDBDataChangeListener.onDBDataChanged();
155 | }
156 | return true;
157 | }
158 |
159 | public boolean update(Weight weight) {
160 | if (weight.key == -1) {
161 | return false;
162 | }
163 | ContentValues values = new ContentValues();
164 | values.put(DB_TABLE_COLUMN_WEIGHT, weight.value);
165 | values.put(DB_TABLE_COLUMN_DATE, weight.date);
166 | String condition = DB_PRIMARY_KEY + "=" + "\'" + weight.key + "\'";
167 | if (!update(values,condition,null)) {
168 | return false;
169 | }
170 | if (mDBDataChangeListener!=null) {
171 | mDBDataChangeListener.onDBDataChanged();
172 | }
173 | return true;
174 | }
175 |
176 | protected boolean update(ContentValues values, String whereClause, String[] whereArgs) {
177 | int rows = mDB.update(DB_TABLE_NAME,values, whereClause, whereArgs);
178 | if (rows <= 0) {
179 | Log.d(TAG,"db update fail!");
180 | return false;
181 | }
182 | return true;
183 | }
184 |
185 | public boolean delete(int position) {
186 | return delete(makeCondition(position));
187 | }
188 |
189 | public boolean delete(int position,String condition) {
190 | return delete(makeCondition(position,condition));
191 | }
192 |
193 | public boolean delete(String condition) {
194 | return delete(condition,null);
195 | }
196 |
197 | protected boolean delete(String whereClause, String[] whereArgs) {
198 | int rows = mDB.delete(DB_TABLE_NAME,whereClause,whereArgs);
199 | if (rows <= 0) {
200 | Log.e(TAG,"db delete fail!");
201 | return false;
202 | }
203 | if (mDBDataChangeListener!=null) {
204 | mDBDataChangeListener.onDBDataChanged();
205 | }
206 | return true;
207 | }
208 |
209 | public boolean clear() {
210 | return delete(null,null);
211 | }
212 |
213 | public boolean clear(String condition) {
214 | return delete(condition,null);
215 | }
216 |
217 | public Weight get(int position) {
218 | return get(position,null);
219 | }
220 |
221 | public Weight get(int position,String condition) {
222 | Cursor cursor = mDB.query(DB_TABLE_NAME,null,condition,null,null,null,
223 | DB_DEFAULT_ORDERBY,null);
224 | List weights = extract(position,cursor);
225 | if (weights.isEmpty()) {
226 | return null;
227 | }
228 | return weights.get(0);
229 | }
230 |
231 | public List query() {
232 | Cursor cursor = mDB.query(DB_TABLE_NAME,null,null,null,null,null,
233 | DB_DEFAULT_ORDERBY,null);
234 | return extract(0,cursor);
235 | }
236 |
237 | public List query(String condition) {
238 | Cursor cursor = mDB.query(DB_TABLE_NAME,null,condition,null,null,null,
239 | DB_DEFAULT_ORDERBY,null);
240 | return extract(0,cursor);
241 | }
242 |
243 | public List query(int offset,int limit) {
244 | return query(null,offset,limit);
245 | }
246 |
247 | public List query(String condition,int offset,int limit) {
248 | Cursor cursor = mDB.query(DB_TABLE_NAME,null,condition,null,null,null,
249 | DB_DEFAULT_ORDERBY, offset + "," + limit);
250 | return extract(0,cursor);
251 | }
252 |
253 | protected List extract(int position, Cursor cursor) {
254 |
255 | List weights = new ArrayList();
256 | if (cursor == null || cursor.getCount() <= position) {
257 | return weights;
258 | }
259 |
260 | cursor.moveToFirst();
261 | cursor.moveToPosition(position);
262 |
263 | do {
264 | Weight weight = new Weight();
265 | weight.key = cursor.getLong(cursor.getColumnIndex(DB_PRIMARY_KEY));
266 | weight.value = cursor.getString(cursor.getColumnIndex(DB_TABLE_COLUMN_WEIGHT));
267 | weight.date = cursor.getLong(cursor.getColumnIndex(DB_TABLE_COLUMN_DATE));
268 | weights.add(weight);
269 | }while(cursor.moveToNext());
270 |
271 | cursor.close();
272 |
273 | return weights;
274 | }
275 |
276 | protected long getkey(int position,String condition) {
277 | long key = -1;
278 | Cursor cursor = mDB.query(true,DB_TABLE_NAME, new String[]{DB_PRIMARY_KEY},condition,null,null,null,
279 | DB_DEFAULT_ORDERBY, null);
280 | if (cursor != null && cursor.getCount() > 0) {
281 | cursor.moveToPosition(position);
282 | key = cursor.getLong(cursor.getColumnIndex(DB_PRIMARY_KEY));
283 | cursor.close();
284 | }
285 | return key;
286 | }
287 | }
288 |
289 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/core/WeightDBHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.core;
12 |
13 | import java.text.DecimalFormat;
14 | import java.util.List;
15 |
16 | import com.jhuster.eweightscale.Configuration;
17 | import com.jhuster.eweightscale.core.DateHelper.DatePeriod;
18 | import com.jhuster.eweightscale.core.WeightDB.Weight;
19 |
20 | public class WeightDBHelper {
21 |
22 | public static boolean isEmpty() {
23 | return WeightDB.getInstance().size()==0;
24 | }
25 |
26 | public static boolean isEmpty(int year) {
27 | DatePeriod period = DateHelper.getYearPeriod(year);
28 | String condition = WeightDB.getInstance().makeCondition(period.begin,period.end);
29 | return WeightDB.getInstance().size(condition)==0;
30 | }
31 |
32 | public static boolean isEmpty(int year,int month) {
33 | DatePeriod period = DateHelper.getMonthPeriod(year,month);
34 | String condition = WeightDB.getInstance().makeCondition(period.begin,period.end);
35 | return WeightDB.getInstance().size(condition)==0;
36 | }
37 |
38 | public static boolean isEmpty(int year,int month,int day) {
39 | DatePeriod period = DateHelper.getDatePeriod(year,month,day);
40 | String condition = WeightDB.getInstance().makeCondition(period.begin,period.end);
41 | return WeightDB.getInstance().size(condition)==0;
42 | }
43 |
44 | public static Double getWeightAverage(int year) {
45 | DatePeriod period = DateHelper.getYearPeriod(year);
46 | return getWeightAverage(period);
47 | }
48 |
49 | public static Double getWeightAverage(int year,int month) {
50 | DatePeriod period = DateHelper.getMonthPeriod(year,month);
51 | return getWeightAverage(period);
52 | }
53 |
54 | public static Double getWeightAverage(int year,int month,int day) {
55 | DatePeriod period = DateHelper.getDatePeriod(year,month,day);
56 | return getWeightAverage(period);
57 | }
58 |
59 | public static Double getWeightReduceThisWeek() {
60 | DatePeriod period = DateHelper.getWeekPeriod(DateHelper.getToday());
61 | String condition = WeightDB.getInstance().makeCondition(period.begin,period.end);
62 | List weights = WeightDB.getInstance().query(condition);
63 | if (weights.size() < 2) {
64 | return 0.0;
65 | }
66 | return Double.valueOf(weights.get(0).value) - Double.valueOf(weights.get(weights.size()-1).value);
67 | }
68 |
69 | public static Double getWeightReduceThisMonth() {
70 | DatePeriod period = DateHelper.getMonthPeriod(DateHelper.getToday());
71 | String condition = WeightDB.getInstance().makeCondition(period.begin,period.end);
72 | List weights = WeightDB.getInstance().query(condition);
73 | if (weights.size() < 2) {
74 | return 0.0;
75 | }
76 | return Double.valueOf(weights.get(0).value) - Double.valueOf(weights.get(weights.size()-1).value);
77 | }
78 |
79 | public static Double getWeightAverage(DatePeriod period) {
80 | String condition = WeightDB.getInstance().makeCondition(period.begin,period.end);
81 | List weights = WeightDB.getInstance().query(condition);
82 | Double average = 0.0;
83 | if (weights.isEmpty()) {
84 | return average;
85 | }
86 | for (int i=0; i weights = WeightDB.getInstance().query(condition);
99 | if (weights.isEmpty()) {
100 | return false;
101 | }
102 | return true;
103 | }
104 |
105 | public static boolean isTodayRecord() {
106 | DatePeriod period = DateHelper.getDatePeriod(DateHelper.getToday());
107 | String condition = WeightDB.getInstance().makeCondition(period.begin,period.end);
108 | List weights = WeightDB.getInstance().query(condition);
109 | if (weights.isEmpty()) {
110 | return false;
111 | }
112 | return true;
113 | }
114 |
115 | public static int getContinuousDays() {
116 | if (!isYestdayRecord()) {
117 | if (isTodayRecord()) {
118 | Configuration.setContinousDays(1);
119 | }
120 | else {
121 | Configuration.setContinousDays(0);
122 | }
123 | }
124 | return Configuration.getContinousDays();
125 | }
126 |
127 | public static void addContinuousDays() {
128 | if (!isTodayRecord()) {
129 | int continuous = Configuration.getContinousDays();
130 | Configuration.setContinousDays(++continuous);
131 | }
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/widget/ChartDateSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.widget;
12 |
13 | import java.util.ArrayList;
14 | import java.util.Calendar;
15 | import com.jhuster.eweightscale.CommonUtil;
16 | import com.jhuster.eweightscale.R;
17 | import android.view.View;
18 | import android.widget.AdapterView;
19 | import android.widget.ArrayAdapter;
20 | import android.widget.Spinner;
21 | import android.widget.TextView;
22 |
23 | public class ChartDateSelector implements Spinner.OnItemSelectedListener {
24 |
25 | public static final String TITLE_DEFAULT = "体重趋势图";
26 |
27 | private TextView mViewTitle;
28 | private Spinner mYearSpinner;
29 | private Spinner mMonthSpinner;
30 | private ArrayAdapter mYearSpinnerAdapter;
31 | private ArrayAdapter mMonthSpinnerAdapter;
32 | private OnDateSelectedListener mDateSelectedListener;
33 | private int mChartMode = CommonUtil.ChartModeDay;
34 |
35 | public interface OnDateSelectedListener {
36 | public void onDateSelected();
37 | }
38 |
39 | public ChartDateSelector(View layout) {
40 |
41 | mViewTitle = (TextView) layout.findViewById(R.id.DateSelectorTitle);
42 | mYearSpinner = (Spinner) layout.findViewById(R.id.DateSelectorYearSpinner);
43 | mMonthSpinner = (Spinner) layout.findViewById(R.id.DateSelectorMonthSpinner);
44 |
45 | ArrayList years = new ArrayList();
46 | for (int year=CommonUtil.MinYear; year<=CommonUtil.MaxYear; year++) {
47 | years.add(year+CommonUtil.YearUnit);
48 | }
49 |
50 | mYearSpinnerAdapter = new ArrayAdapter(layout.getContext(),android.R.layout.simple_spinner_item,years);
51 | mYearSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
52 | mYearSpinner.setAdapter(mYearSpinnerAdapter);
53 |
54 | ArrayList months = new ArrayList();
55 | for (int month=CommonUtil.MinMonth; month<=CommonUtil.MaxMonth; month++) {
56 | months.add(month+CommonUtil.MonthUnit);
57 | }
58 |
59 | mMonthSpinnerAdapter = new ArrayAdapter(layout.getContext(),android.R.layout.simple_spinner_item,months);
60 | mMonthSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
61 | mMonthSpinner.setAdapter(mMonthSpinnerAdapter);
62 |
63 | mYearSpinner.setOnItemSelectedListener(this);
64 | mMonthSpinner.setOnItemSelectedListener(this);
65 | }
66 |
67 | public void setOnDateSelectedListener(OnDateSelectedListener listener) {
68 | mDateSelectedListener = listener;
69 | }
70 |
71 | public void setChartMode(int chartmode) {
72 |
73 | mChartMode = chartmode;
74 |
75 | mViewTitle.setVisibility(View.GONE);
76 | mYearSpinner.setVisibility(View.GONE);
77 | mMonthSpinner.setVisibility(View.GONE);
78 |
79 | if (chartmode == CommonUtil.ChartModeYear) {
80 | mViewTitle.setText(TITLE_DEFAULT);
81 | mViewTitle.setVisibility(View.VISIBLE);
82 | }
83 | else if (chartmode == CommonUtil.ChartModeMonth) {
84 | setSelectedYear(Calendar.getInstance().get(Calendar.YEAR));
85 | }
86 | else if (chartmode == CommonUtil.ChartModeDay) {
87 | setSelectedYear(Calendar.getInstance().get(Calendar.YEAR));
88 | setSelectedMonth(Calendar.getInstance().get(Calendar.MONTH));
89 | }
90 | else{}
91 | }
92 |
93 | public void setViewTitle(String title) {
94 | mViewTitle.setText(title);
95 | }
96 |
97 | public void setSelectedYear(int year) {
98 | mYearSpinner.setSelection(year-CommonUtil.MinYear);
99 | mYearSpinner.setVisibility(View.VISIBLE);
100 | }
101 |
102 | public void setSelectedMonth(int month) {
103 | mMonthSpinner.setSelection(month);
104 | mMonthSpinner.setVisibility(View.VISIBLE);
105 | }
106 |
107 | public int getChartMode() {
108 | return mChartMode;
109 | }
110 |
111 | public int getSelectYear() {
112 | return mYearSpinner.getSelectedItemPosition() + CommonUtil.MinYear;
113 | }
114 |
115 | public int getSelectMonth() {
116 | return mMonthSpinner.getSelectedItemPosition();
117 | }
118 |
119 | @Override
120 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
121 | if (mDateSelectedListener != null) {
122 | mDateSelectedListener.onDateSelected();
123 | }
124 | }
125 |
126 | @Override
127 | public void onNothingSelected(AdapterView> parent) {
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/widget/ChartModeSelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.widget;
12 |
13 | import com.jhuster.eweightscale.CommonUtil;
14 | import com.jhuster.eweightscale.R;
15 | import android.view.View;
16 | import android.widget.RadioGroup;
17 | import android.widget.TextView;
18 | import android.widget.RadioGroup.OnCheckedChangeListener;
19 |
20 | public class ChartModeSelector implements OnCheckedChangeListener {
21 |
22 | private RadioGroup mRadioGroup;
23 | private TextView mRadioGroupTitle;
24 | private OnDateModeSelectListener mDateModeSelectListener;
25 |
26 | public interface OnDateModeSelectListener {
27 | public void onRadioYearSelected();
28 | public void onRadioMonthSelected();
29 | public void onRadioDaySelected();
30 | }
31 |
32 | public ChartModeSelector(RadioGroup layout, String title) {
33 | mRadioGroup = layout;
34 | mRadioGroupTitle = (TextView)layout.findViewById(R.id.RadioGroupTitle);
35 | mRadioGroupTitle.setText(title);
36 | mRadioGroup.setOnCheckedChangeListener(this);
37 | }
38 |
39 | public void setOnDateModeSelectListener(OnDateModeSelectListener listener) {
40 | mDateModeSelectListener = listener;
41 | }
42 |
43 | public void setRadioChecked(int datemode) {
44 | if (datemode == CommonUtil.ChartModeYear) {
45 | mRadioGroup.check(R.id.RadioYear);
46 | }
47 | else if (datemode == CommonUtil.ChartModeMonth) {
48 | mRadioGroup.check(R.id.RadioMonth);
49 | }
50 | else if (datemode == CommonUtil.ChartModeDay) {
51 | mRadioGroup.check(R.id.RadioDay);
52 | }
53 | else{}
54 | }
55 |
56 | public void setVisibility(boolean isVisible) {
57 | if (isVisible) {
58 | mRadioGroup.setVisibility(View.VISIBLE);
59 | }
60 | else {
61 | mRadioGroup.setVisibility(View.GONE);
62 | }
63 | }
64 |
65 | @Override
66 | public void onCheckedChanged(RadioGroup group, int checkedId) {
67 | if (mDateModeSelectListener == null) {
68 | return;
69 | }
70 | switch(checkedId) {
71 | case R.id.RadioYear:
72 | mDateModeSelectListener.onRadioYearSelected();
73 | break;
74 | case R.id.RadioMonth:
75 | mDateModeSelectListener.onRadioMonthSelected();
76 | break;
77 | case R.id.RadioDay:
78 | mDateModeSelectListener.onRadioDaySelected();
79 | break;
80 | default:
81 | break;
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/widget/InputDialog.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.widget;
12 |
13 | import com.jhuster.eweightscale.R;
14 | import android.app.AlertDialog;
15 | import android.app.AlertDialog.Builder;
16 | import android.content.Context;
17 | import android.content.DialogInterface;
18 | import android.content.DialogInterface.OnClickListener;
19 | import android.text.Editable;
20 | import android.text.TextWatcher;
21 | import android.view.LayoutInflater;
22 | import android.view.View;
23 | import android.widget.EditText;
24 |
25 | public class InputDialog implements TextWatcher {
26 |
27 | protected static final Double MAX_INPUT_DATA = 200.00;
28 | protected static final Double MIN_INPUT_DATA = 10.00;
29 |
30 | protected Context mContext;
31 | protected EditText mEditText;
32 | protected AlertDialog mAlertDialog;
33 |
34 | public InputDialog(Context context) {
35 | mContext = context;
36 | AlertDialog.Builder builder = new Builder(context);
37 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
38 | View root = inflater.inflate(R.layout.dialog_input_weight,null);
39 | mEditText = (EditText)root.findViewById(R.id.DlgEditText);
40 | builder.setTitle(context.getString(R.string.dlg_add_weight));
41 | builder.setView(root);
42 | mAlertDialog = builder.create();
43 | mAlertDialog.setCancelable(false);
44 | mEditText.addTextChangedListener(this);
45 | }
46 |
47 | public void setOnClickListener(OnClickListener listener) {
48 | mAlertDialog.setButton(DialogInterface.BUTTON_POSITIVE,mContext.getString(R.string.dlg_ok),listener);
49 | mAlertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,mContext.getString(R.string.dlg_cancel),listener);
50 | }
51 |
52 | public void show() {
53 | mAlertDialog.show();
54 | mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
55 | }
56 |
57 | public String getInputValue() {
58 | return mEditText.getText().toString();
59 | }
60 |
61 | @Override
62 | public void beforeTextChanged(CharSequence s, int start, int count,int after) {
63 |
64 | }
65 |
66 | @Override
67 | public void onTextChanged(CharSequence s, int start, int before, int count) {
68 |
69 | }
70 |
71 | @Override
72 | public void afterTextChanged(Editable s) {
73 |
74 | if (mAlertDialog == null) {
75 | return;
76 | }
77 |
78 | mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
79 |
80 | if ("".equals(s.toString())) {
81 | return;
82 | }
83 |
84 | Double value = Double.valueOf(s.toString());
85 | if (value < MIN_INPUT_DATA || value > MAX_INPUT_DATA) {
86 | return;
87 | }
88 |
89 | mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/widget/SearchDialog.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.widget;
12 |
13 | import com.jhuster.eweightscale.core.DateHelper;
14 | import com.jhuster.eweightscale.core.WeightDB;
15 | import com.jhuster.eweightscale.core.DateHelper.DatePeriod;
16 | import com.jhuster.eweightscale.widget.ChartModeSelector.OnDateModeSelectListener;
17 | import com.jhuster.eweightscale.R;
18 |
19 | import android.app.AlertDialog;
20 | import android.app.AlertDialog.Builder;
21 | import android.content.Context;
22 | import android.content.DialogInterface;
23 | import android.content.DialogInterface.OnClickListener;
24 | import android.view.LayoutInflater;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 | import android.widget.DatePicker;
28 | import android.widget.EditText;
29 | import android.widget.RadioGroup;
30 |
31 | public class SearchDialog implements OnDateModeSelectListener {
32 |
33 | protected Context mContext;
34 | protected EditText mEditText;
35 | protected AlertDialog mAlertDialog;
36 |
37 | protected SearchType mSearchType = SearchType.SearchTypeYear;
38 | protected ChartModeSelector mDateModeWidget;
39 | protected DatePicker mDatePicker;
40 | protected String mSearchCondition=null;
41 |
42 | public static enum SearchType {
43 | SearchTypeYear,
44 | SearchTypeMonth,
45 | SearchTypeDay,
46 | };
47 |
48 | public SearchDialog(Context context) {
49 | mContext = context;
50 | AlertDialog.Builder builder = new Builder(context);
51 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
52 | View root = inflater.inflate(R.layout.dialog_search,null);
53 | mDateModeWidget = new ChartModeSelector((RadioGroup)root.findViewById(R.id.SearchModeSelecter),
54 | context.getString(R.string.dlg_search_condition));
55 | mDateModeWidget.setOnDateModeSelectListener(this);
56 | mDatePicker = (DatePicker) root.findViewById(R.id.SearchDatePicker);
57 | setDatePickerEnabled(true,false,false);
58 | builder.setTitle(context.getString(R.string.dlg_search_weight));
59 | builder.setView(root);
60 | mAlertDialog = builder.create();
61 | mAlertDialog.setCancelable(false);
62 | }
63 |
64 | public void setOnClickListener(OnClickListener listener) {
65 | mAlertDialog.setButton(DialogInterface.BUTTON_POSITIVE,mContext.getString(R.string.dlg_ok),listener);
66 | mAlertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,mContext.getString(R.string.dlg_cancel),listener);
67 | }
68 |
69 | public void show() {
70 | mAlertDialog.show();
71 | }
72 |
73 | protected void setDatePickerEnabled(boolean year, boolean month, boolean date) {
74 | ((ViewGroup)((ViewGroup)mDatePicker.getChildAt(0)).getChildAt(0)).getChildAt(0).setEnabled(year);
75 | ((ViewGroup)((ViewGroup)mDatePicker.getChildAt(0)).getChildAt(0)).getChildAt(1).setEnabled(month);
76 | ((ViewGroup)((ViewGroup)mDatePicker.getChildAt(0)).getChildAt(0)).getChildAt(2).setEnabled(date);
77 | mDatePicker.invalidate();
78 | }
79 |
80 | @Override
81 | public void onRadioYearSelected() {
82 | setDatePickerEnabled(true,false,false);
83 | mSearchType = SearchType.SearchTypeYear;
84 | }
85 |
86 | @Override
87 | public void onRadioMonthSelected() {
88 | setDatePickerEnabled(true,true,false);
89 | mSearchType = SearchType.SearchTypeMonth;
90 | }
91 |
92 | @Override
93 | public void onRadioDaySelected() {
94 | setDatePickerEnabled(true,true,true);
95 | mSearchType = SearchType.SearchTypeDay;
96 | }
97 |
98 | public SearchType getSearchType() {
99 | return mSearchType;
100 | }
101 |
102 | public int getSearchYear() {
103 | return mDatePicker.getYear();
104 | }
105 |
106 | public int getSearchMonth() {
107 | return mDatePicker.getMonth(); //DatePicker返回的month是0~11
108 | }
109 |
110 | public int getSearchDay() {
111 | return mDatePicker.getDayOfMonth();
112 | }
113 |
114 | public String getSearchCondition() {
115 | DatePeriod period = null;
116 | if (mSearchType == SearchType.SearchTypeYear) {
117 | period = DateHelper.getYearPeriod(getSearchYear());
118 | }
119 | else if (mSearchType == SearchType.SearchTypeMonth) {
120 | period = DateHelper.getMonthPeriod(getSearchYear(),getSearchMonth());
121 | }
122 | else {
123 | period = DateHelper.getDatePeriod(getSearchYear(),getSearchMonth(),getSearchDay());
124 | }
125 | return WeightDB.getInstance().makeCondition(period.begin,period.end);
126 | }
127 | }
128 |
129 |
130 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jhuster/eweightscale/widget/SquareItemWidget.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015, Jhuster, All Rights Reserved
3 | * Author: Jhuster(lujun.hust@gmail.com)
4 | *
5 | * https://github.com/Jhuster/EWeightScale
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; version 2 of the License.
10 | */
11 | package com.jhuster.eweightscale.widget;
12 |
13 | import com.jhuster.eweightscale.R;
14 | import android.view.View;
15 | import android.widget.TextView;
16 |
17 | public class SquareItemWidget {
18 |
19 | private TextView mSquareTitle;
20 | private TextView mSquareValue;
21 |
22 | public SquareItemWidget(View layout, String title) {
23 | mSquareTitle = (TextView)layout.findViewById(R.id.SquareItemTitle);
24 | mSquareValue = (TextView)layout.findViewById(R.id.SquareItemValue);
25 | mSquareTitle.setText(title);
26 | }
27 |
28 | public void setItemValue(String value) {
29 | mSquareValue.setText(value);
30 | }
31 |
32 | public String getItemValue() {
33 | return mSquareValue.getText().toString();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/color/tablehost_text_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/blue_btn_normal.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/blue_btn_normal.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/blue_btn_pressed.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/blue_btn_pressed.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/content_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/content_bg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/data_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/data_bg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/ic_action_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/ic_action_search.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_goicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/ic_goicon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_green.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/ic_green.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/ic_red.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_yellow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/ic_yellow.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_chart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/icon_chart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_chart_s.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/icon_chart_s.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_data.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/icon_data.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_data_s.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/icon_data_s.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_more.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/icon_more.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_more_s.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/icon_more_s.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/icon_search.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_square.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/icon_square.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/icon_square_s.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/icon_square_s.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/img_about_app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-hdpi/img_about_app.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/actionbar_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/blue_btn_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/item_click_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_chart_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_data_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_more_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_square_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/timestamp_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_about.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
22 |
23 |
32 |
33 |
42 |
43 |
44 |
45 |
52 |
53 |
59 |
60 |
66 |
67 |
73 |
74 |
75 |
76 |
84 |
85 |
93 |
94 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_chart.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
17 |
18 |
19 |
20 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_data.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
24 |
25 |
31 |
32 |
37 |
38 |
39 |
40 |
46 |
47 |
53 |
54 |
59 |
60 |
61 |
62 |
68 |
69 |
75 |
76 |
81 |
82 |
83 |
84 |
85 |
86 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
15 |
21 |
28 |
34 |
39 |
44 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_more.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
20 |
21 |
22 |
23 |
29 |
30 |
32 |
33 |
38 |
39 |
42 |
43 |
44 |
45 |
51 |
52 |
54 |
55 |
60 |
61 |
63 |
64 |
65 |
66 |
72 |
73 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_personal.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
19 |
20 |
24 |
25 |
26 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_setting.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_square.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
21 |
22 |
30 |
31 |
35 |
36 |
38 |
39 |
43 |
44 |
46 |
47 |
51 |
52 |
54 |
55 |
56 |
57 |
63 |
64 |
72 |
73 |
77 |
78 |
80 |
81 |
85 |
86 |
88 |
89 |
93 |
94 |
104 |
105 |
106 |
107 |
117 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_what.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_input_weight.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_search.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
9 |
10 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_birthday_selecter.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
25 |
26 |
32 |
33 |
34 |
35 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_chartdate_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
23 |
24 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_height_input.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_search_input.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_search_mode_selecter.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
26 |
27 |
33 |
34 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_setting_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
20 |
21 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_sex_selecter.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
26 |
27 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_square_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
18 |
19 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/widget_weight_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
22 |
23 |
28 |
29 |
35 |
36 |
37 |
38 |
44 |
45 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/data_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_actions.xml:
--------------------------------------------------------------------------------
1 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | @android:color/white
5 | @android:color/black
6 | #083a8a
7 | #FF888888
8 | #009933
9 |
10 | #FFCCCCCC
11 | #e6ecee
12 | #dddfe2
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 8dp
3 | 12sp
4 | 15sp
5 | 20sp
6 | 30sp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 体重档案
5 |
6 | 图表
7 | 数据
8 | 更多
9 | 诊断
10 |
11 | 搜索
12 | 添加
13 |
14 | 持续记录
15 | 本周体重
16 | 本月体重
17 |
18 | 检索结果
19 | 关于我们
20 |
21 | 添加体重
22 | 请输入体重(kg)
23 |
24 | 检索数据
25 | 检索方式
26 |
27 | 个人信息
28 | 系统设置
29 | 数据备份与恢复
30 |
31 | 什么是BMI
32 | 什么是BMR
33 |
34 | 检查新版本
35 | 关于我们
36 |
37 | 图片
38 |
39 | 确定
40 | 取消
41 | 是
42 | 否
43 |
44 | 年
45 | 月
46 | 日
47 |
48 | 性别:
49 | 男
50 | 女
51 |
52 | 生日:
53 | 身高:
54 | 请输入身高(cm)
55 |
56 | 保存
57 |
58 | 没有有效数据
59 | 请先到\"更多\"->\"个人信息\"栏目完善您的个人信息
60 |
61 | 当前身体指标
62 | 体重值:
63 | 身体质量指数(BMI):
64 | 基础代谢率(BMR):
65 | 体重状况:
66 | 您的健康体重范围:
67 | 诊断结果:
68 |
69 | 检测新版本
70 | 当前已经是最新版本
71 | 记录体重变化
72 | 保持魔鬼身材
73 | 软件作者:卢俊
74 | 联系方式:lujun.hust@gmail.com
75 | 个人网站:http://www.jhuster.com
76 | Copyright @2015 Jhuster
77 | All Rights Reserved
78 | setting_arrow
79 |
80 | 再按一次退出程序
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | jcenter()
5 | }
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:2.0.0-alpha7'
8 | }
9 | }
10 |
11 | allprojects {
12 | repositories {
13 | jcenter()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
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.10-all.zip
7 |
--------------------------------------------------------------------------------
/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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/screenshots/download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/screenshots/download.png
--------------------------------------------------------------------------------
/screenshots/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Jhuster/EWeightScale/384785c4a8610cb00a086b9cd2f34054f23bf215/screenshots/home.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------