├── README.md
├── libs
└── android-support-v4.jar
├── res
├── drawable-hdpi
│ ├── ic_send.png
│ ├── ic_games.png
│ ├── ic_refresh.png
│ ├── ic_launcher.png
│ ├── ic_messages.png
│ ├── ic_settings.png
│ ├── ic_new_message.png
│ ├── ic_player_info.png
│ └── ic_statistics.png
├── drawable-mdpi
│ ├── ic_send.png
│ ├── ic_games.png
│ ├── ic_refresh.png
│ ├── ic_launcher.png
│ ├── ic_messages.png
│ ├── ic_settings.png
│ ├── ic_new_message.png
│ ├── ic_player_info.png
│ └── ic_statistics.png
├── drawable-xhdpi
│ ├── ic_games.png
│ ├── ic_send.png
│ ├── ic_launcher.png
│ ├── ic_messages.png
│ ├── ic_refresh.png
│ ├── ic_settings.png
│ ├── ic_new_message.png
│ ├── ic_player_info.png
│ └── ic_statistics.png
├── drawable
│ └── border.xml
├── values
│ ├── shared_ids.xml
│ ├── player_state_colors.xml
│ ├── game_state_colors.xml
│ └── strings.xml
├── xml
│ └── general_overview_widgetinfo.xml
├── menu
│ ├── message_context_menu.xml
│ └── navigation_menu.xml
├── layout
│ ├── navigation_button.xml
│ ├── message_listing_activity.xml
│ ├── game_listing_activity.xml
│ ├── player_view.xml
│ ├── general_overview_widget.xml
│ ├── message_view.xml
│ ├── message_write_activity.xml
│ ├── settings_activity.xml
│ └── game_view.xml
├── layout-large
│ ├── game_listing_activity.xml
│ ├── player_view.xml
│ ├── message_view.xml
│ └── game_view.xml
├── layout-xlarge
│ ├── game_listing_activity.xml
│ ├── player_view.xml
│ ├── message_view.xml
│ └── game_view.xml
├── layout-land
│ ├── message_view.xml
│ └── game_view.xml
├── layout-small-land
│ ├── message_view.xml
│ └── game_view.xml
├── values-en
│ └── strings.xml
├── values-en-rGB
│ └── strings.xml
├── values-en-rUS
│ └── strings.xml
├── values-de
│ └── strings.xml
├── layout-normal
│ └── game_view.xml
└── layout-small
│ └── game_view.xml
├── AndroidManifest.xml
├── .gitignore
├── project.properties
├── src
└── de
│ └── raptor2101
│ └── BattleWorldsKronos
│ └── Connector
│ ├── Tasks
│ ├── LoaderTask.java
│ ├── DeleteMessageTask.java
│ ├── ServerConnectionTask.java
│ ├── MessageLoaderTask.java
│ ├── SendMessageTask.java
│ └── GamesLoaderTask.java
│ ├── Gui
│ ├── Controls
│ │ ├── NavigationButton.java
│ │ └── NavigationMenu.java
│ ├── Views
│ │ ├── PlayerView.java
│ │ ├── MessageView.java
│ │ └── GameView.java
│ ├── Adapters
│ │ ├── GameViewAdapter.java
│ │ ├── MessageViewAdapter.java
│ │ └── NavigationButtonAdapter.java
│ ├── Activities
│ │ ├── AbstractWriteMessageActivity.java
│ │ ├── AbstractGameListingActivity.java
│ │ ├── SettingsActivity.java
│ │ └── AbstractMessageListingActivity.java
│ └── WidgetProviders
│ │ └── GeneralOverviewProvider.java
│ ├── AbstractConnectorApp.java
│ ├── ApplicationSettings.java
│ ├── Data
│ ├── Entities
│ │ ├── Message.java
│ │ ├── Player.java
│ │ └── Game.java
│ ├── DbHelper.java
│ └── Database.java
│ └── NotificationService.java
└── proguard-project.txt
/README.md:
--------------------------------------------------------------------------------
1 | BWKConnector.Library.Base
2 | =========================
3 |
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_send.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-hdpi/ic_send.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_send.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-mdpi/ic_send.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_games.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-hdpi/ic_games.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-hdpi/ic_refresh.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_games.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-mdpi/ic_games.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-mdpi/ic_refresh.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_games.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-xhdpi/ic_games.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_send.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-xhdpi/ic_send.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_messages.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-hdpi/ic_messages.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-hdpi/ic_settings.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_messages.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-mdpi/ic_messages.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-mdpi/ic_settings.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_messages.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-xhdpi/ic_messages.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-xhdpi/ic_refresh.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-xhdpi/ic_settings.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-hdpi/ic_new_message.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_player_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-hdpi/ic_player_info.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_statistics.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-hdpi/ic_statistics.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-mdpi/ic_new_message.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_player_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-mdpi/ic_player_info.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_statistics.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-mdpi/ic_statistics.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_new_message.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-xhdpi/ic_new_message.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_player_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-xhdpi/ic_player_info.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_statistics.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raptor2101/BWKConnector.Library.Base/master/res/drawable-xhdpi/ic_statistics.png
--------------------------------------------------------------------------------
/res/drawable/border.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/shared_ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/xml/general_overview_widgetinfo.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Intellij project files
26 | *.iml
27 | *.ipr
28 | *.iws
29 | .idea/
30 |
--------------------------------------------------------------------------------
/res/menu/message_context_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
--------------------------------------------------------------------------------
/res/values/player_state_colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3C0000
4 | #3C0000
5 | #3C0000
6 | #003C00
7 | #00000000
8 | #646400
9 | #444444
10 | #00000000
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values/game_state_colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF646464
4 | #FF646464
5 | #FFC80000
6 | #FF00C800
7 | #FFFFFF
8 | #FFFF00
9 | #FFFFFF
10 | #FFFFFF
11 | #FFFFFF
12 |
13 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-10
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Tasks/LoaderTask.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Tasks;
2 |
3 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
4 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Database;
5 |
6 | public abstract class LoaderTask extends ServerConnectionTask{
7 |
8 | private Database mDatabase;
9 |
10 | public LoaderTask(AbstractConnectorApp app, ResultListener resultListener) {
11 | super(app, resultListener);
12 | mDatabase = app.getDatabase();
13 | }
14 |
15 | protected Database getDatabase(){
16 | return mDatabase;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/res/menu/navigation_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
24 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Tasks/DeleteMessageTask.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Tasks;
2 |
3 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
4 | import de.raptor2101.BattleWorldsKronos.Connector.JSON.ServerConnection;
5 |
6 | public class DeleteMessageTask extends ServerConnectionTask{
7 |
8 | public DeleteMessageTask(AbstractConnectorApp app, ResultListener resultListener) {
9 | super(app, resultListener);
10 | }
11 |
12 | @Override
13 | protected Void doInBackground(Integer... params) {
14 | try {
15 | ServerConnection connection = getConnection();
16 |
17 | if(connection == null){
18 | return null;
19 | }
20 |
21 | for(Integer messageId:params){
22 | connection.deleteMessage(messageId);
23 | }
24 | } catch (Exception e) {
25 |
26 | }
27 |
28 | return null;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/res/layout/navigation_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
18 |
19 |
25 |
26 |
--------------------------------------------------------------------------------
/res/layout/message_listing_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/layout/game_listing_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Controls/NavigationButton.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Controls;
2 |
3 |
4 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
5 | import android.content.Context;
6 | import android.graphics.drawable.Drawable;
7 | import android.view.LayoutInflater;
8 | import android.widget.ImageView;
9 | import android.widget.LinearLayout;
10 | import android.widget.TextView;
11 |
12 | public class NavigationButton extends LinearLayout{
13 |
14 | public NavigationButton(Context context, int buttonId, CharSequence title, Drawable iconDrawable) {
15 | super(context);
16 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
17 | inflater.inflate(R.layout.navigation_button, this);
18 |
19 | setId(buttonId);
20 | TextView textView = (TextView) findViewById(R.id.navigation_button_text);
21 | textView.setText(title);
22 |
23 | ImageView imageView = (ImageView) findViewById(R.id.navigation_button_icon);
24 | imageView.setImageDrawable(iconDrawable);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/AbstractConnectorApp.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector;
2 |
3 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Database;
4 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
5 | import android.app.Activity;
6 | import android.app.Application;
7 | import android.net.http.AndroidHttpClient;
8 |
9 |
10 | public abstract class AbstractConnectorApp extends Application {
11 | private Database mDatabase;
12 |
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 | mDatabase = new Database(this);
17 | mDatabase.open();
18 | mDatabase.resetTimestamps();
19 | }
20 |
21 | @Override
22 | public void onTerminate() {
23 | super.onTerminate();
24 | mDatabase.close();
25 | }
26 |
27 | public Database getDatabase(){
28 | return mDatabase;
29 | }
30 |
31 | public AndroidHttpClient getHttpClient(){
32 | return AndroidHttpClient.newInstance(this.getString(R.string.app_name));
33 | }
34 |
35 | public abstract Class extends Activity> getGameListingActivityClass();
36 | public abstract Class extends Activity> getMessageListingActivityClass();
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/res/layout-large/game_listing_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/res/layout-xlarge/game_listing_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Views/PlayerView.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Views;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.widget.LinearLayout;
6 | import android.widget.TextView;
7 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Player.State;
8 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Player;
9 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
10 |
11 | public class PlayerView extends LinearLayout {
12 |
13 | public PlayerView(Context context) {
14 | super(context);
15 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
16 | inflater.inflate(R.layout.player_view, this);
17 |
18 | }
19 |
20 | public void setPlayerInfo(Player player) {
21 | State state = player.getState();
22 | LinearLayout playerLine = (LinearLayout) findViewById(R.id.label_player_info_view_PlayerLine);
23 | playerLine.setBackgroundColor(state.getColor(this.getContext()));
24 |
25 | TextView textView = (TextView) findViewById(R.id.text_player_info_view_PlayerName);
26 | textView.setText(player.getPlayerName());
27 |
28 | textView = (TextView) findViewById(R.id.text_player_info_view_PlayerState);
29 | textView.setText(state.getResourceId());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Adapters/GameViewAdapter.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Adapters;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Game;
7 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.Views.GameView;
8 |
9 | import android.content.Context;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.BaseAdapter;
13 |
14 | public class GameViewAdapter extends BaseAdapter {
15 |
16 | private List mGames;
17 | private Context mContext;
18 |
19 | public GameViewAdapter(Context context){
20 | mGames = new ArrayList(0);
21 | mContext =context;
22 | }
23 |
24 | public void setGames(List games){
25 | mGames = games;
26 | this.notifyDataSetChanged();
27 | }
28 |
29 | @Override
30 | public int getCount() {
31 | return mGames.size();
32 | }
33 |
34 | @Override
35 | public Object getItem(int position) {
36 |
37 | return mGames.get(position);
38 | }
39 |
40 | @Override
41 | public long getItemId(int position) {
42 | return mGames.get(position).getGameId();
43 | }
44 |
45 | @Override
46 | public View getView(int position, View currentView, ViewGroup parent) {
47 | GameView view;
48 | if(currentView != null){
49 | view = (GameView) currentView;
50 |
51 | }
52 | else {
53 | view = new GameView(mContext);
54 | }
55 | view.setGame(mGames.get(position));
56 | return (View)view;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Adapters/MessageViewAdapter.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Adapters;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Message;
7 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.Views.MessageView;
8 |
9 | import android.content.Context;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.BaseAdapter;
13 |
14 | public class MessageViewAdapter extends BaseAdapter {
15 |
16 | private List mMassages;
17 | private Context mContext;
18 |
19 | public MessageViewAdapter(Context context){
20 | mMassages = new ArrayList(0);
21 | mContext =context;
22 | }
23 |
24 | public void setMessages(List messages){
25 | mMassages = messages;
26 | this.notifyDataSetChanged();
27 | }
28 |
29 | @Override
30 | public int getCount() {
31 | return mMassages.size();
32 | }
33 |
34 | @Override
35 | public Object getItem(int position) {
36 |
37 | return mMassages.get(position);
38 | }
39 |
40 | @Override
41 | public long getItemId(int position) {
42 | return mMassages.get(position).getMessageId();
43 | }
44 |
45 | @Override
46 | public View getView(int position, View currentView, ViewGroup parent) {
47 | MessageView view;
48 | if(currentView != null){
49 | view = (MessageView) currentView;
50 |
51 | }
52 | else {
53 | view = new MessageView(mContext);
54 | }
55 | view.setMessage(mMassages.get(position));
56 | return (View)view;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Tasks/ServerConnectionTask.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Tasks;
2 |
3 | import java.io.IOException;
4 |
5 | import org.apache.http.client.ClientProtocolException;
6 |
7 | import android.net.http.AndroidHttpClient;
8 | import android.os.AsyncTask;
9 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
10 | import de.raptor2101.BattleWorldsKronos.Connector.ApplicationSettings;
11 | import de.raptor2101.BattleWorldsKronos.Connector.JSON.ServerConnection;
12 |
13 | public abstract class ServerConnectionTask extends AsyncTask{
14 | public interface ResultListener {
15 | void handleResult(TResultType result);
16 | }
17 |
18 | private AndroidHttpClient mHttpClient;
19 | private String mEMail;
20 | private String mPassword;
21 | private ResultListener mListener;
22 |
23 | protected ServerConnectionTask(AbstractConnectorApp app, ResultListener resultListener) {
24 | ApplicationSettings settings = new ApplicationSettings(app);
25 | mHttpClient = app.getHttpClient();
26 | mEMail = settings.getEmail();
27 | mPassword = settings.getPassword();
28 | mListener = resultListener;
29 | }
30 |
31 | protected ServerConnection getConnection() throws ClientProtocolException, IOException{
32 | ServerConnection connection = new ServerConnection(mHttpClient);
33 | if(connection.login(mEMail, mPassword)){
34 | return connection;
35 | }
36 |
37 | return null;
38 | }
39 |
40 | @Override
41 | protected abstract TResultType doInBackground(TParemeterType... params);
42 |
43 | @Override
44 | protected void onPostExecute(TResultType result) {
45 | mListener.handleResult(result);
46 | mHttpClient.close();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/res/layout/player_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
18 |
22 |
23 |
28 |
29 |
30 |
36 |
37 |
41 |
42 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/res/layout-large/player_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
18 |
22 |
23 |
28 |
29 |
30 |
36 |
37 |
41 |
42 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/res/layout-xlarge/player_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
18 |
22 |
23 |
28 |
29 |
30 |
36 |
37 |
41 |
42 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Tasks/MessageLoaderTask.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Tasks;
2 |
3 | import java.util.List;
4 |
5 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
6 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Database;
7 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Message;
8 | import de.raptor2101.BattleWorldsKronos.Connector.JSON.ServerConnection;
9 |
10 | public class MessageLoaderTask extends LoaderTask {
11 | public MessageLoaderTask(AbstractConnectorApp app, ResultListener resultListener) {
12 | super(app, resultListener);
13 | }
14 |
15 | public class Result {
16 | private final List mMessages;
17 | private final int mUnnotifiedMessages;
18 |
19 | public List getMessages() {
20 | return mMessages;
21 | }
22 |
23 | public int getUnnotifiedMessages() {
24 | return mUnnotifiedMessages;
25 | }
26 |
27 | public Result(List messages, int unnotfiedMessages) {
28 | mMessages = messages;
29 | mUnnotifiedMessages = unnotfiedMessages;
30 | }
31 | }
32 |
33 | @Override
34 | protected Result doInBackground(Boolean... params) {
35 | if (!isCancelled()) {
36 | try {
37 | Database database = getDatabase();
38 | boolean forceUpdate = params.length > 0 && params[0];
39 |
40 | List messages = null;
41 | if (forceUpdate) {
42 | ServerConnection connection = getConnection();
43 | if (connection != null) {
44 | messages = connection.getMessages();
45 | database.persistMessage(messages);
46 | }
47 | }
48 |
49 | messages = database.getMessages();
50 |
51 | return new Result(messages, 0);
52 | } catch (Exception e) {
53 | // TODO Auto-generated catch block
54 | e.printStackTrace();
55 | }
56 | }
57 | return null;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Controls/NavigationMenu.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Controls;
2 |
3 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
4 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
5 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.Adapters.NavigationButtonAdapter;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 | import android.widget.AdapterView;
11 | import android.widget.ListView;
12 |
13 | public class NavigationMenu extends ListView implements android.widget.AdapterView.OnItemClickListener {
14 | private NavigationButtonAdapter mAdapter;
15 | private Context mContext;
16 |
17 | public NavigationMenu(Context context) {
18 | super(context);
19 | setupNavigationMenu(context);
20 | }
21 |
22 | public NavigationMenu(Context context, AttributeSet attrs){
23 | super(context,attrs);
24 | setupNavigationMenu(context);
25 | }
26 |
27 | public NavigationMenu(Context context, AttributeSet attrs, int defStyle){
28 | super(context,attrs,defStyle);
29 | setupNavigationMenu(context);
30 | }
31 |
32 | private void setupNavigationMenu(Context context){
33 | if(isInEditMode()){
34 | return;
35 | }
36 |
37 | mContext = context;
38 | mAdapter = new NavigationButtonAdapter(context, R.menu.navigation_menu);
39 | this.setAdapter(mAdapter);
40 |
41 | this.setOnItemClickListener(this);
42 | }
43 |
44 | @Override
45 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
46 |
47 | AbstractConnectorApp app = (AbstractConnectorApp) mContext.getApplicationContext();
48 |
49 | if(id == R.id.navigation_messages){
50 | Intent intent = new Intent(mContext, app.getMessageListingActivityClass());
51 | mContext.startActivity(intent);
52 | } else if (id == R.id.navigation_games){
53 | Intent intent = new Intent(mContext, app.getGameListingActivityClass());
54 | mContext.startActivity(intent);
55 | }
56 | }
57 |
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/ApplicationSettings.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector;
2 |
3 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 |
7 | public class ApplicationSettings {
8 | private final static String PREFERENCE_NAME_EMAIL ="e-mail";
9 | private final static String PREFERENCE_NAME_PASSWORD ="password";
10 | private final static String PREFERENCE_NAME_REFRESH_CYCLE ="refreshCylce";
11 | private final static String PREFERENCE_NAME_ENABLE_NOTIFY_ON_GAMES ="gameNotification";
12 | private final static String PREFERENCE_NAME_ENABLE_NOTIFY_ON_MESSAGES ="messageNotification";
13 |
14 | public final static String EmptyResult = "";
15 |
16 | SharedPreferences mSettings;
17 |
18 | public ApplicationSettings(Context context){
19 | mSettings = context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE);
20 | }
21 |
22 | public String getEmail(){
23 | return mSettings.getString(PREFERENCE_NAME_EMAIL, EmptyResult);
24 | }
25 |
26 | public String getPassword(){
27 | return mSettings.getString(PREFERENCE_NAME_PASSWORD, EmptyResult);
28 | }
29 |
30 | public boolean isNotifyOnGamesEnabled(){
31 | return mSettings.getInt(PREFERENCE_NAME_ENABLE_NOTIFY_ON_GAMES, 0) == 1;
32 | }
33 | public boolean isNotifyOnMessagesEnabled(){
34 | return mSettings.getInt(PREFERENCE_NAME_ENABLE_NOTIFY_ON_MESSAGES, 0) == 1;
35 | }
36 |
37 | public int getRefreshCylce(){
38 | return mSettings.getInt(PREFERENCE_NAME_REFRESH_CYCLE, 30*60*1000);
39 | }
40 |
41 | public void Save(String eMail, String password, boolean isNotifyOnGamesEnabled, boolean isNotifyOnMessagesEnabled, int refreshCycle){
42 | SharedPreferences.Editor editor = mSettings.edit();
43 | editor.putString(PREFERENCE_NAME_EMAIL, eMail);
44 | editor.putString(PREFERENCE_NAME_PASSWORD, password);
45 |
46 | editor.putInt(PREFERENCE_NAME_ENABLE_NOTIFY_ON_GAMES, isNotifyOnGamesEnabled?1:0);
47 | editor.putInt(PREFERENCE_NAME_ENABLE_NOTIFY_ON_MESSAGES, isNotifyOnMessagesEnabled?1:0);
48 | editor.putInt(PREFERENCE_NAME_REFRESH_CYCLE, refreshCycle);
49 |
50 | editor.commit();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Tasks/SendMessageTask.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Tasks;
2 |
3 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
4 | import de.raptor2101.BattleWorldsKronos.Connector.JSON.ServerConnection;
5 |
6 | public class SendMessageTask extends ServerConnectionTask{
7 | public SendMessageTask(AbstractConnectorApp app, ResultListener resultListener) {
8 | super(app, resultListener);
9 | }
10 |
11 | public static class Message{
12 | private String mText;
13 | private String mReceiver;
14 | private int mLastMessageId;
15 |
16 | public String getText() {
17 | return mText;
18 | }
19 | public void setText(String text) {
20 | this.mText = text;
21 | }
22 | public String getReceiver() {
23 | return mReceiver;
24 | }
25 | public void setReceiver(String receiver) {
26 | this.mReceiver = receiver;
27 | }
28 | public int getLastMessageId() {
29 | return mLastMessageId;
30 | }
31 | public void setLastMessageId(int lastMessageId) {
32 | this.mLastMessageId = lastMessageId;
33 | }
34 | }
35 |
36 | public class Result{
37 | private boolean mAllMessagesSendedSuccessFully;
38 |
39 | public Result(boolean allMessagesSendedSuccessFully){
40 | mAllMessagesSendedSuccessFully = allMessagesSendedSuccessFully;
41 | }
42 |
43 | public boolean areAllMessagesSuccesfullySend(){
44 | return mAllMessagesSendedSuccessFully;
45 | }
46 | }
47 |
48 | @Override
49 | protected Result doInBackground(Message... messages) {
50 | try {
51 | ServerConnection connection = getConnection();
52 |
53 | if(connection == null){
54 | return new Result(false);
55 | }
56 |
57 | boolean allMessagesSendedSuccessFully = false;
58 |
59 | for(Message message:messages){
60 | allMessagesSendedSuccessFully = connection.sendMessage(message.getReceiver(), message.getText(), message.getLastMessageId());
61 | if(allMessagesSendedSuccessFully!= true){
62 | break;
63 | }
64 | }
65 | return new Result(allMessagesSendedSuccessFully);
66 | } catch (Exception e) {
67 | return new Result(false);
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Data/Entities/Message.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Data.Entities;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | public class Message implements Serializable {
7 | private static final long serialVersionUID = -9093944735684552706L;
8 |
9 | private int mMessageId;
10 | private int mAuthorId;
11 | private String mAuthorName;
12 | private Date mTimestamp;
13 | private String mMessageText;
14 | private int mLastMessageId;
15 | private boolean mIsSystemMessage;
16 |
17 | private boolean mIsReaded;
18 | private boolean mIsDiscarded;
19 | private boolean mIsDeleted;
20 | public int getMessageId() {
21 | return mMessageId;
22 | }
23 | public void setMessageId(int messageId) {
24 | this.mMessageId = messageId;
25 | }
26 | public int getAuthorId() {
27 | return mAuthorId;
28 | }
29 | public void setAuthorId(int authorId) {
30 | this.mAuthorId = authorId;
31 | }
32 | public String getAuthorName() {
33 | return mAuthorName;
34 | }
35 | public void setAuthorName(String authorName) {
36 | this.mAuthorName = authorName;
37 | }
38 | public Date getTimestamp() {
39 | return mTimestamp;
40 | }
41 | public void setTimestamp(Date timestamp) {
42 | this.mTimestamp = timestamp;
43 | }
44 | public String getMessageText() {
45 | return mMessageText;
46 | }
47 | public void setMessageText(String text) {
48 | this.mMessageText = text;
49 | }
50 | public int getLastMessageId() {
51 | return mLastMessageId;
52 | }
53 | public void setLastMessageId(int lastMessageId) {
54 | this.mLastMessageId = lastMessageId;
55 | }
56 | public boolean isSystemMessage() {
57 | return mIsSystemMessage;
58 | }
59 | public void setSystemMessage(boolean isSystemMessage) {
60 | this.mIsSystemMessage = isSystemMessage;
61 | }
62 | public boolean isReaded() {
63 | return mIsReaded;
64 | }
65 | public void setReaded(boolean isReaded) {
66 | this.mIsReaded = isReaded;
67 | }
68 | public boolean isDiscarded() {
69 | return mIsDiscarded;
70 | }
71 | public void setDiscarded(boolean isDiscarded) {
72 | this.mIsDiscarded = isDiscarded;
73 | }
74 | public boolean isDeleted() {
75 | return mIsDeleted;
76 | }
77 | public void setDeleted(boolean isDeleted) {
78 | this.mIsDeleted = isDeleted;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/res/layout/general_overview_widget.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
19 |
20 |
25 |
30 |
31 |
36 |
41 |
42 |
47 |
52 |
--------------------------------------------------------------------------------
/res/layout/message_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
24 |
25 |
29 |
30 |
39 |
40 |
44 |
45 |
54 |
55 |
56 |
63 |
64 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Views/MessageView.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Views;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Locale;
5 |
6 | import android.content.Context;
7 | import android.content.res.Resources;
8 | import android.view.LayoutInflater;
9 | import android.widget.LinearLayout;
10 | import android.widget.TextView;
11 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Message;
12 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
13 |
14 | public class MessageView extends LinearLayout {
15 | private SimpleDateFormat mFormater;
16 |
17 | private static final String TOKEN_SERVER_MESSAGE_WATCHLIST_PREFIX ="{{server_message_watchlist_prefix}}";
18 | private static final String TOKEN_SERVER_MESSAGE_WATCHLIST_SUFFIX ="{{server_message_watchlist_suffix}}";
19 |
20 | public MessageView(Context context) {
21 | super(context);
22 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
23 | inflater.inflate(R.layout.message_view, this);
24 | mFormater = new SimpleDateFormat(context.getString(R.string.date_format_string), Locale.getDefault());
25 | }
26 |
27 | public void setMessage(Message message) {
28 | TextView textView = (TextView) findViewById(R.id.text_message_info_view_author);
29 | textView.setText(message.getAuthorName());
30 |
31 | textView = (TextView)findViewById(R.id.text_message_info_view_date);
32 | textView.setText(mFormater.format(message.getTimestamp()));
33 |
34 | textView = (TextView)findViewById(R.id.text_message_info_view_message);
35 |
36 | String messageText = message.getMessageText();
37 | if(message.isSystemMessage()){
38 | Resources resources = this.getResources();
39 |
40 | StringBuilder builder = new StringBuilder(messageText);
41 |
42 | int startIndex = builder.indexOf(TOKEN_SERVER_MESSAGE_WATCHLIST_PREFIX);
43 | if(startIndex>-1){
44 | builder.replace(startIndex, TOKEN_SERVER_MESSAGE_WATCHLIST_PREFIX.length() + startIndex, resources.getString(R.string.server_message_watchlist_prefix));
45 | }
46 |
47 | startIndex = builder.indexOf(TOKEN_SERVER_MESSAGE_WATCHLIST_SUFFIX);
48 | if(startIndex>-1){
49 | builder.replace(startIndex, TOKEN_SERVER_MESSAGE_WATCHLIST_SUFFIX.length() + startIndex, resources.getString(R.string.server_message_watchlist_suffix));
50 | }
51 |
52 | messageText = builder.toString();
53 | }
54 |
55 | textView.setText(messageText);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/res/layout/message_write_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
17 |
18 |
24 |
25 |
33 |
34 |
41 |
42 |
47 |
48 |
49 |
50 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/res/layout-land/message_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
22 |
23 |
32 |
33 |
37 |
38 |
47 |
48 |
49 |
58 |
59 |
60 |
69 |
70 |
--------------------------------------------------------------------------------
/res/layout-large/message_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
22 |
23 |
32 |
33 |
37 |
38 |
47 |
48 |
49 |
58 |
59 |
60 |
69 |
70 |
--------------------------------------------------------------------------------
/res/layout-xlarge/message_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
22 |
23 |
32 |
33 |
37 |
38 |
47 |
48 |
49 |
58 |
59 |
60 |
69 |
70 |
--------------------------------------------------------------------------------
/res/layout-small-land/message_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
22 |
23 |
32 |
33 |
37 |
38 |
47 |
48 |
49 |
58 |
59 |
60 |
69 |
70 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Tasks/GamesLoaderTask.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Tasks;
2 |
3 | import java.util.List;
4 |
5 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
6 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Database;
7 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Game;
8 | import de.raptor2101.BattleWorldsKronos.Connector.JSON.ServerConnection;
9 |
10 | public class GamesLoaderTask extends LoaderTask {
11 |
12 | public GamesLoaderTask(AbstractConnectorApp app,ResultListener resultListener) {
13 | super(app, resultListener);
14 | }
15 |
16 | public class Result{
17 | private final List mGames;
18 | private final int mUnnotifiedPendingGames;
19 | public List getGames() {
20 | return mGames;
21 | }
22 |
23 | public int getUnnotifiedPendingGames() {
24 | return mUnnotifiedPendingGames;
25 | }
26 |
27 | public int getPendingGamesCount() {
28 | return mPendingGamesCount;
29 | }
30 |
31 | public int getUnnotifiedOpenGames() {
32 | return mUnnotifiedOpenGames;
33 | }
34 |
35 | public int getOpenGames() {
36 | return mOpenGames;
37 | }
38 |
39 | public int getRunningGames() {
40 | return mRunningGames;
41 | }
42 |
43 | private final int mPendingGamesCount;
44 | private final int mUnnotifiedOpenGames;
45 | private final int mOpenGames;
46 | private final int mRunningGames;
47 |
48 | public Result(List games, int unnotfiedPendingGames, int pendingGamesCount, int unnotifiedOpenGames, int openGames, int runningGames){
49 | mGames = games;
50 | mUnnotifiedPendingGames = unnotfiedPendingGames;
51 | mUnnotifiedOpenGames = unnotifiedOpenGames;
52 | mPendingGamesCount = pendingGamesCount;
53 | mOpenGames = openGames;
54 | mRunningGames = runningGames;
55 | }
56 | }
57 |
58 | @Override
59 | protected Result doInBackground(Boolean... params) {
60 | try {
61 | Database database = getDatabase();
62 | List games = null;
63 |
64 | boolean forceUpdate = params.length > 0 && params[0];
65 | if(forceUpdate){
66 | ServerConnection connection = getConnection();
67 | if (connection != null) {
68 | games = connection.getGames();
69 | database.persistGames(games);
70 | }
71 | }
72 |
73 | games = database.getGames();
74 |
75 | int unnotifiedPendingGames = database.getUnnotfiedPendingGamesCount();
76 | int pendingGames = database.getPendingGamesCount();
77 | int runningGames = database.getRunningGamesCount();
78 | int openGames = database.getOpenGamesCount();
79 |
80 | database.setAllGamesNotified();
81 |
82 | return new Result(games, unnotifiedPendingGames, pendingGames, 0, openGames, runningGames );
83 | } catch (Exception e) {
84 | // TODO Auto-generated catch block
85 | e.printStackTrace();
86 | }
87 | return null;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Views/GameView.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Views;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.List;
5 | import java.util.Locale;
6 |
7 | import android.content.Context;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.widget.LinearLayout;
11 | import android.widget.TextView;
12 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Game;
13 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Player;
14 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
15 |
16 | public class GameView extends LinearLayout {
17 |
18 | private SimpleDateFormat mFormater;
19 |
20 | public GameView(Context context) {
21 | super(context);
22 | mFormater = new SimpleDateFormat(context.getString(R.string.date_format_string), Locale.getDefault());
23 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
24 |
25 | inflater.inflate(R.layout.game_view, this);
26 | }
27 |
28 | public void setGame(Game game) {
29 | Game.State gameState = game.getState();
30 |
31 | TextView textView = (TextView) this.findViewById(R.id.text_game_info_view_Title);
32 | textView.setText(game.getGameName());
33 |
34 | textView = (TextView) this.findViewById(R.id.text_game_info_view_State);
35 | textView.setText(gameState.getResourceId());
36 | textView.setTextColor(gameState.getColor(this.getContext()));
37 |
38 | textView = (TextView) this.findViewById(R.id.text_game_info_view_Round);
39 | textView.setText(String.format("%d", game.getCurrentRound()));
40 |
41 | textView = (TextView) this.findViewById(R.id.text_game_info_view_PlayerCount);
42 | textView.setText(String.format("%d", game.getPlayers().size()));
43 |
44 | textView = (TextView) this.findViewById(R.id.text_game_info_view_Date);
45 | textView.setText(String.format("%d", game.getPlayers().size()));
46 |
47 | textView = (TextView) this.findViewById(R.id.text_game_info_view_Date);
48 | textView.setText(mFormater.format(game.getUpdateDate()));
49 |
50 | LinearLayout layout = (LinearLayout) findViewById(R.id.layout_game_info_view_PlayerInfo);
51 | layout.removeAllViews();
52 | List players = game.getPlayers();
53 |
54 | textView = (TextView) this.findViewById(R.id.text_game_info_view_PlayerCount);
55 | textView.setText(String.format("%d", players.size()));
56 |
57 | for (int i = 0; i < players.size(); i++) {
58 | PlayerView view = new PlayerView(getContext());
59 | view.setPlayerInfo(players.get(i));
60 | layout.addView(view);
61 | }
62 | }
63 |
64 | public boolean isExpanded() {
65 | LinearLayout layout = (LinearLayout) findViewById(R.id.layout_game_info_view_PlayerBox);
66 | return layout.getVisibility() == View.VISIBLE;
67 | }
68 |
69 | public void collapse() {
70 | LinearLayout layout = (LinearLayout) findViewById(R.id.layout_game_info_view_PlayerBox);
71 | layout.setVisibility(View.GONE);
72 | }
73 |
74 | public void expand() {
75 | LinearLayout layout = (LinearLayout) findViewById(R.id.layout_game_info_view_PlayerBox);
76 | layout.setVisibility(View.VISIBLE);
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Activities/AbstractWriteMessageActivity.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Activities;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.os.Bundle;
6 | import android.view.MenuItem;
7 | import android.view.View;
8 | import android.widget.EditText;
9 | import android.widget.ProgressBar;
10 | import android.widget.TextView;
11 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
12 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Message;
13 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
14 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.SendMessageTask;
15 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.SendMessageTask.Result;
16 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.ServerConnectionTask.ResultListener;
17 |
18 | public abstract class AbstractWriteMessageActivity extends Activity implements ResultListener {
19 | public final static String INTENT_EXTRA_MESSAGE_RESPOND_TO = "RESPONSE_MESSAGE";
20 | private SendMessageTask mTask;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.message_write_activity);
26 |
27 | View view = (View) findViewById(R.id.text_write_message_respond_box);
28 | Message message = (Message) getIntent().getExtras().get(INTENT_EXTRA_MESSAGE_RESPOND_TO);
29 | if(message != null){
30 |
31 | EditText editText = (EditText) findViewById(R.id.edit_write_message_receiver);
32 | editText.setText(message.getAuthorName());
33 |
34 | TextView textView = (TextView) findViewById(R.id.text_write_message_respond_text);
35 | textView.setText(message.getMessageText());
36 |
37 | view.setVisibility(View.VISIBLE);
38 | }
39 | else{
40 | view.setVisibility(View.GONE);
41 | }
42 | }
43 |
44 | @Override
45 | public boolean onMenuItemSelected(int featureId, MenuItem item) {
46 | if (item.getItemId() == R.id.action_send_message) {
47 | Message messageRespondTo = (Message) getIntent().getExtras().get(INTENT_EXTRA_MESSAGE_RESPOND_TO);
48 |
49 | SendMessageTask.Message message = new SendMessageTask.Message();
50 |
51 | EditText editText = (EditText) findViewById(R.id.edit_write_message_receiver);
52 | if(messageRespondTo == null){
53 | message.setReceiver(editText.getText().toString());
54 | }
55 | else
56 | {
57 | message.setReceiver(messageRespondTo.getAuthorName());
58 | message.setLastMessageId(messageRespondTo.getLastMessageId());
59 | }
60 |
61 | editText = (EditText) findViewById(R.id.edit_write_message_text);
62 | message.setText(editText.getText().toString());
63 |
64 | if (mTask != null) {
65 | mTask.cancel(true);
66 | }
67 |
68 | mTask = new SendMessageTask((AbstractConnectorApp) this.getApplication(), this);
69 | mTask.execute(message);
70 |
71 | ProgressBar progressBar = getProgressBar();
72 | progressBar.setVisibility(View.VISIBLE);
73 | }
74 | return super.onMenuItemSelected(featureId, item);
75 | }
76 |
77 | @Override
78 | public void handleResult(Result result) {
79 | mTask = null;
80 | ProgressBar progressBar = getProgressBar();
81 | progressBar.setVisibility(View.GONE);
82 | if (result.areAllMessagesSuccesfullySend()) {
83 | this.finish();
84 | } else {
85 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
86 | builder.setMessage(R.string.alert_dialog_send_message_error_message);
87 | builder.setTitle(R.string.alert_dialog_send_message_error_title);
88 |
89 | builder.create().show();
90 | }
91 | };
92 |
93 | protected abstract ProgressBar getProgressBar();
94 | }
95 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Data/Entities/Player.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Data.Entities;
2 |
3 | import android.content.Context;
4 | import android.util.SparseArray;
5 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
6 |
7 | public class Player {
8 |
9 | public enum State {
10 | PLAYING(0, R.string.player_state_playing, R.color.player_state_playing),
11 | LOST(1, R.string.player_state_lost, R.color.player_state_lost),
12 | WON(2, R.string.player_state_won, R.color.player_state_won),
13 | ABORTED(3, R.string.player_state_aborted, R.color.player_state_aborted),
14 | UNKNOWN(4, R.string.player_state_unknown, R.color.player_state_unknown),
15 | TIMEOUT(5, R.string.player_state_timeout, R.color.player_state_timeout),
16 | ACTIVE(6, R.string.player_state_active, R.color.player_state_active),
17 | WAITING(7, R.string.player_state_waiting, R.color.player_state_waiting),;
18 |
19 | private static final SparseArray intToState = new SparseArray();
20 |
21 | static {
22 | intToState.put(PLAYING.getValue(), PLAYING);
23 | intToState.put(LOST.getValue(), LOST);
24 | intToState.put(WON.getValue(), WON);
25 | intToState.put(TIMEOUT.getValue(), TIMEOUT);
26 | intToState.put(ABORTED.getValue(), ABORTED);
27 | intToState.put(ACTIVE.getValue(), ACTIVE);
28 | intToState.put(WAITING.getValue(), WAITING);
29 | intToState.put(UNKNOWN.getValue(), UNKNOWN);
30 | }
31 |
32 | private final int mValue;
33 | private final int mResourceId;
34 | private final int mColorId;
35 |
36 | private State(final int value, final int resourceId, final int colorId) {
37 | mValue = value;
38 | mResourceId = resourceId;
39 | mColorId = colorId;
40 | }
41 |
42 | public int getColorId() {
43 | return mColorId;
44 | }
45 |
46 | public int getColor(Context context){
47 | return context.getResources().getColor(mColorId);
48 | }
49 |
50 | public int getResourceId() {
51 | return mResourceId;
52 | }
53 |
54 | public int getValue() {
55 | return mValue;
56 | }
57 |
58 | public static State FromInt(int value) {
59 | State returnValue = intToState.get(value);
60 |
61 | if(returnValue == null){
62 | return State.UNKNOWN;
63 | }
64 |
65 | return returnValue;
66 | }
67 | }
68 |
69 | private int mPlayerId;
70 | private int mUserId;
71 | private String mPlayerName;
72 | private String mColor;
73 | private State mState;
74 | private int mTeam;
75 | private String mLastMessage;
76 |
77 | public int getPlayerId() {
78 | return mPlayerId;
79 | }
80 |
81 | public int getUserId() {
82 | return mUserId;
83 | }
84 |
85 | public String getPlayerName() {
86 | return mPlayerName;
87 | }
88 |
89 | public String getColor() {
90 | return mColor;
91 | }
92 |
93 | public State getState() {
94 | return mState;
95 | }
96 |
97 | public int getTeam() {
98 | return mTeam;
99 | }
100 |
101 | public String getLastMessage() {
102 | return mLastMessage;
103 | }
104 |
105 | public void setPlayerId(int playerId) {
106 | this.mPlayerId = playerId;
107 | }
108 |
109 | public void setUserId(int userId) {
110 | this.mUserId = userId;
111 | }
112 |
113 | public void setPlayerName(String playerName) {
114 | this.mPlayerName = playerName;
115 | }
116 |
117 | public void setColor(String color) {
118 | this.mColor = color;
119 | }
120 |
121 | public void setState(State state) {
122 | this.mState = state;
123 | }
124 |
125 | public void setTeam(int team) {
126 | this.mTeam = team;
127 | }
128 |
129 | public void setLastMessage(String lastMessage) {
130 | this.mLastMessage = lastMessage;
131 | }
132 |
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/res/layout/settings_activity.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
11 |
12 |
18 |
19 |
23 |
24 |
28 |
29 |
35 |
36 |
40 |
41 |
47 |
48 |
54 |
55 |
59 |
60 |
65 |
66 |
71 |
72 |
76 |
77 |
81 |
82 |
85 |
86 |
91 |
92 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/WidgetProviders/GeneralOverviewProvider.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.WidgetProviders;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Date;
5 | import java.util.Locale;
6 |
7 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
8 | import de.raptor2101.BattleWorldsKronos.Connector.ApplicationSettings;
9 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
10 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R.id;
11 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.GamesLoaderTask;
12 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.GamesLoaderTask.Result;
13 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.ServerConnectionTask.ResultListener;
14 | import android.app.PendingIntent;
15 | import android.appwidget.AppWidgetManager;
16 | import android.appwidget.AppWidgetProvider;
17 | import android.content.ComponentName;
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.os.SystemClock;
21 | import android.widget.RemoteViews;
22 |
23 | public class GeneralOverviewProvider extends AppWidgetProvider implements ResultListener {
24 | int[] mAppWidgetIds;
25 | AppWidgetManager mAppWidgetManager;
26 | Context mContext;
27 |
28 | public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
29 | mContext = context;
30 | mAppWidgetManager = appWidgetManager;
31 | mAppWidgetIds = appWidgetIds;
32 |
33 | ApplicationSettings settings = new ApplicationSettings(context);
34 | AbstractConnectorApp app = (AbstractConnectorApp) context.getApplicationContext();
35 |
36 | GamesLoaderTask task = new GamesLoaderTask(app, this);
37 | long lastLoad = app.getDatabase().getTimestampLastGameUpdate();
38 |
39 | task.execute(new Boolean[] { SystemClock.elapsedRealtime()-lastLoad>settings.getRefreshCylce() });
40 | }
41 |
42 | @Override
43 | public void handleResult(Result result) {
44 | final int N = mAppWidgetIds.length;
45 | Locale locale = mContext.getResources().getConfiguration().locale;
46 | SimpleDateFormat sdf = new SimpleDateFormat(mContext.getResources().getString(R.string.date_format_string), locale);
47 | AbstractConnectorApp app = (AbstractConnectorApp)mContext.getApplicationContext();
48 |
49 | Intent intent = new Intent(mContext, app.getGameListingActivityClass());
50 | PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
51 |
52 | String pendingGames = String.format(locale,"%d", result.getPendingGamesCount());
53 | String runningGames = String.format(locale,"%d", result.getRunningGames());
54 | String openGames = String.format(locale,"%d", result.getOpenGames());
55 | String timestamp = sdf.format(new Date());
56 |
57 | for (int i = 0; i < N; i++) {
58 | int appWidgetId = mAppWidgetIds[i];
59 |
60 |
61 |
62 | RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.general_overview_widget);
63 | views.setTextViewText(R.id.general_overview_text_pending_games, pendingGames);
64 | views.setTextViewText(R.id.general_overview_text_running_games, runningGames);
65 | views.setTextViewText(R.id.general_overview_text_open_games, openGames);
66 | views.setTextViewText(R.id.general_overview_text_last_update, timestamp);
67 | views.setOnClickPendingIntent(R.id.general_overview_layout, pendingIntent);
68 |
69 | mAppWidgetManager.updateAppWidget(appWidgetId, views);
70 | }
71 | }
72 |
73 | public static void Update(Context context){
74 | AppWidgetManager manager = AppWidgetManager.getInstance(context);
75 | int[] widgetIds = manager.getAppWidgetIds(new ComponentName(context.getApplicationContext(), GeneralOverviewProvider.class));
76 |
77 | Intent intent = new Intent();
78 | intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
79 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
80 | context.sendBroadcast(intent);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Adapters/NavigationButtonAdapter.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Adapters;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 |
6 | import org.xmlpull.v1.XmlPullParserException;
7 |
8 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.Controls.NavigationButton;
9 |
10 | import android.content.Context;
11 | import android.content.res.XmlResourceParser;
12 | import android.graphics.drawable.Drawable;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.BaseAdapter;
16 |
17 | public class NavigationButtonAdapter extends BaseAdapter {
18 |
19 | private static final String XmlTagName_Item = "item";
20 | private static final String XmlAttributeNamespace = "http://schemas.android.com/apk/res/android";
21 | private static final String XmlAttributeName_Title = "title";
22 | private static final String XmlAttributeName_Icon = "icon";
23 | private static final String XmlAttributeName_Id = "id";
24 |
25 | private ArrayList buttons;
26 |
27 | public NavigationButtonAdapter(Context context, int menuResourceId) {
28 | buttons = new ArrayList(10);
29 | XmlResourceParser parser = context.getResources().getXml(menuResourceId);
30 | int eventType;
31 |
32 | try {
33 | do {
34 | eventType = parser.next();
35 | if (eventType == XmlResourceParser.START_TAG && XmlTagName_Item.equals(parser.getName())) {
36 | int buttonId = -1;
37 | CharSequence title = null;
38 | Drawable iconDrawable = null;
39 | for (int index = 0; index < parser.getAttributeCount(); index++) {
40 | String attributeName = parser.getAttributeName(index);
41 | String namsespace = parser.getAttributeNamespace(index);
42 | if (XmlAttributeNamespace.equals(namsespace)) {
43 | String value = parser.getAttributeValue(index);
44 | if (XmlAttributeName_Title.equals(attributeName)) {
45 | if (value.startsWith("@")) {
46 | int resourceId = Integer.parseInt(value.substring(1));
47 | title = context.getText(resourceId);
48 | } else {
49 | title = value;
50 | }
51 | } else if (XmlAttributeName_Icon.equals(attributeName)) {
52 | int resourceId;
53 | if (value.startsWith("@")) {
54 | resourceId = Integer.parseInt(value.substring(1));
55 | } else {
56 | resourceId = Integer.parseInt(value);
57 | }
58 | iconDrawable = context.getResources().getDrawable(resourceId);
59 | } else if (XmlAttributeName_Id.equals(attributeName)) {
60 | if (value.startsWith("@")) {
61 | buttonId = Integer.parseInt(value.substring(1));
62 | } else {
63 | buttonId = Integer.parseInt(value);
64 | }
65 |
66 | }
67 | }
68 | }
69 |
70 | if(buttonId > -1 && title != null && iconDrawable != null){
71 | buttons.add(new NavigationButton(context, buttonId, title, iconDrawable));
72 | }
73 | }
74 | } while (eventType != XmlResourceParser.END_DOCUMENT);
75 | } catch (XmlPullParserException e) {
76 | // TODO Auto-generated catch block
77 | e.printStackTrace();
78 | } catch (IOException e) {
79 | // TODO Auto-generated catch block
80 | e.printStackTrace();
81 | }
82 | }
83 |
84 | @Override
85 | public int getCount() {
86 | return buttons.size();
87 | }
88 |
89 | @Override
90 | public Object getItem(int position) {
91 | return buttons.get(position);
92 | }
93 |
94 | @Override
95 | public long getItemId(int position) {
96 | return buttons.get(position).getId();
97 | }
98 |
99 | @Override
100 | public View getView(int position, View convertView, ViewGroup parent) {
101 | return buttons.get(position);
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | BWK:Connector
5 |
6 | Settings
7 | Refresh
8 | Write Message
9 | Send
10 |
11 | "State: "
12 | "Round: "
13 | Players:
14 | Players
15 | Date
16 |
17 | LastMessage
18 |
19 | E-Mail
20 | Password
21 | Notfication
22 | Update Cycle
23 | Pending Games
24 | New Messages
25 | Save
26 | Discard
27 | Login
28 |
29 | Running
30 | Ended
31 | Lost
32 | Won
33 | Pending
34 | Waiting
35 | Open
36 | Aborted
37 | Unknown
38 |
39 | Aborted
40 | Playing
41 | Lost
42 | Won
43 | Timeout
44 | Active
45 | Waiting
46 | Unknown
47 |
48 | There are %d games waiting for your interaction
49 | There are %d unreaded messages
50 | "yyyy.MM.dd HH:mm"
51 |
52 | Respond to
53 |
54 | receiver
55 | message
56 |
57 | - 10 minutes
58 | - 20 minutes
59 | - 30 minutes
60 | - 1 hour
61 | - 2 hours
62 | - 3 hours
63 | - 6 hours
64 | - 12 hours
65 | - 1 Day
66 |
67 | Games
68 | PlayerStats
69 | Leagues
70 | Messages
71 |
72 | Application Icon
73 | wrote at
74 |
75 | Games
76 | Messages
77 | Settings
78 | Write Message
79 |
80 | Hello! The user
81 | has added you to his watchlist! If you want to add him to your watchlist too, enter his name in the watchlist window in the chat!
82 |
83 | Unable to send your Message
84 | The Server rejects your message.
85 | Delete
86 | Answer
87 |
88 | Pending Games:
89 | Running Games:
90 | Open Games:
91 | Last Update:
92 |
93 |
--------------------------------------------------------------------------------
/res/values-en/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | BWK:Connector
5 |
6 | Settings
7 | Refresh
8 | Write Message
9 | Send
10 |
11 | "State: "
12 | "Round: "
13 | Players:
14 | Players
15 | Date
16 |
17 | LastMessage
18 |
19 | E-Mail
20 | Password
21 | Notfication
22 | Update Cycle
23 | Pending Games
24 | New Messages
25 | Save
26 | Discard
27 | Login
28 |
29 | Running
30 | Ended
31 | Lost
32 | Won
33 | Pending
34 | Waiting
35 | Open
36 | Aborted
37 | Unknown
38 |
39 | Aborted
40 | Playing
41 | Lost
42 | Won
43 | Timeout
44 | Active
45 | Waiting
46 | Unknown
47 |
48 | There are %d games waiting for your interaction
49 | There are %d unreaded messages
50 | "yyyy.MM.dd HH:mm"
51 |
52 | Respond to
53 |
54 | receiver
55 | message
56 |
57 | - 10 minutes
58 | - 20 minutes
59 | - 30 minutes
60 | - 1 hour
61 | - 2 hours
62 | - 3 hours
63 | - 6 hours
64 | - 12 hours
65 | - 1 Day
66 |
67 | Games
68 | PlayerStats
69 | Leagues
70 | Messages
71 |
72 | Application Icon
73 | wrote at
74 |
75 | Games
76 | Messages
77 | Settings
78 | Write Message
79 |
80 | Hello! The user
81 | has added you to his watchlist! If you want to add him to your watchlist too, enter his name in the watchlist window in the chat!
82 |
83 | Unable to send your Message
84 | The Server rejects your message.
85 | Delete
86 | Answer
87 |
88 | Pending Games:
89 | Running Games:
90 | Open Games:
91 | Last Update:
92 |
93 |
--------------------------------------------------------------------------------
/res/values-en-rGB/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | BWK:Connector
5 |
6 | Settings
7 | Refresh
8 | Write Message
9 | Send
10 |
11 | "State: "
12 | "Round: "
13 | Players:
14 | Players
15 | Date
16 |
17 | LastMessage
18 |
19 | E-Mail
20 | Password
21 | Notfication
22 | Update Cycle
23 | Pending Games
24 | New Messages
25 | Save
26 | Discard
27 | Login
28 |
29 | Running
30 | Ended
31 | Lost
32 | Won
33 | Pending
34 | Waiting
35 | Open
36 | Aborted
37 | Unknown
38 |
39 | Aborted
40 | Playing
41 | Lost
42 | Won
43 | Timeout
44 | Active
45 | Waiting
46 | Unknown
47 |
48 | There are %d games waiting for your interaction
49 | There are %d unreaded messages
50 | "yyyy.MM.dd HH:mm"
51 |
52 | Respond to
53 |
54 | receiver
55 | message
56 |
57 | - 10 minutes
58 | - 20 minutes
59 | - 30 minutes
60 | - 1 hour
61 | - 2 hours
62 | - 3 hours
63 | - 6 hours
64 | - 12 hours
65 | - 1 Day
66 |
67 | Games
68 | PlayerStats
69 | Leagues
70 | Messages
71 |
72 | Application Icon
73 | wrote at
74 |
75 | Games
76 | Messages
77 | Settings
78 | Write Message
79 |
80 | Hello! The user
81 | has added you to his watchlist! If you want to add him to your watchlist too, enter his name in the watchlist window in the chat!
82 |
83 | Unable to send your Message
84 | The Server rejects your message.
85 | Delete
86 | Answer
87 |
88 | Pending Games:
89 | Running Games:
90 | Open Games:
91 | Last Update:
92 |
93 |
--------------------------------------------------------------------------------
/res/values-en-rUS/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | BWK:Connector
5 |
6 | Settings
7 | Refresh
8 | Write Message
9 | Send
10 |
11 | "State: "
12 | "Round: "
13 | Players:
14 | Players
15 | Date
16 |
17 | LastMessage
18 |
19 | E-Mail
20 | Password
21 | Notfication
22 | Update Cycle
23 | Pending Games
24 | New Messages
25 | Save
26 | Discard
27 | Login
28 |
29 | Running
30 | Ended
31 | Lost
32 | Won
33 | Pending
34 | Waiting
35 | Open
36 | Aborted
37 | Unknown
38 |
39 | Aborted
40 | Playing
41 | Lost
42 | Won
43 | Timeout
44 | Active
45 | Waiting
46 | Unknown
47 |
48 | There are %d games waiting for your interaction
49 | There are %d unreaded messages
50 | "yyyy.MM.dd HH:mm"
51 |
52 | Respond to
53 |
54 | receiver
55 | message
56 |
57 | - 10 minutes
58 | - 20 minutes
59 | - 30 minutes
60 | - 1 hour
61 | - 2 hours
62 | - 3 hours
63 | - 6 hours
64 | - 12 hours
65 | - 1 Day
66 |
67 | Games
68 | PlayerStats
69 | Leagues
70 | Messages
71 |
72 | Application Icon
73 | wrote at
74 |
75 | Games
76 | Messages
77 | Settings
78 | Write Message
79 |
80 | Hello! The user
81 | has added you to his watchlist! If you want to add him to your watchlist too, enter his name in the watchlist window in the chat!
82 |
83 | Unable to send your Message
84 | The Server rejects your message.
85 | Delete
86 | Answer
87 |
88 | Pending Games:
89 | Running Games:
90 | Open Games:
91 | Last Update:
92 |
93 |
--------------------------------------------------------------------------------
/res/values-de/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | BWK:Connector
5 |
6 | Einstellungen
7 | Aktualisieren
8 | Nachricht schreiben
9 | Senden
10 |
11 | "Status:"
12 | "Runde:"
13 | Spieler:
14 | Spieler
15 | Datum
16 |
17 | Letzte Nachricht
18 |
19 | E-Mail
20 | Passwort
21 | Benachrichtigung
22 | Aktualisierungszyklus
23 | Spiele mit offenen Zügen
24 | Neue Nachrichten
25 | Übernehmen
26 | Verwerfen
27 | Account-Informationen
28 |
29 | Laufend
30 | Beendet
31 | Verloren
32 | Gewonnen
33 | Am Zug
34 | Wartend
35 | Offen
36 | Abgebrochen
37 | Unbekannt
38 |
39 |
40 | Abgebrochen
41 | Spielend
42 | Verloren
43 | Gewonnen
44 | Timeout
45 | Aktive
46 | Wartet
47 | Unbekannt
48 |
49 | %d Spiele warten auf deinen Zug.
50 | %d ungelesene Nachrichten
51 | "dd.MM.yyyy HH:mm"
52 |
53 | Antworten auf
54 |
55 | Empfänger
56 | Nachricht
57 |
58 |
59 | - 10 Minuten
60 | - 20 Minuten
61 | - 30 Minuten
62 | - 1 Stunden
63 | - 2 Stunden
64 | - 3 Stunden
65 | - 6 Stunden
66 | - 12 Stunden
67 | - 1 Tag
68 |
69 | Spiele
70 | SpielerStatistik
71 | Liegen
72 | Nachrichten
73 |
74 | Anwendungsicon
75 | schrieb am
76 |
77 | Spiele
78 | Nachrichten
79 | Einstellungen
80 | Schreibe Nachricht
81 |
82 | Hallo! Der Benutzer
83 | hat dich seiner Watchlist hinzugefügt! Falls du ihn ebenfalls deiner Watchlist hinzufügen möchtest, tippe seinen Namen in das Watchlist-Fenster im Chat ein!
84 |
85 | Nachrichte konnte nicht abgeliefert werden
86 | Der Server hat die Nachricht abgelehnt.
87 | Löschen
88 | Antworten
89 |
90 | Wartende Games:
91 | Laufende Games:
92 | Offene Games:
93 | Letzes Update:
94 |
95 |
--------------------------------------------------------------------------------
/res/layout-large/game_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
21 |
22 |
30 |
31 |
40 |
41 |
45 |
46 |
54 |
55 |
63 |
64 |
65 |
70 |
71 |
79 |
80 |
87 |
88 |
89 |
94 |
95 |
100 |
101 |
106 |
107 |
111 |
112 |
118 |
119 |
120 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/res/layout-xlarge/game_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
21 |
22 |
30 |
31 |
40 |
41 |
45 |
46 |
54 |
55 |
63 |
64 |
65 |
70 |
71 |
79 |
80 |
87 |
88 |
89 |
94 |
95 |
100 |
101 |
106 |
107 |
111 |
112 |
118 |
119 |
120 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/res/layout-land/game_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
21 |
22 |
30 |
31 |
40 |
41 |
45 |
46 |
54 |
55 |
63 |
64 |
68 |
69 |
77 |
78 |
85 |
86 |
87 |
94 |
95 |
100 |
101 |
106 |
107 |
111 |
112 |
118 |
119 |
120 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/res/layout-small-land/game_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
21 |
22 |
30 |
31 |
40 |
41 |
45 |
46 |
54 |
55 |
63 |
64 |
68 |
69 |
77 |
78 |
85 |
86 |
87 |
94 |
95 |
100 |
101 |
106 |
107 |
111 |
112 |
118 |
119 |
120 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Activities/AbstractGameListingActivity.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Activities;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.SystemClock;
7 | import android.support.v4.widget.DrawerLayout;
8 | import android.view.Gravity;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.view.View.OnClickListener;
13 | import android.widget.AbsListView;
14 | import android.widget.AdapterView;
15 | import android.widget.AdapterView.OnItemClickListener;
16 | import android.widget.ProgressBar;
17 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
18 | import de.raptor2101.BattleWorldsKronos.Connector.ApplicationSettings;
19 | import de.raptor2101.BattleWorldsKronos.Connector.NotificationService;
20 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
21 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.Adapters.GameViewAdapter;
22 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.Views.GameView;
23 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.WidgetProviders.GeneralOverviewProvider;
24 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.GamesLoaderTask;
25 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.ServerConnectionTask.ResultListener;
26 |
27 | public abstract class AbstractGameListingActivity extends Activity implements ResultListener, OnItemClickListener, OnClickListener {
28 | public final static String TAG_EXPENDABLE = "expendable";
29 | GameViewAdapter mGameViewAdapater = new GameViewAdapter(this);
30 | GameView mExpandedView;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.game_listing_activity);
36 |
37 | AbsListView listView = (AbsListView) findViewById(R.id.game_listing);
38 | listView.setAdapter(mGameViewAdapater);
39 |
40 | if(TAG_EXPENDABLE.equals(listView.getTag())){
41 | listView.setOnItemClickListener(this);
42 | listView.setClickable(true);
43 | } else {
44 | listView.setClickable(false);
45 | }
46 | }
47 |
48 | @Override
49 | protected void onStart() {
50 | View view = getTitleImageButton();
51 | view.setOnClickListener(this);
52 | super.onStart();
53 | }
54 |
55 | @Override
56 | protected void onResume() {
57 | super.onResume();
58 |
59 | ApplicationSettings settings = new ApplicationSettings(this);
60 |
61 | if(settings.getEmail().equals(ApplicationSettings.EmptyResult)){
62 | startSettingsActivity();
63 | return;
64 | }
65 |
66 | AbstractConnectorApp app = (AbstractConnectorApp) getApplication();
67 | long lastLoad = app.getDatabase().getTimestampLastGameUpdate();
68 | loadGames(SystemClock.elapsedRealtime()-lastLoad>settings.getRefreshCylce());
69 | }
70 |
71 | private void loadGames(boolean forceReload) {
72 |
73 | ProgressBar progressBar = getProgressBar();
74 | progressBar.setVisibility(View.VISIBLE);
75 |
76 | GamesLoaderTask task = new GamesLoaderTask((AbstractConnectorApp) this.getApplication(), this);
77 | task.execute(new Boolean[]{forceReload});
78 |
79 | }
80 |
81 | @Override
82 | public abstract boolean onCreateOptionsMenu(Menu menu);
83 |
84 | @Override
85 | public boolean onMenuItemSelected(int featureId, MenuItem item) {
86 | if(item.getItemId() == R.id.action_settings){
87 | startSettingsActivity();
88 | } else if (item.getItemId() == R.id.action_refresh){
89 | loadGames(true);
90 | }
91 | return super.onMenuItemSelected(featureId, item);
92 | }
93 |
94 | @Override
95 | public void handleResult(GamesLoaderTask.Result result) {
96 | ProgressBar progressBar = getProgressBar();
97 | progressBar.setVisibility(View.GONE);
98 | if(result != null){
99 | mGameViewAdapater.setGames(result.getGames());
100 | NotificationService.resetPendingGames(this);
101 | GeneralOverviewProvider.Update(this);
102 | }
103 | }
104 |
105 | private void startSettingsActivity() {
106 | Intent intent = new Intent(this, SettingsActivity.class);
107 | startActivity(intent);
108 | }
109 |
110 | @Override
111 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
112 | GameView gameView = (GameView) view;
113 | if(gameView.isExpanded()){
114 | gameView.collapse();
115 | mExpandedView = null;
116 | } else{
117 | if(mExpandedView != null){
118 | mExpandedView.collapse();
119 | }
120 | gameView.expand();
121 | mExpandedView = gameView;
122 | }
123 | }
124 |
125 | @Override
126 | public void onClick(View v) {
127 | DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
128 | if(drawerLayout.isDrawerOpen(Gravity.LEFT)){
129 | drawerLayout.closeDrawer(Gravity.LEFT);
130 | } else {
131 | drawerLayout.openDrawer(Gravity.LEFT);
132 | }
133 | };
134 |
135 | protected abstract ProgressBar getProgressBar();
136 | protected abstract View getTitleImageButton();
137 | }
138 |
--------------------------------------------------------------------------------
/res/layout/game_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
21 |
22 |
30 |
31 |
40 |
41 |
45 |
46 |
54 |
55 |
63 |
64 |
65 |
69 |
70 |
78 |
79 |
83 |
84 |
91 |
92 |
93 |
101 |
102 |
107 |
108 |
113 |
114 |
118 |
119 |
125 |
126 |
127 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/res/layout-normal/game_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
21 |
22 |
30 |
31 |
40 |
41 |
45 |
46 |
54 |
55 |
63 |
64 |
65 |
69 |
70 |
78 |
79 |
83 |
84 |
91 |
92 |
93 |
101 |
102 |
107 |
108 |
113 |
114 |
118 |
119 |
125 |
126 |
127 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/res/layout-small/game_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
21 |
22 |
30 |
31 |
40 |
41 |
45 |
46 |
54 |
55 |
63 |
64 |
65 |
69 |
70 |
78 |
79 |
83 |
84 |
91 |
92 |
93 |
101 |
102 |
107 |
108 |
113 |
114 |
118 |
119 |
125 |
126 |
127 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Activities/SettingsActivity.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Activities;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.Menu;
6 | import android.view.View;
7 | import android.view.View.OnClickListener;
8 | import android.widget.ArrayAdapter;
9 | import android.widget.Button;
10 | import android.widget.CheckBox;
11 | import android.widget.EditText;
12 | import android.widget.Spinner;
13 | import de.raptor2101.BattleWorldsKronos.Connector.ApplicationSettings;
14 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
15 |
16 | public class SettingsActivity extends Activity implements OnClickListener {
17 |
18 | private static final int TimeSpan_10Minutes = 10 * 60 * 1000;
19 | private static final int TimeSpan_20Minutes = 20 * 60 * 1000;
20 | private static final int TimeSpan_30Minutes = 30 * 60 * 1000;
21 | private static final int TimeSpan_1Hour = 60 * 60 * 1000;
22 | private static final int TimeSpan_2Hours = 2 * 60 * 60 * 1000;
23 | private static final int TimeSpan_3Hours = 3 * 60 * 60 * 1000;
24 | private static final int TimeSpan_6Hours = 6 * 60 * 60 * 1000;
25 | private static final int TimeSpan_12Hours = 12 * 60 * 60 * 1000;
26 | private static final int TimeSpan_24Hours = 24 * 60 * 60 * 1000;
27 |
28 | private ApplicationSettings mSettings;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.settings_activity);
34 | mSettings = new ApplicationSettings(this);
35 |
36 | EditText textBox = (EditText) findViewById(R.id.editEmail);
37 | textBox.setText(mSettings.getEmail());
38 |
39 | textBox = (EditText) findViewById(R.id.editPassword);
40 | textBox.setText(mSettings.getPassword());
41 |
42 | CheckBox checkBox = (CheckBox) findViewById(R.id.checkBoxPendingGames);
43 | checkBox.setChecked(mSettings.isNotifyOnGamesEnabled());
44 |
45 | checkBox = (CheckBox) findViewById(R.id.checkBoxNewMessages);
46 | checkBox.setChecked(mSettings.isNotifyOnMessagesEnabled());
47 |
48 | Button button = (Button) findViewById(R.id.button_save);
49 | button.setOnClickListener(this);
50 |
51 | button = (Button) findViewById(R.id.button_discard);
52 | button.setOnClickListener(this);
53 |
54 | Spinner spinner = (Spinner) findViewById(R.id.spinnerUpdateCycle);
55 | ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.setting_spinner_updatecycle, android.R.layout.simple_spinner_item);
56 | adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
57 | spinner.setAdapter(adapter);
58 | switch (mSettings.getRefreshCylce()) {
59 | case TimeSpan_10Minutes:
60 | spinner.setSelection(0);
61 | break;
62 | case TimeSpan_20Minutes:
63 | spinner.setSelection(1);
64 | break;
65 | case TimeSpan_30Minutes:
66 | spinner.setSelection(2);
67 | break;
68 | case TimeSpan_1Hour:
69 | spinner.setSelection(3);
70 | break;
71 | case TimeSpan_2Hours:
72 | spinner.setSelection(4);
73 | break;
74 | case TimeSpan_3Hours:
75 | spinner.setSelection(5);
76 | break;
77 | case TimeSpan_6Hours:
78 | spinner.setSelection(6);
79 | break;
80 | case TimeSpan_12Hours:
81 | spinner.setSelection(7);
82 | break;
83 | case TimeSpan_24Hours:
84 | spinner.setSelection(8);
85 | break;
86 | }
87 | }
88 |
89 | @Override
90 | public boolean onCreateOptionsMenu(Menu menu) {
91 | return true;
92 | }
93 |
94 | @Override
95 | public void onClick(View v) {
96 | if (v.getId() == R.id.button_save) {
97 | EditText textBox = (EditText) findViewById(R.id.editEmail);
98 | String email = textBox.getText().toString();
99 |
100 | textBox = (EditText) findViewById(R.id.editPassword);
101 | String password = textBox.getText().toString();
102 |
103 | CheckBox checkBox = (CheckBox) findViewById(R.id.checkBoxPendingGames);
104 | boolean isNotifyOnGamesEnabled = checkBox.isChecked();
105 |
106 | checkBox = (CheckBox) findViewById(R.id.checkBoxNewMessages);
107 | boolean isNotifyOnMessagesEnabled = checkBox.isChecked();
108 |
109 | int refreshIntervall = 0;
110 | Spinner spinner = (Spinner) findViewById(R.id.spinnerUpdateCycle);
111 | switch (spinner.getSelectedItemPosition()) {
112 | case 0:
113 | refreshIntervall = TimeSpan_10Minutes;
114 | break;
115 | case 1:
116 | refreshIntervall = TimeSpan_20Minutes;
117 | break;
118 | case 2:
119 | refreshIntervall = TimeSpan_30Minutes;
120 | break;
121 | case 3:
122 | refreshIntervall = TimeSpan_1Hour;
123 | break;
124 | case 4:
125 | refreshIntervall = TimeSpan_2Hours;
126 | break;
127 | case 5:
128 | refreshIntervall = TimeSpan_3Hours;
129 | break;
130 | case 6:
131 | refreshIntervall = TimeSpan_6Hours;
132 | break;
133 | case 7:
134 | refreshIntervall = TimeSpan_12Hours;
135 | break;
136 | case 8:
137 | refreshIntervall = TimeSpan_24Hours;
138 | break;
139 | }
140 |
141 | mSettings.Save(email, password, isNotifyOnGamesEnabled, isNotifyOnMessagesEnabled, refreshIntervall);
142 | }
143 |
144 | this.finish();
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Data/Entities/Game.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Data.Entities;
2 |
3 | import java.util.Date;
4 | import java.util.List;
5 |
6 | import android.content.Context;
7 | import android.util.SparseArray;
8 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
9 |
10 | public class Game {
11 |
12 | public enum State {
13 | RUNNING(0, R.string.game_state_running, R.color.game_state_running),
14 | ENDED(1, R.string.game_state_ended, R.color.game_state_ended),
15 | LOST(2, R.string.game_state_lost, R.color.game_state_lost),
16 | WON(3, R.string.game_state_won, R.color.game_state_won),
17 | PENDING(4, R.string.game_state_pending, R.color.game_state_pending),
18 | WAITING(5, R.string.game_state_waiting, R.color.game_state_waiting),
19 | OPEN(6, R.string.game_state_open, R.color.game_state_open),
20 | ABORTED(7, R.string.game_state_aborted, R.color.game_state_aborted),
21 | UNKNOWN(8, R.string.game_state_unknown, R.color.game_state_unknown);
22 |
23 | private static final SparseArray intToState = new SparseArray();
24 |
25 | static {
26 | intToState.put(RUNNING.getValue(), RUNNING);
27 | intToState.put(ENDED.getValue(), ENDED);
28 | intToState.put(LOST.getValue(), LOST);
29 | intToState.put(WON.getValue(), WON);
30 | intToState.put(PENDING.getValue(), PENDING);
31 | intToState.put(WAITING.getValue(), WAITING);
32 | intToState.put(OPEN.getValue(), OPEN);
33 | intToState.put(ABORTED.getValue(), ABORTED);
34 | intToState.put(UNKNOWN.getValue(), UNKNOWN);
35 | }
36 |
37 | private final int mValue;
38 | private final int mResourceId;
39 | private final int mColorId;
40 |
41 | private State(final int value, final int resourceId, final int colorId) {
42 | mValue = value;
43 | mResourceId = resourceId;
44 | mColorId = colorId;
45 | }
46 |
47 | public int getResourceId() {
48 | return mResourceId;
49 | }
50 |
51 | public int getColorId() {
52 | return mColorId;
53 | }
54 |
55 | public int getColor(Context context) {
56 | return context.getResources().getColor(mColorId);
57 | }
58 |
59 | public int getValue() {
60 | return mValue;
61 | }
62 |
63 | public static State FromInt(int value) {
64 | State returnValue = intToState.get(value);
65 |
66 | if(returnValue == null){
67 | return State.UNKNOWN;
68 | }
69 |
70 | return returnValue;
71 | }
72 | }
73 |
74 | private Date mCreateDate;
75 | private int mCurrentRound;
76 | private int mCurrentTurn;
77 | private int mGameId;
78 | private String mGameName;
79 | private int mMapId;
80 | private int mActivePlayerId;
81 | private int mOwnerId;
82 | private State mState;
83 | private Date mUpdateDate;
84 | private List mPlayers;
85 | private Player mWinner;
86 | private Player mActivePlayer;
87 |
88 | public Player getWinner() {
89 | return mWinner;
90 | }
91 |
92 | public void setWinner(Player player) {
93 | mWinner = player;
94 | }
95 |
96 | public Date getCreateDate() {
97 | return mCreateDate;
98 | }
99 |
100 | public int getCurrentRound() {
101 | return mCurrentRound;
102 | }
103 |
104 | public int getCurrentTurn() {
105 | return mCurrentTurn;
106 | }
107 |
108 | public int getGameId() {
109 | return mGameId;
110 | }
111 |
112 | public String getGameName() {
113 | return mGameName;
114 | }
115 |
116 | public int getMapId() {
117 | return mMapId;
118 | }
119 |
120 | public int getActivePlayerId() {
121 | return mActivePlayerId;
122 | }
123 |
124 | public int getOwnerId() {
125 | return mOwnerId;
126 | }
127 |
128 | public List getPlayers() {
129 | return mPlayers;
130 | }
131 |
132 | public State getState() {
133 | return mState;
134 | }
135 |
136 | public Date getUpdateDate() {
137 | return mUpdateDate;
138 | }
139 |
140 | public void setCreateDate(Date createDate) {
141 | this.mCreateDate = createDate;
142 | }
143 |
144 | public void setCurrentRound(int currentRound) {
145 | this.mCurrentRound = currentRound;
146 | }
147 |
148 | public void setCurrentTurn(int currentTurn) {
149 | this.mCurrentTurn = currentTurn;
150 | }
151 |
152 | public void setGameId(int gameId) {
153 | this.mGameId = gameId;
154 | }
155 |
156 | public void setGameName(String gameName) {
157 | this.mGameName = gameName;
158 | }
159 |
160 | public void setMapId(int mapId) {
161 | this.mMapId = mapId;
162 | }
163 |
164 | public void setNextPlayerId(int nextPlayerId) {
165 | this.mActivePlayer = null;
166 | this.mActivePlayerId = nextPlayerId;
167 | }
168 |
169 | public void setOwnerId(int mOwnerId) {
170 | this.mOwnerId = mOwnerId;
171 | }
172 |
173 | public void setPlayers(List players, Player winner, Player nextPlayer) {
174 | this.mActivePlayer = nextPlayer;
175 | this.mWinner = winner;
176 | this.mPlayers = players;
177 | }
178 |
179 | public void setState(State state) {
180 | this.mState = state;
181 | }
182 |
183 | public void setUpdateDate(Date updateDate) {
184 | this.mUpdateDate = updateDate;
185 | }
186 |
187 | public Player getActivePlayer() {
188 | if(mActivePlayer == null && mPlayers != null){
189 | for(Player player:mPlayers){
190 | if(mActivePlayerId == player.getPlayerId()){
191 | mActivePlayer = player;
192 | break;
193 | }
194 | }
195 | }
196 |
197 | return mActivePlayer;
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Gui/Activities/AbstractMessageListingActivity.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Gui.Activities;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.SystemClock;
7 | import android.support.v4.widget.DrawerLayout;
8 | import android.view.ContextMenu;
9 | import android.view.ContextMenu.ContextMenuInfo;
10 | import android.view.View.OnClickListener;
11 | import android.view.Gravity;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 | import android.view.View;
15 | import android.widget.AbsListView;
16 | import android.widget.AdapterView;
17 | import android.widget.ProgressBar;
18 | import de.raptor2101.BattleWorldsKronos.Connector.AbstractConnectorApp;
19 | import de.raptor2101.BattleWorldsKronos.Connector.ApplicationSettings;
20 | import de.raptor2101.BattleWorldsKronos.Connector.NotificationService;
21 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Message;
22 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
23 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.Adapters.MessageViewAdapter;
24 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.DeleteMessageTask;
25 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.MessageLoaderTask;
26 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.ServerConnectionTask.ResultListener;
27 |
28 | public abstract class AbstractMessageListingActivity extends Activity implements OnClickListener{
29 | private MessageViewAdapter mMessageViewAdapater= new MessageViewAdapter(this);
30 |
31 | private class MessageLoaderTaskListener implements ResultListener{
32 |
33 | AbstractMessageListingActivity mActivity;
34 |
35 | public MessageLoaderTaskListener(AbstractMessageListingActivity activity){
36 | mActivity = activity;
37 | }
38 |
39 | @Override
40 | public void handleResult(MessageLoaderTask.Result result) {
41 | ProgressBar progressBar = mActivity.getProgressBar();
42 | progressBar.setVisibility(View.GONE);
43 |
44 | if(result != null){
45 | mMessageViewAdapater.setMessages(result.getMessages());
46 | NotificationService.resetUnreadMessages(mActivity);
47 | }
48 | }
49 | }
50 |
51 | private class DeleteMessageTaskListener implements ResultListener{
52 |
53 | AbstractMessageListingActivity mActivity;
54 |
55 | public DeleteMessageTaskListener(AbstractMessageListingActivity activity){
56 | mActivity = activity;
57 | }
58 |
59 | @Override
60 | public void handleResult(Void result) {
61 | mActivity.loadMessages(true);
62 | }
63 | }
64 |
65 | @Override
66 | protected void onCreate(Bundle savedInstanceState) {
67 | super.onCreate(savedInstanceState);
68 |
69 | setContentView(R.layout.message_listing_activity);
70 |
71 |
72 | AbsListView listView = (AbsListView) findViewById(R.id.message_listing);
73 | listView.setAdapter(mMessageViewAdapater);
74 | listView.setClickable(true);
75 | registerForContextMenu(listView);
76 | }
77 |
78 | @Override
79 | protected void onStart() {
80 | View view = getTitleImageButton();
81 | view.setOnClickListener(this);
82 | super.onStart();
83 | }
84 |
85 | @Override
86 | protected void onResume() {
87 | super.onResume();
88 |
89 | ApplicationSettings settings = new ApplicationSettings(this);
90 |
91 | if(settings.getEmail().equals(ApplicationSettings.EmptyResult)){
92 | startSettingsActivity();
93 | return;
94 | }
95 |
96 | AbstractConnectorApp app = (AbstractConnectorApp) getApplication();
97 | //TODO das last load ist noch falsch...
98 | long lastLoad = app.getDatabase().getTimestampMessagesUpdate();
99 | loadMessages(SystemClock.elapsedRealtime()-lastLoad>settings.getRefreshCylce());
100 | }
101 |
102 | private void startSettingsActivity() {
103 | Intent intent = new Intent(this, SettingsActivity.class);
104 | startActivity(intent);
105 | }
106 |
107 | protected abstract void startWriteMessageActivity(Message Message);
108 |
109 | private void loadMessages(boolean forceReload){
110 |
111 | ProgressBar progressBar = getProgressBar();
112 | progressBar.setVisibility(View.VISIBLE);
113 |
114 | MessageLoaderTask loaderTask = new MessageLoaderTask((AbstractConnectorApp) this.getApplication(), new MessageLoaderTaskListener(this));
115 | loaderTask.execute(new Boolean[]{true});
116 | }
117 |
118 |
119 |
120 | @Override
121 | public abstract boolean onCreateOptionsMenu(Menu menu);
122 |
123 | @Override
124 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
125 | getMenuInflater().inflate(R.menu.message_context_menu, menu);
126 | super.onCreateContextMenu(menu, v, menuInfo);
127 | }
128 |
129 | @Override
130 | public boolean onMenuItemSelected(int featureId, MenuItem item) {
131 | if(item.getItemId() == R.id.action_settings){
132 | startSettingsActivity();
133 | } else if (item.getItemId() == R.id.action_refresh){
134 | loadMessages(true);
135 | } else if (item.getItemId() == R.id.action_write_message){
136 | startWriteMessageActivity(null);
137 | }
138 |
139 | return super.onMenuItemSelected(featureId, item);
140 | }
141 |
142 | @Override
143 | public boolean onContextItemSelected(MenuItem item) {
144 | AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
145 | Message message = (Message) mMessageViewAdapater.getItem(info.position);
146 |
147 | if(item.getItemId() == R.id.context_menu_message_answer){
148 | startWriteMessageActivity(message);
149 | } else if(item.getItemId() == R.id.context_menu_message_delete){
150 | DeleteMessageTask task = new DeleteMessageTask((AbstractConnectorApp) this.getApplication(), new DeleteMessageTaskListener(this));
151 | task.execute(message.getMessageId());
152 | }
153 | return true;
154 | };
155 |
156 | @Override
157 | public void onClick(View v) {
158 | DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
159 | if(drawerLayout.isDrawerOpen(Gravity.LEFT)){
160 | drawerLayout.closeDrawer(Gravity.LEFT);
161 | } else {
162 | drawerLayout.openDrawer(Gravity.LEFT);
163 | }
164 | };
165 |
166 | protected abstract ProgressBar getProgressBar();
167 | protected abstract View getTitleImageButton();
168 | }
169 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Data/DbHelper.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Data;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | class DbHelper extends SQLiteOpenHelper {
8 | public static final String EQUALS = "%s = ?";
9 | public static final String LESS_THAN = "%s < ?";
10 | public static final String DESC = "%s DESC";
11 |
12 |
13 | static class TableGames {
14 | public static final String Name = "games";
15 | public static final String[] ALL_COLUMNS = { Columns.GAME_ID, Columns.MAP_ID, Columns.NAME, Columns.OWNER_ID, Columns.CURRENT_ROUND, Columns.CURRENT_TURN, Columns.NEXT_PLAYER_ID, Columns.STATE, Columns.CREATED,
16 | Columns.UPDATED , Columns.PERSISTED, Columns.NOTIFIED};
17 |
18 | static class Columns {
19 | public static final String GAME_ID = "game_id";
20 | public static final String MAP_ID = "map_id";
21 | public static final String NAME = "name";
22 | public static final String OWNER_ID = "owner_id";
23 | public static final String CURRENT_TURN = "current_turn";
24 | public static final String CURRENT_ROUND = "current_round";
25 | public static final String NEXT_PLAYER_ID = "next_player_id";
26 | public static final String STATE = "state";
27 | public static final String CREATED = "created";
28 | public static final String UPDATED = "updated";
29 | public static final String PERSISTED = "persisted";
30 | public static final String NOTIFIED = "notified";
31 | }
32 |
33 | static class SqlCommands {
34 | public static final String CREATE_TABLE = String.format("CREATE TABLE %s (" +
35 | "%s INTEGER NOT NULL PRIMARY KEY," +
36 | "%s INTEGER NOT NULL," +
37 | "%s VARCHAR(250) NOT NULL," +
38 | "%s INTEGER NOT NULL," +
39 | "%s INTEGER NOT NULL," +
40 | "%s INTEGER NOT NULL," +
41 | "%s INTEGER NOT NULL," +
42 | "%s INTEGER NOT NULL," +
43 | "%s DATETIME NOT NULL," +
44 | "%s DATETIME NOT NULL," +
45 | "%s INTEGER NOT NULL," +
46 | "%s INTEGER NOT NULL" +
47 | ")",
48 | Name, Columns.GAME_ID, Columns.MAP_ID, Columns.NAME, Columns.OWNER_ID, Columns.CURRENT_TURN, Columns.CURRENT_ROUND, Columns.NEXT_PLAYER_ID, Columns.STATE, Columns.CREATED, Columns.UPDATED,
49 | Columns.PERSISTED, Columns.NOTIFIED);
50 | public static final String DROP_TABLE = String.format("DROP TABLE IF EXISTS %s", Name);
51 | public static final String COUNT_UNNOTIFIED_GAMES_IN_STATE = String.format("SELECT COUNT(*) FROM %s WHERE %s = 0 AND %s = ?", Name,Columns.NOTIFIED,Columns.STATE);
52 | public static final String COUNT_GAMES_IN_STATE = String.format("SELECT COUNT(*) FROM %s WHERE %s = ?", Name, Columns.STATE);
53 | public static final String RESET_ALL_TIMESTAMPS = String.format("UPDATE %s SET %s = ? WHERE %s > ?", Name,Columns.PERSISTED,Columns.PERSISTED);
54 | }
55 | }
56 |
57 | static class TablePlayers{
58 | public static final String Name = "players";
59 | public static final String[] ALL_COLUMNS = {Columns.GAME_ID, Columns.PLAYER_ID, Columns.USER_ID, Columns.TEAM, Columns.NAME, Columns.COLOR, Columns.STATE, Columns.LAST_MESSAGE};
60 |
61 | static class Columns {
62 | public static final String GAME_ID = "game_id";
63 | public static final String PLAYER_ID = "player_id";
64 | public static final String USER_ID = "user_id";
65 | public static final String NAME = "name";
66 | public static final String TEAM = "team";
67 | public static final String COLOR = "color";
68 | public static final String STATE = "state";
69 | public static final String LAST_MESSAGE = "last_message";
70 | }
71 |
72 | static class SqlCommands {
73 | public static final String CREATE_TABLE = String.format("CREATE TABLE %s (" +
74 | "%s INTEGER NOT NULL," +
75 | "%s INTEGER NOT NULL," +
76 | "%s INTEGER NOT NULL," +
77 | "%s VARCHAR(250) NOT NULL," +
78 | "%s INTEGER NOT NULL," +
79 | "%s VARCHAR(7) NOT NULL," +
80 | "%s INTEGER NOT NULL," +
81 | "%s VARCHAR(140) NOT NULL," +
82 | "PRIMARY KEY (%s,%s))",
83 | Name, Columns.GAME_ID, Columns.PLAYER_ID, Columns.USER_ID, Columns.NAME, Columns.TEAM, Columns.COLOR, Columns.STATE, Columns.LAST_MESSAGE, Columns.GAME_ID, Columns.PLAYER_ID);
84 | public static final String DROP_TABLE = String.format("DROP TABLE IF EXISTS %s", Name);
85 | }
86 | }
87 |
88 | static class TableMessage{
89 | public static final String Name = "messages";
90 | public static final String[] ALL_COLUMNS = new String[]{Columns.MESSAGE_ID, Columns.AUTHOR_ID, Columns.AUTHOR_NAME, Columns.TIMESTAMP, Columns.MESSAGE, Columns.LAST_MESSAGE_ID, Columns.IS_SYSTEM_MESSAGE, Columns.IS_READ, Columns.IS_DISCARDED, Columns.IS_DELETED, Columns.PERSISTED, Columns.NOTIFIED};
91 |
92 | static class Columns {
93 | public static final String MESSAGE_ID = "message_id";
94 | public static final String AUTHOR_ID = "author_id";
95 | public static final String AUTHOR_NAME = "author_name";
96 | public static final String TIMESTAMP = "timestamp";
97 | public static final String MESSAGE = "message";
98 | public static final String LAST_MESSAGE_ID = "last_message_id";
99 |
100 | public static final String IS_SYSTEM_MESSAGE = "is_system_message";
101 | public static final String IS_READ = "is_read";
102 | public static final String IS_DISCARDED = "is_discarded";
103 | public static final String IS_DELETED = "is_deleted";
104 |
105 | public static final String PERSISTED = "persisted";
106 | public static final String NOTIFIED = "notified";
107 | }
108 |
109 | static class SqlCommands {
110 | public static final String CREATE_TABLE = String.format("CREATE TABLE %s (" +
111 | "%s INTEGER NOT NULL PRIMARY KEY," +
112 | "%s INTEGER NOT NULL," +
113 | "%s VARCHAR(250) NOT NULL," +
114 | "%s DATETIME NOT NULL," +
115 | "%s TEXT NOT NULL," +
116 | "%s INTEGER NOT NULL," +
117 | "%s INTEGER NOT NULL," +
118 | "%s INTEGER NOT NULL," +
119 | "%s INTEGER NOT NULL," +
120 | "%s INTEGER NOT NULL," +
121 | "%s INTEGER NOT NULL," +
122 | "%s INTEGER NOT NULL" +
123 | ")",
124 | Name, Columns.MESSAGE_ID, Columns.AUTHOR_ID, Columns.AUTHOR_NAME, Columns.TIMESTAMP, Columns.MESSAGE, Columns.LAST_MESSAGE_ID, Columns.IS_SYSTEM_MESSAGE, Columns.IS_READ, Columns.IS_DISCARDED, Columns.IS_DELETED,Columns.PERSISTED,Columns.NOTIFIED);
125 | public static final String DROP_TABLE = String.format("DROP TABLE IF EXISTS %s", Name);
126 | public static final String DELETE_OLD_MESSAGES = String.format("DELETE FROM %s WHERE %s = 1 OR %s < ?", Name, Columns.IS_DELETED, Columns.PERSISTED);
127 | public static final String WHERE_MESSAGES_TO_READ = String.format("%s = 0 AND %s = 0", Columns.IS_DISCARDED,Columns.IS_DELETED);
128 | public static final String RESET_ALL_TIMESTAMPS = String.format("UPDATE %s SET %s = ? WHERE %s > ?", Name,Columns.PERSISTED,Columns.PERSISTED);
129 | }
130 | }
131 |
132 | static class TableLastUpdate{
133 | public static final String Name = "last_update";
134 |
135 | static class Columns {
136 | public static final String Name = "name";
137 | public static final String Timestamp = "timestamp";
138 | }
139 |
140 | static class SqlCommands {
141 | public static final String CREATE_TABLE = String.format("CREATE TABLE %s (" +
142 | "%s VARCHAR(50) NOT NULL PRIMARY KEY,"+
143 | "%s INTEGER NOT NULL" +
144 | ")",
145 | Name,Columns.Name,Columns.Timestamp);
146 | public static final String DROP_TABLE = String.format("DROP TABLE IF EXISTS %s", Name);
147 | }
148 | }
149 |
150 | private static final String DATABASE_NAME = "connector.db";
151 | private static final int DATABASE_VERSION = 4;
152 |
153 |
154 | public DbHelper(Context context) {
155 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
156 | }
157 |
158 | @Override
159 | public void onCreate(SQLiteDatabase database) {
160 | database.execSQL(TableGames.SqlCommands.CREATE_TABLE);
161 | database.execSQL(TablePlayers.SqlCommands.CREATE_TABLE);
162 | database.execSQL(TableMessage.SqlCommands.CREATE_TABLE);
163 | database.execSQL(TableLastUpdate.SqlCommands.CREATE_TABLE);
164 | }
165 |
166 | @Override
167 | public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
168 | database.execSQL(TableGames.SqlCommands.DROP_TABLE);
169 | database.execSQL(TablePlayers.SqlCommands.DROP_TABLE);
170 | database.execSQL(TableMessage.SqlCommands.DROP_TABLE);
171 | database.execSQL(TableLastUpdate.SqlCommands.DROP_TABLE);
172 | database.execSQL(TableGames.SqlCommands.CREATE_TABLE);
173 | database.execSQL(TablePlayers.SqlCommands.CREATE_TABLE);
174 | database.execSQL(TableMessage.SqlCommands.CREATE_TABLE);
175 | database.execSQL(TableLastUpdate.SqlCommands.CREATE_TABLE);
176 | }
177 |
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/NotificationService.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector;
2 |
3 | import android.app.Activity;
4 | import android.app.AlarmManager;
5 | import android.app.Notification;
6 | import android.app.NotificationManager;
7 | import android.app.PendingIntent;
8 | import android.app.Service;
9 | import android.appwidget.AppWidgetManager;
10 | import android.content.Context;
11 | import android.content.Intent;
12 | import android.net.ConnectivityManager;
13 | import android.os.AsyncTask.Status;
14 | import android.os.IBinder;
15 | import android.os.PowerManager;
16 | import android.os.PowerManager.WakeLock;
17 | import android.support.v4.app.NotificationCompat;
18 | import android.support.v4.app.TaskStackBuilder;
19 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.R;
20 | import de.raptor2101.BattleWorldsKronos.Connector.Gui.WidgetProviders.GeneralOverviewProvider;
21 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.GamesLoaderTask;
22 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.MessageLoaderTask;
23 | import de.raptor2101.BattleWorldsKronos.Connector.Tasks.ServerConnectionTask.ResultListener;
24 |
25 | public class NotificationService extends Service {
26 | private static final String ServiceTag = "BWK:Connector-Service";
27 | private static final int NotificationIdPendingGames = 1;
28 | private static final int NotificationIdUnreadMessages = 2;
29 |
30 | private static Class extends Activity> GameListingActivity;
31 | private static Class extends Activity> MessageListingActivity;
32 | private WakeLock mWakeLock;
33 | private GamesLoaderTask mGameLoaderTask;
34 | private MessageLoaderTask mMessageLoaderTask;
35 |
36 | private class MessageLoaderResultListener implements ResultListener{
37 | NotificationService mService;
38 |
39 | public MessageLoaderResultListener(NotificationService service){
40 | mService = service;
41 | }
42 |
43 | @Override
44 | public void handleResult(MessageLoaderTask.Result result) {
45 |
46 | if (result != null && result.getUnnotifiedMessages()>0) {
47 | mService.generateUnreadMessageNotification(result.getMessages().size());
48 | }
49 |
50 | if(mService.mGameLoaderTask != null && mService.mGameLoaderTask.getStatus() ==Status.FINISHED){
51 | mService.stopSelf();
52 | }
53 |
54 | }
55 | }
56 |
57 | private class GamesLoaderResultListener implements ResultListener{
58 | NotificationService mService;
59 |
60 | public GamesLoaderResultListener(NotificationService service){
61 | mService = service;
62 | }
63 |
64 | @Override
65 | public void handleResult(GamesLoaderTask.Result result) {
66 | if (result != null && result.getUnnotifiedPendingGames() > 0) {
67 | mService.generatePendingGamesNotification(result.getPendingGamesCount());
68 |
69 | Intent intent = new Intent(mService, GeneralOverviewProvider.class);
70 | intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
71 | // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID,
72 | // since it seems the onUpdate() is only fired on that:
73 | int[] ids = {R.xml.general_overview_widgetinfo};
74 | intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids);
75 | sendBroadcast(intent);
76 | }
77 |
78 | if(mService.mMessageLoaderTask != null && mService.mMessageLoaderTask.getStatus() ==Status.FINISHED){
79 | mService.stopSelf();
80 | }
81 | }
82 | }
83 |
84 | @Override
85 | public IBinder onBind(Intent intent) {
86 | return null;
87 | }
88 |
89 | @Override
90 | public void onStart(Intent intent, int startId) {
91 | handleIntent(intent);
92 | }
93 |
94 | @Override
95 | public int onStartCommand(Intent intent, int flags, int startId) {
96 | handleIntent(intent);
97 | return START_STICKY;
98 | }
99 |
100 | public void onDestroy() {
101 | super.onDestroy();
102 | mWakeLock.release();
103 | }
104 |
105 | private void handleIntent(Intent intent) {
106 | // obtain the wake lock
107 | PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
108 | mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ServiceTag);
109 | mWakeLock.acquire();
110 | ApplicationSettings settings = new ApplicationSettings(this);
111 | // check the global background data setting
112 | ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
113 | if (!cm.getBackgroundDataSetting() || (!settings.isNotifyOnGamesEnabled() && !settings.isNotifyOnMessagesEnabled())) {
114 | stopSelf();
115 | return;
116 | }
117 |
118 | AbstractConnectorApp app = (AbstractConnectorApp) this.getApplication();
119 | if(settings.isNotifyOnGamesEnabled()){
120 | mGameLoaderTask = new GamesLoaderTask(app, new GamesLoaderResultListener(this));
121 | mGameLoaderTask.execute(new Boolean[]{true});
122 | }
123 |
124 | if(settings.isNotifyOnMessagesEnabled()){
125 | mMessageLoaderTask = new MessageLoaderTask(app, new MessageLoaderResultListener(this));
126 | mMessageLoaderTask.execute(new Boolean[]{true});
127 | }
128 |
129 | }
130 |
131 | private void generatePendingGamesNotification(int pendingGames) {
132 | NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle(this.getString(R.string.app_name))
133 | .setContentText(String.format(this.getString(R.string.notification_games_pending), pendingGames)).setAutoCancel(true)
134 | .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS).setPriority(NotificationCompat.PRIORITY_HIGH);
135 |
136 | Intent resultIntent = new Intent(this, GameListingActivity);
137 |
138 | TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
139 | stackBuilder.addParentStack(GameListingActivity);
140 | stackBuilder.addNextIntent(resultIntent);
141 | PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
142 | builder.setContentIntent(resultPendingIntent);
143 | NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
144 |
145 | notificationManager.notify(NotificationIdPendingGames, builder.build());
146 |
147 | GeneralOverviewProvider.Update(this);
148 | }
149 |
150 | private void generateUnreadMessageNotification(int unreadMessages) {
151 | NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setContentTitle(this.getString(R.string.app_name))
152 | .setContentText(String.format(this.getString(R.string.notification_messages_unread), unreadMessages)).setAutoCancel(true)
153 | .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS).setPriority(NotificationCompat.PRIORITY_HIGH);
154 |
155 | Intent resultIntent = new Intent(this, MessageListingActivity);
156 |
157 | TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
158 | stackBuilder.addParentStack(MessageListingActivity);
159 | stackBuilder.addNextIntent(resultIntent);
160 | PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
161 | builder.setContentIntent(resultPendingIntent);
162 | NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
163 |
164 | notificationManager.notify(NotificationIdUnreadMessages, builder.build());
165 | }
166 |
167 | private static boolean isNotificationServiceNeeded(ApplicationSettings settings) {
168 |
169 | return settings.isNotifyOnGamesEnabled() || settings.isNotifyOnMessagesEnabled();
170 | }
171 |
172 | public static void setResponseActivities(Class extends Activity> gameListingActivity, Class extends Activity> showMessageActivity) {
173 | GameListingActivity = gameListingActivity;
174 | MessageListingActivity = showMessageActivity;
175 | }
176 |
177 | public static void resetPendingGames(Context context) {
178 | ApplicationSettings settings = new ApplicationSettings(context);
179 |
180 | if (!isNotificationServiceNeeded(settings)) {
181 | return;
182 | }
183 | // Reset notifications
184 | NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
185 | notificationManager.cancel(NotificationIdPendingGames);
186 |
187 | resetAndRegister(context, settings);
188 | }
189 |
190 | public static void resetUnreadMessages(Context context) {
191 | ApplicationSettings settings = new ApplicationSettings(context);
192 |
193 | if (!isNotificationServiceNeeded(settings)) {
194 | return;
195 | }
196 | // Reset notifications
197 | NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
198 | notificationManager.cancel(NotificationIdUnreadMessages);
199 |
200 | resetAndRegister(context, settings);
201 | }
202 |
203 | private static void resetAndRegister(Context context, ApplicationSettings settings) {
204 | // Reset and reregister the service
205 | int timeSpan = settings.getRefreshCylce();
206 | AlarmManager am = (AlarmManager) context.getSystemService(ALARM_SERVICE);
207 | Intent intent = new Intent(context, NotificationService.class);
208 | PendingIntent pi = PendingIntent.getService(context, 0, intent, 0);
209 | am.cancel(pi);
210 | am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, timeSpan, timeSpan, pi);
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/src/de/raptor2101/BattleWorldsKronos/Connector/Data/Database.java:
--------------------------------------------------------------------------------
1 | package de.raptor2101.BattleWorldsKronos.Connector.Data;
2 |
3 | import java.text.ParseException;
4 | import java.text.SimpleDateFormat;
5 | import java.util.ArrayList;
6 | import java.util.Date;
7 | import java.util.List;
8 | import java.util.Locale;
9 |
10 | import android.content.ContentValues;
11 | import android.content.Context;
12 | import android.database.Cursor;
13 | import android.database.sqlite.SQLiteDatabase;
14 | import android.os.SystemClock;
15 | import de.raptor2101.BattleWorldsKronos.Connector.Data.DbHelper.TableGames;
16 | import de.raptor2101.BattleWorldsKronos.Connector.Data.DbHelper.TableMessage;
17 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Game;
18 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Message;
19 | import de.raptor2101.BattleWorldsKronos.Connector.Data.Entities.Player;
20 |
21 | public class Database {
22 | private final static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
23 | private DbHelper mDbHelper;
24 | private SQLiteDatabase mDatabase;
25 |
26 | public Database(Context context) {
27 | mDbHelper = new DbHelper(context);
28 | }
29 |
30 | public void open() {
31 | mDatabase = mDbHelper.getWritableDatabase();
32 | }
33 |
34 | public void close() {
35 | mDbHelper.close();
36 | mDatabase = null;
37 | }
38 |
39 | public void persistMessage(List messages){
40 | long persistTimestamp = SystemClock.elapsedRealtime();
41 |
42 | for(Message message:messages){
43 | int messageId = message.getMessageId();
44 | ContentValues contentValues = buildContentValues(message, persistTimestamp);
45 |
46 | String whereCondition = String.format(DbHelper.EQUALS, DbHelper.TableMessage.Columns.MESSAGE_ID);
47 | String[] arguments = new String[] { String.valueOf(messageId) };
48 | int updatedRows = mDatabase.update(DbHelper.TableMessage.Name, contentValues, whereCondition, arguments);
49 |
50 | if(updatedRows == 0) {
51 | contentValues.put(DbHelper.TableMessage.Columns.NOTIFIED, 0);
52 | mDatabase.insert(DbHelper.TableMessage.Name, null, contentValues);
53 | }
54 | }
55 |
56 | deleteOldMessages(persistTimestamp);
57 | setLastUpdate(DbHelper.TableMessage.Name, persistTimestamp);
58 | }
59 |
60 | private void deleteOldMessages(long persistTimestamp) {
61 | mDatabase.execSQL(DbHelper.TableMessage.SqlCommands.DELETE_OLD_MESSAGES, new String[]{String.valueOf(persistTimestamp)});
62 | }
63 |
64 | public List getMessages(){
65 | Cursor cursor = mDatabase.query(DbHelper.TableMessage.Name, DbHelper.TableMessage.ALL_COLUMNS, DbHelper.TableMessage.SqlCommands.WHERE_MESSAGES_TO_READ, null, null, null, DbHelper.TableMessage.Columns.MESSAGE_ID);
66 |
67 | ArrayList messages = new ArrayList(cursor.getCount());
68 |
69 | cursor.moveToFirst();
70 | while(!cursor.isAfterLast()){
71 | try {
72 | Message message = new Message();
73 |
74 | message.setMessageId(cursor.getInt(0));
75 | message.setAuthorId(cursor.getInt(1));
76 | message.setAuthorName(cursor.getString(2));
77 | message.setTimestamp(DATE_FORMAT.parse(cursor.getString(3)));
78 | message.setMessageText(cursor.getString(4));
79 | message.setLastMessageId(cursor.getInt(5));
80 | message.setSystemMessage(cursor.getInt(6)==1);
81 | message.setReaded(cursor.getInt(7)==1);
82 | message.setDiscarded(cursor.getInt(8)==1);
83 | message.setDeleted(cursor.getInt(9)==1);
84 |
85 | messages.add(message);
86 | } catch (ParseException e) {
87 | e.printStackTrace();
88 | }
89 | cursor.moveToNext();
90 | }
91 | cursor.close();
92 |
93 | return messages;
94 | }
95 |
96 | private ContentValues buildContentValues(Message message, long persistTimestamp) {
97 | ContentValues contentValues = new ContentValues(DbHelper.TableMessage.ALL_COLUMNS.length);
98 | contentValues.put(DbHelper.TableMessage.Columns.MESSAGE_ID, message.getMessageId());
99 | contentValues.put(DbHelper.TableMessage.Columns.AUTHOR_ID, message.getAuthorId());
100 | contentValues.put(DbHelper.TableMessage.Columns.AUTHOR_NAME, message.getAuthorName());
101 | contentValues.put(DbHelper.TableMessage.Columns.TIMESTAMP, DATE_FORMAT.format(message.getTimestamp()));
102 | contentValues.put(DbHelper.TableMessage.Columns.MESSAGE, message.getMessageText());
103 | contentValues.put(DbHelper.TableMessage.Columns.LAST_MESSAGE_ID, message.getLastMessageId());
104 | contentValues.put(DbHelper.TableMessage.Columns.IS_SYSTEM_MESSAGE, message.isSystemMessage());
105 | contentValues.put(DbHelper.TableMessage.Columns.IS_READ, message.isReaded());
106 | contentValues.put(DbHelper.TableMessage.Columns.IS_DISCARDED, message.isDiscarded());
107 | contentValues.put(DbHelper.TableMessage.Columns.IS_DELETED, message.isDeleted());
108 | contentValues.put(DbHelper.TableMessage.Columns.PERSISTED, persistTimestamp);
109 |
110 | return contentValues;
111 | }
112 |
113 | public void persistGames(List games) {
114 | long persistTimestamp = SystemClock.elapsedRealtime();
115 | for (Game game : games) {
116 | ContentValues contentValues = buildContentValues(game, persistTimestamp);
117 | int gameId = game.getGameId();
118 | int modiefied = updateGame(gameId, game.getUpdateDate(), contentValues);
119 | if (modiefied == 0) {
120 | contentValues.put(DbHelper.TableGames.Columns.NOTIFIED, 0);
121 | insertGame(contentValues);
122 |
123 | for (Player player : game.getPlayers()) {
124 | contentValues = buildContentValues(gameId, player);
125 | insertPlayer(contentValues);
126 | }
127 | } else {
128 | for (Player player : game.getPlayers()) {
129 | contentValues = new ContentValues(2);
130 | contentValues.put(DbHelper.TablePlayers.Columns.STATE, player.getState().getValue());
131 | contentValues.put(DbHelper.TablePlayers.Columns.LAST_MESSAGE, player.getLastMessage());
132 | if(updatePlayer(player.getPlayerId(), contentValues) == 0){
133 | contentValues = buildContentValues(gameId, player);
134 | insertPlayer(contentValues);
135 | }
136 | }
137 | }
138 | }
139 |
140 | deleteOldGames(persistTimestamp);
141 | setLastUpdate(DbHelper.TableGames.Name, persistTimestamp);
142 | }
143 |
144 | private void deleteOldGames(long persistTimestamp) {
145 | Cursor cursor = mDatabase.query(DbHelper.TableGames.Name, new String[]{DbHelper.TableGames.Columns.GAME_ID}, String.format(DbHelper.LESS_THAN, DbHelper.TableGames.Columns.PERSISTED), new String[]{String.valueOf(persistTimestamp)}, null, null, null);
146 | cursor.moveToFirst();
147 | while(!cursor.isAfterLast()){
148 | int gameId = cursor.getInt(0);
149 |
150 | mDatabase.delete(DbHelper.TablePlayers.Name, String.format(DbHelper.EQUALS,DbHelper.TablePlayers.Columns.GAME_ID), new String[]{String.valueOf(gameId)});
151 | mDatabase.delete(DbHelper.TableGames.Name, String.format(DbHelper.EQUALS,DbHelper.TableGames.Columns.GAME_ID), new String[]{String.valueOf(gameId)});
152 | cursor.moveToNext();
153 | }
154 | cursor.close();
155 | }
156 |
157 | private void insertPlayer(ContentValues contentValues) {
158 | mDatabase.insert(DbHelper.TablePlayers.Name, null, contentValues);
159 | }
160 |
161 | private ContentValues buildContentValues(int gameId, Player player) {
162 | ContentValues contentValues = new ContentValues(DbHelper.TablePlayers.ALL_COLUMNS.length);
163 | contentValues.put(DbHelper.TablePlayers.Columns.GAME_ID, gameId);
164 | contentValues.put(DbHelper.TablePlayers.Columns.PLAYER_ID, player.getPlayerId());
165 | contentValues.put(DbHelper.TablePlayers.Columns.NAME, player.getPlayerName());
166 | contentValues.put(DbHelper.TablePlayers.Columns.STATE, player.getState().getValue());
167 | contentValues.put(DbHelper.TablePlayers.Columns.TEAM, player.getTeam());
168 | contentValues.put(DbHelper.TablePlayers.Columns.USER_ID, player.getUserId());
169 | contentValues.put(DbHelper.TablePlayers.Columns.COLOR, player.getColor());
170 | contentValues.put(DbHelper.TablePlayers.Columns.LAST_MESSAGE, player.getLastMessage());
171 | return contentValues;
172 | }
173 |
174 | private ContentValues buildContentValues(Game game, long persistTimestamp) {
175 | ContentValues contentValues = new ContentValues(DbHelper.TableGames.ALL_COLUMNS.length);
176 | contentValues.put(DbHelper.TableGames.Columns.GAME_ID, game.getGameId());
177 | contentValues.put(DbHelper.TableGames.Columns.MAP_ID, game.getMapId());
178 | contentValues.put(DbHelper.TableGames.Columns.NAME, game.getGameName());
179 | contentValues.put(DbHelper.TableGames.Columns.OWNER_ID, game.getOwnerId());
180 | contentValues.put(DbHelper.TableGames.Columns.CURRENT_TURN, game.getCurrentTurn());
181 | contentValues.put(DbHelper.TableGames.Columns.CURRENT_ROUND, game.getCurrentRound());
182 | contentValues.put(DbHelper.TableGames.Columns.NEXT_PLAYER_ID, game.getActivePlayerId());
183 | contentValues.put(DbHelper.TableGames.Columns.STATE, game.getState().getValue());
184 | contentValues.put(DbHelper.TableGames.Columns.CREATED, DATE_FORMAT.format(game.getCreateDate()));
185 | contentValues.put(DbHelper.TableGames.Columns.UPDATED, DATE_FORMAT.format(game.getUpdateDate()));
186 | contentValues.put(DbHelper.TableGames.Columns.PERSISTED, persistTimestamp);
187 | contentValues.put(DbHelper.TableGames.Columns.NOTIFIED, 0);
188 | return contentValues;
189 | }
190 |
191 | private int updatePlayer(int playerId, ContentValues contentValues) {
192 | String whereCondition = String.format(DbHelper.EQUALS, DbHelper.TablePlayers.Columns.PLAYER_ID);
193 | String[] arguments = new String[] { String.valueOf(playerId) };
194 | return mDatabase.update(DbHelper.TablePlayers.Name, contentValues, whereCondition, arguments);
195 | }
196 |
197 | private void insertGame(ContentValues contentValues) {
198 | mDatabase.insert(DbHelper.TableGames.Name, null, contentValues);
199 | }
200 |
201 | private int updateGame(int gameId, Date updateTimestamp, ContentValues contentValues) {
202 |
203 | Date savedUpdateTimestamp;
204 | savedUpdateTimestamp = getUpdateTimestamp(gameId);
205 |
206 | if (savedUpdateTimestamp == null) {
207 | return 0;
208 | }
209 |
210 | if (!updateTimestamp.after(savedUpdateTimestamp)) {
211 | long persistTimestamp = contentValues.getAsLong(DbHelper.TableGames.Columns.PERSISTED);
212 | contentValues = new ContentValues(1);
213 | contentValues.put(DbHelper.TableGames.Columns.PERSISTED, persistTimestamp);
214 | }
215 |
216 | String whereCondition = String.format(DbHelper.EQUALS, DbHelper.TableGames.Columns.GAME_ID);
217 | String[] arguments = new String[] { String.valueOf(gameId) };
218 | return mDatabase.update(DbHelper.TableGames.Name, contentValues, whereCondition, arguments);
219 | }
220 |
221 | private Date getUpdateTimestamp(int gameId) {
222 | Date returnDate = null;
223 | Cursor cursor = mDatabase.query(DbHelper.TableGames.Name, new String[] { DbHelper.TableGames.Columns.UPDATED }, String.format(DbHelper.EQUALS, DbHelper.TableGames.Columns.GAME_ID),
224 | new String[] { String.valueOf(gameId) }, null, null, null);
225 | try {
226 |
227 | cursor.moveToFirst();
228 | if (!cursor.isAfterLast()) {
229 | returnDate = DATE_FORMAT.parse(cursor.getString(0));
230 | }
231 | } catch (ParseException e) {
232 | } finally {
233 | cursor.close();
234 | }
235 | return returnDate;
236 | }
237 |
238 | public int getPendingGamesCount() {
239 | Cursor cursor = mDatabase.rawQuery(DbHelper.TableGames.SqlCommands.COUNT_GAMES_IN_STATE, new String[]{String.valueOf(Game.State.PENDING.getValue())});
240 | return getSingleIntFromCursor(cursor);
241 | }
242 |
243 | public int getRunningGamesCount() {
244 | Cursor cursor = mDatabase.rawQuery(DbHelper.TableGames.SqlCommands.COUNT_GAMES_IN_STATE, new String[]{String.valueOf(Game.State.WAITING.getValue())});
245 | return getSingleIntFromCursor(cursor);
246 | }
247 |
248 | public int getOpenGamesCount() {
249 | Cursor cursor = mDatabase.rawQuery(DbHelper.TableGames.SqlCommands.COUNT_GAMES_IN_STATE, new String[]{String.valueOf(Game.State.OPEN.getValue())});
250 | return getSingleIntFromCursor(cursor);
251 | }
252 |
253 | public int getUnnotfiedPendingGamesCount() {
254 | Cursor cursor = mDatabase.rawQuery(DbHelper.TableGames.SqlCommands.COUNT_UNNOTIFIED_GAMES_IN_STATE, new String[]{String.valueOf(Game.State.PENDING.getValue())});
255 | return getSingleIntFromCursor(cursor);
256 | }
257 |
258 | public void setAllGamesNotified(){
259 | ContentValues contentValues = new ContentValues(1);
260 | contentValues.put(DbHelper.TableGames.Columns.NOTIFIED, 1);
261 | mDatabase.update(DbHelper.TableGames.Name, contentValues, String.format(DbHelper.EQUALS, DbHelper.TableGames.Columns.NOTIFIED), new String[]{"0"});
262 | }
263 |
264 | public long getTimestampLastGameUpdate(){
265 | return getLastUpdate(DbHelper.TableGames.Name);
266 | }
267 |
268 | public long getTimestampMessagesUpdate(){
269 | return getLastUpdate(DbHelper.TableMessage.Name);
270 | }
271 |
272 | private long getLastUpdate(String tableName){
273 | Cursor cursor = mDatabase.query(DbHelper.TableLastUpdate.Name, new String[]{DbHelper.TableLastUpdate.Columns.Timestamp}, String.format(DbHelper.EQUALS,DbHelper.TableLastUpdate.Columns.Name), new String[]{tableName}, null, null, null);
274 |
275 | long returnValue = 0;
276 | cursor.moveToFirst();
277 | if(!cursor.isAfterLast()){
278 | returnValue = cursor.getLong(0);
279 | }
280 | cursor.close();
281 |
282 | return returnValue;
283 | }
284 |
285 | private void setLastUpdate(String tableName, long timestamp){
286 | ContentValues values = new ContentValues(2);
287 | values.put(DbHelper.TableLastUpdate.Columns.Name, tableName);
288 | values.put(DbHelper.TableLastUpdate.Columns.Timestamp, timestamp);
289 |
290 | int updatedRows = mDatabase.update(DbHelper.TableLastUpdate.Name, values, String.format(DbHelper.EQUALS,DbHelper.TableLastUpdate.Columns.Name), new String[]{tableName});
291 | if(updatedRows == 0){
292 | mDatabase.insert(DbHelper.TableLastUpdate.Name, null, values);
293 | }
294 | }
295 |
296 |
297 | private int getSingleIntFromCursor(Cursor cursor){
298 | int returnValue = 0;
299 | cursor.moveToFirst();
300 | if(!cursor.isAfterLast()){
301 | returnValue = cursor.getInt(0);
302 | }
303 | cursor.close();
304 |
305 | return returnValue;
306 | }
307 |
308 | public List getGames() {
309 | Cursor cursor = mDatabase.query(DbHelper.TableGames.Name, DbHelper.TableGames.ALL_COLUMNS, null, null, null, null, String.format(DbHelper.DESC, DbHelper.TableGames.Columns.UPDATED));
310 |
311 | ArrayList games = new ArrayList(cursor.getCount());
312 |
313 | cursor.moveToFirst();
314 | while(!cursor.isAfterLast()){
315 | try {
316 | Game game = new Game();
317 | game.setGameId(cursor.getInt(0));
318 | game.setMapId(cursor.getInt(1));
319 | game.setGameName(cursor.getString(2));
320 | game.setOwnerId(cursor.getInt(3));
321 | game.setCurrentRound(cursor.getInt(4));
322 | game.setCurrentTurn(cursor.getInt(5));
323 | game.setNextPlayerId(cursor.getInt(6));
324 | game.setState(Game.State.FromInt(cursor.getInt(7)));
325 | game.setUpdateDate(DATE_FORMAT.parse(cursor.getString(9)));
326 | game.setCreateDate(DATE_FORMAT.parse(cursor.getString(8)));
327 |
328 | games.add(game);
329 | } catch (ParseException e) {
330 | e.printStackTrace();
331 | }
332 | cursor.moveToNext();
333 | }
334 | cursor.close();
335 |
336 | for(Game game:games){
337 | loadPlayers(game);
338 | }
339 |
340 | return games;
341 | }
342 |
343 | private void loadPlayers(Game game) {
344 | Cursor cursor = mDatabase.query(DbHelper.TablePlayers.Name, DbHelper.TablePlayers.ALL_COLUMNS, String.format(DbHelper.EQUALS,DbHelper.TablePlayers.Columns.GAME_ID), new String[]{String.valueOf(game.getGameId())}, null, null, DbHelper.TablePlayers.Columns.PLAYER_ID);
345 | List players = new ArrayList(cursor.getCount());
346 | Player activePlayer = null, winner = null;
347 |
348 | int activePlayerId = game.getActivePlayerId();
349 | cursor.moveToFirst();
350 | while(!cursor.isAfterLast()){
351 | Player player = new Player();
352 | player.setPlayerId(cursor.getInt(1));
353 | player.setUserId(cursor.getInt(2));
354 | player.setTeam(cursor.getInt(3));
355 | player.setPlayerName(cursor.getString(4));
356 | player.setColor(cursor.getString(5));
357 | player.setState(Player.State.FromInt(cursor.getInt(6)));
358 | player.setLastMessage(cursor.getString(7));
359 |
360 | if(player.getState() == Player.State.WON){
361 | winner = player;
362 | }
363 |
364 | if(player.getPlayerId() == activePlayerId){
365 | activePlayer = player;
366 | }
367 |
368 | players.add(player);
369 | cursor.moveToNext();
370 | }
371 | cursor.close();
372 |
373 | game.setPlayers(players, winner, activePlayer);
374 | }
375 |
376 | public void resetTimestamps(){
377 | long timestamp = SystemClock.elapsedRealtime();
378 | String[] timestampValue= new String[]{String.valueOf(timestamp),String.valueOf(timestamp)};
379 | mDatabase.execSQL(TableGames.SqlCommands.RESET_ALL_TIMESTAMPS,timestampValue);
380 | mDatabase.execSQL(TableMessage.SqlCommands.RESET_ALL_TIMESTAMPS,timestampValue);
381 | }
382 | }
383 |
--------------------------------------------------------------------------------