Skip to content

Instantly share code, notes, and snippets.

View kathisai's full-sized avatar
💻
Focusing on open source

Kathi sai prathap reddy kathisai

💻
Focusing on open source
View GitHub Profile
@kathisai
kathisai / ItemClickSupport.java
Created September 18, 2016 16:20 — forked from nesquena/ItemClickSupport.java
Click handling for RecyclerView
/*
Source: http://www.littlerobots.nl/blog/Handle-Android-RecyclerView-Clicks/
USAGE:
ItemClickSupport.addTo(mRecyclerView).setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
@Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
// do it
}
});
@kathisai
kathisai / AccountAuthenticator.java
Created August 16, 2018 09:19 — forked from burgalon/AccountAuthenticator.java
Implementing OAuth2 with AccountManager, Retrofit and Dagger
public class AccountAuthenticator extends AbstractAccountAuthenticator {
private final Context context;
@Inject @ClientId String clientId;
@Inject @ClientSecret String clientSecret;
@Inject ApiService apiService;
public AccountAuthenticator(Context context) {
super(context);
@kathisai
kathisai / java_abstraction.java
Last active January 5, 2019 10:53
abstraction with abstract class
// ABSTRACT CLASSES
// An abstract class only has method declarations. it is intended to be
// a superclass for other classes. It doesn't define how methods are
// implemented, only that they are implemented. Abstract classes cannot
// be instantiated and subclasses MUST implement abstract methods.
abstract class FlyingAnimal {
public abstract void Fly();
}
@kathisai
kathisai / java_abstraction_shape.java
Created January 5, 2019 11:39
Complete example of java abstraction
abstract class Shape
{
String color;
// these are abstract methods
abstract double area();
// abstract class can have constructor
public Shape(String color) {
this.color = color;
}
//Interface declaration: by first user
interface Drawable{
void draw();
}
//Implementation: by second user
class Rectangle implements Drawable{
public void draw(){
System.out.println("drawing rectangle");
}
}
FragmentB fragmentA= new FragmentB();
fragmentA.setTargetFragment(FragmentA.this, REQUEST_DATE);
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.Layout_container, nextFrag, “findThisFragment”).addToBackStack(null).commit();
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
 if (resultCode != Activity.RESULT_OK) {
 return;
 }
 if (requestCode == REQUEST_DATE) { 
 Date date = (Date) data .getSerializableExtra("EXTRA_DATE"); //EXTRA_DATE is key used in FragmentB
 }
}
private void sendResult(int resultCode, Date date) {
 if (getTargetFragment() == null) {
 return;
 }
Intent intent = new Intent(); 
 intent.putExtra(EXTRA_DATE, date); 
 getTargetFragment() .onActivityResult(getTargetRequestCode(), resultCode, intent);
 } 
}
public class ExampleService extends IntentService {
private static final String TAG = "ExampleService";
public static Intent newIntent(Context context) {
return new Intent(context, ExampleService.class);
}
public ExampleService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
class ExampleService : IntentService("ExampleService") {
override fun onHandleIntent(intent: Intent?) {
// Normally we would do some work here, like download a file.
// For our sample, we just sleep for 5 seconds.
try {
Thread.sleep(5000)
} catch (e: InterruptedException) {
// Restore interrupt status.