个人信息添加

This commit is contained in:
ScorpioMiku
2018-10-01 14:26:58 +08:00
parent 660320d900
commit a0483f33e6
18 changed files with 626 additions and 102 deletions

View File

@@ -6,9 +6,18 @@ import android.os.Bundle;
import com.example.ninefourone.nutritionmaster.bean.MyUser;
import com.example.ninefourone.nutritionmaster.bean.Occupation;
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
import com.example.ninefourone.nutritionmaster.utils.WebUtils;
import com.google.gson.Gson;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
/**
@@ -70,6 +79,7 @@ public class NutritionMaster extends Application {
}
});
initOccupations();
}
public static NutritionMaster getInstance() {
@@ -94,6 +104,27 @@ public class NutritionMaster extends Application {
user.setNickName("ScorpioMiku");
}
/**
* 初始化职业常量
*/
private void initOccupations() {
WebUtils.getAllOccupations(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Occupation[] occupations = new Gson().fromJson(response.body().string(), Occupation[].class);
for (int i = 0; i < occupations.length; i++) {
ConstantUtils.occupationList.add(occupations[i].getOccupation_name());
}
}
});
}
}

View File

@@ -51,13 +51,13 @@ public class CardAdapter extends RecyclerView.Adapter<CardHolder> {
* 右划
*/
public void swipe2Right() {
Logger.d("右划");
// Logger.d("右划");
}
/**
* 左划
*/
public void swipe2left() {
Logger.d("左划");
// Logger.d("左划");
}
}

View File

@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
import com.example.ninefourone.nutritionmaster.NutritionMaster;
import com.example.ninefourone.nutritionmaster.bean.MyUser;
import com.orhanobut.logger.Logger;
import butterknife.ButterKnife;
import butterknife.Unbinder;
@@ -91,4 +92,17 @@ public abstract class BaseActivity extends AppCompatActivity {
protected void upUser(MyUser user) {
NutritionMaster.user = user;
}
@Override
protected void onResume() {
super.onResume();
backChangeData();
}
/**
* 填写完信息返回Activity调用
*/
protected void backChangeData() {
}
}

View File

@@ -0,0 +1,30 @@
package com.example.ninefourone.nutritionmaster.base;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import com.example.ninefourone.nutritionmaster.NutritionMaster;
import com.example.ninefourone.nutritionmaster.bean.MyUser;
/**
* Created by ScorpioMiku on 2018/10/1.
*/
public abstract class BaseDialog extends AlertDialog.Builder {
protected AlertDialog dialog;
public BaseDialog(@NonNull Context context) {
super(context);
}
protected void upUser(MyUser user) {
NutritionMaster.user = user;
}
public void showDialog() {
dialog.show();
}
}

View File

@@ -39,10 +39,19 @@ public class MyUser {
private String occupation_name;
private List<?> groups;
private List<?> user_permissions;
private int age;
private float weight = 0;
private float height = 0;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public float getWeight() {
return weight;
}
@@ -163,6 +172,14 @@ public class MyUser {
this.sex = sex;
}
public void setSex(String sex) {
if (sex.equals("")) {
this.sex = 1;
} else {
this.sex = 0;
}
}
public String getOccupation_name() {
return occupation_name;
}
@@ -206,6 +223,10 @@ public class MyUser {
", occupation_name='" + occupation_name + '\'' +
", groups=" + groups +
", user_permissions=" + user_permissions +
", user_age=" + age +
", user_sex=" + sex +
", user_height=" + height +
", user_weight=" + weight +
'}';
}
}

View File

