Commit 8927993b by aquilescanta Committed by Oliver Woodman

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
parent afebd60e
...@@ -22,6 +22,7 @@ import android.content.res.AssetManager; ...@@ -22,6 +22,7 @@ import android.content.res.AssetManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.JsonReader; import android.util.JsonReader;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
...@@ -162,8 +163,8 @@ public class SampleChooserActivity extends Activity ...@@ -162,8 +163,8 @@ public class SampleChooserActivity extends Activity
startActivity( startActivity(
sample.buildIntent( sample.buildIntent(
/* context= */ this, /* context= */ this,
preferExtensionDecodersMenuItem.isChecked(), isNonNullAndChecked(preferExtensionDecodersMenuItem),
randomAbrMenuItem.isChecked() isNonNullAndChecked(randomAbrMenuItem)
? PlayerActivity.ABR_ALGORITHM_RANDOM ? PlayerActivity.ABR_ALGORITHM_RANDOM
: PlayerActivity.ABR_ALGORITHM_DEFAULT)); : PlayerActivity.ABR_ALGORITHM_DEFAULT));
return true; return true;
...@@ -198,6 +199,11 @@ public class SampleChooserActivity extends Activity ...@@ -198,6 +199,11 @@ public class SampleChooserActivity extends Activity
return 0; 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 final class SampleListLoader extends AsyncTask<String, Void, List<SampleGroup>> {
private boolean sawError; private boolean sawError;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment