Skip to content

Commit

Permalink
New version 1.0.1 with token export functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
blitz committed Jul 12, 2010
1 parent 14edfb8 commit b326e64
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 20 deletions.
16 changes: 7 additions & 9 deletions AndroidManifest.xml
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.c3d2.blitz.moleflap" package="de.c3d2.blitz.moleflap"
android:versionCode="1" android:versionCode="2"
android:versionName="1.0"> android:versionName="1.0.1">

<application android:icon="@drawable/icon" android:label="@string/app_name" <application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true"> android:debuggable="true">
<activity android:label="@string/app_name" android:name="MoleflapClient"> <activity android:label="@string/app_name" android:name="MoleflapClient">
Expand All @@ -11,14 +12,11 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:label="@string/set_preferences" android:name="Preferences"> <activity android:label="@string/set_preferences" android:name="Preferences" />
<intent-filter><action android:name="android.settings.SETTINGS"></action> </application>
<category android:name="android.intent.category.PREFERENCE"></category>


</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" /> <uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


</manifest> </manifest>
19 changes: 16 additions & 3 deletions res/menu/options_menu.xml
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,21 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu <menu
xmlns:android="http://schemas.android.com/apk/res/android"> 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> </menu>
9 changes: 5 additions & 4 deletions res/values/strings.xml
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="set_preferences">Preferences</string> <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 <string name="hello">Open the gates to the HQ. Blame bl!tz
Blame bl!tz (js@alien8.de) for bugs. (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>
<string name="app_name">MoleflapClient</string> <string name="app_name">Moleflap Client</string>
</resources> </resources>
49 changes: 45 additions & 4 deletions src/de/c3d2/blitz/moleflap/MoleflapClient.java
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.c3d2.blitz.moleflap; package de.c3d2.blitz.moleflap;


import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
Expand Down Expand Up @@ -80,14 +82,51 @@ private void checkDefaults() {
e.commit(); 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() { private void checkTokenFile() {
SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getBaseContext());


String state = Environment.getExternalStorageState(); String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED) || if (state.equals(Environment.MEDIA_MOUNTED) ||
state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
File path = Environment.getExternalStorageDirectory(); File tokenfile = tokenFile();
File tokenfile = new File(path, "token.txt");
if (tokenfile.exists() && tokenfile.canRead()) { if (tokenfile.exists() && tokenfile.canRead()) {
try { try {
FileReader fr = new FileReader(tokenfile); FileReader fr = new FileReader(tokenfile);
Expand Down Expand Up @@ -135,13 +174,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
finish(); finish();
return true; return true;
case R.id.settings: case R.id.settings:
Intent intent = new Intent(); Intent intent = new Intent(this, Preferences.class);
intent.setClassName("de.c3d2.blitz.moleflap", "de.c3d2.blitz.moleflap.Preferences");
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.import_token: case R.id.import_token:
checkTokenFile(); checkTokenFile();
return true; return true;
case R.id.export_token:
exportTokenFile();
return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
Expand Down

0 comments on commit b326e64

Please sign in to comment.