Skip to content

Instantly share code, notes, and snippets.

View ookami-kb's full-sized avatar

Kirill Bubochkin ookami-kb

View GitHub Profile
@ookami-kb
ookami-kb / Convert.sh
Created April 1, 2014 16:18
Converting to .mp3 and .ogg from .wav
lame -h -b 192 from.wav to.mp3
oggenc -b 192 from.wav -o to.ogg
@ookami-kb
ookami-kb / create_drawables.sh
Last active August 29, 2015 14:03
resize and put into res/drawable-* directories
#!/bin/sh
show_help() {
cat << EOF
Usage: ${0##*/} -i INPUT_FILE -o OUTPUT_RES_DIR -s MDPI_SIZE -n NAME
EOF
}
while getopts "hi:s:o:n:" opt; do
case $opt in
i)
@ookami-kb
ookami-kb / MaskedImageButton.java
Last active August 29, 2015 14:06
ImageButton that accepts drawable as mask. Touch is only processed when touched on black pixel of mask.
package package_name;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageButton;
@ookami-kb
ookami-kb / DrawerListView.kt
Created April 7, 2015 20:17
DrawerListView with width by Material design guidelines
public class DrawerListView(context: Context, attrs: AttributeSet) : ListView(context, attrs) {
val widthCalculated : Int
init {
val displayMetrics = getContext().getResources().getDisplayMetrics()
val maxWidth = Math.round(400 * displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)
val wm = getContext().getSystemService(Context.WINDOW_SERVICE) as WindowManager
val size = Point()
wm.getDefaultDisplay().getSize(size)
@ookami-kb
ookami-kb / gist:5563286
Last active December 17, 2015 06:09
Open url in Android
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
@ookami-kb
ookami-kb / gist:5563304
Last active December 17, 2015 06:09
Open Send email intent in android
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"to@example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "the subject");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("the content"));
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/file.ext"));
startActivity(intent);
@ookami-kb
ookami-kb / gist:5578151
Last active December 17, 2015 08:09
Intent for sending email in Android
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
@ookami-kb
ookami-kb / MyActivity.java
Created June 27, 2013 11:28
How to listen to screen orientation changes when orientation is locked.
public class MyActivity extends Activity {
private OrientationEventListener orientationEventListener;
private boolean isPortrait;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
orientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int orientation) {
@ookami-kb
ookami-kb / productFlavors.gradle
Last active January 12, 2016 21:30
Flavor-specific tasks
all { flavor ->
task("${flavor.name}GoogleServices", type: Copy) {
description = 'Switches to google-services.json depending on flavor'
from "src/${flavor.name}"
include "google-services.json"
into "."
}
}
// inspired by http://www.andreamaglie.com/rxjava-listener-to-observable/
interface ValueUpdateListener {
fun onValueChanged(value: String)
}
class ValueUpdater {
fun registerListener(listener: ValueUpdateListener) {
// ...
}