首页 > 其他分享 >每周总结--第一周

每周总结--第一周

时间:2023-06-09 18:55:36浏览次数:35  
标签:每周 -- void 第一周 id Intent import android public

在本周我接触了安卓的基础学习,并且通过自学完成了一个每日打卡app

每日打卡app源码

alarmActivity,java

package com.example.myapp01;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class alarmActivity extends AppCompatActivity {

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

Demo01.java

package com.example.myapp01;

import androidx.appcompat.app.AppCompatActivity;

import java.text.SimpleDateFormat;
import java.util.Date;

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 Demo01 extends AppCompatActivity {

    private Button Daka2;
    private EditText DakaContent;

    private MYsqliteopenhelper mYsqliteopenhelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo01);
        mYsqliteopenhelper = new MYsqliteopenhelper(this);
        find();
    }

    public void find(){
        Daka2 = findViewById(R.id.Daka2);
        DakaContent = findViewById(R.id.DaKaIn);
    }

    public void Daydaka(View view){
        String s = DakaContent.getText().toString();
        System.out.println(s);
        long l = mYsqliteopenhelper.DakeIn(s);
        if(l!=-1){
            Toast.makeText(this,"打卡成功",Toast.LENGTH_SHORT).show();
            Intent i3 = new Intent(this,good.class);
            startActivity(i3);
        }else{
            Toast.makeText(this,"打卡失败",Toast.LENGTH_SHORT).show();
        }

    }


}

demo02.java

package com.example.myapp01;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Demo02 extends AppCompatActivity {
    private Button chaxun;
    private TextView showcontent,showdate;

    private MYsqliteopenhelper mYsqliteopenhelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo02);
        mYsqliteopenhelper = new MYsqliteopenhelper(this);
        find();
    }
    public void find(){
        chaxun = findViewById(R.id.chaxun);
        showcontent = findViewById(R.id.tv_showcontent);
        showdate = findViewById(R.id.tv_showdate);

    }

    public void chaxun(View view){
        SQLiteDatabase db = mYsqliteopenhelper.get();
        showcontent.setText("打卡内容");
        showdate.setText("日期");
        Cursor cursor = db.rawQuery("select * from note",null);//查询所有数据
        while (cursor.moveToNext()) {
             @SuppressLint("Range") String content = cursor.getString(cursor.getColumnIndex("content"));//查询数据name
            @SuppressLint("Range") String date = cursor.getString(cursor.getColumnIndex("date"));//查询数据age
            showcontent.setText(showcontent.getText() + "\n" + content);//在一个textView显示所有查询到的数据一条加一个换号
            showdate.setText(showdate.getText()+"\n" + date);
        }
        cursor.close();
    }


}

good.java

package com.example.myapp01;

import androidx.appcompat.app.AppCompatActivity;

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

public class good extends AppCompatActivity implements View.OnClickListener{

    private Button DaKa,ChaXun,NaoZhong;


    private MYsqliteopenhelper mYsqliteopenhelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_good);
        mYsqliteopenhelper = new MYsqliteopenhelper(this);
        find();
    }

    private void find(){
        DaKa = findViewById(R.id.DaKa);
        DaKa.setOnClickListener(this);
        ChaXun = findViewById(R.id.chaxun);
        ChaXun.setOnClickListener(this);
        NaoZhong = findViewById(R.id.naozhong);
        NaoZhong.setOnClickListener(this);
    }
    public void onClick(View view){
        int id = view.getId();
        switch (id){
            case R.id.DaKa:
                Intent i =new Intent(this,Demo01.class);
                startActivity(i);
                break;
            case R.id.chaxun:
                Intent j = new Intent(this,Demo02.class);
                startActivity(j);
                break;
            case R.id.naozhong:
                Intent k = new Intent(this,TimeClock.class);
                startActivity(k);
                break;

        }
    }
}

MainActivity.java

package com.example.myapp01;

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;

