Search in sources :

Example 1 with Sensor

use of android.hardware.Sensor in project CoCoin by Nightonke.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mContext = this;
    //        Bmob.initialize(CoCoinApplication.getAppContext(), CoCoin.APPLICATION_ID);
    //        CrashReport.initCrashReport(CoCoinApplication.getAppContext(), "900016815", false);
    //        RecordManager.getInstance(CoCoinApplication.getAppContext());
    //        CoCoinUtil.init(CoCoinApplication.getAppContext());
    appUpdateManager = new AppUpdateManager(mContext);
    appUpdateManager.checkUpdateInfo(false);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    Sensor magneticSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    sensorManager.registerListener(listener, magneticSensor, SensorManager.SENSOR_DELAY_GAME);
    sensorManager.registerListener(listener, accelerometerSensor, SensorManager.SENSOR_DELAY_GAME);
    superToast = new SuperToast(this);
    superActivityToast = new SuperActivityToast(this, SuperToast.Type.PROGRESS_HORIZONTAL);
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    Log.d("Saver", "Version number: " + currentapiVersion);
    if (currentapiVersion >= Build.VERSION_CODES.LOLLIPOP) {
        // Do something for lollipop and above versions
        Window window = this.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(ContextCompat.getColor(mContext, R.color.statusBarColor));
    } else {
    // do something for phones running an SDK before lollipop
    }
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        SettingManager.getInstance().setLoggenOn(true);
        SettingManager.getInstance().setUserName(user.getUsername());
        SettingManager.getInstance().setUserEmail(user.getEmail());
        showToast(WELCOME_BACK);
    // 允许用户使用应用
    } else {
        SettingManager.getInstance().setLoggenOn(false);
    //缓存用户对象为空时, 可打开用户注册界面…
    }
    guillotineBackground = findViewById(R.id.guillotine_background);
    toolBarTitle = (TextView) findViewById(R.id.guillotine_title);
    toolBarTitle.setTypeface(CoCoinUtil.typefaceLatoLight);
    toolBarTitle.setText(SettingManager.getInstance().getAccountBookName());
    // edit viewpager///////////////////////////////////////////////////////////////////////////////////
    editViewPager = (CoCoinScrollableViewPager) findViewById(R.id.edit_pager);
    editAdapter = new EditMoneyRemarkFragmentAdapter(getSupportFragmentManager(), CoCoinFragmentManager.MAIN_ACTIVITY_FRAGMENT);
    editViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (position == 1) {
                if (CoCoinFragmentManager.mainActivityEditRemarkFragment != null)
                    CoCoinFragmentManager.mainActivityEditRemarkFragment.editRequestFocus();
            } else {
                if (CoCoinFragmentManager.mainActivityEditMoneyFragment != null)
                    CoCoinFragmentManager.mainActivityEditMoneyFragment.editRequestFocus();
            }
        }

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    editViewPager.setAdapter(editAdapter);
    // tag viewpager////////////////////////////////////////////////////////////////////////////////////
    tagViewPager = (ViewPager) findViewById(R.id.viewpager);
    if (RecordManager.getInstance(mContext).TAGS.size() % 8 == 0)
        tagAdapter = new TagChooseFragmentAdapter(getSupportFragmentManager(), RecordManager.TAGS.size() / 8);
    else
        tagAdapter = new TagChooseFragmentAdapter(getSupportFragmentManager(), RecordManager.TAGS.size() / 8 + 1);
    tagViewPager.setAdapter(tagAdapter);
    // button grid view/////////////////////////////////////////////////////////////////////////////////
    myGridView = (MyGridView) findViewById(R.id.gridview);
    myGridViewAdapter = new ButtonGridViewAdapter(this);
    myGridView.setAdapter(myGridViewAdapter);
    myGridView.setOnItemClickListener(gridViewClickListener);
    myGridView.setOnItemLongClickListener(gridViewLongClickListener);
    myGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            myGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            View lastChild = myGridView.getChildAt(myGridView.getChildCount() - 1);
            myGridView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, lastChild.getBottom()));
            ViewGroup.LayoutParams params = transparentLy.getLayoutParams();
            params.height = myGridView.getMeasuredHeight();
        }
    });
    ButterKnife.inject(this);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(null);
    }
    toolbar.hideOverflowMenu();
    guillotineMenu = LayoutInflater.from(this).inflate(R.layout.guillotine, null);
    root.addView(guillotineMenu);
    transparentLy = (LinearLayout) guillotineMenu.findViewById(R.id.transparent_ly);
    guillotineColorLy = (LinearLayout) guillotineMenu.findViewById(R.id.guillotine_color_ly);
    guillotineToolBar = (Toolbar) guillotineMenu.findViewById(R.id.toolbar);
    menuToolBarTitle = (TextView) guillotineMenu.findViewById(R.id.guillotine_title);
    menuToolBarTitle.setTypeface(CoCoinUtil.typefaceLatoLight);
    menuToolBarTitle.setText(SettingManager.getInstance().getAccountBookName());
    radioButton0 = (RadioButton) guillotineMenu.findViewById(R.id.radio_button_0);
    radioButton1 = (RadioButton) guillotineMenu.findViewById(R.id.radio_button_1);
    radioButton2 = (RadioButton) guillotineMenu.findViewById(R.id.radio_button_2);
    radioButton3 = (RadioButton) guillotineMenu.findViewById(R.id.radio_button_3);
    passwordTip = (TextView) guillotineMenu.findViewById(R.id.password_tip);
    passwordTip.setText(mContext.getResources().getString(R.string.password_tip));
    passwordTip.setTypeface(CoCoinUtil.typefaceLatoLight);
    radioButtonLy = (LinearLayout) guillotineMenu.findViewById(R.id.radio_button_ly);
    statusButton = (MaterialMenuView) guillotineMenu.findViewById(R.id.status_button);
    statusButton.setState(MaterialMenuDrawable.IconState.ARROW);
    statusButton.setOnClickListener(statusButtonOnClickListener);
    animation = new GuillotineAnimation.GuillotineBuilder(guillotineMenu, guillotineMenu.findViewById(R.id.guillotine_hamburger), contentHamburger).setStartDelay(RIPPLE_DURATION).setActionBarViewForAnimation(toolbar).setClosedOnStart(true).setGuillotineListener(new GuillotineListener() {

        @Override
        public void onGuillotineOpened() {
            isPassword = true;
        }

        @Override
        public void onGuillotineClosed() {
            isPassword = false;
            CoCoinFragmentManager.mainActivityEditMoneyFragment.editRequestFocus();
            radioButton0.setChecked(false);
            radioButton1.setChecked(false);
            radioButton2.setChecked(false);
            radioButton3.setChecked(false);
            inputPassword = "";
            statusButton.setState(MaterialMenuDrawable.IconState.ARROW);
        }
    }).build();
    toolbar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            animation.open();
        }
    });
    if (SettingManager.getInstance().getFirstTime()) {
        Intent intent = new Intent(mContext, ShowActivity.class);
        startActivity(intent);
    }
    if (SettingManager.getInstance().getShowMainActivityGuide()) {
        boolean wrapInScrollView = true;
        new MaterialDialog.Builder(this).title(R.string.guide).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).customView(R.layout.main_activity_guide, wrapInScrollView).positiveText(R.string.ok).show();
        SettingManager.getInstance().setShowMainActivityGuide(false);
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) SuperToast(com.github.johnpersano.supertoasts.SuperToast) ButtonGridViewAdapter(com.nightonke.saver.adapter.ButtonGridViewAdapter) ViewTreeObserver(android.view.ViewTreeObserver) TagChooseFragmentAdapter(com.nightonke.saver.adapter.TagChooseFragmentAdapter) Window(android.view.Window) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SuperActivityToast(com.github.johnpersano.supertoasts.SuperActivityToast) Intent(android.content.Intent) ViewPager(android.support.v4.view.ViewPager) CoCoinScrollableViewPager(com.nightonke.saver.ui.CoCoinScrollableViewPager) InjectView(butterknife.InjectView) View(android.view.View) MyGridView(com.nightonke.saver.ui.MyGridView) AdapterView(android.widget.AdapterView) MaterialMenuView(com.balysv.materialmenu.MaterialMenuView) TextView(android.widget.TextView) AppUpdateManager(com.nightonke.saver.model.AppUpdateManager) EditMoneyRemarkFragmentAdapter(com.nightonke.saver.adapter.EditMoneyRemarkFragmentAdapter) GuillotineListener(com.nightonke.saver.ui.guillotine.interfaces.GuillotineListener) Sensor(android.hardware.Sensor)

Example 2 with Sensor

use of android.hardware.Sensor in project jmonkeyengine by jMonkeyEngine.

the class AndroidSensorJoyInput method loadJoystick.

// Start of JoyInput methods
public Joystick loadJoystick(int joyId, InputManager inputManager) {
    SensorData sensorData;
    AndroidSensorJoystickAxis axis;
    AndroidSensorJoystick joystick = new AndroidSensorJoystick(inputManager, joyInput, joyId, "AndroidSensorsJoystick");
    List<Sensor> availSensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
    for (Sensor sensor : availSensors) {
        logger.log(Level.FINE, "{0} Sensor is available, Type: {1}, Vendor: {2}, Version: {3}", new Object[] { sensor.getName(), sensor.getType(), sensor.getVendor(), sensor.getVersion() });
    }
    // manually create orientation sensor data since orientation is not a physical sensor
    sensorData = new SensorData(Sensor.TYPE_ORIENTATION, null);
    sensorData.lastValues = new float[3];
    sensors.put(Sensor.TYPE_ORIENTATION, sensorData);
    axis = joystick.addAxis(SensorJoystickAxis.ORIENTATION_X, SensorJoystickAxis.ORIENTATION_X, joystick.getAxisCount(), FastMath.HALF_PI);
    // joystick y axis = rotation around device x axis
    joystick.setYAxis(axis);
    sensorData.axes.add(axis);
    axis = joystick.addAxis(SensorJoystickAxis.ORIENTATION_Y, SensorJoystickAxis.ORIENTATION_Y, joystick.getAxisCount(), FastMath.HALF_PI);
    // joystick x axis = rotation around device y axis
    joystick.setXAxis(axis);
    sensorData.axes.add(axis);
    axis = joystick.addAxis(SensorJoystickAxis.ORIENTATION_Z, SensorJoystickAxis.ORIENTATION_Z, joystick.getAxisCount(), FastMath.HALF_PI);
    sensorData.axes.add(axis);
    // add axes for physical sensors
    sensorData = initSensor(Sensor.TYPE_MAGNETIC_FIELD);
    if (sensorData != null) {
        sensorData.lastValues = new float[3];
        sensors.put(Sensor.TYPE_MAGNETIC_FIELD, sensorData);
    //            axis = joystick.addAxis(SensorJoystickAxis.MAGNETIC_X, "MagneticField_X", joystick.getAxisCount(), 1f);
    //            sensorData.axes.add(axis);
    //            axis = joystick.addAxis(SensorJoystickAxis.MAGNETIC_Y, "MagneticField_Y", joystick.getAxisCount(), 1f);
    //            sensorData.axes.add(axis);
    //            axis = joystick.addAxis(SensorJoystickAxis.MAGNETIC_Z, "MagneticField_Z", joystick.getAxisCount(), 1f);
    //            sensorData.axes.add(axis);
    }
    sensorData = initSensor(Sensor.TYPE_ACCELEROMETER);
    if (sensorData != null) {
        sensorData.lastValues = new float[3];
        sensors.put(Sensor.TYPE_ACCELEROMETER, sensorData);
    //            axis = joystick.addAxis(SensorJoystickAxis.ACCELEROMETER_X, "Accelerometer_X", joystick.getAxisCount(), 1f);
    //            sensorData.axes.add(axis);
    //            axis = joystick.addAxis(SensorJoystickAxis.ACCELEROMETER_Y, "Accelerometer_Y", joystick.getAxisCount(), 1f);
    //            sensorData.axes.add(axis);
    //            axis = joystick.addAxis(SensorJoystickAxis.ACCELEROMETER_Z, "Accelerometer_Z", joystick.getAxisCount(), 1f);
    //            sensorData.axes.add(axis);
    }
    //        sensorData = initSensor(Sensor.TYPE_GYROSCOPE);
    //        if (sensorData != null) {
    //            sensorData.lastValues = new float[3];
    //        }
    //
    //        sensorData = initSensor(Sensor.TYPE_GRAVITY);
    //        if (sensorData != null) {
    //            sensorData.lastValues = new float[3];
    //        }
    //
    //        sensorData = initSensor(Sensor.TYPE_LINEAR_ACCELERATION);
    //        if (sensorData != null) {
    //            sensorData.lastValues = new float[3];
    //        }
    //
    //        sensorData = initSensor(Sensor.TYPE_ROTATION_VECTOR);
    //        if (sensorData != null) {
    //            sensorData.lastValues = new float[4];
    //        }
    //
    //        sensorData = initSensor(Sensor.TYPE_PROXIMITY);
    //        if (sensorData != null) {
    //            sensorData.lastValues = new float[1];
    //        }
    //
    //        sensorData = initSensor(Sensor.TYPE_LIGHT);
    //        if (sensorData != null) {
    //            sensorData.lastValues = new float[1];
    //        }
    //
    //        sensorData = initSensor(Sensor.TYPE_PRESSURE);
    //        if (sensorData != null) {
    //            sensorData.lastValues = new float[1];
    //        }
    //
    //        sensorData = initSensor(Sensor.TYPE_TEMPERATURE);
    //        if (sensorData != null) {
    //            sensorData.lastValues = new float[1];
    //        }
    loaded = true;
    return joystick;
}
Also used : Sensor(android.hardware.Sensor)

