Skip to content

Instantly share code, notes, and snippets.

@alexfu
alexfu / DividerItemDecoration.java
Last active February 9, 2023 05:09
An ItemDecoration that draws dividers between items. Pulled from Android support demos.
/*
* 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
@grantland
grantland / post.md
Last active February 9, 2023 05:09
RecyclerView item onClick

RecyclerView item onClick

RecyclerView does not have an OnItemClickListener like it's predecessor, ListView. However, detecting item clicks is pretty simple.

Set an OnClickListener in your ViewHolder creation:

private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>  {

    public static class ViewHolder extends RecyclerView.ViewHolder
@cyrilmottier
cyrilmottier / AndroidManifest.xml
Last active January 30, 2023 00:04
Android example of how to add a custom logo to the ActionBar and ensure the best possible matching starting Window.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyrilmottier.android.anapp">
<!-- ... -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/config_app_name"
android:theme="@style/Theme.AnApp" >
@meoyawn
meoyawn / EmptyRecyclerView.java
Created November 1, 2014 11:20
RecyclerView doesn't have an emptyView support, we gotta fix that
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class EmptyRecyclerView extends RecyclerView {
@Nullable View emptyView;
@kristopherjohnson
kristopherjohnson / showForegroundNotification.java
Last active June 21, 2022 13:41
Shows a foreground notification for an Android service. Tapping the notification will display the app as if it was tapped in application launcher
private static final int NOTIFICATION_ID = 1;
private void showForegroundNotification(String contentText) {
// Create intent that will bring our app to the front, as if it was tapped in the app
// launcher
Intent showTaskIntent = new Intent(getApplicationContext(), MyMainActivity.class);
showTaskIntent.setAction(Intent.ACTION_MAIN);
showTaskIntent.addCategory(Intent.CATEGORY_LAUNCHER);
showTaskIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@koyopro
koyopro / amazon-calc.js
Last active April 2, 2022 08:23 — forked from polamjag/amazon-calc.js
Amazonで一年間に使った金額と、注文履歴のTSVを出力するブックマークレット【2015年版】
// Amazonの注文履歴をTSV形式で出力するスクリプト
//
// 2015-01-01 時点での DOM 構造に対応, GoogleCrome, Opera でテスト済。
// formatEntry関数を書き換えれば自由な書式で出力できます。
//
// 参考:
// - Amazonの注文履歴をCSV形式にして出力するスクリプト
// https://gist.github.com/arcatdmz/8500521
// - Amazon で使った金額の合計を出す奴 (2014 年バージョン)
// https://gist.github.com/polamjag/866a8af775c44b3c1a6d
@rpavlik
rpavlik / fix_homebrew.rb
Created January 6, 2011 20:32 — forked from mxcl/install_homebrew.markdown
Fix permissions on /usr/local for Homebrew
#!/usr/bin/ruby
#
# This script fixes /usr/local only.
#
# 6th January 2010:
# Modified the script to just fix, rather than install. - rpavlik
#
# 30th March 2010:
# Added a check to make sure user is in the staff group. This was a problem
# for me, and I think it was due to me migrating my account over several
@euske
euske / are-you-an-expert.md
Last active January 27, 2022 10:14
Japanese Translation of "Are You An Expert?" by Jeff Atwood

あなたは専門家か? (Are You An Expert?)

(Original article: https://blog.codinghorror.com/are-you-an-expert/ )

ぼくは権威というものが嫌いらしい。 まず自分自身の過去から始めよう。

ぼくは、人々からアマチュア仲間としてではなく、 何らかの専門家や権威だとみなされることがひどく嫌いである。

@seamountain
seamountain / Migrating_to_WebView_in_Android_4.4.md
Last active January 18, 2022 06:26
Migrating to WebView in Android 4.4 翻訳

以下Android公式ドキュメント Migrating to WebView in Android 4.4 の翻訳です。 間違いなどあればぜひご指摘ください。拙いですが誰かの役に立てば幸いです。

Migrating to WebView in Android 4.4

Android 4.4(API レベル 19)では、Chrominium ベースの新しい WebView が紹介されました。この変更で、WebView のパフォーマンス向上し、最新の Web ブラウザに追いつくために、HTML5、CSS3やJavaScript を標準サポートします。WebView を使っているアプリは、Android 4.4 以上からはこれらのアップデートの恩恵を受けることになります。

本ドキュメントは WebVeiew の変更点について説明します。なお、その変更は Android 4.4 以上、つまり targetSdkVersion を "19" 以上にした場合です。

Note: targetSdkVersion を "18" 以下にした場合、WebView は以下で述べるような挙動をすることを避けるために、"quirks モード" になります。これは、パフォーマンス向上と Web 標準に対応するためです。

@wasabeef
wasabeef / daily-ktlint.yml
Created September 3, 2019 07:18
Scheduled ktlint with Github Actions
# .github/workflows/daily-ktlint.yml
name: Android CI (Ktlint)
on:
schedule:
# Daily 7am (JST)
- cron: '00 22 * * *'
jobs: