List of usage examples for android.text Html fromHtml
@Deprecated public static Spanned fromHtml(String source)
From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java
@SuppressWarnings("deprecation") public void displaydata(final AccountData result, boolean fromcache) { if (getActivity() == null) { return;/* ww w.jav a2s. co m*/ } svAccount.setVisibility(View.VISIBLE); llLoading.setVisibility(View.GONE); unsupportedErrorView.setVisibility(View.GONE); answerErrorView.setVisibility(View.GONE); errorView.removeAllViews(); this.fromcache = fromcache; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(app.getApplicationContext()); final int tolerance = Integer.parseInt(sp.getString("notification_warning", "3")); tvAccLabel.setText(account.getLabel()); tvAccUser.setText(account.getName()); Library lib; try { lib = app.getLibrary(account.getLibrary()); tvAccCity.setText(lib.getDisplayName()); } catch (IOException e) { ErrorReporter.handleException(e); e.printStackTrace(); } catch (JSONException e) { ErrorReporter.handleException(e); } /* Lent items */ llLent.removeAllViews(); final boolean notification_on = sp.getBoolean(SyncAccountAlarmListener.PREF_SYNC_SERVICE, false); boolean notification_problems = false; if (tvWarning != null) { if (result.getWarning() != null && result.getWarning().length() > 1) { tvWarning.setVisibility(View.VISIBLE); tvWarning.setText(result.getWarning()); } else { tvWarning.setVisibility(View.GONE); } } if (result.getLent().size() == 0) { TextView t1 = new TextView(getActivity()); t1.setText(R.string.entl_none); llLent.addView(t1); tvLentHeader.setText(getActivity().getString(R.string.lent_head) + " (0)"); } else { tvLentHeader .setText(getActivity().getString(R.string.lent_head) + " (" + result.getLent().size() + ")"); lentManager = new ExpandingCardListManager(getActivity(), llLent) { @Override public View getView(final int position, ViewGroup container) { final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_lent, container, false); LentViewHolder holder = new LentViewHolder(); holder.findViews(v); final LentItem item = result.getLent().get(position); // Expanding and closing details v.setClickable(true); v.setFocusable(true); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getExpandedPosition() != position) { expand(position); } else { collapse(); } } }); if (item.getId() != null) { // Connection to detail view holder.ivDetails.setOnClickListener(new OnClickListener() { @Override public void onClick(View clicked) { Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class); intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId()); ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v, v.getLeft(), v.getTop(), v.getWidth(), v.getHeight()); ActivityCompat.startActivity(getActivity(), intent, options.toBundle()); } }); holder.hasDetailLink = true; } // Overview (Title/Author, Status/Deadline) if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { holder.tvTitleAndAuthor.setText(item.getTitle()); } else { setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor); } DateTimeFormatter fmt = DateTimeFormat.shortDate(); if (item.getDeadline() != null && item.getStatus() != null) { holder.tvStatus.setText( fmt.print(item.getDeadline()) + " (" + Html.fromHtml(item.getStatus()) + ")"); } else if (item.getDeadline() != null) { holder.tvStatus.setText(fmt.print(new LocalDate(item.getDeadline()))); } else { setHtmlTextOrHide(item.getStatus(), holder.tvStatus); } // Detail setTextOrHide(item.getAuthor(), holder.tvAuthorDetail); setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail); if (item.getLendingBranch() != null && item.getHomeBranch() != null) { holder.tvBranchDetail .setText(Html.fromHtml(item.getLendingBranch() + " / " + item.getHomeBranch())); } else if (item.getLendingBranch() != null) { holder.tvBranchDetail.setText(Html.fromHtml(item.getLendingBranch())); } else { setHtmlTextOrHide(item.getHomeBranch(), holder.tvBranchDetail); } // Color codes for return dates if (item.getDeadline() != null) { if (item.getDeadline().equals(LocalDate.now()) || item.getDeadline().isBefore(LocalDate.now())) { holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_overdue)); } else if (Days.daysBetween(LocalDate.now(), item.getDeadline()).getDays() <= tolerance) { holder.vStatusColor.setBackgroundColor(getResources().getColor(R.color.date_warning)); } else if (item.getDownloadData() != null) { holder.vStatusColor .setBackgroundColor(getResources().getColor(R.color.account_downloadable)); } } else if (item.getDownloadData() != null) { holder.vStatusColor .setBackgroundColor(getResources().getColor(R.color.account_downloadable)); } if (item.getProlongData() != null) { holder.ivProlong.setTag(item.getProlongData()); holder.ivProlong.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { prolong((String) arg0.getTag()); } }); holder.ivProlong.setVisibility(View.VISIBLE); holder.ivProlong.setAlpha(item.isRenewable() ? 255 : 100); } else if (item.getDownloadData() != null && app.getApi() instanceof EbookServiceApi) { holder.ivDownload.setTag(item.getDownloadData()); holder.ivDownload.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { download((String) arg0.getTag()); } }); holder.ivProlong.setVisibility(View.GONE); holder.ivDownload.setVisibility(View.VISIBLE); } else { holder.ivProlong.setVisibility(View.INVISIBLE); } v.setTag(holder); return v; } @Override public void expandView(int position, View view) { LentViewHolder holder = (LentViewHolder) view.getTag(); LentItem item = result.getLent().get(position); holder.llDetails.setVisibility(View.VISIBLE); setHtmlTextOrHide(item.getTitle(), holder.tvTitleAndAuthor); if (holder.hasDetailLink) holder.ivDetails.setVisibility(View.VISIBLE); } @Override public void collapseView(int position, View view) { LentViewHolder holder = (LentViewHolder) view.getTag(); LentItem item = result.getLent().get(position); holder.llDetails.setVisibility(View.GONE); if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getAuthor()); holder.tvTitleAndAuthor.setVisibility(View.VISIBLE); } holder.ivDetails.setVisibility(View.GONE); } @Override public int getCount() { return result.getLent().size(); } }; lentManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() { private float llDataY; private float llDataTranslationY = 0; @Override public void beforeExpand(View unexpandedView) { LentViewHolder holder = (LentViewHolder) unexpandedView.getTag(); llDataY = ViewHelper.getY(holder.llData); } @Override public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) { LentViewHolder holder = (LentViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(-heightDifference, 0); // Animate buttons to the side int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0)); // Animate llData to the bottom if required if (ViewHelper.getY(holder.llData) != llDataY) { ViewHelper.setY(holder.llData, llDataY); llDataTranslationY = ViewHelper.getTranslationY(holder.llData); anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0)); } else { llDataTranslationY = 0; } return anims; } @Override public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) { LentViewHolder holder = (LentViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(0, heightDifference); // Animate buttons back int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference)); // Animate llData back anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY)); return anims; } @Override public void onCollapseAnimationEnd() { if (view.findViewById(R.id.rlMeta) != null) { // tablet ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0); } else { // phone ViewHelper.setTranslationY(tvResHeader, 0); ViewHelper.setTranslationY(llRes, 0); ViewHelper.setTranslationY(tvAge, 0); ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0); } } private Collection<Animator> getAnimations(float from, float to) { List<Animator> animators = new ArrayList<>(); if (view.findViewById(R.id.rlMeta) != null) { // tablet if (result.getLent().size() >= result.getReservations().size()) { animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY", from, to)); } } else { // phone animators.add(ObjectAnimator.ofFloat(tvResHeader, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(llRes, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY", from, to)); } return animators; } }); for (final LentItem item : result.getLent()) { try { if (notification_on && item.getDeadline() == null && !item.isEbook()) { notification_problems = true; } } catch (Exception e) { notification_problems = true; } } } if (notification_problems) { if (tvError != null) { tvError.setVisibility(View.VISIBLE); tvError.setText(R.string.notification_problems); } } /* Reservations */ llRes.removeAllViews(); if (result.getReservations().size() == 0) { TextView t1 = new TextView(getActivity()); t1.setText(R.string.reservations_none); llRes.addView(t1); tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " (0)"); } else { tvResHeader.setText(getActivity().getString(R.string.reservations_head) + " (" + result.getReservations().size() + ")"); resManager = new ExpandingCardListManager(getActivity(), llRes) { @Override public View getView(final int position, ViewGroup container) { final View v = getLayoutInflater(null).inflate(R.layout.listitem_account_reservation, llRes, false); ReservationViewHolder holder = new ReservationViewHolder(); holder.findViews(v); final ReservedItem item = result.getReservations().get(position); // Expanding and closing details v.setClickable(true); v.setFocusable(true); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getExpandedPosition() != position) { expand(position); } else { collapse(); } } }); if (item.getId() != null) { // Connection to detail view holder.ivDetails.setOnClickListener(new OnClickListener() { @Override public void onClick(View clicked) { Intent intent = new Intent(getActivity(), SearchResultDetailActivity.class); intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, item.getId()); ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(v, v.getLeft(), v.getTop(), v.getWidth(), v.getHeight()); ActivityCompat.startActivity(getActivity(), intent, options.toBundle()); } }); holder.hasDetailLink = true; } // Overview (Title/Author, Ready/Expire) if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { holder.tvTitleAndAuthor.setText(item.getTitle()); } else { setTextOrHide(item.getAuthor(), holder.tvTitleAndAuthor); } DateTimeFormatter fmt = DateTimeFormat.shortDate(); StringBuilder status = new StringBuilder(); if (item.getStatus() != null) status.append(item.getStatus()); boolean needsBraces = item.getStatus() != null && (item.getReadyDate() != null || item.getExpirationDate() != null); if (needsBraces) status.append(" ("); if (item.getReadyDate() != null) { status.append(getString(R.string.reservation_expire_until)).append(" ") .append(fmt.print(item.getReadyDate())); } if (item.getExpirationDate() != null) { if (item.getReadyDate() != null) status.append(", "); status.append(fmt.print(item.getExpirationDate())); } if (needsBraces) status.append(")"); if (status.length() > 0) { holder.tvStatus.setText(Html.fromHtml(status.toString())); } else { holder.tvStatus.setVisibility(View.GONE); } // Detail setTextOrHide(item.getAuthor(), holder.tvAuthorDetail); setHtmlTextOrHide(item.getFormat(), holder.tvFormatDetail); setHtmlTextOrHide(item.getBranch(), holder.tvBranchDetail); if (item.getBookingData() != null) { holder.ivBooking.setTag(item.getBookingData()); holder.ivBooking.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { bookingStart((String) arg0.getTag()); } }); holder.ivBooking.setVisibility(View.VISIBLE); holder.ivCancel.setVisibility(View.GONE); } else if (item.getCancelData() != null) { holder.ivCancel.setTag(item.getCancelData()); holder.ivCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { cancel((String) arg0.getTag()); } }); holder.ivCancel.setVisibility(View.VISIBLE); holder.ivBooking.setVisibility(View.GONE); } else { holder.ivCancel.setVisibility(View.INVISIBLE); holder.ivBooking.setVisibility(View.GONE); } v.setTag(holder); return v; } @Override public void expandView(int position, View view) { ReservationViewHolder holder = (ReservationViewHolder) view.getTag(); ReservedItem item = result.getReservations().get(position); holder.llDetails.setVisibility(View.VISIBLE); setTextOrHide(item.getTitle(), holder.tvTitleAndAuthor); if (holder.hasDetailLink) holder.ivDetails.setVisibility(View.VISIBLE); } @Override public void collapseView(int position, View view) { ReservationViewHolder holder = (ReservationViewHolder) view.getTag(); ReservedItem item = result.getReservations().get(position); holder.llDetails.setVisibility(View.GONE); if (item.getTitle() != null && item.getAuthor() != null) { holder.tvTitleAndAuthor.setText(item.getTitle() + ", " + item.getAuthor()); } else if (item.getTitle() != null) { holder.tvTitleAndAuthor.setText(item.getAuthor()); holder.tvTitleAndAuthor.setVisibility(View.VISIBLE); } holder.ivDetails.setVisibility(View.GONE); } @Override public int getCount() { return result.getReservations().size(); } }; resManager.setAnimationInterceptor(new ExpandingCardListManager.AnimationInterceptor() { private float llDataY; private float llDataTranslationY = 0; @Override public void beforeExpand(View unexpandedView) { ReservationViewHolder holder = (ReservationViewHolder) unexpandedView.getTag(); llDataY = ViewHelper.getY(holder.llData); } @Override public Collection<Animator> getExpandAnimations(int heightDifference, View expandedView) { ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(-heightDifference, 0); // Animate buttons to the side int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", difference, 0)); // Animate llData to the bottom if required if (ViewHelper.getY(holder.llData) != llDataY) { ViewHelper.setY(holder.llData, llDataY); llDataTranslationY = ViewHelper.getTranslationY(holder.llData); anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", 0)); } else { llDataTranslationY = 0; } return anims; } @Override public Collection<Animator> getCollapseAnimations(int heightDifference, View expandedView) { ReservationViewHolder holder = (ReservationViewHolder) expandedView.getTag(); Collection<Animator> anims = getAnimations(0, heightDifference); // Animate buttons back int difference = 2 * (getResources().getDimensionPixelSize(R.dimen.card_side_margin_selected) - getResources().getDimensionPixelSize(R.dimen.card_side_margin_default)); anims.add(ObjectAnimator.ofFloat(holder.llButtons, "translationX", 0, difference)); // Animate llData back anims.add(ObjectAnimator.ofFloat(holder.llData, "translationY", llDataTranslationY)); return anims; } @Override public void onCollapseAnimationEnd() { if (view.findViewById(R.id.rlMeta) != null) { // tablet ViewHelper.setTranslationY(view.findViewById(R.id.rlMeta), 0); } else { // phone ViewHelper.setTranslationY(tvAge, 0); ViewHelper.setTranslationY(view.findViewById(R.id.tvNoWarranty), 0); } } private Collection<Animator> getAnimations(float from, float to) { List<Animator> animators = new ArrayList<>(); if (view.findViewById(R.id.rlMeta) != null) { // tablet if (result.getReservations().size() >= result.getLent().size()) { animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.rlMeta), "translationY", from, to)); } } else { // phone animators.add(ObjectAnimator.ofFloat(tvAge, "translationY", from, to)); animators.add(ObjectAnimator.ofFloat(view.findViewById(R.id.tvNoWarranty), "translationY", from, to)); } return animators; } }); } if (result.getPendingFees() != null) { tvPendingFeesLabel.setVisibility(View.VISIBLE); tvPendingFees.setVisibility(View.VISIBLE); tvPendingFees.setText(result.getPendingFees()); } else { tvPendingFeesLabel.setVisibility(View.GONE); tvPendingFees.setVisibility(View.GONE); } if (result.getValidUntil() != null) { tvValidUntilLabel.setVisibility(View.VISIBLE); tvValidUntil.setVisibility(View.VISIBLE); tvValidUntil.setText(result.getValidUntil()); } else { tvValidUntilLabel.setVisibility(View.GONE); tvValidUntil.setVisibility(View.GONE); } refreshage(); }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); final SharedPreferences settings = activity.getApiCall().settings; sort = settings.getString("CommentSort", "Best"); boolean newData = true; if (commentData != null) { newData = false;/*from w w w . ja v a 2 s . c o m*/ } mainView = inflater.inflate(R.layout.single_image_layout, container, false); String[] mMenuList = getResources().getStringArray(R.array.emptyList); if (commentAdapter == null) commentAdapter = new CommentAdapter(mainView.getContext()); commentLayout = (ListView) mainView.findViewById(R.id.comment_thread); commentLayout.setChoiceMode(ListView.CHOICE_MODE_SINGLE); if (settings.getString("theme", MainActivity.HOLO_LIGHT).equals(MainActivity.HOLO_LIGHT)) imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.image_view, null); else imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.dark_image_view, null); mPullToRefreshLayout = (PullToRefreshLayout) mainView.findViewById(R.id.ptr_layout); ActionBarPullToRefresh.from(getActivity()) // Mark All Children as pullable .allChildrenArePullable() // Set the OnRefreshListener .listener(this) // Finally commit the setup to our PullToRefreshLayout .setup(mPullToRefreshLayout); if (savedInstanceState != null && newData) { imageData = savedInstanceState.getParcelable("imageData"); inGallery = savedInstanceState.getBoolean("inGallery"); } LinearLayout layout = (LinearLayout) imageLayoutView.findViewById(R.id.image_buttons); TextView imageDetails = (TextView) imageLayoutView.findViewById(R.id.single_image_details); layout.setVisibility(View.VISIBLE); ImageButton imageFullscreen = (ImageButton) imageLayoutView.findViewById(R.id.fullscreen); imageUpvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_good); imageDownvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_bad); ImageButton imageFavorite = (ImageButton) imageLayoutView.findViewById(R.id.rating_favorite); imageComment = (ImageButton) imageLayoutView.findViewById(R.id.comment); ImageButton imageUser = (ImageButton) imageLayoutView.findViewById(R.id.user); imageScore = (TextView) imageLayoutView.findViewById(R.id.single_image_score); TextView imageInfo = (TextView) imageLayoutView.findViewById(R.id.single_image_info); Log.d("imageData", imageData.getJSONObject().toString()); if (imageData.getJSONObject().has("ups")) { imageUpvote.setVisibility(View.VISIBLE); imageDownvote.setVisibility(View.VISIBLE); imageScore.setVisibility(View.VISIBLE); imageComment.setVisibility(View.VISIBLE); ImageUtils.updateImageFont(imageData, imageScore); } imageInfo.setVisibility(View.VISIBLE); ImageUtils.updateInfoFont(imageData, imageInfo); imageUser.setVisibility(View.VISIBLE); imageFavorite.setVisibility(View.VISIBLE); try { if (!imageData.getJSONObject().has("account_url") || imageData.getJSONObject().getString("account_url").equals("null") || imageData.getJSONObject().getString("account_url").equals("[deleted]")) imageUser.setVisibility(View.GONE); if (!imageData.getJSONObject().has("vote")) { imageUpvote.setVisibility(View.GONE); imageDownvote.setVisibility(View.GONE); } else { if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("up")) imageUpvote.setImageResource(R.drawable.green_rating_good); else if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("down")) imageDownvote.setImageResource(R.drawable.red_rating_bad); } if (imageData.getJSONObject().getString("favorite") != null && imageData.getJSONObject().getBoolean("favorite")) imageFavorite.setImageResource(R.drawable.green_rating_favorite); } catch (JSONException e) { Log.e("Error!", e.toString()); } imageFavorite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.favoriteImage(singleImageFragment, imageData, (ImageButton) view, activity.getApiCall()); } }); imageUser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.gotoUser(singleImageFragment, imageData); } }); imageComment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Activity activity = getActivity(); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_body); newBody.setLines(3); final TextView characterCount = new TextView(activity); characterCount.setText("140"); LinearLayout commentReplyLayout = new LinearLayout(activity); newBody.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { // } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { characterCount.setText(String.valueOf(140 - charSequence.length())); } @Override public void afterTextChanged(Editable editable) { for (int i = editable.length(); i > 0; i--) { if (editable.subSequence(i - 1, i).toString().equals("\n")) editable.replace(i - 1, i, ""); } } }); commentReplyLayout.setOrientation(LinearLayout.VERTICAL); commentReplyLayout.addView(newBody); commentReplyLayout.addView(characterCount); new AlertDialog.Builder(activity).setTitle(R.string.dialog_comment_on_image_title) .setView(commentReplyLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (newBody.getText() != null && newBody.getText().toString().length() < 141) { HashMap<String, Object> commentMap = new HashMap<String, Object>(); try { commentMap.put("comment", newBody.getText().toString()); commentMap.put("image_id", imageData.getJSONObject().getString("id")); Fetcher fetcher = new Fetcher(singleImageFragment, "3/comment/", ApiCall.POST, commentMap, ((ImgurHoloActivity) getActivity()).getApiCall(), POSTCOMMENT); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } }); imageUpvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.upVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); imageDownvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.downVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); if (popupWindow != null) { popupWindow.dismiss(); } popupWindow = new PopupWindow(); imageFullscreen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.fullscreen(singleImageFragment, imageData, popupWindow, mainView); } }); ArrayAdapter<String> tempAdapter = new ArrayAdapter<String>(mainView.getContext(), R.layout.drawer_list_item, mMenuList); Log.d("URI", "YO I'M IN YOUR SINGLE FRAGMENT gallery:" + inGallery); imageView = (ImageView) imageLayoutView.findViewById(R.id.single_image_view); loadImage(); TextView imageTitle = (TextView) imageLayoutView.findViewById(R.id.single_image_title); TextView imageDescription = (TextView) imageLayoutView.findViewById(R.id.single_image_description); try { String size = String .valueOf(NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_WIDTH))) + "x" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_HEIGHT)) + " (" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_SIZE)) + "B)"; String initial = imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) + " " + Html.fromHtml("•") + " " + size + " " + Html.fromHtml("•") + " " + "Views: " + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_VIEWS)); imageDetails.setText(initial); Log.d("imagedata", imageData.getJSONObject().toString()); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null")) imageTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE)); else imageTitle.setVisibility(View.GONE); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) { imageDescription .setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION)); imageDescription.setVisibility(View.VISIBLE); } else imageDescription.setVisibility(View.GONE); commentLayout.addHeaderView(imageLayoutView); commentLayout.setAdapter(tempAdapter); } catch (JSONException e) { Log.e("Text Error!", e.toString()); } if ((savedInstanceState == null || commentData == null) && newData) { commentData = new JSONParcelable(); getComments(); commentLayout.setAdapter(commentAdapter); } else if (newData) { commentArray = savedInstanceState.getParcelableArrayList("commentData"); commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } else if (commentArray != null) { commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } return mainView; }
From source file:ch.ethz.twimight.net.opportunistic.ScanningService.java
private void sendDisasterHtmls(Cursor c) throws JSONException { JSONObject toSendXml;/* ww w . jav a 2s . com*/ // String userId = String.valueOf(c.getLong(c // .getColumnIndex(Tweets.COL_TWITTERUSER))); String substr = Html.fromHtml(c.getString(c.getColumnIndex(Tweets.COL_TEXT))).toString(); String[] strarr = substr.split(" "); // check the urls of the tweet for (String subStrarr : strarr) { if (subStrarr.indexOf("http://") >= 0 || subStrarr.indexOf("https://") >= 0) { String subUrl = null; if (subStrarr.indexOf("http://") >= 0) { subUrl = subStrarr.substring(subStrarr.indexOf("http://")); } else if (subStrarr.indexOf("https://") >= 0) { subUrl = subStrarr.substring(subStrarr.indexOf("https://")); } Cursor cursorHtml = htmlDbHelper.getPageInfo(subUrl); if (cursorHtml != null) { if (!cursorHtml.isNull(cursorHtml.getColumnIndex(HtmlPage.COL_FILENAME))) { String[] filePath = { HtmlPage.HTML_PATH + "/" + LoginActivity.getTwitterId(this) }; String filename = cursorHtml.getString(cursorHtml.getColumnIndex(HtmlPage.COL_FILENAME)); Long tweetId = cursorHtml.getLong(cursorHtml.getColumnIndex(HtmlPage.COL_DISASTERID)); if (sdCardHelper.checkSDState(filePath)) { File xmlFile = sdCardHelper.getFileFromSDCard(filePath[0], filename); if (xmlFile.exists()) { toSendXml = getJSONFromXml(xmlFile); toSendXml.put(HtmlPage.COL_URL, subUrl); toSendXml.put(HtmlPage.COL_FILENAME, filename); toSendXml.put(HtmlPage.COL_DISASTERID, tweetId); Log.d(TAG, "sending htmls"); Log.d(TAG, toSendXml.toString(5)); bluetoothHelper.write(toSendXml.toString()); } } } } } } }
From source file:com.android.mms.ui.MessageListItem.java
private CharSequence formatMessage(MessageItem msgItem, String body, String subject, Pattern highlight, String contentType) {/*from w ww. j av a2s. c om*/ SpannableStringBuilder buf = new SpannableStringBuilder(); boolean hasSubject = !TextUtils.isEmpty(subject); SmileyParser parser = SmileyParser.getInstance(); if (hasSubject) { CharSequence smilizedSubject = parser.addSmileySpans(subject); // Can't use the normal getString() with extra arguments for string replacement // because it doesn't preserve the SpannableText returned by addSmileySpans. // We have to manually replace the %s with our text. buf.append(TextUtils.replace(mContext.getResources().getString(R.string.inline_subject), new String[] { "%s" }, new CharSequence[] { smilizedSubject })); } if (!TextUtils.isEmpty(body)) { // Converts html to spannable if ContentType is "text/html". if (contentType != null && ContentType.TEXT_HTML.equals(contentType)) { buf.append("\n"); buf.append(Html.fromHtml(body)); } else { if (hasSubject) { buf.append(" - "); } buf.append(parser.addSmileySpans(body)); } } if (highlight != null) { Matcher m = highlight.matcher(buf.toString()); while (m.find()) { buf.setSpan(new StyleSpan(Typeface.BOLD), m.start(), m.end(), 0); } } return buf; }
From source file:com.amaze.filemanager.utils.Futils.java
public void showSMBHelpDialog(Context m, String acc) { MaterialDialog.Builder b = new MaterialDialog.Builder(m); b.content(Html.fromHtml("<html>\n" + "<body>\n" + "<center>\n" + "<h1>How to access shared windows folder on android (smb)</h1>\n" + "</center>\n" + "<ol>\n" + "<li>\n" + "<b>Enable File Sharing</b>\n" + "<br>Open the Control Panel, click Choose homegroup and sharing options under Network and Internet, and click Change advanced sharing settings. Enable the file and printer sharing feature.\n" + "</li><br><li><b>Additional File Sharing settings</b><br>You may also want to configure the other advanced sharing settings here. \n" + "For example, you could enable access to your files without a password if you trust all the devices on your local network.Once file and printer sharing is enabled, you can open File Explorer or Windows Explorer, right-click a folder you want to share, and select Properties. \n" + "Click the Share button and make the folder available on the network.\n" + "</li><li><br><b>Make sure both devices are on same Wifi</b><br> \n" + "This feature makes files available on the local network, so your PC and mobile devices have to be on the same local network. You cant access a shared Windows folder over the Internet or when your smartphone is connected to its mobile data it has to be connected to Wi-Fi.</li><li>\n" + "<br><b>Find IP Address</b>\n" + "<br>Open Command Prompt. Type 'ipconfig' and press Enter. Look for Default Gateway under your network adapter for your router's IP address. Look for \\\"IPv4 Address\\\" under the same adapter section to find your computer's IP address.</li><li><br>\n" + "<b>Enter details in smb dialog box</b>\n" + "<br>\n" + "</ol>\n" + "</body>\n" + "</html>")); b.positiveText(R.string.doit);/*ww w .ja v a 2s .c o m*/ b.positiveColor(Color.parseColor(acc)); b.build().show(); }
From source file:dev.memento.MainActivity.java
private void refreshDisplayedDate() { mDateDisplayedView.setText(//from w ww.j a v a 2 s . c o m Html.fromHtml(getText(R.string.display_date) + "\n<b>" + mDateDisplayed.dateFormatted() + "</b>")); }
From source file:org.nla.tarotdroid.lib.ui.GameSetHistoryActivity.java
@Override public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { SubMenu subMenuBlueTooth = menu.addSubMenu(this.getString(R.string.lblBluetoothItem)); com.actionbarsherlock.view.MenuItem miBluetooth = subMenuBlueTooth.getItem(); miBluetooth.setIcon(R.drawable.stat_sys_data_bluetooth); miBluetooth.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); com.actionbarsherlock.view.MenuItem miBlueToothDiscover = subMenuBlueTooth .add(R.string.lblBluetoothDiscover).setIcon(R.drawable.ic_menu_allfriends); com.actionbarsherlock.view.MenuItem miBlueToothGetDiscoverable = subMenuBlueTooth .add(R.string.lblBluetoothGetDiscoverable).setIcon(android.R.drawable.ic_menu_myplaces); com.actionbarsherlock.view.MenuItem miBlueToothReceive = subMenuBlueTooth.add(R.string.lblBluetoothReceive) .setIcon(R.drawable.ic_menu_download); com.actionbarsherlock.view.MenuItem miBlueToothHelp = subMenuBlueTooth.add(R.string.lblBluetoothHelp) .setIcon(android.R.drawable.ic_menu_info_details); miBlueToothDiscover.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override// w ww. j a va 2 s . co m public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { if (isBluetoothActivated()) { GameSetHistoryActivity.this.bluetoothHelper.startDiscovery(); AuditHelper.auditEvent(AuditHelper.EventTypes.actionBluetoothDiscoverDevices); } return true; } }); miBlueToothGetDiscoverable.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { if (isBluetoothActivated()) { GameSetHistoryActivity.this.bluetoothHelper.setBluetoothDeviceDiscoverable(); AuditHelper.auditEvent(AuditHelper.EventTypes.actionBluetoothSetDiscoverable); } return true; } }); miBlueToothReceive.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { if (isBluetoothActivated()) { // retrieve game count int gameSetCount; try { gameSetCount = AppContext.getApplication().getDalService().getGameSetCount(); } catch (DalException de) { gameSetCount = 0; } // prevent user from downloading if game set count > 5 and // limited version if (AppContext.getApplication().isAppLimited() && gameSetCount >= 5) { Toast.makeText(GameSetHistoryActivity.this, AppContext.getApplication().getResources() .getString(R.string.msgLimitedVersionInformation), Toast.LENGTH_SHORT).show(); } // ok for download else { try { GameSetHistoryActivity.this.receiveGameSetTask = new ReceiveGameSetTask( GameSetHistoryActivity.this, GameSetHistoryActivity.this.progressDialog, GameSetHistoryActivity.this.bluetoothHelper.getBluetoothAdapter()); GameSetHistoryActivity.this.receiveGameSetTask.setCallback(refreshCallback); GameSetHistoryActivity.this.receiveGameSetTask.execute(); AuditHelper.auditEvent(AuditHelper.EventTypes.actionBluetoothReceiveGameSet); } catch (IOException ioe) { Log.v(AppContext.getApplication().getAppLogTag(), "TarotDroid Exception in " + this.getClass().toString(), ioe); Toast.makeText(GameSetHistoryActivity.this, AppContext.getApplication().getResources() .getString(R.string.msgBluetoothError, ioe), Toast.LENGTH_SHORT).show(); } } } return true; } }); miBlueToothHelp.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { UIHelper.showSimpleRichTextDialog(GameSetHistoryActivity.this, AppContext.getApplication().getResources().getText(R.string.msgHelpBluetooth).toString(), AppContext.getApplication().getResources().getString(R.string.titleHelpBluetooth)); return true; } }); // TODO Improve Massive excel export // if (!AppContext.getApplication().isAppLimited()) { // com.actionbarsherlock.view.MenuItem miGlobalExport = // menu.add(this.getString(R.string.lblExcelExport)).setIcon(R.drawable.ic_excel); // miGlobalExport.setShowAsAction(com.actionbarsherlock.view.MenuItem.SHOW_AS_ACTION_NEVER); // //miGlobalExport.setIcon(R.drawable.ic_excel); // // miGlobalExport.setOnMenuItemClickListener(new // OnMenuItemClickListener() { // @Override // public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem // item) { // ExportToExcelTask task = new // ExportToExcelTask(GameSetHistoryActivity.this, progressDialog); // task.execute(); // return true; // } // }); // } com.actionbarsherlock.view.MenuItem miBin = menu.add(this.getString(R.string.lblInitDalItem)); miBin.setShowAsAction(com.actionbarsherlock.view.MenuItem.SHOW_AS_ACTION_NEVER); miBin.setIcon(R.drawable.gd_action_bar_trashcan); miBin.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { AlertDialog.Builder builder = new AlertDialog.Builder(GameSetHistoryActivity.this); builder.setTitle(GameSetHistoryActivity.this.getString(R.string.titleReinitDalYesNo)); builder.setMessage( Html.fromHtml(GameSetHistoryActivity.this.getText(R.string.msgReinitDalYesNo).toString())); builder.setPositiveButton(GameSetHistoryActivity.this.getString(R.string.btnOk), GameSetHistoryActivity.this.removeAllGameSetsDialogClickListener); builder.setNegativeButton(GameSetHistoryActivity.this.getString(R.string.btnCancel), GameSetHistoryActivity.this.removeAllGameSetsDialogClickListener).show(); builder.setIcon(android.R.drawable.ic_dialog_alert); return true; } }); return true; }
From source file:gr.scify.newsum.ui.ViewActivity.java
@Override public void run() { // take the String from the TopicActivity Bundle extras = getIntent().getExtras(); Category = extras.getString(CATEGORY_INTENT_VAR); // Make sure we have updated the data source NewSumUiActivity.setDataSource(this); // Get user sources String sUserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this); // get Topics from TopicActivity (avoid multiple server calls) TopicInfo[] tiTopics = TopicActivity.getTopics(sUserSources, Category, this); // Also get Topic Titles, to display to adapter final String[] saTopicTitles = new String[tiTopics.length]; // Also get Topic IDs final String[] saTopicIDs = new String[tiTopics.length]; // Also get Dates, in order to show in summary title final String[] saTopicDates = new String[tiTopics.length]; // DeHTML titles for (int iCnt = 0; iCnt < tiTopics.length; iCnt++) { // update Titles Array saTopicTitles[iCnt] = Html.fromHtml(tiTopics[iCnt].getTitle()).toString(); // update IDs Array saTopicIDs[iCnt] = tiTopics[iCnt].getID(); // update Date Array saTopicDates[iCnt] = tiTopics[iCnt].getPrintableDate(NewSumUiActivity.getDefaultLocale()); }// w ww . jav a2s . c o m // get the value of the TopicIDs list size (to use in swipe) saTopicIDsLength = saTopicIDs.length; final TextView title = (TextView) findViewById(R.id.title); // Fill topic spinner final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, saTopicTitles); final TextView tx = (TextView) findViewById(R.id.textView1); // final float minm = tx.getTextSize(); // final float maxm = (minm + 24); // Get active topic int iTopicNum; // If we have returned from a pause if (iPrvSelectedItem >= 0) // use previous selection before pause iTopicNum = iPrvSelectedItem; // else else // use selection from topic page iTopicNum = extras.getInt(TOPIC_ID_INTENT_VAR); final int num = iTopicNum; // create an invisible spinner just to control the summaries of the // category (i will use it later on Swipe) final Spinner spinner = (Spinner) findViewById(R.id.spinner1); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); runOnUiThread(new Runnable() { @Override public void run() { spinner.setAdapter(adapter); // Scroll view init final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1); final String[] saTopicTitlesArg = saTopicTitles; final String[] saTopicIDsArg = saTopicIDs; final String[] SaTopicDatesArg = saTopicDates; // Add selection event spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // Changing summary loading = true; showWaitingDialog(); // Update visibility of rating bar final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar); rb.setRating(0.0f); rb.setVisibility(View.VISIBLE); final TextView rateLbl = (TextView) findViewById(R.id.rateLbl); rateLbl.setVisibility(View.VISIBLE); scroll.scrollTo(0, 0); String UserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this); String[] saTopicIDs = saTopicIDsArg; // track summary views per category and topic title if (getAnalyticsPref()) { EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, Category, saTopicTitlesArg[arg2], 0l); } if (sCustomCategory.trim().length() > 0) { if (Category.equals(sCustomCategory)) { Context ctxCur = NewSumUiActivity.getAppContext(ViewActivity.this); String sCustomCategoryURL = ctxCur.getResources() .getString(R.string.custom_category_url); // Check if specific element needs to be read String sElementID = ctxCur.getResources() .getString(R.string.custom_category_elementId); // If an element needs to be selected if (sElementID.trim().length() > 0) { try { // Check if specific element needs to be read String sViewOriginalPage = ctxCur.getResources() .getString(R.string.custom_category_visit_source); // Init text by a link to the original page sText = "<p><a href='" + sCustomCategoryURL + "'>" + sViewOriginalPage + "</a></p>"; // Get document Document doc = Jsoup.connect(sCustomCategoryURL).get(); // If a table Element eCur = doc.getElementById(sElementID); if (eCur.tagName().equalsIgnoreCase("table")) { // Get table rows Elements eRows = eCur.select("tr"); // For each row StringBuffer sTextBuf = new StringBuffer(); for (Element eCurRow : eRows) { // Append content // TODO: Use HTML if possible. Now problematic (crashes when we click on link) sTextBuf.append("<p>" + eCurRow.text() + "</p>"); } // Return as string sText = sText + sTextBuf.toString(); } else // else get text sText = eCur.text(); } catch (IOException e) { // Show unavailable text sText = ctxCur.getResources() .getString(R.string.custom_category_unavailable); e.printStackTrace(); } } else sText = Utils.getFromHttp(sCustomCategoryURL, false); } } else { // call getSummary with (sTopicID, sUserSources). Use "All" for // all Sources String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources); // check if Summary exists, otherwise display message if (Summary.length == 0) { // DONE APPLICATION HANGS, DOES NOT // WORK. Updated: Probably OK nothingFound = true; AlertDialog.Builder al = new AlertDialog.Builder(ViewActivity.this); al.setMessage(R.string.shouldReloadSummaries); al.setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { // Reset cache CacheController.clearCache(); // Restart main activity startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); } }); al.setCancelable(false); al.show(); // Return to home activity loading = false; return; } // Generate Summary text for normal categories sText = generateSummaryText(Summary, ViewActivity.this); pText = generatesummarypost(Summary, ViewActivity.this); } // Update HTML tx.setText(Html.fromHtml(sText)); // Allow links to be followed into browser tx.setMovementMethod(LinkMovementMethod.getInstance()); // Also Add Date to Topic Title inside Summary title.setText(saTopicTitlesArg[arg2] + " : " + SaTopicDatesArg[arg2]); // Update size updateTextSize(); // Update visited topics TopicActivity.addVisitedTopicID(saTopicIDs[arg2]); // Done loading = false; closeWaitingDialog(); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); runOnUiThread(new Runnable() { @Override public void run() { // Get active topic spinner.setSelection(num); } }); } }); runOnUiThread(new Runnable() { @Override public void run() { showHelpDialog(); } }); closeWaitingDialog(); }
From source file:com.birdeye.MainActivity.java
public void initateCounter(int timer) { // 900000 15 min new CountDownTimer(timer, 1000) { // adjust the milli seconds here public void onTick(long millisUntilFinished) { Log.e("millisUntilFinished", "" + millisUntilFinished); String pausedTimerValue = "" + millisUntilFinished; String timerText = "The app closes in " + String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished), TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES .toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))) + " you can remove shut off timer by upgrading for only & $2.99 "; tv_cancel.setText(timerText + Html.fromHtml("<p><u>SUBSCRIBE</u></p>")); tv_cancel.setOnClickListener(new View.OnClickListener() { @Override/*from w w w .j av a 2 s .co m*/ public void onClick(View v) { removeAdsDialog(); } }); // tv_cancel.setText(timerText); } public void onFinish() { if (!Globals.hasPaid) { enabled.setChecked(false); enable(false); enabled.setChecked(false); initial(false); MainActivity.this.finish(); System.exit(0); if (SharedPref.get_savedCards1(MainActivity.this).equalsIgnoreCase("true")) { } } } }.start(); }