llr #3

Merged
pjmhoeuy7 merged 3 commits from llr_branch into dev 3 months ago

@ -0,0 +1,156 @@
package net.micode.notes.timer;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.widget.TextView;
import android.os.CountDownTimer;
import android.media.MediaPlayer;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuInflater;
import android.view.MenuItem.OnMenuItemClickListener;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import net.micode.notes.R;
public class CountDown extends AppCompatActivity implements CountDownListener {
private Button startButton,resetButton,stopButton;
private static final int HOUR = 60*60*1000;//小时
private static final int MIN = 60*1000;//分钟
private static final int SEC = 1000;//秒
private long hour,min,sec;
private boolean IsRunning;//是不是在跑
private long startTime;//开始时间
private long currentTime;//还剩多久
private CountDownTimer timer;
private CountDownListener listener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
//getWindow().setBackgroundDrawableResource(R.drawable.cloud);
setContentView(R.layout.activity_count_down);
startButton = findViewById(R.id.button_start);
resetButton = findViewById(R.id.button_reset);
stopButton = findViewById(R.id.button_stop);//按钮
startButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
start();
}
});
resetButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
reset();
}
});
stopButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
stop();
}
});
Intent intent = this.getIntent();
hour=intent.getLongExtra("hour", 0L);
min=intent.getLongExtra("min", 0L);
sec=intent.getLongExtra("sec", 0L);
currentTime=startTime=hour*HOUR+min*MIN+sec*SEC;
updateTime(startTime);
IsRunning=false;
start();//开始跑
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}
public void setTime(long duration){
if(IsRunning)return;
currentTime=startTime=duration;
updateTime(duration);
}
public void start() {
if(IsRunning) {return;}//还在跑
IsRunning = true;
timer = new CountDownTimer(currentTime, 100){//精度100ms
@Override public void onTick(long millis){
currentTime = millis;
updateTime(millis);
//invalidate();
}
@Override public void onFinish() {
stop();
if (listener != null) {
listener.onFinishCountDown();
}
}
};
timer.start();
}
public void reset() {
stop();
setTime(startTime);
//invalidate();
}
public void stop() {
if(!IsRunning){return;}//已经停了
IsRunning=false;
timer.cancel();
setListener(this);//监听器
}
public void updateTime(long duration){//展示倒计时数字
TextView timeView = findViewById(R.id.timeshow);
String res=getTimeShow(duration);
timeView.setText(res);
}
public String getTimeShow(long duration){//获取显示数字
int hour=(int)duration/HOUR;
duration%=HOUR;
int min=(int)duration/MIN;
duration%=MIN;
int sec=(int)duration/SEC;
String format="%02d";
String Shour = String.format(format, hour);
String Smin = String.format( format, min);
String Ssec = String.format(format, sec);
return String.format("%s h : %s m : %s s", Shour, Smin, Ssec);
}
public void setListener(CountDownListener listener) {
this.listener = listener;
}
@Override
public void onFinishCountDown() {//倒计时截至
//Toast.makeText(this, "Time up !!!", Toast.LENGTH_SHORT).show();
TextView timeView = findViewById(R.id.timeshow);
timeView.setText("Time up ");
MediaPlayer player=MediaPlayer.create(this,R.raw.timedown);
player.start();
}
}

@ -0,0 +1,5 @@
package net.micode.notes.timer;
public interface CountDownListener {//监听器
public void onFinishCountDown();//是否完成倒计时
}

@ -28,6 +28,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Paint;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Spannable;
@ -51,6 +52,11 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Button;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import java.util.Locale;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
@ -72,6 +78,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener {
private class HeadViewHolder {
@ -148,12 +155,33 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private String mUserQuery;
private Pattern mPattern;
private Button readButton;
private TextToSpeech tts;//接口
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.note_edit);
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {//tts初始化
@Override
public void onInit(int status) {
if(status == TextToSpeech.SUCCESS) {//设置中文
int result = tts.setLanguage(Locale.CHINA);
if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE && result != TextToSpeech.LANG_AVAILABLE) {
Toast.makeText(NoteEditActivity.this, "正在跳转", Toast.LENGTH_SHORT).show();
}
tts.setSpeechRate(1.0f);//速度
tts.setPitch(1.0f);//音调
}
}
});
readButton=findViewById(R.id.readnote);//按钮
readButton.setOnClickListener(new View.OnClickListener() {//点击阅读
@Override public void onClick(View view) {
ReadNow();
}
});
if (savedInstanceState == null && !initActivityState(getIntent())) {
finish();
return;
@ -161,6 +189,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
initResources();
}
public void ReadNow(){
;
}
/**
* Current activity may be killed when the memory is low. Once it is killed, for another time
* user load this activity, we should restore the former state

@ -0,0 +1,63 @@
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".timer.CountDown">
<TextView
android:id="@+id/timeshow"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center"
android:textSize="50dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/button_stop"
app:layout_constraintTop_toTopOf="parent"
/>
<Button
android:id="@+id/button_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/button_stop"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.9" />
<Button
android:id="@+id/button_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.9" />
<Button
android:id="@+id/button_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button_stop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.9" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="15dp"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:orientation="horizontal"
>
<TextView
android:layout_width="15dp"
android:layout_height="wrap_content"
android:text=" "
android:textSize="55dp"
></TextView>
<EditText
android:id="@+id/hour"
android:layout_width="60dp"
android:layout_height="50dp"
></EditText>
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="h"
android:textSize="30dp"></TextView>
<EditText
android:id="@+id/min"
android:layout_width="60dp"
android:layout_height="50dp"
></EditText>
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="m"
android:textSize="30dp"></TextView>
<EditText
android:id="@+id/sec"
android:layout_width="60dp"
android:layout_height="50dp"
></EditText>
<TextView
android:layout_width="40dp"
android:layout_height="wrap_content"
android:text="s"
android:textSize="30dp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp">
</LinearLayout>
</LinearLayout>
Loading…
Cancel
Save