冲刺day1

今天开始冲刺了,每天完成一部分代码,如何粘贴进来

先写界面代码:

AboutActivity.java

package timeline.lizimumu.com.t.ui;

import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;

import java.util.Locale;

import timeline.lizimumu.com.t.BuildConfig;
import timeline.lizimumu.com.t.R;

public class AboutActivity extends AppCompatActivity {

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

        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setTitle(R.string.about);
        }

        ((TextView) findViewById(R.id.version)).setText(
                String.format(Locale.getDefault(),
                        getResources().getString(R.string.version), BuildConfig.VERSION_NAME));
    }
}

AlarmActivity.java

package timeline.lizimumu.com.t.ui;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
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 androidx.appcompat.app.AppCompatActivity;

import java.util.Calendar;

import timeline.lizimumu.com.t.R;
import timeline.lizimumu.com.t.service.AlertActivity;

public class AlarmActivity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ring);

        TimePicker timePicker=(TimePicker) findViewById(R.id.timePicker);
        timePicker.setIs24HourView(true);
        Button btn=(Button) findViewById(R.id.timeSet);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(AlarmActivity.this, AlertActivity.class);
                PendingIntent pendingIntent=PendingIntent.getActivity(AlarmActivity.this,0,intent,0);
                AlarmManager alarmManager=(AlarmManager) getSystemService(Context.ALARM_SERVICE);
                Calendar calendar=Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY,timePicker.getCurrentHour());
                calendar.set(Calendar.MINUTE,timePicker.getCurrentMinute());
                calendar.set(Calendar.SECOND,0);

                alarmManager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),pendingIntent);
                Toast.makeText(AlarmActivity.this,"主人,闹钟设置成功,么么哒。",Toast.LENGTH_SHORT).show();
            }
        });


    }
}

 

posted @ 2022-04-16 21:48  椅念琼  阅读(19)  评论(0编辑  收藏  举报