Merge branch 'master' into experimental
This commit is contained in:
commit
434abe26e1
27
build.py
27
build.py
@ -168,6 +168,11 @@ else:
|
|||||||
os.makedirs(outDir)
|
os.makedirs(outDir)
|
||||||
|
|
||||||
|
|
||||||
|
# run any preBuild commands
|
||||||
|
for cmd in settings.get('preBuild',[]):
|
||||||
|
os.system ( cmd )
|
||||||
|
|
||||||
|
|
||||||
# load main.js, parse, and create main total-conversion-build.user.js
|
# load main.js, parse, and create main total-conversion-build.user.js
|
||||||
main = readfile('main.js')
|
main = readfile('main.js')
|
||||||
|
|
||||||
@ -191,15 +196,6 @@ for fn in glob.glob("plugins/*.user.js"):
|
|||||||
metafn = fn.replace('.user.js', '.meta.js')
|
metafn = fn.replace('.user.js', '.meta.js')
|
||||||
saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn))
|
saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn))
|
||||||
|
|
||||||
def copytree(src, dst, symlinks=False, ignore=None):
|
|
||||||
for item in os.listdir(src):
|
|
||||||
s = os.path.join(src, item)
|
|
||||||
d = os.path.join(dst, item)
|
|
||||||
if os.path.isdir(s):
|
|
||||||
shutil.copytree(s, d, symlinks, ignore)
|
|
||||||
else:
|
|
||||||
shutil.copy2(s, d)
|
|
||||||
|
|
||||||
# if we're building mobile too
|
# if we're building mobile too
|
||||||
if buildMobile:
|
if buildMobile:
|
||||||
if buildMobile not in ['debug','release','copyonly']:
|
if buildMobile not in ['debug','release','copyonly']:
|
||||||
@ -223,13 +219,9 @@ if buildMobile:
|
|||||||
shutil.copy(os.path.join(outDir,"total-conversion-build.user.js"), "mobile/assets/total-conversion-build.user.js")
|
shutil.copy(os.path.join(outDir,"total-conversion-build.user.js"), "mobile/assets/total-conversion-build.user.js")
|
||||||
# copy the user location script into the mobile folder.
|
# copy the user location script into the mobile folder.
|
||||||
shutil.copy(os.path.join(outDir,"user-location.user.js"), "mobile/assets/user-location.user.js")
|
shutil.copy(os.path.join(outDir,"user-location.user.js"), "mobile/assets/user-location.user.js")
|
||||||
|
|
||||||
# also copy plugins
|
# also copy plugins
|
||||||
try:
|
shutil.rmtree("mobile/assets/plugins")
|
||||||
os.makedirs("mobile/assets/plugins")
|
shutil.copytree(os.path.join(outDir,"plugins"), "mobile/assets/plugins", ignore=shutil.ignore_patterns('*.meta.js', 'force-https*'))
|
||||||
except:
|
|
||||||
pass
|
|
||||||
copytree(os.path.join(outDir,"plugins"), "mobile/assets/plugins")
|
|
||||||
|
|
||||||
|
|
||||||
if buildMobile != 'copyonly':
|
if buildMobile != 'copyonly':
|
||||||
@ -242,4 +234,9 @@ if buildMobile:
|
|||||||
shutil.copy("mobile/bin/IITC_Mobile-%s.apk" % buildMobile, os.path.join(outDir,"IITC_Mobile-%s.apk" % buildMobile) )
|
shutil.copy("mobile/bin/IITC_Mobile-%s.apk" % buildMobile, os.path.join(outDir,"IITC_Mobile-%s.apk" % buildMobile) )
|
||||||
|
|
||||||
|
|
||||||
|
# run any postBuild commands
|
||||||
|
for cmd in settings.get('postBuild',[]):
|
||||||
|
os.system ( cmd )
|
||||||
|
|
||||||
|
|
||||||
# vim: ai si ts=4 sw=4 sts=4 et
|
# vim: ai si ts=4 sw=4 sts=4 et
|
||||||
|
@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
# if you want to have custom builds, copy this file to "localbuildsettings.py" and make changes there.
|
# if you want to have custom builds, copy this file to "localbuildsettings.py" and make changes there.
|
||||||
|
|
||||||
|
# possible fields:
|
||||||
|
# resourceBaseUrl - optional - the URL base for external resources (all resources embedded in standard IITC)
|
||||||
|
# distUrlBase - optional - the base URL to use for update checks
|
||||||
|
# buildMobild - optional - if set, mobild builds are built with 'ant'. requires the Android SDK and appropriate mobile/local.properties file configured
|
||||||
|
# preBuild - optional - an array of strings to run as commands, via os.system, before building the scripts
|
||||||
|
# postBuild - optional - an array of string to run as commands, via os.system, after all builds are complete
|
||||||
|
|
||||||
|
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
# local: use this build if you're not modifying external resources
|
# local: use this build if you're not modifying external resources
|
||||||
# no external resources allowed - they're not needed any more
|
# no external resources allowed - they're not needed any more
|
||||||
@ -40,6 +48,7 @@ buildSettings = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# defaultBuild - the name of the default build to use if none is specified on the build.py command line
|
# defaultBuild - the name of the default build to use if none is specified on the build.py command line
|
||||||
# (in here as an example - it only works in localbuildsettings.py)
|
# (in here as an example - it only works in localbuildsettings.py)
|
||||||
#defaultBuild = 'local'
|
#defaultBuild = 'local'
|
||||||
|
2
mobile/.gitignore
vendored
2
mobile/.gitignore
vendored
@ -6,6 +6,6 @@ gen/
|
|||||||
libs/
|
libs/
|
||||||
proguard-project.txt
|
proguard-project.txt
|
||||||
local.properties
|
local.properties
|
||||||
assets/iitc.js
|
assets/total-conversion-build.user.js
|
||||||
assets/user-location.user.js
|
assets/user-location.user.js
|
||||||
assets/plugins/
|
assets/plugins/
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.cradle.iitc_mobile"
|
package="com.cradle.iitc_mobile"
|
||||||
android:versionCode="15"
|
android:versionCode="17"
|
||||||
android:versionName="0.3.3" >
|
android:versionName="0.3.5" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
|
@ -15,6 +15,12 @@
|
|||||||
android:showAsAction="never"
|
android:showAsAction="never"
|
||||||
android:title="@string/cache_clear"></item>
|
android:title="@string/cache_clear"></item>
|
||||||
|
|
||||||
|
<item android:id="@+id/toggle_fullscreen"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:showAsAction="ifRoom"
|
||||||
|
android:title="@string/toggle_fullscreen"
|
||||||
|
android:icon="@android:drawable/ic_menu_zoom"></item>
|
||||||
|
|
||||||
<item android:id="@+id/locate"
|
<item android:id="@+id/locate"
|
||||||
android:icon="@android:drawable/ic_menu_mylocation"
|
android:icon="@android:drawable/ic_menu_mylocation"
|
||||||
android:orderInCategory="80"
|
android:orderInCategory="80"
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<string name="reload">Reload IITC</string>
|
<string name="reload">Reload IITC</string>
|
||||||
<string name="version">Print Version</string>
|
<string name="version">Print Version</string>
|
||||||
<string name="cache_clear">Clear Cache</string>
|
<string name="cache_clear">Clear Cache</string>
|
||||||
|
<string name="toggle_fullscreen">Toggle fullscreen</string>
|
||||||
<string name="locate">Get Location</string>
|
<string name="locate">Get Location</string>
|
||||||
<string name="local">local</string>
|
<string name="local">local</string>
|
||||||
<string name="close">close</string>
|
<string name="close">close</string>
|
||||||
@ -37,6 +38,8 @@
|
|||||||
<string name="pref_force_desktop_sum">Nice for tablets, looks awful on smartphones</string>
|
<string name="pref_force_desktop_sum">Nice for tablets, looks awful on smartphones</string>
|
||||||
<string name="pref_user_loc">Display user location</string>
|
<string name="pref_user_loc">Display user location</string>
|
||||||
<string name="pref_user_loc_sum">Show users position on map</string>
|
<string name="pref_user_loc_sum">Show users position on map</string>
|
||||||
|
<string name="pref_force_https">Force https</string>
|
||||||
|
<string name="pref_force_https_sum">Disabling may improve performance</string>
|
||||||
<string name="pref_developer_options">Developer options</string>
|
<string name="pref_developer_options">Developer options</string>
|
||||||
<string name="pref_enable_dev_mode">Enable developer mode</string>
|
<string name="pref_enable_dev_mode">Enable developer mode</string>
|
||||||
<string name="pref_enable_dev_mode_sum">If enabled, all IITC sources will be loaded from external storage of the Android device.
|
<string name="pref_enable_dev_mode_sum">If enabled, all IITC sources will be loaded from external storage of the Android device.
|
||||||
|
@ -36,6 +36,11 @@
|
|||||||
android:key="pref_plugins"
|
android:key="pref_plugins"
|
||||||
android:title="@string/pref_plugins"
|
android:title="@string/pref_plugins"
|
||||||
android:dialogTitle="@string/pref_plugins_title"/>
|
android:dialogTitle="@string/pref_plugins_title"/>
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="pref_force_https"
|
||||||
|
android:title="@string/pref_force_https"
|
||||||
|
android:summary="@string/pref_force_https_sum"
|
||||||
|
android:defaultValue="true" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
@ -20,10 +20,12 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class IITC_Mobile extends Activity {
|
public class IITC_Mobile extends Activity {
|
||||||
@ -37,6 +39,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
private LocationManager loc_mngr = null;
|
private LocationManager loc_mngr = null;
|
||||||
private LocationListener loc_listener = null;
|
private LocationListener loc_listener = null;
|
||||||
private boolean keyboad_open = false;
|
private boolean keyboad_open = false;
|
||||||
|
private boolean fullscreen_mode = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -65,8 +68,14 @@ public class IITC_Mobile extends Activity {
|
|||||||
iitc_view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
|
iitc_view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
if ((iitc_view.getRootView().getHeight() - iitc_view.getHeight()) >
|
Rect r = new Rect();
|
||||||
iitc_view.getRootView().getHeight()/3) {
|
//r will be populated with the coordinates of your view that area still visible.
|
||||||
|
iitc_view.getWindowVisibleDisplayFrame(r);
|
||||||
|
|
||||||
|
int screenHeight = iitc_view.getRootView().getHeight();
|
||||||
|
int heightDiff = screenHeight - (r.bottom - r.top);
|
||||||
|
boolean visible = heightDiff > screenHeight / 3;
|
||||||
|
if (visible == true) {
|
||||||
Log.d("iitcm", "Open Keyboard...");
|
Log.d("iitcm", "Open Keyboard...");
|
||||||
IITC_Mobile.this.keyboad_open = true;
|
IITC_Mobile.this.keyboad_open = true;
|
||||||
} else {
|
} else {
|
||||||
@ -114,7 +123,6 @@ public class IITC_Mobile extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.d("iitcm", "no intent...loading " + intel_url);
|
|
||||||
this.loadUrl(intel_url);
|
this.loadUrl(intel_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,6 +135,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
Log.d("iitcm", "resuming...setting reset idleTimer");
|
Log.d("iitcm", "resuming...setting reset idleTimer");
|
||||||
iitc_view.loadUrl("javascript: window.idleTime = 0");
|
iitc_view.loadUrl("javascript: window.idleTime = 0");
|
||||||
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
||||||
|
iitc_view.updateCaching();
|
||||||
|
|
||||||
if (user_loc == true) {
|
if (user_loc == true) {
|
||||||
// Register the listener with the Location Manager to receive location updates
|
// Register the listener with the Location Manager to receive location updates
|
||||||
@ -181,6 +190,17 @@ public class IITC_Mobile extends Activity {
|
|||||||
// we want a self defined behavior for the back button
|
// we want a self defined behavior for the back button
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
// leave fullscreen mode if it is enabled
|
||||||
|
if (fullscreen_mode) {
|
||||||
|
// get back action bar
|
||||||
|
this.getActionBar().show();
|
||||||
|
// show notification bar again
|
||||||
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
||||||
|
attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||||
|
this.getWindow().setAttributes(attrs);
|
||||||
|
this.fullscreen_mode = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.back_button_pressed) {
|
if (this.back_button_pressed) {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
return;
|
return;
|
||||||
@ -219,6 +239,29 @@ public class IITC_Mobile extends Activity {
|
|||||||
iitc_view.clearFormData();
|
iitc_view.clearFormData();
|
||||||
iitc_view.clearCache(true);
|
iitc_view.clearCache(true);
|
||||||
return true;
|
return true;
|
||||||
|
// toggle fullscreen
|
||||||
|
case R.id.toggle_fullscreen:
|
||||||
|
if (!this.fullscreen_mode) {
|
||||||
|
// get rid of action bar
|
||||||
|
this.getActionBar().hide();
|
||||||
|
// hide notification bar
|
||||||
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
||||||
|
attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||||
|
this.getWindow().setAttributes(attrs);
|
||||||
|
this.fullscreen_mode = true;
|
||||||
|
// show a little toast for the user
|
||||||
|
Toast.makeText(this, "Press back button to exit fullscreen", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// get back action bar
|
||||||
|
this.getActionBar().show();
|
||||||
|
// show notification bar again
|
||||||
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
||||||
|
attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||||
|
this.getWindow().setAttributes(attrs);
|
||||||
|
this.fullscreen_mode = false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
// get the users current location and focus it on map
|
// get the users current location and focus it on map
|
||||||
case R.id.locate:
|
case R.id.locate:
|
||||||
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});");
|
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});");
|
||||||
@ -259,9 +302,8 @@ public class IITC_Mobile extends Activity {
|
|||||||
// plugins are injected onPageFinished
|
// plugins are injected onPageFinished
|
||||||
public void loadUrl(String url) {
|
public void loadUrl(String url) {
|
||||||
url = addUrlParam(url);
|
url = addUrlParam(url);
|
||||||
Log.d("iitcm", "injecting js...");
|
Log.d("iitcm", "injecting main-script...");
|
||||||
injectJS();
|
injectJS();
|
||||||
Log.d("iitcm", "loading url: " + url);
|
|
||||||
iitc_view.loadUrl(url);
|
iitc_view.loadUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ public class IITC_Settings extends Activity {
|
|||||||
ArrayList<String> asset_values = new ArrayList<String>();
|
ArrayList<String> asset_values = new ArrayList<String>();
|
||||||
|
|
||||||
for (int i = 0; i < asset_array.length ; i++) {
|
for (int i = 0; i < asset_array.length ; i++) {
|
||||||
if (asset_array[i].endsWith("user.js")) {
|
|
||||||
// find user plugin name for user readable entries
|
// find user plugin name for user readable entries
|
||||||
Scanner s = null;
|
Scanner s = null;
|
||||||
String src = "";
|
String src = "";
|
||||||
@ -55,7 +54,6 @@ public class IITC_Settings extends Activity {
|
|||||||
// real value
|
// real value
|
||||||
asset_values.add(asset_array[i]);
|
asset_values.add(asset_array[i]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Bundle bundle = getIntent().getExtras();
|
Bundle bundle = getIntent().getExtras();
|
||||||
bundle.putStringArray("ASSETS", (String[]) asset_list.toArray(new String[0]));
|
bundle.putStringArray("ASSETS", (String[]) asset_list.toArray(new String[0]));
|
||||||
|
@ -2,7 +2,12 @@ package com.cradle.iitc_mobile;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.webkit.WebChromeClient;
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
@ -22,9 +27,10 @@ public class IITC_WebView extends WebView {
|
|||||||
settings.setDomStorageEnabled(true);
|
settings.setDomStorageEnabled(true);
|
||||||
settings.setAllowFileAccess(true);
|
settings.setAllowFileAccess(true);
|
||||||
settings.setGeolocationEnabled(true);
|
settings.setGeolocationEnabled(true);
|
||||||
|
settings.setAppCacheEnabled(true);
|
||||||
settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + "/databases/");
|
settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + "/databases/");
|
||||||
settings.setAppCachePath(this.getContext().getApplicationInfo().dataDir + "/cache/");
|
settings.setAppCachePath(this.getContext().getCacheDir().getAbsolutePath());
|
||||||
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
// use cache if on mobile network...saves traffic
|
||||||
this.js_interface = new IITC_JSInterface(c);
|
this.js_interface = new IITC_JSInterface(c);
|
||||||
this.addJavascriptInterface(js_interface, "android");
|
this.addJavascriptInterface(js_interface, "android");
|
||||||
|
|
||||||
@ -61,6 +67,20 @@ public class IITC_WebView extends WebView {
|
|||||||
}
|
}
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadUrl(String url) {
|
||||||
|
if (!url.startsWith("javascript:")) {
|
||||||
|
// force https if enabled in settings
|
||||||
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
|
if (sharedPref.getBoolean("pref_force_https", true))
|
||||||
|
url = url.replace("http://", "https://");
|
||||||
|
else
|
||||||
|
url = url.replace("https://", "http://");
|
||||||
|
Log.d("iitcm", "loading url: " + url);
|
||||||
|
}
|
||||||
|
super.loadUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
public IITC_WebViewClient getWebViewClient() {
|
public IITC_WebViewClient getWebViewClient() {
|
||||||
return this.webclient;
|
return this.webclient;
|
||||||
}
|
}
|
||||||
@ -69,4 +89,21 @@ public class IITC_WebView extends WebView {
|
|||||||
return this.js_interface;
|
return this.js_interface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateCaching() {
|
||||||
|
if (!this.isConnectedToWifi())
|
||||||
|
{
|
||||||
|
Log.d("iitcm", "not connected to wifi...load tiles from cache");
|
||||||
|
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||||
|
} else {
|
||||||
|
Log.d("iitcm", "connected to wifi...load tiles from network");
|
||||||
|
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isConnectedToWifi() {
|
||||||
|
ConnectivityManager conMan = (ConnectivityManager) getContext().getSystemService( Context.CONNECTIVITY_SERVICE );
|
||||||
|
NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
|
return wifi.getState() == NetworkInfo.State.CONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
@ -30,13 +30,12 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
private WebResourceResponse iitcjs;
|
private WebResourceResponse iitcjs;
|
||||||
private String js = null;
|
private String js = null;
|
||||||
private String dev_path = null;
|
private String iitc_path = null;
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
public IITC_WebViewClient(Context c) {
|
public IITC_WebViewClient(Context c) {
|
||||||
this.context = c;
|
this.context = c;
|
||||||
this.dev_path = Environment.getExternalStorageDirectory().getPath() +
|
this.iitc_path = Environment.getExternalStorageDirectory().getPath() + "/IITC_Mobile/";
|
||||||
"/IITC_Mobile/dev/";
|
|
||||||
try {
|
try {
|
||||||
loadIITC_JS(c);
|
loadIITC_JS(c);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
@ -68,32 +67,24 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
String js = "";
|
String js = "";
|
||||||
|
|
||||||
// if developer mode are enabled, load all iitc script from external storage
|
// if developer mode are enabled, load all iitc script from external storage
|
||||||
if (sharedPref.getBoolean("pref_dev_checkbox", true)) {
|
if (sharedPref.getBoolean("pref_dev_checkbox", false)) {
|
||||||
File js_file = new File(dev_path + "total-conversion-build.user.js");
|
js = this.fileToString(iitc_path + "dev/total-conversion-build.user.js", false);
|
||||||
if (!js_file.exists()) {
|
if (js.equals("false")) {
|
||||||
Toast.makeText(context, "File " + dev_path +
|
Toast.makeText(context, "File " + iitc_path +
|
||||||
"total-conversion-build.user.js not found. " +
|
"dev/total-conversion-build.user.js not found. " +
|
||||||
"Disable developer mode or add iitc files " +
|
"Disable developer mode or add iitc files " +
|
||||||
"to the dev folder.", Toast.LENGTH_LONG).show();
|
"to the dev folder.", Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, "Developer mode enabled", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Developer mode enabled", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
Scanner s = null;
|
|
||||||
s = new Scanner(js_file).useDelimiter("\\A");
|
|
||||||
if (s != null) js = s.hasNext() ? s.next() : "";
|
|
||||||
} else {
|
} else {
|
||||||
// load iitc script from web or asset folder
|
// load iitc script from web or asset folder
|
||||||
if (iitc_source.contains("http")) {
|
if (iitc_source.contains("http")) {
|
||||||
URL url = new URL(iitc_source);
|
URL url = new URL(iitc_source);
|
||||||
js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next();
|
js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next();
|
||||||
} else {
|
} else {
|
||||||
InputStream input;
|
js = this.fileToString("total-conversion-build.user.js", true);
|
||||||
input = c.getAssets().open("total-conversion-build.user.js");
|
|
||||||
int size = input.available();
|
|
||||||
byte[] buffer = new byte[size];
|
|
||||||
input.read(buffer);
|
|
||||||
input.close();
|
|
||||||
js = new String(buffer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,59 +122,83 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
// iterate through all enabled plugins and load them
|
// iterate through all enabled plugins and load them
|
||||||
if (plugin_list != null) {
|
if (plugin_list != null) {
|
||||||
AssetManager am = context.getAssets();
|
|
||||||
String[] plugin_array = plugin_list.toArray(new String[0]);
|
String[] plugin_array = plugin_list.toArray(new String[0]);
|
||||||
|
|
||||||
for(int i = 0; i < plugin_list.size(); i++) {
|
for(int i = 0; i < plugin_list.size(); i++) {
|
||||||
if (plugin_array[i].endsWith("user.js"));
|
|
||||||
{
|
|
||||||
Log.d("iitcm", "adding plugin " + plugin_array[i]);
|
Log.d("iitcm", "adding plugin " + plugin_array[i]);
|
||||||
Scanner s = null;
|
if (dev_enabled)
|
||||||
String src = "";
|
this.loadJS(iitc_path + "dev/plugins/" + plugin_array[i], false, view);
|
||||||
try {
|
|
||||||
// load plugins from external storage if dev mode are enabled
|
|
||||||
if (dev_enabled) {
|
|
||||||
File js_file = new File(dev_path + "plugins/" + plugin_array[i]);
|
|
||||||
s = new Scanner(js_file).useDelimiter("\\A");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
// load plugins from asset folder
|
this.loadJS("plugins/" + plugin_array[i], true, view);
|
||||||
s = new Scanner(am.open("plugins/" + plugin_array[i])).useDelimiter("\\A");
|
|
||||||
} catch (IOException e2) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
|
||||||
if (s != null) src = s.hasNext() ? s.next() : "";
|
|
||||||
view.loadUrl("javascript:" + src);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// inject the user location script if enabled in settings
|
// inject the user location script if enabled in settings
|
||||||
if (sharedPref.getBoolean("pref_user_loc", false))
|
if (sharedPref.getBoolean("pref_user_loc", false))
|
||||||
enableTracking(view, dev_enabled);
|
enableTracking(view, dev_enabled);
|
||||||
|
|
||||||
|
// load additional plugins from <storage-path>/IITC-Mobile/plugins/
|
||||||
|
File directory = new File(iitc_path + "plugins/");
|
||||||
|
File[] files = directory.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (int i = 0; i < files.length; ++i) {
|
||||||
|
if(this.loadJS(files[i].toString(), false, view))
|
||||||
|
Log.d("iitcm", "loading additional plugin " + files[i].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableTracking(WebView view, boolean dev_enabled) {
|
public void enableTracking(WebView view, boolean dev_enabled) {
|
||||||
Log.d("iitcm", "enable tracking...");
|
Log.d("iitcm", "enable tracking...");
|
||||||
AssetManager am = context.getAssets();
|
|
||||||
Scanner s = null;
|
|
||||||
String src = "";
|
|
||||||
try {
|
|
||||||
// load plugin from external storage if dev mode are enabled
|
// load plugin from external storage if dev mode are enabled
|
||||||
if (dev_enabled) {
|
if (dev_enabled)
|
||||||
File js_file = new File(dev_path + "user-location.user.js");
|
this.loadJS(iitc_path + "dev/user-location.user.js", false, view);
|
||||||
s = new Scanner(js_file).useDelimiter("\\A");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
// load plugin from asset folder
|
// load plugin from asset folder
|
||||||
s = new Scanner(am.open("user-location.user.js")).useDelimiter("\\A");
|
this.loadJS("user-location.user.js", true, view);
|
||||||
} catch (IOException e2) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read a file into a string
|
||||||
|
// use the full path for File
|
||||||
|
// if asset == true use the asset manager to open file
|
||||||
|
public String fileToString(String file, boolean asset) {
|
||||||
|
Scanner s = null;
|
||||||
|
String src= "";
|
||||||
|
if (!asset) {
|
||||||
|
File js_file = new File(file);
|
||||||
|
try {
|
||||||
|
s = new Scanner(js_file).useDelimiter("\\A");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.d("iitcm", "failed to parse file " + file);
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// load plugins from asset folder
|
||||||
|
AssetManager am = context.getAssets();
|
||||||
|
try {
|
||||||
|
s = new Scanner(am.open(file)).useDelimiter("\\A");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.d("iitcm", "failed to parse file assets/" + file);
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (s != null) src = s.hasNext() ? s.next() : "";
|
if (s != null) src = s.hasNext() ? s.next() : "";
|
||||||
view.loadUrl("javascript:" + src);
|
return src;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read a file into a string
|
||||||
|
// load it as javascript
|
||||||
|
public boolean loadJS(String file, boolean asset, WebView view) {
|
||||||
|
if (!file.endsWith("user.js"))
|
||||||
|
return false;
|
||||||
|
String js = fileToString(file, asset);
|
||||||
|
if (js.equals("false"))
|
||||||
|
return false;
|
||||||
|
else view.loadUrl("javascript:" + js);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check every external resource if it’s okay to load it and maybe replace it
|
// Check every external resource if it’s okay to load it and maybe replace it
|
||||||
|
@ -86,6 +86,8 @@ $pages = Array (
|
|||||||
'donate' => '<i class="icon-gift"></i> Donate',
|
'donate' => '<i class="icon-gift"></i> Donate',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$page = 'home';
|
||||||
|
if ( array_key_exists ( 'page', $_REQUEST ) )
|
||||||
$page = $_REQUEST['page'];
|
$page = $_REQUEST['page'];
|
||||||
if ( ! array_key_exists ( $page, $pages ) )
|
if ( ! array_key_exists ( $page, $pages ) )
|
||||||
$page = "home";
|
$page = "home";
|
||||||
|
@ -17,15 +17,21 @@ function getMobileVersion ( $apkfile )
|
|||||||
|
|
||||||
|
|
||||||
$archive = $apkinfo->getApkArchive();
|
$archive = $apkinfo->getApkArchive();
|
||||||
$iitc_file = "assets/total-conversion-build.user.js";
|
|
||||||
if ( $archive->statName ( $iitc_file ) === FALSE );
|
|
||||||
$iitc_file = "assets/iitc.js";
|
|
||||||
|
|
||||||
$stream = $archive->getStream ( $iitc_file );
|
$stream = $archive->getStream ( "assets/total-conversion-build.user.js" );
|
||||||
|
if ( ! $stream )
|
||||||
|
$stream = $archive->getStream ( "assets/iitc.js" );
|
||||||
|
|
||||||
|
if ( $stream )
|
||||||
|
{
|
||||||
$header = loadUserScriptHeader ( $stream );
|
$header = loadUserScriptHeader ( $stream );
|
||||||
|
|
||||||
$result['iitc_version'] = $header['@version'];
|
$result['iitc_version'] = $header['@version'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$result['iitc_version'] = 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -40,7 +46,7 @@ function iitcMobileDownload ( $apkfile )
|
|||||||
|
|
||||||
# we need an absolute link for the QR Code
|
# we need an absolute link for the QR Code
|
||||||
# get the URL of this page itself
|
# get the URL of this page itself
|
||||||
$pageurl = ($_SERVER['HTTPS'] ? "https" : "http")."://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
$pageurl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? "https" : "http")."://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
||||||
$apkurl = url_to_absolute ( $pageurl, $apkfile );
|
$apkurl = url_to_absolute ( $pageurl, $apkfile );
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ function loadUserScriptHeader($file)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose ( $f );
|
fclose ( $file );
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,13 @@ include_once ( "code/desktop-download.php" );
|
|||||||
|
|
||||||
$path = "test";
|
$path = "test";
|
||||||
|
|
||||||
|
if ( array_key_exists ( 'build', $_REQUEST ) )
|
||||||
|
{
|
||||||
if ( $_REQUEST['build'] == 'experimental' )
|
if ( $_REQUEST['build'] == 'experimental' )
|
||||||
$path = "experimental";
|
$path = "experimental";
|
||||||
if ( $_REQUEST['build'] == 'dev' )
|
if ( $_REQUEST['build'] == 'dev' )
|
||||||
$path = "dev";
|
$path = "dev";
|
||||||
|
}
|
||||||
|
|
||||||
if ( $path != "test" )
|
if ( $path != "test" )
|
||||||
print "<div class=\"alert alert-block alert-error\"><b>NOTE</b>: A non-standard test build, <b>$path</b>, is currently selected. The notes <b>may not apply!</b> <a href=\"?page=test\">Return to the standard test build</a>.</div>";
|
print "<div class=\"alert alert-block alert-error\"><b>NOTE</b>: A non-standard test build, <b>$path</b>, is currently selected. The notes <b>may not apply!</b> <a href=\"?page=test\">Return to the standard test build</a>.</div>";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user