This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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 | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class Shape | |
| { | |
| String color; | |
| // these are abstract methods | |
| abstract double area(); | |
| // abstract class can have constructor | |
| public Shape(String color) { | |
| this.color = color; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FragmentB fragmentA= new FragmentB(); | |
| fragmentA.setTargetFragment(FragmentA.this, REQUEST_DATE); | |
| getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.Layout_container, nextFrag, “findThisFragment”).addToBackStack(null).commit(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
OlderNewer