List of usage examples for java.lang CharSequence toString
public String toString();
From source file:com.gmail.boiledorange73.ut.map.MapActivityBase.java
/** * (LOCAL) Gets the application name. 1. Returns label attribute of * application element if exists. 2. Returns the title of the activity. 3. * Returns empty string (not null)./*from w ww . j ava 2 s.co m*/ */ private String getAppName() { CharSequence appinfoLabel = this.getPackageManager().getApplicationLabel(this.getApplicationInfo()); if (appinfoLabel != null) { return appinfoLabel.toString(); } CharSequence title = this.getTitle(); if (title != null) { return title.toString(); } return ""; }
From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.conversation); database = Database.getInstance(getApplicationContext()); preferences = Preferences.getInstance(getApplicationContext()); contact = getIntent().getStringExtra(getString(R.string.conversation_extra_contact)); // Remove the leading one from a North American phone number (e.g. +1 (123) 555-4567) if ((contact.length() == 11) && (contact.charAt(0) == '1')) { contact = contact.substring(1);/*from www . jav a 2 s . c o m*/ } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation)); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { String contactName = Utils.getContactName(this, contact); if (contactName != null) { actionBar.setTitle(contactName); } else { actionBar.setTitle(Utils.getFormattedPhoneNumber(contact)); } actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); } layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); layoutManager.setStackFromEnd(true); adapter = new ConversationRecyclerViewAdapter(this, layoutManager, contact); recyclerView = (RecyclerView) findViewById(R.id.list); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); actionMode = null; actionModeEnabled = false; final EditText messageText = (EditText) findViewById(R.id.message_edit_text); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { messageText.setOutlineProvider(new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15); } }); messageText.setClipToOutline(true); } messageText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Do nothing. } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // Do nothing. } @Override public void afterTextChanged(Editable s) { ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher); if (s.toString().equals("") && viewSwitcher.getDisplayedChild() == 1) { viewSwitcher.setDisplayedChild(0); } else if (viewSwitcher.getDisplayedChild() == 0) { viewSwitcher.setDisplayedChild(1); } } }); messageText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { adapter.refresh(); } } }); String intentMessageText = getIntent().getStringExtra(getString(R.string.conversation_extra_message_text)); if (intentMessageText != null) { messageText.setText(intentMessageText); } boolean intentFocus = getIntent().getBooleanExtra(getString(R.string.conversation_extra_focus), false); if (intentFocus) { messageText.requestFocus(); } RelativeLayout messageSection = (RelativeLayout) findViewById(R.id.message_section); ViewCompat.setElevation(messageSection, 8); QuickContactBadge photo = (QuickContactBadge) findViewById(R.id.photo); Utils.applyCircularMask(photo); photo.assignContactFromPhone(preferences.getDid(), true); String photoUri = Utils.getContactPhotoUri(getApplicationContext(), preferences.getDid()); if (photoUri != null) { photo.setImageURI(Uri.parse(photoUri)); } else { photo.setImageToDefault(); } final ImageButton sendButton = (ImageButton) findViewById(R.id.send_button); Utils.applyCircularMask(sendButton); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { preSendMessage(); } }); }
From source file:de.schildbach.pte.AbstractNavitiaProvider.java
@Override public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException { final String nameCstr = constraint.toString(); final HttpUrl.Builder url = url().addPathSegment("places"); url.addQueryParameter("q", nameCstr); url.addQueryParameter("type[]", "stop_area"); url.addQueryParameter("type[]", "address"); url.addQueryParameter("type[]", "poi"); url.addQueryParameter("type[]", "administrative_region"); url.addQueryParameter("depth", "1"); final CharSequence page = httpClient.get(url.build()); try {/*from w ww .j av a2s. co m*/ final List<SuggestedLocation> locations = new ArrayList<>(); final JSONObject head = new JSONObject(page.toString()); if (head.has("places")) { final JSONArray places = head.getJSONArray("places"); for (int i = 0; i < places.length(); ++i) { final JSONObject place = places.getJSONObject(i); final int priority = place.optInt("quality", 0); // Add location to station list. final Location location = parseLocation(place); locations.add(new SuggestedLocation(location, priority)); } } final ResultHeader resultHeader = new ResultHeader(network, SERVER_PRODUCT, SERVER_VERSION, null, 0, null); return new SuggestLocationsResult(resultHeader, locations); } catch (final JSONException jsonExc) { throw new ParserException(jsonExc); } }
From source file:codemirror.eclipse.ui.utils.IOUtils.java
/** * Convert the specified CharSequence to an input stream, encoded as bytes * using the default character encoding of the platform. * * @param input the CharSequence to convert * @return an input stream//w ww .j av a 2s. co m * @since 2.0 */ public static InputStream toInputStream(CharSequence input) { return toInputStream(input.toString()); }
From source file:eu.faircode.netguard.AdapterRule.java
@Override public Filter getFilter() { return new Filter() { @Override/* w w w. j a va2 s .c o m*/ protected FilterResults performFiltering(CharSequence query) { List<Rule> listResult = new ArrayList<>(); if (query == null) listResult.addAll(listAll); else { query = query.toString().toLowerCase().trim(); int uid; try { uid = Integer.parseInt(query.toString()); } catch (NumberFormatException ignore) { uid = -1; } for (Rule rule : listAll) if (rule.info.applicationInfo.uid == uid || rule.info.packageName.toLowerCase().contains(query) || (rule.name != null && rule.name.toLowerCase().contains(query))) listResult.add(rule); } FilterResults result = new FilterResults(); result.values = listResult; result.count = listResult.size(); return result; } @Override protected void publishResults(CharSequence query, FilterResults result) { listFiltered.clear(); if (result == null) listFiltered.addAll(listAll); else { listFiltered.addAll((List<Rule>) result.values); if (listFiltered.size() == 1) listFiltered.get(0).expanded = true; } notifyDataSetChanged(); } }; }
From source file:de.schildbach.pte.AbstractNavitiaProvider.java
private String getStopAreaId(final String stopPointId) throws IOException { final HttpUrl.Builder url = url().addPathSegment("stop_points").addPathSegment(stopPointId); url.addQueryParameter("depth", "1"); final CharSequence page = httpClient.get(url.build()); try {//from w ww . j a v a 2 s .com final JSONObject head = new JSONObject(page.toString()); final JSONArray stopPoints = head.getJSONArray("stop_points"); final JSONObject stopPoint = stopPoints.getJSONObject(0); final JSONObject stopArea = stopPoint.getJSONObject("stop_area"); return stopArea.getString("id"); } catch (final JSONException jsonExc) { throw new ParserException(jsonExc); } }
From source file:com.example.android.cardreader.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.alternate_main_fragment); //TODO Stop Executing Eden //Globals.executeEden(); getUsers(1);/* www .j a v a 2 s . c om*/ instance = this; final ActionBar actionBar = getActionBar(); actionBar.setTitle(" TartanHacks"); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg)); actionBar.setStackedBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg)); actionBar.setDisplayShowHomeEnabled(true); frags.add(new PersonListFrag(Globals.pending)); frags.add(new PersonListFrag(Globals.allUsers)); frags.add(new PersonListFrag(Globals.checkedIn)); mAdapter = new FragmentAdapter(getFragmentManager()); fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View dialogView = View.inflate(instance, R.layout.dialog_signup, null); idField = (EditText) dialogView.findViewById(R.id.andrewIdField); pb = (ProgressBar) dialogView.findViewById(R.id.progress); nameField = (TextView) dialogView.findViewById(R.id.name); scanView = (TextView) dialogView.findViewById(R.id.scan_view); idField.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String id = s.toString(); pb.setVisibility(View.VISIBLE); queryId(id); } @Override public void afterTextChanged(Editable s) { } }); AlertDialog.Builder builder; builder = new AlertDialog.Builder(instance); builder.setView(dialogView); builder.setCancelable(true); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { Globals.adding = false; } }); signupDialog = builder.show(); } }); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setOffscreenPageLimit(0); mViewPager.setAdapter(mAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); actionBar.addTab(actionBar.newTab().setText("Pending").setTabListener(this)); actionBar.addTab(actionBar.newTab().setText("All").setTabListener(this)); actionBar.addTab(actionBar.newTab().setText("Checked In").setTabListener(this)); mLoyaltyCardReader = new LoyaltyCardReader(this); // Disable Android Beam and register our card reader callback enableReaderMode(); new UpdateThread().executeOnExecutor(Executors.newSingleThreadExecutor()); }
From source file:com.cyberway.issue.extractor.RegexpHTMLLinkExtractor.java
protected boolean processGeneralTag(CharSequence element, CharSequence cs) { Matcher attr = TextUtils.getMatcher(EACH_ATTRIBUTE_EXTRACTOR, cs); // Just in case it's an OBJECT or APPLET tag String codebase = null;/*from w w w . ja va 2 s . c o m*/ ArrayList<String> resources = null; long tally = next.size(); while (attr.find()) { int valueGroup = (attr.start(12) > -1) ? 12 : (attr.start(13) > -1) ? 13 : 14; int start = attr.start(valueGroup); int end = attr.end(valueGroup); CharSequence value = cs.subSequence(start, end); if (attr.start(2) > -1) { // HREF CharSequence context = Link.elementContext(element, attr.group(2)); if (element.toString().equalsIgnoreCase(LINK)) { // <LINK> elements treated as embeds (css, ico, etc) processEmbed(value, context); } else { if (element.toString().equalsIgnoreCase(BASE)) { try { base = UURIFactory.getInstance(value.toString()); } catch (URIException e) { extractErrorListener.noteExtractError(e, source, value); } } // other HREFs treated as links processLink(value, context); } } else if (attr.start(3) > -1) { // ACTION CharSequence context = Link.elementContext(element, attr.group(3)); processLink(value, context); } else if (attr.start(4) > -1) { // ON____ processScriptCode(value); // TODO: context? } else if (attr.start(5) > -1) { // SRC etc. CharSequence context = Link.elementContext(element, attr.group(5)); processEmbed(value, context); } else if (attr.start(6) > -1) { // CODEBASE // TODO: more HTML deescaping? codebase = TextUtils.replaceAll(ESCAPED_AMP, value, AMP); CharSequence context = Link.elementContext(element, attr.group(6)); processEmbed(codebase, context); } else if (attr.start(7) > -1) { // CLASSID, DATA if (resources == null) { resources = new ArrayList<String>(); } resources.add(value.toString()); } else if (attr.start(8) > -1) { // ARCHIVE if (resources == null) { resources = new ArrayList<String>(); } String[] multi = TextUtils.split(WHITESPACE, value); for (int i = 0; i < multi.length; i++) { resources.add(multi[i]); } } else if (attr.start(9) > -1) { // CODE if (resources == null) { resources = new ArrayList<String>(); } // If element is applet and code value does not end with // '.class' then append '.class' to the code value. if (element.toString().toLowerCase().equals(APPLET) && !value.toString().toLowerCase().endsWith(CLASSEXT)) { resources.add(value.toString() + CLASSEXT); } else { resources.add(value.toString()); } } else if (attr.start(10) > -1) { // VALUE if (TextUtils.matches(LIKELY_URI_PATH, value)) { CharSequence context = Link.elementContext(element, attr.group(10)); processLink(value, context); } } else if (attr.start(11) > -1) { // any other attribute // ignore for now // could probe for path- or script-looking strings, but // those should be vanishingly rare in other attributes, // and/or symptomatic of page bugs } } TextUtils.recycleMatcher(attr); // handle codebase/resources if (resources == null) { return (tally - next.size()) > 0; } Iterator iter = resources.iterator(); UURI codebaseURI = null; String res = null; try { if (codebase != null) { // TODO: Pass in the charset. codebaseURI = UURIFactory.getInstance(base, codebase); } while (iter.hasNext()) { res = iter.next().toString(); // TODO: more HTML deescaping? res = TextUtils.replaceAll(ESCAPED_AMP, res, AMP); if (codebaseURI != null) { res = codebaseURI.resolve(res).toString(); } processEmbed(res, element); // TODO: include attribute too } } catch (URIException e) { extractErrorListener.noteExtractError(e, source, codebase); } catch (IllegalArgumentException e) { DevUtils.logger.log(Level.WARNING, "processGeneralTag()\n" + "codebase=" + codebase + " res=" + res + "\n" + DevUtils.extraInfo(), e); } return (tally - next.size()) > 0; }
From source file:org.archive.modules.extractor.ExtractorHTML.java
/** * Handle generic HREF cases. * /*from ww w . j a v a 2 s . c o m*/ * @param curi * @param value * @param context */ protected void processLink(CrawlURI curi, final CharSequence value, CharSequence context) { if (TextUtils.matches(JAVASCRIPT, value)) { processScriptCode(curi, value.subSequence(11, value.length())); } else { if (logger.isLoggable(Level.FINEST)) { logger.finest("link: " + value.toString() + " from " + curi); } addLinkFromString(curi, value, context, Hop.NAVLINK); numberOfLinksExtracted.incrementAndGet(); } }