定期循环访问多个CardBuilder视图

时间:2015-01-25 01:44:34

标签: android google-glass google-gdk

我所在的学校企业正在研究Google Glass对驾驶员分心的影响。为此,我们一直在使用Stroop效果 - http://en.wikipedia.org/wiki/Stroop_effect

到目前为止,我们一直在使用CardScrollView让我们的参与者在使用驾驶模拟器的同时刷卡多张卡片。问题是必须每次刷卡太分散注意力。

理想情况下,我们希望在几秒左右的设定时间内显示每个视图,然后切换到下一个视图。

我整天都在网上搜索,并尝试了很多不同的配置,这在理论上可以起作用,但我还没有成功。

这是我最近一直在使用的课程。我从主活动函数onResume()调用run。

package com.google.android.glass.sample.apidemo;
import android.app.Activity;
import android.content.Context;
import android.os.SystemClock;
import com.google.android.glass.widget.CardBuilder;
import java.lang.Runnable;
import java.util.ArrayList;

public class StroopCycle implements Runnable {
private Activity mActivity;
private ArrayList<CardBuilder> cards = new ArrayList<CardBuilder>();

public StroopCycle(Activity act){
    mActivity = act;

    cards.add(createCard(mActivity, R.drawable.one));
    cards.add(createCard(mActivity, R.drawable.two));
    cards.add(createCard(mActivity, R.drawable.three));
    cards.add(createCard(mActivity, R.drawable.four));
    cards.add(createCard(mActivity, R.drawable.five));
    cards.add(createCard(mActivity, R.drawable.six));
    cards.add(createCard(mActivity, R.drawable.seven));
    cards.add(createCard(mActivity, R.drawable.eight));
    cards.add(createCard(mActivity, R.drawable.nine));
    cards.add(createCard(mActivity, R.drawable.ten));
    cards.add(createCard(mActivity, R.drawable.eleven));
    cards.add(createCard(mActivity, R.drawable.twelve));
    cards.add(createCard(mActivity, R.drawable.thirteen));
    cards.add(createCard(mActivity, R.drawable.fourteen));
    cards.add(createCard(mActivity, R.drawable.fifteen));
    cards.add(createCard(mActivity, R.drawable.sixteen));
    cards.add(createCard(mActivity, R.drawable.seventeen));
    cards.add(createCard(mActivity, R.drawable.eighteen));
    cards.add(createCard(mActivity, R.drawable.nineteen));
    cards.add(createCard(mActivity, R.drawable.twenty));
}

@Override
public void run() {
    for(int j = 0; j < cards.size(); j++){
        mActivity.setContentView(cards.get(j).getView());
        SystemClock.sleep(1000);
        if (j == cards.size() - 1){
            j = 0;
        }
    }
}

private static CardBuilder createCard(Context context, int drawable) {
    return new CardBuilder(context, CardBuilder.Layout.TITLE)
            .addImage(drawable);
}
}

任何帮助都会受到赞赏!

谢谢。

1 个答案:

答案 0 :(得分:0)

一种解决方案是使用CardScrollView备份CardScrollAdapter 您将在official documentation website上找到一个示例 然后,要更改卡片,请使用animate(int position, Animation animationType)setSelection(int position)