Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Created May 19, 2020 23:21
Show Gist options
  • Save jtmuller5/82a576d1f7f144a1b2ae522ab6ada685 to your computer and use it in GitHub Desktop.
Save jtmuller5/82a576d1f7f144a1b2ae522ab6ada685 to your computer and use it in GitHub Desktop.
class HomeFragment : Fragment() {
private lateinit var homeViewModel: HomeViewModel
private lateinit var sensorManager: SensorManager
lateinit var main: MainActivity
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
main = requireActivity() as MainActivity
sensorManager = main.getSystemService(Context.SENSOR_SERVICE) as SensorManager
homeViewModel =
ViewModelProviders.of(this).get(HomeViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_home, container, false)
return root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val sensor: Sensor? = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY)
val deviceSensors: List<Sensor> = sensorManager.getSensorList(Sensor.TYPE_ALL)
angle_value.setText(deviceSensors.toString())
deviceSensors.forEach {
Log.d("Sensors",it.toString())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment