Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onReceive(Context context, Intent intent) {
- AppWidgetManager mgr = AppWidgetManager.getInstance(context);
- if (intent.getAction().equals(OPEN_DETAILS)) {
- //We receive the Id of item which has been clicked
- int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
- int viewIndex = intent.getIntExtra(EXTRA_ITEM, 0);
- Toast.makeText(context, "Touched view " + viewIndex, Toast.LENGTH_SHORT).show();
- // Now, we want receive all information of the item : titre, url, description, ...
- // ????
- // ????
- //And after, we want to start an activity with all information of the item which has been clicked and print them in the activity
- Intent DetailDeal = new Intent(Intent.ACTION_VIEW);
- DetailDeal.setClassName("com.example.android.stackwidget", "com.example.android.stackwidget.AddDealActivity");
- DetailDeal.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(DetailDeal);
- }
- super.onReceive(context, intent);
- }
- @Override
- public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
- // update each of the widgets with the remote adapter
- for (int i = 0; i < appWidgetIds.length; ++i) {
- // Here we setup the intent which points to the StackViewService which will
- // provide the views for this collection.
- Intent intent = new Intent(context, StackWidgetService.class);
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
- // When intents are compared, the extras are ignored, so we need to embed the extras
- // into the data so that the extras will not be ignored.
- intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
- RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout_white_theme);
- rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_view, intent);
- // The empty view is displayed when the collection has no items. It should be a sibling
- // of the collection view.
- rv.setEmptyView(R.id.stack_view, R.id.empty_view);
- // Here we setup the a pending intent template. Individuals items of a collection
- // cannot setup their own pending intents, instead, the collection as a whole can
- // setup a pending intent template, and the individual items can set a fillInIntent
- // to create unique before on an item to item basis.
- Intent toastIntent = new Intent(context, StackWidgetProvider.class);
- toastIntent.setAction(StackWidgetProvider.OPEN_DETAILS);
- toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
- intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
- PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- rv.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent);
- appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
- }
- super.onUpdate(context, appWidgetManager, appWidgetIds);
- }
- public RemoteViews getViewAt(int position) {
- // position will always range from 0 to getCount() - 1.
- // We construct a remote views item based on our widget item xml file, and set the
- // text based on the position.
- WidgetItem item = mWidgetItems.get(position);
- // We construct a remote views item based on our widget item xml file, and set the
- // text based on the position.
- RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item_white_theme);
- rv.setTextViewText(R.id.titre, item.titre);
- rv.setTextViewText(R.id.description, item.description);
- rv.setTextViewText(R.id.url, "@"+item.site.toString());
- rv.setTextViewText(R.id.ancienprix, item.ancienprix);
- rv.setTextViewText(R.id.nouveauprix, item.nouveauPrix);
- //On barre l'ancien prix
- rv.setInt(R.id.ancienprix, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
- //On positionne la bande à gauche de l'item. Verte si le deal est encore actif, rouge sinon
- rv.setInt(R.id.dealtermine, "setBackgroundColor", item.dealTermine ? android.graphics.Color.rgb(204, 0, 0) : android.graphics.Color.rgb(102, 153, 0));
- //On positionne l'image de l'item suivant le degré du deal
- if (item.qualite == "chaud") { //C'est un très bon deal
- rv.setImageViewResource(R.id.img, R.drawable.ic_action_lab_black);
- }
- else if (item.qualite == "moyen") { //c'est un deal moyen
- rv.setImageViewResource(R.id.img, R.drawable.ic_action_lab_red);
- }
- else if (item.qualite == "froid") { //c'est un deal bof
- rv.setImageViewResource(R.id.img, R.drawable.ic_action_lab_green);
- }
- // Next, we set a fill-intent which will be used to fill-in the pending intent template
- // which is set on the collection view in StackWidgetProvider.
- Bundle extras = new Bundle();
- extras.putInt(StackWidgetProvider.EXTRA_ITEM, position);
- Intent fillInIntent = new Intent();
- fillInIntent.putExtras(extras);
- rv.setOnClickFillInIntent(R.id.group_layout, fillInIntent);
- // You can do heaving lifting in here, synchronously. For example, if you need to
- // process an image, fetch something from the network, etc., it is ok to do it here,
- // synchronously. A loading view will show up in lieu of the actual contents in the
- // interim.
- try {
- System.out.println("Loading view " + position);
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- // Return the remote views object.
- return rv;
- }
Add Comment
Please, Sign In to add comment