Skip to content

Instantly share code, notes, and snippets.

View dmitriy-chernysh's full-sized avatar
🚀
Building Android apps

Dmitri Chernysh dmitriy-chernysh

🚀
Building Android apps
View GitHub Profile
@dmitriy-chernysh
dmitriy-chernysh / hideKeyboard.java
Created May 8, 2018 13:38
Android. Hide keyboard
@Override
public void hideKeyboard() {
Activity activity = getActivity();
if (activity == null) return;
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
@dmitriy-chernysh
dmitriy-chernysh / DrawingView.java
Created April 4, 2018 15:32
Custom view for drawing
public class DrawingView extends View implements IDrawingView {
private static final int TOUCH_TOLERANCE = 4;
private static final int PAINT_COLOR = 0xff1565C0;
private static final int PAINT_BRUSH_SIZE = 20;
// To hold the path that will be drawn.
private Path mDrawPath;
// Paint object to draw drawPath and drawCanvas.
private Paint mDrawPaint, mCanvasPaint;
@dmitriy-chernysh
dmitriy-chernysh / fileToByteArray
Last active December 19, 2017 16:20
Java. readBytes from File
private static byte[] readBytes(@NonNull File file) throws IOException {
byte[] byteArray = null;
InputStream inputStream = null;
ByteArrayOutputStream outputStream = null;
try {
inputStream = new FileInputStream(file);
outputStream = new ByteArrayOutputStream();
byte[] b = new byte[1024 * 4];
int bytesRead = 0;
/**
* Divider for RecyclerView list items
* <p>
* Created by Dmitriy V. Chernysh on 24.09.16.
* [email protected]
* <p>
* www.mobile-dev.pro
*/
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
@dmitriy-chernysh
dmitriy-chernysh / .gitignore
Created September 9, 2016 13:00
Gitignore for android projects
.gradle
.DS_Store
/build
/captures
.idea
*.txt
*.apk
*.iml
*.properties
wiki
# Need to paste this into the file [HOME]/[username]/.gradle/gradle.properties
# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
public class FragmentsHelper {
private static Fragment sCurrentVisibleFragment;
/**
* Method for creating new fragment
* @param fm FragmentManager
*/
public static void createFragment(FragmentManager fm, Fragment newFragment, boolean addToBackStack) {
@dmitriy-chernysh
dmitriy-chernysh / Activity.java
Created August 20, 2015 12:46
Implement onBackPressed() in Fragment
......
@Override
public void onBackPressed() {
OnBackPressedListener listener = null;
boolean backInFragment = false;
//back pressed listener in fragment
@dmitriy-chernysh
dmitriy-chernysh / isGooglePlayServicesAvailable.java
Created August 11, 2015 18:33
isGooglePlayServicesAvailable method
private boolean isGooglePlayServicesAvailable() {
// Check that Google Play services is available
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// If Google Play services is available
if (ConnectionResult.SUCCESS == resultCode) {
// In debug mode, log the status
Log.d("Location Updates", "Google Play services is available.");
return true;
} else {
// Get the error dialog from Google Play services