Skip to content

Commit 80fe6de

Browse files
committed
v0.0.7新增仿头条小视频拖拽控件
1 parent d58d660 commit 80fe6de

File tree

9 files changed

+510
-29
lines changed

9 files changed

+510
-29
lines changed

app/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ dependencies {
3131

3232
implementation 'me.relex:photodraweeview:1.1.3'
3333
implementation 'com.facebook.fresco:fresco:1.9.0'
34+
35+
implementation 'com.google.android.exoplayer:exoplayer:2.7.3'
3436
}

app/src/main/AndroidManifest.xml

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.demo.widget">
44

5+
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
6+
57
<application
68
android:name=".MyApplication"
79
android:allowBackup="true"
@@ -28,6 +30,9 @@
2830
<activity
2931
android:name=".meis.MeiPhotoDragActivity"
3032
android:theme="@style/translucent"></activity>
33+
<activity
34+
android:name=".meis.MeiVideoDragActivity"
35+
android:theme="@style/translucent"></activity>
3136
</application>
3237

3338
</manifest>

app/src/main/java/com/demo/widget/meis/MainActivity.java

+4
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ public void onRadiusView(View view) {
4646
public void onPhotoDrag(View view) {
4747
startActivity(new Intent(this, MeiPhotoDragActivity.class));
4848
}
49+
50+
public void onVideoDrag(View view) {
51+
startActivity(new Intent(this, MeiVideoDragActivity.class));
52+
}
4953
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.demo.widget.meis;
2+
3+
import android.net.Uri;
4+
import android.os.Bundle;
5+
import android.support.annotation.Nullable;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.view.View;
8+
import android.widget.ImageView;
9+
import android.widget.TextView;
10+
11+
import com.demo.widget.R;
12+
import com.demo.widget.utils.Eyes;
13+
import com.google.android.exoplayer2.ExoPlayerFactory;
14+
import com.google.android.exoplayer2.SimpleExoPlayer;
15+
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
16+
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
17+
import com.google.android.exoplayer2.source.ExtractorMediaSource;
18+
import com.google.android.exoplayer2.source.MediaSource;
19+
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
20+
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
21+
import com.google.android.exoplayer2.trackselection.TrackSelection;
22+
import com.google.android.exoplayer2.trackselection.TrackSelector;
23+
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
24+
import com.google.android.exoplayer2.upstream.BandwidthMeter;
25+
import com.google.android.exoplayer2.upstream.DataSource;
26+
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
27+
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
28+
import com.google.android.exoplayer2.util.Util;
29+
import com.meis.widget.photodrag.VideoDragRelativeLayout;
30+
import com.meis.widget.radius.RadiusTextView;
31+
32+
/**
33+
* Created by wenshi on 2018/5/23.
34+
* Description
35+
*/
36+
public class MeiVideoDragActivity extends AppCompatActivity {
37+
38+
TextView mTvComment;
39+
TextView mTvAttention;
40+
RadiusTextView mTvName;
41+
ImageView mIvClose;
42+
SimpleExoPlayerView mPlayerView;
43+
44+
VideoDragRelativeLayout mDragLayout;
45+
46+
@Override
47+
protected void onCreate(@Nullable Bundle savedInstanceState) {
48+
super.onCreate(savedInstanceState);
49+
setContentView(R.layout.mei_video_drag_activity);
50+
Eyes.translucentStatusBar(this, true);
51+
52+
mTvComment = findViewById(R.id.tv_comment);
53+
mTvAttention = findViewById(R.id.tv_attention);
54+
mTvName = findViewById(R.id.tv_name);
55+
mIvClose = findViewById(R.id.iv_close);
56+
mDragLayout = findViewById(R.id.rl_drag);
57+
mPlayerView = findViewById(R.id.play_view);
58+
59+
//视频源
60+
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
61+
TrackSelection.Factory trackFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
62+
TrackSelector trackSelector = new DefaultTrackSelector(trackFactory);
63+
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
64+
mPlayerView.setPlayer(player);
65+
66+
DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
67+
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this
68+
, Util.getUserAgent(this, "MyApplication")
69+
, defaultBandwidthMeter);
70+
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
71+
Uri uri = Uri.parse("http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4");
72+
MediaSource mediaSource = new ExtractorMediaSource(uri
73+
, dataSourceFactory, extractorsFactory, null, null);
74+
player.prepare(mediaSource);
75+
76+
mDragLayout.setOnVideoDragListener(new VideoDragRelativeLayout.OnVideoDragListener() {
77+
@Override
78+
public void onStartDrag() {
79+
mTvComment.setVisibility(View.GONE);
80+
mTvAttention.setVisibility(View.GONE);
81+
mTvName.setVisibility(View.GONE);
82+
mIvClose.setVisibility(View.GONE);
83+
}
84+
85+
@Override
86+
public void onRelease(boolean dismiss) {
87+
if (!dismiss) {
88+
mTvComment.setVisibility(View.VISIBLE);
89+
mTvAttention.setVisibility(View.VISIBLE);
90+
mTvName.setVisibility(View.VISIBLE);
91+
mIvClose.setVisibility(View.VISIBLE);
92+
} else {
93+
//根据转场来执行相应的动画
94+
finish();
95+
}
96+
}
97+
});
98+
99+
mIvClose.setOnClickListener(new View.OnClickListener() {
100+
@Override
101+
public void onClick(View v) {
102+
finish();
103+
}
104+
});
105+
106+
}
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.meis.widget.photodrag.VideoDragRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/rl_drag"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
app:video_drag_transition="false">
8+
9+
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
10+
android:id="@+id/play_view"
11+
app:resize_mode="fill"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent">
14+
15+
</com.google.android.exoplayer2.ui.SimpleExoPlayerView>
16+
17+
<com.meis.widget.radius.RadiusTextView
18+
android:id="@+id/tv_name"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:layout_above="@+id/tv_comment"
22+
android:layout_alignBaseline="@+id/tv_attention"
23+
android:layout_marginLeft="16dp"
24+
android:text="文淑欢迎您的关注"
25+
android:textColor="#FFF"
26+
android:textSize="18sp" />
27+
28+
<com.meis.widget.radius.RadiusTextView
29+
android:id="@+id/tv_attention"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:layout_above="@+id/tv_comment"
33+
android:layout_marginLeft="16dp"
34+
android:layout_toRightOf="@+id/tv_name"
35+
android:gravity="center"
36+
android:paddingBottom="4dp"
37+
android:paddingLeft="16dp"
38+
android:paddingRight="16dp"
39+
android:paddingTop="4dp"
40+
android:tag="dispatch"
41+
android:text="关注"
42+
android:textSize="16sp"
43+
app:rv_backgroundColor="@color/colorPrimary"
44+
app:rv_backgroundPressedColor="@color/colorPrimaryDark"
45+
app:rv_radius="16dp"
46+
app:rv_textColor="#FFF" />
47+
48+
<com.meis.widget.radius.RadiusTextView
49+
android:id="@+id/tv_comment"
50+
android:layout_width="match_parent"
51+
android:layout_height="48dp"
52+
android:layout_alignParentBottom="true"
53+
android:layout_margin="8dp"
54+
android:gravity="center_vertical"
55+
android:hint="写评论..."
56+
android:paddingLeft="16dp"
57+
android:tag="dispatch"
58+
android:textColorHint="#FFF"
59+
android:textSize="16sp"
60+
app:rv_backgroundColor="#8F000000"
61+
app:rv_radius="16dp" />
62+
63+
<ImageView
64+
android:id="@+id/iv_close"
65+
android:layout_width="48dp"
66+
android:layout_height="48dp"
67+
android:layout_marginLeft="16dp"
68+
android:layout_marginTop="24dp"
69+
android:scaleType="centerInside"
70+
android:src="@mipmap/ic_arrow_back_white_24dp"
71+
android:tag="dispatch" />
72+
73+
</com.meis.widget.photodrag.VideoDragRelativeLayout>

app/src/main/res/layout/meis_activity.xml

+25
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,29 @@
111111

112112
</android.support.v7.widget.CardView>
113113

114+
115+
<android.support.v7.widget.CardView
116+
android:layout_width="match_parent"
117+
android:layout_height="wrap_content"
118+
android:layout_marginLeft="8dp"
119+
android:layout_marginRight="8dp"
120+
android:layout_marginTop="16dp"
121+
android:foreground="?attr/selectableItemBackground"
122+
android:onClick="onVideoDrag"
123+
app:cardBackgroundColor="@android:color/white"
124+
app:cardPreventCornerOverlap="false"
125+
app:cardUseCompatPadding="true">
126+
127+
<TextView
128+
android:layout_width="match_parent"
129+
android:layout_height="wrap_content"
130+
android:gravity="center"
131+
android:padding="16dp"
132+
android:text="仿头条视频拖拽控件"
133+
android:textAllCaps="false"
134+
android:textColor="#999999"
135+
android:textSize="16sp"/>
136+
137+
</android.support.v7.widget.CardView>
138+
114139
</LinearLayout>

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':app', ':widget', ':wid', ':widget'
1+
include ':app', ':widget'

0 commit comments

Comments
 (0)