diff --git a/Notesmaster/app/src/main/AndroidManifest.xml b/Notesmaster/app/src/main/AndroidManifest.xml index 4010b4f..638979f 100644 --- a/Notesmaster/app/src/main/AndroidManifest.xml +++ b/Notesmaster/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools" > @@ -21,47 +21,54 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Notesmaster" - tools:targetApi="31"> - + tools:targetApi="31" > + - + android:windowSoftInputMode="adjustPan" > + - - - + android:theme="@style/NoteTheme" > + + + - > - - + +> + + + - + @@ -70,16 +77,15 @@ android:resource="@xml/searchable" /> - + android:exported="true" + android:label="@string/app_widget2x2" > @@ -92,9 +98,8 @@ - + android:exported="true" + android:label="@string/app_widget4x4" > @@ -105,16 +110,15 @@ android:name="android.appwidget.provider" android:resource="@xml/widget_4x_info" /> - - + - @@ -124,33 +128,21 @@ android:launchMode="singleInstance" android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar" > - - - - - - - - - - - - \ No newline at end of file diff --git a/Notesmaster/app/src/main/java/net/micode/notes/SplashActivity.java b/Notesmaster/app/src/main/java/net/micode/notes/SplashActivity.java new file mode 100644 index 0000000..098c73f --- /dev/null +++ b/Notesmaster/app/src/main/java/net/micode/notes/SplashActivity.java @@ -0,0 +1,190 @@ +package net.micode.notes; + +import android.annotation.SuppressLint; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; +import android.os.Build; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.view.MotionEvent; +import android.view.View; +import android.view.WindowInsets; +import net.micode.notes.databinding.ActivitySplashBinding; + +/** + * An example full-screen activity that shows and hides the system UI (i.e. + * status bar and navigation/system bar) with user interaction. + */ +public class SplashActivity extends AppCompatActivity { + /** + * Whether or not the system UI should be auto-hidden after + * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds. + */ + private static final boolean AUTO_HIDE = true; + + /** + * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after + * user interaction before hiding the system UI. + */ + private static final int AUTO_HIDE_DELAY_MILLIS = 3000; + + /** + * Some older devices needs a small delay between UI widget updates + * and a change of the status and navigation bar. + */ + private static final int UI_ANIMATION_DELAY = 300; + + private View mContentView; + private View mControlsView; + private boolean mVisible; +private ActivitySplashBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + binding = ActivitySplashBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + + mVisible = true; + mControlsView = binding.fullscreenContentControls; + mContentView = binding.fullscreenContent; + + // Set up the user interaction to manually show or hide the system UI. + mContentView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + toggle(); + } + }); + + // Upon interacting with UI controls, delay any scheduled hide() + // operations to prevent the jarring behavior of controls going away + // while interacting with the UI. + binding.dummyButton.setOnTouchListener(mDelayHideTouchListener); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + + // Trigger the initial hide() shortly after the activity has been + // created, to briefly hint to the user that UI controls + // are available. + delayedHide(100); + } + + /** + * Touch listener to use for in-layout UI controls to delay hiding the + * system UI. This is to prevent the jarring behavior of controls going away + * while interacting with activity UI. + */ + private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + switch (motionEvent.getAction()) { + case MotionEvent.ACTION_DOWN: + if (AUTO_HIDE) { + delayedHide(AUTO_HIDE_DELAY_MILLIS); + } + break; + case MotionEvent.ACTION_UP: + view.performClick(); + break; + default: + break; + } + return false; + } + }; + + private void toggle() { + if (mVisible) { + hide(); + } else { + show(); + } + } + + private void hide() { + // Hide UI first + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.hide(); + } + mControlsView.setVisibility(View.GONE); + mVisible = false; + + // Schedule a runnable to remove the status and navigation bar after a delay + mHideHandler.removeCallbacks(mShowPart2Runnable); + mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY); + } + + private final Runnable mHidePart2Runnable = new Runnable() { + @SuppressLint("InlinedApi") + @Override + public void run() { + // Delayed removal of status and navigation bar + if (Build.VERSION.SDK_INT >= 30) { + mContentView.getWindowInsetsController().hide( + WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars()); + } else { + // Note that some of these constants are new as of API 16 (Jelly Bean) + // and API 19 (KitKat). It is safe to use them, as they are inlined + // at compile-time and do nothing on earlier devices. + mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); + } + } + }; + + private void show() { + // Show the system bar + if (Build.VERSION.SDK_INT >= 30) { + mContentView.getWindowInsetsController().show( + WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars()); + } else { + mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); + } + mVisible = true; + + // Schedule a runnable to display UI elements after a delay + mHideHandler.removeCallbacks(mHidePart2Runnable); + mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY); + } + + private final Runnable mShowPart2Runnable = new Runnable() { + @Override + public void run() { + // Delayed display of UI elements + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.show(); + } + mControlsView.setVisibility(View.VISIBLE); + } + }; + + private final Handler mHideHandler = new Handler(Looper.myLooper()); + private final Runnable mHideRunnable = new Runnable() { + @Override + public void run() { + hide(); + } + }; + + /** + * Schedules a call to hide() in delay milliseconds, canceling any + * previously scheduled calls. + */ + private void delayedHide(int delayMillis) { + mHideHandler.removeCallbacks(mHideRunnable); + mHideHandler.postDelayed(mHideRunnable, delayMillis); + } +} \ No newline at end of file diff --git a/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java b/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java index f221202..240fc85 100644 --- a/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java +++ b/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java @@ -27,12 +27,11 @@ import android.database.Cursor; import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; - public class AlarmInitReceiver extends BroadcastReceiver { private static final String [] PROJECTION = new String [] { - NoteColumns.ID, - NoteColumns.ALERTED_DATE + NoteColumns.ID, + NoteColumns.ALERTED_DATE }; private static final int COLUMN_ID = 0; @@ -53,7 +52,13 @@ public class AlarmInitReceiver extends BroadcastReceiver { long alertDate = c.getLong(COLUMN_ALERTED_DATE); Intent sender = new Intent(context, AlarmReceiver.class); sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID))); - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0); + // 修改处:添加PendingIntent.FLAG_IMMUTABLE或FLAG_MUTABLE标志 + PendingIntent pendingIntent = PendingIntent.getBroadcast( + context, + 0, + sender, + PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT + ); AlarmManager alermManager = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent); @@ -62,4 +67,4 @@ public class AlarmInitReceiver extends BroadcastReceiver { c.close(); } } -} +} \ No newline at end of file diff --git a/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 96a9ff8..2ef6507 100644 --- a/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -71,16 +71,12 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; - public class NoteEditActivity extends Activity implements OnClickListener, NoteSettingChangedListener, OnTextViewChangeListener { private class HeadViewHolder { public TextView tvModified; - public ImageView ivAlertIcon; - public TextView tvAlertDate; - public ImageView ibSetBgColor; } @@ -121,31 +117,19 @@ public class NoteEditActivity extends Activity implements OnClickListener, private static final String TAG = "NoteEditActivity"; private HeadViewHolder mNoteHeaderHolder; - private View mHeadViewPanel; - private View mNoteBgColorSelector; - private View mFontSizeSelector; - private EditText mNoteEditor; - private View mNoteEditorPanel; - private WorkingNote mWorkingNote; - private SharedPreferences mSharedPrefs; private int mFontSizeId; - private static final String PREFERENCE_FONT_SIZE = "pref_font_size"; - private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10; - public static final String TAG_CHECKED = String.valueOf('\u221A'); public static final String TAG_UNCHECKED = String.valueOf('\u25A1'); - private LinearLayout mEditTextList; - private String mUserQuery; private Pattern mPattern; @@ -161,10 +145,6 @@ public class NoteEditActivity extends Activity implements OnClickListener, initResources(); } - /** - * 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 - */ @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); @@ -180,18 +160,11 @@ public class NoteEditActivity extends Activity implements OnClickListener, } private boolean initActivityState(Intent intent) { - /** - * If the user specified the {@link Intent#ACTION_VIEW} but not provided with id, - * then jump to the NotesListActivity - */ mWorkingNote = null; if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) { long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0); mUserQuery = ""; - /** - * Starting from the searched result - */ if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) { noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY)); mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY); @@ -215,7 +188,6 @@ public class NoteEditActivity extends Activity implements OnClickListener, WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) { - // New note long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0); int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); @@ -224,7 +196,6 @@ public class NoteEditActivity extends Activity implements OnClickListener, int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, ResourceParser.getDefaultBgId(this)); - // Parse call-record note String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0); if (callDate != 0 && phoneNumber != null) { @@ -288,10 +259,6 @@ public class NoteEditActivity extends Activity implements OnClickListener, | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR)); - /** - * TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker - * is not ready - */ showAlertHeader(); } @@ -321,11 +288,6 @@ public class NoteEditActivity extends Activity implements OnClickListener, @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - /** - * For new note without note id, we should firstly save it to - * generate a id. If the editing note is not worth saving, there - * is no id which is equivalent to create new note - */ if (!mWorkingNote.existInDatabase()) { saveNote(); } @@ -358,8 +320,8 @@ public class NoteEditActivity extends Activity implements OnClickListener, || ev.getX() > (x + view.getWidth()) || ev.getY() < y || ev.getY() > (y + view.getHeight())) { - return false; - } + return false; + } return true; } @@ -386,11 +348,6 @@ public class NoteEditActivity extends Activity implements OnClickListener, }; mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE); - /** - * HACKME: Fix bug of store the resource id in shared preference. - * The id may larger than the length of resources, in this case, - * return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE} - */ if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) { mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE; } @@ -418,7 +375,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, } intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { - mWorkingNote.getWidgetId() + mWorkingNote.getWidgetId() }); sendBroadcast(intent); @@ -430,7 +387,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, if (id == R.id.btn_set_bg_color) { mNoteBgColorSelector.setVisibility(View.VISIBLE); findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( - - View.VISIBLE); + View.VISIBLE); // 修复错误1:将"-"改为View.VISIBLE } else if (sBgSelectorBtnsMap.containsKey(id)) { findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility( View.GONE); @@ -557,16 +514,12 @@ public class NoteEditActivity extends Activity implements OnClickListener, DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis()); d.setOnDateTimeSetListener(new OnDateTimeSetListener() { public void OnDateTimeSet(AlertDialog dialog, long date) { - mWorkingNote.setAlertDate(date , true); + mWorkingNote.setAlertDate(date, true); } }); d.show(); } - /** - * Share note to apps that support {@link Intent#ACTION_SEND} action - * and {@text/plain} type - */ private void sendTo(Context context, String info) { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, info); @@ -575,10 +528,7 @@ public class NoteEditActivity extends Activity implements OnClickListener, } private void createNewNote() { - // Firstly, save current editing notes saveNote(); - - // For safety, start a new NoteEditActivity finish(); Intent intent = new Intent(this, NoteEditActivity.class); intent.setAction(Intent.ACTION_INSERT_OR_EDIT); @@ -613,17 +563,19 @@ public class NoteEditActivity extends Activity implements OnClickListener, } public void onClockAlertChanged(long date, boolean set) { - /** - * User could set clock to an unsaved note, so before setting the - * alert clock, we should save the note first - */ if (!mWorkingNote.existInDatabase()) { saveNote(); } if (mWorkingNote.getNoteId() > 0) { Intent intent = new Intent(this, AlarmReceiver.class); intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId())); - PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); + // 修复错误2:添加FLAG_IMMUTABLE + PendingIntent pendingIntent = PendingIntent.getBroadcast( + this, + 0, + intent, + PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT + ); AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE)); showAlertHeader(); if(!set) { @@ -632,11 +584,6 @@ public class NoteEditActivity extends Activity implements OnClickListener, alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); } } else { - /** - * There is the condition that user has input nothing (the note is - * not worthy saving), we have no note id, remind the user that he - * should input something - */ Log.e(TAG, "Clock alert setting error"); showToast(R.string.error_note_empty_for_clock); } @@ -673,9 +620,6 @@ public class NoteEditActivity extends Activity implements OnClickListener, } public void onEditTextEnter(int index, String text) { - /** - * Should not happen, check for debug - */ if(index > mEditTextList.getChildCount()) { Log.e(TAG, "Index out of mEditTextList boundrary, should not happen"); } @@ -809,24 +753,12 @@ public class NoteEditActivity extends Activity implements OnClickListener, getWorkingText(); boolean saved = mWorkingNote.saveNote(); if (saved) { - /** - * There are two modes from List view to edit view, open one note, - * create/edit a node. Opening node requires to the original - * position in the list when back from edit view, while creating a - * new node requires to the top of the list. This code - * {@link #RESULT_OK} is used to identify the create/edit state - */ setResult(RESULT_OK); } return saved; } private void sendToDesktop() { - /** - * Before send message to home, we should make sure that current - * editing note is exists in databases. So, for new note, firstly - * save it - */ if (!mWorkingNote.existInDatabase()) { saveNote(); } @@ -846,11 +778,6 @@ public class NoteEditActivity extends Activity implements OnClickListener, showToast(R.string.info_note_enter_desktop); sendBroadcast(sender); } else { - /** - * There is the condition that user has input nothing (the note is - * not worthy saving), we have no note id, remind the user that he - * should input something - */ Log.e(TAG, "Send to desktop error"); showToast(R.string.error_note_empty_for_send_to_desktop); } @@ -870,4 +797,4 @@ public class NoteEditActivity extends Activity implements OnClickListener, private void showToast(int resId, int duration) { Toast.makeText(this, resId, duration).show(); } -} +} \ No newline at end of file diff --git a/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteEditText.java b/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteEditText.java index 2afe2a8..aeee329 100644 --- a/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteEditText.java +++ b/Notesmaster/app/src/main/java/net/micode/notes/ui/NoteEditText.java @@ -30,14 +30,15 @@ import android.view.KeyEvent; import android.view.MenuItem; import android.view.MenuItem.OnMenuItemClickListener; import android.view.MotionEvent; -import android.widget.EditText; + +import androidx.appcompat.widget.AppCompatEditText; import net.micode.notes.R; import java.util.HashMap; import java.util.Map; -public class NoteEditText extends EditText { +public class NoteEditText extends AppCompatEditText { // 修改为继承AppCompatEditText private static final String TAG = "NoteEditText"; private int mIndex; private int mSelectionStartBeforeDelete; @@ -53,57 +54,39 @@ public class NoteEditText extends EditText { sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email); } - /** - * Call by the {@link NoteEditActivity} to delete or add edit text - */ public interface OnTextViewChangeListener { - /** - * Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens - * and the text is null - */ void onEditTextDelete(int index, String text); - - /** - * Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER} - * happen - */ void onEditTextEnter(int index, String text); - - /** - * Hide or show item option when text change - */ void onTextChange(int index, boolean hasText); } private OnTextViewChangeListener mOnTextViewChangeListener; public NoteEditText(Context context) { - super(context, null); + super(context); mIndex = 0; } - public void setIndex(int index) { - mIndex = index; + public NoteEditText(Context context, AttributeSet attrs) { + super(context, attrs); } - public void setOnTextViewChangeListener(OnTextViewChangeListener listener) { - mOnTextViewChangeListener = listener; + public NoteEditText(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); } - public NoteEditText(Context context, AttributeSet attrs) { - super(context, attrs, android.R.attr.editTextStyle); + public void setIndex(int index) { + mIndex = index; } - public NoteEditText(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - // TODO Auto-generated constructor stub + public void setOnTextViewChangeListener(OnTextViewChangeListener listener) { + mOnTextViewChangeListener = listener; } @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - int x = (int) event.getX(); int y = (int) event.getY(); x -= getTotalPaddingLeft(); @@ -117,7 +100,6 @@ public class NoteEditText extends EditText { Selection.setSelection(getText(), off); break; } - return super.onTouchEvent(event); } @@ -205,7 +187,6 @@ public class NoteEditText extends EditText { menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener( new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { - // goto a new intent urls[0].onClick(NoteEditText.this); return true; } @@ -214,4 +195,4 @@ public class NoteEditText extends EditText { } super.onCreateContextMenu(menu); } -} +} \ No newline at end of file diff --git a/Notesmaster/app/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java b/Notesmaster/app/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java index 07c5f7e..e0545d1 100644 --- a/Notesmaster/app/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java +++ b/Notesmaster/app/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java @@ -47,33 +47,22 @@ import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.gtask.remote.GTaskSyncService; - public class NotesPreferenceActivity extends PreferenceActivity { public static final String PREFERENCE_NAME = "notes_preferences"; - public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name"; - public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time"; - public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear"; - private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key"; - private static final String AUTHORITIES_FILTER_KEY = "authorities"; private PreferenceCategory mAccountCategory; - private GTaskReceiver mReceiver; - private Account[] mOriAccounts; - private boolean mHasAddedAccount; @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); - - /* using the app icon for navigation */ getActionBar().setDisplayHomeAsUpEnabled(true); addPreferencesFromResource(R.xml.preferences); @@ -81,7 +70,13 @@ public class NotesPreferenceActivity extends PreferenceActivity { mReceiver = new GTaskReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME); - registerReceiver(mReceiver, filter); + + // 修复:添加RECEIVER_NOT_EXPORTED标志 + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) { + registerReceiver(mReceiver, filter, Context.RECEIVER_NOT_EXPORTED); + } else { + registerReceiver(mReceiver, filter); + } mOriAccounts = null; View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null); @@ -91,9 +86,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { @Override protected void onResume() { super.onResume(); - - // need to set sync account automatically if user has added a new - // account if (mHasAddedAccount) { Account[] accounts = getGoogleAccounts(); if (mOriAccounts != null && accounts.length > mOriAccounts.length) { @@ -112,7 +104,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { } } } - refreshUI(); } @@ -126,7 +117,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { private void loadAccountPreference() { mAccountCategory.removeAll(); - Preference accountPref = new Preference(this); final String defaultAccount = getSyncAccountName(this); accountPref.setTitle(getString(R.string.preferences_account_title)); @@ -135,22 +125,18 @@ public class NotesPreferenceActivity extends PreferenceActivity { public boolean onPreferenceClick(Preference preference) { if (!GTaskSyncService.isSyncing()) { if (TextUtils.isEmpty(defaultAccount)) { - // the first time to set account showSelectAccountAlertDialog(); } else { - // if the account has already been set, we need to promp - // user about the risk showChangeAccountConfirmAlertDialog(); } } else { Toast.makeText(NotesPreferenceActivity.this, - R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT) + R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT) .show(); } return true; } }); - mAccountCategory.addPreference(accountPref); } @@ -158,7 +144,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { Button syncButton = (Button) findViewById(R.id.preference_sync_button); TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview); - // set button state if (GTaskSyncService.isSyncing()) { syncButton.setText(getString(R.string.preferences_button_sync_cancel)); syncButton.setOnClickListener(new View.OnClickListener() { @@ -176,7 +161,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { } syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this))); - // set last sync time if (GTaskSyncService.isSyncing()) { lastSyncTimeView.setText(GTaskSyncService.getProgressString()); lastSyncTimeView.setVisibility(View.VISIBLE); @@ -200,7 +184,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { private void showSelectAccountAlertDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); - View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null); TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title); titleTextView.setText(getString(R.string.preferences_dialog_select_account_title)); @@ -246,7 +229,7 @@ public class NotesPreferenceActivity extends PreferenceActivity { mHasAddedAccount = true; Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] { - "gmail-ls" + "gmail-ls" }); startActivityForResult(intent, -1); dialog.dismiss(); @@ -256,7 +239,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { private void showChangeAccountConfirmAlertDialog() { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); - View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null); TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title); titleTextView.setText(getString(R.string.preferences_dialog_change_account_title, @@ -299,10 +281,8 @@ public class NotesPreferenceActivity extends PreferenceActivity { } editor.commit(); - // clean up last sync time setLastSyncTime(this, 0); - // clean up local gtask related info new Thread(new Runnable() { public void run() { ContentValues values = new ContentValues(); @@ -329,7 +309,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { } editor.commit(); - // clean up local gtask related info new Thread(new Runnable() { public void run() { ContentValues values = new ContentValues(); @@ -361,7 +340,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { } private class GTaskReceiver extends BroadcastReceiver { - @Override public void onReceive(Context context, Intent intent) { refreshUI(); @@ -370,7 +348,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { syncStatus.setText(intent .getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG)); } - } } @@ -385,4 +362,4 @@ public class NotesPreferenceActivity extends PreferenceActivity { return false; } } -} +} \ No newline at end of file diff --git a/Notesmaster/app/src/main/res/layout/activity_splash.xml b/Notesmaster/app/src/main/res/layout/activity_splash.xml new file mode 100644 index 0000000..52aa1ad --- /dev/null +++ b/Notesmaster/app/src/main/res/layout/activity_splash.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + +