Skip to content

Instantly share code, notes, and snippets.

@killvetrov
killvetrov / BaseViewBindingFragment.java
Last active November 15, 2022 12:58
Android View Binding: base class to reduce boilerplate in Java
public abstract class BaseViewBindingFragment extends Fragment {
private Field bindingField;
private Method inflate;
{
try {
for (Field declaredField : this.getClass().getDeclaredFields()) {
if (ViewBinding.class.isAssignableFrom(declaredField.getType())) {
bindingField = declaredField;
@TWiStErRob
TWiStErRob / README.md
Last active June 12, 2023 00:21
Kotlin Script (kts) 1.3.21 with dependencies to call a JSON web endpoint, including tests
@dkarmalita
dkarmalita / androidSdkInstall.sh
Last active August 27, 2022 00:26
Android SDK & Emulator installer for React Native development
#! /bin/bash
# =================================
# Android SDK & Emulator installer
# For React Native development
# Platform: OSX, WIN
# Ver: 20171128
# dmitriy.karmalita@gmail.com
# Original gist: https://git.io/vbLFg
# =================================
#
static class UIHandler extends Handler {
private final WeakReference<ImageFetcherActivity> mActivityRef;
UIHandler(ImageFetcherActivity activity) {
mActivityRef = new WeakReference(activity);
}
@Override
public void handleMessage(Message msg) {
final ImageFetcherActivity activity = mActivityRef.get();
/*
* Copyright 2016 Jake Wharton
*
* 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
package com.example.mediasessioncompat;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaButtonReceiver;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
@ivacf
ivacf / ProfileViewModel.java
Last active April 22, 2018 19:07
View model that downloads an image using Picasso and data binding
public class ProfileViewModel {
// The URL will usually come from a model (i.e Profile)
static final String IMAGE_URL = "http://cdn.meme.am/instances/60677654.jpg";
public ObservableField<Drawable> profileImage;
private BindableFieldTarget bindableFieldTarget;
public ProfileViewModel(Context context) {
profileImage = new ObservableField<>();
// Picasso keeps a weak reference to the target so it needs to be stored in a field
bindableFieldTarget = new BindableFieldTarget(profileImage, context.getResources());
@ArthurSav
ArthurSav / WrapGridLayoutManager.java
Created September 11, 2015 14:45
GridLayoutManager with working wrap_content.
package com.inperson.android.utils.leastview;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
public class WrappableGridLayoutManager extends GridLayoutManager {
@ianhanniballake
ianhanniballake / PlayerService.java
Created July 12, 2015 18:57
Minimal MediaSessionCompat needed to get RemoteControlClient to appear
package com.example.remotecontrolclient;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.os.IBinder;
import android.support.v4.media.MediaMetadataCompat;
@martijn00
martijn00 / MainLayout.xaml
Last active June 15, 2024 11:13
Android v22.2 Tabs and ViewPager in MvvmCross
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"