Search in sources :

Example 11 with Sensor

use of android.hardware.Sensor in project JieCaoVideoPlayer by lipangit.

the class ListViewNormalActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    sensorManager.registerListener(sensorEventListener, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
Also used : Sensor(android.hardware.Sensor)

Example 12 with Sensor

use of android.hardware.Sensor in project NotificationPeekPort by lzanita09.

the class SensorHelper method checkSensorStatus.

/**
     * Check if the given sensor is presented in the device and/or the user choose to use it.
     *
     * @param context           Context instance.
     * @param sensor            Sensor type, can be {@link SensorHelper#SENSOR_GYRO}
     *                          or {@link SensorHelper#SENSOR_PROXIMITY_LIGHT}
     * @param combinePreference Boolean value for whether we need to check the preference or not.
     * @return
     */
public static boolean checkSensorStatus(Context context, int sensor, boolean combinePreference) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    switch(sensor) {
        case SENSOR_PROXIMITY_LIGHT:
            Sensor proxSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) != null ? sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) : sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
            return proxSensor != null && (preferences.getBoolean(PreferenceKeys.PREF_PROX_LIGHT_SENSOR, true) || !combinePreference);
        case SENSOR_GYRO:
            Sensor gyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
            return gyroSensor != null && (preferences.getBoolean(PreferenceKeys.PREF_GYRO_SENSOR, true) || !combinePreference);
        default:
            return false;
    }
}
Also used : SensorManager(android.hardware.SensorManager) SharedPreferences(android.content.SharedPreferences) Sensor(android.hardware.Sensor)

Example 13 with Sensor

use of android.hardware.Sensor in project love-android by hagish.

the class LuanPhone method InitLib.

