Skip to content

Commit

Permalink
Merge pull request #19 from dev-labs-bg/refactor/library-module
Browse files Browse the repository at this point in the history
Refactored part of the library module
  • Loading branch information
slavipetrov authored Feb 23, 2018
2 parents bad100d + f2af671 commit 3c809c6
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 100 deletions.
14 changes: 0 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
### AndroidStudio ###
# Covers files to be ignored for android development using Android Studio.

# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
Expand All @@ -35,7 +25,6 @@ proguard/
*.log

# Android Studio
/*/build/
/*/local.properties
/*/out
/*/*/build
Expand All @@ -52,9 +41,6 @@ gen-external-apklibs
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# NDK
obj/

# IntelliJ IDEA
*.iml
*.iws
Expand Down
8 changes: 4 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
ext.versions = [
minSdk : 19,
compileSdk : 27,
buildTools : '26.0.2',
publishVersion : '0.0.7',
buildTools : '27.0.3',
publishVersion : '0.0.8',
publishVersionCode: 1,
gradlePlugin : '3.0.1',
bintrayPlugin : '1.7.3',
mavenPlugin : '1.4.1',

supportLib : '27.0.2',
supportLib : '27.0.3',
espresso : '3.0.1',
kotlin : '1.2.0',
kotlin : '1.2.21',
leakCanary : '1.5.4'
]
2 changes: 1 addition & 1 deletion library/release.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply from: 'keystore.gradle'
ext {
publishedGroupId = 'bg.devlabs.fullscreenvideoview'
artifactId = 'library'
libraryVersion = '0.0.7'
libraryVersion = '0.0.8'
}

version = libraryVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ private void initOnBackPressedListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
return (event.getAction() == KeyEvent.ACTION_UP)
&& (keyCode == KeyEvent.KEYCODE_BACK)
&& orientationHelper.shouldHandleOnBackPressed();
&& (orientationHelper != null
&& orientationHelper.shouldHandleOnBackPressed());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,25 @@ class VideoControllerView extends FrameLayout {
private ImageButton rewButton;
private ImageButton fullscreenButton;
@Nullable
private View.OnClickListener pauseListener = new PauseOnClickListener();
private View.OnClickListener pauseListener = new OnClickListener() {
@Override
public void onClick(View v) {
doPauseResume();
show(DEFAULT_TIMEOUT);
}
};
@Nullable
private View.OnClickListener fullscreenListener = new FullscreenOnClickListener();
// There are two scenarios that can trigger the seekbar listener to trigger:
private View.OnClickListener fullscreenListener = new OnClickListener() {
@Override
public void onClick(View view) {
doToggleFullscreen();
show(DEFAULT_TIMEOUT);
}
};
// There are two scenarios that can trigger the SeekBar listener to trigger:
//
// The first is the user using the touchpad to adjust the position of the
// seekbar's thumb. In this case onStartTrackingTouch is called followed by
// The first is the user using the TouchPad to adjust the position of the
// SeekBar's thumb. In this case onStartTrackingTouch is called followed by
// a number of onProgressChanged notifications, concluded by onStopTrackingTouch.
// We're setting the field "isDragging" to true for the duration of the dragging
// session to avoid jumps in the position in case of ongoing playback.
Expand All @@ -106,9 +118,37 @@ class VideoControllerView extends FrameLayout {
@Nullable
private SeekBar.OnSeekBarChangeListener seekListener = new OnSeekChangeListener();
@Nullable
private View.OnClickListener rewListener = new RewindOnClickListener();
private View.OnClickListener rewListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (videoMediaPlayer == null) {
return;
}

int pos = videoMediaPlayer.getCurrentPosition();
pos -= rewindDuration; // milliseconds
videoMediaPlayer.seekTo(pos);
setProgress();

show(DEFAULT_TIMEOUT);
}
};
@Nullable
private View.OnClickListener ffwdListener = new FfwdOnClickListener();
private View.OnClickListener ffwdListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (videoMediaPlayer == null) {
return;
}

int pos = videoMediaPlayer.getCurrentPosition();
pos += fastForwardDuration; // milliseconds
videoMediaPlayer.seekTo(pos);
setProgress();

