Skip to content

Instantly share code, notes, and snippets.

View artem-zinnatullin's full-sized avatar
:shipit:

Artem Zinnatullin artem-zinnatullin

:shipit:
View GitHub Profile
@artem-zinnatullin
artem-zinnatullin / gist:6916740
Last active October 26, 2020 12:15
Android support library onActivityResult() bug fix for nested fragments
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// notifying nested fragments (support library bug fix)
final FragmentManager childFragmentManager = getChildFragmentManager();
if (childFragmentManager != null) {
final List<Fragment> nestedFragments = childFragmentManager.getFragments();
@artem-zinnatullin
artem-zinnatullin / MyApp.java
Last active January 15, 2023 13:04
If you need to set one font for all TextViews in android application you can use this solution. It will override ALL TextView's typefaces, includes action bar and other standard components, but EditText's password font won't be overriden.
public class MyApp extends Application {
@Override
public void onCreate() {
TypefaceUtil.overrideFont(getApplicationContext(), "SERIF", "fonts/Roboto-Regular.ttf"); // font from assets: "assets/fonts/Roboto-Regular.ttf
}
}
@artem-zinnatullin
artem-zinnatullin / GCMHelper.java
Last active December 30, 2015 05:39 — forked from beshkenadze/GCMHelper.java
GCMHelper improvements
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging;
@artem-zinnatullin
artem-zinnatullin / App.cs
Created December 20, 2013 22:28
Changing windows phone app localization at runtime via bindings!
public class App : Application
{
// ... bla bla
// when app is launching, we should set its language to previous saved or best for user's system language or default for application
private void Application_Launching(object sender, LaunchingEventArgs e)
{
LocalizationManager.ChangeAppLanguage(LocalizationManager.GetCurrentAppLang());
}
}
public static String getIntentExtrasAsString(Intent intent) {
if (intent == null || intent.getExtras() == null || intent.getExtras().isEmpty()) return "no extras or null intent";
StringBuilder stringBuilder = new StringBuilder();
for (String key : intent.getExtras().keySet()) {
stringBuilder.append("(" + key + ", " + intent.getExtras().get(key) + ")")
.append(", ");
}
@artem-zinnatullin
artem-zinnatullin / build.gradle
Created July 17, 2014 07:30
Gradle & Android: Disable/Enable preDexing
// add this to the general build.gradle, not in the subproject's build.gradle
// improved version of Xavier's tip http://tools.android.com/tech-docs/new-build-system/tips#TOC-Improving-Build-Server-performance.
// usage example default, preDex will be enabled: gradle clean build
// usage example disabling preDex: gradle clean build -PpreDexEnable=false
// preDexEnable parameter's value can be set as property of Continuous Integration build config
// this is the main difference from Xavier's workaround where he doing only hasProperty check
project.ext {
if (project.hasProperty('preDexEnable')) {
@artem-zinnatullin
artem-zinnatullin / ShortCreateAndFillCollection
Created August 28, 2014 13:59
Short write of Collection creation and filling
Collection<String> stringsCollection = new ArrayList<String>() {
{
add("1");
add("2");
add("3");
}
};
@artem-zinnatullin
artem-zinnatullin / Dangerous.java
Created August 29, 2014 14:09
Dangerous annotation for Java
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to mark code as dangerous
*
* @author Artem Zinnatullin [artem.zinnatullin@gmail.com]
*/
@artem-zinnatullin
artem-zinnatullin / bg_common
Created January 22, 2015 21:23
Common Ripple drawable
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/bg_item_ripple">
<item>
<selector>
<item android:state_pressed="true" android:drawable="@color/bg_item_pressed"/>
<item android:state_focused="true" android:drawable="@color/bg_item_focused"/>
<item android:drawable="@color/bg_item_normal"/>
</selector>
</item>
@artem-zinnatullin
artem-zinnatullin / build.gradle
Created January 27, 2015 17:01
Root build.gradle with Kotlin Gradle plugin
buildscript {
repositories {
jcenter() // or use mavenCentral() repo
}
// Please visit http://search.maven.org
// or https://bintray.com to find newest versions of dependencies
dependencies {
// Android Gradle plugin
classpath 'com.android.tools.build:gradle:1.0.1'