@@ -29,6 +29,9 @@ import com.example.ninefourone.nutritionmaster.base.BaseActivity;
import com.example.ninefourone.nutritionmaster.bean.Occupation;
import com.example.ninefourone.nutritionmaster.camera.FoodMaterialCamera;
import com.example.ninefourone.nutritionmaster.modules.addinformation.AddActivity;
import com.example.ninefourone.nutritionmaster.modules.addinformation.AddInformationActivity;
import com.example.ninefourone.nutritionmaster.modules.information.InformationActivity;
import com.example.ninefourone.nutritionmaster.ui.InformationDialog;
import com.example.ninefourone.nutritionmaster.ui.NoScrollViewPager;
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
@@ -52,6 +55,7 @@ import com.mxn.soul.flowingdrawer_core.FlowingDrawer;
import com.nightonke.boommenu.BoomButtons.HamButton;
import com.nightonke.boommenu.BoomButtons.OnBMClickListener;
import com.nightonke.boommenu.BoomMenuButton;
import com.orhanobut.logger.Logger;
import java.io.IOException;
import java.util.ArrayList;
@@ -109,7 +113,6 @@ public class MainActivity extends BaseActivity {
@BindView(R.id.show_information)
LinearLayout showInformation;
private OptionsPickerView pickerView;
@Override
public int getLayoutId() {
@@ -137,13 +140,12 @@ public class MainActivity extends BaseActivity {
// Logger.i("openRatio=" + openRatio + " ,offsetPixels=" + offsetPixels);
}
});
initInforView();
initPicker();
// initInforView();
initSpiderView();
initViewPager();
initSearchView();
initBMB();
initOccupations();
// initOccupations();
}
@@ -305,23 +307,6 @@ public class MainActivity extends BaseActivity {
}
/**
* 初始化picker
*/
private void initPicker() {
pickerView = new OptionsPickerBuilder(MainActivity.this, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
final int option = options1;
userOccupationText.post(new Runnable() {
@Override
public void run() {
userOccupationText.setText(ConstantUtils.occupationList.get(option));
}
});
}
}).build();
}
/**
* 初始化悬浮按钮
@@ -349,6 +334,7 @@ public class MainActivity extends BaseActivity {
* 初始化个人信息界面UI
*/
private void initInforView() {
// Logger.d(NutritionMaster.user.toString());
adderInfor.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
if (NutritionMaster.user.getHeight() != 0) {
showInformation.setVisibility(View.VISIBLE);
@@ -358,13 +344,6 @@ public class MainActivity extends BaseActivity {
adderInfor.setVisibility(View.VISIBLE);
}
adderInfor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
/**
@@ -400,36 +379,25 @@ public class MainActivity extends BaseActivity {
case R.id.information_layout:
break;
case R.id.user_occupation_text:
pickerView.show();
break;
case R.id.adder_infor:
Intent i = new Intent(MainActivity.this, AddInformationActivity.class);
startActivity(i);
break;
}
}
/**
* 初始化职业常量
*/
private void initOccupations() {
if (userOccupationText.getText().equals("请选择您的职业")) {
WebUtils.getAllOccupations(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Occupation[] occupations = new Gson().fromJson(response.body().string(), Occupation[].class);
for (int i = 0; i < occupations.length; i++) {
// Logger.d(occupations[i].getOccupation_name());
ConstantUtils.occupationList.add(occupations[i].getOccupation_name());
}
pickerView.setPicker(ConstantUtils.occupationList);
}
});
@Override
protected void backChangeData() {
super.backChangeData();
initInforView();
if (NutritionMaster.user.getOccupation_name() == null) {
} else {
userOccupationText.setText("职业: " + NutritionMaster.user.getOccupation_name());
}
}
}

View File

@@ -0,0 +1,180 @@
package com.example.ninefourone.nutritionmaster.modules.addinformation;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.example.ninefourone.nutritionmaster.NutritionMaster;
import com.example.ninefourone.nutritionmaster.R;
import com.example.ninefourone.nutritionmaster.base.BaseActivity;
import com.example.ninefourone.nutritionmaster.bean.MyUser;
import com.example.ninefourone.nutritionmaster.modules.MainActivity;
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
import com.example.ninefourone.nutritionmaster.utils.MessageUtils;
public class AddInformationActivity extends BaseActivity {
private TextView ageTextView;
private TextView heightTextView;
private TextView weightTextView;
private TextView sexTextView;
private TextView occupationTextView;
private ImageView ageImageView;
private ImageView sexImageView;
private ImageView heightImageView;
private ImageView weightImageView;
private ImageView occupationImageView;
private Button okButton;
private OptionsPickerView agePicker;
private OptionsPickerView weightPicker;
private OptionsPickerView heightPicker;
private OptionsPickerView sexPicker;
private OptionsPickerView occupationPicker;
private Context context;
@Override
public int getLayoutId() {
return R.layout.add_information_activity;
}
@Override
public void initViews(Bundle savedInstanceState) {
context = this;
ageImageView = findViewById(R.id.age_image_view);
sexImageView = findViewById(R.id.sex_image_view);
heightImageView = findViewById(R.id.height_image_view);
weightImageView = findViewById(R.id.weight_image_view);
occupationImageView = findViewById(R.id.occupation_image_view);
ageTextView = findViewById(R.id.age_text_view);
sexTextView = findViewById(R.id.sex_text_view);
weightTextView = findViewById(R.id.weight_text_view);
heightTextView = findViewById(R.id.height_text_view);
occupationTextView = findViewById(R.id.occupation_text_view);
okButton = findViewById(R.id.ok_button);
occupationPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
occupationTextView.setText(ConstantUtils.occupationList.get(options1));
}
}).build();
occupationPicker.setPicker(ConstantUtils.occupationList);
agePicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
ageTextView.setText(ConstantUtils.ageList.get(options1));
}
}).build();
agePicker.setPicker(ConstantUtils.ageList);
agePicker.setSelectOptions(25);
sexPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
sexTextView.setText(ConstantUtils.sexList.get(options1));
}
}).build();
sexPicker.setPicker(ConstantUtils.sexList);
heightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
heightTextView.setText(ConstantUtils.heightList.get(options1));
}
}).build();
heightPicker.setPicker(ConstantUtils.heightList);
heightPicker.setSelectOptions(119);
weightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
weightTextView.setText(ConstantUtils.weightList.get(options1));
}
}).build();
weightPicker.setPicker(ConstantUtils.weightList);
weightPicker.setSelectOptions(59);
occupationImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
occupationPicker.show();
}
});
ageImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
agePicker.show();
}
});
sexImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sexPicker.show();
}
});
heightImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
heightPicker.show();
}
});
weightImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
weightPicker.show();
}
});
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MyUser user = NutritionMaster.user;
if (ageTextView.getText().toString().equals("年龄") || weightTextView.getText().toString().equals("体重")
|| sexTextView.getText().toString().equals("性别") || heightTextView.getText().toString().equals("身高")||
occupationTextView.getText().toString().equals("职业")) {
MessageUtils.MakeToast("请点击图片填写所有信息");
} else {
user.setHeight(Integer.valueOf(heightTextView.getText().toString().split("c")[0]));
user.setWeight(Integer.valueOf(weightTextView.getText().toString().split("k")[0]));
user.setAge(Integer.valueOf(ageTextView.getText().toString().split("")[0]));
user.setSex(sexTextView.getText().toString());
user.setOccupation_name(occupationTextView.getText().toString());
// Logger.d(user.toString());
upUser(user);
MessageUtils.MakeToast("信息填写成功");
finish();
}
}
});
}
@Override
public void initToolBar() {
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
}

