improved debugging interface
@ -507,7 +507,8 @@ window.setupLayerChooserApi = function() {
|
||||
|
||||
function boot() {
|
||||
try { //EXPERIMENTAL TEST
|
||||
window.debug.console.overwriteNativeIfRequired();
|
||||
if(!isSmartphone()) // TODO remove completly?
|
||||
window.debug.console.overwriteNativeIfRequired();
|
||||
|
||||
console.log('loading done, booting. Built: @@BUILDDATE@@');
|
||||
if(window.deviceID) console.log('Your device ID: ' + window.deviceID);
|
||||
|
BIN
mobile/res/drawable-hdpi/ic_action_error_red.png
Normal file
After Width: | Height: | Size: 300 B |
BIN
mobile/res/drawable-hdpi/ic_action_warning_yellow.png
Normal file
After Width: | Height: | Size: 471 B |
BIN
mobile/res/drawable-mdpi/ic_action_error_red.png
Normal file
After Width: | Height: | Size: 259 B |
BIN
mobile/res/drawable-mdpi/ic_action_warning_yellow.png
Normal file
After Width: | Height: | Size: 374 B |
BIN
mobile/res/drawable-xhdpi/ic_action_error_red.png
Normal file
After Width: | Height: | Size: 385 B |
BIN
mobile/res/drawable-xhdpi/ic_action_warning_yellow.png
Normal file
After Width: | Height: | Size: 632 B |
BIN
mobile/res/drawable-xxhdpi/ic_action_error_red.png
Normal file
After Width: | Height: | Size: 432 B |
BIN
mobile/res/drawable-xxhdpi/ic_action_warning_yellow.png
Normal file
After Width: | Height: | Size: 840 B |
@ -4,20 +4,58 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.cradle.iitc_mobile.IITC_WebView
|
||||
android:id="@+id/iitc_webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageLoading"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/darker_gray"
|
||||
android:paddingBottom="20dp"
|
||||
android:paddingTop="20dp"
|
||||
android:src="@drawable/iitc"
|
||||
tools:ignore="ContentDescription"/>
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.cradle.iitc_mobile.IITC_WebView
|
||||
android:id="@+id/iitc_webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageLoading"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/darker_gray"
|
||||
android:paddingBottom="20dp"
|
||||
android:paddingTop="20dp"
|
||||
android:src="@drawable/iitc"
|
||||
tools:ignore="ContentDescription"/>
|
||||
|
||||
<ListView
|
||||
android:id="@+id/lvDebug"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/viewDebug"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnToggleMapVisibility"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="@android:color/transparent"
|
||||
android:contentDescription="@string/toggle_map"
|
||||
android:onClick="onToggleMapVisibility"
|
||||
android:src="@drawable/ic_action_map"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editCommand"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1"
|
||||
android:imeOptions="actionGo"
|
||||
android:inputType="textNoSuggestions"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- The navigation drawer -->
|
||||
|
||||
|
51
mobile/res/layout/view_log_msg.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:ignore="HardcodedText">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/log_type"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:src="@drawable/ic_action_about"
|
||||
tools:ignore="ContentDescription"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/log_tag"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/log_type"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toRightOf="@+id/log_type"
|
||||
android:gravity="center_vertical|left"
|
||||
android:text="iitcm"
|
||||
android:textAppearance="?android:attr/textAppearance"
|
||||
android:typeface="monospace"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/log_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/log_type"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toRightOf="@+id/log_tag"
|
||||
android:gravity="center_vertical|right"
|
||||
android:text="13:37:42.000"
|
||||
android:textAppearance="?android:attr/textAppearance"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/log_msg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@+id/log_type"
|
||||
android:text="iitcm://script/total-conversion-build.user.js:1337: Some random message"
|
||||
android:typeface="monospace"/>
|
||||
|
||||
</RelativeLayout>
|
@ -1,48 +1,52 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item android:id="@+id/menu_search"
|
||||
android:title="@string/menu_search"
|
||||
android:icon="@drawable/ic_action_search"
|
||||
android:orderInCategory="10"
|
||||
android:showAsAction="ifRoom|collapseActionView"
|
||||
android:actionViewClass="android.widget.SearchView" />
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_search"
|
||||
android:actionViewClass="android.widget.SearchView"
|
||||
android:icon="@drawable/ic_action_search"
|
||||
android:orderInCategory="10"
|
||||
android:showAsAction="ifRoom|collapseActionView"
|
||||
android:title="@string/menu_search"/>
|
||||
<item
|
||||
android:id="@+id/locate"
|
||||
android:icon="@drawable/ic_action_location_found"
|
||||
android:orderInCategory="100"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/locate">
|
||||
</item>
|
||||
android:title="@string/locate"/>
|
||||
<item
|
||||
android:id="@+id/layer_chooser"
|
||||
android:icon="@drawable/ic_action_add_to_queue"
|
||||
android:orderInCategory="105"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/layer_chooser">
|
||||
</item>
|
||||
android:title="@string/layer_chooser"/>
|
||||
<item
|
||||
android:id="@+id/toggle_fullscreen"
|
||||
android:icon="@drawable/ic_action_full_screen"
|
||||
android:orderInCategory="110"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/toggle_fullscreen">
|
||||
</item>
|
||||
android:title="@string/toggle_fullscreen"/>
|
||||
<item
|
||||
android:id="@+id/reload_button"
|
||||
android:icon="@drawable/ic_action_refresh"
|
||||
android:orderInCategory="120"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/reload">
|
||||
</item>
|
||||
android:title="@string/reload"/>
|
||||
<item
|
||||
android:id="@+id/menu_clear_cookies"
|
||||
android:orderInCategory="130"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/menu_clear_cookies">
|
||||
</item>
|
||||
android:title="@string/menu_clear_cookies"/>
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="200"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/action_settings">
|
||||
</item>
|
||||
</menu>
|
||||
android:title="@string/action_settings"/>
|
||||
<item
|
||||
android:id="@+id/menu_debug"
|
||||
android:checkable="true"
|
||||
android:icon="@drawable/ic_action_error"
|
||||
android:orderInCategory="190"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/menu_debug"/>
|
||||
|
||||
</menu>
|
@ -2,6 +2,7 @@
|
||||
<resources>
|
||||
|
||||
<string name="app_name">IITC Mobile</string>
|
||||
<string name="toggle_map">Toggle map visibility</string>
|
||||
<string name="activity_settings">IITC Mobile Settings</string>
|
||||
<string name="activity_plugins">IITC Plugins</string>
|
||||
<string name="activity_share">Share using…</string>
|
||||
@ -140,6 +141,7 @@
|
||||
|
||||
<string name="menu_clear_cookies">Clear Cookies</string>
|
||||
<string name="menu_search">Search</string>
|
||||
<string name="menu_debug">Debug</string>
|
||||
<string name="choose_account_to_login">Choose account to login</string>
|
||||
<string name="login_failed">Login failed.</string>
|
||||
<string name="search_hint">Search Locations</string>
|
||||
|
89
mobile/src/com/cradle/iitc_mobile/IITC_LogAdapter.java
Normal file
@ -0,0 +1,89 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.database.DataSetObserver;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.cradle.iitc_mobile.Log.Message;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class IITC_LogAdapter extends ArrayAdapter<Log.Message> implements Log.Receiver {
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||
|
||||
private int mObservers = 0;
|
||||
private IITC_Mobile mIitc;
|
||||
|
||||
public IITC_LogAdapter(IITC_Mobile iitc) {
|
||||
super(iitc, 0);
|
||||
mIitc = iitc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Message item = getItem(position);
|
||||
View v = mIitc.getLayoutInflater().inflate(R.layout.view_log_msg, parent, false);
|
||||
|
||||
ImageView iv = (ImageView) v.findViewById(R.id.log_type);
|
||||
switch (item.getPriority()) {
|
||||
case Log.ASSERT:
|
||||
case Log.ERROR:
|
||||
iv.setImageResource(R.drawable.ic_action_error_red);
|
||||
break;
|
||||
case Log.WARN:
|
||||
iv.setImageResource(R.drawable.ic_action_warning_yellow);
|
||||
break;
|
||||
default:
|
||||
iv.setImageResource(R.drawable.ic_action_about);
|
||||
}
|
||||
|
||||
TextView tv;
|
||||
|
||||
tv = (TextView) v.findViewById(R.id.log_tag);
|
||||
tv.setText(item.getTag());
|
||||
|
||||
tv = (TextView) v.findViewById(R.id.log_time);
|
||||
tv.setText(FORMATTER.format(item.getDate()));
|
||||
|
||||
tv = (TextView) v.findViewById(R.id.log_msg);
|
||||
tv.setText(item.getMsg());
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterDataSetObserver(DataSetObserver observer) {
|
||||
super.unregisterDataSetObserver(observer);
|
||||
mObservers--;
|
||||
|
||||
if (mObservers < 1) {
|
||||
clear();
|
||||
Log.removeReceiver(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDataSetObserver(DataSetObserver observer) {
|
||||
super.registerDataSetObserver(observer);
|
||||
|
||||
if (mObservers < 1)
|
||||
Log.addReceiver(this);
|
||||
|
||||
mObservers++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Message message) {
|
||||
this.insert(message, 0);
|
||||
}
|
||||
}
|
@ -24,6 +24,9 @@ import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -49,8 +52,15 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
private boolean mDesktopMode = false;
|
||||
private boolean mAdvancedMenu = false;
|
||||
private MenuItem mSearchMenuItem;
|
||||
private View mImageLoading;
|
||||
private ListView mLvDebug;
|
||||
private View mViewDebug;
|
||||
private ImageButton mBtnToggleMap;
|
||||
private EditText mEditCommand;
|
||||
private boolean mDebugging = false;
|
||||
private boolean mReloadNeeded = false;
|
||||
private boolean mIsLoading = true;
|
||||
private boolean mShowMapInDebug = false;
|
||||
private final Stack<String> mDialogStack = new Stack<String>();
|
||||
|
||||
// Used for custom back stack handling
|
||||
@ -73,7 +83,14 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
mImageLoading = findViewById(R.id.imageLoading);
|
||||
mIitcWebView = (IITC_WebView) findViewById(R.id.iitc_webview);
|
||||
mLvDebug = (ListView) findViewById(R.id.lvDebug);
|
||||
mViewDebug = findViewById(R.id.viewDebug);
|
||||
mBtnToggleMap = (ImageButton) findViewById(R.id.btnToggleMapVisibility);
|
||||
mEditCommand = (EditText) findViewById(R.id.editCommand);
|
||||
|
||||
mLvDebug.setAdapter(new IITC_LogAdapter(this));
|
||||
|
||||
// do something if user changed something in the settings
|
||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
@ -425,6 +442,11 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
: R.drawable.ic_action_location_found);
|
||||
break;
|
||||
|
||||
case R.id.menu_debug:
|
||||
item.setVisible(mAdvancedMenu && visible);
|
||||
item.setChecked(mDebugging);
|
||||
break;
|
||||
|
||||
default:
|
||||
item.setVisible(visible);
|
||||
}
|
||||
@ -480,6 +502,13 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
CookieManager cm = CookieManager.getInstance();
|
||||
cm.removeAllCookie();
|
||||
return true;
|
||||
case R.id.menu_debug:
|
||||
mDebugging = !mDebugging;
|
||||
updateViews();
|
||||
invalidateOptionsMenu();
|
||||
|
||||
// TODO remove debugging stuff from JS?
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -494,6 +523,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
mNavigationHelper.reset();
|
||||
mMapSettings.reset();
|
||||
mUserLocation.reset();
|
||||
mIitcWebView.getWebViewClient().reset();
|
||||
mBackStack.clear();
|
||||
// iitc starts on map after reload
|
||||
mCurrentPane = Pane.MAP;
|
||||
@ -585,15 +615,54 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
|
||||
mNavigationHelper.onLoadingStateChanged();
|
||||
|
||||
if (isLoading && !mSharedPrefs.getBoolean("pref_disable_splash", false)) {
|
||||
findViewById(R.id.iitc_webview).setVisibility(View.GONE);
|
||||
findViewById(R.id.imageLoading).setVisibility(View.VISIBLE);
|
||||
updateViews();
|
||||
}
|
||||
|
||||
private void updateViews() {
|
||||
if (!mDebugging) {
|
||||
mViewDebug.setVisibility(View.GONE);
|
||||
mLvDebug.setVisibility(View.GONE);
|
||||
|
||||
if (mIsLoading && !mSharedPrefs.getBoolean("pref_disable_splash", false)) {
|
||||
mIitcWebView.setVisibility(View.GONE);
|
||||
mImageLoading.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mIitcWebView.setVisibility(View.VISIBLE);
|
||||
mImageLoading.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
findViewById(R.id.iitc_webview).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.imageLoading).setVisibility(View.GONE);
|
||||
// if the debug container is invisible (and we are about to show it), select the text box
|
||||
boolean select = mViewDebug.getVisibility() != View.VISIBLE;
|
||||
|
||||
mImageLoading.setVisibility(View.GONE); // never show splash screen while debugging
|
||||
mViewDebug.setVisibility(View.VISIBLE);
|
||||
|
||||
if (select) {
|
||||
mEditCommand.requestFocus();
|
||||
mEditCommand.selectAll();
|
||||
}
|
||||
|
||||
if (mShowMapInDebug) {
|
||||
mBtnToggleMap.setImageResource(R.drawable.ic_action_view_as_list);
|
||||
mIitcWebView.setVisibility(View.VISIBLE);
|
||||
mLvDebug.setVisibility(View.GONE);
|
||||
} else {
|
||||
mBtnToggleMap.setImageResource(R.drawable.ic_action_map);
|
||||
mIitcWebView.setVisibility(View.GONE);
|
||||
mLvDebug.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* onClick handler for R.id.btnToggleMapVisibility, assigned in activity_main.xml
|
||||
*/
|
||||
public void onToggleMapVisibility(View v)
|
||||
{
|
||||
mShowMapInDebug = !mShowMapInDebug;
|
||||
updateViews();
|
||||
}
|
||||
|
||||
private void deleteUpdateFile() {
|
||||
File file = new File(getExternalFilesDir(null).toString() + "/iitcUpdate.apk");
|
||||
if (file != null) file.delete();
|
||||
|
@ -336,16 +336,11 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
||||
add(Pane.COMPACT);
|
||||
add(Pane.PUBLIC);
|
||||
add(Pane.FACTION);
|
||||
|
||||
if (mPrefs.getBoolean("pref_advanced_menu", false)) {
|
||||
add(Pane.DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Pane {
|
||||
public static final Pane COMPACT = new Pane("compact", "Compact", R.drawable.ic_action_view_as_list_compact);
|
||||
public static final Pane DEBUG = new Pane("debug", "Debug", R.drawable.ic_action_error);
|
||||
public static final Pane FACTION = new Pane("faction", "Faction", R.drawable.ic_action_cc_bcc);
|
||||
public static final Pane FULL = new Pane("full", "Full", R.drawable.ic_action_view_as_list);
|
||||
public static final Pane INFO = new Pane("info", "Info", R.drawable.ic_action_about);
|
||||
|
@ -15,14 +15,14 @@ public class IITC_WebChromeClient extends WebChromeClient {
|
||||
public IITC_WebChromeClient(IITC_Mobile iitcm) {
|
||||
mIitcm = iitcm;
|
||||
}
|
||||
|
||||
/**
|
||||
* our webchromeclient should share geolocation with the iitc script
|
||||
*
|
||||
* allow access by default
|
||||
*/
|
||||
@Override
|
||||
public void onGeolocationPermissionsShowPrompt(String origin,
|
||||
GeolocationPermissions.Callback callback) {
|
||||
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
||||
callback.invoke(origin, true, false);
|
||||
}
|
||||
|
||||
@ -42,10 +42,14 @@ public class IITC_WebChromeClient extends WebChromeClient {
|
||||
* remove splash screen if any JS error occurs
|
||||
*/
|
||||
@Override
|
||||
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
|
||||
if (consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR) {
|
||||
public boolean onConsoleMessage(ConsoleMessage message) {
|
||||
if (message.messageLevel() == ConsoleMessage.MessageLevel.ERROR) {
|
||||
mIitcm.setLoadingState(false);
|
||||
}
|
||||
return super.onConsoleMessage(consoleMessage);
|
||||
|
||||
if (Log.log(message))
|
||||
return true; // message was handled
|
||||
|
||||
return super.onConsoleMessage(message);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import android.net.Uri;
|
||||
import android.net.http.SslError;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.webkit.SslErrorHandler;
|
||||
import android.webkit.WebResourceResponse;
|
||||
@ -86,7 +87,7 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
scripts.add("script/user-location.user.js");
|
||||
}
|
||||
|
||||
String js = "(function(){['" + join(scripts, "','") + "'].forEach(function(src) {" +
|
||||
String js = "(function(){['" + TextUtils.join("','", scripts) + "'].forEach(function(src) {" +
|
||||
"var script = document.createElement('script');script.src = 'iitcm://'+src;" +
|
||||
"(document.body || document.head || document.documentElement).appendChild(script);" +
|
||||
"});})();";
|
||||
@ -94,64 +95,16 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
view.loadJS(js);
|
||||
}
|
||||
|
||||
static public String join(List<String> list, String conjunction)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (String item : list)
|
||||
{
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
sb.append(conjunction);
|
||||
sb.append(item);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* this method is called automatically when the Google login form is opened.
|
||||
*/
|
||||
@Override
|
||||
public void onReceivedLoginRequest(WebView view, String realm, String account, String args) {
|
||||
Log.d("iitcm", "Login requested: " + realm + " " + account + " " + args);
|
||||
mIitcInjected = false;
|
||||
// Log.d("iitcm", "Login requested: " + realm + " " + account + " " + args);
|
||||
// ((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args);
|
||||
}
|
||||
|
||||
// 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 = mIitc.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() : "";
|
||||
// }
|
||||
// return src;
|
||||
// }
|
||||
|
||||
// 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
|
||||
@ -220,4 +173,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
mIitcInjected = false;
|
||||
}
|
||||
}
|
||||
|
220
mobile/src/com/cradle/iitc_mobile/Log.java
Normal file
@ -0,0 +1,220 @@
|
||||
package com.cradle.iitc_mobile;
|
||||
|
||||
import android.webkit.ConsoleMessage;
|
||||
import android.webkit.ConsoleMessage.MessageLevel;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public final class Log {
|
||||
private static final HashMap<ConsoleMessage.MessageLevel, Integer> CONSOLE_MAPPING;
|
||||
private static final List<Receiver> RECEIVERS = new LinkedList<Log.Receiver>();
|
||||
|
||||
public static final String CONSOLE_TAG = "iitcm-console";
|
||||
public static final String DEFAULT_TAG = "iitcm";
|
||||
|
||||
public static final int ASSERT = android.util.Log.ASSERT;
|
||||
public static final int DEBUG = android.util.Log.DEBUG;
|
||||
public static final int ERROR = android.util.Log.ERROR;
|
||||
public static final int INFO = android.util.Log.INFO;
|
||||
public static final int VERBOSE = android.util.Log.VERBOSE;
|
||||
public static final int WARN = android.util.Log.WARN;
|
||||
|
||||
static {
|
||||
CONSOLE_MAPPING = new HashMap<ConsoleMessage.MessageLevel, Integer>();
|
||||
CONSOLE_MAPPING.put(MessageLevel.TIP, android.util.Log.VERBOSE);
|
||||
CONSOLE_MAPPING.put(MessageLevel.LOG, android.util.Log.INFO);
|
||||
CONSOLE_MAPPING.put(MessageLevel.WARNING, android.util.Log.WARN);
|
||||
CONSOLE_MAPPING.put(MessageLevel.ERROR, android.util.Log.ERROR);
|
||||
CONSOLE_MAPPING.put(MessageLevel.DEBUG, android.util.Log.DEBUG);
|
||||
};
|
||||
|
||||
private static synchronized void log(int priority, String tag, String msg, Throwable tr) {
|
||||
Date now = new Date();
|
||||
|
||||
Message message = new Message(now, priority, tag, msg, tr);
|
||||
for (Receiver receiver : RECEIVERS) {
|
||||
receiver.handle(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void d(String msg) {
|
||||
d(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void d(String tag, String msg) {
|
||||
log(android.util.Log.DEBUG, tag, msg, null);
|
||||
android.util.Log.d(tag, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void d(String tag, String msg, Throwable tr) {
|
||||
log(android.util.Log.DEBUG, tag, msg, tr);
|
||||
android.util.Log.d(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void d(String msg, Throwable tr) {
|
||||
d(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
public static void e(String msg) {
|
||||
e(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void e(String tag, String msg) {
|
||||
log(android.util.Log.ERROR, tag, msg, null);
|
||||
android.util.Log.e(tag, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void e(String tag, String msg, Throwable tr) {
|
||||
log(android.util.Log.ERROR, tag, msg, tr);
|
||||
android.util.Log.e(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void e(String msg, Throwable tr) {
|
||||
e(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
public static void i(String msg) {
|
||||
i(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void i(String tag, String msg) {
|
||||
log(android.util.Log.INFO, tag, msg, null);
|
||||
android.util.Log.i(tag, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void i(String tag, String msg, Throwable tr) {
|
||||
log(android.util.Log.INFO, tag, msg, tr);
|
||||
android.util.Log.i(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void i(String msg, Throwable tr) {
|
||||
i(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
public static boolean log(ConsoleMessage message) {
|
||||
final String msg = message.sourceId() + ":" + message.lineNumber() + ": " + message.message();
|
||||
final Integer priority = CONSOLE_MAPPING.get(message.messageLevel());
|
||||
|
||||
if (priority != null) {
|
||||
log(priority, CONSOLE_TAG, msg, null);
|
||||
android.util.Log.println(priority, CONSOLE_TAG, msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.w(CONSOLE_TAG, "Warning: unknown message level in Logger.log(ConsoleMessage message): "
|
||||
+ message.messageLevel().ordinal() + "/" + message.messageLevel().name());
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int println(int priority, String msg) {
|
||||
return println(priority, DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static int println(int priority, String tag, String msg) {
|
||||
log(priority, tag, msg, null);
|
||||
return android.util.Log.println(priority, tag, msg);
|
||||
}
|
||||
|
||||
public static void v(String msg) {
|
||||
v(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void v(String tag, String msg) {
|
||||
log(android.util.Log.VERBOSE, tag, msg, null);
|
||||
android.util.Log.v(tag, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void v(String tag, String msg, Throwable tr) {
|
||||
log(android.util.Log.VERBOSE, tag, msg, tr);
|
||||
android.util.Log.v(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void v(String msg, Throwable tr) {
|
||||
v(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
public static void w(String msg) {
|
||||
w(DEFAULT_TAG, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void w(String tag, String msg) {
|
||||
log(android.util.Log.WARN, tag, msg, null);
|
||||
android.util.Log.w(tag, msg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void w(String tag, String msg, Throwable tr) {
|
||||
log(android.util.Log.WARN, tag, msg, tr);
|
||||
android.util.Log.w(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void w(String msg, Throwable tr) {
|
||||
w(DEFAULT_TAG, msg, tr);
|
||||
}
|
||||
|
||||
private Log() {
|
||||
// prevent instantiation
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static class Message {
|
||||
private Date mDate;
|
||||
private String mMsg;
|
||||
private int mPriority;
|
||||
private String mTag;
|
||||
private Throwable mTr;
|
||||
|
||||
private Message(Date date, int priority, String tag, String msg, Throwable tr) {
|
||||
mDate = date;
|
||||
mPriority = priority;
|
||||
mTag = tag;
|
||||
mMsg = msg;
|
||||
mTr = tr;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return this.mDate;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return this.mMsg;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return this.mPriority;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return this.mTag;
|
||||
}
|
||||
|
||||
public Throwable getTr() {
|
||||
return this.mTr;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface Receiver {
|
||||
void handle(Message message);
|
||||
}
|
||||
|
||||
public static void removeReceiver(Log.Receiver receiver) {
|
||||
RECEIVERS.remove(receiver);
|
||||
}
|
||||
|
||||
public static void addReceiver(Log.Receiver receiver) {
|
||||
RECEIVERS.add(receiver);
|
||||
}
|
||||
}
|