Skip to content

Instantly share code, notes, and snippets.

View JohnMars's full-sized avatar

Zhanibek Marshal JohnMars

  • Trade Republic
  • Germany, Berlin
View GitHub Profile
@JohnMars
JohnMars / BottomNavigationBehavior.kt
Created July 9, 2019 08:38 — forked from ValCanBuild/BottomNavigationBehavior.kt
Full code of a BottomNavigationBehavior which hides itself on scroll and handles Snackbars, FAB and snapping. https://medium.com/@ValCanBuild/scroll-your-bottom-navigation-view-away-with-10-lines-of-code-346f1ed40e9e
/**
MIT License
Copyright (c) 2018 Valentin Hinov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@JohnMars
JohnMars / FixToolbar.java
Last active August 29, 2015 14:25
Fixing bug that puts toolbar out of screen on API 21
private void fixApi21ToolBarBug(Toolbar toolbar){
if(Build.VERSION.SDK_INT!=21) return; //only on api 21
final int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
final int result = (resourceId>0) ? getResources().getDimensionPixelSize(resourceId)*2 : 0;
final CollapsingToolbarLayout.LayoutParams params =
(CollapsingToolbarLayout.LayoutParams)toolbar.getLayoutParams();
params.topMargin -= result;
toolbar.setLayoutParams(params);
}
/**
* Getting activities that are available for smsto:phone_number action
* and starting intent chooser to support on API version greater than Lollipop,
* because Lollipop is using default sms action provider as Hangouts
* as result, we couldn't give an option to choose intent provider
* @param context used to get package manager and start intent filter
* @param phoneNumber to send sms
*/
private void startMessengerIntent(Context context, String phoneNumber) {
Uri uri = Uri.parse("sms:" + phoneNumber);
/*
* Copyright (C) 2013-2015 Juha Kuitunen
* Copyright (C) 2007 The Android Open Source Project
*
* 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
*
@JohnMars
JohnMars / FacebookShare.java
Last active August 29, 2015 14:11
Sharing on Facebook with images
OpenGraphObject object = OpenGraphObject.Factory.createForPost("application:object");
recipe.setProperty("title", "your title");
recipe.setProperty("description", "your description");
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setType("application:share");
action.setProperty("object", object);
action.setProperty("message", "your message");
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "object")
@JohnMars
JohnMars / OnSwipeTouchListener.java
Created October 17, 2014 10:41
Swipe gesture listener
/**
* Created by John on 05.08.2014.
* Version 1.0
*/
public class OnSwipeTouchListener implements View.OnTouchListener {
private GestureDetector gestureDetector;
public OnSwipeTouchListener(Context c) {
gestureDetector = new GestureDetector(c, new GestureListener());
@JohnMars
JohnMars / FixedAspectLayout.java
Created September 19, 2014 11:13
Aspect Ration Layout
public class FixedAspectLayout extends FrameLayout {
private float aspect = 1.0f;
// .. alternative constructors omitted
public FixedAspectLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
@JohnMars
JohnMars / ExpandableTextView.java
Created August 20, 2014 09:52
Android - Expandable Text View
public class ExpandableTextView extends TextView {
private static final int DEFAULT_TRIM_LENGTH = 200;
private static final String ELLIPSIS = ".....";
private CharSequence originalText;
private CharSequence trimmedText;
private BufferType bufferType;
private boolean trim = true;
private int trimLength;
@JohnMars
JohnMars / DynamicClustering.java
Last active August 29, 2015 14:03
Dynamically adding cluster items to avoid lagging while moving Google maps camera
googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
LatLngBounds bounds = googleMap.getProjection().getVisibleRegion().latLngBounds;
new DynamicallyAddMarkerTask().execute(bounds);
}
});
private class DynamicClusteringTask extends AsyncTask<LatLngBounds, Void, Void> {
@JohnMars
JohnMars / EndlessScrollListener.java
Created July 11, 2014 05:34
Endless scroll listener for list view
import android.widget.AbsListView;
/**
* Created by JohnMars on 7/10/14.
* Version 1.0
*/
public abstract class EndlessScrollListener implements AbsListView.OnScrollListener {
private int visibleThreshold = 5;
// The current offset index of data you have loaded
private int currentPage = 0;