Example usage for android.util Log getStackTraceString

List of usage examples for android.util Log getStackTraceString

Introduction

In this page you can find the example usage for android.util Log getStackTraceString.

Prototype

public static String getStackTraceString(Throwable tr) 

Source Link

Document

Handy function to get a loggable stack trace from a Throwable

Usage

From source file:com.dm.material.dashboard.candybar.fragments.ApplyFragment.java

private void getLaunchers() {
    mGetLaunchers = new AsyncTask<Void, Void, Boolean>() {

        List<Icon> launchers;

        @Override//from w w  w.jav a 2  s  . c  o  m
        protected void onPreExecute() {
            super.onPreExecute();
            launchers = new ArrayList<>();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    String[] launcherNames = getActivity().getResources()
                            .getStringArray(R.array.launcher_names);
                    TypedArray launcherIcons = getActivity().getResources()
                            .obtainTypedArray(R.array.launcher_icons);
                    String[] launcherPackages1 = getActivity().getResources()
                            .getStringArray(R.array.launcher_packages_1);
                    String[] launcherPackages2 = getActivity().getResources()
                            .getStringArray(R.array.launcher_packages_2);
                    String[] launcherPackages3 = getActivity().getResources()
                            .getStringArray(R.array.launcher_packages_3);

                    List<Icon> installed = new ArrayList<>();
                    List<Icon> supported = new ArrayList<>();

                    for (int i = 0; i < launcherNames.length; i++) {
                        boolean isInstalled = isLauncherInstalled(launcherPackages1[i], launcherPackages2[i],
                                launcherPackages3[i]);

                        int icon = R.drawable.ic_app_default;
                        if (i < launcherIcons.length())
                            icon = launcherIcons.getResourceId(i, icon);

                        String launcherPackage = launcherPackages1[i];
                        if (launcherPackages1[i].equals("com.lge.launcher2")) {
                            boolean lghome3 = isPackageInstalled(launcherPackages2[i]);
                            if (lghome3)
                                launcherPackage = launcherPackages2[i];
                        }

                        Icon launcher = new Icon(launcherNames[i], icon, launcherPackage);
                        if (isInstalled)
                            installed.add(launcher);
                        else
                            supported.add(launcher);
                    }

                    try {
                        Collections.sort(installed, new AlphanumComparator() {
                            @Override
                            public int compare(Object o1, Object o2) {
                                String s1 = ((Icon) o1).getTitle();
                                String s2 = ((Icon) o2).getTitle();
                                return super.compare(s1, s2);
                            }
                        });
                    } catch (Exception ignored) {
                    }

                    try {
                        Collections.sort(supported, new AlphanumComparator() {
                            @Override
                            public int compare(Object o1, Object o2) {
                                String s1 = ((Icon) o1).getTitle();
                                String s2 = ((Icon) o2).getTitle();
                                return super.compare(s1, s2);
                            }
                        });
                    } catch (Exception ignored) {
                    }

                    if (installed.size() > 0) {
                        launchers.add(new Icon(getActivity().getResources().getString(R.string.apply_installed),
                                -1, null));
                    }

                    launchers.addAll(installed);
                    launchers.add(new Icon(getActivity().getResources().getString(R.string.apply_supported), -2,
                            null));
                    launchers.addAll(supported);

                    launcherIcons.recycle();
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (aBoolean) {
                mRecyclerView.setAdapter(new LauncherAdapter(getActivity(), launchers));
                resetSpanSizeLookUp();
            }
            mGetLaunchers = null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:net.olejon.mdapp.InteractionsCardsAdapter.java

@Override
public void onBindViewHolder(InteractionsViewHolder viewHolder, int i) {
    try {/*from   w w w.  j a va  2 s. co  m*/
        final JSONObject interactionJsonObject = mInteractions.getJSONObject(i);

        final String color = interactionJsonObject.getString("color");
        final String title = interactionJsonObject.getString("title");
        final String text = interactionJsonObject.getString("text");
        final String pubmedSearchUri = interactionJsonObject.getString("pubmed_search_uri");
        final String uri = interactionJsonObject.getString("uri");

        switch (color) {
        case "red": {
            viewHolder.card.setCardBackgroundColor(mContext.getResources().getColor(R.color.red));
            viewHolder.relevance.setText(mContext.getString(R.string.interactions_cards_relevance) + ": "
                    + mContext.getString(R.string.interactions_cards_relevance_red));
            viewHolder.icon.setImageResource(R.drawable.ic_error_white_24dp);

            break;
        }
        case "orange": {
            viewHolder.card.setCardBackgroundColor(mContext.getResources().getColor(R.color.orange));
            viewHolder.relevance.setText(mContext.getString(R.string.interactions_cards_relevance) + ": "
                    + mContext.getString(R.string.interactions_cards_relevance_orange));
            viewHolder.icon.setImageResource(R.drawable.ic_warning_white_24dp);

            break;
        }
        case "green": {
            viewHolder.card.setCardBackgroundColor(mContext.getResources().getColor(R.color.green));
            viewHolder.relevance.setText(mContext.getString(R.string.interactions_cards_relevance) + ": "
                    + mContext.getString(R.string.interactions_cards_relevance_green));
            viewHolder.icon.setImageResource(R.drawable.ic_check_white_24dp);

            break;
        }
        default: {
            viewHolder.card.setCardBackgroundColor(mContext.getResources().getColor(R.color.red));
            viewHolder.relevance.setText(mContext.getString(R.string.interactions_cards_relevance) + ": "
                    + mContext.getString(R.string.interactions_cards_relevance_red));
            viewHolder.icon.setImageResource(R.drawable.ic_error_white_24dp);

            break;
        }
        }

        viewHolder.title.setText(title);
        viewHolder.text.setText(text);

        viewHolder.buttonHandling.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mTools.isDeviceConnected()) {
                    try {
                        mProgressBar.setVisibility(View.VISIBLE);

                        RequestQueue requestQueue = Volley.newRequestQueue(mContext);

                        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
                                mContext.getString(R.string.project_website_uri)
                                        + "api/1/interactions/handling/?uri=" + URLEncoder.encode(uri, "utf-8"),
                                new Response.Listener<JSONObject>() {
                                    @Override
                                    public void onResponse(JSONObject response) {
                                        mProgressBar.setVisibility(View.GONE);

                                        try {
                                            new MaterialDialog.Builder(mContext)
                                                    .title(mContext.getString(
                                                            R.string.interactions_cards_handling_dialog_title))
                                                    .content(response.getString("handling"))
                                                    .positiveText(mContext.getString(
                                                            R.string.interactions_cards_handling_dialog_positive_button))
                                                    .contentColorRes(R.color.black)
                                                    .positiveColorRes(R.color.dark_blue).show();
                                        } catch (Exception e) {
                                            mTools.showToast(mContext.getString(
                                                    R.string.interactions_cards_no_handling_information_available),
                                                    1);

                                            Log.e("InteractionsCards", Log.getStackTraceString(e));
                                        }
                                    }
                                }, new Response.ErrorListener() {
                                    @Override
                                    public void onErrorResponse(VolleyError error) {
                                        mProgressBar.setVisibility(View.GONE);

                                        mTools.showToast(mContext.getString(
                                                R.string.interactions_cards_no_handling_information_available),
                                                1);

                                        Log.e("InteractionsCards", error.toString());
                                    }
                                });

                        jsonObjectRequest.setRetryPolicy(
                                new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                                        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

                        requestQueue.add(jsonObjectRequest);
                    } catch (Exception e) {
                        Log.e("InteractionsCards", Log.getStackTraceString(e));
                    }
                } else {
                    mTools.showToast(mContext.getString(R.string.device_not_connected), 1);
                }
            }
        });

        viewHolder.buttonPubmedSearchUri.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title", "PubMed");
                intent.putExtra("uri", pubmedSearchUri);
                mContext.startActivity(intent);
            }
        });

        viewHolder.buttonUri.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title", title);
                intent.putExtra("uri", uri);
                mContext.startActivity(intent);
            }
        });

        animateView(viewHolder.card, i);
    } catch (Exception e) {
        Log.e("InteractionsCards", Log.getStackTraceString(e));
    }
}