Example 3 with Sensor

use of android.hardware.Sensor in project Android-Developers-Samples by johnjohndoe.

the class BatchStepSensorFragment method registerEventListener.

/**
     * Register a {@link android.hardware.SensorEventListener} for the sensor and max batch delay.
     * The maximum batch delay specifies the maximum duration in microseconds for which subsequent
     * sensor events can be temporarily stored by the sensor before they are delivered to the
     * registered SensorEventListener. A larger delay allows the system to handle sensor events more
     * efficiently, allowing the system to switch to a lower power state while the sensor is
     * capturing events. Once the max delay is reached, all stored events are delivered to the
     * registered listener. Note that this value only specifies the maximum delay, the listener may
     * receive events quicker. A delay of 0 disables batch mode and registers the listener in
     * continuous mode.
     * The optimium batch delay depends on the application. For example, a delay of 5 seconds or
     * higher may be appropriate for an  application that does not update the UI in real time.
     *
     * @param maxdelay
     * @param sensorType
     */
private void registerEventListener(int maxdelay, int sensorType) {
    // BEGIN_INCLUDE(register)
    // Keep track of state so that the correct sensor type and batch delay can be set up when
    // the app is restored (for example on screen rotation).
    mMaxDelay = maxdelay;
    if (sensorType == Sensor.TYPE_STEP_COUNTER) {
        mState = STATE_COUNTER;
        /*
            Reset the initial step counter value, the first event received by the event listener is
            stored in mCounterSteps and used to calculate the total number of steps taken.
             */
        mCounterSteps = 0;
        Log.i(TAG, "Event listener for step counter sensor registered with a max delay of " + mMaxDelay);
    } else {
        mState = STATE_DETECTOR;
        Log.i(TAG, "Event listener for step detector sensor registered with a max delay of " + mMaxDelay);
    }
    // Get the default sensor for the sensor type from the SenorManager
    SensorManager sensorManager = (SensorManager) getActivity().getSystemService(Activity.SENSOR_SERVICE);
    // sensorType is either Sensor.TYPE_STEP_COUNTER or Sensor.TYPE_STEP_DETECTOR
    Sensor sensor = sensorManager.getDefaultSensor(sensorType);
    // Register the listener for this sensor in batch mode.
    // If the max delay is 0, events will be delivered in continuous mode without batching.
    final boolean batchMode = sensorManager.registerListener(mListener, sensor, SensorManager.SENSOR_DELAY_NORMAL, maxdelay);
    if (!batchMode) {
        // Batch mode could not be enabled, show a warning message and switch to continuous mode
        getCardStream().getCard(CARD_NOBATCHSUPPORT).setDescription(getString(R.string.warning_nobatching));
        getCardStream().showCard(CARD_NOBATCHSUPPORT);
        Log.w(TAG, "Could not register sensor listener in batch mode, " + "falling back to continuous mode.");
    }
    if (maxdelay > 0 && batchMode) {
        // Batch mode was enabled successfully, show a description card
        getCardStream().showCard(CARD_BATCHING_DESCRIPTION);
    }
    // Show the explanation card
    getCardStream().showCard(CARD_EXPLANATION);
// END_INCLUDE(register)
}
Also used : SensorManager(android.hardware.SensorManager) Sensor(android.hardware.Sensor)

