Skip to content

Instantly share code, notes, and snippets.

Miles Peele mformetal

View GitHub Profile
@mformetal
mformetal / build.gradle
Created Jun 7, 2016
Gradle command line builds
View build.gradle
task appStart(type: Exec, dependsOn: 'installDebug') {
def adb = "$System.env.ANDROID_HOME/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'package.name/activityclass'
}
@mformetal
mformetal / BaseFragment.java
Created Apr 5, 2016
Base-Handling class for Fragments. Yes, I hate casting this much.
View BaseFragment.java
public abstract class BaseFragment extends Fragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
((MainApp) context.getApplicationContext()).getApplicationComponent().inject(this);
Map<Object, Class> map = getCastMap();
for (Object object: map.keySet()) {
Class clazz = map.get(object);
@mformetal
mformetal / MotionEventHandler.java
Created Mar 8, 2016
My solution to the Pinch-To-Zoom problem
View MotionEventHandler.java
// Defines the actions of the Zoomer class. Feel free to implement as you see fit
public interface MotionEventHandler {
// Defines which "Mode" the user is in. NONE means they have not taken any action, DRAG means tehy're dragging,
// ZOOM means they're zooming
enum Mode {
NONE,
DRAG,
ZOOM
}
View CancelEditTextListener.java
public class CancelEditTextListener {
private EditText widget;
private Drawable[] hideDrawables;
private Drawable canceler;
public CancelListener(EditText editText) {
widget = editText;
widget.addTextChangedListener(textWatcher);
View.OnTouchListener touchListener = (v, event) -> {
@mformetal
mformetal / PreDrawer.java
Last active Apr 7, 2017
A simple way to add a predraw listener to a view
View PreDrawer.java
public abstract class PreDrawer<T extends View> {
// Private constructor prevent instantiation by the caller. Use addPredrawer() method instead.
private PreDrawer(final T view) {
// Adds the observer to the given view, then calls notifyPredraw() when clean up has been done ready
final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();
viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
You can’t perform that action at this time.