From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java

@Nullable
public static String buildCrashLog(Context context, File folder, String stackTrace) {
    try {/*from  ww w .ja  v a  2 s . co m*/
        if (stackTrace.length() == 0)
            return null;

        File fileDir = new File(folder.toString() + "/crashlog.txt");
        String deviceInfo = DeviceHelper.getDeviceInfoForCrashReport(context);
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"));
        out.append(deviceInfo).append(stackTrace);
        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.dm.material.dashboard.candybar.fragments.IconsSearchFragment.java

private void getIcons() {
    mGetIcons = new AsyncTask<Void, Void, Boolean>() {

        List<Icon> icons;

        @Override//from   w w  w.  j  a  v  a2  s  . c om
        protected void onPreExecute() {
            super.onPreExecute();
            icons = new ArrayList<>();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    if (CandyBarMainActivity.sSections == null) {
                        CandyBarMainActivity.sSections = IconsHelper.getIconsList(getActivity());
                        CandyBarMainActivity.sIconsCount = 0;

                        for (Icon section : CandyBarMainActivity.sSections) {
                            CandyBarMainActivity.sIconsCount += section.getIcons().size();

                            if (getActivity().getResources().getBoolean(R.bool.show_icon_name)) {
                                for (Icon icon : section.getIcons()) {
                                    String name = IconsHelper.replaceName(getActivity(), getActivity()
                                            .getResources().getBoolean(R.bool.enable_icon_name_replacer),
                                            icon.getTitle());
                                    icon.setTitle(name);
                                }
                            }
                        }
                    }

                    for (Icon icon : CandyBarMainActivity.sSections)
                        icons.addAll(icon.getIcons());

                    Collections.sort(icons, new AlphanumComparator() {
                        @Override
                        public int compare(Object o1, Object o2) {
                            String s1 = ((Icon) o1).getTitle();
                            String s2 = ((Icon) o2).getTitle();
                            return super.compare(s1, s2);
                        }
                    });
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (aBoolean) {
                mAdapter = new IconsAdapter(getActivity(), icons, true);
                mRecyclerView.setAdapter(mAdapter);
                mSearchView.requestFocus();
                SoftKeyboardHelper.openKeyboard(getActivity());
            } else {
                //Unable to load all icons
                Toast.makeText(getActivity(), R.string.icons_load_failed, Toast.LENGTH_LONG).show();
            }
            mGetIcons = null;
        }
    }.execute();
}

From source file:org.maikelwever.droidpile.backend.ApiConnecter.java

public int getRemoteTotal(boolean dbg) {
    int total = 0;
    try {/*from   w w  w  .  ja  va2  s. c  o  m*/
        List<DataCache> currentlyCached = new Select().from(DataCache.class)
                .where("key = ?", remoteTotalKeyName).execute();
        for (DataCache dc : currentlyCached) {
            if (total == 0) {
                total = Integer.parseInt(dc.data);
            }
            dc.delete();
        }
    } catch (Exception e) {
        Log.d("droidpile", "No old cache entries to clear.");
        Log.d("droidpile", Log.getStackTraceString(e));
        return total;
    }
    return total;
}

From source file:org.proninyaroslav.libretorrent.core.TorrentEngine.java

private void runNextLoadTorrentTask() {
    LoadTorrentTask task;//from www .j a v  a2 s .c o  m

    try {
        task = loadTorrentsQueue.poll();
    } catch (Exception e) {
        Log.e(TAG, Log.getStackTraceString(e));

        return;
    }

    if (task != null) {
        loadTorrentsExec.execute(task);
    }
}

From source file:org.alfresco.mobile.android.platform.exception.AlfrescoExceptionHelper.java

public static void displayErrorStackTrace(Activity activity, Exception e) {
    MaterialDialog.Builder builder = new MaterialDialog.Builder(activity).title("Error Informations")
            .cancelListener(new DialogInterface.OnCancelListener() {
                @Override/*  w  ww . j a v a 2 s . c  om*/
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                }
            }).content(Log.getStackTraceString(e)).negativeText(R.string.share).positiveText(R.string.cancel);
    builder.show();
    return;
}

From source file:org.alfresco.mobile.android.application.fragments.fileexplorer.FileExplorerMenuFragment.java

private File requestWriteExternalStorage(final String externalFolder) {
    try {/*from ww  w. j  av a  2 s  . co m*/
        if (Build.VERSION.SDK_INT < 23) {
            return (externalFolder == null) ? Environment.getExternalStorageDirectory()
                    : Environment.getExternalStoragePublicDirectory(externalFolder);
        }

        int hasWriteExternalStoragePermission = ContextCompat.checkSelfPermission(getActivity(),
                Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (hasWriteExternalStoragePermission != PackageManager.PERMISSION_GRANTED) {
            if (!ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                ActivityCompat.requestPermissions(getActivity(),
                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                        externalFolder == null ? BaseActivity.REQUEST_PERMISSION_SD
                                : BaseActivity.REQUEST_PERMISSION_DL);
                return null;
            }
            ActivityCompat.requestPermissions(getActivity(),
                    new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    externalFolder == null ? BaseActivity.REQUEST_PERMISSION_SD
                            : BaseActivity.REQUEST_PERMISSION_DL);
            return null;
        } else {
            return (externalFolder == null) ? Environment.getExternalStorageDirectory()
                    : Environment.getExternalStoragePublicDirectory(externalFolder);
        }
    } catch (Exception e) {
        Log.d(FileExplorerMenuFragment.TAG, Log.getStackTraceString(e));
    }
    return null;
}

From source file:com.tmall.wireless.tangram.support.ExposureSupport.java

public void onExposure(@NonNull View targetView, @NonNull BaseCell cell, int type) {
    if (optimizedMode) {
        defaultExposureCell(targetView, cell, type);
    } else {/*from ww w.jav a  2s . c  om*/
        if (mOnExposureMethods.isEmpty() || mOnTraceMethods.isEmpty()) {
            Method[] methods = this.getClass().getMethods();
            findTraceMethods(methods);
            findExposureMethods(methods);
        }
        List<Class<?>> classes = lookupCellTypes(targetView.getClass());
        for (Class clz : classes) {
            if (clz.equals(View.class)) {
                continue;
            }
            if (mOnExposureMethods.containsKey(clz)) {
                OnTraceMethod onTraceMethod = mOnExposureMethods.get(clz);
                try {
                    if (onTraceMethod.paramLength == 3) {
                        onTraceMethod.method.invoke(this, targetView, cell, type);
                        return;
                    }
                } catch (Exception e) {
                    LogUtils.e(TAG, "Invoke onExposure method error: " + Log.getStackTraceString(e), e);
                }
            }
        }
        defaultExposureCell(targetView, cell, type);
    }
}

From source file:com.kth.common.utils.etc.LogUtil.java

/**
 * WARN  ?./*from  w ww  .  ja  v  a2  s .  co  m*/
 * 
 * @param clazz  ??  Class.
 * @param msg .
 * @param tr Throwable.
 */
public static void w(final Class<?> clazz, final String msg, final Throwable tr) {
    if (LogUtil.isWarnEnabled()) {
        Log.println(Log.WARN, TAG,
                LogUtil.getClassLineNumber(clazz) + " - " + msg + '\n' + Log.getStackTraceString(tr));

        //  ?? ?   ?.
        if (LogUtil.isFileLogEnabled()) {
            write(Log.WARN, LogUtil.getClassLineNumber(clazz), msg, tr);
        }
    }
}