Skip to content

Instantly share code, notes, and snippets.

@keyboardr
keyboardr / HeadlessFragment.java
Last active December 31, 2021 01:05
A file template for creating a headless Fragment. The attach() methods add the fragment to the parent if it doesn't already exist and returns the attached fragment. The methods ensure that the parent implements the parent interface. If needed, parameters may be added to the attach() methods to supply fragment arguments.
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
#parse("File Header.java")
public class ${NAME} extends Fragment {
private static final String FRAG_TAG = ${NAME}.class.getCanonicalName();
@leon
leon / IdNumberValidator.java
Last active March 30, 2020 10:42
Swedish Organisation number / SSN validator
package util;
import org.apache.commons.lang3.StringUtils;
public class IdNumberValidator {
// Invalid Result is used as a return value when the test fails
private static final IdNumberValidatorResult invalid = new IdNumberValidatorResult();
public static IdNumberValidatorResult validate(String value) {
@FrancoisBlavoet
FrancoisBlavoet / ContextMenuRecyclerView.java
Last active October 26, 2016 23:38
ContextMenuRecyclerView - simple sample on how to adapt an existing ContextMenu to RecyclerView
import android.content.Context;
import android.util.AttributeSet;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
public class ContextMenuRecyclerView extends RecyclerView {
@Shywim
Shywim / CursorRecyclerAdapter.java
Last active February 28, 2025 09:59
A custom Adapter for the new RecyclerView, behaving like the CursorAdapter class from previous ListView and alike. Now with Filters and updated doc.
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Matthieu Harlé
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@benjchristensen
benjchristensen / RetryWhenTests.java
Created August 20, 2014 17:24
RetryWhen Example
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Subscriber;
public class RetryWhenTests {
public static void main(String[] args) {
Observable.create((Subscriber<? super String> s) -> {
@burgalon
burgalon / AccountAuthenticator.java
Last active July 15, 2023 08:29
Implementing OAuth2 with AccountManager, Retrofit and Dagger
public class AccountAuthenticator extends AbstractAccountAuthenticator {
private final Context context;
@Inject @ClientId String clientId;
@Inject @ClientSecret String clientSecret;
@Inject ApiService apiService;
public AccountAuthenticator(Context context) {
super(context);
@staltz
staltz / introrx.md
Last active April 24, 2025 06:10
The introduction to Reactive Programming you've been missing
@beshkenadze
beshkenadze / tz_mobile_android.md
Last active October 5, 2024 10:08
Тестовое задание для мобильного разработчика

Тестовое задание для Android разработчиков

Время выполнения задания - 4-6 часов.

Необходимо показать умение владением стека технологий: sqlite (sql/contentresolver), json (xml), API (rest), offline mode, git.

(!) Обязательная реализация CRUD, для работы с данными.

  • Необходимо создать rss reader. Приложение должно иметь минимум 3 встроенных rss подписки, пользователь может добавить свои подписки. Приложение должно выводить список подписок, при переходе по подписке надо показывать список постов, после перехода по посту надо показывать его заголовок и описание.
@julianshen
julianshen / CircleTransform.java
Last active November 6, 2023 12:47
CircleTransform for Picasso
/*
* Copyright 2014 Julian Shen
*
* 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
@TomTasche
TomTasche / AndroidManifest.xml
Last active May 11, 2023 20:00
OAuth flow using the AccountManager on Android
<!-- ... -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!-- ... -->