diff options
Diffstat (limited to 'android/src/ch')
-rw-r--r-- | android/src/ch/asynk/rustanddust/android/AndroidBackend.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/android/src/ch/asynk/rustanddust/android/AndroidBackend.java b/android/src/ch/asynk/rustanddust/android/AndroidBackend.java index 796e4e2..6454dfb 100644 --- a/android/src/ch/asynk/rustanddust/android/AndroidBackend.java +++ b/android/src/ch/asynk/rustanddust/android/AndroidBackend.java @@ -1,13 +1,19 @@ package ch.asynk.rustanddust.android; +import com.badlogic.gdx.Gdx; + import android.app.Application; import android.content.Context; +import android.database.Cursor; import android.accounts.Account; import android.accounts.AccountManager; +import android.provider.ContactsContract; import ch.asynk.rustanddust.RustAndDust; +import ch.asynk.rustanddust.ui.List.ListElement; import ch.asynk.rustanddust.util.Backend; +import ch.asynk.rustanddust.util.PlayerRecord; public class AndroidBackend implements Backend { @@ -23,6 +29,49 @@ public class AndroidBackend implements Backend public int getMyId() { return me; } public int getOpponentId() { return opponent; } + private void updateUsers(final RustAndDust game) + { + new Thread( new Runnable() { + @Override + public void run() { + Cursor ccs = app.getContentResolver().query( + ContactsContract.CommonDataKinds.Email.CONTENT_URI, + new String[] { + ContactsContract.Data.DISPLAY_NAME, + ContactsContract.CommonDataKinds.Email.DATA1, + }, + ContactsContract.CommonDataKinds.Email.DATA1 + " like '%gmail.com' and " + ContactsContract.CommonDataKinds.Email.DATA3 + " like 'Rustanddust'", + null, null); + + if (ccs == null) { + RustAndDust.debug("No Contacts found"); + return; + } + + PlayerRecord.clearList(); + RustAndDust.debug("Contacts :"); + while (ccs.moveToNext()) { + PlayerRecord r = PlayerRecord.get(); + r.name = ccs.getString(0); + r.email = ccs.getString(1); + PlayerRecord.list.add(r); + RustAndDust.debug( " " + r.toString()); + } + + Gdx.app.postRunnable( new Runnable() { + @Override + public void run() { + for (ListElement e : PlayerRecord.list) { + PlayerRecord r = (PlayerRecord) e; + game.db.storePlayer(r.name, r.email); + } + PlayerRecord.clearList(); + } + }); + } + }).start(); + } + @Override public void init(final RustAndDust game) { @@ -35,5 +84,7 @@ public class AndroidBackend implements Backend else me = game.db.storePlayerGetId("me", "myself"); opponent = me; + + updateUsers(game); } } |