Example usage for android.text SpannableStringBuilder SpannableStringBuilder

List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder

Introduction

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

Prototype

public SpannableStringBuilder() 

Source Link

Document

Create a new SpannableStringBuilder with empty contents

Usage

From source file:org.chromium.chrome.browser.notifications.NotificationUIManager.java

/**
 * Creates the ticker text for a notification having |title| and |body|. The notification's
 * title will be printed in bold, followed by the text of the body.
 *
 * @param title Title of the notification.
 * @param body Textual contents of the notification.
 * @return A character sequence containing the ticker's text.
 *//*from   w w  w. j a va2 s .  co m*/
private CharSequence createTickerText(String title, String body) {
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();

    spannableStringBuilder.append(title);
    spannableStringBuilder.append("\n");
    spannableStringBuilder.append(body);

    // Mark the title of the notification as being bold.
    spannableStringBuilder.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, title.length(),
            Spannable.SPAN_INCLUSIVE_INCLUSIVE);

    return spannableStringBuilder;
}

From source file:com.android.launcher2.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(/*from   w w  w . j av a2s. co m*/
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

    super.onCreate(savedInstanceState);
    LauncherApplication app = ((LauncherApplication) getApplication());
    mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    checkForLocaleChange();
    setContentView(R.layout.launcher);
    setupViews();
    showFirstRunWorkspaceCling();

    registerContentObservers();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    // Update customization drawer _after_ restoring the states
    if (mAppsCustomizeContent != null) {
        mAppsCustomizeContent.onPackagesUpdated();
    }

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        if (sPausedFromUserAction) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, -1);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(true, mWorkspace.getCurrentPage());
        }
    }

    if (!mModel.isAllAppsLoaded()) {
        ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
        mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);

    updateGlobalIcons();

    // On large interfaces, we want the screen to auto-rotate based on the current orientation
    unlockScreenOrientation(true);
}

From source file:in.shick.diode.threads.ThreadsListActivity.java

public static void fillThreadsListItemView(int position, View view, ThingInfo item, ListActivity activity,
        HttpClient client, RedditSettings settings,
        ThumbnailOnClickListenerFactory thumbnailOnClickListenerFactory) {

    Resources res = activity.getResources();
    ViewHolder vh;//from w ww .ja  va 2s .  c o m
    if (view.getTag() == null) {
        vh = new ViewHolder();
        vh.titleView = (TextView) view.findViewById(R.id.title);
        vh.votesView = (TextView) view.findViewById(R.id.votes);
        vh.numCommentsSubredditView = (TextView) view.findViewById(R.id.numCommentsSubreddit);
        vh.nsfwView = (TextView) view.findViewById(R.id.nsfw);
        vh.voteUpView = (ImageView) view.findViewById(R.id.vote_up_image);
        vh.voteDownView = (ImageView) view.findViewById(R.id.vote_down_image);
        vh.thumbnailContainer = view.findViewById(R.id.thumbnail_view);
        vh.thumbnailFrame = (FrameLayout) view.findViewById(R.id.thumbnail_frame);
        vh.thumbnailImageView = (ImageView) view.findViewById(R.id.thumbnail);
        vh.indeterminateProgressBar = (ProgressBar) view.findViewById(R.id.indeterminate_progress);
        view.setTag(vh);
    } else {
        vh = (ViewHolder) view.getTag();
    }

    // Need to store the Thing's id in the thumbnail image so that the thumbnail loader task
    // knows that the row is still displaying the requested thumbnail.
    vh.thumbnailImageView.setTag(item.getId());
    // Set the title and domain using a SpannableStringBuilder
    SpannableStringBuilder builder = new SpannableStringBuilder();
    String title = item.getTitle();
    if (title == null)
        title = "";
    SpannableString titleSS = new SpannableString(title);
    int titleLen = title.length();
    titleSS.setSpan(
            new TextAppearanceSpan(activity,
                    Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Large)),
            0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    String domain = item.getDomain();
    if (domain == null)
        domain = "";
    String flair = item.getLink_flair_text();
    if (flair == null) {
        flair = "";
    } else {
        flair = "[" + flair + "] ";
    }
    int domainLen = domain.length() + flair.length();
    SpannableString domainSS = new SpannableString(flair + "(" + item.getDomain() + ")");
    domainSS.setSpan(
            new TextAppearanceSpan(activity,
                    Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Small)),
            0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (Util.isLightTheme(settings.getTheme())) {
        if (item.isClicked()) {
            ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.purple));
            titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.blue));
            titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_50)), 0, domainLen + 2,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        if (item.isClicked()) {
            ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.gray_50));
            titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_75)), 0, domainLen + 2,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    builder.append(titleSS).append(" ").append(domainSS);
    vh.titleView.setText(builder);

    vh.votesView.setText(String.format(Locale.US, "%d", item.getScore()));
    // Lock icon emoji
    String preText = item.isLocked() ? "\uD83D\uDD12 " : "";
    vh.numCommentsSubredditView
            .setText(preText + Util.showNumComments(item.getNum_comments()) + "  " + item.getSubreddit());

    vh.nsfwView.setVisibility(item.isOver_18() ? View.VISIBLE : View.GONE);

    // Set the up and down arrow colors based on whether user likes
    if (settings.isLoggedIn()) {
        if (item.getLikes() == null) {
            vh.voteUpView.setImageResource(R.drawable.vote_up_gray);
            vh.voteDownView.setImageResource(R.drawable.vote_down_gray);
            vh.votesView.setTextColor(res.getColor(R.color.gray_75));
        } else if (item.getLikes()) {
            vh.voteUpView.setImageResource(R.drawable.vote_up_red);
            vh.voteDownView.setImageResource(R.drawable.vote_down_gray);
            vh.votesView.setTextColor(res.getColor(R.color.arrow_red));
        } else {
            vh.voteUpView.setImageResource(R.drawable.vote_up_gray);
            vh.voteDownView.setImageResource(R.drawable.vote_down_blue);
            vh.votesView.setTextColor(res.getColor(R.color.arrow_blue));
        }
    } else {
        vh.voteUpView.setImageResource(R.drawable.vote_up_gray);
        vh.voteDownView.setImageResource(R.drawable.vote_down_gray);
        vh.votesView.setTextColor(res.getColor(R.color.gray_75));
    }

    // Thumbnails open links
    if (vh.thumbnailContainer != null) {
        if (Common.shouldLoadThumbnails(activity, settings)) {
            vh.thumbnailContainer.setVisibility(View.VISIBLE);

            if (item.getUrl() != null) {
                OnClickListener thumbnailOnClickListener = thumbnailOnClickListenerFactory
                        .getThumbnailOnClickListener(item, activity);
                if (thumbnailOnClickListener != null) {
                    vh.thumbnailFrame.setOnClickListener(thumbnailOnClickListener);
                }
            }

            // Show thumbnail based on ThingInfo
            if (Constants.NSFW_STRING.equalsIgnoreCase(item.getThumbnail())
                    || Constants.DEFAULT_STRING.equals(item.getThumbnail())
                    || Constants.SUBMIT_KIND_SELF.equals(item.getThumbnail())
                    || StringUtils.isEmpty(item.getThumbnail())) {
                vh.indeterminateProgressBar.setVisibility(View.GONE);
                vh.thumbnailImageView.setVisibility(View.VISIBLE);
                vh.thumbnailImageView.setImageResource(R.drawable.go_arrow);
            } else {
                if (item.getThumbnailBitmap() != null) {
                    vh.indeterminateProgressBar.setVisibility(View.GONE);
                    vh.thumbnailImageView.setVisibility(View.VISIBLE);
                    vh.thumbnailImageView.setImageBitmap(item.getThumbnailBitmap());
                } else {
                    vh.indeterminateProgressBar.setVisibility(View.VISIBLE);
                    vh.thumbnailImageView.setVisibility(View.GONE);
                    vh.thumbnailImageView.setImageBitmap(null);
                    new ShowThumbnailsTask(activity, client, R.drawable.go_arrow)
                            .execute(new ThumbnailLoadAction(item, vh.thumbnailImageView, position,
                                    vh.indeterminateProgressBar));
                }
            }

            // Set thumbnail background based on current theme
            if (Util.isLightTheme(settings.getTheme()))
                vh.thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_light);
            else
                vh.thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_dark);
        } else {
            // if thumbnails disabled, hide thumbnail icon
            vh.thumbnailContainer.setVisibility(View.GONE);
        }
    }
}

