3

I have a Google Glass application which publishes a pair of live cards. When I click these cards it takes me into the UI for the Activity. What I'd like to do is intercept this click on one of the cards, and rather than change the view to the Activities layout, I'd like to do some actions (cause some background code to run and update the other live card).

I don't see any click listeners for Cards. Is there a way to do this?

Edit::: For Clarification. Here is a very simple example of what I might want to try and do. This doesn't work because LiveCards don't accept clickListeners...

package com.example.exampleglasslivecardselection;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.widget.RemoteViews;

import com.google.android.glass.timeline.LiveCard;
import com.google.android.glass.timeline.TimelineManager;

public class MainActivity extends Activity {
    LiveCard card1;
    LiveCard card2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


            if (card1 == null && card2 == null) {
                String cardId = "card1";
                TimelineManager tm = TimelineManager.from(this);

                // set up card 1 and publish
                card1 = tm.getLiveCard(cardId);
                RemoteViews views = new RemoteViews(this.getPackageName(),
                        R.layout.card1_page);
                Intent intent = new Intent(this, MainActivity.class);
                card1.setAction(PendingIntent.getActivity(this, 0,
                        intent, 0));

                card1.publish();


                // set up card 2 and publish
                card2 = tm.getLiveCard(cardId);
                RemoteViews views2 = new RemoteViews(this.getPackageName(),
                        R.layout.card2_page);
                Intent twoIntent = new Intent(this, MainActivity.class);
                card2.setAction(PendingIntent.getActivity(this, 0,
                        intent, 0));


                // set up a click listener or something...(THIS DOESN"T WORK, how would I do this?)
                card2.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // do stuff to card 1...
                        card1.setViews(someNewVewis);
                        // TODO Auto-generated method stub

                    }   

                }
                card2.publish();
            }
        } 
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }



}
Nathaniel D. Waggoner
  • 2,856
  • 2
  • 19
  • 41
  • You can write some code before before Activity starts, in *onCreate* and then show UI. Can you show some code, to be more specific. – sigrlami Dec 07 '13 at 20:09
  • I don't really understand what your comment is saying Sigrlami, up until the request for code. – Nathaniel D. Waggoner Dec 07 '13 at 20:21
  • I meant that your cards will lead to some remote UI, which is part of Android SDK, in that remote UI you can first run your code and then show UI in method onCreate. On the other hand you can create some dispatch class (intermediate layer), which will handle arguments from Intent and make what you want. – sigrlami Dec 07 '13 at 20:40
  • I don't want to divert the user from the timeline. I also don't want to FORCE the user to look at my new UI. I simply want to update card1 when the user selects card2. – Nathaniel D. Waggoner Dec 07 '13 at 20:45
  • I don't see any events or other actions being fired that I can latch onto when a Card is selected from the timeline. – Nathaniel D. Waggoner Dec 07 '13 at 20:46
  • ok, now I get it. I thought you want to update both Activity and LiveCard. I think you need bind *Service* to your LiveCard1 which will be notified, when you click on LiveCard2. – sigrlami Dec 07 '13 at 21:02
  • https://github.com/harrywye/gdkdemo/blob/master/apidemo/livecarddemo2/src/main/java/com/gdkdemo/livecard2/service/LiveCardDemoLocalService.java – sigrlami Dec 07 '13 at 21:02

1 Answers1

2

Keep in mind that an activity does not have to have a UI associated with it — you can have your LiveCard's action go to an activity that executes some code in its onCreate method, never calls setContentView, and then calls finish to end the activity. This would probably give you the functionality you want.

However, consider the effect this would have on the user experience. Live cards have two kinds of interaction right now — a bundle, which lets the user drill deeper into a card scroller when clicked (these are usually indicated by a "folded page corner" at the top-right of the card); or an options menu that appears when the card is tapped. At the very least, you should provide a menu with an option to let the user remove the card from their timeline when they tap it.

Tony Allevato
  • 6,429
  • 1
  • 29
  • 34
  • My use case is fairly specific. We're looking at using glass as an enterprise solution for data display, and the average user would not have the ability to show/hide tools which were made available. I agree with your points in terms of commercial apps, but for our purposes disallowing user control at this level is actually desirable. – Nathaniel D. Waggoner Dec 11 '13 at 18:04