Skip to content

Instantly share code, notes, and snippets.

View RahulSDeshpande's full-sized avatar
☑️
Code • Jam • Shoot | Repeat

Rahul RahulSDeshpande

☑️
Code • Jam • Shoot | Repeat
View GitHub Profile
@ryneli
ryneli / gist:bc4ea5b679a75b940a44d4bc967e2f54
Created May 2, 2017 17:54
android elevation translationz on ImageView
v.setOutlineProvider(ViewOutlineProvider.BOUNDS);
v.setElevation(10.0);
v.setTranslationZ(10.0);
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
class SplashActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Make sure this is before calling super.onCreate
setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState)
@abhaysood
abhaysood / medium_rider_redesign_blog_example.kt
Created March 18, 2018 20:04
A simple component which is created when user clicks the cancel order button in the app. It is responsible for showing a confirmation dialog and actually cancelling the order by making an API call.
class OrderCancellationComponent(private val context: Context,
private val api: Api,
private val orderNumber: String) {
interface Callbacks {
fun onOrderCancelledSuccessfully()
fun onOrderCancellationFailed()
}
var callbacks: Callbacks? = null // Callbacks for communication with the parent component
@grennis
grennis / RoundedCornerLayout.java
Created April 22, 2016 14:00
Android Rounded Corner Layout
// This layout will display its children with rounded corners
// It works with Glide image library placeholders and animations
// It assumes your background is a solid color. If you need the corners to be truly transparent,
// this solution will not work for you.
package com.myapp.ui;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
@alphamu
alphamu / ExpandableTextView.java
Created April 24, 2015 01:17
A TextView and that expand and contract to show more or less content. Using ellipses with the TextView or the TextUtils to calculate where to ellipsize text can return the wrong result as it doesn't cater for new line characters. This code will consistently returns the correct number of lines.
import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
import android.widget.TextView;
@antoniolg
antoniolg / SwipeRefreshActivity.java
Last active July 29, 2019 11:59
An activity that uses a SwipeRefreshLayout as a container for the layout of the classes that extend it.
/*
* Copyright (C) 2014 Antonio Leiva Gordillo.
*
* 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
@eveliotc
eveliotc / RoundedAvatarDrawable.java
Created July 22, 2013 04:59
RoundedAvatarDrawable: A Drawable that draws an oval with given {@link Bitmap} See http://evel.io/2013/07/21/rounded-avatars-in-android/
/*
* Copyright 2013 Evelio Tarazona Cáceres <evelio@evelio.info>
*
* 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
@segunfamisa
segunfamisa / app-module-build.gradle
Last active June 22, 2020 11:43
Using gradle extra properties to manage Android dependency versioning
// app module build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "com.segunfamisa.gradleextraproperties"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
@kevinvanmierlo
kevinvanmierlo / BaseActivity.java
Last active September 1, 2020 15:22
Same Navigation Drawer on different Activities
public class BaseActivity extends AppCompatActivity
{
public DrawerLayout drawerLayout;
public ListView drawerList;
private ActionBarDrawerToggle drawerToggle;
protected void onCreate(Bundle savedInstanceState)
{
// R.id.drawer_layout should be in every activity with exactly the same id.
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
object MyReachability {
private fun hasNetworkAvailable(context: Context): Boolean {
val service = Context.CONNECTIVITY_SERVICE
val manager = context.getSystemService(service) as ConnectivityManager?
val network = manager?.activeNetworkInfo
Log.d(classTag, "hasNetworkAvailable: ${(network != null)}")
return (network?.isConnected) ?: false
}