From source file:com.android.mms.ui.MessageListItem.java

private void bindCommonMessage(final boolean sameItem) {
    if (mDownloadButton != null) {
        mDownloadButton.setVisibility(View.GONE);
        mDownloading.setVisibility(View.GONE);
    }//from w  w w. ja v  a 2  s. c  o m

    // Since the message text should be concatenated with the sender's
    // address(or name), I have to display it here instead of
    // displaying it by the Presenter.
    mBodyTextView.setTransformationMethod(HideReturnsTransformationMethod.getInstance());

    boolean haveLoadedPdu = mMessageItem.isSms() || mMessageItem.mSlideshow != null;
    // Here we're avoiding reseting the avatar to the empty avatar when we're rebinding
    // to the same item. This happens when there's a DB change which causes the message item
    // cache in the MessageListAdapter to get cleared. When an mms MessageItem is newly
    // created, it has no info in it except the message id. The info is eventually loaded
    // and bindCommonMessage is called again (see onPduLoaded below). When we haven't loaded
    // the pdu, we don't want to call updateAvatarView because it
    // will set the avatar to the generic avatar then when this method is called again
    // from onPduLoaded, it will reset to the real avatar. This test is to avoid that flash.
    if (!sameItem || haveLoadedPdu) {
        boolean isSelf = Sms.isOutgoingFolder(mMessageItem.mBoxId);
        String addr = isSelf ? null : mMessageItem.mAddress;
        updateAvatarView(addr, isSelf);
    }

    // Add SIM sms address above body.
    if (isSimCardMessage()) {
        mSimMessageAddress.setVisibility(VISIBLE);
        SpannableStringBuilder buf = new SpannableStringBuilder();
        if (mMessageItem.mBoxId == Sms.MESSAGE_TYPE_INBOX) {
            buf.append(mContext.getString(R.string.from_label));
        } else {
            buf.append(mContext.getString(R.string.to_address_label));
        }
        buf.append(Contact.get(mMessageItem.mAddress, true).getName());
        mSimMessageAddress.setText(buf);
    }

    // Get and/or lazily set the formatted message from/on the
    // MessageItem.  Because the MessageItem instances come from a
    // cache (currently of size ~50), the hit rate on avoiding the
    // expensive formatMessage() call is very high.
    CharSequence formattedMessage = mMessageItem.getCachedFormattedMessage();
    if (formattedMessage == null) {
        formattedMessage = formatMessage(mMessageItem, mMessageItem.mBody, mMessageItem.mSubject,
                mMessageItem.mHighlight, mMessageItem.mTextContentType);
        mMessageItem.setCachedFormattedMessage(formattedMessage);
    }
    if (!sameItem || haveLoadedPdu) {
        mBodyTextView.setText(formattedMessage);
    }
    updateSimIndicatorView(mMessageItem.mSubId);
    // Debugging code to put the URI of the image attachment in the body of the list item.
    if (DEBUG) {
        String debugText = null;
        if (mMessageItem.mSlideshow == null) {
            debugText = "NULL slideshow";
        } else {
            SlideModel slide = ((SlideshowModel) mMessageItem.mSlideshow).get(0);
            if (slide == null) {
                debugText = "NULL first slide";
            } else if (!slide.hasImage()) {
                debugText = "Not an image";
            } else {
                debugText = slide.getImage().getUri().toString();
            }
        }
        mBodyTextView.setText(mPosition + ": " + debugText);
    }

    // If we're in the process of sending a message (i.e. pending), then we show a "SENDING..."
    // string in place of the timestamp.
    if (!sameItem || haveLoadedPdu) {
        boolean isCountingDown = mMessageItem.getCountDown() > 0
                && MessagingPreferenceActivity.getMessageSendDelayDuration(mContext) > 0;
        int sendingTextResId = isCountingDown ? R.string.sent_countdown : R.string.sending_message;
        mDateView.setText(buildTimestampLine(
                mMessageItem.isSending() ? mContext.getResources().getString(sendingTextResId)
                        : mMessageItem.mTimestamp));
    }
    if (mMessageItem.isSms()) {
        showMmsView(false);
        mMessageItem.setOnPduLoaded(null);
    } else {
        if (DEBUG) {
            Log.v(TAG,
                    "bindCommonMessage for item: " + mPosition + " " + mMessageItem.toString()
                            + " mMessageItem.mAttachmentType: " + mMessageItem.mAttachmentType + " sameItem: "
                            + sameItem);
        }
        if (mMessageItem.mAttachmentType != WorkingMessage.TEXT) {
            if (!sameItem) {
                setImage(null, null);
            }
            setOnClickListener(mMessageItem);
            drawPlaybackButton(mMessageItem);
        } else {
            showMmsView(false);
        }
        if (mMessageItem.mSlideshow == null) {
            final int mCurrentAttachmentType = mMessageItem.mAttachmentType;
            mMessageItem.setOnPduLoaded(new MessageItem.PduLoadedCallback() {
                public void onPduLoaded(MessageItem messageItem) {
                    if (DEBUG) {
                        Log.v(TAG,
                                "PduLoadedCallback in MessageListItem for item: " + mPosition + " "
                                        + (mMessageItem == null ? "NULL" : mMessageItem.toString())
                                        + " passed in item: "
                                        + (messageItem == null ? "NULL" : messageItem.toString()));
                    }
                    if (messageItem != null && mMessageItem != null
                            && messageItem.getMessageId() == mMessageItem.getMessageId()) {
                        mMessageItem.setCachedFormattedMessage(null);
                        bindCommonMessage(mCurrentAttachmentType == messageItem.mAttachmentType);
                    }
                }
            });
        } else {
            if (mPresenter == null) {
                mPresenter = PresenterFactory.getPresenter("MmsThumbnailPresenter", mContext, this,
                        mMessageItem.mSlideshow);
            } else {
                mPresenter.setModel(mMessageItem.mSlideshow);
                mPresenter.setView(this);
            }
            if (mImageLoadedCallback == null) {
                mImageLoadedCallback = new ImageLoadedCallback(this);
            } else {
                mImageLoadedCallback.reset(this);
            }
            mPresenter.present(mImageLoadedCallback);
        }
    }
    drawRightStatusIndicator(mMessageItem);
    requestLayout();
}

