Example usage for android.content.res Resources getString

List of usage examples for android.content.res Resources getString

Introduction

In this page you can find the example usage for android.content.res Resources getString.

Prototype

@NonNull
public String getString(@StringRes int id) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.ichi2.anki.DeckPicker.java

public void confirmDeckDeletion(long did) {
    Resources res = getResources();
    if (!colIsOpen()) {
        return;//from   www  .  jav  a  2  s  . co  m
    }
    if (did == 1) {
        showSimpleSnackbar(R.string.delete_deck_default_deck, true);
        dismissAllDialogFragments();
        return;
    }
    // Get the number of cards contained in this deck and its subdecks
    TreeMap<String, Long> children = getCol().getDecks().children(did);
    long[] dids = new long[children.size() + 1];
    dids[0] = did;
    int i = 1;
    for (Long l : children.values()) {
        dids[i++] = l;
    }
    String ids = Utils.ids2str(dids);
    int cnt = getCol().getDb()
            .queryScalar("select count() from cards where did in " + ids + " or odid in " + ids);
    // Delete empty decks without warning
    if (cnt == 0) {
        deleteDeck(did);
        dismissAllDialogFragments();
        return;
    }
    // Otherwise we show a warning and require confirmation
    String msg;
    String deckName = "\'" + getCol().getDecks().name(did) + "\'";
    boolean isDyn = getCol().getDecks().isDyn(did);
    if (isDyn) {
        msg = String.format(res.getString(R.string.delete_cram_deck_message), deckName);
    } else {
        msg = res.getQuantityString(R.plurals.delete_deck_message, cnt, deckName, cnt);
    }
    showDialogFragment(DeckPickerConfirmDeleteDeckDialog.newInstance(msg));
}

From source file:com.android.mms.ui.MessageUtils.java

private static String getNotificationIndDetails(Context context, MessageItem msgItem) {
    /// @}// w w  w  .ja v a 2 s . c o  m
    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();

    // / M: Code analyze 027, new feature, to improve the performance of
    // Mms. @{
    Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, msgItem.mMsgId);
    /// @}
    NotificationInd nInd;

    try {
        // / M: Code analyze 027, new feature, to improve the performance of
        // Mms. @{
        nInd = (NotificationInd) PduPersister.getPduPersister(context).load(uri);
        /// @}
    } catch (MmsException e) {
        Log.e(TAG, "Failed to load the message: " + uri, e);
        return context.getResources().getString(R.string.cannot_get_details);
    }

    // Message Type: Mms Notification.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.multimedia_notification));

    /// M: Code analyze 026, new feature, show the service center number.
    // @{
    details.append('\n');
    details.append(res.getString(R.string.service_center_label));
    details.append(!TextUtils.isEmpty(msgItem.mServiceCenter) ? msgItem.mServiceCenter : "");
    /// @}

    // From: ***
    String from = extractEncStr(context, nInd.getFrom());
    details.append('\n');
    details.append(res.getString(R.string.from_label));
    details.append(!TextUtils.isEmpty(from) ? from : res.getString(R.string.hidden_sender_address));

    // Date: ***
    details.append('\n');
    details.append(res.getString(R.string.expire_on,
            MessageUtils.formatTimeStampString(context, nInd.getExpiry() * 1000L, true)));

    // Subject: ***
    details.append('\n');
    details.append(res.getString(R.string.subject_label));

    EncodedStringValue subject = nInd.getSubject();
    if (subject != null) {
        details.append(subject.getString());
    }

    // Message class: Personal/Advertisement/Infomational/Auto
    details.append('\n');
    details.append(res.getString(R.string.message_class_label));
    details.append(new String(nInd.getMessageClass()));

    // Message size: *** KB
    details.append('\n');
    details.append(res.getString(R.string.message_size_label));
    details.append(String.valueOf((nInd.getMessageSize() + 1023) / 1024));
    details.append(context.getString(R.string.kilobyte));

    return details.toString();
}

From source file:com.androzic.Androzic.java

public void onCreateEx() {
    try {//from  w w  w .ja v  a 2s. co m
        (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER)).mkdirs();
        (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER + "/ghiam")).mkdirs();
    } catch (Throwable e) {
    }

    if (initialized)
        return;

    AndroidGraphicFactory.createInstance(this);
    try {
        OzfDecoder.useNativeCalls();
    } catch (UnsatisfiedLinkError e) {
        Toast.makeText(Androzic.this, "Failed to initialize native library: " + e.getMessage(),
                Toast.LENGTH_LONG).show();
    }

    Resources resources = getResources();
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    Configuration config = resources.getConfiguration();

    renderingThread = new HandlerThread("RenderingThread");
    renderingThread.start();

    longOperationsThread = new HandlerThread("LongOperationsThread");
    longOperationsThread.setPriority(Thread.MIN_PRIORITY);
    longOperationsThread.start();

    uiHandler = new Handler();
    mapsHandler = new Handler(longOperationsThread.getLooper());

    // We silently initialize data uri to let location service restart after crash
    File datadir = new File(
            settings.getString(getString(R.string.pref_folder_data), Environment.getExternalStorageDirectory()
                    + File.separator + resources.getString(R.string.def_folder_data)));
    setDataPath(Androzic.PATH_DATA, datadir.getAbsolutePath());

    setInstance(this);

    String intentToCheck = "com.androzic.donate";
    String myPackageName = getPackageName();
    PackageManager pm = getPackageManager();
    PackageInfo pi;
    try {
        pi = pm.getPackageInfo(intentToCheck, 0);
        isPaid = (pm.checkSignatures(myPackageName, pi.packageName) == PackageManager.SIGNATURE_MATCH);
    } catch (NameNotFoundException e) {
        //         e.printStackTrace();
    }

    File sdcard = Environment.getExternalStorageDirectory();
    Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this, sdcard.getAbsolutePath()));

    DisplayMetrics displayMetrics = new DisplayMetrics();

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    if (wm != null) {
        wm.getDefaultDisplay().getMetrics(displayMetrics);
    } else {
        displayMetrics.setTo(resources.getDisplayMetrics());
    }
    BaseMap.viewportWidth = displayMetrics.widthPixels;
    BaseMap.viewportHeight = displayMetrics.heightPixels;

    charset = settings.getString(getString(R.string.pref_charset), "UTF-8");
    String lang = settings.getString(getString(R.string.pref_locale), "");
    if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) {
        locale = new Locale(lang);
        Locale.setDefault(locale);
        config.locale = locale;
        resources.updateConfiguration(config, resources.getDisplayMetrics());
    }

    magInterval = resources.getInteger(R.integer.def_maginterval) * 1000;

    overlayManager = new OverlayManager(longOperationsThread.getLooper());
    TooltipManager.initialize(this);

    onSharedPreferenceChanged(settings, getString(R.string.pref_unitcoordinate));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitdistance));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitspeed));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitelevation));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitangle));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitanglemagnetic));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitprecision));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitsunrise));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapadjacent));
    onSharedPreferenceChanged(settings, getString(R.string.pref_vectormap_textscale));
    onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapprescalefactor));
    onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapexpiration));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapcropborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapdrawborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showwaypoints));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showcurrenttrack));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showaccuracy));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showdistance_int));

    settings.registerOnSharedPreferenceChangeListener(this);

    initialized = true;
}

From source file:cgeo.geocaching.CacheDetailActivity.java

static void updateOfflineBox(final View view, final Geocache cache, final Resources res,
        final OnClickListener refreshCacheClickListener, final OnClickListener dropCacheClickListener,
        final OnClickListener storeCacheClickListener, final OnLongClickListener moveCacheListener,
        final OnLongClickListener storeCachePreselectedListener) {
    // offline use
    final TextView offlineText = ButterKnife.findById(view, R.id.offline_text);
    final ImageButton offlineRefresh = ButterKnife.findById(view, R.id.offline_refresh);
    final ImageButton offlineStoreDrop = ButterKnife.findById(view, R.id.offline_store_drop);
    final ImageButton offlineEdit = ButterKnife.findById(view, R.id.offline_edit);

    offlineStoreDrop.setClickable(true);
    offlineStoreDrop.setOnClickListener(storeCacheClickListener);
    offlineStoreDrop.setOnLongClickListener(storeCachePreselectedListener);

    if (moveCacheListener != null) {
        offlineEdit.setOnLongClickListener(moveCacheListener);
    }// w ww . j av a2s .c  o  m

    offlineRefresh.setVisibility(cache.supportsRefresh() ? View.VISIBLE : View.GONE);
    offlineRefresh.setClickable(true);
    offlineRefresh.setOnClickListener(refreshCacheClickListener);

    if (cache.isOffline()) {
        offlineText.setText(Formatter.formatStoredAgo(cache.getUpdated()));

        offlineStoreDrop.setOnClickListener(dropCacheClickListener);
        offlineStoreDrop.setOnLongClickListener(null);
        offlineStoreDrop.setClickable(true);
        offlineStoreDrop.setImageResource(R.drawable.ic_menu_delete);

        offlineEdit.setVisibility(View.VISIBLE);
        offlineEdit.setOnClickListener(storeCacheClickListener);
    } else {
        offlineText.setText(res.getString(R.string.cache_offline_not_ready));
        offlineStoreDrop.setImageResource(R.drawable.ic_menu_save);

        offlineEdit.setVisibility(View.GONE);
    }

}

