mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
save and restore chat text selection
This commit is contained in:
parent
91a58ab041
commit
c11c1f4a64
2 changed files with 25 additions and 6 deletions
|
@ -138,10 +138,12 @@ public class ChatDelegate extends DelegateBase {
|
|||
finish();
|
||||
} else {
|
||||
s_visibleThis = this;
|
||||
String curMsg = DBUtils.getCurChat( m_activity, m_rowid, m_curPlayer );
|
||||
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( curMsg.length() );
|
||||
m_edit.setSelection( startAndEnd[0], startAndEnd[1] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +157,9 @@ public class ChatDelegate extends DelegateBase {
|
|||
s_visibleThis = null;
|
||||
|
||||
String curText = m_edit.getText().toString();
|
||||
DBUtils.setCurChat( m_activity, m_rowid, m_curPlayer, curText );
|
||||
DBUtils.setCurChat( m_activity, m_rowid, m_curPlayer, curText,
|
||||
m_edit.getSelectionStart(),
|
||||
m_edit.getSelectionEnd() );
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
|
|
@ -1312,13 +1312,28 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static String getCurChat( Context context, long rowid, int player ) {
|
||||
public static String getCurChat( Context context, long rowid, int player,
|
||||
int[] startAndEndOut ) {
|
||||
String result = null;
|
||||
String key = formatCurChatKey( rowid, player );
|
||||
return getStringFor( context, key, "" );
|
||||
String all = getStringFor( context, key, "" );
|
||||
String[] parts = TextUtils.split( all, ":" );
|
||||
if ( 3 <= parts.length ) {
|
||||
result = all.substring( 2 + parts[0].length() + parts[1].length() );
|
||||
startAndEndOut[0] = Math.min( result.length(),
|
||||
Integer.parseInt( parts[0] ) );
|
||||
startAndEndOut[1] = Math.min( result.length(),
|
||||
Integer.parseInt( parts[1] ) );
|
||||
}
|
||||
DbgUtils.logdf( "getCurChat(): => %s [%d,%d]", result,
|
||||
startAndEndOut[0], startAndEndOut[1] );
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void setCurChat( Context context, long rowid, int player, String text ) {
|
||||
public static void setCurChat( Context context, long rowid, int player,
|
||||
String text, int start, int end ) {
|
||||
String key = formatCurChatKey( rowid, player );
|
||||
text = String.format( "%d:%d:%s", start, end, text );
|
||||
setStringFor( context, key, text );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue