Example usage for android.text.style StyleSpan StyleSpan

List of usage examples for android.text.style StyleSpan StyleSpan

Introduction

In this page you can find the example usage for android.text.style StyleSpan StyleSpan.

Prototype

public StyleSpan(@NonNull Parcel src) 

Source Link

Document

Creates a StyleSpan from a parcel.

Usage

From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java

private static void appendPushNotificationState(Context context, MasterSecret masterSecret,
        NotificationState notificationState, Cursor cursor) {
    if (masterSecret != null)
        return;/*from w  w  w  .  j a v  a 2s . c o  m*/

    PushDatabase.Reader reader = null;
    TextSecureEnvelope envelope;

    try {
        reader = DatabaseFactory.getPushDatabase(context).readerFor(cursor);

        while ((envelope = reader.getNext()) != null) {
            Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(),
                    false);
            Recipient recipient = recipients.getPrimaryRecipient();
            long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
            SpannableString body = new SpannableString(
                    context.getString(R.string.MessageNotifier_encrypted_message));
            body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            if (!recipients.isMuted()) {
                notificationState.addNotification(
                        new NotificationItem(recipient, recipients, null, threadId, body, null, 0));
            }
        }
    } finally {
        if (reader != null)
            reader.close();
    }
}

From source file:com.keylesspalace.tusky.activity.MainActivity.java

private void setupSearchView() {
    searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());

    searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
        @Override/*from   w ww .  j av  a 2 s.c o m*/
        public void onSearchTextChanged(String oldQuery, String newQuery) {
            if (!oldQuery.equals("") && newQuery.equals("")) {
                searchView.clearSuggestions();
                return;
            }

            if (newQuery.length() < 3) {
                return;
            }

            searchView.showProgress();

            mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() {
                @Override
                public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
                    if (response.isSuccessful()) {
                        searchView.swapSuggestions(response.body());
                        searchView.hideProgress();
                    } else {
                        searchView.hideProgress();
                    }
                }

                @Override
                public void onFailure(Call<List<Account>> call, Throwable t) {
                    searchView.hideProgress();
                }
            });
        }
    });

    searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
        @Override
        public void onSuggestionClicked(SearchSuggestion searchSuggestion) {
            Account accountSuggestion = (Account) searchSuggestion;
            Intent intent = new Intent(MainActivity.this, AccountActivity.class);
            intent.putExtra("id", accountSuggestion.id);
            startActivity(intent);
        }

        @Override
        public void onSearchAction(String currentQuery) {

        }
    });

    searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
        @Override
        public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView,
                SearchSuggestion item, int itemPosition) {
            Account accountSuggestion = ((Account) item);

            Picasso.with(MainActivity.this).load(accountSuggestion.avatar)
                    .placeholder(R.drawable.avatar_default).into(leftIcon);

            String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username;
            final SpannableStringBuilder str = new SpannableStringBuilder(searchStr);

            str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            textView.setText(str);
            textView.setMaxLines(1);
            textView.setEllipsize(TextUtils.TruncateAt.END);
        }
    });
}

From source file:com.appeaser.sublimepicker.Sampler.java

private SpannableStringBuilder applyBoldStyle(String text) {
    SpannableStringBuilder ss = new SpannableStringBuilder(text);
    ss.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ss;/*from  w  ww  .  j a va 2 s.c  o  m*/
}

From source file:com.onesignal.GenerateNotification.java

static void createSummaryNotification(Context inContext, boolean updateSummary, JSONObject gcmBundle) {
    if (updateSummary)
        setStatics(inContext);//from   w w  w  .j a va 2 s  . c o 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: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.  ja  va2  s  .  c o m*/
        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:io.development.tymo.adapters.FeedZoomMoreAdapter.java

@Override
public void onBindViewHolder(SimpleViewHolder holder, int position) {
    ActivityServer feedCubeModel;/*from  ww  w. j  a  va  2s .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 av a 2s.c o  m*/
    }

    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   www . j  a  va 2s. c  om
    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:com.battlelancer.seriesguide.service.NotificationService.java

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

    CharSequence tickerText;/*from  www . j a v a 2s  .  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.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 www  .  j  a  v a  2 s . c  o m
    }

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

    return spanText;
}