From source file:com.ichi2.anki.NoteEditor.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Resources res = getResources();
    switch (item.getItemId()) {
    case android.R.id.home:
        Timber.i("NoteEditor:: Home button pressed");
        closeCardEditorWithCheck();/*from   ww w . j  av  a  2s. com*/
        return true;

    case R.id.action_save:
        Timber.i("NoteEditor:: Save note button pressed");
        saveNote();
        return true;

    case R.id.action_add_card_from_card_editor:
    case R.id.action_copy_card:
        Timber.i("NoteEditor:: Copy or add card button pressed");
        Intent intent = new Intent(NoteEditor.this, NoteEditor.class);
        intent.putExtra(EXTRA_CALLER, CALLER_CARDEDITOR);
        // intent.putExtra(EXTRA_DECKPATH, mDeckPath);
        if (item.getItemId() == R.id.action_copy_card) {
            intent.putExtra(EXTRA_CONTENTS, getFieldsText());
        }
        startActivityForResultWithAnimation(intent, REQUEST_ADD, ActivityTransitionAnimation.LEFT);
        return true;

    case R.id.action_reset_card_progress:
        Timber.i("NoteEditor:: Reset progress button pressed");
        // Show confirmation dialog before resetting card progress
        ConfirmationDialog dialog = new ConfirmationDialog() {
            @Override
            public void confirm() {
                Timber.i("NoteEditor:: OK button pressed");
                getCol().getSched().forgetCards(new long[] { mCurrentEditedCard.getId() });
                getCol().reset();
                mReloadRequired = true;
                Themes.showThemedToast(NoteEditor.this,
                        getResources().getString(R.string.reset_card_dialog_acknowledge), true);
            }
        };
        String title = res.getString(R.string.reset_card_dialog_title);
        String message = res.getString(R.string.reset_card_dialog_message);
        dialog.setArgs(title, message);
        showDialogFragment(dialog);
        return true;

    case R.id.action_reschedule_card:
        Timber.i("NoteEditor:: Reschedule button pressed");
        showDialogFragment(NoteEditorRescheduleCard.newInstance());
        return true;

    default:
        return super.onOptionsItemSelected(item);

    }
}

From source file:com.android.mms.ui.MessageUtils.java

private static String getMultimediaMessageDetails(Context context, MessageItem msgItem) {
    if (msgItem.mMessageType == PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND) {
        return getNotificationIndDetails(context, msgItem);
    }/*  w  w  w .  j  av a2s.c  o  m*/

    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();

    // / M: Code analyze 027, new feature, to improve the performance of
    // Mms. @{
    Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, msgItem.mMsgId);
    /// @}
    MultimediaMessagePdu msg;
    try {
        msg = (MultimediaMessagePdu) PduPersister.getPduPersister(context).load(uri);
    } catch (MmsException e) {
        Log.e(TAG, "Failed to load the message: " + uri, e);
        return context.getResources().getString(R.string.cannot_get_details);
    }

    // Message Type: Text message.
    initializeMsgDetails(context, details, res, msg);

    // SentDate: ***
    if (msg.getDateSent() > 0 && msgItem.mBoxId == Mms.MESSAGE_BOX_INBOX) {
        details.append('\n');
        details.append(res.getString(R.string.sent_label));
        String dateStr = formatDateAndTimeStampString(context, 0, msg.getDateSent() * 1000L, true);
        details.append(dateStr);
    }

    // Date: ***
    details.append('\n');
    // / M: Code analyze 027, new feature, to improve the performance of
    // Mms. @{
    int msgBox = msgItem.mBoxId;
    /// @}
    if (msgBox == Mms.MESSAGE_BOX_DRAFTS) {
        details.append(res.getString(R.string.saved_label));
    } else if (msgBox == Mms.MESSAGE_BOX_INBOX) {
        details.append(res.getString(R.string.received_label));
    } else {
        details.append(res.getString(R.string.sent_label));
    }
    String dateStr = formatDateAndTimeStampString(context, 0, msg.getDate() * 1000L, true);

    details.append(dateStr);

    // Subject: ***
    details.append('\n');
    details.append(res.getString(R.string.subject_label));

    // / M: Code analyze 027, new feature, to improve the performance of
    // Mms. @{
    int size = msgItem.mMessageSize;
    /// @}
    EncodedStringValue subject = msg.getSubject();
    if (subject != null) {
        String subStr = subject.getString();
        // Message size should include size of subject.
        // Modify ALPS00427926. Because message size has
        // include PDU header, so it should not add this size here
        //size += subStr.length();
        details.append(subStr);
    }

    // Priority: High/Normal/Low
    return formatDetails(details, context, msg, size, res);
}

