Compare commits

..

1 Commits

@ -1,131 +0,0 @@
package net.micode.notes.ui;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.widget.Toast;
import android.view.View;
import net.micode.notes.R;
import java.io.InputStream;
public class BackgroundManager {
public static final int REQUEST_CODE_PICK_IMAGE = 2001;
private static final String PREF_BG_TYPE = "pref_bg_type"; // 0=color,1=builtin,2=uri
private static final String PREF_BG_COLOR = "pref_bg_color";
private static final String PREF_BG_RES_ID = "pref_bg_res_id";
private static final String PREF_BG_URI = "pref_bg_uri";
private static final int BG_TYPE_COLOR = 0;
private static final int BG_TYPE_BUILTIN = 1;
private static final int BG_TYPE_URI = 2;
private Activity mActivity;
private View mRootView;
public BackgroundManager(Activity activity, int rootViewId) {
mActivity = activity;
mRootView = activity.findViewById(rootViewId);
if (mRootView == null) {
mRootView = activity.getWindow().getDecorView();
}
}
public void applyBackgroundFromPrefs() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mActivity);
int type = sp.getInt(PREF_BG_TYPE, -1);
if (type == BG_TYPE_COLOR) {
int color = sp.getInt(PREF_BG_COLOR, 0xFFFFFFFF);
applyColorBackground(color);
} else if (type == BG_TYPE_BUILTIN) {
int resId = sp.getInt(PREF_BG_RES_ID, R.drawable.list_background);
applyBuiltinBackground(resId);
} else if (type == BG_TYPE_URI) {
String uriStr = sp.getString(PREF_BG_URI, null);
if (uriStr != null) {
applyUriBackground(Uri.parse(uriStr));
}
} else {
mRootView.setBackgroundResource(R.drawable.list_background);
}
}
public void applyColorAndSave(int color) {
applyColorBackground(color);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mActivity);
sp.edit().putInt(PREF_BG_TYPE, BG_TYPE_COLOR).putInt(PREF_BG_COLOR, color).commit();
}
public void applyBuiltinAndSave(int resId) {
applyBuiltinBackground(resId);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mActivity);
sp.edit().putInt(PREF_BG_TYPE, BG_TYPE_BUILTIN).putInt(PREF_BG_RES_ID, resId).commit();
}
public void pickImageFromGallery() {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
mActivity.startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE);
}
public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PICK_IMAGE && resultCode == Activity.RESULT_OK && data != null) {
Uri uri = data.getData();
if (uri != null) {
applyUriAndSave(uri);
}
return true;
}
return false;
}
public void resetToDefaultAndClear() {
mRootView.setBackgroundResource(R.drawable.list_background);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mActivity);
sp.edit().remove(PREF_BG_TYPE).remove(PREF_BG_COLOR).remove(PREF_BG_RES_ID).remove(PREF_BG_URI).commit();
}
private void applyColorBackground(int color) {
mRootView.setBackgroundColor(color);
}
private void applyBuiltinBackground(int resId) {
mRootView.setBackgroundResource(resId);
}
private void applyUriBackground(Uri uri) {
try {
InputStream is = mActivity.getContentResolver().openInputStream(uri);
if (is != null) {
Drawable d = Drawable.createFromStream(is, uri.toString());
mRootView.setBackgroundDrawable(d);
is.close();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(mActivity, "无法加载图片", Toast.LENGTH_SHORT).show();
}
}
private void applyUriAndSave(Uri uri) {
try {
InputStream is = mActivity.getContentResolver().openInputStream(uri);
if (is != null) {
Drawable d = Drawable.createFromStream(is, uri.toString());
mRootView.setBackgroundDrawable(d);
is.close();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mActivity);
sp.edit().putInt(PREF_BG_TYPE, BG_TYPE_URI).putString(PREF_BG_URI, uri.toString()).commit();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(mActivity, "无法加载图片", Toast.LENGTH_SHORT).show();
}
}
}

