Example usage for android.content.res Resources getColor

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

Introduction

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

Prototype

@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException 

Source Link

Document

Returns a color integer associated with a particular resource ID.

Usage

From source file:com.philliphsu.hybridtimepicker.HybridTimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    View view = inflater.inflate(R.layout.hybrid_time_picker_dialog, null);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    Resources res = getResources();
    mHourPickerDescription = res.getString(R.string.hour_picker_description);
    mSelectHours = res.getString(R.string.select_hours);
    mMinutePickerDescription = res.getString(R.string.minute_picker_description);
    mSelectMinutes = res.getString(R.string.select_minutes);
    // TODO: Rename variable to mAccentColor
    mSelectedColor = //res.getColor(mThemeDark? R.color.red : R.color.blue);
            Utils.getAccentColorFromThemeIfAvailable(getActivity());
    mUnselectedColor = res.getColor(mThemeDark ? android.R.color.white : R.color.numbers_text_color);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];// w ww.ja  v a  2 s.c om
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());

    mGridPicker = (GridPickerLayout) view.findViewById(R.id.time_picker);
    mGridPicker.setOnValueSelectedListener(this);
    // TODO: Adapt to my GridPickerLayout
    //        mTimePicker.setOnKeyListener(keyboardListener);
    mGridPicker.initialize(getActivity(), /*mHapticFeedbackController,*/ this, mInitialHourOfDay,
            mInitialMinute, mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mGridPicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mCancelButton = (TextView) view.findViewById(R.id.cancel_button);
    mCancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            // TODO: Do we need to fire a OnDialogCancel event?
            dismiss();
        }
    });
    mCancelButton.setOnKeyListener(keyboardListener);

    mDoneButton = (TextView) view.findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            if (mCallback != null) {
                mCallback.onTimeSet(mGridPicker, mGridPicker.getHours(), mGridPicker.getMinutes());
            }
            dismiss();
        }
    });
    mDoneButton.setOnKeyListener(keyboardListener);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);

        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                tryVibrate();
                int amOrPm = mGridPicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                updateAmPmDisplay(amOrPm);
                mGridPicker.setAmOrPm(amOrPm);
            }
        });
    }

    mAllowAutoAdvance = true;
    setHour(mInitialHourOfDay, true);
    setMinute(mInitialMinute);

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<Integer>();
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    mGridPicker.setTheme(getActivity().getApplicationContext(), mThemeDark);
    // Prepare some colors to use.
    int white = res.getColor(android.R.color.white);
    //        int circleBackground = res.getColor(R.color.circle_background);
    //        int line = res.getColor(R.color.line_background);
    int timeDisplay = res.getColor(R.color.numbers_text_color);
    // We'll just use an actual color instead of a ColorStateList for the dialog buttons since
    // I don't see why we would ever need to disable them.
    //        ColorStateList dialogButtonsTextColor = res.getColorStateList(R.color.dialog_buttons_text_color);
    int doneBackground = R.drawable.done_background_color;

    int darkGray = res.getColor(R.color.dark_gray);
    //        int lightGray = res.getColor(R.color.light_gray);
    //        int darkLine = res.getColor(R.color.line_dark);
    // TODO: We don't have an accent color variant for the dark theme, so leave it off for now.
    //        ColorStateList darkDialogButtonsTextColor = res.getColorStateList(R.color.dialog_buttons_text_color_dark);
    int darkDoneBackground = R.drawable.done_background_color_dark;

    // Set the colors for each view based on the theme.
    view.findViewById(R.id.time_display_background).setBackgroundColor(mThemeDark ? darkGray : white);
    view.findViewById(R.id.time_display).setBackgroundColor(mThemeDark ? darkGray : white);
    ((TextView) view.findViewById(R.id.separator)).setTextColor(mThemeDark ? white : timeDisplay);
    ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mThemeDark ? white : timeDisplay);
    //        view.findViewById(R.id.line).setBackgroundColor(mThemeDark? darkLine : line);
    mDoneButton.setTextColor(mSelectedColor); // accent color
    mCancelButton.setTextColor(mSelectedColor); // accent color
    mGridPicker.setBackgroundColor(mThemeDark ? darkGray : white);
    ((LinearLayout) view.findViewById(R.id.dialog_buttons)).setBackgroundColor(mThemeDark ? darkGray : white);
    return view;
}

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

