mirror of
https://github.com/status-im/syng-client.git
synced 2025-02-22 16:08:11 +00:00
Implemented toolbar animation for dapp webview.
This commit is contained in:
parent
1cee37e123
commit
98c9d27537
@ -33,6 +33,8 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
@ -74,6 +76,23 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
private EditText mSearchTextView;
|
||||
private DrawerLayout mDrawerLayout;
|
||||
|
||||
Toolbar topToolbar;
|
||||
boolean isTopToolbarShown = true;
|
||||
Runnable mShowToolbarRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
topToolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
|
||||
isTopToolbarShown = true;
|
||||
}
|
||||
};
|
||||
Runnable mHideToolbarRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
topToolbar.animate().translationY(-topToolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
|
||||
isTopToolbarShown = false;
|
||||
}
|
||||
};
|
||||
Handler mTopToolbarHandler = new Handler();
|
||||
|
||||
private View mFrontView;
|
||||
private View mBackView;
|
||||
@ -105,14 +124,14 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
|
||||
FrameLayout content = (FrameLayout) findViewById(R.id.content);
|
||||
ViewGroup inflated = (ViewGroup) inflater.inflate(layoutResID, content, true);
|
||||
Toolbar toolbar = (Toolbar) inflated.findViewById(R.id.app_toolbar);
|
||||
topToolbar = (Toolbar) inflated.findViewById(R.id.app_toolbar);
|
||||
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
if (topToolbar != null) {
|
||||
setSupportActionBar(topToolbar);
|
||||
mDrawerLayout.setStatusBarBackgroundColor(ContextCompat.getColor(this, android.R.color.black));
|
||||
}
|
||||
|
||||
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
|
||||
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, topToolbar,
|
||||
R.string.drawer_open, R.string.drawer_close) {
|
||||
@Override
|
||||
public void onDrawerClosed(View drawerView) {
|
||||
@ -180,6 +199,19 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
ProfileManager.setProfilesChangeListener(this);
|
||||
}
|
||||
|
||||
public void hideToolbar(int seconds) {
|
||||
if (isTopToolbarShown) {
|
||||
isTopToolbarShown = false;
|
||||
mTopToolbarHandler.postDelayed(mHideToolbarRunnable, seconds * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public void showToolbar(int seconds) {
|
||||
if (!isTopToolbarShown) {
|
||||
isTopToolbarShown = true;
|
||||
mTopToolbarHandler.postDelayed(mShowToolbarRunnable, seconds * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private void populateProfiles() {
|
||||
mProfileDrawerAdapter.swapData(ProfileManager.getProfiles());
|
||||
|
@ -15,7 +15,9 @@ import android.graphics.Color;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
@ -35,10 +37,12 @@ import org.apache.cordova.PluginManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.syng.activity.BaseActivity;
|
||||
import io.syng.app.SyngApplication;
|
||||
import io.syng.cordova.plugin.WebViewEngine;
|
||||
|
||||
|
||||
public class WebViewFragment extends Fragment {
|
||||
public class WebViewFragment extends Fragment implements View.OnTouchListener, GestureDetector.OnGestureListener {
|
||||
|
||||
private static final String DEFAULT_DAPP = "dapp://syng.io/dapps/wallet";
|
||||
|
||||
@ -50,6 +54,8 @@ public class WebViewFragment extends Fragment {
|
||||
protected boolean keepRunning = true;
|
||||
protected boolean immersiveMode;
|
||||
|
||||
protected GestureDetector gestureDetector;
|
||||
|
||||
protected String url;
|
||||
|
||||
/*
|
||||
@ -159,6 +165,72 @@ public class WebViewFragment extends Fragment {
|
||||
if ("media".equals(volumePref.toLowerCase(Locale.ENGLISH))) {
|
||||
getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
}
|
||||
BaseActivity activity = (BaseActivity)getActivity();
|
||||
activity.hideToolbar(2);
|
||||
gestureDetector = new GestureDetector(webView.getContext(), this);
|
||||
webView.getView().setOnTouchListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
|
||||
|
||||
return gestureDetector.onTouchEvent(motionEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX, float velocityY) { float gapX = start.getRawX() - finish.getRawX();
|
||||
float gapY = start.getRawY() - finish.getRawY();
|
||||
float distanceX = Math.abs(gapX);
|
||||
float distanceY = Math.abs(gapY);
|
||||
|
||||
if (distanceY > distanceX) { // up downs
|
||||
if (gapY > 0) {
|
||||
// up
|
||||
System.out.println("Swipe up");
|
||||
} else {
|
||||
// down
|
||||
System.out.println("Swipe down");
|
||||
BaseActivity activity = (BaseActivity)getActivity();
|
||||
activity.showToolbar(0);
|
||||
activity.hideToolbar(2);
|
||||
}
|
||||
} else { // left right
|
||||
if (gapX > 0) {
|
||||
// left
|
||||
System.out.println("Swipe left");
|
||||
} else {
|
||||
// rights
|
||||
System.out.println("Swipe right");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent motionEvent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent motionEvent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowPress(MotionEvent motionEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent motionEvent) {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -167,6 +239,7 @@ public class WebViewFragment extends Fragment {
|
||||
parser.parse(getActivity());
|
||||
preferences = parser.getPreferences();
|
||||
preferences.setPreferencesBundle(getActivity().getIntent().getExtras());
|
||||
//preferences.set("webview", "io.syng.cordova.plugin.WebViewEngine");
|
||||
pluginEntries = parser.getPluginEntries();
|
||||
Config.init(getActivity());
|
||||
}
|
||||
@ -178,12 +251,8 @@ public class WebViewFragment extends Fragment {
|
||||
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
// p.addRule(RelativeLayout.BELOW, R.id.myToolbar);
|
||||
webView.getView().setLayoutParams(p);
|
||||
|
||||
// RelativeLayout rl = (RelativeLayout)view.findViewById(R.id.web_view_layout);
|
||||
// rl.addView(webView.getView());
|
||||
|
||||
if (preferences.contains("BackgroundColor")) {
|
||||
int backgroundColor = preferences.getInteger("BackgroundColor", Color.BLACK);
|
||||
// Background of activity:
|
||||
@ -238,6 +307,8 @@ public class WebViewFragment extends Fragment {
|
||||
boolean keepRunning = this.keepRunning;// || this.cordovaInterface.activityResultCallback != null;
|
||||
this.webView.handlePause(keepRunning);
|
||||
}
|
||||
BaseActivity activity = (BaseActivity)getActivity();
|
||||
activity.showToolbar(0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user