Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
liweiyap committed Jun 25, 2021
1 parent 8407598 commit 8cf2df6
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,10 @@ public void onPlaybackStateChanged(@Player.State int playbackState)
pauseButton.addOnClickObserver(() -> {
mAudioPlayer.playClickSound();

if (mAudioPlayer.isPlayingIntro())
{
pauseButton.setText(R.string.pause_button_text_state_inactive);
}
else
{
pauseButton.setText(R.string.pause_button_text_state_active);
}
pauseButton.setText(
mAudioPlayer.isPlayingIntro() ?
R.string.pause_button_text_state_inactive :
R.string.pause_button_text_state_active);

mAudioPlayer.toggle(mBackgroundSoundVolume);
});
Expand Down Expand Up @@ -192,13 +188,25 @@ protected void onDestroy()
mAudioPlayer.freeResources();
}

mCurrentDisplayedCharacterImageView.setImageDrawable(null);
mCurrentDisplayedIntroSegmentTextView.setText("");
if (mCurrentDisplayedCharacterImageView != null)
{
mCurrentDisplayedCharacterImageView.setImageDrawable(null);
}

if (mCurrentDisplayedIntroSegmentTextView != null)
{
mCurrentDisplayedIntroSegmentTextView.setText("");
}
}

@SuppressLint("NonConstantResourceId")
private void switchCurrentDisplayedCharacterImage(@RawRes final int resId)
{
if (mCurrentDisplayedCharacterImageView == null)
{
return;
}

switch (resId)
{
case R.raw.avalonintrosegment1nooberon:
Expand Down Expand Up @@ -234,6 +242,11 @@ private void switchCurrentDisplayedCharacterImage(@RawRes final int resId)
@SuppressLint("NonConstantResourceId")
private void switchCurrentDisplayedIntroSegmentTextView(@RawRes final int resId)
{
if (mCurrentDisplayedIntroSegmentTextView == null)
{
return;
}

@StringRes final int subtitleId = IntroSegmentDictionary.getSubtitleResIdFromIntroSegmentResId(resId);

if (subtitleId == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ private void addBackgroundSoundSetters()
CustomTypefaceableCheckableObserverButton btn = findViewById(R.id.backgroundSoundNoneButton);
btn.addOnClickObserver(() -> mBackgroundSoundRawResId = 0);
btn.addOnLongClickObserver(() -> {
if (mBackgroundSoundTestMediaPlayer != null)
if (mBackgroundSoundTestMediaPlayer == null)
{
mBackgroundSoundTestMediaPlayer.stop();
return;
}
mBackgroundSoundTestMediaPlayer.stop();
});

addBackgroundSoundSetter(R.raw.backgroundcards);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,29 @@ protected void makeFullScreen()
// https://stackoverflow.com/questions/62643517/immersive-fullscreen-on-android-11
getWindow().setDecorFitsSystemWindows(false);
WindowInsetsController controller = getWindow().getInsetsController();
if (controller != null)

if (controller == null)
{
controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
return;
}

controller.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
return;
}
else
{
// make the below show-/hide-changes temporary
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
// set the content to appear under the system bars
// so that the content does not resize when the system bars hide and show
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
// hide navigation bar
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
// hide status bar
View.SYSTEM_UI_FLAG_FULLSCREEN);
}

// make the below show-/hide-changes temporary
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
// set the content to appear under the system bars
// so that the content does not resize when the system bars hide and show
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
// hide navigation bar
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
// hide status bar
View.SYSTEM_UI_FLAG_FULLSCREEN);
}
}
10 changes: 6 additions & 4 deletions app/src/main/java/com/liweiyap/narradir/ui/SettingsLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ public void setKey(final String key)
}

CustomTypefaceableTextView keyTextView = findViewById(R.id.keyTextView);
if (keyTextView != null)
if (keyTextView == null)
{
keyTextView.setText(key);
return;
}
keyTextView.setText(key);
}

/**
Expand All @@ -62,10 +63,11 @@ public void setValue(final String value)
}

CustomTypefaceableTextView valueTextView = findViewById(R.id.valueTextView);
if (valueTextView != null)
if (valueTextView == null)
{
valueTextView.setText(value);
return;
}
valueTextView.setText(value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,26 @@ public StrokedCustomTypefaceableTextView(@NonNull Context context, final String
@Override
protected void onDraw(Canvas canvas)
{
if (mStrokeWidth > 0)
if (mStrokeWidth <= 0)
{
mIsDrawing = true;

Paint p = getPaint();
p.setStyle(Paint.Style.FILL);
super.onDraw(canvas);
return;
}

int currentTextColor = getCurrentTextColor();
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(mStrokeWidth);
setTextColor(mStrokeColor);
super.onDraw(canvas);
mIsDrawing = true;

setTextColor(currentTextColor);
mIsDrawing = false;
}
else
{
super.onDraw(canvas);
}
Paint p = getPaint();
p.setStyle(Paint.Style.FILL);
super.onDraw(canvas);

int currentTextColor = getCurrentTextColor();
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(mStrokeWidth);
setTextColor(mStrokeColor);
super.onDraw(canvas);

setTextColor(currentTextColor);
mIsDrawing = false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void freeResources()
{
return;
}

mSoundPool.release();
mSoundPool = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public IntroAudioPlayer(
{
allocateResources(
context,
introSegmentArrayList, Math.max(pauseDurationInMilliSecs, IntroAudioPlayer.sMinPauseDurationInMilliSecs), narrationVolume,
introSegmentArrayList, pauseDurationInMilliSecs, narrationVolume,
backgroundSoundRawResId, backgroundSoundVolume);
}

Expand All @@ -49,7 +49,7 @@ public void allocateResources(
initSoundPool(context, backgroundSoundRawResId, backgroundSoundVolume);

// initialise and prepare ExoPlayer for intro segments
prepareExoPlayer(context, introSegmentArrayList, pauseDurationInMilliSecs, narrationVolume);
prepareExoPlayer(context, introSegmentArrayList, Math.max(pauseDurationInMilliSecs, IntroAudioPlayer.sMinPauseDurationInMilliSecs), narrationVolume);
}

private void initSoundPool(final @NonNull Context context, final @RawRes int backgroundSoundRawResId, final float backgroundSoundVolume)
Expand Down

0 comments on commit 8cf2df6

Please sign in to comment.