Search in sources :

Example 11 with Note

use of com.ichi2.libanki.Note in project Anki-Android by Ramblurr.

the class CardEditor method setNote.

private void setNote(Note note) {
    try {
        if (note == null) {
            if (mCol.getDecks().isDyn(mCurrentDid)) {
                /*
                     * If the deck in mCurrentDid is a filtered (dynamic) deck, then we can't create
                     * cards in it, and we set mCurrentDid to the Default deck. Otherwise, we keep
                     * the number that had been selected previously in the activity.
                     */
                mCurrentDid = 1;
            }
            JSONObject model = mCol.getModels().current();
            mEditorNote = new Note(mCol, model);
            mEditorNote.model().put("did", mCurrentDid);
            mModelButton.setText(getResources().getString(R.string.CardEditorModel, model.getString("name")));
            JSONArray tags = model.getJSONArray("tags");
            for (int i = 0; i < tags.length(); i++) {
                mEditorNote.addTag(tags.getString(i));
            }
        } else {
            mEditorNote = note;
            mCurrentDid = mCurrentEditedCard.getDid();
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    mCurrentTags = mEditorNote.getTags();
    updateDeck();
    updateTags();
    populateEditFields();
    swapText(true);
}
Also used : JSONObject(org.json.JSONObject) Note(com.ichi2.libanki.Note) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 12 with Note

use of com.ichi2.libanki.Note in project Anki-Android by Ramblurr.

the class CardBrowser method updateCardInList.

private void updateCardInList(Card card, String updatedCardTags) {
    Note note = card.note();
    int pos;
    for (Card c : note.cards()) {
        pos = getPosition(mCards, c.getId());
        if (pos < 0 || pos >= mCards.size()) {
            continue;
        }
        if (updatedCardTags != null) {
            mCards.get(pos).put("tags", updatedCardTags);
        }
        String sfld = note.getSFld();
        mCards.get(pos).put("sfld", sfld);
        if (mWholeCollection) {
            String deckName;
            try {
                deckName = mCol.getDecks().get(card.getDid()).getString("name");
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
            mCards.get(pos).put("deck", deckName);
        }
        String flags = Integer.toString((c.getQueue() == -1 ? 1 : 0) + (note.hasTag("marked") ? 2 : 0));
        mCards.get(pos).put("flags", flags);
    }
    updateList();
}
Also used : Note(com.ichi2.libanki.Note) JSONException(org.json.JSONException) Card(com.ichi2.libanki.Card)

Example 13 with Note

use of com.ichi2.libanki.Note in project Anki-Android by Ramblurr.

the class DeckPicker method showStartupScreensAndDialogs.

private void showStartupScreensAndDialogs(SharedPreferences preferences, int skip) {
    if (skip < 1 && preferences.getLong("lastTimeOpened", 0) == 0) {
        Intent infoIntent = new Intent(this, Info.class);
        infoIntent.putExtra(Info.TYPE_EXTRA, Info.TYPE_WELCOME);
        startActivityForResult(infoIntent, SHOW_INFO_WELCOME);
        if (skip != 0 && AnkiDroidApp.SDK_VERSION > 4) {
            ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.LEFT);
        }
    } else if (skip < 2 && !preferences.getString("lastVersion", "").equals(AnkiDroidApp.getPkgVersionName())) {
        preferences.edit().putBoolean("showBroadcastMessageToday", true).commit();
        Intent infoIntent = new Intent(this, Info.class);
        infoIntent.putExtra(Info.TYPE_EXTRA, Info.TYPE_NEW_VERSION);
        startActivityForResult(infoIntent, SHOW_INFO_NEW_VERSION);
        if (skip != 0 && AnkiDroidApp.SDK_VERSION > 4) {
            ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.LEFT);
        }
    } else if (skip < 3 && upgradeNeeded()) {
        // Note that the "upgrade needed" refers to upgrading Anki 1.x decks, not to newer
        // versions of AnkiDroid.
        AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putInt("lastUpgradeVersion", AnkiDroidApp.getPkgVersionCode()).commit();
        showUpgradeScreen(skip != 0, Info.UPGRADE_SCREEN_BASIC1);
    } else if (skip < 4 && hasErrorFiles()) {
        Intent i = new Intent(this, Feedback.class);
        startActivityForResult(i, REPORT_ERROR);
        if (skip != 0 && AnkiDroidApp.SDK_VERSION > 4) {
            ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.LEFT);
        }
    } else if (!AnkiDroidApp.isSdCardMounted()) {
        showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
    } else if (!BackupManager.enoughDiscSpace(mPrefDeckPath)) {
        // && !preferences.getBoolean("dontShowLowMemory",
        // false)) {
        showDialog(DIALOG_NO_SPACE_LEFT);
    } else if (preferences.getBoolean("noSpaceLeft", false)) {
        showDialog(DIALOG_BACKUP_NO_SPACE_LEFT);
        preferences.edit().putBoolean("noSpaceLeft", false).commit();
    } else if (mImportPath != null && AnkiDroidApp.colIsOpen()) {
        showDialog(DIALOG_IMPORT);
    } else {
        // AnkiDroid is being updated and a collection already exists. We check if we are upgrading
        // to a version that contains additions to the database integrity check routine that we would
        // like to run on all collections. A missing version number is assumed to be a fresh
        // installation of AnkiDroid and we don't run the check.
        int current = AnkiDroidApp.getPkgVersionCode();
        // a non-final variable, for intermediate calculations
        int previousTemp;
        if (!preferences.contains("lastUpgradeVersion")) {
            // Fresh install
            previousTemp = current;
        } else {
            try {
                previousTemp = preferences.getInt("lastUpgradeVersion", current);
            } catch (ClassCastException e) {
                // Previous versions stored this as a string.
                String s = preferences.getString("lastUpgradeVersion", "");
                // check.
                if (s.equals("2.0.2")) {
                    previousTemp = 40;
                } else {
                    previousTemp = 0;
                }
            }
        }
        final int previous = previousTemp;
        preferences.edit().putInt("lastUpgradeVersion", current).commit();
        if (previous < AnkiDroidApp.CHECK_DB_AT_VERSION || previous < AnkiDroidApp.CHECK_PREFERENCES_AT_VERSION) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_OPEN_COLLECTION, new Listener() {

                @Override
                public void onPostExecute(DeckTask task, TaskData result) {
                    mOpenCollectionHandler.onPostExecute(result);
                    if (previous < AnkiDroidApp.CHECK_DB_AT_VERSION) {
                        integrityCheck();
                    }
                    if (previous < AnkiDroidApp.CHECK_PREFERENCES_AT_VERSION) {
                        upgradePreferences(previous);
                    }
                }

                @Override
                public void onPreExecute(DeckTask task) {
                }

                @Override
                public void onProgressUpdate(DeckTask task, TaskData... values) {
                }
            }, new DeckTask.TaskData(AnkiDroidApp.getCollectionPath()));
        } else {
            loadCollection();
        }
    }
}
Also used : OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) OnCancelListener(android.content.DialogInterface.OnCancelListener) SimpleOnGestureListener(android.view.GestureDetector.SimpleOnGestureListener) Listener(com.ichi2.async.DeckTask.Listener) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) ActivityInfo(android.content.pm.ActivityInfo) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) DeckTask(com.ichi2.async.DeckTask) TaskData(com.ichi2.async.DeckTask.TaskData)

