List of usage examples for android.graphics Typeface BOLD
int BOLD
To view the source code for android.graphics Typeface BOLD.
Click Source Link
From source file:com.zainsoft.ramzantimetable.QiblaActivity.java
/** Called when the activity is first created. */ @Override/*from ww w. j av a 2s. c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_qibla_direction); // registering for listeners Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); registerListeners(); // Checking if the GPS is on or off. If it was on the default location // will be set and if its on, appropriate Context context = getApplicationContext(); perfs = PreferenceManager.getDefaultSharedPreferences(context); perfs.registerOnSharedPreferenceChangeListener(this); String gpsPerfKey = getString(R.string.gps_pref_key); TextView text1 = (TextView) findViewById(R.id.location_text_line2); TextView text2 = (TextView) findViewById(R.id.noLocationText); Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/kufi.ttf"); tf = Typeface.create(tf, Typeface.BOLD); if ("fa".equals(Locale.getDefault().getLanguage())) { text1.setTypeface(tf); text2.setTypeface(tf); } else { text1.setTypeface(Typeface.SERIF); text2.setTypeface(Typeface.SERIF); } boolean isGPS = false; /* if(hasPermission( LOC_PERMS[0] )) { checkForGPSnShowQibla(); } else { requestLocationPermission(); } */ this.qiblaImageView = (ImageView) findViewById(R.id.arrowImage); this.compassImageView = (ImageView) findViewById(R.id.compassImage); }
From source file:com.money.manager.ex.reports.IncomeVsExpensesListFragment.java
/** * update View of footer with income, expenses and difference * * @param footer// ww w . j a va2 s. co m * @param income * @param expenses */ private void updateListViewFooter(View footer, double income, double expenses) { if (footer == null) { return; } TextView txtIncome = (TextView) footer.findViewById(R.id.textViewIncome); TextView txtExpenses = (TextView) footer.findViewById(R.id.textViewExpenses); TextView txtDifference = (TextView) footer.findViewById(R.id.textViewDifference); CurrencyService currencyService = new CurrencyService(getActivity().getApplicationContext()); //set income txtIncome.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(income))); txtIncome.setTypeface(null, Typeface.BOLD); //set expenses txtExpenses.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(Math.abs(expenses)))); txtExpenses.setTypeface(null, Typeface.BOLD); //set difference txtDifference.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(income - Math.abs(expenses)))); txtDifference.setTypeface(null, Typeface.BOLD); //change colors UIHelper uiHelper = new UIHelper(getActivity()); if (income - Math.abs(expenses) < 0) { txtDifference.setTextColor( ContextCompat.getColor(getActivity(), uiHelper.resolveAttribute(R.attr.holo_red_color_theme))); } else { txtDifference.setTextColor(ContextCompat.getColor(getActivity(), uiHelper.resolveAttribute(R.attr.holo_green_color_theme))); } }
From source file:com.bookkos.bircle.CaptureActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); _context = getApplicationContext();//from w w w. j a v a 2 s . co m _activity = this; currentTime = new Time("Asia/Tokyo"); // exceptionHandler = new ExceptionHandler(_context); // Thread.setDefaultUncaughtExceptionHandler(exceptionHandler); // sharedPreference???, user_id?group_id?registration_id?? getUserData(); Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // ?? WindowManager window_manager = getWindowManager(); Display display = window_manager.getDefaultDisplay(); Point point = new Point(); display.getSize(point); displayWidth = point.x; displayHeight = point.y; displayInch = getInch(); // ??4??????? textSize = 17 * (displayInch / 4); actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_USE_LOGO); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayUseLogoEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); String title_text = ""; subGroupText = ""; groupText = groupName; if (displayInch < 4.7) { title_text = "<small><small><small>??: </small></small></small>"; resizeTitleSizeTooSmall(); } else if (displayInch >= 4.7 && displayInch < 5.5) { title_text = "<small><small>??: </small></small>"; resizeTitleSizeSmall(); } else if (displayInch >= 5.5 && displayInch < 6.5) { title_text = "<small>??: </small>"; resizeTitleSizeMiddle(); } else if (displayInch >= 6.5 && displayInch < 8) { title_text = "<small>??: </small>"; resizeTitleSizeLarge(); } else { title_text = "??: "; } String modify_group_text = title_text + "<font color=#FF0000>" + groupName + "</font>"; actionBar.setTitle(Html.fromHtml(modify_group_text)); Resources resources = _context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); titleBarHeight = resources.getDimensionPixelSize(resourceId); setContentView(R.layout.capture); returnBorrowHelpView = (ImageView) findViewById(R.id.return_borrow_help_view); returnBorrowHelpView.setImageResource(R.drawable.return_borrow_help); returnBorrowHelpView.setTranslationY(displayHeight / 5 + titleBarHeight); returnBorrowHelpView.setLayoutParams(new FrameLayout.LayoutParams(displayWidth, displayHeight / 5 + titleBarHeight, Gravity.BOTTOM | Gravity.CENTER)); registHelpView = (ImageView) findViewById(R.id.regist_help_view); registHelpView.setImageResource(R.drawable.regist_help); registHelpView.setTranslationY(displayHeight / 5 + titleBarHeight); registHelpView.setLayoutParams(new FrameLayout.LayoutParams(displayWidth, displayHeight / 5 + titleBarHeight, Gravity.BOTTOM | Gravity.CENTER)); registHelpView.setVisibility(View.GONE); leftDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); leftDrawer = (ListView) findViewById(R.id.left_drawer); textView = (TextView) findViewById(R.id.textView); modeText = (TextView) findViewById(R.id.mode_text); modeText.setTextColor(Color.rgb(56, 234, 123)); modeText.setTextSize(textSize); modeText.setTypeface(Typeface.SERIF.MONOSPACE, Typeface.BOLD); strokeColor = Color.rgb(56, 234, 123); borrowReturnButton = (Button) findViewById(R.id.borrowReturnButton); registButton = (Button) findViewById(R.id.registButton); returnHistoryButton = (Button) findViewById(R.id.return_history_button); helpViewButton = (Button) findViewById(R.id.help_view_button); registSelectShelfRelativeLayout = (RelativeLayout) findViewById(R.id.regist_select_shelf_relative_layout); textViewLinearLayout = (LinearLayout) findViewById(R.id.text_view_linear_layout); buttonLinearLayout = (LinearLayout) findViewById(R.id.button_linear_layout); listViewLinearLayout = (LinearLayout) findViewById(R.id.list_view_linear_layout); decisionButton = (Button) findViewById(R.id.decision_button); cancelButton = (Button) findViewById(R.id.cancel_button); shelfListView = (ListView) findViewById(R.id.shelf_list_view); tempTextView = (TextView) findViewById(R.id.temp_text_view); // bookListViewAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); bookListViewAdapter = new BookListViewAdapter(_context, R.layout.book_list_row, this); bookRegistRelativeLayout = (RelativeLayout) findViewById(R.id.book_regist_relative_layout); bookRegistLinearLayout = (LinearLayout) findViewById(R.id.book_regist_linear_layout); bookRegistListViewLinearLayout = (LinearLayout) findViewById(R.id.book_regist_list_view_linear_layout); bookRegistListView = (ListView) findViewById(R.id.book_regist_list_view); bookRegistTextView = (TextView) findViewById(R.id.book_regist_text_view); bookRegistCancelButton = (Button) findViewById(R.id.book_regist_cancel_button); registFlag = 0; int borrowReturnButton_width = displayWidth / 5 * 2; int borrowReturnButton_height = displayHeight / 10; int borrowReturnButton_x = ((displayWidth / 2) - borrowReturnButton_width) / 2; int borrowReturnButton_y = displayHeight / 2 + titleBarHeight; borrowReturnButton.setTranslationX(borrowReturnButton_x); borrowReturnButton.setTranslationY(borrowReturnButton_y); borrowReturnButton .setLayoutParams(new FrameLayout.LayoutParams(borrowReturnButton_width, borrowReturnButton_height)); borrowReturnButton.setBackgroundColor(Color.rgb(56, 234, 123)); borrowReturnButton.setText("??\n"); borrowReturnButton.setTextSize(textSize * 7 / 10); borrowReturnButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { arrayList.clear(); registFlag = 0; borrowReturnButton.setText("??\n"); borrowReturnButton.setEnabled(false); borrowReturnButton.setTextColor(Color.WHITE); borrowReturnButton.setBackgroundColor(Color.rgb(56, 234, 123)); registButton.setText("?\n??"); registButton.setEnabled(true); registButton.setTextColor(Color.GRAY); registButton.setBackgroundColor(Color.argb(170, 21, 38, 45)); modeText.setText("??"); modeText.setTextColor(Color.rgb(56, 234, 123)); returnBorrowHelpView.setVisibility(View.VISIBLE); registHelpView.setVisibility(View.GONE); strokeColor = Color.rgb(56, 234, 123); } }); int registButton_width = displayWidth / 5 * 2; int registButton_height = displayHeight / 10; int registButton_x = (displayWidth / 2) + ((displayWidth / 2) - registButton_width) / 2; int registButton_y = displayHeight / 2 + titleBarHeight; registButton.setTranslationX(registButton_x); registButton.setTranslationY(registButton_y); registButton.setLayoutParams(new FrameLayout.LayoutParams(registButton_width, registButton_height)); registButton.setBackgroundColor(Color.argb(170, 21, 38, 45)); registButton.setTextColor(Color.GRAY); registButton.setTextSize(textSize * 7 / 10); registButton.setText("?\n??"); registButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { arrayList.clear(); registFlag = 1; borrowReturnButton.setText("??\n??"); borrowReturnButton.setEnabled(true); borrowReturnButton.setTextColor(Color.GRAY); borrowReturnButton.setBackgroundColor(Color.argb(170, 9, 54, 16)); registButton.setText("?\n"); registButton.setEnabled(false); registButton.setTextColor(Color.WHITE); registButton.setBackgroundColor(Color.rgb(62, 162, 229)); modeText.setText("?"); modeText.setTextColor(Color.rgb(62, 162, 229)); returnBorrowHelpView.setVisibility(View.GONE); registHelpView.setVisibility(View.VISIBLE); strokeColor = Color.rgb(62, 162, 229); } }); returnHistoryButton.setText("????"); returnHistoryButton.setTextSize(textSize * 7 / 10); returnHistoryButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { leftDrawerLayout.openDrawer(Gravity.RIGHT); // animateTranslationY(bookRegistRelativeLayout, displayHeight, displayHeight - displayHeight / 4 - titleBarHeight); } }); getReturnHistory(); getCurrentTime(); setHelpView(); setScanUnregisterBookView(); setBookRegistView(); arrayList = new ArrayList<String>(); tempRegistIsbn = ""; initBookRegistUrl = book_register_url + "?user_id=" + userId + "&group_id=" + groupId; initLendRegistUrl = lend_register_url + "?user_id=" + userId + "&group_id=" + groupId; initTemporaryLendRegistUrl = temporary_lend_register_url + "?user_id=" + userId + "&group_id=" + groupId; initCatalogRegistUrl = catalog_register_url + "?group_id=" + groupId + "&book_code="; initManuallyCatalogRegistUrl = manually_catalog_register_url + "?group_id=" + groupId + "&book_code="; getStatusUrl = get_status_url + "?group_id=" + groupId + "&user_id=" + userId; hasSurface = false; inactivityTimer = new InactivityTimer(this); bircleBeepManager = new BircleBeepManager(this); ambientLightManager = new AmbientLightManager(this); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); toastText = ""; }
From source file:com.keylesspalace.tusky.activity.MainActivity.java
private void setupSearchView() { searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout()); searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { @Override/* w ww .ja v a 2s . com*/ 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:org.nla.tarotdroid.lib.ui.GameSetSynthesisFragment.java
/** * Refreshes the stats rows on the synthesis view. *///from w w w . j a v a2 s . co m protected void refreshPlayerStatsRows() { // sort players List<Player> sortedPlayers = this.getGameSet().getPlayers().getPlayers(); Collections.sort(sortedPlayers, new PlayerScoreComparator()); // get general data sources IGameSetStatisticsComputer gameSetStatisticsComputer = GameSetStatisticsComputerFactory .GetGameSetStatisticsComputer(this.getGameSet(), "guava"); MapPlayersScores lastScores = this.getGameSet().getGameSetScores().getResultsAtLastGame(); Map<Player, Integer> leadingCount = gameSetStatisticsComputer.getLeadingCount(); Map<Player, Integer> leadingSuccesses = gameSetStatisticsComputer.getLeadingSuccessCount(); Map<Player, Integer> calledCount = gameSetStatisticsComputer.getCalledCount(); int minScoreEver = gameSetStatisticsComputer.getMinScoreEver(); int maxScoreEver = gameSetStatisticsComputer.getMaxScoreEver(); // format statistics lines for (int rank = 0; rank < sortedPlayers.size(); ++rank) { // get player specific data sources Player player = sortedPlayers.get(rank); int lastScore = lastScores == null ? 0 : lastScores.get(player); int successfulLeadingGamesCount = leadingSuccesses.get(player) == null ? 0 : leadingSuccesses.get(player).intValue(); int leadingGamesCount = leadingCount.get(player) == null ? 0 : leadingCount.get(player); int successRate = (int) (((double) successfulLeadingGamesCount) / ((double) leadingGamesCount) * 100.0); int minScoreForPlayer = gameSetStatisticsComputer.getMinScoreEverForPlayer(player); int maxScoreForPlayer = gameSetStatisticsComputer.getMaxScoreEverForPlayer(player); // get line widgets LinearLayout statRow = this.statsRows.get(rank + 1); //TextView statPlayerName = (TextView)statRow.findViewById(R.id.statPlayerName); TextView statScore = (TextView) statRow.findViewById(R.id.statScore); TextView statLeadingGamesCount = (TextView) statRow.findViewById(R.id.statLeadingGamesCount); TextView statSuccessfulGamesCount = (TextView) statRow.findViewById(R.id.statSuccessfulGamesCount); TextView statMinScore = (TextView) statRow.findViewById(R.id.statMinScore); TextView statMaxScore = (TextView) statRow.findViewById(R.id.statMaxScore); // Bitmap playerImage = null; // if (player.getPictureUri() != null && !player.getPictureUri().equals("")) { // playerImage = UIHelper.getPlayerImage(this.getActivity(), player); // } // // // // assign values to widgets // if (player.getFacebookId() != null) { // // player facebook image // ProfilePictureView pictureView = new ProfilePictureView(this.getActivity()); // pictureView.setProfileId(player.getFacebookId()); // pictureView.setPresetSize(ProfilePictureView.SMALL); // //pictureView.setOnClickListener(playerClickListener); // pictureView.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS); // statRow.removeViewAt(0); // statRow.addView(pictureView, 0); // } // else { // // WARNING: The properties below reference the style ScoreTextStyle, but we can't set a style at runtime. // TextView playerName = new TextView(this.getActivity()); // playerName.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1)); // playerName.setGravity(Gravity.CENTER); // playerName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); // playerName.setEllipsize(TruncateAt.END); // playerName.setSingleLine(); // playerName.setTextColor(Color.WHITE); // playerName.setTypeface(null, Typeface.BOLD); // playerName.setText(player.getName()); // //playerName.setBackgroundResource(R.drawable.border_player_white); // statRow.removeViewAt(0); // statRow.addView(playerName, 0); // } OnClickListener playerClickListener = new PlayerClickListener(player); // facebook picture if (player.getFacebookId() != null) { ProfilePictureView pictureView = new ProfilePictureView(this.getActivity()); pictureView.setProfileId(player.getFacebookId()); pictureView.setPresetSize(ProfilePictureView.SMALL); pictureView.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS); pictureView.setOnClickListener(playerClickListener); //this.addView(pictureView); statRow.removeViewAt(0); statRow.addView(pictureView, 0); } // contact picture else if (player.getPictureUri() != null && player.getPictureUri().toString().contains("content://com.android.contacts/contacts")) { Bitmap playerImage = UIHelper.getContactPicture(this.getActivity(), Uri.parse(player.getPictureUri()).getLastPathSegment()); ImageView imgPlayer = new ImageView(this.getActivity()); imgPlayer.setImageBitmap(playerImage); imgPlayer.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS); imgPlayer.setOnClickListener(playerClickListener); //this.addView(imgPlayer); statRow.removeViewAt(0); statRow.addView(imgPlayer, 0); } // no picture, only name else { TextView txtPlayer = new TextView(this.getActivity()); txtPlayer.setText(player.getName()); txtPlayer.setGravity(Gravity.CENTER); txtPlayer.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS); txtPlayer.setMinWidth(UIConstants.PLAYER_VIEW_WIDTH); txtPlayer.setHeight(UIConstants.PLAYER_VIEW_HEIGHT); txtPlayer.setBackgroundColor(Color.TRANSPARENT); txtPlayer.setTypeface(null, Typeface.BOLD); txtPlayer.setTextColor(Color.WHITE); txtPlayer.setSingleLine(); txtPlayer.setEllipsize(TruncateAt.END); txtPlayer.setOnClickListener(playerClickListener); //this.addView(txtPlayer); statRow.removeViewAt(0); statRow.addView(txtPlayer, 0); } statScore.setText(Integer.toString(lastScore)); statLeadingGamesCount.setText(Integer.toString(leadingGamesCount)); statSuccessfulGamesCount.setText( Integer.toString(successfulLeadingGamesCount) + " (" + Integer.toString(successRate) + "%)"); // display called game count if necessary if (this.getGameSet().getGameStyleType() == GameStyleType.Tarot5) { TextView statCalledGamesCount = (TextView) statRow.findViewById(R.id.statCalledGamesCount); statCalledGamesCount .setText(Integer.toString(calledCount.get(player) == null ? 0 : calledCount.get(player))); } statMinScore.setText(Integer.toString(minScoreForPlayer)); statMaxScore.setText(Integer.toString(maxScoreForPlayer)); statMinScore.setTextColor(Color.WHITE); statMaxScore.setTextColor(Color.WHITE); // color min score if lowest if (minScoreEver == minScoreForPlayer) { statMinScore.setTextColor(Color.YELLOW); } // color max score if highest if (maxScoreEver == maxScoreForPlayer) { statMaxScore.setTextColor(Color.GREEN); } } }
From source file:com.github.omadahealth.slidepager.lib.views.SlideChartView.java
/** * Sets the selected {@link ProgressView} * * @param selected The index of the selected view in {@link #mProgressList} *///from ww w . ja va2s . co m private void toggleSelectedViews(int selected) { mSelectedView = selected; for (int i = 0; i < mProgressList.size(); i++) { ProgressView day = mProgressList.get(i); TypefaceTextView currentBottomText = mProgressBottomTextList.get(i); if (day.getIntTag() == mSelectedView) { day.isSelected(true); currentBottomText.setTypeface(currentBottomText.getTypeface(), Typeface.BOLD); continue; } day.isSelected(false); currentBottomText.setTypeface( TypefaceTextView.getFont(getContext(), TypefaceType .getTypeface(TypefaceType.getDefaultTypeface(getContext())).getAssetFileName()), Typeface.NORMAL); } }
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 w w . j a v a2 s .c o m }
From source file:org.tlhInganHol.android.klingonassistant.EntryActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // TTS:/* www .j a v a 2s . com*/ // Initialize text-to-speech. This is an asynchronous operation. // The OnInitListener (second argument) is called after initialization completes. // Log.d(TAG, "Initialising TTS"); mTts = new TextToSpeech(this, this, // TextToSpeech.OnInitListener "org.tlhInganHol.android.klingonttsengine"); // Requires API 14. setDrawerContentView(R.layout.entry); Resources resources = getResources(); JellyBeanSpanFixTextView entryTitle = (JellyBeanSpanFixTextView) findViewById(R.id.entry_title); JellyBeanSpanFixTextView entryText = (JellyBeanSpanFixTextView) findViewById(R.id.definition); // TODO: Save and restore bundle state to preserve links. Uri uri = getIntent().getData(); // Log.d(TAG, "EntryActivity - uri: " + uri.toString()); // TODO: Disable the "About" menu item if this is the "About" entry. mParentQuery = getIntent().getStringExtra(SearchManager.QUERY); // Retrieve the entry's data. // Note: managedQuery is deprecated since API 11. Cursor cursor = managedQuery(uri, KlingonContentDatabase.ALL_KEYS, null, null, null); KlingonContentProvider.Entry entry = new KlingonContentProvider.Entry(cursor, getBaseContext()); // Handle alternative spellings here. if (entry.isAlternativeSpelling()) { // TODO: Immediate redirect to query in entry.getDefinition(); } // Get the shared preferences. SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); // Set the entry's name (along with info like "slang", formatted in HTML). entryTitle.invalidate(); boolean useKlingonFont = sharedPrefs.getBoolean(Preferences.KEY_KLINGON_FONT_CHECKBOX_PREFERENCE, /* default */false); Typeface klingonTypeface = KlingonAssistant.getKlingonFontTypeface(getBaseContext()); if (useKlingonFont) { // Preference is set to display this in {pIqaD}! entryTitle.setTypeface(klingonTypeface); entryTitle.setText(entry.getEntryNameInKlingonFont()); } else { // Boring transcription based on English (Latin) alphabet. entryTitle.setText(Html.fromHtml(entry.getFormattedEntryName(/* isHtml */true))); } mEntryName = entry.getEntryName(); // Set the colour for the entry name depending on its part of speech. boolean useColours = sharedPrefs.getBoolean(Preferences.KEY_USE_COLOURS_CHECKBOX_PREFERENCE, /* default */true); if (useColours) { entryTitle.setTextColor(entry.getTextColor()); } // Create the expanded definition. String pos = entry.getFormattedPartOfSpeech(/* isHtml */false); String expandedDefinition = pos + entry.getDefinition(); // Show the German definition. String definition_DE = ""; boolean displayGermanEntry = entry.shouldDisplayGerman(); int germanDefinitionStart = -1; String germanDefinitionHeader = "\n" + resources.getString(R.string.label_german) + ": "; if (displayGermanEntry) { germanDefinitionStart = expandedDefinition.length(); definition_DE = entry.getDefinition_DE(); expandedDefinition += germanDefinitionHeader + definition_DE; } // Set the share intent. setShareEntryIntent(entry); // Show the basic notes. String notes = entry.getNotes(); if (!notes.equals("")) { expandedDefinition += "\n\n" + notes; } // If this entry is hypothetical or extended canon, display warnings. if (entry.isHypothetical() || entry.isExtendedCanon()) { expandedDefinition += "\n\n"; if (entry.isHypothetical()) { expandedDefinition += resources.getString(R.string.warning_hypothetical); } if (entry.isExtendedCanon()) { expandedDefinition += resources.getString(R.string.warning_extended_canon); } } // Show synonyms, antonyms, and related entries. String synonyms = entry.getSynonyms(); String antonyms = entry.getAntonyms(); String seeAlso = entry.getSeeAlso(); if (!synonyms.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_synonyms) + ": " + synonyms; } if (!antonyms.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_antonyms) + ": " + antonyms; } if (!seeAlso.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_see_also) + ": " + seeAlso; } // Display components if that field is not empty, unless we are showing an analysis link, in // which case we want to hide the components. boolean showAnalysis = entry.isSentence() || entry.isDerivative(); String components = entry.getComponents(); if (!components.equals("")) { // Treat the components column of inherent plurals and their // singulars differently than for other entries. if (entry.isInherentPlural()) { expandedDefinition += "\n\n" + String.format(resources.getString(R.string.info_inherent_plural), components); } else if (entry.isSingularFormOfInherentPlural()) { expandedDefinition += "\n\n" + String.format(resources.getString(R.string.info_singular_form), components); } else if (!showAnalysis) { // This is just a regular list of components. expandedDefinition += "\n\n" + resources.getString(R.string.label_components) + ": " + components; } } // Display plural information. if (!entry.isPlural() && !entry.isInherentPlural() && !entry.isPlural()) { if (entry.isBeingCapableOfLanguage()) { expandedDefinition += "\n\n" + resources.getString(R.string.info_being); } else if (entry.isBodyPart()) { expandedDefinition += "\n\n" + resources.getString(R.string.info_body); } } // If the entry is a useful phrase, link back to its category. if (entry.isSentence()) { String sentenceType = entry.getSentenceType(); if (!sentenceType.equals("")) { // Put the query as a placeholder for the actual category. expandedDefinition += "\n\n" + resources.getString(R.string.label_category) + ": {" + entry.getSentenceTypeQuery() + "}"; } } // If the entry is a sentence, make a link to analyse its components. if (showAnalysis) { String analysisQuery = entry.getEntryName(); if (!components.equals("")) { // Strip the brackets around each component so they won't be processed. analysisQuery += ":" + entry.getPartOfSpeech(); int homophoneNumber = entry.getHomophoneNumber(); if (homophoneNumber != -1) { analysisQuery += ":" + homophoneNumber; } analysisQuery += KlingonContentProvider.Entry.COMPONENTS_MARKER + components.replaceAll("[{}]", ""); } expandedDefinition += "\n\n" + resources.getString(R.string.label_analyze) + ": {" + analysisQuery + "}"; } // Show the examples. String examples = entry.getExamples(); if (!examples.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_examples) + ": " + examples; } // Show the source. String source = entry.getSource(); if (!source.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_sources) + ": " + source; } // If this is a verb (but not a prefix or suffix), show the transitivity information. String transitivity = ""; if (entry.isVerb() && sharedPrefs.getBoolean(Preferences.KEY_SHOW_TRANSITIVITY_CHECKBOX_PREFERENCE, /* default */ true)) { // This is a verb and show transitivity preference is set to true. transitivity = entry.getTransitivityString(); } int transitivityStart = -1; String transitivityHeader = "\n\n" + resources.getString(R.string.label_transitivity) + ": "; boolean showTransitivityInformation = !transitivity.equals(""); if (showTransitivityInformation) { transitivityStart = expandedDefinition.length(); expandedDefinition += transitivityHeader + transitivity; } // Show the hidden notes. String hiddenNotes = ""; if (sharedPrefs.getBoolean(Preferences.KEY_SHOW_ADDITIONAL_INFORMATION_CHECKBOX_PREFERENCE, /* default */ true)) { // Show additional information preference set to true. hiddenNotes = entry.getHiddenNotes(); } int hiddenNotesStart = -1; String hiddenNotesHeader = "\n\n" + resources.getString(R.string.label_additional_information) + ": "; if (!hiddenNotes.equals("")) { hiddenNotesStart = expandedDefinition.length(); expandedDefinition += hiddenNotesHeader + hiddenNotes; } // Format the expanded definition, including linkifying the links to other entries. float smallTextScale = (float) 0.8; SpannableStringBuilder ssb = new SpannableStringBuilder(expandedDefinition); int intermediateFlags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_INTERMEDIATE; int finalFlags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; if (!pos.equals("")) { // Italicise the part of speech. ssb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, pos.length(), finalFlags); } if (displayGermanEntry) { // Reduce the size of the German definition. ssb.setSpan(new RelativeSizeSpan(smallTextScale), germanDefinitionStart, germanDefinitionStart + germanDefinitionHeader.length() + definition_DE.length(), finalFlags); } if (showTransitivityInformation) { // Reduce the size of the transitivity information. ssb.setSpan(new RelativeSizeSpan(smallTextScale), transitivityStart, transitivityStart + transitivityHeader.length() + transitivity.length(), finalFlags); } if (!hiddenNotes.equals("")) { // Reduce the size of the hidden notes. ssb.setSpan(new RelativeSizeSpan(smallTextScale), hiddenNotesStart, hiddenNotesStart + hiddenNotesHeader.length() + hiddenNotes.length(), finalFlags); } Matcher m = KlingonContentProvider.Entry.ENTRY_PATTERN.matcher(expandedDefinition); while (m.find()) { // Strip the brackets {} to get the query. String query = expandedDefinition.substring(m.start() + 1, m.end() - 1); LookupClickableSpan viewLauncher = new LookupClickableSpan(query); // Process the linked entry information. KlingonContentProvider.Entry linkedEntry = new KlingonContentProvider.Entry(query, getBaseContext()); // Log.d(TAG, "linkedEntry.getEntryName() = " + linkedEntry.getEntryName()); // Delete the brackets and metadata parts of the string (which includes analysis components). ssb.delete(m.start() + 1 + linkedEntry.getEntryName().length(), m.end()); ssb.delete(m.start(), m.start() + 1); int end = m.start() + linkedEntry.getEntryName().length(); // Insert link to the category for a useful phrase. if (entry.isSentence() && !entry.getSentenceType().equals("") && linkedEntry.getEntryName().equals("*")) { // Delete the "*" placeholder. ssb.delete(m.start(), m.start() + 1); // Insert the category name. ssb.insert(m.start(), entry.getSentenceType()); end += entry.getSentenceType().length() - 1; } // Set the font and link. // TODO: Source should link to description of the source. // This is true if this entry doesn't launch an EntryActivity. boolean disableEntryLink = linkedEntry.doNotLink() || linkedEntry.isSource() || linkedEntry.isURL(); // The last span set on a range must have finalFlags. int maybeFinalFlags = disableEntryLink ? finalFlags : intermediateFlags; if (linkedEntry.isSource()) { // Names of sources are in italics. ssb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), m.start(), end, maybeFinalFlags); } else if (linkedEntry.isURL()) { // Linkify URL if there is one. String url = linkedEntry.getURL(); if (!url.equals("")) { ssb.setSpan(new URLSpan(url), m.start(), end, maybeFinalFlags); } } else if (useKlingonFont) { // Display the text using the Klingon font. Categories (which have an entry of "*") must // be handled specially. String klingonEntryName = !linkedEntry.getEntryName().equals("*") ? linkedEntry.getEntryNameInKlingonFont() : KlingonContentProvider.convertStringToKlingonFont(entry.getSentenceType()); ssb.delete(m.start(), end); ssb.insert(m.start(), klingonEntryName); end = m.start() + klingonEntryName.length(); ssb.setSpan(new KlingonTypefaceSpan("", klingonTypeface), m.start(), end, maybeFinalFlags); } else { // Klingon is in bold serif. ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), m.start(), end, intermediateFlags); ssb.setSpan(new TypefaceSpan("serif"), m.start(), end, maybeFinalFlags); } // If linked entry is hypothetical or extended canon, insert a "?" in front. if (linkedEntry.isHypothetical() || linkedEntry.isExtendedCanon()) { ssb.insert(m.start(), "?"); ssb.setSpan(new RelativeSizeSpan(smallTextScale), m.start(), m.start() + 1, intermediateFlags); ssb.setSpan(new SuperscriptSpan(), m.start(), m.start() + 1, maybeFinalFlags); end++; } // Only apply colours to verbs, nouns, and affixes (exclude BLUE and WHITE). if (!disableEntryLink) { // Link to view launcher. ssb.setSpan(viewLauncher, m.start(), end, useColours ? intermediateFlags : finalFlags); } // Set the colour last, so it's not overridden by other spans. if (useColours) { ssb.setSpan(new ForegroundColorSpan(linkedEntry.getTextColor()), m.start(), end, finalFlags); } String linkedPos = linkedEntry.getBracketedPartOfSpeech(/* isHtml */false); if (!linkedPos.equals("") && linkedPos.length() > 1) { ssb.insert(end, linkedPos); int rightBracketLoc = linkedPos.indexOf(")"); if (rightBracketLoc != -1) { // linkedPos is always of the form " (pos)[ (def'n N)]", we want to italicise // the "pos" part only. ssb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), end + 2, end + rightBracketLoc, finalFlags); } } // Rinse and repeat. expandedDefinition = ssb.toString(); m = KlingonContentProvider.Entry.ENTRY_PATTERN.matcher(expandedDefinition); } // Display the entry name and definition. entryText.invalidate(); entryText.setText(ssb); entryText.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:org.kontalk.ui.GroupInfoFragment.java
private void showIdentityDialog(Contact c, boolean subscribed) { final String jid = c.getJID(); final String dialogFingerprint; final String fingerprint; final boolean selfJid = Authenticator.isSelfJID(getContext(), jid); int titleResId = R.string.title_identity; String uid;//from w w w. jav a 2 s.c o m PGPPublicKeyRing publicKey = Keyring.getPublicKey(getContext(), jid, MyUsers.Keys.TRUST_UNKNOWN); if (publicKey != null) { PGPPublicKey pk = PGP.getMasterKey(publicKey); String rawFingerprint = PGP.getFingerprint(pk); fingerprint = PGP.formatFingerprint(rawFingerprint); uid = PGP.getUserId(pk, XmppStringUtils.parseDomain(jid)); dialogFingerprint = selfJid ? null : rawFingerprint; } else { // FIXME using another string fingerprint = getString(R.string.peer_unknown); uid = null; dialogFingerprint = null; } if (Authenticator.isSelfJID(getContext(), jid)) { titleResId = R.string.title_identity_self; } SpannableStringBuilder text = new SpannableStringBuilder(); if (c.getName() != null && c.getNumber() != null) { text.append(c.getName()).append('\n').append(c.getNumber()); } else { int start = text.length(); text.append(uid != null ? uid : c.getJID()); text.setSpan(SystemUtils.getTypefaceSpan(Typeface.BOLD), start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } text.append('\n').append(getString(R.string.text_invitation2)).append('\n'); int start = text.length(); text.append(fingerprint); text.setSpan(SystemUtils.getTypefaceSpan(Typeface.BOLD), start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); int trustStringId; CharacterStyle[] trustSpans; if (subscribed) { int trustedLevel; if (c.isKeyChanged()) { // the key has changed and was not trusted yet trustedLevel = MyUsers.Keys.TRUST_UNKNOWN; } else { trustedLevel = c.getTrustedLevel(); } switch (trustedLevel) { case MyUsers.Keys.TRUST_IGNORED: trustStringId = R.string.trust_ignored; trustSpans = new CharacterStyle[] { SystemUtils.getTypefaceSpan(Typeface.BOLD), SystemUtils.getColoredSpan(getContext(), R.color.button_danger) }; break; case MyUsers.Keys.TRUST_VERIFIED: trustStringId = R.string.trust_verified; trustSpans = new CharacterStyle[] { SystemUtils.getTypefaceSpan(Typeface.BOLD), SystemUtils.getColoredSpan(getContext(), R.color.button_success) }; break; case MyUsers.Keys.TRUST_UNKNOWN: default: trustStringId = R.string.trust_unknown; trustSpans = new CharacterStyle[] { SystemUtils.getTypefaceSpan(Typeface.BOLD), SystemUtils.getColoredSpan(getContext(), R.color.button_danger) }; break; } } else { trustStringId = R.string.status_notsubscribed; trustSpans = new CharacterStyle[] { SystemUtils.getTypefaceSpan(Typeface.BOLD), }; } text.append('\n').append(getString(R.string.status_label)); start = text.length(); text.append(getString(trustStringId)); for (CharacterStyle span : trustSpans) text.setSpan(span, start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); MaterialDialog.Builder builder = new MaterialDialog.Builder(getContext()).content(text).title(titleResId); if (dialogFingerprint != null && subscribed) { builder.onAny(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { switch (which) { case POSITIVE: // trust the key trustKey(jid, dialogFingerprint, MyUsers.Keys.TRUST_VERIFIED); break; case NEUTRAL: // ignore the key trustKey(jid, dialogFingerprint, MyUsers.Keys.TRUST_IGNORED); break; case NEGATIVE: // untrust the key trustKey(jid, dialogFingerprint, MyUsers.Keys.TRUST_UNKNOWN); break; } } }).positiveText(R.string.button_accept).positiveColorRes(R.color.button_success) .neutralText(R.string.button_ignore).negativeText(R.string.button_refuse) .negativeColorRes(R.color.button_danger); } else if (!selfJid) { builder.onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { openChat(jid); } }).positiveText(R.string.button_private_chat); } builder.show(); }
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 {// ww w . ja v a2 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); } }