Skip to content

Commit

Permalink
Merge pull request #65 from antest1/feature/new_button_drawer
Browse files Browse the repository at this point in the history
Improve side panel button drawer
  • Loading branch information
antest1 authored Oct 20, 2021
2 parents 3b5071e + f63f263 commit 2170b8f
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;

import com.antest1.gotobrowser.Browser.BrowserGestureListener;
import com.antest1.gotobrowser.Browser.CustomDrawerLayout;
import com.antest1.gotobrowser.Browser.WebViewL;
import com.antest1.gotobrowser.Browser.WebViewManager;
import com.antest1.gotobrowser.BuildConfig;
import com.antest1.gotobrowser.Helpers.AnimationUtils;
import com.antest1.gotobrowser.Helpers.BackPressCloseHandler;
import com.antest1.gotobrowser.Helpers.FpsPatcher;
import com.antest1.gotobrowser.Helpers.K3dPatcher;
Expand Down Expand Up @@ -86,7 +87,6 @@ public class BrowserActivity extends AppCompatActivity {
private final FpsPatcher fpsPatcher = new FpsPatcher();

private boolean isKcBrowserMode = false;
private boolean isPanelVisible = false;
private boolean isStartedFlag = false;
private boolean isAdjustChangedByUser = false;
private List<String> connector_info;
Expand Down Expand Up @@ -163,37 +163,37 @@ protected void onCreate(Bundle savedInstanceState) {
View menuLogout = findViewById(R.id.menu_logout);
menuLogout.setOnClickListener(v -> showLogoutDialog());

View menuMute = findViewById(R.id.menu_mute);
menuMute.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), isMuteMode ? R.color.panel_red : R.color.transparent));
ImageView menuMute = findViewById(R.id.menu_mute);
menuMute.setColorFilter(ContextCompat.getColor(getApplicationContext(), isMuteMode ? R.color.colorAccent : R.color.lightGray));
menuMute.setOnClickListener(this::setMuteMode);

View menuCamera = findViewById(R.id.menu_camera);
menuCamera.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), isCaptureMode ? R.color.panel_red : R.color.transparent));
ImageView menuCamera = findViewById(R.id.menu_camera);
menuCamera.setColorFilter(ContextCompat.getColor(getApplicationContext(), isCaptureMode ? R.color.colorAccent : R.color.lightGray));
menuCamera.setOnClickListener(this::setCaptureMode);
setCaptureButton();

View menuLock = findViewById(R.id.menu_lock);
menuLock.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), isLockMode ? R.color.panel_red : R.color.transparent));
ImageView menuLock = findViewById(R.id.menu_lock);
menuLock.setColorFilter(ContextCompat.getColor(getApplicationContext(), isLockMode ? R.color.colorAccent : R.color.lightGray));
menuLock.setOnClickListener(this::setOrientationLockMode);

View menuBrightOn = findViewById(R.id.menu_brighton);
menuBrightOn.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), isKeepMode ? R.color.panel_red : R.color.transparent));
ImageView menuBrightOn = findViewById(R.id.menu_brighton);
menuBrightOn.setColorFilter(ContextCompat.getColor(getApplicationContext(), isKeepMode ? R.color.colorAccent : R.color.lightGray));
menuBrightOn.setOnClickListener(this::setBrightOnMode);

View menuCaption = findViewById(R.id.menu_cc);
menuCaption.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), isCaptionMode ? R.color.panel_red : R.color.transparent));
ImageView menuCaption = findViewById(R.id.menu_cc);
menuCaption.setColorFilter(ContextCompat.getColor(getApplicationContext(), isCaptionMode ? R.color.colorAccent : R.color.lightGray));
menuCaption.setOnClickListener(this::setCaptionMode);

View menuKantai3d = findViewById(R.id.menu_kantai3d);
ImageView menuKantai3d = findViewById(R.id.menu_kantai3d);
if (k3dPatcher.isPatcherEnabled()) {
menuKantai3d.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), k3dPatcher.isEffectEnabled() ? R.color.panel_red : R.color.transparent));
menuKantai3d.setColorFilter(ContextCompat.getColor(getApplicationContext(), k3dPatcher.isEffectEnabled() ? R.color.colorAccent : R.color.lightGray));
menuKantai3d.setOnClickListener(this::setKantai3dMode);
} else {
menuKantai3d.setVisibility(View.GONE);
}