Example 14 with Note

use of com.ichi2.libanki.Note in project Anki-Android by Ramblurr.

the class Reviewer method setInterface.

private void setInterface() {
    if (mCurrentCard == null) {
        return;
    }
    if (mSimpleInterface) {
        Note note = mCurrentCard.note();
        mCurrentSimpleInterface = true;
        for (String s : mSimpleInterfaceExcludeTags) {
            if (note.hasTag(s)) {
                mCurrentSimpleInterface = false;
                break;
            }
        }
    }
    if (mCurrentSimpleInterface) {
        if (mSimpleCard == null) {
            mSimpleCard = new ScrollTextView(this);
            Themes.setRegularFont(mSimpleCard);
            mSimpleCard.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics()) * mDisplayFontSize / 100);
            mSimpleCard.setGravity(Gravity.CENTER);
            try {
                mSetTextIsSelectable = TextView.class.getMethod("setTextIsSelectable", boolean.class);
            } catch (Throwable e) {
                Log.i(AnkiDroidApp.TAG, "mSetTextIsSelectable could not be found due to a too low Android version (< 3.0)");
                mSetTextIsSelectable = null;
            }
            if (mSetTextIsSelectable != null) {
                try {
                    mSetTextIsSelectable.invoke(mSimpleCard, true);
                } catch (Exception e) {
                    Log.e(AnkiDroidApp.TAG, e.toString());
                }
            }
            mSimpleCard.setClickable(true);
            mCardFrame.addView(mSimpleCard);
            mSimpleCard.setBackgroundColor(mCurrentBackgroundColor);
            mSimpleCard.setTextColor(mForegroundColor);
        }
        if (mSimpleCard.getVisibility() != View.VISIBLE || (mCard != null && mCard.getVisibility() == View.VISIBLE)) {
            mSimpleCard.setVisibility(View.VISIBLE);
            mCard.setVisibility(View.GONE);
        }
    } else {
        if (mCard == null) {
            mCard = createWebView();
            mCardFrame.addView(mCard);
            if (!mUseQuickUpdate) {
                mNextCard = createWebView();
                mNextCard.setVisibility(View.GONE);
                mCardFrame.addView(mNextCard, 0);
                mCard.setBackgroundColor(mCurrentBackgroundColor);
            }
        }
        if (mCard.getVisibility() != View.VISIBLE || (mSimpleCard != null && mSimpleCard.getVisibility() == View.VISIBLE)) {
            mSimpleCard.setVisibility(View.GONE);
            mCard.setVisibility(View.VISIBLE);
        }
    }
}
Also used : Note(com.ichi2.libanki.Note) TextView(android.widget.TextView) SpannedString(android.text.SpannedString) SpannableString(android.text.SpannableString) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 15 with Note

