project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java
author Wuzzy <almikes@aol.com>
Thu, 12 May 2016 16:20:17 +0200
changeset 12196 d7ccd18ae7bf
parent 10017 de822cd3df3a
child 15533 fb23e49b2d4e
permissions -rw-r--r--
Fix swimming rubberduck screwing up after portal, also change timer to 15s, no resets
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     1
/*
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6623
diff changeset
     3
 * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com>
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     4
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
     5
 *
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     6
 * This program is free software; you can redistribute it and/or
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     7
 * modify it under the terms of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     8
 * as published by the Free Software Foundation; either version 2
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     9
 * of the License, or (at your option) any later version.
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    10
 *
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful,
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    14
 * GNU General Public License for more details.
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    15
 *
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    17
 * along with this program; if not, write to the Free Software
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    19
 */
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    20
package org.hedgewars.hedgeroid;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    21
7344
25b8906f901a Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    22
import java.io.File;
25b8906f901a Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    23
import java.io.FileInputStream;
25b8906f901a Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    24
import java.io.IOException;
25b8906f901a Hedgeroid: Modified detection of assets on SD card (should be more reliable)
Medo <smaxein@googlemail.com>
parents: 7330
diff changeset
    25
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    26
import org.hedgewars.hedgeroid.Downloader.DownloadAssets;
6343
9df5a486f41e first part of the new downloader implementation
Xeli
parents: 6049
diff changeset
    27
import org.hedgewars.hedgeroid.Downloader.DownloadListActivity;
7358
57a508884052 Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents: 7355
diff changeset
    28
import org.hedgewars.hedgeroid.netplay.Netplay;
57a508884052 Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents: 7355
diff changeset
    29
import org.hedgewars.hedgeroid.netplay.Netplay.State;
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7485
diff changeset
    30
import org.hedgewars.hedgeroid.util.FileUtils;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    31
6456
fed715edc3ee android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents: 6350
diff changeset
    32
import android.app.AlertDialog;
fed715edc3ee android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents: 6350
diff changeset
    33
import android.app.Dialog;
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    34
import android.app.ProgressDialog;
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7352
diff changeset
    35
import android.content.BroadcastReceiver;
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7352
diff changeset
    36
import android.content.Context;
6456
fed715edc3ee android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents: 6350
diff changeset
    37
import android.content.DialogInterface;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    38
import android.content.Intent;
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7352
diff changeset
    39
import android.content.IntentFilter;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    40
import android.os.Bundle;
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    41
import android.support.v4.app.FragmentActivity;
7444
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents: 7358
diff changeset
    42
import android.support.v4.app.FragmentManager;
7355
5673e95ef647 Hedgeroid: Misguided attempts at getting the connection lifecycle right.
Medo <smaxein@googlemail.com>
parents: 7352
diff changeset
    43
import android.support.v4.content.LocalBroadcastManager;
7444
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents: 7358
diff changeset
    44
import android.view.Menu;
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents: 7358
diff changeset
    45
