Skip to content

Instantly share code, notes, and snippets.

View JosiasSena's full-sized avatar
🏠
Working from home

Josias Sena JosiasSena

🏠
Working from home
View GitHub Profile
@JosiasSena
JosiasSena / isGpsEnabled
Created July 15, 2016 23:23
check if GPS is enabled
/**
* Returns the current enabled/disabled status of the GPS provider.
* <p/>
* If the user has enabled GPS in the Settings menu, true
* is returned otherwise false is returned
*/
public static boolean isGpsEnabled(final Context context) {
final LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
@JosiasSena
JosiasSena / goToAppSettings
Created July 15, 2016 23:24
go to the settings for the current application
public static void goToAppSettings(final Context context) {
final Uri uri = Uri.fromParts("package", context.getPackageName(), null);
final Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
context.startActivity(intent);
}
@JosiasSena
JosiasSena / getCurrentDevicePhoneNumber
Created July 15, 2016 23:25
Get the current devices phone number
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = telephonyManager.getLine1Number();
@JosiasSena
JosiasSena / gist:c257013bb222ad2430334468bd442ea1
Created July 15, 2016 23:26
Check if the string contains a number or a special character
/**
* Check if the string contains a number or a special character
*
* @param text - string to check
* @return - true if it contains a number or a special character, else false
*/
public boolean textContainsSpecialCharsOrNumbers(String text) {
return !text.matches("^[a-z A-Z]+$");
}
@JosiasSena
JosiasSena / removeWhiteSpaces
Created July 15, 2016 23:26
Removes all white spaces from string
/**
* Removes all white spaces from string
*
* @param text - text to remove white spaces from
* @return - text without any whitespaces
*/
public static String removeWhiteSpaces(String text) {
return text.replaceAll("\\s+", "");
}
@JosiasSena
JosiasSena / wakeUpPhone
Created July 15, 2016 23:27
Wakes up device/turns on screen. For example if a notification is received this will make sure that the devices screen lights up
public static void wakeUpPhone(Context context, String tag) {
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock((
PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP), tag);
wakeLock.acquire();
}
@JosiasSena
JosiasSena / rando_btn_rgb.py
Last active October 2, 2016 02:22
Raspberry Pi - Display red, green, or blue randomly on button press
import random
import time
import RPi.GPIO as GPIO
# Constants
RUNNING = True
SLEEP_TIME = .2 # in seconds
FREQUENCY_ON = 100 # Hz
FREQUENCY_OFF = 0 # Hz
@JosiasSena
JosiasSena / get_supported_android_devices.js
Last active December 7, 2016 21:54
get supported devices from developer portal
$(document).ready(function () {
var interval = setInterval(function () {
myTimer();
}, 5000);
function myTimer() {
var manufacturers = [];
var devices = [];
var elements = document.getElementsByTagName("li");
@JosiasSena
JosiasSena / Utils.java
Created December 20, 2016 01:51
Helpful utility class
package josiassena.humbug;
import android.Manifest;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@JosiasSena
JosiasSena / WifiConnectionReceiver.java
Last active June 1, 2023 16:36
WifiConnectionReceiver
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.support.annotation.NonNull;
import android.util.Log;
import static android.content.ContentValues.TAG;