Example usage for android.content.res Resources getStringArray

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

Introduction

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

Prototype

@NonNull
public String[] getStringArray(@ArrayRes int id) throws NotFoundException 

Source Link

Document

Return the string array associated with a particular resource ID.

Usage

From source file:org.totschnig.myexpenses.dialog.HelpDialogFragment.java

@NonNull
@Override/*  w ww  .  j  av  a  2 s  .c o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    FragmentActivity ctx = getActivity();
    final Resources res = getResources();
    String title;
    String screenInfo = "";
    Bundle args = getArguments();
    context = args.getString(KEY_CONTEXT);
    variant = args.getString(KEY_VARIANT);
    layoutInflater = LayoutInflater.from(ctx);
    @SuppressLint("InflateParams")
    final View view = layoutInflater.inflate(R.layout.help_dialog, null);
    linearLayout = (LinearLayout) view.findViewById(R.id.help);

    try {
        String resIdString = "help_" + context + "_info";
        int resId = resolveString(resIdString);
        if (resId != 0) {
            screenInfo = getStringSafe(resId);
        }
        if (variant != null) {
            resIdString = "help_" + context + "_" + variant + "_info";
            resId = resolveString(resIdString);
            if (resId != 0) {
                String variantInfo = getStringSafe(resId);
                if (!TextUtils.isEmpty(variantInfo)) {
                    if (!TextUtils.isEmpty(screenInfo)) {
                        screenInfo += "<br>";
                    }
                    screenInfo += variantInfo;
                }
            }
        }
        final TextView infoView = (TextView) view.findViewById(R.id.screen_info);
        if (TextUtils.isEmpty(screenInfo)) {
            infoView.setVisibility(View.GONE);
        } else {
            infoView.setText(Html.fromHtml(screenInfo, this, null));
        }

        // Form entries
        resId = variant != null ? resolveArray(context + "_" + variant + "_formfields")
                : resolveArray(context + "_formfields");
        ArrayList<String> menuItems = new ArrayList<>();
        if (resId != 0) {
            menuItems.addAll(Arrays.asList(res.getStringArray(resId)));
        }
        if (menuItems.isEmpty()) {
            view.findViewById(R.id.form_fields_heading).setVisibility(View.GONE);
        } else {
            handleMenuItems(menuItems, "form", 2);
        }

        // Menu items
        resId = variant != null ? resolveArray(context + "_" + variant + "_menuitems")
                : resolveArray(context + "_menuitems");
        menuItems.clear();
        if (resId != 0)
            menuItems.addAll(Arrays.asList(res.getStringArray(resId)));
        if (menuItems.isEmpty())
            view.findViewById(R.id.menu_commands_heading).setVisibility(View.GONE);
        else {
            handleMenuItems(menuItems, "menu", 1);
        }

        // Contextual action bar
        resId = variant != null ? resolveArray(context + "_" + variant + "_cabitems")
                : resolveArray(context + "_cabitems");
        menuItems.clear();
        if (resId != 0)
            menuItems.addAll(Arrays.asList(res.getStringArray(resId)));
        if (menuItems.isEmpty())
            view.findViewById(R.id.cab_commands_heading).setVisibility(View.GONE);
        else {
            handleMenuItems(menuItems, "cab", 0);
        }

        resId = variant != null ? resolveString("help_" + context + "_" + variant + "_title") : 0;
        if (resId == 0) {
            title = resolveStringOrThrowIf0("help_" + context + "_title");
        } else {
            title = getString(resId);
        }
    } catch (NotFoundException e) {
        AcraHelper.report(e);
        return new AlertDialog.Builder(ctx).setMessage("Error generating Help dialog").create();
    }
    /*    view.setOnTouchListener(new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            final ObjectAnimator animScrollToTop = ObjectAnimator.ofInt(view, "scrollY", 4000);
            animScrollToTop.setDuration(4000);
            animScrollToTop.start();
            return true;
          }
        });*/
    return new AlertDialog.Builder(ctx).setTitle(title).setIcon(R.drawable.ic_menu_help).setView(view)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (getActivity() == null) {
                        return;
                    }
                    getActivity().finish();
                }
            }).create();
}

From source file:com.androzic.MapActivity.java

