Removed unused welcome screen.
This commit is contained in:
parent
cdef682fe2
commit
abda0b1830
@ -3,7 +3,7 @@
|
||||
|
||||
Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
||||
If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
@ -51,76 +51,70 @@ import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class HomeActivity extends Activity
|
||||
{
|
||||
public class HomeActivity extends Activity {
|
||||
private final static String ADD_BOOKMARK_PLACEHOLDER = "add_bookmark";
|
||||
|
||||
|
||||
private ListView listViewBookmarks;
|
||||
private WebView webViewGetStarted;
|
||||
|
||||
private Button clearTextButton;
|
||||
private EditText superBarEditText;
|
||||
private BookmarkArrayAdapter manualBookmarkAdapter;
|
||||
private SeparatedListAdapter separatedListAdapter;
|
||||
|
||||
private PlaceholderBookmark addBookmarkPlaceholder;
|
||||
|
||||
|
||||
private PlaceholderBookmark addBookmarkPlaceholder;
|
||||
|
||||
private static final String TAG = "HomeActivity";
|
||||
|
||||
|
||||
private static final String PARAM_SUPERBAR_TEXT = "superbar_text";
|
||||
|
||||
private String sectionLabelBookmarks;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
setTitle(R.string.title_home);
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setTitle(R.string.title_home);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.home);
|
||||
|
||||
|
||||
long heapSize = Runtime.getRuntime().maxMemory();
|
||||
Log.i(TAG, "Max HeapSize: " + heapSize);
|
||||
Log.i(TAG, "App data folder: " + getFilesDir().toString());
|
||||
|
||||
Log.i(TAG, "App data folder: " + getFilesDir().toString());
|
||||
|
||||
// load strings
|
||||
sectionLabelBookmarks = getResources().getString(R.string.section_bookmarks);
|
||||
|
||||
sectionLabelBookmarks = getResources().getString(R.string.section_bookmarks);
|
||||
|
||||
// create add bookmark/quick connect bookmark placeholder
|
||||
addBookmarkPlaceholder = new PlaceholderBookmark();
|
||||
addBookmarkPlaceholder.setName(ADD_BOOKMARK_PLACEHOLDER);
|
||||
addBookmarkPlaceholder.setLabel(getResources().getString(R.string.list_placeholder_add_bookmark));
|
||||
|
||||
|
||||
// check for passed .rdp file and open it in a new bookmark
|
||||
Intent caller = getIntent();
|
||||
Uri callParameter = caller.getData();
|
||||
|
||||
if (Intent.ACTION_VIEW.equals(caller.getAction()) && callParameter != null)
|
||||
{
|
||||
|
||||
if (Intent.ACTION_VIEW.equals(caller.getAction()) && callParameter != null) {
|
||||
String refStr = ConnectionReference.getFileReference(callParameter.getPath());
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(BookmarkActivity.PARAM_CONNECTION_REFERENCE, refStr);
|
||||
|
||||
Intent bookmarkIntent = new Intent(this.getApplicationContext(), BookmarkActivity.class);
|
||||
bookmarkIntent.putExtras(bundle);
|
||||
bookmarkIntent.putExtras(bundle);
|
||||
startActivity(bookmarkIntent);
|
||||
}
|
||||
|
||||
|
||||
// load views
|
||||
clearTextButton = (Button) findViewById(R.id.clear_search_btn);
|
||||
superBarEditText = (EditText) findViewById(R.id.superBarEditText);
|
||||
|
||||
listViewBookmarks = (ListView) findViewById(R.id.listViewBookmarks);
|
||||
webViewGetStarted = (WebView) findViewById(R.id.webViewWelcome);
|
||||
|
||||
superBarEditText = (EditText) findViewById(R.id.superBarEditText);
|
||||
|
||||
listViewBookmarks = (ListView) findViewById(R.id.listViewBookmarks);
|
||||
|
||||
String filename = ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) ? "welcome.html" : "welcome_phone.html";
|
||||
webViewGetStarted.getSettings().setJavaScriptEnabled(true);
|
||||
Locale def = Locale.getDefault();
|
||||
String prefix = def.getLanguage().toLowerCase(def);
|
||||
|
||||
String base = "file:///android_asset/";
|
||||
String base = "file:///android_asset/";
|
||||
String dir = prefix + "_help_page/"
|
||||
+ filename;
|
||||
+ filename;
|
||||
try {
|
||||
InputStream is = getAssets().open(dir);
|
||||
is.close();
|
||||
@ -128,164 +122,127 @@ public class HomeActivity extends Activity
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Missing localized asset " + dir, e);
|
||||
dir = "file:///android_asset/help_page/" + filename;
|
||||
}
|
||||
}
|
||||
|
||||
webViewGetStarted.loadUrl(dir);
|
||||
|
||||
// set listeners for the list view
|
||||
// set listeners for the list view
|
||||
listViewBookmarks.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
String curSection = separatedListAdapter.getSectionForPosition(position);
|
||||
Log.v(TAG, "Clicked on item id " + separatedListAdapter.getItemId(position) + " in section " + curSection);
|
||||
if(curSection == sectionLabelBookmarks)
|
||||
{
|
||||
String refStr = view.getTag().toString();
|
||||
if(curSection == sectionLabelBookmarks) {
|
||||
String refStr = view.getTag().toString();
|
||||
if (ConnectionReference.isManualBookmarkReference(refStr) ||
|
||||
ConnectionReference.isHostnameReference(refStr))
|
||||
{
|
||||
ConnectionReference.isHostnameReference(refStr)) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
|
||||
bundle.putString(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
|
||||
|
||||
Intent sessionIntent = new Intent(view.getContext(), SessionActivity.class);
|
||||
sessionIntent.putExtras(bundle);
|
||||
startActivity(sessionIntent);
|
||||
|
||||
Intent sessionIntent = new Intent(view.getContext(), SessionActivity.class);
|
||||
sessionIntent.putExtras(bundle);
|
||||
startActivity(sessionIntent);
|
||||
|
||||
// clear any search text
|
||||
superBarEditText.setText("");
|
||||
superBarEditText.clearFocus();
|
||||
}
|
||||
else if (ConnectionReference.isPlaceholderReference(refStr))
|
||||
{
|
||||
} else if (ConnectionReference.isPlaceholderReference(refStr)) {
|
||||
// is this the add bookmark placeholder?
|
||||
if (ConnectionReference.getPlaceholder(refStr).equals(ADD_BOOKMARK_PLACEHOLDER))
|
||||
{
|
||||
Intent bookmarkIntent = new Intent(view.getContext(), BookmarkActivity.class);
|
||||
startActivity(bookmarkIntent);
|
||||
if (ConnectionReference.getPlaceholder(refStr).equals(ADD_BOOKMARK_PLACEHOLDER)) {
|
||||
Intent bookmarkIntent = new Intent(view.getContext(), BookmarkActivity.class);
|
||||
startActivity(bookmarkIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
listViewBookmarks.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
|
||||
|
||||
listViewBookmarks.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
// if the selected item is not a session item (tag == null) and not a quick connect entry
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
// if the selected item is not a session item (tag == null) and not a quick connect entry
|
||||
// (not a hostname connection reference) inflate the context menu
|
||||
View itemView = ((AdapterContextMenuInfo)menuInfo).targetView;
|
||||
String refStr = itemView.getTag() != null ? itemView.getTag().toString() : null;
|
||||
if (refStr != null && !ConnectionReference.isHostnameReference(refStr) && !ConnectionReference.isPlaceholderReference(refStr))
|
||||
{
|
||||
String refStr = itemView.getTag() != null ? itemView.getTag().toString() : null;
|
||||
if (refStr != null && !ConnectionReference.isHostnameReference(refStr) && !ConnectionReference.isPlaceholderReference(refStr)) {
|
||||
getMenuInflater().inflate(R.menu.bookmark_context_menu, menu);
|
||||
menu.setHeaderTitle(getResources().getString(R.string.menu_title_bookmark));
|
||||
menu.setHeaderTitle(getResources().getString(R.string.menu_title_bookmark));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
superBarEditText.addTextChangedListener(new SuperBarTextWatcher());
|
||||
|
||||
|
||||
superBarEditText.addTextChangedListener(new SuperBarTextWatcher());
|
||||
|
||||
clearTextButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
superBarEditText.setText("");
|
||||
}
|
||||
});
|
||||
|
||||
webViewGetStarted.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url)
|
||||
{
|
||||
if (url.endsWith("new_connection"))
|
||||
{
|
||||
Intent bookmarkIntent = new Intent(getApplicationContext(), BookmarkActivity.class);
|
||||
startActivity(bookmarkIntent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
superBarEditText.setText("");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onSearchRequested() {
|
||||
superBarEditText.requestFocus();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem aItem) {
|
||||
|
||||
// get connection reference
|
||||
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)aItem.getMenuInfo();
|
||||
String refStr = menuInfo.targetView.getTag().toString();
|
||||
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)aItem.getMenuInfo();
|
||||
String refStr = menuInfo.targetView.getTag().toString();
|
||||
|
||||
// refer to http://tools.android.com/tips/non-constant-fields why we can't use switch/case here ..
|
||||
int itemId = aItem.getItemId();
|
||||
if (itemId == R.id.bookmark_connect)
|
||||
{
|
||||
if (itemId == R.id.bookmark_connect) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
|
||||
Intent sessionIntent = new Intent(this, SessionActivity.class);
|
||||
sessionIntent.putExtras(bundle);
|
||||
bundle.putString(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
|
||||
Intent sessionIntent = new Intent(this, SessionActivity.class);
|
||||
sessionIntent.putExtras(bundle);
|
||||
|
||||
startActivity(sessionIntent);
|
||||
startActivity(sessionIntent);
|
||||
return true;
|
||||
}
|
||||
else if (itemId == R.id.bookmark_edit)
|
||||
{
|
||||
} else if (itemId == R.id.bookmark_edit) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(BookmarkActivity.PARAM_CONNECTION_REFERENCE, refStr);
|
||||
|
||||
Intent bookmarkIntent = new Intent(this.getApplicationContext(), BookmarkActivity.class);
|
||||
bookmarkIntent.putExtras(bundle);
|
||||
bookmarkIntent.putExtras(bundle);
|
||||
startActivity(bookmarkIntent);
|
||||
return true;
|
||||
}
|
||||
else if (itemId == R.id.bookmark_delete)
|
||||
{
|
||||
if(ConnectionReference.isManualBookmarkReference(refStr))
|
||||
{
|
||||
} else if (itemId == R.id.bookmark_delete) {
|
||||
if(ConnectionReference.isManualBookmarkReference(refStr)) {
|
||||
long id = ConnectionReference.getManualBookmarkId(refStr);
|
||||
GlobalApp.getManualBookmarkGateway().delete(id);
|
||||
manualBookmarkAdapter.remove(id);
|
||||
separatedListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
assert false;
|
||||
}
|
||||
|
||||
showWelcomeScreenOrBookmarkList();
|
||||
|
||||
|
||||
// clear super bar text
|
||||
superBarEditText.setText("");
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Log.v(TAG, "HomeActivity.onResume");
|
||||
|
||||
|
||||
// create bookmark cursor adapter
|
||||
manualBookmarkAdapter = new BookmarkArrayAdapter(this, R.layout.bookmark_list_item, GlobalApp.getManualBookmarkGateway().findAll());
|
||||
|
||||
|
||||
// add add bookmark item to manual adapter
|
||||
manualBookmarkAdapter.insert(addBookmarkPlaceholder, 0);
|
||||
|
||||
|
||||
// attach all adapters to the separatedListView adapter and assign it to the list view
|
||||
separatedListAdapter = new SeparatedListAdapter(this);
|
||||
separatedListAdapter.addSection(sectionLabelBookmarks, manualBookmarkAdapter);
|
||||
listViewBookmarks.setAdapter(separatedListAdapter);
|
||||
|
||||
// show welcome screen in case we have a first-time user
|
||||
showWelcomeScreenOrBookmarkList();
|
||||
|
||||
listViewBookmarks.setAdapter(separatedListAdapter);
|
||||
|
||||
// if we have a filter text entered cause an update to be caused here
|
||||
String filter = superBarEditText.getText().toString();
|
||||
if (filter.length() > 0)
|
||||
@ -302,54 +259,46 @@ public class HomeActivity extends Activity
|
||||
separatedListAdapter = null;
|
||||
manualBookmarkAdapter = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
// if back was pressed - ask the user if he really wants to exit
|
||||
if (GlobalSettings.getAskOnExit())
|
||||
{
|
||||
public void onBackPressed() {
|
||||
// if back was pressed - ask the user if he really wants to exit
|
||||
if (GlobalSettings.getAskOnExit()) {
|
||||
final CheckBox cb = new CheckBox(this);
|
||||
cb.setChecked(!GlobalSettings.getAskOnExit());
|
||||
cb.setText(R.string.dlg_dont_show_again);
|
||||
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.dlg_title_exit)
|
||||
.setMessage(R.string.dlg_msg_exit)
|
||||
.setView(cb)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
GlobalSettings.setAskOnExit(!cb.isChecked());
|
||||
finish();
|
||||
}
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
GlobalSettings.setAskOnExit(!cb.isChecked());
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
GlobalSettings.setAskOnExit(!cb.isChecked());
|
||||
dialog.dismiss();
|
||||
}
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
GlobalSettings.setAskOnExit(!cb.isChecked());
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
else
|
||||
{
|
||||
.show();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState)
|
||||
{
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(PARAM_SUPERBAR_TEXT, superBarEditText.getText().toString());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle inState)
|
||||
{
|
||||
protected void onRestoreInstanceState(Bundle inState) {
|
||||
super.onRestoreInstanceState(inState);
|
||||
superBarEditText.setText(inState.getString(PARAM_SUPERBAR_TEXT));
|
||||
}
|
||||
@ -366,45 +315,29 @@ public class HomeActivity extends Activity
|
||||
|
||||
// refer to http://tools.android.com/tips/non-constant-fields why we can't use switch/case here ..
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.newBookmark)
|
||||
{
|
||||
if (itemId == R.id.newBookmark) {
|
||||
Intent bookmarkIntent = new Intent(this, BookmarkActivity.class);
|
||||
startActivity(bookmarkIntent);
|
||||
}
|
||||
else if (itemId == R.id.appSettings)
|
||||
{
|
||||
startActivity(bookmarkIntent);
|
||||
} else if (itemId == R.id.appSettings) {
|
||||
Intent settingsIntent = new Intent(this, ApplicationSettingsActivity.class);
|
||||
startActivity(settingsIntent);
|
||||
}
|
||||
else if (itemId == R.id.help)
|
||||
{
|
||||
} else if (itemId == R.id.help) {
|
||||
Intent helpIntent = new Intent(this, HelpActivity.class);
|
||||
startActivity(helpIntent);
|
||||
}
|
||||
else if (itemId == R.id.about)
|
||||
{
|
||||
} else if (itemId == R.id.about) {
|
||||
Intent aboutIntent = new Intent(this, AboutActivity.class);
|
||||
startActivity(aboutIntent);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showWelcomeScreenOrBookmarkList()
|
||||
{
|
||||
listViewBookmarks.setVisibility(View.VISIBLE);
|
||||
webViewGetStarted.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private class SuperBarTextWatcher implements TextWatcher
|
||||
{
|
||||
|
||||
private class SuperBarTextWatcher implements TextWatcher {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if(separatedListAdapter != null)
|
||||
{
|
||||
if(separatedListAdapter != null) {
|
||||
String text = s.toString();
|
||||
if(text.length() > 0)
|
||||
{
|
||||
if(text.length() > 0) {
|
||||
ArrayList<BookmarkBase> computers_list = GlobalApp.getQuickConnectHistoryGateway().findHistory(text);
|
||||
computers_list.addAll(GlobalApp.getManualBookmarkGateway().findByLabelOrHostnameLike(text));
|
||||
manualBookmarkAdapter.replaceItems(computers_list);
|
||||
@ -412,13 +345,11 @@ public class HomeActivity extends Activity
|
||||
qcBm.setLabel(text);
|
||||
qcBm.setHostname(text);
|
||||
manualBookmarkAdapter.insert(qcBm, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
manualBookmarkAdapter.replaceItems(GlobalApp.getManualBookmarkGateway().findAll());
|
||||
manualBookmarkAdapter.insert(addBookmarkPlaceholder, 0);
|
||||
}
|
||||
|
||||
|
||||
separatedListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@ -429,6 +360,6 @@ public class HomeActivity extends Activity
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user