Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2013 Naver Business Platform Corp. 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. /
 
 package com.handmark.pulltorefresh.library;
 
 
 
Factory which creates indicator layouts
Indicator layouts must be listed in pulltorefresh.xml as "PullToRefresh/IndicatorLayouts/layout" nodes

Author(s):
Wonjun Kim
 
 public class IndicatorLayoutFactory {
 
 	private static final String LOG_TAG = IndicatorLayoutFactory.class.getName();
Create the class token matched by layoutCode

Parameters:
layoutCode Indicator layout code, which must be defined in pulltorefresh.xml
Returns:
Class token which is matched by layoutCode, or the class token of DefaultIndicatorLayout instance if not
 
 	public static Class<? extends IndicatorLayoutcreateIndicatorLayoutClazzByLayoutCode(String layoutCode) {
 		String clazzName = PullToRefreshXmlConfiguration.getInstance().getIndicatorLayoutClazzName(layoutCode);
 		return createIndicatorLayoutClazz(clazzName);
 	}
Create the class token matched by class name

Parameters:
clazzName Class name such as "com.handmark.pulltorefresh.library.internal.DefaultIndicatorLayout"
Returns:
Class token if the class matched by class name exists, or the class token of DefaultIndicatorLayout instance if not
 
 	@SuppressWarnings("unchecked")
 	public static Class<? extends IndicatorLayoutcreateIndicatorLayoutClazz(String clazzName) {
 		Class<? extends IndicatorLayoutclazz = null;
 		if (clazzName == null) {
 			clazz = DefaultIndicatorLayoutFactory.createIndicatorLayoutClazz(clazzName);
 			return clazz;
 		}
 		
  		try {
 			clazz = (Class<? extends IndicatorLayout> )Class.forName(clazzName);
 			
 		} catch (ClassNotFoundException e) {
 			Log.e("The indicator layout you have chosen class has not been found."e);
 			clazz = DefaultIndicatorLayoutFactory.createIndicatorLayoutClazz(clazzName);
 			
 		}
 		
 		return clazz;
 	}
Create a IndicatorLayout instance matched by layoutCode

Parameters:
layoutCode Indicator layout code, which must be defined in pulltorefresh.xml
context
mode
Returns:
IndicatorLayout instance if the class matched by layoutCode exists, or DefaultIndicatorLayout instance if not
 
 	public static IndicatorLayout createIndicatorLayout(String layoutCodeContext contextPullToRefreshBase.Mode mode) {
 		Class<? extends IndicatorLayoutclazz = createIndicatorLayoutClazz(layoutCode);
 		return createIndicatorLayout(clazzcontextmode);
 	}
Create a IndicatorLayout instance matched by clazz token

Parameters:
clazz Indicator layout class token, which must be defined in pulltorefresh.xml
context
mode
Returns:
IndicatorLayout instance if the class matched by layoutCode exists, or DefaultIndicatorLayout instance if not
 
 			Class<? extends IndicatorLayoutclazzContext contextMode mode) {
 		IndicatorLayout layout = null;
 		// Prevent NullPointerException 
 		if ( clazz == null ) {
 			Log.i("The Class token of the Indicator Layout is missing. Default Indicator Layout will be used.");
 			clazz = DefaultIndicatorLayoutFactory.createIndicatorLayoutClazz("");
 		}
 		
 		layout = tryNewInstance(clazzcontextmode);
 		
		// If trying to create new instance has failed,
		if (layout == null) {
			layout = DefaultIndicatorLayoutFactory.createIndicatorLayout(clazzcontextmode);
		}
		return layout;
	}
			Class<? extends IndicatorLayoutclazzContext contextMode mode) {
		IndicatorLayout layout = null;
		try {
			Constructor<? extends IndicatorLayoutconstructor = clazz
					.getConstructor(Context.classMode.class);
			layout = (IndicatorLayoutconstructor.newInstance(contextmode);
catch (IllegalArgumentException e) {
			Log.e("The indicator layout has failed to be created. "e);
catch (InvocationTargetException e) {
			Log.e("The indicator layout has failed to be created. "e);
catch (SecurityException e) {
			Log.e("The indicator layout has failed to be created. "e);
catch (NoSuchMethodException e) {
			Log.e("The indicator layout has failed to be created. "e);
catch (InstantiationException e) {
			Log.e("The indicator layout has failed to be created. "e);
catch (IllegalAccessException e) {
			Log.e("The indicator layout has failed to be created. "e);
catch (NullPointerException e) {
			Log.e("The indicator layout has failed to be created. "e);
		}
		return layout;
	}	
Factory which creates a default indicator layout instance. This is used when IndicatorLayoutFactory fails to create a instance

Author(s):
Wonjun Kim
	private static class DefaultIndicatorLayoutFactory {

Parameters:
clazzName This class name is being ignored
Returns:
Class token of DefaultIndicatorLayout
		public static Class<? extends IndicatorLayoutcreateIndicatorLayoutClazz(String clazzName) {
		}

Parameters:
clazz Class token is being ignored.
context
mode
Returns:
DefaultIndicatorLayout instance
		public static IndicatorLayout createIndicatorLayout(Class<? extends IndicatorLayoutclazzContext contextPullToRefreshBase.Mode mode) {
			return new DefaultIndicatorLayout(contextmode);
		}
	}
New to GrepCode? Check out our FAQ X