7474import androidx .annotation .NonNull ;
7575import androidx .appcompat .app .AlertDialog ;
7676import androidx .appcompat .app .AppCompatDialogFragment ;
77+ import androidx .appcompat .view .ContextThemeWrapper ;
78+ import androidx .appcompat .widget .PopupMenu ;
7779import androidx .swiperefreshlayout .widget .SwipeRefreshLayout ;
7880import androidx .appcompat .app .ActionBar ;
7981import androidx .appcompat .app .AppCompatActivity ;
8486import android .text .format .DateUtils ;
8587import android .text .method .LinkMovementMethod ;
8688import android .util .Log ;
89+ import android .view .Gravity ;
8790import android .view .KeyEvent ;
8891import android .view .LayoutInflater ;
8992import android .view .Menu ;
@@ -181,6 +184,8 @@ public final class RSSReader extends AppCompatActivity implements FileHandler, A
181184 public static final String PREF_CLIENT_VERSION = "client_version" ;
182185 public static final String PREF_FEED_ID = "news_feed" ;
183186
187+ public static final String PREF_BRICIOLA = "briciola" ;//used in place of Settings.Secure.ANDROID_ID, DO NOT insert this in backable_prefs
188+
184189 private final static String tag = "RSSReader" ;
185190
186191 public final static String uniqueWorkerName = "RSSReaderService" ;
@@ -221,23 +226,30 @@ else if (lang_code.startsWith("de"))
221226
222227 private final FileManager mBackupRestore = new FileManager (this , this , true , APP_FOLDER );
223228
224- /** Called when the activity is first created. */
225- @ SuppressLint ("NewApi" )
226229 @ Override
227- public void onCreate (Bundle savedInstanceState ) {
228- prefs = PreferenceManager .getDefaultSharedPreferences (this );
230+ public Resources .Theme getTheme () {
231+ Resources .Theme theme = super .getTheme ();
232+ SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences (this );
229233 int theme_idx = get_theme_idx (prefs , getResources ());
230234 int background = preset_colors [theme_idx ][0 ];
231235 if (!isDarkColor (background )) { // light background
232- setTheme (R .style .ThemeLightNoActionBar );
236+ theme . applyStyle (R .style .ThemeLightNoActionBar , true );
233237 } else { // dark background
234- setTheme (R .style .ThemeNoActionBar );
238+ theme . applyStyle (R .style .ThemeNoActionBar , true );
235239 }
240+ return theme ;
241+ }
242+
243+ /** Called when the activity is first created. */
244+ @ SuppressLint ("NewApi" )
245+ @ Override
246+ public void onCreate (Bundle savedInstanceState ) {
236247 super .onCreate (savedInstanceState );
237248 if (BuildConfig .DEBUG )
238249 Log .d (tag , "onCreate" );
239250
240251 setContentView (R .layout .main );
252+ prefs = PreferenceManager .getDefaultSharedPreferences (this );
241253
242254 System .setProperty ("http.keepAlive" , "false" ); // workaround to avoid responseCode = -1 problem
243255
@@ -336,7 +348,7 @@ public void run() {
336348 Uri intent_data = intent .getData ();
337349 if (intent_data != null ) {
338350 if (BuildConfig .DEBUG )
339- Log .d (tag , "intent uri: " + intent_data . toString () );
351+ Log .d (tag , "intent uri: " + intent_data );
340352//TODO: process feed via intent
341353//command: adb shell am start -W -a android.intent.action.VIEW -d "<replace with url to feed>" -t "application/rss+xml"
342354 }
@@ -434,11 +446,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
434446 inflater .inflate (R .menu .menu , menu );
435447 ttsplay = menu .findItem (R .id .menu_play );
436448 ttsplay .setShowAsAction (MenuItem .SHOW_AS_ACTION_IF_ROOM );
437-
438- if (Build .VERSION .SDK_INT > Build .VERSION_CODES .Q ) {//scopedstorage
439- MenuItem restore = menu .findItem (R .id .menu_restore );//scopedstorage
440- restore .getSubMenu ().clear ();//scopedstorage - disable (local restore / external restore)
441- }
442449 return true ;
443450 }
444451
@@ -455,7 +462,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
455462
456463 @ Override
457464 public boolean onOptionsItemSelected (MenuItem item ) {
458- // Handle item selection
465+ // Handle item selection
459466 int itemId = item .getItemId ();
460467 if (itemId == R .id .menu_preferences ) {
461468 showPreferences ();
@@ -515,16 +522,27 @@ public boolean onOptionsItemSelected(MenuItem item) {
515522 } else if (itemId == R .id .menu_backup ) {
516523 doBackup (prefs , mBackupRestore , getResources ());
517524 return true ;
518- } else if (itemId == R .id .menu_local_storage ) {//restore from local storage (direct) - not valid for Android 11 or later
519- mBackupRestore .readLocalFile (EXTENDED_BACKUP_FILENAME , BACKUP_FILENAME );//scopedstorage
520- return true ;
521525 } else if (itemId == R .id .menu_restore ) {//scopedstorage (purtroppo in Android 11 non si riesce ad usare in modo sicuro filename2uri_downloads_Q(), quindi usiamo per il restore comunque il SAF, come nel caso di storage esterno
522526 if (Build .VERSION .SDK_INT > Build .VERSION_CODES .Q ) {
523527 mBackupRestore .openFileSAF (EXTENDED_BACKUP_MIMETYPE_ONEDRIVE , false );//scopedstorage, use SAF on Android 11 or later
524- } // else ignore
525- return true ;
526- } else if (itemId == R .id .menu_ext_storage ) {//restore from external storage - not valid for Android 11 or later
527- mBackupRestore .readExternalFile ();
528+ } else {
529+ //18-09-2022: nuova gestione con PopupMenu per evitare problemi in ChromeOS basato su Android 11 (o superiore)
530+ //PopupMenu risolve problema del passaggio del mouse sopra la voce del menu 'restore' che apre il filemanager su ChromeOS in modo indesiderato
531+ PopupMenu popup = showRestorePopup (findViewById (R .id .my_toolbar ), Gravity .END );
532+
533+ popup .setOnMenuItemClickListener (item1 -> {
534+ // mDrawerLayout.closeDrawer(mDrawerList);
535+ int itemId1 = item1 .getItemId ();
536+ if (itemId1 == R .id .menu_ext_storage ) {//restore from external storage
537+ mBackupRestore .readExternalFile ();
538+ return true ;
539+ } else if (itemId1 == R .id .menu_local_storage ) {//restore from local storage (direct)
540+ mBackupRestore .readLocalFile (EXTENDED_BACKUP_FILENAME , BACKUP_FILENAME );//scopedstorage
541+ return true ;
542+ }
543+ return false ;//never happen
544+ });
545+ }
528546 return true ;
529547 } else if (itemId == R .id .menu_exit ) {
530548 finishAffinity ();//nn
@@ -538,6 +556,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
538556 return super .onOptionsItemSelected (item );
539557 }
540558
559+ private PopupMenu showRestorePopup (View view , int gravity ) {
560+ Context wrapper = new ContextThemeWrapper (RSSReader .this , R .style .MyPopupMenu );//18-09-2022: aggiunto wrapper per risolvere un problema sul colore del testo del popup quando il tema è scuro
561+ PopupMenu popup = new PopupMenu (wrapper , view , gravity );
562+ Menu popmenu = popup .getMenu ();
563+ popmenu .add (Menu .NONE , R .id .menu_local_storage , Menu .NONE , R .string .local_storage );//menu_local_storage is hidden in buildNavDrawerItems()
564+ popmenu .add (Menu .NONE , R .id .menu_ext_storage , Menu .NONE , R .string .ext_storage );//menu_ext_storage is hidden in buildNavDrawerItems()
565+
566+ popup .show ();
567+ return popup ;
568+ }
569+
541570 private static void doBackup (SharedPreferences prefs , FileManager mBackupRestore , Resources resources ) {
542571 if (Build .VERSION .SDK_INT > Build .VERSION_CODES .Q ) {//scopedstorage
543572 mBackupRestore .createFileSAF (EXTENDED_BACKUP_FILENAME );//scopedstorage
@@ -676,7 +705,7 @@ private void showPreferences() {
676705
677706 @ Override
678707 public void onRequestPermissionsResult (int requestCode ,
679- String [] permissions , int [] grantResults ) {
708+ @ NonNull String [] permissions , int [] grantResults ) {
680709 if (grantResults .length > 0 && grantResults [0 ] == PackageManager .PERMISSION_GRANTED ) {
681710 mBackupRestore .processRequestPermissionsResult (requestCode );
682711 } else {// permission denied
0 commit comments