List of usage examples for android.util Log getStackTraceString
public static String getStackTraceString(Throwable tr)
From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java
@Nullable private static String buildBrokenAppFilter(Context context, File folder) { try {//from w w w .j a va 2s.c om AssetManager asset = context.getAssets(); InputStream stream = asset.open("appfilter.xml"); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse(stream); NodeList list = doc.getElementsByTagName("item"); File fileDir = new File(folder.toString() + "/" + "broken_appfilter.xml"); Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8")); boolean first = true; for (int i = 0; i < list.getLength(); i++) { Node nNode = list.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; if (first) { first = false; out.append("<!-- BROKEN APPFILTER -->"); out.append("\n\n\n"); } int drawable = context.getResources().getIdentifier(eElement.getAttribute("drawable"), "drawable", context.getPackageName()); if (drawable == 0) { out.append("Activity : ").append( eElement.getAttribute("component").replace("ComponentInfo{", "").replace("}", "")); out.append("\n"); out.append("Drawable : ").append(eElement.getAttribute("drawable")); out.append("\n"); out.append("Reason : Drawable Not Found!"); out.append("\n\n"); } } } out.flush(); out.close(); return fileDir.toString(); } catch (Exception | OutOfMemoryError e) { Log.d(Tag.LOG_TAG, Log.getStackTraceString(e)); } return null; }
From source file:com.kth.common.utils.etc.LogUtil.java
/** * INFO ?.// ww w . java 2 s.com * * @param clazz ?? Class. * @param tr Throwable. */ public static void i(final Class<?> clazz, final Throwable tr) { if (LogUtil.isInfoEnabled()) { Log.println(Log.INFO, TAG, LogUtil.getClassLineNumber(clazz) + " - " + Log.getStackTraceString(tr)); // ?? ? ?. if (LogUtil.isFileLogEnabled()) { write(Log.INFO, LogUtil.getClassLineNumber(clazz), tr); } } }
From source file:io.teak.sdk.Request.java
@Override public void run() { HttpsURLConnection connection = null; SecretKeySpec keySpec = new SecretKeySpec(this.session.appConfiguration.apiKey.getBytes(), "HmacSHA256"); String requestBody;/*from w ww .jav a 2 s . co m*/ String hostnameForEndpoint = this.hostname; if (hostnameForEndpoint == null) { hostnameForEndpoint = this.session.remoteConfiguration.getHostnameForEndpoint(this.endpoint); } try { ArrayList<String> payloadKeys = new ArrayList<>(this.payload.keySet()); Collections.sort(payloadKeys); StringBuilder builder = new StringBuilder(); for (String key : payloadKeys) { Object value = this.payload.get(key); if (value != null) { String valueString; if (value instanceof Map) { valueString = new JSONObject((Map) value).toString(); } else if (value instanceof Array) { valueString = new JSONArray(Collections.singletonList(value)).toString(); } else if (value instanceof Collection) { valueString = new JSONArray((Collection) value).toString(); } else { valueString = value.toString(); } builder.append(key).append("=").append(valueString).append("&"); } else { Log.e(LOG_TAG, "Value for key: " + key + " is null."); } } builder.deleteCharAt(builder.length() - 1); String stringToSign = "POST\n" + hostnameForEndpoint + "\n" + this.endpoint + "\n" + builder.toString(); Mac mac = Mac.getInstance("HmacSHA256"); mac.init(keySpec); byte[] result = mac.doFinal(stringToSign.getBytes()); builder = new StringBuilder(); for (String key : payloadKeys) { Object value = this.payload.get(key); String valueString; if (value instanceof Map) { valueString = new JSONObject((Map) value).toString(); } else if (value instanceof Array) { valueString = new JSONArray(Collections.singletonList(value)).toString(); } else if (value instanceof Collection) { valueString = new JSONArray((Collection) value).toString(); } else { valueString = value.toString(); } builder.append(key).append("=").append(URLEncoder.encode(valueString, "UTF-8")).append("&"); } builder.append("sig=") .append(URLEncoder.encode(Base64.encodeToString(result, Base64.NO_WRAP), "UTF-8")); requestBody = builder.toString(); } catch (Exception e) { Log.e(LOG_TAG, "Error signing payload: " + Log.getStackTraceString(e)); return; } try { if (Teak.isDebug) { Log.d(LOG_TAG, "Submitting request to '" + this.endpoint + "': " + new JSONObject(this.payload).toString(2)); } URL url = new URL("https://" + hostnameForEndpoint + this.endpoint); connection = (HttpsURLConnection) url.openConnection(); connection.setRequestProperty("Accept-Charset", "UTF-8"); connection.setUseCaches(false); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", "" + Integer.toString(requestBody.getBytes().length)); // Send request DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(requestBody); wr.flush(); wr.close(); // Get Response InputStream is; if (connection.getResponseCode() < 400) { is = connection.getInputStream(); } else { is = connection.getErrorStream(); } BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuilder response = new StringBuilder(); while ((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); if (Teak.isDebug) { String responseText = response.toString(); try { responseText = new JSONObject(response.toString()).toString(2); } catch (Exception ignored) { } Log.d(LOG_TAG, "Reply from '" + this.endpoint + "': " + responseText); } // For extending classes done(connection.getResponseCode(), response.toString()); } catch (Exception e) { Log.e(LOG_TAG, Log.getStackTraceString(e)); } finally { if (connection != null) { connection.disconnect(); } } }
From source file:com.dm.material.dashboard.candybar.fragments.IconsSearchFragment.java
private void filterSearch(String query) { try {/* w ww.jav a 2s . co m*/ mAdapter.search(query); if (mAdapter.getItemCount() == 0) { String text = String.format(getActivity().getResources().getString(R.string.search_noresult), query); mSearchResult.setText(text); mSearchResult.setVisibility(View.VISIBLE); } else mSearchResult.setVisibility(View.GONE); } catch (Exception e) { LogUtil.e(Log.getStackTraceString(e)); } }
From source file:org.maikelwever.droidpile.backend.ApiConnecter.java
public String getCachedRecordForQuery(String query) { String jsonToReturn = ""; try {//from w ww.j a va 2 s .c om List<DataCache> currentlyCached = new Select().from(DataCache.class).where("key = ?", query).execute(); for (DataCache record : currentlyCached) { long diff = new Date().getTime() - record.retrievedOn; long diffMinutes = diff / (60 * 1000) % 60; long diffHours = diff / (60 * 60 * 1000) % 24; long diffDays = diff / (24 * 60 * 60 * 1000); if (diffHours > 0 || diffDays > 0 || diffMinutes > CACHE_TIMEOUT) { record.delete(); } else { jsonToReturn = record.data; Log.d("droidpile", String.format("Cache hit for query: %s\nAge is %d hours %d minutes", query, diffHours, diffMinutes)); break; } } } catch (Exception e) { Log.d("droidpile", Log.getStackTraceString(e)); } return jsonToReturn; }
From source file:net.olejon.mdapp.DiseasesAndTreatmentsSearchAdapter.java
@Override public void onBindViewHolder(DiseasesAndTreatmentsSearchViewHolder viewHolder, final int i) { try {//w w w . j a v a 2 s. c om final JSONObject result = mResults.getJSONObject(i); final String type = result.getString("type"); final String title = result.getString("title"); final String text = result.getString("text"); final String uri = result.getString("uri"); viewHolder.title.setText(title); switch (type) { case "pubmed": { viewHolder.icon.setImageResource(R.drawable.pubmed); viewHolder.text.setText(text); break; } case "webofscience": { viewHolder.icon.setImageResource(R.drawable.webofscience); viewHolder.text.setText(text); break; } case "medlineplus": { viewHolder.icon.setImageResource(R.drawable.medlineplus); viewHolder.text.setText(text); break; } case "wikipedia": { viewHolder.icon.setImageResource(R.drawable.wikipedia); viewHolder.text.setText(text); break; } case "uptodate": { viewHolder.icon.setImageResource(R.drawable.uptodate); viewHolder.text.setText(text); break; } case "bmj": { viewHolder.icon.setImageResource(R.drawable.bmj); viewHolder.text.setText(text); break; } case "nhi": { viewHolder.icon.setImageResource(R.drawable.nhi); viewHolder.text.setText(text); break; } case "sml": { viewHolder.icon.setImageResource(R.drawable.sml); viewHolder.text.setText(text); break; } case "forskning": { viewHolder.icon.setImageResource(R.drawable.forskning); viewHolder.text.setText(text); break; } case "helsebiblioteket": { viewHolder.icon.setImageResource(R.drawable.helsebiblioteket); viewHolder.text.setText(text); break; } case "tidsskriftet": { viewHolder.icon.setImageResource(R.drawable.tidsskriftet); viewHolder.text.setText(text); break; } case "oncolex": { viewHolder.icon.setImageResource(R.drawable.oncolex); viewHolder.text.setText(text); break; } case "brukerhandboken": { viewHolder.icon.setImageResource(R.drawable.brukerhandboken); viewHolder.text.setText(text); break; } case "helsenorge": { viewHolder.icon.setImageResource(R.drawable.helsenorge); viewHolder.text.setText(text); break; } } viewHolder.card.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(mContext, DiseasesAndTreatmentsSearchWebViewActivity.class); intent.putExtra("title", title); intent.putExtra("uri", uri); intent.putExtra("search", mSearch); mContext.startActivity(intent); } }); animateView(viewHolder.card, i); } catch (Exception e) { Log.e("DiseasesAndTreatments", Log.getStackTraceString(e)); } }
From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java
public static void resetSpanCount(@NonNull RecyclerView recyclerView, @IntegerRes int id) { try {//from ww w. ja v a2s . com Context context = ContextHelper.getBaseContext(recyclerView); if (recyclerView.getLayoutManager() instanceof GridLayoutManager) { GridLayoutManager manager = (GridLayoutManager) recyclerView.getLayoutManager(); manager.setSpanCount(context.getResources().getInteger(id)); manager.requestLayout(); } else if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager manager = (StaggeredGridLayoutManager) recyclerView.getLayoutManager(); manager.setSpanCount(context.getResources().getInteger(id)); manager.requestLayout(); } } catch (Exception e) { LogUtil.e(Log.getStackTraceString(e)); } }
From source file:net.olejon.mdapp.ManufacturerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: { NavUtils.navigateUpFromSameTask(this); return true; }/*w ww. j a v a 2 s . c o m*/ case R.id.manufacturer_menu_contact: { try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", manufacturerName); intent.putExtra("uri", "http://www.gulesider.no/finn:" + URLEncoder.encode(manufacturerName.replaceAll(" .*", ""), "utf-8")); startActivity(intent); } catch (Exception e) { Log.e("ManufacturerActivity", Log.getStackTraceString(e)); } } default: { return super.onOptionsItemSelected(item); } } }
From source file:io.teak.sdk.Raven.java
public void reportException(Throwable t) { if (t == null) { return;/* ww w . j av a 2 s. c o m*/ } HashMap<String, Object> additions = new HashMap<>(); ArrayList<Object> exceptions = new ArrayList<>(); HashMap<String, Object> exception = new HashMap<>(); exception.put("type", t.getClass().getSimpleName()); exception.put("value", t.getMessage()); exception.put("module", t.getClass().getPackage().getName()); HashMap<String, Object> stacktrace = new HashMap<>(); ArrayList<Object> stackFrames = new ArrayList<>(); StackTraceElement[] steArray = t.getStackTrace(); for (int i = steArray.length - 1; i >= 0; i--) { StackTraceElement ste = steArray[i]; HashMap<String, Object> frame = new HashMap<>(); frame.put("filename", ste.getFileName()); String method = ste.getMethodName(); if (method.length() != 0) { frame.put("function", method); } int lineno = ste.getLineNumber(); if (!ste.isNativeMethod() && lineno >= 0) { frame.put("lineno", lineno); } String module = ste.getClassName(); frame.put("module", module); boolean in_app = true; if (module.startsWith("android.") || module.startsWith("java.") || module.startsWith("dalvik.") || module.startsWith("com.android.")) { in_app = false; } frame.put("in_app", in_app); stackFrames.add(frame); } stacktrace.put("frames", stackFrames); exception.put("stacktrace", stacktrace); exceptions.add(exception); additions.put("exception", exceptions); try { Report report = new Report(t.getMessage(), Level.ERROR, additions); report.sendToService(); } catch (Exception e) { Log.e(LOG_TAG, "Unable to report Teak SDK exception. " + Log.getStackTraceString(t) + "\n" + Log.getStackTraceString(e)); } }
From source file:com.tmall.wireless.tangram.support.SimpleClickSupport.java
public void onClick(View targetView, BaseCell cell, int type, Map<String, Object> params) { if (optimizedMode) { defaultClick(targetView, cell, type); } else {/* www . jav a 2 s . c o m*/ if (mOnClickMethods.isEmpty()) { findClickMethods(this.getClass().getMethods()); } List<Class<?>> classes = lookupCellTypes(targetView.getClass()); for (Class clz : classes) { if (clz.equals(View.class)) { continue; } if (mOnClickMethods.containsKey(clz)) { OnClickMethod onClickMethod = mOnClickMethods.get(clz); try { if (onClickMethod.paramLength == 3) { onClickMethod.method.invoke(this, targetView, cell, type); return; } else if (onClickMethod.paramLength == 4) { onClickMethod.method.invoke(this, targetView, cell, type, params); return; } } catch (Exception e) { LogUtils.e(TAG, "Invoke onClick method error: " + Log.getStackTraceString(e), e); } } } defaultClick(targetView, cell, type); } }