Skip to content

Instantly share code, notes, and snippets.

View ok3141's full-sized avatar

Oleksii ok3141

View GitHub Profile

###styles.xml

<style name="Theme.Custom.Dark" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <!-- -->
    <item name="android:windowAnimationStyle">@style/Custom.Window.Animation</item>
</style>

<style name="Custom.Window.Animation" parent="@android:style/Animation.Activity">
    <item name="android:activityOpenEnterAnimation">@anim/custom_in_next</item>
 @anim/custom_out_curr
@ok3141
ok3141 / Sample.java
Last active August 29, 2015 14:10
How to synchronize usage of stream providing direct reference on it? One of possible solutions
import java.io.PrintStream;
public class Sample {
public static final int COUNT = 10000;
public static void main(String[] args) {
final StreamHolder holder = new StreamHolder(System.out);
new Thread(new Runnable() {
@Override
@ok3141
ok3141 / gist:dbc06ae56258cb632a14
Created December 24, 2014 15:07
Color state list programmatically
private static ColorStateList createThemedColorStateList(Context context) {
TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(R.attr.selectableItemTextColor, typedValue, true);
int[] attribute = new int[]{R.attr.selectableItemTextColor};
TypedArray array = context.obtainStyledAttributes(typedValue.resourceId, attribute);
final int color;
@ok3141
ok3141 / gist:9106e4df26dd9d4ccc06
Last active August 29, 2015 14:12
Get values from attribute
private static int getDefaultColorFromAttribute(Context context, int attr) {
TypedArray array = obtainStyledAttributeResource(context, attr);
final int color;
try {
color = notNull(array.getColorStateList(0)).getDefaultColor();
} finally {
array.recycle();
package android.support.v4.preference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
@ok3141
ok3141 / build.gradle
Last active August 9, 2021 11:36
Gradle obfuscate string
apply from: "$rootDir/utils.gradle"
android {
defaultConfig {
buildConfigField 'String', 'SECRET_KEY', toJavaCodeString(SECRET_KEY)
}
}
@ok3141
ok3141 / gist:26bef66f10728bdf3e2d
Created March 25, 2015 09:52
Optimize ListView items which update frequently
public View getView(int position, View convertView, ViewGroup parent) {
// check convertView, inflate new layout, obtain ViewHolder, get data item, etc.
ViewHolder holder = ... ;
Data item = getItem(position);
if (holder.item != item) {
holder.item = item;
@ok3141
ok3141 / Somewhere.java
Created May 7, 2015 13:24
Relaunch Android app
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
@ok3141
ok3141 / BaseActivity.java
Created May 7, 2015 13:37
Prevent FC when starting 3rd-party Activity
public void startActivity(Intent intent) {
try {
super.startActivity(intent);
} catch (Throwable ex) {
if (SNAPSHOT) {
Log.wtf(LOG_TAG, ex);
}
}
}
@ok3141
ok3141 / SurfaceViewExt.java
Created July 15, 2015 11:18
How to use SurfaceView
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
import android.util.AttributeSet;
import android.view.SurfaceView;
public class SurfaceViewExt extends SurfaceView implements SurfaceViewHelper.Client {
private SurfaceViewHelper mHelper;