commit 506e22fea0cef7b2fee3136fc5f5dceaa6c80f6a Author: sairajzero Date: Fri Aug 23 21:20:37 2019 +0530 Upload Android Studios Project Uploading the entire Android Studios Project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b75303 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..a9eb6ce --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.1" + defaultConfig { + applicationId "com.ranchimall.androidhttparch" + minSdkVersion 24 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.browser:browser:1.0.0' + implementation 'org.nanohttpd:nanohttpd:2.3.1' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/ranchimall/androidhttparch/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/ranchimall/androidhttparch/ExampleInstrumentedTest.java new file mode 100644 index 0000000..57a191e --- /dev/null +++ b/app/src/androidTest/java/com/ranchimall/androidhttparch/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.ranchimall.androidhttparch; + +import android.content.Context; + +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.ranchimall.androidhttparch", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..082e16b --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/assets/home.html b/app/src/main/assets/home.html new file mode 100644 index 0000000..8718fbe --- /dev/null +++ b/app/src/main/assets/home.html @@ -0,0 +1,8 @@ + + + Home page + + +

Hello World!

+ + \ No newline at end of file diff --git a/app/src/main/java/com/ranchimall/androidhttparch/MainActivity.java b/app/src/main/java/com/ranchimall/androidhttparch/MainActivity.java new file mode 100644 index 0000000..9171b02 --- /dev/null +++ b/app/src/main/java/com/ranchimall/androidhttparch/MainActivity.java @@ -0,0 +1,52 @@ +package com.ranchimall.androidhttparch; + +import android.net.Uri; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import androidx.appcompat.app.AppCompatActivity; +import androidx.browser.customtabs.CustomTabsIntent; +import androidx.core.content.ContextCompat; +import java.io.IOException; + + +public class MainActivity extends AppCompatActivity { + private ServerHttp server; + private CustomTabsIntent customTabsIntent; + private static final int PORT = 7654; //PORT for the local http server + private static final String localUrl = "http://localhost:"+PORT+"/home.html"; + private static final String externalUrl = "https://www.ranchimall.net/"; + private static final String TAG = "Application"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + //Start the local HTTP server + try { + server = new ServerHttp(getApplicationContext(),PORT); + }catch (IOException e) { + Log.d(TAG,"Error in hosting server"); + e.printStackTrace(); + } + + //Chrome Custom Tab + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); + customTabsIntent = builder.build(); + builder.setShowTitle(true); + builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorAccent)); + + //open local url when app opens + customTabsIntent.launchUrl(this, Uri.parse(localUrl)); + } + //opens local url when button is clicked + public void openLocalUrl(View view) { + customTabsIntent.launchUrl(this, Uri.parse(localUrl)); + } + //opens external url when button is clicked + public void openExternalUrl(View view) { + customTabsIntent.launchUrl(this, Uri.parse(externalUrl)); + } +} + diff --git a/app/src/main/java/com/ranchimall/androidhttparch/ServerHttp.java b/app/src/main/java/com/ranchimall/androidhttparch/ServerHttp.java new file mode 100644 index 0000000..f8f8e20 --- /dev/null +++ b/app/src/main/java/com/ranchimall/androidhttparch/ServerHttp.java @@ -0,0 +1,34 @@ +package com.ranchimall.androidhttparch; + +import android.content.Context; +import android.util.Log; +import java.io.IOException; +import java.io.InputStream; +import fi.iki.elonen.NanoHTTPD; + +//Class to host local http server +public class ServerHttp extends NanoHTTPD { + private Context mContext; + private static final String TAG = "Application"; + public ServerHttp(Context context, int port) throws IOException { + super(port); + mContext=context; + start(); + } + + @Override + public Response serve(IHTTPSession session) { + String uri = session.getUri(); + Log.d(TAG,"Incoming HTTP Request : "+uri.substring(1)); + try { + if (uri.contains(".html")) { + InputStream is = mContext.getAssets().open(uri.substring(1)); + return newChunkedResponse(Response.Status.OK, "text/html", is); + } + } catch (IOException e) { + Log.d(TAG,"Error opening file : "+uri.substring(1)); + e.printStackTrace(); + } + return null; + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..2442c1b --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,33 @@ + + + +