Example 4 with Sensor

use of android.hardware.Sensor in project SmartAndroidSource by jaychou2012.

the class SystemInfo method getSensor.

/**
	 * ����ֻ��ϵĴ��ڵ����д�����
	 * 
	 * @return �����ֻ��ϵ����д����������Ϣ
	 */
public String getSensor() {
    StringBuilder sb = new StringBuilder();
    // ��ϵͳ�����л�ô�����������
    SensorManager sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    // �Ӵ������������л��ȫ���Ĵ������б�
    List<Sensor> allSensors = sm.getSensorList(Sensor.TYPE_ALL);
    // ��ʾ�ж��ٸ�������
    sb.append("�������ֻ���" + allSensors.size() + "�������������Ƿֱ��ǣ�\n");
    for (Sensor s : allSensors) {
        String tempString = "\n" + " �豸���ƣ�" + s.getName() + "\n" + " �豸�汾��" + s.getVersion() + "\n" + " ��Ӧ�̣�" + s.getVendor() + "\n";
        switch(s.getType()) {
            case Sensor.TYPE_ACCELEROMETER:
                sb.append("����������ID��" + s.getType() + " ���ٶȴ�����accelerometer" + tempString);
                break;
            case Sensor.TYPE_GYROSCOPE:
                sb.append("����������ID��" + s.getType() + " �����Ǵ�����gyroscope" + tempString);
                break;
            case Sensor.TYPE_LIGHT:
                sb.append("����������ID��" + s.getType() + " �������ߴ�����light" + tempString);
                break;
            case Sensor.TYPE_MAGNETIC_FIELD:
                sb.append("����������ID��" + s.getType() + " ��ų�������magnetic field" + tempString);
                break;
            case Sensor.TYPE_ORIENTATION:
                sb.append("����������ID��" + s.getType() + " ���򴫸���orientation" + tempString);
                break;
            case Sensor.TYPE_PRESSURE:
                sb.append("����������ID��" + s.getType() + " ѹ��������pressure" + tempString);
                break;
            case Sensor.TYPE_PROXIMITY:
                sb.append("����������ID��" + s.getType() + " ���봫����proximity" + tempString);
                break;
            case Sensor.TYPE_TEMPERATURE:
                sb.append("����������ID��" + s.getType() + " �¶ȴ�����temperature" + tempString);
                break;
            default:
                sb.append("����������ID��" + s.getType() + " δ֪������" + tempString);
                break;
        }
    }
    return sb.toString();
}
Also used : SensorManager(android.hardware.SensorManager) Sensor(android.hardware.Sensor)

Example 5 with Sensor

use of android.hardware.Sensor in project AndEngine by nicolasgramlich.

the class Engine method registerSelfAsSensorListener.

private void registerSelfAsSensorListener(final SensorManager pSensorManager, final int pType, final SensorDelay pSensorDelay) {
    final Sensor sensor = pSensorManager.getSensorList(pType).get(0);
    pSensorManager.registerListener(this, sensor, pSensorDelay.getDelay());
}
Also used : Sensor(android.hardware.Sensor)

Aggregations

Sensor (android.hardware.Sensor)34 SensorEventListener (android.hardware.SensorEventListener)5 SensorManager (android.hardware.SensorManager)5 BatteryStats (android.os.BatteryStats)5 SensorEvent (android.hardware.SensorEvent)4 Handler (android.os.Handler)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 Window (android.view.Window)1 AdapterView (android.widget.AdapterView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 BmobUser (cn.bmob.v3.BmobUser)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 MaterialMenuView (com.balysv.materialmenu.MaterialMenuView)1 SuperActivityToast (com.github.johnpersano.supertoasts.SuperActivityToast)1