关于Rajawali Vuforia例子的进展对话

时间:2013-12-19 06:02:57

标签: progressdialog vuforia rajawali

加载.obj模型时可以显示进度对话框。我试图在RajawaliVuforiaExampleRenderer.java中调用ProgressDialog,但它说“无法在未调用Looper.prepare()的线程内创建处理程序”

我在这里粘贴了部分代码:

protected void initScene(){

    mLight = new DirectionalLight(.1f, 0, -1.0f);
    mLight.setColor(1.0f, 0, 0);
    mLight.setPower(1);

    getCurrentScene().addLight(mLight);

    LoaderOBJ objParser = new LoaderOBJ(mContext.getResources(),
            mTextureManager, R.raw.wall_obj);

    try {
        // Load model
        objParser.parse();
        wall = objParser.getParsedObject();
        addChild(wall);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

EDITED: 我已经阅读了Abhishek Agarwal的评论并更新了Renderer部分的代码,现在我在加载模型时调用ProgressDialog时出现问题,这是我的UI线程代码。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    // receive file path
    String filePath = this.getIntent().getStringExtra("FullFilePath");
    Log.i(filePath, "FullFilePath:" + filePath);

    waitDialog = ProgressDialog.show(this, "", "Loading", true);
    waitDialog.show();
    new ModelLoader().execute();

}

@Override
protected void setupTracker() {
    int result = initTracker(TRACKER_TYPE_MARKER);
    if (result == 1) {
        result = initTracker(TRACKER_TYPE_IMAGE);
        if (result == 1) {
            super.setupTracker();
        } else {RajLog.e("Couldn't initialize image tracker.");
        }
    } else {
        RajLog.e("Couldn't initialize marker tracker.");
    }}

protected void initApplicationAR() {
    super.initApplicationAR();
    createImageMarker("marker.xml");
}

protected void initRajawali() {
    super.initRajawali();
    mRenderer = new ModelRenderer(this);
    mRenderer.setSurfaceView(mSurfaceView);
    super.setRenderer(mRenderer);

    mUILayout = this;
    mUILayout.setContentView(mLayout, new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}

private class ModelLoader extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {
        startVuforia();
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        waitDialog.dismiss();
    }
}

2 个答案:

答案 0 :(得分:1)

进度对话框可以显示在 UIThread 上。因此,在GLThread

下的主线程上显示进度对话框

答案 1 :(得分:0)

您可以在HandUI上使用Handler:

`private Handler mHandler = new Handler();
...
mHandler.post(new Runnable() {
        @Override
        public void run() {
            view_progressBar.setProgress(val);
        }
    });`