View menuClose = findViewById(R.id.menu_close);
menuClose.setOnClickListener(this::setPanelVisible);
menuClose.setOnClickListener(this::togglePanelVisibility);

View uiHintLayout = findViewById(R.id.ui_hint_layout);
String uiHintCheckedVer = sharedPref.getString(PREF_UI_HELP_CHECKED, "");
Expand Down Expand Up @@ -247,9 +247,7 @@ public void onBackPressed() {
// On back pressed, always show the button panel
// It is in case new users don't know tapping background shows the panel
// Or if the screen is exactly 15:9 so there is no background to tap on
isPanelVisible = true;
AnimationUtils.beginAuto(findViewById(R.id.main_container));
findViewById(R.id.browser_panel).setVisibility(View.VISIBLE);
((CustomDrawerLayout)findViewById(R.id.main_container)).openDrawer(GravityCompat.START);

backPressCloseHandler.onBackPressed();
} else {
Expand Down Expand Up @@ -340,11 +338,8 @@ public void onConfigurationChanged(Configuration newConfig) {
Log.e("GOTO", isAdjustChangedByUser + " " + isInPictureInPictureMode + " " + isMultiWindowMode());

if (isMultiWindowMode()) {
findViewById(R.id.browser_panel).setVisibility(View.GONE);
} else {
findViewById(R.id.browser_panel).setVisibility(View.VISIBLE);
View browserPanel = findViewById(R.id.browser_panel);
browserPanel.setVisibility(isPanelVisible ? View.VISIBLE : View.GONE);
// Close drawer
((CustomDrawerLayout)findViewById(R.id.main_container)).closeDrawer(GravityCompat.START);
}

if (sharedPref.getBoolean(PREF_MULTIWIN_MARGIN, false)) {
Expand All @@ -369,6 +364,8 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
}
Snackbar.make(this.findViewById(R.id.main_container), message, Snackbar.LENGTH_SHORT).show();
}
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}

Expand All @@ -386,10 +383,10 @@ private void setMuteMode(View v) {
manager.runMuteScript(mContentView, isMuteMode);
}
if (isMuteMode) {
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.panel_red));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
sharedPref.edit().putBoolean(PREF_MUTEMODE, true).apply();
} else {
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.lightGray));
sharedPref.edit().putBoolean(PREF_MUTEMODE, false).apply();
}
}
Expand All @@ -401,11 +398,11 @@ private void setCaptureMode(View v) {
isCaptureMode = !isCaptureMode;
if (isCaptureMode) {
findViewById(R.id.kc_camera).setVisibility(View.VISIBLE);
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.panel_red));
((ImageView) findViewById(R.id.menu_camera)).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
sharedPref.edit().putBoolean(PREF_CAPTURE, true).apply();
} else {
findViewById(R.id.kc_camera).setVisibility(View.GONE);
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent));
((ImageView) findViewById(R.id.menu_camera)).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.lightGray));
sharedPref.edit().putBoolean(PREF_CAPTURE, false).apply();
}
}
Expand Down Expand Up @@ -439,10 +436,10 @@ private void showStoragePermissionDialog() {
private void setOrientationLockMode(View v) {
isLockMode = !isLockMode;
if (isLockMode) {
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.panel_red));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
sharedPref.edit().putBoolean(PREF_LOCKMODE, true).apply();
} else {
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.lightGray));
sharedPref.edit().putBoolean(PREF_LOCKMODE, false).apply();
}

Expand All @@ -466,11 +463,11 @@ private void setBrightOnMode(View v) {
isKeepMode = !isKeepMode;
if (isKeepMode) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.panel_red));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
sharedPref.edit().putBoolean(PREF_KEEPMODE, true).apply();
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.lightGray));
sharedPref.edit().putBoolean(PREF_KEEPMODE, false).apply();
}
}
Expand All @@ -479,27 +476,24 @@ private void setCaptionMode(View v) {
isCaptionMode = !isCaptionMode;
if (isCaptionMode) {
subtitleText.setVisibility(View.VISIBLE);
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.panel_red));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
sharedPref.edit().putBoolean(PREF_SHOWCC, true).apply();
} else {
subtitleText.setVisibility(View.GONE);
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.lightGray));
sharedPref.edit().putBoolean(PREF_SHOWCC, false).apply();
}
}

