Search code examples
javaandroidgoogle-glassgoogle-gdk

mSlider.startIndeterminate() not working


I'm switching to the Slider API for indeterminate progress bars. I'm following this tutorial. Everything works, except the fact the indeterminate progress bar doesn't appear.

The end result is supposed to look something like this:

gif from google glass developement page

Here is the activity that fetches some videos, while an indeterminate slider is shown waiting for the results.

public class SearchActivity extends Activity {
    //...
    private Slider.Indeterminate mIndeterminate;
    private CardScrollView mCardScroller;
    private Slider mSlider;

    @Override
    protected void onCreate(Bundle bundle){
        super.onCreate(bundle);

        keyword = (String)getIntent().getSerializableExtra("keywords");
        mCardScroller = new CardScrollView(this);
        mCardScroller.setAdapter(new CardAdapter(createCards(this)));
        mSlider = Slider.from(mCardScroller);
        setContentView(mCardScroller);
        new LoadAllVideos().execute();
    }
    private ArrayList<CardBuilder> createCards(Context context){
        ArrayList<CardBuilder> cards = new ArrayList<>();
        cards.add(new CardBuilder(context, CardBuilder.Layout.MENU)
              .setText("Loading...")
              .setIcon(R.drawable.ic_launcher));
        return cards;
    }
        //...
}

In my LoadAllVideos (that extends AsyncTask ..) I have

@Override
protected void onPreExecute(){
    super.onPreExecute();
    Log.w("progressbar", "start");
    mIndeterminate = mSlider.startIndeterminate();
}

and

@Override
protected void onPostExecute(String url){
    Log.w("progressbar", "stop");
    mIndeterminate.hide();
    Intent res = new Intent(SearchActivity.this, ResultActivity.class);
    res.putExtra("videos", videos);
    startActivity(res);
    finish();
}

What could I be doing wrong?


Solution

  • The Slider API relies on the View you used when initializing it to be VISIBLE so that it can properly recycle sliders that were started from Views that got hidden.

    Could you try starting your load video task in the onResume callback instead of onCreate? At that point the CardScrolLView you're using should have been attached to a Window and be rendered VISIBLE.