Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Josias Sena JosiasSena

🏠
Working from home
View GitHub Profile
@JosiasSena
JosiasSena / DeCryptor.java
Last active Jul 26, 2021
Encryptor and Decryptor for data encryption.decryption using the Android KeyStore.
View DeCryptor.java
/**
_____ _____ _
| __ \ / ____| | |
| | | | ___| | _ __ _ _ _ __ | |_ ___ _ __
| | | |/ _ \ | | '__| | | | '_ \| __/ _ \| '__|
| |__| | __/ |____| | | |_| | |_) | || (_) | |
|_____/ \___|\_____|_| \__, | .__/ \__\___/|_|
__/ | |
|___/|_|
*/
View WifiConnectionReceiver.java
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;
@JosiasSena
JosiasSena / AndroidManifest.xml
Created Mar 10, 2017
Job Scheduler Code sample
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.josiassena.jobscheduler">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
View FixedGetCameraIds.java
private void getCameraIds() {
cameraManager = (CameraManager) appContext.getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics cameraCharacteristics;
try {
for (String cameraId : cameraManager.getCameraIdList()) {
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
if (isCameraFacingBack(cameraCharacteristics) && backCameraId == null) {
backCameraId = cameraId;
} else if (isCameraFacingFront(cameraCharacteristics) && frontCameraId == null) {
frontCameraId = cameraId;
@JosiasSena
JosiasSena / BuggyGetCameraIds.java
Last active Feb 12, 2020
Buggy getCameraIds()
View BuggyGetCameraIds.java
private void getCameraIds() {
cameraManager = (CameraManager) appContext.getSystemService (Context.CAMERA_SERVICE);
CameraCharacteristics cameraCharacteristics;
try {
for (String cameraId : cameraManager.getCameraIdList()) {
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
if (isCameraFacingBack(cameraCharacteristics)) {
backCameraId = cameraId;
} else if (isCameraFacingFront(cameraCharacteristics)) {
frontCameraId = cameraId;
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.packagename">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<application
View GraphQLApi.kt
class GraphQLApi(private val sharedOkHttpClientBuilder: OkHttpClient.Builder) {
// ...
fun <D : Operation.Data, V : Operation.Variables> subscribe(subscription: Subscription<D, D, V>): Flowable<Response<D>> {
// Create our dedicated apollo client
val apolloClient = ApolloSubscriptionClientFactory(sharedOkHttpClientBuilder)
.createSubscriptionApolloClient()
View subscriptions.graphql
subscription onNewMessagesReceived($groupUUID: String!) {
groupChatSubscription(group: $groupUUID) {
... on Message {
uuid
}
}
}
View ApolloSubscriptionClientFactory.kt
class ApolloSubscriptionClientFactory {
fun createSubscriptionApolloClient(sharedOkHttpClientBuilder: OkHttpClient.Builder): ApolloClient {
val okHttpClient = sharedOkHttpClientBuilder
.pingInterval(KEEP_ALIVE_INTERVAL, TimeUnit.SECONDS)
.build()
val subscriptionTransportFactory = WebSocketSubscriptionTransport.Factory("wss://your_subscription_host/graphql", okHttpClient)
return ApolloClient.builder()
View SomePresenterOrViewModelEtc.kt
class SomePresenterOrViewModelEtc(private val api: GraphQLApi) {
// ...
fun sunscribeToMessages() {
val messagesSubscription = OnNewMessagesReceivedSubscription.builder()
.groupUUID("uuid")
.build()
api.subscribe(messagesSubscription)