Permalink
Browse files

New version 1.0.1 with token export functionality.

  • Loading branch information...
1 parent 14edfb8 commit b326e6423f5b192e82ced363d9d7ccbf9f029b54 @blitz blitz committed Jul 12, 2010
Showing with 73 additions and 20 deletions.
  1. +7 −9 AndroidManifest.xml
  2. +16 −3 res/menu/options_menu.xml
  3. +5 −4 res/values/strings.xml
  4. +45 −4 src/de/c3d2/blitz/moleflap/MoleflapClient.java
View
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.c3d2.blitz.moleflap"
- android:versionCode="1"
- android:versionName="1.0">
+ android:versionCode="2"
+ android:versionName="1.0.1">
+
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
<activity android:label="@string/app_name" android:name="MoleflapClient">
@@ -11,14 +12,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
- <activity android:label="@string/set_preferences" android:name="Preferences">
-<intent-filter><action android:name="android.settings.SETTINGS"></action>
-<category android:name="android.intent.category.PREFERENCE"></category>
+ <activity android:label="@string/set_preferences" android:name="Preferences" />
+ </application>
-</intent-filter>
-</activity>
-</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-</manifest>
+</manifest>
View
@@ -1,8 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
-<item android:title="Settings" android:id="@+id/settings" android:icon="@android:drawable/ic_menu_preferences"></item>
-<item android:title="Quit" android:id="@+id/quit" android:icon="@android:drawable/ic_menu_close_clear_cancel"></item>
-<item android:id="@+id/import_token" android:title="Import Token" android:icon="@android:drawable/ic_menu_add"></item>
+ <item android:id="@+id/import_token"
+ android:title="Import Token"
+ android:icon="@android:drawable/ic_menu_add"/>
+
+ <item android:id="@+id/export_token"
+ android:title="Export Token"
+ android:icon="@android:drawable/ic_menu_save"/>
+
+ <item android:title="Settings"
+ android:id="@+id/settings"
+ android:icon="@android:drawable/ic_menu_preferences"/>
+
+ <item android:title="Quit"
+ android:id="@+id/quit"
+ android:icon="@android:drawable/ic_menu_close_clear_cancel"/>
+
</menu>
View
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="set_preferences">Preferences</string>
- <string name="hello">This is your friendly <a href="https://wiki.c3d2.de/HQ_Zugangssystem">door opener</a>.\n\n
- Blame bl!tz (js@alien8.de) for bugs.
-
+ <string name="hello">Open the gates to the HQ. Blame bl!tz
+ (js@alien8.de) for bugs.\n\nRemember that with great power comes
+ great responsibility. The HQ is a project that is run for you by
+ you.\n\nWhat is your contribution?
</string>
- <string name="app_name">MoleflapClient</string>
+ <string name="app_name">Moleflap Client</string>
</resources>
@@ -1,9 +1,11 @@
package de.c3d2.blitz.moleflap;
import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
@@ -80,14 +82,51 @@ private void checkDefaults() {
e.commit();
}
+ private File tokenFile()
+ {
+ return new File(Environment.getExternalStorageDirectory(), "token.txt");
+ }
+
+ private void exportTokenFile() {
+ SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+ String token = p.getString("token", null);
+
+ if (token == null) {
+ Toast.makeText(getBaseContext(), "You have to import a token, before you can export it.",
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+
+ String state = Environment.getExternalStorageState();
+
+ if (state.equals(Environment.MEDIA_MOUNTED)) {
+ try {
+ FileWriter fw = new FileWriter(tokenFile());
+ BufferedWriter out = new BufferedWriter(fw);
+ out.write(token);
+ out.newLine();
+ out.close();
+ fw.close();
+
+ Toast.makeText(getBaseContext(), "Token exported as token.txt.",
+ Toast.LENGTH_LONG).show();
+ return;
+ } catch (IOException e) {
+ Log.e(TAG, "IO Exception during token export: " + e );
+ }
+ }
+
+ Toast.makeText(getBaseContext(), "Could not write token file.",
+ Toast.LENGTH_LONG).show();
+ }
+
private void checkTokenFile() {
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED) ||
state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
- File path = Environment.getExternalStorageDirectory();
- File tokenfile = new File(path, "token.txt");
+ File tokenfile = tokenFile();
if (tokenfile.exists() && tokenfile.canRead()) {
try {
FileReader fr = new FileReader(tokenfile);
@@ -135,13 +174,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
case R.id.settings:
- Intent intent = new Intent();
- intent.setClassName("de.c3d2.blitz.moleflap", "de.c3d2.blitz.moleflap.Preferences");
+ Intent intent = new Intent(this, Preferences.class);
startActivity(intent);
return true;
case R.id.import_token:
checkTokenFile();
return true;
+ case R.id.export_token:
+ exportTokenFile();
+ return true;
default:
return super.onOptionsItemSelected(item);
}

0 comments on commit b326e64

Please sign in to comment.