From source file:com.juick.android.ThreadActivity.java

public void onReplySelected(final JuickMessage msg) {
    selectedReply = msg;/*from   www  . j  av  a2s .  c om*/
    rid = msg.getRID();
    if (rid > 0) {
        SpannableStringBuilder ssb = new SpannableStringBuilder();
        String inreplyto = getResources().getString(R.string.In_reply_to_) + " ";
        ssb.append(inreplyto).append(msg.Text);
        ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, inreplyto.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvReplyTo.setText(ssb);
        setHeight(replyToContainer, ActionBar.LayoutParams.WRAP_CONTENT);
        showThread.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tf.showThread(msg, false);
            }
        });
    } else {
        setHeight(replyToContainer, 0);
    }
}

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

@SuppressWarnings("unused")
@Override//from   www  .  j  a  va 2s. c  o m
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

    super.onCreate(savedInstanceState);
    LauncherApplication app = ((LauncherApplication) getApplication());
    mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mAppWidgetManager = AppWidgetManager.getInstance(this);
    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    checkForLocaleChange();

    if (MainConfiguration.SCREEN_COUNT == 2) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_2);
        else
            setContentView(R.layout.launcher_2);
    } else if (MainConfiguration.SCREEN_COUNT == 3) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_3);
        else
            setContentView(R.layout.launcher_3);
    } else if (MainConfiguration.SCREEN_COUNT == 4) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_4);
        else
            setContentView(R.layout.launcher_4);
    } else if (MainConfiguration.SCREEN_COUNT == 5) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_5);
        else
            setContentView(R.layout.launcher_5);
    } else if (MainConfiguration.SCREEN_COUNT == 6) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_6);
        else
            setContentView(R.layout.launcher_6);
    } else if (MainConfiguration.SCREEN_COUNT == 7) {
        if (MainConfiguration.ALLOW_DRAWER)
            setContentView(R.layout.drawer_launcher_7);
        else
            setContentView(R.layout.launcher_7);
    } else {
        setContentView(R.layout.launcher_5);
    }

    setupViews();
    showFirstRunWorkspaceCling();

    if (MainConfiguration.ALLOW_DRAWER) {
        this.drawerLayout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
        ((LauncherDrawerLayout) this.drawerLayout).postInit(this, this.mWorkspace, this.mSharedPrefs);
    }

    registerContentObservers();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    // Update customization drawer _after_ restoring the states
    if (mAppsCustomizeContent != null) {
        mAppsCustomizeContent.onPackagesUpdated();
    }

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        if (sPausedFromUserAction) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, -1);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(true, mWorkspace.getCurrentPage());
        }
    }

    if (!mModel.isAllAppsLoaded()) {
        ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent();
        mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent);
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);

    updateGlobalIcons();

    // On large interfaces, we want the screen to auto-rotate based on the current orientation
    unlockScreenOrientation(true);
}

