List of usage examples for android.text Spannable setSpan
public void setSpan(Object what, int start, int end, int flags);
start…end
of the text, or move the object to that range if it was already attached elsewhere. From source file:android.melbournehistorymap.MapsActivity.java
/** * Manipulates the map once available.//from w w w .j ava 2 s .c o m * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; spinner = (ProgressBar) findViewById(R.id.prograssSpinner); //check if permission has been granted if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission has already been granted return; } mMap.setMyLocationEnabled(true); mMap.getUiSettings().setZoomControlsEnabled(false); double lat; double lng; final int radius; int zoom; lat = Double.parseDouble(CurrLat); lng = Double.parseDouble(CurrLong); //build current location LatLng currentLocation = new LatLng(lat, lng); final LatLng realLocation = currentLocation; if (MELBOURNE.contains(currentLocation)) { mMap.getUiSettings().setMyLocationButtonEnabled(true); zoom = 17; } else { mMap.getUiSettings().setMyLocationButtonEnabled(false); lat = -37.81161508043379; lng = 144.9647320434451; zoom = 15; currentLocation = new LatLng(lat, lng); } mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLocation, 13)); CameraPosition cameraPosition = new CameraPosition.Builder().target(currentLocation) // Sets the center of the map to location user .zoom(zoom) // Sets the zoom .bearing(0) // Sets the orientation of the camera to east .tilt(25) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder //Animate user to map location, if in Melbourne or outside of Melbourne bounds mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), new GoogleMap.CancelableCallback() { @Override public void onFinish() { updateMap(); } @Override public void onCancel() { } }); final TextView placeTitle = (TextView) findViewById(R.id.placeTitle); final TextView placeVic = (TextView) findViewById(R.id.placeVic); final TextView expPlaceTitle = (TextView) findViewById(R.id.expPlaceTitle); final TextView expPlaceVic = (TextView) findViewById(R.id.expPlaceVic); final TextView expPlaceDescription = (TextView) findViewById(R.id.placeDescription); final TextView wikiLicense = (TextView) findViewById(R.id.wikiLicense); final TextView expPlaceDistance = (TextView) findViewById(R.id.expPlaceDistance); final RelativeLayout tile = (RelativeLayout) findViewById(R.id.tile); final TextView fab = (TextView) findViewById(R.id.fab); final RelativeLayout distanceCont = (RelativeLayout) findViewById(R.id.distanceContainer); // String license = "Text is available under the <a rel=\"license\" href=\"//en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License\">Creative Commons Attribution-ShareAlike License</a><a rel=\"license\" href=\"//creativecommons.org/licenses/by-sa/3.0/\" style=\"display:none;\"></a>;\n" + // "additional terms may apply."; // wikiLicense.setText(Html.fromHtml(license)); // wikiLicense.setMovementMethod(LinkMovementMethod.getInstance()); //Marker click mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { @Override public boolean onMarkerClick(Marker marker) { String title = marker.getTitle(); mMap.setPadding(0, 0, 0, 620); //set clicked marker to full opacity marker.setAlpha(1f); //set previous marker back to partial opac (if there is a prevMarker if (dirtyMarker == 1) { prevMarker.setAlpha(0.6f); } prevMarker = marker; dirtyMarker = 1; //Set DB helper DBHelper myDBHelper = new DBHelper(MapsActivity.this, WikiAPI.DB_NAME, null, WikiAPI.VERSION); //Only search for Wiki API requests if no place article returned. // ** //Open DB as readable only. SQLiteDatabase db = myDBHelper.getReadableDatabase(); //Set the query String dbFriendlyName = title.replace("\'", "\'\'"); //Limit by 1 rows Cursor cursor = db.query(DBHelper.TABLE_NAME, null, "PLACE_NAME = '" + dbFriendlyName + "'", null, null, null, null, "1"); //move through each row returned in the query results while (cursor.moveToNext()) { String place_ID = cursor.getString(cursor.getColumnIndex("PLACE_ID")); String placeName = cursor.getString(cursor.getColumnIndex("PLACE_NAME")); String placeLoc = cursor.getString(cursor.getColumnIndex("PLACE_LOCATION")); String placeArticle = cursor.getString(cursor.getColumnIndex("ARTICLE")); String placeLat = cursor.getString(cursor.getColumnIndex("LAT")); String placeLng = cursor.getString(cursor.getColumnIndex("LNG")); //Get Google Place photos //Source: https://developers.google.com/places/android-api/photos final String placeId = place_ID; Places.GeoDataApi.getPlacePhotos(mGoogleApiClient, placeId) .setResultCallback(new ResultCallback<PlacePhotoMetadataResult>() { @Override public void onResult(PlacePhotoMetadataResult photos) { if (!photos.getStatus().isSuccess()) { return; } ImageView mImageView = (ImageView) findViewById(R.id.imageView); ImageView mImageViewExpanded = (ImageView) findViewById(R.id.headerImage); TextView txtAttribute = (TextView) findViewById(R.id.photoAttribute); TextView expTxtAttribute = (TextView) findViewById(R.id.expPhotoAttribute); PlacePhotoMetadataBuffer photoMetadataBuffer = photos.getPhotoMetadata(); if (photoMetadataBuffer.getCount() > 0) { // Display the first bitmap in an ImageView in the size of the view photoMetadataBuffer.get(0).getScaledPhoto(mGoogleApiClient, 600, 200) .setResultCallback(mDisplayPhotoResultCallback); //get photo attributions PlacePhotoMetadata photo = photoMetadataBuffer.get(0); CharSequence attribution = photo.getAttributions(); if (attribution != null) { txtAttribute.setText(Html.fromHtml(String.valueOf(attribution))); expTxtAttribute.setText(Html.fromHtml(String.valueOf(attribution))); //http://stackoverflow.com/questions/4303160/how-can-i-make-links-in-fromhtml-clickable-android txtAttribute.setMovementMethod(LinkMovementMethod.getInstance()); expTxtAttribute.setMovementMethod(LinkMovementMethod.getInstance()); } else { txtAttribute.setText(" "); expTxtAttribute.setText(" "); } } else { //Reset image view as no photo was identified mImageView.setImageResource(android.R.color.transparent); mImageViewExpanded.setImageResource(android.R.color.transparent); txtAttribute.setText(R.string.no_photos); expTxtAttribute.setText(R.string.no_photos); } photoMetadataBuffer.release(); } }); LatLng destLocation = new LatLng(Double.parseDouble(placeLat), Double.parseDouble(placeLng)); //Work out distance between current location and place location //Source Library: https://github.com/googlemaps/android-maps-utils double distance = SphericalUtil.computeDistanceBetween(realLocation, destLocation); distance = Math.round(distance); distance = distance * 0.001; String strDistance = String.valueOf(distance); String[] arrDistance = strDistance.split("\\."); String unit = "km"; if (arrDistance[0] == "0") { unit = "m"; strDistance = arrDistance[1]; } else { strDistance = arrDistance[0] + "." + arrDistance[1].substring(0, 1); } placeArticle = placeArticle .replaceAll("(<div class=\"thumb t).*\\s.*\\s.*\\s.*\\s.*\\s<\\/div>\\s<\\/div>", " "); Spannable noUnderlineMessage = new SpannableString(Html.fromHtml(placeArticle)); //http://stackoverflow.com/questions/4096851/remove-underline-from-links-in-textview-android for (URLSpan u : noUnderlineMessage.getSpans(0, noUnderlineMessage.length(), URLSpan.class)) { noUnderlineMessage.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, noUnderlineMessage.getSpanStart(u), noUnderlineMessage.getSpanEnd(u), 0); } placeArticle = String.valueOf(noUnderlineMessage); placeArticle = placeArticle.replaceAll("(\\[\\d\\])", " "); placeTitle.setText(placeName); expPlaceTitle.setText(placeName); placeVic.setText(placeLoc); expPlaceVic.setText(placeLoc); expPlaceDescription.setText(placeArticle); if (MELBOURNE.contains(realLocation)) { expPlaceDistance.setText("Distance: " + strDistance + unit); distanceCont.setVisibility(View.VISIBLE); } } tile.setVisibility(View.VISIBLE); fab.setVisibility(View.VISIBLE); //Set to true to not show default behaviour. return false; } }); mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() { @Override public void onMapClick(LatLng latLng) { int viewStatus = tile.getVisibility(); if (viewStatus == View.VISIBLE) { tile.setVisibility(View.INVISIBLE); fab.setVisibility(View.INVISIBLE); //set previous marker back to partial opac (if there is a prevMarker if (dirtyMarker == 1) { prevMarker.setAlpha(0.6f); } } mMap.setPadding(0, 0, 0, 0); } }); FloatingActionButton shareIcon = (FloatingActionButton) findViewById(R.id.shareIcon); shareIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //https://www.google.com.au/maps/place/Federation+Square/@-37.8179789,144.9668635,15z //Build implicit intent by triggering a SENDTO action, which will capture applications that allow for messages //that allow for messages to be sent to a specific user with data //http://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); //Build SMS String encodedPlace = "empty"; try { encodedPlace = URLEncoder.encode(String.valueOf(expPlaceTitle.getText()), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(expPlaceTitle.getText()) + " \n\nhttps://www.google.com.au/maps/place/" + encodedPlace); Intent sms = Intent.createChooser(intent, null); startActivity(sms); } }); TextView fullArticle = (TextView) findViewById(R.id.fullArticle); fullArticle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String wikiPlace = WikiPlace.getName(String.valueOf(expPlaceTitle.getText())); String url = "https://en.wikipedia.org/wiki/" + wikiPlace; Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent); } }); }
From source file:com.flipzu.flipzu.Player.java
private void displayComment(Hashtable<String, String> comment) { if (comment == null) return;//ww w . ja v a 2s .c o m final LinearLayout com_layout = (LinearLayout) findViewById(R.id.comments_layout); TextView comment_tv = new TextView(Player.this); comment_tv.setText(comment.get("username") + ": " + comment.get("comment"), TextView.BufferType.SPANNABLE); comment_tv.setTextColor(Color.parseColor("#656565")); Spannable comment_span = (Spannable) comment_tv.getText(); comment_span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, comment_tv.getText().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); comment_span.setSpan(new ForegroundColorSpan(Color.parseColor("#597490")), 0, comment.get("username").length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); comment_tv.setText(comment_span); com_layout.addView(comment_tv); }
From source file:org.sirimangalo.meditationplus.ActivityMain.java
private void populateMeds(JSONArray meds) { if (findViewById(R.id.med_list) == null) return;/*from w w w . j a v a2s . c om*/ medList = (ListView) findViewById(R.id.med_list); medArray = new ArrayList<JSONObject>(); for (int i = 0; i < meds.length(); i++) { try { JSONObject med = meds.getJSONObject(i); if (med.getString("username").equals(username)) { if (startMeditating) { startMeditating = false; if (lastWalking > 0 || lastSitting > 0) scheduleClient.setAlarmForNotification(lastWalking, lastSitting); } if (med.getString("type").equals("love")) { special = "love"; Spannable span = new SpannableString("LOVE"); span.setSpan(new ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(Color.YELLOW), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(Color.GREEN), 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(Color.BLUE), 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); medButton.setText(span); } else { special = "none"; medButton.setText(R.string.start); } } medArray.add(med); } catch (JSONException e) { e.printStackTrace(); } } TextView emptyText = (TextView) findViewById(android.R.id.empty); medList.setEmptyView(emptyText); AdapterMed adapter = new AdapterMed(this, R.layout.list_item_med, medArray, postHandler); medList.setAdapter(adapter); }
From source file:org.sirimangalo.meditationplus.ActivityMain.java
private void populateOnline(JSONArray onlines) { if (onlines.length() == 0) { onlineList.setVisibility(View.GONE); return;//from ww w.j ava 2s . c om } onlineList.setVisibility(View.VISIBLE); ArrayList<JSONObject> onlineArray = new ArrayList<JSONObject>(); ArrayList<String> onlineNamesArray = new ArrayList<String>(); // collect into array for (int i = 0; i < onlines.length(); i++) { try { JSONObject a = onlines.getJSONObject(i); onlineArray.add(a); onlineNamesArray.add(a.getString("username")); } catch (JSONException e) { e.printStackTrace(); } } String text = getString(R.string.online) + " "; // add spans int pos = text.length(); // start after "Online: " text += TextUtils.join(", ", onlineNamesArray); Spannable span = new SpannableString(text); span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: " Drawable android = context.getResources().getDrawable(R.drawable.android); android.setBounds(0, 0, 48, 32); for (JSONObject oneOnA : onlineArray) { try { final String oneOn = oneOnA.getString("username"); int end = pos + oneOn.length(); boolean isMed = false; for (int j = 0; j < jsonList.length(); j++) { JSONObject user = jsonList.getJSONObject(j); String username = user.getString("username"); if (username.equals(oneOn)) isMed = true; } if (oneOnA.getString("source").equals("android")) { ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE); span.setSpan(image, pos - 1, pos, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } ClickableSpan clickable = new ClickableSpan() { @Override public void onClick(View widget) { showProfile(oneOn); } }; span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, pos, end, 0); span.setSpan(new ForegroundColorSpan(isMed ? 0xFF009900 : 0xFFFF9900), pos, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); pos += oneOn.length() + 2; } catch (JSONException e) { e.printStackTrace(); } } onlineList.setText(span); onlineList.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.ruesga.rview.tasks.AsyncTextDiffProcessor.java
private List<DiffView.AbstractModel> processUnifiedDiffs() { final List<DiffView.AbstractModel> model = new ArrayList<>(); addBinaryAdviseIfNeeded(model);/* www . j a v a 2 s .co m*/ if (mDiffs == null) { return model; } int lineNumberA = 0; int lineNumberB = 0; final Spannable.Factory spannableFactory = Spannable.Factory.getInstance(); final int noColor = ContextCompat.getColor(mContext, android.R.color.transparent); final int addedBgColor = ContextCompat.getColor(mContext, R.color.diffAddedBackgroundColor); final int addedFgColor = ContextCompat.getColor(mContext, R.color.diffAddedForegroundColor); final int deletedBgColor = ContextCompat.getColor(mContext, R.color.diffDeletedBackgroundColor); final int deletedFgColor = ContextCompat.getColor(mContext, R.color.diffDeletedForegroundColor); boolean noDiffs = mDiffs.length == 1 && mDiffs[0].a == null && mDiffs[0].b == null; int j = 0; for (DiffContentInfo diff : mDiffs) { if (diff.ab != null) { // Unchanged lines int[] p = processUnchangedLines(diff, model, j, lineNumberA, lineNumberB, noColor, noDiffs); lineNumberA = p[0]; lineNumberB = p[1]; } else { if (diff.a != null) { int pos = 0; for (String line : diff.a) { DiffInfoModel m = new DiffInfoModel(); m.a = ++lineNumberA; m.lineNumberA = String.valueOf(m.a); if (diff.editA != null) { Spannable span = spannableFactory.newSpannable(prepareTabs(line)); if (mHighlightIntralineDiffs) { int s2 = 0; for (ArrayList<Integer> intra : diff.editA) { int s1 = s2 + intra.get(0); s2 = s1 + intra.get(1); int l = pos + line.length(); if ((s1 >= pos && s1 <= l) || (s2 >= pos && s2 <= l) || (s1 <= pos && s2 >= l)) { span.setSpan(new BackgroundColorSpan(deletedFgColor), Math.max(pos, s1) - pos, Math.min(l, s2) - pos, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } m.lineA = span; } else { // No intraline data, but it still could differ at start or at end processNoIntralineDataA(diff, m, line, deletedFgColor); } m.colorA = deletedBgColor; m.colorB = noColor; processHighlights(m); model.add(m); pos += line.length() + 1; } } if (diff.b != null) { int pos = 0; for (String line : diff.b) { DiffInfoModel m = new DiffInfoModel(); m.b = ++lineNumberB; m.lineNumberB = String.valueOf(m.b); if (diff.editB != null) { Spannable span = spannableFactory.newSpannable(prepareTabs(line)); if (mHighlightIntralineDiffs) { int s2 = 0; for (ArrayList<Integer> intra : diff.editB) { int s1 = s2 + intra.get(0); s2 = s1 + intra.get(1); int l = pos + line.length(); if ((s1 >= pos && s1 <= l) || (s2 >= pos && s2 <= l) || (s1 <= pos && s2 >= l)) { span.setSpan(new BackgroundColorSpan(addedFgColor), Math.max(pos, s1) - pos, Math.min(l, s2) - pos, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } m.lineB = span; } else { // No intraline data, but it still could differ at start or at end processNoIntralineDataB(diff, m, line, addedFgColor); } m.colorA = addedBgColor; m.colorB = noColor; processHighlights(m); model.add(m); pos += line.length() + 1; } } } j++; } return model; }
From source file:com.ruesga.rview.tasks.AsyncTextDiffProcessor.java
private List<DiffView.AbstractModel> processSideBySideDiffs() { final List<DiffView.AbstractModel> model = new ArrayList<>(); addBinaryAdviseIfNeeded(model);//www . j ava2 s .c o m if (mDiffs == null) { return model; } int lineNumberA = 0; int lineNumberB = 0; final Spannable.Factory spannableFactory = Spannable.Factory.getInstance(); final int noColor = ContextCompat.getColor(mContext, android.R.color.transparent); final int addedBgColor = ContextCompat.getColor(mContext, R.color.diffAddedBackgroundColor); final int addedFgColor = ContextCompat.getColor(mContext, R.color.diffAddedForegroundColor); final int deletedBgColor = ContextCompat.getColor(mContext, R.color.diffDeletedBackgroundColor); final int deletedFgColor = ContextCompat.getColor(mContext, R.color.diffDeletedForegroundColor); boolean noDiffs = mDiffs.length == 1 && mDiffs[0].a == null && mDiffs[0].b == null; int j = 0; for (DiffContentInfo diff : mDiffs) { if (diff.ab != null) { // Unchanged lines int[] p = processUnchangedLines(diff, model, j, lineNumberA, lineNumberB, noColor, noDiffs); lineNumberA = p[0]; lineNumberB = p[1]; } else { int posA = 0; int posB = 0; int count = Math.max(diff.a == null ? 0 : diff.a.length, diff.b == null ? 0 : diff.b.length); for (int i = 0; i < count; i++) { DiffInfoModel m = new DiffInfoModel(); m.colorA = noColor; m.colorB = noColor; if (diff.a != null && i < diff.a.length) { String line = diff.a[i]; m.a = ++lineNumberA; m.lineNumberA = String.valueOf(m.a); if (diff.editA != null) { Spannable span = spannableFactory.newSpannable(prepareTabs(line)); if (mHighlightIntralineDiffs) { int s2 = 0; for (ArrayList<Integer> intra : diff.editA) { int s1 = s2 + intra.get(0); s2 = s1 + intra.get(1); int l = posA + line.length(); if ((s1 >= posA && s1 <= l) || (s2 >= posA && s2 <= l) || (s1 <= posA && s2 >= l)) { span.setSpan(new BackgroundColorSpan(deletedFgColor), Math.max(posA, s1) - posA, Math.min(l, s2) - posA, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } m.lineA = span; } else { // No intraline data, but it still could differ at start or at end processNoIntralineDataA(diff, m, line, deletedFgColor); } m.colorA = deletedBgColor; posA += line.length() + 1; } if (diff.b != null && i < diff.b.length) { String line = diff.b[i]; m.b = ++lineNumberB; m.lineNumberB = String.valueOf(m.b); if (diff.editB != null) { Spannable span = spannableFactory.newSpannable(prepareTabs(line)); if (mHighlightIntralineDiffs) { int s2 = 0; for (ArrayList<Integer> intra : diff.editB) { int s1 = s2 + intra.get(0); s2 = s1 + intra.get(1); int l = posB + line.length(); if ((s1 >= posB && s1 <= l) || (s2 >= posB && s2 <= l) || (s1 <= posB && s2 >= l)) { span.setSpan(new BackgroundColorSpan(addedFgColor), Math.max(posB, s1) - posB, Math.min(l, s2) - posB, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } m.lineB = span; } else { // No intraline data, but it still could differ at start or at end processNoIntralineDataB(diff, m, line, addedFgColor); } m.colorB = addedBgColor; posB += line.length() + 1; } processHighlights(m); model.add(m); } } j++; } return model; }
From source file:com.nearnotes.NoteEdit.java
/** * Populates the checkboxes on the side by analyzing the current text from * the body of the note./* w w w . j a va 2 s .co m*/ * * @param currentString * the current body of the note. * */ public ArrayList<NoteRow> populateBoxes(String currentString) { // Load ArrayList<String> mLines with the current bodytext seperated into seperate lines. mLines = Arrays.asList(currentString.split(System.getProperty("line.separator"))); // row counter to determine what the current line number is for the for loop int row = 0; // realRow counter to determine what line of text in the actual display we are on // used to get the number of characters on each line int realRow = 0; int activeRow = 0; int finishedCount = 0; ArrayList<NoteRow> tempRealRow = new ArrayList<NoteRow>(); for (String line : mLines) { NoteRow temp = new NoteRow(0, 1, row); // Create a note row object with rowType of 0 (invisible), lineSize of 1 and the current row number if (!line.isEmpty()) { activeRow++; temp.setType(1); // Set the NoteRow object to 1 (visible) // Determine how many lines the note takes up int internalCounter = 0; try { float lineLength = (float) line.length(); for (int k = 0; (lineLength / (getFloatLineEnd(realRow + k) - getFloatLineEnd(realRow - 1))) > 1; k++) { internalCounter++; } } catch (NullPointerException e) { e.printStackTrace(); } // Detemine if the note is supposed to be checked and set the NoteRow object to 2 (Checked) if (line.startsWith("[X]")) { finishedCount++; int spanstart = 0; StrikethroughSpan STRIKE_THROUGH_SPAN = new StrikethroughSpan(); Spannable spannable = (Spannable) mBodyText.getText(); // TableRow checkRow1 = (TableRow) View.inflate(getActivity(), R.layout.table_row, null); for (int j = 0; j < row; j++) { spanstart += mLines.get(j).length() + 1; } Object spansToRemove[] = spannable.getSpans(spanstart, spanstart + mLines.get(row).length(), Object.class); for (Object span : spansToRemove) { if (span instanceof CharacterStyle) spannable.removeSpan(span); } spannable.setSpan(STRIKE_THROUGH_SPAN, spanstart, spanstart + mLines.get(row).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); temp.setType(2); } temp.setSize(1 + internalCounter); // Set the amount of rows the note takes up realRow = realRow + internalCounter; // Determine the real line on the display text we are on } tempRealRow.add(temp); // NoteRow object has been finalized - add to the ListArray<NoteRow> realRow++; // Increase the noteRow and the displayRow for the next line row++; } if (finishedCount == activeRow && finishedCount != 0) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); boolean useListPref = sharedPref.getBoolean("pref_key_use_checklist_default", false); String stringlistPref = sharedPref.getString("pref_key_checklist_listPref", "2"); int listPref = Integer.parseInt(stringlistPref); ChecklistDialog newFragment = new ChecklistDialog(); if (mRowId == null) { saveState(); } Bundle args = new Bundle(); args.putLong("_id", mRowId); args.putBoolean("useDefault", useListPref); args.putInt("listPref", listPref); newFragment.setArguments(args); if (listPref == 2 && useListPref) { return tempRealRow; } if (getFragmentManager().findFragmentByTag("MyDialog") == null) { newFragment.show(getFragmentManager(), "MyDialog"); } } return tempRealRow; }
From source file:com.ruesga.rview.SearchActivity.java
private CharSequence performFilterHighlight(Suggestion suggestion) { Spannable span = Spannable.Factory.getInstance().newSpannable(suggestion.mSuggestionText); int pos = 0;// w w w . jav a 2s. c o m final Locale locale = AndroidHelper.getCurrentLocale(getApplicationContext()); final String suggestionNoCase = suggestion.mSuggestionText.toLowerCase(locale); final String filterNoCase = suggestion.mFilter.toLowerCase(locale); while ((pos = suggestionNoCase.indexOf(filterNoCase, pos)) != -1) { final int length = suggestion.mFilter.length(); if (length == 0) { break; } final StyleSpan bold = new StyleSpan(android.graphics.Typeface.BOLD); final ForegroundColorSpan color = new ForegroundColorSpan(ContextCompat.getColor(this, R.color.accent)); span.setSpan(bold, pos, pos + length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(color, pos, pos + length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); pos += length; if (pos >= suggestionNoCase.length()) { break; } } return span; }
From source file:com.msopentech.applicationgateway.EnterpriseBrowserActivity.java
public void showSettingsPopup(View v) { try {/*from w w w .j a v a 2 s . c o m*/ PopupMenu popup = new PopupMenu(this, v); MenuInflater inflater = popup.getMenuInflater(); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_connection: { showAgentsList(); return true; } case R.id.menu_sign_in_or_out: { if (mIsSigninRequired) { // Menu item in sign in mode. //TODO: showSignIn(null, true); return true; } // Clean up the session. mTraits.sessionID = null; mTraits.token = null; mTraits.agent = null; // Indicate the condition. mIsSigninRequired = true; //Remove all tabs except one. mCustomTabHost.resetTabs(); mUrlEditTextView.setText(""); mProgressBarView.setProgress(0); // Disable the reload button and set the right image for it. mReloadButtonView.setEnabled(false); mReloadButtonView.setImageResource(R.drawable.reload_button); mStatusButtonView.setImageResource(R.drawable.connection_red); // Since it's the user's intention to sign out, his // history must be dropped. PersistenceManager.dropContent(PersistenceManager.ContentType.HISTORY); return true; } // Removed from RELEASE version. Should be active for development ONLY. // case R.id.menu_advanced_router_settings: { // showAdvancedRouterSettings(null); // } default: { return false; } } } }); inflater.inflate(R.menu.settings_menu, popup.getMenu()); if (mIsSigninRequired) { MenuItem signItem = popup.getMenu().findItem(R.id.menu_sign_in_or_out); signItem.setTitle(getResources().getString(R.string.browser_menu_item_sign_in)); } // Assumes that agent always has a display name. If display name is not present agent is considered to be not connected. MenuItem agentItem = popup.getMenu().findItem(R.id.menu_connection); String status = getResources().getString(R.string.browser_menu_item_choose_connection_not_connected); if (mTraits != null && mTraits.agent != null && !TextUtils.isEmpty(mTraits.agent.getDisplayName())) { status = mTraits.agent.getDisplayName(); } Spannable span = new SpannableString( getResources().getString(R.string.browser_menu_item_choose_connection, status)); span.setSpan(new RelativeSizeSpan(0.8f), 18, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(Color.GRAY), 18, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); agentItem.setTitle(span); popup.show(); } catch (final Exception e) { Utility.showAlertDialog(EnterpriseBrowserActivity.class.getSimpleName() + ".showSettingsPopup(): Failed. " + e.toString(), EnterpriseBrowserActivity.this); } }
From source file:eu.iescities.pilot.rovereto.roveretoexplorer.fragments.event.info.EventDetailInfoAdapter.java
@SuppressWarnings("deprecation") @Override/*ww w. j a v a 2s . com*/ public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parentView) { final EventInfoParent parent = this.fragment.parents.get(groupPosition); final EventInfoChild child = parent.getChildren().get(childPosition); int itemType = getChildType(groupPosition, childPosition); Log.i("GROUPVIEW", "************ init child view!! ************ "); Log.i("GROUPVIEW", "COUNT: " + countChildViewCall); Log.i("GROUPVIEW", "CHILD TEXT: " + child.getText()); Log.i("GROUPVIEW", "CHILD TYPE: " + child.getType()); row = convertView; if (row == null) { // Inflate event_info_child_item.xml file for child rows LayoutInflater inflater = (LayoutInflater) this.fragment.context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.event_info_child_item, parentView, false); eventChildViewHolder = new EventInfoChildViewHolder(); eventChildViewHolder.text = (TextView) row.findViewById(R.id.event_info_attribute_values); // eventChildViewHolder.imgSx = (ImageView) row // .findViewById(R.id.event_info_attribute_value_icon); eventChildViewHolder.imgsDx1 = (ImageView) row.findViewById(R.id.event_info_action1); eventChildViewHolder.divider = (View) row.findViewById(R.id.event_info_item_divider); //this will be added again when it will be possible to cancel/edit the single items // eventChildViewHolder.imgsDx2 = (ImageView) row // .findViewById(R.id.event_info_action2); // eventChildViewHolder.imgsDx3 = (ImageView) row // .findViewById(R.id.event_info_action3); row.setTag(eventChildViewHolder); } else { eventChildViewHolder = (EventInfoChildViewHolder) row.getTag(); } // Get event_info_child_item.xml file elements and set values if (child.getTextInBold()) eventChildViewHolder.text.setTypeface(null, Typeface.BOLD); else eventChildViewHolder.text.setTypeface(null, Typeface.NORMAL); if (!child.getText().contains("http")) { eventChildViewHolder.text.setText(child.getText()); } else { if (!child.getText().matches(fragment.getString(R.string.start_url))) { Log.i("GROUPVIEW", "make the text part clickable!!!"); //make the text part clickable int i1 = 0; int i2 = child.getName().length() - 1; eventChildViewHolder.text.setMovementMethod(LinkMovementMethod.getInstance()); eventChildViewHolder.text.setText(child.getName(), BufferType.SPANNABLE); //eventChildViewHolder.text.setAutoLinkMask(Linkify.WEB_URLS); //Linkify.addLinks(eventChildViewHolder.text, Linkify.WEB_URLS); //String s = "<a href=\" + child.getText() + \">Website</a>"; //eventChildViewHolder.text.setText(Html.fromHtml(s)); Spannable mySpannable = (Spannable) eventChildViewHolder.text.getText(); ClickableSpan myClickableSpan = new ClickableSpan() { @Override public void onClick(View widget) { // Toast.makeText(fragment.context, // "Open browser ofr url: " + child.getText(), // Toast.LENGTH_LONG).show(); String url = child.getText(); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); fragment.context.startActivity(i); } }; // row.setFocusable(true); // row.setFocusableInTouchMode(true); mySpannable.setSpan(myClickableSpan, i1, i2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // eventChildViewHolder.text.setText(Html.fromHtml(child.getText())); // eventChildViewHolder.text.setMovementMethod(LinkMovementMethod.getInstance()); } else eventChildViewHolder.text.setText(child.getName()); } if (child.getName().equals("Description")) { //Log.i("EVENT", "EventDetailInfoAdapter --> set description to html!!"); eventChildViewHolder.text.setText(Html.fromHtml(child.getText())); eventChildViewHolder.text.setPadding(10, 10, 0, 0); } // set icon on the left side // if (child.getLeftIconId() != -1) { // Log.i("GROUPVIEW", "CHILD SX ICON ID: " + child.getLeftIconId()); // eventChildViewHolder.imgSx.setVisibility(View.VISIBLE); // eventChildViewHolder.imgSx.setImageResource(child.getLeftIconId()); // // Log.i("IMAGE", "IMG CHILD NAME: " // + child.getText()); // // Log.i("IMAGE", "IMG ICON WIDTH: " // + eventChildViewHolder.imgSx.getWidth()); // // } else { // Log.i("GROUPVIEW", "CHILD SX ICON -1"); // if ( (child.getName().equals("email")) || (child.getName().equals("tel")) ){ // Log.i("GROUPVIEW", "CHILD NAME: " + child.getName()); // eventChildViewHolder.imgSx.setVisibility(View.INVISIBLE); // eventChildViewHolder.text.setPadding(10, 0, 0, 0); // } // else{ // eventChildViewHolder.imgSx.setVisibility(View.GONE); // eventChildViewHolder.text.setPadding(10, 10, 0, 0); // } // // } // set icon on the left side if (child.getLeftIconId() != -1) { Log.i("GROUPVIEW", "CHILD SX ICON ID: " + child.getLeftIconId()); eventChildViewHolder.text.setCompoundDrawablesWithIntrinsicBounds(child.getLeftIconId(), 0, 0, 0); } else eventChildViewHolder.text.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); // set icons on the right side for the items of type 1 (telefono, email) if ((child.getRightIconIds() != null) && (child.getType() == 1)) { Log.i("GROUPVIEW", "CHILD DX1 ICON ID: " + child.getRightIconIds()[0]); eventChildViewHolder.text.setTypeface(null, Typeface.BOLD); eventChildViewHolder.imgsDx1.setVisibility(View.VISIBLE); eventChildViewHolder.imgsDx1.setImageResource(child.getRightIconIds()[0]); eventChildViewHolder.imgsDx1 .setOnClickListener(new ChildAddIconClickListener(this.fragment.context, child)); } else { Log.i("GROUPVIEW", "CHILD DX1 ICON NULL"); eventChildViewHolder.imgsDx1.setVisibility(View.INVISIBLE); } //set divider line height and color eventChildViewHolder.divider.setBackgroundColor(fragment.getResources().getColor(child.getDividerColor())); eventChildViewHolder.divider.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, child.getDividerHeight())); // set icons on the right side for the items of type 0 (single values) if ((child.getRightIconIds() != null) && (child.getType() == 0)) { Log.i("GROUPVIEW", "CHILD DX1 ICON ID: " + child.getRightIconIds()[0]); int iconsNumb = child.getRightIconIds().length; Log.i("GROUPVIEW", "ICON NUMMBER: " + iconsNumb); eventChildViewHolder.imgsDx1.setVisibility(View.VISIBLE); eventChildViewHolder.imgsDx1.setImageResource(child.getRightIconIds()[0]); eventChildViewHolder.imgsDx1 .setOnClickListener(new ChildActionIconClickListener(this.fragment.context, child)); //this will be added when cancel/edit for single item will be possible // eventChildViewHolder.imgsDx2.setVisibility(View.VISIBLE); // eventChildViewHolder.imgsDx2.setImageResource(child // .getRightIconIds()[1]); // if (iconsNumb == 3) // eventChildViewHolder.imgsDx3.setVisibility(View.VISIBLE); // eventChildViewHolder.imgsDx3.setImageResource(child // .getRightIconIds()[2]); } else { Log.i("GROUPVIEW", "CHILD DX1 ICON NULL"); eventChildViewHolder.imgsDx1.setVisibility(View.INVISIBLE); //this will be added when cancel/edit for single item will be possible // eventChildViewHolder.imgsDx2.setVisibility(View.INVISIBLE); // eventChildViewHolder.imgsDx3.setVisibility(View.INVISIBLE); } // Log.i("GROUPVIEW", "child view: group POS: " + groupPosition + "!!"); // Log.i("GROUPVIEW", "child view: child POS: " + childPosition + "!!"); countChildViewCall++; return row; }