Skip to content

Instantly share code, notes, and snippets.

View bapspatil's full-sized avatar
🪄

Bapusaheb Patil bapspatil

🪄
View GitHub Profile
@bapspatil
bapspatil / ExoPlayerDemoFragment.java
Last active May 10, 2020 09:32
Generic code to set up ExoPlayer in a Fragment
/*
** Created by bapspatil
*/
public class ExoPlayerDemoFragment extends Fragment {
@BindView(R.id.video_exoplayer_view) SimpleExoPlayerView mPlayerView;
private SimpleExoPlayer mPlayer;
private Unbinder unbinder;
public ExoPlayerDemoFragment() {
import android.content.res.Resources;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
/**
* Created by bapspatil
*/
@bapspatil
bapspatil / LoadJson.java
Created October 27, 2017 04:18
Load Json from local file and URL
/*
** Created by bapspatil
*/
// Load JSON from URL
public static String loadJsonFromUrl(URL url) throws IOException {
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = urlConnection.getInputStream();
Scanner scanner = new Scanner(in);
@bapspatil
bapspatil / CheckDeviceOrientation.java
Created October 27, 2017 04:23
Check the orientation of the device (landscape or portrait)
/*
** Created by bapspatil
*/
// Checks if the device is in portrait mode or not
public boolean isDeviceInPortrait() {
// Use Configuration.ORIENTATION_LANDSCAPE if you want to check for landscape orientation
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
@bapspatil
bapspatil / ImmersiveModes.java
Last active November 6, 2017 16:59
Load an Activity/Fragment in different Immersive modes
/*
** Created by bapspatil
*/
private void immersiveMode() {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
@bapspatil
bapspatil / YouTubeUtils.java
Created November 5, 2017 09:14
Get the video ID for a YouTube video from its YouTube URL
/*
** Created by bapspatil
*/
private static String extractVideoId(String ytUrl) {
String vId = null;
Pattern pattern = Pattern.compile("(?<=watch\\\\?v=|/videos/|embed\\\\/|youtu.be\\\\/|\\\\/v\\\\/|\\\\/e\\\\/|watch\\\\?v%3D|watch\\\\?feature=player_embedded&v=|%2Fvideos%2F|embed%\\u200C\\u200B2F|youtu.be%2F|%2Fv%2F)[^#\\\\&\\\\?\\\\n]*");
Matcher matcher = pattern.matcher(ytUrl);
if (matcher.matches()){
vId = matcher.group(1);
@bapspatil
bapspatil / EndlessScrollListener.java
Created November 12, 2017 01:53
An endless scroll listener for RecyclerView.
/*
** Created by bapspatil
*/
public abstract class EndlessScrollListener extends RecyclerView.OnScrollListener {
// The minimum amount of items to have below your current scroll position
// before loading more.
private int visibleThreshold = 5;
// The current offset index of data you have loaded
@bapspatil
bapspatil / AspectRatioImageView.java
Created November 30, 2017 14:17 — forked from JakeWharton/AspectRatioImageView.java
ImageView that respects an aspect ratio applied to a specific measurement.
// Copyright 2012 Square, Inc.
package com.squareup.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;
/** Maintains an aspect ratio based on either width or height. Disabled by default. */
public class AspectRatioImageView extends ImageView {
@bapspatil
bapspatil / ExpandableTextView.java
Created December 5, 2017 14:10 — forked from gilbertwat/ExpandableTextView.java
A TextView that only click to expand to show full text and click to show shorten text, The ellipsis can be configured too.
package com.mpayme.znap.core.widget;
import java.lang.reflect.Field;
import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
public class AnimatedActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//opening transition animations
overridePendingTransition(R.anim.activity_open_translate,R.anim.activity_close_scale);
}