@Override
protected void onResume() {
    super.onResume();
    Log.e(TAG, "onResume()");

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

    // update some preferences
    int speedIdx = Integer.parseInt(settings.getString(getString(R.string.pref_unitspeed), "0"));
    speedFactor = Double.parseDouble(resources.getStringArray(R.array.speed_factors)[speedIdx]);
    speedAbbr = resources.getStringArray(R.array.speed_abbrs)[speedIdx];
    speedUnit.setText(speedAbbr);//w  ww .  ja va 2 s . c o m
    int distanceIdx = Integer.parseInt(settings.getString(getString(R.string.pref_unitdistance), "0"));
    StringFormatter.distanceFactor = Double
            .parseDouble(resources.getStringArray(R.array.distance_factors)[distanceIdx]);
    StringFormatter.distanceAbbr = resources.getStringArray(R.array.distance_abbrs)[distanceIdx];
    StringFormatter.distanceShortFactor = Double
            .parseDouble(resources.getStringArray(R.array.distance_factors_short)[distanceIdx]);
    StringFormatter.distanceShortAbbr = resources.getStringArray(R.array.distance_abbrs_short)[distanceIdx];
    int elevationIdx = Integer.parseInt(settings.getString(getString(R.string.pref_unitelevation), "0"));
    elevationFactor = Double.parseDouble(resources.getStringArray(R.array.elevation_factors)[elevationIdx]);
    elevationAbbr = resources.getStringArray(R.array.elevation_abbrs)[elevationIdx];
    elevationUnit.setText(elevationAbbr);
    application.angleType = Integer.parseInt(settings.getString(getString(R.string.pref_unitangle), "0"));
    trackUnit.setText((application.angleType == 0 ? "deg" : getString(R.string.degmag)));
    bearingUnit.setText((application.angleType == 0 ? "deg" : getString(R.string.degmag)));
    application.coordinateFormat = Integer
            .parseInt(settings.getString(getString(R.string.pref_unitcoordinate), "0"));
    application.sunriseType = Integer.parseInt(settings.getString(getString(R.string.pref_unitsunrise), "0"));

    renderInterval = settings.getInt(getString(R.string.pref_maprenderinterval),
            resources.getInteger(R.integer.def_maprenderinterval)) * 100;
    followOnLocation = settings.getBoolean(getString(R.string.pref_mapfollowonloc),
            resources.getBoolean(R.bool.def_mapfollowonloc));
    magInterval = resources.getInteger(R.integer.def_maginterval) * 1000;
    showDistance = Integer.parseInt(settings.getString(getString(R.string.pref_showdistance_int),
            getString(R.string.def_showdistance)));
    showAccuracy = settings.getBoolean(getString(R.string.pref_showaccuracy), true);
    autoDim = settings.getBoolean(getString(R.string.pref_mapdim), resources.getBoolean(R.bool.def_mapdim));
    dimInterval = settings.getInt(getString(R.string.pref_mapdiminterval),
            resources.getInteger(R.integer.def_mapdiminterval)) * 1000;
    dimValue = settings.getInt(getString(R.string.pref_mapdimvalue),
            resources.getInteger(R.integer.def_mapdimvalue));

    map.setHideOnDrag(settings.getBoolean(getString(R.string.pref_maphideondrag),
            resources.getBoolean(R.bool.def_maphideondrag)));
    map.setStrictUnfollow(!settings.getBoolean(getString(R.string.pref_unfollowontap),
            resources.getBoolean(R.bool.def_unfollowontap)));
    map.setLookAhead(
            settings.getInt(getString(R.string.pref_lookahead), resources.getInteger(R.integer.def_lookahead)));
    map.setBestMapEnabled(
            settings.getBoolean(getString(R.string.pref_mapbest), resources.getBoolean(R.bool.def_mapbest)));
    map.setBestMapInterval(settings.getInt(getString(R.string.pref_mapbestinterval),
            resources.getInteger(R.integer.def_mapbestinterval)) * 1000);
    map.setCursorVector(
            Integer.parseInt(settings.getString(getString(R.string.pref_cursorvector),
                    getString(R.string.def_cursorvector))),
            settings.getInt(getString(R.string.pref_cursorvectormlpr),
                    resources.getInteger(R.integer.def_cursorvectormlpr)));
    map.setProximity(Integer.parseInt(settings.getString(getString(R.string.pref_navigation_proximity),
            getString(R.string.def_navigation_proximity))));

    // prepare views
    customizeLayout(settings);
    findViewById(R.id.editroute).setVisibility(application.editingRoute != null ? View.VISIBLE : View.GONE);
    if (application.editingTrack != null) {
        startEditTrack(application.editingTrack);
    }
    updateGPSStatus();
    updateNavigationStatus();
    // prepare overlays
    updateOverlays(settings, false);

    if (settings.getBoolean(getString(R.string.ui_drawer_open), false)) {
        Panel panel = (Panel) findViewById(R.id.panel);
        panel.setOpen(true, false);
    }

    onSharedPreferenceChanged(settings, getString(R.string.pref_wakelock));
    map.setKeepScreenOn(keepScreenOn);

    // TODO move into application
    if (lastKnownLocation != null) {
        if (lastKnownLocation.getProvider().equals(LocationManager.GPS_PROVIDER)) {
            updateMovingInfo(lastKnownLocation, true);
            updateNavigationInfo();
            dimScreen(lastKnownLocation);
        } else if (lastKnownLocation.getProvider().equals(LocationManager.NETWORK_PROVIDER)) {
            dimScreen(lastKnownLocation);
        }
    }

    bindService(new Intent(this, LocationService.class), locationConnection, BIND_AUTO_CREATE);
    bindService(new Intent(this, NavigationService.class), navigationConnection, BIND_AUTO_CREATE);

    registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.BROADCAST_NAVIGATION_STATUS));
    registerReceiver(broadcastReceiver, new IntentFilter(NavigationService.BROADCAST_NAVIGATION_STATE));
    registerReceiver(broadcastReceiver, new IntentFilter(LocationService.BROADCAST_LOCATING_STATUS));
    registerReceiver(broadcastReceiver, new IntentFilter(LocationService.BROADCAST_TRACKING_STATUS));
    registerReceiver(broadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
    registerReceiver(broadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));

    if (application.hasEnsureVisible()) {
        setFollowing(false);
        double[] loc = application.getEnsureVisible();
        application.setMapCenter(loc[0], loc[1], true, false);
        application.clearEnsureVisible();
    } else {
        application.updateLocationMaps(true, map.isBestMapEnabled());
    }
    updateMapViewArea();
    map.resume();
    map.updateMapInfo();
    map.update();
    map.requestFocus();
}

