Tweak sample chooser

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=195511490
This commit is contained in:
olly 2018-05-04 20:45:16 -07:00 committed by Oliver Woodman
parent 4e42c547ac
commit 17b4e020f4
9 changed files with 68 additions and 79 deletions

View File

@ -98,29 +98,22 @@ public class SampleChooserActivity extends Activity {
}
ExpandableListView sampleList = findViewById(R.id.sample_list);
sampleList.setAdapter(new SampleAdapter(this, groups));
sampleList.setOnChildClickListener(new OnChildClickListener() {
sampleList.setOnChildClickListener(
new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View view, int groupPosition,
int childPosition, long id) {
onSampleSelected(groups.get(groupPosition).samples.get(childPosition));
public boolean onChildClick(
ExpandableListView parent, View view, int groupPosition, int childPosition, long id) {
onSampleClicked(groups.get(groupPosition).samples.get(childPosition));
return true;
}
});
}
private void onSampleSelected(Sample sample) {
private void onSampleClicked(Sample sample) {
startActivity(sample.buildIntent(this));
}
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.putExtra(DownloadActivity.SAMPLE_NAME, sample.name);
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 {
String sampleName = null;
String uri = null;
Uri uri = null;
String extension = null;
String drmScheme = null;
String drmLicenseUrl = null;
@ -217,7 +210,7 @@ public class SampleChooserActivity extends Activity {
sampleName = reader.nextString();
break;
case "uri":
uri = reader.nextString();
uri = Uri.parse(reader.nextString());
break;
case "extension":
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 List<SampleGroup> sampleGroups;
private OnClickListener onClickListener;
public SampleAdapter(Context context, List<SampleGroup> sampleGroups) {
this.context = context;
@ -328,6 +320,7 @@ public class SampleChooserActivity extends Activity {
View view = convertView;
if (view == null) {
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));
return view;
@ -375,27 +368,30 @@ public class SampleChooserActivity extends Activity {
return true;
}
@Override
public void onClick(View view) {
onSampleDownloadButtonClicked((Sample) view.getTag());
}
private void initializeChildView(View view, Sample sample) {
TextView sampleTitle = view.findViewById(R.id.sample_title);
sampleTitle.setText(sample.name);
ImageButton downloadButton = view.findViewById(R.id.download_button);
downloadButton.setFocusable(false);
downloadButton.setOnClickListener(getOnClickListener());
downloadButton.setTag(sample);
downloadButton.setColorFilter(0xFFBBBBBB);
downloadButton.setVisibility(canDownload(sample) ? View.VISIBLE : View.GONE);
}
private OnClickListener getOnClickListener() {
if (onClickListener == null) {
onClickListener =
new OnClickListener() {
@Override
public void onClick(View v) {
onSampleDownloadButtonClicked((Sample) v.getTag());
private boolean canDownload(Sample sample) {
if (!(sample instanceof UriSample)) {
return false;
}
};
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 {
public final String uri;
public final Uri uri;
public final String extension;
public final String adTagUri;
@ -474,7 +470,7 @@ public class SampleChooserActivity extends Activity {
boolean preferExtensionDecoders,
String abrAlgorithm,
DrmInfo drmInfo,
String uri,
Uri uri,
String extension,
String adTagUri) {
super(name, preferExtensionDecoders, abrAlgorithm, drmInfo);
@ -486,7 +482,7 @@ public class SampleChooserActivity extends Activity {
@Override
public Intent buildIntent(Context context) {
return super.buildIntent(context)
.setData(Uri.parse(uri))
.setData(uri)
.putExtra(PlayerActivity.EXTENSION_EXTRA, extension)
.putExtra(PlayerActivity.AD_TAG_URI_EXTRA, adTagUri)
.setAction(PlayerActivity.ACTION_VIEW);
@ -510,7 +506,7 @@ public class SampleChooserActivity extends Activity {
@Override
public Intent buildIntent(Context context) {
String[] uris = new String[children.length];
Uri[] uris = new Uri[children.length];
String[] extensions = new String[children.length];
for (int i = 0; i < children.length; i++) {
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

View File

@ -1,18 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 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.
<!-- Copyright (C) 2017 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_downloader"

View File

@ -1,30 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<!-- 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="12dip"
android:paddingEnd="12dip"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/sample_title"
<TextView android:id="@+id/sample_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -32,12 +29,11 @@
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"/>
<ImageButton
android:id="@+id/download_button"
android:layout_width="35dip"
<ImageButton android:id="@+id/download_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/exo_download_description"
android:gravity="center_vertical"
android:src="@android:drawable/stat_sys_download"/>
android:background="@android:color/transparent"
android:src="@drawable/ic_offline_pin_white_36dp"/>
</LinearLayout>

View File

@ -51,6 +51,4 @@
<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>