Android Studio 抽卡小游戏

https://download.csdn.net/download/weixin_45609946/86405765

Hello 大家好,此项目是我学习Android时完成的大作业。

首先我来介绍一下此项目,此项目功能包括

实现登录注册

Android Studio 抽卡小游戏_第1张图片

实现开屏动画

Android Studio 抽卡小游戏_第2张图片

卡牌抽取跳转展示,震动反馈,视频播放,背景音乐,页面跳转

计时器,颜色选取,画板,笔刷粗细调节

Android Studio 抽卡小游戏_第3张图片

SQL数据库,数据储存,读取,删除

Android Studio 抽卡小游戏_第4张图片Android Studio 抽卡小游戏_第5张图片

流程展示

Android Studio 抽卡小游戏_第6张图片

  部分源码分享

首先分享的是MySQL数据库代码

package com.example.myapplication;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class Mysql extends SQLiteOpenHelper {
    public Mysql(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table logins(id integer primary key autoincrement,usname text,uspwd text)";
        db.execSQL(sql);
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

2.注册数据源码

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.myapplication.MainActivity;

public class Register extends AppCompatActivity {
    EditText usename,usepwd,usepwd2;
    Button submit;
    Mysql mysql;
    SQLiteDatabase db;
    SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        usename = this.findViewById(R.id.usename);			    //用户名编辑框
        usepwd =  this.findViewById(R.id.usepwd);				//设置初始密码编辑框
        usepwd2 = this.findViewById(R.id.usepwd2);			    //二次输入密码编辑框
        submit =   this.findViewById(R.id.submit);				//注册按钮
        mysql = new Mysql(this,"Userinfo",null,1);      //建数据库
        db = mysql.getReadableDatabase();
        sp = this.getSharedPreferences("useinfo",this.MODE_PRIVATE);
        submit.setOnClickListener(new View.OnClickListener() {
            boolean flag = true;            //判断用户是否已存在的标志位
            @Override
            public void onClick(View v) {

                String name = usename.getText().toString();				//用户名
                String pwd01 = usepwd.getText().toString();				//密码
                String pwd02 = usepwd2.getText().toString();			//二次输入的密码
                //性别
                if(name.equals("")||pwd01 .equals("")||pwd02.equals("")){
                    Toast.makeText(Register.this, "用户名或密码不能为空!!", Toast.LENGTH_LONG).show();
                }
                else{
                    Cursor cursor = db.query("logins",new String[]{"usname"},null,
                            null,null,null,null);

                    while (cursor.moveToNext()){
                        if(cursor.getString(0).equals(name)){
                            flag = false;
                            break;
                        }
                    }
                    if(flag==true){                                             //判断用户是否已存在
                        if (pwd01.equals(pwd02)) {								//判断两次输入的密码是否一致,若一致则继续,不一致则提醒密码不一致
                            ContentValues cv = new ContentValues();
                            cv.put("usname",name);
                            cv.put("uspwd",pwd01);
                            db.insert("logins",null,cv);
                            SharedPreferences.Editor editor = sp.edit();
                            editor.putString("usname",name);
                            editor.putString("uspwd",pwd01);
                            editor.commit();
                            Intent intent = new Intent();
                            intent.setClass(Register.this, MainActivity.class);      //跳转到登录页面
                            startActivity(intent);
                            Toast.makeText(Register.this, "注册成功!", Toast.LENGTH_LONG).show();
                        }
                        else {
                            Toast.makeText(Register.this, "密码不一致!", Toast.LENGTH_LONG).show();			//提示密码不一致
                        }
                    }
                    else{
                        Toast.makeText(Register.this, "用户已存在!", Toast.LENGTH_LONG).show();			//提示密码不一致
                    }

                }
            }
        });
    }
}

 3.登录界面

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity9 extends AppCompatActivity implements View.OnClickListener {
    EditText name, pwd;
    Button btnlogin, btnreg;
    Mysql mysql;
    SQLiteDatabase db;
    SharedPreferences sp1, sp2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main9);
        name = this.findViewById(R.id.name);            //用户名输入框
        pwd = this.findViewById(R.id.pwd);              //密码输入框
        btnlogin = this.findViewById(R.id.login);         //登录按钮
        btnreg = this.findViewById(R.id.reg);               //注册按钮
        sp1 = this.getSharedPreferences("useinfo", this.MODE_PRIVATE);
        sp2 = this.getSharedPreferences("username", this.MODE_PRIVATE);
        name.setText(sp1.getString("usname", null));
        pwd.setText(sp1.getString("uspwd", null));
        mysql = new Mysql(this, "Userinfo", null, 1);//建数据库或者取数据库
        db = mysql.getReadableDatabase();
        btnlogin.setOnClickListener(this);
        btnreg.setOnClickListener(this);
        //登录事件
    }

    @Override
    public void onClick(View v) {
        if ((v.getId() == R.id.reg))
        {
            Intent z = new Intent(this, Register.class);
            startActivity(z);
            Toast.makeText(MainActivity9.this,"前往注册!",Toast.LENGTH_SHORT).show();
        }
        if ((v.getId() == R.id.login))
        {
            String username = name.getText().toString();
            String password = pwd.getText().toString();                 //获取用户输入的用户名和密码
            //查询用户名和密码相同的数据
            Cursor cursor = db.query("logins",new String[]{"usname","uspwd"},
                    " usname=? and uspwd=?",new String[]{username,password},null,null,null);
            int flag = cursor.getCount();                            //查询出来的记录项的条数,若没有该用户则为0条
            if(flag!=0){                                            //若查询出的记录不为0,则进行跳转操作
                //设置页面跳转
                SharedPreferences.Editor editor = sp2.edit();
                cursor.moveToFirst();                                   //将光标移动到position为0的位置,默认位置为-1
                String loginname = cursor.getString(0);
                editor.putString("Loginname",loginname);
                editor.commit();                                        //将用户名存到SharedPreferences中
                Intent x = new Intent(this, MainActivity10.class);
                startActivity(x);
            }
            else{
                Toast.makeText(MainActivity9.this,"用户名或密码错误!",Toast.LENGTH_LONG).show();//提示用户信息错误或没有账号
            }
        }
    }
}

