Tweak sample chooser
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=195511490
This commit is contained in:
parent
4e42c547ac
commit
17b4e020f4
@ -98,29 +98,22 @@ public class SampleChooserActivity extends Activity {
|
|||||||
}
|
}
|
||||||
ExpandableListView sampleList = findViewById(R.id.sample_list);
|
ExpandableListView sampleList = findViewById(R.id.sample_list);
|
||||||
sampleList.setAdapter(new SampleAdapter(this, groups));
|
sampleList.setAdapter(new SampleAdapter(this, groups));
|
||||||
sampleList.setOnChildClickListener(new OnChildClickListener() {
|
sampleList.setOnChildClickListener(
|
||||||
|
new OnChildClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onChildClick(ExpandableListView parent, View view, int groupPosition,
|
public boolean onChildClick(
|
||||||
int childPosition, long id) {
|
ExpandableListView parent, View view, int groupPosition, int childPosition, long id) {
|
||||||
onSampleSelected(groups.get(groupPosition).samples.get(childPosition));
|
onSampleClicked(groups.get(groupPosition).samples.get(childPosition));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSampleSelected(Sample sample) {
|
private void onSampleClicked(Sample sample) {
|
||||||
startActivity(sample.buildIntent(this));
|
startActivity(sample.buildIntent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSampleDownloadButtonClicked(Sample sample) {
|
private void onSampleDownloadButtonClicked(Sample sample) {
|
||||||
if (!(sample instanceof UriSample) || sample.drmInfo != null) {
|
|
||||||
Toast.makeText(
|
|
||||||
getApplicationContext(),
|
|
||||||
R.string.download_only_single_period_non_drm_protected,
|
|
||||||
Toast.LENGTH_SHORT)
|
|
||||||
.show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Intent intent = new Intent(this, DownloadActivity.class);
|
Intent intent = new Intent(this, DownloadActivity.class);
|
||||||
intent.putExtra(DownloadActivity.SAMPLE_NAME, sample.name);
|
intent.putExtra(DownloadActivity.SAMPLE_NAME, sample.name);
|
||||||
intent.putExtra(DownloadActivity.PLAYER_INTENT, sample.buildIntent(this));
|
intent.putExtra(DownloadActivity.PLAYER_INTENT, sample.buildIntent(this));
|
||||||
@ -198,7 +191,7 @@ public class SampleChooserActivity extends Activity {
|
|||||||
|
|
||||||
private Sample readEntry(JsonReader reader, boolean insidePlaylist) throws IOException {
|
private Sample readEntry(JsonReader reader, boolean insidePlaylist) throws IOException {
|
||||||
String sampleName = null;
|
String sampleName = null;
|
||||||
String uri = null;
|
Uri uri = null;
|
||||||
String extension = null;
|
String extension = null;
|
||||||
String drmScheme = null;
|
String drmScheme = null;
|
||||||
String drmLicenseUrl = null;
|
String drmLicenseUrl = null;
|
||||||
@ -217,7 +210,7 @@ public class SampleChooserActivity extends Activity {
|
|||||||
sampleName = reader.nextString();
|
sampleName = reader.nextString();
|
||||||
break;
|
break;
|
||||||
case "uri":
|
case "uri":
|
||||||
uri = reader.nextString();
|
uri = Uri.parse(reader.nextString());
|
||||||
break;
|
break;
|
||||||
case "extension":
|
case "extension":
|
||||||
extension = reader.nextString();
|
extension = reader.nextString();
|
||||||
@ -301,11 +294,10 @@ public class SampleChooserActivity extends Activity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class SampleAdapter extends BaseExpandableListAdapter {
|
private final class SampleAdapter extends BaseExpandableListAdapter implements OnClickListener {
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final List<SampleGroup> sampleGroups;
|
private final List<SampleGroup> sampleGroups;
|
||||||
private OnClickListener onClickListener;
|
|
||||||
|
|
||||||
public SampleAdapter(Context context, List<SampleGroup> sampleGroups) {
|
public SampleAdapter(Context context, List<SampleGroup> sampleGroups) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -328,6 +320,7 @@ public class SampleChooserActivity extends Activity {
|
|||||||
View view = convertView;
|
View view = convertView;
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = LayoutInflater.from(context).inflate(R.layout.sample_list_item, parent, false);
|
view = LayoutInflater.from(context).inflate(R.layout.sample_list_item, parent, false);
|
||||||
|
view.findViewById(R.id.download_button).setOnClickListener(this);
|
||||||
}
|
}
|
||||||
initializeChildView(view, getChild(groupPosition, childPosition));
|
initializeChildView(view, getChild(groupPosition, childPosition));
|
||||||
return view;
|
return view;
|
||||||
@ -375,27 +368,30 @@ public class SampleChooserActivity extends Activity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
onSampleDownloadButtonClicked((Sample) view.getTag());
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeChildView(View view, Sample sample) {
|
private void initializeChildView(View view, Sample sample) {
|
||||||
TextView sampleTitle = view.findViewById(R.id.sample_title);
|
TextView sampleTitle = view.findViewById(R.id.sample_title);
|
||||||
sampleTitle.setText(sample.name);
|
sampleTitle.setText(sample.name);
|
||||||
|
|
||||||
ImageButton downloadButton = view.findViewById(R.id.download_button);
|
ImageButton downloadButton = view.findViewById(R.id.download_button);
|
||||||
downloadButton.setFocusable(false);
|
|
||||||
downloadButton.setOnClickListener(getOnClickListener());
|
|
||||||
downloadButton.setTag(sample);
|
downloadButton.setTag(sample);
|
||||||
|
downloadButton.setColorFilter(0xFFBBBBBB);
|
||||||
|
downloadButton.setVisibility(canDownload(sample) ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnClickListener getOnClickListener() {
|
private boolean canDownload(Sample sample) {
|
||||||
if (onClickListener == null) {
|
if (!(sample instanceof UriSample)) {
|
||||||
onClickListener =
|
return false;
|
||||||
new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
onSampleDownloadButtonClicked((Sample) v.getTag());
|
|
||||||
}
|
}
|
||||||
};
|
UriSample uriSample = (UriSample) sample;
|
||||||
|
if (uriSample.drmInfo != null || uriSample.adTagUri != null) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return onClickListener;
|
String scheme = uriSample.uri.getScheme();
|
||||||
|
return "http".equals(scheme) || "https".equals(scheme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +461,7 @@ public class SampleChooserActivity extends Activity {
|
|||||||
|
|
||||||
private static final class UriSample extends Sample {
|
private static final class UriSample extends Sample {
|
||||||
|
|
||||||
public final String uri;
|
public final Uri uri;
|
||||||
public final String extension;
|
public final String extension;
|
||||||
public final String adTagUri;
|
public final String adTagUri;
|
||||||
|
|
||||||
@ -474,7 +470,7 @@ public class SampleChooserActivity extends Activity {
|
|||||||
boolean preferExtensionDecoders,
|
boolean preferExtensionDecoders,
|
||||||
String abrAlgorithm,
|
String abrAlgorithm,
|
||||||
DrmInfo drmInfo,
|
DrmInfo drmInfo,
|
||||||
String uri,
|
Uri uri,
|
||||||
String extension,
|
String extension,
|
||||||
String adTagUri) {
|
String adTagUri) {
|
||||||
super(name, preferExtensionDecoders, abrAlgorithm, drmInfo);
|
super(name, preferExtensionDecoders, abrAlgorithm, drmInfo);
|
||||||
@ -486,7 +482,7 @@ public class SampleChooserActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public Intent buildIntent(Context context) {
|
public Intent buildIntent(Context context) {
|
||||||
return super.buildIntent(context)
|
return super.buildIntent(context)
|
||||||
.setData(Uri.parse(uri))
|
.setData(uri)
|
||||||
.putExtra(PlayerActivity.EXTENSION_EXTRA, extension)
|
.putExtra(PlayerActivity.EXTENSION_EXTRA, extension)
|
||||||
.putExtra(PlayerActivity.AD_TAG_URI_EXTRA, adTagUri)
|
.putExtra(PlayerActivity.AD_TAG_URI_EXTRA, adTagUri)
|
||||||
.setAction(PlayerActivity.ACTION_VIEW);
|
.setAction(PlayerActivity.ACTION_VIEW);
|
||||||
@ -510,7 +506,7 @@ public class SampleChooserActivity extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Intent buildIntent(Context context) {
|
public Intent buildIntent(Context context) {
|
||||||
String[] uris = new String[children.length];
|
Uri[] uris = new Uri[children.length];
|
||||||
String[] extensions = new String[children.length];
|
String[] extensions = new String[children.length];
|
||||||
for (int i = 0; i < children.length; i++) {
|
for (int i = 0; i < children.length; i++) {
|
||||||
uris[i] = children[i].uri;
|
uris[i] = children[i].uri;
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 551 B |
Binary file not shown.
After Width: | Height: | Size: 388 B |
Binary file not shown.
After Width: | Height: | Size: 691 B |
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
@ -1,19 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!-- Copyright (C) 2017 The Android Open Source Project
|
||||||
~ Copyright (C) 2017 The Android Open Source Project
|
|
||||||
~
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
you may not use this file except in compliance with the License.
|
||||||
~ you may not use this file except in compliance with the License.
|
You may obtain a copy of the License at
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
Unless required by applicable law or agreed to in writing, software
|
||||||
~ Unless required by applicable law or agreed to in writing, software
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
See the License for the specific language governing permissions and
|
||||||
~ See the License for the specific language governing permissions and
|
limitations under the License.
|
||||||
~ limitations under the License.
|
-->
|
||||||
-->
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/activity_downloader"
|
android:id="@+id/activity_downloader"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -1,30 +1,27 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!-- Copyright (C) 2018 The Android Open Source Project
|
||||||
~ Copyright (C) 2018 The Android Open Source Project
|
|
||||||
~
|
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
~ you may not use this file except in compliance with the License.
|
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing, software
|
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
~ See the License for the specific language governing permissions and
|
|
||||||
~ limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="12dip"
|
android:paddingStart="12dp"
|
||||||
android:paddingEnd="12dip"
|
android:paddingEnd="12dp"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView android:id="@+id/sample_title"
|
||||||
android:id="@+id/sample_title"
|
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
@ -32,12 +29,11 @@
|
|||||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||||
android:textAppearance="?android:attr/textAppearanceListItemSmall"/>
|
android:textAppearance="?android:attr/textAppearanceListItemSmall"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton android:id="@+id/download_button"
|
||||||
android:id="@+id/download_button"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="35dip"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:contentDescription="@string/exo_download_description"
|
android:contentDescription="@string/exo_download_description"
|
||||||
android:gravity="center_vertical"
|
android:background="@android:color/transparent"
|
||||||
android:src="@android:drawable/stat_sys_download"/>
|
android:src="@drawable/ic_offline_pin_white_36dp"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -51,6 +51,4 @@
|
|||||||
|
|
||||||
<string name="download_remove_all">Remove all</string>
|
<string name="download_remove_all">Remove all</string>
|
||||||
|
|
||||||
<string name="download_only_single_period_non_drm_protected">Currently only downloading of single period non-DRM protected content is demonstrated in this app.</string>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user