List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
From source file:cm.aptoide.pt.webservices.login.Login.java
private void drawLoginForm() { setContentView(R.layout.form_login); username_box = (EditText) findViewById(R.id.username); password_box = (EditText) findViewById(R.id.password); checkShowPass = (CheckBox) findViewById(R.id.show_login_passwd); checkShowPass.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { password_box.setTransformationMethod(null); } else { password_box.setTransformationMethod(new PasswordTransformationMethod()); }//from ww w.j ava2s . co m } }); checkShowPass.setEnabled(true); createUser = (Button) findViewById(R.id.new_to_aptoide); SpannableString newUserString = new SpannableString(getString(R.string.new_to_aptoide)); newUserString.setSpan(new UnderlineSpan(), 0, newUserString.length(), 0); createUser.setText(newUserString); forgot_password = (TextView) findViewById(R.id.forgot_password); SpannableString forgetString = new SpannableString(getString(R.string.forgot_passwd)); forgetString.setSpan(new UnderlineSpan(), 0, forgetString.length(), 0); forgot_password.setText(forgetString); forgot_password.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent passwordRecovery = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.aptoide.com/account/password-recovery")); startActivity(passwordRecovery); } }); }
From source file:truesculpt.ui.panels.WebFilePanel.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getManagers().getUtilsManager().updateFullscreenWindowStatus(getWindow()); setContentView(R.layout.webfile);/*from w ww .j a v a 2 s. c o m*/ getManagers().getUsageStatisticsManager().TrackEvent("OpenFromWeb", "", 1); mWebView = (WebView) findViewById(R.id.webview); mWebView.setWebViewClient(new MyWebViewClient()); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); mWebView.addJavascriptInterface(new JavaScriptInterface(this, getManagers()), "Android"); int nVersionCode = getManagers().getUpdateManager().getCurrentVersionCode(); mWebView.loadUrl(mStrBaseWebSite + "?version=" + nVersionCode); mPublishToWebBtn = (Button) findViewById(R.id.publish_to_web); mPublishToWebBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String name = getManagers().getMeshManager().getName(); final File imagefile = new File(getManagers().getFileManager().GetImageFileName()); final File objectfile = new File(getManagers().getFileManager().GetObjectFileName()); getManagers().getUsageStatisticsManager().TrackEvent("PublishToWeb", name, 1); if (imagefile.exists() && objectfile.exists()) { try { final File zippedObject = File.createTempFile("object", "zip"); zippedObject.deleteOnExit(); BufferedReader in = new BufferedReader(new FileReader(objectfile)); BufferedOutputStream out = new BufferedOutputStream( new GZIPOutputStream(new FileOutputStream(zippedObject))); System.out.println("Compressing file"); int c; while ((c = in.read()) != -1) { out.write(c); } in.close(); out.close(); long size = 0; size = new FileInputStream(imagefile).getChannel().size(); size += new FileInputStream(zippedObject).getChannel().size(); size /= 1000; final SpannableString msg = new SpannableString( "You will upload your latest saved version of this scupture representing " + size + " ko of data\n\n" + "When clicking the yes button you accept to publish your sculpture under the terms of the creative commons share alike, non commercial license\n" + "http://creativecommons.org/licenses/by-nc-sa/3.0" + "\n\nDo you want to proceed ?"); Linkify.addLinks(msg, Linkify.ALL); AlertDialog.Builder builder = new AlertDialog.Builder(WebFilePanel.this); builder.setMessage(msg).setCancelable(false) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { PublishPicture(imagefile, zippedObject, name); } }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); AlertDialog dlg = builder.create(); dlg.show(); // Make the textview clickable. Must be called after // show() ((TextView) dlg.findViewById(android.R.id.message)) .setMovementMethod(LinkMovementMethod.getInstance()); } catch (Exception e) { e.printStackTrace(); } } else { AlertDialog.Builder builder = new AlertDialog.Builder(WebFilePanel.this); builder.setMessage( "File has not been saved, you need to save it before publishing\nDo you want to proceed to save window ?") .setCancelable(false) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { ((FileSelectorPanel) getParent()).getTabHost().setCurrentTab(2); } }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); builder.show(); } } }); }
From source file:info.guardianproject.otr.app.im.app.ContactView.java
public void bind(Cursor cursor, String underLineText, boolean showChatMsg, boolean scrolling) { mHolder = (ViewHolder) getTag();/* ww w . jav a2 s. com*/ long providerId = cursor.getLong(COLUMN_CONTACT_PROVIDER); String address = cursor.getString(COLUMN_CONTACT_USERNAME); String nickname = cursor.getString(COLUMN_CONTACT_NICKNAME); int type = cursor.getInt(COLUMN_CONTACT_TYPE); String statusText = cursor.getString(COLUMN_CONTACT_CUSTOM_STATUS); String lastMsg = cursor.getString(COLUMN_LAST_MESSAGE); int presence = cursor.getInt(COLUMN_CONTACT_PRESENCE_STATUS); if (!TextUtils.isEmpty(underLineText)) { // highlight/underline the word being searched String lowercase = nickname.toLowerCase(); int start = lowercase.indexOf(underLineText.toLowerCase()); if (start >= 0) { int end = start + underLineText.length(); SpannableString str = new SpannableString(nickname); str.setSpan(new UnderlineSpan(), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE); mHolder.mLine1.setText(str); } else mHolder.mLine1.setText(nickname); } else mHolder.mLine1.setText(nickname); if (mHolder.mAvatar != null) { if (Imps.Contacts.TYPE_GROUP == type) { mHolder.mAvatar.setImageResource(R.drawable.group_chat); } else { Drawable avatar = DatabaseUtils.getAvatarFromCursor(cursor, COLUMN_AVATAR_DATA, ImApp.DEFAULT_AVATAR_WIDTH, ImApp.DEFAULT_AVATAR_HEIGHT); if (avatar != null) mHolder.mAvatar.setImageDrawable(avatar); else mHolder.mAvatar.setImageDrawable(mAvatarUnknown); } } if (showChatMsg && lastMsg != null) { if (mHolder.mAvatar != null) { setBackgroundResource(R.color.holo_blue_bright); mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_blue_bright)); mHolder.mLine1.setTextColor(Color.WHITE); } else if (mHolder.mStatusBlock != null) { mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_blue_bright)); } if (mHolder.mLine2 != null) mHolder.mLine2.setText(android.text.Html.fromHtml(lastMsg).toString()); } else { if (mHolder.mLine2 != null) { if (statusText == null || statusText.length() == 0) { if (Imps.Contacts.TYPE_GROUP == type) { statusText = mContext.getString(R.string.menu_new_group_chat); } else { ImApp app = ((ImApp) ((Activity) mContext).getApplication()); BrandingResources brandingRes = app.getBrandingResource(providerId); statusText = brandingRes.getString(PresenceUtils.getStatusStringRes(presence)); } } mHolder.mLine2.setText(statusText); } if (presence == Imps.Presence.AVAILABLE) { if (mHolder.mAvatar != null) { setBackgroundColor(getResources().getColor(R.color.holo_green_light)); mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_green_dark)); mHolder.mLine1.setTextColor(getResources().getColor(R.color.contact_status_fg_light)); } else if (mHolder.mStatusBlock != null) { mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_green_light)); } } else if (presence == Imps.Presence.AWAY || presence == Imps.Presence.IDLE) { if (mHolder.mAvatar != null) { setBackgroundColor(getResources().getColor(R.color.holo_orange_light)); mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_orange_dark)); mHolder.mLine1.setTextColor(getResources().getColor(R.color.contact_status_fg_light)); } else if (mHolder.mStatusBlock != null) { mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_orange_light)); } } else if (presence == Imps.Presence.DO_NOT_DISTURB) { if (mHolder.mAvatar != null) { setBackgroundColor(getResources().getColor(R.color.holo_red_light)); mHolder.mLine1.setBackgroundColor(getResources().getColor(R.color.holo_red_dark)); mHolder.mLine1.setTextColor(getResources().getColor(R.color.contact_status_fg_light)); } else if (mHolder.mStatusBlock != null) { mHolder.mStatusBlock.setBackgroundColor(getResources().getColor(R.color.holo_red_light)); } } else { if (mHolder.mAvatar != null) { setBackgroundColor(Color.LTGRAY); mHolder.mLine1.setBackgroundColor(Color.LTGRAY); } else if (mHolder.mStatusBlock != null) { mHolder.mStatusBlock.setBackgroundColor(Color.LTGRAY); } } } }
From source file:cw.kop.autobackground.tutorial.AppFragment.java
private void resetFabricText(boolean use) { SpannableString text;/*from w w w . ja v a 2 s . c om*/ if (use) { text = new SpannableString("Thanks!"); text.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.BLUE_OPAQUE)), 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { text = new SpannableString("Send reports?"); } fabricText.setText(text); fabricText.invalidate(); }
From source file:org.jraf.android.dcn.wearable.app.notif.NotificationWearableListenerService.java
private void showNotification(String title, String textShort, String textLong, @Nullable Bitmap photo, Uri contactUri, @Nullable String phoneNumber) { Log.d();//from w w w. j ava 2 s . com NotificationCompat.Builder mainNotifBuilder = new NotificationCompat.Builder(this); // Small icon mainNotifBuilder.setSmallIcon(R.drawable.ic_launcher); // Title SpannableString spannableTitle = new SpannableString(title); Object appearanceSpan = new TextAppearanceSpan(this, R.style.NotificationContentTitleTextAppearance); spannableTitle.setSpan(appearanceSpan, 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mainNotifBuilder.setContentTitle(spannableTitle); // Text (short) -- This may be completely useless since the "big text style" (below) is always used instead SpannableString spannableTextShort = new SpannableString(textShort); appearanceSpan = new TextAppearanceSpan(this, R.style.NotificationContentTextTextAppearance); spannableTextShort.setSpan(appearanceSpan, 0, textShort.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mainNotifBuilder.setContentText(spannableTextShort); // Text (long) SpannableString spannableTextLong = new SpannableString(textLong); appearanceSpan = new TextAppearanceSpan(this, R.style.NotificationContentTextTextAppearance); spannableTextLong.setSpan(appearanceSpan, 0, textLong.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mainNotifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(spannableTextLong)); // Dismiss intent Intent dismissIntent = new Intent(NotificationIntentService.ACTION_DISMISS_NOTIFICATION, null, this, NotificationIntentService.class); PendingIntent dismissPendingIntent = PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); mainNotifBuilder.setDeleteIntent(dismissPendingIntent); // Wear specifics NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); // Contact photo if (photo != null) wearableExtender.setBackground(photo); // Actions if (phoneNumber != null) { // Call action Intent callIntent = new Intent(NotificationIntentService.ACTION_CALL, null, this, NotificationIntentService.class); callIntent.putExtra(NotificationIntentService.EXTRA_PHONE_NUMBER, phoneNumber); PendingIntent callPendingIntent = PendingIntent.getService(this, 0, callIntent, PendingIntent.FLAG_UPDATE_CURRENT); String callText = getString(R.string.notification_action_call); wearableExtender.addAction( new NotificationCompat.Action(R.drawable.ic_action_call_full, callText, callPendingIntent)); // Sms action Intent smsIntent = new Intent(NotificationIntentService.ACTION_SMS, null, this, NotificationIntentService.class); smsIntent.putExtra(NotificationIntentService.EXTRA_PHONE_NUMBER, phoneNumber); PendingIntent smsPendingIntent = PendingIntent.getService(this, 0, smsIntent, PendingIntent.FLAG_UPDATE_CURRENT); String smsText = getString(R.string.notification_action_sms); wearableExtender.addAction( new NotificationCompat.Action(R.drawable.ic_action_sms_full, smsText, smsPendingIntent)); } // 'Show contact' action Intent showContactIntent = new Intent(NotificationIntentService.ACTION_SHOW_CONTACT, null, this, NotificationIntentService.class); showContactIntent.setData(contactUri); PendingIntent showContactPendingIntent = PendingIntent.getService(this, 0, showContactIntent, PendingIntent.FLAG_UPDATE_CURRENT); String showContactText = getString(R.string.notification_action_showContact); wearableExtender.addAction(new NotificationCompat.Action(R.drawable.ic_action_show_contact_full, showContactText, showContactPendingIntent)); // Misc mainNotifBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); // Time sensitive, try to appear on top mainNotifBuilder.setCategory(NotificationCompat.CATEGORY_STATUS); // Not sure if this category is really the most appropriate wearableExtender.setHintScreenTimeout(NotificationCompat.WearableExtender.SCREEN_TIMEOUT_LONG); // Could be useful mainNotifBuilder.extend(wearableExtender); // Show the notification Notification notification = mainNotifBuilder.build(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notification); }
From source file:nz.ac.otago.psyanlab.common.designer.program.operand.RenameOperandDialogueFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments();// www . j a v a 2s. co m if (args != null) { mOperandId = args.getLong(ARG_OPERAND_ID, -1); } if (mOperandId == -1) { throw new RuntimeException("Invalid operand id."); } mOperand = mCallbacks.getOperand(mOperandId); LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.dialogue_rename_variable, null); mName = (EditText) view.findViewById(R.id.name); mName.setText(mOperand.getName()); // Thanks to serwus <http://stackoverflow.com/users/1598308/serwus>, // who posted at <http://stackoverflow.com/a/20325852>. Modified to // support unicode codepoints and validating first character of input. InputFilter filter = new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { boolean keepOriginal = true; StringBuilder sb = new StringBuilder(end - start); int offset = 0; String s = source.toString(); while (offset < s.length()) { final int codePoint = s.codePointAt(offset); if ((offset == 0 && isAllowedAsFirst(codePoint)) || (offset > 0 && isAllowed(codePoint))) { sb.appendCodePoint(codePoint); } else { keepOriginal = false; } offset += Character.charCount(codePoint); } if (keepOriginal) return null; else { if (source instanceof Spanned) { SpannableString sp = new SpannableString(sb); TextUtils.copySpansFrom((Spanned) source, start, sb.length(), null, sp, 0); return sp; } else { return sb; } } } private boolean isAllowed(int codePoint) { return Character.isLetterOrDigit(codePoint); } private boolean isAllowedAsFirst(int codePoint) { return Character.isLetter(codePoint); } }; mName.setFilters(new InputFilter[] { filter }); // Build dialogue. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(getString(R.string.title_rename_variable, mOperand.getName())).setView(view) .setPositiveButton(R.string.action_rename, mPositiveListener) .setNegativeButton(R.string.action_cancel, mNegativeListener); // Create the AlertDialog object and return it Dialog dialog = builder.create(); dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); return dialog; }
From source file:org.anoopam.main.anoopamvideo.VideoCatListActivity.java
@Override public void manageAppBar(ActionBar actionBar, Toolbar toolbar, ActionBarDrawerToggle actionBarDrawerToggle) { actionBar.setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override/*from w w w .j av a 2s.co m*/ public void onClick(View v) { handleBackPress(); } }); toolbar.setTitle(getString(R.string.nav_video_title)); SpannableString spannableString = new SpannableString(albumName); spannableString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spannableString.length(), 0); toolbar.setSubtitle(spannableString); }
From source file:com.github.guwenk.smuradio.SignInDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { builder = new AlertDialog.Builder(getActivity()); View signInDialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_sign_in, null); builder.setView(signInDialogView);//from www .ja v a 2 s. c om builder.setMessage(R.string.upload_your_song); checkBox = (CheckBox) signInDialogView.findViewById(R.id.checkBox2); int currentOrientation = getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } check1 = false; check2 = false; check3 = false; // Log.d(AuthTag, "onCreateDialog " + check1 + " " + check2 + " " + check3); this.mGoogleApiClient = OrderActivity.getmGoogleApiClient(); mAuth = FirebaseAuth.getInstance(); selectFileButton = (Button) signInDialogView.findViewById(R.id.selectFileButton); selectFileButton.setOnClickListener(new customButtonClickListener()); signInButton = (SignInButton) signInDialogView.findViewById(R.id.sign_in_button); signInButton.setStyle(SignInButton.SIZE_WIDE, SignInButton.COLOR_AUTO); signInButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { signIn(); } }); builder.setPositiveButton(getString(R.string.next), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO upload song } }); builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); SpannableString ss = new SpannableString(getString(R.string.you_accepting_license_agreement)); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View textView) { Log.d(AuthTag, "click"); LicenseDialog licenseDialog = new LicenseDialog(); licenseDialog.show(getFragmentManager(), "Sing in dialog"); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(true); } }; ss.setSpan(clickableSpan, 14, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); TextView textView = (TextView) signInDialogView.findViewById(R.id.textView); textView.setText(ss); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setHighlightColor(Color.TRANSPARENT); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { check2 = isChecked; Log.d(AuthTag, "Checked: " + isChecked); buttonStatus(); } }); mStorageRef = FirebaseStorage.getInstance().getReference(); alert = builder.create(); return alert; }
From source file:com.fastbootmobile.encore.app.fragments.ListenNowFragment.java
/** * Default empty constructor//from w ww. java2 s. co m */ public ListenNowFragment() { mScrollListener = new ScrollStatusBarColorListener() { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (view.getChildCount() == 0 || getActivity() == null) { return; } final float heroHeight = mHeaderView.getMeasuredHeight(); final float scrollY = getScroll(view); final float toolbarBgAlpha = Math.min(1, scrollY / heroHeight); final int toolbarAlphaInteger = (((int) (toolbarBgAlpha * 255)) << 24) | 0xFFFFFF; mColorDrawable.setColor(toolbarAlphaInteger & mBackgroundColor); SpannableString spannableTitle = new SpannableString( ((MainActivity) getActivity()).getFragmentTitle()); mAlphaSpan.setAlpha(toolbarBgAlpha); ActionBar actionbar = ((AppActivity) getActivity()).getSupportActionBar(); if (actionbar != null) { actionbar.setBackgroundDrawable(mColorDrawable); spannableTitle.setSpan(mAlphaSpan, 0, spannableTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); actionbar.setTitle(spannableTitle); } mCardSearchBox.setAlpha(1.0f - toolbarBgAlpha); } }; }
From source file:eu.faircode.netguard.AdapterAccess.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { // Get values final int version = cursor.getInt(colVersion); final int protocol = cursor.getInt(colProtocol); final String daddr = cursor.getString(colDaddr); final int dport = cursor.getInt(colDPort); long time = cursor.getLong(colTime); int allowed = cursor.getInt(colAllowed); int block = cursor.getInt(colBlock); int count = cursor.getInt(colCount); long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent); long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived); int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections); // Get views/*from w w w . java 2 s. c o m*/ TextView tvTime = view.findViewById(R.id.tvTime); ImageView ivBlock = view.findViewById(R.id.ivBlock); final TextView tvDest = view.findViewById(R.id.tvDest); LinearLayout llTraffic = view.findViewById(R.id.llTraffic); TextView tvConnections = view.findViewById(R.id.tvConnections); TextView tvTraffic = view.findViewById(R.id.tvTraffic); // Set values tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time)); if (block < 0) ivBlock.setImageDrawable(null); else { ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable()); DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn); } } String dest = Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : "") + (count > 1 ? " ?" + count : ""); SpannableString span = new SpannableString(dest); span.setSpan(new UnderlineSpan(), 0, dest.length(), 0); tvDest.setText(span); if (Util.isNumericAddress(daddr)) new AsyncTask<String, Object, String>() { @Override protected void onPreExecute() { ViewCompat.setHasTransientState(tvDest, true); } @Override protected String doInBackground(String... args) { try { return InetAddress.getByName(args[0]).getHostName(); } catch (UnknownHostException ignored) { return args[0]; } } @Override protected void onPostExecute(String addr) { tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr + (dport > 0 ? "/" + dport : "")); ViewCompat.setHasTransientState(tvDest, false); } }.execute(daddr); if (allowed < 0) tvDest.setTextColor(colorText); else if (allowed > 0) tvDest.setTextColor(colorOn); else tvDest.setTextColor(colorOff); llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE); if (connections > 0) tvConnections.setText(context.getString(R.string.msg_count, connections)); if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L) tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0), (received > 0 ? received / (1024 * 1024 * 1024f) : 0))); else if (sent > 1204 * 1024L || received > 1024 * 1024L) tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0), (received > 0 ? received / (1024 * 1024f) : 0))); else tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0), (received > 0 ? received / 1024f : 0))); }