Formatted files via Eclipse to hopefully have correct spacing/ident.
This commit is contained in:
parent
4906b57f15
commit
b0e7110182
@ -10,7 +10,7 @@ import android.text.method.LinkMovementMethod;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class IITC_AboutDialogPreference extends DialogPreference{
|
public class IITC_AboutDialogPreference extends DialogPreference {
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
@ -20,11 +20,10 @@ public class IITC_AboutDialogPreference extends DialogPreference{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* start a little about-dialog
|
* start a little about-dialog srsly...I found no better way for clickable
|
||||||
* srsly...I found no better way for clickable links in a TextView then
|
* links in a TextView then using Html.fromHtml...Linkify is just broken and
|
||||||
* using Html.fromHtml...Linkify is just broken and does not understand
|
* does not understand html href tags...so let's tag the @string/about_msg
|
||||||
* html href tags...so let's tag the @string/about_msg with CDATA and
|
* with CDATA and use Html.fromHtml(...) for clickable hrefs with tags.
|
||||||
* use Html.fromHtml(...) for clickable hrefs with tags.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onPrepareDialogBuilder(Builder builder) {
|
protected void onPrepareDialogBuilder(Builder builder) {
|
||||||
@ -32,14 +31,13 @@ public class IITC_AboutDialogPreference extends DialogPreference{
|
|||||||
String about_msg = context.getText(R.string.pref_about_msg).toString();
|
String about_msg = context.getText(R.string.pref_about_msg).toString();
|
||||||
message.setText(Html.fromHtml(about_msg));
|
message.setText(Html.fromHtml(about_msg));
|
||||||
message.setMovementMethod(LinkMovementMethod.getInstance());
|
message.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
builder.setView(message)
|
builder.setView(message).setTitle(R.string.about)
|
||||||
.setTitle(R.string.about)
|
.setIcon(android.R.drawable.ic_dialog_info)
|
||||||
.setIcon(android.R.drawable.ic_dialog_info)
|
.setNeutralButton(R.string.close, new OnClickListener() {
|
||||||
.setNeutralButton(R.string.close, new OnClickListener() {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
dialog.cancel();
|
||||||
dialog.cancel();
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
super.onPrepareDialogBuilder(builder);
|
super.onPrepareDialogBuilder(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ public class IITC_JSInterface {
|
|||||||
// send geo intent for navigation apps like gmaps or waze etc...
|
// send geo intent for navigation apps like gmaps or waze etc...
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void intentPosLink(String lat, String lng, String portal_name) {
|
public void intentPosLink(String lat, String lng, String portal_name) {
|
||||||
String uri = "geo:" + lat + "," + lng + "?q=" + lat + "," + lng + portal_name;
|
String uri = "geo:" + lat + "," + lng + "?q=" + lat + "," + lng
|
||||||
|
+ portal_name;
|
||||||
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
||||||
Uri.parse(uri));
|
Uri.parse(uri));
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
@ -30,9 +31,11 @@ public class IITC_JSInterface {
|
|||||||
// copy link to specific portal to android clipboard
|
// copy link to specific portal to android clipboard
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void copy(String s) {
|
public void copy(String s) {
|
||||||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager) context
|
||||||
|
.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
ClipData clip = ClipData.newPlainText("Copied Text ", s);
|
ClipData clip = ClipData.newPlainText("Copied Text ", s);
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "copied to clipboard", Toast.LENGTH_SHORT)
|
||||||
|
.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,70 +46,87 @@ public class IITC_Mobile extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// TODO build an async task for url.openStream() in IITC_WebViewClient
|
// TODO build an async task for url.openStream() in IITC_WebViewClient
|
||||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
|
||||||
|
.permitAll().build();
|
||||||
StrictMode.setThreadPolicy(policy);
|
StrictMode.setThreadPolicy(policy);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
iitc_view = (IITC_WebView) findViewById(R.id.iitc_webview);
|
iitc_view = (IITC_WebView) findViewById(R.id.iitc_webview);
|
||||||
|
|
||||||
actionBar = this.getActionBar();
|
actionBar = this.getActionBar();
|
||||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
|
||||||
|
| ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
|
||||||
actionBar.setTitle(getString(R.string.menu_map));
|
actionBar.setTitle(getString(R.string.menu_map));
|
||||||
actionBar.setHomeButtonEnabled(true);
|
actionBar.setHomeButtonEnabled(true);
|
||||||
|
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPref = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(this);
|
||||||
listener = new OnSharedPreferenceChangeListener() {
|
listener = new OnSharedPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(
|
||||||
|
SharedPreferences sharedPreferences, String key) {
|
||||||
if (key.equals("pref_user_loc"))
|
if (key.equals("pref_user_loc"))
|
||||||
user_loc = sharedPreferences.getBoolean("pref_user_loc", false);
|
user_loc = sharedPreferences.getBoolean("pref_user_loc",
|
||||||
|
false);
|
||||||
IITC_Mobile.this.loadUrl(intel_url);
|
IITC_Mobile.this.loadUrl(intel_url);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
sharedPref.registerOnSharedPreferenceChangeListener(listener);
|
sharedPref.registerOnSharedPreferenceChangeListener(listener);
|
||||||
|
|
||||||
// we need this one to prevent location updates to javascript when keyboard is open
|
// we need this one to prevent location updates to javascript when
|
||||||
|
// keyboard is open
|
||||||
// it closes on updates
|
// it closes on updates
|
||||||
iitc_view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
|
iitc_view.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||||
@Override
|
new OnGlobalLayoutListener() {
|
||||||
public void onGlobalLayout() {
|
@Override
|
||||||
Rect r = new Rect();
|
public void onGlobalLayout() {
|
||||||
//r will be populated with the coordinates of your view that area still visible.
|
Rect r = new Rect();
|
||||||
iitc_view.getWindowVisibleDisplayFrame(r);
|
// 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 screenHeight = iitc_view.getRootView().getHeight();
|
||||||
int heightDiff = screenHeight - (r.bottom - r.top);
|
int heightDiff = screenHeight - (r.bottom - r.top);
|
||||||
boolean visible = heightDiff > screenHeight / 3;
|
boolean visible = heightDiff > screenHeight / 3;
|
||||||
if (visible == true) {
|
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 {
|
||||||
Log.d("iitcm", "Close Keyboard...");
|
Log.d("iitcm", "Close Keyboard...");
|
||||||
IITC_Mobile.this.keyboad_open = false;
|
IITC_Mobile.this.keyboad_open = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Acquire a reference to the system Location Manager
|
// Acquire a reference to the system Location Manager
|
||||||
loc_mngr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
|
loc_mngr = (LocationManager) this
|
||||||
|
.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
// Define a listener that responds to location updates
|
// Define a listener that responds to location updates
|
||||||
loc_listener = new LocationListener() {
|
loc_listener = new LocationListener() {
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
// Called when a new location is found by the network location provider.
|
// Called when a new location is found by the network location
|
||||||
drawMarker(location);
|
// provider.
|
||||||
|
drawMarker(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras) {}
|
public void onStatusChanged(String provider, int status,
|
||||||
|
Bundle extras) {
|
||||||
|
}
|
||||||
|
|
||||||
public void onProviderEnabled(String provider) {}
|
public void onProviderEnabled(String provider) {
|
||||||
|
}
|
||||||
|
|
||||||
public void onProviderDisabled(String provider) {}
|
public void onProviderDisabled(String provider) {
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
user_loc = sharedPref.getBoolean("pref_user_loc", false);
|
user_loc = sharedPref.getBoolean("pref_user_loc", false);
|
||||||
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
|
||||||
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, loc_listener);
|
// location updates
|
||||||
loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, loc_listener);
|
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
|
||||||
|
0, 0, loc_listener);
|
||||||
|
loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
|
||||||
|
loc_listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load new iitc web view with ingress intel page
|
// load new iitc web view with ingress intel page
|
||||||
@ -125,8 +142,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
Log.d("iitcm", "loading url...");
|
Log.d("iitcm", "loading url...");
|
||||||
this.loadUrl(url);
|
this.loadUrl(url);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.loadUrl(intel_url);
|
this.loadUrl(intel_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,9 +158,12 @@ public class IITC_Mobile extends Activity {
|
|||||||
iitc_view.updateCaching();
|
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
|
||||||
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, loc_listener);
|
// location updates
|
||||||
loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, loc_listener);
|
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
|
||||||
|
0, 0, loc_listener);
|
||||||
|
loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
|
||||||
|
loc_listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,25 +171,32 @@ public class IITC_Mobile extends Activity {
|
|||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
|
||||||
NetworkInfo mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
NetworkInfo mobile = conMan
|
||||||
|
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||||
NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
|
|
||||||
// check if Mobile or Wifi module is available..then handle states
|
// check if Mobile or Wifi module is available..then handle states
|
||||||
// TODO: theory...we do not have to check for a Wifi module...every android device should have one
|
// TODO: theory...we do not have to check for a Wifi module...every
|
||||||
|
// android device should have one
|
||||||
if (mobile != null) {
|
if (mobile != null) {
|
||||||
Log.d("iitcm", "mobile internet module detected...check states");
|
Log.d("iitcm", "mobile internet module detected...check states");
|
||||||
if (mobile.getState() == NetworkInfo.State.CONNECTED || mobile.getState() == NetworkInfo.State.CONNECTING) {
|
if (mobile.getState() == NetworkInfo.State.CONNECTED
|
||||||
Log.d("iitcm", "connected to mobile net...abort all running requests");
|
|| mobile.getState() == NetworkInfo.State.CONNECTING) {
|
||||||
|
Log.d("iitcm",
|
||||||
|
"connected to mobile net...abort all running requests");
|
||||||
// cancel all current requests
|
// cancel all current requests
|
||||||
iitc_view.loadUrl("javascript: window.requests.abort()");
|
iitc_view.loadUrl("javascript: window.requests.abort()");
|
||||||
// set idletime to maximum...no need for more
|
// set idletime to maximum...no need for more
|
||||||
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
||||||
} else if (wifi.getState() == NetworkInfo.State.CONNECTED || wifi.getState() == NetworkInfo.State.CONNECTING) {
|
} else if (wifi.getState() == NetworkInfo.State.CONNECTED
|
||||||
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
|| wifi.getState() == NetworkInfo.State.CONNECTING) {
|
||||||
|
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d("iitcm", "no mobile internet module detected...check wifi state");
|
Log.d("iitcm",
|
||||||
if (wifi.getState() == NetworkInfo.State.CONNECTED || wifi.getState() == NetworkInfo.State.CONNECTING) {
|
"no mobile internet module detected...check wifi state");
|
||||||
|
if (wifi.getState() == NetworkInfo.State.CONNECTED
|
||||||
|
|| wifi.getState() == NetworkInfo.State.CONNECTING) {
|
||||||
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
iitc_view.loadUrl("javascript: window.idleTime = 999");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,7 +244,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
back_button_pressed=false;
|
back_button_pressed = false;
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
@ -235,85 +261,90 @@ public class IITC_Mobile extends Activity {
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
// Handle item selection
|
// Handle item selection
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home :
|
||||||
iitc_view.loadUrl("javascript: window.show('map');");
|
iitc_view.loadUrl("javascript: window.show('map');");
|
||||||
actionBar.setTitle(getString(R.string.menu_map));
|
actionBar.setTitle(getString(R.string.menu_map));
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_map:
|
case R.id.menu_map :
|
||||||
iitc_view.loadUrl("javascript: window.show('map');");
|
iitc_view.loadUrl("javascript: window.show('map');");
|
||||||
actionBar.setTitle(getString(R.string.menu_map));
|
actionBar.setTitle(getString(R.string.menu_map));
|
||||||
return true;
|
return true;
|
||||||
case R.id.reload_button:
|
case R.id.reload_button :
|
||||||
this.loadUrl(intel_url);
|
this.loadUrl(intel_url);
|
||||||
actionBar.setTitle(getString(R.string.menu_map));
|
actionBar.setTitle(getString(R.string.menu_map));
|
||||||
return true;
|
return true;
|
||||||
// clear cache
|
// clear cache
|
||||||
case R.id.cache_clear:
|
case R.id.cache_clear :
|
||||||
iitc_view.clearHistory();
|
iitc_view.clearHistory();
|
||||||
iitc_view.clearFormData();
|
iitc_view.clearFormData();
|
||||||
iitc_view.clearCache(true);
|
iitc_view.clearCache(true);
|
||||||
return true;
|
return true;
|
||||||
// toggle fullscreen
|
// toggle fullscreen
|
||||||
case R.id.toggle_fullscreen:
|
case R.id.toggle_fullscreen :
|
||||||
if (!this.fullscreen_mode) {
|
if (!this.fullscreen_mode) {
|
||||||
// get rid of action bar
|
// get rid of action bar
|
||||||
this.getActionBar().hide();
|
this.getActionBar().hide();
|
||||||
// hide notification bar
|
// hide notification bar
|
||||||
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
WindowManager.LayoutParams attrs = getWindow()
|
||||||
attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
.getAttributes();
|
||||||
this.getWindow().setAttributes(attrs);
|
attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||||
this.fullscreen_mode = true;
|
this.getWindow().setAttributes(attrs);
|
||||||
// show a little toast for the user
|
this.fullscreen_mode = true;
|
||||||
Toast.makeText(this, "Press back button to exit fullscreen", Toast.LENGTH_SHORT).show();
|
// show a little toast for the user
|
||||||
}
|
Toast.makeText(this,
|
||||||
else {
|
"Press back button to exit fullscreen",
|
||||||
// get back action bar
|
Toast.LENGTH_SHORT).show();
|
||||||
this.getActionBar().show();
|
} else {
|
||||||
// show notification bar again
|
// get back action bar
|
||||||
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
this.getActionBar().show();
|
||||||
attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
// show notification bar again
|
||||||
this.getWindow().setAttributes(attrs);
|
WindowManager.LayoutParams attrs = getWindow()
|
||||||
this.fullscreen_mode = false;
|
.getAttributes();
|
||||||
}
|
attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
||||||
return true;
|
this.getWindow().setAttributes(attrs);
|
||||||
// get the users current location and focus it on map
|
this.fullscreen_mode = false;
|
||||||
case R.id.locate:
|
}
|
||||||
|
return true;
|
||||||
|
// get the users current location and focus it on map
|
||||||
|
case R.id.locate :
|
||||||
iitc_view.loadUrl("javascript: window.show('map');");
|
iitc_view.loadUrl("javascript: window.show('map');");
|
||||||
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});");
|
iitc_view
|
||||||
|
.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});");
|
||||||
actionBar.setTitle(getString(R.string.menu_map));
|
actionBar.setTitle(getString(R.string.menu_map));
|
||||||
return true;
|
return true;
|
||||||
// start settings activity
|
// start settings activity
|
||||||
case R.id.action_settings:
|
case R.id.action_settings :
|
||||||
Intent intent = new Intent(this, IITC_Settings.class);
|
Intent intent = new Intent(this, IITC_Settings.class);
|
||||||
intent.putExtra("iitc_version", iitc_view.getWebViewClient().getIITCVersion());
|
intent.putExtra("iitc_version", iitc_view.getWebViewClient()
|
||||||
startActivity(intent);
|
.getIITCVersion());
|
||||||
return true;
|
startActivity(intent);
|
||||||
case R.id.menu_info:
|
return true;
|
||||||
|
case R.id.menu_info :
|
||||||
iitc_view.loadUrl("javascript: window.show('info');");
|
iitc_view.loadUrl("javascript: window.show('info');");
|
||||||
actionBar.setTitle(getString(R.string.menu_info));
|
actionBar.setTitle(getString(R.string.menu_info));
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_full:
|
case R.id.menu_full :
|
||||||
iitc_view.loadUrl("javascript: window.show('full');");
|
iitc_view.loadUrl("javascript: window.show('full');");
|
||||||
actionBar.setTitle(getString(R.string.menu_full));
|
actionBar.setTitle(getString(R.string.menu_full));
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_compact:
|
case R.id.menu_compact :
|
||||||
iitc_view.loadUrl("javascript: window.show('compact');");
|
iitc_view.loadUrl("javascript: window.show('compact');");
|
||||||
actionBar.setTitle(getString(R.string.menu_compact));
|
actionBar.setTitle(getString(R.string.menu_compact));
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_public:
|
case R.id.menu_public :
|
||||||
iitc_view.loadUrl("javascript: window.show('public');");
|
iitc_view.loadUrl("javascript: window.show('public');");
|
||||||
actionBar.setTitle(getString(R.string.menu_public));
|
actionBar.setTitle(getString(R.string.menu_public));
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_faction:
|
case R.id.menu_faction :
|
||||||
iitc_view.loadUrl("javascript: window.show('faction');");
|
iitc_view.loadUrl("javascript: window.show('faction');");
|
||||||
actionBar.setTitle(getString(R.string.menu_faction));
|
actionBar.setTitle(getString(R.string.menu_faction));
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_debug:
|
case R.id.menu_debug :
|
||||||
iitc_view.loadUrl("javascript: window.show('debug')");
|
iitc_view.loadUrl("javascript: window.show('debug')");
|
||||||
actionBar.setTitle(getString(R.string.menu_debug));
|
actionBar.setTitle(getString(R.string.menu_debug));
|
||||||
return true;
|
return true;
|
||||||
default:
|
default :
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +361,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
// Force mobile view.
|
// Force mobile view.
|
||||||
// New actions are not compatible with desktop mode
|
// New actions are not compatible with desktop mode
|
||||||
private String addUrlParam(String url) {
|
private String addUrlParam(String url) {
|
||||||
return (url + "?vp=m");
|
return (url + "?vp=m");
|
||||||
}
|
}
|
||||||
|
|
||||||
// inject the iitc-script and load the intel url
|
// inject the iitc-script and load the intel url
|
||||||
@ -348,9 +379,9 @@ public class IITC_Mobile extends Activity {
|
|||||||
// should avoid gps glitches
|
// should avoid gps glitches
|
||||||
if (loc.getAccuracy() < 100) {
|
if (loc.getAccuracy() < 100) {
|
||||||
if (keyboad_open == false) {
|
if (keyboad_open == false) {
|
||||||
iitc_view.loadUrl("javascript: " +
|
iitc_view.loadUrl("javascript: "
|
||||||
"window.plugin.userLocation.updateLocation( " +
|
+ "window.plugin.userLocation.updateLocation( "
|
||||||
loc.getLatitude() + ", " + loc.getLongitude() + ");");
|
+ loc.getLatitude() + ", " + loc.getLongitude() + ");");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,18 +28,21 @@ public class IITC_Settings extends Activity {
|
|||||||
ArrayList<String> asset_list = new ArrayList<String>();
|
ArrayList<String> asset_list = new ArrayList<String>();
|
||||||
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++) {
|
||||||
// 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 = "";
|
||||||
try {
|
try {
|
||||||
s = new Scanner(am.open("plugins/" + asset_array[i])).useDelimiter("\\A");
|
s = new Scanner(am.open("plugins/" + asset_array[i]))
|
||||||
|
.useDelimiter("\\A");
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
}
|
}
|
||||||
if (s != null) src = s.hasNext() ? s.next() : "";
|
if (s != null)
|
||||||
String header = src.substring(src.indexOf("==UserScript=="), src.indexOf("==/UserScript=="));
|
src = s.hasNext() ? s.next() : "";
|
||||||
|
String header = src.substring(src.indexOf("==UserScript=="),
|
||||||
|
src.indexOf("==/UserScript=="));
|
||||||
// remove new line comments and replace with space
|
// remove new line comments and replace with space
|
||||||
// this way we get double spaces instead of newline + double slash
|
// this way we get double spaces instead of newline + double slash
|
||||||
header = header.replace("\n//", " ");
|
header = header.replace("\n//", " ");
|
||||||
@ -48,7 +51,8 @@ public class IITC_Settings extends Activity {
|
|||||||
String plugin_name = "not found";
|
String plugin_name = "not found";
|
||||||
for (int j = 0; j < attributes.length; j++) {
|
for (int j = 0; j < attributes.length; j++) {
|
||||||
// search for name and use the value
|
// search for name and use the value
|
||||||
if (attributes[j].equals("@name")) plugin_name = attributes[j+1];
|
if (attributes[j].equals("@name"))
|
||||||
|
plugin_name = attributes[j + 1];
|
||||||
}
|
}
|
||||||
asset_list.add(plugin_name);
|
asset_list.add(plugin_name);
|
||||||
// real value
|
// real value
|
||||||
@ -56,13 +60,14 @@ public class IITC_Settings extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bundle bundle = getIntent().getExtras();
|
Bundle bundle = getIntent().getExtras();
|
||||||
bundle.putStringArray("ASSETS", (String[]) asset_list.toArray(new String[0]));
|
bundle.putStringArray("ASSETS",
|
||||||
bundle.putStringArray("ASSETS_VAL", (String[]) asset_values.toArray(new String[0]));
|
(String[]) asset_list.toArray(new String[0]));
|
||||||
|
bundle.putStringArray("ASSETS_VAL",
|
||||||
|
(String[]) asset_values.toArray(new String[0]));
|
||||||
settings.setArguments(bundle);
|
settings.setArguments(bundle);
|
||||||
|
|
||||||
// Display the fragment as the main content.
|
// Display the fragment as the main content.
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
.replace(android.R.id.content, settings)
|
.replace(android.R.id.content, settings).commit();
|
||||||
.commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,20 +23,21 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
|||||||
|
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
//plugins
|
// plugins
|
||||||
MultiSelectListPreference pref_plugins = (MultiSelectListPreference) findPreference("pref_plugins");
|
MultiSelectListPreference pref_plugins = (MultiSelectListPreference) findPreference("pref_plugins");
|
||||||
pref_plugins.setEntries(getArguments().getStringArray("ASSETS"));
|
pref_plugins.setEntries(getArguments().getStringArray("ASSETS"));
|
||||||
pref_plugins.setEntryValues(getArguments().getStringArray("ASSETS_VAL"));
|
pref_plugins
|
||||||
|
.setEntryValues(getArguments().getStringArray("ASSETS_VAL"));
|
||||||
|
|
||||||
// set build version
|
// set build version
|
||||||
ListPreference pref_build_version = (ListPreference) findPreference("pref_build_version");
|
ListPreference pref_build_version = (ListPreference) findPreference("pref_build_version");
|
||||||
PackageManager pm = getActivity().getPackageManager();
|
PackageManager pm = getActivity().getPackageManager();
|
||||||
String version = "unknown";
|
String version = "unknown";
|
||||||
try {
|
try {
|
||||||
PackageInfo info = pm.getPackageInfo(getActivity().getPackageName(), 0);
|
PackageInfo info = pm.getPackageInfo(
|
||||||
|
getActivity().getPackageName(), 0);
|
||||||
version = info.versionName;
|
version = info.versionName;
|
||||||
}
|
} catch (NameNotFoundException e) {
|
||||||
catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
pref_build_version.setSummary(version);
|
pref_build_version.setSummary(version);
|
||||||
@ -47,16 +48,20 @@ public class IITC_SettingsFragment extends PreferenceFragment {
|
|||||||
|
|
||||||
// set iitc source
|
// set iitc source
|
||||||
EditTextPreference pref_iitc_source = (EditTextPreference) findPreference("pref_iitc_source");
|
EditTextPreference pref_iitc_source = (EditTextPreference) findPreference("pref_iitc_source");
|
||||||
pref_iitc_source.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
pref_iitc_source
|
||||||
@Override
|
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
@Override
|
||||||
preference.setSummary((CharSequence) newValue);
|
public boolean onPreferenceChange(Preference preference,
|
||||||
// TODO: update iitc_version when iitc source has changed
|
Object newValue) {
|
||||||
return true;
|
preference.setSummary((CharSequence) newValue);
|
||||||
}
|
// TODO: update iitc_version when iitc source has
|
||||||
});
|
// changed
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
// first init of summary
|
// first init of summary
|
||||||
String pref_iitc_source_sum = (String) pref_iitc_source.getSummary() + pref_iitc_source.getText();
|
String pref_iitc_source_sum = (String) pref_iitc_source.getSummary()
|
||||||
|
+ pref_iitc_source.getText();
|
||||||
pref_iitc_source.setSummary(pref_iitc_source_sum);
|
pref_iitc_source.setSummary(pref_iitc_source_sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,10 @@ public class IITC_WebView extends WebView {
|
|||||||
settings.setAllowFileAccess(true);
|
settings.setAllowFileAccess(true);
|
||||||
settings.setGeolocationEnabled(true);
|
settings.setGeolocationEnabled(true);
|
||||||
settings.setAppCacheEnabled(true);
|
settings.setAppCacheEnabled(true);
|
||||||
settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + "/databases/");
|
settings.setDatabasePath(this.getContext().getApplicationInfo().dataDir
|
||||||
settings.setAppCachePath(this.getContext().getCacheDir().getAbsolutePath());
|
+ "/databases/");
|
||||||
|
settings.setAppCachePath(this.getContext().getCacheDir()
|
||||||
|
.getAbsolutePath());
|
||||||
// use cache if on mobile network...saves traffic
|
// 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");
|
||||||
@ -38,7 +40,8 @@ public class IITC_WebView extends WebView {
|
|||||||
// allow access by default
|
// allow access by default
|
||||||
this.setWebChromeClient(new WebChromeClient() {
|
this.setWebChromeClient(new WebChromeClient() {
|
||||||
@Override
|
@Override
|
||||||
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
public void onGeolocationPermissionsShowPrompt(String origin,
|
||||||
|
GeolocationPermissions.Callback callback) {
|
||||||
callback.invoke(origin, true, false);
|
callback.invoke(origin, true, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -65,13 +68,15 @@ public class IITC_WebView extends WebView {
|
|||||||
|
|
||||||
iitc_init(context);
|
iitc_init(context);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadUrl(String url) {
|
public void loadUrl(String url) {
|
||||||
if (!url.startsWith("javascript:")) {
|
if (!url.startsWith("javascript:")) {
|
||||||
// force https if enabled in settings
|
// force https if enabled in settings
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
SharedPreferences sharedPref = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(getContext());
|
||||||
if (sharedPref.getBoolean("pref_force_https", true))
|
if (sharedPref.getBoolean("pref_force_https", true))
|
||||||
url = url.replace("http://", "https://");
|
url = url.replace("http://", "https://");
|
||||||
else
|
else
|
||||||
@ -90,8 +95,7 @@ public class IITC_WebView extends WebView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateCaching() {
|
public void updateCaching() {
|
||||||
if (!this.isConnectedToWifi())
|
if (!this.isConnectedToWifi()) {
|
||||||
{
|
|
||||||
Log.d("iitcm", "not connected to wifi...load tiles from cache");
|
Log.d("iitcm", "not connected to wifi...load tiles from cache");
|
||||||
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||||
} else {
|
} else {
|
||||||
@ -101,7 +105,8 @@ public class IITC_WebView extends WebView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConnectedToWifi() {
|
private boolean isConnectedToWifi() {
|
||||||
ConnectivityManager conMan = (ConnectivityManager) getContext().getSystemService( Context.CONNECTIVITY_SERVICE );
|
ConnectivityManager conMan = (ConnectivityManager) getContext()
|
||||||
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
return wifi.getState() == NetworkInfo.State.CONNECTED;
|
return wifi.getState() == NetworkInfo.State.CONNECTED;
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,10 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class IITC_WebViewClient extends WebViewClient {
|
public class IITC_WebViewClient extends WebViewClient {
|
||||||
private static final ByteArrayInputStream style = new ByteArrayInputStream(
|
private static final ByteArrayInputStream style = new ByteArrayInputStream(
|
||||||
"body, #dashboard_container, #map_canvas { background: #000 !important; }".getBytes());
|
"body, #dashboard_container, #map_canvas { background: #000 !important; }"
|
||||||
private static final ByteArrayInputStream empty = new ByteArrayInputStream("".getBytes());
|
.getBytes());
|
||||||
|
private static final ByteArrayInputStream empty = new ByteArrayInputStream(
|
||||||
|
"".getBytes());
|
||||||
|
|
||||||
private WebResourceResponse iitcjs;
|
private WebResourceResponse iitcjs;
|
||||||
private String js = null;
|
private String js = null;
|
||||||
@ -36,10 +38,11 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
public IITC_WebViewClient(Context c) {
|
public IITC_WebViewClient(Context c) {
|
||||||
this.context = c;
|
this.context = c;
|
||||||
this.iitc_path = Environment.getExternalStorageDirectory().getPath() + "/IITC_Mobile/";
|
this.iitc_path = Environment.getExternalStorageDirectory().getPath()
|
||||||
|
+ "/IITC_Mobile/";
|
||||||
try {
|
try {
|
||||||
loadIITC_JS(c);
|
loadIITC_JS(c);
|
||||||
} catch(IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +50,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
public String getIITCVersion() {
|
public String getIITCVersion() {
|
||||||
String header = "";
|
String header = "";
|
||||||
if (js != null)
|
if (js != null)
|
||||||
header = js.substring(js.indexOf("==UserScript=="), js.indexOf("==/UserScript=="));
|
header = js.substring(js.indexOf("==UserScript=="),
|
||||||
|
js.indexOf("==/UserScript=="));
|
||||||
// remove new line comments
|
// remove new line comments
|
||||||
header = header.replace("\n//", "");
|
header = header.replace("\n//", "");
|
||||||
// get a list of key-value
|
// get a list of key-value
|
||||||
@ -55,35 +59,46 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
String iitc_version = "not found";
|
String iitc_version = "not found";
|
||||||
for (int i = 0; i < attributes.length; i++) {
|
for (int i = 0; i < attributes.length; i++) {
|
||||||
// search for version and use the value
|
// search for version and use the value
|
||||||
if (attributes[i].equals("@version")) iitc_version = attributes[i+1];
|
if (attributes[i].equals("@version"))
|
||||||
|
iitc_version = attributes[i + 1];
|
||||||
}
|
}
|
||||||
return iitc_version;
|
return iitc_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadIITC_JS(Context c) throws java.io.IOException {
|
public void loadIITC_JS(Context c) throws java.io.IOException {
|
||||||
// You are able to load the script from external source
|
// You are able to load the script from external source
|
||||||
// if a http address is given, use script from this address. else use the local script
|
// if a http address is given, use script from this address. else use
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(c);
|
// the local script
|
||||||
|
SharedPreferences sharedPref = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(c);
|
||||||
String iitc_source = sharedPref.getString("pref_iitc_source", "local");
|
String iitc_source = sharedPref.getString("pref_iitc_source", "local");
|
||||||
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", false)) {
|
if (sharedPref.getBoolean("pref_dev_checkbox", false)) {
|
||||||
js = this.fileToString(iitc_path + "dev/total-conversion-build.user.js", false);
|
js = this.fileToString(iitc_path
|
||||||
|
+ "dev/total-conversion-build.user.js", false);
|
||||||
if (js.equals("false")) {
|
if (js.equals("false")) {
|
||||||
Toast.makeText(context, "File " + iitc_path +
|
Toast.makeText(
|
||||||
"dev/total-conversion-build.user.js not found. " +
|
context,
|
||||||
"Disable developer mode or add iitc files " +
|
"File "
|
||||||
"to the dev folder.", Toast.LENGTH_LONG).show();
|
+ iitc_path
|
||||||
|
+ "dev/total-conversion-build.user.js not found. "
|
||||||
|
+ "Disable developer mode or add iitc files "
|
||||||
|
+ "to the dev folder.", Toast.LENGTH_LONG)
|
||||||
|
.show();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, "Developer mode enabled", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Developer mode enabled",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
} 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 {
|
||||||
js = this.fileToString("total-conversion-build.user.js", true);
|
js = this.fileToString("total-conversion-build.user.js", true);
|
||||||
}
|
}
|
||||||
@ -92,15 +107,14 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
this.js = js;
|
this.js = js;
|
||||||
|
|
||||||
PackageManager pm = context.getPackageManager();
|
PackageManager pm = context.getPackageManager();
|
||||||
boolean hasMultitouch =
|
boolean hasMultitouch = pm
|
||||||
pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
|
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
|
||||||
boolean forcedZoom = sharedPref.getBoolean("pref_user_zoom", false);
|
boolean forcedZoom = sharedPref.getBoolean("pref_user_zoom", false);
|
||||||
if (hasMultitouch && !forcedZoom) {
|
if (hasMultitouch && !forcedZoom) {
|
||||||
js = js.replace("window.showZoom = true;", "window.showZoom = false;");
|
js = js.replace("window.showZoom = true;",
|
||||||
|
"window.showZoom = false;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// need to wrap the mobile iitc.js version in a document ready. IITC
|
// need to wrap the mobile iitc.js version in a document ready. IITC
|
||||||
// expects to be injected after the DOM has been loaded completely.
|
// expects to be injected after the DOM has been loaded completely.
|
||||||
// Since the mobile client injects IITC by replacing the gen_dashboard
|
// Since the mobile client injects IITC by replacing the gen_dashboard
|
||||||
@ -108,17 +122,15 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
// so it boots correctly.
|
// so it boots correctly.
|
||||||
js = "$(document).ready(function(){" + js + "});";
|
js = "$(document).ready(function(){" + js + "});";
|
||||||
|
|
||||||
iitcjs = new WebResourceResponse(
|
iitcjs = new WebResourceResponse("text/javascript", "UTF-8",
|
||||||
"text/javascript",
|
new ByteArrayInputStream(js.getBytes()));
|
||||||
"UTF-8",
|
|
||||||
new ByteArrayInputStream(js.getBytes())
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// enable https
|
// enable https
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
public void onReceivedSslError(WebView view, SslErrorHandler handler,
|
||||||
handler.proceed() ;
|
SslError error) {
|
||||||
|
handler.proceed();
|
||||||
};
|
};
|
||||||
|
|
||||||
// plugins should be loaded after the main script is injected
|
// plugins should be loaded after the main script is injected
|
||||||
@ -127,7 +139,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
super.onPageFinished(view, url);
|
super.onPageFinished(view, url);
|
||||||
|
|
||||||
// get the plugin preferences
|
// get the plugin preferences
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences sharedPref = PreferenceManager
|
||||||
|
.getDefaultSharedPreferences(context);
|
||||||
Set<String> plugin_list = sharedPref.getStringSet("pref_plugins", null);
|
Set<String> plugin_list = sharedPref.getStringSet("pref_plugins", null);
|
||||||
boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", true);
|
boolean dev_enabled = sharedPref.getBoolean("pref_dev_checkbox", true);
|
||||||
|
|
||||||
@ -135,10 +148,11 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
if (plugin_list != null) {
|
if (plugin_list != null) {
|
||||||
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++) {
|
||||||
Log.d("iitcm", "adding plugin " + plugin_array[i]);
|
Log.d("iitcm", "adding plugin " + plugin_array[i]);
|
||||||
if (dev_enabled)
|
if (dev_enabled)
|
||||||
this.loadJS(iitc_path + "dev/plugins/" + plugin_array[i], false, view);
|
this.loadJS(iitc_path + "dev/plugins/" + plugin_array[i],
|
||||||
|
false, view);
|
||||||
else
|
else
|
||||||
this.loadJS("plugins/" + plugin_array[i], true, view);
|
this.loadJS("plugins/" + plugin_array[i], true, view);
|
||||||
}
|
}
|
||||||
@ -153,20 +167,21 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
File[] files = directory.listFiles();
|
File[] files = directory.listFiles();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (int i = 0; i < files.length; ++i) {
|
for (int i = 0; i < files.length; ++i) {
|
||||||
if(this.loadJS(files[i].toString(), false, view))
|
if (this.loadJS(files[i].toString(), false, view))
|
||||||
Log.d("iitcm", "loading additional plugin " + files[i].toString());
|
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...");
|
||||||
// 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)
|
||||||
this.loadJS(iitc_path + "dev/user-location.user.js", false, view);
|
this.loadJS(iitc_path + "dev/user-location.user.js", false, view);
|
||||||
else
|
else
|
||||||
// load plugin from asset folder
|
// load plugin from asset folder
|
||||||
this.loadJS("user-location.user.js", true, view);
|
this.loadJS("user-location.user.js", true, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
// read a file into a string
|
// read a file into a string
|
||||||
@ -174,7 +189,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
// if asset == true use the asset manager to open file
|
// if asset == true use the asset manager to open file
|
||||||
public String fileToString(String file, boolean asset) {
|
public String fileToString(String file, boolean asset) {
|
||||||
Scanner s = null;
|
Scanner s = null;
|
||||||
String src= "";
|
String src = "";
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
File js_file = new File(file);
|
File js_file = new File(file);
|
||||||
try {
|
try {
|
||||||
@ -196,7 +211,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s != null) src = s.hasNext() ? s.next() : "";
|
if (s != null)
|
||||||
|
src = s.hasNext() ? s.next() : "";
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,21 +224,24 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
String js = fileToString(file, asset);
|
String js = fileToString(file, asset);
|
||||||
if (js.equals("false"))
|
if (js.equals("false"))
|
||||||
return false;
|
return false;
|
||||||
else view.loadUrl("javascript:" + js);
|
else
|
||||||
|
view.loadUrl("javascript:" + js);
|
||||||
return true;
|
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
|
||||||
// with our own content. This is used to block loading Niantic resources
|
// with our own content. This is used to block loading Niantic resources
|
||||||
// which aren’t required and to inject IITC early into the site.
|
// which aren’t required and to inject IITC early into the site.
|
||||||
// via http://stackoverflow.com/a/8274881/1684530
|
// via http://stackoverflow.com/a/8274881/1684530
|
||||||
@Override
|
@Override
|
||||||
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
|
public WebResourceResponse shouldInterceptRequest(final WebView view,
|
||||||
if(url.contains("/css/common.css")) {
|
String url) {
|
||||||
|
if (url.contains("/css/common.css")) {
|
||||||
return new WebResourceResponse("text/css", "UTF-8", style);
|
return new WebResourceResponse("text/css", "UTF-8", style);
|
||||||
} else if(url.contains("gen_dashboard.js")) {
|
} else if (url.contains("gen_dashboard.js")) {
|
||||||
return this.iitcjs;
|
return this.iitcjs;
|
||||||
} else if(url.contains("/css/ap_icons.css")
|
} else if (url.contains("/css/ap_icons.css")
|
||||||
|| url.contains("/css/map_icons.css")
|
|| url.contains("/css/map_icons.css")
|
||||||
|| url.contains("/css/misc_icons.css")
|
|| url.contains("/css/misc_icons.css")
|
||||||
|| url.contains("/css/style_full.css")
|
|| url.contains("/css/style_full.css")
|
||||||
@ -241,13 +260,18 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||||
if (url.contains("ingress.com") || url.contains("appengine.google.com")) {
|
if (url.contains("ingress.com") || url.contains("appengine.google.com")) {
|
||||||
// reload iitc if a poslink is clicked inside the app
|
// reload iitc if a poslink is clicked inside the app
|
||||||
if (url.contains("intel?ll=") || (url.contains("latE6") && url.contains("lngE6"))) {
|
if (url.contains("intel?ll=")
|
||||||
Log.d("iitcm", "should be an internal clicked position link...reload script for: " + url);
|
|| (url.contains("latE6") && url.contains("lngE6"))) {
|
||||||
|
Log.d("iitcm",
|
||||||
|
"should be an internal clicked position link...reload script for: "
|
||||||
|
+ url);
|
||||||
((IITC_Mobile) context).loadUrl(url);
|
((IITC_Mobile) context).loadUrl(url);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
Log.d("iitcm", "no ingress intel link, start external app to load url: " + url);
|
Log.d("iitcm",
|
||||||
|
"no ingress intel link, start external app to load url: "
|
||||||
|
+ url);
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user