Android登陆注册
目录
主页.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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<ImageView
android:layout_marginTop="30dp"
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/imageView"
android:background="#F1F1F1"
/>
<TextView
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="账号名"
/>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="个人信息"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="订单列表"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="修改密码"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="意见反馈"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
app:cardCornerRadius="30dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
app:cardBackgroundColor="#EFEFEF"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:text="退出"
android:gravity="center"
/>
</androidx.cardview.widget.CardView>
</LinearLayout>
主页.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import com.example.smartcity.gerenzhongxing.denglu.DengLu;
import com.example.smartcity.gerenzhongxing.gerenxingxi.DingDangLieBiao;
import com.example.smartcity.gerenzhongxing.gerenxingxi.FangKuiXingXi;
import com.example.smartcity.gerenzhongxing.gerenxingxi.GeRenXingXi;
import com.example.smartcity.gerenzhongxing.gerenxingxi.XiuGaiMiMa;
import com.example.smartcity.gerenzhongxing.gerenxingxi.XiuGaiXingXi;
import org.json.JSONException;
import org.json.JSONObject;
public class GeRenZhongXing extends Fragment implements View.OnClickListener {
TextView textView1,textView,textView2,textView3,textView4,textView5;
ImageView imageView;
View view;
String token="";
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
view= LayoutInflater.from(getContext()).inflate(R.layout.xinwen,null,false);
SharedPreferences sharedPreferences=getActivity().getSharedPreferences("name",0);
token=sharedPreferences.getString("token","");
textView=view.findViewById(R.id.textView);
textView1=view.findViewById(R.id.textView1);
textView2=view.findViewById(R.id.textView2);
textView3=view.findViewById(R.id.textView3);
textView4=view.findViewById(R.id.textView4);
textView5=view.findViewById(R.id.textView5);
imageView=view.findViewById(R.id.imageView);
textView.setOnClickListener(this);
imageView.setOnClickListener(this);
textView1.setOnClickListener(this);
textView2.setOnClickListener(this);
textView3.setOnClickListener(this);
textView4.setOnClickListener(this);
textView5.setOnClickListener(this);
// 获取数据
huoqushuju();
return view;
}
private void huoqushuju() {
if (!token.equals("")){
new Thread(new Runnable() {
@Override
public void run() {
try {
String data=new GongJuLei().getHuoquGeRenXingXi(token);
JSONObject jsonObject=new JSONObject(data);
JSONObject jsonObject1=jsonObject.getJSONObject("user");
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
textView.setText("账号名:"+jsonObject1.getString("userName"));
Glide.with(getContext()).load(url).into(imageView);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.imageView:
if (token.equals("")){
startActivity(new Intent(getContext(), DengLu.class));
}
break;
case R.id.textView:
if (token.equals("")){
startActivity(new Intent(getContext(), DengLu.class));
}
break;
case R.id.textView1:
if (token.equals("")){
startActivity(new Intent(getContext(), DengLu.class));
}else {
startActivity(new Intent(getContext(), GeRenXingXi.class));
}
break;
case R.id.textView2:
if (token.equals("")){
startActivity(new Intent(getContext(), DengLu.class));
}else {
startActivity(new Intent(getContext(), DingDangLieBiao.class));
}
break;
case R.id.textView3:
if (token.equals("")){
startActivity(new Intent(getContext(), DengLu.class));
}else {
startActivity(new Intent(getContext(), XiuGaiMiMa.class));
}
break;
case R.id.textView4:
if (token.equals("")){
startActivity(new Intent(getContext(), DengLu.class));
}else {
startActivity(new Intent(getContext(), FangKuiXingXi.class));
}
break;
case R.id.textView5:
startActivity(new Intent(getContext(), DengLu.class));
break;
}
}
}
登陆.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=".gerenzhongxing.denglu.DengLu"
android:orientation="vertical"
android:gravity="right"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:text="登陆"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:hint="请输入账号"
android:singleLine="true"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:hint="请输入密码"
android:singleLine="true"
android:inputType="textPassword"
/>
<TextView
android:id="@+id/textView"
android:padding="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="注册账号"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="登陆"
/>
</LinearLayout>
</LinearLayout>
登陆.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import com.example.smartcity.daohanglang.DaoHangLang;
import org.json.JSONException;
import org.json.JSONObject;
public class DengLu extends AppCompatActivity {
EditText editText1,editText2;
Button button;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deng_lu);
editText1=findViewById(R.id.editText1);
editText2=findViewById(R.id.editText2);
button=findViewById(R.id.button);
textView=findViewById(R.id.textView);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(DengLu.this,ZhuChe.class));
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!editText1.getText().equals("")&&!editText2.getText().equals("")){
// 获取数据
new Thread(new Runnable() {
@Override
public void run() {
try {
String data=new GongJuLei().getDengLu(editText1.getText().toString().trim(),editText2.getText().toString().trim());
JSONObject jsonObject=new JSONObject(data);
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (jsonObject.getString("msg").equals("操作成功")){
SharedPreferences sharedPreferences=getSharedPreferences("name",0);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString("token",jsonObject.getString("token"));
editor.commit();
startActivity(new Intent(DengLu.this, DaoHangLang.class));
finish();
}
Toast.makeText(DengLu.this,jsonObject.getString("msg") +"", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}else {
Toast.makeText(DengLu.this, "数据未填写完整", Toast.LENGTH_SHORT).show();
}
}
});
}
}
注册.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=".gerenzhongxing.denglu.DengLu"
android:orientation="vertical"
android:gravity="right"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="注册"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:hint="请输入账号名"
android:singleLine="true"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:hint="请输入手机号"
android:singleLine="true"
android:inputType="textPassword"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText3"
android:hint="请输入密码"
android:singleLine="true"
android:inputType="textPassword"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText4"
android:hint="请重复密码"
android:singleLine="true"
android:inputType="textPassword"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="注册"
/>
</LinearLayout>
</LinearLayout>
注册.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class ZhuChe extends AppCompatActivity {
TextView textView;
Button button;
EditText editText1,editText2,editText3,editText4;
String xinbie="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zhu_che);
textView=findViewById(R.id.textView);
button=findViewById(R.id.button);
editText1=findViewById(R.id.editText1);
editText2=findViewById(R.id.editText2);
editText3=findViewById(R.id.editText3);
editText4=findViewById(R.id.editText4);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
try {
String data=new GongJuLei().getZhuChe(editText1.getText().toString(),editText2.getText().toString(),editText3.getText().toString(),xinbie);
JSONObject jsonObject=new JSONObject(data);
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (jsonObject.getString("msg").equals("操作成功")){
finish();
}
Toast.makeText(ZhuChe.this, jsonObject.getString("msg")+"", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}
});
}
}
个人信息.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"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".gerenzhongxing.gerenxingxi.GeRenXingXi">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="个人信息"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<ImageView
android:background="#F5F5F5"
android:layout_marginTop="20dp"
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/imageView"
/>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
<TextView
android:id="@+id/textView1"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="昵称:"
/>
<TextView
android:id="@+id/textView2"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="邮箱号:"
/>
<TextView
android:id="@+id/textView3"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="电话号码:"
/>
<TextView
android:id="@+id/textView4"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="性别:"
/>
<TextView
android:id="@+id/textView5"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="身份证号码:"
/>
<TextView
android:id="@+id/textView6"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="余额:"
/>
<TextView
android:id="@+id/textView7"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#F2F2F2"
android:padding="10dp"
android:layout_height="wrap_content">
<TextView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="积分:"
/>
<TextView
android:id="@+id/textView8"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="账号名:"
/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="修改"
android:id="@+id/button"
/>
</LinearLayout>
个人信息.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class GeRenXingXi extends AppCompatActivity {
TextView textView,textView1,textView2,textView3,textView4,
textView5,textView6,textView7,textView8;
ImageView imageView;
String token="";
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ge_ren_xing_xi);
token=getSharedPreferences("name",0).getString("token","");
textView=findViewById(R.id.textView);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
imageView=findViewById(R.id.imageView);
textView1=findViewById(R.id.textView1);
textView2=findViewById(R.id.textView2);
textView3=findViewById(R.id.textView3);
textView4=findViewById(R.id.textView4);
textView5=findViewById(R.id.textView5);
textView6=findViewById(R.id.textView6);
textView7=findViewById(R.id.textView7);
textView8=findViewById(R.id.textView8);
button=findViewById(R.id.button) ;
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(GeRenXingXi.this,XiuGaiXingXi.class));
}
});
// 获取数据
new Thread(new Runnable() {
@Override
public void run() {
try {
String data=new GongJuLei().getHuoquGeRenXingXi(token);
JSONObject jsonObject=new JSONObject(data);
JSONObject jsonObject1=jsonObject.getJSONObject("user");
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Glide.with(GeRenXingXi.this).load(url).into(imageView);
textView1.setText(jsonObject1.getString("userName"));
textView2.setText(jsonObject1.getString("nickName"));
textView3.setText(jsonObject1.getString("email"));
textView4.setText(jsonObject1.getString("phonenumber"));
if (jsonObject1.getString("sex").equals("0")){
textView5.setText("男");
}else {
textView5.setText("女");
}
StringBuffer stringBuffer=new StringBuffer(jsonObject1.getString("idCard"));
stringBuffer.replace(2,14,"***");
textView6.setText(stringBuffer);
textView7.setText(jsonObject1.getString("balance"));
textView8.setText(jsonObject1.getString("score"));
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}
}
修改个人信息.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"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".gerenzhongxing.gerenxingxi.XiuGaiXingXi">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="修改信息"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<EditText
android:id="@+id/editText1"
android:hint="请输入昵称"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/editText2"
android:hint="请输入电话号码"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/editText3"
android:hint="请输入身份证号码"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RadioGroup
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:id="@+id/radioGroup"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton1"
android:text="男"
/>
<RadioButton
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton2"
android:text="女"
/>
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="修改"
/>
</LinearLayout>
修改个人信息.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class XiuGaiXingXi extends AppCompatActivity {
TextView textView;
Button button;
EditText editText1,editText2,editText3;
RadioGroup radioGroup;
String token="",xinbie="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xiu_gai_xing_xi);
textView=findViewById(R.id.textView);
button=findViewById(R.id.button);
editText1=findViewById(R.id.editText1);
editText2=findViewById(R.id.editText2);
editText3=findViewById(R.id.editText3);
radioGroup=findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i) {
case R.id.radioButton1:
xinbie="0";
break;
case R.id.radioButton2:
xinbie="1";
break;
}
}
});
token=getSharedPreferences("name",0).getString("token","");
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!editText1.getText().toString().trim().equals("")&&
!editText2.getText().toString().trim().equals("")&&
!editText3.getText().toString().trim().equals("")&&
!xinbie.equals("")
){
if (editText2.length()==11){
if (editText3.length()==18){
new Thread(new Runnable() {
@Override
public void run() {
try {
String data=new GongJuLei().getXiuGaiXingXi(token,
editText1.getText().toString().trim(),
editText2.getText().toString().trim(),
editText3.getText().toString().trim(),xinbie);
JSONObject jsonObject=new JSONObject(data);
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (jsonObject.getString("msg").equals("操作成功")){
finish();
}
Toast.makeText(XiuGaiXingXi.this, jsonObject.getString("msg")+"", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}else {
Toast.makeText(XiuGaiXingXi.this, "请输入18位身份证号码", Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(XiuGaiXingXi.this, "请输入11位电话号码", Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(XiuGaiXingXi.this, "请输入完整", Toast.LENGTH_SHORT).show();
}
}
});
}
}
修改密码.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"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".gerenzhongxing.gerenxingxi.XiuGaiMiMa">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="修改密码"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:hint="请输入旧密码"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:hint="请输入新密码"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText3"
android:hint="请重复密码"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="修改"
/>
</LinearLayout>
修改密码.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class XiuGaiMiMa extends AppCompatActivity {
TextView textView;
EditText editText1,editText2,editText3;
Button button;
String token="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xiu_gai_mi_ma);
token=getSharedPreferences("name",0).getString("token","");
textView=findViewById(R.id.textView);
editText1=findViewById(R.id.editText1);
editText2=findViewById(R.id.editText2);
editText3=findViewById(R.id.editText3);
button=findViewById(R.id.button);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (editText2.getText().toString().trim().equals(editText3.getText().toString().trim())){
new Thread(new Runnable() {
@Override
public void run() {
try {
String data=new GongJuLei().getXiuGaiMiMa(token,editText1.getText().toString().trim(),editText2.getText().toString().trim());
JSONObject jsonObject=new JSONObject(data);
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (!editText1.getText().toString().trim().equals("")&&!editText2.getText().toString().trim().equals("")){
if (jsonObject.getString("msg").equals("操作成功")){
finish();
}
Toast.makeText(XiuGaiMiMa.this, jsonObject.getString("msg")+"", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(XiuGaiMiMa.this, "未填写完整", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}else {
Toast.makeText(XiuGaiMiMa.this, "新密码不一致", Toast.LENGTH_SHORT).show();
}
}
});
}
}
意见反馈.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"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".gerenzhongxing.gerenxingxi.FangKuiXingXi">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="反馈信息"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_margin="20dp"
android:background="#fff"
app:cardCornerRadius="30dp"
app:cardBackgroundColor="#EEEEEE"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:background="@null"
android:id="@+id/editText"
android:hint="请输入反馈信息"
android:gravity="left"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:maxLength="150"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="还剩150个字可以输入"
android:id="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="30dp"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="提交"
/>
</LinearLayout>
意见反馈.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONException;
import org.json.JSONObject;
public class FangKuiXingXi extends AppCompatActivity {
TextView textView,textView1;
EditText editText;
Button button;
String token="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fang_kui_xing_xi);
token=getSharedPreferences("name",0).getString("token","");
textView=findViewById(R.id.textView);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
textView1=findViewById(R.id.textView1);
editText=findViewById(R.id.editText);
button=findViewById(R.id.button );
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
textView1.setText("还剩"+(150-editText.length())+"个字可以输入");
if (editText.length()==150){
Toast.makeText(FangKuiXingXi.this, "不可以输入了", Toast.LENGTH_SHORT).show();
}
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!editText.getText().toString().trim().equals("")){
new Thread(new Runnable() {
@Override
public void run() {
try {
String data=new GongJuLei().getFangKuiXingXi(token,editText.getText().toString().trim());
JSONObject jsonObject=new JSONObject(data );
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (jsonObject.getString("msg").equals("操作成功")){
finish();
}
Toast.makeText(FangKuiXingXi.this, jsonObject.getString("msg")+"", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}else {
Toast.makeText(FangKuiXingXi.this, "未填写", Toast.LENGTH_SHORT).show();
}
}
});
}
}
订单列表.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"
android:orientation="vertical"
tools:context=".gerenzhongxing.gerenxingxi.DingDangLieBiao">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="返回"
android:padding="10dp"
/>
<TextView
android:text="订单列表"
android:gravity="center"
android:textSize="30dp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView1"
android:layout_weight="1"
android:gravity="center"
android:layout_width="0dp"
android:text="订单编号"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/textView2"
android:layout_weight="1"
android:gravity="center"
android:layout_width="0dp"
android:text="订单类型"
android:layout_height="wrap_content"/>
<TextView
android:text="电影院名"
android:id="@+id/textView3"
android:layout_weight="1"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerView"
/>
</LinearLayout>
订单列表.构造
public class DingDangGozhao {
String id,bianhao,leixing,time;
public DingDangGozhao(String id, String bianhao, String leixing, String time) {
this.id = id;
this.bianhao = bianhao;
this.leixing = leixing;
this.time = time;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getBianhao() {
return bianhao;
}
public void setBianhao(String bianhao) {
this.bianhao = bianhao;
}
public String getLeixing() {
return leixing;
}
public void setLeixing(String leixing) {
this.leixing = leixing;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
订单适配器
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.smartcity.R;
import java.util.List;
public class DingDangAdapter extends RecyclerView.Adapter<DingDangAdapter.ViewHolder> {
List<DingDangGozhao> list;
Context context;
public DingDangAdapter(List<DingDangGozhao> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.dingdan,parent,false));
}
@Override
public void onBindViewHolder(DingDangAdapter.ViewHolder holder, int position) {
holder.textView1.setText(list.get(position).getBianhao());
holder.textView2.setText(list.get(position).getLeixing());
holder.textView3.setText(list.get(position).getTime());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(context,DingDangXiangQing.class);
intent.putExtra("id",list.get(position).getId());
((Activity)context).startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return list.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView textView1,textView2,textView3;
public ViewHolder(View itemView) {
super(itemView);
textView1=itemView.findViewById(R.id.textView1);
textView2=itemView.findViewById(R.id.textView2);
textView3=itemView.findViewById(R.id.textView3);
}
}
}
适配器里面的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
>
<TextView
android:id="@+id/textView1"
android:layout_weight="1"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/textView2"
android:layout_weight="1"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/textView3"
android:layout_weight="1"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</LinearLayout>
订单列表.java
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.smartcity.GongJuLei;
import com.example.smartcity.R;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class DingDangLieBiao extends AppCompatActivity {
TextView textView;
RecyclerView recyclerView;
List<DingDangGozhao> list=new ArrayList<>();
String token="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ding_dang_lie_biao);
token=getSharedPreferences("name",0).getString("token","");
textView=findViewById(R.id.textView);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
recyclerView=findViewById(R.id.recyclerView);
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
recyclerView.setLayoutManager( linearLayoutManager);
new Thread(new Runnable() {
@Override
public void run() {
try {
String data=new GongJuLei().getDingDang(token);
JSONObject jsonObject=new JSONObject(data);
JSONArray jsonArray=jsonObject.getJSONArray("rows");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1=jsonArray.getJSONObject(i);
DingDangGozhao gozhao=new DingDangGozhao(jsonObject1.getInt("id")+"",
jsonObject1.getString("orderNo"),
jsonObject1.getString("orderType"),
jsonObject1.getString("name"));
list.add(gozhao);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
DingDangAdapter adapter=new DingDangAdapter(list,DingDangLieBiao.this);
recyclerView.setAdapter(adapter);
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}
}
工具类,GongJuLei.java
import android.text.Editable;
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class GongJuLei {
public String getDengLu(String username, String password) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{rn"username":""+username+"",rn"password":""+password+""rn}");
Request request = new Request.Builder()
.url(url)
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
public String getZhuChe(String username,String phone, String password,String xinbie) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{rn"userName": ""+username+"",rn"password": ""+password+"",rn"phonenumber": ""+phone+"",rn"sex": ""+xinbie+""rn}");
Request request = new Request.Builder()
.url(url)
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
public String getHuoquGeRenXingXi(String token) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url(url)
.method("GET", null)
.addHeader("Authorization", token)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
public String getXiuGaiXingXi(String token,String name,String phone,String shengfengzheng,String xinbie) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{rn"idCard": ""+shengfengzheng+"",rn"nickName": ""+name+"",rn"phonenumber": ""+phone+"",rn"sex": ""+xinbie+""rn}");
Request request = new Request.Builder()
.url(url)
.method("PUT", body)
.addHeader("Authorization", token)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
public String getXiuGaiMiMa(String token,String jiumima,String xinmima) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{rn"newPassword": ""+xinmima+"",rn"oldPassword": ""+jiumima+""rn}");
Request request = new Request.Builder()
.url(url)
.method("PUT", body)
.addHeader("Authorization", token)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
public String getFangKuiXingXi(String token,String content) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{rn"content": ""+content+""rn}");
Request request = new Request.Builder()
.url(url)
.method("POST", body)
.addHeader("Authorization", token)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
public String getDingDang(String token) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url(url)
.method("GET", null)
.addHeader("Authorization", token)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
}
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
二维码