Skip to content

Instantly share code, notes, and snippets.

View mibrahimdev's full-sized avatar
🐞
Bugging

Mohamed Ibrahim mibrahimdev

🐞
Bugging
View GitHub Profile
public class ChronoActivity2 extends AppCompatActivity {
@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// The ViewModelStore provides a new ViewModel or one previously created.
ChronometerViewModel chronometerViewModel
= ViewModelProviders.of(this).get(ChronometerViewModel.class);
/**
* A ViewModel used for the {@link ChronoActivity2}.
*/
public class ChronometerViewModel extends ViewModel {
@Nullable private Long mStartTime;
@Nullable
public Long getStartTime() {
return mStartTime;
public class LocationActivity extends AppCompatActivity {
...
private void bindLocationListener() {
//You can safely pass (this) as it expose only the type not the view
BoundLocationManager.bindLocationListenerIn(this, mGpsListener, getApplicationContext());
@mibrahimdev
mibrahimdev / BoundLocationManager.java
Created May 29, 2018 17:55
Android architecure components
public class BoundLocationManager {
public static void bindLocationListenerIn(LifecycleOwner lifecycleOwner, LocationListener listener, Context context) {
new BoundLocationListener(lifecycleOwner, listener, context);
}
@SuppressWarnings("MissingPermission")
static class BoundLocationListener implements LifecycleObserver {
...
public BoundLocationListener(LifecycleOwner lifecycleOwner, LocationListener listener, Context context) {
@mibrahimdev
mibrahimdev / MainActiviy.java
Last active March 11, 2017 12:09
5 design patterns every Android developer should know - how to use Builder pattern
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//how to create your object using builder pattern
Ship ship = new Ship.Builder().setName("Avenger")
.howManyCrew(12)
.howManyGuns(10)
@mibrahimdev
mibrahimdev / Ship.java
Last active March 11, 2017 12:15
5 design patterns every Android developer should know - Builder pattern
public class Ship {
private String name;
private String area;
private int guns;
private int crew;
private String radarType;
//normal getters
public String getName() {
@mibrahimdev
mibrahimdev / Singleton.java
Last active January 28, 2017 20:38
5 design patterns every Android developer should know - Singleton pattern
public class Singleton {
//instance holder
private static Singleton mInstance = null;
private String mString;
//prevent others from instantiating the class with new keyword
private Singleton(){
mString = "Hello";
}
@mibrahimdev
mibrahimdev / API.md
Created November 28, 2016 08:45 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method: