Example usage for android.hardware SensorManager GRAVITY_EARTH

List of usage examples for android.hardware SensorManager GRAVITY_EARTH

Introduction

In this page you can find the example usage for android.hardware SensorManager GRAVITY_EARTH.

Prototype

float GRAVITY_EARTH

To view the source code for android.hardware SensorManager GRAVITY_EARTH.

Click Source Link

Document

Earth's gravity in SI units (m/s^2)

Usage

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

private void initLayout(Integer layout) {
    setContentView(layout);/*w  w  w  . j  a v  a 2 s .  co m*/

    mMainLayout = findViewById(R.id.main_layout);
    Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER);

    mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
    setInAnimation(false);

    findViewById(R.id.top_bar).setOnClickListener(mCardStatisticsListener);

    mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
    mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
    mTouchLayer.setOnTouchListener(mGestureListener);
    if (mPrefTextSelection && mLongClickWorkaround) {
        mTouchLayer.setOnLongClickListener(mLongClickListener);
    }
    if (mPrefTextSelection) {
        mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    }
    mCardFrame.removeAllViews();
    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);
    }

    // Initialize swipe
    gestureDetector = new GestureDetector(new MyGestureDetector());

    mProgressBar = (ProgressBar) findViewById(R.id.flashcard_progressbar);

    // initialise shake detection
    if (mShakeEnabled) {
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
        mAccel = 0.00f;
        mAccelCurrent = SensorManager.GRAVITY_EARTH;
        mAccelLast = SensorManager.GRAVITY_EARTH;
    }

    Resources res = getResources();

    mEase1 = (Button) findViewById(R.id.ease1);
    mEase1.setTextColor(res.getColor(R.color.next_time_failed_color));
    mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1);
    mEase1Layout.setOnClickListener(mSelectEaseHandler);

    mEase2 = (Button) findViewById(R.id.ease2);
    mEase2.setTextColor(res.getColor(R.color.next_time_usual_color));
    mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2);
    mEase2Layout.setOnClickListener(mSelectEaseHandler);

    mEase3 = (Button) findViewById(R.id.ease3);
    mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3);
    mEase3Layout.setOnClickListener(mSelectEaseHandler);

    mEase4 = (Button) findViewById(R.id.ease4);
    mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4);
    mEase4Layout.setOnClickListener(mSelectEaseHandler);

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

    mTextBarRed = (TextView) findViewById(R.id.red_number);
    mTextBarBlack = (TextView) findViewById(R.id.black_number);
    mTextBarBlue = (TextView) findViewById(R.id.blue_number);

    if (mShowProgressBars) {
        mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar);
        mSessionProgressBar = (View) findViewById(R.id.session_progress);
        mProgressBars = (LinearLayout) findViewById(R.id.progress_bars);
    }

    mCardTimer = (Chronometer) findViewById(R.id.card_time);
    if (mShowProgressBars && mProgressBars.getVisibility() != View.VISIBLE) {
        switchVisibility(mProgressBars, View.VISIBLE);
    }

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

        mWhiteboard.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (mShowWhiteboard) {
                    return false;
                }
                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }
                return false;
            }
        });
    }
    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);
    if (mInvertedColors) {
        invertColors(true);
    }

    mLookUpIcon = findViewById(R.id.lookup_button);
    mLookUpIcon.setVisibility(View.GONE);
    mLookUpIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (clipboardHasText()) {
                lookUp();
            }
        }

    });
    initControls();
}

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

