Search in sources :

Example 11 with Result

use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result in project Anki-Android by Ramblurr.

the class Info method upgradeCancelled.

public void upgradeCancelled() {
    StyledDialog.Builder builder = new StyledDialog.Builder(Info.this);
    builder.setTitle(getString(R.string.upgrade_deck_cancelled_title));
    builder.setIcon(R.drawable.ic_dialog_alert);
    builder.setMessage(getString(R.string.upgrade_deck_cancelled_description));
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            Intent result = new Intent();
            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC1);
            setResult(RESULT_OK, result);
            finishWithAnimation();
        }
    });
    builder.show();
}
Also used : DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) Intent(android.content.Intent)

Example 12 with Result

use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result in project Anki-Android by Ramblurr.

the class CardEditor method reloadCollection.

private void reloadCollection(Bundle savedInstanceState) {
    mSavedInstanceState = savedInstanceState;
    DeckTask.launchDeckTask(DeckTask.TASK_TYPE_OPEN_COLLECTION, new DeckTask.TaskListener() {

        @Override
        public void onPostExecute(DeckTask.TaskData result) {
            if (mOpenCollectionDialog.isShowing()) {
                try {
                    mOpenCollectionDialog.dismiss();
                } catch (Exception e) {
                    Log.e(AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
                }
            }
            mCol = result.getCollection();
            if (mCol == null) {
                finish();
            } else {
                onCreate(mSavedInstanceState);
            }
        }

        @Override
        public void onPreExecute() {
            mOpenCollectionDialog = StyledOpenCollectionDialog.show(CardEditor.this, getResources().getString(R.string.open_collection), new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface arg0) {
                    finish();
                }
            });
        }

        @Override
        public void onProgressUpdate(DeckTask.TaskData... values) {
        }
    }, new DeckTask.TaskData(AnkiDroidApp.getCurrentAnkiDroidDirectory() + AnkiDroidApp.COLLECTION_PATH));
}
Also used : DialogInterface(android.content.DialogInterface) DeckTask(com.ichi2.async.DeckTask) JSONException(org.json.JSONException) NotFoundException(android.content.res.Resources.NotFoundException) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 13 with Result

use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result in project Anki-Android by Ramblurr.

