├── 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 | 3 | 8 | 13 | 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 | 3 | 8 | 13 | 18 | 23 | 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 getGameListingActivityClass(); 36 | public abstract Class 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 |