Example usage for android.graphics Typeface BOLD

List of usage examples for android.graphics Typeface BOLD

Introduction

In this page you can find the example usage for android.graphics Typeface BOLD.

Prototype

int BOLD

To view the source code for android.graphics Typeface BOLD.

Click Source Link

Usage

From source file:com.github.irshulx.Components.InputExtensions.java

private void updateTextStyle(TextView editText, EditorTextStyle editorTextStyle) {
    EditorControl tag;//from   ww  w.ja v a2 s  . com
    if (editText == null) {
        editText = (EditText) editorCore.getActiveView();
    }
    EditorControl editorControl = editorCore.getControlTag(editText);
    if (isEditorTextStyleHeaders(editorTextStyle)) {
        if (editorCore.containsStyle(editorControl.editorTextStyles, editorTextStyle)) {
            editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, NORMALTEXTSIZE);
            editText.setTypeface(getTypeface(CONTENT, Typeface.NORMAL));
            tag = reWriteTags(editorControl, EditorTextStyle.NORMAL);
        } else {
            editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, getTextStyleFromStyle(editorTextStyle));
            editText.setTypeface(getTypeface(HEADING, Typeface.BOLD));
            tag = reWriteTags(editorControl, editorTextStyle);
        }
        editText.setTag(tag);
    }
}

From source file:io.development.tymo.adapters.FeedZoomMoreAdapter.java