From source file:com.android.talkback.formatter.TouchExplorationFormatter.java

/**
 * Returns the collection's name plus its role. If {@code detailed} is true, then adds
 * the collection row/column count as well.
 * *//*w ww. j a  va2s.  com*/
private CharSequence getCollectionDescription(@NonNull CollectionState state, boolean detailed) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    StringBuilderUtils.append(builder, state.getCollectionName(), state.getCollectionRoleDescription(mService));

    if (detailed) {
        int collectionLevel = state.getCollectionLevel();
        if (collectionLevel >= 0) {
            String levelText = mService.getString(R.string.template_collection_level, collectionLevel + 1);
            StringBuilderUtils.appendWithSeparator(builder, levelText);
        }

        int rowCount = state.getCollectionRowCount();
        int columnCount = state.getCollectionColumnCount();

        if (state.getCollectionRole() == Role.ROLE_GRID && rowCount != -1 && columnCount != -1) {
            String rowText = mService.getResources().getQuantityString(R.plurals.template_list_row_count,
                    rowCount, rowCount);
            String columnText = mService.getResources().getQuantityString(R.plurals.template_list_column_count,
                    columnCount, columnCount);
            StringBuilderUtils.appendWithSeparator(builder, rowText, columnText);
        } else if (state.getCollectionRole() == Role.ROLE_LIST) {
            if (state.getCollectionAlignment() == CollectionState.ALIGNMENT_VERTICAL && rowCount != -1) {
                String totalText = mService.getResources()
                        .getQuantityString(R.plurals.template_list_total_count, rowCount, rowCount);
                StringBuilderUtils.appendWithSeparator(builder, totalText);
            } else if (state.getCollectionAlignment() == CollectionState.ALIGNMENT_HORIZONTAL
                    && columnCount != -1) {
                String totalText = mService.getResources()
                        .getQuantityString(R.plurals.template_list_total_count, columnCount, columnCount);
                StringBuilderUtils.appendWithSeparator(builder, totalText);
            }
        }
    }

    return builder;
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(//from  w  ww .j  a  v  a2s  .c o m
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

    predictiveAppsProvider = new PredictiveAppsProvider(this);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.preOnCreate();
    }

    try {
        super.onCreate(savedInstanceState);
    } catch (Exception e) {
        super.onCreate(new Bundle());
    }

    UpdateUtils.checkUpdate(this);
    LauncherAppState app = LauncherAppState.getInstance();

    // Load configuration-specific DeviceProfile
    mDeviceProfile = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            ? app.getInvariantDeviceProfile().landscapeProfile
            : app.getInvariantDeviceProfile().portraitProfile;

    mSharedPrefs = Utilities.getPrefs(this);
    mIsSafeModeEnabled = getPackageManager().isSafeMode();
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();

    mDragController = new DragController(this);
    mInflater = getLayoutInflater();
    mStateTransitionAnimation = new LauncherStateTransitionAnimation(this);

    mStats = new Stats(this);

    mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);

    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    setContentView(R.layout.launcher);

    app.getInvariantDeviceProfile().landscapeProfile.setSearchBarHeight(getSearchBarHeight());
    app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
    setupViews();
    setUpBlur();

    mDeviceProfile.layout(this);

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(PagedView.INVALID_RESTORE_PAGE);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(mWorkspace.getRestorePage());
        }
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);

    mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
    // In case we are on a device with locked rotation, we should look at preferences to check
    // if the user has specifically allowed rotation.
    if (!mRotationEnabled) {
        mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
    }

    // On large interfaces, or on devices that a user has specifically enabled screen rotation,
    // we want the screen to auto-rotate based on the current orientation
    setOrientation();

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
    }

    if (shouldShowIntroScreen()) {
        showIntroScreen();
    } else {
        showFirstRunActivity();
        showFirstRunClings();
    }
}