View File

@@ -0,0 +1,128 @@
package com.example.ninefourone.nutritionmaster.ui;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.example.ninefourone.nutritionmaster.R;
import com.example.ninefourone.nutritionmaster.base.BaseDialog;
import com.example.ninefourone.nutritionmaster.utils.ConstantUtils;
/**
* Created by ScorpioMiku on 2018/10/1.
*/
public class InformationDialog extends BaseDialog {
private TextView ageTextView;
private TextView heightTextView;
private TextView weightTextView;
private TextView sexTextView;
private ImageView ageImageView;
private ImageView sexImageView;
private ImageView heightImageView;
private ImageView weightImageView;
private Button okButton;
private OptionsPickerView agePicker;
private OptionsPickerView weightPicker;
private OptionsPickerView heightPicker;
private OptionsPickerView sexPicker;
public InformationDialog(@NonNull Context context) {
super(context);
dialog = create();
View view = View.inflate(context, R.layout.add_information_activity, null);
dialog.setView(view);
ageImageView = view.findViewById(R.id.age_image_view);
sexImageView = view.findViewById(R.id.sex_image_view);
heightImageView = view.findViewById(R.id.height_image_view);
weightImageView = view.findViewById(R.id.weight_image_view);
ageTextView = view.findViewById(R.id.age_text_view);
sexTextView = view.findViewById(R.id.sex_text_view);
weightTextView = view.findViewById(R.id.weight_text_view);
heightTextView = view.findViewById(R.id.height_text_view);
okButton = view.findViewById(R.id.ok_button);
agePicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
ageTextView.setText(ConstantUtils.ageList.get(options1));
}
}).build();
agePicker.setPicker(ConstantUtils.ageList);
sexPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
sexTextView.setText(ConstantUtils.ageList.get(options1));
}
}).build();
sexPicker.setPicker(ConstantUtils.sexList);
heightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
heightTextView.setText(ConstantUtils.ageList.get(options1));
}
}).build();
heightPicker.setPicker(ConstantUtils.heightList);
weightPicker = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
@Override
public void onOptionsSelect(int options1, int options2, int options3, View v) {
weightTextView.setText(ConstantUtils.ageList.get(options1));
}
}).build();
weightPicker.setPicker(ConstantUtils.weightList);
ageImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
agePicker.show();
}
});
sexImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sexPicker.show();
}
});
heightImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
heightPicker.show();
}
});
weightImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
weightPicker.show();
}
});
}
}

View File

@@ -54,4 +54,26 @@ public class ConstantUtils {
public static ArrayList<String> occupationList = new ArrayList<>();
public static ArrayList<String> ageList = new ArrayList<>();
public static ArrayList<String> sexList = new ArrayList<>();
public static ArrayList<String> heightList = new ArrayList<>();
public static ArrayList<String> weightList = new ArrayList<>();
static {
for (int i = 1; i <= 200; i++) {
if (i < 100) {
ageList.add(i + "");
}
heightList.add(i + 50 + "cm");
if (i < 150) {
weightList.add(i + "kg");
}
}
sexList.add("");
sexList.add("");
}
}