List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
From source file:com.musiqueplayer.playlistequalizerandroidwear.activities.MainActivity.java
private void updatePosition(final MenuItem menuItem) { runnable = null;//from w w w. jav a 2s . c om switch (menuItem.getItemId()) { case R.id.nav_library: runnable = navigateLibrary; break; case R.id.nav_playlists: runnable = navigatePlaylist; break; case R.id.nav_folders: runnable = navigateFolder; break; case R.id.nav_nowplaying: NavigationUtils.navigateToNowplaying(MainActivity.this, false); break; case R.id.nav_queue: runnable = navigateQueue; break; case R.id.nav_timer: runnable = navigateTimer; break; case R.id.nav_settings: NavigationUtils.navigateToSettings(MainActivity.this); break; case R.id.nav_about: mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { final String APP_PNAME = "com.musiqueplayer.playlistequalizerandroidwear"; final Context mContext = getApplicationContext(); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.this, R.style.myDialog)); final SpannableString s = new SpannableString( Html.fromHtml("Thanks for downloading Music Player.<br>" + "Thanks for being an awesome user! If you enjoy using <b>Music Player</b> app, please take a moment to rate it with <b>5 stars</b>. " + "")); Linkify.addLinks(s, Linkify.ALL); alertDialogBuilder.setTitle("About"); alertDialogBuilder.setMessage(s); alertDialogBuilder.setPositiveButton("Rate Now", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { mContext.startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME))); } }); alertDialogBuilder.setNegativeButton("Remind Later", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0); SharedPreferences.Editor editor = prefs.edit(); editor.putLong("launch_count", 0); editor.commit(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }, 350); break; } if (runnable != null) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { runnable.run(); } }, 350); } }
From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java
private void showAnnouncementDialogIfNeeded(Intent intent) { final String title = intent.getStringExtra(EXTRA_DIALOG_TITLE); final String message = intent.getStringExtra(EXTRA_DIALOG_MESSAGE); if (!mShowedAnnouncementDialog && !TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) { LOGD(TAG, "showAnnouncementDialogIfNeeded, title: " + title); LOGD(TAG, "showAnnouncementDialogIfNeeded, message: " + message); final String yes = intent.getStringExtra(EXTRA_DIALOG_YES); LOGD(TAG, "showAnnouncementDialogIfNeeded, yes: " + yes); final String no = intent.getStringExtra(EXTRA_DIALOG_NO); LOGD(TAG, "showAnnouncementDialogIfNeeded, no: " + no); final String url = intent.getStringExtra(EXTRA_DIALOG_URL); LOGD(TAG, "showAnnouncementDialogIfNeeded, url: " + url); final SpannableString spannable = new SpannableString(message == null ? "" : message); Linkify.addLinks(spannable, Linkify.WEB_URLS); AlertDialog.Builder builder = new AlertDialog.Builder(this); if (!TextUtils.isEmpty(title)) { builder.setTitle(title);//from w w w .j a v a2 s .c o m } builder.setMessage(spannable); if (!TextUtils.isEmpty(no)) { builder.setNegativeButton(no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); } if (!TextUtils.isEmpty(yes)) { builder.setPositiveButton(yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); } }); } final AlertDialog dialog = builder.create(); dialog.show(); final TextView messageView = (TextView) dialog.findViewById(android.R.id.message); if (messageView != null) { // makes the embedded links in the text clickable, if there are any messageView.setMovementMethod(LinkMovementMethod.getInstance()); } mShowedAnnouncementDialog = true; } }
From source file:com.onesignal.GenerateNotification.java
static void createSummaryNotification(Context inContext, boolean updateSummary, JSONObject gcmBundle) { if (updateSummary) setStatics(inContext);/*from w ww .ja v a2 s . co m*/ String group = null; try { group = gcmBundle.getString("grp"); } catch (Throwable t) { } Random random = new Random(); PendingIntent summaryDeleteIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseDeleteIntent(0).putExtra("summary", group)); OneSignalDbHelper dbHelper = new OneSignalDbHelper(currentContext); SQLiteDatabase writableDb = dbHelper.getWritableDatabase(); String[] retColumn = { NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, NotificationTable.COLUMN_NAME_FULL_DATA, NotificationTable.COLUMN_NAME_IS_SUMMARY, NotificationTable.COLUMN_NAME_TITLE, NotificationTable.COLUMN_NAME_MESSAGE }; String[] whereArgs = { group }; Cursor cursor = writableDb.query(NotificationTable.TABLE_NAME, retColumn, NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + // Where String NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED + " = 0", whereArgs, null, // group by null, // filter by row groups NotificationTable._ID + " DESC" // sort order, new to old ); Notification summaryNotification; int summaryNotificationId = random.nextInt(); String firstFullData = null; Collection<SpannableString> summeryList = null; if (cursor.moveToFirst()) { SpannableString spannableString; summeryList = new ArrayList<SpannableString>(); do { if (cursor.getInt(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_IS_SUMMARY)) == 1) summaryNotificationId = cursor .getInt(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID)); else { String title = cursor.getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_TITLE)); if (title == null) title = ""; else title += " "; // Html.fromHtml("<strong>" + line1Title + "</strong> " + gcmBundle.getString("alert")); String msg = cursor.getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_MESSAGE)); spannableString = new SpannableString(title + msg); if (title.length() > 0) spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, title.length(), 0); summeryList.add(spannableString); if (firstFullData == null) firstFullData = cursor .getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_FULL_DATA)); } } while (cursor.moveToNext()); if (updateSummary) { try { gcmBundle = new JSONObject(firstFullData); } catch (JSONException e) { e.printStackTrace(); } } } if (summeryList != null && (!updateSummary || summeryList.size() > 1)) { int notificationCount = summeryList.size() + (updateSummary ? 0 : 1); String summaryMessage = null; if (gcmBundle.has("grp_msg")) { try { summaryMessage = gcmBundle.getString("grp_msg").replace("$[notif_count]", "" + notificationCount); } catch (Throwable t) { } } if (summaryMessage == null) summaryMessage = notificationCount + " new messages"; JSONObject summaryDataBundle = new JSONObject(); try { summaryDataBundle.put("alert", summaryMessage); } catch (JSONException e) { e.printStackTrace(); } Intent summaryIntent = getNewBaseIntent(summaryNotificationId).putExtra("summary", group) .putExtra("onesignal_data", summaryDataBundle.toString()); PendingIntent summaryContentIntent = getNewActionPendingIntent(random.nextInt(), summaryIntent); NotificationCompat.Builder summeryBuilder = getBaseNotificationCompatBuilder(gcmBundle, !updateSummary); summeryBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent) .setContentTitle(currentContext.getPackageManager() .getApplicationLabel(currentContext.getApplicationInfo())) .setContentText(summaryMessage).setNumber(notificationCount).setOnlyAlertOnce(updateSummary) .setGroup(group).setGroupSummary(true); if (!updateSummary) summeryBuilder.setTicker(summaryMessage); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String line1Title = null; // Add the latest notification to the summary if (!updateSummary) { try { line1Title = gcmBundle.getString("title"); } catch (Throwable t) { } if (line1Title == null) line1Title = ""; else line1Title += " "; String message = ""; try { message = gcmBundle.getString("alert"); } catch (Throwable t) { } SpannableString spannableString = new SpannableString(line1Title + message); if (line1Title.length() > 0) spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, line1Title.length(), 0); inboxStyle.addLine(spannableString); } for (SpannableString line : summeryList) inboxStyle.addLine(line); inboxStyle.setBigContentTitle(summaryMessage); summeryBuilder.setStyle(inboxStyle); summaryNotification = summeryBuilder.build(); } else { // There currently isn't a visible notification from this group, save the group summary notification id and post it so it looks like a normal notification. ContentValues values = new ContentValues(); values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, summaryNotificationId); values.put(NotificationTable.COLUMN_NAME_GROUP_ID, group); values.put(NotificationTable.COLUMN_NAME_IS_SUMMARY, 1); writableDb.insert(NotificationTable.TABLE_NAME, null, values); NotificationCompat.Builder notifBuilder = getBaseNotificationCompatBuilder(gcmBundle, !updateSummary); PendingIntent summaryContentIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseIntent(summaryNotificationId).putExtra("onesignal_data", gcmBundle.toString()) .putExtra("summary", group)); addNotificationActionButtons(gcmBundle, notifBuilder, summaryNotificationId, group); notifBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent) .setOnlyAlertOnce(updateSummary).setGroup(group).setGroupSummary(true); summaryNotification = notifBuilder.build(); } NotificationManagerCompat.from(currentContext).notify(summaryNotificationId, summaryNotification); cursor.close(); writableDb.close(); }
From source file:com.todoroo.astrid.adapter.TaskAdapter.java
private void showEditNotesDialog(final Task task) { Task t = taskDao.fetch(task.getId(), Task.NOTES); if (t == null || !t.hasNotes()) { return;// w w w.j a v a 2s . co m } SpannableString description = new SpannableString(t.getNotes()); Linkify.addLinks(description, Linkify.ALL); AlertDialog dialog = dialogBuilder.newDialog().setMessage(description) .setPositiveButton(android.R.string.ok, null).show(); View message = dialog.findViewById(android.R.id.message); if (message != null && message instanceof TextView) { ((TextView) message).setMovementMethod(LinkMovementMethod.getInstance()); } }
From source file:fr.cph.chicago.core.adapter.FavoritesAdapter.java
private void handleBusRoute(@NonNull final FavoritesViewHolder holder, @NonNull final BusRoute busRoute) { holder.stationNameTextView.setText(busRoute.getId()); holder.favoriteImage.setImageResource(R.drawable.ic_directions_bus_white_24dp); final List<BusDetailsDTO> busDetailsDTOs = new ArrayList<>(); final Map<String, Map<String, List<BusArrival>>> busArrivals = favoritesData .getBusArrivalsMapped(busRoute.getId()); for (final Entry<String, Map<String, List<BusArrival>>> entry : busArrivals.entrySet()) { // Build data for button outside of the loop final String stopName = entry.getKey(); final String stopNameTrimmed = Util.trimBusStopNameIfNeeded(stopName); final Map<String, List<BusArrival>> value = entry.getValue(); for (final String key2 : value.keySet()) { final BusArrival busArrival = value.get(key2).get(0); final String boundTitle = busArrival.getRouteDirection(); final BusDirection.BusDirectionEnum busDirectionEnum = BusDirection.BusDirectionEnum .fromString(boundTitle); final BusDetailsDTO busDetails = BusDetailsDTO.builder().busRouteId(busArrival.getRouteId()) .bound(busDirectionEnum.getShortUpperCase()).boundTitle(boundTitle) .stopId(Integer.toString(busArrival.getStopId())).routeName(busRoute.getName()) .stopName(stopName).build(); busDetailsDTOs.add(busDetails); }//from www .j a v a 2 s . co m boolean newLine = true; int i = 0; for (final Entry<String, List<BusArrival>> entry2 : value.entrySet()) { final LinearLayout.LayoutParams containParams = getInsideParams(newLine, i == value.size() - 1); final LinearLayout container = new LinearLayout(context); container.setOrientation(LinearLayout.HORIZONTAL); container.setLayoutParams(containParams); // Left final LinearLayout.LayoutParams leftParams = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final RelativeLayout left = new RelativeLayout(context); left.setLayoutParams(leftParams); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams destinationParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); destinationParams.addRule(RelativeLayout.RIGHT_OF, lineId); destinationParams.setMargins(pixelsHalf, 0, 0, 0); final String bound = BusDirection.BusDirectionEnum.fromString(entry2.getKey()).getShortLowerCase(); final String leftString = stopNameTrimmed + " " + bound; final SpannableString destinationSpannable = new SpannableString(leftString); destinationSpannable.setSpan(new RelativeSizeSpan(0.65f), stopNameTrimmed.length(), leftString.length(), 0); // set size destinationSpannable.setSpan(new ForegroundColorSpan(grey5), 0, leftString.length(), 0); // set color final TextView boundCustomTextView = new TextView(context); boundCustomTextView.setText(destinationSpannable); boundCustomTextView.setSingleLine(true); boundCustomTextView.setLayoutParams(destinationParams); left.addView(lineIndication); left.addView(boundCustomTextView); // Right final LinearLayout.LayoutParams rightParams = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rightParams.setMargins(marginLeftPixel, 0, 0, 0); final LinearLayout right = new LinearLayout(context); right.setOrientation(LinearLayout.VERTICAL); right.setLayoutParams(rightParams); final List<BusArrival> buses = entry2.getValue(); final StringBuilder currentEtas = new StringBuilder(); for (final BusArrival arri : buses) { currentEtas.append(" ").append(arri.getTimeLeftDueDelay()); } final TextView arrivalText = new TextView(context); arrivalText.setText(currentEtas); arrivalText.setGravity(Gravity.END); arrivalText.setSingleLine(true); arrivalText.setTextColor(grey5); arrivalText.setEllipsize(TextUtils.TruncateAt.END); right.addView(arrivalText); container.addView(left); container.addView(right); holder.mainLayout.addView(container); newLine = false; i++; } } holder.mapButton.setText(activity.getString(R.string.favorites_view_buses)); holder.detailsButton .setOnClickListener(new BusStopOnClickListener(activity, holder.parent, busDetailsDTOs)); holder.mapButton.setOnClickListener(v -> { if (!Util.isNetworkAvailable(context)) { Util.showNetworkErrorMessage(activity); } else { final Set<String> bounds = Stream.of(busDetailsDTOs).map(BusDetailsDTO::getBound) .collect(Collectors.toSet()); final Intent intent = new Intent(activity.getApplicationContext(), BusMapActivity.class); final Bundle extras = new Bundle(); extras.putString(activity.getString(R.string.bundle_bus_route_id), busRoute.getId()); extras.putStringArray(activity.getString(R.string.bundle_bus_bounds), bounds.toArray(new String[bounds.size()])); intent.putExtras(extras); activity.startActivity(intent); } }); }
From source file:com.coderdojo.libretalk.MainActivity.java
private final void printMsg(final String message) { ArrayAdapter<SpannableString> adapter = new ArrayAdapter<SpannableString>(this, android.R.layout.simple_list_item_1, mMessageListArray); ListView listView = (ListView) findViewById(R.id.message_list); listView.setAdapter(adapter);/*w ww. j a va 2s . c om*/ listView.setStackFromBottom(true); mMessageListArray.add(new SpannableString(message)); adapter.notifyDataSetChanged(); }
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);/*w w w . j a v a 2s .c o 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); }
From source file:org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder.java
private Spanned getTitleStringAboutMe(int stringRes, int stringResMulti, ParcelableUser[] sources) { if (sources == null || sources.length == 0) return null; final Context context = adapter.getContext(); final boolean nameFirst = adapter.isNameFirst(); final UserColorNameManager manager = adapter.getUserColorNameManager(); final Resources resources = context.getResources(); final Configuration configuration = resources.getConfiguration(); final SpannableString firstDisplayName = new SpannableString( manager.getDisplayName(sources[0], nameFirst, false)); firstDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstDisplayName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (sources.length == 1) { final String format = context.getString(stringRes); return SpanFormatter.format(configuration.locale, format, firstDisplayName); } else if (sources.length == 2) { final String format = context.getString(stringResMulti); final SpannableString secondDisplayName = new SpannableString( manager.getDisplayName(sources[1], nameFirst, false)); secondDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, secondDisplayName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return SpanFormatter.format(configuration.locale, format, firstDisplayName, secondDisplayName); } else {/*from ww w .j av a2 s . c om*/ final int othersCount = sources.length - 1; final SpannableString nOthers = new SpannableString( resources.getQuantityString(R.plurals.N_others, othersCount, othersCount)); nOthers.setSpan(new StyleSpan(Typeface.BOLD), 0, nOthers.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); final String format = context.getString(stringResMulti); return SpanFormatter.format(configuration.locale, format, firstDisplayName, nOthers); } }
From source file:com.example.lowviscam.GalleryActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); if (isLight == true) { inflater.inflate(R.menu.gallery, menu); } else {// w ww.j av a 2 s.c o m inflater.inflate(R.menu.gallery_dark, menu); } // Get the SearchView and set the searchable configuration SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); // Assumes current activity is the searchable activity searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default searchView.setSubmitButtonEnabled(true); searchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { search(query); // First image toast String firstResult; if (numSearchResults == 0) { firstResult = "No results found for " + query + "."; } else { firstResult = "The first image result is titled " + tagList[0]; } SpannableString s = new SpannableString(firstResult); s.setSpan(new TypefaceSpan(GalleryActivity.this, "APHont-Regular_q15c.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Toast.makeText(GalleryActivity.this, s, Toast.LENGTH_LONG).show(); return true; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { search(""); } return true; } public void search(String query) { // hide keyboard InputMethodManager inputManager = (InputMethodManager) GalleryActivity.this .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(GalleryActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); // Fetch the {@link LayoutInflater} service so that new views can be created LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); // Find the {@link GridView} that was already defined in the XML layout GridView gridView = (GridView) findViewById(R.id.grid); try { gridView.setAdapter(new CouponAdapter(inflater, createSearchedCoupons(query))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); return true; //return super.onCreateOptionsMenu(menu); }
From source file:com.arantius.tivocommander.Explore.java
protected void finishRequest() { if (--mRequestCount != 0) { return;//from w ww . ja v a 2 s. c o m } getParent().setProgressBarIndeterminateVisibility(false); if (mRecordingId == null) { for (JsonNode recording : mContent.path("recordingForContentId")) { String state = recording.path("state").asText(); if ("inProgress".equals(state) || "complete".equals(state) || "scheduled".equals(state)) { mRecordingId = recording.path("recordingId").asText(); mRecordingState = state; break; } } } // Fill mChoices based on the data we now have. if ("scheduled".equals(mRecordingState)) { mChoices.add(RecordActions.DONT_RECORD.toString()); } else if ("inProgress".equals(mRecordingState)) { mChoices.add(RecordActions.RECORD_STOP.toString()); } else if (mOfferId != null) { mChoices.add(RecordActions.RECORD.toString()); } if (mSubscriptionId != null) { mChoices.add(RecordActions.SP_MODIFY.toString()); mChoices.add(RecordActions.SP_CANCEL.toString()); } else if (mCollectionId != null && !"movie".equals(mContent.path("collectionType").asText()) && !mContent.has("movieYear")) { mChoices.add(RecordActions.SP_ADD.toString()); } setContentView(R.layout.explore); // Show only appropriate buttons. findViewById(R.id.explore_btn_watch).setVisibility( "complete".equals(mRecordingState) || "inprogress".equals(mRecordingState) ? View.VISIBLE : View.GONE); hideViewIfNull(R.id.explore_btn_upcoming, mCollectionId); if (mChoices.size() == 0) { findViewById(R.id.explore_btn_record).setVisibility(View.GONE); } // Delete / undelete buttons visible only if appropriate. findViewById(R.id.explore_btn_delete) .setVisibility("complete".equals(mRecordingState) ? View.VISIBLE : View.GONE); findViewById(R.id.explore_btn_undelete) .setVisibility("deleted".equals(mRecordingState) ? View.VISIBLE : View.GONE); // Display titles. String title = mContent.path("title").asText(); String subtitle = mContent.path("subtitle").asText(); ((TextView) findViewById(R.id.content_title)).setText(title); TextView subtitleView = ((TextView) findViewById(R.id.content_subtitle)); if ("".equals(subtitle)) { subtitleView.setVisibility(View.GONE); } else { subtitleView.setText(subtitle); } // Display (only the proper) badges. if (mRecording != null && mRecording.path("episodic").asBoolean() && !mRecording.path("repeat").asBoolean()) { findViewById(R.id.badge_new).setVisibility(View.VISIBLE); } if (mRecording != null && mRecording.path("hdtv").asBoolean()) { findViewById(R.id.badge_hd).setVisibility(View.VISIBLE); } ImageView iconSubType = (ImageView) findViewById(R.id.icon_sub_type); TextView textSubType = (TextView) findViewById(R.id.text_sub_type); // TODO: Downloading state? if ("complete".equals(mRecordingState)) { iconSubType.setVisibility(View.GONE); textSubType.setVisibility(View.GONE); } else if ("inProgress".equals(mRecordingState)) { iconSubType.setImageResource(R.drawable.recording_recording); textSubType.setText(R.string.sub_recording); } else if (mSubscriptionType != null) { switch (mSubscriptionType) { case SEASON_PASS: iconSubType.setImageResource(R.drawable.todo_seasonpass); textSubType.setText(R.string.sub_season_pass); break; case SINGLE_OFFER: iconSubType.setImageResource(R.drawable.todo_single_offer); textSubType.setText(R.string.sub_single_offer); break; case WISHLIST: iconSubType.setImageResource(R.drawable.todo_wishlist); textSubType.setText(R.string.sub_wishlist); break; default: iconSubType.setVisibility(View.GONE); textSubType.setVisibility(View.GONE); } } else { iconSubType.setVisibility(View.GONE); textSubType.setVisibility(View.GONE); } // Display channel and time. if (mRecording != null) { String channelStr = ""; JsonNode channel = mRecording.path("channel"); if (!channel.isMissingNode()) { channelStr = String.format("%s %s, ", channel.path("channelNumber").asText(), channel.path("callSign").asText()); } // Lots of shows seem to be a few seconds short, add padding so that // rounding down works as expected. Magic number. final int minutes = (30 + mRecording.path("duration").asInt()) / 60; String durationStr = minutes >= 60 ? String.format(Locale.US, "%d hr", minutes / 60) : String.format(Locale.US, "%d min", minutes); if (isRecordingPartial()) { durationStr += " (partial)"; } ((TextView) findViewById(R.id.content_chan_len)).setText(channelStr + durationStr); String airTime = new SimpleDateFormat("EEE MMM d, hh:mm a", Locale.US) .format(Utils.parseDateTimeStr(mRecording.path("actualStartTime").asText())); ((TextView) findViewById(R.id.content_air_time)).setText("Air time: " + airTime); } else { ((TextView) findViewById(R.id.content_chan_len)).setVisibility(View.GONE); ((TextView) findViewById(R.id.content_air_time)).setVisibility(View.GONE); } // Construct and display details. ArrayList<String> detailParts = new ArrayList<String>(); int season = mContent.path("seasonNumber").asInt(); int epNum = mContent.path("episodeNum").path(0).asInt(); if (season != 0 && epNum != 0) { detailParts.add(String.format("Sea %d Ep %d", season, epNum)); } if (mContent.has("mpaaRating")) { detailParts.add(mContent.path("mpaaRating").asText().toUpperCase(Locale.US)); } else if (mContent.has("tvRating")) { detailParts.add("TV-" + mContent.path("tvRating").asText().toUpperCase(Locale.US)); } detailParts.add(mContent.path("category").path(0).path("label").asText()); int year = mContent.path("originalAirYear").asInt(); if (year != 0) { detailParts.add(Integer.toString(year)); } // Filter empty strings. for (int i = detailParts.size() - 1; i >= 0; i--) { if ("".equals(detailParts.get(i)) || null == detailParts.get(i)) { detailParts.remove(i); } } // Then format the parts into one string. String detail1 = "(" + Utils.join(", ", detailParts) + ") "; if ("() ".equals(detail1)) { detail1 = ""; } String detail2 = mContent.path("description").asText(); TextView detailView = ((TextView) findViewById(R.id.content_details)); if (detail2 == null) { detailView.setText(detail1); } else { Spannable details = new SpannableString(detail1 + detail2); details.setSpan(new ForegroundColorSpan(Color.WHITE), detail1.length(), details.length(), 0); detailView.setText(details); } // Add credits. ArrayList<String> credits = new ArrayList<String>(); for (JsonNode credit : mContent.path("credit")) { String role = credit.path("role").asText(); if ("actor".equals(role) || "host".equals(role) || "guestStar".equals(role)) { credits.add(credit.path("first").asText() + " " + credit.path("last").asText()); } } TextView creditsView = (TextView) findViewById(R.id.content_credits); creditsView.setText(Utils.join(", ", credits)); // Find and set the banner image if possible. ImageView imageView = (ImageView) findViewById(R.id.content_image); View progressView = findViewById(R.id.content_image_progress); String imageUrl = Utils.findImageUrl(mContent); new DownloadImageTask(this, imageView, progressView).execute(imageUrl); }