ui包大部分代码批注上传

ui包大部分代码批注上传
pull/9/head
mth9uq3ve 2 years ago
commit c1fc0da4f6

@ -1,3 +0,0 @@
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Android API 33, extension level 3 Platform" project-jdk-type="Android SDK" />
</project>

@ -59,7 +59,12 @@ import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
/**
* @classname: GTaskClient
* @description:GTASKGTASK
* @date: 2024/1/4 11:21
* @author: wangrunze
*/
public class GTaskClient {
private static final String TAG = GTaskClient.class.getSimpleName();
@ -101,17 +106,32 @@ public class GTaskClient {
mAccount = null;
mUpdateArray = null;
}
/**
* @classname: GTaskClient
* @methodname: getInstance
* @description:
* @date: 2024/1/4 11:22
* @author: wangrunze
*/
public static synchronized GTaskClient getInstance() {
if (mInstance == null) {
mInstance = new GTaskClient();
}
return mInstance;
}
/**
* @classname: GTaskClient
* @methodname: login
* @description:
* @date: 2024/1/4 11:22
* @author: wangrunze
* @param:Activity activity
* @return:true/false
*/
public boolean login(Activity activity) {
// we suppose that the cookie would expire after 5 minutes
// then we need to re-login
//判断距离最后一次登录操作是否超过5分钟
final long interval = 1000 * 60 * 5;
if (mLastLoginTime + interval < System.currentTimeMillis()) {
mLoggedin = false;
@ -126,6 +146,7 @@ public class GTaskClient {
if (mLoggedin) {
Log.d(TAG, "already logged in");
//如果没超过时间,则不需要重新登录
return true;
}
@ -135,7 +156,7 @@ public class GTaskClient {
Log.e(TAG, "login google account failed");
return false;
}
//使用用户自己的域名登录
// login with custom domain if necessary
if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase()
.endsWith("googlemail.com"))) {
@ -151,6 +172,7 @@ public class GTaskClient {
}
}
//如果用户账户无法登录则使用谷歌官方的URI进行登录
// try to login with google official url
if (!mLoggedin) {
mGetUrl = GTASK_GET_URL;
@ -163,7 +185,16 @@ public class GTaskClient {
mLoggedin = true;
return true;
}
/**
* @classname: GTaskClient
* @methodname: loginGoogleAccount
* @description:使
* @date: 2024/1/4 11:24
* @author: wangrunze
* @param:Activity activity
* @param:boolean invalidateToken
* @return:
*/
private String loginGoogleAccount(Activity activity, boolean invalidateToken) {
String authToken;
AccountManager accountManager = AccountManager.get(activity);
@ -188,7 +219,7 @@ public class GTaskClient {
Log.e(TAG, "unable to get an account with the same name in the settings");
return null;
}
//获取选中账号的令牌
// get the token now
AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthToken(account,
"goanna_mobile", null, activity, null, null);
@ -206,7 +237,16 @@ public class GTaskClient {
return authToken;
}
/**
* @classname: GTaskClient
* @methodname: tryToLoginGtask
* @description:GTask
* @date: 2024/1/4 11:25
* @author: wangrunze
* @param:Activity activity
* @param:String authToken
* @return:true/false
*/
private boolean tryToLoginGtask(Activity activity, String authToken) {
if (!loginGtask(authToken)) {
// maybe the auth token is out of date, now let's invalidate the
@ -224,7 +264,14 @@ public class GTaskClient {
}
return true;
}
/**
* @classname: GTaskClient
* @methodname: loginGtask
* @description:GTask
* @date: 2024/1/4 11:26
* @author: wangrunze
* @param:String authToken
*/
private boolean loginGtask(String authToken) {
int timeoutConnection = 10000;
int timeoutSocket = 15000;
@ -238,11 +285,11 @@ public class GTaskClient {
// login gtask
try {
String loginUrl = mGetUrl + "?auth=" + authToken;
HttpGet httpGet = new HttpGet(loginUrl);
String loginUrl = mGetUrl + "?auth=" + authToken;//设置登录的url
HttpGet httpGet = new HttpGet(loginUrl);//通过登录的uri实例化网页上资源的查找
HttpResponse response = null;
response = mHttpClient.execute(httpGet);
//获取CookieStore里存放的cookie
// get the cookie now
List<Cookie> cookies = mHttpClient.getCookieStore().getCookies();
boolean hasAuthCookie = false;
@ -254,7 +301,7 @@ public class GTaskClient {
if (!hasAuthCookie) {
Log.w(TAG, "it seems that there is no auth cookie");
}
//获取client的内容
// get the client version
String resString = getResponseContent(response.getEntity());
String jsBegin = "_setup(";
@ -283,14 +330,29 @@ public class GTaskClient {
private int getActionId() {
return mActionId++;
}
/**
* @classname: GTaskClient
* @methodname: createHttpPost
* @description:
* @date: 2024/1/4 11:28
* @author: wangrunze
* @return:httpPost
*/
private HttpPost createHttpPost() {
HttpPost httpPost = new HttpPost(mPostUrl);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
httpPost.setHeader("AT", "1");
return httpPost;
}
/**
* @classname: GTaskClient
* @methodname: getResponseContent
* @description:
* @date: 2024/1/4 11:29
* @author: wangrunze
* @param:HttpEntity entity
* @return:
*/
private String getResponseContent(HttpEntity entity) throws IOException {
String contentEncoding = null;
if (entity.getContentEncoding() != null) {
@ -322,7 +384,15 @@ public class GTaskClient {
input.close();
}
}
/**
* @classname: GTaskClient
* @methodname: postRequest
* @description: JSON
* @date: 2024/1/4 11:30
* @author: wangrunze
* @param:JSONObject js
* @return:JSONObject
*/
private JSONObject postRequest(JSONObject js) throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
@ -359,7 +429,14 @@ public class GTaskClient {
throw new ActionFailureException("error occurs when posting request");
}
}
/**
* @classname: GTaskClient
* @methodname: createTask
* @description:
* @date: 2024/1/4 11:31
* @author: wangrunze
* @param:Task task
*/
public void createTask(Task task) throws NetworkFailureException {
commitUpdate();
try {
@ -385,7 +462,14 @@ public class GTaskClient {
throw new ActionFailureException("create task: handing jsonobject failed");
}
}
/**
* @classname: GTaskClient
* @methodname: createTaskList
* @description:
* @date: 2024/1/4 11:31
* @author: wangrunze
* @param:TaskList tasklist
*/
public void createTaskList(TaskList tasklist) throws NetworkFailureException {
commitUpdate();
try {
@ -411,7 +495,13 @@ public class GTaskClient {
throw new ActionFailureException("create tasklist: handing jsonobject failed");
}
}
/**
* @classname: GTaskClient
* @methodname: commitUpdate
* @description:
* @date: 2024/1/4 11:32
* @author: wangrunze
*/
public void commitUpdate() throws NetworkFailureException {
if (mUpdateArray != null) {
try {
@ -432,7 +522,14 @@ public class GTaskClient {
}
}
}
/**
* @classname: GTaskClient
* @methodname: addUpdateNode
* @description:
* @date: 2024/1/4 11:32
* @author: wangrunze
* @param:Node node
*/
public void addUpdateNode(Node node) throws NetworkFailureException {
if (node != null) {
// too many update items may result in an error
@ -446,7 +543,16 @@ public class GTaskClient {
mUpdateArray.put(node.getUpdateAction(getActionId()));
}
}
/**
* @classname: GTaskClient
* @methodname: moveTask
* @description:task
* @date: 2024/1/4 11:32
* @author: wangrunze
* @param:Task task
* @param:TaskList preParent
* @param:TaskList curParent
*/
public void moveTask(Task task, TaskList preParent, TaskList curParent)
throws NetworkFailureException {
commitUpdate();
@ -485,7 +591,14 @@ public class GTaskClient {
throw new ActionFailureException("move task: handing jsonobject failed");
}
}
/**
* @classname: GTaskClient
* @methodname: deleteNode
* @description:
* @date: 2024/1/4 11:33
* @author: wangrunze
* @param:Node node
*/
public void deleteNode(Node node) throws NetworkFailureException {
commitUpdate();
try {
@ -508,7 +621,13 @@ public class GTaskClient {
throw new ActionFailureException("delete node: handing jsonobject failed");
}
}
/**
* @classname: GTaskClient
* @methodname: getTaskLists
* @description:
* @date: 2024/1/4 11:34
* @author: wangrunze
*/
public JSONArray getTaskLists() throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
@ -546,7 +665,14 @@ public class GTaskClient {
throw new ActionFailureException("get task lists: handing jasonobject failed");
}
}
/**
* @classname: GTaskClient
* @methodname: getTaskList
* @description:
* @date: 2024/1/4 11:34
* @author: wangrunze
* @param:String listGid
*/
public JSONArray getTaskList(String listGid) throws NetworkFailureException {
commitUpdate();
try {

@ -47,7 +47,12 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
/**
* @classname: GTaskManager
* @description:gtask
* @date: 2024/1/4 11:36
* @author: wangrunze
*/
public class GTaskManager {
private static final String TAG = GTaskManager.class.getSimpleName();
@ -87,7 +92,7 @@ public class GTaskManager {
private HashMap<Long, String> mNidToGid;
private GTaskManager() {
private GTaskManager() {//对象初始化函数
mSyncing = false;
mCancelled = false;
mGTaskListHashMap = new HashMap<String, TaskList>();
@ -98,19 +103,41 @@ public class GTaskManager {
mGidToNid = new HashMap<String, Long>();
mNidToGid = new HashMap<Long, String>();
}
/**
* @classname: GTaskManager
* @methodname: getInstance
* @description:
* @date: 2024/1/4 11:37
* @author: wangrunze
*/
public static synchronized GTaskManager getInstance() {
if (mInstance == null) {
mInstance = new GTaskManager();
}
return mInstance;
}
/**
* @classname: GTaskManager
* @methodname: setActivityContext
* @description:线
* @date: 2024/1/4 11:38
* @author: wangrunze
* @param:Activity activity
*/
public synchronized void setActivityContext(Activity activity) {
// used for getting authtoken
mActivity = activity;
}
/**
* @classname: GTaskManager
* @methodname: sync
* @description:
* @date: 2024/1/4 11:38
* @author: wangrunze
* @param:Context context
* @param:GTaskASyncTask asyncTask
*/
public int sync(Context context, GTaskASyncTask asyncTask) {
if (mSyncing) {
Log.d(TAG, "Sync is in progress");
@ -128,14 +155,14 @@ public class GTaskManager {
mNidToGid.clear();
try {
GTaskClient client = GTaskClient.getInstance();
GTaskClient client = GTaskClient.getInstance();//getInstance即为创建一个实例
client.resetUpdateArray();
// login google task
if (!mCancelled) {
if (!client.login(mActivity)) {
throw new NetworkFailureException("login google task failed");
}
}//获取Google上的JSONtasklist转为本地TaskList
}
// get the task list from google
@ -167,7 +194,13 @@ public class GTaskManager {
return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS;
}
/**
* @classname: GTaskManager
* @methodname: initGTaskList
* @description:GtaskList
* @date: 2024/1/4 11:41
* @author: wangrunze
*/
private void initGTaskList() throws NetworkFailureException {
if (mCancelled)
return;
@ -246,7 +279,13 @@ public class GTaskManager {
throw new ActionFailureException("initGTaskList: handing JSONObject failed");
}
}
/**
* @classname: GTaskManager
* @methodname: syncContent
* @description:
* @date: 2024/1/4 11:41
* @author: wangrunze
*/
private void syncContent() throws NetworkFailureException {
int syncType;
Cursor c = null;
@ -350,7 +389,13 @@ public class GTaskManager {
}
}
/**
* @classname: GTaskManager
* @methodname: syncFolder
* @description:
* @date: 2024/1/4 11:42
* @author: wangrunze
*/
private void syncFolder() throws NetworkFailureException {
Cursor c = null;
String gid;
@ -475,7 +520,16 @@ public class GTaskManager {
if (!mCancelled)
GTaskClient.getInstance().commitUpdate();
}
/**
* @classname: GTaskManager
* @methodname: doContentSync
* @description:syncType
* @date: 2024/1/4 11:43
* @author: wangrunze
* @param:int syncType
* @param:Node node
* @param: Cursor c
*/
private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -521,7 +575,14 @@ public class GTaskManager {
throw new ActionFailureException("unkown sync action type");
}
}
/**
* @classname: GTaskManager
* @methodname: addLocalNode
* @description:Node
* @date: 2024/1/4 11:43
* @author: wangrunze
* @param:Node node
*/
private void addLocalNode(Node node) throws NetworkFailureException {
if (mCancelled) {
return;
@ -595,7 +656,15 @@ public class GTaskManager {
// update meta
updateRemoteMeta(node.getGid(), sqlNote);
}
/**
* @classname: GTaskManager
* @methodname: updateLocalNode
* @description:node
* @date: 2024/1/4 11:44
* @author: wangrunze
* @param:Node node
* @param:Cursor cCursor c
*/
private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -618,7 +687,15 @@ public class GTaskManager {
// update meta info
updateRemoteMeta(node.getGid(), sqlNote);
}
/**
* @classname: GTaskManager
* @methodname: addRemoteNode
* @description:Node
* @date: 2024/1/4 11:44
* @author: wangrunze
* @param:Node node
* @param:Cursor c
*/
private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -691,7 +768,15 @@ public class GTaskManager {
mGidToNid.put(n.getGid(), sqlNote.getId());
mNidToGid.put(sqlNote.getId(), n.getGid());
}
/**
* @classname: GTaskManager
* @methodname: updateRemoteNode
* @description:Node
* @date: 2024/1/4 11:45
* @author: wangrunze
* @param:Node node
* @param:Cursor c
*/
private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -729,7 +814,15 @@ public class GTaskManager {
sqlNote.resetLocalModified();
sqlNote.commit(true);
}
/**
* @classname: GTaskManager
* @methodname: updateRemoteMeta
* @description:meta
* @date: 2024/1/4 11:45
* @author: wangrunze
* @param:String gid
* @param:SqlNote sqlNote
*/
private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException {
if (sqlNote != null && sqlNote.isNoteType()) {
MetaData metaData = mMetaHashMap.get(gid);
@ -745,7 +838,13 @@ public class GTaskManager {
}
}
}
/**
* @classname: GTaskManager
* @methodname: refreshLocalSyncId
* @description:
* @date: 2024/1/4 11:46
* @author: wangrunze
*/
private void refreshLocalSyncId() throws NetworkFailureException {
if (mCancelled) {
return;
@ -789,11 +888,23 @@ public class GTaskManager {
}
}
}
/**
* @classname: GTaskManager
* @methodname: getSyncAccount
* @description:
* @date: 2024/1/4 11:47
* @author: wangrunze
*/
public String getSyncAccount() {
return GTaskClient.getInstance().getSyncAccount().name;
}
/**
* @classname: GTaskManager
* @methodname: cancelSync
* @description:
* @date: 2024/1/4 11:48
* @author: wangrunze
*/
public void cancelSync() {
mCancelled = true;
}

@ -22,7 +22,12 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
/**
* @classname: GTaskSyncService
* @description:
* @date: 2024/1/4 11:50
* @author: wangrunze
*/
public class GTaskSyncService extends Service {
public final static String ACTION_STRING_NAME = "sync_action_type";
@ -41,7 +46,13 @@ public class GTaskSyncService extends Service {
private static GTaskASyncTask mSyncTask = null;
private static String mSyncProgress = "";
/**
* @classname: GTaskSyncService
* @methodname: startSync
* @description:
* @date: 2024/1/4 11:52
* @author: wangrunze
*/
private void startSync() {
if (mSyncTask == null) {
mSyncTask = new GTaskASyncTask(this, new GTaskASyncTask.OnCompleteListener() {
@ -55,18 +66,36 @@ public class GTaskSyncService extends Service {
mSyncTask.execute();
}
}
/**
* @classname: GTaskSyncService
* @methodname: cancelSync
* @description:
* @date: 2024/1/4 11:53
* @author: wangrunze
*/
private void cancelSync() {
if (mSyncTask != null) {
mSyncTask.cancelSync();
}
}
/**
* @classname: GTaskSyncService
* @methodname: onCreate
* @description:service
* @date: 2024/1/4 11:53
* @author: wangrunze
*/
@Override
public void onCreate() {
mSyncTask = null;
}
/**
* @classname: GTaskSyncService
* @methodname: onStartCommand
* @description:service
* @date: 2024/1/4 11:54
* @author: wangrunze
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle bundle = intent.getExtras();
@ -85,7 +114,13 @@ public class GTaskSyncService extends Service {
}
return super.onStartCommand(intent, flags, startId);
}
/**
* @classname: GTaskSyncService
* @methodname: onLowMemory
* @description:
* @date: 2024/1/4 11:54
* @author: wangrunze
*/
@Override
public void onLowMemory() {
if (mSyncTask != null) {
@ -96,7 +131,14 @@ public class GTaskSyncService extends Service {
public IBinder onBind(Intent intent) {
return null;
}
/**
* @classname: GTaskSyncService
* @methodname: sendBroadcast
* @description:广
* @date: 2024/1/4 11:55
* @author: wangrunze
* @param:String msg
*/
public void sendBroadcast(String msg) {
mSyncProgress = msg;
Intent intent = new Intent(GTASK_SERVICE_BROADCAST_NAME);
@ -105,13 +147,28 @@ public class GTaskSyncService extends Service {
sendBroadcast(intent);
}
/**
* @classname: GTaskSyncService
* @methodname: startSync
* @description:service
* @date: 2024/1/4 11:56
* @author: wangrunze
* @param:Activity activity
*/
public static void startSync(Activity activity) {
GTaskManager.getInstance().setActivityContext(activity);
Intent intent = new Intent(activity, GTaskSyncService.class);
intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_START_SYNC);
activity.startService(intent);
}
/**
* @classname: GTaskSyncService
* @methodname: cancelSync
* @description:service
* @date: 2024/1/4 11:56
* @author: wangrunze
* @param:Context context
*/
public static void cancelSync(Context context) {
Intent intent = new Intent(context, GTaskSyncService.class);
intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_CANCEL_SYNC);

@ -14,200 +14,199 @@
* limitations under the License.
*/
package net.micode.notes.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.view.Window;
import android.view.WindowManager;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils;
import java.io.IOException;
/**
* @classname: AlarmAlertActivity
* @description:
* @date: 2023/12/28 11:18
* @author: wangrunze
*/
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
private long mNoteId;//文本在数据库存储中的ID号
private String mSnippet;//闹钟提示时出现的文本片段
private static final int SNIPPET_PREW_MAX_LEN = 60;
MediaPlayer mPlayer;
//Bundle类型的数据与Map类型的数据相似都是以key-value的形式存储数据的
//onsaveInstanceState方法是用来保存Activity的状态的,能从onCreate的参数savedInsanceState中获得状态数据
/**
* @classname: AlarmAlertActivity
* @methodname onCreate
* @description:
* @date: 2023/12/28 11:27
* @author: wangrunze
* @param: Bundle savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//界面显示——无标题
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
if (!isScreenOn()) {
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON//保持窗体点亮
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON//将窗体点亮
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON//允许窗体点亮时锁屏
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);//在手机锁屏后如果到了闹钟提示时间,点亮屏幕
}
Intent intent = getIntent();
try {
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);//根据ID从数据库中获取标签的内容
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)//判断标签片段是否达到符合长度
: mSnippet;
} catch (IllegalArgumentException e) {
e.printStackTrace();
return;
}
mPlayer = new MediaPlayer();
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
showActionDialog();//弹出对话框
playAlarmSound();//闹钟提示音激发
} else {
finish();
}
}
/**
* @classname: AlarmAlertActivity
* @methodname isScreenOn
* @description:
* @date: 2023/12/28 11:28
* @author: wangrunze
* @return: pm.isScreenOn()
*/
private boolean isScreenOn() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
return pm.isScreenOn();
}
/**
* @classname: AlarmAlertActivity
* @methodname playAlarmSound
* @description:
* @date: 2023/12/28 11:29
* @author: wangrunze
*/
private void playAlarmSound() {
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
int silentModeStreams = Settings.System.getInt(getContentResolver(),
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); //调用系统的铃声管理URI得到闹钟提示音
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
mPlayer.setAudioStreamType(silentModeStreams);
} else {
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
}
try {
mPlayer.setDataSource(this, url);//无返回值,设置多媒体数据来源
mPlayer.prepare();//准备同步
mPlayer.setLooping(true);//设置是否循环播放
mPlayer.start();//开始播放
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();//抛出异常, 还将显示出更深的调用信息
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @classname: AlarmAlertActivity
* @methodname showActionDialog
* @description:
* @date: 2023/12/28 11:30
* @author: wangrunze
*/
private void showActionDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);//用到AlertDialog.Builder中的create()新建了一个AlertDialog
dialog.setTitle(R.string.app_name);//为对话框设置标题
dialog.setMessage(mSnippet);//为对话框设置内容
dialog.setPositiveButton(R.string.notealert_ok, this);//给对话框添加"Yes"按钮
if (isScreenOn()) {
dialog.setNegativeButton(R.string.notealert_enter, this);//给对话框添加"no"按钮
}
dialog.show().setOnDismissListener(this);
}
//DialogInterface dialog为对话框which为选择按钮,功能为选择各种操作
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_NEGATIVE://这是取消操作
Intent intent = new Intent(this, NoteEditActivity.class);//实现两个类间的数据传输
intent.setAction(Intent.ACTION_VIEW);//设置动作属性
intent.putExtra(Intent.EXTRA_UID, mNoteId);
startActivity(intent);
break;
default:
break;
}
}
/**
* @classname: AlarmAlertActivity
* @methodname onDismiss
* @description:
* @date: 2023/12/28 11:30
* @author: wangrunze
* @param:DialogInterface dialog
*/
public void onDismiss(DialogInterface dialog) {
stopAlarmSound();
finish();
}
/**
* @classname: AlarmAlertActivity
* @methodname: stopAlarmSound
* @description:
* @date: 2023/12/28 11:31
* @author: wangrunze
*/
private void stopAlarmSound() {
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
mPlayer = null;
}
}
}
package net.micode.notes.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.view.Window;
import android.view.WindowManager;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils;
import java.io.IOException;
/**
* @classname: AlarmAlertActivity
* @description:
* @date: 2023/12/28 11:18
* @author: wangrunze
*/
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
private long mNoteId;//文本在数据库存储中的ID号
private String mSnippet;//闹钟提示时出现的文本片段
private static final int SNIPPET_PREW_MAX_LEN = 60;
MediaPlayer mPlayer;
//Bundle类型的数据与Map类型的数据相似都是以key-value的形式存储数据的
//onsaveInstanceState方法是用来保存Activity的状态的,能从onCreate的参数savedInsanceState中获得状态数据
/**
* @classname: AlarmAlertActivity
* @methodname onCreate
* @description:
* @date: 2023/12/28 11:27
* @author: wangrunze
* @param: Bundle savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//界面显示——无标题
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
if (!isScreenOn()) {
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON//保持窗体点亮
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON//将窗体点亮
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON//允许窗体点亮时锁屏
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);//在手机锁屏后如果到了闹钟提示时间,点亮屏幕
}
Intent intent = getIntent();
try {
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);//根据ID从数据库中获取标签的内容
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)//判断标签片段是否达到符合长度
: mSnippet;
} catch (IllegalArgumentException e) {
e.printStackTrace();
return;
}
mPlayer = new MediaPlayer();
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
showActionDialog();//弹出对话框
playAlarmSound();//闹钟提示音激发
} else {
finish();
}
}
/**
* @classname: AlarmAlertActivity
* @methodname isScreenOn
* @description:
* @date: 2023/12/28 11:28
* @author: wangrunze
* @return: pm.isScreenOn()
*/
private boolean isScreenOn() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
return pm.isScreenOn();
}
/**
* @classname: AlarmAlertActivity
* @methodname playAlarmSound
* @description:
* @date: 2023/12/28 11:29
* @author: wangrunze
*/
private void playAlarmSound() {
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
int silentModeStreams = Settings.System.getInt(getContentResolver(),
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); //调用系统的铃声管理URI得到闹钟提示音
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
mPlayer.setAudioStreamType(silentModeStreams);
} else {
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
}
try {
mPlayer.setDataSource(this, url);//无返回值,设置多媒体数据来源
mPlayer.prepare();//准备同步
mPlayer.setLooping(true);//设置是否循环播放
mPlayer.start();//开始播放
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();//抛出异常, 还将显示出更深的调用信息
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @classname: AlarmAlertActivity
* @methodname showActionDialog
* @description:
* @date: 2023/12/28 11:30
* @author: wangrunze
*/
private void showActionDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);//用到AlertDialog.Builder中的create()新建了一个AlertDialog
dialog.setTitle(R.string.app_name);//为对话框设置标题
dialog.setMessage(mSnippet);//为对话框设置内容
dialog.setPositiveButton(R.string.notealert_ok, this);//给对话框添加"Yes"按钮
if (isScreenOn()) {
dialog.setNegativeButton(R.string.notealert_enter, this);//给对话框添加"no"按钮
}
dialog.show().setOnDismissListener(this);
}
//DialogInterface dialog为对话框which为选择按钮,功能为选择各种操作
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_NEGATIVE://这是取消操作
Intent intent = new Intent(this, NoteEditActivity.class);//实现两个类间的数据传输
intent.setAction(Intent.ACTION_VIEW);//设置动作属性
intent.putExtra(Intent.EXTRA_UID, mNoteId);
startActivity(intent);
break;
default:
break;
}
}
/**
* @classname: AlarmAlertActivity
* @methodname onDismiss
* @description:
* @date: 2023/12/28 11:30
* @author: wangrunze
* @param:DialogInterface dialog
*/
public void onDismiss(DialogInterface dialog) {
stopAlarmSound();
finish();
}
/**
* @classname: AlarmAlertActivity
* @methodname: stopAlarmSound
* @description:
* @date: 2023/12/28 11:31
* @author: wangrunze
*/
private void stopAlarmSound() {
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
mPlayer = null;
}
}
}

@ -27,20 +27,34 @@ import android.database.Cursor;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
/**
* @classname: AlarmInitReceiver
* @description:
* @date: 2023/12/29 11:17
* @author: wangrunze
*/
public class AlarmInitReceiver extends BroadcastReceiver {
private static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.ALERTED_DATE
};
//对数据库的操作调用标签ID和闹钟时间
private static final int COLUMN_ID = 0;
private static final int COLUMN_ALERTED_DATE = 1;
/**
* @classname: AlarmInitReceiver
* @methodname: onReceive
* @description:
* @date: 2023/12/29 11:23
* @author: wangrunze
* @param:Context context
* @param:Intent intent
*/
@Override
public void onReceive(Context context, Intent intent) {
long currentDate = System.currentTimeMillis();
long currentDate = System.currentTimeMillis();//System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数
Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,

@ -19,8 +19,23 @@ package net.micode.notes.ui;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
/**
* @classname: AlarmReceiver
* @description:alarm
* @date: 2023/12/29 11:28
* @author: wangrunze
*/
public class AlarmReceiver extends BroadcastReceiver {
/**
* @classname: AlarmReceiver
* @methodname: onReceive
* @description:AlarmAlertActivity
* @date: 2023/12/29 11:29
* @author: wangrunze
* @param:Context context
* @param:Intent intent
*/
@Override
public void onReceive(Context context, Intent intent) {
intent.setClass(context, AlarmAlertActivity.class);

@ -28,6 +28,12 @@ import android.view.View;
import android.widget.FrameLayout;
import android.widget.NumberPicker;
/**
* @classname: DateTimePicker
* @description:
* @date: 2023/12/29 11:40
* @author: wangrunze
*/
public class DateTimePicker extends FrameLayout {
private static final boolean DEFAULT_ENABLE_STATE = true;
@ -65,6 +71,16 @@ public class DateTimePicker extends FrameLayout {
private OnDateTimeChangedListener mOnDateTimeChangedListener;
private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
/**
* @classname: DateTimePicker
* @methodname: onValueChange
* @description:
* @date: 2023/12/29 11:41
* @author: wangrunze
* @param:NumberPicker picker
* @param:int oldVal
* @param: int newVal
*/
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal);
@ -74,6 +90,16 @@ public class DateTimePicker extends FrameLayout {
};
private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
/**
* @classname: DateTimePicker
* @methodname: onValueChange
* @description:Hour
* @date: 2023/12/29 11:42
* @author: wangrunze
* @param:NumberPicker picker
* @param:int oldVal
* @param:int newVal
*/
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
boolean isDateChanged = false;
@ -116,6 +142,16 @@ public class DateTimePicker extends FrameLayout {
};
private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
/**
* @classname: DateTimePicker
* @methodname: onValueChange
* @description:
* @date: 2023/12/29 11:43
* @author: wangrunze
* @param:NumberPicker picker
* @param:int oldVal
* @param:int newVal
*/
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
int minValue = mMinuteSpinner.getMinValue();
@ -146,6 +182,16 @@ public class DateTimePicker extends FrameLayout {
private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
/**
* @classname: DateTimePicker
* @methodname: onValueChange
* @description: AMPM
* @date: 2023/12/29 11:43
* @author: wangrunze
* @param:NumberPicker picker
* @param:int oldVal
* @param: int newVal
*/
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mIsAm = !mIsAm;
if (mIsAm) {
@ -157,12 +203,20 @@ public class DateTimePicker extends FrameLayout {
onDateTimeChanged();
}
};
public interface OnDateTimeChangedListener {
void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute);
}
/**
* @classname: DateTimePicker
* @methodname: DateTimePicker
* @description:
* @date: 2023/12/29 11:45
* @author: wangrunze
* @param:Context context
*/
public DateTimePicker(Context context) {
this(context, System.currentTimeMillis());
}
@ -171,6 +225,16 @@ public class DateTimePicker extends FrameLayout {
this(context, date, DateFormat.is24HourFormat(context));
}
/**
* @classname: DateTimePicker
* @methodname: DateTimePicker
* @description:
* @date: 2023/12/29 11:47
* @author: wangrunze
* @param:Context context
* @param:long date
* @param:boolean is24HourView
*/
public DateTimePicker(Context context, long date, boolean is24HourView) {
super(context);
mDate = Calendar.getInstance();
@ -214,6 +278,14 @@ public class DateTimePicker extends FrameLayout {
mInitialising = false;
}
/**
* @classname: DateTimePicker
* @methodname: setEnabled
* @description:
* @date: 2023/12/29 11:49
* @author: wangrunze
* @param:boolean enabled
*/
@Override
public void setEnabled(boolean enabled) {
if (mIsEnabled == enabled) {
@ -246,6 +318,14 @@ public class DateTimePicker extends FrameLayout {
*
* @param date The current date in millis
*/
/**
* @classname: DateTimePicker
* @methodname: setCurrentDate
* @description:
* @date: 2023/12/29 11:51
* @author: wangrunze
* @param:long date
*/
public void setCurrentDate(long date) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(date);
@ -262,6 +342,14 @@ public class DateTimePicker extends FrameLayout {
* @param hourOfDay The current hourOfDay
* @param minute The current minute
*/
/**
* @classname: DateTimePicker
* @methodname: setCurrentDate
* @description:
* @date: 2023/12/29 11:51
* @author: wangrunze
* @param:long date
*/
public void setCurrentDate(int year, int month,
int dayOfMonth, int hourOfDay, int minute) {
setCurrentYear(year);
@ -285,6 +373,14 @@ public class DateTimePicker extends FrameLayout {
*
* @param year The current year
*/
/**
* @classname: DateTimePicker
* @methodname: setCurrentYear
* @description:Set current year
* @date: 2024/1/7 9:53
* @author: wangrunze
* @param:year
*/
public void setCurrentYear(int year) {
if (!mInitialising && year == getCurrentYear()) {
return;
@ -293,12 +389,19 @@ public class DateTimePicker extends FrameLayout {
updateDateControl();
onDateTimeChanged();
}
/**
* Get current month in the year
*
* @return The current month in the year
*/
/**
* @classname: DateTimePicker
* @methodname: getCurrentMonth
* @description:Get current month in the year
* @date: 2024/1/7 9:54
* @author: wangrunze
* @return:current month
*/
public int getCurrentMonth() {
return mDate.get(Calendar.MONTH);
}
@ -308,6 +411,14 @@ public class DateTimePicker extends FrameLayout {
*
* @param month The month in the year
*/
/**
* @classname: DateTimePicker
* @methodname: setCurrentMonth
* @description:Set current month in the year
* @date: 2024/1/7 9:56
* @author: wangrunze
* @param:current month
*/
public void setCurrentMonth(int month) {
if (!mInitialising && month == getCurrentMonth()) {
return;
@ -322,6 +433,14 @@ public class DateTimePicker extends FrameLayout {
*
* @return The day of the month
*/
/**
* @classname: DateTimePicker
* @methodname: getCurrentDay
* @description:Get current day of the month
* @date: 2024/1/7 9:57
* @author: wangrunze
* @return:current day
*/
public int getCurrentDay() {
return mDate.get(Calendar.DAY_OF_MONTH);
}
@ -331,6 +450,14 @@ public class DateTimePicker extends FrameLayout {
*
* @param dayOfMonth The day of the month
*/
/**
* @classname: DateTimePicker
* @methodname: setCurrentDay
* @description:Set current day of the month
* @date: 2024/1/7 9:57
* @author: wangrunze
* @param:The day of the month
*/
public void setCurrentDay(int dayOfMonth) {
if (!mInitialising && dayOfMonth == getCurrentDay()) {
return;
@ -344,10 +471,26 @@ public class DateTimePicker extends FrameLayout {
* Get current hour in 24 hour mode, in the range (0~23)
* @return The current hour in 24 hour mode
*/
/**
* @classname: DateTimePicker
* @methodname: getCurrentHourOfDay
* @description:Get current hour in 24 hour mode
* @date: 2024/1/7 9:58
* @author: wangrunze
* @return:The current hour in 24 hour mode
*/
public int getCurrentHourOfDay() {
return mDate.get(Calendar.HOUR_OF_DAY);
}
/**
* @classname: DateTimePicker
* @methodname: getCurrentHour
* @description:Get current hour
* @date: 2024/1/7 9:58
* @author: wangrunze
* @return:The current hour
*/
private int getCurrentHour() {
if (mIs24HourView){
return getCurrentHourOfDay();
@ -366,6 +509,14 @@ public class DateTimePicker extends FrameLayout {
*
* @param hourOfDay
*/
/**
* @classname: DateTimePicker
* @methodname: setCurrentHour
* @description:Set current hour in 24 hour mode
* @date: 2024/1/7 9:59
* @author: wangrunze
* @param:hourOfDay
*/
public void setCurrentHour(int hourOfDay) {
if (!mInitialising && hourOfDay == getCurrentHourOfDay()) {
return;
@ -394,6 +545,14 @@ public class DateTimePicker extends FrameLayout {
*
* @return The Current Minute
*/
/**
* @classname: DateTimePicker
* @methodname: getCurrentMinute
* @description: Get currentMinute
* @date: 2024/1/7 9:59
* @author: wangrunze
* @return:The Current Minute
*/
public int getCurrentMinute() {
return mDate.get(Calendar.MINUTE);
}
@ -401,6 +560,14 @@ public class DateTimePicker extends FrameLayout {
/**
* Set current minute
*/
/**
* @classname: DateTimePicker
* @methodname: setCurrentMinute
* @description:Set current minute
* @date: 2024/1/7 9:59
* @author: wangrunze
* @param:int minute
*/
public void setCurrentMinute(int minute) {
if (!mInitialising && minute == getCurrentMinute()) {
return;
@ -413,6 +580,14 @@ public class DateTimePicker extends FrameLayout {
/**
* @return true if this is in 24 hour view else false.
*/
/**
* @classname: DateTimePicker
* @methodname: is24HourView
* @description:24Hour
* @date: 2024/1/7 10:00
* @author: wangrunze
* @return:true if this is in 24 hour view else false.
*/
public boolean is24HourView () {
return mIs24HourView;
}
@ -422,6 +597,14 @@ public class DateTimePicker extends FrameLayout {
*
* @param is24HourView True for 24 hour mode. False for AM/PM mode.
*/
/**
* @classname: DateTimePicker
* @methodname: set24HourView
* @description:Set whether in 24 hour or AM/PM mode
* @date: 2024/1/7 10:01
* @author: wangrunze
* @param:is24HourView True for 24 hour mode
*/
public void set24HourView(boolean is24HourView) {
if (mIs24HourView == is24HourView) {
return;
@ -434,6 +617,13 @@ public class DateTimePicker extends FrameLayout {
updateAmPmControl();
}
/**
* @classname: DateTimePicker
* @methodname: updateDateControl
* @description:
* @date: 2023/12/29 11:53
* @author: wangrunze
*/
private void updateDateControl() {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(mDate.getTimeInMillis());
@ -448,6 +638,13 @@ public class DateTimePicker extends FrameLayout {
mDateSpinner.invalidate();
}
/**
* @classname: DateTimePicker
* @methodname: updateDateControl
* @description:ampm
* @date: 2023/12/29 11:53
* @author: wangrunze
*/
private void updateAmPmControl() {
if (mIs24HourView) {
mAmPmSpinner.setVisibility(View.GONE);
@ -458,6 +655,13 @@ public class DateTimePicker extends FrameLayout {
}
}
/**
* @classname: DateTimePicker
* @methodname: updateDateControl
* @description:
* @date: 2023/12/29 11:53
* @author: wangrunze
*/
private void updateHourControl() {
if (mIs24HourView) {
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW);
@ -476,6 +680,13 @@ public class DateTimePicker extends FrameLayout {
mOnDateTimeChangedListener = callback;
}
/**
* @classname: DateTimePicker
* @methodname: onDateTimeChanged
* @description:
* @date: 2023/12/29 11:54
* @author: wangrunze
*/
private void onDateTimeChanged() {
if (mOnDateTimeChangedListener != null) {
mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(),

@ -29,17 +29,31 @@ import android.content.DialogInterface.OnClickListener;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
/**
* @classname: DateTimePickerDialog
* @description:
* @date: 2024/1/4 10:19
* @author: wangrunze
*/
public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
private Calendar mDate = Calendar.getInstance();
private boolean mIs24HourView;
private OnDateTimeSetListener mOnDateTimeSetListener;
private DateTimePicker mDateTimePicker;
private DateTimePicker mDateTimePicker;//DateTimePicker控件控件一般用于让用户可以从日期列表中选择单个值。
public interface OnDateTimeSetListener {
void OnDateTimeSet(AlertDialog dialog, long date);
}
/**
* @classname: DateTimePickerDialog
* @methodname: DateTimePickerDialog
* @description:
* @date: 2024/1/4 10:26
* @author: wangrunze
* @param:Context context
* @param:long date
*/
public DateTimePickerDialog(Context context, long date) {
super(context);
mDateTimePicker = new DateTimePicker(context);
@ -64,14 +78,35 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
updateTitle(mDate.getTimeInMillis());
}
/**
* @classname: DateTimePickerDialog
* @methodname: set24HourView
* @description:24
* @date: 2024/1/4 10:34
* @author: wangrunze
*/
public void set24HourView(boolean is24HourView) {
mIs24HourView = is24HourView;
}
/**
* @classname: DateTimePickerDialog
* @methodname: setOnDateTimeSetListener
* @description:
* @date: 2024/1/4 10:43
* @author: wangrunze
* @param:OnDateTimeSetListener callBack
*/
public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
mOnDateTimeSetListener = callBack;
}
/**
* @classname: DateTimePickerDialog
* @methodname: updateTitle
* @description:
* @date: 2024/1/4 10:55
* @author: wangrunze
* @param:long date
*/
private void updateTitle(long date) {
int flag =
DateUtils.FORMAT_SHOW_YEAR |
@ -80,7 +115,15 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR;
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
}
/**
* @classname: DateTimePickerDialog
* @methodname: onClick
* @description:
* @date: 2024/1/4 10:58
* @author: wangrunze
* @param:DialogInterface arg0
* @param:int arg1
*/
public void onClick(DialogInterface arg0, int arg1) {
if (mOnDateTimeSetListener != null) {
mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());

@ -26,12 +26,26 @@ import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import net.micode.notes.R;
/**
* @classname: DropdownMenu
* @description:
* @date: 2024/1/4 11:00
* @author: wangrunze
*/
public class DropdownMenu {
private Button mButton;
private PopupMenu mPopupMenu;
private Menu mMenu;
/**
* @classname: DropdownMenu
* @methodname: DropdownMenu
* @description:
* @date: 2024/1/4 11:02
* @author: wangrunze
* @param:Context context
* @param:Button button
* @param:int menuId
*/
public DropdownMenu(Context context, Button button, int menuId) {
mButton = button;
mButton.setBackgroundResource(R.drawable.dropdown_icon);
@ -44,17 +58,38 @@ public class DropdownMenu {
}
});
}
/**
* @classname: DropdownMenu
* @methodname: setOnDropdownMenuItemClickListener
* @description:
* @date: 2024/1/4 11:03
* @author: wangrunze
* @param:OnMenuItemClickListener listener
*/
public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) {
if (mPopupMenu != null) {
mPopupMenu.setOnMenuItemClickListener(listener);
}
}
/**
* @classname: DropdownMenu
* @methodname: findItem
* @description:
* @date: 2024/1/4 11:04
* @author: wangrunze
* @param:int id
*/
public MenuItem findItem(int id) {
return mMenu.findItem(id);
}
/**
* @classname: DropdownMenu
* @methodname: setTitle
* @description:
* @date: 2024/1/4 11:05
* @author: wangrunze
* @param:CharSequence title
*/
public void setTitle(CharSequence title) {
mButton.setText(title);
}

@ -28,26 +28,57 @@ import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
/**
* @classname: FoldersListAdapter
* @description:便
* @date: 2024/1/4 11:07
* @author: wangrunze
*/
public class FoldersListAdapter extends CursorAdapter {
public static final String [] PROJECTION = {
NoteColumns.ID,
NoteColumns.SNIPPET
};
};//调用数据库中便签的ID和片段
public static final int ID_COLUMN = 0;
public static final int NAME_COLUMN = 1;
/**
* @classname: FoldersListAdapter
* @methodname: FoldersListAdapter
* @description:
* @date: 2024/1/4 11:08
* @author: wangrunze
* @param:Context context
* @param: Cursor c
*/
public FoldersListAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
/**
* @classname: FoldersListAdapter
* @methodname: newView
* @description:
* @date: 2024/1/4 11:09
* @author: wangrunze
* @param:Context context
* @param:Cursor cursor
* @param:ViewGroup parent
*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new FolderListItem(context);
}
/**
* @classname: FoldersListAdapter
* @methodname: bindView
* @description:
* @date: 2024/1/4 11:10
* @author: wangrunze
* @param:View view
* @param:Context context
* @param:Cursor cursor
*/
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof FolderListItem) {
@ -56,22 +87,49 @@ public class FoldersListAdapter extends CursorAdapter {
((FolderListItem) view).bind(folderName);
}
}
/**
* @classname: FoldersListAdapter
* @methodname: getFolderName
* @description:
* @date: 2024/1/4 11:10
* @author: wangrunze
* @param:Context context
* @param:int position
*/
public String getFolderName(Context context, int position) {
Cursor cursor = (Cursor) getItem(position);
return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
}
/**
* @classname: FoldersListAdapter
* @description:
* @date: 2024/1/4 11:11
* @author: wangrunze
*/
private class FolderListItem extends LinearLayout {
private TextView mName;
/**
* @classname: FolderListItem
* @methodname: FolderListItem
* @description:
* @date: 2024/1/4 11:12
* @author: wangrunze
* @param:Context context
*/
public FolderListItem(Context context) {
super(context);
inflate(context, R.layout.folder_list_item, this);
mName = (TextView) findViewById(R.id.tv_folder_name);
}
/**
* @classname: FolderListItem
* @methodname: bind
* @description:
* @date: 2024/1/4 11:13
* @author: wangrunze
* @param:String name
*/
public void bind(String name) {
mName.setText(name);
}

@ -31,7 +31,12 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity;
/**
* @classname: NoteWidgetProvider
* @description:
* @date: 2024/1/7 10:22
* @author: wangrunze
*/
public abstract class NoteWidgetProvider extends AppWidgetProvider {
public static final String [] PROJECTION = new String [] {
NoteColumns.ID,
@ -45,6 +50,15 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
private static final String TAG = "NoteWidgetProvider";
/**
* @classname: NoteWidgetProvider
* @methodname: onDeleted
* @description:
* @date: 2024/1/7 10:23
* @author: wangrunze
* @param:Context context
* @param:int[] appWidgetIds
*/
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
ContentValues values = new ContentValues();
@ -56,7 +70,15 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
new String[] { String.valueOf(appWidgetIds[i])});
}
}
/**
* @classname: NoteWidgetProvider
* @methodname: getNoteWidgetInfo
* @description:
* @date: 2024/1/7 10:23
* @author: wangrunze
* @param:Context context
* @param:int widgetId
*/
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
@ -64,11 +86,30 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) },
null);
}
/**
* @classname: NoteWidgetProvider
* @methodname: update
* @description:
* @date: 2024/1/7 10:24
* @author: wangrunze
* @param:Context context
* @param:AppWidgetManager appWidgetManager
* @param:int[] appWidgetIds
*/
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
update(context, appWidgetManager, appWidgetIds, false);
}
/**
* @classname: NoteWidgetProvider
* @methodname: update
* @description:
* @date: 2024/1/7 10:24
* @author: wangrunze
* @param:Context context
* @param:AppWidgetManager appWidgetManager
* @param:int[] appWidgetIds
* @param:boolean privacyMode
*/
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
boolean privacyMode) {
for (int i = 0; i < appWidgetIds.length; i++) {

@ -23,24 +23,61 @@ import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
/**
* @classname: NoteWidgetProvider_2x
* @description:2*2
* @date: 2024/1/7 10:27
* @author: wangrunze
*/
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
@Override
/**
* @classname: NoteWidgetProvider_2x
* @methodname: onUpdate
* @description:
* @date: 2024/1/7 10:29
* @author: wangrunze
* @param:Context context
* @param:AppWidgetManager appWidgetManager
* @param:int[] appWidgetIds
*/
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
@Override
/**
* @classname: NoteWidgetProvider_2x
* @methodname: getLayoutId
* @description:ID
* @date: 2024/1/7 10:30
* @author: wangrunze
*/
protected int getLayoutId() {
return R.layout.widget_2x;
}
@Override
/**
* @classname: NoteWidgetProvider_2x
* @methodname: getBgResourceId
* @description:2ID
* @date: 2024/1/7 10:31
* @author: wangrunze
* @param:int bgId
*/
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
@Override
/**
* @classname: NoteWidgetProvider_2x
* @methodname: getWidgetType
* @description:
* @date: 2024/1/7 10:31
* @author: wangrunze
*/
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X;
}

@ -23,23 +23,59 @@ import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
/**
* @classname: NoteWidgetProvider_4x
* @description:4*1
* @date: 2024/1/7 10:32
* @author: wangrunze
*/
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
@Override
/**
* @classname: NoteWidgetProvider_4x
* @methodname: onUpdate
* @description:
* @date: 2024/1/7 10:32
* @author: wangrunze
* @param:Context context
* @param:AppWidgetManager appWidgetManager
* @param: int[] appWidgetIds
*/
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
/**
* @classname: NoteWidgetProvider_4x
* @methodname: getLayoutId
* @description:ID
* @date: 2024/1/7 10:33
* @author: wangrunze
*/
protected int getLayoutId() {
return R.layout.widget_4x;
}
@Override
/**
* @classname: NoteWidgetProvider_4x
* @methodname: getBgResourceId
* @description:4ID
* @date: 2024/1/7 10:33
* @author: wangrunze
* @param:int bgId
*/
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
}
@Override
/**
* @classname: NoteWidgetProvider_4x
* @methodname: getWidgetType
* @description:
* @date: 2024/1/7 10:34
* @author: wangrunze
*/
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X;
}

Loading…
Cancel
Save