登录注册+webview

public class Yhdlzc extends AppCompatActivity implements View.OnClickListener{
    private EditText ed_mima;
    private EditText ed_sjh;
    private Button but_dl;
    private Button but_zc;
    private String mima;
    private String sjh;
    private String num="[1][358]\\d{9}";
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yhdlzc);
        ed_sjh = (EditText) findViewById(R.id.edshoujihao);
        ed_mima = (EditText) findViewById(R.id.edmima);
        but_dl= (Button) findViewById(R.id.butdl);
        but_zc= (Button) findViewById(R.id.butzc);

        but_dl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mima = ed_mima.getText().toString().trim();
                    sjh = ed_sjh.getText().toString().trim();
                    boolean flag=checkData(mima,sjh);
                    if(flag){
                        register(mima,sjh);
                    }else{
                        Toast.makeText(Yhdlzc.this,"手机不合法",Toast.LENGTH_LONG).show();
                    }
                }
            });
            but_zc.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(Yhdlzc.this, Zhuce.class);
                    startActivity(intent);
                }
            });
    }

    private void register(String mima, String sjh) {
        final RequestParams params=new RequestParams("http://120.27.23.105/user/login");
        params.addQueryStringParameter("mobile",sjh);
        params.addQueryStringParameter("password",mima);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                LoginBean bean = gson.fromJson(result, LoginBean.class);
                Toast.makeText(Yhdlzc.this,bean.getMsg(),Toast.LENGTH_SHORT).show();
                if(bean.getCode().equals("0")){
                    Toast.makeText(Yhdlzc.this,"好了",Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });

    }

    private boolean checkData(String mima, String sjh) {
        if(TextUtils.isEmpty(sjh)||TextUtils.isEmpty(mima)){
            Toast.makeText(Yhdlzc.this,"手机号和密码不能为空",Toast.LENGTH_LONG).show();
            return false;
        }else if(mima.length()<6){
            Toast.makeText(Yhdlzc.this,"密码不能小于6位",Toast.LENGTH_LONG).show();
            return false;
        }else{
            return sjh.matches(num);
        }
    }

    @Override
    public void onClick(View view) {

    }
}
注册
public class Zhuce extends AppCompatActivity {

    private String sjh;
    private String mm;
    private Button butzhuce;
    private EditText zcsjh;
    private EditText zcmima;
    private String num="[1][358]\\d{9}";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhuce);

        butzhuce = (Button) findViewById(R.id.butzhuce);
        zcsjh = (EditText) findViewById(R.id.edzhucesjh);
        zcmima = (EditText) findViewById(R.id.edzhucemima);
        sjh= zcsjh.getText().toString();
        mm= zcmima.getText().toString();

        butzhuce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sjh= zcsjh.getText().toString();
                mm= zcmima.getText().toString();
                boolean a=checkData(sjh,mm);
                if(a==true){
                    Toast.makeText(Zhuce.this,"可以",Toast.LENGTH_LONG).show();
                    regfster(sjh,mm);
                }else{
                    Toast.makeText(Zhuce.this,"手机不合法",Toast.LENGTH_LONG).show();
                }
            }
        });

    }

    private void regfster(String sjh, String mm) {
        RequestParams params = new RequestParams("http://120.27.23.105/user/reg");
        params.addBodyParameter("mobile",sjh);
        params.addBodyParameter("password",mm);
        x.http().get(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                RegistBean bean = gson.fromJson(result, RegistBean.class);
                Toast.makeText(Zhuce.this,bean.getMsg(),Toast.LENGTH_SHORT).show();
                if(bean.getCode().equals("0")){
                    finish();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    private boolean checkData(String sjh, String mm) {
        if(TextUtils.isEmpty(sjh)||TextUtils.isEmpty(mm)){
            Toast.makeText(this,"手机号和密码不能为空",Toast.LENGTH_LONG).show();
            return false;
        } else if(mm.length()<6){
            Toast.makeText(this,"密码不能小于6位",Toast.LENGTH_LONG).show();
            return false;
        }else {
            return sjh.matches(num);
        }

    }
}

webview
public class Xiangqing extends AppCompatActivity {

    private WebView xqweb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiangqing);
        Intent intent = getIntent();

        String s = intent.getStringExtra("name");
        xqweb = (WebView) findViewById(R.id.xq_web);
// 缩放至屏幕的大小
        xqweb.getSettings().setLoadWithOverviewMode(true);
        //webVew去加载网页
        xqweb.loadUrl(s);

        //设置用自己的浏览器打开
        xqweb.setWebViewClient(new MyWebViewClient());
    }

    class MyWebViewClient extends WebViewClient {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);

            return super.shouldOverrideUrlLoading(view, url);
        }



    }

}

<WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/xq_web"></WebView>

 





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值