use of com.ichi2.libanki.Note in project Anki-Android by Ramblurr.

the class NoteService method updateMultimediaNoteFromJsonNote.

public static void updateMultimediaNoteFromJsonNote(final Note editorNoteSrc, final IMultimediaEditableNote noteDst) {
    if (noteDst instanceof MultimediaEditableNote) {
        MultimediaEditableNote mmNote = (MultimediaEditableNote) noteDst;
        String[] values = editorNoteSrc.getFields();
        for (int i = 0; i < values.length; i++) {
            String value = values[i];
            IField field = null;
            if (value.startsWith("<img")) {
                field = new ImageField();
            } else if (value.startsWith("[sound:")) {
                field = new AudioField();
            } else {
                field = new TextField();
            }
            field.setFormattedString(value);
            mmNote.setField(i, field);
        }
        mmNote.setModelId(editorNoteSrc.getMid());
    // TODO: set current id of the note as well
    }
}
Also used : AudioField(com.ichi2.anki.multimediacard.fields.AudioField) ImageField(com.ichi2.anki.multimediacard.fields.ImageField) MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote) TextField(com.ichi2.anki.multimediacard.fields.TextField) IField(com.ichi2.anki.multimediacard.fields.IField)

Aggregations

Note (com.ichi2.libanki.Note)11 JSONException (org.json.JSONException)11 JSONObject (org.json.JSONObject)8 IMultimediaEditableNote (com.ichi2.anki.multimediacard.IMultimediaEditableNote)7 MultimediaEditableNote (com.ichi2.anki.multimediacard.impl.MultimediaEditableNote)6 Collection (com.ichi2.libanki.Collection)6 TextField (com.ichi2.anki.multimediacard.fields.TextField)4 Card (com.ichi2.libanki.Card)4 AnkiDb (com.ichi2.anki.AnkiDb)3 IField (com.ichi2.anki.multimediacard.fields.IField)3 ImageField (com.ichi2.anki.multimediacard.fields.ImageField)3 Sched (com.ichi2.libanki.Sched)3 IOException (java.io.IOException)3 JSONArray (org.json.JSONArray)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 Resources (android.content.res.Resources)2 SpannableString (android.text.SpannableString)2 SpannedString (android.text.SpannedString)2 TextView (android.widget.TextView)2