@ -1,102 +0,0 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
import net.micode.notes.data.Notes;
/**
* 广
*/
public class CallRecordReceiver extends BroadcastReceiver {
private static final String TAG = "CallRecordReceiver";
private static String mLastPhoneNumber;// 记录最后一个电话号码
private static long mCallStartTime;// 记录通话开始时间
private static boolean mIsOutgoingCall;// 是否为拨出电话
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
Log.d(TAG, "Received broadcast: " + intent.getAction());
if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.d(TAG, "Phone state changed: " + state + ", number: " + phoneNumber);
if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
// 电话响铃,记录来电号码
mLastPhoneNumber = phoneNumber;
mCallStartTime = System.currentTimeMillis();
mIsOutgoingCall = false;
Log.d(TAG, "Incoming call ringing: " + phoneNumber);
} else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)) {
// 电话接通,记录开始时间
if (mCallStartTime == 0) {
mCallStartTime = System.currentTimeMillis();
}
if (phoneNumber != null) {
mLastPhoneNumber = phoneNumber;
}
Log.d(TAG, "Call answered");
} else if (TelephonyManager.EXTRA_STATE_IDLE.equals(state)) {
// 电话挂断,创建通话记录便签
if (mLastPhoneNumber != null && mCallStartTime > 0) {
long callEndTime = System.currentTimeMillis();
long callDuration = callEndTime - mCallStartTime;
// 创建通话记录便签
Log.d(TAG, "Call ended, creating call note for: " + mLastPhoneNumber);
Intent serviceIntent = new Intent(context, CallRecordService.class);
serviceIntent.putExtra(TelephonyManager.EXTRA_INCOMING_NUMBER, mLastPhoneNumber);
serviceIntent.putExtra("call_date", callEndTime);
serviceIntent.putExtra("call_duration", callDuration);
// 启动服务创建通话记录便签
try {
context.startService(serviceIntent);
Log.d(TAG, "Successfully started CallRecordService");
} catch (Exception e) {
Log.e(TAG, "Error starting CallRecordService", e);
}
}
// 重置状态
mLastPhoneNumber = null;
mCallStartTime = 0;
mIsOutgoingCall = false;
Log.d(TAG, "Call state reset to idle");
}
} else if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
// 拨出电话
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if (phoneNumber != null) {
mLastPhoneNumber = phoneNumber;
mCallStartTime = System.currentTimeMillis();
mIsOutgoingCall = true;
Log.d(TAG, "Outgoing call started: " + phoneNumber);
}
}
}
}
}

@ -1,105 +0,0 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
import net.micode.notes.data.Notes;
import net.micode.notes.model.WorkingNote;
import net.micode.notes.tool.ResourceParser;
/**
* 便
*/
public class CallRecordService extends IntentService {
private static final String TAG = "CallRecordService";
public CallRecordService() {
super("CallRecordService");
}
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
String phoneNumber = intent.getStringExtra(android.telephony.TelephonyManager.EXTRA_INCOMING_NUMBER);
long callDate = intent.getLongExtra("call_date", System.currentTimeMillis());
long callDuration = intent.getLongExtra("call_duration", 0);
if (phoneNumber != null) {
Log.d(TAG, "Creating call note for number: " + phoneNumber + ", date: " + callDate);
createCallNote(phoneNumber, callDate, callDuration);
}
}
}
/**
* 便
* @param phoneNumber
* @param callDate
* @param callDuration
*/
private void createCallNote(String phoneNumber, long callDate, long callDuration) {
try {
Log.d(TAG, "Starting createCallNote for number: " + phoneNumber);
// 创建空便签
WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_CALL_RECORD_FOLDER,
0, Notes.TYPE_WIDGET_INVALIDE, ResourceParser.BLUE);
// 转换为通话便签
note.convertToCallNote(phoneNumber, callDate);
// 设置空格作为内容,确保能保存
note.setWorkingText(" ");
// 保存便签获取ID
long noteId = -1;
if (note.saveNote()) {
noteId = note.getNoteId();
Log.d(TAG, "Call note created successfully for: " + phoneNumber + ", noteId: " + noteId);
} else {
Log.e(TAG, "Failed to create call note for: " + phoneNumber);
return;
}
// 跳转到刚刚创建的通话记录便签的编辑视图
if (noteId > 0) {
Log.d(TAG, "Attempting to start NoteEditActivity for noteId: " + noteId);
Intent intent = new Intent(this, NoteEditActivity.class);
// 使用 ACTION_VIEW 以便 NoteEditActivity 正确处理并打开已有便签
intent.setAction(Intent.ACTION_VIEW);
// 使用正确的键名传递便签ID
intent.putExtra(Intent.EXTRA_UID, noteId);
intent.putExtra(Notes.INTENT_EXTRA_CALL_DATE, callDate);
intent.putExtra("phone_number", phoneNumber);
// 从服务启动 Activity需要 NEW_TASK 标志;避免清除整个任务栈
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
Log.d(TAG, "Successfully started NoteEditActivity for call note: " + noteId);
} catch (Exception e) {
Log.e(TAG, "Error starting NoteEditActivity", e);
}
}
} catch (Exception e) {
Log.e(TAG, "Error creating call note", e);
}
}
}