private void updateChart(double[][] serieslist) {
    if (mSmallChart != null) {
        Resources res = getResources();
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        XYSeriesRenderer r = new XYSeriesRenderer();
        r.setColor(res.getColor(R.color.stats_young));
        renderer.addSeriesRenderer(r);//from w  ww .j a  v  a 2  s  .  c om
        r = new XYSeriesRenderer();
        r.setColor(res.getColor(R.color.stats_mature));
        renderer.addSeriesRenderer(r);

        for (int i = 1; i < serieslist.length; i++) {
            XYSeries series = new XYSeries("");
            for (int j = 0; j < serieslist[i].length; j++) {
                series.add(serieslist[0][j], serieslist[i][j]);
            }
            dataset.addSeries(series);
        }
        renderer.setBarSpacing(0.4);
        renderer.setShowLegend(false);
        renderer.setLabelsTextSize(13);
        renderer.setXAxisMin(-0.5);
        renderer.setXAxisMax(7.5);
        renderer.setYAxisMin(0);
        renderer.setGridColor(Color.LTGRAY);
        renderer.setShowGrid(true);
        renderer.setBackgroundColor(Color.WHITE);
        renderer.setMarginsColor(Color.WHITE);
        renderer.setAxesColor(Color.BLACK);
        renderer.setLabelsColor(Color.BLACK);
        renderer.setYLabelsColor(0, Color.BLACK);
        renderer.setYLabelsAngle(-90);
        renderer.setXLabelsColor(Color.BLACK);
        renderer.setXLabelsAlign(Align.CENTER);
        renderer.setYLabelsAlign(Align.CENTER);
        renderer.setZoomEnabled(false, false);
        // mRenderer.setMargins(new int[] { 15, 48, 30, 10 });
        renderer.setAntialiasing(true);
        renderer.setPanEnabled(true, false);
        GraphicalView chartView = ChartFactory.getBarChartView(getActivity(), dataset, renderer,
                BarChart.Type.STACKED);
        mSmallChart.addView(chartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        if (mDeckChart.getVisibility() == View.INVISIBLE) {
            mDeckChart.setVisibility(View.VISIBLE);
            mDeckChart.setAnimation(ViewAnimation.fade(ViewAnimation.FADE_IN, 500, 0));
        }
    }
}

From source file:com.meiste.greg.ptw.tab.QuestionsAnswers.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    Util.log("QuestionsAnswers: onCreateView");

    final String qjson = getArguments().getString(RACE_QUESTIONS);
    if (qjson == null) {
        return null;
    }//from  w  ww .java2 s.c om
    final String ajson = getArguments().getString(RACE_ANSWERS);
    if (ajson == null) {
        return null;
    }
    final RaceQuestions rq = RaceQuestions.fromJson(qjson);
    final RaceAnswers ra = RaceAnswers.fromJson(ajson);
    final Resources res = getActivity().getResources();

    final View v = inflater.inflate(R.layout.questions_answered, container, false);

    final TextView q2 = (TextView) v.findViewById(R.id.question2);
    q2.setText(getActivity().getString(R.string.questions_2, rq.q2));

    final TextView q3 = (TextView) v.findViewById(R.id.question3);
    q3.setText(getActivity().getString(R.string.questions_3, rq.q3));

    final TextView a1 = (TextView) v.findViewById(R.id.answer1);
    a1.setText(Driver.find(rq.drivers, res, ra.a1).getName());

    final TextView a2 = (TextView) v.findViewById(R.id.answer2);
    a2.setText(rq.a2[ra.a2]);

    final TextView a3 = (TextView) v.findViewById(R.id.answer3);
    a3.setText(rq.a3[ra.a3]);

    final TextView a4 = (TextView) v.findViewById(R.id.answer4);
    a4.setText(Driver.find(rq.drivers, res, ra.a4).getName());

    final TextView a5 = (TextView) v.findViewById(R.id.answer5);
    a5.setText(res.getStringArray(R.array.num_leaders)[ra.a5]);

    final String cajson = getArguments().getString(RACE_CORRECT_ANSWERS);
    if (cajson != null) {
        Util.log("QuestionsAnswers: Correct answers available");
        final RaceAnswers rca = RaceAnswers.fromJson(cajson);

        // Have to check for null in case there is no correct answer
        if ((rca.a1 != null) && (rca.a1 >= 0)) {
            if (rca.a1 == ra.a1) {
                a1.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a1.setPaintFlags(a1.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a1.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c1 = (TextView) v.findViewById(R.id.correct1);
                c1.setText(Driver.find(rq.drivers, res, rca.a1).getName());
                c1.setVisibility(View.VISIBLE);
            }
        }
        if ((rca.a2 != null) && (rca.a2 >= 0)) {
            if (rca.a2 == ra.a2) {
                a2.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a2.setPaintFlags(a2.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a2.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c2 = (TextView) v.findViewById(R.id.correct2);
                c2.setText(rq.a2[rca.a2]);
                c2.setVisibility(View.VISIBLE);
            }
        }
        if ((rca.a3 != null) && (rca.a3 >= 0)) {
            if (rca.a3 == ra.a3) {
                a3.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a3.setPaintFlags(a3.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a3.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c3 = (TextView) v.findViewById(R.id.correct3);
                c3.setText(rq.a3[rca.a3]);
                c3.setVisibility(View.VISIBLE);
            }
        }
        if ((rca.a4 != null) && (rca.a4 >= 0)) {
            if (rca.a4 == ra.a4) {
                a4.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a4.setPaintFlags(a4.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a4.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c4 = (TextView) v.findViewById(R.id.correct4);
                c4.setText(Driver.find(rq.drivers, res, rca.a4).getName());
                c4.setVisibility(View.VISIBLE);
            }
        }
        if ((rca.a5 != null) && (rca.a5 >= 0)) {
            if (rca.a5 == ra.a5) {
                a5.setTextColor(res.getColor(R.color.answer_right));
            } else {
                a5.setPaintFlags(a5.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                a5.setTextColor(res.getColor(R.color.answer_wrong));
                final TextView c5 = (TextView) v.findViewById(R.id.correct5);
                c5.setText(res.getStringArray(R.array.num_leaders)[rca.a5]);
                c5.setVisibility(View.VISIBLE);
            }
        }
    }

    return v;
}

From source file:com.github.omadahealth.slidepager.lib.views.ProgressView.java

/**
 * Loads the styles and attributes defined in the xml tag of this class
 *
 * @param attributes The attributes to read from, do not pass {@link AttributeSet} as inflation needs the context of the {@link android.support.v4.view.PagerAdapter}
 *///from  w ww. j  a va2s. c om
public ProgressView loadStyledAttributes(TypedArray attributes, ProgressAttr progress) {
    mAttributes = attributes;
    mProgressAttr = progress;

    mIsSpecial = progress != null && progress.isSpecial();
    mIsFuture = progress != null && progress.isFuture();
    mCompletedDrawable = progress == null ? null : progress.getCompletedDrawable();

    Resources res = getContext().getResources();
    if (attributes != null) {
        mShowStreaks = attributes.getBoolean(R.styleable.SlidePager_slide_show_streaks, true);
        mShowProgressText = attributes.getBoolean(R.styleable.SlidePager_slide_show_progress_text, true);
        mShowProgressPlusMark = attributes.getBoolean(R.styleable.SlidePager_slide_show_progress_plusmark,
                true);
        mHasToReanimate = mAttributes.getBoolean(R.styleable.SlidePager_slide_pager_reanimate_slide_view, true);

        mCompletedColor = progress != null && progress.getCompletedColor() != null
                ? progress.getCompletedColor()
                : attributes.getColor(R.styleable.SlidePager_slide_progress_completed_reach_color,
                        res.getColor(R.color.default_progress_completed_reach_color));

        mCompletedFillColor = progress != null && progress.getCompletedFillColor() != null
                ? progress.getCompletedFillColor()
                : attributes.getColor(R.styleable.SlidePager_slide_progress_completed_fill_color,
                        res.getColor(R.color.default_progress_completed_fill_color));

        mNotCompletedReachColor = progress != null && progress.getReachedColor() != null
                ? progress.getReachedColor()
                : attributes.getColor(R.styleable.SlidePager_slide_progress_not_completed_reach_color,
                        res.getColor(R.color.default_progress_not_completed_reach_color));

        mNotCompletedOutlineColor = attributes.getColor(
                R.styleable.SlidePager_slide_progress_not_completed_outline_color,
                res.getColor(R.color.default_progress_not_completed_outline_color));
        mNotCompletedOutlineSize = attributes.getDimension(
                R.styleable.SlidePager_slide_progress_not_completed_outline_size,
                res.getDimension(R.dimen.circular_bar_default_outline_width));
        mNotCompletedFutureOutlineSize = attributes.getDimension(
                R.styleable.SlidePager_slide_progress_not_completed_future_outline_size,
                res.getDimension(R.dimen.circular_bar_default_future_outline_width));
        mNotCompletedFillColor = attributes.getColor(
                R.styleable.SlidePager_slide_progress_not_completed_fill_color,
                res.getColor(R.color.default_progress_not_completed_fill_color));

        mSpecialReachColor = attributes.getColor(R.styleable.SlidePager_slide_progress_special_reach_color,
                res.getColor(R.color.default_progress_special_reach_color));
        mSpecialOutlineColor = attributes.getColor(R.styleable.SlidePager_slide_progress_special_outline_color,
                res.getColor(R.color.default_progress_special_outline_color));
        mSpecialFillColor = attributes.getColor(R.styleable.SlidePager_slide_progress_special_fill_color,
                res.getColor(R.color.default_progress_special_fill_color));

        mProgressTextColor = attributes.getColor(R.styleable.SlidePager_slide_progress_text_color,
                res.getColor(R.color.default_progress_text_color));

        mReachedWidth = attributes.getDimension(R.styleable.SlidePager_slide_progress_reached_width,
                res.getDimension(R.dimen.default_progress_reached_width));
        //Do not recycle attributes, we need them for the future views
    } else {
        mShowStreaks = true;
        mShowProgressText = true;
        mShowProgressPlusMark = true;
        mHasToReanimate = true;

        mCompletedColor = progress != null && progress.getCompletedColor() != null
                ? progress.getCompletedColor()
                : res.getColor(R.color.default_progress_completed_reach_color);
        mCompletedFillColor = res.getColor(R.color.default_progress_completed_fill_color);

        mNotCompletedReachColor = res.getColor(R.color.default_progress_not_completed_reach_color);
        mNotCompletedOutlineColor = res.getColor(R.color.default_progress_not_completed_outline_color);
        mNotCompletedOutlineSize = res.getDimension(R.dimen.circular_bar_default_outline_width);
        mNotCompletedFutureOutlineSize = res.getDimension(R.dimen.circular_bar_default_future_outline_width);
        mNotCompletedFillColor = res.getColor(R.color.default_progress_not_completed_fill_color);

        mSpecialReachColor = res.getColor(R.color.default_progress_special_reach_color);
        mSpecialOutlineColor = res.getColor(R.color.default_progress_special_outline_color);
        mSpecialFillColor = res.getColor(R.color.default_progress_special_fill_color);

        mProgressTextColor = res.getColor(R.color.default_progress_text_color);

        mReachedWidth = res.getDimension(R.dimen.default_progress_reached_width);
    }
    loadProgressTextLabels(res);

    setCircleColorsAndSize();

    initAnimations();

    return this;
}

From source file:com.htc.dotdesign.ToolBoxService.java

private void updateBrushColor() {
    Resources resources = getResources();
    ImageView button = null;/*  w  ww.ja v a2  s  .  co m*/
    GradientDrawable drawable = null;

    View extendView = null;
    if (mCurrFun == FunType.Fun_Palette) {
        extendView = mPalette;
    } else {
        extendView = mEraser;
    }
    if (extendView != null) {
        button = (ImageView) extendView.findViewById(R.id.btn_1x1);
        if (button != null) {
            //drawable = (GradientDrawable) button.getBackground();
            drawable = (GradientDrawable) button.getDrawable();
            if (mCurrBrushSize == BrushSize.Size_1x1) {
                drawable.setColor(resources.getColor(R.color.brush_size_enable_color));
            } else if (mCurrBrushSize == BrushSize.Size_2x2) {
                drawable.setColor(resources.getColor(R.color.brush_size_disable_color));
            }
        }

        button = (ImageView) extendView.findViewById(R.id.btn_2x2);
        if (button != null) {
            //drawable = (GradientDrawable) button.getBackground();
            drawable = (GradientDrawable) button.getDrawable();
            if (mCurrBrushSize == BrushSize.Size_1x1) {
                drawable.setColor(resources.getColor(R.color.brush_size_disable_color));
            } else if (mCurrBrushSize == BrushSize.Size_2x2) {
                drawable.setColor(resources.getColor(R.color.brush_size_enable_color));
            }
        }
    }
}

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  ww  w  .jav  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());

    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());/*from w w w.  j a va2s.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 ww  w. ja  va 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());

    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.android.volley.ui.PhotoView.java

/**
 * Initializes the header and any static values
 *//*from   www.  j ava  2s  .  c o  m*/
private void initialize() {
    Context context = getContext();

    if (!sInitialized) {
        sInitialized = true;

        Resources resources = context.getApplicationContext().getResources();

        sCropSize = resources.getDimensionPixelSize(R.dimen.photo_crop_width);

        sCropDimPaint = new Paint();
        sCropDimPaint.setAntiAlias(true);
        sCropDimPaint.setColor(resources.getColor(R.color.photo_crop_dim_color));
        sCropDimPaint.setStyle(Style.FILL);

        sCropPaint = new Paint();
        sCropPaint.setAntiAlias(true);
        sCropPaint.setColor(resources.getColor(R.color.photo_crop_highlight_color));
        sCropPaint.setStyle(Style.STROKE);
        sCropPaint.setStrokeWidth(resources.getDimension(R.dimen.photo_crop_stroke_width));

        final ViewConfiguration configuration = ViewConfiguration.get(context);
        final int touchSlop = configuration.getScaledTouchSlop();
        sTouchSlopSquare = touchSlop * touchSlop;
    }

    mGestureDetector = new GestureDetectorCompat(context, this, null);
    mScaleGetureDetector = new ScaleGestureDetector(context, this);
    mQuickScaleEnabled = ScaleGestureDetectorCompat.isQuickScaleEnabled(mScaleGetureDetector);
    mScaleRunnable = new ScaleRunnable(this);
    mTranslateRunnable = new TranslateRunnable(this);
    mSnapRunnable = new SnapRunnable(this);
    mRotateRunnable = new RotateRunnable(this);
}

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());/*from  w w w . j  a v a  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());

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