11 package com.freerdp.freerdpcore.presentation;
13 import android.app.AlertDialog;
14 import android.content.DialogInterface;
15 import android.content.Intent;
16 import android.content.res.Configuration;
17 import android.net.Uri;
18 import android.os.Bundle;
19 import androidx.appcompat.app.AppCompatActivity;
20 import android.text.Editable;
21 import android.text.TextWatcher;
22 import android.util.Log;
23 import android.view.ContextMenu;
24 import android.view.ContextMenu.ContextMenuInfo;
25 import android.view.Menu;
26 import android.view.MenuInflater;
27 import android.view.MenuItem;
28 import android.view.View;
29 import android.view.View.OnClickListener;
30 import android.view.View.OnCreateContextMenuListener;
31 import android.widget.AdapterView;
32 import android.widget.AdapterView.AdapterContextMenuInfo;
33 import android.widget.Button;
34 import android.widget.CheckBox;
35 import android.widget.EditText;
36 import android.widget.ListView;
38 import com.freerdp.freerdpcore.R;
39 import com.freerdp.freerdpcore.application.GlobalApp;
40 import com.freerdp.freerdpcore.domain.BookmarkBase;
41 import com.freerdp.freerdpcore.domain.ConnectionReference;
42 import com.freerdp.freerdpcore.domain.PlaceholderBookmark;
43 import com.freerdp.freerdpcore.domain.QuickConnectBookmark;
44 import com.freerdp.freerdpcore.utils.BookmarkArrayAdapter;
45 import com.freerdp.freerdpcore.utils.SeparatedListAdapter;
47 import java.util.ArrayList;
51 private final static String ADD_BOOKMARK_PLACEHOLDER =
"add_bookmark";
52 private static final String TAG =
"HomeActivity";
53 private static final String PARAM_SUPERBAR_TEXT =
"superbar_text";
54 private ListView listViewBookmarks;
55 private Button clearTextButton;
56 private EditText superBarEditText;
60 private String sectionLabelBookmarks;
64 @Override
public void onCreate(Bundle savedInstanceState)
66 setTitle(R.string.title_home);
67 super.onCreate(savedInstanceState);
68 setContentView(R.layout.home);
70 mDecor = getWindow().getDecorView();
71 mDecor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
72 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
74 long heapSize = Runtime.getRuntime().maxMemory();
75 Log.i(TAG,
"Max HeapSize: " + heapSize);
76 Log.i(TAG,
"App data folder: " + getFilesDir().toString());
79 sectionLabelBookmarks = getResources().getString(R.string.section_bookmarks);
83 addBookmarkPlaceholder.setName(ADD_BOOKMARK_PLACEHOLDER);
84 addBookmarkPlaceholder.setLabel(
85 getResources().getString(R.string.list_placeholder_add_bookmark));
88 Intent caller = getIntent();
89 Uri callParameter = caller.getData();
91 if (Intent.ACTION_VIEW.equals(caller.getAction()) && callParameter !=
null)
94 Bundle bundle =
new Bundle();
97 Intent bookmarkIntent =
99 bookmarkIntent.putExtras(bundle);
100 startActivity(bookmarkIntent);
104 clearTextButton = (Button)findViewById(R.id.clear_search_btn);
105 superBarEditText = (EditText)findViewById(R.id.superBarEditText);
107 listViewBookmarks = (ListView)findViewById(R.id.listViewBookmarks);
110 listViewBookmarks.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
111 public void onItemClick(AdapterView<?> parent, View view,
int position,
long id)
113 String curSection = separatedListAdapter.getSectionForPosition(position);
114 Log.v(TAG,
"Clicked on item id " + separatedListAdapter.getItemId(position) +
115 " in section " + curSection);
116 if (curSection.equals(sectionLabelBookmarks))
118 String refStr = view.getTag().toString();
122 Bundle bundle =
new Bundle();
125 Intent sessionIntent =
new Intent(view.getContext(),
SessionActivity.class);
126 sessionIntent.putExtras(bundle);
127 startActivity(sessionIntent);
130 superBarEditText.setText(
"");
131 superBarEditText.clearFocus();
137 ADD_BOOKMARK_PLACEHOLDER))
139 Intent bookmarkIntent =
141 startActivity(bookmarkIntent);
148 listViewBookmarks.setOnCreateContextMenuListener(
new OnCreateContextMenuListener() {
150 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
154 View itemView = ((AdapterContextMenuInfo)menuInfo).targetView;
155 String refStr = itemView.getTag() !=
null ? itemView.getTag().toString() :
null;
159 getMenuInflater().inflate(R.menu.bookmark_context_menu, menu);
160 menu.setHeaderTitle(getResources().getString(R.string.menu_title_bookmark));
165 superBarEditText.addTextChangedListener(
new SuperBarTextWatcher());
167 clearTextButton.setOnClickListener(
new OnClickListener() {
168 @Override
public void onClick(View v)
170 superBarEditText.setText(
"");
175 @Override
public void onConfigurationChanged(Configuration newConfig)
178 super.onConfigurationChanged(newConfig);
179 mDecor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
180 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
183 @Override
public boolean onSearchRequested()
185 superBarEditText.requestFocus();
189 @Override
public boolean onContextItemSelected(MenuItem aItem)
193 AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)aItem.getMenuInfo();
194 String refStr = menuInfo.targetView.getTag().toString();
198 int itemId = aItem.getItemId();
199 if (itemId == R.id.bookmark_connect)
201 Bundle bundle =
new Bundle();
204 sessionIntent.putExtras(bundle);
206 startActivity(sessionIntent);
209 else if (itemId == R.id.bookmark_edit)
211 Bundle bundle =
new Bundle();
214 Intent bookmarkIntent =
216 bookmarkIntent.putExtras(bundle);
217 startActivity(bookmarkIntent);
220 else if (itemId == R.id.bookmark_delete)
225 GlobalApp.getManualBookmarkGateway().delete(
id);
226 manualBookmarkAdapter.remove(
id);
227 separatedListAdapter.notifyDataSetChanged();
235 superBarEditText.setText(
"");
242 @Override
protected void onResume()
245 Log.v(TAG,
"HomeActivity.onResume");
249 this, R.layout.bookmark_list_item,
GlobalApp.getManualBookmarkGateway().findAll());
252 manualBookmarkAdapter.insert(addBookmarkPlaceholder, 0);
256 separatedListAdapter.addSection(sectionLabelBookmarks, manualBookmarkAdapter);
257 listViewBookmarks.setAdapter(separatedListAdapter);
260 String filter = superBarEditText.getText().toString();
261 if (filter.length() > 0)
262 superBarEditText.setText(filter);
265 @Override
protected void onPause()
268 Log.v(TAG,
"HomeActivity.onPause");
271 listViewBookmarks.setAdapter(
null);
272 separatedListAdapter =
null;
273 manualBookmarkAdapter =
null;
276 @Override
public void onBackPressed()
281 final CheckBox cb =
new CheckBox(
this);
283 cb.setText(R.string.dlg_dont_show_again);
285 AlertDialog.Builder builder =
new AlertDialog.Builder(
this);
286 builder.setTitle(R.string.dlg_title_exit)
287 .setMessage(R.string.dlg_msg_exit)
289 .setPositiveButton(R.string.yes,
290 new DialogInterface.OnClickListener() {
291 public void onClick(DialogInterface dialog, int which)
296 .setNegativeButton(R.string.no,
297 new DialogInterface.OnClickListener() {
298 public void onClick(DialogInterface dialog, int which)
308 super.onBackPressed();
312 @Override
protected void onSaveInstanceState(Bundle outState)
314 super.onSaveInstanceState(outState);
315 outState.putString(PARAM_SUPERBAR_TEXT, superBarEditText.getText().toString());
318 @Override
protected void onRestoreInstanceState(Bundle inState)
320 super.onRestoreInstanceState(inState);
321 superBarEditText.setText(inState.getString(PARAM_SUPERBAR_TEXT));
324 @Override
public boolean onCreateOptionsMenu(Menu menu)
326 MenuInflater inflater = getMenuInflater();
327 inflater.inflate(R.menu.home_menu, menu);
331 @Override
public boolean onOptionsItemSelected(MenuItem item)
336 int itemId = item.getItemId();
337 if (itemId == R.id.newBookmark)
339 Intent bookmarkIntent =
new Intent(
this, BookmarkActivity.class);
340 startActivity(bookmarkIntent);
342 else if (itemId == R.id.appSettings)
344 Intent settingsIntent =
new Intent(
this, ApplicationSettingsActivity.class);
345 startActivity(settingsIntent);
347 else if (itemId == R.id.help)
349 Intent helpIntent =
new Intent(
this, HelpActivity.class);
350 startActivity(helpIntent);
352 else if (itemId == R.id.about)
354 Intent aboutIntent =
new Intent(
this, AboutActivity.class);
355 startActivity(aboutIntent);
361 private class SuperBarTextWatcher
implements TextWatcher
363 @Override
public void afterTextChanged(Editable s)
365 if (separatedListAdapter !=
null)
367 String text = s.toString();
368 if (text.length() > 0)
370 ArrayList<BookmarkBase> computers_list =
371 GlobalApp.getQuickConnectHistoryGateway().findHistory(text);
372 computers_list.addAll(
373 GlobalApp.getManualBookmarkGateway().findByLabelOrHostnameLike(text));
374 manualBookmarkAdapter.replaceItems(computers_list);
375 QuickConnectBookmark qcBm =
new QuickConnectBookmark();
377 qcBm.setHostname(text);
378 manualBookmarkAdapter.insert(qcBm, 0);
382 manualBookmarkAdapter.replaceItems(
383 GlobalApp.getManualBookmarkGateway().findAll());
384 manualBookmarkAdapter.insert(addBookmarkPlaceholder, 0);
387 separatedListAdapter.notifyDataSetChanged();
391 @Override
public void beforeTextChanged(CharSequence s,
int start,
int count,
int after)
395 @Override
public void onTextChanged(CharSequence s,
int start,
int before,
int count)