Skip to content

Instantly share code, notes, and snippets.

View eyeahs's full-sized avatar

박현우(HyunwooPark) eyeahs

  • Hyundai
  • South Korea
View GitHub Profile
@eyeahs
eyeahs / CustomAsyncTaskLoader
Last active August 29, 2015 14:03
Custom AsyncTaskLoader
public class CustomLoader extends AsyncTaskLoader<List<Data>> {
private List<Data> cachedData;
private ContentObserver observer = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
// CallLog Uri에 변경이 발생한 경우 LoadTask를 갱신한다.
onContentChanged();
@eyeahs
eyeahs / AsyncTaskWithFragment
Last active August 29, 2015 14:03
AsyncTask in Fragment
private static class MyAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<MyFragment> fragmentWeakRef;
private MyAsyncTask (MyFragmentfragment) {
this.fragmentWeakRef = new WeakReference<MyFragment>(fragment);
}
@Override
protected Void doInBackground(Void... params) {
@eyeahs
eyeahs / ActivityWithAsyncTask
Last active August 29, 2015 14:03
AsyncTask in Actvity
/*
AsyncTask can not be coded as instance inner class (non-static).
An instance inner class is tied to an instance of the containing class and it cannot be changed.
So, it is not possible to relink an instance of an async task to the new instance of the activity (on rotation).
What happens : when the async task finishes and onPostExecute is executed, the old activity is updated and not the new one.
*/
public class MyActivity extends Activity {
/*
@eyeahs
eyeahs / MultiItemsCursorAdapter
Created July 23, 2014 02:36
CursorAdapter with two list items
Public class MultiItemsCursorAdapter extends CursorAdapter {
private static final int FIRST_ITEM_TYPE = 0;
private static final int SECOND_ITEM_TYPE = 1;
private static final int TYPE_MAX_CCOUNT = SECOND_ITEM + 1;
private final LayoutInflater layoutInflater;
private final MVPPresenter presenter;
public static class ViewHolder {
@InjectView(R.id.text_view)

##Getting results from DialogFragments to another Fragment.

When setting up the DialogFragment make a call to Fragment.setTargetFragment()
Then from DialogFragment you can access the main fragment with Fragment.getTargetFragment()
Use interfaces to provide the required actions to the calling Fragment.

##Example code.

###AddFriendDialogFragment - Calls back to calling fragment.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- disabled -->
<item android:color="#ff000000" android:state_enabled="false" />
<!-- pressed -->
<item android:color="#ff000000" android:state_enabled="true" android:state_pressed="true" />
<!-- focused -->
<item android:color="#ff000000" android:state_enabled="true" android:state_focused="true" />
@eyeahs
eyeahs / manipulating List
Last active August 29, 2015 14:11
Collection Gist
// Delete items while iterate
Iterator<Long> iterator = anyArrayList.iterator();
while (iterator.hasNext()) {
long value = iterator.next();
if (/** condition **/) {
iterator.remove();
}
}
// Find duplicates
public enum EnumCode {
ABC(R.string.abc),
DEF(R.string.def),
GHI(R.string.ghi);
private final int stringResourceId;
public static EnumCode fromString(String name) {
for (EnumCode code : EnumCode.values()) {
if (code.name().equalsIgnoreCase(name)) {
@eyeahs
eyeahs / MyTest.java
Created May 10, 2016 08:28 — forked from romainpiel/MyTest.java
Source for https://medium.com/p/3f6f4179652e - "RecyclerView and espresso, a complicated story"
RecyclerViewInteraction.<Item>onRecyclerView(withId(R.id.recyclerview))
.withItems(items)
.check(new ItemViewAssertion<Item>() {
@Override
public void check(Item item, View view, NoMatchingViewException e) {
matches(hasDescendant(withText(item.getDisplayName())))
.check(view, e);
}
});
@eyeahs
eyeahs / DefaultInjectingHelper.java
Last active December 29, 2016 02:00
Reflection of overloaded methods
public class DefaultInjectingHelper {
public static void main(String[] args) {
final Component component = new ComponentMockImpl();
final BaseDependecy a = new A();
injectWithReflection(component, a);
}
public void injectWithReflection(Component component, Object target) throws InterruptedException {