private void initLayout(Integer layout) {
    setContentView(layout);/*from  w  w  w  .  ja va 2  s.  com*/

    mMainLayout = findViewById(R.id.main_layout);
    Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER);

    mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
    setInAnimation(false);

    findViewById(R.id.top_bar).setOnClickListener(mCardStatisticsListener);

    mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
    mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
    mTouchLayer.setOnTouchListener(mGestureListener);
    if (mPrefTextSelection && mLongClickWorkaround) {
        mTouchLayer.setOnLongClickListener(mLongClickListener);
    }
    if (mPrefTextSelection) {
        mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    }
    mCardFrame.removeAllViews();
    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);
    }

    // Initialize swipe
    gestureDetector = new GestureDetector(new MyGestureDetector());

    mProgressBar = (ProgressBar) findViewById(R.id.flashcard_progressbar);

    // initialise shake detection
    if (mShakeEnabled) {
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
        mAccel = 0.00f;
        mAccelCurrent = SensorManager.GRAVITY_EARTH;
        mAccelLast = SensorManager.GRAVITY_EARTH;
    }

    Resources res = getResources();

    mEase1 = (Button) findViewById(R.id.ease1);
    mEase1.setTextColor(res.getColor(R.color.next_time_failed_color));
    mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1);
    mEase1Layout.setOnClickListener(mSelectEaseHandler);

    mEase2 = (Button) findViewById(R.id.ease2);
    mEase2.setTextColor(res.getColor(R.color.next_time_usual_color));
    mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2);
    mEase2Layout.setOnClickListener(mSelectEaseHandler);

    mEase3 = (Button) findViewById(R.id.ease3);
    mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3);
    mEase3Layout.setOnClickListener(mSelectEaseHandler);

    mEase4 = (Button) findViewById(R.id.ease4);
    mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4);
    mEase4Layout.setOnClickListener(mSelectEaseHandler);

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

    mTextBarRed = (TextView) findViewById(R.id.red_number);
    mTextBarBlack = (TextView) findViewById(R.id.black_number);
    mTextBarBlue = (TextView) findViewById(R.id.blue_number);

    if (!mShowRemainingCardCount) {
        mTextBarRed.setVisibility(View.GONE);
        mTextBarBlack.setVisibility(View.GONE);
        mTextBarBlue.setVisibility(View.GONE);
    }

    if (mShowProgressBars) {
        mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar);
        mSessionProgressBar = (View) findViewById(R.id.session_progress);
        mProgressBars = (LinearLayout) findViewById(R.id.progress_bars);
    }

    mCardTimer = (Chronometer) findViewById(R.id.card_time);
    if (mShowProgressBars && mProgressBars.getVisibility() != View.VISIBLE) {
        switchVisibility(mProgressBars, View.VISIBLE);
    }

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

        mWhiteboard.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (mShowWhiteboard) {
                    return false;
                }
                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }
                return false;
            }
        });
    }
    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);
    if (mInvertedColors) {
        invertColors(true);
    }

    mLookUpIcon = findViewById(R.id.lookup_button);
    mLookUpIcon.setVisibility(View.GONE);
    mLookUpIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (clipboardHasText()) {
                lookUp();
            }
        }

    });
    initControls();
}

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

private void initLayout(Integer layout) {
    setContentView(layout);/*from  www  .  j a  va 2 s  . c o  m*/

    mMainLayout = findViewById(R.id.main_layout);
    Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER);

    mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
    setInAnimation(false);

    findViewById(R.id.top_bar).setOnClickListener(mCardStatisticsListener);

    mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
    mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
    mTouchLayer.setOnTouchListener(mGestureListener);
    if (mPrefTextSelection && mLongClickWorkaround) {
        mTouchLayer.setOnLongClickListener(mLongClickListener);
    }
    if (mPrefTextSelection) {
        mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    }
    mCardFrame.removeAllViews();
    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);
    }

    // Initialize swipe
    gestureDetector = new GestureDetector(new MyGestureDetector());

    mProgressBar = (ProgressBar) findViewById(R.id.flashcard_progressbar);

    // initialise shake detection
    if (mShakeEnabled) {
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSensorManager.registerListener(mSensorListener,
                mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
        mAccel = 0.00f;
        mAccelCurrent = SensorManager.GRAVITY_EARTH;
        mAccelLast = SensorManager.GRAVITY_EARTH;
    }

    Resources res = getResources();

    mEase1 = (Button) findViewById(R.id.ease1);
    mEase1.setTextColor(res.getColor(R.color.next_time_failed_color));
    mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1);
    mEase1Layout.setOnClickListener(mSelectEaseHandler);

    mEase2 = (Button) findViewById(R.id.ease2);
    mEase2.setTextColor(res.getColor(R.color.next_time_usual_color));
    mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2);
    mEase2Layout.setOnClickListener(mSelectEaseHandler);

    mEase3 = (Button) findViewById(R.id.ease3);
    mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3);
    mEase3Layout.setOnClickListener(mSelectEaseHandler);

    mEase4 = (Button) findViewById(R.id.ease4);
    mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4);
    mEase4Layout.setOnClickListener(mSelectEaseHandler);

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

    mTextBarRed = (TextView) findViewById(R.id.red_number);
    mTextBarBlack = (TextView) findViewById(R.id.black_number);
    mTextBarBlue = (TextView) findViewById(R.id.blue_number);

    if (!mShowRemainingCardCount) {
        mTextBarRed.setVisibility(View.GONE);
        mTextBarBlack.setVisibility(View.GONE);
        mTextBarBlue.setVisibility(View.GONE);
    }

    if (mShowProgressBars) {
        mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar);
        mSessionProgressBar = (View) findViewById(R.id.session_progress);
        mProgressBars = (LinearLayout) findViewById(R.id.progress_bars);
    }

    mCardTimer = (Chronometer) findViewById(R.id.card_time);
    if (mShowProgressBars && mProgressBars.getVisibility() != View.VISIBLE) {
        //            switchVisibility(mProgressBars, View.VISIBLE);
    }

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

        mWhiteboard.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (mShowWhiteboard) {
                    return false;
                }
                if (gestureDetector.onTouchEvent(event)) {
                    return true;
                }
                return false;
            }
        });
    }
    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);
    if (mInvertedColors) {
        invertColors(true);
    }

    mLookUpIcon = findViewById(R.id.lookup_button);
    mLookUpIcon.setVisibility(View.GONE);
    mLookUpIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (clipboardHasText()) {
                lookUp();
            }
        }

    });
    initControls();
}