Skip to content

Commit

Permalink
fix: No toolbar menu button on Android TV
Browse files Browse the repository at this point in the history
Workaround: add option menu items to the "Apps" list item context menu.
  • Loading branch information
willemw12 committed Mar 17, 2024
1 parent 81da950 commit ebffaa2
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,117 @@
*/
package com.google.code.appsorganizer;

import static android.view.Menu.NONE;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.widget.Toast;

import com.google.code.appsorganizer.db.DatabaseHelper;
import com.google.code.appsorganizer.dialogs.GenericDialogManager;
import com.google.code.appsorganizer.dialogs.GenericDialogManagerActivity;
import com.google.code.appsorganizer.dialogs.OnOkClickListener;
import com.google.code.appsorganizer.model.AppCache;
import com.google.code.appsorganizer.preferences.PreferencesFromXml;

//import java.nio.DoubleBuffer;

/**
* @author fabio
*
*
*/
public class ApplicationContextMenuManager {

private static final int UNINSTALL = 2;
private static final int LAUNCH = 1;
private static final int CHOOSE_LABELS = 0;
private static final int SET_STAR = 3;
private static final int UNSET_STAR = 4;
private static final int APPINFO = 5;
private static final int UNINSTALL = 3;
private static final int LAUNCH = 2;
private static final int CHOOSE_LABELS = 1;
private static final int SET_STAR = 4;
private static final int UNSET_STAR = 5;
private static final int APPINFO = 6;

// Option menu items
private static final int NEW_LABEL = 7;
private static final int RELOAD = 8;
private static final int IMPORT_MENU = 9;
private static final int EXPORT_MENU = 10;
private static final int PREFERENCES = 11;

public static void createMenu(Context context, ContextMenu menu, String label, int id) {
menu.setHeaderTitle(label);
menu.add(0, CHOOSE_LABELS, 0, R.string.choose_labels_header);
menu.add(NONE, CHOOSE_LABELS, 0, R.string.choose_labels_header);
if (id >= 0) {
AppCache app = DatabaseHelper.initOrSingleton(context).appCacheDao.queryById(Long.valueOf(id));
menu.add(0, app.starred ? UNSET_STAR : SET_STAR,
menu.add(NONE, app.starred ? UNSET_STAR : SET_STAR,
1, app.starred ? R.string.unstar_app : R.string.star_app);
}
menu.add(0, LAUNCH, 2, R.string.launch);
menu.add(0, APPINFO, 3, R.string.appinfo);
menu.add(0, UNINSTALL, 4, R.string.uninstall);
menu.add(NONE, LAUNCH, 2, R.string.launch);
menu.add(NONE, APPINFO, 3, R.string.appinfo);
menu.add(NONE, UNINSTALL, 4, R.string.uninstall);

// Option menu items
// //menu.addSubMenu();
menu.add(0, NONE, 5, null);
menu.add(0, NEW_LABEL, 6, R.string.New_label);
menu.add(0, RELOAD, 7, R.string.reload_apps);
menu.add(0, IMPORT_MENU, 8, R.string.import_menu);
menu.add(0, EXPORT_MENU, 9, R.string.export_menu);
menu.add(0, PREFERENCES, 10, R.string.Preferences);
}

public static void onContextItemSelected(MenuItem item, String packageName, String name, Activity activity,
ChooseLabelDialogCreator chooseLabelDialog) {
ChooseLabelDialogCreator chooseLabelDialog) {
switch (item.getItemId()) {
case CHOOSE_LABELS:
chooseLabelDialog.setCurrentApp(packageName, name);
((GenericDialogManagerActivity) activity).showDialog(chooseLabelDialog);
break;
case SET_STAR:
DatabaseHelper.initOrSingleton(activity).appCacheDao.updateStarred(packageName, name, true);
break;
case UNSET_STAR:
DatabaseHelper.initOrSingleton(activity).appCacheDao.updateStarred(packageName, name, false);
break;
case LAUNCH:
startApplication(activity, packageName, name);
break;
case APPINFO:
viewApplicationInfo(activity, packageName);
break;
case UNINSTALL:
uninstallApplication(activity, packageName);
break;
case CHOOSE_LABELS:
chooseLabelDialog.setCurrentApp(packageName, name);
((GenericDialogManagerActivity) activity).showDialog(chooseLabelDialog);
break;
case SET_STAR:
DatabaseHelper.initOrSingleton(activity).appCacheDao.updateStarred(packageName, name, true);
break;
case UNSET_STAR:
DatabaseHelper.initOrSingleton(activity).appCacheDao.updateStarred(packageName, name, false);
break;
case LAUNCH:
startApplication(activity, packageName, name);
break;
case APPINFO:
viewApplicationInfo(activity, packageName);
break;
case UNINSTALL:
uninstallApplication(activity, packageName);
break;

// Option menu items
case NEW_LABEL:
GenericDialogManager genericDialogManager = ((GenericDialogManagerActivity) activity).getGenericDialogManager();
NewLabelDialog newLabelDialog = new NewLabelDialog(genericDialogManager, new OnOkClickListener() {

private static final long serialVersionUID = 1036198138637107577L;

public void onClick(CharSequence l, DialogInterface dialog, int which) {
DatabaseHelper.initOrSingleton(activity).labelDao.insert(l.toString());
}
});
newLabelDialog.showDialog();
break;
case RELOAD:
new AppsReloader(activity, true).reload();
break;
case IMPORT_MENU:
activity.startActivity(new Intent(activity, FileImporter.class));
break;
case EXPORT_MENU:
activity.startActivity(new Intent(activity, FileExporter.class));
break;
case PREFERENCES:
activity.startActivity(new Intent(activity, PreferencesFromXml.class));
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<string name="How_to">如何使用 Apps Organizer</string>
<string name="Starred_apps">星號標記</string>
<string name="how_to_message">你可以藉由在桌面上長按來建立標籤的捷徑</string>
<string name="how_to_message_2">An how to is available online (see about dialog for details)</string>
<string name="how_to_message_2">A how to is available online (see about dialog for details)</string>
<string name="Preferences">偏好設定</string>
<string name="Shortcut_folder">捷徑夾</string>
<string name="show_close_button_in_folder">顯示關閉按鈕</string>
Expand Down Expand Up @@ -74,4 +74,4 @@
<string name="choose_app">選擇程式</string>
<string name="Android_Image_Gallery">Android Image Gallery</string>
<string name="Change_log">更新紀錄</string>
</resources>
</resources>
8 changes: 4 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<string name="How_to">How to use Apps Organizer</string>
<string name="Starred_apps">Starred apps</string>
<string name="how_to_message">You can create labels home shortcuts with a long click on your Android home</string>
<string name="how_to_message_2">An how to is available online (see about dialog for details)</string>
<string name="how_to_message_2">A how to is available online (see about dialog for details)</string>
<string name="Preferences">Preferences</string>
<string name="Shortcut_folder">Shortcut folder</string>
<string name="show_close_button_in_folder">Show close button</string>
Expand Down Expand Up @@ -168,9 +168,9 @@
Android 2.0 support</string>
<string name="label_already_exists">Label already exists</string>
<string name="looking_for_icons">Looking for icons...</string>
<string name="loading_icons">Loading icons...</string>
<string name="error_while_launching_activity">Error while launching application</string>
<string name="New_label">New label</string>
<string name="loading_icons">Loading icons...</string>
<string name="error_while_launching_activity">Error while launching application</string>
<string name="New_label">New label</string>
<string name="Apps_list">Apps list</string>
<string name="label_default_internet">Internet</string>
<string name="label_default_android">Android</string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.2.2" apply false
id("com.android.application") version "8.3.0" apply false

//CHECK
//id("com.android.library") version "8.2.2" apply false
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Feb 07 21:25:08 CET 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit ebffaa2

Please sign in to comment.