Skip to content

Instantly share code, notes, and snippets.

Fung LAM seventhmoon

Block or report user

Report or block seventhmoon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@seventhmoon
seventhmoon / Connectivity.java
Created Jan 4, 2016
Connectivity helper for Android
View Connectivity.java
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/**
* Check device's network connectivity and speed
*
* @author emil http://stackoverflow.com/users/220710/emil
@seventhmoon
seventhmoon / GsonRequest.java
Created Jan 4, 2016
GsonRequest for Volley
View GsonRequest.java
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonRequest;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@seventhmoon
seventhmoon / OkHttpStack.java
Created Dec 23, 2015
OkHttpStack for Volley
View OkHttpStack.java
import com.android.volley.toolbox.HurlStack;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.OkUrlFactory;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation which
@seventhmoon
seventhmoon / CachedDrmSessionManager.java
Last active Dec 1, 2016
CachedDrmSessionManager for Exoplayer offline playback use
View CachedDrmSessionManager.java
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@seventhmoon
seventhmoon / AspectRatioImageView.java
Created Oct 27, 2015 — forked from JakeWharton/AspectRatioImageView.java
ImageView that respects an aspect ratio applied to a specific measurement.
View AspectRatioImageView.java
// 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 {
@seventhmoon
seventhmoon / GsonRequest.java
Last active Sep 10, 2015
GsonRequest for Volley
View GsonRequest.java
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonRequest;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
View gist:1e2cd5fd098cc88b8ae1
Glide.with(this)
.load(url)
.asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop()
.into(new BitmapImageViewTarget(mImageViewBackdrop) {
@Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
super.onResourceReady(bitmap, anim);
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
@seventhmoon
seventhmoon / DefaultApplication.java
Last active Aug 29, 2015
Detect UI mode is TV or not
View DefaultApplication.java
import android.app.Application;
import android.app.UiModeManager;
import android.content.res.Configuration;
/**
* Created by fung.lam on 27/07/2015.
*/
public class DefaultApplication extends Application {
private boolean isRunningOnTv(){
View ViewPagerActivity.java
//implement ViewPager.SimpleOnPageChangeListener(), override the following method
public void onPageScrollStateChanged(int state) {
if (state == ViewPager2.SCROLL_STATE_IDLE) {
int curr = mViewPager.getCurrentItem();
int lastReal = mViewPager.getAdapter().getCount() - 2;
if (curr == 0) {
mViewPager.setCurrentItem(lastReal, false);
} else if (curr > lastReal) {
mViewPager.setCurrentItem(1, false);
}
@seventhmoon
seventhmoon / calcDist.java
Last active Aug 29, 2015
Convert LatLong to Meter
View calcDist.java
private double calcDist(double lat1, double lng1, double lat2, double lng2) {
double earthRadius = 3958.75;
double lat = Math.toRadians(lat2 - lat1);
double lng = Math.toRadians(lng2 - lng1);
double a = Math.sin(lat / 2) * Math.sin(lat / 2)
+ Math.cos(Math.toRadians(lat1))
* Math.cos(Math.toRadians(lat2)) * Math.sin(lng / 2)
* Math.sin(lng / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double dist = earthRadius * c;
You can’t perform that action at this time.