ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

引导页+ipport+登录+注册卡哇伊伊伊的娃

2021-12-22 09:34:05  阅读:117  来源: 互联网

标签:ipport Toast 卡哇伊 伊伊 new import android btn public


引导页

java

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.test1218.banner.GBData;
import com.example.test1218.fengzhuang.Okhehe;
import com.google.gson.Gson;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;
import com.youth.banner.loader.ImageLoaderInterface;

import java.util.ArrayList;
import java.util.List;

public class Yindaoye extends AppCompatActivity {
    Banner banner;
    Okhehe hehe;
    List<String> l1 = new ArrayList<>();
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yindaoye);
        banner = findViewById(R.id.yindao_banner);
        btn = findViewById(R.id.yindao_btn);
        hehe = Okhehe.getInstance();
        String ydy=getSharedPreferences("Myshujv",MODE_PRIVATE).getString("ydy","");
        if (ydy.equals("y")){
            startActivity(new Intent(Yindaoye.this, IpPort.class));
            finish();
        }
        getSharedPreferences("Myshujv",MODE_PRIVATE).edit()
                .putString("ydy","y").commit();
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(Yindaoye.this, IpPort.class));
                finish();
            }
        });
        String url = "http://124.93.196.45:10001/prod-api/api/rotation/list?type=1";
        hehe.GetString(url, new Okhehe.FuncString() {
            @Override
            public void onResponse(String js) {
                GBData gb = new Gson().fromJson(js, GBData.class);
                l1.clear();
                for (int i = 0; i < gb.getRows().size(); i++) {
                    l1.add("http://124.93.196.45:10001" + gb.getRows().get(i).getAdvImg());
                }
                banner.setImages(l1)
                        .setImageLoader(new MyImgLoader())
                        .isAutoPlay(false)

                        .setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                            @Override
                            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                            }

                            @Override
                            public void onPageSelected(int position) {
                                if (l1.size() - 1 == position) {
                                    btn.setVisibility(View.VISIBLE);
                                } else {
                                    btn.setVisibility(View.GONE);
                                }
                            }

                            @Override
                            public void onPageScrollStateChanged(int state) {

                            }
                        });banner.start();

            }
        });


    }

    public class MyImgLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object o, ImageView imageView) {
            Glide.with(context).load(o).into(imageView);
        }
    }
}

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.youth.banner.Banner
        android:id="@+id/yindao_banner"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:image_scale_type="fit_xy" />

    <Button
        android:visibility="gone"
        android:textSize="18sp"
        android:text="网络设置"
        android:textColor="@color/white"
        android:id="@+id/yindao_btn"
        android:background="@drawable/btn_touming"
        android:layout_marginBottom="40dp"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_width="200dp"
        android:layout_height="50sp"/>

</RelativeLayout>

IpPort

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.EditText;
import android.widget.Toast;

public class IpPort extends AppCompatActivity {
EditText e1,e2;
Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ip_port);
        e1=findViewById(R.id.ip_ip);
        e2=findViewById(R.id.ip_port);
        btn=findViewById(R.id.ip_btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String ip=e1.getText().toString();
                String port=e2.getText().toString();
                if (ip.isEmpty()){
                    Toast.makeText(IpPort.this,"IP地址不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }else  if (port.isEmpty()){
                    Toast.makeText(IpPort.this,"端口号不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                getSharedPreferences("Myshujv",MODE_PRIVATE).edit()
                        .putString("qianzhui","http://"+ip+":"+port)
                        .commit();
                startActivity(new Intent(IpPort.this,Login.class));
            }
        });
    }
}

XML