the class Info method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(AnkiDroidApp.TAG, "Info - onCreate()");
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);
    Resources res = getResources();
    mType = getIntent().getIntExtra(TYPE_EXTRA, TYPE_ABOUT);
    setTitle(getTitleString());
    setContentView(R.layout.info);
    mWebView = (WebView) findViewById(R.id.info);
    mWebView.setBackgroundColor(res.getColor(Themes.getBackgroundColor()));
    Themes.setWallpaper((View) mWebView.getParent().getParent().getParent());
    TextView termsAndConditionsView = (TextView) findViewById(R.id.info_terms_and_conditions);
    termsAndConditionsView.setMovementMethod(LinkMovementMethod.getInstance());
    Button continueButton = (Button) findViewById(R.id.info_continue);
    continueButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (mType == TYPE_ABOUT) {
                Info.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.ichi2.anki")));
                return;
            }
            setResult(RESULT_OK);
            switch(mType) {
                case TYPE_WELCOME:
                    AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit().putLong("lastTimeOpened", System.currentTimeMillis()).commit();
                    break;
                case TYPE_NEW_VERSION:
                    AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit().putString("lastVersion", AnkiDroidApp.getPkgVersionName()).commit();
                    break;
                case TYPE_UPGRADE_DECKS:
                    break;
            }
            finishWithAnimation();
        }
    });
    StringBuilder sb = new StringBuilder();
    switch(mType) {
        case TYPE_ABOUT:
            String[] content = res.getStringArray(R.array.about_content);
            sb.append("<html><body text=\"#000000\" link=\"#E37068\" alink=\"#E37068\" vlink=\"#E37068\">");
            sb.append(String.format(content[0], res.getString(R.string.app_name), res.getString(R.string.link_anki))).append("<br/><br/>");
            sb.append(String.format(content[1], res.getString(R.string.link_issue_tracker), res.getString(R.string.link_wiki), res.getString(R.string.link_forum))).append("<br/><br/>");
            sb.append(String.format(content[2], res.getString(R.string.link_wikipedia_open_source), res.getString(R.string.link_contribution), res.getString(R.string.link_contribution_contributors))).append(" ");
            sb.append(String.format(content[3], res.getString(R.string.link_translation), res.getString(R.string.link_donation))).append("<br/><br/>");
            sb.append(String.format(content[4], res.getString(R.string.licence_wiki), res.getString(R.string.link_source))).append("<br/><br/>");
            sb.append("</body></html>");
            mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null);
            ((Button) findViewById(R.id.info_continue)).setText(res.getString(R.string.info_rate));
            break;
        case TYPE_WELCOME:
            // title
            sb.append("<html><body text=\"#000000\" link=\"#E37068\" alink=\"#E37068\" vlink=\"#E37068\">");
            sb.append("<big><b>");
            sb.append(res.getString(R.string.studyoptions_welcome_title));
            sb.append("</big></b><br><br>");
            // message
            sb.append(res.getString(R.string.welcome_message).replace("\n", "<br>"));
            sb.append("</body></html>");
            mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null);
            // add tutorial button
            Button tutBut = (Button) findViewById(R.id.info_tutorial);
            tutBut.setVisibility(View.VISIBLE);
            tutBut.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    setResult(RESULT_OK);
                    Editor edit = AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit();
                    edit.putLong("lastTimeOpened", System.currentTimeMillis());
                    edit.putBoolean("createTutorial", true);
                    edit.commit();
                    finishWithAnimation();
                }
            });
            break;
        case TYPE_NEW_VERSION:
            sb.append(res.getString(R.string.new_version_message));
            sb.append("<ul>");
            String[] features = res.getStringArray(R.array.new_version_features);
            for (int i = 0; i < features.length; i++) {
                sb.append("<li>");
                sb.append(features[i]);
                sb.append("</li>");
            }
            sb.append("</ul>");
            sb.append("</body></html>");
            mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null);
            // reactivating ssl check for every new version
            AnkiDroidApp.getSharedPrefs(Info.this.getBaseContext()).edit().putBoolean("sslAcceptAll", false).commit();
            break;
        case TYPE_SHARED_DECKS:
            mLoadingLayer = (RelativeLayout) findViewById(R.id.info_loading_layer);
            mLoadingLayer.setVisibility(View.VISIBLE);
            try {
                mShareDecksTemplate = Utils.convertStreamToString(getAssets().open("shared_decks_template.html"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            mWebView.setWebViewClient(new MobileAnkiWebview());
            mWebView.loadUrl(res.getString(R.string.shared_decks_url));
            mWebView.getSettings().setJavaScriptEnabled(true);
            termsAndConditionsView.setVisibility(View.VISIBLE);
            continueButton.setText(res.getString(R.string.download_button_return));
            break;
        case TYPE_UPGRADE_DECKS:
            setTitle(R.string.deck_upgrade_title);
            sb.append("<html><body>");
            // add upgrade button
            Button but = (Button) findViewById(R.id.info_tutorial);
            but.setVisibility(View.VISIBLE);
            // add sync button
            Button syncButton = (Button) findViewById(R.id.info_sync);
            syncButton.setVisibility(View.VISIBLE);
            mUpgradeStage = getIntent().getIntExtra(TYPE_UPGRADE_STAGE, -1);
            boolean reupgrading = false;
            switch(mUpgradeStage) {
                case UPGRADE_SCREEN_BASIC1:
                    sb.append(getString(R.string.deck_upgrade_major_warning));
                    but.setText(R.string.later);
                    but.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Themes.showThemedToast(Info.this, getString(R.string.deck_upgrade_start_again_to_upgrade_toast), false);
                            setResult(RESULT_CANCELED);
                            finish();
                        }
                    });
                    syncButton.setText(R.string.more_options);
                    syncButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_MORE_OPTIONS);
                            setResult(RESULT_OK, result);
                            finishWithAnimation();
                        }
                    });
                    continueButton.setText(R.string.now);
                    continueButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2);
                            setResult(RESULT_OK, result);
                            finishWithAnimation();
                        }
                    });
                    break;
                case UPGRADE_SCREEN_BASIC2:
                    sb.append(getString(R.string.deck_upgrade_recommended_method));
                    but.setText(R.string.back);
                    but.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC1);
                            result.putExtra(TYPE_ANIMATION_RIGHT, true);
                            setResult(RESULT_OK, result);
                            finishWithAnimation(false);
                        }
                    });
                    syncButton.setEnabled(false);
                    syncButton.setText("N/A");
                    syncButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_WEB_UPGRADE);
                            setResult(RESULT_OK, result);
                            finishWithAnimation();
                        }
                    });
                    continueButton.setText(getString(R.string.pc));
                    continueButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_PC_UPGRADE);
                            setResult(RESULT_OK, result);
                            finishWithAnimation();
                        }
                    });
                    break;
                case UPGRADE_SCREEN_MORE_OPTIONS:
                    // If re-upgrading a collection exists already, so don't offer to make a new one
                    if (new File(AnkiDroidApp.getCollectionPath()).exists()) {
                        setTitle(getString(R.string.exit_wizard));
                        reupgrading = true;
                        sb.append(getString(R.string.deck_upgrade_more_options_exit));
                    } else {
                        sb.append(getString(R.string.deck_upgrade_more_options_new_collection));
                    }
                    sb.append(getString(R.string.deck_upgrade_more_options_downgrade));
                    but.setText(R.string.upgrade_decks_button);
                    but.setText(R.string.back);
                    but.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC1);
                            result.putExtra(TYPE_ANIMATION_RIGHT, true);
                            setResult(RESULT_OK, result);
                            finishWithAnimation(false);
                        }
                    });
                    if (reupgrading) {
                        syncButton.setText(getString(R.string.upgrade_deck_dont_upgrade));
                        syncButton.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View arg0) {
                                Intent result = new Intent();
                                result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_CONTINUE);
                                setResult(RESULT_OK, result);
                                finishWithAnimation();
                            }
                        });
                    } else {
                        syncButton.setText(R.string.deck_upgrade_create_new_collection);
                        syncButton.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View arg0) {
                                StyledDialog.Builder builder = new StyledDialog.Builder(Info.this);
                                builder.setTitle(R.string.deck_upgrade_create_new_collection_title);
                                builder.setIcon(R.drawable.ic_dialog_alert);
                                builder.setMessage(R.string.deck_upgrade_not_import_warning);
                                builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Intent result = new Intent();
                                        result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_CONTINUE);
                                        setResult(RESULT_OK, result);
                                        finishWithAnimation();
                                    }
                                });
                                builder.setNegativeButton(R.string.no, null);
                                builder.show();
                            }
                        });
                    }
                    continueButton.setVisibility(View.GONE);
                    break;
                case UPGRADE_SCREEN_WEB_UPGRADE:
                    sb.append(getString(R.string.deck_upgrade_via_web));
                    but.setText(R.string.back);
                    but.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2);
                            result.putExtra(TYPE_ANIMATION_RIGHT, true);
                            setResult(RESULT_OK, result);
                            finishWithAnimation(false);
                        }
                    });
                    syncButton.setVisibility(View.GONE);
                    continueButton.setText(R.string.yes);
                    continueButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            lockScreenOrientation();
                            Connection.upgradeDecks(mWebUpgradeListener, new Connection.Payload(new Object[] { AnkiDroidApp.getCurrentAnkiDroidDirectory() }));
                        }
                    });
                    break;
                case UPGRADE_SCREEN_PC_UPGRADE:
                    sb.append(getString(R.string.deck_upgrade_via_anki_desktop));
                    but.setText(R.string.back);
                    but.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2);
                            result.putExtra(TYPE_ANIMATION_RIGHT, true);
                            setResult(RESULT_OK, result);
                            finishWithAnimation(false);
                        }
                    });
                    syncButton.setText(R.string.usb);
                    syncButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_MANUAL_UPGRADE);
                            setResult(RESULT_OK, result);
                            finishWithAnimation();
                        }
                    });
                    continueButton.setEnabled(false);
                    continueButton.setText("N/A");
                    continueButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_AUTO_UPGRADE);
                            setResult(RESULT_OK, result);
                            finishWithAnimation();
                        }
                    });
                    break;
                case UPGRADE_SCREEN_MANUAL_UPGRADE:
                    sb.append(getString(R.string.deck_upgrade_manual));
                    but.setText(R.string.back);
                    but.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_BASIC2);
                            result.putExtra(TYPE_ANIMATION_RIGHT, true);
                            setResult(RESULT_OK, result);
                            finishWithAnimation(false);
                        }
                    });
                    syncButton.setText(R.string._import);
                    syncButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            File apkgFile = new File(AnkiDroidApp.getCurrentAnkiDroidDirectory(), DeckPicker.IMPORT_REPLACE_COLLECTION_NAME);
                            List<File> importables = Utils.getImportableDecks();
                            if (importables == null || !importables.contains(apkgFile)) {
                                Themes.showThemedToast(Info.this, getResources().getString(R.string.upgrade_import_no_file_found, DeckPicker.IMPORT_REPLACE_COLLECTION_NAME), false);
                            } else {
                                lockScreenOrientation();
                                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT_REPLACE, mUpgradeImportListener, new DeckTask.TaskData(AnkiDroidApp.getCol(), apkgFile.getAbsolutePath()));
                            }
                        }
                    });
                    continueButton.setVisibility(View.GONE);
                    break;
                case UPGRADE_SCREEN_AUTO_UPGRADE:
                    sb.append(getString(R.string.deck_upgrade_auto_upgrade));
                    but.setText(R.string.back);
                    but.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            Intent result = new Intent();
                            result.putExtra(TYPE_UPGRADE_STAGE, UPGRADE_SCREEN_PC_UPGRADE);
                            result.putExtra(TYPE_ANIMATION_RIGHT, true);
                            setResult(RESULT_OK, result);
                            finishWithAnimation(false);
                        }
                    });
                    syncButton.setText(getString(R.string.upgrade_deck_sync_from_ankiweb));
                    syncButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            StyledDialog.Builder builder = new StyledDialog.Builder(Info.this);
                            builder.setTitle(R.string.upgrade_deck_sync_from_ankiweb);
                            builder.setIcon(R.drawable.ic_dialog_alert);
                            builder.setMessage(getString(R.string.upgrade_deck_have_you_synced));
                            builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    lockScreenOrientation();
                                    downloadCollection();
                                }
                            });
                            builder.setNegativeButton(R.string.back, null);
                            builder.show();
                        }
                    });
                    continueButton.setVisibility(View.GONE);
                    break;
            }
            //                File[] fileList = (new File(AnkiDroidApp.getCurrentAnkiDroidDirectory())).listFiles(new OldAnkiDeckFilter());
            //                StringBuilder fsb = new StringBuilder();
            //                fsb.append("<ul>");
            //                for (File f : fileList) {
            //                	fsb.append("<li>").append(f.getName().replace(".anki", "")).append("</li>");
            //                }
            //            	fsb.append("</ul>");
            //                sb.append(res.getString(R.string.upgrade_decks_message, fsb.toString()));
            //                sb.append("<ul><li>");
            //                sb.append(res.getString(R.string.upgrade_decks_message_pos1,
            //                		AnkiDroidApp.getCurrentAnkiDroidDirectory()));
            //                sb.append("</li><li>");
            //                sb.append(res.getString(R.string.upgrade_decks_message_pos2, res.getString(R.string.link_anki)));
            //                sb.append("</li><li>");
            //                sb.append(res.getString(R.string.upgrade_decks_message_pos3));
            //                sb.append("</li></ul>");
            //                sb.append(res.getString(R.string.upgrade_decks_message_finish));
            sb.append("</body></html>");
            mWebView.loadDataWithBaseURL("", sb.toString(), "text/html", "utf-8", null);
            StyledDialog.Builder builder2 = new StyledDialog.Builder(this);
            builder2.setTitle(res.getString(R.string.connection_error_title));
            builder2.setIcon(R.drawable.ic_dialog_alert);
            builder2.setMessage(res.getString(R.string.connection_needed));
            builder2.setPositiveButton(res.getString(R.string.ok), null);
            mNoConnectionAlert = builder2.create();
            break;
        default:
            finish();
            break;
    }
}
Also used : DialogInterface(android.content.DialogInterface) StyledDialog(com.ichi2.themes.StyledDialog) Intent(android.content.Intent) IOException(java.io.IOException) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) Payload(com.ichi2.async.Connection.Payload) List(java.util.List) ArrayList(java.util.ArrayList) Resources(android.content.res.Resources) Editor(android.content.SharedPreferences.Editor) File(java.io.File)