@Override
public void onBindViewHolder(SimpleViewHolder holder, int position) {
    ActivityServer feedCubeModel;//from   w  w  w  . ja  va2s  .  c o m
    FlagServer feedFlagModel;
    holder.adapter = new PersonSmallAdapter(listPeople.get(position), mContext);
    holder.recyclerView.setAdapter(holder.adapter);
    if (mItems.get(position) instanceof ActivityServer) {
        holder.textDescription.setVisibility(View.VISIBLE);
        holder.cubeLowerBox.setVisibility(View.VISIBLE);
        holder.locationBox.setVisibility(View.VISIBLE);
        holder.pieceIcon.setVisibility(View.VISIBLE);
        holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE);
        holder.cubeLowerBoxIcon.setVisibility(View.VISIBLE);

        feedCubeModel = (ActivityServer) mItems.get(position);
        holder.textTitle.setText(feedCubeModel.getTitle());
        holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.grey_900));
        holder.textDescription.setText(feedCubeModel.getTitle());
        if (feedCubeModel.getDescription() != null && !feedCubeModel.getDescription().matches(""))
            holder.textDescription.setText(feedCubeModel.getDescription());
        else
            holder.textDescription.setVisibility(View.GONE);

        holder.cubeLowerBox.setVisibility(View.VISIBLE);
        holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE);
        holder.flagButton.setVisibility(View.GONE);

        holder.cubeUpperBoxIcon.setColorFilter(feedCubeModel.getCubeColorUpper());
        holder.cubeLowerBoxIcon.setColorFilter(feedCubeModel.getCubeColor());

        Glide.clear(holder.pieceIcon);
        Glide.with(mContext).load(feedCubeModel.getCubeIcon()).asBitmap()
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.pieceIcon);

        Calendar calendar = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar.set(feedCubeModel.getYearStart(), feedCubeModel.getMonthStart() - 1,
                feedCubeModel.getDayStart());
        calendar2.set(feedCubeModel.getYearEnd(), feedCubeModel.getMonthEnd() - 1, feedCubeModel.getDayEnd());
        String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK),
                calendar);
        String dayStart = String.format("%02d", feedCubeModel.getDayStart());
        String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar.getTime().getTime());
        int yearStart = feedCubeModel.getYearStart();
        String hourStart = String.format("%02d", feedCubeModel.getHourStart());
        String minuteStart = String.format("%02d", feedCubeModel.getMinuteStart());
        String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK),
                calendar2);
        String dayEnd = String.format("%02d", feedCubeModel.getDayEnd());
        String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar2.getTime().getTime());
        int yearEnd = feedCubeModel.getYearEnd();
        String hourEnd = String.format("%02d", feedCubeModel.getHourEnd());
        String minuteEnd = String.format("%02d", feedCubeModel.getMinuteEnd());

        if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) {
            if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart));
            } else {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd));
            }
        } else {
            holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart,
                    dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd,
                    yearEnd, hourEnd, minuteEnd));
        }

        if (!feedCubeModel.getLocation().matches("")) {
            SharedPreferences mSharedPreferences = mContext.getSharedPreferences(Constants.USER_CREDENTIALS,
                    MODE_PRIVATE);
            boolean location = mSharedPreferences.getBoolean(Constants.LOCATION, true);

            if (location) {
                LocationManager manager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);

                if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && lat != -500
                        && (feedCubeModel.getLat() != 0 && feedCubeModel.getLng() != 0)) {
                    double distance = Utilities.distance(lat, lng, feedCubeModel.getLat(),
                            feedCubeModel.getLng());
                    if (distance < 1) {
                        distanceText = mContext.getResources().getString(R.string.distance_meters,
                                (int) (distance * 1000)) + " ";
                    } else {
                        distanceText = mContext.getResources().getString(R.string.distance_km, (int) distance)
                                + " ";
                    }
                } else
                    distanceText = "";

            } else
                distanceText = "";

            if (!distanceText.matches("")) {
                final SpannableStringBuilder sb = new SpannableStringBuilder(
                        distanceText + feedCubeModel.getLocation());
                final StyleSpan styleBold = new StyleSpan(Typeface.BOLD);
                sb.setSpan(styleBold, 0, distanceText.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                holder.location.setText(sb);
            } else {
                holder.location.setText(feedCubeModel.getLocation());
            }

        } else {
            holder.locationBox.setVisibility(View.GONE);
            distanceText = "";
        }

        if (!feedCubeModel.getUser().getPhoto().matches("")) {
            Glide.clear(holder.photoCreator);
            Glide.with(mContext).load(feedCubeModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new BitmapImageViewTarget(holder.photoCreator) {
                        @Override
                        protected void setResource(Bitmap resource) {
                            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory
                                    .create(mContext.getResources(), resource);
                            circularBitmapDrawable.setCircular(true);
                            holder.photoCreator.setImageDrawable(circularBitmapDrawable);
                        }
                    });
        } else
            holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty);

        if (feedCubeModel.getFavoriteCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more);
        } else if (feedCubeModel.getKnowCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more);
        } else if (feedCubeModel.getUser().getEmail().equals(email)) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more);
        } else {
            holder.photoCreatorRingBox.setVisibility(View.INVISIBLE);
        }
    } else {
        feedFlagModel = (FlagServer) mItems.get(position);
        holder.textTitle.setText(mContext.getResources().getString(R.string.flag_available));
        holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.flag_available));
        if (feedFlagModel.getTitle().matches("")) {
            holder.textDescription.setVisibility(View.GONE);
        } else {
            holder.textDescription.setText(feedFlagModel.getTitle());
        }
        holder.cubeLowerBox.setVisibility(View.GONE);
        holder.cubeUpperBoxIcon.setVisibility(View.GONE);
        holder.flagButton.setVisibility(View.VISIBLE);
        holder.locationBox.setVisibility(View.GONE);

        Calendar calendar = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar.set(feedFlagModel.getYearStart(), feedFlagModel.getMonthStart() - 1,
                feedFlagModel.getDayStart());
        calendar2.set(feedFlagModel.getYearEnd(), feedFlagModel.getMonthEnd() - 1, feedFlagModel.getDayEnd());

        String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK),
                calendar);
        String dayStart = String.format("%02d", feedFlagModel.getDayStart());
        String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar.getTime().getTime());
        int yearStart = feedFlagModel.getYearStart();
        String hourStart = String.format("%02d", feedFlagModel.getHourStart());
        String minuteStart = String.format("%02d", feedFlagModel.getMinuteStart());
        String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK),
                calendar2);
        String dayEnd = String.format("%02d", feedFlagModel.getDayEnd());
        String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar2.getTime().getTime());
        int yearEnd = feedFlagModel.getYearEnd();
        String hourEnd = String.format("%02d", feedFlagModel.getHourEnd());
        String minuteEnd = String.format("%02d", feedFlagModel.getMinuteEnd());

        if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) {
            if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart));
            } else {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd));
            }
        } else {
            holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart,
                    dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd,
                    yearEnd, hourEnd, minuteEnd));
        }

        if (!feedFlagModel.getUser().getPhoto().matches("")) {
            Glide.clear(holder.photoCreator);
            Glide.with(mContext).load(feedFlagModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new BitmapImageViewTarget(holder.photoCreator) {
                        @Override
                        protected void setResource(Bitmap resource) {
                            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory
                                    .create(mContext.getResources(), resource);
                            circularBitmapDrawable.setCircular(true);
                            holder.photoCreator.setImageDrawable(circularBitmapDrawable);
                        }
                    });
        } else
            holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty);

        if (feedFlagModel.getFavoriteCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more);
        } else if (feedFlagModel.getKnowCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more);
        } else if (feedFlagModel.getUser().getEmail().equals(email)) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more);
        } else {
            holder.photoCreatorRingBox.setVisibility(View.INVISIBLE);
        }

    }

    if (holder.flagButton.getVisibility() == View.VISIBLE) {
        holder.pieceBox.startAnimation(animation2);
    } else {
        holder.pieceBox.startAnimation(animation2);
    }
    holder.textBox.startAnimation(animation);
    holder.triangle.startAnimation(animation);
}

