Skip to content

Instantly share code, notes, and snippets.

@StKotok
StKotok / MyActivity.java
Last active August 29, 2015 14:17
Hide ActionBar: put this code to onCreate method fo activity
try { // this hide ActionBar in Android app
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
} catch (NullPointerException ignore) {
}
@StKotok
StKotok / Activity.java
Last active August 29, 2015 14:18
Read/Write preferences example
public static final String PREFERENCES_FILE = "preferences.txt";
SharedPreferences preferences = this.getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE);
String pref1Value = preferences.getString("PREF_1", ""); // This get value of PREF_1 key
SharedPreferences.Editor edit = preferences.edit();
edit.putString("key", "value"); // This put value to PREF_1 key
edit.commit(); // This write preferences to disk
package net.neatapps.avi.app.util;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
@StKotok
StKotok / shape_blue_button.xml
Last active July 15, 2017 17:24
Button for API < 21
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_pressed="true">
<layer-list>
<!-- button background shadow -->
<item android:left="2dp" android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="@color/blue_shadow" />
<corners android:radius="6dp" />
@StKotok
StKotok / shape_blue_stroke_button.xml
Last active July 15, 2017 17:43
Button for API < 21
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_pressed="true">
<layer-list>
<!-- button background shadow -->
<item android:left="1dp" android:top="1dp">
<shape android:shape="rectangle">
<stroke android:width="3dp" android:color="@color/blue_shadow" />
<solid android:color="@color/transparent" />
@StKotok
StKotok / list_selector.xml
Last active August 5, 2017 20:05
selector for ListView with custom highlight effect API<21
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selected -->
<item android:state_focused="true" android:state_pressed="false">
<shape>
<solid android:color="#00ffffff" />
</shape>
</item>
@StKotok
StKotok / list_selector.xml
Last active August 5, 2017 20:06
selector for ListView with custom highlight effect. Put in drawable-v21
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<!-- Selected -->
<item android:state_focused="true" android:state_pressed="false">
<shape>
<solid android:color="#00ffffff" />
</shape>
</item>
@StKotok
StKotok / Prefs.java
Last active August 5, 2017 20:42
PreferencesWrapper
package co.neatapps.android.samples;
import android.content.Context;
import android.content.SharedPreferences;
import java.lang.reflect.ParameterizedType;
public class Prefs {
public static final ValueWrapper<Boolean> SAMPLE_BOOL_TOKEN = new ValueWrapper<Boolean>("SAMPLE_BOOL_TOKEN", false) {
};
package net.nemanjakovacevic.recyclerviewswipetodelete;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
class MyItemDecoration extends RecyclerView.ItemDecoration {
/*
Copyright 2018 *********.
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