10/13


package com.example.app6;

import android.Manifest;
import android.content.SharedPreferences;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main2Activity extends AppCompatActivity {
    private EditText yonghuming;
    private EditText mima;
    private CheckBox jizhumima;
    private Button dianjidenglu;

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

        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 110);


        yonghuming = (EditText) findViewById(R.id.yonghuming);
        mima = (EditText) findViewById(R.id.mima);
        jizhumima = (CheckBox) findViewById(R.id.jizhumima);
        dianjidenglu = (Button) findViewById(R.id.dianjidenglu);
        SharedPreferences sp = getSharedPreferences("login", MODE_PRIVATE);
        String yhm = sp.getString("yhm", "");
        String mm = sp.getString("mm", "");
        boolean jzmm = sp.getBoolean("jzmm", false);
        if (jzmm) {
            jizhumima.setChecked(true);
        } else {
            jizhumima.setChecked(false);
        }
        yonghuming.setText(yhm);
        mima.setText(mm);
    }

    public void denglu(View view) {
        File externalStorageDirectory = Environment.getExternalStorageDirectory();
        File file = new File(externalStorageDirectory, "two.txt");
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
//            Toast.makeText(this, ""+yonghuming.getText().toString(), Toast.LENGTH_SHORT).show();
            fileOutputStream.write(yonghuming.getText().toString().getBytes());

        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            FileInputStream fileInputStream = new FileInputStream(file);

            int len;
            byte[] b = new byte[1024];
            while ((len = fileInputStream.read(b))!=-1) {
                String s = new String(b, 0, len);
                Toast.makeText(this, ""+s, Toast.LENGTH_SHORT).show();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        if (jizhumima.isChecked()) {

            String s = yonghuming.getText().toString();
            String s1 = mima.getText().toString();
            SharedPreferences sp = getSharedPreferences("login", MODE_PRIVATE);
            SharedPreferences.Editor edit = sp.edit();
            edit.putString("yhm", s);
            edit.putString("mm", s1);
            edit.putBoolean("jzmm", true);
            edit.commit();
        } else {
            SharedPreferences sp = getSharedPreferences("login", MODE_PRIVATE);
            SharedPreferences.Editor edit = sp.edit();
            edit.putString("yhm", "");
            edit.putString("mm", "");
            edit.putBoolean("jzmm", false);
            edit.commit();

        }
    }
}


package com.example.app6;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {
    private TabLayout tab;
    private ViewPager vp;
    private List<Fragment> lists = new ArrayList<>();
    private List<String> listss = new ArrayList<>();
    private int index=5;
    private int yeshu=0;
    private TextView daojishi;
    @SuppressLint("HandlerLeak")
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what==1){
                daojishi.setText("倒计时"+index+"秒");
                index--;
                if (index==0){

                    finish();
                    Intent intent = new Intent(MainActivity.this,Main2Activity.class);
                    startActivity(intent);

                }
            }else if(msg.what==200){
                vp.setCurrentItem(yeshu);
                yeshu++;
            }
        }
    };

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

        tab = (TabLayout) findViewById(R.id.tab);
        vp = (ViewPager) findViewById(R.id.vp);


        daojishi = (TextView) findViewById(R.id.daojishi);

        for (int i = 0; i < 10; i++) {
            lists.add(new BlankFragment());


            listss.add("第" + i + "页");
        }
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(200);
            }
        },0,1000);
        tab.setupWithViewPager(vp);
        vp.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int i) {
                return lists.get(i);
            }

            @Override
            public int getCount() {
                return lists.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {



                return listss.get(position);

            }
        });
        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                timer.cancel();
                if (i==lists.size()-1){
                    Toast.makeText(MainActivity.this, "最大页数", Toast.LENGTH_SHORT).show();
                    daojishi.setVisibility(View.VISIBLE);
                    Timer timer = new Timer();
                    timer.schedule(new TimerTask() {
                        @Override
                        public void run() {
                            handler.sendEmptyMessage(1);
                        }
                    },0,1000);

                }

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">

    <android.support.design.widget.TabLayout
        android:id="@+id/tab"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        app:tabMode="scrollable">

    </android.support.design.widget.TabLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:layout_marginTop="50dp">


    </android.support.v4.view.ViewPager>

    <TextView
        android:visibility="gone"
        android:id="@+id/daojishi"
        android:layout_marginLeft="330dp"
        android:layout_marginTop="50dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="一个倒计时" />

</RelativeLayout>
<?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=".Main2Activity">

    <EditText
        android:id="@+id/yonghuming"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入用户名" />

    <EditText
        android:id="@+id/mima"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入密码" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp">

        <CheckBox
            android:id="@+id/jizhumima"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="记住密码" />

        <Button
            android:onClick="denglu"
            android:id="@+id/dianjidenglu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="点击登陆" />
    </LinearLayout>
</LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值