如何设计个人中心

登录

LoginActivity.java

package com.example.smartcity.activity.user;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.smartcity.R;
import com.example.smartcity.info.MCallBack;
import com.example.smartcity.utils.CacheUtils;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static com.example.smartcity.utils.ConstantsUtils.IP;
import static com.example.smartcity.utils.ConstantsUtils.LOGIN;
import static com.example.smartcity.utils.ConstantsUtils.LOGIN_WHAT;
import static com.example.smartcity.utils.KeyUtils.TOKEN;

public class LoginActivity extends AppCompatActivity {
    private EditText mEdtUsername;
    private EditText mEdtPwd;
    private TextView mRegJudge;
    Handler handler = new Handler(Looper.myLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case LOGIN_WHAT:
                    MCallBack mCallBack = (MCallBack) msg.obj;
                    if (mCallBack.getCode() == 200) {
                        Toast.makeText(LoginActivity.this, "登录成功!", Toast.LENGTH_SHORT).show();
                        CacheUtils.putString(LoginActivity.this, TOKEN, mCallBack.getToken());//存token
                       finish();
                    } else {
                        Toast.makeText(LoginActivity.this, mCallBack.getMsg(), Toast.LENGTH_SHORT).show();
                    }
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
    }

    //异步请求用户登录数据
    public void loginData() {
        String form = "{" +
                "\"username\":\""+mEdtUsername.getText().toString()+"\"," +
                "\"password\":\""+mEdtPwd.getText().toString()+"\"" +
                "}";
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, form);
        Request request = new Request.Builder()
                .url(IP + LOGIN)
                .post(body)
                .build();
        new OkHttpClient().newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String loginDataStr = response.body().string();
                Log.e("TAG", "onResponse: "+loginDataStr);
                MCallBack mCallBack = new Gson().fromJson(loginDataStr, MCallBack.class);
                Message message = new Message();
                message.what = LOGIN_WHAT;
                message.obj = mCallBack;
                handler.sendMessage(message);
            }
        });
    }

    public void initView() {
        mEdtUsername = (EditText) findViewById(R.id.edt_username);
        mEdtPwd = (EditText) findViewById(R.id.edt_pwd);
        mRegJudge = (TextView) findViewById(R.id.reg_judge);
    }

    //点击返回
    public void backPerson(View view) {
        finish();
    }

    //点击登录
    public void login(View view) {
        loginData();
    }
}

activity_login.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.user.LoginActivity"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal"
        android:layout_marginTop="70dp">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/ic_logo"
            android:layout_gravity="center"
            android:layout_marginLeft="90dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:text="猫眼电影"
            android:textSize="30dp"
            android:layout_marginTop="5dp"/>
    </LinearLayout>

    <EditText
        android:id="@+id/edt_username"
        android:layout_width="250dp"
        android:layout_height="50dp"
        android:background="@drawable/bg_login"
        android:layout_gravity="center"
        android:layout_marginTop="70dp"
        android:hint="请输入账号"
        android:textColor="#000000"
        android:textAlignment="center"
        android:inputType="number"/>

    <EditText
        android:id="@+id/edt_pwd"
        android:layout_width="250dp"
        android:layout_height="50dp"
        android:background="@drawable/bg_login"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:hint="请输入密码"
        android:textColor="#000000"
        android:textAlignment="center"
        android:inputType="textPassword"/>

    <TextView
        android:id="@+id/reg_judge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="点击注册?"
        android:layout_marginLeft="260dp"
        android:layout_marginTop="40dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="50dp">
        <Button
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:text="登 录"
            android:textColor="@color/white"
            android:background="#CA3939"
            android:textSize="20dp"
            android:layout_gravity="center"
            android:layout_marginLeft="65dp"
            android:onClick="login"/>

        <Button
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:text="返 回"
            android:textColor="@color/white"
            android:background="#CA3939"
            android:textSize="20dp"
            android:layout_gravity="center"
            android:layout_marginLeft="30dp"
            android:onClick="backPerson"/>


    </LinearLayout>




</LinearLayout>

个人信息

InfoActivity.java

package com.example.smartcity.activity.user;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.smartcity.R;
import com.example.smartcity.info.GetPersonInfo;
import com.example.smartcity.info.MCallBack;
import com.example.smartcity.utils.CacheUtils;
import com.example.smartcity.utils.SexUtils;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static com.example.smartcity.utils.ConstantsUtils.IP;
import static com.example.smartcity.utils.ConstantsUtils.MODIFY_INFO;
import static com.example.smartcity.utils.ConstantsUtils.MODIFY_INFO_WHAT;
import static com.example.smartcity.utils.KeyUtils.TOKEN;
import static com.example.smartcity.utils.KeyUtils.USER_INFO;