import android.view.MenuItem;
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    46
import android.view.View;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    47
import android.view.View.OnClickListener;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    48
import android.widget.Button;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    49
import android.widget.Toast;
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
    50
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    51
public class MainActivity extends FragmentActivity {
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    52
    private static final int DIALOG_NO_SDCARD = 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    53
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    54
    private LocalBroadcastManager broadcastManager;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    55
    private ProgressDialog assetsDialog;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    56
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    57
    public void onCreate(Bundle sis){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    58
        super.onCreate(sis);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    59
        setContentView(R.layout.activity_main);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    60
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    61
        broadcastManager = LocalBroadcastManager.getInstance(getApplicationContext());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    62
        Button startLocalGame = (Button)findViewById(R.id.startGame);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    63
        Button startNetGame = (Button)findViewById(R.id.joinLobby);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    64
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    65
        startLocalGame.setOnClickListener(startGameListener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    66
        startNetGame.setOnClickListener(startNetGameListener);
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    67
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    68
        if(!FileUtils.isDataPathAvailable()){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    69
            showDialog(DIALOG_NO_SDCARD);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    70
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    71
            String existingVersion = "";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    72
            try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    73
                File versionFile = new File(FileUtils.getCachePath(this), "assetsversion.txt");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    74
                existingVersion = FileUtils.readToString(new FileInputStream(versionFile));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    75
            } catch(IOException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    76
            }
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    77
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    78
            String newVersion = "";
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    79
            try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    80
                newVersion = FileUtils.readToString(getAssets().open("assetsversion.txt"));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    81
            } catch(IOException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    82
            }
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
    83
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    84
            if(!existingVersion.equals(newVersion)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    85
                DownloadAssets assetsAsyncTask = new DownloadAssets(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    86
                assetsDialog = ProgressDialog.show(this, "Please wait a moment", "Moving assets to SD card...");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    87
                assetsAsyncTask.execute();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    88
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    89
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    90
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    91
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    92
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    93
    protected void onResume() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    94
        super.onResume();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    95
        broadcastManager.registerReceiver(connectedReceiver, new IntentFilter(Netplay.ACTION_CONNECTED));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    96
        broadcastManager.registerReceiver(connectionFailedReceiver, new IntentFilter(Netplay.ACTION_DISCONNECTED));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    97
        broadcastManager.registerReceiver(passwordRequestedReceiver, new IntentFilter(Netplay.ACTION_PASSWORD_REQUESTED));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    98
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    99
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   100
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   101
    protected void onPause() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   102
        super.onPause();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   103
        broadcastManager.unregisterReceiver(connectedReceiver);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   104
        broadcastManager.unregisterReceiver(connectionFailedReceiver);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   105
        broadcastManager.unregisterReceiver(passwordRequestedReceiver);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   106
        Netplay netplay = Netplay.getAppInstance(getApplicationContext());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   107
        if(netplay.getState() == State.CONNECTING) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   108
            netplay.disconnect();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   109
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   110
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   111
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   112
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   113
    public boolean onCreateOptionsMenu(Menu menu) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   114
        super.onCreateOptionsMenu(menu);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   115
        getMenuInflater().inflate(R.menu.main_options, menu);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   116
        return true;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   117
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
   118
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   119
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   120
    public boolean onOptionsItemSelected(MenuItem item) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   121
        switch(item.getItemId()) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   122
        case R.id.download:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   123
            startActivityForResult(new Intent(this, DownloadListActivity.class), 0);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   124
            return true;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   125
        case R.id.preferences:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   126
            Toast.makeText(this, R.string.not_implemented_yet, Toast.LENGTH_SHORT).show();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   127
            return true;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   128
        case R.id.edit_weaponsets:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   129
            startActivity(new Intent(this, WeaponsetListActivity.class));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   130
            return true;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   131
        case R.id.edit_teams:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   132
            startActivity(new Intent(this, TeamListActivity.class));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   133
            return true;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   134
        default:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   135
            return super.onOptionsItemSelected(item);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   136
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   137
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   138
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   139
    public Dialog onCreateDialog(int id, Bundle args){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   140
        switch(id) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   141
        case DIALOG_NO_SDCARD:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   142
            return createNoSdcardDialog();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   143
        default:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   144
            throw new IndexOutOfBoundsException();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   145
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   146
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   147
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   148
    private Dialog createNoSdcardDialog() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   149
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   150
        builder.setTitle(R.string.sdcard_not_mounted_title);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   151
        builder.setMessage(R.string.sdcard_not_mounted);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   152
        builder.setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   153
            public void onClick(DialogInterface dialog, int which) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   154
                finish();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   155
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   156
        });
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   157
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   158
        return builder.create();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   159
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   160
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   161
    public void onAssetsDownloaded(boolean result){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   162
        if(!result){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   163
            Toast.makeText(this, R.string.download_failed, Toast.LENGTH_LONG).show();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   164
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   165
        assetsDialog.dismiss();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   166
    }
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7349
diff changeset
   167
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   168
    private final OnClickListener startGameListener = new OnClickListener(){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   169
        public void onClick(View v){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   170
            startActivity(new Intent(getApplicationContext(), LocalRoomActivity.class));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   171
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   172
    };
6456
fed715edc3ee android: check if the sdcard directory is writable, if it isn't close the app
Xeli
parents: 6350
diff changeset
   173
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   174
    private final OnClickListener startNetGameListener = new OnClickListener() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   175
        public void onClick(View v) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   176
            State state = Netplay.getAppInstance(getApplicationContext()).getState();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   177
            switch(state) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   178
            case NOT_CONNECTED:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   179
                FragmentManager fm = getSupportFragmentManager();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   180
                StartNetgameDialog startNetgameDialog = new StartNetgameDialog();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   181
                startNetgameDialog.show(fm, "start_netgame_dialog");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   182
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   183
            case CONNECTING:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   184
                onNetConnectingStarted();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   185
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   186
            default:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   187
                startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   188
                break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   189
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   190
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   191
    };
6350
41b0a9955c47 new download manager \o/
Xeli
parents: 6343
diff changeset
   192
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   193
    private BroadcastReceiver connectedReceiver = new BroadcastReceiver() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   194
        @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   195
        public void onReceive(Context context, Intent intent) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   196
            startActivity(new Intent(getApplicationContext(), LobbyActivity.class));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   197
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   198
    };
7444
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents: 7358
diff changeset
   199
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   200
    private BroadcastReceiver connectionFailedReceiver = new BroadcastReceiver() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   201
        @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   202
        public void onReceive(Context context, Intent intent) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   203
            if(intent.getBooleanExtra(Netplay.EXTRA_HAS_ERROR, true)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   204
                Toast.makeText(getApplicationContext(), intent.getStringExtra(Netplay.EXTRA_MESSAGE), Toast.LENGTH_LONG).show();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   205
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   206
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   207
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   208
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   209
    private BroadcastReceiver passwordRequestedReceiver = new BroadcastReceiver() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   210
        @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   211
        public void onReceive(Context context, Intent intent) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   212
            FragmentManager fm = getSupportFragmentManager();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   213
            PasswordDialog passwordDialog = new PasswordDialog(intent.getStringExtra(Netplay.EXTRA_PLAYERNAME));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   214
            passwordDialog.show(fm, "fragment_password_dialog");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   215
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   216
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   217
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   218
    public void onNetConnectingStarted() {
7444
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents: 7358
diff changeset
   219
        FragmentManager fm = getSupportFragmentManager();
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents: 7358
diff changeset
   220
        ConnectingDialog connectingDialog = new ConnectingDialog();
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents: 7358
diff changeset
   221
        connectingDialog.show(fm, "fragment_connecting_dialog");
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   222
    }
6047
10011f051f9c Changed package name from org.hedgewars.mobile to org.hedgewars.hedgeroid to upload it to the market
Xeli
parents:
diff changeset
   223
}