// ***** ***** ***** ***** ***** init 
public LuaTable InitLib() {
    LuaTable t = LuaValue.tableOf();
    LuaValue _G = vm.get_G();
    _G.set(sMetaName_LuanSensor, LuanObjSensor.CreateMetaTable(this));
    // TODO: add phone/android/iphone specific api additions here, e.g. multi-touch event stuff, accelerometer, gravity sensor, maybe intent/running apps/network/start browser etc ?
    /// img = love.phone.newResourceImage(int iResID)
    /// loads an image from a resource id
    t.set("newResourceImage", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            int iResID = args.checkint(1);
            try {
                return LuaValue.userdataOf(new LuanObjImage(vm.getLuanGraphics(), iResID), vm.get_G().get(LuanGraphics.sMetaName_LuanImage));
            } catch (Exception e) {
                vm.handleError(e);
            }
            return LuaValue.NONE;
        }
    });
    /// source = love.phone.newResourceAudioSource(int iResID,string type)
    /// loads a sound/music/audio source from a resource id
    t.set("newResourceAudioSource", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            int iResID = args.checkint(1);
            try {
                String sType = IsArgSet(args, 2) ? args.checkjstring(2) : "static";
                return LuaValue.userdataOf(new LuanAudio.LuanObjSource(vm.getLuanAudio(), iResID, sType), vm.get_G().get(LuanAudio.sMetaName_LuanSource));
            } catch (Exception e) {
                vm.handleError(e);
            }
            return LuaValue.NONE;
        }
    });
    // TODO: newResourceFontTTF !!!
    /// source = love.phone.newResourceFontTTF(int iResID,int iSize)
    /// loads a ttf from ressource id
    /// String 	love.phone.getPackageName()
    /// Return the name of this application's package.
    t.set("getPackageName", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.valueOf(vm.getActivity().getPackageName());
        }
    });
    /// String 	love.phone.getResourceName(int iResID)
    /// Return the full name for a given resource identifier.
    t.set("getResourceName", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            try {
                return LuaValue.valueOf(vm.getResources().getResourceName(args.checkint(1)));
            } catch (Exception e) {
                vm.handleError(e);
            }
            return LuaValue.NONE;
        }
    });
    /// iResID = love.phone.getResourceID(String name, String defType, String defPackage)
    /// @name 	The name of the desired resource.
    /// @defType 	Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type.
    /// @defPackage 	Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package.
    t.set("getResourceID", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            return LuaValue.valueOf(vm.getResources().getIdentifier(args.checkjstring(1), IsArgSet(args, 2) ? args.checkjstring(2) : null, IsArgSet(args, 3) ? args.checkjstring(3) : null));
        }
    });
    // int 	getIdentifier(String name, String defType, String defPackage)
    /// {sensor,..} = love.phone.getSensorList(iSensorType)
    /// see also love.phone.SENSOR_TYPE
    t.set("getSensorList", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            List<Sensor> myList = vm.getSensorManager().getSensorList(args.checkint(1));
            LuaTable t = new LuaTable(myList.size(), 0);
            for (int i = 0; i < myList.size(); ++i) t.set(i + 1, LuaValue.userdataOf(new LuanObjSensor(LuanPhone.this, myList.get(i)), vm.get_G().get(sMetaName_LuanSensor)));
            return t;
        }
    });
    /// sensor = love.phone.getDefaultSensor(iSensorType)
    /// see also love.phone.SENSOR_TYPE
    t.set("getDefaultSensor", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            Sensor s = vm.getSensorManager().getDefaultSensor(args.checkint(1));
            return LuaValue.userdataOf(new LuanObjSensor(LuanPhone.this, s), vm.get_G().get(sMetaName_LuanSensor));
        }
    });
    /// love.phone.enableTouchEvents()
    /// enable love.phone.touch(...) callback
    t.set("enableTouchEvents", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            mbEnableTouchEvents = true;
            return LuaValue.NONE;
        }
    });
    /// boolean love.phone.registerSensorListener(sensor,rate)
    /// Registers a SensorEventListener for the given sensor.
    t.set("registerSensorListener", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            LuanObjSensor s = (LuanObjSensor) args.checkuserdata(1, LuanObjSensor.class);
            int rate = args.checkint(2);
            return LuaValue.valueOf(vm.getSensorManager().registerListener(s, s.getSensor(), rate));
        }
    });
    /// love.phone.setBlockMainKey_Back(bBlocked)
    t.set("setBlockMainKey_Back", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            ((LoveAndroid) vm.getActivity()).setBlockMainKey_Back(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    /// love.phone.setBlockMainKey_Menu(bBlocked)
    t.set("setBlockMainKey_Menu", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            ((LoveAndroid) vm.getActivity()).setBlockMainKey_Menu(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    /// love.phone.setBlockMainKey_Search(bBlocked)
    t.set("setBlockMainKey_Search", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            ((LoveAndroid) vm.getActivity()).setBlockMainKey_Search(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    /// love.phone.setHapticFeedbackEnabled(bEnabled)
    t.set("setHapticFeedbackEnabled", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.getView().setHapticFeedbackEnabled(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    /// love.phone.performHapticFeedback(feedbackConstant)
    /// see also FEEDBACK_CONSTANT
    t.set("performHapticFeedback", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.getView().performHapticFeedback(args.checkint(1));
            return LuaValue.NONE;
        }
    });
    /// love.phone.setKeepScreenOn(bool bKeepScreenOn)
    t.set("setKeepScreenOn", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.setKeepScreenOn(args.checkboolean(1));
            return LuaValue.NONE;
        }
    });
    /// love.phone.setRequestedOrientation(requestedOrientation)
    /// string param : behind,full_sensor,landscape,nosensor,portrait,reverse_landscape,reverse_portrait,sensor,sensor_landscape,sensor_portrait,unspecified,user
    /// for param meaning see also http://developer.android.com/reference/android/content/pm/ActivityInfo.html
    /// numeric parameter are still supported but are discouraged, see SCREEN_ORIENTATION
    t.set("setRequestedOrientation", new VarArgFunction() {

        @Override
        public Varargs invoke(Varargs args) {
            vm.getActivity().setRequestedOrientation(args.isstring(1) ? Str2ScreenOrientation(args.checkjstring(1)) : args.checkint(1));
            return LuaValue.NONE;
        }
    });
    /// love.phone.SCREEN_ORIENTATION = {[name]=value,...}
    /// see also http://developer.android.com/reference/android/content/pm/ActivityInfo.html
    {
        LuaTable c = new LuaTable();
        t.set("SCREEN_ORIENTATION", c);
        ///< 	Constant corresponding to behind in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_BEHIND", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND);
        //~ c.set("SCREEN_ORIENTATION_FULL_SENSOR",			android.content.pm.ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR	); ///< 	Constant corresponding to fullSensor in the screenOrientation attribute.
        ///< 	Constant corresponding to landscape in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_LANDSCAPE", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        ///< 	Constant corresponding to nosensor in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_NOSENSOR", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
        ///< 	Constant corresponding to portrait in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_PORTRAIT", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        //~ c.set("SCREEN_ORIENTATION_REVERSE_LANDSCAPE",	android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE	); ///< 	Constant corresponding to reverseLandscape in the screenOrientation attribute.
        //~ c.set("SCREEN_ORIENTATION_REVERSE_PORTRAIT",	android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT	); ///< 	Constant corresponding to reversePortrait in the screenOrientation attribute.
        ///< 	Constant corresponding to sensor in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_SENSOR", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        //~ c.set("SCREEN_ORIENTATION_SENSOR_LANDSCAPE",	android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE	); ///< 	Constant corresponding to sensorLandscape in the screenOrientation attribute.
        //~ c.set("SCREEN_ORIENTATION_SENSOR_PORTRAIT",		android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT	); ///< 	Constant corresponding to sensorPortrait in the screenOrientation attribute.
        ///< 	Constant corresponding to unspecified in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_UNSPECIFIED", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        ///< 	Constant corresponding to user in the screenOrientation attribute.
        c.set("SCREEN_ORIENTATION_USER", android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER);
    }
    /// love.phone.FEEDBACK_CONSTANT = {[name]=value,...}
    /// see also http://developer.android.com/reference/android/view/HapticFeedbackConstants.html
    {
        LuaTable c = new LuaTable();
        t.set("FEEDBACK_CONSTANT", c);
        ///< Flag for View.performHapticFeedback(int, int): Ignore the global setting for whether to perform haptic feedback, do it always.
        c.set("FLAG_IGNORE_GLOBAL_SETTING", android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
        ///< Flag for View.performHapticFeedback(int, int): Ignore the setting in the view for whether to perform haptic feedback, do it always.
        c.set("FLAG_IGNORE_VIEW_SETTING", android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
        //~ c.set("KEYBOARD_TAP",				android.view.HapticFeedbackConstants.KEYBOARD_TAP 					); ///< The user has pressed a soft keyboard key.	// FIXME: cannot be resolved or is not a field
        ///< The user has performed a long press on an object that is resulting in an action being performed.
        c.set("LONG_PRESS", android.view.HapticFeedbackConstants.LONG_PRESS);
        ///< The user has pressed on a virtual on-screen key.
        c.set("VIRTUAL_KEY", android.view.HapticFeedbackConstants.VIRTUAL_KEY);
    }
    /// love.phone.SENSOR_TYPE = {[name]=value,...}
    /// see also http://developer.android.com/reference/android/hardware/Sensor.html
    /// see also http://developer.android.com/reference/android/hardware/SensorEvent.html#values
    {
        LuaTable c = new LuaTable();
        t.set("SENSOR_TYPE", c);
        c.set("TYPE_ACCELEROMETER", Sensor.TYPE_ACCELEROMETER);
        c.set("TYPE_ALL", Sensor.TYPE_ALL);
        //~ c.set(	"TYPE_AMBIENT_TEMPERATURE",		Sensor.TYPE_AMBIENT_TEMPERATURE	); // FIXME: cannot be resolved or is not a field
        //~ c.set(	"TYPE_GRAVITY",					Sensor.TYPE_GRAVITY				); // FIXME: cannot be resolved or is not a field
        c.set("TYPE_GYROSCOPE", Sensor.TYPE_GYROSCOPE);
        c.set("TYPE_LIGHT", Sensor.TYPE_LIGHT);
        //~ c.set(	"TYPE_LINEAR_ACCELERATION",		Sensor.TYPE_LINEAR_ACCELERATION	); // FIXME: cannot be resolved or is not a field
        // compass
        c.set("TYPE_MAGNETIC_FIELD", Sensor.TYPE_MAGNETIC_FIELD);
        c.set("TYPE_ORIENTATION", Sensor.TYPE_ORIENTATION);
        c.set("TYPE_PRESSURE", Sensor.TYPE_PRESSURE);
        c.set("TYPE_PROXIMITY", Sensor.TYPE_PROXIMITY);
    //~ c.set(	"TYPE_RELATIVE_HUMIDITY",		Sensor.TYPE_RELATIVE_HUMIDITY	); // FIXME: cannot be resolved or is not a field
    //~ c.set(	"TYPE_ROTATION_VECTOR",			Sensor.TYPE_ROTATION_VECTOR		); // FIXME: cannot be resolved or is not a field
    }
    /// love.phone.MOTION_EVENT_ACTION_TYPE = {[name]=value,...} 
    /// e.g. love.phone.touch(..) event
    /// see also http://developer.android.com/reference/android/view/MotionEvent.html
    {
        LuaTable c = new LuaTable();
        t.set("MOTION_EVENT_ACTION_TYPE", c);
        c.set("ACTION_CANCEL", MotionEvent.ACTION_CANCEL);
        c.set("ACTION_DOWN", MotionEvent.ACTION_DOWN);
        c.set("ACTION_MASK", MotionEvent.ACTION_MASK);
        c.set("ACTION_MOVE", MotionEvent.ACTION_MOVE);
        c.set("ACTION_OUTSIDE", MotionEvent.ACTION_OUTSIDE);
        c.set("ACTION_POINTER_1_DOWN", MotionEvent.ACTION_POINTER_1_DOWN);
        c.set("ACTION_POINTER_1_UP", MotionEvent.ACTION_POINTER_1_UP);
        c.set("ACTION_POINTER_2_DOWN", MotionEvent.ACTION_POINTER_2_DOWN);
        c.set("ACTION_POINTER_2_UP", MotionEvent.ACTION_POINTER_2_UP);
        c.set("ACTION_POINTER_3_DOWN", MotionEvent.ACTION_POINTER_3_DOWN);
        c.set("ACTION_POINTER_3_UP", MotionEvent.ACTION_POINTER_3_UP);
        c.set("ACTION_POINTER_DOWN", MotionEvent.ACTION_POINTER_DOWN);
        c.set("ACTION_POINTER_ID_MASK", MotionEvent.ACTION_POINTER_ID_MASK);
        c.set("ACTION_POINTER_ID_SHIFT", MotionEvent.ACTION_POINTER_ID_SHIFT);
        c.set("ACTION_POINTER_UP", MotionEvent.ACTION_POINTER_UP);
        c.set("ACTION_UP", MotionEvent.ACTION_UP);
    }
    return t;
}
Also used : LuaTable(org.luaj.vm2.LuaTable) Varargs(org.luaj.vm2.Varargs) List(java.util.List) LuaValue(org.luaj.vm2.LuaValue) VarArgFunction(org.luaj.vm2.lib.VarArgFunction) LuanObjImage(net.schattenkind.androidLove.luan.obj.LuanObjImage) Sensor(android.hardware.Sensor)

Example 14 with Sensor

use of android.hardware.Sensor in project AndroidSDK-RecipeBook by gabu.

the class Recipe074 method onResume.

@Override
protected void onResume() {
    super.onResume();
    // 傾きセンサーを取得
    List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
    // 取得できなければ何もしない
    if (list.size() < 1)
        return;
    // 傾きセンサーを取得
    Sensor sensor = list.get(0);
    // 傾きセンサーにリスナーを登録
    // 第3引数で感度を指定できます。
    mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
Also used : Sensor(android.hardware.Sensor)

Example 15 with Sensor

use of android.hardware.Sensor in project AndroidSDK-RecipeBook by gabu.

the class Recipe075 method onResume.

@Override
protected void onResume() {
    super.onResume();
    // 地磁気センサーを取得
    List<Sensor> list = mSensorManager.getSensorList(Sensor.TYPE_MAGNETIC_FIELD);
    // 取得できなければ何もしない
    if (list.size() < 1)
        return;
    // 地磁気センサーを取得
    Sensor sensor = list.get(0);
    // 地磁気センサーにリスナーを登録
    // 第3引数で感度を指定できます。
    mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
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