List of usage examples for android.util Log getStackTraceString
public static String getStackTraceString(Throwable tr)
From source file:org.droidparts.persist.json.JSONSerializer.java
private void readFromJSONAndSetFieldVal(ModelType model, FieldSpec<KeyAnn> spec, JSONObject obj, String key) throws JSONException { Pair<String, String> keyParts = getNestedKeyParts(key); if (keyParts != null) { String subKey = keyParts.first; if (hasNonNull(obj, subKey)) { JSONObject subObj = obj.getJSONObject(subKey); readFromJSONAndSetFieldVal(model, spec, subObj, keyParts.second); } else {/*from w w w . j a v a2s .c o m*/ throwIfRequired(spec); } } else if (obj.has(key)) { Object val = obj.get(key); try { val = readFromJSON(spec.field.getType(), spec.arrCollItemType, val); if (!NULL.equals(val)) { setFieldVal(model, spec.field, val); } else { L.i("Received NULL '" + spec.ann.name + "', skipping."); } } catch (Exception e) { if (spec.ann.optional) { L.w("Failed to deserialize '" + spec.ann.name + "': " + e.getMessage()); } else { throw new JSONException(Log.getStackTraceString(e)); } } } else { throwIfRequired(spec); } }
From source file:net.olejon.mdapp.NasjonaleRetningslinjerActivity.java
private void search(final String searchString) { if (searchString.equals("")) return;/* ww w . j av a 2 s .c o m*/ mToolbarSearchLayout.setVisibility(View.GONE); mToolbarSearchEditText.setText(""); mProgressBar.setVisibility(View.VISIBLE); RequestQueue requestQueue = Volley.newRequestQueue(mContext); try { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, getString(R.string.project_website_uri) + "api/1/correct/?search=" + URLEncoder.encode(searchString, "utf-8"), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { mProgressBar.setVisibility(View.GONE); try { final String correctSearchString = response.getString("correct"); if (correctSearchString.equals("")) { saveRecentSearch(searchString); try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.nasjonale_retningslinjer_search) + ": \"" + searchString + "\""); intent.putExtra("uri", "https://helsedirektoratet.no/retningslinjer#k=" + URLEncoder.encode(searchString.toLowerCase(), "utf-8")); startActivity(intent); } catch (Exception e) { Log.e("NasjonaleRetningslinjer", Log.getStackTraceString(e)); } } else { new MaterialDialog.Builder(mContext) .title(getString(R.string.correct_dialog_title)) .content(Html.fromHtml(getString(R.string.correct_dialog_message) + ":<br><br><b>" + correctSearchString + "</b>")) .positiveText(getString(R.string.correct_dialog_positive_button)) .negativeText(getString(R.string.correct_dialog_negative_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { saveRecentSearch(correctSearchString); try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.nasjonale_retningslinjer_search) + ": \"" + correctSearchString + "\""); intent.putExtra("uri", "https://helsedirektoratet.no/retningslinjer#k=" + URLEncoder.encode( correctSearchString.toLowerCase(), "utf-8")); startActivity(intent); } catch (Exception e) { Log.e("NasjonaleRetningslinjer", Log.getStackTraceString(e)); } } @Override public void onNegative(MaterialDialog dialog) { saveRecentSearch(searchString); try { Intent intent = new Intent(mContext, MainWebViewActivity.class); intent.putExtra("title", getString(R.string.nasjonale_retningslinjer_search) + ": \"" + searchString + "\""); intent.putExtra("uri", "https://helsedirektoratet.no/retningslinjer#k=" + URLEncoder.encode( searchString.toLowerCase(), "utf-8")); startActivity(intent); } catch (Exception e) { Log.e("NasjonaleRetningslinjer", Log.getStackTraceString(e)); } } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .negativeColorRes(R.color.black).show(); } } catch (Exception e) { Log.e("NasjonaleRetningslinjer", Log.getStackTraceString(e)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { mProgressBar.setVisibility(View.GONE); Log.e("NasjonaleRetningslinjer", error.toString()); } }); jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); requestQueue.add(jsonObjectRequest); } catch (Exception e) { Log.e("NasjonaleRetningslinjer", Log.getStackTraceString(e)); } }
From source file:org.apache.cordova.plugins.Actionable.java
private void updateButtons(final JSONArray buttons) { for (int i = 0; i < buttons.length(); i++) { try {//from ww w .j a va 2s. com JSONObject btn = buttons.getJSONObject(i); Actionable action = Actionable.fromJSON(btn); action.setFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); mMenuItems.put(action.getTitle(), action); } catch (Exception e) { Log.v("Cambie", Log.getStackTraceString(e)); } } }
From source file:org.proninyaroslav.libretorrent.core.TorrentEngine.java
@Override public void saveSettings() { if (session == null) { return;//from ww w .j a v a 2s .c om } try { TorrentUtils.saveSession(context, session.saveState()); } catch (Exception e) { Log.e(TAG, "Error saving session state: "); Log.e(TAG, Log.getStackTraceString(e)); } }
From source file:com.myandroidremote.AccountsActivity.java
/** * Registers for C2DM messaging with the given account name. * /* w w w .j a va 2 s .c om*/ * @param accountName * a String containing a Google account name */ private void register(final String accountName) { // Store the account name in shared preferences final SharedPreferences prefs = Util.getSharedPreferences(mContext); SharedPreferences.Editor editor = prefs.edit(); editor.putString(Util.ACCOUNT_NAME, accountName); editor.putString(Util.AUTH_COOKIE, null); editor.commit(); // Obtain an auth token and register final AccountManager mgr = AccountManager.get(mContext); Account[] accts = mgr.getAccountsByType("com.google"); for (Account acct : accts) { if (acct.name.equals(accountName)) { if (Util.isDebug(mContext)) { // Use a fake cookie for the dev mode app engine server // The cookie has the form email:isAdmin:userId // We set the userId to be the same as the account name String authCookie = "dev_appserver_login=" + accountName + ":false:" + accountName; boolean result = prefs.edit().putString(Util.AUTH_COOKIE, authCookie).commit(); C2DMessaging.register(mContext, Setup.SENDER_ID); } else { // Get the auth token from the AccountManager and convert // it into a cookie for the appengine server mgr.getAuthToken(acct, "ah", null, this, new AccountManagerCallback<Bundle>() { public void run(AccountManagerFuture<Bundle> future) { try { Bundle authTokenBundle = future.getResult(); String authToken = authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString(); String authCookie = getAuthCookie(authToken); if (authCookie == null) { mgr.invalidateAuthToken("com.google", authToken); } prefs.edit().putString(Util.AUTH_COOKIE, authCookie).commit(); C2DMessaging.register(mContext, Setup.SENDER_ID); } catch (AuthenticatorException e) { Log.w(TAG, "Got AuthenticatorException " + e); Log.w(TAG, Log.getStackTraceString(e)); } catch (IOException e) { Log.w(TAG, "Got IOException " + Log.getStackTraceString(e)); Log.w(TAG, Log.getStackTraceString(e)); } catch (OperationCanceledException e) { Log.w(TAG, "Got OperationCanceledException " + e); Log.w(TAG, Log.getStackTraceString(e)); } } }, null); } break; } } }
From source file:com.stepinmobile.fantasticbutton.api.ButtonHandle.java
/** * Method post tweet.//from w w w. j av a 2 s.com */ private void postTweet() { Twitter twitter = new TwitterFactory().getInstance(); AccessToken accessToken = new AccessToken(twitterHandle.getToken(), twitterHandle.getSecret()); twitter.setOAuthConsumer(twitterAppId, twitterAppSecret); twitter.setOAuthAccessToken(accessToken); Status status = null; try { status = twitter.updateStatus(tweetToBeTweeted); } catch (TwitterException e) { Log.e(TAG, Log.getStackTraceString(e)); } }
From source file:info.papdt.blacklight.ui.statuses.NewPostActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { mLayout = R.layout.post_status;/* www .j av a2 s .co m*/ super.onCreate(savedInstanceState); mLoginCache = new LoginApiCache(this); mUserCache = new UserApiCache(this); new GetAvatarTask().execute(); // Initialize views mText = Utility.findViewById(this, R.id.post_edit); mCount = Utility.findViewById(this, R.id.post_count); mDrawer = Utility.findViewById(this, R.id.post_drawer); mAvatar = Utility.findViewById(this, R.id.post_avatar); mScroll = Utility.findViewById(this, R.id.post_scroll); mPicsParent = Utility.findViewById(this, R.id.post_pics); mPic = Utility.findViewById(this, R.id.post_pic); mEmoji = Utility.findViewById(this, R.id.post_emoji); mAt = Utility.findViewById(this, R.id.post_at); mTopic = Utility.findViewById(this, R.id.post_topic); mSend = Utility.findViewById(this, R.id.post_send); mCache = getSharedPreferences("post_cache", MODE_PRIVATE); // Bind onClick events Utility.bindOnClick(this, mPic, "pic"); Utility.bindOnClick(this, mEmoji, "emoji"); Utility.bindOnClick(this, mAt, "at"); Utility.bindOnClick(this, mTopic, "topic"); Utility.bindOnClick(this, mSend, "send"); Utility.bindOnClick(this, mAvatar, "avatar"); // Version try { mVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; } catch (Exception e) { } // Hints if (Math.random() < 0.42) { // Make this a matter of possibility. mHints = getResources().getStringArray(R.array.splashes); mText.setHint(mHints[new Random().nextInt(mHints.length)]); } // Fragments mEmoticonFragment = new EmoticonFragment(); mColorPickerFragment = new ColorPickerFragment(); getFragmentManager().beginTransaction().replace(R.id.post_emoticons, mEmoticonFragment).commit(); // Filter try { TypedArray array = getTheme().obtainStyledAttributes(R.styleable.BlackLight); mFilter = array.getColor(R.styleable.BlackLight_NewPostImgFilter, 0); mForeground = array.getColor(R.styleable.BlackLight_NewPostForeground, 0); array.recycle(); } catch (Exception e) { mFilter = 0; } // Listeners mEmoticonFragment.setEmoticonListener(new EmoticonFragment.EmoticonListener() { @Override public void onEmoticonSelected(String name) { mText.getText().insert(mText.getSelectionStart(), name); mDrawer.closeDrawer(Gravity.RIGHT); } }); mColorPickerFragment.setOnColorSelectedListener(new ColorPickerFragment.OnColorSelectedListener() { @Override public void onSelected(String hex) { int sel = mText.getSelectionStart(); mText.getText().insert(sel, "[" + hex + " [d"); mText.setSelection(sel + 9); mDrawer.closeDrawer(Gravity.RIGHT); } }); mText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (needCache()) mCache.edit().putString(DRAFT, s.toString()).apply(); } @Override public void afterTextChanged(Editable s) { // How many Chinese characters (1 Chinses character = 2 English characters) try { int length = Utility.lengthOfString(s.toString()); if (DEBUG) { Log.d(TAG, "Text length = " + length); } if (length <= 140 && !s.toString().contains("\n")) { mCount.setTextColor(mForeground); mCount.setText(String.valueOf(140 - length)); mIsLong = false; } else if (!(NewPostActivity.this instanceof RepostActivity) && !(NewPostActivity.this instanceof CommentOnActivity) && !(NewPostActivity.this instanceof ReplyToActivity)) { mCount.setText(getResources().getString(R.string.long_post)); mIsLong = true; } else { mCount.setTextColor(getResources().getColor(android.R.color.holo_red_light)); mCount.setText(String.valueOf(140 - length)); mIsLong = false; } } catch (Exception e) { } if (mEmoji != null) { if (mIsLong) { getFragmentManager().beginTransaction().replace(R.id.post_emoticons, mColorPickerFragment) .commit(); mEmoji.setImageResource(R.drawable.ic_mode_edit_black_36dp); } else { getFragmentManager().beginTransaction().replace(R.id.post_emoticons, mEmoticonFragment) .commit(); mEmoji.setImageResource(R.drawable.ic_emoji); } } } }); getWindow().getDecorView().getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mText.requestFocus(); mText.requestFocusFromTouch(); // Draft if (needCache()) mText.setText(mCache.getString(DRAFT, "")); // Must be removed getWindow().getDecorView().getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); // Imgs for (int i = 0; i < 9; i++) { mPics[i] = (ImageView) mPicsParent.getChildAt(i); mPics[i].setOnLongClickListener(this); mPics[i].setOnClickListener(this); } // Handle share intent Intent i = getIntent(); if (i != null && i.getType() != null) { if (i.getType().contains("text/plain")) { mText.setText(i.getStringExtra(Intent.EXTRA_TEXT)); } else if (i.getType().contains("image/")) { Uri uri = (Uri) i.getParcelableExtra(Intent.EXTRA_STREAM); try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); addPicture(bitmap, null); } catch (IOException e) { if (DEBUG) { Log.d(TAG, Log.getStackTraceString(e)); } } } } }
From source file:org.opendatakit.logging.WebLoggerImpl.java
public void log(int severity, String t, String logMsg) { try {/*from w w w. j a v a 2s .c o m*/ String androidLogLine = logMsg; // insert timestamp to help with time tracking String curLogLineStamp = getFormattedLogLineDateNow(); if (!logMsg.startsWith(curLogLineStamp.substring(0, 16))) { logMsg = curLogLineStamp + " " + logMsg; } else { androidLogLine = logMsg.length() > curLogLineStamp.length() ? logMsg.substring(curLogLineStamp.length()) : logMsg; } if (androidLogLine.length() > 128) { androidLogLine = androidLogLine.substring(0, 125) + "..."; } String androidTag = t; int periodIdx = t.lastIndexOf('.'); if (t.length() > 26 && periodIdx != -1) { androidTag = t.substring(periodIdx + 1); } // Our severity level has to have unique values that we actually want to compress // when calculating whether to emit the value to the system log or not. Do that via the // remappedSeverity computation below. int remappedSeverity = severity; if (severity == SUCCESS) { remappedSeverity = ERROR; } if (severity == TIP) { remappedSeverity = ASSERT; } if (remappedSeverity >= minLogLevelToSpew) { // do logcat logging... if (severity == ERROR) { Log.e(androidTag, androidLogLine); } else if (severity == WARN) { Log.w(androidTag, androidLogLine); } else if (severity == INFO || severity == SUCCESS || severity == TIP) { Log.i(androidTag, androidLogLine); } else if (severity == DEBUG) { Log.d(androidTag, androidLogLine); } else { Log.v(androidTag, androidLogLine); } } // and compose the log to the file... switch (severity) { case ASSERT: logMsg = "A/" + t + ": " + logMsg; break; case DEBUG: logMsg = "D/" + t + ": " + logMsg; break; case ERROR: logMsg = "E/" + t + ": " + logMsg; break; case INFO: logMsg = "I/" + t + ": " + logMsg; break; case SUCCESS: logMsg = "S/" + t + ": " + logMsg; break; case VERBOSE: logMsg = "V/" + t + ": " + logMsg; break; case TIP: logMsg = "T/" + t + ": " + logMsg; break; case WARN: logMsg = "W/" + t + ": " + logMsg; break; default: Log.d(t, logMsg); logMsg = "?/" + t + ": " + logMsg; break; } log(logMsg); } catch (IOException e) { Log.e(TAG, Log.getStackTraceString(e), e); } }
From source file:com.master.metehan.filtereagle.AdapterLog.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values final long id = cursor.getLong(colID); long time = cursor.getLong(colTime); int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion)); int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol)); String flags = cursor.getString(colFlags); String saddr = cursor.getString(colSAddr); int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort)); String daddr = cursor.getString(colDAddr); int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort)); String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName)); int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid)); String data = cursor.getString(colData); int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed)); int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection)); int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive)); // Get views/* ww w .j a v a2s .co m*/ TextView tvTime = (TextView) view.findViewById(R.id.tvTime); TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol); TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags); TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr); TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort); final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr); TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort); final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization); ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon); TextView tvUid = (TextView) view.findViewById(R.id.tvUid); TextView tvData = (TextView) view.findViewById(R.id.tvData); ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection); ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive); // Show time tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time)); // Show connection type if (connection <= 0) ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked); else { if (allowed > 0) ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on); else ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable()); DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff); } // Show if screen on if (interactive <= 0) ivInteractive.setImageDrawable(null); else { ivInteractive.setImageResource(R.drawable.screen_on); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable()); DrawableCompat.setTint(wrap, colorOn); } } // Show protocol name tvProtocol.setText(Util.getProtocolName(protocol, version, false)); // SHow TCP flags tvFlags.setText(flags); tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE); // Show source and destination port if (protocol == 6 || protocol == 17) { tvSPort.setText(sport < 0 ? "" : getKnownPort(sport)); tvDPort.setText(dport < 0 ? "" : getKnownPort(dport)); } else { tvSPort.setText(sport < 0 ? "" : Integer.toString(sport)); tvDPort.setText(dport < 0 ? "" : Integer.toString(dport)); } // Application icon ApplicationInfo info = null; PackageManager pm = context.getPackageManager(); String[] pkg = pm.getPackagesForUid(uid); if (pkg != null && pkg.length > 0) try { info = pm.getApplicationInfo(pkg[0], 0); } catch (PackageManager.NameNotFoundException ignored) { } if (info == null) ivIcon.setImageDrawable(null); else if (info.icon == 0) Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon); else { Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon); Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon); } // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h uid = uid % 100000; // strip off user ID if (uid == -1) tvUid.setText(""); else if (uid == 0) tvUid.setText(context.getString(R.string.title_root)); else if (uid == 9999) tvUid.setText("-"); // nobody else tvUid.setText(Integer.toString(uid)); // Show source address tvSAddr.setText(getKnownAddress(saddr)); // Show destination address if (resolve && !isKnownAddress(daddr)) if (dname == null) { if (tvDaddr.getTag() == null) { tvDaddr.setText(daddr); new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { tvDaddr.setTag(id); } @Override protected String doInBackground(String... args) { try { return InetAddress.getByName(args[0]).getHostName(); } catch (UnknownHostException ignored) { return args[0]; } } @Override protected void onPostExecute(String name) { Object tag = tvDaddr.getTag(); if (tag != null && (Long) tag == id) tvDaddr.setText(">" + name); tvDaddr.setTag(null); } }.execute(daddr); } } else tvDaddr.setText(dname); else tvDaddr.setText(getKnownAddress(daddr)); // Show organization tvOrganization.setVisibility(View.GONE); if (organization) { if (!isKnownAddress(daddr) && tvOrganization.getTag() == null) new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { tvOrganization.setTag(id); } @Override protected String doInBackground(String... args) { try { return Util.getOrganization(args[0]); } catch (Throwable ex) { Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); return null; } } @Override protected void onPostExecute(String organization) { Object tag = tvOrganization.getTag(); if (organization != null && tag != null && (Long) tag == id) { tvOrganization.setText(organization); tvOrganization.setVisibility(View.VISIBLE); } tvOrganization.setTag(null); } }.execute(daddr); } // Show extra data if (TextUtils.isEmpty(data)) { tvData.setText(""); tvData.setVisibility(View.GONE); } else { tvData.setText(data); tvData.setVisibility(View.VISIBLE); } }
From source file:com.zhengde163.netguard.AdapterLog.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values final long id = cursor.getLong(colID); long time = cursor.getLong(colTime); int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion)); int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol)); String flags = cursor.getString(colFlags); String saddr = cursor.getString(colSAddr); int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort)); String daddr = cursor.getString(colDAddr); int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort)); String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName)); int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid)); String data = cursor.getString(colData); int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed)); int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection)); int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive)); // Get views/*from ww w .j a va2 s . com*/ TextView tvTime = (TextView) view.findViewById(R.id.tvTime); TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol); // TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags); TextView tvSAddr = (TextView) view.findViewById(R.id.tvSAddr); TextView tvSPort = (TextView) view.findViewById(R.id.tvSPort); final TextView tvDaddr = (TextView) view.findViewById(R.id.tvDAddr); TextView tvDPort = (TextView) view.findViewById(R.id.tvDPort); final TextView tvOrganization = (TextView) view.findViewById(R.id.tvOrganization); ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon); TextView tvUid = (TextView) view.findViewById(R.id.tvUid); TextView tvData = (TextView) view.findViewById(R.id.tvData); ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection); ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive); // Show time tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time)); // Show connection type if (connection <= 0) ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked); else { if (allowed > 0) ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on); else ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable()); DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff); } // Show if screen on if (interactive <= 0) ivInteractive.setImageDrawable(null); else { ivInteractive.setImageResource(R.drawable.screen_on); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable()); DrawableCompat.setTint(wrap, colorOn); } } // Show protocol name tvProtocol.setText(Util.getProtocolName(protocol, version, false) + flags); // SHow TCP flags // tvFlags.setText(flags); // tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE); // Show source and destination port if (protocol == 6 || protocol == 17) { tvSPort.setText(sport < 0 ? "" : getKnownPort(sport)); tvDPort.setText(dport < 0 ? "" : getKnownPort(dport)); } else { tvSPort.setText(sport < 0 ? "" : Integer.toString(sport)); tvDPort.setText(dport < 0 ? "" : Integer.toString(dport)); } // Application icon ApplicationInfo info = null; PackageManager pm = context.getPackageManager(); String[] pkg = pm.getPackagesForUid(uid); if (pkg != null && pkg.length > 0) try { info = pm.getApplicationInfo(pkg[0], 0); } catch (PackageManager.NameNotFoundException ignored) { } if (info == null) ivIcon.setImageDrawable(null); else if (info.icon == 0) Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(ivIcon); else { Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon); Picasso.with(context).load(uri).resize(iconSize, iconSize).into(ivIcon); } // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h uid = uid % 100000; // strip off user ID if (uid == -1) tvUid.setText(""); else if (uid == 0) tvUid.setText(context.getString(R.string.title_root)); else if (uid == 9999) tvUid.setText("-"); // nobody else tvUid.setText(Integer.toString(uid)); // Show source address tvSAddr.setText(getKnownAddress(saddr)); // Show destination address if (resolve && !isKnownAddress(daddr)) if (dname == null) { if (tvDaddr.getTag() == null) { tvDaddr.setText(daddr); new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { tvDaddr.setTag(id); } @Override protected String doInBackground(String... args) { try { return InetAddress.getByName(args[0]).getHostName(); } catch (UnknownHostException ignored) { return args[0]; } } @Override protected void onPostExecute(String name) { Object tag = tvDaddr.getTag(); if (tag != null && (Long) tag == id) tvDaddr.setText(">" + name); tvDaddr.setTag(null); } }.execute(daddr); } } else tvDaddr.setText(dname); else tvDaddr.setText(getKnownAddress(daddr)); // Show organization tvOrganization.setVisibility(View.GONE); if (organization) { if (!isKnownAddress(daddr) && tvOrganization.getTag() == null) new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { tvOrganization.setTag(id); } @Override protected String doInBackground(String... args) { try { return Util.getOrganization(args[0]); } catch (Throwable ex) { Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); return null; } } @Override protected void onPostExecute(String organization) { Object tag = tvOrganization.getTag(); if (organization != null && tag != null && (Long) tag == id) { tvOrganization.setText(organization); tvOrganization.setVisibility(View.VISIBLE); } tvOrganization.setTag(null); } }.execute(daddr); } // Show extra data if (TextUtils.isEmpty(data)) { tvData.setText(""); tvData.setVisibility(View.GONE); } else { tvData.setText(data); tvData.setVisibility(View.VISIBLE); } }