public class InfoActivity extends AppCompatActivity {
    private ImageView mInfoHeadImg;
    private TextView mInfoUsername;
    private TextView mInfoCardTitle;
    private TextView mInfoCardTxt;
    private EditText mInfoNickname;
    private EditText mInfoSex;
    private EditText mInfoPhone;
    private ImageView back;
    private String token;
    Handler handler = new Handler(Looper.myLooper()){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case MODIFY_INFO_WHAT:
                    MCallBack mCallBack = (MCallBack) msg.obj;
                    if (mCallBack.getCode()==200){
                        Toast.makeText(InfoActivity.this,"修改成功!",Toast.LENGTH_SHORT).show();
                        finish();
                    }
                    else {
                        Toast.makeText(InfoActivity.this,mCallBack.getMsg(),Toast.LENGTH_SHORT).show();
                    }
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info);
        initView();

        //显示信息
        token = CacheUtils.getString(InfoActivity.this, TOKEN);//取出token
        if (!token.isEmpty()){
            showInfo();
        }
    }

    //异步请求修改用户信息数据
    public void modifyInfoData(){
        String sexs="";
        SexUtils.putSex(InfoActivity.this,mInfoSex.getText().toString(),sexs);
        String form = "{"+
                "\"nickName\": \""+mInfoNickname.getText().toString()+"\","+
                "\"phonenumber\": \""+mInfoPhone.getText().toString()+"\","+
                "\"sex\": \""+sexs+"\""+
                "}";
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, form);
        Request request = new Request.Builder()
                .url(IP + MODIFY_INFO)
                .put(body)
                .addHeader("authorization", token)
                .addHeader("content-type", "application/json")
                .addHeader("cache-control", "no-cache")
                .addHeader("postman-token", "06c9f262-35ae-af77-51e5-8d68a15de94b")
                .build();
        new OkHttpClient().newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String modifyInfoDataStr = response.body().string();
                MCallBack mCallBack = new Gson().fromJson(modifyInfoDataStr, MCallBack.class);
                Message message = new Message();
                message.what = MODIFY_INFO_WHAT;
                message.obj = mCallBack;
                handler.sendMessage(message);
            }
        });
    }

    //显示信息
    public void showInfo(){
        String json = CacheUtils.getString(InfoActivity.this,USER_INFO);//取出用户信息
        GetPersonInfo getPersonInfo = new Gson().fromJson(json, GetPersonInfo.class);//在解析一遍

        mInfoUsername.setText(getPersonInfo.getUser().getUserName());

        //身份证
        String cardId = getPersonInfo.getUser().getIdCard().substring(0,2)+"************"+getPersonInfo.getUser().getIdCard().substring(14);
        mInfoCardTxt.setText(cardId);

        mInfoNickname.setHint(getPersonInfo.getUser().getNickName());

        //性别
        mInfoSex.setHint(getPersonInfo.getUser().getSex());



        //电话
        mInfoPhone.setHint(getPersonInfo.getUser().getPhonenumber());
    }

    //初始化
    public void initView(){
        mInfoHeadImg = (ImageView) findViewById(R.id.info_head_img);
        mInfoUsername = (TextView) findViewById(R.id.info_username);
        mInfoCardTitle = (TextView) findViewById(R.id.info_card_title);
        mInfoCardTxt = (TextView) findViewById(R.id.info_card_txt);
        mInfoNickname = (EditText) findViewById(R.id.info_nickname);
        mInfoSex = (EditText) findViewById(R.id.info_sex);
        mInfoPhone = (EditText) findViewById(R.id.info_phone);
        back = findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    //修改信息
    public void modifyInfo(View view) {
        modifyInfoData();
    }
}

