Use new log system
This commit is contained in:
		| @@ -83,7 +83,7 @@ public class IITC_FileManager { | ||||
|             try { | ||||
|                 return new FileInputStream(file); | ||||
|             } catch (FileNotFoundException e) { | ||||
|                 e.printStackTrace(); | ||||
|                 Log.w(e); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -96,14 +96,14 @@ public class IITC_FileManager { | ||||
|                     URL url = new URL(context, filename); | ||||
|                     return url.openStream(); | ||||
|                 } catch (IOException e) { | ||||
|                     e.printStackTrace(); | ||||
|                     Log.w(e); | ||||
|                 } | ||||
|             } else { | ||||
|                 File file = new File(source + File.separatorChar + filename); | ||||
|                 try { | ||||
|                     return new FileInputStream(file); | ||||
|                 } catch (FileNotFoundException e) { | ||||
|                     e.printStackTrace(); | ||||
|                     Log.w(e); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| @@ -117,7 +117,7 @@ public class IITC_FileManager { | ||||
|         try { | ||||
|             stream = getAssetFile(uri.getPath().substring(1)); | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|             return EMPTY; | ||||
|         } | ||||
|  | ||||
| @@ -140,7 +140,7 @@ public class IITC_FileManager { | ||||
|         try { | ||||
|             stream = new FileInputStream(new File(uri.getPath())); | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|             return EMPTY; | ||||
|         } | ||||
|  | ||||
| @@ -173,7 +173,7 @@ public class IITC_FileManager { | ||||
|                 os.write(buffer, 0, read); | ||||
|             } | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|             return ""; | ||||
|         } | ||||
|         return os.toString(); | ||||
|   | ||||
| @@ -68,7 +68,7 @@ public class IITC_JSInterface { | ||||
|                     .getPackageInfo(mIitc.getPackageName(), 0); | ||||
|             versionCode = pInfo.versionCode; | ||||
|         } catch (PackageManager.NameNotFoundException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } | ||||
|         return versionCode; | ||||
|     } | ||||
| @@ -81,7 +81,7 @@ public class IITC_JSInterface { | ||||
|             PackageInfo info = pm.getPackageInfo(mIitc.getPackageName(), 0); | ||||
|             buildVersion = info.versionName; | ||||
|         } catch (PackageManager.NameNotFoundException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } | ||||
|         return buildVersion; | ||||
|     } | ||||
|   | ||||
| @@ -10,6 +10,8 @@ import android.widget.TextView; | ||||
|  | ||||
| import com.cradle.iitc_mobile.Log.Message; | ||||
|  | ||||
| import java.io.PrintWriter; | ||||
| import java.io.StringWriter; | ||||
| import java.text.SimpleDateFormat; | ||||
|  | ||||
| public class IITC_LogAdapter extends ArrayAdapter<Log.Message> implements Log.Receiver { | ||||
| @@ -50,8 +52,20 @@ public class IITC_LogAdapter extends ArrayAdapter<Log.Message> implements Log.Re | ||||
|         tv = (TextView) v.findViewById(R.id.log_time); | ||||
|         tv.setText(FORMATTER.format(item.getDate())); | ||||
|  | ||||
|         String msg = item.getMsg(); | ||||
|         if (item.getTr() != null) { | ||||
|             StringWriter sw = new StringWriter(); | ||||
|             PrintWriter pw = new PrintWriter(sw); | ||||
|             item.getTr().printStackTrace(pw); | ||||
|  | ||||
|             if (msg == null || msg.isEmpty()) | ||||
|                 msg = sw.toString(); | ||||
|             else | ||||
|                 msg += "\n" + sw.toString(); | ||||
|         } | ||||
|  | ||||
|         tv = (TextView) v.findViewById(R.id.log_msg); | ||||
|         tv.setText(item.getMsg()); | ||||
|         tv.setText(msg); | ||||
|  | ||||
|         return v; | ||||
|     } | ||||
|   | ||||
| @@ -231,7 +231,7 @@ public class IITC_MapSettings implements OnItemSelectedListener, OnItemClickList | ||||
|             base_layers = new JSONArray(base_layer); | ||||
|             overlay_layers = new JSONArray(overlay_layer); | ||||
|         } catch (JSONException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
| @@ -255,7 +255,7 @@ public class IITC_MapSettings implements OnItemSelectedListener, OnItemClickList | ||||
|  | ||||
|                 mBaseLayers.add(layer); | ||||
|             } catch (JSONException e) { | ||||
|                 e.printStackTrace(); | ||||
|                 Log.w(e); | ||||
|             } | ||||
|         } | ||||
|         mBaseLayers.notifyDataSetChanged(); | ||||
| @@ -274,7 +274,7 @@ public class IITC_MapSettings implements OnItemSelectedListener, OnItemClickList | ||||
|  | ||||
|                 mOverlayLayers.add(layer); | ||||
|             } catch (JSONException e) { | ||||
|                 e.printStackTrace(); | ||||
|                 Log.w(e); | ||||
|             } | ||||
|         } | ||||
|         mOverlayLayers.notifyDataSetChanged(); | ||||
|   | ||||
| @@ -205,7 +205,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis | ||||
|                     handleGeoUri(uri); | ||||
|                     return; | ||||
|                 } catch (URISyntaxException e) { | ||||
|                     e.printStackTrace(); | ||||
|                     Log.w(e); | ||||
|                     new AlertDialog.Builder(this) | ||||
|                             .setTitle(R.string.intent_error) | ||||
|                             .setMessage(e.getReason()) | ||||
| @@ -513,7 +513,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis | ||||
|                 try { | ||||
|                     intent.putExtra("iitc_version", mFileManager.getIITCVersion()); | ||||
|                 } catch (IOException e) { | ||||
|                     e.printStackTrace(); | ||||
|                     Log.w(e); | ||||
|                     return true; | ||||
|                 } | ||||
|                 startActivity(intent); | ||||
| @@ -680,7 +680,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis | ||||
|         try { | ||||
|             obj.put("code", code); | ||||
|         } catch (JSONException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -120,7 +120,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { | ||||
|             asset_array = am.list("plugins"); | ||||
|         } catch (IOException e) { | ||||
|             // TODO Auto-generated catch block | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } | ||||
|         if (asset_array == null) { | ||||
|             asset_array = new String[0]; | ||||
| @@ -163,11 +163,9 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { | ||||
|             Scanner s = null; | ||||
|             String src = ""; | ||||
|             try { | ||||
|                 s = new Scanner(getAssets().open("plugins/" + asset)) | ||||
|                         .useDelimiter("\\A"); | ||||
|             } catch (IOException e2) { | ||||
|                 // TODO Auto-generated catch block | ||||
|                 e2.printStackTrace(); | ||||
|                 s = new Scanner(getAssets().open("plugins/" + asset)).useDelimiter("\\A"); | ||||
|             } catch (IOException e) { | ||||
|                 Log.w(e); | ||||
|             } | ||||
|             if (s != null) { | ||||
|                 src = s.hasNext() ? s.next() : ""; | ||||
| @@ -184,7 +182,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { | ||||
|             try { | ||||
|                 s = new Scanner(file).useDelimiter("\\A"); | ||||
|             } catch (FileNotFoundException e) { | ||||
|                 e.printStackTrace(); | ||||
|                 Log.w(e); | ||||
|                 Log.d("failed to parse file " + file); | ||||
|             } | ||||
|             if (s != null) { | ||||
| @@ -200,7 +198,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { | ||||
|  | ||||
|         // parse plugin name, description and category | ||||
|         // we need default versions here otherwise iitcm may crash | ||||
|         HashMap<String,String> info = IITC_FileManager.getScriptInfo(src); | ||||
|         HashMap<String, String> info = IITC_FileManager.getScriptInfo(src); | ||||
|         String plugin_name = info.get("name"); | ||||
|         String plugin_cat = info.get("category"); | ||||
|         String plugin_desc = info.get("description"); | ||||
|   | ||||
| @@ -64,13 +64,13 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener | ||||
|                 mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); | ||||
|             } catch (IllegalArgumentException e) { | ||||
|                 // if the given provider doesn't exist | ||||
|                 e.printStackTrace(); | ||||
|                 Log.w(e); | ||||
|             } | ||||
|             try { | ||||
|                 mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); | ||||
|             } catch (IllegalArgumentException e) { | ||||
|                 // if the given provider doesn't exist | ||||
|                 e.printStackTrace(); | ||||
|                 Log.w(e); | ||||
|             } | ||||
|             mLocationRegistered = true; | ||||
|         } | ||||
|   | ||||
| @@ -122,7 +122,7 @@ public class IITC_WebViewClient extends WebViewClient { | ||||
|             try { | ||||
|                 return mTileManager.getTile(url); | ||||
|             } catch (Exception e) { | ||||
|                 e.printStackTrace(); | ||||
|                 Log.w(e); | ||||
|                 return super.shouldInterceptRequest(view, url); | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -46,6 +46,10 @@ public final class Log { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static void addReceiver(Log.Receiver receiver) { | ||||
|         RECEIVERS.add(receiver); | ||||
|     } | ||||
|  | ||||
|     public static void d(String msg) { | ||||
|         d(DEFAULT_TAG, msg); | ||||
|     } | ||||
| @@ -72,6 +76,10 @@ public final class Log { | ||||
|         d(DEFAULT_TAG, msg, tr); | ||||
|     } | ||||
|  | ||||
|     public static void d(Throwable tr) { | ||||
|         d("Unexpected " + tr, tr); | ||||
|     } | ||||
|  | ||||
|     public static void e(String msg) { | ||||
|         e(DEFAULT_TAG, msg); | ||||
|     } | ||||
| @@ -98,6 +106,10 @@ public final class Log { | ||||
|         e(DEFAULT_TAG, msg, tr); | ||||
|     } | ||||
|  | ||||
|     public static void e(Throwable tr) { | ||||
|         e("Unexpected " + tr, tr); | ||||
|     } | ||||
|  | ||||
|     public static void i(String msg) { | ||||
|         i(DEFAULT_TAG, msg); | ||||
|     } | ||||
| @@ -124,6 +136,10 @@ public final class Log { | ||||
|         i(DEFAULT_TAG, msg, tr); | ||||
|     } | ||||
|  | ||||
|     public static void i(Throwable tr) { | ||||
|         i("Unexpected " + tr, tr); | ||||
|     } | ||||
|  | ||||
|     public static boolean log(ConsoleMessage message) { | ||||
|         String msg = message.sourceId(); | ||||
|         Matcher matcher = URL_PATTERN.matcher(msg); | ||||
| @@ -160,6 +176,10 @@ public final class Log { | ||||
|         return android.util.Log.println(priority, tag, msg); | ||||
|     } | ||||
|  | ||||
|     public static void removeReceiver(Log.Receiver receiver) { | ||||
|         RECEIVERS.remove(receiver); | ||||
|     } | ||||
|  | ||||
|     public static void v(String msg) { | ||||
|         v(DEFAULT_TAG, msg); | ||||
|     } | ||||
| @@ -186,6 +206,10 @@ public final class Log { | ||||
|         v(DEFAULT_TAG, msg, tr); | ||||
|     } | ||||
|  | ||||
|     public static void v(Throwable tr) { | ||||
|         v("Unexpected " + tr, tr); | ||||
|     } | ||||
|  | ||||
|     public static void w(String msg) { | ||||
|         w(DEFAULT_TAG, msg); | ||||
|     } | ||||
| @@ -212,6 +236,10 @@ public final class Log { | ||||
|         w(DEFAULT_TAG, msg, tr); | ||||
|     } | ||||
|  | ||||
|     public static void w(Throwable tr) { | ||||
|         w("Unexpected " + tr, tr); | ||||
|     } | ||||
|  | ||||
|     private Log() { | ||||
|         // prevent instantiation | ||||
|         throw new UnsupportedOperationException(); | ||||
| @@ -256,12 +284,4 @@ public final class Log { | ||||
|     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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -51,7 +51,7 @@ public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> { | ||||
|                 } | ||||
|             } | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|   | ||||
| @@ -35,16 +35,12 @@ public class DownloadTile extends AsyncTask<String, Void, Boolean> { | ||||
|             Log.d("writing to file: " + file.toString()); | ||||
|             writeTileToFile(is, file); | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|             return false; | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|             return false; | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     private void writeTileToFile(InputStream inStream, File file) throws Exception { | ||||
|     private void writeTileToFile(InputStream inStream, File file) throws IOException { | ||||
|         file.getParentFile().mkdirs(); | ||||
|         FileOutputStream outStream = new FileOutputStream(file); | ||||
|         int bufferSize = 1024; | ||||
| @@ -53,7 +49,7 @@ public class DownloadTile extends AsyncTask<String, Void, Boolean> { | ||||
|         while ((len = inStream.read(buffer)) != -1) { | ||||
|             outStream.write(buffer, 0, len); | ||||
|         } | ||||
|         if(outStream!=null) outStream.close(); | ||||
|         if (outStream != null) | ||||
|             outStream.close(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,8 @@ package com.cradle.iitc_mobile.async; | ||||
|  | ||||
| import android.os.AsyncTask; | ||||
|  | ||||
| import com.cradle.iitc_mobile.Log; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.net.URL; | ||||
| import java.util.Scanner; | ||||
| @@ -21,7 +23,7 @@ public class UrlContentToString extends AsyncTask<URL, Integer, String> { | ||||
|             js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A") | ||||
|                     .next(); | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } | ||||
|         return js; | ||||
|     } | ||||
|   | ||||
| @@ -18,6 +18,7 @@ import android.widget.FrameLayout; | ||||
| import android.widget.LinearLayout; | ||||
|  | ||||
| import com.cradle.iitc_mobile.IITC_AboutDialogPreference; | ||||
| import com.cradle.iitc_mobile.Log; | ||||
| import com.cradle.iitc_mobile.R; | ||||
|  | ||||
| public class MainSettings extends PreferenceFragment { | ||||
| @@ -37,7 +38,7 @@ public class MainSettings extends PreferenceFragment { | ||||
|             PackageInfo info = pm.getPackageInfo(getActivity().getPackageName(), 0); | ||||
|             buildVersion = info.versionName; | ||||
|         } catch (NameNotFoundException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } | ||||
|  | ||||
|         IITC_AboutDialogPreference pref_about = (IITC_AboutDialogPreference) findPreference("pref_about"); | ||||
|   | ||||
| @@ -4,6 +4,8 @@ import android.app.Activity; | ||||
| import android.content.pm.PackageManager; | ||||
| import android.content.pm.ResolveInfo; | ||||
|  | ||||
| import com.cradle.iitc_mobile.Log; | ||||
|  | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.io.FileOutputStream; | ||||
| @@ -106,15 +108,15 @@ public class IntentComparator implements Comparator<ResolveInfo> { | ||||
|         } catch (FileNotFoundException e) { | ||||
|             // Do nothing | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } catch (ClassNotFoundException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } finally { | ||||
|             if (objectIn != null) { | ||||
|                 try { | ||||
|                     objectIn.close(); | ||||
|                 } catch (IOException e) { | ||||
|                     e.printStackTrace(); | ||||
|                     Log.w(e); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| @@ -173,13 +175,13 @@ public class IntentComparator implements Comparator<ResolveInfo> { | ||||
|             objectOut.writeObject(mIntentMap); | ||||
|             fileOut.getFD().sync(); | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } finally { | ||||
|             if (objectOut != null) { | ||||
|                 try { | ||||
|                     objectOut.close(); | ||||
|                 } catch (IOException e) { | ||||
|                     e.printStackTrace(); | ||||
|                     Log.w(e); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -12,6 +12,7 @@ import android.support.v4.app.NavUtils; | ||||
| import android.support.v4.view.ViewPager; | ||||
| import android.view.MenuItem; | ||||
|  | ||||
| import com.cradle.iitc_mobile.Log; | ||||
| import com.cradle.iitc_mobile.R; | ||||
|  | ||||
| import java.io.UnsupportedEncodingException; | ||||
| @@ -74,7 +75,7 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList | ||||
|                     + "%20(" + URLEncoder.encode(mTitle, "UTF-8") + ")&z=" + mZoom; | ||||
|         } catch (UnsupportedEncodingException e) { | ||||
|             gMapsUri = "http://maps.google.com/?ll=" + mLl + "&z=" + mZoom; | ||||
|             e.printStackTrace(); | ||||
|             Log.w(e); | ||||
|         } | ||||
|         Intent gMapsIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(gMapsUri)); | ||||
|         intents.add(gMapsIntent); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user