show(DEFAULT_TIMEOUT);
}
};
// Drawables for the buttons of the controller
private Drawable exitFullscreenDrawable = ContextCompat.getDrawable(getContext(),
R.drawable.ic_fullscreen_exit_white_48dp);
Expand All @@ -128,25 +168,25 @@ class VideoControllerView extends FrameLayout {
private int rewindDuration = Constants.REWIND_DURATION;
private OrientationHelper orientationHelper;

public VideoControllerView(Context context, AttributeSet attrs) {
super(context, attrs);

public VideoControllerView(Context context) {
super(context);
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
layoutInflater.inflate(R.layout.video_controller, this, true);
initControllerView();
setupXmlAttributes(attrs);
}

public VideoControllerView(Context context) {
super(context);
public VideoControllerView(Context context, AttributeSet attrs) {
super(context, attrs);

LayoutInflater layoutInflater = LayoutInflater.from(getContext());
layoutInflater.inflate(R.layout.video_controller, this, true);
initControllerView();
setupXmlAttributes(attrs);
}

private void setupXmlAttributes(AttributeSet attrs) {
TypedArray typedArr = getContext().obtainStyledAttributes(attrs,
R.styleable.FullscreenVideoView, 0, 0);
R.styleable.VideoControllerView, 0, 0);
setupPlayPauseButton(typedArr);
setupFullscreenButton(typedArr);
setupFastForwardButton(typedArr);
Expand All @@ -157,7 +197,7 @@ private void setupXmlAttributes(AttributeSet attrs) {
}

private void setupProgressBar(TypedArray a) {
int color = a.getColor(R.styleable.FullscreenVideoView_progress_color, 0);
int color = a.getColor(R.styleable.VideoControllerView_progress_color, 0);
if (color != 0) {
// Set the default color
progressBarColor = color;
Expand All @@ -167,15 +207,15 @@ private void setupProgressBar(TypedArray a) {
}

private void setupRewindButton(TypedArray a) {
Drawable drawable = a.getDrawable(R.styleable.FullscreenVideoView_rew_drawable);
Drawable drawable = a.getDrawable(R.styleable.VideoControllerView_rew_drawable);
if (drawable != null) {
rewindDrawable = drawable;
}
rewButton.setImageDrawable(rewindDrawable);
}

private void setupFastForwardButton(TypedArray a) {
Drawable drawable = a.getDrawable(R.styleable.FullscreenVideoView_ffwd_drawable);
Drawable drawable = a.getDrawable(R.styleable.VideoControllerView_ffwd_drawable);
if (drawable != null) {
fastForwardDrawable = drawable;
}
Expand All @@ -184,27 +224,27 @@ private void setupFastForwardButton(TypedArray a) {

private void setupFullscreenButton(TypedArray a) {
Drawable enterDrawable = a.getDrawable(
R.styleable.FullscreenVideoView_enter_fullscreen_drawable);
R.styleable.VideoControllerView_enter_fullscreen_drawable);
if (enterDrawable != null) {
enterFullscreenDrawable = enterDrawable;
}
fullscreenButton.setImageDrawable(enterFullscreenDrawable);

Drawable exitDrawable = a.getDrawable(
R.styleable.FullscreenVideoView_exit_fullscreen_drawable);
R.styleable.VideoControllerView_exit_fullscreen_drawable);
if (exitDrawable != null) {
exitFullscreenDrawable = exitDrawable;
}
}

private void setupPlayPauseButton(TypedArray a) {
Drawable drawable = a.getDrawable(R.styleable.FullscreenVideoView_play_drawable);
Drawable drawable = a.getDrawable(R.styleable.VideoControllerView_play_drawable);
if (drawable != null) {
playDrawable = drawable;
}
startPauseButton.setImageDrawable(playDrawable);

Drawable drawable1 = a.getDrawable(R.styleable.FullscreenVideoView_pause_drawable);
Drawable drawable1 = a.getDrawable(R.styleable.VideoControllerView_pause_drawable);
if (drawable1 != null) {
pauseDrawable = drawable1;
}
Expand Down Expand Up @@ -308,9 +348,13 @@ private void show(int timeout) {
updatePausePlay();
updateFullScreenDrawable();

// cause the progress bar to be updated even if mShowing
// was already true. This happens, for example, if we're
// Cause the progress bar to be updated even if it's showing.
// This happens, for example, if we're
// paused with the progress bar showing the user hits play.
if (handler == null) {
return;
}

handler.sendEmptyMessage(SHOW_PROGRESS);

Message msg = handler.obtainMessage(FADE_OUT);
Expand All @@ -330,7 +374,9 @@ private boolean isShowing() {
private void hide() {
try {
setVisibility(INVISIBLE);
handler.removeMessages(SHOW_PROGRESS);
if (handler != null) {
handler.removeMessages(SHOW_PROGRESS);
}
} catch (IllegalArgumentException ignored) {
Log.w("MediaController", "already removed");
}
Expand Down Expand Up @@ -554,22 +600,6 @@ public void handleMessage(Message msg) {
}
}

private class PauseOnClickListener implements View.OnClickListener {
@Override
public void onClick(View view) {
doPauseResume();
show(DEFAULT_TIMEOUT);
}
}

private class FullscreenOnClickListener implements View.OnClickListener {
@Override
public void onClick(View view) {
doToggleFullscreen();
show(DEFAULT_TIMEOUT);
}
}

private class OnSeekChangeListener implements SeekBar.OnSeekBarChangeListener {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Expand All @@ -582,7 +612,9 @@ public void onStartTrackingTouch(SeekBar seekBar) {
// the seekbar and b) once the user is done dragging the thumb
// we will post one of these messages to the queue again and
// this ensures that there will be exactly one message queued up.
handler.removeMessages(SHOW_PROGRESS);
if (handler != null) {
handler.removeMessages(SHOW_PROGRESS);
}
}

@Override
Expand Down Expand Up @@ -615,37 +647,9 @@ public void onStopTrackingTouch(SeekBar seekBar) {
// Ensure that progress is properly updated in the future,
// the call to show() does not guarantee this because it is a
// no-op if we are already showing.
handler.sendEmptyMessage(SHOW_PROGRESS);
}
}

private class RewindOnClickListener implements View.OnClickListener {
public void onClick(View v) {
if (videoMediaPlayer == null) {
return;
if (handler != null) {
handler.sendEmptyMessage(SHOW_PROGRESS);
}

int pos = videoMediaPlayer.getCurrentPosition();
pos -= rewindDuration; // milliseconds
videoMediaPlayer.seekTo(pos);
setProgress();

show(DEFAULT_TIMEOUT);
}
}

private class FfwdOnClickListener implements View.OnClickListener {
public void onClick(View v) {
if (videoMediaPlayer == null) {
return;
}

int pos = videoMediaPlayer.getCurrentPosition();
pos += fastForwardDuration; // milliseconds
videoMediaPlayer.seekTo(pos);
setProgress();

show(DEFAULT_TIMEOUT);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void updateLayoutParams(int videoWidth, int videoHeight) {
setLayoutParams(lp);
}

public void resetLayoutParams() {
private void resetLayoutParams() {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) getLayoutParams();
layoutParams.height = previousHeight;
layoutParams.width = previousWidth;
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="FullscreenVideoView">
<declare-styleable name="VideoControllerView">
<attr name="play_drawable" format="reference"/>
<attr name="pause_drawable" format="reference"/>
<attr name="enter_fullscreen_drawable" format="reference"/>
Expand Down
12 changes: 6 additions & 6 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name="bg.devlabs.fullscreenvideoviewsample.FullscreenVideoViewApp"
android:name=".FullscreenVideoViewApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="bg.devlabs.fullscreenvideoviewsample.MainActivity"
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -23,17 +23,17 @@
</intent-filter>
</activity>
<activity
android:name="bg.devlabs.fullscreenvideoviewsample.ActionBarActivity"
android:name=".ActionBarActivity"
android:configChanges="orientation|screenSize" />
<activity
android:name="bg.devlabs.fullscreenvideoviewsample.ToolbarActivity"
android:name=".ToolbarActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/NoActionBarAppTheme" />
<activity
android:name="bg.devlabs.fullscreenvideoviewsample.NoActionBarActivity"
android:name=".NoActionBarActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/NoActionBarAppTheme" />
<activity android:name="bg.devlabs.fullscreenvideoviewsample.RegularActivity"
<activity android:name=".RegularActivity"
android:configChanges="orientation|screenSize"/>
</application>

Expand Down
Loading

0 comments on commit 3c809c6

Please sign in to comment.