@ -59,7 +59,7 @@ import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import net.micode.notes.ui.BackgroundManager;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
@ -72,12 +72,6 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import net.micode.notes.widget.NoteWidgetProvider_2x;
import net.micode.notes.widget.NoteWidgetProvider_4x;
import android.net.Uri;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@ -154,18 +148,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
setContentView(R.layout.note_list);
initResources();
// 注册Android 13+的返回键回调
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
android.window.OnBackInvokedDispatcher.PRIORITY_DEFAULT,
new android.window.OnBackInvokedCallback() {
@Override
public void onBackInvoked() {
handleBackPress();
}
}
);
}
/**
* Insert an introduction when user firstly use this application
*/
@ -174,10 +156,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {// 处理子活动返回结果
//如果是背景管理器的结果,交给背景管理器处理
if (mBackgroundManager != null && mBackgroundManager.handleActivityResult(requestCode, resultCode, data)) {
return;
}
if (resultCode == RESULT_OK
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
mNotesListAdapter.changeCursor(null);
@ -267,62 +245,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mTitleBar = (TextView) findViewById(R.id.tv_title_bar);
mState = ListEditState.NOTE_LIST;
mModeCallBack = new ModeCallback();
//初始化背景管理器
mNotesRootView = findViewById(R.id.notes_root);
mBackgroundManager = new BackgroundManager(this, R.id.notes_root);
mBackgroundManager.applyBackgroundFromPrefs();
}
//显示背景设置对话框
private void showBackgroundSettingsDialog() {
final String[] options = new String[] {"纯色背景", "系统内置图片", "从相册选择", "恢复默认"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("选择背景");
builder.setItems(options, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
showColorChoiceDialog();
} else if (which == 1) {
showBuiltinChoiceDialog();
} else if (which == 2) {
if (mBackgroundManager != null) mBackgroundManager.pickImageFromGallery();
} else if (which == 3) {
if (mBackgroundManager != null) mBackgroundManager.resetToDefaultAndClear();
}
}
});
builder.show();
}
private void showColorChoiceDialog() {
final int[] colors = new int[] {0xFFFFFFFF, 0xFFFFFFCC, 0xFFFFF0F0, 0xFFE8FFF0, 0xFFDDE8FF};
final String[] names = new String[] {"白色", "浅黄", "浅红", "浅绿", "浅蓝"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("选择纯色背景");
builder.setItems(names, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
int color = colors[which];
if (mBackgroundManager != null) mBackgroundManager.applyColorAndSave(color);
}
});
builder.show();
}
private void showBuiltinChoiceDialog() {
final int[] resIds = new int[] {R.drawable.background_1, R.drawable.background_2, R.drawable.background_3, R.drawable.background_4};
final String[] names = new String[] {"预设1", "预设2", "预设3", "预设4"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("选择内置背景");
builder.setItems(names, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
int resId = resIds[which];
if (mBackgroundManager != null) mBackgroundManager.applyBuiltinAndSave(resId);
}
});
builder.show();
}
/**
*
*/
@ -785,17 +709,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
@Override
public void onBackPressed() {
handleBackPress();
}
public void handleBackPress() {// 处理返回键按下事件,根据当前状态执行相应操作
public void onBackPressed() {// 处理返回键事件
switch (mState) {
case SUB_FOLDER:// 返回上一级文件夹
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST;
mTitleBar.setVisibility(View.GONE);
startAsyncNotesListQuery();
invalidateOptionsMenu();
mTitleBar.setVisibility(View.GONE);
break;
case CALL_RECORD_FOLDER:// 返回上一级通话记录文件夹
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
@ -938,9 +858,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
break;
}
//如果是背景设置菜单项
case R.id.menu_background_settings: {
showBackgroundSettingsDialog();
case R.id.menu_search:{
onSearchRequested();
break;
}
default:

Loading…
Cancel
Save