Created
April 21, 2017 12:45
-
-
Save pedrofelipemm/943fb4ec302394c37f191620e6cf96e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public RemoteViews getViewAt(int position) { | |
if (position == AdapterView.INVALID_POSITION || data == null || !data.moveToPosition(position)) { | |
return null; | |
} | |
String symbol = data.getString(Quote.POSITION_SYMBOL); | |
String price = CurrencyUtils.formatDollar(data.getDouble(Quote.POSITION_PRICE)); | |
double changeDouble = data.getDouble(Quote.POSITION_PERCENTAGE_CHANGE); | |
String change = CurrencyUtils.formatDollarWithPlus(changeDouble); | |
Intent fillInIntent = new Intent(); | |
intent.putExtra(EXTRA_SYMBOL, symbol); | |
intent.putExtra(EXTRA_PRICE, price); | |
intent.putExtra(EXTRA_CHANGE, change); | |
RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget_stocks_item); | |
views.setTextViewText(R.id.widget_symbol, symbol); | |
views.setTextViewText(R.id.widget_price, price); | |
views.setTextViewText(R.id.widget_change, change); | |
views.setInt(R.id.change, "setBackgroundResource", | |
changeDouble > 0 ? R.drawable.percent_change_pill_green : R.drawable.percent_change_pill_red); | |
views.setOnClickFillInIntent(R.id.widget_list_item, fillInIntent); | |
return views; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment