Commit 3b5e8ec6 authored by Rémi BERTHO's avatar Rémi BERTHO

Add open file

parent e33f44d0
......@@ -42,6 +42,7 @@ local.properties
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/vcs.xml
.idea/gradle.xml
*.iml
# OS-specific files
......
[submodule "app/libs/aFileDialog"]
path = app/libs/aFileDialog
url = https://github.com/jfmdev/aFileDialog.git
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="/media/Data/Documents/Programmes/Csuper/Csuper-Android" />
<option value="/media/Data/Documents/Programmes/Csuper/Csuper-Android/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
......@@ -22,5 +22,6 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile files('libs/jdom-2.0.6.jar')
compile project(':aFileDialog')
}
Subproject commit 4c2c0e1d0f07779ee7eae138fc558fa593fc35ca
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.dalan.csuper">
xmlns:tools="http://schemas.android.com/tools"
package="org.dalan.csuper">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
tools:replace="android:icon,android:label"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
......@@ -24,6 +26,7 @@
android:label="@string/About"
android:parentActivityName=".Activity.MainActivity">
</activity>
<activity android:name="ar.com.daidalos.afiledialog.FileChooserActivity" />
</application>
</manifest>
......@@ -26,9 +26,9 @@
package org.dalan.csuper.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
......@@ -41,16 +41,40 @@ import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import org.dalan.csuper.Core.Exception.FileError;
import org.dalan.csuper.Core.Exception.XmlError;
import org.dalan.csuper.Core.Game;
import org.dalan.csuper.Core.Utility.I18n;
import org.dalan.csuper.R;
import java.io.File;
import ar.com.daidalos.afiledialog.FileChooserDialog;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// Attributes /////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
/**
* The game
*/
private Game game_;
/**
* The file
*/
private File file_;
private TextView text;
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// Creation functions /////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Called when the application is launch
* @param savedInstanceState
......@@ -67,7 +91,7 @@ public class MainActivity extends AppCompatActivity
I18n.setContext(this);
// Floatting button
// Floating button
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -92,26 +116,7 @@ public class MainActivity extends AppCompatActivity
//
// Test
//
final TextView text = (TextView) findViewById(R.id.test);
String filename1 = Environment.getExternalStorageDirectory().getPath() + "/testé.csu";
Game g = null;
try {
g = new Game(filename1);
}
catch (XmlError e){
e.printStackTrace();
text.setText(e.getMessage());
}
String filename2 = Environment.getExternalStorageDirectory().getPath() + "/testé2.csu";
try {
g.writeToFile(filename2);
text.setText(g.toString());
} catch (Exception fileError) {
fileError.printStackTrace();
text.setText(fileError.getMessage());
}
text = (TextView) findViewById(R.id.test);
}
/**
......@@ -139,6 +144,10 @@ public class MainActivity extends AppCompatActivity
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// Menus //////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
/**
* The response of the main menu
* @param item the selected item
......@@ -170,11 +179,43 @@ public class MainActivity extends AppCompatActivity
// Handle navigation view item clicks here.
int id = item.getItemId();
// New
if (id == R.id.new_file) {
} else if (id == R.id.open_file) {
}
// Open
else if (id == R.id.open_file) {
FileChooserDialog dialog = new FileChooserDialog(this);
dialog.setShowCancelButton(true);
dialog.setFilter(".*csu");
dialog.show();
dialog.addListener(new FileChooserDialog.OnFileSelectedListener() {
public void onFileSelected(Dialog source, File file) {
source.hide();
try {
setGame(new Game(file));
setFile(file);
} catch (XmlError e) {
Toast toast = Toast.makeText(source.getContext(),
I18n.tr(R.string.main_activity_open_error,file.getName()),
Toast.LENGTH_LONG);
toast.show();
}
}
public void onFileSelected(Dialog source, File folder, String name) {
}
});
}
} else if (id == R.id.about) {
// Save
else if (id == R.id.save_file) {
}
// About
else if (id == R.id.about) {
Intent intent = new Intent(MainActivity.this, AboutActivity.class);
startActivity(intent);
}
......@@ -183,4 +224,45 @@ public class MainActivity extends AppCompatActivity
drawer.closeDrawer(GravityCompat.START);
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// Functions //////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// Setters and getters ////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
/**
* Return the game
* @return the game
*/
public Game getGame(){
return game_;
}
/**
* Return the file
* @return the file
*/
public File getFile(){
return file_;
}
/**
* Set the game
* @param game the game
*/
public void setGame(Game game){
game_ = game;
text.setText(game_.toString());
}
/**
* Set the file
* @param file the file
*/
public void setFile(File file){
file_ = file;
}
}
......@@ -36,4 +36,5 @@
<string name="game_turn">Tour %1$d |</string>
<string name="game_total">Total |</string>
<string name="game_ranking">Classmt |</string>
<string name="main_activity_open_error">Erreur lors de l\'ouverture de %1$s.</string>
</resources>
\ No newline at end of file
......@@ -37,4 +37,5 @@
<string name="game_turn">Turn %1$d |</string>
<string name="game_total">Total |</string>
<string name="game_ranking">Ranking |</string>
<string name="main_activity_open_error">Error when opening %1$s.</string>
</resources>
include ':app'
include ':app', ':aFileDialog'
project(':aFileDialog').projectDir = new File('app/libs/aFileDialog/library/app')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment