Skip to content

Commit

Permalink
Merge pull request #13 from groupme/remove-overlap
Browse files Browse the repository at this point in the history
Increase height of toggle switch view so the switch isn't cut off
  • Loading branch information
ra0s authored Jun 17, 2021
2 parents d69bad7 + 3ab5345 commit 6f14027
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 169 deletions.
6 changes: 3 additions & 3 deletions videokit/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 29
buildToolsVersion "28.0.3"
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 19
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ public CommonControllerOverlay(Context context) {
mToggleSwitch = new Switch(context);
mToggleSwitch.setTextColor(getResources().getColor(R.color.white));
mToggleSwitch.setTextSize(16);
mToggleSwitch.setMinimumHeight(64);
ColorStateList trackColor = ColorStateList.valueOf(getResources().getColor(R.color.white));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mToggleSwitch.setTrackTintList(trackColor);
}
mToggleSwitchView.addView(mToggleSwitch, wrapContent);
mToggleSwitchView.setMinimumHeight(64);
mToggleSwitchView.setMinimumHeight(mToggleSwitch.getMinimumHeight() + 8);
addView(mToggleSwitchView, matchParent);
hide();
}
Expand Down Expand Up @@ -225,10 +226,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (super.onTouchEvent(event)) {
return true;
}
return false;
return super.onTouchEvent(event);
}
// The paddings of 4 sides which covered by system components. E.g.
// +-----------------+\
Expand Down
22 changes: 14 additions & 8 deletions videokit/src/main/java/com/android/gallery3d/app/TimeBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import com.groupme.android.videokit.R;

import java.util.Locale;

