Skip to content

Instantly share code, notes, and snippets.

View cutiko's full-sized avatar

Erick Navarro cutiko

View GitHub Profile
@cutiko
cutiko / AlarmBroadcaster.java
Created February 13, 2016 22:49
How to set an alarm Android (AlarmManager)
public class AlarmBroadcaster extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//Remember in the SetAlarm file we made an intent to this, this is way this work, otherwise you would have to put an action
//and here listen to the action, like in a normal receiver
createNotification(context);
}
public void createNotification(Context context) {
@cutiko
cutiko / SomeActivity.java
Created February 19, 2016 02:31
Falling leaf animation
//This code is highly summarized
private int height;
private Timer timer;
private int leafFallDuration = 6000;
private int leafRotationDuration = 900;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@cutiko
cutiko / TabAdapter.java
Created February 19, 2016 15:51
Two state icons for tabs adapter
public class TabsAdapter extends FragmentStatePagerAdapter {
//Add this method to all the other override methods
public int getPageIcon(int position) {
Integer id;
switch (position){
case 0:
id = R.layout.layout_example;
break;
@cutiko
cutiko / TrackerComparison.md
Last active August 19, 2016 13:02
Mobile App tracker comparison
Events Performance Crashs Http requests Problems
Fabric Easy to implement and very neat to read No Ver easy to understand, includes memory usage No Limited
AppDynamics Configurable Something like it Automatic, a lot of info, but not neat Automatic, its awesome! Has everything! Compile time went from 7 to
@cutiko
cutiko / SyncScrollsActivity.java
Last active June 28, 2016 18:47
Syncronized scroll views
//We will simply pass two ScrollViews to our method.
//This is not perfect cause you have to syncScrolls(first, second), and then syncScrolls(second, first)
//Please look at the xml below, the views to pass should be rightHeader, rightBody and viceversa
private void syncScrolls(final HorizontalScrollView currentView, final HorizontalScrollView otherView) {
GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDoubleTap(MotionEvent e) {
return true;
@cutiko
cutiko / broadcast.java
Created May 27, 2016 18:08
Simple Android Broadcast
Intent broadcast = new Intent();
broadcast.setAction("YourBroadcastKey");
broadcast.putExtra("extraKey", value);
sendBroadcast(broadcast);
@cutiko
cutiko / ActivityIntent.java
Last active August 25, 2016 20:42
Android simpliest Activity Intent
Intent goToActivity = new Intent(YourCurrentActivity.this, OtherActivity.class);
startActivity(goToActivity);
//The first param in setClass() is the context, usually can be YourCurrentActivity.this but also can be,
//this, getApplicationContext, getContext, or Contex context if variable context was initialized before
@cutiko
cutiko / CustomRecyclerAdapter.java
Last active November 3, 2021 08:34
How to work with adapters, RecyclerView and ListView
//Create the inner class before extending it, yes obvious, but sometimes can be forgotten
public class CustomRecyclerAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
//Sometimes you can have your set of data as empty but initialized and then update it using an update method
//This is usefull when you want to do an http request, set the adapter empty then when the AsyncTask is done, refresh it
private List<YourObject> mObjects = new ArrayList();
//There is no constructor matching the super here, so create your own with what ever you need
public CustomAdapter() {
}
@cutiko
cutiko / bg_image.xml
Created June 16, 2016 22:37
Use images inside drawables
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:gravity="bottom|center_horizontal"
android:src="@mipmap/ic_drag_handle_white_18px" />
</item>
</layer-list>
@cutiko
cutiko / Dialog.java
Last active July 25, 2018 15:33
Android Dialogs Cheat Sheet
/*CUSTOM LAYOUT*/
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_background_primary_dark);
//Then to find a view inside the custom layout use the dialog as root view
EditText inputEt = (EditText) dialog.findViewById(R.id.inputEt);
/*FULLSCREEN*/
//The style below can be replaced by any fullscreen style, you can create a fullscreen activity and use that style
Dialog fullScreen = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);