Merge branch 'android_studylist' into android_branch

This commit is contained in:
Eric House 2014-01-31 06:43:36 -08:00
commit ff2615fbc6
22 changed files with 528 additions and 28 deletions

View file

@ -3,4 +3,7 @@ local.properties
bin
gen
proguard.cfg
proguard-project.txt
obj
res/drawable*/*gen.png
img_src

View file

@ -125,6 +125,10 @@
android:theme="@android:style/Theme.Dialog"
/>
<activity android:name="StudyList"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
<receiver android:name="RelayReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="120"
height="120" xml:space="preserve">
<g
id="g12"
transform="matrix(1.25,0,0,-1.25,0,120)">
<path style='fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none' d='M 29.99,72.01 78,72.01 78,11.99 29.99,11.99 29.99,72.01 z M 72,66 36,66 36,17.99 72,17.99 72,66 z M 55.34,53 42,53 42,55 55.34,55 55.34,53 z M 66,47 41.99,47 41.99,49 66,49 66,47 z M 59.34,41 42,41 42,43 59.34,43 59.34,41 z M 55.34,35 42,35 42,37 55.34,37 55.34,35 z M 64.67,28.99 41.99,28.99 41.99,30.99 64.67,30.99 64.67,28.99 z M 60.01,78.01 23.99,78.01 23.99,29.99 26.99,29.99 26.99,23.99 23.99,23.99 17.99,23.99 17.99,84.01 66,84.01 66,78.01 66,75.01 60.01,75.01 60.01,78.01 z' id='path1220'/></g>
</svg>

After

Width:  |  Height:  |  Size: 933 B

View file

@ -19,6 +19,10 @@
android:layout_weight="1"
/>
<Button android:id="@+id/button_study"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:id="@+id/button_done"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
>
<LinearLayout android:id="@+id/pick_lang"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/study_langpick"
/>
<Spinner android:id="@+id/pick_lang_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
/>
</LinearLayout>
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"
/>
</LinearLayout>

View file

@ -57,6 +57,10 @@
android:title="@string/board_menu_game_resend" />
</menu>
</item>
<item android:id="@+id/games_menu_study"
android:title="@string/gamel_menu_study"
/>
<item android:id="@+id/gamel_menu_checkmoves"
android:title="@string/gamel_menu_checkmoves"

View file

@ -26,6 +26,9 @@
android:icon="@drawable/dict__gen"
android:showAsAction="ifRoom"
/>
<item android:id="@+id/games_menu_study"
android:title="@string/gamel_menu_study"
/>
<item android:id="@+id/games_menu_email"
android:title="@string/board_menu_file_email"
android:icon="@drawable/email__gen"

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/copy_all"
android:title="@string/slmenu_copy_all"
android:icon="@drawable/content_copy__gen"
android:showAsAction="ifRoom"
/>
<item android:id="@+id/clear_all"
android:title="@string/slmenu_clear_all"
android:icon="@drawable/content_discard__gen"
android:showAsAction="ifRoom"
/>
</menu>

View file

@ -58,6 +58,7 @@
<string name="key_enable_sms">key_enable_sms</string>
<string name="key_keep_screenon">key_keep_screenon</string>
<string name="key_thumbsize">key_thumbsize3</string>
<string name="key_studyon">key_studyon</string>
<string name="key_summary_field">key_summary_field</string>
<string name="key_default_loc">key_default_loc</string>
@ -106,6 +107,7 @@
<string name="key_na_browse">key_na_browse</string>
<string name="key_na_browseall">key_na_browseall</string>
<string name="key_na_values">key_na_values</string>
<string name="key_na_studycopy">key_na_studycopy</string>
<string name="key_enable_debug">key_enable_debug</string>
<string name="key_enable_dup_invite">key_enable_dup_invite</string>
<string name="key_download_path">key_download_path</string>

View file

@ -1788,10 +1788,13 @@
<!-- New strings that need to be documented and found a home
above. -->
<string name="button_lookup">Look up words</string>
<string name="button_lookup_study">Look up/study words</string>
<!-- -->
<string name="button_lookupf">Look up %s</string>
<string name="button_lookup_studyf">Look up/study %s</string>
<!-- -->
<string name="title_lookup">Tap to look up</string>
<string name="title_lookup_study">Tap to look up or study</string>
<!-- -->
<string name="button_done">Done</string>
<!-- -->
@ -2200,4 +2203,29 @@
<string name="menu_rateme">Rate Crosswords</string>
<string name="no_market">Google Play app not found</string>
<string name="add_to_studyf">Add %s to studylist</string>
<string name="title_studyon">Enable studylists</string>
<string name="summary_studyon">Offer to add to and display lists
of words to remember</string>
<string name="gamel_menu_study">Studylist…</string>
<string name="slmenu_copy_all">Copy to clipboard</string>
<string name="slmenu_clear_all">Delete</string>
<string name="confirm_studylist_clear">Are you sure you want to
delete this list?\n\n(This action cannot be undone.)</string>
<string name="paste_donef">%d word[s] copied</string>
<string name="studylist_titlef">Studylist for %s</string>
<string name="study_langpick">Your words for:</string>
<string name="study_no_langf">You have not yet saved any words
into a studylist for %s.</string>
<string name="study_no_lists">You have not yet saved any words
into a studylist.</string>
<string name="not_again_studycopy">The words in this list will be
copied to the system clipboard. You can then paste them into any
app that supports pasting text, e.g. an email app.</string>
</resources>

View file

@ -246,6 +246,11 @@
android:summary="@string/summary_sort_tiles"
android:defaultValue="true"
/>
<CheckBoxPreference android:key="@string/key_studyon"
android:title="@string/title_studyon"
android:summary="@string/summary_studyon"
android:defaultValue="false"
/>
<CheckBoxPreference android:key="@string/key_ringer_zoom"
android:title="@string/ringer_zoom"
android:summary="@string/ringer_zoom_summary"

View file

@ -393,12 +393,16 @@ public class BoardActivity extends XWActivity
} else if ( DLG_SCORES_BLK == id ) {
if ( null != m_words && m_words.length > 0 ) {
String buttonTxt;
boolean studyOn = XWPrefs.getStudyEnabled( this );
if ( m_words.length == 1 ) {
buttonTxt = Utils.format( this,
R.string.button_lookupf,
m_words[0] );
int resID = studyOn
? R.string.button_lookup_studyf
: R.string.button_lookupf;
buttonTxt = Utils.format( this, resID, m_words[0] );
} else {
buttonTxt = getString( R.string.button_lookup );
int resID = studyOn ? R.string.button_lookup_study
: R.string.button_lookup;
buttonTxt = getString( resID );
}
lstnr = new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog,
@ -800,6 +804,9 @@ public class BoardActivity extends XWActivity
Utils.setItemVisible( menu, R.id.gamel_menu_checkmoves, false );
}
boolean enable = XWPrefs.getStudyEnabled( this );
Utils.setItemVisible( menu, R.id.games_menu_study, enable );
return true;
} // onPrepareOptionsMenu
@ -863,6 +870,9 @@ public class BoardActivity extends XWActivity
case R.id.board_menu_tray:
cmd = JNICmd.CMD_TOGGLE_TRAY;
break;
case R.id.games_menu_study:
StudyList.launchOrAlert( this, m_gi.dictLang, this );
break;
case R.id.board_menu_undo_current:
cmd = JNICmd.CMD_UNDO_CUR;
break;

View file

@ -36,8 +36,9 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String TABLE_NAME_DICTBROWSE = "dictbrowse";
public static final String TABLE_NAME_DICTINFO = "dictinfo";
public static final String TABLE_NAME_GROUPS = "groups";
public static final String TABLE_NAME_STUDYLIST = "study";
private static final String DB_NAME = "xwdb";
private static final int DB_VERSION = 18;
private static final int DB_VERSION = 19;
public static final String GAME_NAME = "GAME_NAME";
public static final String VISID = "VISID";
@ -87,6 +88,9 @@ public class DBHelper extends SQLiteOpenHelper {
public static final String GROUPNAME = "GROUPNAME";
public static final String EXPANDED = "EXPANDED";
public static final String WORD = "WORD";
public static final String LANGUAGE = "LANGUAGE";
private Context m_context;
private static final String[][] s_summaryColsAndTypes = {
@ -153,6 +157,12 @@ public class DBHelper extends SQLiteOpenHelper {
,{ EXPANDED, "INTEGER(1)" }
};
private static final String[][] s_studySchema = {
{ WORD, "TEXT" }
,{ LANGUAGE, "INTEGER(1)" }
,{ "UNIQUE", "(" + WORD + ", " + LANGUAGE + ")" }
};
public DBHelper( Context context )
{
super( context, DB_NAME, null, DB_VERSION );
@ -173,6 +183,7 @@ public class DBHelper extends SQLiteOpenHelper {
createTable( db, TABLE_NAME_DICTBROWSE, s_dictBrowseColsAndTypes );
forceRowidHigh( db, TABLE_NAME_SUM );
createGroupsTable( db );
createStudyTable( db );
}
@Override
@ -215,7 +226,8 @@ public class DBHelper extends SQLiteOpenHelper {
makeAutoincrement( db, TABLE_NAME_SUM, s_summaryColsAndTypes );
case 17:
addSumColumn( db, THUMBNAIL );
// nothing yet
case 18:
createStudyTable( db );
break;
default:
db.execSQL( "DROP TABLE " + TABLE_NAME_SUM + ";" );
@ -278,6 +290,11 @@ public class DBHelper extends SQLiteOpenHelper {
XWPrefs.setDefaultNewGameGroup( m_context, newGroup );
}
private void createStudyTable( SQLiteDatabase db )
{
createTable( db, TABLE_NAME_STUDYLIST, s_studySchema );
}
// Move all existing games to the row previously named "cur games'
private void moveToCurGames( SQLiteDatabase db )
{

View file

@ -1565,6 +1565,87 @@ public class DBUtils {
return colNames;
}
public static void addToStudyList( Context context, String word,
int lang )
{
ContentValues values = new ContentValues();
values.put( DBHelper.WORD, word );
values.put( DBHelper.LANGUAGE, lang );
initDB( context );
synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
db.insert( DBHelper.TABLE_NAME_STUDYLIST, null, values );
db.close();
}
}
public static int[] studyListLangs( Context context )
{
int[] result = null;
String groupBy = DBHelper.LANGUAGE;
String selection = null;//DBHelper.LANGUAGE;
String[] columns = { DBHelper.LANGUAGE };
initDB( context );
synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
Cursor cursor = db.query( DBHelper.TABLE_NAME_STUDYLIST, columns,
null, null, groupBy, null, null );
int count = cursor.getCount();
result = new int[count];
if ( 0 < count ) {
int index = 0;
int colIndex = cursor.getColumnIndex( DBHelper.LANGUAGE );
while ( cursor.moveToNext() ) {
result[index++] = cursor.getInt(colIndex);
}
}
cursor.close();
db.close();
}
return result;
}
public static String[] studyListWords( Context context, int lang )
{
String[] result = null;
String selection = String.format( "%s = %d", DBHelper.LANGUAGE, lang );
String[] columns = { DBHelper.WORD };
String orderBy = DBHelper.WORD;
initDB( context );
synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
Cursor cursor = db.query( DBHelper.TABLE_NAME_STUDYLIST, columns,
selection, null, null, null, orderBy );
int count = cursor.getCount();
result = new String[count];
if ( 0 < count ) {
int index = 0;
int colIndex = cursor.getColumnIndex( DBHelper.WORD );
while ( cursor.moveToNext() ) {
result[index++] = cursor.getString(colIndex);
}
}
cursor.close();
db.close();
}
return result;
}
public static void studyListClear( Context context, int lang )
{
String selection = String.format( "%s = %d", DBHelper.LANGUAGE, lang );
initDB( context );
synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
db.delete( DBHelper.TABLE_NAME_STUDYLIST, selection, null );
db.close();
}
}
private static void copyGameDB( Context context, boolean toSDCard )
{
String name = DBHelper.getDBName();

View file

@ -59,6 +59,10 @@ public class DlgDelegate {
public interface DlgClickNotify {
void dlgButtonClicked( int id, int button, Object[] params );
}
public interface HasDlgDelegate {
void showOKOnlyDialog( int msgID );
void showOKOnlyDialog( String msg );
}
private Activity m_activity;
private DlgClickNotify m_clickCallback;
@ -253,13 +257,9 @@ public class DlgDelegate {
}
}
public void launchLookup( String[] words, int lang, boolean forceList )
public void launchLookup( String[] words, int lang, boolean noStudyOption )
{
Intent intent = new Intent( m_activity, LookupActivity.class );
intent.putExtra( LookupActivity.WORDS, words );
intent.putExtra( LookupActivity.LANG, lang );
m_activity.startActivity( intent );
LookupActivity.launch( m_activity, words, lang, noStudyOption );
}
public void startProgress( int id )

View file

@ -717,6 +717,9 @@ public class GamesList extends XWExpandableListActivity
enable = nothingSelected && Utils.isGooglePlayApp( this );
Utils.setItemVisible( menu, R.id.games_menu_rateme, enable );
enable = nothingSelected && XWPrefs.getStudyEnabled( this );
Utils.setItemVisible( menu, R.id.games_menu_study, enable );
m_menuPrepared = super.onPrepareOptionsMenu( menu );
} else {
DbgUtils.logf( "onPrepareOptionsMenu: incomplete so bailing" );
@ -785,6 +788,10 @@ public class GamesList extends XWExpandableListActivity
}
break;
case R.id.games_menu_study:
StudyList.launchOrAlert( this, StudyList.NO_LANG, this );
break;
case R.id.games_menu_about:
showAboutDialog();
break;

View file

@ -20,6 +20,7 @@
package org.eehouse.android.xw4;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@ -41,7 +42,8 @@ public class LookupActivity extends XWListActivity
public static final String WORDS = "WORDS";
public static final String LANG = "LANG";
public static final String FORCELIST = "FORCELIST";
public static final String NOSTUDY = "NOSTUDY";
private static final String FORCELIST = "FORCELIST";
private static final String STATE = "STATE";
private static final String WORDINDEX = "WORDINDEX";
private static final String URLINDEX = "URLINDEX";
@ -62,11 +64,13 @@ public class LookupActivity extends XWListActivity
private String[] m_words;
private boolean m_forceList;
private boolean m_studyOn;
private int m_wordIndex = 0;
private int m_urlIndex = 0;
private int m_state;
private ArrayAdapter<String> m_wordsAdapter;
private Button m_doneButton;
private Button m_studyButton;
private TextView m_summary;
@Override
@ -80,6 +84,10 @@ public class LookupActivity extends XWListActivity
m_words = intent.getStringArrayExtra( WORDS );
setLang( intent.getIntExtra( LANG, -1 ) );
m_forceList = intent.getBooleanExtra( FORCELIST, false );
m_studyOn = XWPrefs.getStudyEnabled( this );
if ( m_studyOn ) {
m_studyOn = !intent.getBooleanExtra( NOSTUDY, false );
}
m_state = STATE_DONE;
adjustState( 1 );
@ -90,6 +98,12 @@ public class LookupActivity extends XWListActivity
m_doneButton = (Button)findViewById( R.id.button_done );
m_doneButton.setOnClickListener( this );
m_studyButton = (Button)findViewById( R.id.button_study );
if ( m_studyOn ) {
m_studyButton.setOnClickListener( this );
} else {
m_studyButton.setVisibility( View.GONE );
}
m_summary = (TextView)findViewById( R.id.summary );
@ -120,7 +134,12 @@ public class LookupActivity extends XWListActivity
/* View.OnClickListener -- just the Done button */
public void onClick( View view )
{
switchState( -1 );
if ( view == m_doneButton ) {
switchState( -1 );
} else if ( view == m_studyButton ) {
DBUtils.addToStudyList( this, m_words[m_wordIndex], s_lang );
m_studyButton.setEnabled( false );
}
}
/* AdapterView.OnItemClickListener */
@ -146,7 +165,7 @@ public class LookupActivity extends XWListActivity
m_state += incr;
}
if ( STATE_URLS == m_state &&
( 1 >= s_lookupUrls.length && !m_forceList ) ) {
( 1 >= s_lookupUrls.length && !m_forceList && !m_studyOn ) ) {
m_state += incr;
}
if ( m_state == curState ) {
@ -169,8 +188,10 @@ public class LookupActivity extends XWListActivity
break;
case STATE_WORDS:
getListView().setAdapter( m_wordsAdapter );
setSummary( R.string.title_lookup );
setSummary( m_studyOn ?
R.string.title_lookup_study : R.string.title_lookup );
m_doneButton.setText( R.string.button_done );
m_studyButton.setVisibility( View.GONE );
break;
case STATE_URLS:
getListView().setAdapter( s_urlsAdapter );
@ -178,6 +199,13 @@ public class LookupActivity extends XWListActivity
String txt = Utils.format( this, R.string.button_donef,
m_words[m_wordIndex] );
m_doneButton.setText( txt );
txt = Utils.format( this, R.string.add_to_studyf,
m_words[m_wordIndex] );
if ( m_studyOn ) {
m_studyButton.setVisibility( View.VISIBLE );
m_studyButton.setEnabled( true );
m_studyButton.setText( txt );
}
break;
case STATE_LOOKUP:
lookupWord( m_words[m_wordIndex], s_lookupUrls[m_urlIndex] );
@ -244,4 +272,15 @@ public class LookupActivity extends XWListActivity
String title = Utils.format( this, R.string.pick_url_titlef, word );
m_summary.setText( title );
}
public static void launch( Activity activity, String[] words, int lang,
boolean noStudyOption )
{
Intent intent = new Intent( activity, LookupActivity.class );
intent.putExtra( WORDS, words );
intent.putExtra( LANG, lang );
intent.putExtra( NOSTUDY, noStudyOption );
activity.startActivity( intent );
}
}

View file

@ -0,0 +1,227 @@
/* -*- compile-command: "cd ../../../../../; ant debug install"; -*- */
/*
* Copyright 2014 by Eric House (xwords@eehouse.org). All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.widget.ListView;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import junit.framework.Assert;
public class StudyList extends XWListActivity
implements OnItemSelectedListener {
public static final int NO_LANG = -1;
private static final int CLEAR_ACTION = 1;
private static final int COPY_ACTION = 2;
private static final String START_LANG = "START_LANG";
private Spinner m_spinner;
private View m_pickView; // LinearLayout, actually
private int[] m_langCodes;
private String[] m_words;
private int m_position;
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.studylist );
m_spinner = (Spinner)findViewById( R.id.pick_lang_spinner );
m_pickView = findViewById( R.id.pick_lang );
initOrFinish( getIntent() );
}
@Override
public boolean onCreateOptionsMenu( Menu menu )
{
getMenuInflater().inflate( R.menu.studylist, menu );
return true;
}
// @Override
// public boolean onPrepareOptionsMenu( Menu menu )
// {
// return true;
// }
public boolean onOptionsItemSelected( MenuItem item )
{
boolean handled = true;
switch ( item.getItemId() ) {
case R.id.copy_all:
showNotAgainDlgThen( R.string.not_again_studycopy,
R.string.key_na_studycopy,
COPY_ACTION );
break;
case R.id.clear_all:
showConfirmThen( R.string.confirm_studylist_clear, CLEAR_ACTION );
break;
default:
handled = false;
}
return handled;
}
//////////////////////////////////////////////////
// DlgDelegate.DlgClickNotify interface
//////////////////////////////////////////////////
@Override
public void dlgButtonClicked( int id, int which, Object[] params )
{
if ( AlertDialog.BUTTON_POSITIVE == which ) {
switch ( id ) {
case CLEAR_ACTION:
DBUtils.studyListClear( this, m_langCodes[m_position] );
initOrFinish( null );
break;
case COPY_ACTION:
ClipboardManager clipboard = (ClipboardManager)
getSystemService( Context.CLIPBOARD_SERVICE );
clipboard.setText( TextUtils.join( "\n", m_words ) );
String msg = getString( R.string.paste_donef, m_words.length );
Utils.showToast( this, msg );
break;
default:
Assert.fail();
break;
}
}
}
@Override
public void onListItemClick( ListView lv, View view, int position, long id )
{
String[] words = { m_words[position] };
launchLookup( words, m_langCodes[m_position], true );
}
//////////////////////////////////////////////////
// AdapterView.OnItemSelectedListener interface
//////////////////////////////////////////////////
public void onItemSelected( AdapterView<?> parent, View view,
int position, long id )
{
m_position = position;
loadList();
}
public void onNothingSelected( AdapterView<?> parent )
{
}
private void loadList()
{
int lang = m_langCodes[m_position];
m_words = DBUtils.studyListWords( this, lang );
ArrayAdapter<String> adapter = new ArrayAdapter<String>
( this, android.R.layout.simple_list_item_1 );
for ( String word : m_words ) {
adapter.add( word );
}
// adapter.sort();
setListAdapter( adapter );
String langName = DictLangCache.getLangNames( this )[lang];
String title = getString( R.string.studylist_titlef, langName );
setTitle( title );
}
private void initOrFinish( Intent startIntent )
{
m_langCodes = DBUtils.studyListLangs( this );
if ( 0 == m_langCodes.length ) {
finish();
} else if ( 1 == m_langCodes.length ) {
m_pickView.setVisibility( View.GONE );
m_position = 0;
loadList();
} else {
int startLang = NO_LANG;
int startIndex = -1;
if ( null != startIntent ) {
startLang = startIntent.getIntExtra( START_LANG, NO_LANG );
}
String[] names = DictLangCache.getLangNames( this );
String[] myNames = new String[m_langCodes.length];
for ( int ii = 0; ii < m_langCodes.length; ++ii ) {
int lang = m_langCodes[ii];
myNames[ii] = names[lang];
if ( lang == startLang ) {
startIndex = ii;
}
}
ArrayAdapter<String> adapter = new
ArrayAdapter<String>( this,
android.R.layout.simple_spinner_item,
myNames );
adapter.setDropDownViewResource( android.R.layout.
simple_spinner_dropdown_item );
m_spinner.setAdapter( adapter );
m_spinner.setOnItemSelectedListener( this );
if ( -1 != startIndex ) {
m_spinner.setSelection( startIndex );
}
}
}
public static void launchOrAlert( Context context, int lang,
DlgDelegate.HasDlgDelegate dlg )
{
String msg = null;
if ( 0 == DBUtils.studyListLangs( context ).length ) {
msg = context.getString( R.string.study_no_lists );
} else if ( NO_LANG != lang &&
0 == DBUtils.studyListWords( context, lang ).length ) {
String langname = DictLangCache.getLangName( context, lang );
msg = context.getString( R.string.study_no_langf, langname );
} else {
Intent intent = new Intent( context, StudyList.class );
if ( NO_LANG != lang ) {
intent.putExtra( START_LANG, lang );
}
context.startActivity( intent );
}
if ( null != msg ) {
dlg.showOKOnlyDialog( msg );
}
}
}

View file

@ -31,7 +31,8 @@ import android.widget.TextView;
import junit.framework.Assert;
public class XWActivity extends Activity
implements DlgDelegate.DlgClickNotify, MultiService.MultiEventListener {
implements DlgDelegate.DlgClickNotify, DlgDelegate.HasDlgDelegate,
MultiService.MultiEventListener {
private DlgDelegate m_delegate;
@ -123,12 +124,12 @@ public class XWActivity extends Activity
m_delegate.showNotAgainDlgThen( msgID, prefsKey );
}
protected void showOKOnlyDialog( int msgID )
public void showOKOnlyDialog( int msgID )
{
m_delegate.showOKOnlyDialog( msgID );
}
protected void showOKOnlyDialog( String msg )
public void showOKOnlyDialog( String msg )
{
m_delegate.showOKOnlyDialog( msg );
}

View file

@ -29,7 +29,8 @@ import junit.framework.Assert;
public class XWExpandableListActivity extends ExpandableListActivity
implements DlgDelegate.DlgClickNotify, MultiService.MultiEventListener {
implements DlgDelegate.DlgClickNotify, DlgDelegate.HasDlgDelegate,
MultiService.MultiEventListener {
private DlgDelegate m_delegate;
@ -107,12 +108,12 @@ public class XWExpandableListActivity extends ExpandableListActivity
m_delegate.showAboutDialog();
}
protected void showOKOnlyDialog( int msgID )
public void showOKOnlyDialog( int msgID )
{
m_delegate.showOKOnlyDialog( msgID );
}
protected void showOKOnlyDialog( String msg )
public void showOKOnlyDialog( String msg )
{
m_delegate.showOKOnlyDialog( msg );
}

View file

@ -168,16 +168,16 @@ public class XWListActivity extends ListActivity
Assert.fail();
}
protected void launchLookup( String[] words, int lang, boolean noStudy )
{
m_delegate.launchLookup( words, lang, noStudy );
}
protected void launchLookup( String[] words, int lang )
{
m_delegate.launchLookup( words, lang, false );
}
protected void launchLookup( String[] words, int lang, boolean forceList )
{
m_delegate.launchLookup( words, lang, forceList );
}
// MultiService.MultiEventListener interface
public void eventOccurred( MultiService.MultiEvent event,
final Object ... args )

View file

@ -370,6 +370,11 @@ public class XWPrefs {
return result;
}
public static boolean getStudyEnabled( Context context )
{
return getPrefsBoolean( context, R.string.key_studyon, false );
}
protected static String getPrefsString( Context context, int keyID )
{
String key = context.getString( keyID );
@ -424,4 +429,4 @@ public class XWPrefs {
{
setPrefsString( context, keyID, TextUtils.join( "\n", value ) );
}
}
}