从高频真人卡到沉浸式(活动)

时间:2014-06-24 18:34:47

标签: google-glass google-gdk

我正在尝试将GDK示例罗盘项目(https://developers.google.com/glass/samples/gdk)从使用Livecard基础转换为沉浸/活动基础。我所做的一些更改包括以下内容:

  • CompassRenderer实现SurfaceHolder.Callback而不是DirectRenderingCallback
  • CompassView扩展了SurfaceView而不是View
  • 删除了CompassService.java
  • 创建扩展Activity的CompassMain.java
    • onCreate几乎相同
    • onStarts看起来像以下代码示例

任何人都有见解?


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

1 个答案:

答案 0 :(得分:2)

我得到了它的工作。以下是我所做的其他更改:

  • 在向CompassRenderer构造函数添加参数的同时更改了我的主要活动中的onStart()
  • 更改了CompassRenderer构造函数的正文

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