/
FragmentUtil.java
57 lines (48 loc) · 2.32 KB
/
FragmentUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package roboguice.fragment;
import com.google.inject.Provider;
import android.app.Activity;
import android.view.View;
/**
* Fragment utility class, it's actual implementation will use native or support library v4 fragment's based
* on whether or not the underlying app uses support library or not.
* @author Charles Munger
*/
@SuppressWarnings({ "unchecked", "rawtypes","PMD" }) //Need an unchecked conversion
public final class FragmentUtil {
public static final String SUPPORT_PACKAGE = "android.support.v4.app.";
public static final String NATIVE_PACKAGE = "android.app.";
//CHECKSTYLE :OFF
@edu.umd.cs.findbugs.annotations.SuppressWarnings("MS_SHOULD_BE_REFACTORED_TO_BE_FINAL")
public static f nativeFrag = null;
@edu.umd.cs.findbugs.annotations.SuppressWarnings("MS_SHOULD_BE_REFACTORED_TO_BE_FINAL")
public static f supportFrag = null;
@edu.umd.cs.findbugs.annotations.SuppressWarnings("MS_SHOULD_BE_REFACTORED_TO_BE_FINAL")
public static Class<? extends Activity> supportActivity = null;
@edu.umd.cs.findbugs.annotations.SuppressWarnings("MS_SHOULD_BE_REFACTORED_TO_BE_FINAL")
public static boolean hasNative = false;
@edu.umd.cs.findbugs.annotations.SuppressWarnings("MS_SHOULD_BE_REFACTORED_TO_BE_FINAL")
public static boolean hasSupport = false;
//CHECKSTYLE :ON
public interface f<fragType,fragManagerType> {
View getView(fragType frag);
fragType findFragmentById(fragManagerType fm, int id);
fragType findFragmentByTag(fragManagerType fm, String tag);
Class<fragType> fragmentType();
Class<fragManagerType> fragmentManagerType();
Class<Provider<fragManagerType>> fragmentManagerProviderType();
}
static {
try {
nativeFrag = (f) Class.forName("roboguice.fragment.provided.NativeFragmentUtil").newInstance();
hasNative = nativeFrag != null;
} catch (Throwable e) {}
try {
supportFrag = (f) Class.forName("roboguice.fragment.support.SupportFragmentUtil").newInstance();
supportActivity = (Class<? extends Activity>) Class.forName(SUPPORT_PACKAGE+"FragmentActivity");
hasSupport = supportFrag != null && supportActivity != null;
} catch (Throwable e) {}
}
private FragmentUtil() {
//private utility class constructor
}
}