Skip to content

Instantly share code, notes, and snippets.

View StevenRudenko's full-sized avatar

Steven Rudenko StevenRudenko

View GitHub Profile
@dpmedeiros
dpmedeiros / AndroidMockUtil.java
Last active January 28, 2021 06:26
Mock main thread handler for use in Android unit tests (requires Mockito and PowerMock)
package com.dpmedeiros.androidtestsupportlibrary;
import android.os.Handler;
import android.os.Looper;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import java.util.concurrent.Executors;
@gabrielemariotti
gabrielemariotti / Activity.java
Last active November 27, 2022 09:27
Floating Action Button (requires Android-L preview)
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layoutfab);
//Outline
int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
Outline outline = new Outline();
@dalewking
dalewking / CamCompatListView
Created June 6, 2014 16:11
Backwards compatible Contextual Action Mode
import android.content.Context;
import android.support.v7.view.ActionMode;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;
public class CamCompatListView extends ListView
{
public CamCompatListView(Context context)
@vpodlesnyak
vpodlesnyak / gist:9930423
Created April 2, 2014 08:54
Multipart POST file upload
public static void uploadFile(String urlString, Map<String, String> params, String fileName, InputStream fileInputStream) {
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
HttpURLConnection conn;
try {
// ------------------ CLIENT REQUEST
Log.e(Tag, "Inside second Method");
// open a URL connection to the Servlet
URL url = new URL(urlString);
@vpodlesnyak
vpodlesnyak / gist:9910308
Created April 1, 2014 08:41
View overlay displayed on top of all activities
public class OverlayService extends Service {
LinearLayout oView;
@Override
public IBinder onBind(Intent i) {
return null;
}
@Override
Intent filter for URL capturing
Task: catch urls of type http://ХХХXviewster.com/movie/XXXXXX
Solution: activity with intent filter
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:host="*.viewster.com" />
@romannurik
romannurik / CharsPerLineActivity.java
Last active December 17, 2021 03:15
Demonstrates how to identify and avoid line-length issues with TextView. The measure, or characters per line, of a block of text plays a key role in how comfortable it is to read (sometimes referred to as readability). A widely accepted optimal range for a text block's measure is between 45 and 75 characters. This code demonstrates two phases of…
/*
* Copyright 2013 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
@leemour
leemour / Zsh & theme
Last active April 12, 2023 08:53
Zsh installation and Agnoster theme settings
# Railscast
http://railscasts.com/episodes/308-oh-my-zsh
# Install Zsh
sudo apt-get update && sudo apt-get install zsh
# Install Oh-my-zsh
wget –no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O – | sh
# Make ZSH default shell
public class CheckableFrameLayout extends FrameLayout implements Checkable {
private static final int[] CHECKED_STATE_SET = {
android.R.attr.state_activated,
android.R.attr.state_checked,
};
private boolean mChecked;
public CheckableFrameLayout(Context context) {
super(context);