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;
 
   57  private BookmarkArrayAdapter manualBookmarkAdapter;
 
   58  private SeparatedListAdapter separatedListAdapter;
 
   59  private PlaceholderBookmark addBookmarkPlaceholder;
 
   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);
 
   82    addBookmarkPlaceholder = 
new PlaceholderBookmark();
 
   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)
 
   93      String refStr = ConnectionReference.getFileReference(callParameter.getPath());
 
   94      Bundle bundle = 
new Bundle();
 
   97      Intent bookmarkIntent =
 
   99      bookmarkIntent.putExtras(bundle);
 
  100      startActivity(bookmarkIntent);
 
  104    clearTextButton = findViewById(R.id.clear_search_btn);
 
  105    superBarEditText = findViewById(R.id.superBarEditText);
 
  107    listViewBookmarks = 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();
 
  119          if (ConnectionReference.isManualBookmarkReference(refStr) ||
 
  120              ConnectionReference.isHostnameReference(refStr))
 
  122            Bundle bundle = new Bundle();
 
  123            bundle.putString(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
 
  125            Intent sessionIntent = new Intent(view.getContext(), SessionActivity.class);
 
  126            sessionIntent.putExtras(bundle);
 
  127            startActivity(sessionIntent);
 
  130            superBarEditText.setText(
"");
 
  131            superBarEditText.clearFocus();
 
  133          else if (ConnectionReference.isPlaceholderReference(refStr))
 
  136            if (ConnectionReference.getPlaceholder(refStr).equals(
 
  137                    ADD_BOOKMARK_PLACEHOLDER))
 
  139              Intent bookmarkIntent =
 
  140                  new Intent(view.getContext(), BookmarkActivity.class);
 
  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;
 
  156        if (refStr != 
null && !ConnectionReference.isHostnameReference(refStr) &&
 
  157            !ConnectionReference.isPlaceholderReference(refStr))
 
  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();
 
  202      bundle.putString(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
 
  203      Intent sessionIntent = 
new Intent(
this, SessionActivity.class);
 
  204      sessionIntent.putExtras(bundle);
 
  206      startActivity(sessionIntent);
 
  209    else if (itemId == R.id.bookmark_edit)
 
  211      Bundle bundle = 
new Bundle();
 
  212      bundle.putString(BookmarkActivity.PARAM_CONNECTION_REFERENCE, refStr);
 
  214      Intent bookmarkIntent =
 
  215          new Intent(this.getApplicationContext(), BookmarkActivity.class);
 
  216      bookmarkIntent.putExtras(bundle);
 
  217      startActivity(bookmarkIntent);
 
  220    else if (itemId == R.id.bookmark_delete)
 
  222      if (ConnectionReference.isManualBookmarkReference(refStr))
 
  224        long id = ConnectionReference.getManualBookmarkId(refStr);
 
  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");
 
  248    manualBookmarkAdapter = 
new BookmarkArrayAdapter(
 
  249        this, R.layout.bookmark_list_item, GlobalApp.getManualBookmarkGateway().findAll());
 
  252    manualBookmarkAdapter.insert(addBookmarkPlaceholder, 0);
 
  255    separatedListAdapter = 
new SeparatedListAdapter(
this);
 
  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()
 
  279    if (ApplicationSettingsActivity.getAskOnExit(
this))
 
  281      final CheckBox cb = 
new CheckBox(
this);
 
  282      cb.setChecked(!ApplicationSettingsActivity.getAskOnExit(
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)