import com.example.myapp01.javabean.User;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button login,register; //从xml中获得的两个按钮 登录和注册
private EditText name,password;  //从xml中获得的两个数据 name 和 password
private MYsqliteopenhelper mYsqliteopenhelper; //连接数据的对象

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mYsqliteopenhelper = new MYsqliteopenhelper(this);//创建功能类执行其中的登录和注册功能
        find();
    }

    private void find(){ //获得从xml中设置的各种按钮和数据
        login = findViewById(R.id.login);
        register = findViewById(R.id.register);
        name = findViewById(R.id.edname);
        password = findViewById(R.id.edpassword);
        login.setOnClickListener(this);
        register.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        switch (id){  //来分别设置两个按钮的功能
            case R.id.login:
                String s = name.getText().toString();   //获得xml中获得name值
                String s1 = password.getText().toString();  //获得xml中获得的password值v

                boolean login = mYsqliteopenhelper.login(s,s1); //调用MYsqliteopenhelper中写的登录功能
                if(login){
                    Toast.makeText(this,"登录成功",Toast.LENGTH_SHORT).show(); //给出登陆成功提示
                    Intent i = new Intent(this,good.class); //设置跳转
                    startActivity(i); //完成跳转
                }else{
                    Toast.makeText(this,"登录失败",Toast.LENGTH_SHORT).show(); //给出登陆失败提示
                }

                break;
            case R.id.register:
                Intent i1 = new Intent(this, com.example.myapp01.register.class);//直接跳转到注册界面
                startActivity(i1);
                break;
        }

    }


}

MYsqliteopenhelper.java

package com.example.myapp01;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.text.SimpleDateFormat;

import androidx.annotation.Nullable;

import com.example.myapp01.javabean.User;

import java.sql.SQLInput;
import java.util.Date;

public class MYsqliteopenhelper extends SQLiteOpenHelper {


    private static final String DB_NAME="db3";
    public static final String TABLE_NAME_NOTES = "note";
    public static final String COLUMN_NAME_ID = "_id";
    public static final String COLUMN_NAME_NOTE_CONTENT = "content";
    public static final String COLUMN_NAME_NOTE_DATE = "date";

    private static final String create_users = "create table users(name varchar(32),password varchar(32))";//sql语句
    private static final String create_note = "CREATE TABLE " + TABLE_NAME_NOTES + "(" + COLUMN_NAME_ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + COLUMN_NAME_NOTE_CONTENT + " TEXT NOT NULL DEFAULT\"\","
            + COLUMN_NAME_NOTE_DATE + " TEXT NOT NULL DEFAULT\"\"" + ")";
    public MYsqliteopenhelper(@Nullable Context context) {
        super(context, DB_NAME, null, 1);
    }
    //与数据库进行连接的具体代码

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(create_users);
        sqLiteDatabase.execSQL(create_note);
    }//调用sql语句来创建表

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
    public long register(User u){       //注册功能的实现 数据库方面
        SQLiteDatabase db = getWritableDatabase();//获得数据库连接
        ContentValues cv = new ContentValues();     //大概是个暂时储存数据的一个容器
        cv.put("name",u.getName());    //将name存进cv中
        cv.put("password",u.getPassword());   //将password存进cv中
        long users = db.insert("users",null,cv);  //从cv中取出数据并且放入数据库中
        return users;  //返回一个值 有值说明取出成功 否则失败 用于判断

    }

    public boolean login(String name,String password){  //登录功能的实现 数据库方面
        SQLiteDatabase db1 = getWritableDatabase();  //获得数据库的连接
        boolean result = false;  //创建一个boolean类型 以判断是否登录成功

        Cursor users = db1.query("users",null,"name like ?",new String[]{name},null,null,null);
        //获得账号的哪一行数据 用users存储
        if(users != null){ //如果 users不为空 就进行密码校对 否则直接返回false
            while(users.moveToNext()){ //进行密码校对
                String password1 = users.getString(1);
                result = password1.equals(password);
                return result;

            }

        }

        return false;
    }
    public long DakeIn(String content){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        Date curDate = new Date(System.currentTimeMillis());//获取当前时间
        String str  = formatter.format(curDate);
        SQLiteDatabase db = getWritableDatabase();
        ContentValues cv = new ContentValues();
        cv.put("content",content);
        cv.put("date",str);
        long flag = db.insert("note",null,cv);
        System.out.println(flag);
        return flag;
    }
    public SQLiteDatabase get(){
        SQLiteDatabase db = getWritableDatabase();
        return db;
    }





}

