all
main
pjmhoeuy7 3 months ago
commit 088cbebbeb

@ -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,36 @@ public class NoteEditActivity extends Activity implements OnClickListener,
initResources();
}
public void ReadNow(){
String noteContent = getCurrentNoteContent();
if (noteContent.isEmpty()){
MediaPlayer player=MediaPlayer.create(this,R.raw.pleaseinput);
player.start();
Toast.makeText(NoteEditActivity.this, "请输入内容", Toast.LENGTH_SHORT).show();
return;
}
Toast.makeText(NoteEditActivity.this, "开始阅读", Toast.LENGTH_SHORT).show();
// 开始朗读(使用本地语音)
tts.speak(noteContent, TextToSpeech.QUEUE_ADD, null, "test");
}
private String getCurrentNoteContent() {//获取文本
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
StringBuilder content = new StringBuilder();
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
View itemView = mEditTextList.getChildAt(i);
CheckBox checkBox = itemView.findViewById(R.id.cb_edit_item);
NoteEditText editText = itemView.findViewById(R.id.et_edit_text);
String prefix = checkBox.isChecked() ? "已完成: " : "未完成: ";
content.append(prefix).append(editText.getText()).append("\n");
}
return content.toString();
} else {
return mNoteEditor.getText().toString();
}
}//
/**
* 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

@ -331,6 +331,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
public void onClick(DialogInterface dialog,
int which) {
batchDelete();
//Notesback();
}
});
builder.setNegativeButton(android.R.string.cancel, null);
@ -505,6 +506,32 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}.execute();
}
private void Notesback(){
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_ROOT_FOLDER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens");
}
return widgets;
}
@Override
protected void onPostExecute(HashSet<AppWidgetAttribute> widgets) {
if (widgets != null) {
for (AppWidgetAttribute widget : widgets) {
if (widget.widgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& widget.widgetType != Notes.TYPE_WIDGET_INVALIDE) {
updateWidget(widget.widgetId, widget.widgetType);
}
}
}
mModeCallBack.finishActionMode();
}
}.execute();
//DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter.getSelectedItemIds(),Notes.ID_ROOT_FOLDER);
}
private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) {
@ -579,6 +606,74 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
private void showTimeGet() {//获取倒计时时间
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("请输入倒计时时间");//标题
View view = LayoutInflater.from(this).inflate(R.layout.get_time, null);
final EditText hour = (EditText) view.findViewById(R.id.hour);
final EditText min = (EditText) view.findViewById(R.id.min);
final EditText sec = (EditText) view.findViewById(R.id.sec);
showSoftInput();//打开键盘
builder.setPositiveButton(android.R.string.ok, null);// 确认(逻辑在下方)
builder.setNegativeButton(android.R.string.cancel, null);
final Dialog dialog = builder.setView(view).show();//显示
final Button positive = (Button) dialog.findViewById(android.R.id.button1);
positive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), net.micode.notes.timer.CountDown.class);
long h=Long.parseLong(hour.getText().toString());
intent.putExtra("hour",h);
long m=Long.parseLong(min.getText().toString());
intent.putExtra("min",m);
long s=Long.parseLong(sec.getText().toString());
intent.putExtra("sec",s);
Toast.makeText(v.getContext(), "正在跳转", Toast.LENGTH_SHORT).show();
startActivity(intent);//跳转页面到倒计时
dialog.dismiss();
}
});
//后面全是监听器
if (TextUtils.isEmpty(hour.getText())) {
positive.setEnabled(false);
}
hour.addTextChangedListener(new TextWatcher() {//监听器
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!TextUtils.isEmpty(hour.getText())&&!TextUtils.isEmpty(min.getText())
&&!TextUtils.isEmpty(sec.getText()))
{positive.setEnabled(true);}
else{positive.setEnabled(false);}
}
public void afterTextChanged(Editable s) {}
});
min.addTextChangedListener(new TextWatcher() {//监听器
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!TextUtils.isEmpty(hour.getText())&&!TextUtils.isEmpty(min.getText())
&&!TextUtils.isEmpty(sec.getText()))
{positive.setEnabled(true);}
else{positive.setEnabled(false);}
}
public void afterTextChanged(Editable s) {}
});
sec.addTextChangedListener(new TextWatcher() {//监听器
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!TextUtils.isEmpty(hour.getText())&&!TextUtils.isEmpty(min.getText())
&&!TextUtils.isEmpty(sec.getText()))
{positive.setEnabled(true);}
else{positive.setEnabled(false);}
}
public void afterTextChanged(Editable s) {}
});
}
private void showCreateOrModifyFolderDialog(final boolean create) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
@ -812,6 +907,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
case R.id.menu_search:
onSearchRequested();
break;
case R.id.menu_countdown:
showTimeGet();
break;
default:
break;
}

@ -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>

@ -69,6 +69,17 @@
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="@+id/readnote"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
style="?android:attr/textAppearanceMedium"
android:text="阅读便签"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="7dip"
@ -83,6 +94,8 @@
android:layout_gravity="left|top"
android:fadingEdgeLength="0dip">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
@ -396,5 +409,7 @@
android:layout_marginBottom="-7dip"
android:src="@drawable/selected" />
</FrameLayout>
</LinearLayout>
</FrameLayout>

@ -15,7 +15,7 @@
limitations under the License.
-->
<menu
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_new_folder"
@ -36,4 +36,7 @@
<item
android:id="@+id/menu_search"
android:title="@string/menu_search" />
<item
android:id="@+id/menu_countdown"
android:title="countdown" />
</menu>

Loading…
Cancel
Save