net.sf.dictccfe.and
Class DictAndActivity

java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.view.ContextThemeWrapper
              extended by android.app.Activity
                  extended by net.sf.dictccfe.and.DictAndActivity
All Implemented Interfaces:
android.content.ComponentCallbacks, android.content.DialogInterface.OnCancelListener, android.view.KeyEvent.Callback, android.view.LayoutInflater.Factory, android.view.View.OnCreateContextMenuListener, android.view.Window.Callback, IProgress, ISearchResult

public final class DictAndActivity
extends android.app.Activity
implements ISearchResult, IProgress, android.content.DialogInterface.OnCancelListener

Main android app class.

Version:
$Revision$
Author:
Daniel Stoinski

Nested Class Summary
private  class DictAndActivity.DictSelector
          Listener for the dialog box for selecting or loading the dictionary.
private  class DictAndActivity.ExcpShower
          For showing the given exception from a background thread.
private  class DictAndActivity.ListViewKeyListener
          Exact searching if the D-Pad center or Enter key has been pressed in the ListView in the lower part of the window.
private  class DictAndActivity.LVUpdater
          Used for updating the list view.
private  class DictAndActivity.ProgrShower
           
private  class DictAndActivity.TextViewKeyListener
          Calls search exact if the D-Pad center or Enter key has been pressed in the TextView above.
 
Field Summary
private  android.database.sqlite.SQLiteDatabase m_db
          The dictionary index database.
private  java.lang.CharSequence m_dictname
          The name of the dictionary currently used.
private  DictAndActivity.ExcpShower m_excpshow
          Used for showing exceptions from possibly background threads.
private  android.os.Handler m_handler
          For doing UI operations from background threads.
private  IdxLoader m_idxloader
          For loading the index files into the dictionary index database.
private  DictAndActivity.LVUpdater m_lvupdater
          Results ListView updater.
private  android.content.SharedPreferences m_prefs
          The last configuration used by the application.
private  DictAndActivity.ProgrShower m_progrshow
          For showing a progress of a background application.
private  java.util.ArrayList<java.lang.CharSequence> m_resultarr
          Array of search results, The list view is synchronized with this array.
private  Search m_srch
          The search engine.
 
Fields inherited from class android.app.Activity
DEFAULT_KEYS_DIALER, DEFAULT_KEYS_DISABLE, DEFAULT_KEYS_SEARCH_GLOBAL, DEFAULT_KEYS_SEARCH_LOCAL, DEFAULT_KEYS_SHORTCUT, FOCUSED_STATE_SET, RESULT_CANCELED, RESULT_FIRST_USER, RESULT_OK
 
Fields inherited from class android.content.Context
ACCESSIBILITY_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, INPUT_METHOD_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MODE_APPEND, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NOTIFICATION_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, TELEPHONY_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
Constructor Summary
DictAndActivity()
          The constructor initializes local variables.
 
Method Summary
 void addResult(java.lang.CharSequence aResult)
          Called for single results found while searching.
 void endProgress(int aProgress)
          Closes the progress showing gauge window.
 void endResults()
          Called if a search engine starts returning results.
private  void loadDictionary()
          Creates a submenu allowing the user to load a dictionary.
 void loadDictionary(java.lang.String aDictionaryName)
          Starts loading the dictionary index file.
 void onCancel(android.content.DialogInterface aDialog)
          Called if the progress dialog is cancelled.
 void onCreate(android.os.Bundle savedInstanceState)
          Called when the activity is first created.
 boolean onCreateOptionsMenu(android.view.Menu menu)
          Creates the application menu.
 void onDestroy()
           
 void onLowMemory()
           
 boolean onOptionsItemSelected(android.view.MenuItem aMenuItem)
          Reacts on menu selections.
 void onStop()
           
private  void searchexact(java.lang.CharSequence aKeyword)
          Starts exact searching for a description of a keyword.
private  void searchexactlv(int aPos)
          Starts exact searching for the description in the list view control.
private  void searchexacttv()
          Starts exact searching for the description in the text view control.
private  void searchsimilar()
          Starts similar searching for the description in the text view control.
private  void searchsimilar(java.lang.CharSequence aKeyword)
          Starts searching for similar keywords.
