diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-06-29 15:10:46 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-06-29 15:10:46 +0200 |
commit | 9c38b82ce276d0b5723cdd4e83eee422eb1568b6 (patch) | |
tree | 067812d3da9a2d43944c64c982ffa973d81e0fc3 /android/src/ch/asynk | |
parent | ae07c9551c338d2f6ee08d70beccfcbe89f93a74 (diff) | |
download | RustAndDust-9c38b82ce276d0b5723cdd4e83eee422eb1568b6.zip RustAndDust-9c38b82ce276d0b5723cdd4e83eee422eb1568b6.tar.gz |
AndroidBackend: add updateUsers : collects users with an email of type 'Rustanddust'
Diffstat (limited to 'android/src/ch/asynk')
-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); } } |