Skip to content

Instantly share code, notes, and snippets.

View pedrofelipemm's full-sized avatar

Pedro Felipe Marques Moreira pedrofelipemm

  • CI&T
  • Campinas - Brazil
View GitHub Profile
package com.firebase.utils;
import java.util.Date;
/**
* Fancy ID generator that creates 20-character string identifiers with the
* following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't
@pedrofelipemm
pedrofelipemm / generate-pushid.js
Created July 30, 2017 00:43 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
PendingIntent pendingIntent = TaskStackBuilder.create(context)
.addNextIntentWithParentStack(new Intent(context, MainActivity.class))
.addNextIntent(new Intent(context, DetailActivity.class))
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_stocks);
@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);