21
21
import android .app .AlertDialog ;
22
22
import android .app .Dialog ;
23
23
import android .app .ProgressDialog ;
24
+ import android .content .ClipData ;
25
+ import android .content .ClipboardManager ;
24
26
import android .content .DialogInterface ;
25
27
import android .content .Intent ;
26
28
import android .content .SharedPreferences ;
@@ -112,7 +114,8 @@ public class DroidZebra extends FragmentActivity
112
114
SETTINGS_KEY_DISPLAY_ENABLE_ANIMATIONS = "settings_ui_display_enable_animations" ;
113
115
114
116
private final CandidateMoves mCandidateMoves = new CandidateMoves ();
115
- public int mSettingFunction = DEFAULT_SETTING_FUNCTION ;
117
+ private ClipboardManager clipboard ;
118
+ public int mSettingFunction = DEFAULT_SETTING_FUNCTION ;
116
119
public boolean mSettingAutoMakeForcedMoves = DEFAULT_SETTING_AUTO_MAKE_FORCED_MOVES ;
117
120
public int mSettingZebraRandomness = DEFAULT_SETTING_RANDOMNESS ;
118
121
public String mSettingZebraForceOpening = DEFAULT_SETTING_FORCE_OPENING ;
@@ -143,8 +146,10 @@ public class DroidZebra extends FragmentActivity
143
146
private DroidZebraHandler mDroidZebraHandler = null ;
144
147
145
148
public DroidZebra () {
149
+
146
150
initBoard ();
147
- }
151
+
152
+ }
148
153
149
154
public boolean isThinking () {
150
155
return mZebraThread .isThinking ();
@@ -330,6 +335,9 @@ public void onCreate(Bundle savedInstanceState)
330
335
{
331
336
super .onCreate (savedInstanceState );
332
337
338
+
339
+ clipboard = (ClipboardManager ) getSystemService (CLIPBOARD_SERVICE );
340
+
333
341
setContentView (R .layout .spash_layout );
334
342
if (android .os .Build .VERSION .SDK_INT >= 11 ) {
335
343
new ActionBarHelper ().hide ();
@@ -686,17 +694,17 @@ public void showQuitDialog() {
686
694
}
687
695
688
696
private void enterMoves () {
689
- DialogFragment newFragment = DialogMoves .newInstance ();
690
- showDialog (newFragment , "dialog_moves" );
697
+ DialogFragment newFragment = DialogMoves .newInstance (clipboard );
698
+ showDialog (newFragment , "dialog_moves" );
691
699
}
692
700
693
701
private void setUpBoard (String s ) {
694
702
final LinkedList <Move > moves = makeMoveList (s );
695
703
mZebraThread .sendReplayMoves (moves );
696
704
}
697
705
698
- private LinkedList <Move > makeMoveList (String s ) {
699
- LinkedList <Move > moves = new LinkedList <Move >();
706
+ private static LinkedList <Move > makeMoveList (String s ) {
707
+ LinkedList <Move > moves = new LinkedList <Move >();
700
708
Pattern p = Pattern .compile ("([ABCDEFGH]{1}[12345678]{1})+" );
701
709
Matcher matcher = p .matcher (s .toUpperCase ());
702
710
if (!matcher .matches ()) {
@@ -972,8 +980,12 @@ public void onClick(DialogInterface dialog, int id) {
972
980
// Moves as Text
973
981
public static class DialogMoves extends DialogFragment {
974
982
975
- public static DialogMoves newInstance () {
976
- return new DialogMoves ();
983
+ private ClipboardManager clipBoard ;
984
+
985
+ public static DialogMoves newInstance (ClipboardManager clipBoard ) {
986
+ DialogMoves moves = new DialogMoves ();
987
+ moves .setClipBoard (clipBoard );
988
+ return moves ;
977
989
}
978
990
979
991
public DroidZebra getDroidZebra () {
@@ -991,6 +1003,24 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
991
1003
input .setInputType (InputType .TYPE_CLASS_TEXT );
992
1004
builder .setView (input );
993
1005
1006
+ if (clipBoard != null ) {
1007
+ String possibleMatch = null ;
1008
+ ClipData primaryClip = clipBoard .getPrimaryClip ();
1009
+ for (int i = 0 ; i < primaryClip .getItemCount (); i ++) {
1010
+ ClipData .Item clip = primaryClip .getItemAt (i );
1011
+ CharSequence charSequence = clip .coerceToText (getActivity ().getBaseContext ());
1012
+ if (charSequence != null ) {
1013
+ possibleMatch = charSequence .toString ();
1014
+ break ;
1015
+ }
1016
+ }
1017
+
1018
+ if (possibleMatch != null && !DroidZebra .makeMoveList (possibleMatch ).isEmpty ()) {
1019
+ input .setText (possibleMatch );
1020
+ }
1021
+ }
1022
+
1023
+
994
1024
// Set up the buttons
995
1025
builder .setPositiveButton (R .string .dialog_ok , new DialogInterface .OnClickListener () {
996
1026
@ Override
@@ -1007,6 +1037,10 @@ public void onClick(DialogInterface dialog, int which) {
1007
1037
1008
1038
return builder .create ();
1009
1039
}
1040
+
1041
+ public void setClipBoard (ClipboardManager clipBoard ) {
1042
+ this .clipBoard = clipBoard ;
1043
+ }
1010
1044
}
1011
1045
1012
1046
//-------------------------------------------------------------------------
0 commit comments