activity_info.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.user.InfoActivity"
    android:orientation="vertical">
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="#00BCD4"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="20dp"
            android:background="@drawable/ic_back" />

        <TextView
            android:layout_width="280dp"
            android:layout_height="match_parent"
            android:text="个人信息"
            android:textSize="25dp"
            android:textColor="@color/white"
            android:gravity="center"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/info_head_img"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:background="@drawable/ic_head_img"
            android:layout_gravity="center"
            android:layout_marginTop="30dp"/>

        <TextView
            android:id="@+id/info_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="未登录"
            android:textSize="20dp"
            android:textAlignment="center"
            android:layout_marginTop="20dp"/>
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#3F51B5"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/info_card_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="身份证:"
            android:textSize="20dp"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="70dp"/>

        <TextView
            android:id="@+id/info_card_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_marginTop="8dp"
            android:layout_marginLeft="10dp"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="30dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="昵 称:"
            android:textSize="25dp"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="70dp"/>

        <EditText
            android:id="@+id/info_nickname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint=""
            android:background="@null"
            android:layout_marginTop="8dp"
            android:layout_marginLeft="10dp"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="性 别:"
            android:textSize="25dp"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="70dp"/>

        <EditText
            android:id="@+id/info_sex"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint=""
            android:background="@null"
            android:layout_marginTop="8dp"
            android:layout_marginLeft="10dp"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="10dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="电话号码:"
            android:textSize="25dp"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="70dp"/>

        <EditText
            android:id="@+id/info_phone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint=""
            android:background="@null"
            android:layout_marginTop="8dp"
            android:layout_marginLeft="10dp"/>
    </LinearLayout>

    <Button
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:text="修改信息"
        android:textSize="20dp"
        android:textColor="@color/white"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:background="#00BCD4"
        android:onClick="modifyInfo"/>


  </LinearLayout>

修改密码

ModifyPwdActivity.java

package com.example.smartcity.activity.user;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.smartcity.R;
import com.example.smartcity.info.MCallBack;
import com.example.smartcity.utils.CacheUtils;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static com.example.smartcity.utils.ConstantsUtils.IP;
import static com.example.smartcity.utils.ConstantsUtils.MODIFY_PWD;
import static com.example.smartcity.utils.ConstantsUtils.MODIFY_PWD_WHAT;
import static com.example.smartcity.utils.KeyUtils.TOKEN;
import static com.example.smartcity.utils.KeyUtils.USER_INFO;

public class ModifyPwdActivity extends AppCompatActivity {
    private ImageView mBack;
    private EditText mNewPwd;
    private EditText mOldPwd;
    private String token;

    Handler handler = new Handler(Looper.myLooper()){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case MODIFY_PWD_WHAT:
                    MCallBack mCallBack = (MCallBack) msg.obj;
                    if (mCallBack.getCode()==200){
                        Toast.makeText(ModifyPwdActivity.this,"修改成功!请重新登录",Toast.LENGTH_SHORT).show();
                        CacheUtils.clearString(ModifyPwdActivity.this,TOKEN);
                        CacheUtils.clearString(ModifyPwdActivity.this,USER_INFO);
                        Intent intent = new Intent(ModifyPwdActivity.this,LoginActivity.class);
                        startActivity(intent);
                    }
                    else {
                        Toast.makeText(ModifyPwdActivity.this,mCallBack.getMsg(),Toast.LENGTH_SHORT).show();
                    }
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modiy_pwd);
        initView();
    }

    public void initView(){
        mBack = (ImageView) findViewById(R.id.back);
        mNewPwd = (EditText) findViewById(R.id.new_pwd);
        mOldPwd = (EditText) findViewById(R.id.old_pwd);
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    //异步请求修改密码数据
    public void modifyPwdData(){
        String form = "{"+
                "\"newPassword\": \""+mNewPwd.getText().toString()+"\","+
                "\"oldPassword\": \""+mOldPwd.getText().toString()+"\""+
                "}";
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, form);
        Request request = new Request.Builder()
                .url(IP + MODIFY_PWD)
                .put(body)
                .addHeader("authorization", token)
                .addHeader("content-type", "application/json")
                .addHeader("cache-control", "no-cache")
                .addHeader("postman-token", "3464858b-4b35-2bd6-5b78-c5c81b6f302e")
                .build();
        new OkHttpClient().newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String modifyPwdDataStr = response.body().string();
                MCallBack mCallBack = new Gson().fromJson(modifyPwdDataStr, MCallBack.class);
                Message message = new Message();
                message.what = MODIFY_PWD_WHAT;
                message.obj = mCallBack;
                handler.sendMessage(message);
            }
        });
    }

    //修改密码
    public void modifyPwd(View view) {
        //获取token
        token = CacheUtils.getString(ModifyPwdActivity.this, TOKEN);
        if (!token.isEmpty()){
            modifyPwdData();
        }
    }
}

