OSDN Git Service

Added openURI to Net
authormoly <0700689@live.abertay.ac.uk>
Tue, 9 Oct 2012 19:32:30 +0000 (20:32 +0100)
committermoly <0700689@live.abertay.ac.uk>
Tue, 9 Oct 2012 19:32:30 +0000 (20:32 +0100)
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplication.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidNet.java
backends/gdx-backend-iosmonotouch/src/com/badlogic/gdx/backends/ios/IOSApplication.java
backends/gdx-backend-iosmonotouch/src/com/badlogic/gdx/backends/ios/IOSNet.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglNet.java
backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtNet.java
gdx/src/com/badlogic/gdx/Net.java

index 1882c9a..b3b55e0 100644 (file)
@@ -101,7 +101,7 @@ public class AndroidApplication extends Activity implements Application {
                input = new AndroidInput(this, graphics.view, config);\r
                audio = new AndroidAudio(this, config);\r
                files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());\r
-               net = new AndroidNet();\r
+               net = new AndroidNet(this);\r
                this.listener = listener;\r
                this.handler = new Handler();\r
 \r
index 8702cca..4215741 100755 (executable)
@@ -16,6 +16,8 @@
 \r
 package com.badlogic.gdx.backends.android;\r
 \r
+import android.content.Intent;\r
+\r
 import com.badlogic.gdx.Net;\r
 import com.badlogic.gdx.Net.HttpResult;\r
 import com.badlogic.gdx.Net.Protocol;\r
@@ -28,7 +30,12 @@ public class AndroidNet implements Net {
        \r
        // IMPORTANT: The Gdx.net classes are a currently duplicated for LWJGL + Android!\r
        //            If you make changes here, make changes in the other backend as well.\r
-\r
+       final AndroidApplication app;\r
+       \r
+       public AndroidNet(AndroidApplication activity) {\r
+               app = activity;\r
+       }\r
+       \r
        @Override\r
        public HttpResult httpGet (String url, String... parameters) {\r
                throw new UnsupportedOperationException("Not implemented");\r
@@ -48,4 +55,9 @@ public class AndroidNet implements Net {
        public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {\r
                return new AndroidSocket(protocol, host, port, hints);\r
        }\r
+       \r
+       @Override\r
+       public void openURI(String URI) {\r
+               app.startActivity(new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(URI)));\r
+       }\r
 }\r
index 03d74a4..6931500 100644 (file)
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- ******************************************************************************/
+ ******************************************************************************/\r
 package com.badlogic.gdx.backends.ios;\r
 \r
 import cli.MonoTouch.Foundation.NSDictionary;\r
@@ -100,11 +100,13 @@ public class IOSApplication extends UIApplicationDelegate implements Application
                this.graphics = new IOSGraphics(getBounds(uiViewController), this, input);\r
                this.files = new IOSFiles();\r
                this.audio = new IOSAudio();\r
+               this.net = new IOSNet(this);\r
                \r
                Gdx.files = this.files;\r
                Gdx.graphics = this.graphics;\r
                Gdx.audio = this.audio;\r
                Gdx.input = this.input;\r
+               Gdx.net = this.net;\r
                \r
                this.input.setupPeripherals();\r
 \r
index 9b6029f..be92c27 100755 (executable)
@@ -15,6 +15,9 @@
  ******************************************************************************/\r
 package com.badlogic.gdx.backends.ios;\r
 \r
+import cli.MonoTouch.Foundation.NSUrl;\r
+import cli.MonoTouch.UIKit.UIApplication;\r
+\r
 import com.badlogic.gdx.Net;\r
 import com.badlogic.gdx.Net.HttpResult;\r
 import com.badlogic.gdx.Net.Protocol;\r
@@ -25,6 +28,12 @@ import com.badlogic.gdx.net.SocketHints;
 \r
 public class IOSNet implements Net {\r
        \r
+       final UIApplication uiApp;\r
+       \r
+       public IOSNet(IOSApplication app) {\r
+               uiApp = app.uiApp;\r
+       }\r
+       \r
        @Override\r
        public HttpResult httpGet (String url, String... parameters) {\r
                throw new UnsupportedOperationException("Not implemented");\r
@@ -44,4 +53,9 @@ public class IOSNet implements Net {
        public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {\r
                return new IOSSocket(protocol, host, port, hints);\r
        }\r
+       \r
+       @Override\r
+       public void openURI(String URI) {\r
+               uiApp.OpenUrl(new NSUrl(URI));\r
+       }\r
 }\r
index faca58e..29ec99f 100755 (executable)
 \r
 package com.badlogic.gdx.backends.lwjgl;\r
 \r
+import java.awt.Desktop;\r
+import java.net.URI;\r
+\r
 import com.badlogic.gdx.Net;\r
 import com.badlogic.gdx.net.ServerSocket;\r
 import com.badlogic.gdx.net.ServerSocketHints;\r
 import com.badlogic.gdx.net.Socket;\r
 import com.badlogic.gdx.net.SocketHints;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 public class LwjglNet implements Net {\r
        \r
@@ -46,4 +50,21 @@ public class LwjglNet implements Net {
        public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {\r
                return new LwjglSocket(protocol, host, port, hints);\r
        }\r
+       \r
+       @Override\r
+       public void openURI(String URI) {\r
+               if (!Desktop.isDesktopSupported()) \r
+                       return;\r
+               \r
+               Desktop desktop = Desktop.getDesktop();\r
+               \r
+               if (!desktop.isSupported(Desktop.Action.BROWSE))\r
+                       return;\r
+               \r
+               try {\r
+                       desktop.browse(new java.net.URI(URI));\r
+               } catch (Exception e) {\r
+                       throw new GdxRuntimeException(e);\r
+               }\r
+       }\r
 }\r
index 0db1463..858349e 100755 (executable)
@@ -7,6 +7,7 @@ import com.badlogic.gdx.net.ServerSocket;
 import com.badlogic.gdx.net.ServerSocketHints;\r
 import com.badlogic.gdx.net.Socket;\r
 import com.badlogic.gdx.net.SocketHints;\r
+import com.google.gwt.user.client.Window;\r
 \r
 public class GwtNet implements Net {\r
        @Override\r
@@ -28,4 +29,9 @@ public class GwtNet implements Net {
        public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {\r
                throw new UnsupportedOperationException("Not implemented");\r
        }\r
+       \r
+       @Override\r
+       public void openURI(String URI) {\r
+               Window.open(URI, "_blank", null);\r
+       }\r
 }\r
index d0f8df1..e249e85 100755 (executable)
@@ -148,4 +148,14 @@ public interface Net {
         * @return GdxRuntimeException in case the socket couldn't be opened\r
         */\r
        public Socket newClientSocket(Protocol protocol, String host, int port, SocketHints hints);\r
+       \r
+       /**\r
+        * Launches the default browser to display a URI. If the default browser is not able\r
+        * to handle the specified URI, the application registered for handling URIs of the\r
+        * specified type is invoked. The application is determined from the protocol\r
+        * and path of the URI.\r
+        * \r
+        * @param URI the URI to be opened.\r
+        */\r
+       public void openURI(String URI);\r
 }\r