<?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="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_marginTop="14dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="网 络 设 置"
        android:textColor="@color/blue"
        android:textSize="70sp" />

    <EditText
        android:id="@+id/ip_ip"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:layout_marginRight="14dp"
        android:background="@drawable/edit"
        android:hint="IP地址如:124.93.196.45"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:singleLine="true" />

    <EditText
        android:id="@+id/ip_port"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:layout_marginRight="14dp"
        android:background="@drawable/edit"
        android:hint="端口号如:10001"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:singleLine="true" />
    <Button
        android:id="@+id/ip_btn"
        android:textSize="19sp"
        android:text="立即体验"
        android:textColor="@color/white"
        android:layout_margin="14dp"
        android:background="@drawable/btn_lanse"
        android:layout_width="match_parent"
        android:layout_height="40dp"/>


</LinearLayout>

Login

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.test1218.fengzhuang.Okhehe;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class Login extends AppCompatActivity {
    Okhehe hehe;
    String qianzhui;
    EditText e1,e2;
    Button btn;
    TextView login_reg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        hehe=Okhehe.getInstance();
        qianzhui=getSharedPreferences("Myshujv",MODE_PRIVATE)
                .getString("qianzhui","");
        e1=findViewById(R.id.login_uname);
        e2=findViewById(R.id.login_upsw);
        login_reg=findViewById(R.id.login_reg);
        login_reg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(Login.this,Reg.class));
            }
        });
        btn=findViewById(R.id.login_btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String uname=e1.getText().toString();
                String upsw=e2.getText().toString();
                if (uname.isEmpty()){
                    Toast.makeText(Login.this,"用户名不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }else  if (upsw.isEmpty()){
                    Toast.makeText(Login.this,"密码不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                String url=qianzhui+"/prod-api/api/login";
                Map map=new HashMap();
                map.put("username",uname);
                map.put("password",upsw);
                hehe.PostJSONObejct(url, map, new Okhehe.FuncJSONObejct() {
                    @Override
                    public void onResponse(JSONObject jo) {
                        if (jo.optString("code").equals("200")){
                            Toast.makeText(Login.this,"登陆成功",Toast.LENGTH_SHORT).show();
                            getSharedPreferences("Myshujv",MODE_PRIVATE).edit()
                                    .putString("token",jo.optString("token"))
                                    .commit();
                            startActivity(new Intent(Login.this,MainActivity.class));
                            Login.this.finish();
                        }else {
                            Toast.makeText(Login.this,jo.optString("msg"),Toast.LENGTH_SHORT).show();
                        }
                    }
                });

            }
        });
    }
}

XML

<?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="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_marginTop="14dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="智 慧 城 市"
        android:textColor="@color/blue"
        android:textSize="70sp" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="T H E S M A R T C I T Y"
        android:textColor="@color/blue"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/login_uname"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:layout_marginRight="14dp"
        android:background="@drawable/edit"
        android:hint="请输入用户名"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:singleLine="true" />

    <EditText
        android:id="@+id/login_upsw"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:layout_marginRight="14dp"
        android:background="@drawable/edit"
        android:hint="请输入密码"
        android:inputType="textPassword"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:singleLine="true" />
    <Button
        android:id="@+id/login_btn"
        android:textSize="19sp"
        android:text="立即登录"
        android:textColor="@color/white"
        android:layout_margin="14dp"
        android:background="@drawable/btn_lanse"
        android:layout_width="match_parent"
        android:layout_height="40dp"/>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/login_reg"
        android:text="暂无账号,立即注册"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="14dp"
        android:textColor="@color/blue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</RelativeLayout>

</LinearLayout>

