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:org.projecthdata.ehr.viewer.fragments.WeightFragment.java

private void updateListData() {
    try {//  w  ww .j  ava 2 s  .  co m
        Dao<WeightReading, Integer> weightDao = this.ehrDatabaseHelper.getWeightReadingDao();

        List<WeightReading> readings = weightDao
                .query(weightDao.queryBuilder().orderBy(WeightReading.COLUMN_DATE_TIME, false).prepare());

        adapter = new WeightReadingListAdapter(getActivity(), readings);
        setListAdapter(adapter);

    } catch (SQLException e) {
        Log.e(getClass().getSimpleName(), Log.getStackTraceString(e));
    }
}

From source file:org.alfresco.mobile.android.application.security.DataCleaner.java

@Override
protected Boolean doInBackground(String... params) {
    try {/*w w w  .  j a  v  a  2s .co m*/
        // Remove preferences
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activityRef.get());
        Editor editor = sharedPref.edit();
        editor.clear();
        editor.apply();
        SharedPreferences settings = activityRef.get().getSharedPreferences(AccountsPreferences.ACCOUNT_PREFS,
                0);
        editor = settings.edit();
        editor.clear();
        editor.apply();
        SharedPreferences prefs = activityRef.get().getSharedPreferences(FileExplorerHelper.FILEEXPLORER_PREFS,
                0);
        editor = prefs.edit();
        editor.clear();
        editor.apply();

        // Remove All Accounts
        List<Account> accounts = AlfrescoAccountManager.getInstance(activityRef.get()).getAndroidAccounts();
        for (Account accountToDelete : accounts) {
            AccountManager.get(activityRef.get()).removeAccount(accountToDelete, null, null);
        }

        // Delete loaded accounts
        SessionManager.getInstance(activityRef.get()).shutdown();
        AlfrescoAccountManager.getInstance(activityRef.get()).shutdown();

        // Find folders
        File cache = activityRef.get().getCacheDir();
        File folder = activityRef.get().getExternalFilesDir(null);

        listingFiles.add(cache);
        listingFiles.add(folder);

        // Remove Files/folders
        for (File file : listingFiles) {
            if (file.exists()) {
                if (file.isDirectory()) {
                    recursiveDelete(file);
                } else {
                    file.delete();
                }
            }
        }
        return true;
    } catch (Exception fle) {
        Log.e(TAG, Log.getStackTraceString(fle));
        return false;
    }
}

From source file:org.proninyaroslav.libretorrent.core.utils.TorrentUtils.java

public static boolean removeTorrentDataDir(Context context, String id) {
    if (!FileIOUtils.isStorageWritable()) {
        return false;
    }//from  w  ww  .ja  va2  s. c  o  m

    String path = findTorrentDataDir(context, id);

    if (path != null) {
        try {
            FileUtils.deleteDirectory(new File(path));

            return true;

        } catch (IOException e) {
            Log.e(TAG, Log.getStackTraceString(e));

            return false;
        }
    }

    return false;
}

From source file:eu.faircode.netguard.LogAdapter.java

