目录、
一,项目介绍:
二,项目功能介绍:
1新手引导界面
2健康饮食搭配主页
3食物搭配表
4 食物营养表
5本软件介绍←编辑
三,核心代码
(1)首页Mactivity核心代码
(2)食物搭配表
(3)食物营养表
(4)本软件介绍
四,项目的源码+word+功能截图
用户通过下载应用程序,进入应用程序可以在程序中浏览各种食物的搭配,如果是首次登录则会进入一个新手引导界面,引导选项都选择完成后则进入。
进入后有三个功能:第1个是健康饮食搭配表,查看各种食物的饮食搭配;第2个是事物营养表,查看即将发布的食物饮食详情;第3个是关于本软件的介绍,主要是有个轮播图展示,还有作者的详细信息。
图6.4.2-所述←.
这里是鸡肉的详情,还有鸡肉不能和那些食物搭配←
package com.animee.health.guide;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.animee.health.HomeMenuActivity;
import com.animee.health.R;
/**
* (1)启动器
*/
public class MainActivity extends AppCompatActivity {
TextView tv;
int time = 5;
SharedPreferences preferences; //存储键值对数据
private SharedPreferences.Editor editor;
@SuppressLint("HandlerLeak")
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if (msg.what==1) {
time--;
if (time ==0) {
// 跳转页面
Intent intent = new Intent();
boolean isfirst = preferences.getBoolean("isfirst", true);
if (isfirst) {
intent.setClass(MainActivity.this,GuideActivity.class);
editor.putBoolean("isfirst",false); //写入不是第一次进入的纪录
editor.commit(); // 提交本次修改纪录
}else {
intent.setClass(MainActivity.this,HomeMenuActivity.class);
}
startActivity(intent);
finish();
}else {
tv.setText(time+"");
handler.sendEmptyMessageDelayed(1,1000);
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_01);
tv = findViewById(R.id.main_tv);
preferences = getSharedPreferences("health_pref",MODE_PRIVATE);
editor = preferences.edit(); //写入数据的对象
handler.sendEmptyMessageDelayed(1,1000);
}
}
activity_home_menu_01.xml
package com.animee.health.food_list;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
import com.animee.health.R;
import com.animee.health.bean.FoodBean;
import com.animee.health.bean.FoodSQLite;
import com.animee.health.bean.FoodUtils;
import com.animee.health.food_grid.FoodDescActivity;
import java.util.ArrayList;
import java.util.List;
/**
* (2)菜单功能:食物搭配表--食物搜索页
*/
public class InfoListActivity extends AppCompatActivity implements View.OnClickListener{
EditText searchEt;
ImageView searchIv,flushIv;
ListView showLv;
// ListView内部数据源
ListmDatas;
ListallFoodList;
private InfoListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info_list_02);
// 查找控件
initView();
// 2.找到ListView对应的数据源
mDatas = new ArrayList<>();
allFoodList = FoodUtils.getAllFoodList();// FoodUtils:食物搭配表--食物搜索页
mDatas.addAll(allFoodList);
// 3.创建适配器 BaseAdapter的子类
adapter = new InfoListAdapter(this, mDatas);
showLv.setAdapter(adapter); //4.设置适配器
// 设置单向点击监听功能
setListener();
}
private void setListener() {
showLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
FoodBean foodBean = mDatas.get(position);
Intent intent = new Intent(InfoListActivity.this, FoodDescActivity.class);
intent.putExtra("food",foodBean);
startActivity(intent);
}
});
}
private void initView() {
searchEt = findViewById(R.id.info_et_search);
searchIv = findViewById(R.id.info_iv_search);
flushIv = findViewById(R.id.info_iv_flush);
showLv = findViewById(R.id.infolist_lv);
searchIv.setOnClickListener(this); //添加点击事件的监听器
flushIv.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.info_iv_flush: //刷新点击
searchEt.setText("");
mDatas.clear();
mDatas.addAll(allFoodList);
adapter.notifyDataSetChanged();
break;
case R.id.info_iv_search: //搜索点击
// 1.获取输入内容,判断不为空
String msg = searchEt.getText().toString().trim(); //获取输入信息
if (TextUtils.isEmpty(msg)) {
Toast.makeText(this,"输入内容不能为空!",Toast.LENGTH_SHORT).show();
return;
}
// 判断所有食物列表的标题是否包含输入内容,如果包含,就添加到小集合中
Listlist = new ArrayList<>();
for (int i = 0; i < allFoodList.size(); i++) {
String title = allFoodList.get(i).getTitle();
if (title.contains(msg)) {
list.add(allFoodList.get(i));
}
}
mDatas.clear(); // 清空ListView的适配器数据源内容
mDatas.addAll(list); // 添加新的数据到数据源中
adapter.notifyDataSetChanged(); // 提示适配器更新
break;
}
}
}
activity_info_list_02.xml
package com.animee.health.food_grid;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.animee.health.R;
import com.animee.health.bean.FoodBean;
/**
* (3)菜单功能:食物营养表--食物内容
*/
public class FoodDescActivity extends AppCompatActivity {
TextView titleTv1,titleTv2,descTv,notTv;
ImageView backIv,bigPicIv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_food_desc_03);
initView();
// 接受上一级页面传来的数据
Intent intent = getIntent();
FoodBean foodBean = (FoodBean) intent.getSerializableExtra("food");
// 设置显示控件
titleTv1.setText(foodBean.getTitle());
titleTv2.setText(foodBean.getTitle());
descTv.setText(foodBean.getDesc());
notTv.setText(foodBean.getNotmatch());
bigPicIv.setImageResource(foodBean.getPicId());
}
private void initView() {
titleTv1 = findViewById(R.id.fooddesc_tv_title1);
titleTv2 = findViewById(R.id.fooddesc_tv_title2);
descTv = findViewById(R.id.fooddesc_tv_desc);
notTv = findViewById(R.id.fooddesc_tv_not);
backIv = findViewById(R.id.fooddesc_iv_back);
bigPicIv = findViewById(R.id.fooddesc_iv_bigpic);
backIv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish(); //销毁当前的activity
}
});
}
}
activity_food_grid_03.xml
package com.animee.health;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
/**
* (4)软件版本说明
*/
public class AboutActivity extends AppCompatActivity implements View.OnClickListener{
ViewPager aboutVp;
TextView shareTv;
LinearLayout pointLayout;
ListviewList; //ViewPager的数据源
int[]picIds = {R.mipmap.ab1,R.mipmap.ab2,R.mipmap.ab3,R.mipmap.ab4,R.mipmap.ab5};
private AboutAdapter adapter;
ListpointList; //存放显示器小点点的集合
/**
* 轮播图的轮播
*/
@SuppressLint("HandlerLeak")
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if (msg.what == 1) {
// 接收到消息之后,需要使ViewPager页面向下滑动一页
int currentItem = aboutVp.getCurrentItem();
aboutVp.setCurrentItem(currentItem+1);
handler.sendEmptyMessageDelayed(1,5000);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_04);//设置当前版本
aboutVp = findViewById(R.id.about_vp);
shareTv = findViewById(R.id.about_tv_share);
pointLayout = findViewById(R.id.about_layout_point);
shareTv.setOnClickListener(this);
viewList = new ArrayList<>();
pointList = new ArrayList<>();
// 初始化ViewPager的页面信息
for (int i = 0; i < picIds.length; i++) {
View view = LayoutInflater.from(this).inflate(R.layout.item_aboutvp_04,null);
ImageView iv = view.findViewById(R.id.item_aboutvp_iv);
iv.setImageResource(picIds[i]);
viewList.add(view);
// 创建指示器内容
ImageView pointIv = new ImageView(this);
// 在代码中设置控件的宽高和外边距等属性
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0,0,20,0);
// 将布局参数设置给ImageView
pointIv.setLayoutParams(lp);
pointIv.setImageResource(R.mipmap.a2);
pointList.add(pointIv); //添加到集合当中便于统一管理
pointLayout.addView(pointIv); //添加到布局当中显示出来
}
pointList.get(0).setImageResource(R.mipmap.a3); //设置第一个小圆点为选中状态
// 创建适配器对象
adapter = new AboutAdapter(viewList);
// 设置适配器
aboutVp.setAdapter(adapter);
// 发送切换页面消息
handler.sendEmptyMessageDelayed(1,5000);
// 设置ViewPager页面监听器
setVPListener();
}
private void setVPListener() {
/* 设置ViewPager的监听器*/
aboutVp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
for (int i = 0; i < pointList.size(); i++) {
pointList.get(i).setImageResource(R.mipmap.a2);
}
pointList.get(position%pointList.size()).setImageResource(R.mipmap.a3);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
@Override
public void onClick(View v) {
// 调用系统自带的分享功能
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String msg= "健康饮食非常的重要,了解饮食各种营养素和热量,摄入正确的食物,让你变得更健康,想要了解更多么,快来下载健康饮食app吧~~";
intent.putExtra(Intent.EXTRA_TEXT,msg);
startActivity(Intent.createChooser(intent,"健康饮食分享"));
}
}
activity_about_04.xml