register.java

package com.example.myapp01;

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;

import com.example.myapp01.javabean.User;

public class register extends AppCompatActivity {

    private Button register1;
    private EditText name1,password1;
    private MYsqliteopenhelper mYsqliteopenhelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        mYsqliteopenhelper = new MYsqliteopenhelper(this);
        find();
    }
    private void find(){
        register1 = findViewById(R.id.register1);
        name1 = findViewById(R.id.edname1);
        password1 = findViewById(R.id.edpassword1);
    }
    public void zhuce(View view){
        String s = name1.getText().toString();
        String s1 = password1.getText().toString();
        User u =new User(s,s1);
        long l = mYsqliteopenhelper.register(u);
        if(l!=-1){
            Toast.makeText(this,"注册成功",Toast.LENGTH_SHORT).show();
            Intent i3 = new Intent(this,MainActivity.class);
            startActivity(i3);
        }else{
            Toast.makeText(this,"注册失败",Toast.LENGTH_SHORT).show();
        }
    }
}

TimeClock.java

package com.example.myapp01;

import androidx.appcompat.app.AppCompatActivity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
import android.widget.Toast;

import java.util.Calendar;
public class TimeClock extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_clock);
        final TimePicker timePicker=findViewById(R.id.time);  //获取时间拾取组件
        Button button=findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {   //给'设置闹钟'按钮设置监听
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(TimeClock.this,alarmActivity.class);
                PendingIntent pend=PendingIntent.getActivity(TimeClock.this,0,intent,0); //显示闹钟,alarmActivity
                AlarmManager alarm= (AlarmManager) getSystemService(Context.ALARM_SERVICE);       // 通过Context.ALARM_SERVICE获取AlarmManager对象
                Calendar calendar =Calendar.getInstance();                     //获取日历对象
                calendar.set(Calendar.HOUR_OF_DAY,timePicker.getHour());       //利用时间拾取组件timePicker得到要设定的时间
                calendar.set(Calendar.MINUTE,timePicker.getMinute());
                calendar.set(Calendar.SECOND,0);
                alarm.set(AlarmManager.RTC,calendar.getTimeInMillis(),pend);     //设定闹钟
                //AlarmManager.ELAPSED_REALTIME 在指定延迟后提醒
                //AlarmManager.ELAPSED_REALTIME_WAKEUP 在指定延迟后提醒,并唤醒系统
                //AlarmManager.RTC     在指定时间提醒
                //AlarmManager.RTC_WAKEUP    在指定时间提醒并唤醒系统
            }
        });
    }
}

activity_alarm.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".alarmActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

activity_demo01

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

    <TextView
        android:layout_width="400dp"
        android:layout_height="200dp"
        android:layout_weight="2"
        android:gravity="center"
        android:text="打卡内容"
        android:textSize="40dp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:layout_weight="4"
        android:id="@+id/DaKaIn"
        />

    <Button
        android:id="@+id/Daka2"
        android:layout_width="160dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        android:text="打卡"
        android:textSize="27dp"
        android:onClick="Daydaka"
        />


</LinearLayout>

 

标签:每周,--,void,第一周,id,Intent,import,android,public
From: https://www.cnblogs.com/sxwgzx23/p/17469883.html

