Last active
March 8, 2019 05:30
-
-
Save keyboardr/5455206 to your computer and use it in GitHub Desktop.
Revisions
-
keyboardr revised this gist
Jun 9, 2015 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,15 +3,15 @@ public class FragmentUtils { /** * @param fragment * The Fragment whose parent is to be found * @param parentClass * The interface that the parent should implement * @return The parent of fragment that implements parentClass, * null, if no such parent can be found */ @Nullable public static <T> T getParent(@NonNull Fragment fragment, @NonNull Class<T> parentClass) { Fragment parentFragment = fragment.getParentFragment(); if (parentClass.isInstance(parentFragment)) { //Checked by runtime methods -
keyboardr revised this gist
Jun 7, 2015 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ import android.support.v4.app.Fragment; public class FragmentUtils { -
keyboardr revised this gist
Jun 7, 2015 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,18 +2,18 @@ import android.support.v4.app.FragmentActivity; public class FragmentUtils { /** * @param frag * The Fragment whose parent is to be found * @param callbackInterface * The interface class that the parent should implement * @return The parent of frag that implements the callbackInterface or null * if no such parent can be found */ @Nullable public static <T> T getParent(@NonNull Fragment frag, @NonNull Class<T> callbackInterface) { Fragment parentFragment = fragment.getParentFragment(); if (parentClass.isInstance(parentFragment)) { //Checked by runtime methods //noinspection unchecked @@ -24,5 +24,5 @@ public static <T> T getParent(@NonNull Fragment frag, @NonNull Class<T> callback return (T) fragment.getActivity(); } return null; } } -
keyboardr revised this gist
Jun 7, 2015 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ Copyright 2015 Joshua Brown Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -
keyboardr revised this gist
Jun 7, 2015 . 1 changed file with 14 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import android.support.v4.app.FragmentActivity; public class FragmentUtils { /** * @param frag * The Fragment whose parent is to be found @@ -10,18 +11,18 @@ public class FragmentUtils { * @return The parent of frag that implements the callbackInterface or null * if no such parent can be found */ @Nullable public static <T> T getParent(@NonNull Fragment frag, @NonNull Class<T> callbackInterface) { Fragment parentFragment = fragment.getParentFragment(); if (parentClass.isInstance(parentFragment)) { //Checked by runtime methods //noinspection unchecked return (T) parentFragment; } else if (parentClass.isInstance(fragment.getActivity())) { //Checked by runtime methods //noinspection unchecked return (T) fragment.getActivity(); } return null; } } -
keyboardr revised this gist
Apr 24, 2013 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,14 @@ import android.support.v4.app.FragmentActivity; public class FragmentUtils { /** * @param frag * The Fragment whose parent is to be found * @param callbackInterface * The interface class that the parent should implement * @return The parent of frag that implements the callbackInterface or null * if no such parent can be found */ @SuppressWarnings("unchecked") // Casts are checked using runtime methods public static <T> T getParent(Fragment frag, Class<T> callbackInterface) { Fragment parentFragment = frag.getParentFragment(); -
keyboardr created this gist
Apr 24, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; public class FragmentUtils { @SuppressWarnings("unchecked") // Casts are checked using runtime methods public static <T> T getParent(Fragment frag, Class<T> callbackInterface) { Fragment parentFragment = frag.getParentFragment(); if (parentFragment != null && callbackInterface.isInstance(parentFragment)) { return (T) parentFragment; } else { FragmentActivity activity = frag.getActivity(); if (activity != null && callbackInterface.isInstance(activity)) { return (T) activity; } } return null; } }