Skip to content

Instantly share code, notes, and snippets.

View gajerarajnit's full-sized avatar

Rajnit Gajera gajerarajnit

View GitHub Profile
@gajerarajnit
gajerarajnit / hide_keyboard.java
Created August 22, 2017 06:10
Close keyboard when touch outside of keyboard area.
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
View view = getCurrentFocus();
if (view != null && (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE) && view instanceof EditText && !view.getClass().getName().startsWith("android.webkit.")) {
int scrcoords[] = new int[2];
view.getLocationOnScreen(scrcoords);
float x = ev.getRawX() + view.getLeft() - scrcoords[0];
float y = ev.getRawY() + view.getTop() - scrcoords[1];
if (x < view.getLeft() || x > view.getRight() || y < view.getTop() || y > view.getBottom())
((InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow((this.getWindow().getDecorView().getApplicationWindowToken()), 0);
@gajerarajnit
gajerarajnit / FirebaseDataReceiver.java
Created August 22, 2017 06:12 — forked from Antarix/FirebaseDataReceiver.java
Firebase Android Sample for managing notification
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
/**
* This is called whenever app receives notification
* in background/foreground state so you can
* apply logic for background task, but still Firebase notification
* will be shown in notification tray
@gajerarajnit
gajerarajnit / Category.java
Created August 22, 2017 12:08
Expandable RecyclerView with parent and child item selection.
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Created by rajnit on 22/08/17.
*/
public class Category implements Serializable {
@gajerarajnit
gajerarajnit / MyMediaPlayer.java
Last active September 12, 2022 20:11
Singleton MediaPlayer.
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import java.io.IOException;
/**
* Created by rajnit on 10/07/17.
*/
@gajerarajnit
gajerarajnit / CustomTypeFaceTextView.java
Created October 3, 2017 10:13
Apply custom fonts to textview....
public class CustomTypeFaceTextViewRegular extends TextView {
public TextViewRegular(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
applyCustomFont(context);
}
public TextViewRegular(Context context, AttributeSet attrs) {
super(context, attrs);
applyCustomFont(context);
}
@gajerarajnit
gajerarajnit / VideoPagerAdapter.java
Created September 7, 2018 13:58
Integrate custom youtube player using library.
package com.rajnit.photostudio.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.pierfrancescosoffritti.androidyoutubeplayer.player.YouTubePlayer;