Prevent a Demo app NPE on Android TV

The options menu is not available on Android TV, which triggers a
null pointer exception whenever a sample is chosen.

This CL is a temporary fix until we rework the UI to not use
an options menu.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209742076
This commit is contained in:
aquilescanta 2018-08-22 03:41:18 -07:00 committed by Oliver Woodman
parent afebd60ee4
commit 8927993b03

View file

@ -22,6 +22,7 @@ import android.content.res.AssetManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.JsonReader;
import android.util.Log;
import android.view.Menu;
@ -162,8 +163,8 @@ public class SampleChooserActivity extends Activity
startActivity(
sample.buildIntent(
/* context= */ this,
preferExtensionDecodersMenuItem.isChecked(),
randomAbrMenuItem.isChecked()
isNonNullAndChecked(preferExtensionDecodersMenuItem),
isNonNullAndChecked(randomAbrMenuItem)
? PlayerActivity.ABR_ALGORITHM_RANDOM
: PlayerActivity.ABR_ALGORITHM_DEFAULT));
return true;
@ -198,6 +199,11 @@ public class SampleChooserActivity extends Activity
return 0;
}
private static boolean isNonNullAndChecked(@Nullable MenuItem menuItem) {
// Temporary workaround for layouts that do not inflate the options menu.
return menuItem != null && menuItem.isChecked();
}
private final class SampleListLoader extends AsyncTask<String, Void, List<SampleGroup>> {
private boolean sawError;