package miui.maml.elements; import android.util.Log; import miui.maml.ScreenElementRoot; import org.w3c.dom.Element; public class ScreenElementFactory { public interface FactoryCallback { public ScreenElement onCreateInstance(Element ele, ScreenElementRoot root); } private FactoryCallback mFactoryCallback; public void setCallback(FactoryCallback factoryCallback) { mFactoryCallback = factoryCallback; } public FactoryCallback getCallback() { return mFactoryCallback; } public ScreenElement createInstance(Element ele, ScreenElementRoot root) { String tag = ele.getTagName(); try { if (tag.equalsIgnoreCase(ImageScreenElement.TAG_NAME)) return new ImageScreenElement(ele, root); else if (tag.equalsIgnoreCase(TimepanelScreenElement.TAG_NAME)) return new TimepanelScreenElement(ele, root); else if (mFactoryCallback != null) return mFactoryCallback.onCreateInstance(ele, root); } catch (IllegalArgumentException e) { e.printStackTrace(); Log.w("ScreenElementFactory", "fail to create element." + e); } return null; } }
/** * 这个类是可以通过工厂方法进行重构的 * 每一个检测项是一个类,比如 AirModeCheckItem , WifiIsConnectCheckItem,.......他们实现共同的inferface, * 这个inferface包含itemName等变量,还有checkItem,fixItem等方法 * 有一个CheckItemFactory管理他们 */ public enum NetworkDiagoneItem { APN_ISSUE("checkAPN","APN扫描...", "建议重置APN",false, "重置APN","fixAPN"), SIM_STATE_ISSUE("checkSimState","SIM卡状态扫描...", "检查是否禁用了sim卡",false, "去检查","fixAPN"), SIGNAL_STRENGTH_ISSUE("checkSignalStrength","信号强度扫描...", "当前环境信号较差",false, "确定","fixSignalStrength"), WIFI_NOT_CONNECT("checkWlanConnected","wifi接入点扫描...","去连接wifi",false,"请连接一个wifi","fixWlanConnected"), WIFI_ROUTE_TO_INTERNET("checkRouteToInternet","路由器连接外网扫描...","去检测路由器设置",false,"去检测路由器设置","fixRouteToInternet"), WIFI_DNS_ISSUE("checkWlanDNSAvailable","ADSL DNS 扫描...","WIFI DNS",false,"修复","fixAPN"), WIFI_GATEWAY_ISSUE("checkRouteGetwayAvailable","Wifi网关扫描...", "建议检查路由器设置",false, "网关不能访问","fixRouteGetwayAvailable"), USB_SHARENET_ISSUE("checkUsbSharenetRoute","USB共享上网扫描...", "建议检查路由器设置",false, "网关不能访问","fixUsbSharenetRoute"); public static List<NetworkDiagoneItem> getAllUsbShareItem() { List<NetworkDiagoneItem> usbshareItems = new ArrayList<NetworkDiagoneItem>(); usbshareItems.add(USB_SHARENET_ISSUE); return usbshareItems; } private String itemCheckMethod; private String itemName; private String itemSummary; private boolean isOk; private String itemSolution; private String solutionMethod; public static int CurrentSignalStrength = 0; private NetworkDiagoneItem(String itemCheckMethod,String itemname,String itemSummary, boolean isOk, String itemSolution,String solutionMethod) { //mContext = context; this.itemCheckMethod = itemCheckMethod; this.itemName = itemname; this.itemSummary = itemSummary; this.isOk = isOk; this.itemSolution = itemSolution; this.solutionMethod = solutionMethod; }