0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 20:03:05 +02:00

Fixed the DeckPicker bug where it crashed when there was some file ending in '.anki' that was not a real anki file.

This commit is contained in:
Eduard Zamora Suriñach 2009-11-03 13:08:43 +01:00
parent b554dd2efe
commit 008ce58291
4 changed files with 71 additions and 11 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ichi2.anki"
android:versionName="0.2" android:versionCode="4">
android:versionName="0.3" android:versionCode="6">
<application android:label="@string/app_name" android:icon="@drawable/anki" android:debuggable="false">
<activity android:name=".Ankidroid" android:label="@string/app_name" android:configChanges="orientation"
>

View File

@ -11,8 +11,10 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
@ -56,7 +58,7 @@ public class Ankidroid extends Activity implements Runnable
/**
* Tag for logging messages
*/
private static String TAG = "Ankidroid";
private static final String TAG = "Ankidroid";
/**
* Menus
@ -86,6 +88,8 @@ public class Ankidroid extends Activity implements Runnable
private boolean layoutInitialized;
private BroadcastReceiver mUnmountReceiver = null;
private boolean deckSelected;
private String deckFilename;
@ -198,6 +202,8 @@ public class Ankidroid extends Activity implements Runnable
requestWindowFeature(Window.FEATURE_NO_TITLE);
registerExternalStorageListener();
Bundle extras = getIntent().getExtras();
initResourceValues();
@ -428,6 +434,7 @@ public class Ankidroid extends Activity implements Runnable
{
outState.putString("deckFilename", deckFilename);
}
Log.i(TAG, "onSaveInstanceState - Ending");
}
@Override
@ -703,4 +710,38 @@ public class Ankidroid extends Activity implements Runnable
private boolean isSdCardMounted() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
/**
* Registers an intent to listen for ACTION_MEDIA_EJECT notifications.
* The intent will call closeExternalStorageFiles() if the external media
* is going to be ejected, so applications can clean up any files they have open.
*/
public void registerExternalStorageListener() {
/*if (mUnmountReceiver == null) {
mUnmountReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
//saveQueue(true);
//mOneShot = true; // This makes us not save the state again later,
// which would be wrong because the song ids and
// card id might not match.
//closeExternalStorageFiles(intent.getData().getPath());
} else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
///mMediaMountedCount++;
//mCardId = FileUtils.getFatVolumeId(intent.getData().getPath());
//reloadQueue();
//notifyChange(QUEUE_CHANGED);
//notifyChange(META_CHANGED);
}
}
};
IntentFilter iFilter = new IntentFilter();
iFilter.addAction(Intent.ACTION_MEDIA_EJECT);
iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
iFilter.addDataScheme("file");
registerReceiver(mUnmountReceiver, iFilter);
}*/
}
}

View File

@ -332,6 +332,7 @@ public class Deck
public static float getLastModified(String deckPath)
{
float value;
//Log.i(TAG, "Deck - getLastModified from deck = " + deckPath);
AnkiDb.openDatabase(deckPath);
Cursor cursor = AnkiDb.database.rawQuery("SELECT modified" + " FROM decks" + " LIMIT 1", null);

View File

@ -34,6 +34,8 @@ import android.widget.SimpleAdapter;
public class DeckPicker extends Activity implements Runnable
{
private static final String TAG = "Ankidroid";
private DeckPicker mSelf;
private SimpleAdapter mDeckListAdapter;
@ -64,6 +66,7 @@ public class DeckPicker extends Activity implements Runnable
@Override
public void onCreate(Bundle savedInstanceState) throws SQLException
{
Log.i(TAG, "DeckPicker - onCreate");
super.onCreate(savedInstanceState);
mSelf = this;
String deckPath = getIntent().getStringExtra("com.ichi2.anki.Ankidroid.DeckPath");
@ -98,12 +101,16 @@ public class DeckPicker extends Activity implements Runnable
public void onPause()
{
Log.i(TAG, "DeckPicker - onPause");
super.onPause();
waitForDeckLoaderThread();
}
private void populateDeckList(String location)
{
Log.i(TAG, "DeckPicker - populateDeckList");
Resources res = getResources();
int len = 0;
File[] fileList;
@ -119,10 +126,15 @@ public class DeckPicker extends Activity implements Runnable
mFileList = fileList;
if (len > 0 && fileList != null)
{
Log.i(TAG, "DeckPicker - populateDeckList, number of anki files = " + len);
for (int i = 0; i < len; i++)
{
String absPath = fileList[i].getAbsolutePath();
Log.i(TAG, "DeckPicker - populateDeckList, file " + i + " :" + fileList[i].getName());
try
{
HashMap<String, String> data = new HashMap<String, String>();
data.put("name", fileList[i].getName().replaceAll(".anki", ""));
data.put("due", res.getString(R.string.deckpicker_loaddeck));
@ -132,6 +144,11 @@ public class DeckPicker extends Activity implements Runnable
data.put("showProgress", "true");
tree.add(data);
} catch (SQLException e)
{
Log.w(TAG, "DeckPicker - populateDeckList, File " + fileList[i].getName() + " is not a real anki file");
}
}
Thread thread = new Thread(this);
@ -161,6 +178,7 @@ public class DeckPicker extends Activity implements Runnable
mDeckList.clear();
mDeckList.addAll(tree);
mDeckListView.clearChoices();
Log.i(TAG, "DeckPicker - populateDeckList, Ending");
}
private static final class AnkiFilter implements FileFilter