mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-01 19:57:11 +01:00
use a singlton rather than one Time per object
De-serializing a Time formatter wasn't going well post-proguard, but it was a dumb way to do it anyway when only one object is needed.
This commit is contained in:
parent
fb91ba8608
commit
94dca807ef
2 changed files with 9 additions and 48 deletions
|
@ -45,6 +45,7 @@ import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ConnStatusHandler {
|
public class ConnStatusHandler {
|
||||||
private static final String TAG = ConnStatusHandler.class.getSimpleName();
|
private static final String TAG = ConnStatusHandler.class.getSimpleName();
|
||||||
|
@ -68,17 +69,12 @@ public class ConnStatusHandler {
|
||||||
private static ConnStatusCBacks s_cbacks;
|
private static ConnStatusCBacks s_cbacks;
|
||||||
private static Paint s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG );
|
private static Paint s_fillPaint = new Paint( Paint.ANTI_ALIAS_FLAG );
|
||||||
private static boolean[] s_showSuccesses = { false, false };
|
private static boolean[] s_showSuccesses = { false, false };
|
||||||
|
private static Time s_time = new Time();
|
||||||
|
|
||||||
private static class SuccessRecord implements java.io.Serializable {
|
private static class SuccessRecord implements java.io.Serializable {
|
||||||
public long lastSuccess;
|
public long lastSuccess;
|
||||||
public long lastFailure;
|
public long lastFailure;
|
||||||
public boolean successNewer;
|
public boolean successNewer;
|
||||||
transient private Time m_time;
|
|
||||||
|
|
||||||
public SuccessRecord()
|
|
||||||
{
|
|
||||||
m_time = new Time();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean haveFailure()
|
public boolean haveFailure()
|
||||||
{
|
{
|
||||||
|
@ -92,14 +88,14 @@ public class ConnStatusHandler {
|
||||||
|
|
||||||
public String newerStr( Context context )
|
public String newerStr( Context context )
|
||||||
{
|
{
|
||||||
m_time.set( successNewer? lastSuccess : lastFailure );
|
s_time.set( successNewer? lastSuccess : lastFailure );
|
||||||
return format( context, m_time );
|
return format( context, s_time );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String olderStr( Context context )
|
public String olderStr( Context context )
|
||||||
{
|
{
|
||||||
m_time.set( successNewer? lastFailure : lastSuccess );
|
s_time.set( successNewer? lastFailure : lastSuccess );
|
||||||
return format( context, m_time );
|
return format( context, s_time );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update( boolean success )
|
public void update( boolean success )
|
||||||
|
@ -123,19 +119,11 @@ public class ConnStatusHandler {
|
||||||
0 );
|
0 );
|
||||||
return seq.toString();
|
return seq.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// called during deserialization
|
|
||||||
private void readObject( ObjectInputStream in )
|
|
||||||
throws java.io.IOException, java.lang.ClassNotFoundException
|
|
||||||
{
|
|
||||||
in.defaultReadObject();
|
|
||||||
m_time = new Time();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConnStatusHandler() {}
|
private ConnStatusHandler() {}
|
||||||
|
|
||||||
private static HashMap<CommsConnType,SuccessRecord[]> s_records =
|
private static Map<CommsConnType,SuccessRecord[]> s_records =
|
||||||
new HashMap<CommsConnType,SuccessRecord[]>();
|
new HashMap<CommsConnType,SuccessRecord[]>();
|
||||||
private static Class s_lockObj = ConnStatusHandler.class;
|
private static Class s_lockObj = ConnStatusHandler.class;
|
||||||
private static boolean s_needsSave = false;
|
private static boolean s_needsSave = false;
|
||||||
|
@ -373,16 +361,9 @@ public class ConnStatusHandler {
|
||||||
new ObjectInputStream( new ByteArrayInputStream(bytes) );
|
new ObjectInputStream( new ByteArrayInputStream(bytes) );
|
||||||
s_records =
|
s_records =
|
||||||
(HashMap<CommsConnType,SuccessRecord[]>)ois.readObject();
|
(HashMap<CommsConnType,SuccessRecord[]>)ois.readObject();
|
||||||
// } catch ( java.io.StreamCorruptedException sce ) {
|
|
||||||
// DbgUtils.logf( "loadState: %s", sce.toString() );
|
|
||||||
// } catch ( java.io.OptionalDataException ode ) {
|
|
||||||
// DbgUtils.logf( "loadState: %s", ode.toString() );
|
|
||||||
// } catch ( java.io.IOException ioe ) {
|
|
||||||
// DbgUtils.logf( "loadState: %s", ioe.toString() );
|
|
||||||
// } catch ( java.lang.ClassNotFoundException cnfe ) {
|
|
||||||
// DbgUtils.logf( "loadState: %s", cnfe.toString() );
|
|
||||||
} catch ( Exception ex ) {
|
} catch ( Exception ex ) {
|
||||||
Log.ex( TAG, ex );
|
Log.ex( TAG, ex );
|
||||||
|
s_records = new HashMap<CommsConnType,SuccessRecord[]>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -494,7 +475,7 @@ public class ConnStatusHandler {
|
||||||
try {
|
try {
|
||||||
ObjectOutputStream out
|
ObjectOutputStream out
|
||||||
= new ObjectOutputStream( bas );
|
= new ObjectOutputStream( bas );
|
||||||
out.writeObject(s_records);
|
out.writeObject( s_records );
|
||||||
out.flush();
|
out.flush();
|
||||||
String as64 =
|
String as64 =
|
||||||
XwJNI.base64EncodeJava( bas.toByteArray() );
|
XwJNI.base64EncodeJava( bas.toByteArray() );
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
# To enable ProGuard in your project, edit project.properties
|
|
||||||
# to define the proguard.config property as described in that file.
|
|
||||||
#
|
|
||||||
# Add project specific ProGuard rules here.
|
|
||||||
# By default, the flags in this file are appended to flags specified
|
|
||||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
|
||||||
# You can edit the include path and order by changing the ProGuard
|
|
||||||
# include property in project.properties.
|
|
||||||
#
|
|
||||||
# For more details, see
|
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
||||||
|
|
||||||
# Add any project specific keep options here:
|
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
Loading…
Add table
Reference in a new issue