mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-08 20:46:12 +01:00
Merge branch 'android_branch' into android_translate
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
This commit is contained in:
commit
1addd34e95
167 changed files with 4659 additions and 3829 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ core*
|
|||
xwords_4.4.0.0*
|
||||
gcm_loop.shelf
|
||||
nohup.out
|
||||
/xwords4/android/XWords4-dbg/src/xw4dbg/assets/gitvers.txt
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
android:debuggable="false"
|
||||
>
|
||||
|
||||
<activity android:name="GamesListActivity"
|
||||
<activity android:name="MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="standard"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
<antcall target="my-pre-clean" />
|
||||
</target>
|
||||
|
||||
<target name="-pre-build" depends="my-copy-src">
|
||||
<target name="-pre-build" depends="my-copy-src, my-check-props">
|
||||
<antcall target="my-pre-build">
|
||||
<param name="VARIANT_NAME" value="${VARIANT_NAME}"/>
|
||||
<param name="APP_NAME" value="${APP_NAME}"/>
|
||||
|
|
1
xwords4/android/XWords4-dbg/res/.gitignore
vendored
Normal file
1
xwords4/android/XWords4-dbg/res/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
values-??/strings.xml
|
|
@ -47,3 +47,4 @@ toolbar.xml
|
|||
chat_row.xml
|
||||
fragact.xml
|
||||
main.xml
|
||||
dualcontainer.xml
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -86,7 +86,6 @@ XWSumListPreference.java
|
|||
XWThumbListPreference.java
|
||||
DelegateBase.java
|
||||
DlgID.java
|
||||
GamesListActivity.java
|
||||
GamesListDelegate.java
|
||||
LookupAlert.java
|
||||
BoardDelegate.java
|
||||
|
@ -137,3 +136,6 @@ StudyListFrag.java
|
|||
XWFragment.java
|
||||
ConfirmingCheckBoxPreference.java
|
||||
RelayCheckBoxPreference.java
|
||||
MainActivity.java
|
||||
DictsFrag.java
|
||||
DualpaneDelegate.java
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
to come from a domain that you own or have control over. -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.eehouse.android.xw4"
|
||||
android:versionCode="101"
|
||||
android:versionCode="103"
|
||||
android:versionName="@string/app_version"
|
||||
>
|
||||
|
||||
|
@ -69,7 +69,7 @@
|
|||
android:name=".XWApp"
|
||||
>
|
||||
|
||||
<activity android:name="GamesListActivity"
|
||||
<activity android:name="MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="standard"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
|
|
|
@ -134,7 +134,7 @@ dependencies {
|
|||
task genVers(type: Exec) {
|
||||
workingDir '../'
|
||||
commandLine '../scripts/genvers.sh', '--variant', VARIANT_NAME,
|
||||
'--client-vers', INITIAL_CLIENT_VERS, '--chat-enabled', CHAT_ENABLED,
|
||||
'--client-vers', INITIAL_CLIENT_VERS,
|
||||
'--thumbnail-enabled', THUMBNAIL_ENABLED,
|
||||
'--vers-outfile', "assets/gitvers.txt"
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,10 +13,10 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Crosswords 4.4.107 release</h2>
|
||||
<h2>Crosswords 4.4.108 release</h2>
|
||||
|
||||
<p>This version, for F-droid release only, fixes build problems that
|
||||
caused a number of crashes and other issues.</p>
|
||||
<p>This release fixes a nasty bug in invitations on older Android
|
||||
and improves in-game chat functionality.</p>
|
||||
|
||||
<div id="survey">
|
||||
<p>Please <a href="https://www.surveymonkey.com/s/GX3XLHR">take
|
||||
|
@ -26,7 +26,18 @@
|
|||
|
||||
<h3>New with this release</h3>
|
||||
<ul>
|
||||
<li>Force release builds to be done with ant rather than gradle</li>
|
||||
<li>Fix problem with invitations on older Android versions
|
||||
(e.g. 4.2 and 4.3)</li>
|
||||
|
||||
<li>Chat fixes: send without closing the window, expand for
|
||||
longer messages, smart editing, etc.</li>
|
||||
|
||||
<li>Fix so Bluetooth finds tablets as well as phones</li>
|
||||
|
||||
<li>Add ability to disable relay play (to save battery for users
|
||||
who play standalone only)</li>
|
||||
|
||||
<li>Improvements to French and Japanese translations</li>
|
||||
</ul>
|
||||
|
||||
<p>(The full changelog
|
||||
|
@ -34,8 +45,8 @@
|
|||
|
||||
<h3>Next up</h3>
|
||||
<ul>
|
||||
<li>More chat improvements, especially allowing to send and
|
||||
receive without closing the chat window</li>
|
||||
<li>Working on dual-pane mode (so e.g. board and chat can be
|
||||
side-by-side on tablets)</li>
|
||||
<li>Take advantage of Marshmallow's new permissions model (where
|
||||
the app only asks for them when it needs them.)
|
||||
</ul>
|
||||
|
|
|
@ -5,7 +5,7 @@ buildscript {
|
|||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.1.0'
|
||||
classpath 'com.android.tools.build:gradle:2.1.2'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
|
|
@ -58,12 +58,13 @@
|
|||
<property name="INITIAL_CLIENT_VERS" value="8"/>
|
||||
<property name="VARIANT_NAME" value="xw4"/>
|
||||
<property name="APP_NAME" value="Crosswords"/>
|
||||
<property name="SKIP_LANGS" value="values-de"/>
|
||||
|
||||
<target name="-pre-clean">
|
||||
<antcall target="my-pre-clean" />
|
||||
</target>
|
||||
|
||||
<target name="-pre-build" depends="my-copy-src">
|
||||
<target name="-pre-build" depends="my-copy-src, my-check-props">
|
||||
<antcall target="my-pre-build">
|
||||
<param name="VARIANT_NAME" value="${VARIANT_NAME}"/>
|
||||
<param name="APP_NAME" value="${APP_NAME}"/>
|
||||
|
|
|
@ -38,6 +38,7 @@ LOCAL_DEFINES += \
|
|||
-DHASH_STREAM \
|
||||
-DXWFEATURE_BASE64 \
|
||||
-DXWFEATURE_DEVID \
|
||||
-DXWFEATURE_CHAT \
|
||||
-DCOMMON_LAYOUT \
|
||||
-DNATIVE_NLI \
|
||||
-DCOMMS_VERSION=1 \
|
||||
|
@ -46,10 +47,6 @@ LOCAL_DEFINES += \
|
|||
-DRELAY_ROOM_DEFAULT=\"\" \
|
||||
-D__LITTLE_ENDIAN \
|
||||
|
||||
ifeq ($(CHAT_ENABLED),true)
|
||||
LOCAL_DEFINES += -DXWFEATURE_CHAT
|
||||
endif
|
||||
|
||||
# -DXWFEATURE_SCOREONEPASS \
|
||||
|
||||
LOCAL_SRC_FILES += \
|
||||
|
|
|
@ -62,6 +62,8 @@ typedef struct _JNIGlobalState {
|
|||
MPSLOT
|
||||
} JNIGlobalState;
|
||||
|
||||
// #define LOG_MAPPING
|
||||
|
||||
#define GAMEPTR_IS_OBJECT
|
||||
#ifdef GAMEPTR_IS_OBJECT
|
||||
typedef jobject GamePtrType;
|
||||
|
@ -69,6 +71,22 @@ typedef jobject GamePtrType;
|
|||
typedef int GamePtrType;
|
||||
#endif
|
||||
|
||||
#ifdef LOG_MAPPING
|
||||
static int
|
||||
countUsed(const EnvThreadInfo* ti)
|
||||
{
|
||||
int count = 0;
|
||||
for ( int ii = 0; ii < ti->nEntries; ++ii ) {
|
||||
EnvThreadEntry* entry = &ti->entries[ii];
|
||||
if ( 0 != entry->owner ) {
|
||||
XP_LOGF( "%s(): ii=%d; owner: %x", __func__, ii, (unsigned int)entry->owner );
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
map_thread( EnvThreadInfo* ti, JNIEnv* env )
|
||||
{
|
||||
|
@ -100,17 +118,20 @@ map_thread( EnvThreadInfo* ti, JNIEnv* env )
|
|||
if ( !firstEmpty ) { /* out of slots */
|
||||
if ( 0 == nEntries ) { /* first time */
|
||||
nEntries = 2;
|
||||
ti->entries =
|
||||
XP_MALLOC( ti->mpool, nEntries * sizeof(*ti->entries) );
|
||||
XP_ASSERT( !ti->entries );
|
||||
} else {
|
||||
nEntries *= 2;
|
||||
ti->entries = XP_REALLOC( ti->mpool, ti->entries,
|
||||
nEntries * sizeof(*ti->entries) );
|
||||
}
|
||||
// XP_LOGF( "%s: num env entries now %d", __func__, nEntries );
|
||||
firstEmpty = &ti->entries[ti->nEntries]; /* first new entry */
|
||||
XP_MEMSET( firstEmpty, 0, nEntries - ti->nEntries );
|
||||
EnvThreadEntry* entries = XP_CALLOC( ti->mpool, nEntries * sizeof(*entries) );
|
||||
if ( !!ti->entries ) {
|
||||
XP_MEMCPY( entries, ti->entries, ti->nEntries * sizeof(*ti->entries) );
|
||||
}
|
||||
firstEmpty = &entries[ti->nEntries]; /* first new entry */
|
||||
ti->entries = entries;
|
||||
ti->nEntries = nEntries;
|
||||
#ifdef LOG_MAPPING
|
||||
XP_LOGF( "%s: num env entries now %d", __func__, nEntries );
|
||||
#endif
|
||||
}
|
||||
|
||||
XP_ASSERT( !!firstEmpty );
|
||||
|
@ -119,6 +140,7 @@ map_thread( EnvThreadInfo* ti, JNIEnv* env )
|
|||
#ifdef LOG_MAPPING
|
||||
XP_LOGF( "%s: entry %d: mapped env %p to thread %x", __func__,
|
||||
firstEmpty - ti->entries, env, (int)self );
|
||||
XP_LOGF( "%s: num entries USED now %d", __func__, countUsed(ti) );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -150,6 +172,9 @@ map_remove( EnvThreadInfo* ti, JNIEnv* env )
|
|||
#endif
|
||||
ti->entries[ii].env = NULL;
|
||||
ti->entries[ii].owner = 0;
|
||||
#ifdef LOG_MAPPING
|
||||
XP_LOGF( "%s: %d entries left", __func__, countUsed( ti ) );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock( &ti->mtxThreads );
|
||||
|
@ -1261,6 +1286,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1do
|
|||
{
|
||||
jboolean result;
|
||||
XWJNI_START();
|
||||
XP_ASSERT( !!state->game.server );
|
||||
result = server_do( state->game.server );
|
||||
XWJNI_END();
|
||||
return result;
|
||||
|
|
1
xwords4/android/XWords4/res/.gitignore
vendored
Normal file
1
xwords4/android/XWords4/res/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
values-??/strings.xml
|
|
@ -21,14 +21,26 @@
|
|||
|
||||
</ScrollView>
|
||||
|
||||
<EditText android:id="@+id/chat_edit"
|
||||
android:layout_width="fill_parent"
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<EditText android:id="@+id/chat_edit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="false"
|
||||
android:inputType="textCapSentences|textMultiLine"
|
||||
android:layout_weight="1"
|
||||
android:scrollHorizontally="false"
|
||||
android:hint="@string/chat_hint"
|
||||
/>
|
||||
<Button android:id="@+id/chat_send"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="false"
|
||||
android:inputType="textCapSentences|textMultiLine"
|
||||
android:layout_weight="0"
|
||||
android:scrollHorizontally="false"
|
||||
android:hint="@string/chat_hint"
|
||||
android:text="@string/chat_send"
|
||||
android:layout_gravity="center_vertical"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1,2 +0,0 @@
|
|||
/strings.xml
|
||||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1 +0,0 @@
|
|||
strings.xml
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<resources>
|
||||
<string name="app_version">4.4.107</string>
|
||||
<string name="app_version">4.4.108</string>
|
||||
</resources>
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
<string name="key_summary_field">key_summary_field</string>
|
||||
<string name="key_default_loc">key_default_loc</string>
|
||||
<string name="key_force_tablet">key_force_tablet</string>
|
||||
<!-- <string name="key_enable_dualpane">key_enable_dualpane</string> -->
|
||||
<string name="key_enable_dualpane">key_enable_dualpane</string>
|
||||
<string name="key_force_radio">key_force_radio</string>
|
||||
<string name="key_addrs_pref">key_addrs_pref</string>
|
||||
|
||||
|
|
|
@ -1095,7 +1095,8 @@
|
|||
tapping. -->
|
||||
<string name="hide_crosshairs">Disable crosshairs</string>
|
||||
<!-- explanation of the above -->
|
||||
<string name="hide_crosshairs_summary">Do not visually indicate which board cell is touched</string>
|
||||
<string name="hide_crosshairs_summary">Do not show which board
|
||||
cell is touched</string>
|
||||
|
||||
<string name="network_behavior">Network game settings</string>
|
||||
<!-- explanation of the above -->
|
||||
|
@ -2396,8 +2397,8 @@
|
|||
|
||||
<string name="force_tablet_title">Force tablet layout</string>
|
||||
<string name="force_tablet_summary">Even if my screen is too small</string>
|
||||
<!-- <string name="enable_dualpane_title">Enable dualpane</string> -->
|
||||
<!-- <string name="enable_dualpane_summary">Side-by-side views, very experimental!</string> -->
|
||||
<string name="enable_dualpane_title">Enable dualpane</string>
|
||||
<string name="enable_dualpane_summary">Side-by-side views, very experimental!</string>
|
||||
|
||||
<!-- Nagging: title of notification reminder message -->
|
||||
<string name="nag_title">Reminder: It\'s your turn</string>
|
||||
|
@ -2596,7 +2597,7 @@
|
|||
<string name="pref_group_relay_title">Relay Stuff</string>
|
||||
<string name="pref_group_relay_summary">Prefs related to play via internet/relay</string>
|
||||
<string name="pref_group_l10n_title">Localization Stuff</string>
|
||||
<!-- <string name="pref_group_tablets_title">Tablets Stuff</string> -->
|
||||
<string name="pref_group_tablets_title">Tablets Stuff</string>
|
||||
<string name="pref_group_l10n_summary">Prefs related to in-app localization</string>
|
||||
<string name="pref_item_update_title">Update between releases</string>
|
||||
<string name="pref_item_update_summary">Get intermediate builds</string>
|
||||
|
|
|
@ -423,19 +423,19 @@
|
|||
/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<!-- <PreferenceScreen android:title="@string/pref_group_tablets_title" -->
|
||||
<!-- > -->
|
||||
<!-- <CheckBoxPreference android:key="@string/key_enable_dualpane" -->
|
||||
<!-- android:title="@string/enable_dualpane_title" -->
|
||||
<!-- android:summary="@string/enable_dualpane_summary" -->
|
||||
<!-- android:defaultValue="false" -->
|
||||
<!-- /> -->
|
||||
<!-- <CheckBoxPreference android:key="@string/key_force_tablet" -->
|
||||
<!-- android:title="@string/force_tablet_title" -->
|
||||
<!-- android:summary="@string/force_tablet_summary" -->
|
||||
<!-- android:defaultValue="false" -->
|
||||
<!-- /> -->
|
||||
<!-- </PreferenceScreen> -->
|
||||
<PreferenceScreen android:title="@string/pref_group_tablets_title"
|
||||
>
|
||||
<CheckBoxPreference android:key="@string/key_enable_dualpane"
|
||||
android:title="@string/enable_dualpane_title"
|
||||
android:summary="@string/enable_dualpane_summary"
|
||||
android:defaultValue="false"
|
||||
/>
|
||||
<CheckBoxPreference android:key="@string/key_force_tablet"
|
||||
android:title="@string/force_tablet_title"
|
||||
android:summary="@string/force_tablet_summary"
|
||||
android:defaultValue="false"
|
||||
/>
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen android:title="@string/pref_group_l10n_title"
|
||||
android:summary="@string/pref_group_l10n_summary"
|
||||
|
|
|
@ -943,7 +943,8 @@
|
|||
tapping. -->
|
||||
<string name="hide_crosshairs">Elbasid sriahssorc</string>
|
||||
<!-- explanation of the above -->
|
||||
<string name="hide_crosshairs_summary">Od ton yllausiv etacidni hcihw draob llec si dehcuot</string>
|
||||
<string name="hide_crosshairs_summary">Od ton wohs hcihw draob
|
||||
llec si dehcuot</string>
|
||||
<string name="network_behavior">Krowten emag sgnittes</string>
|
||||
<!-- explanation of the above -->
|
||||
<string name="network_behavior_summary">Sgnittes taht ylppa ot
|
||||
|
@ -2057,8 +2058,8 @@
|
|||
tahw\'s elbaliava.</string>
|
||||
<string name="force_tablet_title">Ecrof telbat tuoyal</string>
|
||||
<string name="force_tablet_summary">Neve fi ym neercs si oot llams</string>
|
||||
<!-- <string name="enable_dualpane_title">Enable dualpane</string> -->
|
||||
<!-- <string name="enable_dualpane_summary">Side-by-side views, very experimental!</string> -->
|
||||
<string name="enable_dualpane_title">Elbane enaplaud</string>
|
||||
<string name="enable_dualpane_summary">Edis-yb-edis ,sweiv yrev !latnemirepxe</string>
|
||||
<!-- Nagging: title of notification reminder message -->
|
||||
<string name="nag_title">Rednimer: Ti\'s ruoy nrut</string>
|
||||
<!-- body of warning notification reminder message. First three
|
||||
|
@ -2227,7 +2228,7 @@
|
|||
<string name="pref_group_relay_title">Yaler Ffuts</string>
|
||||
<string name="pref_group_relay_summary">Sferp detaler ot yalp aiv yaler/tenretni</string>
|
||||
<string name="pref_group_l10n_title">Noitazilacol Ffuts</string>
|
||||
<!-- <string name="pref_group_tablets_title">Tablets Stuff</string> -->
|
||||
<string name="pref_group_tablets_title">Stelbat Ffuts</string>
|
||||
<string name="pref_group_l10n_summary">Sferp detaler ot ppa-ni noitazilacol</string>
|
||||
<string name="pref_item_update_title">Etadpu neewteb sesaeler</string>
|
||||
<string name="pref_item_update_summary">Teg etaidemretni sdliub</string>
|
||||
|
|
|
@ -943,7 +943,8 @@
|
|||
tapping. -->
|
||||
<string name="hide_crosshairs">DISABLE CROSSHAIRS</string>
|
||||
<!-- explanation of the above -->
|
||||
<string name="hide_crosshairs_summary">DO NOT VISUALLY INDICATE WHICH BOARD CELL IS TOUCHED</string>
|
||||
<string name="hide_crosshairs_summary">DO NOT SHOW WHICH BOARD
|
||||
CELL IS TOUCHED</string>
|
||||
<string name="network_behavior">NETWORK GAME SETTINGS</string>
|
||||
<!-- explanation of the above -->
|
||||
<string name="network_behavior_summary">SETTINGS THAT APPLY TO
|
||||
|
@ -2057,8 +2058,8 @@
|
|||
WHAT\'S AVAILABLE.</string>
|
||||
<string name="force_tablet_title">FORCE TABLET LAYOUT</string>
|
||||
<string name="force_tablet_summary">EVEN IF MY SCREEN IS TOO SMALL</string>
|
||||
<!-- <string name="enable_dualpane_title">Enable dualpane</string> -->
|
||||
<!-- <string name="enable_dualpane_summary">Side-by-side views, very experimental!</string> -->
|
||||
<string name="enable_dualpane_title">ENABLE DUALPANE</string>
|
||||
<string name="enable_dualpane_summary">SIDE-BY-SIDE VIEWS, VERY EXPERIMENTAL!</string>
|
||||
<!-- Nagging: title of notification reminder message -->
|
||||
<string name="nag_title">REMINDER: IT\'S YOUR TURN</string>
|
||||
<!-- body of warning notification reminder message. First three
|
||||
|
@ -2227,7 +2228,7 @@
|
|||
<string name="pref_group_relay_title">RELAY STUFF</string>
|
||||
<string name="pref_group_relay_summary">PREFS RELATED TO PLAY VIA INTERNET/RELAY</string>
|
||||
<string name="pref_group_l10n_title">LOCALIZATION STUFF</string>
|
||||
<!-- <string name="pref_group_tablets_title">Tablets Stuff</string> -->
|
||||
<string name="pref_group_tablets_title">TABLETS STUFF</string>
|
||||
<string name="pref_group_l10n_summary">PREFS RELATED TO IN-APP LOCALIZATION</string>
|
||||
<string name="pref_item_update_title">UPDATE BETWEEN RELEASES</string>
|
||||
<string name="pref_item_update_summary">GET INTERMEDIATE BUILDS</string>
|
||||
|
|
|
@ -25,13 +25,13 @@ import android.content.Context;
|
|||
import android.view.ViewConfiguration;
|
||||
|
||||
public class ABUtils {
|
||||
private static int s_sdkVersion =
|
||||
private static int s_sdkVersion =
|
||||
Integer.valueOf( android.os.Build.VERSION.SDK );
|
||||
|
||||
private static interface SafeInvalOptionsMenu {
|
||||
public void doInval( Activity activity );
|
||||
}
|
||||
private static class SafeInvalOptionsMenuImpl
|
||||
private static class SafeInvalOptionsMenuImpl
|
||||
implements SafeInvalOptionsMenu {
|
||||
public void doInval( Activity activity ) {
|
||||
activity.invalidateOptionsMenu();
|
||||
|
@ -42,7 +42,7 @@ public class ABUtils {
|
|||
private static interface SafeHasMenuKey {
|
||||
public boolean hasMenuKey( Context context );
|
||||
}
|
||||
private static class SafeHasMenuKeyImpl
|
||||
private static class SafeHasMenuKeyImpl
|
||||
implements SafeHasMenuKey {
|
||||
public boolean hasMenuKey( Context context )
|
||||
{
|
||||
|
|
|
@ -84,9 +84,9 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
m_counts = new HashMap<String, Integer>();
|
||||
|
||||
String msg = getString( R.string.bt_pick_addall_button );
|
||||
msg = getQuantityString( R.plurals.invite_bt_desc_fmt, m_nMissing,
|
||||
msg = getQuantityString( R.plurals.invite_bt_desc_fmt, m_nMissing,
|
||||
m_nMissing, msg );
|
||||
super.init( R.id.button_invite, R.id.button_rescan,
|
||||
super.init( R.id.button_invite, R.id.button_rescan,
|
||||
R.id.button_clear, R.id.invite_desc, msg );
|
||||
BTService.clearDevices( m_activity, null ); // will return names
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
if ( 0 < count ) {
|
||||
BTService.scan( m_activity );
|
||||
} else {
|
||||
showConfirmThen( R.string.bt_no_devs, R.string.button_go_settings,
|
||||
showConfirmThen( R.string.bt_no_devs, R.string.button_go_settings,
|
||||
Action.OPEN_BT_PREFS_ACTION );
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
protected void tryEnable()
|
||||
protected void tryEnable()
|
||||
{
|
||||
String[][] devs = new String[1][];
|
||||
int[][] counts = new int[1][];
|
||||
|
@ -210,7 +210,7 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
if ( XWPrefs.getCanInviteMulti( m_activity ) && 1 < m_nMissing ) {
|
||||
Spinner spinner = (Spinner)
|
||||
layout.findViewById(R.id.nperdev_spinner);
|
||||
ArrayAdapter<String> adapter =
|
||||
ArrayAdapter<String> adapter =
|
||||
new ArrayAdapter<String>( m_activity, android.R.layout
|
||||
.simple_spinner_item );
|
||||
for ( int ii = 1; ii <= m_nMissing; ++ii ) {
|
||||
|
@ -220,8 +220,8 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
spinner.setAdapter( adapter );
|
||||
spinner.setVisibility( View.VISIBLE );
|
||||
spinner.setOnItemSelectedListener( new OnItemSelectedListener() {
|
||||
public void onItemSelected( AdapterView<?> parent,
|
||||
View view, int pos,
|
||||
public void onItemSelected( AdapterView<?> parent,
|
||||
View view, int pos,
|
||||
long id )
|
||||
{
|
||||
m_counts.put( btAddr, 1 + pos );
|
||||
|
@ -232,9 +232,9 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
} );
|
||||
}
|
||||
|
||||
CompoundButton.OnCheckedChangeListener listener =
|
||||
CompoundButton.OnCheckedChangeListener listener =
|
||||
new CompoundButton.OnCheckedChangeListener() {
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
boolean isChecked ) {
|
||||
if ( isChecked ) {
|
||||
m_checked.add( layout );
|
||||
|
|
|
@ -39,7 +39,7 @@ public class BTReceiver extends BroadcastReceiver {
|
|||
if ( action.equals( BluetoothDevice.ACTION_ACL_CONNECTED ) ) {
|
||||
BTService.startService( context );
|
||||
} else if ( action.equals( BluetoothAdapter.ACTION_STATE_CHANGED ) ) {
|
||||
int newState =
|
||||
int newState =
|
||||
intent.getIntExtra( BluetoothAdapter.EXTRA_STATE, -1 );
|
||||
switch ( newState ) {
|
||||
case BluetoothAdapter.STATE_OFF:
|
||||
|
|
|
@ -53,7 +53,6 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
|||
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||
import org.eehouse.android.xw4.jni.LastMoveInfo;
|
||||
import org.eehouse.android.xw4.jni.XwJNI;
|
||||
import org.eehouse.android.xw4.jni.JNIThread;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
import org.eehouse.android.xw4.XWService.ReceiveResult;
|
||||
|
||||
|
@ -98,7 +97,7 @@ public class BTService extends XWService {
|
|||
private static final String BT_NAME_KEY = "BT_NAME";
|
||||
private static final String BT_ADDRESS_KEY = "BT_ADDRESS";
|
||||
|
||||
private enum BTCmd {
|
||||
private enum BTCmd {
|
||||
BAD_PROTO,
|
||||
PING,
|
||||
PONG,
|
||||
|
@ -135,7 +134,7 @@ public class BTService extends XWService {
|
|||
public BTQueueElem( BTCmd cmd, byte[] buf, String btAddr, int gameID ) {
|
||||
this( cmd );
|
||||
Assert.assertTrue( null != btAddr && 0 < btAddr.length() );
|
||||
m_msg = buf; m_btAddr = btAddr;
|
||||
m_msg = buf; m_btAddr = btAddr;
|
||||
m_gameID = gameID;
|
||||
checkAddr();
|
||||
}
|
||||
|
@ -194,7 +193,7 @@ public class BTService extends XWService {
|
|||
public static String[] getBTNameAndAddress()
|
||||
{
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
return null == adapter ? null
|
||||
return null == adapter ? null
|
||||
: new String[] { adapter.getName(), adapter.getAddress() };
|
||||
}
|
||||
|
||||
|
@ -213,7 +212,7 @@ public class BTService extends XWService {
|
|||
{
|
||||
Intent intent = new Intent();
|
||||
intent.setAction( android.provider.Settings.ACTION_BLUETOOTH_SETTINGS );
|
||||
activity.startActivity( intent );
|
||||
activity.startActivity( intent );
|
||||
}
|
||||
|
||||
public static String nameForAddr( String btAddr )
|
||||
|
@ -265,9 +264,9 @@ public class BTService extends XWService {
|
|||
intent.putExtra( ADDR_KEY, hostAddr );
|
||||
intent.putExtra( GAMEID_KEY, gameID );
|
||||
context.startService( intent );
|
||||
}
|
||||
}
|
||||
|
||||
public static void inviteRemote( Context context, String btAddr,
|
||||
public static void inviteRemote( Context context, String btAddr,
|
||||
NetLaunchInfo nli )
|
||||
{
|
||||
Assert.assertTrue( null != btAddr && 0 < btAddr.length() );
|
||||
|
@ -292,7 +291,7 @@ public class BTService extends XWService {
|
|||
context.startService( intent );
|
||||
}
|
||||
|
||||
public static int enqueueFor( Context context, byte[] buf,
|
||||
public static int enqueueFor( Context context, byte[] buf,
|
||||
CommsAddrRec targetAddr, int gameID )
|
||||
{
|
||||
int nSent = -1;
|
||||
|
@ -313,7 +312,7 @@ public class BTService extends XWService {
|
|||
}
|
||||
return nSent;
|
||||
}
|
||||
|
||||
|
||||
public static void gameDied( Context context, int gameID )
|
||||
{
|
||||
Intent intent = getIntentTo( context, BTAction.REMOVE );
|
||||
|
@ -335,7 +334,7 @@ public class BTService extends XWService {
|
|||
? BluetoothAdapter.getDefaultAdapter() : null;
|
||||
if ( null != adapter && adapter.isEnabled() ) {
|
||||
m_adapter = adapter;
|
||||
DbgUtils.logf( "BTService.onCreate(); bt name = %s; bt addr = %s",
|
||||
DbgUtils.logf( "BTService.onCreate(); bt name = %s; bt addr = %s",
|
||||
adapter.getName(), adapter.getAddress() );
|
||||
initAddrs();
|
||||
startListener();
|
||||
|
@ -390,7 +389,7 @@ public class BTService extends XWService {
|
|||
int nPlayersT = intent.getIntExtra( NTO_KEY, -1 );
|
||||
String btName = intent.getStringExtra( BT_NAME_KEY );
|
||||
btAddr = intent.getStringExtra( BT_ADDRESS_KEY );
|
||||
// /*(void)*/makeOrNotify( this, gameID, null, lang, dict,
|
||||
// /*(void)*/makeOrNotify( this, gameID, null, lang, dict,
|
||||
// nPlayersT, 1, btName, btAddr );
|
||||
Assert.fail();
|
||||
break;
|
||||
|
@ -400,7 +399,7 @@ public class BTService extends XWService {
|
|||
btAddr = intent.getStringExtra( ADDR_KEY );
|
||||
gameID = intent.getIntExtra( GAMEID_KEY, -1 );
|
||||
if ( -1 != gameID ) {
|
||||
m_sender.add( new BTQueueElem( BTCmd.MESG_SEND, buf,
|
||||
m_sender.add( new BTQueueElem( BTCmd.MESG_SEND, buf,
|
||||
btAddr, gameID ) );
|
||||
}
|
||||
break;
|
||||
|
@ -414,7 +413,7 @@ public class BTService extends XWService {
|
|||
false );
|
||||
} else {
|
||||
ConnStatusHandler.updateStatus( this, null,
|
||||
CommsConnType.COMMS_CONN_BT,
|
||||
CommsConnType.COMMS_CONN_BT,
|
||||
false );
|
||||
stopListener();
|
||||
stopSender();
|
||||
|
@ -454,7 +453,7 @@ public class BTService extends XWService {
|
|||
try {
|
||||
BluetoothSocket socket = m_serverSocket.accept(); // blocks
|
||||
addAddr( socket );
|
||||
DataInputStream inStream =
|
||||
DataInputStream inStream =
|
||||
new DataInputStream( socket.getInputStream() );
|
||||
|
||||
byte proto = inStream.readByte();
|
||||
|
@ -477,7 +476,7 @@ public class BTService extends XWService {
|
|||
}
|
||||
updateStatusIn( true );
|
||||
} else {
|
||||
DataOutputStream os =
|
||||
DataOutputStream os =
|
||||
new DataOutputStream( socket.getOutputStream() );
|
||||
os.writeByte( BTCmd.BAD_PROTO.ordinal() );
|
||||
os.flush();
|
||||
|
@ -575,16 +574,16 @@ public class BTService extends XWService {
|
|||
BluetoothDevice host = socket.getRemoteDevice();
|
||||
addAddr( host );
|
||||
|
||||
CommsAddrRec addr = new CommsAddrRec( host.getName(),
|
||||
CommsAddrRec addr = new CommsAddrRec( host.getName(),
|
||||
host.getAddress() );
|
||||
ReceiveResult rslt
|
||||
= BTService.this.receiveMessage( BTService.this, gameID,
|
||||
= BTService.this.receiveMessage( BTService.this, gameID,
|
||||
m_btMsgSink, buffer, addr );
|
||||
|
||||
BTCmd result = rslt == ReceiveResult.GAME_GONE ?
|
||||
BTCmd result = rslt == ReceiveResult.GAME_GONE ?
|
||||
BTCmd.MESG_GAMEGONE : BTCmd.MESG_ACCPT;
|
||||
|
||||
DataOutputStream os =
|
||||
DataOutputStream os =
|
||||
new DataOutputStream( socket.getOutputStream() );
|
||||
os.writeByte( result.ordinal() );
|
||||
os.flush();
|
||||
|
@ -767,7 +766,7 @@ public class BTService extends XWService {
|
|||
os.flush();
|
||||
Thread killer = killSocketIn( socket, 5 );
|
||||
|
||||
DataInputStream is =
|
||||
DataInputStream is =
|
||||
new DataInputStream( socket.getInputStream() );
|
||||
BTCmd reply = BTCmd.values()[is.readByte()];
|
||||
if ( BTCmd.BAD_PROTO == reply ) {
|
||||
|
@ -804,9 +803,9 @@ public class BTService extends XWService {
|
|||
private void sendInvite( BTQueueElem elem )
|
||||
{
|
||||
try {
|
||||
BluetoothDevice dev =
|
||||
BluetoothDevice dev =
|
||||
m_adapter.getRemoteDevice( elem.m_btAddr );
|
||||
BluetoothSocket socket =
|
||||
BluetoothSocket socket =
|
||||
dev.createRfcommSocketToServiceRecord( XWApp.getAppUUID() );
|
||||
if ( null != socket ) {
|
||||
BTCmd reply = null;
|
||||
|
@ -822,7 +821,7 @@ public class BTService extends XWService {
|
|||
DbgUtils.logf( "<eeh>sending invite for %d players", elem.m_nPlayersH );
|
||||
outStream.flush();
|
||||
|
||||
DataInputStream inStream =
|
||||
DataInputStream inStream =
|
||||
new DataInputStream( socket.getInputStream() );
|
||||
reply = BTCmd.values()[inStream.readByte()];
|
||||
}
|
||||
|
@ -862,19 +861,19 @@ public class BTService extends XWService {
|
|||
MultiEvent evt;
|
||||
if ( success ) {
|
||||
evt = MultiEvent.MESSAGE_DROPPED;
|
||||
DbgUtils.logf( "BTService.sendMsg: dropping message %s because game %X dead",
|
||||
DbgUtils.logf( "BTService.sendMsg: dropping message %s because game %X dead",
|
||||
elem.m_cmd, elem.m_gameID );
|
||||
} else {
|
||||
evt = MultiEvent.MESSAGE_REFUSED;
|
||||
}
|
||||
if ( !success ) {
|
||||
try {
|
||||
BluetoothDevice dev =
|
||||
BluetoothDevice dev =
|
||||
m_adapter.getRemoteDevice( elem.m_btAddr );
|
||||
BluetoothSocket socket = dev.
|
||||
createRfcommSocketToServiceRecord( XWApp.getAppUUID() );
|
||||
if ( null != socket ) {
|
||||
DataOutputStream outStream =
|
||||
DataOutputStream outStream =
|
||||
connect( socket, BTCmd.MESG_SEND );
|
||||
if ( null != outStream ) {
|
||||
outStream.writeInt( elem.m_gameID );
|
||||
|
@ -886,7 +885,7 @@ public class BTService extends XWService {
|
|||
outStream.flush();
|
||||
Thread killer = killSocketIn( socket );
|
||||
|
||||
DataInputStream inStream =
|
||||
DataInputStream inStream =
|
||||
new DataInputStream( socket.getInputStream() );
|
||||
BTCmd reply = BTCmd.values()[inStream.readByte()];
|
||||
killer.interrupt();
|
||||
|
@ -942,7 +941,7 @@ public class BTService extends XWService {
|
|||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -1073,7 +1072,7 @@ public class BTService extends XWService {
|
|||
m_sender = null;
|
||||
}
|
||||
|
||||
private BTCmd makeOrNotify( NetLaunchInfo nli, String btName,
|
||||
private BTCmd makeOrNotify( NetLaunchInfo nli, String btName,
|
||||
String btAddr )
|
||||
{
|
||||
BTCmd result;
|
||||
|
@ -1082,27 +1081,27 @@ public class BTService extends XWService {
|
|||
result = makeGame( nli, btName, btAddr );
|
||||
} else {
|
||||
Intent intent = MultiService
|
||||
.makeMissingDictIntent( this, nli,
|
||||
.makeMissingDictIntent( this, nli,
|
||||
DictFetchOwner.OWNER_BT );
|
||||
// NetLaunchInfo.putExtras( intent, gameID, btName, btAddr );
|
||||
MultiService.postMissingDictNotification( this, intent,
|
||||
MultiService.postMissingDictNotification( this, intent,
|
||||
nli.gameID() );
|
||||
result = BTCmd.INVITE_ACCPT; // ???
|
||||
}
|
||||
} else {
|
||||
result = BTCmd.INVITE_DUP_INVITE; // dupe of rematch
|
||||
result = BTCmd.INVITE_DUP_INVITE; // dupe of rematch
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private BTCmd makeGame( NetLaunchInfo nli, String sender,
|
||||
private BTCmd makeGame( NetLaunchInfo nli, String sender,
|
||||
String senderAddress )
|
||||
{
|
||||
BTCmd result;
|
||||
long[] rowids = DBUtils.getRowIDsFor( BTService.this, nli.gameID() );
|
||||
if ( null == rowids || 0 == rowids.length ) {
|
||||
CommsAddrRec addr = nli.makeAddrRec( BTService.this );
|
||||
long rowid = GameUtils.makeNewMultiGame( BTService.this, nli,
|
||||
long rowid = GameUtils.makeNewMultiGame( BTService.this, nli,
|
||||
m_btMsgSink,
|
||||
getUtilCtxt() );
|
||||
if ( DBUtils.ROWID_NOTFOUND == rowid ) {
|
||||
|
@ -1112,11 +1111,11 @@ public class BTService extends XWService {
|
|||
DBUtils.setName( BTService.this, rowid, nli.gameName );
|
||||
}
|
||||
result = BTCmd.INVITE_ACCPT;
|
||||
String body = LocUtils.getString( BTService.this,
|
||||
R.string.new_bt_body_fmt,
|
||||
String body = LocUtils.getString( BTService.this,
|
||||
R.string.new_bt_body_fmt,
|
||||
sender );
|
||||
|
||||
GameUtils.postInvitedNotification( this, nli.gameID(), body,
|
||||
GameUtils.postInvitedNotification( this, nli.gameID(), body,
|
||||
rowid );
|
||||
|
||||
sendResult( MultiEvent.BT_GAME_CREATED, rowid );
|
||||
|
@ -1133,9 +1132,9 @@ public class BTService extends XWService {
|
|||
// DbgUtils.logf( "connecting to %s to send cmd %s", name, cmd.toString() );
|
||||
// Docs say always call cancelDiscovery before trying to connect
|
||||
m_adapter.cancelDiscovery();
|
||||
|
||||
|
||||
DataOutputStream dos;
|
||||
try {
|
||||
try {
|
||||
socket.connect();
|
||||
dos = new DataOutputStream( socket.getOutputStream() );
|
||||
dos.writeByte( BT_PROTO );
|
||||
|
|
|
@ -34,13 +34,13 @@ public class BoardActivity extends XWActivity {
|
|||
private BoardDelegate m_dlgt;
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
if ( CommonPrefs.getHideTitleBar( this )
|
||||
&& ABUtils.haveMenuKey( this ) ) {
|
||||
requestWindowFeature( Window.FEATURE_NO_TITLE );
|
||||
}
|
||||
|
||||
|
||||
m_dlgt = new BoardDelegate( this, savedInstanceState );
|
||||
super.onCreate( savedInstanceState, m_dlgt );
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
this( activity, activity, bitmap, jniThread, dims );
|
||||
}
|
||||
|
||||
private BoardCanvas( Context context, Activity activity, Bitmap bitmap,
|
||||
private BoardCanvas( Context context, Activity activity, Bitmap bitmap,
|
||||
JNIThread jniThread, BoardDims dims )
|
||||
{
|
||||
super( bitmap );
|
||||
|
@ -193,12 +193,12 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
return m_trayOwner;
|
||||
}
|
||||
|
||||
public int curPending()
|
||||
public int curPending()
|
||||
{
|
||||
return m_pendingScore;
|
||||
}
|
||||
|
||||
public void setInTrade( boolean inTrade )
|
||||
public void setInTrade( boolean inTrade )
|
||||
{
|
||||
if ( m_inTrade != inTrade ) {
|
||||
m_inTrade = inTrade;
|
||||
|
@ -207,7 +207,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
|
||||
// DrawCtxt interface implementation
|
||||
public boolean scoreBegin( Rect rect, int numPlayers, int[] scores,
|
||||
public boolean scoreBegin( Rect rect, int numPlayers, int[] scores,
|
||||
int remCount )
|
||||
{
|
||||
fillRectOther( rect, CommonPrefs.COLOR_BACKGRND );
|
||||
|
@ -215,15 +215,15 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean measureRemText( Rect r, int nTilesLeft, int[] width,
|
||||
int[] height )
|
||||
public boolean measureRemText( Rect r, int nTilesLeft, int[] width,
|
||||
int[] height )
|
||||
{
|
||||
boolean showREM = 0 <= nTilesLeft;
|
||||
if ( showREM ) {
|
||||
// should cache a formatter
|
||||
m_remText = String.format( "%d", nTilesLeft );
|
||||
m_fillPaint.setTextSize( m_mediumFontHt );
|
||||
m_fillPaint.getTextBounds( m_remText, 0, m_remText.length(),
|
||||
m_fillPaint.getTextBounds( m_remText, 0, m_remText.length(),
|
||||
m_boundsScratch );
|
||||
|
||||
int minWidth = m_boundsScratch.width();
|
||||
|
@ -236,7 +236,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
return showREM;
|
||||
}
|
||||
|
||||
public void drawRemText( Rect rInner, Rect rOuter, int nTilesLeft,
|
||||
public void drawRemText( Rect rInner, Rect rOuter, int nTilesLeft,
|
||||
boolean focussed )
|
||||
{
|
||||
int indx = focussed ? CommonPrefs.COLOR_FOCUS
|
||||
|
@ -247,7 +247,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
drawCentered( m_remText, rInner, null );
|
||||
}
|
||||
|
||||
public void measureScoreText( Rect rect, DrawScoreInfo dsi,
|
||||
public void measureScoreText( Rect rect, DrawScoreInfo dsi,
|
||||
int[] width, int[] height )
|
||||
{
|
||||
String[] scoreInfo = new String[dsi.isTurn?1:2];
|
||||
|
@ -283,7 +283,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
|
||||
int needWidth = 0;
|
||||
for ( int ii = 0; ii < scoreInfo.length; ++ii ) {
|
||||
m_fillPaint.getTextBounds( scoreInfo[ii], 0, scoreInfo[ii].length(),
|
||||
m_fillPaint.getTextBounds( scoreInfo[ii], 0, scoreInfo[ii].length(),
|
||||
m_boundsScratch );
|
||||
if ( needWidth < m_boundsScratch.width() ) {
|
||||
needWidth = m_boundsScratch.width();
|
||||
|
@ -297,7 +297,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
height[0] = rect.height();
|
||||
}
|
||||
|
||||
public void score_drawPlayer( Rect rInner, Rect rOuter,
|
||||
public void score_drawPlayer( Rect rInner, Rect rOuter,
|
||||
int gotPct, DrawScoreInfo dsi )
|
||||
{
|
||||
if ( 0 != (dsi.flags & CELL_ISCURSOR) ) {
|
||||
|
@ -332,7 +332,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
|
||||
String negSign = secondsLeft < 0? "-":"";
|
||||
secondsLeft = Math.abs( secondsLeft );
|
||||
String time = String.format( "%s%d:%02d", negSign, secondsLeft/60,
|
||||
String time = String.format( "%s%d:%02d", negSign, secondsLeft/60,
|
||||
secondsLeft%60 );
|
||||
|
||||
fillRectOther( rect, CommonPrefs.COLOR_BACKGRND );
|
||||
|
@ -352,8 +352,8 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
|
||||
public boolean drawCell( final Rect rect, String text, int tile, int value,
|
||||
int owner, int bonus, int hintAtts,
|
||||
final int flags )
|
||||
int owner, int bonus, int hintAtts,
|
||||
final int flags )
|
||||
{
|
||||
boolean canDraw = figureFontDims();
|
||||
if ( canDraw ) {
|
||||
|
@ -425,7 +425,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
} // drawCell
|
||||
|
||||
private boolean m_arrowHintShown = false;
|
||||
public void drawBoardArrow( Rect rect, int bonus, boolean vert,
|
||||
public void drawBoardArrow( Rect rect, int bonus, boolean vert,
|
||||
int hintAtts, int flags )
|
||||
{
|
||||
// figure out if the background is more dark than light
|
||||
|
@ -458,7 +458,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
// handler.post( new Runnable() {
|
||||
// public void run() {
|
||||
// m_parent.
|
||||
// showNotAgainDlgThen( R.string.not_again_arrow,
|
||||
// showNotAgainDlgThen( R.string.not_again_arrow,
|
||||
// R.string.
|
||||
// key_notagain_arrow );
|
||||
// } } );
|
||||
|
@ -466,30 +466,30 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean trayBegin( Rect rect, int owner, int score )
|
||||
public boolean trayBegin( Rect rect, int owner, int score )
|
||||
{
|
||||
m_trayOwner = owner;
|
||||
m_pendingScore = score;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean drawTile( Rect rect, String text, int val, int flags )
|
||||
public boolean drawTile( Rect rect, String text, int val, int flags )
|
||||
{
|
||||
return drawTileImpl( rect, text, val, flags, true );
|
||||
}
|
||||
|
||||
public boolean drawTileMidDrag( Rect rect, String text, int val, int owner,
|
||||
int flags )
|
||||
public boolean drawTileMidDrag( Rect rect, String text, int val, int owner,
|
||||
int flags )
|
||||
{
|
||||
return drawTileImpl( rect, text, val, flags, false );
|
||||
}
|
||||
|
||||
public boolean drawTileBack( Rect rect, int flags )
|
||||
public boolean drawTileBack( Rect rect, int flags )
|
||||
{
|
||||
return drawTileImpl( rect, "?", -1, flags, true );
|
||||
}
|
||||
|
||||
public void drawTrayDivider( Rect rect, int flags )
|
||||
public void drawTrayDivider( Rect rect, int flags )
|
||||
{
|
||||
boolean isCursor = 0 != (flags & CELL_ISCURSOR);
|
||||
boolean selected = 0 != (flags & CELL_HIGHLIGHT);
|
||||
|
@ -505,11 +505,11 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
}
|
||||
|
||||
public void score_pendingScore( Rect rect, int score, int playerNum,
|
||||
int curTurn, int flags )
|
||||
public void score_pendingScore( Rect rect, int score, int playerNum,
|
||||
int curTurn, int flags )
|
||||
{
|
||||
String text = score >= 0? String.format( "%d", score ) : "??";
|
||||
int otherIndx = (0 == (flags & CELL_ISCURSOR))
|
||||
int otherIndx = (0 == (flags & CELL_ISCURSOR))
|
||||
? CommonPrefs.COLOR_BACKGRND : CommonPrefs.COLOR_FOCUS;
|
||||
++rect.top;
|
||||
fillRectOther( rect, otherIndx );
|
||||
|
@ -524,7 +524,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
drawCentered( text, rect, null );
|
||||
|
||||
rect.offset( 0, rect.height() );
|
||||
drawCentered( LocUtils.getString( m_context, R.string.pts ),
|
||||
drawCentered( LocUtils.getString( m_context, R.string.pts ),
|
||||
rect, null );
|
||||
}
|
||||
|
||||
|
@ -569,7 +569,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean drawTileImpl( Rect rect, String text, int val,
|
||||
private boolean drawTileImpl( Rect rect, String text, int val,
|
||||
int flags, boolean clearBack )
|
||||
{
|
||||
boolean canDraw = figureFontDims();
|
||||
|
@ -587,7 +587,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
|
||||
if ( isCursor || notEmpty ) {
|
||||
int color = m_otherColors[isCursor? CommonPrefs.COLOR_FOCUS
|
||||
int color = m_otherColors[isCursor? CommonPrefs.COLOR_FOCUS
|
||||
: CommonPrefs.COLOR_TILE_BACK];
|
||||
if ( !clearBack ) {
|
||||
color &= 0x7FFFFFFF; // translucent if being dragged.
|
||||
|
@ -628,23 +628,23 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
}
|
||||
|
||||
private void drawCentered( String text, Rect rect, FontDims fontDims )
|
||||
private void drawCentered( String text, Rect rect, FontDims fontDims )
|
||||
{
|
||||
drawIn( text, rect, fontDims, Paint.Align.CENTER );
|
||||
}
|
||||
|
||||
private void drawIn( String text, Rect rect, FontDims fontDims,
|
||||
Paint.Align align )
|
||||
private void drawIn( String text, Rect rect, FontDims fontDims,
|
||||
Paint.Align align )
|
||||
{
|
||||
int descent = -1;
|
||||
int textSize;
|
||||
if ( null == fontDims ) {
|
||||
textSize = rect.height() - SCORE_HT_DROP;
|
||||
} else {
|
||||
int height = rect.height() - 4; // borders and padding, 2 each
|
||||
int height = rect.height() - 4; // borders and padding, 2 each
|
||||
descent = fontDims.descentFor( height );
|
||||
textSize = fontDims.heightFor( height );
|
||||
// DbgUtils.logf( "using descent: " + descent + " and textSize: "
|
||||
// DbgUtils.logf( "using descent: " + descent + " and textSize: "
|
||||
// + textSize + " in height " + height );
|
||||
}
|
||||
m_fillPaint.setTextSize( textSize );
|
||||
|
@ -671,13 +671,13 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
} // drawCentered
|
||||
|
||||
private void drawScaled( String text, final Rect rect,
|
||||
private void drawScaled( String text, final Rect rect,
|
||||
Rect textBounds, int descent )
|
||||
{
|
||||
textBounds.bottom = rect.height();
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap( textBounds.width(),
|
||||
rect.height(),
|
||||
rect.height(),
|
||||
Bitmap.Config.ARGB_8888 );
|
||||
|
||||
Canvas canvas = new Canvas( bitmap );
|
||||
|
@ -705,7 +705,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
if ( val >= 0 ) {
|
||||
int divisor = m_hasSmallScreen ? 3 : 4;
|
||||
if ( null == m_valRect ) {
|
||||
m_valRect = new Rect( 0, 0, rect.width() / divisor,
|
||||
m_valRect = new Rect( 0, 0, rect.width() / divisor,
|
||||
rect.height() / divisor );
|
||||
m_valRect.inset( offset, offset );
|
||||
}
|
||||
|
@ -714,7 +714,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
text = String.format( "%d", val );
|
||||
m_fillPaint.setTextSize( m_valRect.height() );
|
||||
m_fillPaint.setTextAlign( Paint.Align.RIGHT );
|
||||
drawText( text, m_valRect.right, m_valRect.bottom,
|
||||
drawText( text, m_valRect.right, m_valRect.bottom,
|
||||
m_fillPaint );
|
||||
if ( FRAME_TRAY_RECTS ) {
|
||||
drawRect( m_valRect, m_strokePaint );
|
||||
|
@ -745,7 +745,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
paint.setTextAlign( Paint.Align.LEFT );
|
||||
paint.setTextSize( ht );
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap( width, (ht*3)/2,
|
||||
Bitmap bitmap = Bitmap.createBitmap( width, (ht*3)/2,
|
||||
Bitmap.Config.ARGB_8888 );
|
||||
Canvas canvas = new Canvas( bitmap );
|
||||
|
||||
|
@ -800,7 +800,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_fontDims = new FontDims( ht, topRow, bottomRow, maxWidth );
|
||||
}
|
||||
return null != m_fontDims;
|
||||
|
@ -855,7 +855,7 @@ public class BoardCanvas extends Canvas implements DrawCtx {
|
|||
}
|
||||
}
|
||||
|
||||
arrow = new BitmapDrawable(bitmap);
|
||||
arrow = new BitmapDrawable(bitmap);
|
||||
}
|
||||
return arrow;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -24,6 +24,8 @@ import android.os.Bundle;
|
|||
|
||||
public class BoardFrag extends XWFragment {
|
||||
|
||||
public BoardFrag( Delegator parent ) { super( parent ); }
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle sis )
|
||||
{
|
||||
|
|
|
@ -22,21 +22,14 @@ package org.eehouse.android.xw4;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint.FontMetricsInt;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.FloatMath;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eehouse.android.xw4.jni.*;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
|
||||
|
@ -76,7 +69,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
|
||||
|
||||
// called when inflating xml
|
||||
public BoardView( Context context, AttributeSet attrs )
|
||||
public BoardView( Context context, AttributeSet attrs )
|
||||
{
|
||||
super( context, attrs );
|
||||
|
||||
|
@ -93,14 +86,14 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent( MotionEvent event )
|
||||
public boolean onTouchEvent( MotionEvent event )
|
||||
{
|
||||
boolean wantMore = null != m_jniThread;
|
||||
if ( wantMore ) {
|
||||
int action = event.getAction();
|
||||
int xx = (int)event.getX();
|
||||
int yy = (int)event.getY();
|
||||
|
||||
|
||||
switch ( action ) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
m_lastSpacing = MULTI_INACTIVE;
|
||||
|
@ -115,7 +108,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
} else {
|
||||
int zoomBy = figureZoom( event );
|
||||
if ( 0 != zoomBy ) {
|
||||
handle( JNIThread.JNICmd.CMD_ZOOM,
|
||||
handle( JNIThread.JNICmd.CMD_ZOOM,
|
||||
zoomBy < 0 ? -2 : 2 );
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +140,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
@Override
|
||||
protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec )
|
||||
{
|
||||
// DbgUtils.logf( "onMeasure(width: %s, height: %s)",
|
||||
// DbgUtils.logf( "onMeasure(width: %s, height: %s)",
|
||||
// MeasureSpec.toString( widthMeasureSpec ),
|
||||
// MeasureSpec.toString( heightMeasureSpec ) );
|
||||
|
||||
|
@ -155,7 +148,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
if ( m_boardDlgt.isPortrait() != (m_dims.height > m_dims.width) ) {
|
||||
// square possible; will break above!
|
||||
Assert.assertTrue( m_dims.height != m_dims.width );
|
||||
DbgUtils.logf( "onMeasure: discarding m_dims" );
|
||||
DbgUtils.logdf( "onMeasure: discarding m_dims" );
|
||||
if ( ++m_dimsTossCount < 4 ) {
|
||||
m_dims = null;
|
||||
m_layoutWidth = m_layoutHeight = 0;
|
||||
|
@ -196,34 +189,34 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
|
||||
// This will be called from the UI thread
|
||||
@Override
|
||||
protected void onDraw( Canvas canvas )
|
||||
protected void onDraw( Canvas canvas )
|
||||
{
|
||||
synchronized( this ) {
|
||||
if ( layoutBoardOnce() && m_measuredFromDims ) {
|
||||
canvas.drawBitmap( s_bitmap, 0, 0, new Paint() );
|
||||
ConnStatusHandler.draw( m_context, canvas, getResources(),
|
||||
ConnStatusHandler.draw( m_context, canvas, getResources(),
|
||||
m_connTypes, m_isSolo );
|
||||
} else {
|
||||
DbgUtils.logf( "BoardView.onDraw(): board not laid out yet" );
|
||||
DbgUtils.logdf( "BoardView.onDraw(): board not laid out yet" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean layoutBoardOnce()
|
||||
private boolean layoutBoardOnce()
|
||||
{
|
||||
final int width = getWidth();
|
||||
final int height = getHeight();
|
||||
boolean layoutDone = width == m_layoutWidth && height == m_layoutHeight;
|
||||
if ( layoutDone ) {
|
||||
DbgUtils.logf( "layoutBoardOnce(): layoutDone true" );
|
||||
DbgUtils.logdf( "layoutBoardOnce(): layoutDone true" );
|
||||
} else if ( null == m_gi ) {
|
||||
// nothing to do either
|
||||
DbgUtils.logf( "layoutBoardOnce(): no m_gi" );
|
||||
DbgUtils.logdf( "layoutBoardOnce(): no m_gi" );
|
||||
} else if ( null == m_jniThread ) {
|
||||
// nothing to do either
|
||||
DbgUtils.logf( "layoutBoardOnce(): no m_jniThread" );
|
||||
DbgUtils.logdf( "layoutBoardOnce(): no m_jniThread" );
|
||||
} else if ( null == m_dims ) {
|
||||
DbgUtils.logf( "layoutBoardOnce(): null m_dims" );
|
||||
DbgUtils.logdf( "layoutBoardOnce(): null m_dims" );
|
||||
// m_canvas = null;
|
||||
// need to synchronize??
|
||||
Paint paint = new Paint();
|
||||
|
@ -232,14 +225,14 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
String timerTxt = "-00:00";
|
||||
paint.getTextBounds( timerTxt, 0, timerTxt.length(), scratch );
|
||||
int timerWidth = scratch.width();
|
||||
int fontWidth =
|
||||
int fontWidth =
|
||||
Math.min(m_defaultFontHt, timerWidth / timerTxt.length());
|
||||
DbgUtils.logf( "layoutBoardOnce(): posting JNICmd.CMD_LAYOUT(w=%d, h=%d)", width, height );
|
||||
handle( JNIThread.JNICmd.CMD_LAYOUT, width, height,
|
||||
DbgUtils.logdf( "layoutBoardOnce(): posting JNICmd.CMD_LAYOUT(w=%d, h=%d)", width, height );
|
||||
handle( JNIThread.JNICmd.CMD_LAYOUT, width, height,
|
||||
fontWidth, m_defaultFontHt );
|
||||
// We'll be back....
|
||||
} else {
|
||||
DbgUtils.logf( "layoutBoardOnce(): DOING IT" );
|
||||
DbgUtils.logdf( "layoutBoardOnce(): DOING IT" );
|
||||
// If board size has changed we need a new bitmap
|
||||
int bmHeight = 1 + m_dims.height;
|
||||
int bmWidth = 1 + m_dims.width;
|
||||
|
@ -260,7 +253,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
s_bitmap.eraseColor( 0 );
|
||||
}
|
||||
if ( null == m_canvas ) {
|
||||
m_canvas = new BoardCanvas( m_parent, s_bitmap, m_jniThread,
|
||||
m_canvas = new BoardCanvas( m_parent, s_bitmap, m_jniThread,
|
||||
m_dims );
|
||||
} else {
|
||||
m_canvas.setJNIThread( m_jniThread );
|
||||
|
@ -273,7 +266,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
m_layoutHeight = height;
|
||||
layoutDone = true;
|
||||
}
|
||||
DbgUtils.logf( "layoutBoardOnce()=>%b", layoutDone );
|
||||
DbgUtils.logdf( "layoutBoardOnce()=>%b", layoutDone );
|
||||
return layoutDone;
|
||||
} // layoutBoardOnce
|
||||
|
||||
|
@ -283,10 +276,10 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
}
|
||||
|
||||
// BoardHandler interface implementation
|
||||
public void startHandling( Activity parent, JNIThread thread,
|
||||
CommsConnTypeSet connTypes )
|
||||
public void startHandling( Activity parent, JNIThread thread,
|
||||
CommsConnTypeSet connTypes )
|
||||
{
|
||||
DbgUtils.logf( "BoardView.startHandling(thread=%H)", thread );
|
||||
DbgUtils.logdf( "BoardView.startHandling(thread=%H)", thread );
|
||||
m_parent = parent;
|
||||
m_jniThread = thread;
|
||||
m_jniGamePtr = thread.getGamePtr();
|
||||
|
@ -328,10 +321,10 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
}
|
||||
}
|
||||
|
||||
// Force update now that we have bits to copy
|
||||
if ( drew ) {
|
||||
m_parent.runOnUiThread( m_invalidator );
|
||||
}
|
||||
// Force update now that we have bits to copy. I don't know why (yet),
|
||||
// but on older versions of Android we need to run this even if drew
|
||||
// is false
|
||||
m_parent.runOnUiThread( m_invalidator );
|
||||
}
|
||||
|
||||
public void dimsChanged( BoardDims dims )
|
||||
|
@ -354,7 +347,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
requestLayout();
|
||||
}
|
||||
|
||||
public void setInTrade( boolean inTrade )
|
||||
public void setInTrade( boolean inTrade )
|
||||
{
|
||||
if ( null != m_canvas ) {
|
||||
m_canvas.setInTrade( inTrade );
|
||||
|
@ -366,12 +359,12 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
return null == m_canvas? -1 : m_canvas.getCurPlayer();
|
||||
}
|
||||
|
||||
public int curPending()
|
||||
public int curPending()
|
||||
{
|
||||
return null == m_canvas? 0 : m_canvas.curPending();
|
||||
}
|
||||
|
||||
private int getSpacing( MotionEvent event )
|
||||
private int getSpacing( MotionEvent event )
|
||||
{
|
||||
int result;
|
||||
if ( 1 == event.getPointerCount() ) {
|
||||
|
|
|
@ -25,11 +25,9 @@ import android.os.Bundle;
|
|||
public class ChatActivity extends XWActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle savedInstanceState )
|
||||
public void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
if ( BuildConstants.CHAT_SUPPORTED ) {
|
||||
ChatDelegate dlgt = new ChatDelegate( this, savedInstanceState );
|
||||
super.onCreate( savedInstanceState, dlgt );
|
||||
}
|
||||
ChatDelegate dlgt = new ChatDelegate( this, savedInstanceState );
|
||||
super.onCreate( savedInstanceState, dlgt );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View.OnLayoutChangeListener;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TableLayout;
|
||||
|
@ -46,7 +47,7 @@ public class ChatDelegate extends DelegateBase {
|
|||
private static final String INTENT_KEY_PLAYER = "intent_key_player";
|
||||
private static final String INTENT_KEY_NAMES = "intent_key_names";
|
||||
private static final String INTENT_KEY_LOCS = "intent_key_locs";
|
||||
|
||||
|
||||
private static ChatDelegate s_visibleThis;
|
||||
private long m_rowid;
|
||||
private int m_curPlayer;
|
||||
|
@ -64,58 +65,67 @@ public class ChatDelegate extends DelegateBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init( Bundle savedInstanceState )
|
||||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
DbgUtils.logf( "ChatDelegate.init()" );
|
||||
if ( BuildConstants.CHAT_SUPPORTED ) {
|
||||
m_edit = (EditText)findViewById( R.id.chat_edit );
|
||||
m_edit.addTextChangedListener( new TextWatcher() {
|
||||
public void afterTextChanged( Editable s ) {
|
||||
invalidateOptionsMenuIf();
|
||||
}
|
||||
public void beforeTextChanged( CharSequence s, int st,
|
||||
int cnt, int a ) {}
|
||||
public void onTextChanged( CharSequence s, int start,
|
||||
int before, int count ) {}
|
||||
} );
|
||||
m_edit = (EditText)findViewById( R.id.chat_edit );
|
||||
m_edit.addTextChangedListener( new TextWatcher() {
|
||||
public void afterTextChanged( Editable s ) {
|
||||
invalidateOptionsMenuIf();
|
||||
}
|
||||
public void beforeTextChanged( CharSequence s, int st,
|
||||
int cnt, int a ) {}
|
||||
public void onTextChanged( CharSequence s, int start,
|
||||
int before, int count ) {}
|
||||
} );
|
||||
|
||||
Bundle args = getArguments();
|
||||
m_rowid = args.getLong( GameUtils.INTENT_KEY_ROWID, -1 );
|
||||
m_curPlayer = args.getInt( INTENT_KEY_PLAYER, -1 );
|
||||
m_names = args.getStringArray( INTENT_KEY_NAMES );
|
||||
boolean[] locals = args.getBooleanArray( INTENT_KEY_LOCS );
|
||||
Bundle args = getArguments();
|
||||
m_rowid = args.getLong( GameUtils.INTENT_KEY_ROWID, -1 );
|
||||
m_curPlayer = args.getInt( INTENT_KEY_PLAYER, -1 );
|
||||
m_names = args.getStringArray( INTENT_KEY_NAMES );
|
||||
boolean[] locals = args.getBooleanArray( INTENT_KEY_LOCS );
|
||||
|
||||
m_scroll = (ScrollView)findViewById( R.id.scroll );
|
||||
m_layout = (TableLayout)findViewById( R.id.chat_history );
|
||||
m_scroll = (ScrollView)findViewById( R.id.scroll );
|
||||
m_layout = (TableLayout)findViewById( R.id.chat_history );
|
||||
|
||||
// OnLayoutChangeListener added in API 11
|
||||
if ( 11 <= Integer.valueOf( android.os.Build.VERSION.SDK ) ) {
|
||||
m_layout.addOnLayoutChangeListener( new OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange( View vv, int ll, int tt, int rr,
|
||||
int bb, int ol, int ot,
|
||||
public void onLayoutChange( View vv, int ll, int tt, int rr,
|
||||
int bb, int ol, int ot,
|
||||
int or, int ob ) {
|
||||
scrollDown();
|
||||
}
|
||||
});
|
||||
|
||||
DBUtils.HistoryPair[] pairs
|
||||
= DBUtils.getChatHistory( m_activity, m_rowid, locals );
|
||||
if ( null != pairs ) {
|
||||
for ( DBUtils.HistoryPair pair : pairs ) {
|
||||
addRow( pair.msg, pair.playerIndx );
|
||||
}
|
||||
}
|
||||
// scrollDown();
|
||||
|
||||
String title = getString( R.string.chat_title_fmt,
|
||||
GameUtils.getName( m_activity, m_rowid ) );
|
||||
setTitle( title );
|
||||
} else {
|
||||
// Should really assert....
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
Button sendButton = (Button)findViewById( R.id.chat_send );
|
||||
if ( ABUtils.haveActionBar() ) {
|
||||
sendButton.setVisibility( View.GONE );
|
||||
} else {
|
||||
sendButton.setOnClickListener( new View.OnClickListener() {
|
||||
public void onClick( View view ) {
|
||||
handleSend();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
DBUtils.HistoryPair[] pairs
|
||||
= DBUtils.getChatHistory( m_activity, m_rowid, locals );
|
||||
if ( null != pairs ) {
|
||||
for ( DBUtils.HistoryPair pair : pairs ) {
|
||||
addRow( pair.msg, pair.playerIndx );
|
||||
}
|
||||
}
|
||||
|
||||
String title = getString( R.string.chat_title_fmt,
|
||||
GameUtils.getName( m_activity, m_rowid ) );
|
||||
setTitle( title );
|
||||
} // init
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
m_jniThreadRef = JNIThread.getRetained( m_rowid );
|
||||
|
@ -124,6 +134,13 @@ public class ChatDelegate extends DelegateBase {
|
|||
finish();
|
||||
} else {
|
||||
s_visibleThis = this;
|
||||
int[] startAndEnd = new int[2];
|
||||
String curMsg = DBUtils.getCurChat( m_activity, m_rowid,
|
||||
m_curPlayer, startAndEnd );
|
||||
if ( null != curMsg && 0 < curMsg.length() ) {
|
||||
m_edit.setText( curMsg );
|
||||
m_edit.setSelection( startAndEnd[0], startAndEnd[1] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,6 +151,12 @@ public class ChatDelegate extends DelegateBase {
|
|||
m_jniThreadRef.release();
|
||||
}
|
||||
s_visibleThis = null;
|
||||
|
||||
String curText = m_edit.getText().toString();
|
||||
DBUtils.setCurChat( m_activity, m_rowid, m_curPlayer, curText,
|
||||
m_edit.getSelectionStart(),
|
||||
m_edit.getSelectionEnd() );
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
@ -146,7 +169,7 @@ public class ChatDelegate extends DelegateBase {
|
|||
TextView view = (TextView)row.findViewById( R.id.chat_row_text );
|
||||
view.setText( msg );
|
||||
view = (TextView)row.findViewById( R.id.chat_row_name );
|
||||
view.setText( getString( R.string.chat_sender_fmt,
|
||||
view.setText( getString( R.string.chat_sender_fmt,
|
||||
m_names[playerIndx] ) );
|
||||
m_layout.addView( row );
|
||||
|
||||
|
@ -163,6 +186,15 @@ public class ChatDelegate extends DelegateBase {
|
|||
});
|
||||
}
|
||||
|
||||
private void handleSend() {
|
||||
String text = m_edit.getText().toString();
|
||||
DBUtils.appendChatHistory( m_activity, m_rowid, text, m_curPlayer );
|
||||
addRow( text, m_curPlayer );
|
||||
m_edit.setText( null );
|
||||
|
||||
m_jniThreadRef.sendChat( text );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu( Menu menu )
|
||||
{
|
||||
|
@ -173,7 +205,7 @@ public class ChatDelegate extends DelegateBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected( MenuItem item )
|
||||
public boolean onOptionsItemSelected( MenuItem item )
|
||||
{
|
||||
boolean handled = true;
|
||||
switch ( item.getItemId() ) {
|
||||
|
@ -183,26 +215,7 @@ public class ChatDelegate extends DelegateBase {
|
|||
}
|
||||
break;
|
||||
case R.id.chat_menu_send:
|
||||
String text = m_edit.getText().toString();
|
||||
if ( null == text || text.length() == 0 ) {
|
||||
setResult( Activity.RESULT_CANCELED );
|
||||
finish();
|
||||
} else {
|
||||
DBUtils.appendChatHistory( m_activity, m_rowid, text, m_curPlayer );
|
||||
addRow( text, m_curPlayer );
|
||||
m_edit.setText( null );
|
||||
|
||||
m_jniThreadRef.sendChat( text );
|
||||
// if ( null != jniThread ) {
|
||||
// jniThread.handle( JNIThread.JNICmd.CMD_SENDCHAT, text );
|
||||
// } else {
|
||||
// Intent result = new Intent();
|
||||
// result.putExtra( BoardDelegate.INTENT_KEY_CHAT, text );
|
||||
// setResult( Activity.RESULT_OK, result );
|
||||
// finish();
|
||||
// }
|
||||
}
|
||||
// finish();
|
||||
handleSend();
|
||||
break;
|
||||
default:
|
||||
handled = false;
|
||||
|
@ -218,7 +231,7 @@ public class ChatDelegate extends DelegateBase {
|
|||
case CLEAR_ACTION:
|
||||
if ( AlertDialog.BUTTON_POSITIVE == which ) {
|
||||
DBUtils.clearChatHistory( m_activity, m_rowid );
|
||||
TableLayout layout =
|
||||
TableLayout layout =
|
||||
(TableLayout)findViewById( R.id.chat_history );
|
||||
layout.removeAllViews();
|
||||
}
|
||||
|
@ -239,10 +252,9 @@ public class ChatDelegate extends DelegateBase {
|
|||
return handled;
|
||||
}
|
||||
|
||||
public static void startForResult( Delegator delegator,
|
||||
RequestCode requestCode,
|
||||
long rowID, int curPlayer,
|
||||
String[] names, boolean[] locs )
|
||||
public static void start( Delegator delegator,
|
||||
long rowID, int curPlayer,
|
||||
String[] names, boolean[] locs )
|
||||
{
|
||||
Assert.assertFalse( -1 == curPlayer );
|
||||
Bundle bundle = new Bundle();
|
||||
|
@ -251,13 +263,13 @@ public class ChatDelegate extends DelegateBase {
|
|||
bundle.putStringArray( INTENT_KEY_NAMES, names );
|
||||
bundle.putBooleanArray( INTENT_KEY_LOCS, locs );
|
||||
|
||||
Activity activity = delegator.getActivity();
|
||||
if ( activity instanceof FragActivity ) {
|
||||
FragActivity.addFragment( new ChatFrag(), bundle, delegator );
|
||||
if ( delegator.inDPMode() ) {
|
||||
delegator.addFragment( new ChatFrag( delegator ), bundle );
|
||||
} else {
|
||||
Activity activity = delegator.getActivity();
|
||||
Intent intent = new Intent( activity, ChatActivity.class );
|
||||
intent.putExtras( bundle );
|
||||
activity.startActivityForResult( intent, requestCode.ordinal() );
|
||||
activity.startActivity( intent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import android.os.Bundle;
|
|||
|
||||
public class ChatFrag extends XWFragment {
|
||||
|
||||
public ChatFrag( Delegator parent ) { super( parent ); }
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle sis )
|
||||
{
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
|||
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
|
||||
import org.eehouse.android.xw4.jni.JNIThread.*;
|
||||
|
||||
public class CommsTransport implements TransportProcs,
|
||||
public class CommsTransport implements TransportProcs,
|
||||
NetStateCache.StateChangedIf {
|
||||
private Selector m_selector;
|
||||
private SocketChannel m_socketChannel;
|
||||
|
@ -80,7 +80,7 @@ public class CommsTransport implements TransportProcs,
|
|||
if ( !XWApp.UDP_ENABLED ) {
|
||||
m_done = false;
|
||||
boolean failed = true;
|
||||
try {
|
||||
try {
|
||||
if ( XWApp.onEmulator() ) {
|
||||
System.setProperty("java.net.preferIPv6Addresses", "false");
|
||||
}
|
||||
|
@ -94,13 +94,13 @@ public class CommsTransport implements TransportProcs,
|
|||
DbgUtils.loge( ioe );
|
||||
} catch ( UnresolvedAddressException uae ) {
|
||||
DbgUtils.logf( "bad address: name: %s; port: %s; exception: %s",
|
||||
m_useHost, m_relayAddr.ip_relay_port,
|
||||
m_useHost, m_relayAddr.ip_relay_port,
|
||||
uae.toString() );
|
||||
}
|
||||
|
||||
m_thread = null;
|
||||
if ( failed ) {
|
||||
m_jniThread.handle( JNICmd.CMD_TRANSFAIL,
|
||||
m_jniThread.handle( JNICmd.CMD_TRANSFAIL,
|
||||
CommsConnType.COMMS_CONN_RELAY );
|
||||
}
|
||||
}
|
||||
|
@ -121,10 +121,10 @@ public class CommsTransport implements TransportProcs,
|
|||
try {
|
||||
m_socketChannel = SocketChannel.open();
|
||||
m_socketChannel.configureBlocking( false );
|
||||
DbgUtils.logf( "connecting to %s:%d",
|
||||
m_useHost,
|
||||
DbgUtils.logf( "connecting to %s:%d",
|
||||
m_useHost,
|
||||
m_relayAddr.ip_relay_port );
|
||||
InetSocketAddress isa = new
|
||||
InetSocketAddress isa = new
|
||||
InetSocketAddress(m_useHost,
|
||||
m_relayAddr.ip_relay_port );
|
||||
m_socketChannel.connect( isa );
|
||||
|
@ -163,10 +163,10 @@ public class CommsTransport implements TransportProcs,
|
|||
SelectionKey key = iter.next();
|
||||
SocketChannel channel = (SocketChannel)key.channel();
|
||||
iter.remove();
|
||||
try {
|
||||
try {
|
||||
if (key.isValid() && key.isConnectable()) {
|
||||
if ( !channel.finishConnect() ) {
|
||||
key.cancel();
|
||||
key.cancel();
|
||||
}
|
||||
}
|
||||
if (key.isValid() && key.isReadable()) {
|
||||
|
@ -181,7 +181,7 @@ public class CommsTransport implements TransportProcs,
|
|||
}
|
||||
ConnStatusHandler.
|
||||
updateStatusIn( m_context, null,
|
||||
CommsConnType.COMMS_CONN_RELAY,
|
||||
CommsConnType.COMMS_CONN_RELAY,
|
||||
0 <= nRead );
|
||||
}
|
||||
if (key.isValid() && key.isWritable()) {
|
||||
|
@ -196,7 +196,7 @@ public class CommsTransport implements TransportProcs,
|
|||
}
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
DbgUtils.logf( "%s: cancelling key", ioe.toString() );
|
||||
key.cancel();
|
||||
key.cancel();
|
||||
failed = true;
|
||||
break outer_loop;
|
||||
} catch ( java.nio.channels.
|
||||
|
@ -210,7 +210,7 @@ public class CommsTransport implements TransportProcs,
|
|||
return failed;
|
||||
} // loop
|
||||
}
|
||||
|
||||
|
||||
public void setReceiver( JNIThread jnit )
|
||||
{
|
||||
m_jniThread = jnit;
|
||||
|
@ -229,7 +229,7 @@ public class CommsTransport implements TransportProcs,
|
|||
{
|
||||
if ( !nowAvailable ) {
|
||||
waitToStopImpl();
|
||||
m_jniThread.handle( JNICmd.CMD_TRANSFAIL,
|
||||
m_jniThread.handle( JNICmd.CMD_TRANSFAIL,
|
||||
CommsConnType.COMMS_CONN_RELAY );
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ public class CommsTransport implements TransportProcs,
|
|||
{
|
||||
if ( !XWApp.UDP_ENABLED ) {
|
||||
m_bytesIn.flip();
|
||||
|
||||
|
||||
for ( ; ; ) {
|
||||
int len = m_bytesIn.remaining();
|
||||
if ( len <= 0 ) {
|
||||
|
@ -306,7 +306,7 @@ public class CommsTransport implements TransportProcs,
|
|||
Assert.assertTrue( len > 1 ); // tell me if I see this case
|
||||
if ( len == 1 ) { // half a length byte...
|
||||
break; // can I leave it in the buffer?
|
||||
} else {
|
||||
} else {
|
||||
m_packetIn = new byte[m_bytesIn.getShort()];
|
||||
m_haveLen = 0;
|
||||
}
|
||||
|
@ -349,16 +349,16 @@ public class CommsTransport implements TransportProcs,
|
|||
|
||||
public int getFlags() { return COMMS_XPORT_FLAGS_NONE; }
|
||||
|
||||
public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr,
|
||||
public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr,
|
||||
CommsConnType conType, int gameID )
|
||||
{
|
||||
DbgUtils.logdf( "CommsTransport.transportSend(len=%d, typ=%s)",
|
||||
DbgUtils.logdf( "CommsTransport.transportSend(len=%d, typ=%s)",
|
||||
buf.length, conType.toString() );
|
||||
int nSent = -1;
|
||||
Assert.assertNotNull( addr );
|
||||
Assert.assertTrue( addr.contains( conType ) );
|
||||
|
||||
if ( !XWApp.UDP_ENABLED && conType == CommsConnType.COMMS_CONN_RELAY
|
||||
if ( !XWApp.UDP_ENABLED && conType == CommsConnType.COMMS_CONN_RELAY
|
||||
&& null == m_relayAddr ) {
|
||||
m_relayAddr = new CommsAddrRec( addr );
|
||||
m_useHost = NetUtils.forceHost( m_relayAddr.ip_relay_hostName );
|
||||
|
@ -374,7 +374,7 @@ public class CommsTransport implements TransportProcs,
|
|||
nSent = buf.length;
|
||||
}
|
||||
} else {
|
||||
nSent = sendForAddr( m_context, addr, conType, m_rowid,
|
||||
nSent = sendForAddr( m_context, addr, conType, m_rowid,
|
||||
gameID, buf );
|
||||
}
|
||||
|
||||
|
@ -388,30 +388,30 @@ public class CommsTransport implements TransportProcs,
|
|||
public void relayStatus( CommsRelayState newState )
|
||||
{
|
||||
DbgUtils.logf( "relayStatus called; state=%s", newState.toString() );
|
||||
|
||||
|
||||
switch( newState ) {
|
||||
case COMMS_RELAYSTATE_UNCONNECTED:
|
||||
case COMMS_RELAYSTATE_DENIED:
|
||||
case COMMS_RELAYSTATE_CONNECT_PENDING:
|
||||
ConnStatusHandler.updateStatus( m_context, null,
|
||||
CommsConnType.COMMS_CONN_RELAY,
|
||||
CommsConnType.COMMS_CONN_RELAY,
|
||||
false );
|
||||
break;
|
||||
case COMMS_RELAYSTATE_CONNECTED:
|
||||
case COMMS_RELAYSTATE_RECONNECTED:
|
||||
case COMMS_RELAYSTATE_CONNECTED:
|
||||
case COMMS_RELAYSTATE_RECONNECTED:
|
||||
ConnStatusHandler.updateStatusOut( m_context, null,
|
||||
CommsConnType.COMMS_CONN_RELAY,
|
||||
CommsConnType.COMMS_CONN_RELAY,
|
||||
true );
|
||||
break;
|
||||
case COMMS_RELAYSTATE_ALLCONNECTED:
|
||||
ConnStatusHandler.updateStatusIn( m_context, null,
|
||||
CommsConnType.COMMS_CONN_RELAY,
|
||||
CommsConnType.COMMS_CONN_RELAY,
|
||||
true );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void relayConnd( String room, int devOrder, boolean allHere,
|
||||
public void relayConnd( String room, int devOrder, boolean allHere,
|
||||
int nMissing )
|
||||
{
|
||||
m_tpHandler.tpmRelayConnd( room, devOrder, allHere, nMissing );
|
||||
|
@ -428,8 +428,8 @@ public class CommsTransport implements TransportProcs,
|
|||
return false;
|
||||
}
|
||||
|
||||
private static int sendForAddr( Context context, CommsAddrRec addr,
|
||||
CommsConnType conType, long rowID,
|
||||
private static int sendForAddr( Context context, CommsAddrRec addr,
|
||||
CommsConnType conType, long rowID,
|
||||
int gameID, byte[] buf )
|
||||
{
|
||||
int nSent = -1;
|
||||
|
@ -439,7 +439,7 @@ public class CommsTransport implements TransportProcs,
|
|||
nSent = RelayService.sendPacket( context, rowID, buf );
|
||||
break;
|
||||
case COMMS_CONN_SMS:
|
||||
nSent = SMSService.sendPacket( context, addr.sms_phone,
|
||||
nSent = SMSService.sendPacket( context, addr.sms_phone,
|
||||
gameID, buf );
|
||||
break;
|
||||
case COMMS_CONN_BT:
|
||||
|
|
|
@ -101,7 +101,7 @@ public class ConnStatusHandler {
|
|||
return format( context, m_time );
|
||||
}
|
||||
|
||||
public void update( boolean success )
|
||||
public void update( boolean success )
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
if ( success ) {
|
||||
|
@ -112,19 +112,19 @@ public class ConnStatusHandler {
|
|||
successNewer = success;
|
||||
}
|
||||
|
||||
private String format( Context context, Time time )
|
||||
private String format( Context context, Time time )
|
||||
{
|
||||
CharSequence seq =
|
||||
DateUtils.getRelativeDateTimeString( context,
|
||||
CharSequence seq =
|
||||
DateUtils.getRelativeDateTimeString( context,
|
||||
time.toMillis(true),
|
||||
DateUtils.SECOND_IN_MILLIS,
|
||||
DateUtils.WEEK_IN_MILLIS,
|
||||
DateUtils.WEEK_IN_MILLIS,
|
||||
0 );
|
||||
return seq.toString();
|
||||
}
|
||||
|
||||
// called during deserialization
|
||||
private void readObject( ObjectInputStream in )
|
||||
private void readObject( ObjectInputStream in )
|
||||
throws java.io.IOException, java.lang.ClassNotFoundException
|
||||
{
|
||||
in.defaultReadObject();
|
||||
|
@ -134,7 +134,7 @@ public class ConnStatusHandler {
|
|||
|
||||
private ConnStatusHandler() {}
|
||||
|
||||
private static HashMap<CommsConnType,SuccessRecord[]> s_records =
|
||||
private static HashMap<CommsConnType,SuccessRecord[]> s_records =
|
||||
new HashMap<CommsConnType,SuccessRecord[]>();
|
||||
private static Class s_lockObj = ConnStatusHandler.class;
|
||||
private static boolean s_needsSave = false;
|
||||
|
@ -184,20 +184,20 @@ public class ConnStatusHandler {
|
|||
StringBuffer sb = new StringBuffer();
|
||||
String tmp;
|
||||
synchronized( s_lockObj ) {
|
||||
sb.append( LocUtils.getString( context,
|
||||
sb.append( LocUtils.getString( context,
|
||||
R.string.connstat_net_fmt,
|
||||
connTypes.toString( context )));
|
||||
for ( CommsConnType typ : connTypes.getTypes() ) {
|
||||
String did = "";
|
||||
if ( BuildConfig.DEBUG
|
||||
&& CommsConnType.COMMS_CONN_RELAY == typ ) {
|
||||
did = String.format( "(DevID: %d) ",
|
||||
did = String.format( "(DevID: %d) ",
|
||||
DevID.getRelayDevIDInt(context) );
|
||||
}
|
||||
sb.append( String.format( "\n\n*** %s %s***\n",
|
||||
sb.append( String.format( "\n\n*** %s %s***\n",
|
||||
typ.longName( context ), did ) );
|
||||
SuccessRecord record = recordFor( typ, false );
|
||||
tmp = LocUtils.getString( context, record.successNewer?
|
||||
tmp = LocUtils.getString( context, record.successNewer?
|
||||
R.string.connstat_succ :
|
||||
R.string.connstat_unsucc );
|
||||
sb.append( LocUtils
|
||||
|
@ -215,14 +215,14 @@ public class ConnStatusHandler {
|
|||
}
|
||||
}
|
||||
if ( 0 != fmtId ) {
|
||||
sb.append( LocUtils.getString( context, fmtId,
|
||||
sb.append( LocUtils.getString( context, fmtId,
|
||||
record.olderStr( context )));
|
||||
}
|
||||
sb.append( "\n\n" );
|
||||
|
||||
record = recordFor( typ, true );
|
||||
if ( record.haveSuccess() ) {
|
||||
sb.append( LocUtils.getString( context,
|
||||
sb.append( LocUtils.getString( context,
|
||||
R.string.connstat_lastreceipt_fmt,
|
||||
record.newerStr( context ) ) );
|
||||
} else {
|
||||
|
@ -300,7 +300,7 @@ public class ConnStatusHandler {
|
|||
showSuccessOut( s_cbacks );
|
||||
}
|
||||
|
||||
public static void draw( Context context, Canvas canvas, Resources res,
|
||||
public static void draw( Context context, Canvas canvas, Resources res,
|
||||
CommsConnTypeSet connTypes, boolean isSolo )
|
||||
{
|
||||
if ( !isSolo && null != s_rect ) {
|
||||
|
@ -347,8 +347,8 @@ public class ConnStatusHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static void drawQuarter( Canvas canvas, Resources res, Rect rect,
|
||||
CommsConnTypeSet connTypes,
|
||||
private static void drawQuarter( Canvas canvas, Resources res, Rect rect,
|
||||
CommsConnTypeSet connTypes,
|
||||
boolean enabled, boolean isIn )
|
||||
{
|
||||
enabled = enabled && null != newestSuccess( connTypes, isIn );
|
||||
|
@ -358,10 +358,10 @@ public class ConnStatusHandler {
|
|||
int arrowID;
|
||||
boolean showSuccesses = s_showSuccesses[isIn? SUCCESS_IN : SUCCESS_OUT];
|
||||
if ( isIn ) {
|
||||
arrowID = showSuccesses ?
|
||||
arrowID = showSuccesses ?
|
||||
R.drawable.in_arrow_active : R.drawable.in_arrow;
|
||||
} else {
|
||||
arrowID = showSuccesses ?
|
||||
arrowID = showSuccesses ?
|
||||
R.drawable.out_arrow_active : R.drawable.out_arrow;
|
||||
}
|
||||
drawIn( canvas, res, arrowID, rect );
|
||||
|
@ -373,14 +373,14 @@ public class ConnStatusHandler {
|
|||
public static void loadState( Context context )
|
||||
{
|
||||
synchronized( s_lockObj ) {
|
||||
String as64 = XWPrefs.getPrefsString( context,
|
||||
String as64 = XWPrefs.getPrefsString( context,
|
||||
R.string.key_connstat_data );
|
||||
if ( null != as64 && 0 < as64.length() ) {
|
||||
try {
|
||||
byte[] bytes = XwJNI.base64Decode( as64 );
|
||||
ObjectInputStream ois =
|
||||
ObjectInputStream ois =
|
||||
new ObjectInputStream( new ByteArrayInputStream(bytes) );
|
||||
s_records =
|
||||
s_records =
|
||||
(HashMap<CommsConnType,SuccessRecord[]>)ois.readObject();
|
||||
// } catch ( java.io.StreamCorruptedException sce ) {
|
||||
// DbgUtils.logf( "loadState: %s", sce.toString() );
|
||||
|
@ -397,7 +397,7 @@ public class ConnStatusHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static void saveState( final Context context,
|
||||
private static void saveState( final Context context,
|
||||
ConnStatusCBacks cbcks )
|
||||
{
|
||||
if ( null == cbcks ) {
|
||||
|
@ -463,7 +463,7 @@ public class ConnStatusHandler {
|
|||
icon.draw( canvas );
|
||||
}
|
||||
|
||||
private static SuccessRecord newestSuccess( CommsConnTypeSet connTypes,
|
||||
private static SuccessRecord newestSuccess( CommsConnTypeSet connTypes,
|
||||
boolean isIn )
|
||||
{
|
||||
SuccessRecord result = null;
|
||||
|
@ -486,7 +486,7 @@ public class ConnStatusHandler {
|
|||
{
|
||||
SuccessRecord[] records = s_records.get( connType );
|
||||
if ( null == records ) {
|
||||
records = new SuccessRecord[] { new SuccessRecord(),
|
||||
records = new SuccessRecord[] { new SuccessRecord(),
|
||||
new SuccessRecord(),
|
||||
};
|
||||
s_records.put( connType, records );
|
||||
|
@ -505,9 +505,9 @@ public class ConnStatusHandler {
|
|||
= new ObjectOutputStream( bas );
|
||||
out.writeObject(s_records);
|
||||
out.flush();
|
||||
String as64 =
|
||||
String as64 =
|
||||
XwJNI.base64Encode( bas.toByteArray() );
|
||||
XWPrefs.setPrefsString( context, R.string.key_connstat_data,
|
||||
XWPrefs.setPrefsString( context, R.string.key_connstat_data,
|
||||
as64 );
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
DbgUtils.loge( ioe );
|
||||
|
@ -515,7 +515,7 @@ public class ConnStatusHandler {
|
|||
s_needsSave = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean anyTypeEnabled( Context context, CommsConnTypeSet connTypes )
|
||||
{
|
||||
boolean enabled = false;
|
||||
|
@ -553,7 +553,7 @@ public class ConnStatusHandler {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static boolean getAirplaneModeOn( Context context )
|
||||
private static boolean getAirplaneModeOn( Context context )
|
||||
{
|
||||
boolean result =
|
||||
0 != Settings.System.getInt( context.getContentResolver(),
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ConnViaViewLayout extends LinearLayout {
|
|||
}
|
||||
|
||||
protected void configure( CommsConnTypeSet types,
|
||||
CheckEnabledWarner cew,
|
||||
CheckEnabledWarner cew,
|
||||
SetEmptyWarner sew,
|
||||
DlgDelegate.HasDlgDelegate dlgDlgt )
|
||||
{
|
||||
|
@ -87,10 +87,10 @@ public class ConnViaViewLayout extends LinearLayout {
|
|||
box.setText( typ.longName( context ) );
|
||||
box.setChecked( m_curSet.contains( typ ) );
|
||||
list.addView( item );
|
||||
|
||||
|
||||
final CommsConnType typf = typ;
|
||||
box.setOnCheckedChangeListener( new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
boolean isChecked ) {
|
||||
if ( isChecked ) {
|
||||
showNotAgainTypeTip( typf );
|
||||
|
@ -153,7 +153,7 @@ public class ConnViaViewLayout extends LinearLayout {
|
|||
Assert.fail();
|
||||
break;
|
||||
}
|
||||
m_dlgDlgt.showNotAgainDlgThen( msgID, keyID,
|
||||
m_dlgDlgt.showNotAgainDlgThen( msgID, keyID,
|
||||
DlgDelegate.Action.SKIP_CALLBACK );
|
||||
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
public static final String WORDCOUNT = "WORDCOUNT";
|
||||
public static final String WORDCOUNTS = "WORDCOUNTS";
|
||||
public static final String LANGCODE = "LANGCODE";
|
||||
public static final String LOC = "LOC";
|
||||
public static final String LOC = "LOC";
|
||||
public static final String ITERMIN = "ITERMIN";
|
||||
public static final String ITERMAX = "ITERMAX";
|
||||
public static final String ITERPOS = "ITERPOS";
|
||||
|
@ -236,7 +236,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate( SQLiteDatabase db )
|
||||
public void onCreate( SQLiteDatabase db )
|
||||
{
|
||||
createTable( db, TABLE_NAME_SUM, s_summaryColsAndTypes );
|
||||
createTable( db, TABLE_NAME_OBITS, s_obitsColsAndTypes );
|
||||
|
@ -254,7 +254,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("fallthrough")
|
||||
public void onUpgrade( SQLiteDatabase db, int oldVersion, int newVersion )
|
||||
public void onUpgrade( SQLiteDatabase db, int oldVersion, int newVersion )
|
||||
{
|
||||
DbgUtils.logf( false, "onUpgrade: old: %d; new: %d", oldVersion, newVersion );
|
||||
|
||||
|
@ -359,9 +359,9 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
db.execSQL( cmd );
|
||||
}
|
||||
|
||||
private void createTable( SQLiteDatabase db, String name, String[][] data )
|
||||
private void createTable( SQLiteDatabase db, String name, String[][] data )
|
||||
{
|
||||
StringBuilder query =
|
||||
StringBuilder query =
|
||||
new StringBuilder( String.format("CREATE TABLE %s (", name ) );
|
||||
|
||||
for ( int ii = 0; ii < data.length; ++ii ) {
|
||||
|
@ -438,11 +438,11 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
// Move all existing games to the row previously named "cur games'
|
||||
private void moveToCurGames( SQLiteDatabase db )
|
||||
{
|
||||
String name = LocUtils.getString( m_context, false,
|
||||
String name = LocUtils.getString( m_context, false,
|
||||
R.string.group_cur_games );
|
||||
String[] columns = { "rowid" };
|
||||
String selection = String.format( "%s = '%s'", GROUPNAME, name );
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_GROUPS, columns,
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_GROUPS, columns,
|
||||
selection, null, null, null, null );
|
||||
if ( 1 == cursor.getCount() && cursor.moveToFirst() ) {
|
||||
long rowid = cursor.getLong( cursor.getColumnIndex("rowid") );
|
||||
|
@ -454,7 +454,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
cursor.close();
|
||||
}
|
||||
|
||||
private void makeAutoincrement( SQLiteDatabase db, String name,
|
||||
private void makeAutoincrement( SQLiteDatabase db, String name,
|
||||
String[][] data )
|
||||
{
|
||||
db.beginTransaction();
|
||||
|
@ -468,9 +468,9 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
createTable( db, name, data );
|
||||
forceRowidHigh( db, name );
|
||||
|
||||
|
||||
if ( null != columnNames ) {
|
||||
ArrayList<String> oldCols =
|
||||
ArrayList<String> oldCols =
|
||||
new ArrayList<String>( Arrays.asList( columnNames ) );
|
||||
|
||||
// Make a list of columns in the new DB, using it to
|
||||
|
@ -488,23 +488,23 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||
oldCols.retainAll( newCols );
|
||||
|
||||
String cols = TextUtils.join( ",", oldCols );
|
||||
query =
|
||||
query =
|
||||
String.format( "INSERT INTO %s (%s) SELECT %s from temp_%s",
|
||||
name, cols, cols, name );
|
||||
db.execSQL( query );
|
||||
}
|
||||
db.execSQL( String.format( "DROP table temp_%s", name ) );
|
||||
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
private void setColumnsEqual( SQLiteDatabase db, String table,
|
||||
private void setColumnsEqual( SQLiteDatabase db, String table,
|
||||
String dest, String src )
|
||||
{
|
||||
String query = String.format( "UPDATE %s set %s = %s", table,
|
||||
String query = String.format( "UPDATE %s set %s = %s", table,
|
||||
dest, src );
|
||||
db.execSQL( query );
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -66,7 +66,7 @@ public class DbgUtils {
|
|||
logf( true, msg );
|
||||
}
|
||||
|
||||
public static void logf( boolean persist, String msg )
|
||||
public static void logf( boolean persist, String msg )
|
||||
{
|
||||
if ( s_doLog ) {
|
||||
String time = "";
|
||||
|
@ -162,7 +162,7 @@ public class DbgUtils {
|
|||
// }
|
||||
// }
|
||||
|
||||
public static void dumpCursor( Cursor cursor )
|
||||
public static void dumpCursor( Cursor cursor )
|
||||
{
|
||||
if ( s_doLog ) {
|
||||
String dump = DatabaseUtils.dumpCursorToString( cursor );
|
||||
|
|
|
@ -19,13 +19,14 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.graphics.Point;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -38,6 +39,11 @@ import android.widget.CheckBox;
|
|||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||
import org.eehouse.android.xw4.DlgDelegate.ActionPair;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
@ -57,13 +63,16 @@ public class DelegateBase implements DlgClickNotify,
|
|||
private int m_layoutID;
|
||||
private View m_rootView;
|
||||
private boolean m_isVisible;
|
||||
private ArrayList<Runnable> m_visibleProcs = new ArrayList<Runnable>();
|
||||
private static Map<Class, WeakReference<DelegateBase>> s_instances
|
||||
= new HashMap<Class, WeakReference<DelegateBase>>();
|
||||
|
||||
public DelegateBase( Delegator delegator, Bundle bundle, int layoutID )
|
||||
{
|
||||
this( delegator, bundle, layoutID, R.menu.empty );
|
||||
}
|
||||
|
||||
public DelegateBase( Delegator delegator, Bundle bundle,
|
||||
public DelegateBase( Delegator delegator, Bundle bundle,
|
||||
int layoutID, int menuID )
|
||||
{
|
||||
Assert.assertTrue( 0 < menuID );
|
||||
|
@ -80,16 +89,15 @@ public class DelegateBase implements DlgClickNotify,
|
|||
protected void onSaveInstanceState( Bundle outState ) {}
|
||||
public boolean onPrepareOptionsMenu( Menu menu ) { return false; }
|
||||
public boolean onOptionsItemSelected( MenuItem item ) { return false; }
|
||||
public void onCreateContextMenu( ContextMenu menu, View view,
|
||||
ContextMenuInfo menuInfo ) {}
|
||||
public boolean onContextItemSelected( MenuItem item ) { return false; }
|
||||
protected void onStart() {}
|
||||
protected void onCreateContextMenu( ContextMenu menu, View view,
|
||||
ContextMenuInfo menuInfo ) {}
|
||||
protected boolean onContextItemSelected( MenuItem item ) { return false; }
|
||||
protected void onStop() {}
|
||||
protected void onDestroy() {}
|
||||
protected void onWindowFocusChanged( boolean hasFocus ) {}
|
||||
protected boolean onBackPressed() { return false; }
|
||||
protected boolean handleBackPressed() { return false; }
|
||||
public void orientationChanged() {}
|
||||
|
||||
|
||||
protected void requestWindowFeature( int feature ) {}
|
||||
|
||||
// Fragments only
|
||||
|
@ -105,16 +113,27 @@ public class DelegateBase implements DlgClickNotify,
|
|||
return view;
|
||||
}
|
||||
|
||||
protected void onActivityResult( RequestCode requestCode, int resultCode,
|
||||
Intent data )
|
||||
protected void onActivityResult( RequestCode requestCode, int resultCode,
|
||||
Intent data )
|
||||
{
|
||||
DbgUtils.logf( "DelegateBase.onActivityResult(): subclass responsibility!!!" );
|
||||
DbgUtils.logf( "%s.onActivityResult(): subclass responsibility!!!",
|
||||
getClass().getSimpleName() );
|
||||
}
|
||||
|
||||
protected void onResume()
|
||||
protected void onStart()
|
||||
{
|
||||
if ( s_instances.containsKey(getClass()) ) {
|
||||
DbgUtils.logdf( "%s.onStart(): replacing curThis",
|
||||
getClass().getSimpleName() );
|
||||
}
|
||||
s_instances.put( getClass(), new WeakReference<DelegateBase>(this) );
|
||||
}
|
||||
|
||||
protected void onResume()
|
||||
{
|
||||
m_isVisible = true;
|
||||
XWService.setListener( this );
|
||||
runIfVisible();
|
||||
}
|
||||
|
||||
protected void onPause()
|
||||
|
@ -123,6 +142,17 @@ public class DelegateBase implements DlgClickNotify,
|
|||
XWService.setListener( null );
|
||||
}
|
||||
|
||||
protected DelegateBase curThis()
|
||||
{
|
||||
DelegateBase result = null;
|
||||
WeakReference<DelegateBase> ref = s_instances.get( getClass() );
|
||||
if ( null != ref ) {
|
||||
result = ref.get();
|
||||
}
|
||||
// DbgUtils.logdf( "%s.curThis() => " + result, this.toString() );
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean onCreateOptionsMenu( Menu menu, MenuInflater inflater )
|
||||
{
|
||||
boolean handled = 0 < m_optionsMenuID;
|
||||
|
@ -144,7 +174,9 @@ public class DelegateBase implements DlgClickNotify,
|
|||
|
||||
protected boolean isFinishing()
|
||||
{
|
||||
return m_activity.isFinishing();
|
||||
boolean result = m_activity.isFinishing();
|
||||
// DbgUtils.logf( "%s.isFinishing() => %b", getClass().getSimpleName(), result );
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Intent getIntent()
|
||||
|
@ -202,7 +234,7 @@ public class DelegateBase implements DlgClickNotify,
|
|||
return m_activity.getTitle().toString();
|
||||
}
|
||||
|
||||
protected void startActivityForResult( Intent intent,
|
||||
protected void startActivityForResult( Intent intent,
|
||||
RequestCode requestCode )
|
||||
{
|
||||
m_activity.startActivityForResult( intent, requestCode.ordinal() );
|
||||
|
@ -210,8 +242,10 @@ public class DelegateBase implements DlgClickNotify,
|
|||
|
||||
protected void setResult( int result, Intent intent )
|
||||
{
|
||||
if ( m_activity instanceof FragActivity ) {
|
||||
Assert.fail();
|
||||
if ( m_activity instanceof MainActivity ) {
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
XWFragment fragment = (XWFragment)m_delegator;
|
||||
main.setFragmentResult( fragment, result, intent );
|
||||
} else {
|
||||
m_activity.setResult( result, intent );
|
||||
}
|
||||
|
@ -234,34 +268,52 @@ public class DelegateBase implements DlgClickNotify,
|
|||
|
||||
protected void finish()
|
||||
{
|
||||
if ( m_activity instanceof FragActivity ) {
|
||||
((FragActivity)m_activity).finishFragment();
|
||||
} else {
|
||||
boolean handled = false;
|
||||
if ( m_activity instanceof MainActivity ) {
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
if ( main.inDPMode() ) {
|
||||
main.finishFragment();
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !handled ) {
|
||||
m_activity.finish();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isPortrait()
|
||||
{
|
||||
int[] containerDims = getContainerDims( new int[2] );
|
||||
boolean result = containerDims[0] < containerDims[1];
|
||||
DbgUtils.logdf( "%s.isPortrait() => %b", getClass().getName(), result );
|
||||
Point size = getContainerSize();
|
||||
boolean result = size.x < size.y;
|
||||
DbgUtils.logdf( "%s.isPortrait() => %b",
|
||||
getClass().getSimpleName(), result );
|
||||
return result;
|
||||
}
|
||||
|
||||
protected int[] getContainerDims( int[] outDims )
|
||||
private Point getContainerSize()
|
||||
{
|
||||
if ( m_activity instanceof FragActivity ) {
|
||||
((FragActivity)m_activity).getFragmentDims( outDims );
|
||||
Point result = null;
|
||||
if ( m_activity instanceof MainActivity ) {
|
||||
result = ((MainActivity)m_activity).getFragmentSize();
|
||||
} else {
|
||||
Rect rect = new Rect();
|
||||
m_rootView.getWindowVisibleDisplayFrame( rect );
|
||||
outDims[0] = rect.width();
|
||||
outDims[1] = rect.height();
|
||||
result = new Point( rect.width(), rect.height() );
|
||||
}
|
||||
DbgUtils.logdf( "%s.getContainerSize(): width => %d, height => %d",
|
||||
getClass().getSimpleName(), result.x, result.y );
|
||||
return result;
|
||||
}
|
||||
|
||||
private void runIfVisible()
|
||||
{
|
||||
if ( isVisible() ) {
|
||||
for ( Runnable proc : m_visibleProcs ) {
|
||||
post( proc );
|
||||
}
|
||||
m_visibleProcs.clear();
|
||||
}
|
||||
DbgUtils.logdf( "%s.getContainerDims(): width => %d, height => %d",
|
||||
getClass().getName(), outDims[0], outDims[1] );
|
||||
return outDims;
|
||||
}
|
||||
|
||||
protected String getString( int resID, Object... params )
|
||||
|
@ -279,10 +331,10 @@ public class DelegateBase implements DlgClickNotify,
|
|||
return LocUtils.xlateLang( m_activity, langCode, caps );
|
||||
}
|
||||
|
||||
protected String getQuantityString( int resID, int quantity,
|
||||
protected String getQuantityString( int resID, int quantity,
|
||||
Object... params )
|
||||
{
|
||||
return LocUtils.getQuantityString( m_activity, resID, quantity,
|
||||
return LocUtils.getQuantityString( m_activity, resID, quantity,
|
||||
params );
|
||||
}
|
||||
|
||||
|
@ -463,7 +515,7 @@ public class DelegateBase implements DlgClickNotify,
|
|||
m_dlgDelegate.showConfirmThen( null, msg, action, params );
|
||||
}
|
||||
|
||||
protected void showConfirmThen( Runnable onNA, String msg, int posButton,
|
||||
protected void showConfirmThen( Runnable onNA, String msg, int posButton,
|
||||
Action action, Object... params )
|
||||
{
|
||||
m_dlgDelegate.showConfirmThen( onNA, msg, posButton, action, params );
|
||||
|
@ -491,7 +543,7 @@ public class DelegateBase implements DlgClickNotify,
|
|||
m_dlgDelegate.showConfirmThen( msg, posButton, negButton, action, params );
|
||||
}
|
||||
|
||||
protected void showConfirmThen( int msg, int posButton, Action action,
|
||||
protected void showConfirmThen( int msg, int posButton, Action action,
|
||||
Object... params )
|
||||
{
|
||||
m_dlgDelegate.showConfirmThen( msg, posButton, action, params );
|
||||
|
@ -502,10 +554,10 @@ public class DelegateBase implements DlgClickNotify,
|
|||
m_dlgDelegate.showConfirmThen( msgID, action );
|
||||
}
|
||||
|
||||
public void showConfirmThen( Runnable onNA, String msg, int posButton,
|
||||
public void showConfirmThen( Runnable onNA, String msg, int posButton,
|
||||
int negButton, Action action, Object... params )
|
||||
{
|
||||
m_dlgDelegate.showConfirmThen( onNA, msg, posButton, negButton, action,
|
||||
m_dlgDelegate.showConfirmThen( onNA, msg, posButton, negButton, action,
|
||||
params );
|
||||
}
|
||||
|
||||
|
@ -551,13 +603,13 @@ public class DelegateBase implements DlgClickNotify,
|
|||
m_dlgDelegate.startProgress( titleID, msg, null );
|
||||
}
|
||||
|
||||
protected void startProgress( int titleID, int msgID,
|
||||
protected void startProgress( int titleID, int msgID,
|
||||
OnCancelListener lstnr )
|
||||
{
|
||||
m_dlgDelegate.startProgress( titleID, msgID, lstnr );
|
||||
}
|
||||
|
||||
protected void startProgress( int titleID, String msg,
|
||||
protected void startProgress( int titleID, String msg,
|
||||
OnCancelListener lstnr )
|
||||
{
|
||||
m_dlgDelegate.startProgress( titleID, msg, lstnr );
|
||||
|
@ -584,7 +636,19 @@ public class DelegateBase implements DlgClickNotify,
|
|||
}
|
||||
|
||||
protected boolean isVisible() { return m_isVisible; }
|
||||
|
||||
|
||||
protected boolean handleNewIntent( Intent intent ) {
|
||||
DbgUtils.logf( "%s.handleNewIntent(%s): not handling",
|
||||
getClass().getSimpleName(), intent.toString() );
|
||||
return false; // not handled
|
||||
}
|
||||
|
||||
protected void runWhenActive( Runnable proc )
|
||||
{
|
||||
m_visibleProcs.add( proc );
|
||||
runIfVisible();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// MultiService.MultiEventListener interface
|
||||
//////////////////////////////////////////////////
|
||||
|
@ -609,7 +673,7 @@ public class DelegateBase implements DlgClickNotify,
|
|||
m_dlgDelegate.eventOccurred( event, args );
|
||||
break;
|
||||
default:
|
||||
DbgUtils.logdf( "DelegateBase.eventOccurred(event=%s) (DROPPED)",
|
||||
DbgUtils.logdf( "DelegateBase.eventOccurred(event=%s) (DROPPED)",
|
||||
event.toString() );
|
||||
break;
|
||||
}
|
||||
|
@ -680,5 +744,4 @@ public class DelegateBase implements DlgClickNotify,
|
|||
{
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,10 @@ public interface Delegator {
|
|||
Activity getActivity();
|
||||
Bundle getArguments();
|
||||
void finish();
|
||||
|
||||
boolean inDPMode();
|
||||
void addFragment( XWFragment fragment, Bundle extras );
|
||||
void addFragmentForResult( XWFragment fragment, Bundle extras,
|
||||
RequestCode requestCode );
|
||||
// For activities with lists
|
||||
void setListAdapter( ListAdapter adapter );
|
||||
ListAdapter getListAdapter();
|
||||
|
|
|
@ -126,7 +126,7 @@ public class DevID {
|
|||
int storedVers = DBUtils.getIntFor( context, GCM_REGVERS_KEY, 0 );
|
||||
// TRANSITIONAL
|
||||
if ( 0 == storedVers ) {
|
||||
storedVers = XWPrefs.getPrefsInt( context,
|
||||
storedVers = XWPrefs.getPrefsInt( context,
|
||||
R.string.key_gcmvers_regid, 0 );
|
||||
if ( 0 != storedVers ) {
|
||||
DBUtils.setIntFor( context, GCM_REGVERS_KEY, storedVers );
|
||||
|
|
|
@ -27,7 +27,7 @@ public class DictBrowseActivity extends XWActivity {
|
|||
private DictBrowseDelegate m_dlgt;
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
m_dlgt = new DictBrowseDelegate( this, savedInstanceState );
|
||||
super.onCreate( savedInstanceState, m_dlgt );
|
||||
|
|
|
@ -87,11 +87,11 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
XwJNI.dict_iter_setMinMax( m_dictClosure, m_browseState.m_minShown,
|
||||
m_browseState.m_maxShown );
|
||||
m_nWords = XwJNI.dict_iter_wordCount( m_dictClosure );
|
||||
|
||||
|
||||
int format = m_browseState.m_minShown == m_browseState.m_maxShown ?
|
||||
R.string.dict_browse_title1_fmt : R.string.dict_browse_title_fmt;
|
||||
setTitle( getString( format, m_name, m_nWords,
|
||||
m_browseState.m_minShown,
|
||||
setTitle( getString( format, m_name, m_nWords,
|
||||
m_browseState.m_minShown,
|
||||
m_browseState.m_maxShown ));
|
||||
|
||||
String desc = XwJNI.dict_iter_getDesc( m_dictClosure );
|
||||
|
@ -103,7 +103,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
public Object getItem( int position )
|
||||
public Object getItem( int position )
|
||||
{
|
||||
TextView text = (TextView)
|
||||
inflate( android.R.layout.simple_list_item_1 );
|
||||
|
@ -121,7 +121,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
|
||||
public long getItemId( int position ) { return position; }
|
||||
|
||||
public int getCount() {
|
||||
public int getCount() {
|
||||
Assert.assertTrue( 0 != m_dictClosure );
|
||||
return m_nWords;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
}
|
||||
return m_indices[section];
|
||||
}
|
||||
|
||||
|
||||
public int getSectionForPosition( int position )
|
||||
{
|
||||
int section = Arrays.binarySearch( m_indices, position );
|
||||
|
@ -146,8 +146,8 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
}
|
||||
return section;
|
||||
}
|
||||
|
||||
public Object[] getSections()
|
||||
|
||||
public Object[] getSections()
|
||||
{
|
||||
m_prefixes = XwJNI.dict_iter_getPrefixes( m_dictClosure );
|
||||
m_indices = XwJNI.dict_iter_getIndices( m_dictClosure );
|
||||
|
@ -161,7 +161,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
protected void init( Bundle savedInstanceState )
|
||||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
Bundle args = getArguments();
|
||||
String name = null == args? null : args.getString( DICT_NAME );
|
||||
|
@ -170,7 +170,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
finish();
|
||||
} else {
|
||||
m_name = name;
|
||||
m_loc =
|
||||
m_loc =
|
||||
DictUtils.DictLoc.values()[args.getInt( DICT_LOC, 0 )];
|
||||
m_lang = DictLangCache.getDictLangCode( m_activity, name );
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
m_browseState.m_top = 0;
|
||||
}
|
||||
if ( null == m_browseState.m_counts ) {
|
||||
m_browseState.m_counts =
|
||||
m_browseState.m_counts =
|
||||
XwJNI.dict_iter_getCounts( m_dictClosure );
|
||||
}
|
||||
|
||||
|
@ -278,11 +278,10 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
launchLookup( words, m_lang, true );
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// AdapterView.OnItemSelectedListener interface
|
||||
//////////////////////////////////////////////////
|
||||
public void onItemSelected( AdapterView<?> parent, View view,
|
||||
public void onItemSelected( AdapterView<?> parent, View view,
|
||||
int position, long id )
|
||||
{
|
||||
TextView text = (TextView)view;
|
||||
|
@ -307,7 +306,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
@Override
|
||||
public void dlgButtonClicked( Action action, int which, Object[] params )
|
||||
{
|
||||
Assert.assertTrue( Action.FINISH_ACTION == action );
|
||||
Assert.assertTrue( Action.FINISH_ACTION == action );
|
||||
finish();
|
||||
}
|
||||
|
||||
|
@ -332,7 +331,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
edit.setText( text );
|
||||
}
|
||||
|
||||
private void showPrefix()
|
||||
private void showPrefix()
|
||||
{
|
||||
String text = m_browseState.m_prefix;
|
||||
if ( null != text && 0 < text.length() ) {
|
||||
|
@ -340,7 +339,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
if ( 0 <= pos ) {
|
||||
getListView().setSelection( pos );
|
||||
} else {
|
||||
DbgUtils.showf( m_activity, R.string.dict_browse_nowords_fmt,
|
||||
DbgUtils.showf( m_activity, R.string.dict_browse_nowords_fmt,
|
||||
m_name, text );
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +352,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
// adapter/making it recognized a changed dataset. So, as a
|
||||
// workaround, relaunch the activity with different
|
||||
// parameters.
|
||||
if ( m_browseState.m_minShown != min ||
|
||||
if ( m_browseState.m_minShown != min ||
|
||||
m_browseState.m_maxShown != max ) {
|
||||
|
||||
m_browseState.m_pos = 0;
|
||||
|
@ -378,7 +377,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
++m_minAvail;
|
||||
}
|
||||
m_maxAvail = XwJNI.MAX_COLS_DICT;
|
||||
while ( 0 == counts[m_maxAvail] ) { //
|
||||
while ( 0 == counts[m_maxAvail] ) { //
|
||||
--m_maxAvail;
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +394,7 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
nums[ii] = String.format( "%d", min + ii );
|
||||
}
|
||||
ArrayAdapter<String> adapter = new
|
||||
ArrayAdapter<String>( m_activity,
|
||||
ArrayAdapter<String>( m_activity,
|
||||
//android.R.layout.simple_spinner_dropdown_item,
|
||||
android.R.layout.simple_spinner_item,
|
||||
nums );
|
||||
|
@ -412,29 +411,29 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
// current max the largest min allowed, and the current
|
||||
// min the smallest max allowed.
|
||||
m_minSpinner = (Spinner)findViewById( R.id.wordlen_min );
|
||||
makeAdapter( m_minSpinner, m_minAvail, m_browseState.m_maxShown,
|
||||
makeAdapter( m_minSpinner, m_minAvail, m_browseState.m_maxShown,
|
||||
m_browseState.m_minShown );
|
||||
m_minSpinner.setOnItemSelectedListener( this );
|
||||
|
||||
m_maxSpinner = (Spinner)findViewById( R.id.wordlen_max );
|
||||
makeAdapter( m_maxSpinner, m_browseState.m_minShown,
|
||||
makeAdapter( m_maxSpinner, m_browseState.m_minShown,
|
||||
m_maxAvail, m_browseState.m_maxShown );
|
||||
m_maxSpinner.setOnItemSelectedListener( this );
|
||||
}
|
||||
|
||||
private static void launch( Delegator delegator, Bundle bundle )
|
||||
{
|
||||
Activity activity = delegator.getActivity();
|
||||
if ( activity instanceof FragActivity ) {
|
||||
FragActivity.addFragment( new DictBrowseFrag(), bundle, delegator );
|
||||
if ( delegator.inDPMode() ) {
|
||||
delegator.addFragment( new DictBrowseFrag( delegator ), bundle );
|
||||
} else {
|
||||
Activity activity = delegator.getActivity();
|
||||
Intent intent = new Intent( activity, DictBrowseActivity.class );
|
||||
intent.putExtras( bundle );
|
||||
activity.startActivity( intent );
|
||||
}
|
||||
}
|
||||
|
||||
public static void launch( Delegator delegator, String name,
|
||||
public static void launch( Delegator delegator, String name,
|
||||
DictUtils.DictLoc loc )
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
|
@ -447,6 +446,10 @@ public class DictBrowseDelegate extends ListDelegateBase
|
|||
{
|
||||
DictUtils.DictLoc loc
|
||||
= DictUtils.getDictLoc( delegator.getActivity(), name );
|
||||
launch( delegator, name, loc );
|
||||
if ( null == loc ) {
|
||||
DbgUtils.logf( "DictBrowseDelegate.launch(): DictLoc null; try again?" );
|
||||
} else {
|
||||
launch( delegator, name, loc );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import android.os.Bundle;
|
|||
|
||||
public class DictBrowseFrag extends XWFragment {
|
||||
|
||||
public DictBrowseFrag( Delegator parent ) { super( parent ); }
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle sis )
|
||||
{
|
||||
|
|
|
@ -72,7 +72,7 @@ public class DictLangCache {
|
|||
String lang = getLangName( m_context, dal.name );
|
||||
if ( null != lang && 0 != lang.length() ) {
|
||||
if ( ! m_map.containsValue( lang ) ) {
|
||||
String locName = LocUtils.xlateLang( m_context, lang,
|
||||
String locName = LocUtils.xlateLang( m_context, lang,
|
||||
true );
|
||||
m_map.put( locName, lang );
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class DictLangCache {
|
|||
|
||||
// Now build the array data
|
||||
clear();
|
||||
for ( Iterator<String> iter = m_map.keySet().iterator();
|
||||
for ( Iterator<String> iter = m_map.keySet().iterator();
|
||||
iter.hasNext(); ) {
|
||||
String locName = iter.next();
|
||||
add( locName );
|
||||
|
@ -113,7 +113,7 @@ public class DictLangCache {
|
|||
}
|
||||
}
|
||||
|
||||
private static Comparator<String> KeepLast =
|
||||
private static Comparator<String> KeepLast =
|
||||
new Comparator<String>() {
|
||||
public int compare( String str1, String str2 )
|
||||
{
|
||||
|
@ -133,10 +133,10 @@ public class DictLangCache {
|
|||
DictInfo info = getInfo( context, dal );
|
||||
if ( null != info ) {
|
||||
int wordCount = info.wordCount;
|
||||
|
||||
|
||||
String langName = getLangName( context, dal.name );
|
||||
String locName = LocUtils.xlateLang( context, langName );
|
||||
result = LocUtils.getString( context, R.string.dict_desc_fmt,
|
||||
result = LocUtils.getString( context, R.string.dict_desc_fmt,
|
||||
dal.name, locName,
|
||||
wordCount );
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ public class DictLangCache {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static Comparator<DictInfo> s_ByCount =
|
||||
private static Comparator<DictInfo> s_ByCount =
|
||||
new Comparator<DictInfo>() {
|
||||
public int compare( DictInfo di1, DictInfo di2 )
|
||||
{
|
||||
|
@ -337,9 +337,9 @@ public class DictLangCache {
|
|||
s_handler.post( new Runnable() {
|
||||
public void run() {
|
||||
if ( null != s_dictsAdapter ) {
|
||||
rebuildAdapter( s_dictsAdapter,
|
||||
rebuildAdapter( s_dictsAdapter,
|
||||
DictLangCache.
|
||||
getHaveLang( context,
|
||||
getHaveLang( context,
|
||||
s_adaptedLang ) );
|
||||
}
|
||||
if ( null != s_langsAdapter ) {
|
||||
|
@ -370,7 +370,7 @@ public class DictLangCache {
|
|||
return langs.toArray( result );
|
||||
}
|
||||
|
||||
public static String getBestDefault( Context context, int lang,
|
||||
public static String getBestDefault( Context context, int lang,
|
||||
boolean human )
|
||||
{
|
||||
String dict = human? CommonPrefs.getDefaultHumanDict( context )
|
||||
|
@ -410,19 +410,19 @@ public class DictLangCache {
|
|||
public static LangsArrayAdapter getLangsAdapter( Context context )
|
||||
{
|
||||
if ( null == s_langsAdapter ) {
|
||||
s_langsAdapter =
|
||||
new LangsArrayAdapter( context,
|
||||
s_langsAdapter =
|
||||
new LangsArrayAdapter( context,
|
||||
android.R.layout.simple_spinner_item );
|
||||
s_langsAdapter.rebuild();
|
||||
}
|
||||
return s_langsAdapter;
|
||||
}
|
||||
|
||||
public static ArrayAdapter<String> getDictsAdapter( Context context,
|
||||
public static ArrayAdapter<String> getDictsAdapter( Context context,
|
||||
int lang )
|
||||
{
|
||||
if ( lang != s_adaptedLang ) {
|
||||
s_dictsAdapter =
|
||||
s_dictsAdapter =
|
||||
new ArrayAdapter<String>( context,
|
||||
android.R.layout.simple_spinner_item );
|
||||
rebuildAdapter( s_dictsAdapter, getHaveLang( context, lang ) );
|
||||
|
@ -473,7 +473,7 @@ public class DictLangCache {
|
|||
|
||||
// Tmp test that recovers from problem with new background download code
|
||||
if ( null != info && 0 == info.langCode ) {
|
||||
DbgUtils.logf( "getInfo: dropping info for %s b/c lang code wrong",
|
||||
DbgUtils.logf( "getInfo: dropping info for %s b/c lang code wrong",
|
||||
dal.name );
|
||||
info = null;
|
||||
}
|
||||
|
@ -483,9 +483,9 @@ public class DictLangCache {
|
|||
DictUtils.DictPairs pairs = DictUtils.openDicts( context, names );
|
||||
|
||||
info = new DictInfo();
|
||||
if ( XwJNI.dict_getInfo( pairs.m_bytes[0], dal.name,
|
||||
pairs.m_paths[0],
|
||||
JNIUtilsImpl.get( context ),
|
||||
if ( XwJNI.dict_getInfo( pairs.m_bytes[0], dal.name,
|
||||
pairs.m_paths[0],
|
||||
JNIUtilsImpl.get( context ),
|
||||
DictLoc.DOWNLOAD == dal.loc,
|
||||
info ) ) {
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public class DictListPreference extends XWListPreference {
|
|||
String name = dals[ii].name;
|
||||
if ( langCode == DictLangCache.getDictLangCode( context, name ) ) {
|
||||
values.add( name );
|
||||
dictEntries.add( DictLangCache.annotatedDictName( context,
|
||||
dictEntries.add( DictLangCache.annotatedDictName( context,
|
||||
dals[ii] ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class DictUtils {
|
|||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
public static class DictPairs {
|
||||
public byte[][] m_bytes;
|
||||
public String[] m_paths;
|
||||
|
@ -113,13 +113,13 @@ public class DictUtils {
|
|||
public String name;
|
||||
public DictLoc loc;
|
||||
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
@Override
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
boolean result = false;
|
||||
if ( obj instanceof DictAndLoc ) {
|
||||
DictAndLoc other = (DictAndLoc)obj;
|
||||
|
||||
|
||||
result = name.equals( other.name )
|
||||
&& loc.equals( other.loc );
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public class DictUtils {
|
|||
return name.compareTo( other.name );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void invalDictList()
|
||||
{
|
||||
s_dictListCache = null;
|
||||
|
@ -139,7 +139,7 @@ public class DictUtils {
|
|||
// changes?
|
||||
}
|
||||
|
||||
private static void tryDir( Context context, File dir, boolean strict,
|
||||
private static void tryDir( Context context, File dir, boolean strict,
|
||||
DictLoc loc, ArrayList<DictAndLoc> al )
|
||||
{
|
||||
if ( null != dir ) {
|
||||
|
@ -161,7 +161,7 @@ public class DictUtils {
|
|||
|
||||
for ( String file : getAssets( context ) ) {
|
||||
if ( isDict( context, file, null ) ) {
|
||||
al.add( new DictAndLoc( removeDictExtn( file ),
|
||||
al.add( new DictAndLoc( removeDictExtn( file ),
|
||||
DictLoc.BUILT_IN ) );
|
||||
}
|
||||
}
|
||||
|
@ -174,10 +174,10 @@ public class DictUtils {
|
|||
}
|
||||
|
||||
tryDir( context, getSDDir( context ), false, DictLoc.EXTERNAL, al );
|
||||
tryDir( context, getDownloadDir( context ), true,
|
||||
tryDir( context, getDownloadDir( context ), true,
|
||||
DictLoc.DOWNLOAD, al );
|
||||
|
||||
s_dictListCache =
|
||||
s_dictListCache =
|
||||
al.toArray( new DictUtils.DictAndLoc[al.size()] );
|
||||
}
|
||||
return s_dictListCache;
|
||||
|
@ -221,7 +221,7 @@ public class DictUtils {
|
|||
}
|
||||
}
|
||||
|
||||
// DbgUtils.logf( "getDictLoc(%s)=>%h(%s)", name, loc,
|
||||
// DbgUtils.logf( "getDictLoc(%s)=>%h(%s)", name, loc,
|
||||
// ((null != loc)?loc.toString():"UNKNOWN") );
|
||||
return loc;
|
||||
}
|
||||
|
@ -262,12 +262,12 @@ public class DictUtils {
|
|||
boolean success = false;
|
||||
|
||||
try {
|
||||
FileInputStream fis = DictLoc.INTERNAL == from
|
||||
FileInputStream fis = DictLoc.INTERNAL == from
|
||||
? context.openFileInput( name )
|
||||
: new FileInputStream( getDictFile( context, name, from ) );
|
||||
|
||||
FileOutputStream fos = DictLoc.INTERNAL == to
|
||||
? context.openFileOutput( name, Context.MODE_PRIVATE )
|
||||
FileOutputStream fos = DictLoc.INTERNAL == to
|
||||
? context.openFileOutput( name, Context.MODE_PRIVATE )
|
||||
: new FileOutputStream( getDictFile( context, name, to ) );
|
||||
|
||||
success = DBUtils.copyFileStream( fos, fis );
|
||||
|
@ -376,7 +376,7 @@ public class DictUtils {
|
|||
DbgUtils.loge( ioe );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return bytes;
|
||||
} // openDict
|
||||
|
||||
|
@ -447,7 +447,7 @@ public class DictUtils {
|
|||
}
|
||||
|
||||
public static boolean saveDict( Context context, InputStream in,
|
||||
String name, DictLoc loc,
|
||||
String name, DictLoc loc,
|
||||
DownProgListener dpl )
|
||||
{
|
||||
boolean success = false;
|
||||
|
@ -524,13 +524,13 @@ public class DictUtils {
|
|||
DbgUtils.logf( "uri: %s", uri.toString() );
|
||||
intent.putExtra( Intent.EXTRA_STREAM, uri );
|
||||
|
||||
intent.putExtra( Intent.EXTRA_SUBJECT,
|
||||
intent.putExtra( Intent.EXTRA_SUBJECT,
|
||||
context.getString( R.string.share_subject ) );
|
||||
intent.putExtra( Intent.EXTRA_TEXT,
|
||||
intent.putExtra( Intent.EXTRA_TEXT,
|
||||
Utils.format( context, R.string.share_bodyf, name ) );
|
||||
|
||||
String title = context.getString( R.string.share_chooser );
|
||||
context.startActivity( Intent.createChooser( intent, title ) );
|
||||
context.startActivity( Intent.createChooser( intent, title ) );
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -538,7 +538,7 @@ public class DictUtils {
|
|||
{
|
||||
return file.endsWith( XWConstants.GAME_EXTN );
|
||||
}
|
||||
|
||||
|
||||
private static boolean isDict( Context context, String file, File dir )
|
||||
{
|
||||
boolean ok = file.endsWith( XWConstants.DICT_EXTN );
|
||||
|
@ -559,7 +559,7 @@ public class DictUtils {
|
|||
return str;
|
||||
}
|
||||
|
||||
public static String addDictExtn( String str )
|
||||
public static String addDictExtn( String str )
|
||||
{
|
||||
if ( ! str.endsWith( XWConstants.DICT_EXTN ) ) {
|
||||
str += XWConstants.DICT_EXTN;
|
||||
|
@ -577,7 +577,7 @@ public class DictUtils {
|
|||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean haveWriteableSD()
|
||||
{
|
||||
String state = Environment.getExternalStorageState();
|
||||
|
|
|
@ -39,16 +39,9 @@ public class DictsActivity extends XWActivity {
|
|||
private DictsDelegate m_dlgt;
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
m_dlgt = new DictsDelegate( this, savedInstanceState );
|
||||
super.onCreate( savedInstanceState, m_dlgt );
|
||||
} // onCreate
|
||||
|
||||
public static void start( Context context )
|
||||
{
|
||||
Intent intent = new Intent( context, DictsActivity.class );
|
||||
context.startActivity( intent );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ import org.eehouse.android.xw4.DwnldDelegate.OnGotLcDictListener;
|
|||
|
||||
public class DictsDelegate extends ListDelegateBase
|
||||
implements View.OnClickListener, AdapterView.OnItemLongClickListener,
|
||||
SelectableItem, MountEventReceiver.SDCardNotifiee,
|
||||
SelectableItem, MountEventReceiver.SDCardNotifiee,
|
||||
DlgDelegate.DlgClickNotify, GroupStateListener,
|
||||
DownloadFinishedListener, XWListItem.ExpandedListener {
|
||||
|
||||
|
@ -109,25 +109,25 @@ public class DictsDelegate extends ListDelegateBase
|
|||
private String m_noteNone;
|
||||
|
||||
private static interface SafePopup {
|
||||
public void doPopup( Delegator dlgtor, View button,
|
||||
public void doPopup( Delegator dlgtor, View button,
|
||||
String curDict, int lang );
|
||||
}
|
||||
private static SafePopup s_safePopup = null;
|
||||
|
||||
private static class SafePopupImpl implements SafePopup {
|
||||
public void doPopup( final Delegator dlgtor, View button,
|
||||
public void doPopup( final Delegator dlgtor, View button,
|
||||
String curDict, int lang ) {
|
||||
|
||||
final HashMap<MenuItem, DictAndLoc> itemData
|
||||
= new HashMap<MenuItem, DictAndLoc>();
|
||||
|
||||
MenuItem.OnMenuItemClickListener listener =
|
||||
MenuItem.OnMenuItemClickListener listener =
|
||||
new MenuItem.OnMenuItemClickListener() {
|
||||
public boolean onMenuItemClick( MenuItem item )
|
||||
{
|
||||
DictAndLoc dal = itemData.get( item );
|
||||
|
||||
DictBrowseDelegate.launch( dlgtor, dal.name,
|
||||
DictBrowseDelegate.launch( dlgtor, dal.name,
|
||||
dal.loc );
|
||||
return true;
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
// Add at top but save until have dal info
|
||||
MenuItem curItem =
|
||||
menu.add( LocUtils.getString( context,
|
||||
R.string.cur_menu_marker_fmt,
|
||||
R.string.cur_menu_marker_fmt,
|
||||
curDict ) );
|
||||
|
||||
DictAndLoc[] dals = DictLangCache.getDALsHaveLang( context, lang );
|
||||
|
@ -161,7 +161,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
public int m_nWords;
|
||||
public long m_nBytes;
|
||||
public String m_note;
|
||||
public DictInfo( String name, String lang, int nWords,
|
||||
public DictInfo( String name, String lang, int nWords,
|
||||
long nBytes, String note )
|
||||
{
|
||||
m_name = name;
|
||||
|
@ -178,7 +178,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
private static class LangInfo {
|
||||
int m_numDicts;
|
||||
int m_posn;
|
||||
public LangInfo( int posn, int numDicts )
|
||||
public LangInfo( int posn, int numDicts )
|
||||
{
|
||||
m_posn = posn;
|
||||
m_numDicts = numDicts;
|
||||
|
@ -191,7 +191,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
private class DictListAdapter extends XWExpListAdapter {
|
||||
private Context m_context;
|
||||
|
||||
public DictListAdapter( Context context )
|
||||
public DictListAdapter( Context context )
|
||||
{
|
||||
super( new Class[] { LangInfo.class,
|
||||
DictAndLoc.class,
|
||||
|
@ -207,7 +207,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
int nLangs = m_langs.length;
|
||||
for ( int ii = 0; ii < nLangs; ++ii ) {
|
||||
String langName = m_langs[ii];
|
||||
if ( null != m_filterLang &&
|
||||
if ( null != m_filterLang &&
|
||||
! m_filterLang.equals(langName) ) {
|
||||
continue;
|
||||
}
|
||||
|
@ -235,12 +235,12 @@ public class DictsDelegate extends ListDelegateBase
|
|||
langName );
|
||||
boolean expanded = ! m_closedLangs.contains( langName );
|
||||
String locLangName = xlateLang( langName );
|
||||
String name = getQuantityString( R.plurals.lang_name_fmt,
|
||||
String name = getQuantityString( R.plurals.lang_name_fmt,
|
||||
info.m_numDicts,
|
||||
locLangName, info.m_numDicts );
|
||||
name = Utils.capitalize( name );
|
||||
result = ListGroup.make( m_context, convertView,
|
||||
DictsDelegate.this, groupPos, name,
|
||||
result = ListGroup.make( m_context, convertView,
|
||||
DictsDelegate.this, groupPos, name,
|
||||
expanded );
|
||||
} else {
|
||||
XWListItem item;
|
||||
|
@ -286,7 +286,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
} else {
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
|
||||
protected DictsDelegate( Delegator delegator, Bundle savedInstanceState )
|
||||
{
|
||||
super( delegator, savedInstanceState, R.layout.dict_browse,
|
||||
super( delegator, savedInstanceState, R.layout.dict_browse,
|
||||
R.menu.dicts_menu );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
@ -374,27 +374,28 @@ public class DictsDelegate extends ListDelegateBase
|
|||
public void onClick( DialogInterface dlgi, int item ) {
|
||||
moveTo[0] = item;
|
||||
AlertDialog dlg = (AlertDialog)dlgi;
|
||||
Button btn =
|
||||
dlg.getButton( AlertDialog.BUTTON_POSITIVE );
|
||||
Button btn =
|
||||
dlg.getButton( AlertDialog.BUTTON_POSITIVE );
|
||||
btn.setEnabled( true );
|
||||
}
|
||||
};
|
||||
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
DictLoc toLoc = itemToRealLoc( moveTo[0] );
|
||||
DictsDelegate self = curThis();
|
||||
DictLoc toLoc = self.itemToRealLoc( moveTo[0] );
|
||||
for ( XWListItem selItem : selItems ) {
|
||||
DictLoc fromLoc = (DictLoc)selItem.getCached();
|
||||
String name = selItem.getText();
|
||||
if ( fromLoc == toLoc ) {
|
||||
DbgUtils.logf( "not moving %s: same loc", name );
|
||||
} else if ( DictUtils.moveDict( m_activity,
|
||||
} else if ( DictUtils.moveDict( self.m_activity,
|
||||
name, fromLoc,
|
||||
toLoc ) ) {
|
||||
selItem.setComment( m_locNames[toLoc.ordinal()] );
|
||||
selItem.setComment( self.m_locNames[toLoc.ordinal()] );
|
||||
selItem.setCached( toLoc );
|
||||
selItem.invalidate();
|
||||
DBUtils.dictsMoveInfo( m_activity, name,
|
||||
DBUtils.dictsMoveInfo( self.m_activity, name,
|
||||
fromLoc, toLoc );
|
||||
} else {
|
||||
DbgUtils.logf( "moveDict(%s) failed", name );
|
||||
|
@ -416,15 +417,16 @@ public class DictsDelegate extends ListDelegateBase
|
|||
final XWListItem row = m_selDicts.values().iterator().next();
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
DictsDelegate self = curThis();
|
||||
if ( DialogInterface.BUTTON_NEGATIVE == item
|
||||
|| DialogInterface.BUTTON_POSITIVE == item ) {
|
||||
setDefault( row, R.string.key_default_dict,
|
||||
R.string.key_default_robodict );
|
||||
self.setDefault( row, R.string.key_default_dict,
|
||||
R.string.key_default_robodict );
|
||||
}
|
||||
if ( DialogInterface.BUTTON_NEGATIVE == item
|
||||
if ( DialogInterface.BUTTON_NEGATIVE == item
|
||||
|| DialogInterface.BUTTON_NEUTRAL == item ) {
|
||||
setDefault( row, R.string.key_default_robodict,
|
||||
R.string.key_default_dict );
|
||||
self.setDefault( row, R.string.key_default_robodict,
|
||||
R.string.key_default_dict );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -444,22 +446,22 @@ public class DictsDelegate extends ListDelegateBase
|
|||
case DICT_OR_DECLINE:
|
||||
lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
Intent intent = getIntent();
|
||||
DictsDelegate self = curThis();
|
||||
Intent intent = self.getIntent();
|
||||
int lang = intent.getIntExtra( MultiService.LANG, -1 );
|
||||
String name = intent.getStringExtra( MultiService.DICT );
|
||||
m_launchedForMissing = true;
|
||||
self.m_launchedForMissing = true;
|
||||
DwnldDelegate
|
||||
.downloadDictInBack( m_activity, lang,
|
||||
name, DictsDelegate.this );
|
||||
.downloadDictInBack( self.m_activity, lang, name, self );
|
||||
}
|
||||
};
|
||||
lstnr2 = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
finish();
|
||||
curThis().finish();
|
||||
}
|
||||
};
|
||||
|
||||
dialog = MultiService.missingDictDialog( m_activity, getIntent(),
|
||||
dialog = MultiService.missingDictDialog( m_activity, getIntent(),
|
||||
lstnr, lstnr2 );
|
||||
break;
|
||||
|
||||
|
@ -488,7 +490,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
protected void init( Bundle savedInstanceState )
|
||||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
m_onServerStr = getString( R.string.dict_on_server );
|
||||
m_closedLangs = new HashSet<String>();
|
||||
|
@ -504,7 +506,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
|
||||
m_listView = getListView();
|
||||
m_listView.setOnItemLongClickListener( this );
|
||||
|
||||
|
||||
m_checkbox = (CheckBox)findViewById( R.id.show_remote );
|
||||
m_checkbox.setOnClickListener( this );
|
||||
|
||||
|
@ -515,7 +517,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
if ( MultiService.isMissingDictIntent( intent ) ) {
|
||||
showDialog( DlgID.DICT_OR_DECLINE );
|
||||
} else {
|
||||
boolean showRemote = intent.getBooleanExtra( DICT_SHOWREMOTE,
|
||||
boolean showRemote = intent.getBooleanExtra( DICT_SHOWREMOTE,
|
||||
false );
|
||||
if ( showRemote ) {
|
||||
m_quickFetchMode = true;
|
||||
|
@ -555,23 +557,24 @@ public class DictsDelegate extends ListDelegateBase
|
|||
setTitleBar();
|
||||
}
|
||||
|
||||
protected void onStop()
|
||||
protected void onStop()
|
||||
{
|
||||
MountEventReceiver.unregister( this );
|
||||
}
|
||||
|
||||
public void onClick( View view )
|
||||
public void onClick( View view )
|
||||
{
|
||||
if ( view == m_checkbox ) {
|
||||
switchShowingRemote( m_checkbox.isChecked() );
|
||||
} else {
|
||||
XWListItem item = (XWListItem)view;
|
||||
DictBrowseDelegate.launch( getDelegator(), item.getText(),
|
||||
DictBrowseDelegate.launch( getDelegator(), item.getText(),
|
||||
(DictLoc)item.getCached() );
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean onBackPressed()
|
||||
@Override
|
||||
protected boolean handleBackPressed()
|
||||
{
|
||||
boolean handled = 0 < m_selDicts.size();
|
||||
if ( handled ) {
|
||||
|
@ -590,22 +593,22 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu( Menu menu )
|
||||
public boolean onPrepareOptionsMenu( Menu menu )
|
||||
{
|
||||
// int nSel = m_selDicts.size();
|
||||
int[] nSels = countSelDicts();
|
||||
Utils.setItemVisible( menu, R.id.dicts_select,
|
||||
Utils.setItemVisible( menu, R.id.dicts_select,
|
||||
1 == nSels[SEL_LOCAL] && 0 == nSels[SEL_REMOTE] );
|
||||
|
||||
// NO -- test if any downloadable selected
|
||||
Utils.setItemVisible( menu, R.id.dicts_download,
|
||||
Utils.setItemVisible( menu, R.id.dicts_download,
|
||||
0 == nSels[SEL_LOCAL] && 0 < nSels[SEL_REMOTE] );
|
||||
|
||||
Utils.setItemVisible( menu, R.id.dicts_deselect_all,
|
||||
Utils.setItemVisible( menu, R.id.dicts_deselect_all,
|
||||
0 < nSels[SEL_LOCAL] || 0 < nSels[SEL_REMOTE] );
|
||||
|
||||
boolean allVolatile = 0 == nSels[SEL_REMOTE] && selItemsVolatile();
|
||||
Utils.setItemVisible( menu, R.id.dicts_move,
|
||||
Utils.setItemVisible( menu, R.id.dicts_move,
|
||||
allVolatile && DictUtils.haveWriteableSD() );
|
||||
Utils.setItemVisible( menu, R.id.dicts_delete, allVolatile );
|
||||
|
||||
|
@ -634,14 +637,14 @@ public class DictsDelegate extends ListDelegateBase
|
|||
Uri[] uris = new Uri[countNeedDownload()];
|
||||
String[] names = new String[uris.length];
|
||||
int count = 0;
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
iter.hasNext(); ) {
|
||||
XWListItem litm = iter.next();
|
||||
Object cached = litm.getCached();
|
||||
if ( cached instanceof DictInfo ) {
|
||||
DictInfo info = (DictInfo)cached;
|
||||
String name = litm.getText();
|
||||
Uri uri = Utils.makeDictUri( m_activity, info.m_lang,
|
||||
Uri uri = Utils.makeDictUri( m_activity, info.m_lang,
|
||||
name );
|
||||
uris[count] = uri;
|
||||
names[count] = name;
|
||||
|
@ -675,7 +678,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
private int countNeedDownload()
|
||||
{
|
||||
int result = 0;
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
iter.hasNext(); ) {
|
||||
XWListItem litm = iter.next();
|
||||
Object obj = litm.getCached();
|
||||
|
@ -690,9 +693,9 @@ public class DictsDelegate extends ListDelegateBase
|
|||
{
|
||||
int loci = intent.getIntExtra( UpdateCheckReceiver.NEW_DICT_LOC, 0 );
|
||||
if ( 0 < loci ) {
|
||||
String name =
|
||||
String name =
|
||||
intent.getStringExtra( UpdateCheckReceiver.NEW_DICT_NAME );
|
||||
String url =
|
||||
String url =
|
||||
intent.getStringExtra( UpdateCheckReceiver.NEW_DICT_URL );
|
||||
Uri uri = Uri.parse( url );
|
||||
DwnldDelegate.downloadDictInBack( m_activity, uri, name, null );
|
||||
|
@ -744,11 +747,11 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
saveClosed();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// OnItemLongClickListener interface
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public boolean onItemLongClick( AdapterView<?> parent, View view,
|
||||
public boolean onItemLongClick( AdapterView<?> parent, View view,
|
||||
int position, long id ) {
|
||||
boolean success = view instanceof SelectableItem.LongClickHandler;
|
||||
if ( success ) {
|
||||
|
@ -757,10 +760,10 @@ public class DictsDelegate extends ListDelegateBase
|
|||
return success;
|
||||
}
|
||||
|
||||
private boolean selItemsVolatile()
|
||||
private boolean selItemsVolatile()
|
||||
{
|
||||
boolean result = 0 < m_selDicts.size();
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
result && iter.hasNext(); ) {
|
||||
Object obj = iter.next().getCached();
|
||||
if ( obj instanceof DictLoc ) {
|
||||
|
@ -778,7 +781,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
private void deleteSelected()
|
||||
{
|
||||
XWListItem[] items = getSelItems();
|
||||
String msg = getQuantityString( R.plurals.confirm_delete_dict_fmt,
|
||||
String msg = getQuantityString( R.plurals.confirm_delete_dict_fmt,
|
||||
items.length, getJoinedNames( items ) );
|
||||
|
||||
// Confirm. And for each dict, warn if (after ALL are deleted) any
|
||||
|
@ -795,7 +798,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
public String dictsStr()
|
||||
{
|
||||
if ( null == m_asArray ) {
|
||||
String[] arr = delDicts.toArray(new String[delDicts.size()]);
|
||||
String[] arr = delDicts.toArray(new String[delDicts.size()]);
|
||||
m_asArray = TextUtils.join( ", ", arr );
|
||||
}
|
||||
return m_asArray;
|
||||
|
@ -961,7 +964,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
{
|
||||
XWListItem[] items = new XWListItem[m_selDicts.size()];
|
||||
int indx = 0;
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
iter.hasNext(); ) {
|
||||
items[indx++] = iter.next();
|
||||
}
|
||||
|
@ -973,7 +976,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
{
|
||||
int[] results = new int[2];
|
||||
Assert.assertTrue( 0 == results[0] && 0 == results[1] );
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
for ( Iterator<XWListItem> iter = m_selDicts.values().iterator();
|
||||
iter.hasNext(); ) {
|
||||
Object obj = iter.next().getCached();
|
||||
if ( obj instanceof DictLoc ) {
|
||||
|
@ -999,7 +1002,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
private String[] makeDictDirItems()
|
||||
private String[] makeDictDirItems()
|
||||
{
|
||||
boolean showDownload = DictUtils.haveDownloadDir( m_activity );
|
||||
int nItems = showDownload ? 3 : 2;
|
||||
|
@ -1032,7 +1035,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
// return mkDownloadIntent( context, dict_url );
|
||||
}
|
||||
|
||||
public static void downloadForResult( Activity activity, RequestCode requestCode,
|
||||
public static void downloadForResult( Activity activity, RequestCode requestCode,
|
||||
int lang, String name )
|
||||
{
|
||||
Intent intent = new Intent( activity, DictsActivity.class );
|
||||
|
@ -1084,6 +1087,12 @@ public class DictsDelegate extends ListDelegateBase
|
|||
return canHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DictsDelegate curThis()
|
||||
{
|
||||
return (DictsDelegate)super.curThis();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// XWListItem.ExpandedListener interface
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -1092,25 +1101,25 @@ public class DictsDelegate extends ListDelegateBase
|
|||
final DictInfo info = (DictInfo)me.getCached();
|
||||
if ( expanded ) {
|
||||
m_expandedItems.add( info ); // may already be there
|
||||
LinearLayout view =
|
||||
LinearLayout view =
|
||||
(LinearLayout)inflate( R.layout.remote_dict_details );
|
||||
Button button = (Button)view.findViewById( R.id.download_button );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
public void onClick( View view ) {
|
||||
DwnldDelegate.
|
||||
downloadDictInBack( m_activity, info.m_lang,
|
||||
info.m_name,
|
||||
downloadDictInBack( m_activity, info.m_lang,
|
||||
info.m_name,
|
||||
DictsDelegate.this );
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
long kBytes = (info.m_nBytes + 999) / 1000;
|
||||
String note = null == info.m_note ? m_noteNone : info.m_note;
|
||||
String msg = getString( R.string.dict_info_fmt, info.m_nWords,
|
||||
String msg = getString( R.string.dict_info_fmt, info.m_nWords,
|
||||
kBytes, note );
|
||||
TextView summary = (TextView)view.findViewById( R.id.details );
|
||||
summary.setText( msg );
|
||||
|
||||
|
||||
me.addExpandedView( view );
|
||||
} else {
|
||||
me.removeExpandedView();
|
||||
|
@ -1121,7 +1130,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
// DwnldActivity.DownloadFinishedListener interface
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public void downloadFinished( String lang, final String name,
|
||||
public void downloadFinished( String lang, final String name,
|
||||
final boolean success )
|
||||
{
|
||||
if ( success && m_showRemote ) {
|
||||
|
@ -1160,7 +1169,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
DbgUtils.logf( "itemClicked not implemented" );
|
||||
}
|
||||
|
||||
public void itemToggled( SelectableItem.LongClickHandler toggled,
|
||||
public void itemToggled( SelectableItem.LongClickHandler toggled,
|
||||
boolean selected )
|
||||
{
|
||||
XWListItem dictView = (XWListItem)toggled;
|
||||
|
@ -1187,14 +1196,14 @@ public class DictsDelegate extends ListDelegateBase
|
|||
private String m_langName;
|
||||
private OnGotLcDictListener m_lstnr;
|
||||
|
||||
public GetDefaultDictTask( Context context, String lc,
|
||||
public GetDefaultDictTask( Context context, String lc,
|
||||
OnGotLcDictListener lnr ) {
|
||||
m_context = context;
|
||||
m_lc = lc;
|
||||
m_lstnr = lnr;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public String doInBackground( Void... unused )
|
||||
{
|
||||
// FIXME: this should pass up the language code to retrieve and
|
||||
|
@ -1230,7 +1239,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
break;
|
||||
} else {
|
||||
int nWords = dict.getInt( "nWords" );
|
||||
if ( null == theOne
|
||||
if ( null == theOne
|
||||
|| nWords > theOneNWords ) {
|
||||
theOne = dict;
|
||||
theOneNWords = nWords;
|
||||
|
@ -1244,8 +1253,8 @@ public class DictsDelegate extends ListDelegateBase
|
|||
// the flag so we don't try again, even though
|
||||
// we've failed.
|
||||
if ( null == theOne ) {
|
||||
XWPrefs.setPrefsBoolean( m_context,
|
||||
R.string.key_got_langdict,
|
||||
XWPrefs.setPrefsBoolean( m_context,
|
||||
R.string.key_got_langdict,
|
||||
true );
|
||||
}
|
||||
|
||||
|
@ -1269,7 +1278,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
private class FetchListTask extends AsyncTask<Void, Void, Boolean>
|
||||
private class FetchListTask extends AsyncTask<Void, Void, Boolean>
|
||||
implements OnCancelListener {
|
||||
private Context m_context;
|
||||
|
||||
|
@ -1279,7 +1288,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
startProgress( R.string.progress_title, R.string.remote_empty, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public Boolean doInBackground( Void... unused )
|
||||
{
|
||||
boolean success = false;
|
||||
|
@ -1299,21 +1308,21 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
return new Boolean( success );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
protected void onCancelled()
|
||||
{
|
||||
m_remoteInfo = null;
|
||||
m_showRemote = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected void onCancelled( Boolean success )
|
||||
{
|
||||
onCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected void onPostExecute( Boolean success )
|
||||
{
|
||||
if ( success ) {
|
||||
|
@ -1325,7 +1334,7 @@ public class DictsDelegate extends ListDelegateBase
|
|||
String joined = TextUtils.join( ", ", names );
|
||||
showConfirmThen( getString( R.string.update_dicts_fmt,
|
||||
joined ),
|
||||
R.string.button_download,
|
||||
R.string.button_download,
|
||||
Action.UPDATE_DICTS_ACTION );
|
||||
}
|
||||
} else {
|
||||
|
@ -1358,8 +1367,8 @@ public class DictsDelegate extends ListDelegateBase
|
|||
for ( int ii = 0; !isCancelled() && ii < nLangs; ++ii ) {
|
||||
JSONObject langObj = langs.getJSONObject( ii );
|
||||
String langName = langObj.getString( "lang" );
|
||||
|
||||
if ( null != m_filterLang &&
|
||||
|
||||
if ( null != m_filterLang &&
|
||||
! m_filterLang.equals( langName ) ) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1370,9 +1379,9 @@ public class DictsDelegate extends ListDelegateBase
|
|||
|
||||
JSONArray dicts = langObj.getJSONArray( "dicts" );
|
||||
int nDicts = dicts.length();
|
||||
ArrayList<DictInfo> dictNames =
|
||||
ArrayList<DictInfo> dictNames =
|
||||
new ArrayList<DictInfo>();
|
||||
for ( int jj = 0; !isCancelled() && jj < nDicts;
|
||||
for ( int jj = 0; !isCancelled() && jj < nDicts;
|
||||
++jj ) {
|
||||
JSONObject dict = dicts.getJSONObject( jj );
|
||||
String name = dict.getString( "xwd" );
|
||||
|
@ -1388,18 +1397,18 @@ public class DictsDelegate extends ListDelegateBase
|
|||
|
||||
if ( !m_quickFetchMode ) {
|
||||
// Check if we have it and it needs an update
|
||||
if ( DictLangCache.haveDict( m_activity,
|
||||
if ( DictLangCache.haveDict( m_activity,
|
||||
langName, name )){
|
||||
boolean matches = true;
|
||||
String curSum = DictLangCache
|
||||
.getDictMD5Sum( m_activity, name );
|
||||
if ( null != curSum ) {
|
||||
JSONArray sums =
|
||||
JSONArray sums =
|
||||
dict.getJSONArray("md5sums");
|
||||
if ( null != sums ) {
|
||||
matches = false;
|
||||
for ( int kk = 0;
|
||||
!matches && kk < sums.length();
|
||||
for ( int kk = 0;
|
||||
!matches && kk < sums.length();
|
||||
++kk ) {
|
||||
String sum = sums.getString( kk );
|
||||
matches = sum.equals( curSum );
|
||||
|
@ -1407,8 +1416,8 @@ public class DictsDelegate extends ListDelegateBase
|
|||
}
|
||||
}
|
||||
if ( !matches ) {
|
||||
Uri uri =
|
||||
Utils.makeDictUri( m_activity,
|
||||
Uri uri =
|
||||
Utils.makeDictUri( m_activity,
|
||||
langName, name );
|
||||
m_needUpdates.put( name, uri );
|
||||
}
|
||||
|
@ -1445,4 +1454,15 @@ public class DictsDelegate extends ListDelegateBase
|
|||
cancel( true );
|
||||
}
|
||||
} // class FetchListTask
|
||||
|
||||
public static void start( Delegator delegator )
|
||||
{
|
||||
if ( delegator.inDPMode() ) {
|
||||
delegator.addFragment( new DictsFrag( delegator ), null );
|
||||
} else {
|
||||
Activity activity = delegator.getActivity();
|
||||
Intent intent = new Intent( activity, DictsActivity.class );
|
||||
activity.startActivity( intent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2016 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.os.Bundle;
|
||||
|
||||
public class DictsFrag extends XWFragment {
|
||||
|
||||
public DictsFrag( Delegator parent ) { super( parent ); }
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle sis )
|
||||
{
|
||||
super.onCreate( new DictsDelegate( this, sis ), sis, true );
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ import org.eehouse.android.xw4.jni.GameSummary;
|
|||
public class DispatchNotify extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
super.onCreate( savedInstanceState );
|
||||
|
||||
|
|
|
@ -122,11 +122,12 @@ public class DlgDelegate {
|
|||
ENABLE_SMS_DO,
|
||||
ENABLE_BT_DO,
|
||||
ENABLE_RELAY_DO,
|
||||
ENABLE_RELAY_DO_OR,
|
||||
DISABLE_RELAY_DO,
|
||||
}
|
||||
|
||||
public static class ActionPair {
|
||||
public ActionPair( Action act, int str ) {
|
||||
public ActionPair( Action act, int str ) {
|
||||
buttonStr = str; action = act;
|
||||
}
|
||||
public int buttonStr;
|
||||
|
@ -156,8 +157,8 @@ public class DlgDelegate {
|
|||
void showNotAgainDlgThen( int msgID, int prefsKey, Action action );
|
||||
}
|
||||
|
||||
private static Map<Integer, WeakReference<DelegateBase>> s_pendings
|
||||
= new HashMap<Integer, WeakReference<DelegateBase>>();
|
||||
private static Map<DlgID, WeakReference<DelegateBase>> s_pendings
|
||||
= new HashMap<DlgID, WeakReference<DelegateBase>>();
|
||||
private Activity m_activity;
|
||||
private DelegateBase m_dlgt;
|
||||
private DlgClickNotify m_clickCallback;
|
||||
|
@ -167,8 +168,8 @@ public class DlgDelegate {
|
|||
|
||||
private HashMap<DlgID, DlgState> m_dlgStates;
|
||||
|
||||
public DlgDelegate( Activity activity, DelegateBase dlgt,
|
||||
DlgClickNotify callback, Bundle bundle )
|
||||
public DlgDelegate( Activity activity, DelegateBase dlgt,
|
||||
DlgClickNotify callback, Bundle bundle )
|
||||
{
|
||||
m_activity = activity;
|
||||
m_dlgt = dlgt;
|
||||
|
@ -187,7 +188,7 @@ public class DlgDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
public void onSaveInstanceState( Bundle outState )
|
||||
public void onSaveInstanceState( Bundle outState )
|
||||
{
|
||||
int[] ids = new int[m_dlgStates.size()];
|
||||
if ( 0 < ids.length ) {
|
||||
|
@ -206,15 +207,13 @@ public class DlgDelegate {
|
|||
|
||||
protected void showDialog( DlgID dlgID )
|
||||
{
|
||||
int id = dlgID.ordinal();
|
||||
if ( m_activity instanceof FragActivity ) {
|
||||
s_pendings.put( id, new WeakReference<DelegateBase>(m_dlgt) );
|
||||
}
|
||||
// DbgUtils.logf( "showDialog(%s)", dlgID.toString() );
|
||||
if ( !m_activity.isFinishing() ) {
|
||||
m_activity.showDialog( id );
|
||||
s_pendings.put( dlgID, new WeakReference<DelegateBase>(m_dlgt) );
|
||||
m_activity.showDialog( dlgID.ordinal() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Dialog createDialog( int id )
|
||||
{
|
||||
Dialog dialog = null;
|
||||
|
@ -299,8 +298,8 @@ public class DlgDelegate {
|
|||
showDialog( DlgID.DIALOG_ENABLESMS );
|
||||
}
|
||||
|
||||
public void showNotAgainDlgThen( String msg, int prefsKey,
|
||||
final Action action, ActionPair more,
|
||||
public void showNotAgainDlgThen( String msg, int prefsKey,
|
||||
final Action action, ActionPair more,
|
||||
final Object[] params )
|
||||
{
|
||||
if ( XWPrefs.getPrefsBoolean( m_activity, prefsKey, false ) ) {
|
||||
|
@ -317,18 +316,18 @@ public class DlgDelegate {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
DlgState state =
|
||||
new DlgState( DlgID.DIALOG_NOTAGAIN, msg, prefsKey, action, more,
|
||||
DlgState state =
|
||||
new DlgState( DlgID.DIALOG_NOTAGAIN, msg, prefsKey, action, more,
|
||||
params );
|
||||
addState( state );
|
||||
showDialog( DlgID.DIALOG_NOTAGAIN );
|
||||
}
|
||||
}
|
||||
|
||||
public void showNotAgainDlgThen( int msgID, int prefsKey, Action action,
|
||||
public void showNotAgainDlgThen( int msgID, int prefsKey, Action action,
|
||||
ActionPair more, Object[] params )
|
||||
{
|
||||
showNotAgainDlgThen( getString( msgID ), prefsKey, action, more,
|
||||
showNotAgainDlgThen( getString( msgID ), prefsKey, action, more,
|
||||
params );
|
||||
}
|
||||
|
||||
|
@ -337,7 +336,7 @@ public class DlgDelegate {
|
|||
showNotAgainDlgThen( msgID, prefsKey, action, null, null );
|
||||
}
|
||||
|
||||
public void showNotAgainDlgThen( int msgID, int prefsKey, Action action,
|
||||
public void showNotAgainDlgThen( int msgID, int prefsKey, Action action,
|
||||
ActionPair more )
|
||||
{
|
||||
showNotAgainDlgThen( msgID, prefsKey, action, more, null );
|
||||
|
@ -392,21 +391,21 @@ public class DlgDelegate {
|
|||
public void showConfirmThen( int msg, int posButton, Action action,
|
||||
Object[] params )
|
||||
{
|
||||
showConfirmThen( null, getString(msg), posButton, android.R.string.cancel,
|
||||
showConfirmThen( null, getString(msg), posButton, android.R.string.cancel,
|
||||
action, params );
|
||||
}
|
||||
|
||||
public void showConfirmThen( Runnable onNA, String msg, int posButton, Action action,
|
||||
Object[] params )
|
||||
{
|
||||
showConfirmThen( onNA, msg, posButton, android.R.string.cancel, action,
|
||||
showConfirmThen( onNA, msg, posButton, android.R.string.cancel, action,
|
||||
params );
|
||||
}
|
||||
|
||||
public void showConfirmThen( Runnable onNA, String msg, int posButton,
|
||||
public void showConfirmThen( Runnable onNA, String msg, int posButton,
|
||||
int negButton, Action action, Object[] params )
|
||||
{
|
||||
DlgState state = new DlgState( DlgID.CONFIRM_THEN, onNA, msg, posButton,
|
||||
DlgState state = new DlgState( DlgID.CONFIRM_THEN, onNA, msg, posButton,
|
||||
negButton, action, 0, params );
|
||||
addState( state );
|
||||
showDialog( DlgID.CONFIRM_THEN );
|
||||
|
@ -428,7 +427,7 @@ public class DlgDelegate {
|
|||
DlgClickNotify.InviteMeans means
|
||||
= DlgClickNotify.InviteMeans.EMAIL;
|
||||
m_clickCallback.inviteChoiceMade( action, means, null );
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -463,7 +462,7 @@ public class DlgDelegate {
|
|||
{
|
||||
String title = getString( titleID );
|
||||
m_progress = ProgressDialog.show( m_activity, title, msg, true, true );
|
||||
|
||||
|
||||
if ( null != lstnr ) {
|
||||
m_progress.setCancelable( true );
|
||||
m_progress.setOnCancelListener( lstnr );
|
||||
|
@ -489,14 +488,14 @@ public class DlgDelegate {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void eventOccurred( MultiService.MultiEvent event,
|
||||
public void eventOccurred( MultiService.MultiEvent event,
|
||||
final Object ... args )
|
||||
{
|
||||
String msg = null;
|
||||
boolean asToast = true;
|
||||
switch( event ) {
|
||||
case MESSAGE_RESEND:
|
||||
msg = getString( R.string.bt_resend_fmt, (String)args[0],
|
||||
msg = getString( R.string.bt_resend_fmt, (String)args[0],
|
||||
(Long)args[1], (Integer)args[2] );
|
||||
break;
|
||||
case MESSAGE_FAILOUT:
|
||||
|
@ -532,7 +531,7 @@ public class DlgDelegate {
|
|||
final View view = LocUtils.inflate( m_activity, R.layout.about_dlg );
|
||||
TextView vers = (TextView)view.findViewById( R.id.version_string );
|
||||
|
||||
DateFormat df = DateFormat.getDateTimeInstance( DateFormat.FULL,
|
||||
DateFormat df = DateFormat.getDateTimeInstance( DateFormat.FULL,
|
||||
DateFormat.FULL );
|
||||
String dateString
|
||||
= df.format( new Date( BuildConstants.BUILD_STAMP * 1000 ) );
|
||||
|
@ -555,7 +554,7 @@ public class DlgDelegate {
|
|||
builder.setNegativeButton( R.string.changes_button,
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick( DialogInterface dlg,
|
||||
public void onClick( DialogInterface dlg,
|
||||
int which )
|
||||
{
|
||||
FirstRunDialog.show( m_activity );
|
||||
|
@ -602,7 +601,7 @@ public class DlgDelegate {
|
|||
public void onClick( DialogInterface dlg, int item ) {
|
||||
checkNotAgainCheck( state, naView );
|
||||
m_clickCallback.
|
||||
dlgButtonClicked( more.action,
|
||||
dlgButtonClicked( more.action,
|
||||
AlertDialog.BUTTON_POSITIVE,
|
||||
more.params );
|
||||
}
|
||||
|
@ -629,13 +628,13 @@ public class DlgDelegate {
|
|||
.setPositiveButton( state.m_posButton, lstnr )
|
||||
.setNegativeButton( state.m_negButton, lstnr );
|
||||
Dialog dialog = builder.create();
|
||||
|
||||
|
||||
return setCallbackDismissListener( dialog, state, dlgID );
|
||||
}
|
||||
|
||||
private Dialog createInviteChoicesDialog( final DlgState state, DlgID dlgID )
|
||||
{
|
||||
final ArrayList<DlgClickNotify.InviteMeans> means =
|
||||
final ArrayList<DlgClickNotify.InviteMeans> means =
|
||||
new ArrayList<DlgClickNotify.InviteMeans>();
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
DlgClickNotify.InviteMeans lastMeans = null;
|
||||
|
@ -643,7 +642,7 @@ public class DlgDelegate {
|
|||
&& state.m_params[0] instanceof SentInvitesInfo ) {
|
||||
lastMeans =((SentInvitesInfo)state.m_params[0]).getLastMeans();
|
||||
}
|
||||
|
||||
|
||||
if ( XWApp.SMS_INVITE_ENABLED && Utils.deviceSupportsSMS(m_activity) ) {
|
||||
items.add( getString( R.string.invite_choice_sms ) );
|
||||
means.add( DlgClickNotify.InviteMeans.SMS );
|
||||
|
@ -654,7 +653,7 @@ public class DlgDelegate {
|
|||
items.add( getString( R.string.invite_choice_bt ) );
|
||||
means.add( DlgClickNotify.InviteMeans.BLUETOOTH );
|
||||
}
|
||||
if ( XWPrefs.getNFCToSelfEnabled( m_activity )
|
||||
if ( XWPrefs.getNFCToSelfEnabled( m_activity )
|
||||
|| NFCUtils.nfcAvail( m_activity )[0] ) {
|
||||
items.add( getString( R.string.invite_choice_nfc ) );
|
||||
means.add( DlgClickNotify.InviteMeans.NFC );
|
||||
|
@ -681,7 +680,7 @@ public class DlgDelegate {
|
|||
sel[0] = view;
|
||||
switch ( means.get(view) ) {
|
||||
case CLIPBOARD:
|
||||
String msg =
|
||||
String msg =
|
||||
getString( R.string.not_again_clip_expl_fmt,
|
||||
getString(R.string.slmenu_copy_sel) );
|
||||
showNotAgainDlgThen( msg, R.string.key_na_clip_expl );
|
||||
|
@ -705,8 +704,8 @@ public class DlgDelegate {
|
|||
Assert.assertTrue( Action.SKIP_CALLBACK != state.m_action );
|
||||
int indx = sel[0];
|
||||
if ( 0 <= indx ) {
|
||||
m_clickCallback.inviteChoiceMade( state.m_action,
|
||||
means.get(indx),
|
||||
m_clickCallback.inviteChoiceMade( state.m_action,
|
||||
means.get(indx),
|
||||
state.m_params );
|
||||
}
|
||||
}
|
||||
|
@ -753,14 +752,14 @@ public class DlgDelegate {
|
|||
{
|
||||
final View layout = LocUtils.inflate( m_activity, R.layout.confirm_sms );
|
||||
|
||||
DialogInterface.OnClickListener lstnr =
|
||||
DialogInterface.OnClickListener lstnr =
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
Spinner reasons = (Spinner)
|
||||
layout.findViewById( R.id.confirm_sms_reasons );
|
||||
boolean enabled = 0 < reasons.getSelectedItemPosition();
|
||||
Assert.assertTrue( enabled );
|
||||
m_clickCallback.dlgButtonClicked( state.m_action,
|
||||
m_clickCallback.dlgButtonClicked( state.m_action,
|
||||
AlertDialog.BUTTON_POSITIVE,
|
||||
state.m_params );
|
||||
}
|
||||
|
@ -784,13 +783,13 @@ public class DlgDelegate {
|
|||
button.setEnabled( enabled );
|
||||
}
|
||||
|
||||
private void prepareEnableSMSDialog( final Dialog dialog )
|
||||
private void prepareEnableSMSDialog( final Dialog dialog )
|
||||
{
|
||||
final Spinner reasons = (Spinner)
|
||||
dialog.findViewById( R.id.confirm_sms_reasons );
|
||||
|
||||
OnItemSelectedListener onItemSel = new OnItemSelectedListener() {
|
||||
public void onItemSelected( AdapterView<?> parent, View view,
|
||||
OnItemSelectedListener onItemSel = new OnItemSelectedListener() {
|
||||
public void onItemSelected( AdapterView<?> parent, View view,
|
||||
int position, long id )
|
||||
{
|
||||
checkEnableButton( dialog, reasons );
|
||||
|
@ -811,8 +810,8 @@ public class DlgDelegate {
|
|||
checkNotAgainCheck( state, naView );
|
||||
|
||||
if ( Action.SKIP_CALLBACK != state.m_action ) {
|
||||
m_clickCallback.dlgButtonClicked( state.m_action,
|
||||
button,
|
||||
m_clickCallback.dlgButtonClicked( state.m_action,
|
||||
button,
|
||||
state.m_params );
|
||||
}
|
||||
}
|
||||
|
@ -824,7 +823,7 @@ public class DlgDelegate {
|
|||
{
|
||||
if ( null != naView && naView.getChecked() ) {
|
||||
if ( 0 != state.m_prefsKey ) {
|
||||
XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey,
|
||||
XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey,
|
||||
true );
|
||||
} else if ( null != state.m_onNAChecked ) {
|
||||
state.m_onNAChecked.run();
|
||||
|
@ -832,7 +831,7 @@ public class DlgDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
private Dialog setCallbackDismissListener( final Dialog dialog,
|
||||
private Dialog setCallbackDismissListener( final Dialog dialog,
|
||||
final DlgState state,
|
||||
DlgID dlgID )
|
||||
{
|
||||
|
@ -842,8 +841,8 @@ public class DlgDelegate {
|
|||
public void onDismiss( DialogInterface di ) {
|
||||
dropState( state );
|
||||
if ( Action.SKIP_CALLBACK != state.m_action ) {
|
||||
m_clickCallback.dlgButtonClicked( state.m_action,
|
||||
DISMISS_BUTTON,
|
||||
m_clickCallback.dlgButtonClicked( state.m_action,
|
||||
DISMISS_BUTTON,
|
||||
state.m_params );
|
||||
}
|
||||
m_activity.removeDialog( id );
|
||||
|
@ -867,7 +866,7 @@ public class DlgDelegate {
|
|||
Assert.assertNotNull( state );
|
||||
// Assert.assertTrue( state == m_dlgStates.get( state.m_id ) );
|
||||
m_dlgStates.remove( state.m_id );
|
||||
// DbgUtils.logf( "dropState: active dialogs now %d from %d ",
|
||||
// DbgUtils.logf( "dropState: active dialogs now %d from %d ",
|
||||
// m_dlgStates.size(), nDlgs );
|
||||
}
|
||||
|
||||
|
@ -876,7 +875,7 @@ public class DlgDelegate {
|
|||
// I'm getting serialization failures on devices pointing at
|
||||
// DlgState but the code below says the object's fine (as it
|
||||
// should be.) Just to have a record....
|
||||
//
|
||||
//
|
||||
// Bundle bundle = new Bundle();
|
||||
// DbgUtils.logf( "addState: testing serializable" );
|
||||
// bundle.putSerializable( "foo", state );
|
||||
|
@ -889,7 +888,8 @@ public class DlgDelegate {
|
|||
public static Dialog onCreateDialog( int id )
|
||||
{
|
||||
Dialog result = null;
|
||||
WeakReference<DelegateBase> ref = s_pendings.get( id );
|
||||
DlgID dlgID = DlgID.values()[id];
|
||||
WeakReference<DelegateBase> ref = s_pendings.get( dlgID );
|
||||
DelegateBase dlgt = ref.get();
|
||||
if ( null != dlgt ) {
|
||||
result = dlgt.onCreateDialog( id );
|
||||
|
@ -899,10 +899,11 @@ public class DlgDelegate {
|
|||
|
||||
public static void onPrepareDialog( int id, Dialog dialog )
|
||||
{
|
||||
WeakReference<DelegateBase> ref = s_pendings.get( id );
|
||||
DlgID dlgID = DlgID.values()[id];
|
||||
WeakReference<DelegateBase> ref = s_pendings.get( dlgID );
|
||||
DelegateBase dlgt = ref.get();
|
||||
if ( null != dlgt ) {
|
||||
dlgt.prepareDialog( DlgID.values()[id], dialog );
|
||||
dlgt.prepareDialog( dlgID, dialog );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class DlgState implements Parcelable {
|
|||
this( dlgID, msg, android.R.string.ok, action, prefsKey );
|
||||
}
|
||||
|
||||
public DlgState( DlgID dlgID, String msg, int prefsKey, Action action,
|
||||
public DlgState( DlgID dlgID, String msg, int prefsKey, Action action,
|
||||
ActionPair more, Object[] params )
|
||||
{
|
||||
this( dlgID, msg, android.R.string.ok, action, prefsKey );
|
||||
|
@ -55,20 +55,20 @@ public class DlgState implements Parcelable {
|
|||
m_pair = more;
|
||||
}
|
||||
|
||||
public DlgState( DlgID dlgID, String msg, int posButton,
|
||||
public DlgState( DlgID dlgID, String msg, int posButton,
|
||||
Action action, int prefsKey )
|
||||
{
|
||||
this( dlgID, msg, posButton, action, prefsKey, null );
|
||||
}
|
||||
|
||||
public DlgState( DlgID dlgID, String msg, int posButton,
|
||||
public DlgState( DlgID dlgID, String msg, int posButton,
|
||||
Action action, int prefsKey, Object[] params )
|
||||
{
|
||||
this( dlgID, null, msg, posButton, android.R.string.cancel,
|
||||
this( dlgID, null, msg, posButton, android.R.string.cancel,
|
||||
action, prefsKey, params );
|
||||
}
|
||||
|
||||
public DlgState( DlgID dlgID, Runnable onNA, String msg, int posButton, int negButton,
|
||||
|
||||
public DlgState( DlgID dlgID, Runnable onNA, String msg, int posButton, int negButton,
|
||||
Action action, int prefsKey, Object[] params )
|
||||
{
|
||||
m_id = dlgID;
|
||||
|
|
|
@ -27,7 +27,7 @@ import android.view.View;
|
|||
public class DrawSelDelegate {
|
||||
private View m_view;
|
||||
private Drawable m_origDrawable;
|
||||
private static ColorDrawable s_selDrawable =
|
||||
private static ColorDrawable s_selDrawable =
|
||||
new ColorDrawable( XWApp.SEL_COLOR );
|
||||
|
||||
protected DrawSelDelegate( View view )
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2009 - 2016 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.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
public class DualpaneDelegate extends DelegateBase {
|
||||
private Activity m_activity;
|
||||
|
||||
public DualpaneDelegate( Delegator delegator, Bundle sis )
|
||||
{
|
||||
super( delegator, sis, R.layout.dualcontainer );
|
||||
m_activity = delegator.getActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init( Bundle savedInstanceState )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
{
|
||||
return DlgDelegate.onCreateDialog( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareDialog( DlgID dlgId, Dialog dialog )
|
||||
{
|
||||
DlgDelegate.onPrepareDialog( dlgId.ordinal(), dialog );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleNewIntent( Intent intent )
|
||||
{
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
boolean handled = main.dispatchNewIntent( intent );
|
||||
DbgUtils.logf( "DualpaneDelegate.handleNewIntent() => %b", handled );
|
||||
return handled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean handleBackPressed()
|
||||
{
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
boolean handled = main.dispatchBackPressed();
|
||||
DbgUtils.logf( "DualpaneDelegate.handleBackPressed() => %b", handled );
|
||||
return handled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult( RequestCode requestCode, int resultCode, Intent data )
|
||||
{
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
main.dispatchOnActivityResult( requestCode, resultCode, data );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreateContextMenu( ContextMenu menu, View view,
|
||||
ContextMenuInfo menuInfo )
|
||||
{
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
main.dispatchOnCreateContextMenu( menu, view, menuInfo );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onContextItemSelected( MenuItem item )
|
||||
{
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
return main.dispatchOnContextItemSelected( item );
|
||||
}
|
||||
|
||||
}
|
|
@ -27,14 +27,14 @@ import android.view.Window;
|
|||
public class DwnldActivity extends XWActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
requestWindowFeature( Window.FEATURE_NO_TITLE );
|
||||
requestWindowFeature( Window.FEATURE_LEFT_ICON );
|
||||
getWindow().setFeatureDrawableResource( Window.FEATURE_LEFT_ICON,
|
||||
R.drawable.icon48x48 );
|
||||
|
||||
DwnldDelegate dlgt =
|
||||
|
||||
DwnldDelegate dlgt =
|
||||
new DwnldDelegate( this, savedInstanceState );
|
||||
|
||||
super.onCreate( savedInstanceState, dlgt );
|
||||
|
|
|
@ -89,7 +89,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
private static Map<Uri,ListenerData> s_listeners =
|
||||
new HashMap<Uri,ListenerData>();
|
||||
|
||||
private class DownloadFilesTask extends AsyncTask<Void, Void, Void>
|
||||
private class DownloadFilesTask extends AsyncTask<Void, Void, Void>
|
||||
implements DictUtils.DownProgListener {
|
||||
private String m_savedDict = null;
|
||||
private Uri m_uri = null;
|
||||
|
@ -122,8 +122,8 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
m_appFile = null;
|
||||
|
||||
try {
|
||||
URI jUri = new URI( m_uri.getScheme(),
|
||||
m_uri.getSchemeSpecificPart(),
|
||||
URI jUri = new URI( m_uri.getScheme(),
|
||||
m_uri.getSchemeSpecificPart(),
|
||||
m_uri.getFragment() );
|
||||
URLConnection conn = jUri.toURL().openConnection();
|
||||
final int fileLen = conn.getContentLength();
|
||||
|
@ -150,7 +150,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected void onCancelled()
|
||||
{
|
||||
callListener( m_uri, false );
|
||||
|
@ -160,9 +160,9 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
protected void onPostExecute( Void unused )
|
||||
{
|
||||
if ( null != m_savedDict ) {
|
||||
DictUtils.DictLoc loc =
|
||||
DictUtils.DictLoc loc =
|
||||
XWPrefs.getDefaultLoc( m_activity );
|
||||
DictLangCache.inval( m_activity, m_savedDict,
|
||||
DictLangCache.inval( m_activity, m_savedDict,
|
||||
loc, true );
|
||||
callListener( m_uri, true );
|
||||
} else if ( null != m_appFile ) {
|
||||
|
@ -196,7 +196,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
});
|
||||
}
|
||||
|
||||
private File saveToDownloads( InputStream is, String name,
|
||||
private File saveToDownloads( InputStream is, String name,
|
||||
DictUtils.DownProgListener dpl )
|
||||
{
|
||||
boolean success = false;
|
||||
|
@ -271,7 +271,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
m_views.add( item );
|
||||
}
|
||||
}
|
||||
} else if ( (null != intent.getType()
|
||||
} else if ( (null != intent.getType()
|
||||
&& intent.getType().equals( "application/x-xwordsdict" ))
|
||||
|| uri.toString().endsWith( XWConstants.DICT_EXTN ) ) {
|
||||
item = (LinearLayout)inflate( R.layout.import_dict_item );
|
||||
|
@ -296,9 +296,9 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
for ( int ii = 0; ii < uris.length; ++ii ) {
|
||||
String showName = basename( uris[ii].getPath() );
|
||||
showName = DictUtils.removeDictExtn( showName );
|
||||
String msg =
|
||||
String msg =
|
||||
getString( R.string.downloading_dict_fmt, showName );
|
||||
|
||||
|
||||
dft = m_dfts.get( ii );
|
||||
dft.setLabel( msg );
|
||||
dft.execute();
|
||||
|
@ -307,15 +307,15 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
} // init
|
||||
|
||||
@Override
|
||||
protected boolean onBackPressed()
|
||||
{
|
||||
protected boolean handleBackPressed()
|
||||
{
|
||||
// cancel any tasks that remain
|
||||
for ( Iterator<DownloadFilesTask> iter = m_dfts.iterator();
|
||||
for ( Iterator<DownloadFilesTask> iter = m_dfts.iterator();
|
||||
iter.hasNext(); ) {
|
||||
DownloadFilesTask dft = iter.next();
|
||||
dft.cancel( true );
|
||||
}
|
||||
return super.onBackPressed();
|
||||
return super.handleBackPressed();
|
||||
}
|
||||
|
||||
private void mkListAdapter()
|
||||
|
@ -323,7 +323,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
setListAdapter( new ImportListAdapter() );
|
||||
}
|
||||
|
||||
private String saveDict( InputStream inputStream, String name,
|
||||
private String saveDict( InputStream inputStream, String name,
|
||||
DictUtils.DownProgListener dpl )
|
||||
{
|
||||
DictUtils.DictLoc loc = XWPrefs.getDefaultLoc( m_activity );
|
||||
|
@ -345,7 +345,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static void rememberListener( Uri uri, String name,
|
||||
private static void rememberListener( Uri uri, String name,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
ListenerData ld = new ListenerData( uri, name, lstnr );
|
||||
|
@ -354,7 +354,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
}
|
||||
}
|
||||
|
||||
private static void callListener( Uri uri, boolean success )
|
||||
private static void callListener( Uri uri, boolean success )
|
||||
{
|
||||
if ( null != uri ) {
|
||||
ListenerData ld;
|
||||
|
@ -375,16 +375,16 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
}
|
||||
}
|
||||
|
||||
public static void downloadDictInBack( Context context, String langName,
|
||||
String name,
|
||||
public static void downloadDictInBack( Context context, String langName,
|
||||
String name,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
Uri uri = Utils.makeDictUri( context, langName, name );
|
||||
downloadDictInBack( context, uri, name, lstnr );
|
||||
}
|
||||
|
||||
public static void downloadDictInBack( Context context, int lang,
|
||||
String name,
|
||||
public static void downloadDictInBack( Context context, int lang,
|
||||
String name,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
Uri uri = Utils.makeDictUri( context, lang, name );
|
||||
|
@ -392,7 +392,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
}
|
||||
|
||||
public static void downloadDictInBack( Context context, Uri uri,
|
||||
String name,
|
||||
String name,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
Uri[] uris = new Uri[] { uri };
|
||||
|
@ -401,7 +401,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
}
|
||||
|
||||
public static void downloadDictsInBack( Context context, Uri[] uris,
|
||||
String[] names,
|
||||
String[] names,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
if ( null != lstnr ) {
|
||||
|
|
|
@ -43,9 +43,9 @@ public class EditColorPreference extends DialogPreference {
|
|||
private int m_curColor;
|
||||
// m_updateText: prevent loop that resets edittext cursor
|
||||
private boolean m_updateText = true;
|
||||
private static final int m_seekbarIds[] = { R.id.seek_red, R.id.seek_green,
|
||||
private static final int m_seekbarIds[] = { R.id.seek_red, R.id.seek_green,
|
||||
R.id.seek_blue };
|
||||
private static final int m_editIds[] = { R.id.edit_red, R.id.edit_green,
|
||||
private static final int m_editIds[] = { R.id.edit_red, R.id.edit_green,
|
||||
R.id.edit_blue };
|
||||
|
||||
private class SBCL implements SeekBar.OnSeekBarChangeListener {
|
||||
|
@ -59,7 +59,7 @@ public class EditColorPreference extends DialogPreference {
|
|||
m_editTxt = editTxt;
|
||||
}
|
||||
|
||||
public void onProgressChanged( SeekBar seekBar, int progress,
|
||||
public void onProgressChanged( SeekBar seekBar, int progress,
|
||||
boolean fromUser )
|
||||
{
|
||||
if ( m_updateText ) {
|
||||
|
@ -87,11 +87,11 @@ public class EditColorPreference extends DialogPreference {
|
|||
{
|
||||
}
|
||||
|
||||
public void beforeTextChanged( CharSequence s, int st, int cnt, int a )
|
||||
public void beforeTextChanged( CharSequence s, int st, int cnt, int a )
|
||||
{
|
||||
}
|
||||
|
||||
public void onTextChanged( CharSequence s, int start,
|
||||
public void onTextChanged( CharSequence s, int start,
|
||||
int before, int count )
|
||||
{
|
||||
int val;
|
||||
|
@ -110,7 +110,7 @@ public class EditColorPreference extends DialogPreference {
|
|||
{
|
||||
super( context, attrs );
|
||||
m_context = context;
|
||||
|
||||
|
||||
setWidgetLayoutResource( R.layout.color_display );
|
||||
setDialogLayoutResource( R.layout.color_edit );
|
||||
|
||||
|
@ -134,9 +134,9 @@ public class EditColorPreference extends DialogPreference {
|
|||
persistInt( (Integer)defaultValue );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onBindView( View parent )
|
||||
protected void onBindView( View parent )
|
||||
{
|
||||
super.onBindView( parent );
|
||||
View sample = parent.findViewById( R.id.color_display_sample );
|
||||
|
@ -156,11 +156,11 @@ public class EditColorPreference extends DialogPreference {
|
|||
View sample = view.findViewById( R.id.color_edit_sample );
|
||||
sample.setBackgroundColor( m_curColor );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder( AlertDialog.Builder builder )
|
||||
{
|
||||
DialogInterface.OnClickListener lstnr =
|
||||
DialogInterface.OnClickListener lstnr =
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( DialogInterface dialog, int which )
|
||||
|
@ -179,7 +179,7 @@ public class EditColorPreference extends DialogPreference {
|
|||
super.onPrepareDialogBuilder( builder );
|
||||
}
|
||||
|
||||
private void setOneByte( View parent, int indx )
|
||||
private void setOneByte( View parent, int indx )
|
||||
{
|
||||
int shift = 16 - (indx*8);
|
||||
int byt = (m_curColor >> shift) & 0xFF;
|
||||
|
|
|
@ -42,7 +42,7 @@ public class ExpiringDelegate {
|
|||
private static final long INTERVAL_SECS = 3 * 24 * 60 * 60;
|
||||
// private static final long INTERVAL_SECS = 60 * 10; // for testing
|
||||
|
||||
private static boolean s_kitkat =
|
||||
private static boolean s_kitkat =
|
||||
19 <= Integer.valueOf( android.os.Build.VERSION.SDK );
|
||||
|
||||
private Context m_context;
|
||||
|
@ -90,7 +90,7 @@ public class ExpiringDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
DbgUtils.logdf( "ExpUpdater: ref had %d refs, now has %d expiringdelegate views",
|
||||
DbgUtils.logdf( "ExpUpdater: ref had %d refs, now has %d expiringdelegate views",
|
||||
sizeBefore, dlgts.size() );
|
||||
|
||||
for ( ExpiringDelegate dlgt : dlgts ) {
|
||||
|
@ -100,7 +100,7 @@ public class ExpiringDelegate {
|
|||
reschedule();
|
||||
}
|
||||
|
||||
private void reschedule()
|
||||
private void reschedule()
|
||||
{
|
||||
m_handler.postDelayed( this, INTERVAL_SECS * 1000 / 100 );
|
||||
}
|
||||
|
@ -130,8 +130,8 @@ public class ExpiringDelegate {
|
|||
private static ExpUpdater s_updater;
|
||||
static {
|
||||
s_rect = new Rect();
|
||||
s_paint = new Paint();
|
||||
s_paint.setStyle(Paint.Style.STROKE);
|
||||
s_paint = new Paint();
|
||||
s_paint.setStyle(Paint.Style.STROKE);
|
||||
s_paint.setStrokeWidth( 1 );
|
||||
s_points = new float[4*6];
|
||||
s_updater = new ExpUpdater();
|
||||
|
@ -149,7 +149,7 @@ public class ExpiringDelegate {
|
|||
s_updater.setHandler( handler );
|
||||
}
|
||||
|
||||
public void configure( boolean haveTurn, boolean haveTurnLocal,
|
||||
public void configure( boolean haveTurn, boolean haveTurnLocal,
|
||||
long startSecs )
|
||||
{
|
||||
m_active = haveTurn;
|
||||
|
@ -173,7 +173,7 @@ public class ExpiringDelegate {
|
|||
m_dsdel.showSelected( m_selected );
|
||||
}
|
||||
|
||||
public void onDraw( Canvas canvas )
|
||||
public void onDraw( Canvas canvas )
|
||||
{
|
||||
if ( m_selected ) {
|
||||
// do nothing; the drawable's set already
|
||||
|
@ -194,14 +194,14 @@ public class ExpiringDelegate {
|
|||
s_rect.left, s_rect.bottom - 1 );
|
||||
|
||||
// left horizontals
|
||||
addPoints( 1, s_rect.left, s_rect.top,
|
||||
addPoints( 1, s_rect.left, s_rect.top,
|
||||
s_rect.left + redWidth, s_rect.top );
|
||||
addPoints( 2, s_rect.left, s_rect.bottom - 1,
|
||||
s_rect.left + redWidth,
|
||||
s_rect.bottom - 1 );
|
||||
|
||||
// right horizontals
|
||||
addPoints( 3, s_rect.left + redWidth, s_rect.top,
|
||||
addPoints( 3, s_rect.left + redWidth, s_rect.top,
|
||||
s_rect.right - 1, s_rect.top );
|
||||
addPoints( 4, s_rect.left + redWidth, s_rect.bottom - 1,
|
||||
s_rect.right - 1, s_rect.bottom - 1 );
|
||||
|
@ -253,11 +253,11 @@ public class ExpiringDelegate {
|
|||
Bitmap bm = Bitmap.createBitmap( 100, 1, Bitmap.Config.ARGB_8888 );
|
||||
Canvas canvas = new Canvas(bm);
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setColor( Color.RED );
|
||||
Paint paint = new Paint();
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setColor( Color.RED );
|
||||
canvas.drawRect( 0, 0, pct, 1, paint );
|
||||
paint.setColor( Utils.TURN_COLOR );
|
||||
paint.setColor( Utils.TURN_COLOR );
|
||||
canvas.drawRect( pct, 0, 100, 1, paint );
|
||||
return new BitmapDrawable( m_context.getResources(), bm );
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class ExpiringLinearLayout extends LinearLayout {
|
|||
super( context, as );
|
||||
}
|
||||
|
||||
public void setPct( Handler handler, boolean haveTurn,
|
||||
public void setPct( Handler handler, boolean haveTurn,
|
||||
boolean haveTurnLocal, long startSecs )
|
||||
{
|
||||
if ( null == m_delegate ) {
|
||||
|
@ -49,7 +49,7 @@ public class ExpiringLinearLayout extends LinearLayout {
|
|||
|
||||
@Override
|
||||
// not called unless setWillNotDraw( false ) called
|
||||
protected void onDraw( Canvas canvas )
|
||||
protected void onDraw( Canvas canvas )
|
||||
{
|
||||
super.onDraw( canvas );
|
||||
if ( null != m_delegate ) {
|
||||
|
|
|
@ -35,7 +35,7 @@ class ExpiringTextView extends TextView {
|
|||
m_context = context;
|
||||
}
|
||||
|
||||
public void setPct( Handler handler, boolean haveTurn,
|
||||
public void setPct( Handler handler, boolean haveTurn,
|
||||
boolean haveTurnLocal, long startSecs )
|
||||
{
|
||||
ExpiringDelegate delegate = getDelegate();
|
||||
|
@ -44,7 +44,7 @@ class ExpiringTextView extends TextView {
|
|||
setPct( haveTurn, haveTurnLocal, startSecs );
|
||||
}
|
||||
|
||||
public void setPct( boolean haveTurn, boolean haveTurnLocal,
|
||||
public void setPct( boolean haveTurn, boolean haveTurnLocal,
|
||||
long startSecs )
|
||||
{
|
||||
if ( null != m_delegate ) {
|
||||
|
@ -53,7 +53,7 @@ class ExpiringTextView extends TextView {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw( Canvas canvas )
|
||||
protected void onDraw( Canvas canvas )
|
||||
{
|
||||
super.onDraw( canvas );
|
||||
if ( null != m_delegate ) {
|
||||
|
|
|
@ -42,7 +42,7 @@ public class FirstRunDialog {
|
|||
view.setWebViewClient( new WebViewClient() {
|
||||
private boolean m_loaded = false;
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading( WebView view,
|
||||
public boolean shouldOverrideUrlLoading( WebView view,
|
||||
String url ) {
|
||||
boolean result = false;
|
||||
if ( url.startsWith("mailto:") ){
|
||||
|
|
|
@ -1,309 +1,309 @@
|
|||
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2014-2016 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.
|
||||
*/
|
||||
// /* -*- compile-command: "find-and-ant.sh debug install"; -*- */
|
||||
// /*
|
||||
// * Copyright 2014-2016 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;
|
||||
// package org.eehouse.android.xw4;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.app.Dialog;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentManager.BackStackEntry;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout;
|
||||
// import android.graphics.Rect;
|
||||
// import android.app.Dialog;
|
||||
// import android.content.res.Configuration;
|
||||
// import android.os.Bundle;
|
||||
// import android.support.v4.app.Fragment;
|
||||
// import android.support.v4.app.FragmentActivity;
|
||||
// import android.support.v4.app.FragmentManager;
|
||||
// import android.support.v4.app.FragmentManager.BackStackEntry;
|
||||
// import android.support.v4.app.FragmentTransaction;
|
||||
// import android.view.View;
|
||||
// import android.widget.FrameLayout;
|
||||
// import android.widget.LinearLayout.LayoutParams;
|
||||
// import android.widget.LinearLayout;
|
||||
// import android.widget.LinearLayout;
|
||||
|
||||
import junit.framework.Assert;
|
||||
// import junit.framework.Assert;
|
||||
|
||||
public class FragActivity extends FragmentActivity
|
||||
implements FragmentManager.OnBackStackChangedListener {
|
||||
// public class FragActivity extends FragmentActivity
|
||||
// implements FragmentManager.OnBackStackChangedListener {
|
||||
|
||||
private static final int MAX_PANES_LANDSCAPE = 3;
|
||||
// private static final int MAX_PANES_LANDSCAPE = 3;
|
||||
|
||||
public interface OrientChangeListener {
|
||||
void orientationChanged();
|
||||
}
|
||||
// // public interface OrientChangeListener {
|
||||
// // void orientationChanged();
|
||||
// // }
|
||||
|
||||
private static FragActivity s_this;
|
||||
// private static FragActivity s_this;
|
||||
|
||||
private LinearLayout m_root;
|
||||
private int m_nextID = 0x00FFFFFF;
|
||||
private int m_maxPanes;
|
||||
private Boolean m_isPortrait;
|
||||
// private LinearLayout m_root;
|
||||
// private int m_nextID = 0x00FFFFFF;
|
||||
// private int m_maxPanes;
|
||||
// private Boolean m_isPortrait;
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
s_this = this;
|
||||
super.onCreate( savedInstanceState );
|
||||
setContentView( R.layout.fragact );
|
||||
// @Override
|
||||
// public void onCreate( Bundle savedInstanceState )
|
||||
// {
|
||||
// s_this = this;
|
||||
// super.onCreate( savedInstanceState );
|
||||
// setContentView( R.layout.dualcontainer );
|
||||
|
||||
m_root = (LinearLayout)findViewById( R.id.main_container );
|
||||
getSupportFragmentManager().addOnBackStackChangedListener( this );
|
||||
// m_root = (LinearLayout)findViewById( R.id.main_container );
|
||||
// getSupportFragmentManager().addOnBackStackChangedListener( this );
|
||||
|
||||
m_maxPanes = maxPanes();
|
||||
// m_maxPanes = maxPanes();
|
||||
|
||||
// Nothing to do if we're restarting
|
||||
if ( savedInstanceState == null ) {
|
||||
// In case this activity was started with special instructions from an Intent,
|
||||
// pass the Intent's extras to the fragment as arguments
|
||||
addFragmentImpl( new GamesListFrag(), getIntent().getExtras(), null );
|
||||
}
|
||||
}
|
||||
// // Nothing to do if we're restarting
|
||||
// if ( savedInstanceState == null ) {
|
||||
// // In case this activity was started with special instructions from an Intent,
|
||||
// // pass the Intent's extras to the fragment as arguments
|
||||
// addFragmentImpl( new GamesListFrag(), getIntent().getExtras(), null );
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
DbgUtils.logf( "FragActivity.onBackPressed()" );
|
||||
super.onBackPressed();
|
||||
}
|
||||
// @Override
|
||||
// public void onBackPressed()
|
||||
// {
|
||||
// DbgUtils.logf( "FragActivity.onBackPressed()" );
|
||||
// super.onBackPressed();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged( Configuration newConfig )
|
||||
{
|
||||
Rect rect = new Rect();
|
||||
m_root.getWindowVisibleDisplayFrame( rect );
|
||||
// @Override
|
||||
// public void onConfigurationChanged( Configuration newConfig )
|
||||
// {
|
||||
// Rect rect = new Rect();
|
||||
// m_root.getWindowVisibleDisplayFrame( rect );
|
||||
|
||||
boolean isPortrait
|
||||
= Configuration.ORIENTATION_PORTRAIT == newConfig.orientation;
|
||||
DbgUtils.logf( "FragActivity.onConfigurationChanged(isPortrait=%b)",
|
||||
isPortrait );
|
||||
m_isPortrait = isPortrait;
|
||||
if ( isPortrait != (rect.width() <= rect.height()) ) {
|
||||
DbgUtils.logdf( "FragActivity.onConfigurationChanged(): isPortrait:"
|
||||
+ " %b; width: %d; height: %d",
|
||||
isPortrait, rect.width(), rect.height() );
|
||||
}
|
||||
int maxPanes = isPortrait? 1 : MAX_PANES_LANDSCAPE;
|
||||
if ( m_maxPanes != maxPanes ) {
|
||||
m_maxPanes = maxPanes;
|
||||
setVisiblePanes();
|
||||
}
|
||||
tellOrientationChanged();
|
||||
super.onConfigurationChanged( newConfig );
|
||||
}
|
||||
// boolean isPortrait
|
||||
// = Configuration.ORIENTATION_PORTRAIT == newConfig.orientation;
|
||||
// DbgUtils.logf( "FragActivity.onConfigurationChanged(isPortrait=%b)",
|
||||
// isPortrait );
|
||||
// m_isPortrait = isPortrait;
|
||||
// if ( isPortrait != (rect.width() <= rect.height()) ) {
|
||||
// DbgUtils.logdf( "FragActivity.onConfigurationChanged(): isPortrait:"
|
||||
// + " %b; width: %d; height: %d",
|
||||
// isPortrait, rect.width(), rect.height() );
|
||||
// }
|
||||
// int maxPanes = isPortrait? 1 : MAX_PANES_LANDSCAPE;
|
||||
// if ( m_maxPanes != maxPanes ) {
|
||||
// m_maxPanes = maxPanes;
|
||||
// setVisiblePanes();
|
||||
// }
|
||||
// tellOrientationChanged();
|
||||
// super.onConfigurationChanged( newConfig );
|
||||
// }
|
||||
|
||||
protected void getFragmentDims( int[] dims )
|
||||
{
|
||||
Rect rect = new Rect();
|
||||
m_root.getWindowVisibleDisplayFrame( rect );
|
||||
int width = rect.width();
|
||||
int height = rect.height();
|
||||
if ( null != m_isPortrait && m_isPortrait && height < width ) {
|
||||
int tmp = width;
|
||||
width = height;
|
||||
height = tmp;
|
||||
}
|
||||
dims[0] = width / Math.min( m_maxPanes, m_root.getChildCount() );
|
||||
dims[1] = height;
|
||||
}
|
||||
// protected void getFragmentDims( int[] dims )
|
||||
// {
|
||||
// Rect rect = new Rect();
|
||||
// m_root.getWindowVisibleDisplayFrame( rect );
|
||||
// int width = rect.width();
|
||||
// int height = rect.height();
|
||||
// if ( null != m_isPortrait && m_isPortrait && height < width ) {
|
||||
// int tmp = width;
|
||||
// width = height;
|
||||
// height = tmp;
|
||||
// }
|
||||
// dims[0] = width / Math.min( m_maxPanes, m_root.getChildCount() );
|
||||
// dims[1] = height;
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
{
|
||||
return DlgDelegate.onCreateDialog( id );
|
||||
}
|
||||
// @Override
|
||||
// protected Dialog onCreateDialog( int id )
|
||||
// {
|
||||
// return DlgDelegate.onCreateDialog( id );
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialog( int id, Dialog dialog )
|
||||
{
|
||||
DlgDelegate.onPrepareDialog( id, dialog );
|
||||
}
|
||||
// @Override
|
||||
// protected void onPrepareDialog( int id, Dialog dialog )
|
||||
// {
|
||||
// DlgDelegate.onPrepareDialog( id, dialog );
|
||||
// }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// FragmentManager.OnBackStackChangedListener
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public void onBackStackChanged()
|
||||
{
|
||||
DbgUtils.logf( "FragActivity.onBackStackChanged()" );
|
||||
// make sure the right-most are visible
|
||||
int fragCount = getSupportFragmentManager().getBackStackEntryCount();
|
||||
if ( 0 == fragCount ) {
|
||||
finish();
|
||||
} else if ( fragCount == m_root.getChildCount() - 1 ) {
|
||||
m_root.removeViewAt( fragCount );
|
||||
setVisiblePanes();
|
||||
}
|
||||
}
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
// // FragmentManager.OnBackStackChangedListener
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
// public void onBackStackChanged()
|
||||
// {
|
||||
// DbgUtils.logf( "FragActivity.onBackStackChanged()" );
|
||||
// // make sure the right-most are visible
|
||||
// int fragCount = getSupportFragmentManager().getBackStackEntryCount();
|
||||
// if ( 0 == fragCount ) {
|
||||
// finish();
|
||||
// } else if ( fragCount == m_root.getChildCount() - 1 ) {
|
||||
// m_root.removeViewAt( fragCount );
|
||||
// setVisiblePanes();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void launchDictFrag( Bundle args )
|
||||
// {
|
||||
// // DictBrowseFrag dbf = new DictBrowseFrag();
|
||||
// // dbf.setArguments( args );
|
||||
// // addFragment( dbf );
|
||||
// }
|
||||
// // public void launchDictFrag( Bundle args )
|
||||
// // {
|
||||
// // // DictBrowseFrag dbf = new DictBrowseFrag();
|
||||
// // // dbf.setArguments( args );
|
||||
// // // addFragment( dbf );
|
||||
// // }
|
||||
|
||||
protected void finishFragment()
|
||||
{
|
||||
popFragment( null );
|
||||
}
|
||||
// protected void finishFragment()
|
||||
// {
|
||||
// popFragment( null );
|
||||
// }
|
||||
|
||||
protected void popFragment( Fragment frag )
|
||||
{
|
||||
getSupportFragmentManager().popBackStack();
|
||||
}
|
||||
// protected void popFragment( Fragment frag )
|
||||
// {
|
||||
// getSupportFragmentManager().popBackStack();
|
||||
// }
|
||||
|
||||
private void addFragmentImpl( Fragment fragment, Bundle bundle,
|
||||
Delegator parent )
|
||||
{
|
||||
fragment.setArguments( bundle );
|
||||
addFragmentImpl( fragment, parent );
|
||||
}
|
||||
// private void addFragmentImpl( Fragment fragment, Bundle bundle,
|
||||
// Delegator parent )
|
||||
// {
|
||||
// fragment.setArguments( bundle );
|
||||
// addFragmentImpl( fragment, parent );
|
||||
// }
|
||||
|
||||
private void addFragmentImpl( Fragment fragment, Delegator delegator )
|
||||
{
|
||||
String newName = fragment.getClass().getName();
|
||||
boolean replace = false;
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
int fragCount = fm.getBackStackEntryCount();
|
||||
int containerCount = m_root.getChildCount();
|
||||
DbgUtils.logf( "fragCount: %d; containerCount: %d", fragCount, containerCount );
|
||||
// Assert.assertTrue( fragCount == containerCount );
|
||||
// private void addFragmentImpl( Fragment fragment, Delegator delegator )
|
||||
// {
|
||||
// String newName = fragment.getClass().getName();
|
||||
// boolean replace = false;
|
||||
// FragmentManager fm = getSupportFragmentManager();
|
||||
// int fragCount = fm.getBackStackEntryCount();
|
||||
// int containerCount = m_root.getChildCount();
|
||||
// DbgUtils.logf( "fragCount: %d; containerCount: %d", fragCount, containerCount );
|
||||
// // Assert.assertTrue( fragCount == containerCount );
|
||||
|
||||
// Replace IF we're adding something of the same class at right OR if
|
||||
// we're adding something with the existing left pane as its parent
|
||||
// (delegator)
|
||||
if ( 0 < fragCount ) {
|
||||
FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt( fragCount - 1 );
|
||||
String curName = entry.getName();
|
||||
DbgUtils.logf( "name of last entry: %s", curName );
|
||||
replace = curName.equals( newName );
|
||||
// // Replace IF we're adding something of the same class at right OR if
|
||||
// // we're adding something with the existing left pane as its parent
|
||||
// // (delegator)
|
||||
// if ( 0 < fragCount ) {
|
||||
// FragmentManager.BackStackEntry entry = fm.getBackStackEntryAt( fragCount - 1 );
|
||||
// String curName = entry.getName();
|
||||
// DbgUtils.logf( "name of last entry: %s", curName );
|
||||
// replace = curName.equals( newName );
|
||||
|
||||
if ( !replace && 1 < fragCount ) {
|
||||
entry = fm.getBackStackEntryAt( fragCount - 2 );
|
||||
curName = entry.getName();
|
||||
String delName = delegator.getClass().getName();
|
||||
DbgUtils.logf( "comparing %s, %s", curName, delName );
|
||||
replace = curName.equals( delName );
|
||||
}
|
||||
// if ( !replace && 1 < fragCount ) {
|
||||
// entry = fm.getBackStackEntryAt( fragCount - 2 );
|
||||
// curName = entry.getName();
|
||||
// String delName = delegator.getClass().getName();
|
||||
// DbgUtils.logf( "comparing %s, %s", curName, delName );
|
||||
// replace = curName.equals( delName );
|
||||
// }
|
||||
|
||||
if ( replace ) {
|
||||
fm.popBackStack();
|
||||
}
|
||||
}
|
||||
// if ( replace ) {
|
||||
// fm.popBackStack();
|
||||
// }
|
||||
// }
|
||||
|
||||
// Replace doesn't seem to work with generated IDs, so we'll create a
|
||||
// new FrameLayout each time. If we're replacing, we'll replace the
|
||||
// current rightmost FrameLayout. Otherwise we'll add a new one.
|
||||
FrameLayout cont = new FrameLayout( this );
|
||||
cont.setLayoutParams( new LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) );
|
||||
int id = --m_nextID;
|
||||
cont.setId( id );
|
||||
m_root.addView( cont, replace ? containerCount - 1 : containerCount );
|
||||
// // Replace doesn't seem to work with generated IDs, so we'll create a
|
||||
// // new FrameLayout each time. If we're replacing, we'll replace the
|
||||
// // current rightmost FrameLayout. Otherwise we'll add a new one.
|
||||
// FrameLayout cont = new FrameLayout( this );
|
||||
// cont.setLayoutParams( new LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) );
|
||||
// int id = --m_nextID;
|
||||
// cont.setId( id );
|
||||
// m_root.addView( cont, replace ? containerCount - 1 : containerCount );
|
||||
|
||||
if ( !replace && containerCount >= m_maxPanes ) {
|
||||
int indx = containerCount - m_maxPanes;
|
||||
View child = m_root.getChildAt( indx );
|
||||
child.setVisibility( View.GONE );
|
||||
// if ( !replace && containerCount >= m_maxPanes ) {
|
||||
// int indx = containerCount - m_maxPanes;
|
||||
// View child = m_root.getChildAt( indx );
|
||||
// child.setVisibility( View.GONE );
|
||||
|
||||
setMenuVisibility( child, false );
|
||||
// setMenuVisibility( child, false );
|
||||
|
||||
DbgUtils.logf( "hiding %dth container", indx );
|
||||
}
|
||||
// DbgUtils.logf( "hiding %dth container", indx );
|
||||
// }
|
||||
|
||||
fm.beginTransaction()
|
||||
.add( id, fragment )
|
||||
.addToBackStack( newName )
|
||||
.commit();
|
||||
// fm.executePendingTransactions();
|
||||
}
|
||||
// fm.beginTransaction()
|
||||
// .add( id, fragment )
|
||||
// .addToBackStack( newName )
|
||||
// .commit();
|
||||
// // fm.executePendingTransactions();
|
||||
// }
|
||||
|
||||
private void setVisiblePanes()
|
||||
{
|
||||
// hide all but the right-most m_maxPanes children
|
||||
int nPanes = m_root.getChildCount();
|
||||
for ( int ii = 0; ii < nPanes; ++ii ) {
|
||||
View child = m_root.getChildAt( ii );
|
||||
boolean visible = ii >= nPanes - m_maxPanes;
|
||||
DbgUtils.logf( "pane %d: visible=%b", ii, visible );
|
||||
child.setVisibility( visible ? View.VISIBLE : View.GONE );
|
||||
setMenuVisibility( child, visible );
|
||||
}
|
||||
}
|
||||
// private void setVisiblePanes()
|
||||
// {
|
||||
// // hide all but the right-most m_maxPanes children
|
||||
// int nPanes = m_root.getChildCount();
|
||||
// for ( int ii = 0; ii < nPanes; ++ii ) {
|
||||
// View child = m_root.getChildAt( ii );
|
||||
// boolean visible = ii >= nPanes - m_maxPanes;
|
||||
// DbgUtils.logf( "pane %d: visible=%b", ii, visible );
|
||||
// child.setVisibility( visible ? View.VISIBLE : View.GONE );
|
||||
// setMenuVisibility( child, visible );
|
||||
// }
|
||||
// }
|
||||
|
||||
private void setMenuVisibility( View cont, boolean visible )
|
||||
{
|
||||
FrameLayout layout = (FrameLayout)cont;
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
int hidingId = layout.getId();
|
||||
Fragment frag = fm.findFragmentById( hidingId );
|
||||
if ( null != frag ) { // hasn't been popped?
|
||||
frag.setMenuVisibility( visible );
|
||||
}
|
||||
}
|
||||
// private void setMenuVisibility( View cont, boolean visible )
|
||||
// {
|
||||
// FrameLayout layout = (FrameLayout)cont;
|
||||
// FragmentManager fm = getSupportFragmentManager();
|
||||
// int hidingId = layout.getId();
|
||||
// Fragment frag = fm.findFragmentById( hidingId );
|
||||
// if ( null != frag ) { // hasn't been popped?
|
||||
// frag.setMenuVisibility( visible );
|
||||
// }
|
||||
// }
|
||||
|
||||
// Walk all Fragment children and if they care notify of change.
|
||||
private void tellOrientationChanged()
|
||||
{
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
int nPanes = m_root.getChildCount();
|
||||
for ( int ii = 0; ii < nPanes; ++ii ) {
|
||||
FrameLayout frame = (FrameLayout)m_root.getChildAt( ii );
|
||||
int id = frame.getId();
|
||||
Fragment frag = fm.findFragmentById( id );
|
||||
if ( null == frag ) {
|
||||
DbgUtils.logf( "tellOrienationChanged: NO FRAG at %d, id=%d", ii, id );
|
||||
} else if ( frag instanceof OrientChangeListener ) {
|
||||
((OrientChangeListener)frag).orientationChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
// // Walk all Fragment children and if they care notify of change.
|
||||
// private void tellOrientationChanged()
|
||||
// {
|
||||
// FragmentManager fm = getSupportFragmentManager();
|
||||
// int nPanes = m_root.getChildCount();
|
||||
// for ( int ii = 0; ii < nPanes; ++ii ) {
|
||||
// FrameLayout frame = (FrameLayout)m_root.getChildAt( ii );
|
||||
// int id = frame.getId();
|
||||
// Fragment frag = fm.findFragmentById( id );
|
||||
// if ( null == frag ) {
|
||||
// DbgUtils.logf( "tellOrienationChanged: NO FRAG at %d, id=%d", ii, id );
|
||||
// } else if ( frag instanceof XWFragment ) {
|
||||
// ((XWFragment)frag).getDelegate().orientationChanged();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private int maxPanes()
|
||||
{
|
||||
int result;
|
||||
int orientation = getResources().getConfiguration().orientation;
|
||||
if ( XWPrefs.getIsTablet( this )
|
||||
&& Configuration.ORIENTATION_LANDSCAPE == orientation ) {
|
||||
result = 2;
|
||||
} else {
|
||||
result = 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// private int maxPanes()
|
||||
// {
|
||||
// int result;
|
||||
// int orientation = getResources().getConfiguration().orientation;
|
||||
// if ( XWPrefs.getIsTablet( this )
|
||||
// && Configuration.ORIENTATION_LANDSCAPE == orientation ) {
|
||||
// result = 2;
|
||||
// } else {
|
||||
// result = 1;
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
private static FragActivity getThis()
|
||||
{
|
||||
Assert.assertNotNull( s_this );
|
||||
return s_this;
|
||||
}
|
||||
// private static FragActivity getThis()
|
||||
// {
|
||||
// Assert.assertNotNull( s_this );
|
||||
// return s_this;
|
||||
// }
|
||||
|
||||
public static void addFragment( Fragment fragment, Bundle bundle )
|
||||
{
|
||||
addFragment( fragment, bundle, null );
|
||||
}
|
||||
// public static void addFragment( Fragment fragment, Bundle bundle )
|
||||
// {
|
||||
// addFragment( fragment, bundle, null );
|
||||
// }
|
||||
|
||||
public static void addFragment( Fragment fragment, Bundle bundle,
|
||||
Delegator parent )
|
||||
{
|
||||
getThis().addFragmentImpl( fragment, bundle, parent );
|
||||
}
|
||||
// public static void addFragment( Fragment fragment, Bundle bundle,
|
||||
// Delegator parent )
|
||||
// {
|
||||
// getThis().addFragmentImpl( fragment, bundle, parent );
|
||||
// }
|
||||
|
||||
public static void addFragmentForResult( Fragment fragment, Bundle bundle,
|
||||
RequestCode requestCode, Delegator parent )
|
||||
{
|
||||
getThis().addFragmentImpl( fragment, bundle, parent );
|
||||
}
|
||||
}
|
||||
// public static void addFragmentForResult( Fragment fragment, Bundle bundle,
|
||||
// RequestCode requestCode, Delegator parent )
|
||||
// {
|
||||
// getThis().addFragmentImpl( fragment, bundle, parent );
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -35,13 +35,13 @@ public class GCMIntentService extends GCMBaseIntentService {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onError( Context context, String error )
|
||||
protected void onError( Context context, String error )
|
||||
{
|
||||
DbgUtils.logdf("GCMIntentService.onError(%s)", error );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRegistered( Context context, String regId )
|
||||
protected void onRegistered( Context context, String regId )
|
||||
{
|
||||
DbgUtils.logdf( "GCMIntentService.onRegistered(%s)", regId );
|
||||
DevID.setGCMDevID( context, regId );
|
||||
|
@ -49,7 +49,7 @@ public class GCMIntentService extends GCMBaseIntentService {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onUnregistered( Context context, String regId )
|
||||
protected void onUnregistered( Context context, String regId )
|
||||
{
|
||||
DbgUtils.logdf( "GCMIntentService.onUnregistered(%s)", regId );
|
||||
DevID.clearGCMDevID( context );
|
||||
|
@ -58,7 +58,7 @@ public class GCMIntentService extends GCMBaseIntentService {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onMessage( Context context, Intent intent )
|
||||
protected void onMessage( Context context, Intent intent )
|
||||
{
|
||||
DbgUtils.logdf( "GCMIntentService.onMessage()" );
|
||||
notifyRelayService( context, true );
|
||||
|
@ -108,7 +108,7 @@ public class GCMIntentService extends GCMBaseIntentService {
|
|||
Intent alertIntent = GamesListDelegate
|
||||
.makeAlertIntent( this, value );
|
||||
int code = value.hashCode() ^ title.hashCode();
|
||||
Utils.postNotification( context, alertIntent, title,
|
||||
Utils.postNotification( context, alertIntent, title,
|
||||
teaser, code );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class GameConfigActivity extends XWActivity {
|
|||
@Override
|
||||
public void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
super.onCreate( savedInstanceState,
|
||||
super.onCreate( savedInstanceState,
|
||||
new GameConfigDelegate( this, savedInstanceState ) );
|
||||
} // onCreate
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
,XWListItem.DeleteCallback
|
||||
,RefreshNamesTask.NoNameFound {
|
||||
|
||||
private static final String INTENT_FORRESULT_ROWID = "forresult";
|
||||
private static final String INTENT_FORRESULT_NEWGAME = "newgame";
|
||||
|
||||
private static final String WHICH_PLAYER = "WHICH_PLAYER";
|
||||
|
||||
|
@ -73,6 +73,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
private CheckBox m_joinPublicCheck;
|
||||
private CheckBox m_gameLockedCheck;
|
||||
private boolean m_isLocked;
|
||||
private boolean m_haveClosed;
|
||||
private LinearLayout m_publicRoomsSet;
|
||||
private LinearLayout m_privateRoomsSet;
|
||||
|
||||
|
@ -88,9 +89,10 @@ public class GameConfigDelegate extends DelegateBase
|
|||
private Spinner m_roomChoose;
|
||||
// private Button m_configureButton;
|
||||
private long m_rowid;
|
||||
private boolean m_forResult;
|
||||
private boolean m_isNewGame;
|
||||
private CurGameInfo m_gi;
|
||||
private CurGameInfo m_giOrig;
|
||||
private JNIThread m_jniThread;
|
||||
private int m_whichPlayer;
|
||||
// private Spinner m_roleSpinner;
|
||||
// private Spinner m_connectSpinner;
|
||||
|
@ -140,12 +142,12 @@ public class GameConfigDelegate extends DelegateBase
|
|||
public RemoteChoices() { super( m_gi.nPlayers ); }
|
||||
|
||||
public Object getItem( int position) { return m_gi.players[position]; }
|
||||
public View getView( final int position, View convertView,
|
||||
public View getView( final int position, View convertView,
|
||||
ViewGroup parent ) {
|
||||
OnCheckedChangeListener lstnr;
|
||||
lstnr = new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
boolean isChecked )
|
||||
{
|
||||
m_gi.players[position].isLocal = !isChecked;
|
||||
|
@ -178,11 +180,12 @@ public class GameConfigDelegate extends DelegateBase
|
|||
.setView(playerEditView)
|
||||
.setPositiveButton( android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void
|
||||
onClick( DialogInterface dlg,
|
||||
public void
|
||||
onClick( DialogInterface dlg,
|
||||
int button ) {
|
||||
getPlayerSettings( dlg );
|
||||
loadPlayersList();
|
||||
GameConfigDelegate self = curThis();
|
||||
self.getPlayerSettings( dlg );
|
||||
self.loadPlayersList();
|
||||
}
|
||||
})
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
|
@ -197,7 +200,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
// .inflate( layoutForDlg(id), null ))
|
||||
// .setPositiveButton( android.R.string.ok,
|
||||
// new DialogInterface.OnClickListener() {
|
||||
// public void onClick( DialogInterface dlg,
|
||||
// public void onClick( DialogInterface dlg,
|
||||
// int whichButton ) {
|
||||
// getRoleSettings();
|
||||
// }
|
||||
|
@ -208,9 +211,9 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
case FORCE_REMOTE:
|
||||
dlpos = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
loadPlayersList();
|
||||
curThis().loadPlayersList();
|
||||
}
|
||||
};
|
||||
dialog = makeAlertBuilder()
|
||||
|
@ -218,14 +221,19 @@ public class GameConfigDelegate extends DelegateBase
|
|||
.setView( inflate( layoutForDlg(dlgID) ) )
|
||||
.setPositiveButton( android.R.string.ok, dlpos )
|
||||
.create();
|
||||
DialogInterface.OnDismissListener dismiss =
|
||||
DialogInterface.OnDismissListener dismiss =
|
||||
new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss( DialogInterface di )
|
||||
public void onDismiss( DialogInterface di )
|
||||
{
|
||||
if ( m_gi.forceRemoteConsistent() ) {
|
||||
showToast( R.string.forced_consistent );
|
||||
loadPlayersList();
|
||||
GameConfigDelegate self = curThis();
|
||||
if ( null != self
|
||||
&& self.m_gi.forceRemoteConsistent() ) {
|
||||
self.showToast( R.string.forced_consistent );
|
||||
self.loadPlayersList();
|
||||
} else {
|
||||
DbgUtils.logf( "GameConfigDelegate.onDismiss(): "
|
||||
+ "no visible self" );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -234,11 +242,12 @@ public class GameConfigDelegate extends DelegateBase
|
|||
case CONFIRM_CHANGE_PLAY:
|
||||
case CONFIRM_CHANGE:
|
||||
dlpos = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
applyChanges( true );
|
||||
GameConfigDelegate self = curThis();
|
||||
self.applyChanges( true );
|
||||
if ( DlgID.CONFIRM_CHANGE_PLAY == dlgID ) {
|
||||
launchGame();
|
||||
self.launchGame( true );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -248,9 +257,9 @@ public class GameConfigDelegate extends DelegateBase
|
|||
.setPositiveButton( R.string.button_save, dlpos );
|
||||
if ( DlgID.CONFIRM_CHANGE_PLAY == dlgID ) {
|
||||
dlpos = new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg,
|
||||
public void onClick( DialogInterface dlg,
|
||||
int whichButton ) {
|
||||
launchGame();
|
||||
curThis().finishAndLaunch();
|
||||
}
|
||||
};
|
||||
} else {
|
||||
|
@ -262,12 +271,12 @@ public class GameConfigDelegate extends DelegateBase
|
|||
dialog.setOnDismissListener( new DialogInterface.
|
||||
OnDismissListener() {
|
||||
public void onDismiss( DialogInterface di ) {
|
||||
finish();
|
||||
curThis().closeNoSave();
|
||||
}
|
||||
});
|
||||
break;
|
||||
case NO_NAME_FOUND:
|
||||
String langName = DictLangCache.getLangName( m_activity,
|
||||
String langName = DictLangCache.getLangName( m_activity,
|
||||
m_gi.dictLang );
|
||||
String msg = getString( R.string.no_name_found_fmt,
|
||||
m_gi.nPlayers, xlateLang( langName ) );
|
||||
|
@ -285,22 +294,23 @@ public class GameConfigDelegate extends DelegateBase
|
|||
.findViewById(R.id.default_check);
|
||||
cb.setVisibility( View.VISIBLE );
|
||||
|
||||
final DialogInterface.OnClickListener lstnr =
|
||||
final DialogInterface.OnClickListener lstnr =
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int button ) {
|
||||
m_conTypes = items.getTypes();
|
||||
GameConfigDelegate self = curThis();
|
||||
self.m_conTypes = items.getTypes();
|
||||
if ( cb.isChecked()) {
|
||||
XWPrefs.setAddrTypes( m_activity, m_conTypes );
|
||||
XWPrefs.setAddrTypes( self.m_activity, self.m_conTypes );
|
||||
}
|
||||
|
||||
m_car.populate( m_activity, m_conTypes );
|
||||
self.m_car.populate( self.m_activity, self.m_conTypes );
|
||||
|
||||
setConnLabel();
|
||||
setupRelayStuffIf( false );
|
||||
showHideRelayStuff();
|
||||
self.setConnLabel();
|
||||
self.setupRelayStuffIf( false );
|
||||
self.showHideRelayStuff();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
dialog = makeAlertBuilder()
|
||||
.setTitle( R.string.title_addrs_pref )
|
||||
.setView( layout )
|
||||
|
@ -315,7 +325,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
@Override
|
||||
protected void prepareDialog( DlgID dlgID, Dialog dialog )
|
||||
{
|
||||
{
|
||||
switch ( dlgID ) {
|
||||
case PLAYER_EDIT:
|
||||
setPlayerSettings( dialog );
|
||||
|
@ -339,13 +349,13 @@ public class GameConfigDelegate extends DelegateBase
|
|||
public void warnDisabled( CommsConnType typ ) {
|
||||
switch( typ ) {
|
||||
case COMMS_CONN_SMS:
|
||||
showConfirmThen( R.string.warn_sms_disabled,
|
||||
showConfirmThen( R.string.warn_sms_disabled,
|
||||
R.string.button_enable_sms,
|
||||
R.string.button_later,
|
||||
Action.ENABLE_SMS_ASK );
|
||||
break;
|
||||
case COMMS_CONN_BT:
|
||||
showConfirmThen( R.string.warn_bt_disabled,
|
||||
showConfirmThen( R.string.warn_bt_disabled,
|
||||
R.string.button_enable_bt,
|
||||
R.string.button_later,
|
||||
Action.ENABLE_BT_DO );
|
||||
|
@ -406,9 +416,9 @@ public class GameConfigDelegate extends DelegateBase
|
|||
if ( isServer ) {
|
||||
OnCheckedChangeListener lstnr =
|
||||
new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
boolean checked ) {
|
||||
localSet.setVisibility( checked ?
|
||||
localSet.setVisibility( checked ?
|
||||
View.GONE : View.VISIBLE );
|
||||
}
|
||||
};
|
||||
|
@ -422,7 +432,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
check = (CheckBox)dialog.findViewById( R.id.robot_check );
|
||||
OnCheckedChangeListener lstnr =
|
||||
new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
boolean checked ) {
|
||||
View view = dialog.findViewById( R.id.password_set );
|
||||
view.setVisibility( checked ? View.GONE : View.VISIBLE );
|
||||
|
@ -474,7 +484,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
Bundle args = getArguments();
|
||||
m_rowid = args.getLong( GameUtils.INTENT_KEY_ROWID, DBUtils.ROWID_NOTFOUND );
|
||||
Assert.assertTrue( DBUtils.ROWID_NOTFOUND != m_rowid );
|
||||
m_forResult = args.getBoolean( INTENT_FORRESULT_ROWID, false );
|
||||
m_isNewGame = args.getBoolean( INTENT_FORRESULT_NEWGAME, false );
|
||||
|
||||
m_connectSetRelay = findViewById( R.id.connect_set_relay );
|
||||
|
||||
|
@ -496,9 +506,9 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
// This should only be in for one ship! Remove it and all associated
|
||||
// strings immediately after shipping it.
|
||||
if ( !Utils.onFirstVersion( m_activity )
|
||||
if ( !Utils.onFirstVersion( m_activity )
|
||||
&& !XWPrefs.getPublicRoomsEnabled( m_activity ) ) {
|
||||
ActionPair pair = new ActionPair( Action.SET_ENABLE_PUBLIC,
|
||||
ActionPair pair = new ActionPair( Action.SET_ENABLE_PUBLIC,
|
||||
R.string.enable_pubroom_title );
|
||||
showNotAgainDlgThen( R.string.not_again_enablepublic,
|
||||
R.string.key_notagain_enablepublic,
|
||||
|
@ -509,6 +519,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
m_jniThread = JNIThread.getRetained( m_rowid );
|
||||
super.onResume();
|
||||
loadGame();
|
||||
}
|
||||
|
@ -517,9 +528,13 @@ public class GameConfigDelegate extends DelegateBase
|
|||
{
|
||||
m_giOrig = null; // flag for onStart and onResume
|
||||
super.onPause();
|
||||
if ( null != m_jniThread ) {
|
||||
m_jniThread.release();
|
||||
m_jniThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onSaveInstanceState( Bundle outState )
|
||||
protected void onSaveInstanceState( Bundle outState )
|
||||
{
|
||||
outState.putInt( WHICH_PLAYER, m_whichPlayer );
|
||||
}
|
||||
|
@ -551,8 +566,16 @@ public class GameConfigDelegate extends DelegateBase
|
|||
if ( null == m_giOrig ) {
|
||||
m_giOrig = new CurGameInfo( m_activity );
|
||||
|
||||
GameLock gameLock = new GameLock( m_rowid, false ).lock();
|
||||
XwJNI.GamePtr gamePtr = GameUtils.loadMakeGame( m_activity, m_giOrig, gameLock );
|
||||
GameLock gameLock;
|
||||
XwJNI.GamePtr gamePtr;
|
||||
if ( null == m_jniThread ) {
|
||||
gameLock = new GameLock( m_rowid, false ).lock();
|
||||
gamePtr = GameUtils.loadMakeGame( m_activity, m_giOrig, gameLock );
|
||||
} else {
|
||||
gameLock = m_jniThread.getLock();
|
||||
gamePtr = m_jniThread.getGamePtr();
|
||||
}
|
||||
|
||||
if ( null == gamePtr ) {
|
||||
showDictGoneFinish();
|
||||
} else {
|
||||
|
@ -561,7 +584,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
if ( m_gameStarted ) {
|
||||
if ( null == m_gameLockedCheck ) {
|
||||
m_gameLockedCheck =
|
||||
m_gameLockedCheck =
|
||||
(CheckBox)findViewById( R.id.game_locked_check );
|
||||
m_gameLockedCheck.setVisibility( View.VISIBLE );
|
||||
m_gameLockedCheck.setOnClickListener( this );
|
||||
|
@ -580,13 +603,15 @@ public class GameConfigDelegate extends DelegateBase
|
|||
} else if ( !localOnlyGame() ) {
|
||||
String relayName = XWPrefs.getDefaultRelayHost( m_activity );
|
||||
int relayPort = XWPrefs.getDefaultRelayPort( m_activity );
|
||||
XwJNI.comms_getInitialAddr( m_carOrig, relayName,
|
||||
XwJNI.comms_getInitialAddr( m_carOrig, relayName,
|
||||
relayPort );
|
||||
}
|
||||
m_conTypes = (CommsConnTypeSet)m_carOrig.conTypes.clone();
|
||||
gamePtr.release();
|
||||
|
||||
gameLock.unlock();
|
||||
if ( null == m_jniThread ) {
|
||||
gamePtr.release();
|
||||
gameLock.unlock();
|
||||
}
|
||||
|
||||
m_car = new CommsAddrRec( m_carOrig );
|
||||
|
||||
|
@ -613,13 +638,13 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
setChecked( R.id.hints_allowed, !m_gi.hintsNotAllowed );
|
||||
setChecked( R.id.pick_faceup, m_gi.allowPickTiles );
|
||||
setInt( R.id.timer_minutes_edit,
|
||||
setInt( R.id.timer_minutes_edit,
|
||||
m_gi.gameSeconds/60/m_gi.nPlayers );
|
||||
|
||||
CheckBox check = (CheckBox)findViewById( R.id.use_timer );
|
||||
OnCheckedChangeListener lstnr =
|
||||
new OnCheckedChangeListener() {
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
public void onCheckedChanged( CompoundButton buttonView,
|
||||
boolean checked ) {
|
||||
View view = findViewById( R.id.timer_set );
|
||||
view.setVisibility( checked ? View.VISIBLE : View.GONE );
|
||||
|
@ -658,6 +683,8 @@ public class GameConfigDelegate extends DelegateBase
|
|||
public void dlgButtonClicked( Action action, int button, Object[] params )
|
||||
{
|
||||
boolean callSuper = false;
|
||||
Assert.assertTrue( curThis() == this );
|
||||
|
||||
if ( AlertDialog.BUTTON_POSITIVE == button ) {
|
||||
switch( action ) {
|
||||
case LOCKED_CHANGE_ACTION:
|
||||
|
@ -667,10 +694,10 @@ public class GameConfigDelegate extends DelegateBase
|
|||
Utils.launchSettings( m_activity );
|
||||
break;
|
||||
case DELETE_AND_EXIT:
|
||||
if ( m_forResult ) {
|
||||
if ( m_isNewGame ) {
|
||||
deleteGame();
|
||||
}
|
||||
finish();
|
||||
closeNoSave();
|
||||
break;
|
||||
case SET_ENABLE_PUBLIC:
|
||||
XWPrefs.setPrefsBoolean( m_activity, R.string.key_enable_pubroom,
|
||||
|
@ -689,7 +716,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
callSuper = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
callSuper = true;
|
||||
}
|
||||
|
||||
|
@ -698,7 +725,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
|
||||
public void onClick( View view )
|
||||
public void onClick( View view )
|
||||
{
|
||||
if ( isFinishing() ) {
|
||||
// do nothing; we're on the way out
|
||||
|
@ -714,7 +741,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
} else if ( m_joinPublicCheck == view ) {
|
||||
adjustConnectStuff();
|
||||
} else if ( m_gameLockedCheck == view ) {
|
||||
showNotAgainDlgThen( R.string.not_again_unlock,
|
||||
showNotAgainDlgThen( R.string.not_again_unlock,
|
||||
R.string.key_notagain_unlock,
|
||||
Action.LOCKED_CHANGE_ACTION );
|
||||
} else if ( m_refreshRoomsButton == view ) {
|
||||
|
@ -727,26 +754,19 @@ public class GameConfigDelegate extends DelegateBase
|
|||
// from here if there's no confirmation needed, or launch
|
||||
// a new dialog whose OK button does the same thing.
|
||||
saveChanges();
|
||||
|
||||
if ( !localOnlyGame() && 0 == m_conTypes.size() ) {
|
||||
showConfirmThen( R.string.config_no_connvia,
|
||||
R.string.button_discard,
|
||||
R.string.button_discard,
|
||||
R.string.button_edit,
|
||||
Action.DELETE_AND_EXIT );
|
||||
} else if ( m_forResult ) {
|
||||
applyChanges( true );
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_rowid );
|
||||
setResult( Activity.RESULT_OK, intent );
|
||||
finish();
|
||||
} else if ( !m_gameStarted ) { // no confirm needed
|
||||
applyChanges( true );
|
||||
launchGame();
|
||||
} else if ( m_giOrig.changesMatter(m_gi)
|
||||
} else if ( m_isNewGame || !m_gameStarted ) {
|
||||
saveAndClose( true );
|
||||
} else if ( m_giOrig.changesMatter(m_gi)
|
||||
|| m_carOrig.changesMatter(m_car) ) {
|
||||
showDialog( DlgID.CONFIRM_CHANGE_PLAY );
|
||||
} else {
|
||||
applyChanges( false );
|
||||
launchGame();
|
||||
finishAndLaunch();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -754,18 +774,48 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
} // onClick
|
||||
|
||||
private void saveAndClose( boolean forceNew )
|
||||
{
|
||||
DbgUtils.logf( "GameConfigDelegate.saveAndClose(forceNew=%b)",
|
||||
forceNew );
|
||||
applyChanges( forceNew );
|
||||
|
||||
finishAndLaunch();
|
||||
}
|
||||
|
||||
private void finishAndLaunch()
|
||||
{
|
||||
if ( !m_haveClosed ) {
|
||||
m_haveClosed = true;
|
||||
DbgUtils.logf( "GameConfigDelegate.finishAndLaunch()" );
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra( GameUtils.INTENT_KEY_ROWID, m_rowid );
|
||||
setResult( Activity.RESULT_OK, intent );
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void closeNoSave()
|
||||
{
|
||||
if ( !m_haveClosed ) {
|
||||
m_haveClosed = true;
|
||||
setResult( Activity.RESULT_CANCELED, null );
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onBackPressed()
|
||||
protected boolean handleBackPressed()
|
||||
{
|
||||
boolean consumed = false;
|
||||
if ( ! isFinishing() ) {
|
||||
if ( m_forResult ) {
|
||||
if ( m_isNewGame ) {
|
||||
deleteGame();
|
||||
} else {
|
||||
saveChanges();
|
||||
if ( !m_gameStarted ) { // no confirm needed
|
||||
if ( !m_gameStarted ) { // no confirm needed
|
||||
applyChanges( true );
|
||||
} else if ( m_giOrig.changesMatter(m_gi)
|
||||
} else if ( m_giOrig.changesMatter(m_gi)
|
||||
|| m_carOrig.changesMatter(m_car) ) {
|
||||
showDialog( DlgID.CONFIRM_CHANGE );
|
||||
consumed = true; // don't dismiss activity yet!
|
||||
|
@ -778,6 +828,12 @@ public class GameConfigDelegate extends DelegateBase
|
|||
return consumed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GameConfigDelegate curThis()
|
||||
{
|
||||
return (GameConfigDelegate)super.curThis();
|
||||
}
|
||||
|
||||
private void deleteGame()
|
||||
{
|
||||
GameUtils.deleteGame( m_activity, m_rowid, false );
|
||||
|
@ -799,7 +855,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
showDialog( DlgID.PLAYER_EDIT );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
boolean localGame = localOnlyGame();
|
||||
boolean unlocked = null == m_gameLockedCheck
|
||||
|| !m_gameLockedCheck.isChecked();
|
||||
|
@ -845,20 +901,20 @@ public class GameConfigDelegate extends DelegateBase
|
|||
{
|
||||
if ( null != dictsSpinner ) {
|
||||
String langName = DictLangCache.getLangName( m_activity, lang );
|
||||
dictsSpinner.setPrompt( getString( R.string.dicts_list_prompt_fmt,
|
||||
dictsSpinner.setPrompt( getString( R.string.dicts_list_prompt_fmt,
|
||||
langName ) );
|
||||
|
||||
OnItemSelectedListener onSel =
|
||||
OnItemSelectedListener onSel =
|
||||
new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected( AdapterView<?> parentView,
|
||||
View selectedItemView,
|
||||
public void onItemSelected( AdapterView<?> parentView,
|
||||
View selectedItemView,
|
||||
int position, long id ) {
|
||||
String chosen =
|
||||
String chosen =
|
||||
(String)parentView.getItemAtPosition( position );
|
||||
|
||||
if ( chosen.equals( m_browseText ) ) {
|
||||
DictsDelegate.downloadForResult( m_activity,
|
||||
DictsDelegate.downloadForResult( m_activity,
|
||||
RequestCode.REQUEST_DICT,
|
||||
m_gi.dictLang );
|
||||
}
|
||||
|
@ -868,7 +924,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
public void onNothingSelected(AdapterView<?> parentView) {}
|
||||
};
|
||||
|
||||
ArrayAdapter<String> adapter =
|
||||
ArrayAdapter<String> adapter =
|
||||
DictLangCache.getDictsAdapter( m_activity, lang );
|
||||
|
||||
configSpinnerWDownload( dictsSpinner, adapter, onSel, curDict );
|
||||
|
@ -882,17 +938,17 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
final LangsArrayAdapter adapter = DictLangCache.getLangsAdapter( m_activity );
|
||||
|
||||
OnItemSelectedListener onSel =
|
||||
OnItemSelectedListener onSel =
|
||||
new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parentView,
|
||||
View selectedItemView,
|
||||
public void onItemSelected(AdapterView<?> parentView,
|
||||
View selectedItemView,
|
||||
int position, long id ) {
|
||||
if ( ! isFinishing() ) { // not on the way out?
|
||||
String chosen =
|
||||
String chosen =
|
||||
(String)parentView.getItemAtPosition( position );
|
||||
if ( chosen.equals( m_browseText ) ) {
|
||||
DictsDelegate.downloadForResult( m_activity,
|
||||
DictsDelegate.downloadForResult( m_activity,
|
||||
RequestCode
|
||||
.REQUEST_LANG_GC );
|
||||
} else {
|
||||
|
@ -918,7 +974,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
configDictSpinner( m_dictSpinner, m_gi.dictLang, m_gi.dictName );
|
||||
}
|
||||
|
||||
private void configSpinnerWDownload( Spinner spinner,
|
||||
private void configSpinnerWDownload( Spinner spinner,
|
||||
ArrayAdapter adapter,
|
||||
OnItemSelectedListener onSel,
|
||||
String curSel )
|
||||
|
@ -972,7 +1028,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
setting = 2;
|
||||
break;
|
||||
default:
|
||||
DbgUtils.logf( "setSmartnessSpinner got %d from getRobotSmartness()",
|
||||
DbgUtils.logf( "setSmartnessSpinner got %d from getRobotSmartness()",
|
||||
m_gi.getRobotSmartness() );
|
||||
Assert.fail();
|
||||
}
|
||||
|
@ -1021,7 +1077,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
} else {
|
||||
int remoteCount = m_gi.remoteCount();
|
||||
label = getString( R.string.players_label_host_fmt,
|
||||
m_gi.nPlayers - remoteCount,
|
||||
m_gi.nPlayers - remoteCount,
|
||||
remoteCount );
|
||||
}
|
||||
((TextView)findViewById( R.id.players_label )).setText( label );
|
||||
|
@ -1062,8 +1118,8 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int layoutForDlg( DlgID dlgID )
|
||||
|
||||
private int layoutForDlg( DlgID dlgID )
|
||||
{
|
||||
switch( dlgID ) {
|
||||
// case ROLE_EDIT_RELAY:
|
||||
|
@ -1079,7 +1135,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
return 0;
|
||||
}
|
||||
|
||||
// private int titleForDlg( int id )
|
||||
// private int titleForDlg( int id )
|
||||
// {
|
||||
// switch( id ) {
|
||||
// // case ROLE_EDIT_RELAY:
|
||||
|
@ -1127,7 +1183,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
m_gi.hintsNotAllowed = !getChecked( R.id.hints_allowed );
|
||||
m_gi.allowPickTiles = getChecked( R.id.pick_faceup );
|
||||
m_gi.timerEnabled = getChecked( R.id.use_timer );
|
||||
m_gi.gameSeconds =
|
||||
m_gi.gameSeconds =
|
||||
60 * m_gi.nPlayers * getInt( R.id.timer_minutes_edit );
|
||||
|
||||
int position = m_phoniesSpinner.getSelectedItemPosition();
|
||||
|
@ -1141,7 +1197,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
|
||||
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) ) {
|
||||
m_car.ip_relay_seeksPublicRoom = m_joinPublicCheck.isChecked();
|
||||
m_car.ip_relay_advertiseRoom =
|
||||
m_car.ip_relay_advertiseRoom =
|
||||
getChecked( R.id.advertise_new_room_check );
|
||||
if ( m_car.ip_relay_seeksPublicRoom ) {
|
||||
SpinnerAdapter adapter = m_roomChoose.getAdapter();
|
||||
|
@ -1162,28 +1218,32 @@ public class GameConfigDelegate extends DelegateBase
|
|||
private void applyChanges( boolean forceNew )
|
||||
{
|
||||
if ( !isFinishing() ) {
|
||||
GameLock gameLock = new GameLock( m_rowid, true ).lock();
|
||||
GameUtils.applyChanges( m_activity, m_gi, m_car, gameLock,
|
||||
GameLock gameLock = m_jniThread == null
|
||||
? new GameLock( m_rowid, true ).lock()
|
||||
: m_jniThread.getLock();
|
||||
GameUtils.applyChanges( m_activity, m_gi, m_car, gameLock,
|
||||
forceNew );
|
||||
DBUtils.saveThumbnail( m_activity, gameLock, null ); // clear it
|
||||
gameLock.unlock();
|
||||
if ( null == m_jniThread ) {
|
||||
gameLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void launchGame()
|
||||
private void launchGame( boolean forceNew )
|
||||
{
|
||||
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY )
|
||||
&& 0 == m_car.ip_relay_invite.length() ) {
|
||||
showOKOnlyDialog( R.string.no_empty_rooms );
|
||||
showOKOnlyDialog( R.string.no_empty_rooms );
|
||||
} else {
|
||||
GameUtils.launchGameAndFinish( getDelegator(), m_rowid );
|
||||
saveAndClose( forceNew );
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshNames()
|
||||
{
|
||||
if ( !m_isLocked ) {
|
||||
new RefreshNamesTask( m_activity, this, m_gi.dictLang,
|
||||
new RefreshNamesTask( m_activity, this, m_gi.dictLang,
|
||||
m_gi.nPlayers, m_roomChoose ).execute();
|
||||
}
|
||||
}
|
||||
|
@ -1205,19 +1265,19 @@ public class GameConfigDelegate extends DelegateBase
|
|||
return DeviceRole.SERVER_STANDALONE == m_giOrig.serverRole;
|
||||
}
|
||||
|
||||
public static void editForResult( Delegator delegator,
|
||||
RequestCode requestCode,
|
||||
long rowID )
|
||||
public static void editForResult( Delegator delegator,
|
||||
RequestCode requestCode,
|
||||
long rowID, boolean newGame )
|
||||
{
|
||||
Activity activity = delegator.getActivity();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong( GameUtils.INTENT_KEY_ROWID, rowID );
|
||||
bundle.putBoolean( INTENT_FORRESULT_ROWID, true );
|
||||
|
||||
if ( activity instanceof FragActivity ) {
|
||||
FragActivity.addFragmentForResult( new GameConfigFrag(), bundle,
|
||||
requestCode, delegator );
|
||||
bundle.putBoolean( INTENT_FORRESULT_NEWGAME, newGame );
|
||||
|
||||
if ( delegator.inDPMode() ) {
|
||||
delegator.addFragmentForResult( new GameConfigFrag( delegator ),
|
||||
bundle, requestCode );
|
||||
} else {
|
||||
Activity activity = delegator.getActivity();
|
||||
Intent intent = new Intent( activity, GameConfigActivity.class );
|
||||
intent.setAction( Intent.ACTION_EDIT );
|
||||
intent.putExtras( bundle );
|
||||
|
@ -1242,7 +1302,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
boolean publicEnabled = XWPrefs.getPublicRoomsEnabled( m_activity );
|
||||
int vis = publicEnabled ? View.VISIBLE : View.GONE;
|
||||
if ( reset || null == m_joinPublicCheck ) {
|
||||
m_joinPublicCheck =
|
||||
m_joinPublicCheck =
|
||||
(CheckBox)findViewById(R.id.join_public_room_check);
|
||||
m_joinPublicCheck.setVisibility( vis );
|
||||
|
||||
|
@ -1253,18 +1313,18 @@ public class GameConfigDelegate extends DelegateBase
|
|||
m_joinPublicCheck.setOnClickListener( this );
|
||||
m_joinPublicCheck.setChecked( m_car.ip_relay_seeksPublicRoom );
|
||||
advertise.setChecked( m_car.ip_relay_advertiseRoom );
|
||||
m_publicRoomsSet =
|
||||
m_publicRoomsSet =
|
||||
(LinearLayout)findViewById(R.id.public_rooms_set );
|
||||
m_privateRoomsSet =
|
||||
m_privateRoomsSet =
|
||||
(LinearLayout)findViewById(R.id.private_rooms_set );
|
||||
}
|
||||
|
||||
setText( R.id.room_edit, m_car.ip_relay_invite );
|
||||
|
||||
|
||||
m_roomChoose = (Spinner)findViewById( R.id.room_spinner );
|
||||
m_roomChoose.setVisibility( vis );
|
||||
|
||||
m_refreshRoomsButton =
|
||||
m_refreshRoomsButton =
|
||||
(ImageButton)findViewById( R.id.refresh_button );
|
||||
m_refreshRoomsButton.setVisibility( vis );
|
||||
m_refreshRoomsButton.setOnClickListener( this );
|
||||
|
|
|
@ -23,6 +23,8 @@ import android.os.Bundle;
|
|||
|
||||
public class GameConfigFrag extends XWFragment {
|
||||
|
||||
public GameConfigFrag( Delegator parent ) { super( parent ); }
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle sis )
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ import android.widget.TextView;
|
|||
import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class GameListGroup extends ExpiringLinearLayout
|
||||
public class GameListGroup extends ExpiringLinearLayout
|
||||
implements SelectableItem.LongClickHandler,
|
||||
View.OnClickListener,
|
||||
View.OnLongClickListener
|
||||
|
@ -81,7 +81,7 @@ public class GameListGroup extends ExpiringLinearLayout
|
|||
return result;
|
||||
}
|
||||
|
||||
public GameListGroup( Context cx, AttributeSet as )
|
||||
public GameListGroup( Context cx, AttributeSet as )
|
||||
{
|
||||
super( cx, as );
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ public class GameListGroup extends ExpiringLinearLayout
|
|||
//////////////////////////////////////////////////
|
||||
// View.OnLongClickListener interface
|
||||
//////////////////////////////////////////////////
|
||||
public boolean onLongClick( View view )
|
||||
public boolean onLongClick( View view )
|
||||
{
|
||||
boolean handled = ! XWApp.CONTEXT_MENUS_ENABLED;
|
||||
if ( handled ) {
|
||||
|
@ -149,7 +149,7 @@ public class GameListGroup extends ExpiringLinearLayout
|
|||
//////////////////////////////////////////////////
|
||||
// View.OnClickListener interface
|
||||
//////////////////////////////////////////////////
|
||||
public void onClick( View view )
|
||||
public void onClick( View view )
|
||||
{
|
||||
if ( 0 < m_nGames ) {
|
||||
m_expanded = !m_expanded;
|
||||
|
@ -161,7 +161,7 @@ public class GameListGroup extends ExpiringLinearLayout
|
|||
private void setButton()
|
||||
{
|
||||
if ( null != m_expandButton ) {
|
||||
m_expandButton.setVisibility( 0 == m_nGames ?
|
||||
m_expandButton.setVisibility( 0 == m_nGames ?
|
||||
View.GONE : View.VISIBLE );
|
||||
m_expandButton.setImageResource( m_expanded ?
|
||||
R.drawable.expander_ic_maximized :
|
||||
|
|
|
@ -48,11 +48,11 @@ import org.eehouse.android.xw4.jni.GameSummary;
|
|||
import org.eehouse.android.xw4.jni.JNIThread;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class GameListItem extends LinearLayout
|
||||
public class GameListItem extends LinearLayout
|
||||
implements View.OnClickListener, SelectableItem.LongClickHandler {
|
||||
|
||||
private static final int SUMMARY_WAIT_MSECS = 1000;
|
||||
|
||||
|
||||
private static HashSet<Long> s_invalRows = new HashSet<Long>();
|
||||
|
||||
private Activity m_activity;
|
||||
|
@ -81,7 +81,7 @@ public class GameListItem extends LinearLayout
|
|||
private boolean m_selected = false;
|
||||
private DrawSelDelegate m_dsdel;
|
||||
|
||||
public GameListItem( Context cx, AttributeSet as )
|
||||
public GameListItem( Context cx, AttributeSet as )
|
||||
{
|
||||
super( cx, as );
|
||||
m_context = cx;
|
||||
|
@ -111,7 +111,7 @@ public class GameListItem extends LinearLayout
|
|||
return m_summary;
|
||||
}
|
||||
|
||||
private void init( Handler handler, long rowid, int fieldID,
|
||||
private void init( Handler handler, long rowid, int fieldID,
|
||||
SelectableItem cb )
|
||||
{
|
||||
m_handler = handler;
|
||||
|
@ -149,7 +149,7 @@ public class GameListItem extends LinearLayout
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw( Canvas canvas )
|
||||
protected void onDraw( Canvas canvas )
|
||||
{
|
||||
super.onDraw( canvas );
|
||||
if ( DBUtils.ROWID_NOTFOUND != m_rowid ) {
|
||||
|
@ -198,9 +198,7 @@ public class GameListItem extends LinearLayout
|
|||
m_state = (TextView)findViewById( R.id.state );
|
||||
m_modTime = (TextView)findViewById( R.id.modtime );
|
||||
m_marker = (ImageView)findViewById( R.id.msg_marker );
|
||||
if ( BuildConstants.THUMBNAIL_SUPPORTED ) {
|
||||
m_thumb = (ImageView)findViewById( R.id.thumbnail );
|
||||
}
|
||||
m_thumb = (ImageView)findViewById( R.id.thumbnail );
|
||||
m_role = (TextView)findViewById( R.id.role );
|
||||
}
|
||||
|
||||
|
@ -221,14 +219,13 @@ public class GameListItem extends LinearLayout
|
|||
R.drawable.expander_ic_maximized :
|
||||
R.drawable.expander_ic_minimized);
|
||||
m_hideable.setVisibility( m_expanded? View.VISIBLE : View.GONE );
|
||||
if ( BuildConstants.THUMBNAIL_SUPPORTED ) {
|
||||
int vis = m_expanded && XWPrefs.getThumbEnabled( m_context )
|
||||
? View.VISIBLE : View.GONE;
|
||||
m_thumb.setVisibility( vis );
|
||||
}
|
||||
|
||||
int vis = m_expanded && XWPrefs.getThumbEnabled( m_context )
|
||||
? View.VISIBLE : View.GONE;
|
||||
m_thumb.setVisibility( vis );
|
||||
|
||||
m_name.setBackgroundColor( android.R.color.transparent );
|
||||
m_name.setPct( m_handler, m_haveTurn && !m_expanded,
|
||||
m_name.setPct( m_handler, m_haveTurn && !m_expanded,
|
||||
m_haveTurnLocal, m_lastMoveTime );
|
||||
}
|
||||
|
||||
|
@ -251,8 +248,8 @@ public class GameListItem extends LinearLayout
|
|||
value = String.format( "%d", m_summary.nPacketsPending );
|
||||
break;
|
||||
case R.string.game_summary_field_language:
|
||||
value =
|
||||
DictLangCache.getLangName( m_context,
|
||||
value =
|
||||
DictLangCache.getLangName( m_context,
|
||||
m_summary.dictLang );
|
||||
value = LocUtils.xlateLang( m_context, value, true );
|
||||
break;
|
||||
|
@ -266,12 +263,12 @@ public class GameListItem extends LinearLayout
|
|||
|
||||
String name = GameUtils.getName( m_context, m_rowid );
|
||||
if ( null != value ) {
|
||||
value = LocUtils.getString( m_context, R.string.str_game_name_fmt,
|
||||
value = LocUtils.getString( m_context, R.string.str_game_name_fmt,
|
||||
name, value );
|
||||
} else {
|
||||
value = name;
|
||||
}
|
||||
|
||||
|
||||
m_name.setText( value );
|
||||
}
|
||||
return state;
|
||||
|
@ -300,7 +297,7 @@ public class GameListItem extends LinearLayout
|
|||
haveALocalTurn = true;
|
||||
}
|
||||
}
|
||||
tmp.setPct( m_handler, thisHasTurn, isLocal[0],
|
||||
tmp.setPct( m_handler, thisHasTurn, isLocal[0],
|
||||
summary.lastMoveTime );
|
||||
m_list.addView( tmp, ii );
|
||||
}
|
||||
|
@ -309,7 +306,7 @@ public class GameListItem extends LinearLayout
|
|||
|
||||
long lastMoveTime = summary.lastMoveTime;
|
||||
lastMoveTime *= 1000;
|
||||
DateFormat df = DateFormat.getDateTimeInstance( DateFormat.SHORT,
|
||||
DateFormat df = DateFormat.getDateTimeInstance( DateFormat.SHORT,
|
||||
DateFormat.SHORT );
|
||||
m_modTime.setText( df.format( new Date( lastMoveTime ) ) );
|
||||
|
||||
|
@ -330,7 +327,7 @@ public class GameListItem extends LinearLayout
|
|||
m_role.setVisibility( View.GONE );
|
||||
}
|
||||
|
||||
update( expanded, summary.lastMoveTime, haveATurn,
|
||||
update( expanded, summary.lastMoveTime, haveATurn,
|
||||
haveALocalTurn );
|
||||
}
|
||||
}
|
||||
|
@ -352,35 +349,39 @@ public class GameListItem extends LinearLayout
|
|||
|
||||
private class LoadItemTask extends AsyncTask<Void, Void, GameSummary> {
|
||||
@Override
|
||||
protected GameSummary doInBackground( Void... unused )
|
||||
protected GameSummary doInBackground( Void... unused )
|
||||
{
|
||||
return DBUtils.getSummary( m_context, m_rowid, SUMMARY_WAIT_MSECS );
|
||||
GameSummary result = null;
|
||||
|
||||
JNIThread thread = JNIThread.getRetained( m_rowid );
|
||||
if ( null != thread ) {
|
||||
GameLock lock = thread.getLock();
|
||||
if ( null != lock ) {
|
||||
result = DBUtils.getSummary( m_context, lock );
|
||||
}
|
||||
thread.release( false );
|
||||
}
|
||||
|
||||
if ( null == result ) {
|
||||
result = DBUtils.getSummary( m_context, m_rowid, SUMMARY_WAIT_MSECS );
|
||||
}
|
||||
return result;
|
||||
} // doInBackground
|
||||
|
||||
@Override
|
||||
protected void onPostExecute( GameSummary summary )
|
||||
{
|
||||
if ( 0 == --m_loadingCount ) {
|
||||
if ( null == summary ) {
|
||||
// Try again. Maybe it's open
|
||||
JNIThread thread = JNIThread.getRetained( m_rowid );
|
||||
if ( null != thread ) {
|
||||
summary = DBUtils.getSummary( m_context,
|
||||
thread.getLock() );
|
||||
thread.release();
|
||||
}
|
||||
}
|
||||
|
||||
m_summary = summary;
|
||||
boolean expanded = DBUtils.getExpanded( m_context, m_rowid );
|
||||
|
||||
boolean expanded = DBUtils.getExpanded( m_context, m_rowid );
|
||||
makeThumbnailIf( expanded );
|
||||
|
||||
setData( summary, expanded );
|
||||
setLoaded( null != m_summary );
|
||||
if ( null == summary ) {
|
||||
m_viewUnloaded
|
||||
.setText( LocUtils.getString( m_context,
|
||||
.setText( LocUtils.getString( m_context,
|
||||
R.string.summary_busy ) );
|
||||
}
|
||||
synchronized( s_invalRows ) {
|
||||
|
@ -391,14 +392,14 @@ public class GameListItem extends LinearLayout
|
|||
} // class LoadItemTask
|
||||
|
||||
public static GameListItem makeForRow( Context context, View convertView,
|
||||
long rowid, Handler handler,
|
||||
long rowid, Handler handler,
|
||||
int fieldID, SelectableItem cb )
|
||||
{
|
||||
GameListItem result;
|
||||
if ( null != convertView && convertView instanceof GameListItem ) {
|
||||
result = (GameListItem)convertView;
|
||||
} else {
|
||||
result = (GameListItem)LocUtils.inflate( context,
|
||||
result = (GameListItem)LocUtils.inflate( context,
|
||||
R.layout.game_list_item );
|
||||
result.findViews();
|
||||
}
|
||||
|
@ -406,7 +407,7 @@ public class GameListItem extends LinearLayout
|
|||
return result;
|
||||
}
|
||||
|
||||
public static void inval( long rowid )
|
||||
public static void inval( long rowid )
|
||||
{
|
||||
synchronized( s_invalRows ) {
|
||||
s_invalRows.add( rowid );
|
||||
|
@ -448,14 +449,12 @@ public class GameListItem extends LinearLayout
|
|||
|
||||
private static void enqueueGetThumbnail( GameListItem item, long rowid )
|
||||
{
|
||||
if ( BuildConstants.THUMBNAIL_SUPPORTED ) {
|
||||
s_queue.add( new ThumbQueueElem( item, rowid ) );
|
||||
s_queue.add( new ThumbQueueElem( item, rowid ) );
|
||||
|
||||
synchronized( GameListItem.class ) {
|
||||
if ( null == s_thumbThread ) {
|
||||
s_thumbThread = makeThumbThread();
|
||||
s_thumbThread.start();
|
||||
}
|
||||
synchronized( GameListItem.class ) {
|
||||
if ( null == s_thumbThread ) {
|
||||
s_thumbThread = makeThumbThread();
|
||||
s_thumbThread.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,10 +44,10 @@ public class GameLock {
|
|||
|
||||
public static class GameLockedException extends RuntimeException {}
|
||||
|
||||
private static HashMap<Long, GameLock>
|
||||
private static HashMap<Long, GameLock>
|
||||
s_locks = new HashMap<Long,GameLock>();
|
||||
|
||||
public GameLock( long rowid, boolean isForWrite )
|
||||
public GameLock( long rowid, boolean isForWrite )
|
||||
{
|
||||
Assert.assertTrue( DBUtils.ROWID_NOTFOUND != rowid );
|
||||
m_rowid = rowid;
|
||||
|
@ -78,7 +78,7 @@ public class GameLock {
|
|||
s_locks.put( m_rowid, this );
|
||||
++m_lockCount;
|
||||
gotIt = true;
|
||||
|
||||
|
||||
if ( DEBUG_LOCKS ) {
|
||||
StackTraceElement[] trace
|
||||
= Thread.currentThread().getStackTrace();
|
||||
|
@ -94,17 +94,17 @@ public class GameLock {
|
|||
gotIt = true;
|
||||
owner = null;
|
||||
} else if ( DEBUG_LOCKS ) {
|
||||
DbgUtils.logf( "tryLock(): rowid %d already held by lock %H",
|
||||
DbgUtils.logf( "tryLock(): rowid %d already held by lock %H",
|
||||
m_rowid, owner );
|
||||
}
|
||||
}
|
||||
if ( DEBUG_LOCKS ) {
|
||||
DbgUtils.logf( "GameLock.tryLock %H (rowid=%d) => %b",
|
||||
DbgUtils.logf( "GameLock.tryLock %H (rowid=%d) => %b",
|
||||
this, m_rowid, gotIt );
|
||||
}
|
||||
return owner;
|
||||
}
|
||||
|
||||
|
||||
// Wait forever (but may assert if too long)
|
||||
public GameLock lock()
|
||||
{
|
||||
|
@ -120,7 +120,7 @@ public class GameLock {
|
|||
long sleptTime = 0;
|
||||
|
||||
if ( DEBUG_LOCKS ) {
|
||||
DbgUtils.logf( "lock %H (rowid:%d, maxMillis=%d)", this, m_rowid,
|
||||
DbgUtils.logf( "lock %H (rowid:%d, maxMillis=%d)", this, m_rowid,
|
||||
maxMillis );
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ public class GameLock {
|
|||
if ( DEBUG_LOCKS ) {
|
||||
DbgUtils.logf( "lock %H overlocked", this );
|
||||
}
|
||||
Assert.fail(); // firing
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
// DbgUtils.logf( "GameLock.lock(%s) done", m_path );
|
||||
|
@ -180,13 +180,13 @@ public class GameLock {
|
|||
--m_lockCount;
|
||||
|
||||
if ( DEBUG_LOCKS ) {
|
||||
DbgUtils.logf( "GameLock.unlock: this: %H (rowid:%d) unlocked",
|
||||
DbgUtils.logf( "GameLock.unlock: this: %H (rowid:%d) unlocked",
|
||||
this, m_rowid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long getRowid()
|
||||
public long getRowid()
|
||||
{
|
||||
return m_rowid;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public class GameUtils {
|
|||
* Open an existing game, and use its gi and comms addr as the
|
||||
* basis for a new one.
|
||||
*/
|
||||
public static GameLock resetGame( Context context, GameLock lockSrc,
|
||||
public static GameLock resetGame( Context context, GameLock lockSrc,
|
||||
GameLock lockDest, boolean juggle )
|
||||
{
|
||||
CurGameInfo gi = new CurGameInfo( context );
|
||||
|
@ -112,7 +112,7 @@ public class GameUtils {
|
|||
GamePtr gamePtr = loadMakeGame( context, gi, lockSrc );
|
||||
String[] dictNames = gi.dictNames();
|
||||
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );
|
||||
|
||||
|
||||
if ( XwJNI.game_hasComms( gamePtr ) ) {
|
||||
addr = new CommsAddrRec();
|
||||
XwJNI.comms_getAddr( gamePtr, addr );
|
||||
|
@ -123,12 +123,12 @@ public class GameUtils {
|
|||
}
|
||||
}
|
||||
gamePtr.release();
|
||||
|
||||
|
||||
gamePtr = XwJNI.initJNI();
|
||||
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get( context ),
|
||||
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get( context ),
|
||||
CommonPrefs.get( context ), dictNames,
|
||||
pairs.m_bytes, pairs.m_paths, gi.langName() );
|
||||
|
||||
|
||||
if ( juggle ) {
|
||||
gi.juggle();
|
||||
}
|
||||
|
@ -150,8 +150,9 @@ public class GameUtils {
|
|||
return lockDest;
|
||||
} // resetGame
|
||||
|
||||
public static void resetGame( Context context, long rowidIn )
|
||||
public static boolean resetGame( Context context, long rowidIn )
|
||||
{
|
||||
boolean success = false;
|
||||
GameLock lock = new GameLock( rowidIn, true ).lock( 500 );
|
||||
if ( null != lock ) {
|
||||
tellDied( context, lock, true );
|
||||
|
@ -159,9 +160,11 @@ public class GameUtils {
|
|||
lock.unlock();
|
||||
|
||||
Utils.cancelNotification( context, (int)rowidIn );
|
||||
success = true;
|
||||
} else {
|
||||
DbgUtils.logf( "resetGame: unable to open rowid %d", rowidIn );
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
private static int setFromFeedImpl( FeedUtilsImpl feedImpl )
|
||||
|
@ -169,7 +172,7 @@ public class GameUtils {
|
|||
int result = GameSummary.MSG_FLAGS_NONE;
|
||||
if ( feedImpl.m_gotChat ) {
|
||||
result |= GameSummary.MSG_FLAGS_CHAT;
|
||||
}
|
||||
}
|
||||
if ( feedImpl.m_gotMsg ) {
|
||||
result |= GameSummary.MSG_FLAGS_TURN;
|
||||
}
|
||||
|
@ -179,9 +182,9 @@ public class GameUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static GameSummary summarizeAndClose( Context context,
|
||||
private static GameSummary summarizeAndClose( Context context,
|
||||
GameLock lock,
|
||||
GamePtr gamePtr,
|
||||
GamePtr gamePtr,
|
||||
CurGameInfo gi )
|
||||
{
|
||||
GameSummary summary = new GameSummary( context, gi );
|
||||
|
@ -227,7 +230,7 @@ public class GameUtils {
|
|||
DBUtils.deleteGame( context, lock );
|
||||
}
|
||||
|
||||
public static boolean deleteGame( Context context, long rowid,
|
||||
public static boolean deleteGame( Context context, long rowid,
|
||||
boolean informNow )
|
||||
{
|
||||
boolean success;
|
||||
|
@ -274,25 +277,32 @@ public class GameUtils {
|
|||
return LocUtils.getString( context, R.string.game_fmt, count );
|
||||
}
|
||||
|
||||
public static GamePtr loadMakeGame( Context context, CurGameInfo gi,
|
||||
public static GamePtr loadMakeGame( Context context, CurGameInfo gi,
|
||||
TransportProcs tp, GameLock lock )
|
||||
{
|
||||
return loadMakeGame( context, gi, null, tp, lock );
|
||||
}
|
||||
|
||||
public static GamePtr loadMakeGame( Context context, CurGameInfo gi,
|
||||
public static GamePtr loadMakeGame( Context context, CurGameInfo gi,
|
||||
GameLock lock )
|
||||
{
|
||||
return loadMakeGame( context, gi, null, null, lock );
|
||||
}
|
||||
|
||||
public static GamePtr loadMakeGame( Context context, CurGameInfo gi,
|
||||
UtilCtxt util, TransportProcs tp,
|
||||
public static GamePtr loadMakeGame( Context context, CurGameInfo gi,
|
||||
UtilCtxt util, TransportProcs tp,
|
||||
GameLock lock )
|
||||
{
|
||||
byte[] stream = savedGame( context, lock );
|
||||
return loadMakeGame( context, gi, util, tp, stream, lock.getRowid() );
|
||||
}
|
||||
|
||||
private static GamePtr loadMakeGame( Context context, CurGameInfo gi,
|
||||
UtilCtxt util, TransportProcs tp,
|
||||
byte[] stream, long rowid )
|
||||
{
|
||||
GamePtr gamePtr = null;
|
||||
|
||||
byte[] stream = savedGame( context, lock );
|
||||
if ( null == stream ) {
|
||||
DbgUtils.logf( "loadMakeGame: no saved game!");
|
||||
} else {
|
||||
|
@ -300,23 +310,23 @@ public class GameUtils {
|
|||
String[] dictNames = gi.dictNames();
|
||||
DictUtils.DictPairs pairs = DictUtils.openDicts( context, dictNames );
|
||||
if ( pairs.anyMissing( dictNames ) ) {
|
||||
DbgUtils.logf( "loadMakeGame() failing: dicts %s unavailable",
|
||||
DbgUtils.logf( "loadMakeGame() failing: dicts %s unavailable",
|
||||
TextUtils.join( ",", dictNames ) );
|
||||
} else {
|
||||
gamePtr = XwJNI.initJNI( lock.getRowid() );
|
||||
gamePtr = XwJNI.initJNI( rowid );
|
||||
|
||||
String langName = gi.langName();
|
||||
boolean madeGame =
|
||||
XwJNI.game_makeFromStream( gamePtr, stream, gi,
|
||||
dictNames, pairs.m_bytes,
|
||||
boolean madeGame =
|
||||
XwJNI.game_makeFromStream( gamePtr, stream, gi,
|
||||
dictNames, pairs.m_bytes,
|
||||
pairs.m_paths, langName,
|
||||
util, JNIUtilsImpl.get( context ),
|
||||
util, JNIUtilsImpl.get( context ),
|
||||
CommonPrefs.get(context),
|
||||
tp);
|
||||
if ( !madeGame ) {
|
||||
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(context),
|
||||
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(context),
|
||||
CommonPrefs.get(context), dictNames,
|
||||
pairs.m_bytes, pairs.m_paths,
|
||||
pairs.m_bytes, pairs.m_paths,
|
||||
langName );
|
||||
}
|
||||
}
|
||||
|
@ -324,59 +334,72 @@ public class GameUtils {
|
|||
return gamePtr;
|
||||
}
|
||||
|
||||
public static Bitmap loadMakeBitmap( Activity activity, long rowid )
|
||||
public static Bitmap loadMakeBitmap( Context context, long rowid )
|
||||
{
|
||||
Bitmap thumb = null;
|
||||
GameLock lock = new GameLock( rowid, false );
|
||||
if ( lock.tryLock() ) {
|
||||
CurGameInfo gi = new CurGameInfo( activity );
|
||||
GamePtr gamePtr = loadMakeGame( activity, gi, lock );
|
||||
CurGameInfo gi = new CurGameInfo( context );
|
||||
GamePtr gamePtr = loadMakeGame( context, gi, lock );
|
||||
if ( null != gamePtr ) {
|
||||
thumb = takeSnapshot( activity, gamePtr, gi );
|
||||
thumb = takeSnapshot( context, gamePtr, gi );
|
||||
gamePtr.release();
|
||||
DBUtils.saveThumbnail( activity, lock, thumb );
|
||||
DBUtils.saveThumbnail( context, lock, thumb );
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
return thumb;
|
||||
}
|
||||
|
||||
public static Bitmap takeSnapshot( Context context, GamePtr gamePtr,
|
||||
public static Bitmap loadMakeBitmap( Context context, byte[] stream,
|
||||
GameLock lock )
|
||||
{
|
||||
Bitmap thumb = null;
|
||||
CurGameInfo gi = new CurGameInfo( context );
|
||||
GamePtr gamePtr = loadMakeGame( context, gi, null, null, stream,
|
||||
lock.getRowid() );
|
||||
if ( null != gamePtr ) {
|
||||
thumb = takeSnapshot( context, gamePtr, gi );
|
||||
gamePtr.release();
|
||||
DBUtils.saveThumbnail( context, lock, thumb );
|
||||
}
|
||||
return thumb;
|
||||
}
|
||||
|
||||
public static Bitmap takeSnapshot( Context context, GamePtr gamePtr,
|
||||
CurGameInfo gi )
|
||||
{
|
||||
Bitmap thumb = null;
|
||||
if ( BuildConstants.THUMBNAIL_SUPPORTED ) {
|
||||
if ( XWPrefs.getThumbEnabled( context ) ) {
|
||||
int nCols = gi.boardSize;
|
||||
int pct = XWPrefs.getThumbPct( context );
|
||||
Assert.assertTrue( 0 < pct );
|
||||
if ( XWPrefs.getThumbEnabled( context ) ) {
|
||||
int nCols = gi.boardSize;
|
||||
int pct = XWPrefs.getThumbPct( context );
|
||||
Assert.assertTrue( 0 < pct );
|
||||
|
||||
if ( null == s_minScreen ) {
|
||||
if ( context instanceof Activity ) {
|
||||
Activity activity = (Activity)context;
|
||||
Display display =
|
||||
activity.getWindowManager().getDefaultDisplay();
|
||||
int width = display.getWidth();
|
||||
int height = display.getHeight();
|
||||
s_minScreen = new Integer( Math.min( width, height ) );
|
||||
}
|
||||
if ( null == s_minScreen ) {
|
||||
if ( context instanceof Activity ) {
|
||||
Activity activity = (Activity)context;
|
||||
Display display =
|
||||
activity.getWindowManager().getDefaultDisplay();
|
||||
int width = display.getWidth();
|
||||
int height = display.getHeight();
|
||||
s_minScreen = new Integer( Math.min( width, height ) );
|
||||
}
|
||||
if ( null != s_minScreen ) {
|
||||
int dim = s_minScreen * pct / 100;
|
||||
int size = dim - (dim % nCols);
|
||||
}
|
||||
if ( null != s_minScreen ) {
|
||||
int dim = s_minScreen * pct / 100;
|
||||
int size = dim - (dim % nCols);
|
||||
|
||||
thumb = Bitmap.createBitmap( size, size,
|
||||
Bitmap.Config.ARGB_8888 );
|
||||
thumb = Bitmap.createBitmap( size, size,
|
||||
Bitmap.Config.ARGB_8888 );
|
||||
|
||||
XwJNI.board_figureLayout( gamePtr, gi, 0, 0, size, size,
|
||||
0, 0, 0, 20, 20, false, null );
|
||||
XwJNI.board_figureLayout( gamePtr, gi, 0, 0, size, size,
|
||||
0, 0, 0, 20, 20, false, null );
|
||||
|
||||
ThumbCanvas canvas = new ThumbCanvas( context, thumb );
|
||||
XwJNI.board_setDraw( gamePtr, canvas );
|
||||
XwJNI.board_invalAll( gamePtr );
|
||||
Assert.assertNotNull( gamePtr );
|
||||
XwJNI.board_draw( gamePtr );
|
||||
}
|
||||
ThumbCanvas canvas = new ThumbCanvas( context, thumb );
|
||||
XwJNI.board_setDraw( gamePtr, canvas );
|
||||
XwJNI.board_invalAll( gamePtr );
|
||||
Assert.assertNotNull( gamePtr );
|
||||
XwJNI.board_draw( gamePtr );
|
||||
}
|
||||
}
|
||||
return thumb;
|
||||
|
@ -397,7 +420,7 @@ public class GameUtils {
|
|||
}
|
||||
|
||||
if ( force ) {
|
||||
HashMap<Long,CommsConnTypeSet> games =
|
||||
HashMap<Long,CommsConnTypeSet> games =
|
||||
DBUtils.getGamesWithSendsPending( context );
|
||||
if ( 0 < games.size() ) {
|
||||
new ResendTask( context, games, filter, showUI ).execute();
|
||||
|
@ -410,7 +433,7 @@ public class GameUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static long saveGame( Context context, GamePtr gamePtr,
|
||||
public static long saveGame( Context context, GamePtr gamePtr,
|
||||
CurGameInfo gi, GameLock lock,
|
||||
boolean setCreate )
|
||||
{
|
||||
|
@ -428,7 +451,7 @@ public class GameUtils {
|
|||
return rowid;
|
||||
}
|
||||
|
||||
public static long saveGame( Context context, byte[] bytes,
|
||||
public static long saveGame( Context context, byte[] bytes,
|
||||
GameLock lock, boolean setCreate )
|
||||
{
|
||||
return DBUtils.saveGame( context, lock, bytes, setCreate );
|
||||
|
@ -455,7 +478,7 @@ public class GameUtils {
|
|||
long rowid = DBUtils.ROWID_NOTFOUND;
|
||||
byte[] bytes = XwJNI.gi_to_stream( gi );
|
||||
if ( null != bytes ) {
|
||||
GameLock lock = DBUtils.saveNewGame( context, bytes, groupID,
|
||||
GameLock lock = DBUtils.saveNewGame( context, bytes, groupID,
|
||||
gameName );
|
||||
rowid = lock.getRowid();
|
||||
lock.unlock();
|
||||
|
@ -465,7 +488,7 @@ public class GameUtils {
|
|||
|
||||
public static long makeNewMultiGame( Context context, NetLaunchInfo nli )
|
||||
{
|
||||
return makeNewMultiGame( context, nli, (MultiMsgSink)null,
|
||||
return makeNewMultiGame( context, nli, (MultiMsgSink)null,
|
||||
(UtilCtxt)null );
|
||||
}
|
||||
|
||||
|
@ -475,33 +498,33 @@ public class GameUtils {
|
|||
DbgUtils.logdf( "makeNewMultiGame(nli=%s)", nli.toString() );
|
||||
CommsAddrRec addr = nli.makeAddrRec( context );
|
||||
|
||||
return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC,
|
||||
addr, new int[] {nli.lang},
|
||||
new String[] { nli.dict }, null, nli.nPlayersT,
|
||||
return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC,
|
||||
addr, new int[] {nli.lang},
|
||||
new String[] { nli.dict }, null, nli.nPlayersT,
|
||||
nli.nPlayersH, nli.forceChannel,
|
||||
nli.inviteID(), nli.gameID(),
|
||||
nli.gameName, false );
|
||||
}
|
||||
|
||||
public static long makeNewMultiGame( Context context, long groupID,
|
||||
public static long makeNewMultiGame( Context context, long groupID,
|
||||
String gameName )
|
||||
{
|
||||
return makeNewMultiGame( context, groupID, null, 0, null,
|
||||
(CommsConnTypeSet)null, gameName );
|
||||
}
|
||||
|
||||
public static long makeNewMultiGame( Context context, long groupID,
|
||||
public static long makeNewMultiGame( Context context, long groupID,
|
||||
String dict, int lang, String jsonData,
|
||||
CommsConnTypeSet addrSet,
|
||||
CommsConnTypeSet addrSet,
|
||||
String gameName )
|
||||
{
|
||||
String inviteID = makeRandomID();
|
||||
return makeNewMultiGame( context, groupID, inviteID, dict, lang,
|
||||
return makeNewMultiGame( context, groupID, inviteID, dict, lang,
|
||||
jsonData, addrSet, gameName );
|
||||
}
|
||||
|
||||
private static long makeNewMultiGame( Context context, long groupID,
|
||||
String inviteID, String dict,
|
||||
private static long makeNewMultiGame( Context context, long groupID,
|
||||
String inviteID, String dict,
|
||||
int lang, String jsonData,
|
||||
CommsConnTypeSet addrSet,
|
||||
String gameName )
|
||||
|
@ -520,14 +543,14 @@ public class GameUtils {
|
|||
true );
|
||||
}
|
||||
|
||||
private static long makeNewMultiGame( Context context, MultiMsgSink sink,
|
||||
UtilCtxt util, long groupID,
|
||||
private static long makeNewMultiGame( Context context, MultiMsgSink sink,
|
||||
UtilCtxt util, long groupID,
|
||||
CommsAddrRec addr,
|
||||
int[] lang, String[] dict,
|
||||
String jsonData,
|
||||
int nPlayersT, int nPlayersH,
|
||||
String jsonData,
|
||||
int nPlayersT, int nPlayersH,
|
||||
int forceChannel, String inviteID,
|
||||
int gameID, String gameName,
|
||||
int gameID, String gameName,
|
||||
boolean isHost )
|
||||
{
|
||||
long rowid = -1;
|
||||
|
@ -565,52 +588,52 @@ public class GameUtils {
|
|||
}
|
||||
|
||||
public static long makeNewGame( Context context, MultiMsgSink sink,
|
||||
int gameID, CommsAddrRec addr, int lang,
|
||||
String dict, int nPlayersT,
|
||||
int nPlayersH, int forceChannel,
|
||||
int gameID, CommsAddrRec addr, int lang,
|
||||
String dict, int nPlayersT,
|
||||
int nPlayersH, int forceChannel,
|
||||
String gameName )
|
||||
{
|
||||
return makeNewGame( context, sink, DBUtils.GROUPID_UNSPEC, gameID, addr,
|
||||
lang, dict, nPlayersT, nPlayersH, forceChannel,
|
||||
return makeNewGame( context, sink, DBUtils.GROUPID_UNSPEC, gameID, addr,
|
||||
lang, dict, nPlayersT, nPlayersH, forceChannel,
|
||||
gameName );
|
||||
}
|
||||
|
||||
public static long makeNewGame( Context context, int gameID,
|
||||
CommsAddrRec addr, int lang,
|
||||
String dict, int nPlayersT,
|
||||
int nPlayersH, int forceChannel,
|
||||
public static long makeNewGame( Context context, int gameID,
|
||||
CommsAddrRec addr, int lang,
|
||||
String dict, int nPlayersT,
|
||||
int nPlayersH, int forceChannel,
|
||||
String gameName )
|
||||
{
|
||||
return makeNewGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
|
||||
lang, dict, nPlayersT, nPlayersH, forceChannel,
|
||||
return makeNewGame( context, DBUtils.GROUPID_UNSPEC, gameID, addr,
|
||||
lang, dict, nPlayersT, nPlayersH, forceChannel,
|
||||
gameName );
|
||||
}
|
||||
|
||||
public static long makeNewGame( Context context, long groupID, int gameID,
|
||||
|
||||
public static long makeNewGame( Context context, long groupID, int gameID,
|
||||
CommsAddrRec addr, int lang, String dict,
|
||||
int nPlayersT, int nPlayersH,
|
||||
int nPlayersT, int nPlayersH,
|
||||
int forceChannel, String gameName )
|
||||
{
|
||||
return makeNewGame( context, null, groupID, gameID, addr, lang, dict,
|
||||
nPlayersT, nPlayersH, forceChannel, gameName );
|
||||
}
|
||||
|
||||
public static long makeNewGame( Context context, MultiMsgSink sink,
|
||||
public static long makeNewGame( Context context, MultiMsgSink sink,
|
||||
long groupID, int gameID, CommsAddrRec addr,
|
||||
int lang, String dict,
|
||||
int nPlayersT, int nPlayersH,
|
||||
int lang, String dict,
|
||||
int nPlayersT, int nPlayersH,
|
||||
int forceChannel, String gameName )
|
||||
{
|
||||
long rowid = -1;
|
||||
int[] langa = { lang };
|
||||
String[] dicta = { dict };
|
||||
boolean isHost = null == addr;
|
||||
if ( isHost ) {
|
||||
if ( isHost ) {
|
||||
addr = new CommsAddrRec( null, null );
|
||||
}
|
||||
String inviteID = GameUtils.formatGameID( gameID );
|
||||
return makeNewMultiGame( context, sink, (UtilCtxt)null, groupID, addr,
|
||||
langa, dicta, null, nPlayersT, nPlayersH,
|
||||
return makeNewMultiGame( context, sink, (UtilCtxt)null, groupID, addr,
|
||||
langa, dicta, null, nPlayersT, nPlayersH,
|
||||
forceChannel, inviteID, gameID, gameName,
|
||||
isHost );
|
||||
}
|
||||
|
@ -625,14 +648,14 @@ public class GameUtils {
|
|||
|
||||
int sdk = android.os.Build.VERSION.SDK_INT;
|
||||
if ( sdk < android.os.Build.VERSION_CODES.HONEYCOMB ) {
|
||||
android.text.ClipboardManager clipboard =
|
||||
(android.text.ClipboardManager)
|
||||
android.text.ClipboardManager clipboard =
|
||||
(android.text.ClipboardManager)
|
||||
context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboard.setText( asStr );
|
||||
} else {
|
||||
android.content.ClipboardManager clipboard =
|
||||
(android.content.ClipboardManager)
|
||||
context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
android.content.ClipboardManager clipboard =
|
||||
(android.content.ClipboardManager)
|
||||
context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
String label = LocUtils.getString( context, R.string.clip_label );
|
||||
android.content.ClipData clip = android.content.ClipData
|
||||
.newPlainText( label, asStr );
|
||||
|
@ -656,13 +679,13 @@ public class GameUtils {
|
|||
Intent intent = new Intent();
|
||||
intent.setAction( Intent.ACTION_SEND );
|
||||
String subject =
|
||||
LocUtils.getString( activity, R.string.invite_subject_fmt,
|
||||
LocUtils.getString( activity, R.string.invite_subject_fmt,
|
||||
nli.room );
|
||||
intent.putExtra( Intent.EXTRA_SUBJECT, subject );
|
||||
intent.putExtra( Intent.EXTRA_TEXT, Html.fromHtml(message) );
|
||||
|
||||
File attach = null;
|
||||
File tmpdir = XWApp.ATTACH_SUPPORTED ?
|
||||
File tmpdir = XWApp.ATTACH_SUPPORTED ?
|
||||
DictUtils.getDownloadDir( activity ) : null;
|
||||
if ( null != tmpdir ) { // no attachment
|
||||
attach = makeJsonFor( tmpdir, nli );
|
||||
|
@ -678,17 +701,17 @@ public class GameUtils {
|
|||
}
|
||||
|
||||
String choiceType = LocUtils.getString( activity, R.string.invite_chooser_email );
|
||||
String chooserMsg =
|
||||
LocUtils.getString( activity, R.string.invite_chooser_fmt,
|
||||
String chooserMsg =
|
||||
LocUtils.getString( activity, R.string.invite_chooser_fmt,
|
||||
choiceType );
|
||||
activity.startActivity( Intent.createChooser( intent, chooserMsg ) );
|
||||
}
|
||||
}
|
||||
|
||||
// public static void launchInviteActivity( Activity activity,
|
||||
// InviteMeans means,
|
||||
// public static void launchInviteActivity( Activity activity,
|
||||
// InviteMeans means,
|
||||
// String room, String inviteID,
|
||||
// int lang, String dict,
|
||||
// int lang, String dict,
|
||||
// int nPlayers )
|
||||
// {
|
||||
// Assert.assertNotNull( inviteID );
|
||||
|
@ -713,16 +736,16 @@ public class GameUtils {
|
|||
// if ( choseEmail ) {
|
||||
// intent.setAction( Intent.ACTION_SEND );
|
||||
// String subject =
|
||||
// LocUtils.getString( activity, R.string.invite_subject_fmt,
|
||||
// LocUtils.getString( activity, R.string.invite_subject_fmt,
|
||||
// room );
|
||||
// intent.putExtra( Intent.EXTRA_SUBJECT, subject );
|
||||
// intent.putExtra( Intent.EXTRA_TEXT, Html.fromHtml(message) );
|
||||
|
||||
// File attach = null;
|
||||
// File tmpdir = XWApp.ATTACH_SUPPORTED ?
|
||||
// File tmpdir = XWApp.ATTACH_SUPPORTED ?
|
||||
// DictUtils.getDownloadDir( activity ) : null;
|
||||
// if ( null != tmpdir ) { // no attachment
|
||||
// attach = makeJsonFor( tmpdir, room, inviteID, lang,
|
||||
// attach = makeJsonFor( tmpdir, room, inviteID, lang,
|
||||
// dict, nPlayers );
|
||||
// }
|
||||
|
||||
|
@ -744,8 +767,8 @@ public class GameUtils {
|
|||
// }
|
||||
|
||||
// String choiceType = LocUtils.getString( activity, choiceID );
|
||||
// String chooserMsg =
|
||||
// LocUtils.getString( activity, R.string.invite_chooser_fmt,
|
||||
// String chooserMsg =
|
||||
// LocUtils.getString( activity, R.string.invite_chooser_fmt,
|
||||
// choiceType );
|
||||
// activity.startActivity( Intent.createChooser( intent, chooserMsg ) );
|
||||
// }
|
||||
|
@ -762,7 +785,7 @@ public class GameUtils {
|
|||
}
|
||||
|
||||
public static String[] dictNames( Context context, long rowid,
|
||||
int[] missingLang )
|
||||
int[] missingLang )
|
||||
{
|
||||
byte[] stream = savedGame( context, rowid );
|
||||
CurGameInfo gi = new CurGameInfo( context );
|
||||
|
@ -773,11 +796,11 @@ public class GameUtils {
|
|||
return gi.dictNames();
|
||||
}
|
||||
|
||||
public static String[] dictNames( Context context, long rowid )
|
||||
public static String[] dictNames( Context context, long rowid )
|
||||
{
|
||||
return dictNames( context, rowid, null );
|
||||
}
|
||||
|
||||
|
||||
public static boolean gameDictsHere( Context context, long rowid )
|
||||
{
|
||||
return gameDictsHere( context, rowid, null, null );
|
||||
|
@ -786,7 +809,7 @@ public class GameUtils {
|
|||
// Return true if all dicts present. Return list of those that
|
||||
// are not.
|
||||
public static boolean gameDictsHere( Context context, long rowid,
|
||||
String[][] missingNames,
|
||||
String[][] missingNames,
|
||||
int[] missingLang )
|
||||
{
|
||||
String[] gameDicts = dictNames( context, rowid, missingLang );
|
||||
|
@ -805,14 +828,14 @@ public class GameUtils {
|
|||
DbgUtils.logf( "gameDictsHere: game has no dicts!" );
|
||||
}
|
||||
if ( null != missingNames ) {
|
||||
missingNames[0] =
|
||||
missingNames[0] =
|
||||
missingSet.toArray( new String[missingSet.size()] );
|
||||
}
|
||||
|
||||
return allHere;
|
||||
}
|
||||
|
||||
public static String newName( Context context )
|
||||
public static String newName( Context context )
|
||||
{
|
||||
return "untitled";
|
||||
// String name = null;
|
||||
|
@ -851,11 +874,11 @@ public class GameUtils {
|
|||
public static void launchGame( Delegator delegator, long rowid,
|
||||
boolean invited )
|
||||
{
|
||||
Activity activity = delegator.getActivity();
|
||||
Bundle extras = makeLaunchExtras( rowid, invited );
|
||||
if ( activity instanceof FragActivity ) {
|
||||
FragActivity.addFragment( new BoardFrag(), extras, delegator );
|
||||
if ( delegator.inDPMode() ) {
|
||||
delegator.addFragment( new BoardFrag( delegator ), extras );
|
||||
} else {
|
||||
Activity activity = delegator.getActivity();
|
||||
Intent intent = new Intent( activity, BoardActivity.class );
|
||||
intent.putExtras( extras );
|
||||
activity.startActivity( intent );
|
||||
|
@ -867,12 +890,6 @@ public class GameUtils {
|
|||
launchGame( delegator, rowid, false );
|
||||
}
|
||||
|
||||
public static void launchGameAndFinish( Delegator delegator, long rowid )
|
||||
{
|
||||
launchGame( delegator, rowid );
|
||||
delegator.getActivity().finish();
|
||||
}
|
||||
|
||||
private static class FeedUtilsImpl extends UtilCtxtImpl {
|
||||
private Context m_context;
|
||||
private long m_rowid;
|
||||
|
@ -1004,14 +1021,14 @@ public class GameUtils {
|
|||
gi.replaceDicts( newDict );
|
||||
|
||||
String[] dictNames = gi.dictNames();
|
||||
DictUtils.DictPairs pairs = DictUtils.openDicts( context,
|
||||
DictUtils.DictPairs pairs = DictUtils.openDicts( context,
|
||||
dictNames );
|
||||
|
||||
|
||||
GamePtr gamePtr = XwJNI.initJNI( rowid );
|
||||
XwJNI.game_makeFromStream( gamePtr, stream, gi, dictNames,
|
||||
XwJNI.game_makeFromStream( gamePtr, stream, gi, dictNames,
|
||||
pairs.m_bytes, pairs.m_paths,
|
||||
gi.langName(),
|
||||
JNIUtilsImpl.get(context),
|
||||
gi.langName(),
|
||||
JNIUtilsImpl.get(context),
|
||||
CommonPrefs.get( context ) );
|
||||
// second time required as game_makeFromStream can overwrite
|
||||
gi.replaceDicts( newDict );
|
||||
|
@ -1027,16 +1044,16 @@ public class GameUtils {
|
|||
return success;
|
||||
} // replaceDicts
|
||||
|
||||
public static void applyChanges( Context context, CurGameInfo gi,
|
||||
public static void applyChanges( Context context, CurGameInfo gi,
|
||||
CommsAddrRec car, GameLock lock,
|
||||
boolean forceNew )
|
||||
{
|
||||
applyChanges( context, (MultiMsgSink)null, gi, (UtilCtxt)null, car,
|
||||
applyChanges( context, (MultiMsgSink)null, gi, (UtilCtxt)null, car,
|
||||
lock, forceNew );
|
||||
}
|
||||
|
||||
public static void applyChanges( Context context, MultiMsgSink sink,
|
||||
CurGameInfo gi, UtilCtxt util,
|
||||
CurGameInfo gi, UtilCtxt util,
|
||||
CommsAddrRec car, GameLock lock,
|
||||
boolean forceNew )
|
||||
{
|
||||
|
@ -1056,8 +1073,8 @@ public class GameUtils {
|
|||
} else {
|
||||
byte[] stream = savedGame( context, lock );
|
||||
// Will fail if there's nothing in the stream but a gi.
|
||||
madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
|
||||
new CurGameInfo(context),
|
||||
madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
|
||||
new CurGameInfo(context),
|
||||
dictNames, pairs.m_bytes,
|
||||
pairs.m_paths, langName,
|
||||
JNIUtilsImpl.get(context),
|
||||
|
@ -1065,8 +1082,8 @@ public class GameUtils {
|
|||
}
|
||||
|
||||
if ( forceNew || !madeGame ) {
|
||||
XwJNI.game_makeNewGame( gamePtr, gi, dictNames, pairs.m_bytes,
|
||||
pairs.m_paths, langName, util,
|
||||
XwJNI.game_makeNewGame( gamePtr, gi, dictNames, pairs.m_bytes,
|
||||
pairs.m_paths, langName, util,
|
||||
JNIUtilsImpl.get(context), (DrawCtx)null,
|
||||
cp, sink );
|
||||
}
|
||||
|
@ -1087,22 +1104,6 @@ public class GameUtils {
|
|||
DBUtils.saveSummary( context, lock, summary );
|
||||
} // applyChanges
|
||||
|
||||
public static void doConfig( Delegator delegator, long rowid )
|
||||
{
|
||||
Bundle extras = new Bundle();
|
||||
extras.putLong( INTENT_KEY_ROWID, rowid );
|
||||
|
||||
Activity activity = delegator.getActivity();
|
||||
if ( activity instanceof FragActivity ) {
|
||||
FragActivity.addFragment( new GameConfigFrag(), extras, delegator );
|
||||
} else {
|
||||
Intent intent = new Intent( activity, GameConfigActivity.class );
|
||||
intent.setAction( Intent.ACTION_EDIT );
|
||||
intent.putExtras( extras );
|
||||
activity.startActivity( intent );
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatGameID( int gameID )
|
||||
{
|
||||
Assert.assertTrue( 0 != gameID );
|
||||
|
@ -1126,15 +1127,7 @@ public class GameUtils {
|
|||
return rint;
|
||||
}
|
||||
|
||||
// public static void postSelfNotification( Context context, long rowid )
|
||||
// {
|
||||
// Assert.assertTrue( BuildConfig.DEBUG );
|
||||
// Intent intent = GamesListDelegate.makeRowidIntent( context, rowid );
|
||||
// Utils.postNotification( context, intent, "launch",
|
||||
// String.format("%d", rowid), (int)rowid );
|
||||
// }
|
||||
|
||||
public static void postMoveNotification( Context context, long rowid,
|
||||
public static void postMoveNotification( Context context, long rowid,
|
||||
BackMoveResult bmr,
|
||||
boolean isTurnNow )
|
||||
{
|
||||
|
@ -1178,8 +1171,8 @@ public class GameUtils {
|
|||
Utils.postNotification( context, intent, R.string.invite_notice_title,
|
||||
body, (int)rowid );
|
||||
}
|
||||
|
||||
private static void tellDied( Context context, GameLock lock,
|
||||
|
||||
private static void tellDied( Context context, GameLock lock,
|
||||
boolean informNow )
|
||||
{
|
||||
GameSummary summary = DBUtils.getSummary( context, lock );
|
||||
|
@ -1281,7 +1274,7 @@ public class GameUtils {
|
|||
}
|
||||
lock.unlock();
|
||||
} else {
|
||||
DbgUtils.logf( "ResendTask.doInBackground: unable to unlock %d",
|
||||
DbgUtils.logf( "ResendTask.doInBackground: unable to unlock %d",
|
||||
rowid );
|
||||
}
|
||||
}
|
||||
|
@ -1293,7 +1286,7 @@ public class GameUtils {
|
|||
{
|
||||
if ( m_showUI ) {
|
||||
int nSent = null == m_sink ? 0 : m_sink.numSent();
|
||||
String msg =
|
||||
String msg =
|
||||
LocUtils.getQuantityString( m_context,
|
||||
R.plurals.resend_finished_fmt,
|
||||
nSent, nSent );
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2009 - 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.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.eehouse.android.xw4.jni.CurGameInfo;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class GamesListActivity extends XWActivity {
|
||||
private GamesListDelegate m_dlgt;
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
m_dlgt = new GamesListDelegate( this, savedInstanceState );
|
||||
super.onCreate( savedInstanceState, m_dlgt );
|
||||
|
||||
// Trying to debug situation where two of this activity are running at
|
||||
// once. finish()ing when Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT is
|
||||
// passed is not the fix, but perhaps there's another
|
||||
// int flags = getIntent().getFlags();
|
||||
// DbgUtils.logf( "GamesListActivity.onCreate(this=%H): flags=0x%x",
|
||||
// this, flags );
|
||||
} // onCreate
|
||||
|
||||
// called when we're brought to the front (probably as a result of
|
||||
// notification)
|
||||
@Override
|
||||
protected void onNewIntent( Intent intent )
|
||||
{
|
||||
super.onNewIntent( intent );
|
||||
m_dlgt.onNewIntent( intent );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GamesListDelegator interface
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public void launchGame( long rowID, boolean invited )
|
||||
{
|
||||
GameUtils.launchGame( this, rowID, invited );
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -24,6 +24,8 @@ import android.os.Bundle;
|
|||
|
||||
public class GamesListFrag extends XWFragment {
|
||||
|
||||
public GamesListFrag( Delegator parent ) { super( parent ); }
|
||||
|
||||
@Override
|
||||
public void onCreate( Bundle sis )
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ import junit.framework.Assert;
|
|||
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class HeaderWithExpander extends LinearLayout
|
||||
public class HeaderWithExpander extends LinearLayout
|
||||
implements View.OnClickListener {
|
||||
|
||||
private boolean m_expanded;
|
||||
|
@ -43,7 +43,7 @@ public class HeaderWithExpander extends LinearLayout
|
|||
public void expanded( boolean expanded );
|
||||
}
|
||||
|
||||
public HeaderWithExpander( Context cx, AttributeSet as )
|
||||
public HeaderWithExpander( Context cx, AttributeSet as )
|
||||
{
|
||||
super( cx, as );
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class HeaderWithExpander extends LinearLayout
|
|||
m_label = (TextView)findViewById( R.id.label );
|
||||
}
|
||||
|
||||
public void setExpanded( boolean expanded )
|
||||
public void setExpanded( boolean expanded )
|
||||
{
|
||||
m_expanded = expanded;
|
||||
if ( null != m_listener ) {
|
||||
|
@ -81,7 +81,7 @@ public class HeaderWithExpander extends LinearLayout
|
|||
//////////////////////////////////////////////////
|
||||
// View.OnClickListener interface
|
||||
//////////////////////////////////////////////////
|
||||
public void onClick( View view )
|
||||
public void onClick( View view )
|
||||
{
|
||||
setExpanded( !m_expanded );
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ abstract class InviteDelegate extends ListDelegateBase
|
|||
m_lastDev = intent.getStringExtra( INTENT_KEY_LASTDEV );
|
||||
}
|
||||
|
||||
protected void init( int button_invite, int button_rescan,
|
||||
protected void init( int button_invite, int button_rescan,
|
||||
int button_clear, int desc_id, String descTxt )
|
||||
{
|
||||
m_okButton = (Button)findViewById( button_invite );
|
||||
|
@ -87,7 +87,7 @@ abstract class InviteDelegate extends ListDelegateBase
|
|||
////////////////////////////////////////
|
||||
// View.OnClickListener
|
||||
////////////////////////////////////////
|
||||
public void onClick( View view )
|
||||
public void onClick( View view )
|
||||
{
|
||||
if ( m_okButton == view ) {
|
||||
Intent intent = new Intent();
|
||||
|
|
|
@ -26,7 +26,7 @@ import android.widget.ListAdapter;
|
|||
import android.widget.ListView;
|
||||
|
||||
public class ListDelegateBase extends DelegateBase {
|
||||
|
||||
|
||||
private Activity m_activity;
|
||||
private Delegator m_delegator;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import android.widget.TextView;
|
|||
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class ListGroup extends LinearLayout
|
||||
public class ListGroup extends LinearLayout
|
||||
implements View.OnClickListener {
|
||||
|
||||
private boolean m_expanded;
|
||||
|
@ -39,7 +39,7 @@ public class ListGroup extends LinearLayout
|
|||
private GroupStateListener m_listener;
|
||||
private int m_posn;
|
||||
|
||||
public ListGroup( Context cx, AttributeSet as )
|
||||
public ListGroup( Context cx, AttributeSet as )
|
||||
{
|
||||
super( cx, as );
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class ListGroup extends LinearLayout
|
|||
super.onFinishInflate();
|
||||
m_expandButton = (ImageButton)findViewById( R.id.expander );
|
||||
m_text = (TextView)findViewById( R.id.game_name );
|
||||
|
||||
|
||||
m_expandButton.setOnClickListener( this );
|
||||
setOnClickListener( this );
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class ListGroup extends LinearLayout
|
|||
//////////////////////////////////////////////////
|
||||
// View.OnClickListener interface
|
||||
//////////////////////////////////////////////////
|
||||
public void onClick( View view )
|
||||
public void onClick( View view )
|
||||
{
|
||||
m_expanded = !m_expanded;
|
||||
m_listener.onGroupExpandedChanged( this, m_expanded );
|
||||
|
@ -89,8 +89,8 @@ public class ListGroup extends LinearLayout
|
|||
}
|
||||
}
|
||||
|
||||
public static ListGroup make( Context context, View convertView,
|
||||
GroupStateListener lstnr, int posn,
|
||||
public static ListGroup make( Context context, View convertView,
|
||||
GroupStateListener lstnr, int posn,
|
||||
String desc, boolean expanded )
|
||||
{
|
||||
ListGroup result;
|
||||
|
|
|
@ -72,7 +72,7 @@ public class LookupAlert extends LinearLayout
|
|||
private static String[] s_lookupUrls;
|
||||
private static ArrayAdapter<String> s_urlsAdapter;
|
||||
private static final int LIST_LAYOUT = android.R.layout.simple_list_item_1;
|
||||
|
||||
|
||||
private static int s_lang = -1;
|
||||
private static String s_langName;
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class LookupAlert extends LinearLayout
|
|||
// m_state = STATE_DONE;
|
||||
// adjustState( 1 );
|
||||
|
||||
// m_wordsAdapter = new ArrayAdapter<String>( this, LIST_LAYOUT,
|
||||
// m_wordsAdapter = new ArrayAdapter<String>( this, LIST_LAYOUT,
|
||||
// m_words );
|
||||
// getListView().setOnItemClickListener( this );
|
||||
|
||||
|
@ -147,7 +147,7 @@ public class LookupAlert extends LinearLayout
|
|||
m_state = STATE_DONE;
|
||||
adjustState( 1 );
|
||||
|
||||
m_wordsAdapter = new ArrayAdapter<String>( m_context, LIST_LAYOUT,
|
||||
m_wordsAdapter = new ArrayAdapter<String>( m_context, LIST_LAYOUT,
|
||||
m_words );
|
||||
m_listView = (ListView)findViewById( android.R.id.list );
|
||||
m_listView.setOnItemClickListener( this );
|
||||
|
@ -167,7 +167,7 @@ public class LookupAlert extends LinearLayout
|
|||
}
|
||||
|
||||
// @Override
|
||||
// protected void onSaveInstanceState( Bundle outState )
|
||||
// protected void onSaveInstanceState( Bundle outState )
|
||||
// {
|
||||
// super.onSaveInstanceState( outState );
|
||||
// outState.putInt( STATE, m_state );
|
||||
|
@ -188,9 +188,9 @@ public class LookupAlert extends LinearLayout
|
|||
// }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// View.OnClickListener
|
||||
// View.OnClickListener
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public void onClick( View view )
|
||||
public void onClick( View view )
|
||||
{
|
||||
if ( view == m_doneButton ) {
|
||||
switchState( -1 );
|
||||
|
@ -198,16 +198,16 @@ public class LookupAlert extends LinearLayout
|
|||
String word = m_words[m_wordIndex];
|
||||
DBUtils.addToStudyList( m_context, word, s_lang );
|
||||
|
||||
String msg = LocUtils.getString( m_context, R.string.add_done_fmt,
|
||||
String msg = LocUtils.getString( m_context, R.string.add_done_fmt,
|
||||
word, s_langName );
|
||||
Utils.showToast( m_context, msg );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// AdapterView.OnItemClickListener
|
||||
// AdapterView.OnItemClickListener
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public void onItemClick( AdapterView<?> parentView, View view,
|
||||
public void onItemClick( AdapterView<?> parentView, View view,
|
||||
int position, long id )
|
||||
{
|
||||
if ( STATE_WORDS == m_state ) {
|
||||
|
@ -252,7 +252,7 @@ public class LookupAlert extends LinearLayout
|
|||
break;
|
||||
case STATE_WORDS:
|
||||
m_listView.setAdapter( m_wordsAdapter );
|
||||
setSummary( m_studyOn ?
|
||||
setSummary( m_studyOn ?
|
||||
R.string.title_lookup_study : R.string.title_lookup );
|
||||
m_doneButton.setText( R.string.button_done );
|
||||
m_studyButton.setVisibility( View.GONE );
|
||||
|
@ -271,7 +271,7 @@ public class LookupAlert extends LinearLayout
|
|||
}
|
||||
break;
|
||||
case STATE_LOOKUP:
|
||||
lookupWord( m_context, m_words[m_wordIndex],
|
||||
lookupWord( m_context, m_words[m_wordIndex],
|
||||
s_lookupUrls[m_urlIndex] );
|
||||
switchState( -1 );
|
||||
break;
|
||||
|
@ -291,7 +291,7 @@ public class LookupAlert extends LinearLayout
|
|||
Uri uri = Uri.parse( dict_url );
|
||||
Intent intent = new Intent( Intent.ACTION_VIEW, uri );
|
||||
intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
|
||||
|
||||
try {
|
||||
context.startActivity( intent );
|
||||
} catch ( android.content.ActivityNotFoundException anfe ) {
|
||||
|
@ -323,7 +323,7 @@ public class LookupAlert extends LinearLayout
|
|||
}
|
||||
s_lookupNames = tmpNames.toArray( new String[tmpNames.size()] );
|
||||
s_lookupUrls = tmpUrls.toArray( new String[tmpUrls.size()] );
|
||||
s_urlsAdapter = new ArrayAdapter<String>( context, LIST_LAYOUT,
|
||||
s_urlsAdapter = new ArrayAdapter<String>( context, LIST_LAYOUT,
|
||||
s_lookupNames );
|
||||
s_lang = lang;
|
||||
String langName = DictLangCache.getLangName( context, lang );
|
||||
|
@ -338,7 +338,7 @@ public class LookupAlert extends LinearLayout
|
|||
|
||||
private void setSummary( String word )
|
||||
{
|
||||
String title =
|
||||
String title =
|
||||
LocUtils.getString( m_context, R.string.pick_url_title_fmt, word );
|
||||
m_summary.setText( title );
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ public class LookupAlert extends LinearLayout
|
|||
return handled;
|
||||
}
|
||||
|
||||
public static boolean needAlert( Context context, String[] words,
|
||||
public static boolean needAlert( Context context, String[] words,
|
||||
int langCode, boolean noStudy )
|
||||
{
|
||||
boolean result = !noStudy || 1 < words.length;
|
||||
|
@ -367,7 +367,7 @@ public class LookupAlert extends LinearLayout
|
|||
return result;
|
||||
}
|
||||
|
||||
public static Bundle makeParams( String[] words, int lang,
|
||||
public static Bundle makeParams( String[] words, int lang,
|
||||
boolean noStudyOption )
|
||||
{
|
||||
Bundle bundle = new Bundle();
|
||||
|
@ -391,7 +391,7 @@ public class LookupAlert extends LinearLayout
|
|||
return result;
|
||||
}
|
||||
|
||||
protected static void launchWordLookup( Context context, String word,
|
||||
protected static void launchWordLookup( Context context, String word,
|
||||
int langCode )
|
||||
{
|
||||
setLang( context, langCode );
|
||||
|
|
|
@ -0,0 +1,484 @@
|
|||
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
|
||||
/*
|
||||
* Copyright 2009 - 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.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager.BackStackEntry;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eehouse.android.xw4.jni.CurGameInfo;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class MainActivity extends XWActivity
|
||||
implements FragmentManager.OnBackStackChangedListener {
|
||||
private static final int MAX_PANES_LANDSCAPE = 2;
|
||||
private static final boolean LOG_IDS = true;
|
||||
|
||||
private DelegateBase m_dlgt;
|
||||
private boolean m_dpEnabled;
|
||||
|
||||
// Used only if m_dpEnabled is true
|
||||
private LinearLayout m_root;
|
||||
private int m_maxPanes;
|
||||
private int m_nextID = 0x00FFFFFF;
|
||||
private Boolean m_isPortrait;
|
||||
|
||||
// for tracking launchForResult callback recipients
|
||||
private Map<RequestCode, WeakReference<DelegateBase>> m_pendingCodes
|
||||
= new HashMap<RequestCode, WeakReference<DelegateBase>>();
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
{
|
||||
m_dpEnabled = XWPrefs.dualpaneEnabled( this );
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
Utils.showToast( this, "dualpane mode: " + m_dpEnabled );
|
||||
}
|
||||
|
||||
m_dlgt = m_dpEnabled ? new DualpaneDelegate( this, savedInstanceState )
|
||||
: new GamesListDelegate( this, savedInstanceState );
|
||||
super.onCreate( savedInstanceState, m_dlgt );
|
||||
|
||||
if ( m_dpEnabled ) {
|
||||
m_root = (LinearLayout)findViewById( R.id.main_container );
|
||||
getSupportFragmentManager().addOnBackStackChangedListener( this );
|
||||
|
||||
m_maxPanes = maxPanes();
|
||||
|
||||
// Nothing to do if we're restarting
|
||||
if ( savedInstanceState == null ) {
|
||||
// In case this activity was started with special instructions from an Intent,
|
||||
// pass the Intent's extras to the fragment as arguments
|
||||
addFragmentImpl( new GamesListFrag(null),
|
||||
getIntent().getExtras(), null );
|
||||
}
|
||||
}
|
||||
} // onCreate
|
||||
|
||||
// called when we're brought to the front (probably as a result of
|
||||
// notification)
|
||||
@Override
|
||||
protected void onNewIntent( Intent intent )
|
||||
{
|
||||
super.onNewIntent( intent );
|
||||
|
||||
m_dlgt.handleNewIntent( intent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged( Configuration newConfig )
|
||||
{
|
||||
if ( m_dpEnabled ) {
|
||||
Rect rect = new Rect();
|
||||
m_root.getWindowVisibleDisplayFrame( rect );
|
||||
|
||||
boolean isPortrait
|
||||
= Configuration.ORIENTATION_PORTRAIT == newConfig.orientation;
|
||||
DbgUtils.logf( "MainActivity.onConfigurationChanged(isPortrait=%b)",
|
||||
isPortrait );
|
||||
m_isPortrait = isPortrait;
|
||||
if ( isPortrait != (rect.width() <= rect.height()) ) {
|
||||
DbgUtils.logdf( "FragActivity.onConfigurationChanged(): isPortrait:"
|
||||
+ " %b; width: %d; height: %d",
|
||||
isPortrait, rect.width(), rect.height() );
|
||||
}
|
||||
int maxPanes = isPortrait? 1 : MAX_PANES_LANDSCAPE;
|
||||
if ( m_maxPanes != maxPanes ) {
|
||||
m_maxPanes = maxPanes;
|
||||
setVisiblePanes();
|
||||
}
|
||||
tellOrientationChanged();
|
||||
}
|
||||
super.onConfigurationChanged( newConfig );
|
||||
}
|
||||
|
||||
/**
|
||||
* Run down the list of fragments until one handles the intent. If no
|
||||
* visible one does, pop hidden ones into view until one of them
|
||||
* does. Yes, this will take us back to GamesList being visible even if
|
||||
* nothing handles the intent, but at least now all are handled by
|
||||
* GamesList anyway.
|
||||
*/
|
||||
protected boolean dispatchNewIntent( Intent intent )
|
||||
{
|
||||
boolean handled = false;
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
|
||||
// First try non-left-most fragments, if any. Once we've eliminated
|
||||
// them we can just iterate on the leftmost fragment.
|
||||
int nNonLeft = m_maxPanes - 1;
|
||||
// include paged-to-left invisible views
|
||||
int viewCount = m_root.getChildCount();
|
||||
for ( int ii = nNonLeft; !handled && 0 < ii; --ii ) {
|
||||
View child = m_root.getChildAt( viewCount - ii );
|
||||
Fragment frag = fm.findFragmentById( child.getId() );
|
||||
handled = ((XWFragment)frag).getDelegate().handleNewIntent( intent );
|
||||
}
|
||||
|
||||
while ( !handled ) {
|
||||
// Now iterate on the leftmost, popping if necessary to page new
|
||||
// ones into place
|
||||
int childCount = m_root.getChildCount();
|
||||
int hiddenCount = Math.max( 0, childCount - m_maxPanes );
|
||||
for ( int ii = hiddenCount; ii >= 0; --ii ) {
|
||||
View child = m_root.getChildAt( ii );
|
||||
Fragment frag = fm.findFragmentById( child.getId() );
|
||||
// DbgUtils.logf( "left-most case (child %d): %s", hiddenCount,
|
||||
// frag.getClass().getSimpleName() );
|
||||
handled = ((XWFragment)frag).getDelegate()
|
||||
.handleNewIntent( intent );
|
||||
|
||||
if ( handled ) {
|
||||
break;
|
||||
} else if ( ii > 0 ) {
|
||||
DbgUtils.logf( "popping %s",
|
||||
frag.getClass().getSimpleName() );
|
||||
fm.popBackStackImmediate(); // callback removes view
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
/**
|
||||
* The right-most pane only gets a chance to handle on-back-pressed.
|
||||
*/
|
||||
protected boolean dispatchBackPressed()
|
||||
{
|
||||
XWFragment frag = getTopFragment();
|
||||
boolean handled = null != frag
|
||||
&& frag.getDelegate().handleBackPressed();
|
||||
return handled;
|
||||
}
|
||||
|
||||
protected void dispatchOnActivityResult( RequestCode requestCode,
|
||||
int resultCode, Intent data )
|
||||
{
|
||||
XWFragment frag = getTopFragment();
|
||||
|
||||
if ( null != frag ) {
|
||||
frag.onActivityResult( requestCode.ordinal(), resultCode, data );
|
||||
} else {
|
||||
DbgUtils.logdf( "dispatchOnActivityResult(): can't dispatch %s",
|
||||
requestCode.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
protected void dispatchOnCreateContextMenu( ContextMenu menu, View view,
|
||||
ContextMenuInfo menuInfo )
|
||||
{
|
||||
XWFragment[] frags = getVisibleFragments();
|
||||
for ( XWFragment frag : frags ) {
|
||||
frag.getDelegate().onCreateContextMenu( menu, view, menuInfo );
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean dispatchOnContextItemSelected( MenuItem item )
|
||||
{
|
||||
boolean handled = false;
|
||||
XWFragment[] frags = getVisibleFragments();
|
||||
for ( XWFragment frag : frags ) {
|
||||
handled = frag.getDelegate().onContextItemSelected( item );
|
||||
if ( handled ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
protected Point getFragmentSize()
|
||||
{
|
||||
Rect rect = new Rect();
|
||||
m_root.getWindowVisibleDisplayFrame( rect );
|
||||
int width = rect.width();
|
||||
int height = rect.height();
|
||||
if ( null != m_isPortrait && m_isPortrait && height < width ) {
|
||||
int tmp = width;
|
||||
width = height;
|
||||
height = tmp;
|
||||
}
|
||||
return new Point( width / Math.min( m_maxPanes, m_root.getChildCount() ),
|
||||
height );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Delegator interface
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@Override
|
||||
public boolean inDPMode() {
|
||||
return m_dpEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFragment( XWFragment fragment, Bundle extras )
|
||||
{
|
||||
addFragmentImpl( fragment, extras, fragment.getParent() );
|
||||
}
|
||||
|
||||
private class PendingResultCache {
|
||||
private WeakReference<Fragment> m_frag;
|
||||
public int m_request;
|
||||
public int m_result;
|
||||
public Intent m_data;
|
||||
public PendingResultCache( Fragment target, int request, int result, Intent data ) {
|
||||
m_frag = new WeakReference<Fragment>(target);
|
||||
m_request = request;
|
||||
m_result = result;
|
||||
m_data = data;
|
||||
}
|
||||
|
||||
public Fragment getTarget() { return m_frag.get(); }
|
||||
}
|
||||
private PendingResultCache m_pendingResult;
|
||||
|
||||
public void addFragmentForResult( XWFragment fragment, Bundle extras,
|
||||
RequestCode requestCode, XWFragment registrant )
|
||||
{
|
||||
DbgUtils.assertOnUIThread();
|
||||
|
||||
fragment.setTargetFragment( registrant, requestCode.ordinal() );
|
||||
|
||||
addFragmentImpl( fragment, extras, fragment.getParent() );
|
||||
}
|
||||
|
||||
protected void setFragmentResult( XWFragment fragment, int resultCode,
|
||||
Intent data )
|
||||
{
|
||||
Fragment target = fragment.getTargetFragment();
|
||||
int requestCode = fragment.getTargetRequestCode();
|
||||
|
||||
Assert.assertNull( m_pendingResult );
|
||||
m_pendingResult = new PendingResultCache( target, requestCode,
|
||||
resultCode, data );
|
||||
}
|
||||
|
||||
protected void finishFragment()
|
||||
{
|
||||
// Assert.assertTrue( fragment instanceof XWFragment );
|
||||
// DbgUtils.logf( "MainActivity.finishFragment(%s)", fragment.toString() );
|
||||
getSupportFragmentManager().popBackStack/*Immediate*/();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// FragmentManager.OnBackStackChangedListener
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public void onBackStackChanged()
|
||||
{
|
||||
// make sure the right-most are visible
|
||||
int fragCount = getSupportFragmentManager().getBackStackEntryCount();
|
||||
DbgUtils.logf( "MainActivity.onBackStackChanged(); count now %d", fragCount );
|
||||
if ( 0 == fragCount ) {
|
||||
finish();
|
||||
} else {
|
||||
if ( fragCount == m_root.getChildCount() - 1 ) {
|
||||
View child = m_root.getChildAt( fragCount );
|
||||
if ( LOG_IDS ) {
|
||||
DbgUtils.logf( "onBackStackChanged(): removing view with id %x",
|
||||
child.getId() );
|
||||
}
|
||||
m_root.removeView( child );
|
||||
setVisiblePanes();
|
||||
}
|
||||
|
||||
// If there's a pending on-result call, make it.
|
||||
if ( null != m_pendingResult ) {
|
||||
Fragment target = m_pendingResult.getTarget();
|
||||
if ( null != target ) {
|
||||
DbgUtils.logf( "onBackStackChanged(): calling onActivityResult()" );
|
||||
target.onActivityResult( m_pendingResult.m_request,
|
||||
m_pendingResult.m_result,
|
||||
m_pendingResult.m_data );
|
||||
}
|
||||
m_pendingResult = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Dualpane mode stuff
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private XWFragment getTopFragment()
|
||||
{
|
||||
View child = m_root.getChildAt( m_root.getChildCount() - 1 );
|
||||
XWFragment frag = (XWFragment)getSupportFragmentManager()
|
||||
.findFragmentById( child.getId() );
|
||||
return frag;
|
||||
}
|
||||
|
||||
private XWFragment[] getVisibleFragments()
|
||||
{
|
||||
int childCount = m_root.getChildCount();
|
||||
int count = Math.min( m_maxPanes, childCount );
|
||||
XWFragment[] result = new XWFragment[count];
|
||||
for ( int ii = 0; ii < count; ++ii ) {
|
||||
View child = m_root.getChildAt( childCount - 1 - ii );
|
||||
result[ii] = (XWFragment)getSupportFragmentManager()
|
||||
.findFragmentById( child.getId() );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Walk all Fragment children and if they care notify of change.
|
||||
private void tellOrientationChanged()
|
||||
{
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
int nPanes = m_root.getChildCount();
|
||||
for ( int ii = 0; ii < nPanes; ++ii ) {
|
||||
FrameLayout frame = (FrameLayout)m_root.getChildAt( ii );
|
||||
int id = frame.getId();
|
||||
Fragment frag = fm.findFragmentById( id );
|
||||
if ( null == frag ) {
|
||||
DbgUtils.logf( "tellOrienationChanged: NO FRAG at %d, id=%d", ii, id );
|
||||
} else if ( frag instanceof XWFragment ) {
|
||||
((XWFragment)frag).getDelegate().orientationChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int maxPanes()
|
||||
{
|
||||
int result;
|
||||
int orientation = getResources().getConfiguration().orientation;
|
||||
if ( XWPrefs.getIsTablet( this )
|
||||
&& Configuration.ORIENTATION_LANDSCAPE == orientation ) {
|
||||
result = MAX_PANES_LANDSCAPE;
|
||||
} else {
|
||||
result = 1;
|
||||
}
|
||||
// DbgUtils.logf( "maxPanes() => %d", result );
|
||||
return result;
|
||||
}
|
||||
|
||||
private void setVisiblePanes()
|
||||
{
|
||||
// hide all but the right-most m_maxPanes children
|
||||
int nPanes = m_root.getChildCount();
|
||||
for ( int ii = 0; ii < nPanes; ++ii ) {
|
||||
View child = m_root.getChildAt( ii );
|
||||
boolean visible = ii >= nPanes - m_maxPanes;
|
||||
DbgUtils.logf( "pane %d: visible=%b", ii, visible );
|
||||
child.setVisibility( visible ? View.VISIBLE : View.GONE );
|
||||
setMenuVisibility( child, visible );
|
||||
}
|
||||
}
|
||||
|
||||
private void setMenuVisibility( View cont, boolean visible )
|
||||
{
|
||||
FrameLayout layout = (FrameLayout)cont;
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
int hidingId = layout.getId();
|
||||
Fragment frag = fm.findFragmentById( hidingId );
|
||||
if ( null != frag ) { // hasn't been popped?
|
||||
frag.setMenuVisibility( visible );
|
||||
}
|
||||
}
|
||||
|
||||
private void addFragmentImpl( Fragment fragment, Bundle bundle,
|
||||
Delegator parent )
|
||||
{
|
||||
fragment.setArguments( bundle );
|
||||
addFragmentImpl( fragment, parent );
|
||||
}
|
||||
|
||||
private void addFragmentImpl( Fragment fragment, Delegator parent )
|
||||
{
|
||||
String newName = fragment.getClass().getSimpleName();
|
||||
boolean replace = false;
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
int fragCount = fm.getBackStackEntryCount();
|
||||
int containerCount = m_root.getChildCount();
|
||||
DbgUtils.logf( "fragCount: %d; containerCount: %d", fragCount, containerCount );
|
||||
// Assert.assertTrue( fragCount == containerCount );
|
||||
|
||||
// Replace IF we're adding something of the same class at right OR if
|
||||
// we're adding something with the existing left pane as its parent
|
||||
// (delegator)
|
||||
if ( 1 < fragCount ) {
|
||||
Assert.assertTrue( MAX_PANES_LANDSCAPE == 2 ); // otherwise FIXME
|
||||
FragmentManager.BackStackEntry entry
|
||||
= fm.getBackStackEntryAt( fragCount - 2 );
|
||||
String curName = entry.getName();
|
||||
String delName = parent.getClass().getSimpleName();
|
||||
// DbgUtils.logf( "comparing %s, %s", curName, delName );
|
||||
replace = curName.equals( delName );
|
||||
}
|
||||
|
||||
if ( replace ) {
|
||||
fm.popBackStack();
|
||||
}
|
||||
|
||||
// Replace doesn't seem to work with generated IDs, so we'll create a
|
||||
// new FrameLayout each time. If we're replacing, we'll replace the
|
||||
// current rightmost FrameLayout. Otherwise we'll add a new one.
|
||||
LinearLayout.LayoutParams lp
|
||||
= new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams
|
||||
.MATCH_PARENT, 1.0f);
|
||||
FrameLayout cont = new FrameLayout( this );
|
||||
cont.setLayoutParams( lp );
|
||||
int id = --m_nextID;
|
||||
cont.setId( id );
|
||||
if ( LOG_IDS ) {
|
||||
DbgUtils.logf( "assigning id %x to view with name %s", id, newName );
|
||||
}
|
||||
m_root.addView( cont, replace ? containerCount - 1 : containerCount );
|
||||
|
||||
if ( !replace && containerCount >= m_maxPanes ) {
|
||||
int indx = containerCount - m_maxPanes;
|
||||
View child = m_root.getChildAt( indx );
|
||||
child.setVisibility( View.GONE );
|
||||
|
||||
setMenuVisibility( child, false );
|
||||
|
||||
DbgUtils.logf( "hiding %dth container", indx );
|
||||
}
|
||||
|
||||
fm.beginTransaction()
|
||||
.add( id, fragment )
|
||||
.addToBackStack( newName )
|
||||
.commit();
|
||||
// Don't do this. It causes an exception if e.g. from fragment.start()
|
||||
// I wind up launching another fragment and calling into this code
|
||||
// again. If I need executePendingTransactions() I'm doing something
|
||||
// else wrong.
|
||||
// fm.executePendingTransactions();
|
||||
}
|
||||
}
|
|
@ -79,7 +79,7 @@ public class MultiMsgSink implements TransportProcs {
|
|||
|
||||
public int getFlags() { return COMMS_XPORT_FLAGS_HASNOCONN; }
|
||||
|
||||
public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr,
|
||||
public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr,
|
||||
CommsConnType typ, int gameID )
|
||||
{
|
||||
int nSent = -1;
|
||||
|
@ -97,7 +97,7 @@ public class MultiMsgSink implements TransportProcs {
|
|||
Assert.fail();
|
||||
break;
|
||||
}
|
||||
DbgUtils.logf( "MultiMsgSink.transportSend(): sent %d via %s",
|
||||
DbgUtils.logf( "MultiMsgSink.transportSend(): sent %d via %s",
|
||||
nSent, typ.toString() );
|
||||
if ( 0 < nSent ) {
|
||||
DbgUtils.logdf( "MultiMsgSink.transportSend: adding %s", msgNo );
|
||||
|
@ -115,7 +115,7 @@ public class MultiMsgSink implements TransportProcs {
|
|||
{
|
||||
}
|
||||
|
||||
public void relayConnd( String room, int devOrder, boolean allHere,
|
||||
public void relayConnd( String room, int devOrder, boolean allHere,
|
||||
int nMissing )
|
||||
{
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public class MultiMsgSink implements TransportProcs {
|
|||
public boolean relayNoConnProc( byte[] buf, String msgNo, String relayID )
|
||||
{
|
||||
// Assert.fail();
|
||||
int nSent = RelayService.sendNoConnPacket( m_context, getRowID(),
|
||||
int nSent = RelayService.sendNoConnPacket( m_context, getRowID(),
|
||||
relayID, buf );
|
||||
boolean success = buf.length == nSent;
|
||||
if ( success ) {
|
||||
|
|
|
@ -149,7 +149,7 @@ public class MultiService {
|
|||
String inviter = intent.getStringExtra( INVITER );
|
||||
int msgID = (null == inviter) ? R.string.invite_dict_missing_body_noname_fmt
|
||||
: R.string.invite_dict_missing_body_fmt;
|
||||
String msg = LocUtils.getString( context, msgID, inviter, dict,
|
||||
String msg = LocUtils.getString( context, msgID, inviter, dict,
|
||||
LocUtils.xlateLang( context, langStr));
|
||||
|
||||
return LocUtils.makeAlertBuilder( context )
|
||||
|
@ -160,10 +160,10 @@ public class MultiService {
|
|||
.create();
|
||||
}
|
||||
|
||||
public static void postMissingDictNotification( Context content,
|
||||
public static void postMissingDictNotification( Context content,
|
||||
Intent intent, int id )
|
||||
{
|
||||
Utils.postNotification( content, intent, R.string.missing_dict_title,
|
||||
Utils.postNotification( content, intent, R.string.missing_dict_title,
|
||||
R.string.missing_dict_detail, id );
|
||||
}
|
||||
|
||||
|
|
|
@ -64,12 +64,12 @@ public class NFCUtils {
|
|||
private static class SafeNFCImpl implements SafeNFC {
|
||||
public void register( final Activity activity, final NFCActor actor )
|
||||
{
|
||||
NfcManager manager =
|
||||
NfcManager manager =
|
||||
(NfcManager)activity.getSystemService( Context.NFC_SERVICE );
|
||||
if ( null != manager ) {
|
||||
NfcAdapter adapter = manager.getDefaultAdapter();
|
||||
if ( null != adapter ) {
|
||||
NfcAdapter.CreateNdefMessageCallback cb =
|
||||
NfcAdapter.CreateNdefMessageCallback cb =
|
||||
new NfcAdapter.CreateNdefMessageCallback() {
|
||||
public NdefMessage createNdefMessage( NfcEvent evt )
|
||||
{
|
||||
|
@ -93,7 +93,7 @@ public class NFCUtils {
|
|||
public static boolean[] nfcAvail( Context context )
|
||||
{
|
||||
if ( null == s_nfcAvail ) {
|
||||
s_nfcAvail = new boolean[] {
|
||||
s_nfcAvail = new boolean[] {
|
||||
s_inSDK && null != getNFCAdapter( context ),
|
||||
false
|
||||
};
|
||||
|
@ -110,7 +110,7 @@ public class NFCUtils {
|
|||
|
||||
String action = intent.getAction();
|
||||
if ( NfcAdapter.ACTION_NDEF_DISCOVERED.equals( action ) ) {
|
||||
Parcelable[] rawMsgs =
|
||||
Parcelable[] rawMsgs =
|
||||
intent.getParcelableArrayExtra( NfcAdapter.EXTRA_NDEF_MESSAGES );
|
||||
// only one message sent during the beam
|
||||
NdefMessage msg = (NdefMessage)rawMsgs[0];
|
||||
|
@ -140,7 +140,7 @@ public class NFCUtils {
|
|||
{
|
||||
DialogInterface.OnClickListener lstnr
|
||||
= new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dialog,
|
||||
public void onClick( DialogInterface dialog,
|
||||
int item ) {
|
||||
activity.
|
||||
startActivity( new Intent("android.settings"
|
||||
|
@ -159,8 +159,8 @@ public class NFCUtils {
|
|||
{
|
||||
String mimeType = LocUtils.getString( activity, R.string.xwords_nfc_mime );
|
||||
NdefMessage msg = new NdefMessage( new NdefRecord[] {
|
||||
new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
|
||||
mimeType.getBytes(), new byte[0],
|
||||
new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
|
||||
mimeType.getBytes(), new byte[0],
|
||||
data.getBytes())
|
||||
,NdefRecord.
|
||||
createApplicationRecord( activity.getPackageName() )
|
||||
|
@ -170,9 +170,9 @@ public class NFCUtils {
|
|||
|
||||
private static NfcAdapter getNFCAdapter( Context context )
|
||||
{
|
||||
NfcManager manager =
|
||||
NfcManager manager =
|
||||
(NfcManager)context.getSystemService( Context.NFC_SERVICE );
|
||||
return manager.getDefaultAdapter();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue