Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Subscribe to my newsletter: wajahatkarim.com/subscribe

Wajahat Karim wajahatkarim3

:octocat:
Subscribe to my newsletter: wajahatkarim.com/subscribe
View GitHub Profile
View SplashActivity.java
public class SplashActivity extends Activity {
private static long SLEEP_TIME = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout.activity_splash);
// Start timer and launch main activity
View SampleCode.java
// This example uses decor view, but you can use any visible view.
View decorView = getActivity().getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
@wajahatkarim3
wajahatkarim3 / SampleJob.java
Created Mar 30, 2017
Sample Android Job Scheduling
View SampleJob.java
public static int scheduleFirstAt(int aDay, int hours, int mins) {
int jobID = -1;
long startMs = 0L, endMs = 0L;
int MARGIN_TIME = 30;
// Current Day
DateTime currentDay = new DateTime();
@wajahatkarim3
wajahatkarim3 / MainActivity.kt
Last active Jan 22, 2018
Making user online of Firestore and Firebase
View MainActivity.kt
fun makeUserOnline(user: UserModel)
{
// Firestore
var query = FirebaseFirestore.getInstance().collection("users").document(user.userId ?: "")
user.apply {
online = true
last_active = 0
}
query.set(user)
@wajahatkarim3
wajahatkarim3 / MainActivity.kt
Created Jan 22, 2018
onDisconnect() method example
View MainActivity.kt
FirebaseDatabase.getInstance()
.getReference("some/random/key")
.onDisconnect() // Setting up Disconnect hook
.setValue("Update any kind of values you want here");
@wajahatkarim3
wajahatkarim3 / index.js
Created Jan 22, 2018
Firebase Cloud Function for User Presence Demo
View index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const firestore = functions.firestore;
exports.onUserStatusChange = functions.database
.ref('/status/{userId}')
.onUpdate(event => {
@wajahatkarim3
wajahatkarim3 / MainActivity.kt
Created Jan 22, 2018
The onDisconnect() hook to make user offline
View MainActivity.kt
fun makeUserOnline(user: UserModel)
{
// Adding on disconnect hook
FirebaseDatabase.getInstance().getReference("/status/" + user.userId)
.onDisconnect() // Set up the disconnect hook
.setValue("offline");
}
View MainActivity.java
package com.wajahatkarim3.chipsdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.MultiAutoCompleteTextView;
import com.android.ex.chips.RecipientEditTextView;
import com.tokenautocomplete.TokenCompleteTextView;
public class MainActivity extends AppCompatActivity {
View LogCodeDebugTree.java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import timber.log.Timber;
public class LinkingDebugTree extends Timber.DebugTree {
private static final int CALL_STACK_INDEX = 4;
private static final Pattern ANONYMOUS_CLASS = Pattern.compile("(\\$\\d+)+$");
@wajahatkarim3
wajahatkarim3 / root build.gradle
Last active Jun 28, 2018
Publishing your Android, Kotlin or Java library to jCenter from Android Studio
View root build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Add These Bintray and Maven Gradle Classpaths
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
You can’t perform that action at this time.