/**
* The time bar view, which includes the current and total time, the progress
* bar, and the scrubber.
Expand All @@ -41,7 +43,7 @@ public interface Listener {
// The total padding, top plus bottom
private static final int V_PADDING_IN_DP = 30;
private static final int TEXT_SIZE_IN_DP = 14;
protected final Listener mListener;
protected Listener mListener;
// the bars we use for displaying the progress
protected final Rect mProgressBar;
protected final Rect mPlayedBar;
Expand All @@ -61,9 +63,9 @@ public interface Listener {
protected int mCurrentTime;
protected final Rect mTimeBounds;
protected int mVPaddingInPx;
public TimeBar(Context context, Listener listener) {

TimeBar(Context context) {
super(context);
mListener = checkNotNull(listener);
mShowTimes = true;
mShowScrubber = true;
mProgressBar = new Rect();
Expand All @@ -84,6 +86,10 @@ public TimeBar(Context context, Listener listener) {
mScrubberPadding = (int) (metrics.density * SCRUBBER_PADDING_IN_DP);
mVPaddingInPx = (int) (metrics.density * V_PADDING_IN_DP);
}
public TimeBar(Context context, Listener listener) {
this(context);
mListener = checkNotNull(listener);
}
private void update() {
mPlayedBar.set(mProgressBar);
if (mTotalTime > 0) {
Expand Down Expand Up @@ -165,13 +171,13 @@ protected void onDraw(Canvas canvas) {
if (mShowTimes) {
canvas.drawText(
stringForTime(mCurrentTime),
mTimeBounds.width() / 2 + getPaddingLeft(),
mTimeBounds.height() + mVPaddingInPx / 2 + mScrubberPadding + 1,
mTimeBounds.width() / 2f + getPaddingLeft(),
mTimeBounds.height() + mVPaddingInPx / 2f + mScrubberPadding + 1,
mTimeTextPaint);
canvas.drawText(
stringForTime(mTotalTime),
getWidth() - getPaddingRight() - mTimeBounds.width() / 2,
mTimeBounds.height() + mVPaddingInPx / 2 + mScrubberPadding + 1,
mTimeBounds.height() + mVPaddingInPx / 2f + mScrubberPadding + 1,
mTimeTextPaint);
}
}
Expand Down Expand Up @@ -213,9 +219,9 @@ protected String stringForTime(long millis) {
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
if (hours > 0) {
return String.format("%d:%02d:%02d", hours, minutes, seconds).toString();
return String.format(Locale.US, "%d:%02d:%02d", hours, minutes, seconds);
} else {
return String.format("%02d:%02d", minutes, seconds).toString();
return String.format(Locale.US, "%02d:%02d", minutes, seconds);
}
}
public void setSeekable(boolean canSeek) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.Build;
import android.view.MotionEvent;
import android.view.View;

Expand All @@ -28,8 +27,12 @@
* The controller for the Trimming Video.
*/
public class TrimControllerOverlay extends CommonControllerOverlay {
public TrimControllerOverlay(Context context, int maxDuration) {

TrimControllerOverlay(Context context) {
super(context);
}
public TrimControllerOverlay(Context context, int maxDuration) {
this(context);
((TrimTimeBar) mTimeBar).setMaxDuration(maxDuration);
}
@Override
Expand All @@ -40,9 +43,7 @@ private void hidePlayButtonIfPlaying() {
if (mState == State.PLAYING) {
mPlayPauseReplayView.setVisibility(View.INVISIBLE);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mPlayPauseReplayView.setAlpha(1f);
}
mPlayPauseReplayView.setAlpha(1f);
}
public void hideToggle() {
mToggleSwitchView.setVisibility(View.GONE);
Expand All @@ -52,10 +53,6 @@ public void showToggle() {
mToggleSwitchView.setVisibility(View.VISIBLE);
}

public boolean getToggleState() {
return mToggleSwitch.isChecked();
}

public void setMaxDuration(int maxDuration) {
((TrimTimeBar) mTimeBar).setMaxDuration(maxDuration);
}
Expand All @@ -75,30 +72,26 @@ public void setSwitchText(String text) {
@Override
public void showPlaying() {
super.showPlaying();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Add animation to hide the play button while playing.
ObjectAnimator anim = ObjectAnimator.ofFloat(mPlayPauseReplayView, "alpha", 1f, 0f);
anim.setDuration(200);
anim.start();
anim.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
hidePlayButtonIfPlaying();
}
@Override
public void onAnimationCancel(Animator animation) {
hidePlayButtonIfPlaying();
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
} else {
hidePlayButtonIfPlaying();
}
// Add animation to hide the play button while playing.
ObjectAnimator anim = ObjectAnimator.ofFloat(mPlayPauseReplayView, "alpha", 1f, 0f);
anim.setDuration(200);
anim.start();
anim.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
hidePlayButtonIfPlaying();
}
@Override
public void onAnimationCancel(Animator animation) {
hidePlayButtonIfPlaying();
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
@Override
public void setTimes(int currentTime, int totalTime, int trimStartTime, int trimEndTime) {
Expand Down
19 changes: 8 additions & 11 deletions videokit/src/main/java/com/android/gallery3d/app/TrimTimeBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;

import com.groupme.android.videokit.R;
Expand Down Expand Up @@ -58,8 +56,8 @@ public class TrimTimeBar extends TimeBar {
private final Bitmap mTrimEndScrubber;
private int mMaxDuration;
private int mProgressY;
private Rect mSelectionBar;
private int mMinDuration = 1 * 1000; // 1 second
private final Rect mSelectionBar;
private final int mMinDuration = 1000; // 1 second

public TrimTimeBar(Context context, Listener listener) {
super(context, listener);
Expand Down Expand Up @@ -192,8 +190,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
margin += mTimeBounds.width();
}
mProgressY = h / 2;
int scrubberY = mProgressY - mScrubber.getHeight() / 2 + 1;
mScrubberTop = scrubberY;
mScrubberTop = mProgressY - mScrubber.getHeight() / 2 + 1;
mTrimStartScrubberTop = mProgressY - mTrimStartScrubber.getHeight() / 2 + 1;
mTrimEndScrubberTop = mProgressY - mTrimEndScrubber.getHeight() / 2 + 1;
mProgressBar.set(
Expand All @@ -213,13 +210,13 @@ protected void onDraw(Canvas canvas) {
if (mShowTimes) {
canvas.drawText(
stringForTime(mCurrentTime),
mTimeBounds.width() / 2 + getPaddingLeft(),
mTimeBounds.height() / 2 + mProgressY,
mTimeBounds.width() / 2f + getPaddingLeft(),
mTimeBounds.height() / 2f + mProgressY,
mTimeTextPaint);
canvas.drawText(
stringForTime(mTotalTime),
getWidth() - getPaddingRight() - mTimeBounds.width() / 2,
mTimeBounds.height() / 2 + mProgressY,
getWidth() - getPaddingRight() - mTimeBounds.width() / 2f,
mTimeBounds.height() / 2f + mProgressY,
mTimeTextPaint);
}

Expand Down Expand Up @@ -264,7 +261,7 @@ public boolean onTouchEvent(MotionEvent event) {
mScrubberCorrection = x - mTrimEndScrubberLeft;
break;
}
if (mScrubbing == true) {
if (mScrubbing) {
mListener.onScrubbingStart();
return true;
}
Expand Down
14 changes: 4 additions & 10 deletions videokit/src/main/java/com/android/gallery3d/app/TrimVideo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
Expand All @@ -61,7 +60,6 @@ public class TrimVideo extends Activity implements
private int mMaxDuration = 30 * 1000; // 30 seconds
private VideoView mVideoView;
private TrimControllerOverlay mController;
private Context mContext;
private Uri mUri;
private final Handler mHandler = new Handler();
public ProgressDialog mProgress;
Expand Down Expand Up @@ -118,7 +116,7 @@ protected void hideProcessing() {
@Override
public void onCreate(Bundle savedInstanceState) {
try {
mContext = getApplicationContext();
Context context = getApplicationContext();
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
Expand Down Expand Up @@ -146,7 +144,7 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.trim_view);
View rootView = findViewById(R.id.trim_view_root);
mVideoView = (VideoView) rootView.findViewById(R.id.surface_view);
mController = new TrimControllerOverlay(mContext, mMaxDuration);
mController = new TrimControllerOverlay(context, mMaxDuration);
((ViewGroup) rootView).addView(mController.getView());
mController.setListener(this);
mController.setCanReplay(true);
Expand All @@ -156,7 +154,7 @@ public void onCreate(Bundle savedInstanceState) {
if (ContentResolver.SCHEME_FILE.equals(mUri.getScheme())) {
retriever.setDataSource(mUri.getPath());
} else {
retriever.setDataSource(mContext, mUri);
retriever.setDataSource(context, mUri);
}

mDuration = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
Expand All @@ -181,11 +179,7 @@ public void onCreate(Bundle savedInstanceState) {
} else {
mMaxDuration = getIntent().getIntExtra(EXTRA_MAX_DURATION, mMaxDuration);
}
if(mTrimStartTime + mMaxDuration > mDuration) {
mTrimEndTime = mDuration;
} else {
mTrimEndTime = mTrimStartTime + mMaxDuration;
}
mTrimEndTime = Math.min(mTrimStartTime + mMaxDuration, mDuration);
mController.setMaxDuration(mMaxDuration);
mController.setTimes(mTrimStartTime, mDuration, mTrimStartTime, mTrimEndTime);
});
Expand Down
Loading

0 comments on commit 6f14027

Please sign in to comment.