private  void selectDictionary()
          Creates a submenu allowing the user to select a loaded dictionary.
 void selectDictionary(java.lang.String aDictionaryName)
          Selects a dictionary with the given name.
 void showException(java.lang.Exception anExcp)
          Shows exception in a separate dialog window.
 void showProgress(int aProgress)
          Shows progress in a progress showing gauge window.
 void startProgress(int aProgress)
          Starts a progress showing gauge window.
 void startResults()
          Called if a search engine starts returning results.
private  void stop()
          Stops any currently running background operations.
private  void stopall()
          Stops currently running background jobs and closes the dictionary.
 
Methods inherited from class android.app.Activity
addContentView, closeContextMenu, closeOptionsMenu, createPendingResult, dismissDialog, dispatchKeyEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, finalize, findViewById, finish, finishActivity, finishActivityFromChild, finishFromChild, getApplication, getCallingActivity, getCallingPackage, getChangingConfigurations, getComponentName, getCurrentFocus, getInstanceCount, getIntent, getLastNonConfigurationInstance, getLayoutInflater, getLocalClassName, getMenuInflater, getParent, getPreferences, getRequestedOrientation, getSystemService, getTaskId, getTitle, getTitleColor, getVolumeControlStream, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, getWindow, getWindowManager, hasWindowFocus, isChild, isFinishing, isTaskRoot, managedQuery, moveTaskToBack, onActivityResult, onApplyThemeResource, onChildTitleChanged, onConfigurationChanged, onContentChanged, onContextItemSelected, onContextMenuClosed, onCreateContextMenu, onCreateDescription, onCreateDialog, onCreatePanelMenu, onCreatePanelView, onCreateThumbnail, onCreateView, onKeyDown, onKeyMultiple, onKeyUp, onMenuItemSelected, onMenuOpened, onNewIntent, onOptionsMenuClosed, onPanelClosed, onPause, onPostCreate, onPostResume, onPrepareDialog, onPrepareOptionsMenu, onPreparePanel, onRestart, onRestoreInstanceState, onResume, onRetainNonConfigurationInstance, onSaveInstanceState, onSearchRequested, onStart, onTitleChanged, onTouchEvent, onTrackballEvent, onUserInteraction, onUserLeaveHint, onWindowAttributesChanged, onWindowFocusChanged, openContextMenu, openOptionsMenu, registerForContextMenu, removeDialog, requestWindowFeature, runOnUiThread, setContentView, setContentView, setContentView, setDefaultKeyMode, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setIntent, setPersistent, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRequestedOrientation, setResult, setResult, setSecondaryProgress, setTitle, setTitle, setTitleColor, setVisible, setVolumeControlStream, showDialog, startActivity, startActivityForResult, startActivityFromChild, startActivityIfNeeded, startManagingCursor, startNextMatchingActivity, startSearch, stopManagingCursor, takeKeyEvents, unregisterForContextMenu
 
Methods inherited from class android.view.ContextThemeWrapper
attachBaseContext, getTheme, setTheme
 
Methods inherited from class android.content.ContextWrapper
bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getFilesDir, getFileStreamPath, getMainLooper, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getWallpaper, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendStickyBroadcast, setWallpaper, setWallpaper, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
 
Methods inherited from class android.content.Context
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_resultarr

private java.util.ArrayList<java.lang.CharSequence> m_resultarr
Array of search results, The list view is synchronized with this array.


m_handler

private android.os.Handler m_handler
For doing UI operations from background threads. It is not possible to change UI elements from threads, you have to use a Handler and post methods.


m_lvupdater

private DictAndActivity.LVUpdater m_lvupdater
Results ListView updater. Used in connection with the Handler m_handler and background threads in order to make updates of the ListView element possible from threads. See also http://developer.android.com/guide/appendix/faq/commontasks.html#threading for more hints.


m_excpshow

private final DictAndActivity.ExcpShower m_excpshow
Used for showing exceptions from possibly background threads.


m_progrshow

private final DictAndActivity.ProgrShower m_progrshow
For showing a progress of a background application.


m_dictname

private java.lang.CharSequence m_dictname
The name of the dictionary currently used.


m_idxloader

private IdxLoader m_idxloader
For loading the index files into the dictionary index database.


m_srch

private Search m_srch
The search engine. Both for exact and similar searching.


m_db

private android.database.sqlite.SQLiteDatabase m_db
The dictionary index database.


m_prefs

private android.content.SharedPreferences m_prefs
The last configuration used by the application.

Constructor Detail

DictAndActivity

public DictAndActivity()
The constructor initializes local variables.

Method Detail

stop

