Skip to content

Instantly share code, notes, and snippets.

View amitshekhariitbhu's full-sized avatar
🎯
Helping developers in getting high-paying tech jobs

AMIT SHEKHAR amitshekhariitbhu

🎯
Helping developers in getting high-paying tech jobs
View GitHub Profile
package com.mindorks.snaphelperexample.ui.common;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSnapHelper;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**
* Example of using Button driver for toggling a LED.
*
* This activity initialize an InputDriver to emit key events when the button GPIO pin state change
* and flip the state of the LED GPIO pin.
*
* You need to connect an LED and a push button switch to pins specified in {@link BoardDefaults}
* according to the schematic provided above.
*/
public class ButtonActivity extends Activity {
public class BoardDefaults {
private static final String DEVICE_EDISON_ARDUINO = "edison_arduino";
private static final String DEVICE_EDISON = "edison";
private static final String DEVICE_RPI3 = "rpi3";
private static final String DEVICE_NXP = "imx6ul";
private static String sBoardVariant = "";
/**
* Return the GPIO pin that the LED is connected on.
* For example, on Intel Edison Arduino breakout, pin "IO13" is connected to an onboard LED
public void onCreate() {
if (DEVELOPER_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface Status {
public enum Priority {LOW, MEDIUM, HIGH}
Priority priority() default Priority.LOW;
String author() default “Amit”;
int completion() default 0;
}
Class foo = Foo.class;
for(Method method : foo.getMethods()) {
Status statusAnnotation = (Status)method.getAnnotation(Status.class);
if(statusAnnotation != null) {
System.out.println(" Method Name : " + method.getName());
System.out.println(" Author : " + statusAnnotation.author());
System.out.println(" Priority : " + statusAnnotation.priority());
System.out.println(" Completion Status : " + statusAnnotation.completion());
}
}
public class CompositeDisposableExampleActivity extends AppCompatActivity {
private final CompositeDisposable disposables = new CompositeDisposable();
@Override
protected void onCreate(Bundle savedInstanceState) {
doSomeWork();
}
@Override
/*
* First of all we are getting my friends list from
* server, then by using flatMap we are emitting users
* one by one and then after applying filter we are
* returning only those who are following me one by one.
*/
/*
* This observable return the list of User who are my friends
*/
/*
* This observable return the list of User who loves cricket
*/
private Observable<List<User>> getCricketFansObservable() {
return RxAndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllCricketFans")
.build()
.getObjectListObservable(User.class);
}
/*
RxAndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAnUser/{userId}")
.addPathParameter("userId", "1")
.build()
.getObjectObservable(ApiUser.class) // This returns you an Observable
.subscribeOn(Schedulers.io()) // do the network call on another thread
.observeOn(AndroidSchedulers.mainThread()) // return the result in mainThread
.map(new Func1<ApiUser, User>() {
@Override
public User call(ApiUser apiUser) {
// here we get ApiUser from server