35 @Override
public void onCreate(Bundle savedInstanceState)
37 super.onCreate(savedInstanceState);
39 if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction()))
45 ActivityShortcutsBinding binding = ActivityShortcutsBinding.inflate(getLayoutInflater());
46 setContentView(binding.getRoot());
48 if (getSupportActionBar() !=
null)
49 getSupportActionBar().setDisplayHomeAsUpEnabled(
true);
53 BookmarkListAdapter adapter =
new BookmarkListAdapter();
54 adapter.setActionsEnabled(
false);
55 adapter.setCallbacks(
new BookmarkListAdapter.Callbacks() {
56 @Override public void onItemClick(String refStr)
58 if (!ConnectionReference.isBookmarkReference(refStr))
60 BookmarkBase bookmark = findBookmark(adapter, refStr);
61 String label = bookmark != null ? bookmark.getLabel() : refStr;
62 setupShortcut(refStr, label);
65 @Override
public void onDelete(
long id)
70 binding.recyclerViewShortcuts.setLayoutManager(
new LinearLayoutManager(
this));
71 binding.recyclerViewShortcuts.setAdapter(adapter);
73 viewModel.getBookmarks().observe(
this, adapter::setItems);
75 viewModel.loadBookmarks();
78 @Override
public boolean onSupportNavigateUp()
84 private static BookmarkBase findBookmark(BookmarkListAdapter adapter, String refStr)
86 for (BookmarkBase b : adapter.getItems())
88 if (ConnectionReference.getBookmarkReference(b.getId()).equals(refStr))
94 private void setupShortcut(String strRef, String defaultLabel)
96 final EditText input =
new EditText(
this);
97 input.setText(defaultLabel);
99 new AlertDialog.Builder(
this)
100 .setTitle(R.string.dlg_title_create_shortcut)
101 .setMessage(R.string.dlg_msg_create_shortcut)
106 String label = input.getText().toString();
108 label = defaultLabel;
110 Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
111 shortcutIntent.setClassName(this,
112 SessionRequestHandlerActivity.class.getName());
113 shortcutIntent.setData(Uri.parse(strRef));
115 ShortcutInfoCompat shortcutInfo =
116 new ShortcutInfoCompat.Builder(this,
"shortcut_" + strRef.hashCode())
117 .setShortLabel(label)
118 .setIcon(IconCompat.createWithResource(
119 this, R.drawable.icon_launcher_freerdp))
120 .setIntent(shortcutIntent)
124 ShortcutManagerCompat.createShortcutResultIntent(this, shortcutInfo));
127 .setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())