提交 02497a6f 编写于 作者: S shuyu

增加了自定义输入框输入url页面 (2017-06-19)

上级 48183335
......@@ -75,7 +75,10 @@
android:name=".DetailMoreTypeActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait" />
<activity android:name=".InputUrlDetailActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
/>
</application>
</manifest>
\ No newline at end of file
package com.example.gsyvideoplayer;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.example.gsyvideoplayer.listener.SampleListener;
import com.example.gsyvideoplayer.model.SwitchVideoModel;
import com.example.gsyvideoplayer.video.LandLayoutVideo;
import com.example.gsyvideoplayer.video.SampleVideo;
import com.example.gsyvideoplayer.view.CustomInputDialog;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.listener.LockClickListener;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class InputUrlDetailActivity extends AppCompatActivity {
@BindView(R.id.post_detail_nested_scroll)
NestedScrollView postDetailNestedScroll;
//推荐使用StandardGSYVideoPlayer,功能一致
//CustomGSYVideoPlayer部分功能处于试验阶段
@BindView(R.id.detail_player)
LandLayoutVideo detailPlayer;
@BindView(R.id.activity_detail_player)
RelativeLayout activityDetailPlayer;
@BindView(R.id.inputUrl)
Button inputUrl;
private boolean isPlay;
private boolean isPause;
private boolean cache;
private String url;
private OrientationUtils orientationUtils;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_input_url_detail);
ButterKnife.bind(this);
url = "http://baobab.wdjcdn.com/14564977406580.mp4";
detailPlayer.setUp(url, cache, null, "测试视频");
//增加封面
ImageView imageView = new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(R.mipmap.xxx1);
detailPlayer.setThumbImageView(imageView);
resolveNormalVideoUI();
//外部辅助的旋转,帮助全屏
orientationUtils = new OrientationUtils(this, detailPlayer);
//初始化不打开外部的旋转
orientationUtils.setEnable(false);
detailPlayer.setIsTouchWiget(true);
//detailPlayer.setIsTouchWigetFull(false);
//关闭自动旋转
detailPlayer.setRotateViewAuto(false);
detailPlayer.setLockLand(false);
detailPlayer.setShowFullAnimation(false);
detailPlayer.setNeedLockFull(true);
detailPlayer.setSeekRatio(1);
//detailPlayer.setOpenPreView(false);
detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//直接横屏
orientationUtils.resolveByClick();
//第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
detailPlayer.startWindowFullscreen(InputUrlDetailActivity.this, true, true);
}
});
detailPlayer.setStandardVideoAllCallBack(new SampleListener() {
@Override
public void onPrepared(String url, Object... objects) {
super.onPrepared(url, objects);
//开始播放了才能旋转和全屏
orientationUtils.setEnable(true);
isPlay = true;
}
@Override
public void onAutoComplete(String url, Object... objects) {
super.onAutoComplete(url, objects);
}
@Override
public void onClickStartError(String url, Object... objects) {
super.onClickStartError(url, objects);
}
@Override
public void onQuitFullscreen(String url, Object... objects) {
super.onQuitFullscreen(url, objects);
if (orientationUtils != null) {
orientationUtils.backToProtVideo();
}
}
});
detailPlayer.setLockClickListener(new LockClickListener() {
@Override
public void onClick(View view, boolean lock) {
if (orientationUtils != null) {
//配合下方的onConfigurationChanged
orientationUtils.setEnable(!lock);
}
}
});
inputUrl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showInputDialog();
}
});
}
@Override
public void onBackPressed() {
if (orientationUtils != null) {
orientationUtils.backToProtVideo();
}
if (StandardGSYVideoPlayer.backFromWindowFull(this)) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
isPause = true;
}
@Override
protected void onResume() {
super.onResume();
isPause = false;
}
@Override
protected void onDestroy() {
super.onDestroy();
GSYVideoPlayer.releaseAllVideos();
//GSYPreViewManager.instance().releaseMediaPlayer();
if (orientationUtils != null)
orientationUtils.releaseListener();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//如果旋转了就全屏
if (isPlay && !isPause) {
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
if (!detailPlayer.isIfCurrentIsFullscreen()) {
detailPlayer.startWindowFullscreen(InputUrlDetailActivity.this, true, true);
}
} else {
//新版本isIfCurrentIsFullscreen的标志位内部提前设置了,所以不会和手动点击冲突
if (detailPlayer.isIfCurrentIsFullscreen()) {
StandardGSYVideoPlayer.backFromWindowFull(this);
}
if (orientationUtils != null) {
orientationUtils.setEnable(true);
}
}
}
}
private void playVideo() {
detailPlayer.release();
detailPlayer.setUp(url, cache, null, "测试视频");
detailPlayer.postDelayed(new Runnable() {
@Override
public void run() {
detailPlayer.startPlayLogic();
}
}, 1000);
}
private void resolveNormalVideoUI() {
//增加title
detailPlayer.getTitleTextView().setVisibility(View.GONE);
detailPlayer.getTitleTextView().setText("测试视频");
detailPlayer.getBackButton().setVisibility(View.GONE);
}
private void showInputDialog() {
final CustomInputDialog customInputDialog = new CustomInputDialog(this);
customInputDialog.setInput(url);
customInputDialog.setCache(cache);
customInputDialog.setTitle("请输入URL");
customInputDialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new CustomInputDialog.OnClickListener() {
@Override
public void onInputChanged(String input, boolean cache) {
url = input;
InputUrlDetailActivity.this.cache = cache;
}
@Override
public void onClick(DialogInterface dialog, int which) {
url = customInputDialog.getEditMessage().getText().toString();
playVideo();
}
});
customInputDialog.setCancelable(true);
customInputDialog.show();
}
}
......@@ -27,7 +27,7 @@ public class MainActivity extends AppCompatActivity {
ButterKnife.bind(this);
}
@OnClick({R.id.open_btn, R.id.list_btn, R.id.list_btn_2, R.id.list_detail, R.id.clear_cache, R.id.recycler, R.id.recycler_2, R.id.list_detail_list, R.id.web_detail, R.id.danmaku_video, R.id.fragment_video, R.id.more_type})
@OnClick({R.id.open_btn, R.id.list_btn, R.id.list_btn_2, R.id.list_detail, R.id.clear_cache, R.id.recycler, R.id.recycler_2, R.id.list_detail_list, R.id.web_detail, R.id.danmaku_video, R.id.fragment_video, R.id.more_type, R.id.input_type})
public void onClick(View view) {
switch (view.getId()) {
case R.id.open_btn:
......@@ -71,6 +71,8 @@ public class MainActivity extends AppCompatActivity {
case R.id.more_type:
//跳到多类型详情播放器,比如切换分辨率,旋转等
JumpUtils.gotoMoreType(this);
case R.id.input_type:
JumpUtils.gotoInput(this);
case R.id.clear_cache:
//清理缓存
GSYVideoManager.clearAllDefaultCache(MainActivity.this);
......
......@@ -12,6 +12,7 @@ import com.example.gsyvideoplayer.DetailListPlayer;
import com.example.gsyvideoplayer.DetailMoreTypeActivity;
import com.example.gsyvideoplayer.DetailPlayer;
import com.example.gsyvideoplayer.FragmentVideoActivity;
import com.example.gsyvideoplayer.InputUrlDetailActivity;
import com.example.gsyvideoplayer.ListVideo2Activity;
import com.example.gsyvideoplayer.ListVideoActivity;
import com.example.gsyvideoplayer.PlayActivity;
......@@ -149,4 +150,13 @@ public class JumpUtils {
Intent intent = new Intent(activity, DetailMoreTypeActivity.class);
activity.startActivity(intent);
}
/**
* 跳到可输入
* @param activity
*/
public static void gotoInput(Activity activity) {
Intent intent = new Intent(activity, InputUrlDetailActivity.class);
activity.startActivity(intent);
}
}
package com.example.gsyvideoplayer.view;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import com.example.gsyvideoplayer.R;
public class CustomInputDialog extends Dialog {
private Context context;
private EditText editMessage;
public EditText getEditMessage() {
return editMessage;
}
public void setEditMessage(EditText editMessage) {
this.editMessage = editMessage;
}
private TextView txtTitle;
private TextView btnPostive;
private TextView btnNegative;
private CheckBox cacheCheck;
private OnClickListener onPostiveClickListener;
private OnClickListener onNegativeClickListener;
private String postiveText;
private String negativeText;
private String input;
private String hintInput;
private String title;
private int maxLength = 500;
private boolean needDismissOnClick = true;
private boolean cache = false;
private boolean postiveButtonVisiable = false;
private boolean negativeButtonVisiable = false;
public CustomInputDialog(Context context) {
super(context, R.style.dialog_style);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
}
public void init() {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.layout_custom_dialog, null);
setContentView(view);
txtTitle = (TextView) view.findViewById(R.id.dialog_input_title);
editMessage = (EditText) view.findViewById(R.id.dialog_input_dialog_edit);
btnPostive = (TextView) view.findViewById(R.id.dialog_input_dialog_postive);
btnNegative = (TextView) view.findViewById(R.id.dialog_input_dialog_negative);
cacheCheck = (CheckBox) view.findViewById(R.id.dialog_input_check);
cacheCheck.setChecked(cache);
if (postiveButtonVisiable) {
btnPostive.setVisibility(View.VISIBLE);
} else {
btnPostive.setVisibility(View.GONE);
}
if (negativeButtonVisiable) {
btnNegative.setVisibility(View.VISIBLE);
} else {
btnNegative.setVisibility(View.GONE);
}
if (TextUtils.isEmpty(title)) {
txtTitle.setVisibility(View.GONE);
} else {
txtTitle.setVisibility(View.VISIBLE);
txtTitle.setText(title);
}
editMessage.setText(input);
if (input != null) {
editMessage.setSelection(input.length());
}
if (!TextUtils.isEmpty(hintInput)) {
editMessage.setHint(hintInput);
}
btnPostive.setText(postiveText);
btnNegative.setText(negativeText);
btnPostive.setOnClickListener(new OnButtonClickListener());
btnNegative.setOnClickListener(new OnButtonClickListener());
InputFilter[] filters = {new InputFilter.LengthFilter(maxLength)};
editMessage.setFilters(filters);
Window dialogWindow = getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
lp.width = (int) (d.widthPixels * 0.8); // 宽度设置为屏幕的0.8
dialogWindow.setAttributes(lp);
}
public void setInput(int msgId) {
input = context.getString(msgId);
}
public void setInput(String msg) {
input = msg;
}
public void setHintInput(String msg) {
hintInput = msg;
}
public void setTitle(int msgId) {
title = context.getString(msgId);
}
public void setTitle(String msg) {
title = msg;
}
public void setCache(boolean cache) {
this.cache = cache;
}
public void setNeedDismissOnClick(boolean needDismissOnClick) {
this.needDismissOnClick = needDismissOnClick;
}
public void setButton(int which, String text, OnClickListener onClickListener) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
postiveButtonVisiable = true;
postiveText = text;
setOnPostiveClickListener(onClickListener);
break;
case DialogInterface.BUTTON_NEGATIVE:
negativeButtonVisiable = true;
negativeText = text;
setOnNegativeClickListener(onClickListener);
break;
default:
break;
}
}
public void setOnPostiveClickListener(OnClickListener onPostiveClickListener) {
this.onPostiveClickListener = onPostiveClickListener;
}
public void setOnNegativeClickListener(OnClickListener onNegativeClickListener) {
this.onNegativeClickListener = onNegativeClickListener;
}
private class OnButtonClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
if (R.id.dialog_input_dialog_postive == v.getId()) {
if (onPostiveClickListener != null) {
onPostiveClickListener.onClick(CustomInputDialog.this, DialogInterface.BUTTON_POSITIVE);
String newInput = editMessage.getText().toString();
if (!newInput.equals(input)) {
input = newInput;
onPostiveClickListener.onInputChanged(input, cacheCheck.isChecked());
}
}
} else if (R.id.dialog_input_dialog_negative == v.getId()) {
if (onNegativeClickListener != null) {
onNegativeClickListener.onClick(CustomInputDialog.this, DialogInterface.BUTTON_NEGATIVE);
}
}
if (needDismissOnClick) {
dismiss();
}
}
}
public interface OnClickListener extends DialogInterface.OnClickListener {
public void onInputChanged(String input, boolean cache);
}
public void collapseSoftInputMethod() {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(getContext().INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(getCurrentFocus()
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
@Override
public void dismiss() {
collapseSoftInputMethod();
super.dismiss();
}
public void setMaxLength(int maxLength) {
this.maxLength = maxLength;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- content -->
<item>
<shape android:shape="rectangle">
<solid android:color="#CC2B2B2B" />
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/btn_rect_alpha" android:state_enabled="true" android:state_focused="true" />
<item android:drawable="@color/btn_rect_alpha" android:state_enabled="true" android:state_pressed="true" />
<item android:drawable="@color/btn_rect_alpha" android:state_enabled="true" android:state_selected="true" />
<item android:drawable="@color/transparent" android:state_enabled="false" />
<item android:drawable="@color/transparent" android:state_enabled="true" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_detail_player"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/post_detail_nested_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/post_media_height" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/detail_text"
android:textSize="16sp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<com.example.gsyvideoplayer.video.LandLayoutVideo
android:id="@+id/detail_player"
android:layout_width="match_parent"
android:layout_height="@dimen/post_media_height" />
<Button
android:id="@+id/inputUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
/>
</RelativeLayout>
......@@ -93,6 +93,13 @@
android:layout_marginTop="20dp"
android:text="More Type" />
<Button
android:id="@+id/input_type"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Input Type" />
<Button
android:id="@+id/clear_cache"
android:layout_width="120dp"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_wiht_shadow"
android:orientation="vertical">
<TextView
android:id="@+id/dialog_input_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:text="请输入URL"
android:textColor="#E6E6E6"
android:textSize="18sp" />
<EditText
android:id="@+id/dialog_input_dialog_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:background="@null"
android:gravity="left"
android:minLines="4"
android:textColor="#E6E6E6"
android:textColorHint="#a1a1a1"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="是否缓存"
android:textColor="#FFFFFF" />
<CheckBox
android:id="@+id/dialog_input_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="right">
<TextView
android:id="@+id/dialog_input_dialog_negative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/dialog_btn_bg"
android:gravity="center"
android:paddingBottom="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:text="取消"
android:textColor="#E6E6E6"
android:textSize="16sp" />
<TextView
android:id="@+id/dialog_input_dialog_postive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dialog_btn_bg"
android:gravity="center"
android:paddingBottom="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:text="确定"
android:textColor="#E6E6E6"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -3,4 +3,6 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="transparent">#00000000</color>
<color name="btn_rect_alpha">#56b3b3b3</color>
</resources>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册