Skip to content

Instantly share code, notes, and snippets.

View antoniomartel's full-sized avatar

Antonio Martel antoniomartel

View GitHub Profile
// Get ambient temperature
Sensor mTemperatureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
if (mTemperatureSensor != null) {
sensorManager.registerListener(this, mTemperatureSensor, SensorManager.SENSOR_DELAY_FASTEST);
existTemperatureSensor = true;
} else {
existTemperatureSensor = false;
Toast.makeText(this, "No Temperature Sensor !", Toast.LENGTH_LONG).show();
private void saveAmbientData() {
try {
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 0);
Location location = getLastKnownLocation(lm);
temp.longitude = location.getLongitude();
temp.latitude = location.getLatitude();
temp.altitude = location.getAltitude();
antoniomartel /
Last active July 17, 2016 19:41
Selenium WebDriver and JUnit to test a web application
package newpackage;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
antoniomartel /
Created May 14, 2016 07:51
Class to flatten nested array of Integers
package com.antoniomartel;
import java.util.ArrayList;
public class FlatArray {
protected ArrayList nestedArray = null;
protected ArrayList flattenArray = null;
// New exception created to be thrown when nested array contains something different from Integers