From source file:org.smilec.smile.student.CourseList.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);

    Resources res = getResources(); //get resources
    language_list = res.getStringArray(R.array.language_list);
    category_arr = res.getStringArray(R.array.category_list);

    // First Extract the bundle from intent
    Bundle bundle = getIntent().getExtras();
    // Next extract the values using the key as
    curusertype = 1; // fixed (student)

    curusername = bundle.getString("USERNAME");
    cururi = bundle.getString("URI");
    curlanguage = bundle.getString("CHOSEN_LANGUAGE");
    String manufacturer = android.os.Build.MANUFACTURER;
    //showToast(manufacturer);

    resultSize1 = returnPixels(16.0f);//w w w  .j a  va  2s .  c  o  m
    resultSize2 = returnPixels(18.0f);

    if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) { // 480x640 dp units
        draw_piechart = new piechart(this, returnPixels(200.0f));
        titleSize1 = "<big>";
        titleSize2 = "</big>";
        resultSize1 = returnPixels(24.0f);
        resultSize2 = returnPixels(26.0f);
    } else if (manufacturer != null && manufacturer.toLowerCase().equals("samsung")) {
        draw_piechart = new piechart(this, returnPixels(150.0f));
        draw_piechart.setFontSize(returnPixels(12.0f));
    } else
        draw_piechart = new piechart(this, returnPixels(150.0f)); // to draw the piechart

    draw_piechart.onStart(100, 0);

    add_pic_g = new AndroidCustomGallery(this); // on 3/19/2012s

    answer_arr = new Vector<Integer>();
    rating_arr = new Vector<Integer>();
    my_score = new Vector<Integer>();
    right_answer = new Vector<Integer>();

    score_winner_name = new Vector<String>();
    rating_winner_name = new Vector<String>();
    final_avg_ratings = new Vector<String>();
    r_answer_percents = new Vector<String>();

    // connection_created = false;
    _act = this;

    chkimg = 0; // no image
    image_qa = null;

    student = null; // student communicator is created by make_connection()

    // Adding quick action menu
    image_quickaction();

    MY_IP = get_IP();

    getStoredFileURL();
    create_connection();
    show_todo_view();

    // student.send_initial_message();
    uploadErrorLog(cururi);
}

From source file:com.silentcircle.silenttext.application.SilentTextApplication.java

protected org.apache.http.conn.ssl.SSLSocketFactory getHTTPSocketFactory() {
    Resources resources = getResources();
    String[] protocols = resources.getStringArray(R.array.security_strict_network_protocols);
    String[] ciphers = resources.getStringArray(R.array.security_strict_cipher_suites);
    try {//from w  ww.j a  v a  2  s .  co  m
        return new SSLSocketFactory(getTrustStore(), protocols, ciphers);
    } catch (Throwable exception) {
        return null;
    }
}

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());//from  w  ww .j a v a  2  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.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  va  2s  .  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 va  2  s .  c om

    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;
    }
}

From source file:com.androzic.Androzic.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Resources resources = getResources();

    if (getString(R.string.pref_folder_data).equals(key)) {
        setDataPath(Androzic.PATH_DATA,/*from w  w  w .  j  av  a  2  s . c om*/
                sharedPreferences.getString(key, resources.getString(R.string.def_folder_data)));
    } else if (getString(R.string.pref_folder_icon).equals(key)) {
        setDataPath(Androzic.PATH_ICONS,
                sharedPreferences.getString(key, resources.getString(R.string.def_folder_icon)));
    } else if (getString(R.string.pref_unitcoordinate).equals(key)) {
        StringFormatter.coordinateFormat = Integer.parseInt(sharedPreferences.getString(key, "0"));
    } else if (getString(R.string.pref_unitdistance).equals(key)) {
        int distanceIdx = Integer.parseInt(sharedPreferences.getString(key, "0"));
        StringFormatter.distanceFactor = Double
                .parseDouble(resources.getStringArray(R.array.distance_factors)[distanceIdx]);
        StringFormatter.distanceAbbr = resources.getStringArray(R.array.distance_abbrs)[distanceIdx];
        StringFormatter.distanceShortFactor = Double
                .parseDouble(resources.getStringArray(R.array.distance_factors_short)[distanceIdx]);
        StringFormatter.distanceShortAbbr = resources.getStringArray(R.array.distance_abbrs_short)[distanceIdx];
    } else if (getString(R.string.pref_unitspeed).equals(key)) {
        int speedIdx = Integer.parseInt(sharedPreferences.getString(key, "0"));
        StringFormatter.speedFactor = Double
                .parseDouble(resources.getStringArray(R.array.speed_factors)[speedIdx]);
        StringFormatter.speedAbbr = resources.getStringArray(R.array.speed_abbrs)[speedIdx];
    } else if (getString(R.string.pref_unitelevation).equals(key)) {
        int elevationIdx = Integer.parseInt(sharedPreferences.getString(key, "0"));
        StringFormatter.elevationFactor = Double
                .parseDouble(resources.getStringArray(R.array.elevation_factors)[elevationIdx]);
        StringFormatter.elevationAbbr = resources.getStringArray(R.array.elevation_abbrs)[elevationIdx];
    } else if (getString(R.string.pref_unitangle).equals(key)) {
        int angleIdx = Integer.parseInt(sharedPreferences.getString(key, "0"));
        StringFormatter.angleFactor = Double
                .parseDouble(resources.getStringArray(R.array.angle_factors)[angleIdx]);
        StringFormatter.angleAbbr = resources.getStringArray(R.array.angle_abbrs)[angleIdx];
    } else if (getString(R.string.pref_unitanglemagnetic).equals(key)) {
        angleMagnetic = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_unitanglemagnetic));
    } else if (getString(R.string.pref_unitsunrise).equals(key)) {
        sunriseType = Integer.parseInt(sharedPreferences.getString(key, "0"));
    } else if (getString(R.string.pref_unitprecision).equals(key)) {
        boolean precision = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_unitprecision));
        StringFormatter.precisionFormat = precision ? "%.1f" : "%.0f";
    } else if (getString(R.string.pref_grid_mapshow).equals(key)) {
        overlayManager.mapGrid = sharedPreferences.getBoolean(key, false);
        if (currentMap instanceof OzfMap)
            overlayManager.initGrids((OzfMap) currentMap);
    } else if (getString(R.string.pref_grid_usershow).equals(key)) {
        overlayManager.userGrid = sharedPreferences.getBoolean(key, false);
        if (currentMap instanceof OzfMap)
            overlayManager.initGrids((OzfMap) currentMap);
    } else if (getString(R.string.pref_grid_preference).equals(key)) {
        overlayManager.gridPrefer = Integer.parseInt(sharedPreferences.getString(key, "0"));
        if (currentMap instanceof OzfMap)
            overlayManager.initGrids((OzfMap) currentMap);
    } else if (getString(R.string.pref_grid_userscale).equals(key)
            || getString(R.string.pref_grid_userunit).equals(key)
            || getString(R.string.pref_grid_usermpp).equals(key)) {
        if (currentMap instanceof OzfMap)
            overlayManager.initGrids((OzfMap) currentMap);
    } else if (getString(R.string.pref_vectormap_theme).equals(key)
            || getString(R.string.pref_vectormap_poi).equals(key)) {
        initializeRenderTheme();
        ForgeMap.onRenderThemeChanged();
    } else if (getString(R.string.pref_vectormap_textscale).equals(key)) {
        ForgeMap.textScale = Float
                .parseFloat(sharedPreferences.getString(getString(R.string.pref_vectormap_textscale), "1.0"));
        ForgeMap.onRenderThemeChanged();
    } else if (getString(R.string.pref_onlinemap).equals(key)
            || getString(R.string.pref_onlinemapscale).equals(key)) {
        setOnlineMaps(sharedPreferences.getString(getString(R.string.pref_onlinemap),
                resources.getString(R.string.def_onlinemap)));
    } else if (getString(R.string.pref_mapadjacent).equals(key)) {
        adjacentMaps = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapadjacent));
    } else if (getString(R.string.pref_onlinemapprescalefactor).equals(key)) {
        onlineMapPrescaleFactor = sharedPreferences.getInt(key,
                resources.getInteger(R.integer.def_onlinemapprescalefactor));
        if (maps != null)
            for (BaseMap map : maps.getMaps())
                if (map instanceof OnlineMap)
                    ((OnlineMap) map).setPrescaleFactor(onlineMapPrescaleFactor);
        // Hack to recalculate cache and mpp
        if (currentMap != null && currentMap instanceof OnlineMap)
            currentMap.setZoom(currentMap.getZoom());
    } else if (getString(R.string.pref_onlinemapexpiration).equals(key)) {
        // in weeks
        onlineMapTileExpiration = sharedPreferences.getInt(key,
                resources.getInteger(R.integer.def_onlinemapexpiration));
        // in milliseconds
        onlineMapTileExpiration *= 1000 * 3600 * 24 * 7;
        if (onlineMaps != null) {
            for (TileProvider provider : onlineMaps)
                provider.tileExpiration = onlineMapTileExpiration;
        }
    } else if (getString(R.string.pref_mapcropborder).equals(key)) {
        cropMapBorder = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapcropborder));
    } else if (getString(R.string.pref_mapdrawborder).equals(key)) {
        drawMapBorder = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapdrawborder));
    } else if (getString(R.string.pref_showwaypoints).equals(key)) {
        overlayManager.setWaypointsOverlayEnabled(sharedPreferences.getBoolean(key, true));
    } else if (getString(R.string.pref_showcurrenttrack).equals(key)) {
        overlayManager.setCurrentTrackOverlayEnabled(sharedPreferences.getBoolean(key, true));
    } else if (getString(R.string.pref_showaccuracy).equals(key)) {
        overlayManager.setAccuracyOverlayEnabled(sharedPreferences.getBoolean(key, true));
    } else if (getString(R.string.pref_showdistance_int).equals(key)) {
        int showDistance = Integer
                .parseInt(sharedPreferences.getString(key, getString(R.string.def_showdistance)));
        overlayManager.setDistanceOverlayEnabled(showDistance > 0);
    }
    overlayManager.onPreferencesChanged(sharedPreferences);
    if (mapHolder != null)
        mapHolder.refreshMap();
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    Timber.d("onCreate()");
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    Resources res = getResources();

    mType = getIntent().getIntExtra(TYPE_EXTRA, TYPE_ABOUT);

    setTitle(getTitleString());//  ww  w  .  j a v  a  2  s  .  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());

    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) {
                if (AnkiDroidApp.isKindle()) {
                    Intent intent = new Intent("android.intent.action.VIEW",
                            Uri.parse("http://www.amazon.com/gp/mas/dl/android?p=com.ichi2.anki"));
                    startActivity(intent);
                } else {
                    Info.this.startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.ichi2.anki")));
                }
                return;
            }
            setResult(RESULT_OK);
            switch (mType) {
            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));
        Button debugCopy = ((Button) findViewById(R.id.info_later));
        debugCopy.setText(res.getString(R.string.feedback_copy_debug));
        debugCopy.setVisibility(View.VISIBLE);
        debugCopy.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                copyDebugInfo();
            }
        });
        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(
                "<br><br><br>A new design is coming in v2.5, <a href=\"https://groups.google.com/d/msg/anki-android/DrMPHn9NQtk/aZYXdIZRCwAJ\">preview it here</a>!");
        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 "later" button
        Button but = (Button) findViewById(R.id.info_later);
        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.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_button);
                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.dialog_positive_create,
                                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.dialog_cancel, 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.dialog_continue);
            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.youre_offline));
        builder2.setPositiveButton(res.getString(R.string.dialog_ok), null);
        mNoConnectionAlert = builder2.create();
        break;

    default:
        finish();
        break;
    }
}

