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;
}
}