Skip to content

Instantly share code, notes, and snippets.

View kmansoft's full-sized avatar

Kostya Vasilyev kmansoft

View GitHub Profile
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@kmansoft
kmansoft / ViewPagerInexact.patch.java
Created November 19, 2015 19:00
ViewPager patch to allow the adapter not know the exact number of items, only two adjoining ones
/*
This patch lets a ViewPagerAdapter{subclass} not know the exact number of items, and only keep prev and next.
- Return some arbitrary large number from getCount
- Maintain prev and next data items (not whole list)
- In instantiateItem, return null for item positions other than prev/next, or when there is no prev/next item
With this patch, ViewPager will notice the "null"'s and treat them like "end of list" markers.
*/
@kmansoft
kmansoft / SpinnerWithBaseline.java
Created October 20, 2015 14:49
Fix for Spinner.getBaseline returning wrong value on Android 5.1 (maybe 5.0+) in some cases
public class SpinnerWithBaseline extends Spinner {
public SpinnerWithBaseline(Context context, AttributeSet attr) {
super(context, attr);
}
@Override
public int getBaseline() {
final int children = getChildCount();
int childBaseline = 0;
@kmansoft
kmansoft / SamsungLGLauncher.java
Created August 12, 2015 13:48
"Unread count" for Samsung and LG TouchWiz
public class SamsungLGLauncher {
private static final String TAG = "SamsungLGLauncher";
private static final String SEC_PACKAGE_NAME = "com.sec.android.app.launcher";
private static final String LG_PACKAGE_NAME = "com.lge.launcher2";
private static final String ACTION = "android.intent.action.BADGE_COUNT_UPDATE";
public static boolean isSamsungInstalled(Context context) {
@kmansoft
kmansoft / drawable_alpha_adjust.py
Created July 19, 2015 18:57
A script to convert "material dark" icons to "material" icons, by adjusting the alpha value. The right adjustment seems to be 140 (= increase by 40%).
#!/usr/bin/python
import sys
import argparse
import os
import re
import png
MAPPING = {
"drawable-mdpi" : "drawable-mdpi",
@kmansoft
kmansoft / AppLocaleManager.java
Last active August 29, 2015 14:23
pyler's AppLocaleManager with a few changes...
package org.kman.AquaMail.core;
import java.util.Locale;
import org.kman.Compat.util.MyLog;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@kmansoft
kmansoft / gist:984f24911164100b5435
Last active June 14, 2018 08:40
Elevation test
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:id="@+id/view1"
android:layout_width="160dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
public class SSLHardening {
private static final String TAG = "SSLHardening";
public static boolean isSupported() {
return Build.VERSION.SDK_INT >= 14;
}
public static boolean isHardeningEnabled(Context context) {
if (isSupported()) {
@kmansoft
kmansoft / MediaScannerNotifier.java
Created August 13, 2012 22:53
MediaScanner example
public class MediaScannerNotifier implements MediaScannerConnectionClient, Handler.Callback {
private static final String TAG = "MediaScannerNotifier";
public static boolean submit(Context context, File file, String type) {
if (needScan(type)) {
new MediaScannerNotifier(context, file);
return true;
}
return false;
@kmansoft
kmansoft / find_missing_translations.py
Created July 3, 2012 09:22
A simple script to find missing translations in an Android project
#!/usr/bin/python
'''
This script finds missing string translations in Android applicaitons.
Author: Kostya Vasilyev. License: Creative Commons Attribution.
The output format is, I believe, more suitable to working with external
translators than the output of Lint from the Android SDK.