From source file:org.mozilla.focus.fragment.UrlInputFragment.java

@Override
public void onFilter(String searchText, InlineAutocompleteEditText view) {
    // If the UrlInputFragment has already been hidden, don't bother with filtering. Because of the text
    // input architecture on Android it's possible for onFilter() to be called after we've already
    // hidden the Fragment, see the relevant bug for more background:
    // https://github.com/mozilla-mobile/focus-android/issues/441#issuecomment-293691141
    if (!isVisible()) {
        return;/*from  w  ww .  j a  v  a 2  s  .  com*/
    }

    urlAutoCompleteFilter.onFilter(searchText, view);

    if (searchText.length() == 0) {
        clearView.setVisibility(View.GONE);
        searchViewContainer.setVisibility(View.GONE);
    } else {
        clearView.setVisibility(View.VISIBLE);

        final String hint = getString(R.string.search_hint, searchText);

        final SpannableString content = new SpannableString(hint);
        content.setSpan(new StyleSpan(Typeface.BOLD), hint.length() - searchText.length(), hint.length(), 0);

        searchView.setText(content);
        searchViewContainer.setVisibility(View.VISIBLE);
    }
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyKeybaseFragment.java

@Override
public void onCryptoOperationSuccess(KeybaseVerificationResult result) {

    result.createNotify(getActivity()).show();

    String proofUrl = result.mProofUrl;
    String presenceUrl = result.mPresenceUrl;
    String presenceLabel = result.mPresenceLabel;

    Proof proof = mProof; // TODO: should ideally be contained in result

    String proofLabel;//from  w w w  .ja va2 s  .c  o m
    switch (proof.getType()) {
    case Proof.PROOF_TYPE_TWITTER:
        proofLabel = getString(R.string.keybase_twitter_proof);
        break;
    case Proof.PROOF_TYPE_DNS:
        proofLabel = getString(R.string.keybase_dns_proof);
        break;
    case Proof.PROOF_TYPE_WEB_SITE:
        proofLabel = getString(R.string.keybase_web_site_proof);
        break;
    case Proof.PROOF_TYPE_GITHUB:
        proofLabel = getString(R.string.keybase_github_proof);
        break;
    case Proof.PROOF_TYPE_REDDIT:
        proofLabel = getString(R.string.keybase_reddit_proof);
        break;
    default:
        proofLabel = getString(R.string.keybase_a_post);
        break;
    }

    SpannableStringBuilder ssb = new SpannableStringBuilder();

    ssb.append(getString(R.string.keybase_proof_succeeded));
    StyleSpan bold = new StyleSpan(Typeface.BOLD);
    ssb.setSpan(bold, 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append("\n\n");
    int length = ssb.length();
    ssb.append(proofLabel);
    if (proofUrl != null) {
        URLSpan postLink = new URLSpan(proofUrl);
        ssb.setSpan(postLink, length, length + proofLabel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (Proof.PROOF_TYPE_DNS == proof.getType()) {
        ssb.append(" ").append(getString(R.string.keybase_for_the_domain)).append(" ");
    } else {
        ssb.append(" ").append(getString(R.string.keybase_fetched_from)).append(" ");
    }
    length = ssb.length();
    URLSpan presenceLink = new URLSpan(presenceUrl);
    ssb.append(presenceLabel);
    ssb.setSpan(presenceLink, length, length + presenceLabel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (Proof.PROOF_TYPE_REDDIT == proof.getType()) {
        ssb.append(", ").append(getString(R.string.keybase_reddit_attribution)).append(" ")
                .append(proof.getHandle()).append("?, ");
    }
    ssb.append(" ").append(getString(R.string.keybase_contained_signature));

    displaySpannableResult(ssb);
}

From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java

private View createFabMenuItem(MenuItem menuItem) {
    ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext()).inflate(getMenuItemLayoutId(), this,
            false);/*from w w  w  .j a v a 2  s .com*/

    FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab);
    CardView cardView = (CardView) fabMenuItem.findViewById(R.id.card_view);
    TextView titleView = (TextView) fabMenuItem.findViewById(R.id.title_view);

    fabMenuItemMap.put(miniFab, menuItem);
    cardViewMenuItemMap.put(cardView, menuItem);

    miniFab.setImageDrawable(menuItem.getIcon());
    miniFab.setOnClickListener(this);
    cardView.setOnClickListener(this);

    ViewCompat.setAlpha(miniFab, 0f);
    ViewCompat.setAlpha(cardView, 0f);

    final CharSequence title = menuItem.getTitle();
    if (!TextUtils.isEmpty(title) && miniFabTitlesEnabled) {
        cardView.setCardBackgroundColor(miniFabTitleBackgroundTint.getDefaultColor());
        titleView.setText(title);
        titleView.setTypeface(null, Typeface.BOLD);
        titleView.setTextColor(miniFabTitleTextColor);

        if (miniFabTitleTextColorArray != null) {
            titleView.setTextColor(ContextCompat.getColorStateList(getContext(),
                    miniFabTitleTextColorArray[menuItem.getOrder()]));
        }
    } else {
        fabMenuItem.removeView(cardView);
    }

    miniFab.setBackgroundTintList(miniFabBackgroundTint);

    if (miniFabBackgroundTintArray != null) {
        miniFab.setBackgroundTintList(
                ContextCompat.getColorStateList(getContext(), miniFabBackgroundTintArray[menuItem.getOrder()]));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        miniFab.setImageTintList(miniFabDrawableTint);
    }

    return fabMenuItem;
}

From source file:com.gh4a.activities.IssueEditActivity.java

private void setLabelSelection(TextView view, boolean selected) {
    Label label = (Label) view.getTag();
    if (selected) {
        int color = ApiHelpers.colorForLabel(label);
        view.setTypeface(view.getTypeface(), Typeface.BOLD);
        view.setBackgroundColor(color);//  w w  w.j  a  v  a2  s  .c o  m
        view.setTextColor(UiUtils.textColorForBackground(this, color));
    } else {
        view.setTypeface(view.getTypeface(), 0);
        view.setBackgroundColor(0);
        view.setTextColor(ContextCompat.getColor(this,
                Gh4Application.THEME != R.style.LightTheme ? R.color.label_fg_light : R.color.label_fg_dark));
    }
}

From source file:com.guipenedo.pokeradar.activities.MapsActivity.java

/**
 * Manipulates the map once available.//from  ww w.  jav  a  2 s  .c o  m
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mMap.setMyLocationEnabled(true);
    mMap.getUiSettings().setMyLocationButtonEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.setOnMapLongClickListener(this);
    mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
        @Override
        public boolean onMyLocationButtonClick() {
            onConnected(null);
            update();
            return true;
        }
    });
    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker m) {
            PMarker marker = pokemonMarkers.get(m.getId());
            if (marker == null || marker.type != PMarker.MarkerType.GYM)
                return;
            Intent gymIntent = new Intent(MapsActivity.this, GymDetailsActivity.class);
            gymIntent.putExtra("gymDetails", (PGym) marker);
            startActivity(gymIntent);
        }
    });
    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        @Override
        public View getInfoContents(final Marker m) {

            Context mContext = MapsActivity.this;

            LinearLayout info = new LinearLayout(mContext);
            info.setOrientation(LinearLayout.VERTICAL);

            TextView title = new TextView(mContext);
            title.setText(m.getTitle());
            title.setTypeface(null, Typeface.BOLD);
            title.setGravity(Gravity.CENTER);
            info.addView(title);

            final PMarker marker = pokemonMarkers.get(m.getId());
            long timestamp = -1;
            if (marker != null) {
                if (marker.type == PMarker.MarkerType.CENTER) {
                    TextView littleNotice = new TextView(mContext);
                    littleNotice.setText(R.string.scan_center_infowindow);
                    littleNotice.setGravity(Gravity.CENTER);
                    info.addView(littleNotice);
                } else if (marker.type == PMarker.MarkerType.LUREDPOKESTOP) {
                    PPokestop pokestopMarker = (PPokestop) marker;
                    timestamp = pokestopMarker.getTimestamp();
                    TextView remainingTime = new TextView(mContext);
                    String text = String.format(getString(R.string.lured_remaining), Utils.countdownFromMillis(
                            mContext, pokestopMarker.getTimestamp() - System.currentTimeMillis()));
                    remainingTime.setText(text);
                    remainingTime.setGravity(Gravity.CENTER);
                    info.addView(remainingTime);
                    TextView expireTime = new TextView(mContext);
                    expireTime.setText(Utils.timeFromMillis(pokestopMarker.getTimestamp()));
                    expireTime.setGravity(Gravity.CENTER);
                    info.addView(expireTime);
                } else if (marker.type == PMarker.MarkerType.GYM) {
                    PGym gymMarker = (PGym) marker;
                    Team team = Team.fromTeamColor(gymMarker.getTeam());
                    TextView teamName = new TextView(mContext);
                    teamName.setText(team.getName());
                    teamName.setTextColor(team.getColor());
                    teamName.setGravity(Gravity.CENTER);
                    info.addView(teamName);
                    TextView prestige = new TextView(mContext);
                    prestige.setText(String.format(getString(R.string.gym_points), gymMarker.getPoints()));
                    prestige.setGravity(Gravity.CENTER);
                    info.addView(prestige);
                    TextView clickDetails = new TextView(mContext);
                    clickDetails.setText(R.string.gym_details);
                    clickDetails.setTypeface(null, Typeface.BOLD);
                    clickDetails.setGravity(Gravity.CENTER);
                    info.addView(clickDetails);
                } else if (marker.type == PMarker.MarkerType.POKEMON) {
                    PPokemon pokemonMarker = (PPokemon) marker;
                    timestamp = pokemonMarker.getTimestamp();
                    final TextView remainingTime = new TextView(mContext);
                    remainingTime.setText(
                            String.format(getString(R.string.pokemon_despawns_time), Utils.countdownFromMillis(
                                    mContext, pokemonMarker.getTimestamp() - System.currentTimeMillis())));
                    remainingTime.setGravity(Gravity.CENTER);
                    info.addView(remainingTime);
                    TextView expireTime = new TextView(mContext);
                    expireTime.setText(Utils.timeFromMillis(pokemonMarker.getTimestamp()));
                    expireTime.setGravity(Gravity.CENTER);
                    info.addView(expireTime);
                }
                if (timestamp != -1 && (countdownMarker == null || !countdownMarker.equals(m.getId()))) {
                    countdownMarker = m.getId();
                    new CountDownTimer(timestamp - System.currentTimeMillis(), 1000) {

                        public void onTick(long millisUntilFinished) {
                            if (markers.contains(m) && m.isInfoWindowShown())
                                m.showInfoWindow();
                            else
                                cancel();
                        }

                        @Override
                        public void onFinish() {
                            countdownMarker = null;
                        }
                    }.start();
                }
            }
            return info;
        }
    });
    update();
}

From source file:com.battlelancer.seriesguide.service.NotificationService.java

private void onNotify(final Cursor upcomingEpisodes, List<Integer> notifyPositions, long latestAirtime) {
    final Context context = getApplicationContext();

    CharSequence tickerText;/*from w w w. j a v  a 2  s.  c o m*/
    CharSequence contentTitle;
    CharSequence contentText;
    PendingIntent contentIntent;
    // base intent for task stack
    final Intent showsIntent = new Intent(context, ShowsActivity.class);
    showsIntent.putExtra(ShowsActivity.InitBundle.SELECTED_TAB, ShowsActivity.InitBundle.INDEX_TAB_UPCOMING);

    final int count = notifyPositions.size();
    if (count == 1) {
        // notify in detail about one episode
        Timber.d("Notifying about 1 new episode");
        upcomingEpisodes.moveToPosition(notifyPositions.get(0));

        final String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE);
        tickerText = getString(R.string.upcoming_show, showTitle);
        contentTitle = showTitle + " "
                + Utils.getEpisodeNumber(this, upcomingEpisodes.getInt(NotificationQuery.SEASON),
                        upcomingEpisodes.getInt(NotificationQuery.NUMBER));

        // "8:00 PM on Network"
        final String releaseTime = TimeTools.formatToLocalReleaseTime(this, TimeTools.getEpisodeReleaseTime(
                this, upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS)));
        final String network = upcomingEpisodes.getString(NotificationQuery.NETWORK);
        contentText = getString(R.string.upcoming_show_detailed, releaseTime, network);

        Intent episodeDetailsIntent = new Intent(context, EpisodesActivity.class);
        episodeDetailsIntent.putExtra(EpisodesActivity.InitBundle.EPISODE_TVDBID,
                upcomingEpisodes.getInt(NotificationQuery._ID));
        episodeDetailsIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime);

        contentIntent = TaskStackBuilder.create(context).addNextIntent(showsIntent)
                .addNextIntent(episodeDetailsIntent)
                .getPendingIntent(REQUEST_CODE_SINGLE_EPISODE, PendingIntent.FLAG_CANCEL_CURRENT);
    } else {
        // notify about multiple episodes
        Timber.d("Notifying about " + count + " new episodes");
        tickerText = getString(R.string.upcoming_episodes);
        contentTitle = getString(R.string.upcoming_episodes_number, count);
        contentText = getString(R.string.upcoming_display);

        contentIntent = TaskStackBuilder.create(context)
                .addNextIntent(showsIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime))
                .getPendingIntent(REQUEST_CODE_MULTIPLE_EPISODES, PendingIntent.FLAG_CANCEL_CURRENT);
    }

    final NotificationCompat.Builder nb = new NotificationCompat.Builder(context);

    if (AndroidUtils.isJellyBeanOrHigher()) {
        Timber.d("Building rich notification (JB+)");
        // JELLY BEAN and above
        if (count == 1) {
            // single episode
            upcomingEpisodes.moveToPosition(notifyPositions.get(0));
            maybeSetPoster(context, nb, upcomingEpisodes.getString(NotificationQuery.POSTER));

            final String episodeTitle = upcomingEpisodes.getString(NotificationQuery.TITLE);
            final String episodeSummary = upcomingEpisodes.getString(NotificationQuery.OVERVIEW);

            final SpannableStringBuilder bigText = new SpannableStringBuilder();
            bigText.append(TextUtils.isEmpty(episodeTitle) ? "" : episodeTitle);
            bigText.setSpan(new StyleSpan(Typeface.BOLD), 0, bigText.length(), 0);
            bigText.append("\n");
            bigText.append(TextUtils.isEmpty(episodeSummary) ? "" : episodeSummary);

            nb.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(contentText));

            // Action button to check in
            Intent checkInActionIntent = new Intent(context, QuickCheckInActivity.class);
            checkInActionIntent.putExtra(QuickCheckInActivity.InitBundle.EPISODE_TVDBID,
                    upcomingEpisodes.getInt(NotificationQuery._ID));
            checkInActionIntent
                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            PendingIntent checkInIntent = PendingIntent.getActivity(context, REQUEST_CODE_ACTION_CHECKIN,
                    checkInActionIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            nb.addAction(R.drawable.ic_action_checkin, getString(R.string.checkin), checkInIntent);
        } else {
            // multiple episodes
            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

            // display at most the first five
            for (int displayIndex = 0; displayIndex < Math.min(count, 5); displayIndex++) {
                if (!upcomingEpisodes.moveToPosition(notifyPositions.get(displayIndex))) {
                    // could not go to the desired position (testing just in case)
                    break;
                }

                final SpannableStringBuilder lineText = new SpannableStringBuilder();

                // show title
                String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE);
                lineText.append(TextUtils.isEmpty(showTitle) ? "" : showTitle);
                lineText.setSpan(new StyleSpan(Typeface.BOLD), 0, lineText.length(), 0);

                lineText.append(" ");

                // "8:00 PM on Network"
                String releaseTime = TimeTools.formatToLocalReleaseTime(this, TimeTools.getEpisodeReleaseTime(
                        this, upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS)));
                String network = upcomingEpisodes.getString(NotificationQuery.NETWORK);
                lineText.append(getString(R.string.upcoming_show_detailed, releaseTime, network));

                inboxStyle.addLine(lineText);
            }

            // tell if we could not display all episodes
            if (count > 5) {
                inboxStyle.setSummaryText(getString(R.string.more, count - 5));
            }

            nb.setStyle(inboxStyle);
            nb.setContentInfo(String.valueOf(count));
        }
    } else {
        // ICS and below
        if (count == 1) {
            // single episode
            upcomingEpisodes.moveToPosition(notifyPositions.get(0));
            maybeSetPoster(context, nb, upcomingEpisodes.getString(NotificationQuery.POSTER));
        }
    }

    // notification sound
    final String ringtoneUri = NotificationSettings.getNotificationsRingtone(context);
    // If the string is empty, the user chose silent...
    if (ringtoneUri.length() != 0) {
        // ...otherwise set the specified ringtone
        Timber.d("Notification has sound");
        nb.setSound(Uri.parse(ringtoneUri));
    }
    // vibration
    if (NotificationSettings.isNotificationVibrating(context)) {
        Timber.d("Notification vibrates");
        nb.setVibrate(VIBRATION_PATTERN);
    }
    nb.setDefaults(Notification.DEFAULT_LIGHTS);
    nb.setWhen(System.currentTimeMillis());
    nb.setAutoCancel(true);
    nb.setTicker(tickerText);
    nb.setContentTitle(contentTitle);
    nb.setContentText(contentText);
    nb.setContentIntent(contentIntent);
    nb.setSmallIcon(R.drawable.ic_notification);
    nb.setColor(getResources().getColor(R.color.accent_primary));
    nb.setPriority(NotificationCompat.PRIORITY_DEFAULT);
    nb.setCategory(NotificationCompat.CATEGORY_EVENT);

    Timber.d("Setting delete intent with episode time: " + latestAirtime);
    Intent i = new Intent(this, NotificationService.class);
    i.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime);
    PendingIntent deleteIntent = PendingIntent.getService(this, REQUEST_CODE_DELETE_INTENT, i,
            PendingIntent.FLAG_CANCEL_CURRENT);
    nb.setDeleteIntent(deleteIntent);

    // build the notification
    Notification notification = nb.build();

    // use string resource id, always unique within app
    final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(R.string.upcoming_show, notification);
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void addTitle(String text, int type) {
    TextView txt = new TextView(getActivity());
    txt.setText(text);//from   w w w. j a  v  a 2 s.  c om
    txt.setTypeface(Typeface.create("sans-serif-condensed", Typeface.BOLD));
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(10, 10, 10, 0);
    txt.setLayoutParams(params);
    txt.setTextIsSelectable(true);

    switch (type) {
    case 1:
        txt.setTextSize(26);
        break;
    case 2:
        txt.setTextSize(24);
        break;
    case 3:
        txt.setTextSize(22);
        break;
    case 4:
        txt.setTextSize(20);
        break;
    case 5:
        txt.setTextSize(18);
        break;
    default:
        break;
    }

    lay.addView(txt);
}

From source file:com.csipsimple.service.SipNotifications.java

protected static CharSequence buildTickerMessage(Context context, String address, String body) {
    String displayAddress = address;

    StringBuilder buf = new StringBuilder(
            displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' '));
    buf.append(':').append(' ');

    int offset = buf.length();

    if (!TextUtils.isEmpty(body)) {
        body = body.replace('\n', ' ').replace('\r', ' ');
        buf.append(body);//from   w  ww  .  j ava  2  s  .  c om
    }

    SpannableString spanText = new SpannableString(buf.toString());
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanText;
}