activity_modiy_pwd.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.user.ModifyPwdActivity"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="#00BCD4"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/back"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/ic_back"
            android:layout_gravity="center"
            android:layout_marginLeft="20dp"/>

        <TextView
            android:layout_width="280dp"
            android:layout_height="match_parent"
            android:text="设置密码"
            android:textSize="30dp"
            android:textColor="@color/white"
            android:gravity="center"/>
    </LinearLayout>


    <EditText
        android:id="@+id/new_pwd"
        android:layout_width="250dp"
        android:layout_height="50dp"
        android:background="@drawable/bg_login"
        android:hint="请输入新密码"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:layout_gravity="center"
        android:layout_marginTop="100dp"
        android:inputType="textPassword"/>

    <EditText
        android:id="@+id/old_pwd"
        android:layout_width="250dp"
        android:layout_height="50dp"
        android:background="@drawable/bg_login"
        android:hint="请输入旧密码"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:inputType="textPassword"/>

    <Button
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginTop="80dp"
        android:background="#00BCD4"
        android:onClick="modifyPwd"
        android:text="确  定"
        android:textColor="@color/white"
        android:textSize="20dp" />


</LinearLayout>

意见反馈

SuggestionActivity.java

package com.example.smartcity.activity.user;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.smartcity.R;
import com.example.smartcity.info.MCallBack;
import com.example.smartcity.utils.CacheUtils;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static com.example.smartcity.utils.ConstantsUtils.*;
import static com.example.smartcity.utils.KeyUtils.TOKEN;

public class SuggestionActivity extends AppCompatActivity {
    private ImageView mBack;
    private EditText mEdtSuggestion;
    private String token;

    Handler handler = new Handler(Looper.myLooper()){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case SUGGESTION_WHAT:
                    MCallBack mCallBack = (MCallBack) msg.obj;
                    if (mCallBack.getCode()==200){
                        Toast.makeText(SuggestionActivity.this,"提交成功!",Toast.LENGTH_SHORT).show();
                        mEdtSuggestion.setText("");
                    }
                    else {
                        Toast.makeText(SuggestionActivity.this,mCallBack.getMsg(),Toast.LENGTH_SHORT).show();
                    }
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_suggestion);
        initView();
    }

    //异步请求反馈数据
    public void suggestionData(){
        String form = "{\n" +
                "\"content\": \""+mEdtSuggestion.getText().toString()+"\",\n" +
                "\"title\": \"反馈内容\"\n" +
                "}";
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, form);
        Request request = new Request.Builder()
                .url(IP + SUGGESTION)
                .post(body)
                .addHeader("authorization", token)
                .addHeader("content-type", "application/json")
                .addHeader("cache-control", "no-cache")
                .addHeader("postman-token", "55d63e36-1045-9069-6761-26cfe7e5fc45")
                .build();
        new OkHttpClient().newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String suggestionDataStr = response.body().string();
                MCallBack mCallBack = new Gson().fromJson(suggestionDataStr, MCallBack.class);
                Message message = new Message();
                message.what = SUGGESTION_WHAT;
                message.obj = mCallBack;
                handler.sendMessage(message);
            }
        });
    }

    public void initView(){
        mBack = (ImageView) findViewById(R.id.back);
        mEdtSuggestion = (EditText) findViewById(R.id.edt_suggestion);
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    //提交反馈意见
    public void submit(View view) {
        token = CacheUtils.getString(SuggestionActivity.this, TOKEN);
        if (!token.isEmpty()){
            suggestionData();
        }
    }
}

activity_suggestion.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.user.SuggestionActivity"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="#00BCD4"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/back"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/ic_back"
            android:layout_gravity="center"
            android:layout_marginLeft="20dp"/>

        <TextView
            android:layout_width="280dp"
            android:layout_height="match_parent"
            android:text="意见反馈"
            android:textSize="30dp"
            android:textColor="@color/white"
            android:gravity="center"/>
    </LinearLayout>

    <EditText
        android:id="@+id/edt_suggestion"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:maxLength="150"
        android:hint="说说你想说的" />

    <Button
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_marginLeft="230dp"
        android:textColor="@color/white"
        android:text="提 交"
        android:background="#00BCD4"
        android:textSize="20dp"
        android:layout_marginTop="20dp"
        android:onClick="submit"/>

</LinearLayout>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

玛丽莲.梦露

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值