If you think the Android project coursera-android-pos listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package edu.vuum.mocca;
//www.java2s.comimport java.util.HashMap;
/**
* @class PlatformStrategyFactory
*
* @brief This class is a factory that is responsible for building the
* designated @a PlatformStrategy implementation at runtime.
*/publicclass PlatformStrategyFactory
{
/**
* This interface uses the Strategy pattern to create @a
* PlatformStrategy implementations at runtime.
*/privatestaticinterface IPlatformStrategyFactoryStrategy
{
public PlatformStrategy execute();
}
/**
* Enumeration distinguishing platforms Android from plain ol' Java.
*/publicenum PlatformType {
ANDROID,
PLAIN_JAVA
}
/**
* HashMap used to map strings containing the Java platform names
* and dispatch the execute() method of the associated @a PlatformStrategy
* implementation.
*/private HashMap<PlatformType, IPlatformStrategyFactoryStrategy> mPlatformStrategyMap =
new HashMap<PlatformType, IPlatformStrategyFactoryStrategy>();
/**
* Ctor that stores the objects that perform output for a
* particular platform, such as ConsolePlatformStrategy or the
* AndroidPlatformStrategy.
*/public PlatformStrategyFactory(final Object output,
final Object activity)
{
/**
* The "The Android Project" string maps to a command object
* that creates an @a AndroidPlatformStrategy implementation.
*/
mPlatformStrategyMap.put(PlatformType.ANDROID,
new IPlatformStrategyFactoryStrategy()
{
/**
* Receives the three parameters, input
* (EditText), output (TextView), activity
* (activity).
*/public PlatformStrategy execute()
{
returnnew AndroidPlatformStrategy(output,
activity);
}
});
/**
* The "Sun Microsystems Inc." string maps to a command object
* that creates an @a ConsolePlatformStrategy implementation.
*/
mPlatformStrategyMap.put(PlatformType.PLAIN_JAVA,
new IPlatformStrategyFactoryStrategy()
{
public PlatformStrategy execute()
{
returnnew ConsolePlatformStrategy(output);
}
});
}
/**
* Returns the name of the platform in a string. e.g., Android or
* a JVM.
*/publicstatic String platformName()
{
return System.getProperty("java.specification.vendor");
}
/**
* Returns the type of the platformm e.g. Android or
* a JVM.
*/publicstatic PlatformType platformType() {
if(platformName().indexOf("Android") >= 0)
return PlatformType.ANDROID;
elsereturn PlatformType.PLAIN_JAVA;
}
/**
* Create a new @a PlatformStrategy object based on underlying Java
* platform.
*/public PlatformStrategy makePlatformStrategy()
{
PlatformType type = platformType();
return mPlatformStrategyMap.get(type).execute();
}
}