Skip to content

Instantly share code, notes, and snippets.

View ngima's full-sized avatar
🎯
Focusing

Ngima Sherpa ngima

🎯
Focusing
View GitHub Profile
/*
* BottomNavigationLayout library for Android
* Copyright (c) 2016. Nikola Despotoski (http://github.com/NikolaDespotoski).
* 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
@ngima
ngima / CheatSheet.java
Created March 3, 2017 10:34 — forked from romannurik/CheatSheet.java
Android helper class for showing cheat sheets (tooltips) for icon-only UI elements on long-press. This is already default platform behavior for icon-only action bar items and tabs. This class provides this behavior for any other such UI element.
/*
* Copyright 2012 Google Inc.
*
* 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
/*
* Copyright (C) 2006 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
@ngima
ngima / Singleton.java
Last active April 17, 2017 04:58
Singleton class that is thread, reflection and serialization safe
import java.io.Serializable;
public class Singleton implements Serializable {
private static volatile Singleton sInstance;
private Singleton() {
if (sInstance != null) {
throw new RuntimeException("Use getInstace() method to instantiate.")
}
@ngima
ngima / CharWeight.java
Last active April 24, 2017 06:07
Outputs the character weight like;
package com.yipl.myapplication;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@ngima
ngima / HeaderInterceptor.java
Created May 8, 2017 09:15
Header Interceptor
public class HeaderInterceptor
implements Interceptor {
@Override
public Response intercept(Chain chain)
throws IOException {
Request request = chain.request();
request = request.newBuilder()
.addHeader("appid", "hello")
.addHeader("deviceplatform", "android")
.removeHeader("User-Agent")
private fun displayLocationSettingsRequest(context: Context) {
var googleApiClient = GoogleApiClient.Builder(context)
.addApi(LocationServices.API).build();
googleApiClient.connect();
var locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(30 * 1000);
locationRequest.setFastestInterval(5 * 1000);
@ngima
ngima / CameraResult.java
Created August 21, 2018 13:56
Android Image Picker
@Override
protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_TAKE_PICTURE:
try {
Uri uri = getImageUri(Profile.this, ((Bitmap) data.getExtras().get("data")));
if (uri != null) {
InputStream iStream = getContentResolver().openInputStream(uri);
byte[] inputData = getBytes(iStream);
@ngima
ngima / Logger.java
Created November 19, 2018 06:35
Android Logger Class
import android.util.Log;
public class Logger {
public static void d(String tag, String message) {
if (BuildConfig.DEBUG) Log.d(tag, message);
}
public static void e(String tag, String message) {
if (BuildConfig.DEBUG) Log.d(tag, message);
}
@ngima
ngima / RecyclerView.Adapter.kt
Created June 9, 2021 04:56
Android Live Templates
//radapter
class $adapter$ : androidx.recyclerview.widget.RecyclerView.Adapter<$adapter$.ViewHolder>() {
var data: MutableList<$model$> = mutableListOf()
set(value) {
field = value
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: android.view.ViewGroup, viewType: Int): ViewHolder =