From source file:com.hichinaschool.flashcards.async.DeckTask.java

private TaskData doInBackgroundLoadTutorial(TaskData... params) {
    // Log.i(AnkiDroidApp.TAG, "doInBackgroundLoadTutorial");
    Resources res = AnkiDroidApp.getInstance().getBaseContext().getResources();
    Collection col = params[0].getCollection();
    col.getDb().getDatabase().beginTransaction();
    String title = res.getString(R.string.help_tutorial);
    try {/*from   w w  w .ja  v a2s  .c o m*/
        // get deck or create it
        long did = col.getDecks().id(title);
        // reset todays counts
        JSONObject d = col.getDecks().get(did);
        for (String t : new String[] { "new", "rev", "lrn", "time" }) {
            String k = t + "Today";
            JSONArray ja = new JSONArray();
            ja.put(col.getSched().getToday());
            ja.put(0);
            d.put(k, ja);
        }
        // save deck
        col.getDecks().save(d);
        if (col.getSched().cardCount("(" + did + ")") > 0) {
            // deck does already exist. Remove all cards and recreate them
            // to ensure the correct order
            col.remCards(col.getDecks().cids(did));
        }
        JSONObject model = col.getModels().byName(title);
        // TODO: check, if model is valid or delete and recreate it
        // TODO: deactivated at the moment as if forces a schema change
        // create model (remove old ones first)
        // while (model != null) {
        // JSONObject m = col.getModels().byName(title);
        // // rename old tutorial model if there are some non tutorial cards
        // in it
        // if
        // (col.getDb().queryScalar("SELECT id FROM cards WHERE nid IN (SELECT id FROM notes WHERE mid = "
        // +
        // m.getLong("id") + ")", false) == 0) {
        // col.getModels().rem(m);
        // } else {
        // m.put("name", title + " (renamed)");
        // col.getModels().save(m);
        // }
        // }
        if (model == null) {
            model = col.getModels().addBasicModel(col, title);
        }
        model.put("did", did);
        String[] questions = res.getStringArray(R.array.tutorial_questions);
        String[] answers = res.getStringArray(R.array.tutorial_answers);
        String[] sampleQuestions = res.getStringArray(R.array.tutorial_capitals_questions);
        String[] sampleAnswers = res.getStringArray(R.array.tutorial_capitals_answers);
        int len = Math.min(questions.length, answers.length);
        for (int i = 0; i < len + Math.min(sampleQuestions.length, sampleAnswers.length); i++) {
            Note note = col.newNote(model);
            if (note.values().length < 2) {
                return new TaskData(false);
            }
            note.values()[0] = (i < len) ? questions[i] : sampleQuestions[i - len];
            note.values()[1] = (i < len) ? answers[i] : sampleAnswers[i - len];
            col.addNote(note);
        }
        // deck.setSessionTimeLimit(0);
        if (col.getSched().cardCount("(" + did + ")") == 0) {
            // error, delete deck
            col.getDecks().rem(did, true);
            return new TaskData(false);
        } else {
            col.save();
            col.getDecks().select(did);
            col.getDb().getDatabase().setTransactionSuccessful();
            return new TaskData(true);
        }
    } catch (SQLException e) {
        AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundLoadTutorial");
        return new DeckTask.TaskData(false);
    } catch (JSONException e) {
        AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundLoadTutorial");
        return new DeckTask.TaskData(false);
    } finally {
        col.getDb().getDatabase().endTransaction();
    }
}