Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

version-2.0

  • Loading branch information...
commit 4f6657f4ca905f93920cc2d794f1dac31bc042dd 1 parent c0cff2a
@dashin authored
View
14 .idea/libraries/guice_2_0_no_aop.xml
@@ -0,0 +1,14 @@
+<component name="libraryTable">
+ <library name="guice-2.0-no_aop">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/libs/guice-2.0-no_aop.jar!/" />
+ <root url="jar://$PROJECT_DIR$/libs/roboguice-2.0b3.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$PROJECT_DIR$/libs/roboguice-2.0b3-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$PROJECT_DIR$/libs/roboguice-2.0b3-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
View
5 AndroidManifest.xml
@@ -4,13 +4,16 @@
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/icon">
- <activity android:name=".MainActivity"
+ <activity android:name=".activities.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+
+ <activity android:name=".activities.LearnDictionaryPlainListActivity"/>
+
<uses-library android:name="android.test.runner"/>
</application>
View
2  dropdicts.iml
@@ -33,6 +33,8 @@
</content>
<orderEntry type="jdk" jdkName="Android 2.3.3 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="guice-2.0-no_aop" level="project" />
+ <orderEntry type="library" name="android-support-v4" level="application" />
</component>
</module>
View
BIN  libs/guice-2.0-no_aop.jar
Binary file not shown
View
BIN  libs/roboguice-2.0b3-javadoc.jar
Binary file not shown
View
BIN  libs/roboguice-2.0b3-sources.jar
Binary file not shown
View
BIN  libs/roboguice-2.0b3.jar
Binary file not shown
View
92 src/uk/co/dashin/activities/LearnDictionaryPlainListActivity.java
@@ -0,0 +1,92 @@
+package uk.co.dashin.activities;
+
+import android.os.Bundle;
+import android.util.Pair;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.*;
+import roboguice.activity.RoboActivity;
+import roboguice.inject.ContentView;
+import roboguice.inject.InjectView;
+import uk.co.dashin.R;
+import uk.co.dashin.dictionary.Dictionary;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+/**
+ * User: dashin
+ * Date: 14.01.12
+ * Time: 19:13
+ */
+@ContentView(R.layout.list)
+public class LearnDictionaryPlainListActivity extends RoboActivity {
+
+ public static final String EXTRA_DICTIONARY_PATH = "EXTRA_DICTIONARY_PATH";
+
+ private Dictionary dictionary;
+ private static boolean isTranslation = false;
+ private static final int SWITCH_MENU_ITEM = 0;
+
+ @InjectView(R.id.list)
+ private ListView listView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ showDictionary();
+ }
+
+ private void showDictionary() {
+ listView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, dictionary.getWordsOrTranslations(!isTranslation)));
+ listView.setOnItemClickListener(onWordClick());
+ }
+
+ private AdapterView.OnItemClickListener onWordClick() {
+ return new AdapterView.OnItemClickListener() {
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ Pair<String,String> pair = dictionary.getWordPairs().get((int) id);
+ String translation = isTranslation ? pair.first : pair.second;
+ Toast.makeText(getApplicationContext(), translation,
+ Toast.LENGTH_SHORT).show();
+ }
+ };
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ String path = getIntent().getExtras().getString(EXTRA_DICTIONARY_PATH);
+ try {
+ dictionary = Dictionary.loadFromFile(new FileInputStream(new File(path)));
+ } catch (IOException e) {
+ throw new RuntimeException("Can;t load " + path);
+ //e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ menu.add(0, SWITCH_MENU_ITEM, 0, R.string.menu_switch_direction).setIcon(android.R.drawable.ic_menu_rotate);
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case SWITCH_MENU_ITEM:
+ isTranslation = !isTranslation;
+ showDictionary();
+ break;
+ default: break;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
View
52 src/uk/co/dashin/MainActivity.java → src/uk/co/dashin/activities/MainActivity.java
@@ -1,6 +1,7 @@
-package uk.co.dashin;
+package uk.co.dashin.activities;
import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
import android.util.Pair;
import android.view.Menu;
@@ -8,18 +9,21 @@
import android.view.View;
import android.view.Window;
import android.widget.*;
+import roboguice.activity.RoboActivity;
+import roboguice.inject.ContentView;
+import roboguice.inject.InjectView;
+import uk.co.dashin.FileDialog;
+import uk.co.dashin.R;
import uk.co.dashin.dictionary.Dictionary;
import java.io.File;
import java.io.FileInputStream;
-public class MainActivity extends Activity {
- private Dictionary dictionary;
+@ContentView(R.layout.main)
+public class MainActivity extends RoboActivity {
private static final int OPEN_DICTIONARY_MENU_ITEM = 0;
- private static final int SWITCH_MENU_ITEM = 1;
private static final String DICTIONARY_FILE_EXTENSION = ".txt";
- private static boolean isTranslation = false;
private FileDialog fileDialog;
@@ -27,9 +31,6 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.main);
- final Activity activity = this;
fileDialog = new FileDialog() {
@Override
public String getFileExtension() {
@@ -38,7 +39,7 @@ public String getFileExtension() {
@Override
public Activity getActivity() {
- return activity;
+ return MainActivity.this;
}
@Override
@@ -46,56 +47,37 @@ public void openFile(String chosenFile) {
openDictionary(chosenFile);
}
};
+ //lets start form this
+ //fileDialog.openDirectory();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, OPEN_DICTIONARY_MENU_ITEM, 0, R.string.menu_open_dictionary).setIcon(android.R.drawable.ic_menu_add);
- menu.add(0, SWITCH_MENU_ITEM, 1, R.string.menu_switch_direction).setIcon(android.R.drawable.ic_menu_rotate);
return true;
}
- private AdapterView.OnItemClickListener onWordClick() {
- return new AdapterView.OnItemClickListener() {
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Pair<String,String> pair = dictionary.getWordPairs().get((int) id);
- String translation = isTranslation ? pair.first : pair.second;
- Toast.makeText(getApplicationContext(), translation,
- Toast.LENGTH_SHORT).show();
- }
- };
- }
-
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case OPEN_DICTIONARY_MENU_ITEM:
fileDialog.openDirectory();
break;
- case SWITCH_MENU_ITEM:
- isTranslation = !isTranslation;
- if (dictionary != null) {
- showDictionary(dictionary);
- }
- break;
default: break;
}
return super.onOptionsItemSelected(item);
}
- private void showDictionary(Dictionary dictionary) {
- setContentView(R.layout.list);
- ListView listView = (ListView) findViewById(R.id.list);
-
- listView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, dictionary.getWordsOrTranslations(!isTranslation)));
- listView.setOnItemClickListener(onWordClick());
+ private void showDictionary(String dictPath) {
+ startActivity(new Intent(getApplication(), LearnDictionaryPlainListActivity.class)
+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
+ .putExtra(LearnDictionaryPlainListActivity.EXTRA_DICTIONARY_PATH, dictPath));
}
private void openDictionary(String path) {
try {
- dictionary = Dictionary.loadFromFile(new FileInputStream(new File(path)));
- showDictionary(dictionary);
+ showDictionary(path);
} catch (Exception e) {
((TextView) findViewById(R.id.word)).setText(e.getMessage());
}
Please sign in to comment.
Something went wrong with that request. Please try again.