List of usage examples for android.text SpannableString setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:cw.kop.autobackground.tutorial.FinishFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tutorial_finish_fragment, container, false); int colorFilterInt = AppSettings.getColorFilterInt(appContext); TextView titleText = (TextView) view.findViewById(R.id.title_text); titleText.setTextColor(colorFilterInt); titleText.setText("That's it."); TextView tutorialText = (TextView) view.findViewById(R.id.tutorial_text); tutorialText.setTextColor(colorFilterInt); tutorialText.setText("Now you're ready to use AutoBackground. I'd suggest adding a new source first " + "and then hitting download." + "\n" + "\n" + "If you have any questions, concerns, suggestions, or whatever else, feel free to " + "email me at "); SpannableString emailString = new SpannableString("chiuwinson@gmail.com"); ClickableSpan clickableSpan = new ClickableSpan() { @Override/*from w ww .j a v a 2 s .c o m*/ public void onClick(View widget) { Log.i(TAG, "Clicked"); Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "chiuwinson@gmail.com", null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "AutoBackground Feedback"); startActivity(Intent.createChooser(emailIntent, "Send email")); } }; emailString.setSpan(clickableSpan, 0, emailString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); tutorialText.append(emailString); tutorialText.append("."); tutorialText.setMovementMethod(LinkMovementMethod.getInstance()); return view; }
From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java
public static void fillThreadsListItemView(int position, View view, ThingInfo item, ListActivity activity, HttpClient client, RedditSettings settings, ThumbnailOnClickListenerFactory thumbnailOnClickListenerFactory) { Resources res = activity.getResources(); TextView titleView = (TextView) view.findViewById(R.id.title); TextView votesView = (TextView) view.findViewById(R.id.votes); TextView numCommentsSubredditView = (TextView) view.findViewById(R.id.numCommentsSubreddit); TextView nsfwView = (TextView) view.findViewById(R.id.nsfw); // TextView submissionTimeView = (TextView) view.findViewById(R.id.submissionTime); ImageView voteUpView = (ImageView) view.findViewById(R.id.vote_up_image); ImageView voteDownView = (ImageView) view.findViewById(R.id.vote_down_image); View thumbnailContainer = view.findViewById(R.id.thumbnail_view); FrameLayout thumbnailFrame = (FrameLayout) view.findViewById(R.id.thumbnail_frame); ImageView thumbnailImageView = (ImageView) view.findViewById(R.id.thumbnail); ProgressBar indeterminateProgressBar = (ProgressBar) view.findViewById(R.id.indeterminate_progress); // Set the title and domain using a SpannableStringBuilder SpannableStringBuilder builder = new SpannableStringBuilder(); String title = item.getTitle(); if (title == null) title = ""; SpannableString titleSS = new SpannableString(title); int titleLen = title.length(); titleSS.setSpan( new TextAppearanceSpan(activity, Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Large)), 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); String domain = item.getDomain(); if (domain == null) domain = ""; int domainLen = domain.length(); SpannableString domainSS = new SpannableString("(" + item.getDomain() + ")"); domainSS.setSpan(/*from ww w . j a v a 2s. co m*/ new TextAppearanceSpan(activity, Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Small)), 0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (Util.isLightTheme(settings.getTheme())) { if (item.isClicked()) { ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.purple)); titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.blue)); titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_50)), 0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { if (item.isClicked()) { ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.gray_50)); titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_75)), 0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } builder.append(titleSS).append(" ").append(domainSS); titleView.setText(builder); votesView.setText("" + item.getScore()); numCommentsSubredditView.setText(Util.showNumComments(item.getNum_comments()) + " " + item.getSubreddit()); if (item.isOver_18()) { nsfwView.setVisibility(View.VISIBLE); } else { nsfwView.setVisibility(View.GONE); } // Set the up and down arrow colors based on whether user likes if (settings.isLoggedIn()) { if (item.getLikes() == null) { voteUpView.setImageResource(R.drawable.vote_up_gray); voteDownView.setImageResource(R.drawable.vote_down_gray); votesView.setTextColor(res.getColor(R.color.gray_75)); } else if (item.getLikes() == true) { voteUpView.setImageResource(R.drawable.vote_up_red); voteDownView.setImageResource(R.drawable.vote_down_gray); votesView.setTextColor(res.getColor(R.color.arrow_red)); } else { voteUpView.setImageResource(R.drawable.vote_up_gray); voteDownView.setImageResource(R.drawable.vote_down_blue); votesView.setTextColor(res.getColor(R.color.arrow_blue)); } } else { voteUpView.setImageResource(R.drawable.vote_up_gray); voteDownView.setImageResource(R.drawable.vote_down_gray); votesView.setTextColor(res.getColor(R.color.gray_75)); } // Thumbnails open links if (thumbnailContainer != null) { if (Common.shouldLoadThumbnails(activity, settings)) { thumbnailContainer.setVisibility(View.VISIBLE); if (item.getUrl() != null) { OnClickListener thumbnailOnClickListener = thumbnailOnClickListenerFactory .getThumbnailOnClickListener(item, activity); if (thumbnailOnClickListener != null) { thumbnailFrame.setOnClickListener(thumbnailOnClickListener); } } // Show thumbnail based on ThingInfo if ("default".equals(item.getThumbnail()) || "self".equals(item.getThumbnail()) || StringUtils.isEmpty(item.getThumbnail())) { indeterminateProgressBar.setVisibility(View.GONE); thumbnailImageView.setVisibility(View.VISIBLE); thumbnailImageView.setImageResource(R.drawable.go_arrow); } else { indeterminateProgressBar.setVisibility(View.GONE); thumbnailImageView.setVisibility(View.VISIBLE); if (item.getThumbnailBitmap() != null) { thumbnailImageView.setImageBitmap(item.getThumbnailBitmap()); } else { thumbnailImageView.setImageBitmap(null); new ShowThumbnailsTask(activity, client, R.drawable.go_arrow) .execute(new ThumbnailLoadAction(item, thumbnailImageView, position)); } } // Set thumbnail background based on current theme if (Util.isLightTheme(settings.getTheme())) thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_light); else thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_dark); } else { // if thumbnails disabled, hide thumbnail icon thumbnailContainer.setVisibility(View.GONE); } } }
From source file:com.todoroo.astrid.tags.TagsControlSet.java
private Function<TagData, SpannableString> tagToString(final float maxLength) { return tagData -> { String tagName = tagData.getName(); tagName = tagName.substring(0, Math.min(tagName.length(), (int) maxLength)).replace(' ', NO_BREAK_SPACE);//from ww w. ja v a2 s . c o m SpannableString string = new SpannableString(NO_BREAK_SPACE + tagName + NO_BREAK_SPACE); int themeIndex = tagData.getColor(); ThemeColor color = themeIndex >= 0 ? themeCache.getThemeColor(themeIndex) : themeCache.getUntaggedColor(); string.setSpan(new BackgroundColorSpan(color.getPrimaryColor()), 0, string.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); string.setSpan(new ForegroundColorSpan(color.getActionBarTint()), 0, string.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return string; }; }
From source file:tw.com.geminihsu.app01.fragment.Fragment_Client_Service.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem item = menu.add(Menu.NONE, ACTIONBAR_MENU_ITEM_FIILTER, Menu.NONE, getString(R.string.order_call_taxi_page_title)); SpannableString spanString = new SpannableString(item.getTitle().toString()); spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0); //fix the color to white item.setTitle(spanString);/*from w w w .j a v a 2s . c om*/ if (isShowOneKey) item.setVisible(true); else item.setVisible(false); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); super.onCreateOptionsMenu(menu, inflater); }
From source file:org.awesomeapp.messenger.ui.ConversationListItem.java
/** public void bind(ConversationViewHolder holder, Cursor cursor, String underLineText, boolean scrolling) { bind(holder, cursor, underLineText, true, scrolling); }/*from w w w . j av a 2s . c o m*/ */ public void bind(ConversationViewHolder holder, long contactId, long providerId, long accountId, String address, String nickname, int contactType, String message, long messageDate, int presence, String underLineText, boolean showChatMsg, boolean scrolling) { //applyStyleColors(holder); if (nickname == null) { nickname = address.split("@")[0].split("\\.")[0]; } else { nickname = nickname.split("@")[0].split("\\.")[0]; } if (Imps.Contacts.TYPE_GROUP == contactType) { String groupCountString = getGroupCount(getContext().getContentResolver(), contactId); nickname += groupCountString; } 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); holder.mLine1.setText(str); } else holder.mLine1.setText(nickname); } else holder.mLine1.setText(nickname); holder.mStatusIcon.setVisibility(View.GONE); if (holder.mAvatar != null) { if (Imps.Contacts.TYPE_GROUP == contactType) { holder.mAvatar.setVisibility(View.VISIBLE); if (AVATAR_DEFAULT_GROUP == null) AVATAR_DEFAULT_GROUP = new RoundedAvatarDrawable( BitmapFactory.decodeResource(getResources(), R.drawable.group_chat)); holder.mAvatar.setImageDrawable(AVATAR_DEFAULT_GROUP); } // else if (cursor.getColumnIndex(Imps.Contacts.AVATAR_DATA)!=-1) else { // holder.mAvatar.setVisibility(View.GONE); Drawable avatar = null; try { avatar = DatabaseUtils.getAvatarFromAddress(this.getContext().getContentResolver(), address, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT); // avatar = DatabaseUtils.getAvatarFromCursor(cursor, COLUMN_AVATAR_DATA, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT); } catch (Exception e) { //problem decoding avatar Log.e(ImApp.LOG_TAG, "error decoding avatar", e); } try { if (avatar != null) { //if (avatar instanceof RoundedAvatarDrawable) // setAvatarBorder(presence,(RoundedAvatarDrawable)avatar); holder.mAvatar.setImageDrawable(avatar); } else { // int color = getAvatarBorder(presence); int padding = 24; LetterAvatar lavatar = new LetterAvatar(getContext(), nickname, padding); holder.mAvatar.setImageDrawable(lavatar); } holder.mAvatar.setVisibility(View.VISIBLE); } catch (OutOfMemoryError ome) { //this seems to happen now and then even on tiny images; let's catch it and just not set an avatar } } } if (showChatMsg && message != null) { if (holder.mLine2 != null) { if (SecureMediaStore.isVfsUri(message)) { FileInfo fInfo = SystemServices.getFileInfoFromURI(getContext(), Uri.parse(message)); if (fInfo.type == null || fInfo.type.startsWith("image")) { if (holder.mMediaThumb != null) { holder.mMediaThumb.setVisibility(View.VISIBLE); if (fInfo.type != null && fInfo.type.equals("image/png")) { holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER); } else { holder.mMediaThumb.setScaleType(ImageView.ScaleType.CENTER_CROP); } setThumbnail(getContext().getContentResolver(), holder, Uri.parse(message)); holder.mLine2.setVisibility(View.GONE); } } else { holder.mLine2.setText(""); } } else if ((!TextUtils.isEmpty(message)) && message.startsWith("/")) { String cmd = message.toString().substring(1); if (cmd.startsWith("sticker")) { String[] cmds = cmd.split(":"); String mimeTypeSticker = "image/png"; Uri mediaUri = Uri.parse("asset://" + cmds[1]); setThumbnail(getContext().getContentResolver(), holder, mediaUri); holder.mLine2.setVisibility(View.GONE); holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER); } } else if ((!TextUtils.isEmpty(message)) && message.startsWith(":")) { String[] cmds = message.split(":"); try { String[] stickerParts = cmds[1].split("-"); String stickerPath = "stickers/" + stickerParts[0].toLowerCase() + "/" + stickerParts[1].toLowerCase() + ".png"; //make sure sticker exists AssetFileDescriptor afd = getContext().getAssets().openFd(stickerPath); afd.getLength(); afd.close(); //now setup the new URI for loading local sticker asset Uri mediaUri = Uri.parse("asset://localhost/" + stickerPath); setThumbnail(getContext().getContentResolver(), holder, mediaUri); holder.mLine2.setVisibility(View.GONE); holder.mMediaThumb.setScaleType(ImageView.ScaleType.FIT_CENTER); } catch (Exception e) { } } else { if (holder.mMediaThumb != null) holder.mMediaThumb.setVisibility(View.GONE); holder.mLine2.setVisibility(View.VISIBLE); try { holder.mLine2.setText(android.text.Html.fromHtml(message).toString()); } catch (RuntimeException re) { } } } if (messageDate != -1) { Date dateLast = new Date(messageDate); holder.mStatusText.setText(sPrettyTime.format(dateLast)); } else { holder.mStatusText.setText(""); } } else if (holder.mLine2 != null) { holder.mLine2.setText(address); if (holder.mMediaThumb != null) holder.mMediaThumb.setVisibility(View.GONE); } holder.mLine1.setVisibility(View.VISIBLE); if (providerId != -1) getEncryptionState(providerId, accountId, address, holder); }
From source file:io.github.hidroh.materialistic.data.HackerNewsItem.java
@Override public Spannable getDisplayedTime(Context context) { if (displayedTime == null) { SpannableStringBuilder builder = new SpannableStringBuilder( dead ? context.getString(R.string.dead_prefix) + " " : ""); SpannableString timeSpannable = new SpannableString(AppUtils.getAbbreviatedTimeSpan(time * 1000)); if (deleted) { timeSpannable.setSpan(new StrikethroughSpan(), 0, timeSpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }/*from ww w. ja v a 2s. c o m*/ builder.append(timeSpannable); displayedTime = builder; } return displayedTime; }
From source file:org.lytsing.android.weibo.ui.ComposeActivity.java
private void initGridView() { mGVFaceAdapter = new GridViewFaceAdapter(this); mGridView = (GridView) findViewById(R.id.tweet_pub_faces); mGridView.setAdapter(mGVFaceAdapter); mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // ?/* w w w . ja va 2s. c om*/ SpannableString ss = new SpannableString(view.getTag().toString()); Drawable d = getResources().getDrawable((int) mGVFaceAdapter.getItemId(position)); d.setBounds(0, 0, 35, 35);//? ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM); ss.setSpan(span, 0, view.getTag().toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // ? mEdit.getText().insert(mEdit.getSelectionStart(), ss); } }); }
From source file:it.gulch.linuxday.android.services.AlarmIntentService.java
private void notifyEvent(Intent intent) { long eventId = Long.parseLong(intent.getDataString()); Event event = eventManager.get(eventId); if (event == null) { return;/* w ww .jav a 2s .c om*/ } // NotificationManager notificationManager = (NotificationManager) getSystemService(Context // .NOTIFICATION_SERVICE); // PendingIntent eventPendingIntent = // TaskStackBuilder.create(this).addNextIntent(new Intent(this, // MainActivity.class)).addNextIntent( // new Intent(this, EventDetailsActivity.class).setData(Uri.parse(String.valueOf(event // .getId())))) // .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent eventPendingIntent = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MainActivity.class)) .addNextIntent(new Intent(this, EventDetailsActivity.class) .setData(Uri.parse(String.valueOf(event.getId())))) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); int defaultFlags = Notification.DEFAULT_SOUND; SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); if (sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_NOTIFICATIONS_VIBRATE, false)) { defaultFlags |= Notification.DEFAULT_VIBRATE; } String trackName = event.getTrack().getTitle(); CharSequence bigText; String contentText; if (CollectionUtils.isEmpty(event.getPeople())) { contentText = trackName; bigText = event.getSubtitle(); } else { String personsSummary = StringUtils.join(event.getPeople(), ", "); contentText = String.format("%1$s - %2$s", trackName, personsSummary); String subTitle = event.getSubtitle(); SpannableString spannableBigText; if (TextUtils.isEmpty(subTitle)) { spannableBigText = new SpannableString(personsSummary); } else { spannableBigText = new SpannableString(String.format("%1$s\n%2$s", subTitle, personsSummary)); } // Set the persons summary in italic spannableBigText.setSpan(new StyleSpan(Typeface.ITALIC), +spannableBigText.length() - personsSummary.length(), spannableBigText.length(), +Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); bigText = spannableBigText; } String roomName = event.getTrack().getRoom().getName(); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setWhen(event.getStartDate().getTime()) .setContentTitle(event.getTitle()).setContentText(contentText) .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(trackName)) .setContentInfo(roomName).setContentIntent(eventPendingIntent).setAutoCancel(true) .setDefaults(defaultFlags).setPriority(NotificationCompat.PRIORITY_HIGH); // Blink the LED with FOSDEM color if enabled in the options if (sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_NOTIFICATIONS_LED, false)) { notificationBuilder.setLights(getResources().getColor(R.color.maincolor), 1000, 5000); } /*// Android Wear extensions NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); // Add an optional action button to show the room map image int roomImageResId = getResources() .getIdentifier(StringUtils.roomNameToResourceName(roomName), "drawable", getPackageName()); if(roomImageResId != 0) { // The room name is the unique Id of a RoomImageDialogActivity Intent mapIntent = new Intent(this, RoomImageDialogActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setData(Uri.parse(roomName)); mapIntent.putExtra(RoomImageDialogActivity.EXTRA_ROOM_NAME, roomName); mapIntent.putExtra(RoomImageDialogActivity.EXTRA_ROOM_IMAGE_RESOURCE_ID, roomImageResId); PendingIntent mapPendingIntent = PendingIntent.getActivity(this, 0, mapIntent, PendingIntent.FLAG_UPDATE_CURRENT); CharSequence mapTitle = getString(R.string.room_map); notificationBuilder .addAction(new NotificationCompat.Action(R.drawable.ic_action_place, mapTitle, mapPendingIntent)); // Use bigger action icon for wearable notification wearableExtender.addAction( new NotificationCompat.Action(R.drawable.ic_place_white_wear, mapTitle, mapPendingIntent)); } notificationBuilder.extend(wearableExtender);*/ NotificationManagerCompat.from(this).notify((int) eventId, notificationBuilder.build()); }
From source file:piuk.blockchain.android.ui.dialogs.TransactionSummaryDialog.java
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { super.onCreateDialog(savedInstanceState); final FragmentActivity activity = getActivity(); final LayoutInflater inflater = LayoutInflater.from(activity); final Builder dialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.Theme_Dialog)) .setTitle(R.string.transaction_summary_title); final LinearLayout view = (LinearLayout) inflater.inflate(R.layout.transaction_summary_fragment, null); dialog.setView(view);//from w w w . jav a 2 s.co m try { final MyRemoteWallet wallet = application.getRemoteWallet(); BigInteger totalOutputValue = BigInteger.ZERO; for (TransactionOutput output : tx.getOutputs()) { totalOutputValue = totalOutputValue.add(output.getValue()); } final TextView resultDescriptionView = (TextView) view.findViewById(R.id.result_description); final TextView toView = (TextView) view.findViewById(R.id.transaction_to); final TextView toViewLabel = (TextView) view.findViewById(R.id.transaction_to_label); final View toViewContainer = (View) view.findViewById(R.id.transaction_to_container); final TextView hashView = (TextView) view.findViewById(R.id.transaction_hash); final TextView transactionTimeView = (TextView) view.findViewById(R.id.transaction_date); final TextView confirmationsView = (TextView) view.findViewById(R.id.transaction_confirmations); final TextView noteView = (TextView) view.findViewById(R.id.transaction_note); final Button addNoteButton = (Button) view.findViewById(R.id.add_note_button); final TextView feeView = (TextView) view.findViewById(R.id.transaction_fee); final View feeViewContainer = view.findViewById(R.id.transaction_fee_container); final TextView valueNowView = (TextView) view.findViewById(R.id.transaction_value); final View valueNowContainerView = view.findViewById(R.id.transaction_value_container); String to = null; for (TransactionOutput output : tx.getOutputs()) { try { String toAddress = output.getScriptPubKey().getToAddress().toString(); if (!wallet.isAddressMine(toAddress)) { to = toAddress; } } catch (Exception e) { e.printStackTrace(); } } String from = null; for (TransactionInput input : tx.getInputs()) { try { String fromAddress = input.getFromAddress().toString(); if (!wallet.isAddressMine(fromAddress)) { from = fromAddress; } } catch (Exception e) { e.printStackTrace(); } } long realResult = 0; int confirmations = 0; if (tx instanceof MyTransaction) { MyTransaction myTx = (MyTransaction) tx; realResult = myTx.getResult().longValue(); if (wallet.getLatestBlock() != null) { confirmations = wallet.getLatestBlock().getHeight() - myTx.getHeight() + 1; } } else if (application.isInP2PFallbackMode()) { realResult = tx.getValue(application.bitcoinjWallet).longValue(); if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) confirmations = tx.getConfidence().getDepthInBlocks(); } final long finalResult = realResult; if (realResult <= 0) { toViewLabel.setText(R.string.transaction_fragment_to); if (to == null) { ((LinearLayout) toViewContainer.getParent()).removeView(toViewContainer); } else { toView.setText(to); } } else { toViewLabel.setText(R.string.transaction_fragment_from); if (from == null) { ((LinearLayout) toViewContainer.getParent()).removeView(toViewContainer); } else { toView.setText(from); } } //confirmations view if (confirmations > 0) { confirmationsView.setText("" + confirmations); } else { confirmationsView.setText("Unconfirmed"); } //Hash String view final String hashString = new String(Hex.encode(tx.getHash().getBytes()), "UTF-8"); hashView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https:/" + Constants.BLOCKCHAIN_DOMAIN + "/tx/" + hashString)); startActivity(browserIntent); } }); //Notes View String note = wallet.getTxNotes().get(hashString); if (note == null) { addNoteButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dismiss(); AddNoteDialog.showDialog(getFragmentManager(), hashString); } }); view.removeView(noteView); } else { view.removeView(addNoteButton); noteView.setText(note); noteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dismiss(); AddNoteDialog.showDialog(getFragmentManager(), hashString); } }); } addNoteButton.setEnabled(!application.isInP2PFallbackMode()); SpannableString content = new SpannableString(hashString); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); hashView.setText(content); if (realResult > 0 && from != null) resultDescriptionView.setText(this.getString(R.string.transaction_fragment_amount_you_received, WalletUtils.formatValue(BigInteger.valueOf(realResult)))); else if (realResult < 0 && to != null) resultDescriptionView.setText(this.getString(R.string.transaction_fragment_amount_you_sent, WalletUtils.formatValue(BigInteger.valueOf(realResult)))); else resultDescriptionView.setText(this.getString(R.string.transaction_fragment_amount_you_moved, WalletUtils.formatValue(totalOutputValue))); final Date time = tx.getUpdateTime(); transactionTimeView.setText(dateFormat.format(time)); //These will be made visible again later once information is fetched from server feeViewContainer.setVisibility(View.GONE); valueNowContainerView.setVisibility(View.GONE); if (tx instanceof MyTransaction) { MyTransaction myTx = (MyTransaction) tx; final long txIndex = myTx.getTxIndex(); final Handler handler = new Handler(); new Thread(new Runnable() { @Override public void run() { try { final JSONObject obj = getTransactionSummary(txIndex, wallet.getGUID(), finalResult); handler.post(new Runnable() { @Override public void run() { try { if (obj.get("fee") != null) { feeViewContainer.setVisibility(View.VISIBLE); feeView.setText(WalletUtils.formatValue( BigInteger.valueOf(Long.valueOf(obj.get("fee").toString()))) + " BTC"); } if (obj.get("confirmations") != null) { int confirmations = ((Number) obj.get("confirmations")).intValue(); confirmationsView.setText("" + confirmations); } String result_local = (String) obj.get("result_local"); String result_local_historical = (String) obj .get("result_local_historical"); if (result_local != null && result_local.length() > 0) { valueNowContainerView.setVisibility(View.VISIBLE); if (result_local_historical == null || result_local_historical.length() == 0 || result_local_historical.equals(result_local)) { valueNowView.setText(result_local); } else { valueNowView.setText(getString(R.string.value_now_ten, result_local, result_local_historical)); } } } catch (Exception e) { e.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } } }).start(); } } catch (Exception e) { e.printStackTrace(); } Dialog d = dialog.create(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.dimAmount = 0; lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; d.show(); d.getWindow().setAttributes(lp); d.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); return d; }
From source file:uk.co.ashtonbrsc.intentexplode.Explode.java
private void addTextToLayout(String text, int typeface, int paddingLeft, LinearLayout layout) { TextView textView = new TextView(this); ParagraphStyle style_para = new LeadingMarginSpan.Standard(0, (int) (STANDARD_INDENT_SIZE_IN_DIP * density)); SpannableString styledText = new SpannableString(text); styledText.setSpan(style_para, 0, styledText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); textView.setText(styledText);//from w ww .j a v a2s. co m textView.setTextAppearance(this, R.style.TextFlags); textView.setTypeface(null, typeface); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params.setMargins((int) (paddingLeft * density), 0, 0, 0); layout.addView(textView, params); }