4.  开屏动画源码

package com.example.myapplication;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import android.os.Bundle;
import android.widget.TextView;

import com.example.myapplication.MainActivity;

public class MainActivity10 extends AppCompatActivity {
    private ImageView welcomeImg = null;
    private SharedPreferences sp;
    private  TextView showhello;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main10);//

        ActionBar actionBar = getSupportActionBar();//消除APP该Activity界面标题栏
        if(actionBar!=null){ //消除APP该Activity界面标题栏
            actionBar.hide(); //消除APP该Activity界面标题栏
        } //消除APP该Activity界面标题栏
        welcomeImg = (ImageView) findViewById(R.id.imageView4);
        AlphaAnimation anima = new AlphaAnimation(0.3f, 1.0f);
        anima.setDuration(3000);// 设置简单动画的显示时间
        welcomeImg.startAnimation(anima);
        anima.setAnimationListener(new AnimationImpl());
        sp = this.getSharedPreferences("username", this.MODE_PRIVATE);  //获取sharepreferences
        showhello = this.findViewById(R.id.textView);           //显示欢迎
        showhello.setText("欢迎光临:"+sp.getString("Loginname",""));     //获取用户名

    }
    private class AnimationImpl implements AnimationListener {
        @Override
        public void onAnimationStart(Animation animation) {
            welcomeImg.setBackgroundResource(R.drawable.gjok);
        }
        @Override
        public void onAnimationEnd(Animation animation) {
            skip(); // 动画结束后跳转到别的页面
        }
        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    }
    private void skip() {
        startActivity(new Intent(this, MainActivity.class));//动画开屏后返回APP主界面
        finish(); //结束动画Activity进程
    }
}

5.主界面 

package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.ThemedSpinnerAdapter;

