Search code examples
google-glassgoogle-gdk

Going from a high-frequency livecard to an immersion (an activity)


I'm trying to convert the GDK sample compass project (https://developers.google.com/glass/samples/gdk) from using a Livecard base to an immersion / activity base. Some changes I've made include the following:

  • CompassRenderer implements SurfaceHolder.Callback rather than DirectRenderingCallback
  • CompassView extends SurfaceView rather than View
  • Removed CompassService.java
  • Created CompassMain.java which extends Activity
    • the onCreate is almost identical
    • the onStarts look like the following code samples

Anyone have any insight?


CompassMain.java

@Override
public void onStart(){

    super.onStart();

    // make view visible
    setContentView(R.layout.compass);

    // create renderer
    CompassRenderer mRenderer = new CompassRenderer(this, mOrientationManager, mLandmarks);

    // get handle to the surface view made visible above
    CompassView surfaceView = (CompassView) findViewById(R.id.compass);

    // magic
    surfaceView.getHolder().addCallback(mRenderer);

    // ensure the screen stays on
    surfaceView.setKeepScreenOn(true);
}  

CompassService.java

@Override  
public int onStartCommand(Intent intent, int flags, int startId) {
    if (mLiveCard == null) {
        mLiveCard = new LiveCard(this, LIVE_CARD_ID);
        CompassRenderer mRenderer = new CompassRenderer(this, mOrientationManager, mLandmarks);
        mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mRenderer);

        // Display specific card scroll view based on orientation
        Intent menuIntent = new Intent(this, CompassMenuActivity.class);
        menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));

        mLiveCard.attach(this);
        mLiveCard.publish(PublishMode.REVEAL);
    } else {
        mLiveCard.navigate();
    }
    return START_STICKY;
}

Solution

  • I got it working. Here are the additional changes I made:

    • Changed the onStart() within my main activity while adding an argument to the CompassRenderer constructor
    • Changed the CompassRenderer constructor's body

    CompassMain.java

    @Override  
    public void onStart(){
        super.onStart();
    
        // show the view and create the 
        setContentView(R.layout.compass);
    
        CompassView compassView = (CompassView) findViewById(R.id.compass);
    
        CompassRenderer mRenderer = new CompassRenderer(this, mOrientationManager, mLandmarks, compassView);
    
        compassView.setWillNotDraw(false);
    
        compassView.setKeepScreenOn(true);
    
        compassView.getHolder().addCallback(mRenderer);
    }
    

    CompassRenderer.java

    public CompassRenderer(Context context, OrientationManager orientationManager, Landmarks landmarks, CompassView compassView) {
            LayoutInflater inflater = LayoutInflater.from(context);
            mLayout = (FrameLayout) inflater.inflate(R.layout.compass, null);
            mCompassView = compassView;
            mOrientationManager = orientationManager;
            mLandmarks = landmarks;
            mCompassView.setOrientationManager(mOrientationManager);
        }