Register

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.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.test1218.fengzhuang.Okhehe;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class Reg extends AppCompatActivity {
    EditText e1, e2, e3, e4;
    Button btn;
    RadioGroup rdg;
    TextView reg_login;
    Okhehe hehe;
    String qianzhui;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reg);
        hehe = Okhehe.getInstance();
        qianzhui = getSharedPreferences("Myshujv", MODE_PRIVATE)
                .getString("qianzhui", "");
        reg_login = findViewById(R.id.reg_login);
        reg_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Reg.this.finish();
            }
        });
        e1 = findViewById(R.id.reg_uname);
        e2 = findViewById(R.id.reg_upsw);
        e3 = findViewById(R.id.reg_reupsw);
        e4 = findViewById(R.id.reg_tel);
        rdg = findViewById(R.id.reg_rdg);
        btn = findViewById(R.id.reg_btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String uname = e1.getText().toString();
                String upsw = e2.getText().toString();
                String reupsw = e3.getText().toString();
                String tel = e4.getText().toString();
                RadioButton rdb=findViewById(rdg.getCheckedRadioButtonId());
                if (uname.isEmpty()) {
                    Toast.makeText(Reg.this, "用户名不能为空", Toast.LENGTH_SHORT).show();
                    return;
                } else if (upsw.isEmpty()) {
                    Toast.makeText(Reg.this, "密码不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }else if (reupsw.isEmpty()){
                    Toast.makeText(Reg.this, "确认密码不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }else if (!upsw.equals(reupsw)) {
                    Toast.makeText(Reg.this, "两次密码输入不一致", Toast.LENGTH_SHORT).show();
                    return;
                }else if (tel.isEmpty()){
                    Toast.makeText(Reg.this, "电话号码不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }else if (rdb==null){
                    Toast.makeText(Reg.this, "请选择性别", Toast.LENGTH_SHORT).show();
                    return;
                }
                String url = qianzhui + "/prod-api/api/register";
                Map sex_map=new HashMap();
                sex_map.put("男","0");
                sex_map.put("女","1");
                String sex= String.valueOf(sex_map.get(rdb.getText().toString()));
                Map map = new HashMap();
                map.put("userName", uname);
                map.put("password", upsw);
                map.put("phonenumber",tel);
                map.put("sex",sex);
                hehe.PostJSONObejct(url, map, new Okhehe.FuncJSONObejct() {
                    @Override
                    public void onResponse(JSONObject jo) {
                        if (jo.optString("code").equals("200")) {
                            Toast.makeText(Reg.this, "注册成功", Toast.LENGTH_SHORT).show();
                            startActivity(new Intent(Reg.this, Login.class));
                            Reg.this.finish();
                        } else {
                            Toast.makeText(Reg.this, jo.optString("msg"), Toast.LENGTH_SHORT).show();
                        }
                    }
                });

            }
        });

    }
}

XML

<?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="match_parent"
    android:orientation="vertical">

    <EditText
        android:id="@+id/reg_uname"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:layout_marginRight="14dp"
        android:background="@drawable/edit"
        android:hint="请输入用户名"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:singleLine="true" />

    <EditText
        android:id="@+id/reg_upsw"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:layout_marginRight="14dp"
        android:background="@drawable/edit"
        android:hint="请输入密码"
        android:inputType="textPassword"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:singleLine="true" />
    <EditText
        android:id="@+id/reg_reupsw"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:layout_marginRight="14dp"
        android:background="@drawable/edit"
        android:hint="请输入确认密码"
        android:inputType="textPassword"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:singleLine="true" />

    <EditText
        android:id="@+id/reg_tel"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:layout_marginRight="14dp"
        android:background="@drawable/edit"
        android:hint="请输入手机号"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:singleLine="true" />
    <RadioGroup
        android:id="@+id/reg_rdg"
        android:layout_marginRight="14dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <RadioButton
            android:text="女"
            android:textSize="18sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <RadioButton
            android:text="男"
            android:textSize="18sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </RadioGroup>

    <Button
        android:id="@+id/reg_btn"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_margin="14dp"
        android:background="@drawable/btn_lanse"
        android:text="立即注册"
        android:textColor="@color/white"
        android:textSize="19sp" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/reg_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="14dp"
            android:text="已有账号,立即登录"
            android:textColor="@color/blue" />
    </RelativeLayout>

</LinearLayout>

标签:ipport,Toast,卡哇伊,伊伊,new,import,android,btn,public
来源: https://blog.csdn.net/m0_52585811/article/details/122077648

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有