/** * Create a {@code LoadingLayout} instance matched by <b>{@code clazz} token</b> * * @param layoutCode Loading layout code, which must be defined in pulltorefresh.xml * @param context * @param mode * @return {@code LoadingLayout} instance if the class matched by {@code layoutCode} exists, or * {@code RotateLoadingLayout} instance if not */ public static LoadingLayout createLoadingLayout( Class<? extends LoadingLayout> clazz, Context context, Mode mode, Orientation orientation, TypedArray attrs) { LoadingLayout layout = null; // Prevent NullPointerException if (clazz == null) { Log.i( LOG_TAG, "The Class token of the Loading Layout is missing. Default Loading Layout will be used."); clazz = DefaultLoadingLayoutFactory.createLoadingLayoutClazz(""); } layout = tryNewInstance(clazz, context, mode, orientation, attrs); // If trying to create new instance has failed, if (layout == null) { layout = DefaultLoadingLayoutFactory.createLoadingLayout(clazz, context, mode, orientation, attrs); } layout.setVisibility(View.INVISIBLE); return layout; }
/** * Create a {@code LoadingLayout} instance matched by <b>{@code clazz} token</b> * * @param layoutCode Loading layout code, which must be defined in pulltorefresh.xml * @param context * @param mode * @return {@code LoadingLayout} instance if the class matched by {@code layoutCode} exists, or * {@code RotateLoadingLayout} instance if not */ @SuppressWarnings("unchecked") public static Class<? extends LoadingLayout> createLoadingLayoutClazz(String clazzName) { Class<? extends LoadingLayout> loadingLayoutClazz = null; if (clazzName == null) { loadingLayoutClazz = DefaultLoadingLayoutFactory.createLoadingLayoutClazz(clazzName); return loadingLayoutClazz; } try { loadingLayoutClazz = (Class<LoadingLayout>) Class.forName(clazzName); } catch (ClassNotFoundException e) { Log.e(LOG_TAG, "The loading layout you have chosen class has not been found.", e); loadingLayoutClazz = DefaultLoadingLayoutFactory.createLoadingLayoutClazz(clazzName); } return loadingLayoutClazz; }