Search in sources :

Example 1 with MyGestureDetector

use of com.ichi2.anki.Reviewer.MyGestureDetector in project Anki-Android by Ramblurr.

the class PreviewClass method initLayout.

private void initLayout(Integer layout) {
    setContentView(layout);
    mMainLayout = findViewById(R.id.main_layout);
    Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER);
    mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
    //setInAnimation(false);
    mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
    mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
    mTouchLayer.setOnTouchListener(mGestureListener);
    gestureDetector = new GestureDetector(new MyGestureDetector());
    mCardFrame.removeAllViews();
    mCardFrame.setVisibility(View.GONE);
    mTouchLayer.setVisibility(View.GONE);
    if (!mChangeBorderStyle) {
        ((View) findViewById(R.id.flashcard_border)).setVisibility(View.VISIBLE);
    }
    // hunt for input issue 720, like android issue 3341
    if (AnkiDroidApp.SDK_VERSION <= 7 && (mCard != null)) {
        mCard.setFocusableInTouchMode(true);
    }
    Resources res = getResources();
    mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1);
    mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2);
    mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3);
    mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4);
    mNext1 = (TextView) findViewById(R.id.nextTime1);
    mNext2 = (TextView) findViewById(R.id.nextTime2);
    mNext3 = (TextView) findViewById(R.id.nextTime3);
    mNext4 = (TextView) findViewById(R.id.nextTime4);
    mNext1.setTextColor(res.getColor(R.color.next_time_failed_color));
    mNext2.setTextColor(res.getColor(R.color.next_time_usual_color));
    if (!mshowNextReviewTime) {
        ((TextView) findViewById(R.id.nextTimeflip)).setVisibility(View.GONE);
        mNext1.setVisibility(View.GONE);
        mNext2.setVisibility(View.GONE);
        mNext3.setVisibility(View.GONE);
        mNext4.setVisibility(View.GONE);
    }
    mFlipCard = (Button) findViewById(R.id.flip_card);
    mFlipCardLayout = (LinearLayout) findViewById(R.id.flashcard_layout_flip);
    mFlipCardLayout.setOnClickListener(mFlipCardListener);
    mFlipCard.setVisibility(View.GONE);
    mFlipCardLayout.setVisibility(View.GONE);
    mChosenAnswer = (TextView) findViewById(R.id.choosen_answer);
    if (mPrefWhiteboard) {
        mWhiteboard = new Whiteboard(this, mInvertedColors, mBlackWhiteboard);
        FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        mWhiteboard.setLayoutParams(lp2);
        FrameLayout fl = (FrameLayout) findViewById(R.id.whiteboard);
        fl.addView(mWhiteboard);
    }
    mAnswerField = (EditText) findViewById(R.id.answer_field);
    mNextTimeTextColor = getResources().getColor(R.color.next_time_usual_color);
    mNextTimeTextRecomColor = getResources().getColor(R.color.next_time_recommended_color);
    mForegroundColor = getResources().getColor(R.color.next_time_usual_color);
    try {
        top_bar = (RelativeLayout) findViewById(R.id.top_bar);
        top_bar.setVisibility(View.GONE);
    } catch (Exception er) {
        er.printStackTrace();
    }
    initControls();
}
Also used : LayoutParams(android.widget.FrameLayout.LayoutParams) LayoutParams(android.widget.FrameLayout.LayoutParams) FrameLayout(android.widget.FrameLayout) GestureDetector(android.view.GestureDetector) MyGestureDetector(com.ichi2.anki.Reviewer.MyGestureDetector) TextView(android.widget.TextView) ScrollTextView(com.ichi2.anki.Reviewer.ScrollTextView) Resources(android.content.res.Resources) MyGestureDetector(com.ichi2.anki.Reviewer.MyGestureDetector) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) ScrollTextView(com.ichi2.anki.Reviewer.ScrollTextView) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 2 with MyGestureDetector

use of com.ichi2.anki.Reviewer.MyGestureDetector in project Anki-Android by Ramblurr.

the class ChartBuilder method onCreate.

// public void setRenderer(int type, int row) {
// Resources res = getResources();
// XYSeriesRenderer renderer = new XYSeriesRenderer();
// if (type <= 2) {
// switch (row) {
// case 0:
// renderer.setColor(res.getColor(R.color.statistics_due_young_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_due_mature_cards));
// break;
// case 2:
// // renderer.setColor(res.getColor(R.color.statistics_due_failed_cards));
// break;
// }
// } else if (type == 3) {
// switch (row) {
// case 0:
// // renderer.setColor(res.getColor(R.color.statistics_reps_new_cards));
// break;
// case 1:
// renderer.setColor(res.getColor(R.color.statistics_reps_young_cards));
// break;
// case 2:
// renderer.setColor(res.getColor(R.color.statistics_reps_mature_cards));
// break;
// }
// } else {
// renderer.setColor(res.getColor(R.color.statistics_default));
// }
// mRenderer.addSeriesRenderer(renderer);
// }
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(AnkiDroidApp.TAG, "ChartBuilder.OnCreate");
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);
    restorePreferences();
    Resources res = getResources();
    Stats stats = Stats.currentStats();
    if (stats != null) {
        mSeriesList = stats.getSeriesList();
        mMeta = stats.getMetaInfo();
    } else if (savedInstanceState != null) {
        int len = savedInstanceState.getInt("seriesListLen");
        mSeriesList = new double[len][];
        for (int i = 0; i < len; i++) {
            mSeriesList[i] = (double[]) savedInstanceState.getSerializable("seriesList" + i);
        }
        mMeta = (Object[]) savedInstanceState.getSerializable("meta");
    } else {
        finish();
    }
    String title = res.getString((Integer) mMeta[1]);
    boolean backwards = (Boolean) mMeta[2];
    int[] valueLabels = (int[]) mMeta[3];
    int[] barColors = (int[]) mMeta[4];
    int[] axisTitles = (int[]) mMeta[5];
    String subTitle = (String) mMeta[6];
    if (mSeriesList == null || mSeriesList[0].length < 2) {
        Log.i(AnkiDroidApp.TAG, "ChartBuilder - Data variable empty, closing chartbuilder");
        finish();
        return;
    }
    if (mFullScreen) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    View mainView = getLayoutInflater().inflate(R.layout.statistics, null);
    setContentView(mainView);
    mainView.setBackgroundColor(Color.WHITE);
    mTitle = (TextView) findViewById(R.id.statistics_title);
    if (mChartView == null) {
        if (mFullScreen) {
            mTitle.setText(title);
            mTitle.setTextColor(Color.BLACK);
        } else {
            setTitle(title);
            AnkiDroidApp.getCompat().setSubtitle(this, subTitle);
            mTitle.setVisibility(View.GONE);
        }
        for (int i = 1; i < mSeriesList.length; i++) {
            XYSeries series = new XYSeries(res.getString(valueLabels[i - 1]));
            for (int j = 0; j < mSeriesList[i].length; j++) {
                series.add(mSeriesList[0][j], mSeriesList[i][j]);
            }
            mDataset.addSeries(series);
            XYSeriesRenderer renderer = new XYSeriesRenderer();
            renderer.setColor(res.getColor(barColors[i - 1]));
            mRenderer.addSeriesRenderer(renderer);
        }
        if (mSeriesList.length == 1) {
            mRenderer.setShowLegend(false);
        }
        if (backwards) {
            mPan = new double[] { mSeriesList[0][0] - 0.5, 0.5 };
        } else {
            mPan = new double[] { -0.5, mSeriesList[0][mSeriesList[0].length - 1] + 0.5 };
        }
        mRenderer.setLegendTextSize(17);
        mRenderer.setBarSpacing(0.4);
        mRenderer.setLegendHeight(60);
        mRenderer.setAxisTitleTextSize(17);
        mRenderer.setLabelsTextSize(17);
        mRenderer.setXAxisMin(mPan[0]);
        mRenderer.setXAxisMax(mPan[1]);
        mRenderer.setYAxisMin(0);
        mRenderer.setGridColor(Color.LTGRAY);
        mRenderer.setShowGrid(true);
        mRenderer.setXTitle(res.getStringArray(R.array.due_x_axis_title)[axisTitles[0]]);
        mRenderer.setYTitle(res.getString(axisTitles[1]));
        mRenderer.setBackgroundColor(Color.WHITE);
        mRenderer.setMarginsColor(Color.WHITE);
        mRenderer.setAxesColor(Color.BLACK);
        mRenderer.setLabelsColor(Color.BLACK);
        mRenderer.setYLabelsColor(0, Color.BLACK);
        mRenderer.setYLabelsAngle(-90);
        mRenderer.setXLabelsColor(Color.BLACK);
        mRenderer.setXLabelsAlign(Align.CENTER);
        mRenderer.setYLabelsAlign(Align.CENTER);
        mRenderer.setZoomEnabled(false, false);
        mRenderer.setMargins(new int[] { 15, 48, 30, 10 });
        mRenderer.setAntialiasing(true);
        mRenderer.setPanEnabled(true, false);
        mRenderer.setPanLimits(mPan);
        mChartView = ChartFactory.getBarChartView(this, mDataset, mRenderer, BarChart.Type.STACKED);
        LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
        layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    } else {
        mChartView.repaint();
    }
    gestureDetector = new GestureDetector(new MyGestureDetector());
    mChartView.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }
    });
}
Also used : XYSeries(org.achartengine.model.XYSeries) LayoutParams(android.view.ViewGroup.LayoutParams) GestureDetector(android.view.GestureDetector) View(android.view.View) GraphicalView(org.achartengine.GraphicalView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) Stats(com.ichi2.libanki.Stats) XYSeriesRenderer(org.achartengine.renderer.XYSeriesRenderer) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Aggregations

Resources (android.content.res.Resources)2 GestureDetector (android.view.GestureDetector)2 View (android.view.View)2 TextView (android.widget.TextView)2 MotionEvent (android.view.MotionEvent)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 WebView (android.webkit.WebView)1 FrameLayout (android.widget.FrameLayout)1 LayoutParams (android.widget.FrameLayout.LayoutParams)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 MyGestureDetector (com.ichi2.anki.Reviewer.MyGestureDetector)1 ScrollTextView (com.ichi2.anki.Reviewer.ScrollTextView)1 Stats (com.ichi2.libanki.Stats)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 GraphicalView (org.achartengine.GraphicalView)1 XYSeries (org.achartengine.model.XYSeries)1 XYSeriesRenderer (org.achartengine.renderer.XYSeriesRenderer)1