相关文章

  • 每日打卡app
    项目介绍:项目背景:石家庄铁道大学软件工程系从本学期开始要求21级学生每日打卡总结,特委托石家庄铁道大学给力21软件有限公司进行开发。第一阶段目标:1、用户注册:用户注册信息包括用户ID(学号)、用户名(姓名),手机号码,用户单位(班级),用户班级四项基本信息,用户第一次注册后,用户姓名不用每......
  • Python 字典
    Dict数据类型一、创建一个字典>>>a={'name':'gm','age':18}>>>a{'age':18,'name':'gm'}二、查看字典#获取字典a的值>>>a{'age':18,'name':'gm'}#......
  • CAPL 按行读取 CSV 文件并切分字符串
    切分字符串首先CAPL中并没有内置的类似C中strtok的函数,有两种方法可以实现将strtok封装到CAPLDLL中,然后调用自己造个轮子,如下参考:https://blog.csdn.net/qq_34414530/article/details/121209670做了一些修改用于处理特殊的场景intspilt_string(charinput_strin......
  • SpringCloud中实现全局过滤器JWT校验
    思路图思路分析用户进入网关开始登陆,网关过滤器进行判断,如果是登录,则路由到后台管理微服务进行登录用户登录成功,后台管理微服务签发JWTTOKEN信息返回给用户用户再次进入网关开始访问,网关过滤器接收用户携带的TOKEN网关过滤器解析TOKEN,判断是否有权限,如果有,则放行,如果没有......
  • 常用的内置模块
    time模块在python中,通常有三种方式来表示时间:1.时间戳:秒数,浮点型2.结构化时间(struct_time)3.格式化的时间字符串(FormatString)时间戳是计算机能识别的时间,我们看不懂python中时间日期格式化符号%Y:表示四位数的年份(000-9999)%y:表示两位数的年份(00-99)%m:表示月份(1......
  • 图文详解丨iOS App上架全流程及审核避坑指南
    到了2021年,虽然网上也有大牛写过很多IOSApp上架流程资料,但随着苹果发布机制的微调有些已经过时了。我就趁着这次刚刚发布成功的鲜活经验,记录下来,做一下补充。1、首先得注册AppleDeveloper的开发者账号,最后如果要上架苹果商店,这个账号是要交年费的,核算下来大概600多元人民币。......
  • 备份mysql全量数据库为sql文件
    进入数据库bin目录,cmd运行mysqldump-utest-ptest--all-databases>all.sql 备注            -u后面接用户名 -p后面接密码  “>”是方向,这里指从左到右 备份结果:cmd命令行无提示错误即可, 备份结束的SQL文件才会显示文件大小,之前不显示......
  • Navicat、SQLyog第一次连接mysql8.0 1251错误
    引入:第一次连接mysql数据库时,报错1251代码错误,这是因为mysql8.0版本的加密规则是mysql_native_password,而在mysql8.0版本之后,加密规则是caching_sha2_password.解决首先,打开cmd命令行,按照一下步骤修改加密规则。连接上MYSQL数据库​ mysql-uroot-p.修改加密规则......
  • spring-boot-data Redis 使用
    spring-boot-dataredisSpringBoot提供了Redis集成启动器(Starter),依赖于spring-data-redis和lettuce库。spring-data-redis:对Reids底层开发包高度封装,让开发者对Redis的CRUD操作起来更加方便。创建工程导入相关依赖<dependency><groupId......
  • 图文详解丨iOS App上架全流程及审核避坑指南
    图文详解丨iOSApp上架全流程及审核避坑指南到了2021年,虽然网上也有大牛写过很多IOSApp上架流程资料,但随着苹果发布机制的微调有些已经过时了。我就趁着这次刚刚发布成功的鲜活经验,记录下来,做一下补充。1、首先得注册AppleDeveloper的开发者账号,最后如果要上架苹果商店,这个账......