From source file:com.gsma.rcs.ri.messaging.adapter.TalkCursorAdapter.java

private CharSequence formatMessageWithSmiley(String txt) {
    SpannableStringBuilder buf = new SpannableStringBuilder();
    if (!TextUtils.isEmpty(txt)) {
        SmileyParser smileyParser = new SmileyParser(txt, mSmileyResources);
        smileyParser.parse();/*w w  w.java 2s.  c  o m*/
        buf.append(smileyParser.getSpannableString(mContext));
    }
    return buf;
}

From source file:com.air.mobilebrowser.BrowserActivity.java

/** Logs an onscreen message for debugging. */
public void logMessage(final TextView consoleView, String message, String value, int color) {
    if (mIsDebugEnabled && consoleView != null) {
        consoleView.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override//from w  w  w.  j av a2  s  .  c o m
            public void onFocusChange(View v, boolean hasFocus) {

                ViewParent parent = consoleView.getParent();
                final ScrollView scroll = (ScrollView) parent;

                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {

                        scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10);

                    }
                }, 0);

            }
        });
        Editable editable = consoleView.getEditableText();

        SpannableString str = null;

        if (editable == null) {
            editable = new SpannableStringBuilder();
            str = new SpannableString(message + ": " + value);
            str.setSpan(new ForegroundColorSpan(color), message.length() + 2,
                    message.length() + 2 + value.length(), 0);
        } else {
            str = new SpannableString("\n" + message + ": " + value);
            str.setSpan(new ForegroundColorSpan(color), message.length() + 2,
                    message.length() + 3 + value.length(), 0);
        }

        editable.append(str);

        consoleView.setText(editable, TextView.BufferType.EDITABLE);

        ViewParent parent = consoleView.getParent();
        if (parent instanceof ScrollView) {
            final ScrollView scroll = (ScrollView) parent;

            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {

                    scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10);

                }
            }, 1000);
        }
    }
}