private void initPanelKeyboardFromIntent(Intent intent) {
View browserPanel = findViewById(R.id.browser_panel);
CustomDrawerLayout drawerLayout = findViewById(R.id.main_container);

if (intent != null) {
String action = intent.getAction();
isKcBrowserMode = OPEN_KANCOLLE.equals(action);
String options = intent.getStringExtra("options");
Log.e("GOTO", "options: " + options);
if (options != null) {
isPanelVisible = options.contains(ACTION_SHOWPANEL);
browserPanel.setVisibility(isPanelVisible && !isMultiWindowMode()
? View.VISIBLE : View.GONE);
if (!options.contains(ACTION_SHOWKEYBOARD)) {
mContentView.setFocusableInTouchMode(false);
mContentView.setFocusable(false);
Expand All @@ -516,15 +510,13 @@ private void setUiHintInvisible(View v) {
sharedPref.edit().putString(PREF_UI_HELP_CHECKED, APP_UI_HELP_VER).apply();
}

public void setPanelVisibleValue(boolean value) {
isPanelVisible = value;
}

private void setPanelVisible(View v) {
isPanelVisible = !isPanelVisible;

AnimationUtils.beginAuto(findViewById(R.id.main_container));
findViewById(R.id.browser_panel).setVisibility(isPanelVisible ? View.VISIBLE : View.GONE);
private void togglePanelVisibility(View v) {
CustomDrawerLayout drawerLayout = findViewById(R.id.main_container);
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
} else {
drawerLayout.openDrawer(GravityCompat.START);
}
}

@SuppressLint("ClickableViewAccessibility")
Expand Down Expand Up @@ -566,9 +558,9 @@ public void onAnimationRepeat(Animation animation) { }
private void setKantai3dMode(View v) {
k3dPatcher.setEffectEnabled(!k3dPatcher.isEffectEnabled());
if (k3dPatcher.isEffectEnabled()) {
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.panel_red));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
} else {
v.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.transparent));
((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.lightGray));
}
}

Expand Down Expand Up @@ -716,7 +708,7 @@ public void sendIsFrontChanged (boolean is_front) {

@SuppressLint("ClickableViewAccessibility")
public void setGestureDetector(View view) {
GestureDetector mDetector = new GestureDetector(this, new BrowserGestureListener(this, this::setPanelVisible));
GestureDetector mDetector = new GestureDetector(this, new BrowserGestureListener(this, this::togglePanelVisibility));
view.setOnTouchListener((v, event) -> {
mDetector.onTouchEvent(event);
return event.getAction() != MotionEvent.ACTION_UP;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.antest1.gotobrowser.Browser;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import com.antest1.gotobrowser.R;

public class CustomDrawerLayout extends DrawerLayout
{
public CustomDrawerLayout(@NonNull Context context) {
super(context);
setScrimColor(Color.TRANSPARENT);
setDrawerElevation(0);
}

public CustomDrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setScrimColor(Color.TRANSPARENT);
setDrawerElevation(0);
}

public CustomDrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setScrimColor(Color.TRANSPARENT);
setDrawerElevation(0);
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (!this.isDrawerOpen(Gravity.LEFT)) {
return super.dispatchTouchEvent(event);
}

// Only pass the event to main panel if not handled by side panel
// To avoid touching both at the same time
boolean handledBySidePanel = getChildAt(1).dispatchTouchEvent(event);
if (!handledBySidePanel) {
getChildAt(0).dispatchTouchEvent(event);
}

boolean clickedOutside = false;
if (event.getAction() == MotionEvent.ACTION_UP) {
View content = findViewById(R.id.navigation);
int[] contentLocation = new int[2];
content.getLocationOnScreen(contentLocation);
Rect rect = new Rect(contentLocation[0],
contentLocation[1],
contentLocation[0] + content.getWidth(),
contentLocation[1] + content.getHeight());
clickedOutside = !(rect.contains((int) event.getX(), (int) event.getY()));
}

if (clickedOutside) {
this.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
return true;
}
this.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
return super.dispatchTouchEvent(event);
}
}

This file was deleted.

Loading

0 comments on commit 2170b8f

Please sign in to comment.