@Override public void bindViewHolder(ViewHolder holder, int position) { Site place = mData.get(position); String title = place.getName(); String subtitle = place.getLocality(); boolean isTransitStop = place.isTransitStop(); // Use this for adding an astrix for google places results and to show attribution at the end. // title = title + "*"; // CharacterStyle colorStyle = new // ForegroundColorSpan(mContext.getResources().getColor(R.color.body_text_2)); // CharacterStyle fontSize = new RelativeSizeSpan(0.8f); // CharacterStyle superScript = new SuperscriptSpan(); // CharSequence entryTitle = SpanUtils.createSpannable(title, // Pattern.compile("\\*"), colorStyle, fontSize, superScript); // ViewHelper.setText(holder.text1, entryTitle); ViewHelper.setText(holder.text1, title); if (subtitle != null) { ViewHelper.setText(holder.text2, subtitle); holder.text2.setVisibility(View.VISIBLE); } else { holder.text2.setVisibility(View.GONE); } if (place.hasType()) { if (place.isTransitStop()) { holder.icon.setImageResource(R.drawable.ic_transport_transit_20dp); } else { holder.icon.setImageResource(R.drawable.ic_place_24dp); // holder.icon.setImageResource(R.drawable.ic_transport_bus_24dp); } } else { holder.icon.setImageResource(R.drawable.ic_history_24dp); } ViewHelper.tint(holder.icon, holder.icon.getResources().getColor(R.color.icon_default)); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.place_search_layout); registerScreen("Place Search"); Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey(ARG_ONLY_STOPS)) { mSearchOnlyStops = extras.getBoolean(ARG_ONLY_STOPS); } } initGoogleApiClient(false); createSearchHandler(); if (savedInstanceState != null) { if (savedInstanceState.containsKey(STATE_SEARCH_FILTER)) { mCurrentSearchFilterType = savedInstanceState.getInt(STATE_SEARCH_FILTER); } } mHistoryDbAdapter = new HistoryDbAdapter(this).open(); ImageButton backButton = (ImageButton) findViewById(R.id.search_back); ViewHelper.tint(backButton, ContextCompat.getColor(this, R.color.primary_dark)); ViewHelper.flipIfRtl(backButton); backButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); mSearchEdit = (EditText) findViewById(R.id.search_edit); mSearchEdit.setOnEditorActionListener( new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { mSearchResultAdapter.getFilter().filter(mSearchEdit.getText()); } return false; } }); mSearchEdit.requestFocus(); mClearButton = (ImageButton) findViewById(R.id.search_clear); ViewHelper.tintIcon(mClearButton.getDrawable(), Color.GRAY); mClearButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mSearchEdit.setText(""); mSearchResultAdapter.clear(); } }); mSearchFailed = findViewById(R.id.search_result_error); mProgressBar = (ContentLoadingProgressBar) findViewById(R.id.search_progress_bar); setupHistoryViews(); if (!mSearchOnlyStops) { getSupportLoaderManager().initLoader(LOADER_HISTORY, null, this); } setupSearchResultViews(); if (!shouldSearchGooglePlaces()) { setSearchFilter(FILTER_TYPE_STHLM_TRAVELING); } mMyLocationManager = new LocationManager(this, getGoogleApiClient()); mMyLocationManager.setLocationListener(this); mMyLocationManager.setAccuracy(false); registerPlayService(mMyLocationManager); if (!mSearchOnlyStops) { verifyLocationPermission(); mMyLocationManager.requestLocation(); } }