List of usage examples for android.text SpannableString setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:com.tandong.sa.sherlock.widget.SuggestionsAdapter.java
private CharSequence formatUrl(CharSequence url) { if (mUrlColor == null) { // Lazily get the URL color from the current theme. TypedValue colorValue = new TypedValue(); mContext.getTheme().resolveAttribute( mContext.getResources().getIdentifier("textColorSearchUrl", "attr", mContext.getPackageName()), // mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);// w ww . j a v a 2 s . c o m mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId); } SpannableString text = new SpannableString(url); text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return text; }
From source file:org.mozilla.gecko.AboutHomeContent.java
public void init() { Context context = getContext(); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater.inflate(R.layout.abouthome_content, this); mAccountManager = AccountManager.get(context); // The listener will run on the background thread (see 2nd argument) mAccountManager.addOnAccountsUpdatedListener(new OnAccountsUpdateListener() { public void onAccountsUpdated(Account[] accounts) { final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode(); final boolean syncIsSetup = isSyncSetup(); GeckoApp.mAppContext.mMainHandler.post(new Runnable() { public void run() { // The listener might run before the UI is initially updated. // In this case, we should simply wait for the initial setup // to happen. if (mTopSitesAdapter != null) updateLayout(startupMode, syncIsSetup); }/*from w w w . j av a 2s .c o m*/ }); } }, GeckoAppShell.getHandler(), false); mTopSitesGrid = (GridView) findViewById(R.id.top_sites_grid); mTopSitesGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Cursor c = (Cursor) parent.getItemAtPosition(position); String spec = c.getString(c.getColumnIndex(URLColumns.URL)); Log.i(LOGTAG, "clicked: " + spec); if (mUriLoadCallback != null) mUriLoadCallback.callback(spec); } }); mAddonsLayout = (LinearLayout) findViewById(R.id.recommended_addons); mLastTabsLayout = (LinearLayout) findViewById(R.id.last_tabs); TextView allTopSitesText = (TextView) findViewById(R.id.all_top_sites_text); allTopSitesText.setOnClickListener(new OnClickListener() { public void onClick(View v) { GeckoApp.mAppContext.showAwesomebar(AwesomeBar.Type.EDIT); } }); TextView allAddonsText = (TextView) findViewById(R.id.all_addons_text); allAddonsText.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (mUriLoadCallback != null) mUriLoadCallback.callback("https://addons.mozilla.org/android"); } }); TextView syncTextView = (TextView) findViewById(R.id.sync_text); String syncText = syncTextView.getText().toString() + " \u00BB"; String boldName = getContext().getResources().getString(R.string.abouthome_sync_bold_name); int styleIndex = syncText.indexOf(boldName); // Highlight any occurrence of "Firefox Sync" in the string // with a bold style. if (styleIndex >= 0) { SpannableString spannableText = new SpannableString(syncText); spannableText.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), styleIndex, styleIndex + 12, 0); syncTextView.setText(spannableText, TextView.BufferType.SPANNABLE); } RelativeLayout syncBox = (RelativeLayout) findViewById(R.id.sync_box); syncBox.setOnClickListener(new OnClickListener() { public void onClick(View v) { Context context = v.getContext(); Intent intent = new Intent(context, SetupSyncActivity.class); context.startActivity(intent); } }); }
From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java
@Override protected void onFinishInflate() { super.onFinishInflate(); // This is a focus listener that proxies focus from a view into the list view. This is to // work around the search box from getting first focus and showing the cursor. getContentView().setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override//from www . j ava 2 s . c om public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { mAppsRecyclerView.requestFocus(); } } }); mSearchContainer = findViewById(R.id.search_container); if (Utilities.isAllowNightModePrefEnabled(getContext())) { mSearchContainer.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.night_color)); } else { if (Utilities.getDrawerBackgroundPrefEnabled(getContext()) != -1) { mSearchContainer.setBackgroundColor(Utilities.getDrawerBackgroundPrefEnabled(getContext())); } else { mSearchContainer.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.white)); } } mSearchInput = (ExtendedEditText) findViewById(R.id.search_box_input); // Update the hint to contain the icon. // Prefix the original hint with two spaces. The first space gets replaced by the icon // using span. The second space is used for a singe space character between the hint // and the icon. SpannableString spanned = new SpannableString(" " + mSearchInput.getHint()); spanned.setSpan(new TintedDrawableSpan(getContext(), R.drawable.ic_allapps_search), 0, 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); mSearchInput.setHint(spanned); mSearchContainerOffsetTop = getResources().getDimensionPixelSize(R.dimen.all_apps_search_bar_margin_top); mElevationController = Utilities.ATLEAST_LOLLIPOP ? new HeaderElevationController.ControllerVL(mSearchContainer) : new HeaderElevationController.ControllerV16(mSearchContainer); // Load the all apps recycler view mAppsRecyclerView = (AllAppsRecyclerView) findViewById(R.id.apps_list_view); mAppsRecyclerView.setApps(mApps); mAppsRecyclerView.setLayoutManager(mLayoutManager); mAppsRecyclerView.setAdapter(mAdapter); mAppsRecyclerView.setHasFixedSize(true); mAppsRecyclerView.addOnScrollListener(mElevationController); mAppsRecyclerView.setElevationController(mElevationController); if (mItemDecoration != null) { mAppsRecyclerView.addItemDecoration(mItemDecoration); } FocusedItemDecorator focusedItemDecorator = new FocusedItemDecorator(mAppsRecyclerView); mAppsRecyclerView.addItemDecoration(focusedItemDecorator); mAppsRecyclerView.preMeasureViews(mAdapter); mAdapter.setIconFocusListener(focusedItemDecorator.getFocusListener()); if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) { getRevealView().setVisibility(View.VISIBLE); getContentView().setVisibility(View.VISIBLE); getContentView().setBackground(null); } }
From source file:me.jreilly.JamesTweet.TweetView.TweetFragment.java
public void setTweet(RealmResults<TweetRealm> mDataset) { int i = 0;// w w w . j a va 2 s .c om String user_img = mDataset.get(i).getProfileImageUrl(); final String user_screen = mDataset.get(i).getScreename(); String media_url = "null"; Date created = mDataset.get(i).getDate(); boolean retweeted = mDataset.get(i).isRetweetedStatus(); String original = mDataset.get(i).getRetweetedBy(); String username = mDataset.get(i).getName(); String text = mDataset.get(i).getText(); final long tId = mDataset.get(i).getId(); //Load Profile Image Picasso.with(mProfileImage.getContext()).load(user_img).transform(new CircleTransform()) .into(mProfileImage); //Set profile image to go to the users profile mProfileImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mActivity.swapToProfile(user_screen, mProfileImage); } }); final String imageUrl = media_url; ViewGroup.LayoutParams params = mImage.getLayoutParams(); //Set Cropped Media image and zoomImage animation if (!imageUrl.equals("null")) { mImage.getLayoutParams().height = 400; Picasso.with(mImage.getContext()).load(imageUrl).fit().centerCrop().into(mImage); } else { //Media is not need so it is hidden. mImage.setImageDrawable(null); mImage.getLayoutParams().height = 0; } //Set Username Text Field Calendar cal = Calendar.getInstance(); mDate.setText(DateUtils.getRelativeTimeSpanString(created.getTime())); mUser.setText(username); String tweetText = text; //Highlight Profile names/hashtags and their clickable spans ArrayList<int[]> hashtagSpans = getSpans(tweetText, '#'); ArrayList<int[]> profileSpans = getSpans(tweetText, '@'); SpannableString tweetContent = new SpannableString(tweetText); for (int j = 0; j < profileSpans.size(); j++) { int[] span = profileSpans.get(j); int profileStart = span[0]; int profileEnd = span[1]; tweetContent.setSpan(new ProfileLink(mTweet.getContext(), mActivity), profileStart, profileEnd, 0); } mTweet.setMovementMethod(LinkMovementMethod.getInstance()); mTweet.setText(tweetContent); }
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 w w . j av a 2 s .c om*/ 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.purenexussettings.TinkerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tinker); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w w w . j av a2 s .c o m // set up some defaults boolean cLockInstalled; FRAG_ARRAY_START = getResources().getIntArray(R.array.nav_drawer_cat_nums)[0]; mTitle = mDrawerTitle = getTitle(); mPackageName = getPackageName(); LAST_SLIDE_BAR_TAB = 0; mBackPress = false; mIgnoreBack = false; mFromClick = false; mMenu = false; fullyClosed = true; openingHalf = true; // for backstack tracking fragmentStack = new Stack<>(); // check if cLock installed try { PackageInfo pi = getPackageManager().getPackageInfo(KEY_LOCK_CLOCK_PACKAGE_NAME, 0); cLockInstalled = pi.applicationInfo.enabled; } catch (PackageManager.NameNotFoundException e) { cLockInstalled = false; } // load slide menu items - titles and frag names navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items); navMenuFrags = getResources().getStringArray(R.array.nav_drawer_fragments); // nav drawer icons from resources TypedArray navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavView = (NavigationView) findViewById(R.id.slidermenu); // create navigationview items Menu menu = mNavView.getMenu(); // pulled in crap menu in xml, need to clear it first menu.clear(); // pull in category names and numbers in each String[] navMenuCats = getResources().getStringArray(R.array.nav_drawer_cats); int[] navMenuCatCounts = getResources().getIntArray(R.array.nav_drawer_cat_nums); // set up some counters int j = 0; int total = 0; SubMenu submenu = null; // go through the total possible menu list for (int i = 0; i < navMenuTitles.length; i++) { // when the count equals a threshold value, increment/sum and add submenu if (i == (total + navMenuCatCounts[j])) { total += navMenuCatCounts[j]; // format submenu headings SpannableString strcat = new SpannableString(navMenuCats[j]); strcat.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.alphawhite)), 0, strcat.length(), 0); strcat.setSpan(new RelativeSizeSpan(0.85f), 0, strcat.length(), 0); strcat.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, strcat.length(), 0); // is the 10 * (j + 1) bit needed...? Maybe not... meh submenu = menu.addSubMenu((j + 1), 10 * (j + 1), 10 * (j + 1), strcat); j++; } // assuming all are skipped before first submenu, only add menu items if total <> 0 if (total > 0) { // format menu item title SpannableString stritem = new SpannableString(navMenuTitles[i]); stritem.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.alphawhite)), 0, stritem.length(), 0); // group id is j, i is item id and order..., then title - includes logic for conditional entries if (cLockInstalled || !(navMenuTitles[i].equals("cLock"))) { // an attempt to add icon if included... if (navMenuIcons.getResourceId(i, -1) != -1) { submenu.add(j, i, i, stritem).setIcon(navMenuIcons.getResourceId(i, -1)); } else { submenu.add(j, i, i, stritem); } } } } // remove icon tint from NavView mNavView.setItemIconTintList(null); mNavView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem item) { // check for external app launching navdrawer items if (navMenuTitles[item.getItemId()].equals("cLock")) { mIgnore = true; mDrawerLayout.closeDrawer(mNavView); launchcLock(); } // if nothing was caught in the above, do the usual prep to show frag stuff if (!mIgnore) { mItemPosition = item.getItemId(); mFromClick = true; setTitle(navMenuTitles[mItemPosition]); removeCurrent(); mDrawerLayout.closeDrawer(mNavView); } return true; } }); // Recycle the typed array navMenuIcons.recycle(); // enabling action bar app icon and behaving it as toggle button getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, //nav menu toggle icon R.string.app_name, // nav drawer open - description for accessibility R.string.app_name // nav drawer close - description for accessibility ) { @Override public void onDrawerClosed(View view) { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mNavView); getSupportActionBar().setTitle(mTitle); // calling onPrepareOptionsMenu() to show action bar icons openingHalf = true; invalidateOptionsMenu(); // now that the drawer animation is done - load fragment if (mIgnore || !mFromClick) { mIgnore = false; } else { displayView(mItemPosition); } } @Override public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(mDrawerTitle); // calling onPrepareOptionsMenu() to hide action bar icons openingHalf = false; invalidateOptionsMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); fullyClosed = (slideOffset == 0.0f); if (slideOffset < 0.5f && !openingHalf) { openingHalf = true; invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } else if (slideOffset > 0.5f && openingHalf) { openingHalf = false; invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } } }; mDrawerLayout.setDrawerListener(mDrawerToggle); fragmentManager = getFragmentManager(); if (savedInstanceState == null) { // on first time display view for first nav item displayView(mItemPosition = getIntent().getIntExtra(EXTRA_START_FRAGMENT, 0)); } }
From source file:org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder.java
public void displayActivity(ParcelableActivity activity, boolean byFriends) { final Context context = adapter.getContext(); final Resources resources = adapter.getContext().getResources(); switch (activity.action) { case Activity.ACTION_FOLLOW: { activityTypeView.setImageResource(R.drawable.ic_activity_action_follow); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_follow), Mode.SRC_ATOP);//from w w w.j ava 2s .c o m if (byFriends) { titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_follow, R.string.activity_by_friends_follow_multi, activity.sources, activity.target_users)); } else { titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_follow, R.string.activity_about_me_follow_multi, activity.sources)); } displayUserProfileImages(activity.sources); summaryView.setVisibility(View.GONE); break; } case Activity.ACTION_FAVORITE: { if (adapter.shouldUseStarsForLikes()) { activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite), Mode.SRC_ATOP); if (byFriends) { titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_favorite, R.string.activity_by_friends_favorite_multi, activity.sources, activity.target_statuses)); } else { titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorite, R.string.activity_about_me_favorite_multi, activity.sources)); } } else { activityTypeView.setImageResource(R.drawable.ic_activity_action_like); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like), Mode.SRC_ATOP); if (byFriends) { titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_like, R.string.activity_by_friends_like_multi, activity.sources, activity.target_statuses)); } else { titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_like, R.string.activity_about_me_like_multi, activity.sources)); } } displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_RETWEET: { activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet), Mode.SRC_ATOP); if (byFriends) { titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_retweet, R.string.activity_by_friends_retweet_multi, activity.sources, activity.target_statuses)); } else titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweet, R.string.activity_about_me_retweet_multi, activity.sources)); displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_FAVORITED_RETWEET: { if (byFriends) { showNotSupported(); return; } if (adapter.shouldUseStarsForLikes()) { activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorited_retweet, R.string.activity_about_me_favorited_retweet_multi, activity.sources)); } else { activityTypeView.setImageResource(R.drawable.ic_activity_action_like); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_liked_retweet, R.string.activity_about_me_liked_retweet_multi, activity.sources)); } displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_RETWEETED_RETWEET: { if (byFriends) { showNotSupported(); return; } activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweeted_retweet, R.string.activity_about_me_retweeted_retweet_multi, activity.sources)); displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_RETWEETED_MENTION: { if (byFriends) { showNotSupported(); return; } activityTypeView.setImageResource(R.drawable.ic_activity_action_retweet); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_retweet), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_retweeted_mention, R.string.activity_about_me_retweeted_mention_multi, activity.sources)); displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_FAVORITED_MENTION: { if (byFriends) { showNotSupported(); return; } if (adapter.shouldUseStarsForLikes()) { activityTypeView.setImageResource(R.drawable.ic_activity_action_favorite); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_favorite), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_favorited_mention, R.string.activity_about_me_favorited_mention_multi, activity.sources)); } else { activityTypeView.setImageResource(R.drawable.ic_activity_action_like); activityTypeView.setColorFilter(ContextCompat.getColor(context, R.color.highlight_like), Mode.SRC_ATOP); titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_liked_mention, R.string.activity_about_me_liked_mention_multi, activity.sources)); } displayUserProfileImages(activity.sources); summaryView.setText(activity.target_statuses[0].text_unescaped); summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_LIST_CREATED: { if (!byFriends) { showNotSupported(); return; } activityTypeView.setImageResource(R.drawable.ic_activity_action_list_added); activityTypeView.setColorFilter(activityTypeView.getDefaultColor(), Mode.SRC_ATOP); titleView.setText(getTitleStringByFriends(R.string.activity_by_friends_list_created, R.string.activity_by_friends_list_created_multi, activity.sources, activity.target_object_user_lists)); displayUserProfileImages(activity.sources); boolean firstLine = true; summaryView.setText(""); for (ParcelableUserList item : activity.target_object_user_lists) { if (!firstLine) { summaryView.append("\n"); } summaryView.append(item.description); firstLine = false; } summaryView.setVisibility(View.VISIBLE); break; } case Activity.ACTION_LIST_MEMBER_ADDED: { if (byFriends) { showNotSupported(); return; } activityTypeView.setImageResource(R.drawable.ic_activity_action_list_added); activityTypeView.setColorFilter(activityTypeView.getDefaultColor(), Mode.SRC_ATOP); if (activity.sources.length == 1 && activity.target_object_user_lists != null && activity.target_object_user_lists.length == 1) { final UserColorNameManager manager = adapter.getUserColorNameManager(); final SpannableString firstDisplayName = new SpannableString( manager.getDisplayName(activity.sources[0], adapter.isNameFirst(), false)); final SpannableString listName = new SpannableString(activity.target_object_user_lists[0].name); firstDisplayName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstDisplayName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); listName.setSpan(new StyleSpan(Typeface.BOLD), 0, listName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); final String format = context.getString(R.string.activity_about_me_list_member_added_with_name); final Configuration configuration = resources.getConfiguration(); titleView.setText(SpanFormatter.format(configuration.locale, format, firstDisplayName, listName)); } else { titleView.setText(getTitleStringAboutMe(R.string.activity_about_me_list_member_added, R.string.activity_about_me_list_member_added_multi, activity.sources)); } displayUserProfileImages(activity.sources); summaryView.setVisibility(View.GONE); break; } } }
From source file:org.bobstuff.bobball.ActivityStateEnum.java
private void showWonScreen() { activityState = ActivityStateEnum.GAMEWON; Statistics.saveHighestLevel(numPlayers, gameManager.getLevel() + 1); levelSeries++;//ww w . j a v a 2 s.c o m Statistics.saveLongestSeries(levelSeries); GameState gs = gameManager.getCurrGameState(); Grid currGrid = gs.getGrid(); SpannableStringBuilder percentageCleared = new SpannableStringBuilder(); String percentageString = currGrid.getPercentCompleteFloat(1) + "%"; String totalPercentageString = getString(R.string.percentageCleared, percentageString); int player1Color = gs.getPlayer(1).getColor(); SpannableString percentage = new SpannableString(totalPercentageString); int percentageStart = totalPercentageString.length() - percentageString.length(); int percentageEnd = totalPercentageString.length(); percentage.setSpan(new ForegroundColorSpan(player1Color), percentageStart, percentageEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); percentageCleared.append(percentage); messageView.setText(getString(R.string.levelCompleted, gameManager.getLevel())); button.setText(R.string.nextLevel); retryButton.setVisibility(View.GONE); button.setVisibility(View.VISIBLE); backToLevelSelectButton.setVisibility(View.GONE); this.percentageCleared.setText(percentageCleared); this.percentageCleared.setVisibility(View.VISIBLE); if (numPlayers > 1) { totalPercentageCleared .setText(getString(R.string.totalPercentageCleared, currGrid.getPercentCompleteFloat() + "%")); totalPercentageCleared.setVisibility(View.VISIBLE); } bonusPoints.setText(getString(R.string.bonusPoints, gameManager.getBonusPoints(gs, gs.getPlayer(1)))); bonusPoints.setVisibility(View.VISIBLE); setMessageViewsVisible(true); }
From source file:org.tlhInganHol.android.klingonassistant.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mActivePosition = savedInstanceState.getInt(STATE_ACTIVE_POSITION); }// w w w. j a va2 s .c o m // Close the floating window, if there is one. Work around a race condition. Log.d(TAG, "Starting activity with non-floating window. Close floating window."); Handler killFloatingWindowHandler = new Handler(); Runnable killFloatingWindowRunnable = new Runnable() { public void run() { StandOutWindow.closeAll(BaseActivity.this, FloatingWindow.class); } }; killFloatingWindowHandler.postDelayed(killFloatingWindowRunnable, 100); // 100 ms // Get the action bar. ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); if (sharedPrefs.getBoolean(Preferences.KEY_KLINGON_FONT_CHECKBOX_PREFERENCE, /* default */false)) { // Display the action bar title in Klingon font. SpannableString title = new SpannableString("?"); Typeface klingonTypeface = KlingonAssistant.getKlingonFontTypeface(getBaseContext()); title.setSpan(new KlingonTypefaceSpan("", klingonTypeface), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); actionBar.setTitle(title); } // If the device is in landscape orientation and the screen size is large (or bigger), then // make the slide-out menu static. Otherwise, hide it by default. MenuDrawer.Type drawerType = MenuDrawer.Type.BEHIND; if (isHorizontalTablet()) { drawerType = MenuDrawer.Type.STATIC; } mDrawer = MenuDrawer.attach(this, drawerType, Position.LEFT, MenuDrawer.MENU_DRAG_CONTENT); List<Object> items = new ArrayList<Object>(); if (sharedPrefs.getBoolean(Preferences.KEY_KLINGON_UI_CHECKBOX_PREFERENCE, /* default */false)) { items.add(new SlideMenuCategory(R.string.menu_reference_tlh)); items.add(new SlideMenuItem(R.string.menu_pronunciation_tlh, R.id.pronunciation, 0)); items.add(new SlideMenuItem(R.string.menu_prefixes_tlh, R.id.prefixes, 0)); items.add(new SlideMenuItem(R.string.menu_prefix_charts_tlh, R.id.prefix_charts, 0)); items.add(new SlideMenuItem(R.string.menu_noun_suffixes_tlh, R.id.noun_suffixes, 0)); items.add(new SlideMenuItem(R.string.menu_verb_suffixes_tlh, R.id.verb_suffixes, 0)); items.add(new SlideMenuCategory(R.string.menu_phrases_tlh)); items.add(new SlideMenuItem(R.string.beginners_conversation_tlh, R.id.beginners_conversation, 0)); items.add(new SlideMenuItem(R.string.jokes_tlh, R.id.jokes, 0)); items.add(new SlideMenuItem(R.string.nentay_tlh, R.id.nentay, 0)); items.add(new SlideMenuItem(R.string.military_celebration_tlh, R.id.military_celebration, 0)); items.add(new SlideMenuItem(R.string.toasts_tlh, R.id.toasts, 0)); items.add(new SlideMenuItem(R.string.lyrics_tlh, R.id.lyrics, 0)); items.add(new SlideMenuItem(R.string.curse_warfare_tlh, R.id.curse_warfare, 0)); items.add(new SlideMenuItem(R.string.replacement_proverbs_tlh, R.id.replacement_proverbs, 0)); items.add(new SlideMenuItem(R.string.secrecy_proverbs_tlh, R.id.secrecy_proverbs, 0)); items.add(new SlideMenuItem(R.string.empire_union_day_tlh, R.id.empire_union_day, 0)); items.add(new SlideMenuItem(R.string.rejection_tlh, R.id.rejection, 0)); items.add(new SlideMenuCategory(R.string.menu_media_tlh)); items.add(new SlideMenuItem(R.string.media_1_title_tlh, R.id.media_1, 0)); items.add(new SlideMenuItem(R.string.media_2_title_tlh, R.id.media_2, 0)); items.add(new SlideMenuItem(R.string.media_3_title_tlh, R.id.media_3, 0)); items.add(new SlideMenuItem(R.string.media_4_title_tlh, R.id.media_4, 0)); items.add(new SlideMenuItem(R.string.media_5_title_tlh, R.id.media_5, 0)); items.add(new SlideMenuItem(R.string.media_6_title_tlh, R.id.media_6, 0)); /* items.add(new SlideMenuCategory(R.string.menu_social_tlh)); items.add(new SlideMenuItem(R.string.menu_gplus_tlh, R.id.gplus, 0)); items.add(new SlideMenuItem(R.string.menu_facebook_tlh, R.id.facebook, 0)); items.add(new SlideMenuItem(R.string.menu_kag_tlh, R.id.kag, 0)); items.add(new SlideMenuItem(R.string.menu_kidc_tlh, R.id.kidc, 0)); */ } else { items.add(new SlideMenuCategory(R.string.menu_reference)); items.add(new SlideMenuItem(R.string.menu_pronunciation, R.id.pronunciation, 0)); items.add(new SlideMenuItem(R.string.menu_prefixes, R.id.prefixes, 0)); items.add(new SlideMenuItem(R.string.menu_prefix_charts, R.id.prefix_charts, 0)); items.add(new SlideMenuItem(R.string.menu_noun_suffixes, R.id.noun_suffixes, 0)); items.add(new SlideMenuItem(R.string.menu_verb_suffixes, R.id.verb_suffixes, 0)); items.add(new SlideMenuCategory(R.string.menu_phrases)); items.add(new SlideMenuItem(R.string.beginners_conversation, R.id.beginners_conversation, 0)); items.add(new SlideMenuItem(R.string.jokes, R.id.jokes, 0)); items.add(new SlideMenuItem(R.string.nentay, R.id.nentay, 0)); items.add(new SlideMenuItem(R.string.military_celebration, R.id.military_celebration, 0)); items.add(new SlideMenuItem(R.string.toasts, R.id.toasts, 0)); items.add(new SlideMenuItem(R.string.lyrics, R.id.lyrics, 0)); items.add(new SlideMenuItem(R.string.curse_warfare, R.id.curse_warfare, 0)); items.add(new SlideMenuItem(R.string.replacement_proverbs, R.id.replacement_proverbs, 0)); items.add(new SlideMenuItem(R.string.secrecy_proverbs, R.id.secrecy_proverbs, 0)); items.add(new SlideMenuItem(R.string.empire_union_day, R.id.empire_union_day, 0)); items.add(new SlideMenuItem(R.string.rejection, R.id.rejection, 0)); // Not all general proverbs are properly tagged yet. // Too many idioms; also no known Klingon term for "idiom". items.add(new SlideMenuCategory(R.string.menu_media)); items.add(new SlideMenuItem(R.string.media_1_title, R.id.media_1, 0)); items.add(new SlideMenuItem(R.string.media_2_title, R.id.media_2, 0)); items.add(new SlideMenuItem(R.string.media_3_title, R.id.media_3, 0)); items.add(new SlideMenuItem(R.string.media_4_title, R.id.media_4, 0)); items.add(new SlideMenuItem(R.string.media_5_title, R.id.media_5, 0)); items.add(new SlideMenuItem(R.string.media_6_title, R.id.media_6, 0)); /* items.add(new SlideMenuCategory(R.string.menu_social)); items.add(new SlideMenuItem(R.string.menu_gplus, R.id.gplus, 0)); items.add(new SlideMenuItem(R.string.menu_facebook, R.id.facebook, 0)); items.add(new SlideMenuItem(R.string.menu_kag, R.id.kag, 0)); items.add(new SlideMenuItem(R.string.menu_kidc, R.id.kidc, 0)); */ } mList = new ListView(this); mAdapter = new SlideMenuAdapter(this, items); mAdapter.setListener(this); mAdapter.setActivePosition(mActivePosition); mList.setAdapter(mAdapter); mList.setOnItemClickListener(mItemClickListener); mDrawer.setMenuView(mList); // Allow the menu to slide out when any part of the screen is dragged. mDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN); // The drawable that replaces the up indicator in the action bar. mDrawer.setSlideDrawable(R.drawable.ic_drawer); // Whether the previous drawable should be shown. mDrawer.setDrawerIndicatorEnabled(true); // Activate type-to-search for local search. Typing will automatically // start a search of the database. setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); // Register a receiver for the kill order. mKillReceiver = new KillReceiver(); registerReceiver(mKillReceiver, IntentFilter.create(ACTION_KILL, KILL_TYPE)); }