From source file:com.ichi2.anki2.DeckPicker.java

private void updateDecksList(TreeSet<Object[]> decks, int eta, int count) {
    if (decks == null) {
        Log.e(AnkiDroidApp.TAG, "updateDecksList: empty decks list");
        return;/*from   ww  w.j a v a 2  s  .  co m*/
    }
    mDeckList.clear();
    int due = 0;
    for (Object[] d : decks) {
        HashMap<String, String> m = new HashMap<String, String>();
        String[] name = ((String[]) d[0]);
        m.put("name", readableDeckName(name));
        m.put("did", ((Long) d[1]).toString());
        m.put("new", ((Integer) d[2]).toString());
        m.put("lrn", ((Integer) d[3]).toString());
        m.put("rev", ((Integer) d[4]).toString());
        m.put("dyn", ((Boolean) d[5]) ? "d1" : "d0");
        // m.put("complMat", ((Float)d[5]).toString());
        // m.put("complAll", ((Float)d[6]).toString());
        if (name.length == 1) {
            due += Integer.parseInt(m.get("new")) + Integer.parseInt(m.get("lrn"))
                    + Integer.parseInt(m.get("rev"));
            // top position
            m.put("sep", "top");
            // correct previous deck
            if (mDeckList.size() > 0) {
                HashMap<String, String> map = mDeckList.get(mDeckList.size() - 1);
                if (map.get("sep").equals("top")) {
                    map.put("sep", "ful");
                } else {
                    map.put("sep", "bot");
                }
            }
        } else {
            // center position
            m.put("sep", "cen");
        }
        if (mDeckList.size() > 0 && mDeckList.size() == decks.size() - 1) {
            // bottom position
            if (name.length == 1) {
                m.put("sep", "ful");
            } else {
                m.put("sep", "bot");
            }
        }
        mDeckList.add(m);
    }
    mDeckListAdapter.notifyDataSetChanged();

    // set title
    Resources res = getResources();
    if (count != -1) {
        String time = "-";
        if (eta != -1) {
            time = res.getQuantityString(R.plurals.deckpicker_title_minutes, eta, eta);
        }
        AnkiDroidApp.getCompat().setSubtitle(this,
                res.getQuantityString(R.plurals.deckpicker_title, due, due, count, time));
    }
    setTitle(res.getString(R.string.app_name));

    // update widget
    WidgetStatus.update(this, decks);
}

From source file:com.ichi2.anki2.Info.java

@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());// ww w. j  a  v a2s  .com

    setContentView(R.layout.info);

    mWebView = (WebView) findViewById(R.id.info);
    mWebView.setBackgroundColor(res.getColor(Themes.getBackgroundColor()));
    Themes.setWallpaper((View) mWebView.getParent().getParent().getParent());

    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.getPkgVersion()).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);
        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.setText(getString(R.string.internet));
            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.setText(R.string.ankiweb);
            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;
    }
}

From source file:com.nit.vicky.Info.java

@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());// w w w  .  j  a v  a2s .  c  o m

    setContentView(R.layout.info);

    mWebView = (WebView) findViewById(R.id.info);
    mWebView.setBackgroundColor(res.getColor(Themes.getBackgroundColor()));
    Themes.setWallpaper((View) mWebView.getParent().getParent().getParent());

    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);
        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.setText(getString(R.string.internet));
            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.setText(R.string.ankiweb);
            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;
    }
}

From source file:com.hichinaschool.flashcards.anki.Info.java

@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());/*from w w w.  j a v a2  s .  co m*/

    setContentView(R.layout.info);

    mWebView = (WebView) findViewById(R.id.info);
    mWebView.setBackgroundColor(res.getColor(Themes.getBackgroundColor()));
    Themes.setWallpaper((View) mWebView.getParent().getParent().getParent());

    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.hichinaschool.flashcards.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);
        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.setText(getString(R.string.internet));
            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.setText(R.string.ankiweb);
            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;
    }
}