public LogAdapter(Context context, Cursor cursor, boolean resolve) {
    super(context, cursor, 0);
    this.resolve = resolve;
    colTime = cursor.getColumnIndex("time");
    colVersion = cursor.getColumnIndex("version");
    colProtocol = cursor.getColumnIndex("protocol");
    colFlags = cursor.getColumnIndex("flags");
    colSAddr = cursor.getColumnIndex("saddr");
    colSPort = cursor.getColumnIndex("sport");
    colDaddr = cursor.getColumnIndex("daddr");
    colDPort = cursor.getColumnIndex("dport");
    colDName = cursor.getColumnIndex("dname");
    colUid = cursor.getColumnIndex("uid");
    colData = cursor.getColumnIndex("data");
    colAllowed = cursor.getColumnIndex("allowed");
    colConnection = cursor.getColumnIndex("connection");
    colInteractive = cursor.getColumnIndex("interactive");

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    colorOn = tv.data;/* w w w.java  2s.c  o  m*/
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    colorOff = tv.data;

    try {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        dns = SinkholeService.getDns(context);
        vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1"));
        vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"));
    } catch (UnknownHostException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}

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

public static void prepareIconRequest(@NonNull Context context) {
    new AsyncTask<Void, Void, Boolean>() {

        @Override/*from ww  w.  j  a va  2  s. c om*/
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    if (context.getResources().getBoolean(R.bool.enable_icon_request)
                            || context.getResources().getBoolean(R.bool.enable_premium_request)) {
                        CandyBarMainActivity.sMissedApps = RequestHelper.loadMissingApps(context);
                    }
                    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) {
                if (context == null)
                    return;

                FragmentManager fm = ((AppCompatActivity) context).getSupportFragmentManager();
                if (fm == null)
                    return;

                Fragment fragment = fm.findFragmentByTag("home");
                if (fragment == null)
                    return;

                HomeListener listener = (HomeListener) fragment;
                listener.onHomeDataUpdated(null);
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:com.dm.material.dashboard.candybar.activities.CandyBarSplashActivity.java

private void prepareIconsList() {
    mPrepareIconsList = new AsyncTask<Void, Void, Boolean>() {
        @Override/*from  w w w  .ja v  a 2 s  .  c om*/
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    CandyBarMainActivity.sSections = IconsHelper.getIconsList(CandyBarSplashActivity.this);

                    int count = 0;
                    for (Icon section : CandyBarMainActivity.sSections) {
                        count += section.getIcons().size();
                    }
                    CandyBarMainActivity.sIconsCount = count;
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            mPrepareIconsList = null;
            startActivity(new Intent(CandyBarSplashActivity.this, mMainActivity));
            overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            finish();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

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

@Nullable
public static Uri getUriFromFile(Context context, String applicationId, File file) {
    try {/*from  w  w  w.j a  va  2s .  c o m*/
        return FileProvider.getUriForFile(context, applicationId + ".fileProvider", file);
    } catch (IllegalArgumentException e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return null;
}

From source file:com.dm.material.dashboard.candybar.adapters.CreditsAdapter.java

@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    ViewHolder holder;/*from   w  ww .ja v a2 s  .co  m*/
    if (view == null) {
        view = View.inflate(mContext, R.layout.fragment_credits_item_list, null);
        holder = new ViewHolder(view);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    Credit credit = mCredits.get(position);
    holder.title.setText(credit.getName());
    holder.subtitle.setText(credit.getContribution());
    holder.container.setOnClickListener(view1 -> {
        String link = credit.getLink();
        if (URLUtil.isValidUrl(link)) {
            try {
                mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
            } catch (ActivityNotFoundException e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
        }
    });

    if (credit.getContribution().length() == 0) {
        holder.subtitle.setVisibility(View.GONE);
    } else {
        holder.subtitle.setVisibility(View.VISIBLE);
    }

    ImageLoader.getInstance().displayImage(credit.getImage(), new ImageViewAware(holder.image),
            mOptions.build(), new ImageSize(144, 144), null, null);
    return view;
}

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

private void loadLicenses() {
    mLoadLicenses = new AsyncTask<Void, Void, Boolean>() {

        StringBuilder sb;//from  ww w  .ja va  2  s. co m

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            sb = new StringBuilder();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    InputStream rawResource = getActivity().getResources().openRawResource(R.raw.licenses);
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(rawResource));

                    String line;
                    while ((line = bufferedReader.readLine()) != null) {
                        sb.append(line);
                        sb.append("\n");
                    }
                    bufferedReader.close();
                    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) {
                mWebView.setVisibility(View.VISIBLE);
                mWebView.loadDataWithBaseURL(null, sb.toString(), "text/html", "utf-8", null);
            }
            mLoadLicenses = null;
        }

    }.execute();
}

From source file:eu.faircode.netguard.DownloadTask.java

@Override
protected Object doInBackground(Object... args) {
    Log.i(TAG, "Downloading " + url + " into " + file);

    InputStream in = null;/*from   w  ww  .  j  a  v a  2  s. com*/
    OutputStream out = null;
    URLConnection connection = null;
    try {
        connection = url.openConnection();
        connection.connect();

        if (connection instanceof HttpURLConnection) {
            HttpURLConnection httpConnection = (HttpURLConnection) connection;
            if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK)
                throw new IOException(
                        httpConnection.getResponseCode() + " " + httpConnection.getResponseMessage());
        }

        int contentLength = connection.getContentLength();
        Log.i(TAG, "Content length=" + contentLength);
        in = connection.getInputStream();
        out = new FileOutputStream(file);

        long size = 0;
        byte buffer[] = new byte[4096];
        int bytes;
        while (!isCancelled() && (bytes = in.read(buffer)) != -1) {
            out.write(buffer, 0, bytes);

            size += bytes;
            if (contentLength > 0)
                publishProgress((int) (size * 100 / contentLength));
        }

        Log.i(TAG, "Downloaded size=" + size);
        return null;
    } catch (Throwable ex) {
        return ex;
    } finally {
        try {
            if (out != null)
                out.close();
        } catch (IOException ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        }
        try {
            if (in != null)
                in.close();
        } catch (IOException ex) {
            Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
        }

        if (connection instanceof HttpURLConnection)
            ((HttpURLConnection) connection).disconnect();
    }
}