private void stop()
Stops any currently running background operations.


stopall

private void stopall()
Stops currently running background jobs and closes the dictionary. The method does the following:
  1. Stops background jobs using stop().
  2. Closes the dictionary index database.
  3. Extracts the last used dictionary name and the last last search item from the edit and text view.
  4. Stores the last used dictionary and search item in the so called shared preferences.


searchexacttv

private void searchexacttv()
Starts exact searching for the description in the text view control.


searchexactlv

private void searchexactlv(int aPos)
Starts exact searching for the description in the list view control.

Parameters:
aPos - the position (o-based) of the clicked row in the list view.

searchsimilar

private void searchsimilar()
Starts similar searching for the description in the text view control.


searchexact

private void searchexact(java.lang.CharSequence aKeyword)
Starts exact searching for a description of a keyword.

Parameters:
aKeyword - the keyword.

searchsimilar

private void searchsimilar(java.lang.CharSequence aKeyword)
Starts searching for similar keywords.

Parameters:
aKeyword - the keyword pattern for which to find similar keywords.

loadDictionary

private void loadDictionary()
Creates a submenu allowing the user to load a dictionary.


selectDictionary

private void selectDictionary()
Creates a submenu allowing the user to select a loaded dictionary.


loadDictionary

public final void loadDictionary(java.lang.String aDictionaryName)
Starts loading the dictionary index file.

Parameters:
aDictionaryName - the name of the dictionary to load.

selectDictionary

public final void selectDictionary(java.lang.String aDictionaryName)
Selects a dictionary with the given name. In fact it opens a dictionary index database for the given dictionary name for reading. See IdxLoader.opendb().

Parameters:
aDictionaryName - the name of the dictionary to load.

onCreate

public final void onCreate(android.os.Bundle savedInstanceState)
Called when the activity is first created.

Overrides:
onCreate in class android.app.Activity
Parameters:
savedInstanceState - ignored

onLowMemory

public final void onLowMemory()
Specified by:
onLowMemory in interface android.content.ComponentCallbacks
Overrides:
onLowMemory in class android.app.Activity

onStop

public final void onStop()
Overrides:
onStop in class android.app.Activity

onDestroy

public final void onDestroy()
Overrides:
onDestroy in class android.app.Activity

onCreateOptionsMenu

public final boolean onCreateOptionsMenu(android.view.Menu menu)
Creates the application menu.

Overrides:
onCreateOptionsMenu in class android.app.Activity
Parameters:
menu - the in which to place our items.
Returns:
true

onOptionsItemSelected

public final boolean onOptionsItemSelected(android.view.MenuItem aMenuItem)
Reacts on menu selections.

Overrides:
onOptionsItemSelected in class android.app.Activity
Parameters:
aMenuItem - the selected menu item.
Returns:
true if menu processed here, false else.

startResults

public final void startResults()
Called if a search engine starts returning results. Clears the contents of the list view for the results.

Specified by:
startResults in interface ISearchResult

addResult

public final void addResult(java.lang.CharSequence aResult)
Called for single results found while searching. Puts the given string into the array of results. The results are printed first after endResults().

Specified by:
addResult in interface ISearchResult
Parameters:
aResult - the single result found by the search engine. Added to the list view. been cancelled.

endResults

public final void endResults()
Called if a search engine starts returning results. Prints the results in the list view.

Specified by:
endResults in interface ISearchResult

startProgress

public final void startProgress(int aProgress)
Starts a progress showing gauge window.

Specified by:
startProgress in interface IProgress
Parameters:
aProgress - the initial progress in percents.

showProgress

public final void showProgress(int aProgress)
Shows progress in a progress showing gauge window.

Specified by:
showProgress in interface IProgress
Parameters:
aProgress - the progress.

endProgress

public final void endProgress(int aProgress)
Closes the progress showing gauge window.

Specified by:
endProgress in interface IProgress
Parameters:
aProgress - the final progress to show.

showException

public final void showException(java.lang.Exception anExcp)
Shows exception in a separate dialog window.

Specified by:
showException in interface IProgress
Specified by:
showException in interface ISearchResult
Parameters:
anExcp - the exception to show.

onCancel

public final void onCancel(android.content.DialogInterface aDialog)
Called if the progress dialog is cancelled. Stops all background jobs.

Specified by:
onCancel in interface android.content.DialogInterface.OnCancelListener
Parameters:
aDialog - ignored