Example 14 with Result

use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result 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 15 with Result

use of com.ichi2.anki.multimediacard.googleimagesearch.json.Result in project Anki-Android by Ramblurr.

the class DeckPicker method handleDbError.

// private void resetDeckLanguages(String deckPath) {
// if (MetaDB.resetDeckLanguages(this, deckPath)) {
// Themes.showThemedToast(this, getResources().getString(R.string.contextmenu_deckpicker_reset_reset_message),
// true);
// }
// }
//
//
// public void openSharedDeckPicker() {
// // deckLoaded = false;
// startActivityForResult(new Intent(this, SharedDeckPicker.class), DOWNLOAD_SHARED_DECK);
// if (UIUtils.getApiLevel() > 4) {
// ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
// }
// }
public void handleDbError() {
    AnkiDatabaseManager.closeDatabase(AnkiDroidApp.getCollectionPath());
    DeckTask.launchDeckTask(DeckTask.TASK_TYPE_RESTORE_IF_MISSING, new DeckTask.TaskListener() {

        @Override
        public void onPreExecute() {
            mProgressDialog = StyledProgressDialog.show(DeckPicker.this, "", getResources().getString(R.string.backup_restore_if_missing), true);
        }

        @Override
        public void onPostExecute(TaskData result) {
            if (mProgressDialog.isShowing()) {
                try {
                    mProgressDialog.dismiss();
                } catch (Exception e) {
                    Log.e(AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
                }
            }
            showDialog(DIALOG_DB_ERROR);
        }

        @Override
        public void onProgressUpdate(TaskData... values) {
        }
    }, new DeckTask.TaskData(AnkiDroidApp.getCollectionPath()));
}
Also used : DeckTask(com.ichi2.async.DeckTask) JSONException(org.json.JSONException) NotFoundException(android.content.res.Resources.NotFoundException) SQLException(android.database.SQLException) TaskData(com.ichi2.async.DeckTask.TaskData) TaskData(com.ichi2.async.DeckTask.TaskData)

Aggregations

IOException (java.io.IOException)7 Intent (android.content.Intent)6 Resources (android.content.res.Resources)6 DeckTask (com.ichi2.async.DeckTask)6 Collection (com.ichi2.libanki.Collection)6 JSONException (org.json.JSONException)6 DialogInterface (android.content.DialogInterface)5 TaskData (com.ichi2.async.DeckTask.TaskData)5 File (java.io.File)5 OnCancelListener (android.content.DialogInterface.OnCancelListener)4 SharedPreferences (android.content.SharedPreferences)4 OnClickListener (android.view.View.OnClickListener)4 NotFoundException (android.content.res.Resources.NotFoundException)3 View (android.view.View)3 Payload (com.ichi2.async.Connection.Payload)3 StyledDialog (com.ichi2.themes.StyledDialog)3 FileNotFoundException (java.io.FileNotFoundException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3