import java.util.Random;
public class MainActivity extends AppCompatActivity implements MediaPlayer.OnCompletionListener
        ,CompoundButton. OnCheckedChangeListener {
    private ImageView TP1, TP2, TP3;
    private Button BTN_START, BTN_FINISH,btr,btr1,btr2;
    private TextView RESULT;
    private CheckBox chk;
    static  boolean isPlay=true;
    private MyDatabaseHelper dbHelper;
    private int[] img = {R.drawable.z2, R.drawable.z3, R.drawable.z1};
    private MediaPlayer mper2;
    private MediaPlayer mper3;
    private MediaPlayer mper6;
    private MediaPlayer mper8;
    int HUIYE,QIANHUAN,GUJIAN,ANY,t;
    private Random a = new Random();//随机数
    private int b, c, d;
    private Handler handler= new Handler();
    private Runnable runnable=new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            //要做的事情
            b = a.nextInt(3);
            c = a.nextInt(3);
            d = a.nextInt(3);
            TP1.setImageResource(img[b]);//放置随机图片
            TP2.setImageResource(img[c]);
            TP3.setImageResource(img[d]);
            handler.postDelayed(this, 20);
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        show();

        dbHelper = new MyDatabaseHelper(this,"BooKStore.db",null,2);
        SQLiteDatabase db = dbHelper.getReadableDatabase();


        mper2 = MediaPlayer.create(this,R.raw.any1);
        mper2.setOnCompletionListener(this);
        mper2.setLooping(false);

        mper3 = MediaPlayer.create(this,R.raw.hy1);
        mper3.setOnCompletionListener(this);
        mper3.setLooping(false);



        mper6 = MediaPlayer.create(this,R.raw.gjzc);
        mper6.setOnCompletionListener(this);
        mper6.setLooping(false);

        PlayMusic();
        Intent z=new Intent(this, MainActivity2.class);
        Intent x=new Intent(this, MainActivity3.class);
        Intent v=new Intent(this, MainActivity4.class);
        Intent q=new Intent(this, MainActivity5.class);
        Intent w=new Intent(this, MainActivity6.class);
        Intent e=new Intent(this, MainActivity7.class);
        Intent r=new Intent(this, MainActivity8.class);
        Intent p=new Intent(this, MainActivity11.class);
        Intent ooo=new Intent(this, MainActivity12.class);
        Intent jjj=new Intent(this, MainActivity13.class);
        BTN_START.setOnClickListener(new View.OnClickListener() { //开始按钮监听事件
            @Override
            public void onClick(View view) {
                handler.postDelayed(runnable, 20);//定时器启动
                Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                long[] pattern1 = {10,10};
                vibrator.vibrate(pattern1, 0);
                t=t+5;
            }
        });
        BTN_FINISH.setOnClickListener(new View.OnClickListener() { //结束按钮监听事件
            @Override
            public void onClick(View view) {
                handler.removeCallbacks(runnable);//定时器结束
                if (img[b] == img[c] && img[b] == img[d] && img[c] == img[d] )
                {
                    if(img[b]==img[0]){
                        RESULT.setText("阿尼亚:哇库瓦库");
                        ANY=ANY+3;
                        ContentValues values=new ContentValues();
                        values.put("ANY",ANY);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(x);
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                    else if(img[b]==img[1]){
                        RESULT.setText("古见同学想和你做朋友");
                        GUJIAN=GUJIAN+3;
                        ContentValues values=new ContentValues();
                        values.put("GJTX",GUJIAN);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(v);
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                    else if(img[b]==img[2]){
                        RESULT.setText("辉夜好可爱哟耶耶耶");
                        HUIYE=HUIYE+3;
                        ContentValues values=new ContentValues();
                        values.put("HYDXJ",HUIYE);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(q);
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                }
                else
                if (img[b] == img[c]) {
                    if(img[b]==img[0]){
                        RESULT.setText("阿尼亚想去游乐园");
                        ANY=ANY+2;
                        ContentValues values=new ContentValues();
                        values.put("ANY",ANY);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(w);
                        mper2.start();
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();

                    }
                    if(img[b]==img[1]){
                        RESULT.setText("古见同学对你说:加油");
                        GUJIAN=GUJIAN+2;
                        ContentValues values=new ContentValues();
                        values.put("GJTX",GUJIAN);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(e);
                        mper6.start();
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                    if(img[b]==img[2]){
                        RESULT.setText("辉夜大小姐居然有替身???");
                        HUIYE=HUIYE+2;
                        ContentValues values=new ContentValues();
                        values.put("HYDXJ",HUIYE);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(r);
                        mper3.start();
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                }
                else
                if (img[b] == img[d]) {
                    if (img[b] == img[0]) {
                        RESULT.setText("阿尼亚想去游乐园");
                        ANY=ANY+2;
                        ContentValues values=new ContentValues();
                        values.put("ANY",ANY);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(w);
                        mper2.start();
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                    if (img[b] == img[1]) {
                        RESULT.setText("古见同学对你说:加油");
                        GUJIAN=GUJIAN+2;
                        ContentValues values=new ContentValues();
                        values.put("GJTX",GUJIAN);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(e);
                        mper6.start();
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                    if (img[b] == img[2]) {
                        RESULT.setText("辉夜大小姐居然有替身???");
                        HUIYE=HUIYE+2;
                        ContentValues values=new ContentValues();
                        values.put("HYDXJ",HUIYE);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(r);
                        mper3.start();
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                }
                else
                if (img[c] == img[d]) {
                    if (img[c] == img[0]) {
                        RESULT.setText("阿尼亚想去游乐园");
                        ANY=ANY+2;
                        ContentValues values=new ContentValues();
                        values.put("ANY",ANY);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(w);
                        mper2.start();
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                    if (img[c] == img[1]) {
                        RESULT.setText("古见同学对你说:加油");
                        GUJIAN=GUJIAN+2;
                        ContentValues values=new ContentValues();
                        values.put("GJTX",GUJIAN);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(e);
                        mper6.start();
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                    if (img[c] == img[2]) {
                        RESULT.setText("辉夜大小姐居然有替身???");
                        mper3.start();
                        HUIYE=HUIYE+2;
                        ContentValues values=new ContentValues();
                        values.put("HYDXJ",HUIYE);
                        db.insert("Book",null,values);
                        values.clear();
                        startActivity(r);
                        Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                        vibrator.cancel();
                    }
                }
                else {
                    RESULT.setText("千花:真拿你没办法呢");
                    QIANHUAN=QIANHUAN+3;
                    ContentValues values=new ContentValues();
                    values.put("QIANHUA",QIANHUAN);
                    db.insert("Book",null,values);
                    values.clear();
                    startActivity(z);
                    Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                    vibrator.cancel();
                }
                if(QIANHUAN>=1||GUJIAN>=1||ANY>=1||HUIYE>=1) {
                    btr1.setOnClickListener(new View.OnClickListener() { //开始按钮监听事件
                        @Override
                        public void onClick(View view) {
                            startActivity(jjj);
                        }
                    });
                }
            }
        });
      btr.setOnClickListener(new View.OnClickListener() { //开始按钮监听事件
           @Override
           public void onClick(View view) { startActivity(p);
          }
        });
               btr1.setOnClickListener(new View.OnClickListener(){ //开始按钮监听事件
                  @Override
                   public void onClick(View view) {
                  }
               });
        btr2.setOnClickListener(new View.OnClickListener(){ //开始按钮监听事件
            @Override
            public void onClick(View view) {
                startActivity(ooo);
            }
        });
    }
    private void show() {
        TP1 = findViewById(R.id.tp1);
        TP2 = findViewById(R.id.tp2);
        TP3 = findViewById(R.id.tp3);
        BTN_START = findViewById(R.id.btn_start);
        BTN_FINISH = findViewById(R.id.btn_finish);
        btr = findViewById(R.id.button8);
        btr1 =findViewById(R.id.button11);
        btr2 =findViewById(R.id.button13);
        RESULT = findViewById(R.id.result);
        chk=findViewById(R.id.checkBox);
        chk = findViewById(R.id.checkBox);
        chk.setOnCheckedChangeListener(this);
    }
    @Override
    public void onCompletion(MediaPlayer mediaPlayer) {
    }
    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (chk.isChecked()) {
           mper8.pause();
            }
            else{
                mper8.start();
            }
    }
    protected void onStop()
    {
        super.onStop();
        if(mper8!=null)
        {
            mper8.stop();
        }
    }
    protected void onDestroy()
    {
        super.onDestroy();
        if(mper8!=null)
        {
            mper8.stop();
            mper8.release();
            mper8=null;
        }
    }

    protected void onRestart()
    {super.onRestart();
        if(isPlay=true);
        {
           PlayMusic();
        }
    }

    private void PlayMusic() {
        mper8 = MediaPlayer.create(this,R.raw.bjyy);
        mper8.setOnCompletionListener(this);
        mper8.setLooping(true);
        mper8.start();
    }
}

6.抽卡存放数据库

package com.example.myapplication;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;


public class MyDatabaseHelper extends SQLiteOpenHelper {
    public static final String CREATE_BOOK ="Create table book("
            +"id integer Primary key autoincrement,"
            +"ANY real," +"QIANHUA real," +"GJTX real," +"HYDXJ real)";
    public static final String CREATE_CATEGORY ="Create table Category("
            +"id integer Primary key autoincrement,"
            +"Category_name text,"
            +"category_code text)";
    private Context mContext;
    //必须要有context才能对数据库进行操作
//name数据库名
//返回一个自定义的Cursor 一般传入null
//当前数据库的版本号 可以对数据库进行操作
    public MyDatabaseHelper( Context context,  String name,  SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_BOOK);
        db.execSQL(CREATE_CATEGORY);
        Toast.makeText(mContext,"success",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists Book");
        db.execSQL("drop table if exists Categeory");
        onCreate(db);
    }
}

 7.跳转页面

package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity2 extends AppCompatActivity implements View.OnClickListener{
    private VideoView videoView;
    private MediaController mediaController;
    private Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
         videoView = findViewById(R.id.QHSJ);
          mediaController = new MediaController(this);
          String uri = "android.resource://" + getPackageName() + "/" + R.raw.qhsp;
         videoView.setVideoURI(Uri.parse(uri));
           videoView.setMediaController(mediaController);
           mediaController.setMediaPlayer(videoView);
          videoView.start();
            btn=findViewById(R.id.button);
            btn.setOnClickListener(this);
        }
    @Override
    public void onClick(View view) {
        finish();
    }
}

8. 收集卡片

package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity12 extends AppCompatActivity implements View.OnClickListener {
    private MyDatabaseHelper dbHelper;
    private TextView QH,HY,GJ,AY;
    private Button btr12,btr14;
    private ImageButton gj,any,hy,qh;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main12);
        dbHelper = new MyDatabaseHelper(this,"BooKStore.db",null,2);
        QH = findViewById(R.id.QH);
        HY = findViewById(R.id.HY);
        GJ = findViewById(R.id.GJ);
        AY = findViewById(R.id.AY);
        AY.setText("");
        QH.setText("");
        HY.setText("");
        GJ.setText("");
        btr12 =findViewById(R.id.button12);
        btr14 =findViewById(R.id.button14);
        gj = findViewById(R.id.gjaj);
        gj.setOnClickListener(this);
        any = findViewById(R.id.anyaj);
        any.setOnClickListener(this);
        hy = findViewById(R.id.hyaj);
        hy.setOnClickListener(this);
        qh = findViewById(R.id.qhaj);
        qh.setOnClickListener(this);
        btr12.setOnClickListener(this);
        btr14.setOnClickListener(this);
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        Cursor cursor = db.query("Book",null,null,null,null,null,null);
        if(cursor.moveToFirst())
        {
            do{
                @SuppressLint("Range") int ANY = cursor.getInt(cursor.getColumnIndex("ANY"));
                @SuppressLint("Range") int GJTX = cursor.getInt(cursor.getColumnIndex("GJTX"));
                @SuppressLint("Range") int QIANHUA = cursor.getInt(cursor.getColumnIndex("QIANHUA"));
                @SuppressLint("Range") int HYDXJ = cursor.getInt(cursor.getColumnIndex("HYDXJ"));

                if(ANY>0)AY.setText(""+ANY);
                if(QIANHUA>0)QH.setText(""+QIANHUA);
                if(HYDXJ>0)HY.setText(""+HYDXJ);
                if(GJTX>0)GJ.setText(""+GJTX);
            }while (cursor.moveToNext());
        }
    }
    @Override
    public void onClick(View v) {
        if ((v.getId() == R.id.button12)) {
            SQLiteDatabase db = dbHelper.getReadableDatabase();
            ContentValues values = new ContentValues();
            values.put("ANY", 0);
            values.put("GJTX", 0);
            values.put("QIANHUA", 0);
            values.put("HYDXJ", 0);
            db.update("Book", values, null, null);
            Cursor cursor = db.query("Book", null, null, null, null, null, null);
            if (cursor.moveToFirst()) {
                do {
                    @SuppressLint("Range") int ANY = cursor.getInt(cursor.getColumnIndex("ANY"));
                    @SuppressLint("Range") int GJTX = cursor.getInt(cursor.getColumnIndex("GJTX"));
                    @SuppressLint("Range") int QIANHUA = cursor.getInt(cursor.getColumnIndex("QIANHUA"));
                    @SuppressLint("Range") int HYDXJ = cursor.getInt(cursor.getColumnIndex("HYDXJ"));
                    AY.setText("" + ANY);
                    QH.setText("" + QIANHUA);
                    HY.setText("" + HYDXJ);
                    GJ.setText("" + GJTX);
                } while (cursor.moveToNext());
            }
        }
        if ((v.getId() == R.id.button14))
        {
            finish();
        }
        if ((v.getId() == R.id.gjaj))
        {
            Intent t=new Intent(this, MainActivity4.class);
            startActivity(t);
        }
        if ((v.getId() == R.id.anyaj))

        {
            Intent x=new Intent(this, MainActivity3.class);
            startActivity(x);
        }
        if ((v.getId() == R.id.hyaj))
        {
            Intent q=new Intent(this, MainActivity5.class);
            startActivity(q);
        }
        if ((v.getId() == R.id.qhaj))
        {
            Intent z=new Intent(this, MainActivity2.class);
            startActivity(z);
        }
    }
}

9. 隐藏模式 

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity13 extends AppCompatActivity {
    private TextView QH,HY,GJ,AY;
    private Button btr14;
    int i;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main13);
        QH = findViewById(R.id.QIANHUA);
        HY = findViewById(R.id.HUIYE);
        GJ = findViewById(R.id.GUJIAN);
        AY = findViewById(R.id.ANY);
        btr14=findViewById(R.id.button14);
        btr14.setOnClickListener(new View.OnClickListener(){ //开始按钮监听事件
            @Override
            public void onClick(View view) {
                i+=1;
                if (i==1) {
                    GJ.setText("我每周四都更新哦,大家不要忘记来看啦");
                }
                if (i==2)
                {
                    AY.setText("阿尼亚周六更新哦");

                }
                if (i==3)
                {
                    HY.setText("我也是周六更新哦");

                }
                if (i==4)
                {
                    QH.setText("啊,我和辉夜是在一起哒大家一定要来哦");
                }
                if (i==5)
                {
                    GJ.setText("哎,不知道HYF大人会不会来呢");
                }
                if (i==6)
                {
                    AY.setText("阿尼亚最喜欢HYF哥哥啦");
                }
                if (i==7)
                {
                    HY.setText("Σ(っ °Д °;)っ,HYF大人会来看么!");
                }
                if (i==8)
                {
                    QH.setText("辉夜你不要社长了嘛");
                }
                if (i==9)
                {
                    HY.setText("咳咳,好吧,大家不要错过我们更新就好了,一定要来看哦");
                }
            }
        });
        btr14.setOnLongClickListener(new View.OnLongClickListener(){ //开始按钮监听事件
            @Override
            public boolean onLongClick(View view) {
finish();
return true;
            }
            });



    }

}

10.你画我猜

package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.os.Vibrator;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.TextView;

import java.util.Random;
public class MainActivity11 extends AppCompatActivity{
    Paint paint;
    Canvas canvas;
    ImageView imageview;
    Bitmap bitmap;
    TextView tv_stroke,XIANS;
    Chronometer ch;
    int startX, startY, endX, endY;
    private Random a = new Random();//随机数
    private int b;
    int i=0;
    private Handler handler= new Handler();
    private Runnable runnable=new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            b = a.nextInt(4);
            handler.postDelayed(this, 20);
            if (b==0){
                XIANS.setText("辉夜大小姐");
            }
            if (b==1){
                XIANS.setText("藤原千花");
            }
            if (b==2){
                XIANS.setText("古见同学");
            }
            if (b==3){
                XIANS.setText("阿尼亚");
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main11);
        tv_stroke = findViewById(R.id.tv_stroke);
        XIANS = findViewById(R.id.WENTI);
        LinearLayout ll_layout = findViewById(R.id.ll_layout);
        RadioGroup rg_color = findViewById(R.id.rg_color);
        ch=findViewById(R.id.JSQ);
        ch.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
            @Override
            public void onChronometerTick(Chronometer chronometer) {
                if(SystemClock.elapsedRealtime()-ch.getBase()>=10000){
                    ch.stop();
                    Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                    long[] pattern1 = {100,100,100};
                    vibrator.vibrate(pattern1, 0);
                }
            }
        });
        // 循环遍历单选按钮
        for (int i = 0;i

你可能感兴趣的:(项目学习,android,studio,android-studio,android,sql,算法)