diff options
Diffstat (limited to 'java/demo/android/library/src')
11 files changed, 0 insertions, 2224 deletions
diff --git a/java/demo/android/library/src/com/zeroc/library/EditActivity.java b/java/demo/android/library/src/com/zeroc/library/EditActivity.java deleted file mode 100644 index 2063c4cc477..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/EditActivity.java +++ /dev/null @@ -1,291 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library; - -import java.util.ArrayList; -import java.util.List; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; - -import com.zeroc.library.controller.QueryController; -import com.zeroc.library.controller.QueryModel; - -public class EditActivity extends SessionActivity -{ - private static final int DIALOG_DISCARD = DIALOG_NEXT; - - private static final int SAVE_ID = Menu.FIRST; - private static final int DISCARD_ID = Menu.FIRST + 1; - - private Demo.BookDescription _desc; - - private List<View> _authorEntries = new ArrayList<View>(); - private EditText _isbn; - private EditText _title; - private LinearLayout _authorsLayout; - private LayoutInflater _inflater; - private Button _save; - - private void addAuthorView(String author) - { - final View authorView = _inflater.inflate(R.layout.author, _authorsLayout, false); - EditText auth = (EditText)authorView.findViewById(R.id.author); - auth.setText(author); - _authorsLayout.addView(authorView, _authorsLayout.getChildCount()-2); - _authorEntries.add(authorView); - - Button delete = (Button)authorView.findViewById(R.id.delete); - delete.setOnClickListener(new OnClickListener() - { - public void onClick(View v) - { - _authorsLayout.removeView(authorView); - _authorEntries.remove(authorView); - } - }); - } - - private void updateBookDescription() - { - _isbn.setText(_desc.isbn); - _isbn.setEnabled(_desc.proxy == null); - - _title.setText(_desc.title); - - for(String author : _desc.authors) - { - addAuthorView(author); - } - setSaveState(); - } - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.edit); - _authorsLayout = (LinearLayout)findViewById(R.id.authorsList); - - _isbn = (EditText)findViewById(R.id.isbn); - _isbn.addTextChangedListener(new TextWatcher() - { - public void afterTextChanged(Editable s) - { - setSaveState(); - } - - public void beforeTextChanged(CharSequence s, int start, int count, int after) - { - } - - public void onTextChanged(CharSequence s, int start, int count, int after) - { - } - }); - - _title = (EditText)findViewById(R.id.title); - - _inflater = getLayoutInflater(); - - Button addAuthor = (Button)findViewById(R.id.addAuthor); - addAuthor.setOnClickListener(new OnClickListener() - { - public void onClick(View v) - { - addAuthorView(""); - } - }); - - _save = (Button)findViewById(R.id.saveButton); - _save.setOnClickListener(new OnClickListener() - { - public void onClick(View v) - { - save(); - } - }); - Button discard = (Button)findViewById(R.id.discardButton); - discard.setOnClickListener(new OnClickListener() - { - public void onClick(View v) - { - showDialog(DIALOG_DISCARD); - } - }); - } - - protected void setSaveState() - { - String isbn = _isbn.getText().toString().trim(); - if(_desc.proxy == null && isbn.length() == 0) - { - _save.setEnabled(false); - } - else - { - _save.setEnabled(true); - } - } - - @Override - public void onResume() - { - super.onResume(); - _queryController.setListener(new QueryController.Listener() - { - public void onDataChange(QueryModel data, boolean saved) - { - if(saved) - { - finish(); - } - else - { - _desc = data.currentBook; - updateBookDescription(); - } - } - - public void onError() - { - showDialog(DIALOG_ERROR); - } - }); - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) - { - MenuItem saveItem = menu.findItem(SAVE_ID); - saveItem.setEnabled(_save.isEnabled()); - return true; - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) - { - boolean result = super.onCreateOptionsMenu(menu); - menu.add(0, SAVE_ID, 0, R.string.menu_save); - menu.add(0, DISCARD_ID, 0, R.string.menu_discard); - return result; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) - { - switch (item.getItemId()) - { - case SAVE_ID: - save(); - return true; - - case DISCARD_ID: - showDialog(DIALOG_DISCARD); - return true; - } - - return super.onOptionsItemSelected(item); - } - - // Hook the back key to save the item, if necessary. - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) - { - if(keyCode == KeyEvent.KEYCODE_BACK) - { - if(_save.isEnabled()) - { - save(); - } - else - { - finish(); - } - return true; - } - return false; - } - - private void save() - { - List<String> authors = new ArrayList<String>(); - - for(View authorView : _authorEntries) - { - EditText auth = (EditText)authorView.findViewById(R.id.author); - String a = auth.getText().toString().trim(); - if(a.length() > 0) - { - authors.add(a); - } - } - _desc.authors = authors; - _desc.title = _title.getText().toString().trim(); - _desc.isbn = _isbn.getText().toString().trim(); - - if(!_queryController.saveBook(_desc)) - { - finish(); - } - } - - @Override - protected Dialog onCreateDialog(final int id) - { - Dialog d = super.onCreateDialog(id); - if(d != null) - { - return d; - } - - switch(id) - { - case DIALOG_DISCARD: - { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Discard changes"); - builder.setMessage("Your changes will be discarded."); - builder.setPositiveButton("OK", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int whichButton) - { - setResult(RESULT_CANCELED); - finish(); - } - }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int whichButton) - { - } - }); - return builder.create(); - } - } - - return null; - } - -} diff --git a/java/demo/android/library/src/com/zeroc/library/LibraryActivity.java b/java/demo/android/library/src/com/zeroc/library/LibraryActivity.java deleted file mode 100644 index 7b97f73475e..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/LibraryActivity.java +++ /dev/null @@ -1,281 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library; - -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.view.inputmethod.EditorInfo; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.BaseAdapter; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ListView; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.AdapterView.OnItemClickListener; - -import com.zeroc.library.controller.QueryController; -import com.zeroc.library.controller.QueryModel; - -public class LibraryActivity extends SessionActivity -{ - private static final int ADD_ID = Menu.FIRST; - private static final int LOGOUT_ID = Menu.FIRST + 1; - - private Button _search; - private Spinner _searchType; - private EditText _text; - private ListView _searchTable; - - private QueryModel _querydata; - - private LayoutInflater _inflater; - - class LibraryListAdapter extends BaseAdapter - { - public int getCount() - { - if(_querydata == null) - { - return 0; - } - return _querydata.nrows; - } - - public Object getItem(int position) - { - assert _querydata != null; - return _querydata.books.get(position); - } - - public long getItemId(int position) - { - return 0; - } - - public View getView(int position, View convertView, ViewGroup parent) - { - assert _querydata != null; - TextView text; - - // The use of the inflater ensures that the list contains a - // well styled text view. - if(convertView == null) - { - text = (TextView)_inflater.inflate(android.R.layout.simple_list_item_1, parent, false); - } - else - { - text = (TextView)convertView; - } - if(position > _querydata.books.size() - 1) - { - _queryController.getMore(position); - text.setText("<loading>"); - } - else - { - text.setText(_querydata.books.get(position).title); - } - return text; - } - }; - - private LibraryListAdapter _adapter; - - private QueryController.Listener _queryListener = new QueryController.Listener() - { - public void onDataChange(QueryModel data, boolean saved) - { - _querydata = data; - _adapter.notifyDataSetChanged(); - _search.setEnabled(true); - } - - public void onError() - { - showDialog(DIALOG_ERROR); - } - }; - - // Hook the back key to logout the session. - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) - { - if(keyCode == KeyEvent.KEYCODE_BACK) - { - logout(); - return true; - } - return false; - } - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.library); - - _text = (EditText)findViewById(R.id.text); - _text.addTextChangedListener(new TextWatcher() - { - public void afterTextChanged(Editable s) - { - setSearchState(); - } - - public void beforeTextChanged(CharSequence s, int start, int count, int after) - { - } - - public void onTextChanged(CharSequence s, int start, int count, int after) - { - } - }); - _text.setOnEditorActionListener(new EditText.OnEditorActionListener() - { - - @Override - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) - { - if (actionId == EditorInfo.IME_ACTION_SEARCH) - { - _search.performClick(); - _search.setPressed(true); - new Handler().postDelayed(new Runnable() - { - @Override - public void run() - { - _search.setPressed(false); - } - }, 100); - return true; - } - return false; - } - - }); - - _search = (Button)findViewById(R.id.search); - _search.setOnClickListener(new android.view.View.OnClickListener() - { - public void onClick(android.view.View v) - { - _searchTable.setEmptyView(findViewById(R.id.no_match)); - String queryString = _text.getText().toString().trim(); - // If there is no query, we're done. - if(queryString.length() == 0) - { - return; - } - - QueryController.QueryType type = null; - switch (_searchType.getSelectedItemPosition()) - { - case 0: // ISBN - type = QueryController.QueryType.ISBN; - break; - case 1: // Author - type = QueryController.QueryType.AUTHOR; - break; - case 2: // Title - type = QueryController.QueryType.TITLE; - break; - } - // This immediately calls back on the _callback object with an - // empty dataset which clears the current query list. - _search.setEnabled(false); - _queryController = _sessionController.createQuery(_queryListener, type, queryString); - } - }); - - _inflater = getLayoutInflater(); - - _searchType = (Spinner)findViewById(R.id.searchType); - ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, - new String[] { "ISBN", "Author", "Title" }); - _searchType.setAdapter(modeAdapter); - _adapter = new LibraryListAdapter(); - - _searchTable = (ListView)findViewById(R.id.list); - _searchTable.setEmptyView(null); - _searchTable.setAdapter(_adapter); - _searchTable.setOnItemClickListener(new OnItemClickListener() - { - public void onItemClick(AdapterView<?> parent, View view, int position, long id) - { - // setCurrentBook returns false if the data for the current row - // hasn't loaded yet. - if(_queryController.setCurrentBook(position)) - { - startActivity(new Intent(LibraryActivity.this, ViewActivity.class)); - } - } - }); - } - - @Override - public void onResume() - { - super.onResume(); - _queryController.setListener(_queryListener); - } - - protected void setSearchState() - { - _search.setEnabled(_text.getText().toString().trim().length() > 0); - } - - private void logout() - { - LibraryApp app = (LibraryApp)getApplication(); - app.logout(); - finish(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) - { - boolean result = super.onCreateOptionsMenu(menu); - menu.add(0, ADD_ID, 0, R.string.menu_add); - menu.add(0, LOGOUT_ID, 0, R.string.menu_logout); - return result; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) - { - switch (item.getItemId()) - { - case ADD_ID: - _queryController.setCurrentBook(QueryController.NEW_BOOK); - startActivity(new Intent(LibraryActivity.this, EditActivity.class)); - return true; - - case LOGOUT_ID: - logout(); - return true; - } - - return super.onOptionsItemSelected(item); - } -} diff --git a/java/demo/android/library/src/com/zeroc/library/LibraryApp.java b/java/demo/android/library/src/com/zeroc/library/LibraryApp.java deleted file mode 100644 index d833db13d9a..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/LibraryApp.java +++ /dev/null @@ -1,87 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library; - -import com.zeroc.library.controller.LoginController; -import com.zeroc.library.controller.SessionController; -import com.zeroc.library.controller.LoginController.Listener; - -import android.app.Application; - -public class LibraryApp extends Application -{ - private LoginController _loginController; - private SessionController _sessionController; - - @Override - public void onCreate() - { - } - - @Override - public void onTerminate() - { - if(_loginController != null) - { - _loginController.destroy(); - _loginController = null; - } - - if(_sessionController != null) - { - _sessionController.destroy(); - _sessionController = null; - } - } - - public void loggedIn(SessionController sessionController) - { - assert _sessionController == null && _loginController != null; - _sessionController = sessionController; - - _loginController.destroy(); - _loginController = null; - } - - public void logout() - { - if(_sessionController != null) - { - _sessionController.destroy(); - _sessionController = null; - } - } - - public LoginController login(String hostname, boolean secure, boolean glacier2, Listener listener) - { - assert _loginController == null && _sessionController == null; - _loginController = new LoginController(getResources(), hostname, secure, glacier2, listener); - return _loginController; - } - - public void loginFailure() - { - if(_loginController != null) - { - _loginController.destroy(); - _loginController = null; - } - } - - public SessionController getSessionController() - { - return _sessionController; - } - - public LoginController getLoginController() - { - return _loginController; - } -} diff --git a/java/demo/android/library/src/com/zeroc/library/LoginActivity.java b/java/demo/android/library/src/com/zeroc/library/LoginActivity.java deleted file mode 100644 index fea2265b217..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/LoginActivity.java +++ /dev/null @@ -1,265 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Build.VERSION; -import android.os.Bundle; -import android.text.Editable; -import android.text.TextWatcher; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.EditText; - -import com.zeroc.library.controller.LoginController; -import com.zeroc.library.controller.SessionController; - -public class LoginActivity extends Activity -{ - private static final String DEFAULT_HOST = "demo2.zeroc.com"; - private static final boolean DEFAULT_SECURE = false; - private static final boolean DEFAULT_GLACIER2 = false; - private static final String HOSTNAME_KEY = "host"; - private static final String SECURE_KEY = "secure"; - private static final String GLACIER2_KEY = "glacier2"; - - private static final int DIALOG_ERROR = 1; - private static final int DIALOG_INVALID_HOST = 2; - - private Button _login; - private EditText _hostname; - private CheckBox _glacier2; - private CheckBox _secure; - private SharedPreferences _prefs; - private LoginController _loginController; - private boolean _loginInProgress = false; - - private LoginController.Listener _listener = new LoginController.Listener() - { - public void onLoginInProgress() - { - _loginInProgress = true; - setLoginState(); - } - - public void onLogin(SessionController sessionController) - { - if(isFinishing()) - { - return; - } - - LibraryApp app = (LibraryApp)getApplication(); - app.loggedIn(sessionController); - startActivity(new Intent(LoginActivity.this, LibraryActivity.class)); - } - - public void onLoginError() - { - _loginInProgress = false; - setLoginState(); - - showDialog(DIALOG_ERROR); - } - }; - - private void setLoginState() - { - if(_loginInProgress) - { - _login.setEnabled(false); - } - else - { - String host = _hostname.getText().toString().trim(); - _login.setEnabled(host.length() > 0); - } - } - - private void login() - { - final String hostname = _hostname.getText().toString().trim(); - final boolean secure = _secure.isChecked(); - final boolean glacier2 = _glacier2.isChecked(); - - // We don't want to save obviously bogus hostnames in the application - // preferences. These two regexp validates that the hostname is well - // formed. - // Note that this regexp doesn't handle IPv6 addresses. - final String hostre = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9])$"; - final String ipre = "^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"; - if(!hostname.matches(hostre) && !hostname.matches(ipre)) - { - showDialog(DIALOG_INVALID_HOST); - return; - } - - // Update preferences. - SharedPreferences.Editor edit = _prefs.edit(); - if(!_prefs.getString(HOSTNAME_KEY, DEFAULT_HOST).equals(hostname)) - { - edit.putString(HOSTNAME_KEY, hostname); - } - if(_prefs.getBoolean(SECURE_KEY, DEFAULT_SECURE) != secure) - { - edit.putBoolean(SECURE_KEY, secure); - } - if(_prefs.getBoolean(GLACIER2_KEY, DEFAULT_GLACIER2) != glacier2) - { - edit.putBoolean(GLACIER2_KEY, glacier2); - } - - edit.commit(); - - LibraryApp app = (LibraryApp)getApplication(); - _loginController = app.login(hostname, secure, glacier2, _listener); - } - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.login); - - if(VERSION.SDK_INT == 8) // android.os.Build.VERSION_CODES.FROYO (8) - { - // - // Workaround for a bug in Android 2.2 (Froyo). - // - // See http://code.google.com/p/android/issues/detail?id=9431 - // - java.lang.System.setProperty("java.net.preferIPv4Stack", "true"); - java.lang.System.setProperty("java.net.preferIPv6Addresses", "false"); - } - - _login = (Button) findViewById(R.id.login); - _login.setOnClickListener(new android.view.View.OnClickListener() - { - public void onClick(android.view.View v) - { - login(); - } - }); - _hostname = (EditText) findViewById(R.id.hostname); - _hostname.addTextChangedListener(new TextWatcher() - { - public void afterTextChanged(Editable s) - { - setLoginState(); - } - - public void beforeTextChanged(CharSequence s, int start, int count, int after) - { - } - - public void onTextChanged(CharSequence s, int start, int count, int after) - { - } - }); - - _secure = (android.widget.CheckBox) findViewById(R.id.secure); - _secure.setEnabled(VERSION.SDK_INT >= 8); // android.os.Build.VERSION_CODES.FROYO (8) - - _glacier2 = (android.widget.CheckBox) findViewById(R.id.glacier2); - - _prefs = getPreferences(MODE_PRIVATE); - - _prefs = getPreferences(MODE_PRIVATE); - if(savedInstanceState == null) - { - _hostname.setText(_prefs.getString(HOSTNAME_KEY, DEFAULT_HOST)); - _secure.setChecked(_prefs.getBoolean(SECURE_KEY, DEFAULT_SECURE)); - _glacier2.setChecked(_prefs.getBoolean(GLACIER2_KEY, DEFAULT_GLACIER2)); - } - } - - @Override - protected void onResume() - { - super.onResume(); - LibraryApp app = (LibraryApp)getApplication(); - _loginInProgress = false; - _loginController = app.getLoginController(); - if(_loginController != null) - { - _loginController.setLoginListener(_listener); - } - else - { - setLoginState(); - } - } - - @Override - protected void onStop() - { - super.onStop(); - if(_loginController != null) - { - _loginController.setLoginListener(null); - _loginController = null; - } - } - - @Override - protected Dialog onCreateDialog(int id) - { - switch(id) - { - case DIALOG_ERROR: - { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Error"); - builder.setMessage(""); // The message is filled in onPrepareDialog. - builder.setCancelable(false); - builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int whichButton) - { - // Clean up the login controller upon login failure. - if(_loginController != null) - { - LibraryApp app = (LibraryApp)getApplication(); - app.loginFailure(); - } - } - }); - return builder.create(); - } - - case DIALOG_INVALID_HOST: - { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Error"); - builder.setMessage("The hostname is invalid"); - return builder.create(); - } - } - - return null; - } - - @Override - protected void onPrepareDialog(int id, Dialog dialog) - { - super.onPrepareDialog(id, dialog); - if(id == DIALOG_ERROR) - { - AlertDialog alert = (AlertDialog)dialog; - alert.setMessage(_loginController.getLoginError()); - } - } -} diff --git a/java/demo/android/library/src/com/zeroc/library/SessionActivity.java b/java/demo/android/library/src/com/zeroc/library/SessionActivity.java deleted file mode 100644 index 8a7f9dac01f..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/SessionActivity.java +++ /dev/null @@ -1,107 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library; - -import com.zeroc.library.controller.QueryController; -import com.zeroc.library.controller.SessionController; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; - -// The base class of any activity created after a session has been established. -public class SessionActivity extends Activity -{ - protected static final int DIALOG_ERROR = 0; - protected static final int DIALOG_FATAL = 1; - protected static final int DIALOG_NEXT = 2; - - protected SessionController _sessionController; - protected QueryController _queryController; - - @Override - public void onResume() - { - super.onResume(); - - LibraryApp app = (LibraryApp)getApplication(); - _sessionController = app.getSessionController(); - if(_sessionController == null) - { - finish(); - return; - } - - _sessionController.setSessionListener(new SessionController.Listener() - { - public void onDestroy() - { - showDialog(DIALOG_FATAL); - } - }); - - _queryController = _sessionController.getCurrentQuery(); - } - - @Override - protected Dialog onCreateDialog(final int id) - { - switch (id) - { - case DIALOG_ERROR: - { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Error"); - builder.setMessage(""); // Filled in onPrepareDialog. - builder.setCancelable(false); - builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int whichButton) - { - _queryController.clearLastError(); - } - }); - return builder.create(); - } - - case DIALOG_FATAL: - { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Error"); - builder.setMessage("The session was lost. Please login again."); - builder.setCancelable(false); - builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int whichButton) - { - LibraryApp app = (LibraryApp)getApplication(); - app.logout(); - finish(); - } - }); - return builder.create(); - } - } - - return null; - } - - @Override - protected void onPrepareDialog(int id, Dialog dialog) - { - super.onPrepareDialog(id, dialog); - if(id == DIALOG_ERROR) - { - AlertDialog alert = (AlertDialog)dialog; - alert.setMessage(_queryController.getLastError()); - } - } -} diff --git a/java/demo/android/library/src/com/zeroc/library/ViewActivity.java b/java/demo/android/library/src/com/zeroc/library/ViewActivity.java deleted file mode 100644 index 62422da8023..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/ViewActivity.java +++ /dev/null @@ -1,229 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.zeroc.library.controller.QueryController; -import com.zeroc.library.controller.QueryModel; - -public class ViewActivity extends SessionActivity -{ - private static final int EDIT_ID = Menu.FIRST; - private static final int DELETE_ID = Menu.FIRST + 1; - - public static final int BOOK_DELETED = RESULT_FIRST_USER; - public static final int BOOK_CHANGED = RESULT_FIRST_USER+1; - - private static final int DIALOG_DELETE = DIALOG_NEXT; - private static final int DIALOG_RENT_BOOK = DIALOG_NEXT+1; - - private Demo.BookDescription _desc; - private TextView _isbn; - private TextView _title; - private LinearLayout _authorsLayout; - private LayoutInflater _inflater; - private TextView _rentedBy; - private Button _rent; - - private void updateBookDescription() - { - // Update the fields. - _isbn.setText(_desc.isbn); - _title.setText(_desc.title); - // Remove all the authors. - _authorsLayout.removeViews(0, _authorsLayout.getChildCount()-1); - // Add them back. - for(String author : _desc.authors) - { - TextView auth = (TextView)_inflater.inflate(R.layout.authorview, _authorsLayout, false); - auth.setText(author); - _authorsLayout.addView(auth, _authorsLayout.getChildCount()-1); - } - - _rent.setEnabled(true); - if(_desc.rentedBy.length() == 0) - { - _rentedBy.setVisibility(View.GONE); - _rent.setText("Rent Book"); - } - else - { - _rentedBy.setVisibility(View.VISIBLE); - _rentedBy.setText(_desc.rentedBy); - _rent.setText("Return Book"); - } - } - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - setContentView(R.layout.view); - - _authorsLayout = (LinearLayout)findViewById(R.id.authorsList); - _isbn = (TextView)findViewById(R.id.isbn); - _title = (TextView)findViewById(R.id.title); - _rentedBy = (TextView)findViewById(R.id.rentedBy); - - // This button is a toggle. If the book is returned, the book is - // returned. Otherwise, the book is rented. - _rent = (Button)findViewById(R.id.rent); - _rent.setOnClickListener(new OnClickListener() - { - public void onClick(View v) - { - if(_desc.rentedBy.length() == 0) - { - showDialog(DIALOG_RENT_BOOK); - } - else - { - _rent.setEnabled(false); - _queryController.returnBook(); - } - } - }); - - _inflater = getLayoutInflater(); - } - - @Override - public void onResume() - { - super.onResume(); - _queryController.setListener(new QueryController.Listener() - { - public void onDataChange(QueryModel data, boolean saved) - { - _rent.setEnabled(true); - _desc = data.currentBook; - if(_desc == null) - { - finish(); - } - else - { - updateBookDescription(); - } - } - - public void onError() - { - _rent.setEnabled(true); - showDialog(DIALOG_ERROR); - } - }); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) - { - boolean result = super.onCreateOptionsMenu(menu); - menu.add(0, EDIT_ID, 0, R.string.menu_edit); - menu.add(0, DELETE_ID, 0, R.string.menu_delete); - return result; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) - { - switch (item.getItemId()) - { - case EDIT_ID: - startActivity(new Intent(this, EditActivity.class)); - return true; - - case DELETE_ID: - showDialog(DIALOG_DELETE); - return true; - } - - return super.onOptionsItemSelected(item); - } - - @Override - protected Dialog onCreateDialog(final int id) - { - Dialog d = super.onCreateDialog(id); - if(d != null) - { - return d; - } - switch (id) - { - case DIALOG_DELETE: - { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle("Delete"); - builder.setMessage("This book will be deleted."); - builder.setPositiveButton("OK", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int whichButton) - { - _queryController.deleteBook(); - } - }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int whichButton) - { - } - }); - return builder.create(); - } - - case DIALOG_RENT_BOOK: - { - // This example shows how to add a custom layout to an AlertDialog - LayoutInflater factory = LayoutInflater.from(this); - final View entryView = factory.inflate(R.layout.rentername, null); - final EditText renter = (EditText)entryView.findViewById(R.id.renter); - AlertDialog.Builder builder = new AlertDialog.Builder(ViewActivity.this); - builder.setTitle("Enter Renter"); - builder.setView(entryView); - builder.setPositiveButton("OK", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int whichButton) - { - final String r = renter.getText().toString().trim(); - if(r.length() > 0) - { - _rent.setEnabled(false); - _queryController.rentBook(r); - } - } - }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface dialog, int whichButton) - { - } - }); - return builder.create(); - } - } - return null; - } -} diff --git a/java/demo/android/library/src/com/zeroc/library/controller/LoginController.java b/java/demo/android/library/src/com/zeroc/library/controller/LoginController.java deleted file mode 100644 index a2bc3e304ea..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/controller/LoginController.java +++ /dev/null @@ -1,296 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library.controller; - -import com.zeroc.library.R; - -import android.content.res.Resources; -import android.os.Handler; - -public class LoginController -{ - public interface Listener - { - void onLoginInProgress(); - void onLogin(SessionController controller); - void onLoginError(); - } - - private boolean _destroyed = false; - private Handler _handler; - private Ice.Communicator _communicator; - private String _loginError; - private Listener _loginListener; - private SessionController _sessionController; - - synchronized private void postLoginFailure(final String loginError) - { - _loginError = loginError; - if(_loginListener != null) - { - final Listener listener = _loginListener; - _handler.post(new Runnable() - { - public void run() - { - listener.onLoginError(); - } - }); - } - } - - public LoginController(Resources resources, final String hostname, final boolean secure, final boolean glacier2, - Listener listener) - { - _handler = new Handler(); - _loginListener = listener; - _loginListener.onLoginInProgress(); - - Ice.InitializationData initData = new Ice.InitializationData(); - - initData.properties = Ice.Util.createProperties(); - initData.properties.setProperty("Ice.ACM.Client", "0"); - initData.properties.setProperty("Ice.RetryIntervals", "-1"); - initData.properties.setProperty("Ice.Trace.Network", "0"); - - if(secure) - { - initData.properties.setProperty("IceSSL.Trace.Security", "0"); - initData.properties.setProperty("IceSSL.TruststoreType", "BKS"); - initData.properties.setProperty("IceSSL.Password", "password"); - initData.properties.setProperty("Ice.InitPlugins", "0"); - initData.properties.setProperty("Ice.Plugin.IceSSL", "IceSSL.PluginFactory"); - java.io.InputStream certStream; - certStream = resources.openRawResource(R.raw.client); - _communicator = Ice.Util.initialize(initData); - - IceSSL.Plugin plugin = (IceSSL.Plugin)_communicator.getPluginManager().getPlugin("IceSSL"); - plugin.setTruststoreStream(certStream); - _communicator.getPluginManager().initializePlugins(); - } - else - { - _communicator = Ice.Util.initialize(initData); - } - - new Thread(new Runnable() - { - public void run() - { - try - { - long refreshTimeout; - SessionAdapter session = null; - - if(glacier2) - { - StringBuilder s = new StringBuilder(); - s.append("DemoGlacier2/router:"); - s.append(secure ? "ssl " : "tcp"); - s.append(" -p "); - s.append(secure ? "4064" : "4063"); - s.append(" -h "); - s.append(hostname); - s.append(" -t 10000"); - - Ice.ObjectPrx proxy = _communicator.stringToProxy(s.toString()); - Ice.RouterPrx r = Ice.RouterPrxHelper.uncheckedCast(proxy); - - _communicator.setDefaultRouter(r); - - final Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.checkedCast(r); - if(router == null) - { - postLoginFailure("Glacier2 proxy is invalid."); - return; - } - Glacier2.SessionPrx glacier2session = router.createSession("dummy", "none"); - - final Demo.Glacier2SessionPrx sess = Demo.Glacier2SessionPrxHelper - .uncheckedCast(glacier2session); - final Demo.LibraryPrx library = sess.getLibrary(); - refreshTimeout = (router.getSessionTimeout() * 1000) / 2; - session = new SessionAdapter() - { - public void destroy() - { - try - { - router.destroySession(); - } - catch(Glacier2.SessionNotExistException e) - { - } - } - - public void refresh() - { - sess.refresh(); - } - - public Demo.LibraryPrx getLibrary() - { - return library; - } - }; - } - else - { - StringBuilder s = new StringBuilder(); - s.append("SessionFactory:"); - s.append(secure ? "ssl " : "tcp"); - s.append(" -p "); - s.append(secure ? "10001" : "10000"); - s.append(" -h "); - s.append(hostname); - s.append(" -t 10000"); - Ice.ObjectPrx proxy = _communicator.stringToProxy(s.toString()); - Demo.SessionFactoryPrx factory = Demo.SessionFactoryPrxHelper.checkedCast(proxy); - if(factory == null) - { - postLoginFailure("SessionFactory proxy is invalid."); - return; - } - - final Demo.SessionPrx sess = factory.create(); - final Demo.LibraryPrx library = sess.getLibrary(); - refreshTimeout = (factory.getSessionTimeout() * 1000) / 2; - session = new SessionAdapter() - { - public void destroy() - { - sess.destroy(); - } - - public void refresh() - { - sess.refresh(); - } - - public Demo.LibraryPrx getLibrary() - { - return library; - } - }; - } - - synchronized(LoginController.this) - { - if(_destroyed) - { - // Here the app was terminated while session - // establishment was in progress. - try - { - session.destroy(); - } - catch(Exception e) - { - } - - try - { - _communicator.destroy(); - } - catch(Exception e) - { - } - return; - } - - _sessionController = new SessionController(_handler, _communicator, session, refreshTimeout); - if(_loginListener != null) - { - final Listener listener = _loginListener; - _handler.post(new Runnable() - { - public void run() - { - listener.onLogin(_sessionController); - } - }); - } - } - } - catch(final Glacier2.CannotCreateSessionException ex) - { - ex.printStackTrace(); - postLoginFailure(String.format("Session creation failed: %s", ex.reason)); - } - catch(Glacier2.PermissionDeniedException ex) - { - ex.printStackTrace(); - postLoginFailure(String.format("Login failed: %s", ex.reason)); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - postLoginFailure(String.format("Login failed: %s", ex.toString())); - } - } - }).start(); - } - - synchronized public void destroy() - { - if(_destroyed) - { - return; - } - _destroyed = true; - // - // There are three cases: - // - // 1. A session has been created. In this case the communicator is owned - // by the session controller. - // - // 2. The session creation failed. In this case _loginError is non-null. - // Destroy the communicator. - // - // 3. The session creation is in progress. In which case, things will be - // cleaned up once the session establishment is complete. - // - if(_sessionController == null && _loginError != null) - { - try - { - _communicator.destroy(); - } - catch(Exception e) - { - } - } - } - - synchronized public String getLoginError() - { - return _loginError; - } - - synchronized public void setLoginListener(Listener listener) - { - _loginListener = listener; - if(listener != null) - { - if(_loginError != null) - { - listener.onLoginError(); - } - else if(_sessionController == null) - { - listener.onLoginInProgress(); - } - else - { - listener.onLogin(_sessionController); - } - } - } -} diff --git a/java/demo/android/library/src/com/zeroc/library/controller/QueryController.java b/java/demo/android/library/src/com/zeroc/library/controller/QueryController.java deleted file mode 100644 index 1467426cb52..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/controller/QueryController.java +++ /dev/null @@ -1,461 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library.controller; - -import java.util.ArrayList; -import java.util.List; - -import android.os.Handler; - -public class QueryController -{ - public interface Listener - { - void onDataChange(QueryModel data, boolean saved); - void onError(); - } - - public static final int NO_BOOK = -1; - public static final int NEW_BOOK = -2; - - public enum QueryType - { - ISBN, TITLE, AUTHOR - } - - private ArrayList<Demo.BookDescription> _books = new ArrayList<Demo.BookDescription>(); - private int _nrows = 0; - private int _rowsQueried = 0; - private Demo.BookQueryResultPrx _query = null; - private Listener _listener; - private Handler _handler; - private Demo.LibraryPrx _library; - private int _currentBook = NO_BOOK; - private String _lastError; - - synchronized protected void postDataChanged(final boolean saved) - { - if(_listener != null) - { - _handler.post(new Runnable() - { - public void run() - { - _listener.onDataChange(getQueryModel(), saved); - } - }); - } - } - - synchronized protected void postError(final String string) - { - _lastError = string; - if(_listener != null) - { - _handler.post(new Runnable() - { - public void run() - { - _listener.onError(); - } - }); - } - } - - synchronized private void queryResponse(List<Demo.BookDescription> first, int nrows, Demo.BookQueryResultPrx result) - { - _books.clear(); - _nrows = nrows; - _books.addAll(first); - _query = result; - if(_listener != null) - { - postDataChanged(false); - } - } - - synchronized private QueryModel getQueryModel() - { - QueryModel data = new QueryModel(); - data.books = new ArrayList<Demo.BookDescription>(); - for(Demo.BookDescription book : _books) - { - data.books.add((Demo.BookDescription)book.clone()); - } - data.nrows = _nrows; - if(_currentBook == NEW_BOOK) - { - data.currentBook = new Demo.BookDescription(); - data.currentBook.proxy = null; - data.currentBook.isbn = ""; - data.currentBook.title = ""; - data.currentBook.rentedBy = ""; - data.currentBook.authors = new ArrayList<String>(); - } - else if(_currentBook != NO_BOOK) - { - data.currentBook = (Demo.BookDescription)_books.get(_currentBook).clone(); - } - return data; - } - - // An empty query - QueryController(Handler handler, Demo.LibraryPrx library) - { - _handler = handler; - _library = library; - } - - QueryController(Handler handler, Demo.LibraryPrx library, final Listener listener, final QueryType _type, final String _queryString) - { - _handler = handler; - _listener = listener; - _library = library; - - // Send the initial data change notification. - _listener.onDataChange(getQueryModel(), false); - _rowsQueried = 10; - - if(_type == QueryType.ISBN) - { - Demo.Callback_Library_queryByIsbn cb = new Demo.Callback_Library_queryByIsbn() - { - @Override - public void exception(Ice.LocalException ex) - { - postError(ex.toString()); - } - - @Override - public void response(List<Demo.BookDescription> first, int nrows, Demo.BookQueryResultPrx result) - { - queryResponse(first, nrows, result); - } - }; - - _library.begin_queryByIsbn(_queryString, 10, cb); - } - else if(_type == QueryType.AUTHOR) - { - Demo.Callback_Library_queryByAuthor cb = new Demo.Callback_Library_queryByAuthor() - { - @Override - public void exception(Ice.LocalException ex) - { - postError(ex.toString()); - } - - @Override - public void response(List<Demo.BookDescription> first, int nrows, Demo.BookQueryResultPrx result) - { - queryResponse(first, nrows, result); - } - }; - - _library.begin_queryByAuthor(_queryString, 10, cb); - } - else - { - Demo.Callback_Library_queryByTitle cb = new Demo.Callback_Library_queryByTitle() - { - @Override - public void exception(Ice.LocalException ex) - { - postError(ex.toString()); - } - - @Override - public void response(List<Demo.BookDescription> first, int nrows, Demo.BookQueryResultPrx result) - { - queryResponse(first, nrows, result); - } - }; - _library.begin_queryByTitle(_queryString, 10, cb); - } - } - - protected void destroy() - { - if(_query != null) - { - _query.begin_destroy(new Demo.Callback_BookQueryResult_destroy() - { - @Override - public void exception(Ice.LocalException ex) - { - } - - @Override - public void response() - { - } - }); - _query = null; - } - } - - synchronized public void setListener(Listener cb) - { - _listener = cb; - _listener.onDataChange(getQueryModel(), false); - if(_lastError != null) - { - _listener.onError(); - } - } - - synchronized public String getLastError() - { - return _lastError; - } - - synchronized public void clearLastError() - { - _lastError = null; - } - - synchronized public void getMore(int position) - { - assert position < _nrows; - if(position < _rowsQueried) - { - return; - } - - Demo.Callback_BookQueryResult_next cb = new Demo.Callback_BookQueryResult_next() - { - @Override - public void exception(Ice.LocalException ex) - { - postError(ex.toString()); - } - - @Override - public void response(final List<Demo.BookDescription> ret, final boolean destroyed) - { - synchronized(QueryController.this) - { - _books.addAll(ret); - postDataChanged(false); - } - } - }; - _query.begin_next(10, cb); - _rowsQueried += 10; - } - - synchronized public boolean setCurrentBook(int row) - { - if(row < _books.size()) - { - _currentBook = row; - return true; - } - return false; - } - - synchronized public void returnBook() - { - assert _currentBook != NO_BOOK; - final Demo.BookDescription desc = _books.get(_currentBook); - Demo.Callback_Book_returnBook returnBookCB = new Demo.Callback_Book_returnBook() - { - @Override - public void exception(Ice.LocalException ex) - { - postError(ex.toString()); - } - - @Override - public void exception(Ice.UserException ex) - { - final String error; - if(ex instanceof Demo.BookNotRentedException) - { - error = "The book is no longer rented."; - - desc.rentedBy = ""; - postDataChanged(false); - } - else - { - error = "An error occurred: " + ex.toString(); - } - postError(error); - } - - @Override - public void response() - { - synchronized(QueryController.this) - { - desc.rentedBy = ""; - postDataChanged(false); - } - } - }; - desc.proxy.begin_returnBook(returnBookCB); - } - - synchronized public void rentBook(final String r) - { - assert _currentBook != NO_BOOK; - final Demo.BookDescription desc = _books.get(_currentBook); - Demo.Callback_Book_rentBook rentBookCB = new Demo.Callback_Book_rentBook() - { - @Override - public void exception(final Ice.LocalException ex) - { - postError(ex.toString()); - } - - @Override - public void exception(Ice.UserException ex) - { - final String error; - if(ex instanceof Demo.InvalidCustomerException) - { - error = "The customer name is invalid."; - } - else if(ex instanceof Demo.BookRentedException) - { - error = "That book is already rented."; - - Demo.BookRentedException bre = (Demo.BookRentedException)ex; - desc.rentedBy = bre.renter; - postDataChanged(false); - } - else - { - error = "An error occurred: " + ex.toString(); - } - postError(error); - } - - @Override - public void response() - { - synchronized(QueryController.this) - { - desc.rentedBy = r; - postDataChanged(false); - } - } - }; - desc.proxy.begin_rentBook(r, rentBookCB); - } - - synchronized public void deleteBook() - { - assert _currentBook != NO_BOOK; - final Demo.BookDescription desc = _books.get(_currentBook); - desc.proxy.begin_destroy(new Demo.Callback_Book_destroy() - { - @Override - public void exception(Ice.LocalException ex) - { - postError(ex.toString()); - } - - @Override - public void response() - { - synchronized(QueryController.this) - { - _books.remove(_currentBook); - _currentBook = NO_BOOK; - --_nrows; - postDataChanged(false); - } - } - }); - } - - synchronized public boolean saveBook(final Demo.BookDescription newDesc) - { - assert _currentBook != NO_BOOK; - if(_currentBook == NEW_BOOK) - { - _library.begin_createBook(newDesc.isbn, newDesc.title, newDesc.authors, - new Demo.Callback_Library_createBook() - { - @Override - public void exception(Ice.LocalException ex) - { - postError(ex.toString()); - } - - @Override - public void exception(Ice.UserException ex) - { - if(ex instanceof Demo.BookExistsException) - { - postError("That ISBN is already in the library."); - } - else - { - postError("Unknown error: " + ex.toString()); - } - } - - @Override - public void response(Demo.BookPrx ret) - { - synchronized(QueryController.this) - { - _currentBook = NO_BOOK; - postDataChanged(true); - } - } - - }); - - return true; - } - - final Demo.BookDescription desc = _books.get(_currentBook); - - final boolean saveTitle = !newDesc.title.equals(desc.title); - final boolean saveAuthors = !newDesc.authors.equals(desc.authors); - - // If nothing changed we're done. - if(!saveTitle && !saveAuthors) - { - return false; - } - - Runnable r = new Runnable() - { - public void run() - { - try - { - if(saveTitle) - { - desc.proxy.setTitle(newDesc.title); - desc.title = newDesc.title; - } - if(saveAuthors) - { - desc.proxy.setAuthors(newDesc.authors); - desc.authors = newDesc.authors; - } - postDataChanged(true); - } - catch(Ice.LocalException ex) - { - postError(ex.toString()); - } - } - }; - new Thread(r).start(); - return true; - } -} diff --git a/java/demo/android/library/src/com/zeroc/library/controller/QueryModel.java b/java/demo/android/library/src/com/zeroc/library/controller/QueryModel.java deleted file mode 100644 index 6dd2e817b3c..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/controller/QueryModel.java +++ /dev/null @@ -1,19 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library.controller; - -import java.util.List; - -public class QueryModel -{ - public List<Demo.BookDescription> books; - public int nrows; - public Demo.BookDescription currentBook; -} diff --git a/java/demo/android/library/src/com/zeroc/library/controller/SessionAdapter.java b/java/demo/android/library/src/com/zeroc/library/controller/SessionAdapter.java deleted file mode 100644 index c863220e9b0..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/controller/SessionAdapter.java +++ /dev/null @@ -1,17 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library.controller; - -interface SessionAdapter -{ - void destroy(); - void refresh(); - Demo.LibraryPrx getLibrary(); -} diff --git a/java/demo/android/library/src/com/zeroc/library/controller/SessionController.java b/java/demo/android/library/src/com/zeroc/library/controller/SessionController.java deleted file mode 100644 index 95c4217567b..00000000000 --- a/java/demo/android/library/src/com/zeroc/library/controller/SessionController.java +++ /dev/null @@ -1,171 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -package com.zeroc.library.controller; - -import android.os.Handler; - -public class SessionController -{ - public interface Listener - { - void onDestroy(); - } - - private Handler _handler; - private Ice.Communicator _communicator; - private QueryController _queryController; - private Listener _sessionListener; - private boolean _fatal = false; - private boolean _destroyed = false; - - private SessionAdapter _session; - - class SessionRefreshThread extends Thread - { - SessionRefreshThread(long timeout) - { - _timeout = timeout; // seconds. - } - - synchronized public void - run() - { - while(!_terminated) - { - // check idle. - try - { - wait(_timeout); - } - catch(InterruptedException e) - { - } - if(!_terminated) - { - try - { - _session.refresh(); - } - catch(Ice.LocalException ex) - { - postSessionDestroyed(); - _terminated = true; - } - } - } - } - - synchronized private void - terminate() - { - _terminated = true; - notify(); - } - - final private long _timeout; - private boolean _terminated = false; - } - private SessionRefreshThread _refresh; - - synchronized private void postSessionDestroyed() - { - _fatal = true; - if(_sessionListener != null) - { - final Listener listener = _sessionListener; - _handler.post(new Runnable() - { - public void run() - { - listener.onDestroy(); - } - }); - } - } - - SessionController(Handler handler, Ice.Communicator communicator, SessionAdapter session, long refreshTimeout) - { - _communicator = communicator; - _session = session; - _handler = handler; - - _refresh = new SessionRefreshThread(refreshTimeout); - _refresh.start(); - - _queryController = new QueryController(_handler, _session.getLibrary()); - } - - synchronized public void destroy() - { - if(_destroyed) - { - return; - } - _destroyed = true; - - new Thread(new Runnable() - { - public void run() - { - _queryController.destroy(); - - _refresh.terminate(); - while(_refresh.isAlive()) - { - try - { - _refresh.join(); - } - catch(InterruptedException e) - { - } - } - - try - { - _session.destroy(); - } - catch(Exception e) - { - } - - try - { - _communicator.destroy(); - } - catch(Exception e) - { - } - } - }).start(); - } - - synchronized public void setSessionListener(Listener listener) - { - _sessionListener = listener; - if(_fatal) - { - listener.onDestroy(); - } - } - - synchronized public QueryController createQuery(QueryController.Listener listener, QueryController.QueryType t, - String q) - { - _queryController.destroy(); - _queryController = new QueryController(_handler, _session.getLibrary(), listener, t, q); - return _queryController; - } - - synchronized public QueryController getCurrentQuery() - { - return _queryController; - } -} |