Browse Source

Added Controllers

Fruit of Eden 6 năm trước cách đây
mục cha
commit
371da9736c

+ 3 - 2
app/src/main/java/com/mikhaellopez/androidwebserver/AndroidWebServer.java

@@ -1,5 +1,6 @@
 package com.mikhaellopez.androidwebserver;
 
+import java.util.List;
 import java.util.Map;
 
 import fi.iki.elonen.NanoHTTPD;
@@ -20,11 +21,11 @@ public class AndroidWebServer extends NanoHTTPD {
     @Override
     public Response serve(IHTTPSession session) {
         String msg = "<html><body><h1>Hello server</h1>\n";
-        Map<String, String> parms = session.getParms();
+        Map<String, List<String>> parms = session.getParameters();
         if (parms.get("username") == null) {
             msg += "<form action='?' method='get'>\n  <p>Your name: <input type='text' name='username'></p>\n" + "</form>\n";
         } else {
-            msg += "<p>Hello, " + parms.get("username") + "!</p>";
+            msg += "<p>Hello, " + parms.get("username").toString() + "!</p>";
         }
         return newFixedLengthResponse( msg + "</body></html>\n" );
     }

+ 4 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/Assistant/ConsoleAssist.java

@@ -0,0 +1,4 @@
+package com.mikhaellopez.androidwebserver.Assistant;
+
+public class ConsoleAssist {
+}

+ 4 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/Assistant/HostAssist.java

@@ -0,0 +1,4 @@
+package com.mikhaellopez.androidwebserver.Assistant;
+
+public class HostAssist {
+}

+ 138 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/MainActivity.java

@@ -101,6 +101,144 @@ public class MainActivity extends AppCompatActivity {
         initBroadcastReceiverNetworkStateChanged();
     }
 
+
+    /****
+     *   主机部分功能
+     */
+
+    public void startAP(){
+
+    }
+
+    public void onAPStarted(){
+
+    }
+
+    public void startServer(){
+
+    }
+
+    public void showQR(){
+
+    }
+
+    public void displayMsg(){
+
+    }
+
+    public void setGameSettings(){
+
+    }
+
+    public void onPressedStartGame(){
+
+    }
+
+    public void onGameEnded(){
+
+    }
+
+    /***
+     *   终端部分功能
+     */
+    public void onSelectFromHistory(){
+        // read From Persist and try to reach Host
+    }
+
+    public void scanQrCode(){
+        // scan QR from Host's Screen
+        // save to Persist
+    }
+
+    public void onQrScanned(){
+        //save To Persist
+    }
+
+
+    public void connectToHost(){
+        // read from Persist of the host info,
+        // check time eval
+        // connect to Host
+    }
+
+    public void onConnectToHostSuccess(){
+
+    }
+
+    public void onConnectToHostFailed(){
+
+    }
+
+    public void scanTank(){
+
+    }
+
+    public void onScanTankSuccess(){
+
+    }
+
+    public void connectToTank() {
+
+    }
+
+    public void endConnectToTank() {
+
+    }
+
+    public void connectToHostForGame() {
+
+    }
+
+    public void onHostGameConnected() {
+
+    }
+
+    public void getTanksInfo(){
+
+    }
+
+    public void getRealtimeInfo(){
+
+    }
+
+    public void getRoomInfo(){
+
+    }
+
+    public void onRoomsInfo(){
+
+    }
+
+    public void onTankInfo(){
+
+    }
+
+    public void onRealtimeInfo(){
+
+    }
+
+    public void doActionInGame(){
+
+    }
+
+    public void doActionSuccess(){
+
+    }
+
+    public void doActionTimeoutOrFailed(){
+
+    }
+
+    public void requestVideoInfo(){
+
+    }
+
+    public void onVideoReady(){
+
+    }
+
+
+
     public static String getUniquePsuedoID()
     {
         // If all else fails, if the user does have lower than API 9 (lower

+ 7 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/controller/ConsoleController.java

@@ -5,6 +5,13 @@ import com.mikhaellopez.androidwebserver.service.ArgumentProvider;
 import org.json.JSONObject;
 import java.util.Map;
 
+/**
+ *
+ *  主机Server 处理模块
+ *
+ *  处理来自终端的请求模块
+ *
+ * */
 public class ConsoleController {
     public String dispatch(int action, Map<String,String> arguments){
         return ArgumentProvider.map2query(arguments);

+ 7 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/controller/EchoController.java

@@ -1,5 +1,12 @@
 package com.mikhaellopez.androidwebserver.controller;
 
+/**
+ *
+ *  主机Server 处理模块
+ *
+ *  测试返回模块
+ *
+ * */
 public class EchoController {
 
 }

+ 0 - 4
app/src/main/java/com/mikhaellopez/androidwebserver/controller/PortableController.java

@@ -1,4 +0,0 @@
-package com.mikhaellopez.androidwebserver.controller;
-
-public class PortableController {
-}

+ 11 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/controller/TankController.java

@@ -0,0 +1,11 @@
+package com.mikhaellopez.androidwebserver.controller;
+
+/**
+ *
+ *  主机Server 处理模块
+ *
+ *  处理Tank返回模块
+ *
+ * */
+public class TankController {
+}

+ 1 - 1
app/src/main/java/com/mikhaellopez/androidwebserver/service/WarzoneService.java → app/src/main/java/com/mikhaellopez/androidwebserver/service/APService.java

@@ -1,4 +1,4 @@
 package com.mikhaellopez.androidwebserver.service;
 
-public class WarzoneService {
+public class APService {
 }

+ 4 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/service/GamingService.java

@@ -0,0 +1,4 @@
+package com.mikhaellopez.androidwebserver.service;
+
+public class GamingService {
+}

+ 5 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/service/PersistService.java

@@ -1,4 +1,9 @@
 package com.mikhaellopez.androidwebserver.service;
 
+/**
+ *
+ *   主机、终端使用的参数、数据存储服务
+ *
+ * */
 public class PersistService {
 }

+ 5 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/service/RoomService.java

@@ -1,4 +1,9 @@
 package com.mikhaellopez.androidwebserver.service;
 
+/**
+ *
+ *   主机、终端使用的房间相关操作
+ *
+ * */
 public class RoomService {
 }

+ 36 - 0
app/src/main/java/com/mikhaellopez/androidwebserver/service/WiFiService.java

@@ -0,0 +1,36 @@
+package com.mikhaellopez.androidwebserver.service;
+
+public class WiFiService {
+    /**
+     * setWifiEnabled
+     added in API level 1
+     public boolean setWifiEnabled (boolean enabled)
+     Enable or disable Wi-Fi.
+
+     Applications must have the Manifest.permission.CHANGE_WIFI_STATE permission to toggle wifi.
+
+     Parameters
+     enabled	boolean: true to enable, false to disable.
+     Returns
+     boolean	false if the request cannot be satisfied; true indicates that wifi is either already in the requested state, or in progress toward the requested state.
+     Throws
+     java.lang.SecurityException} if the caller is missing required permissions.
+     startLocalOnlyHotspot
+     added in API level 26
+     public void startLocalOnlyHotspot (WifiManager.LocalOnlyHotspotCallback callback,
+     Handler handler)
+     Request a local only hotspot that an application can use to communicate between co-located devices connected to the created WiFi hotspot. The network created by this method will not have Internet access. Each application can make a single request for the hotspot, but multiple applications could be requesting the hotspot at the same time. When multiple applications have successfully registered concurrently, they will be sharing the underlying hotspot. WifiManager.LocalOnlyHotspotCallback.onStarted(LocalOnlyHotspotReservation) is called when the hotspot is ready for use by the application.
+
+     Each application can make a single active call to this method. The WifiManager.LocalOnlyHotspotCallback.onStarted(LocalOnlyHotspotReservation) callback supplies the requestor with a WifiManager.LocalOnlyHotspotReservation that contains a WifiConfiguration with the SSID, security type and credentials needed to connect to the hotspot. Communicating this information is up to the application.
+
+     If the LocalOnlyHotspot cannot be created, the WifiManager.LocalOnlyHotspotCallback.onFailed(int) method will be called. Example failures include errors bringing up the network or if there is an incompatible operating mode. For example, if the user is currently using Wifi Tethering to provide an upstream to another device, LocalOnlyHotspot will not start due to an incompatible mode. The possible error codes include: WifiManager.LocalOnlyHotspotCallback.ERROR_NO_CHANNEL, WifiManager.LocalOnlyHotspotCallback.ERROR_GENERIC, WifiManager.LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE and WifiManager.LocalOnlyHotspotCallback.ERROR_TETHERING_DISALLOWED.
+
+     Internally, requests will be tracked to prevent the hotspot from being torn down while apps are still using it. The WifiManager.LocalOnlyHotspotReservation object passed in the WifiManager.LocalOnlyHotspotCallback.onStarted(LocalOnlyHotspotReservation) call should be closed when the LocalOnlyHotspot is no longer needed using WifiManager.LocalOnlyHotspotReservation.close(). Since the hotspot may be shared among multiple applications, removing the final registered application request will trigger the hotspot teardown. This means that applications should not listen to broadcasts containing wifi state to determine if the hotspot was stopped after they are done using it. Additionally, once WifiManager.LocalOnlyHotspotReservation.close() is called, applications will not receive callbacks of any kind.
+
+     Applications should be aware that the user may also stop the LocalOnlyHotspot through the Settings UI; it is not guaranteed to stay up as long as there is a requesting application. The requestors will be notified of this case via WifiManager.LocalOnlyHotspotCallback.onStopped(). Other cases may arise where the hotspot is torn down (Emergency mode, etc). Application developers should be aware that it can stop unexpectedly, but they will receive a notification if they have properly registered.
+
+     Applications should also be aware that this network will be shared with other applications. Applications are responsible for protecting their data on this network (e.g., TLS).
+
+     Applications need to have the following permissions to start LocalOnlyHotspot: Manifest.permission.CHANGE_WIFI_STATE and ACCESS_COARSE_LOCATION. Callers without the permissions will trigger a SecurityException.
+     * */
+}