1
0
mirror of https://github.com/MGislv/NekoX.git synced 2024-06-30 10:14:04 +00:00

Different improvements

This commit is contained in:
DrKLO 2014-11-07 13:23:17 +03:00
parent 059035a54c
commit 65e93f91bb
7 changed files with 377 additions and 351 deletions

View File

@ -25,7 +25,7 @@ dependencies {
android {
compileSdkVersion 21
buildToolsVersion '21.1.0'
buildToolsVersion '21.1.1'
signingConfigs {
debug {

View File

@ -35,6 +35,7 @@ import org.telegram.ui.Views.NumberPicker;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Hashtable;
public class AndroidUtilities {
@ -443,4 +444,25 @@ public class AndroidUtilities {
return dp(56);
}
}
public static Point getRealScreenSize() {
Point size = new Point();
try {
WindowManager windowManager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
windowManager.getDefaultDisplay().getRealSize(size);
} else {
try {
Method mGetRawW = Display.class.getMethod("getRawWidth");
Method mGetRawH = Display.class.getMethod("getRawHeight");
size.set((Integer) mGetRawW.invoke(windowManager.getDefaultDisplay()), (Integer) mGetRawH.invoke(windowManager.getDefaultDisplay()));
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return size;
}
}

View File

@ -38,9 +38,7 @@ import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import org.telegram.android.video.InputSurface;
import org.telegram.android.video.MP4Builder;
@ -62,7 +60,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
@ -739,29 +736,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public void processMediaObserver(Uri uri) {
try {
int width = 0;
int height = 0;
try {
WindowManager windowManager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Point size = new Point();
windowManager.getDefaultDisplay().getRealSize(size);
width = size.x;
height = size.y;
} else {
try {
Method mGetRawW = Display.class.getMethod("getRawWidth");
Method mGetRawH = Display.class.getMethod("getRawHeight");
width = (Integer) mGetRawW.invoke(windowManager.getDefaultDisplay());
height = (Integer) mGetRawH.invoke(windowManager.getDefaultDisplay());
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
Point size = AndroidUtilities.getRealScreenSize();
Cursor cursor = ApplicationLoader.applicationContext.getContentResolver().query(uri, mediaProjections, null, null, "date_added DESC LIMIT 1");
final ArrayList<Long> screenshotDates = new ArrayList<Long>();
@ -791,7 +766,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
photoW = bmOptions.outWidth;
photoH = bmOptions.outHeight;
}
if (photoW <= 0 || photoH <= 0 || (photoW == width && photoH == height || photoH == width && photoW == height)) {
if (photoW <= 0 || photoH <= 0 || (photoW == size.x && photoH == size.y || photoH == size.x && photoW == size.y)) {
screenshotDates.add(date);
}
} catch (Exception e) {

View File

@ -14,6 +14,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@ -46,6 +47,7 @@ import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Views.ActionBar.ActionBarLayout;
import org.telegram.ui.Views.ActionBar.BaseFragment;
import org.telegram.ui.Views.ActionBar.DrawerLayoutContainer;
import java.io.BufferedReader;
import java.io.InputStream;
@ -231,15 +233,24 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
});
} else {
setContentView(actionBarLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
DrawerLayoutContainer drawerLayoutContainer = new DrawerLayoutContainer(this);
drawerLayoutContainer.setStatusBarColor(0xff54759e);
drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
FrameLayout frameLayout = new FrameLayout(this);
drawerLayoutContainer.setDrawerLayout(frameLayout);
frameLayout.setBackgroundColor(0xffff0000);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)frameLayout.getLayoutParams();
Point screenSize = AndroidUtilities.getRealScreenSize();
layoutParams.width = Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56);
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
frameLayout.setLayoutParams(layoutParams);
setContentView(drawerLayoutContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBarLayout.setDrawerLayout(drawerLayoutContainer);
actionBarLayout.setAllowOpenDrawer(true);
}
actionBarLayout.init(mainFragmentsStack);
actionBarLayout.setDelegate(this);
if (Build.VERSION.SDK_INT >= 21) {
actionBarLayout.setNeedStatusBar(true);
actionBarLayout.setStatusBarColor(0xff54759e);
}
actionBarLayout.createDrawerLayout();
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {

View File

@ -17,6 +17,7 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ScrollView;
@ -127,6 +128,18 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe
return fragmentView;
}
@Override
public void onPause() {
super.onPause();
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
@Override
public void onResume() {
super.onResume();
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
private void saveCurrentState() {
try {
Bundle bundle = new Bundle();

View File

@ -11,8 +11,6 @@ package org.telegram.ui.Views.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.os.Handler;
import android.view.ActionMode;
@ -66,10 +64,9 @@ public class ActionBarLayout extends FrameLayout {
private FrameLayoutAnimationListener containerView;
private FrameLayoutAnimationListener containerViewBack;
private View shadowView;
private DrawerLayout drawerLayout;
private DrawerLayoutContainer drawerLayoutContainer;
private boolean needStatusBar;
private Paint statusBarPaint = new Paint();
private boolean allowOpenDrawer;
private Animation openAnimation;
private Animation closeAnimation;
@ -137,10 +134,6 @@ public class ActionBarLayout extends FrameLayout {
fragment.setParentLayout(this);
}
if (drawerLayout != null) {
bringChildToFront(drawerLayout);
}
needLayout();
}
@ -154,14 +147,6 @@ public class ActionBarLayout extends FrameLayout {
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (needStatusBar) {
canvas.drawRect(0, 0, getWidth(), AndroidUtilities.statusBarHeight, statusBarPaint);
}
}
public void onResume() {
fixLayout();
if (transitionAnimationInProgress) {
@ -232,9 +217,6 @@ public class ActionBarLayout extends FrameLayout {
parent.bringChildToFront(containerView);
parent.bringChildToFront(shadowView);
parent.bringChildToFront(actionBar);
if (drawerLayout != null) {
parent.bringChildToFront(drawerLayout);
}
//parent.removeViewInLayout(containerView);
//parent.addView(containerView, 1);
lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
@ -261,6 +243,14 @@ public class ActionBarLayout extends FrameLayout {
ViewProxy.setTranslationX(shadowView, -AndroidUtilities.dp(2));
}
private void prepareForDrawerOpen(MotionEvent ev) {
maybeStartTracking = false;
startedTracking = true;
startedTrackingX = (int) ev.getX();
beginTrackingSent = false;
AndroidUtilities.lockOrientation(parentActivity);
}
private void prepareForMoving(MotionEvent ev) {
maybeStartTracking = false;
startedTracking = true;
@ -291,108 +281,181 @@ public class ActionBarLayout extends FrameLayout {
}
public boolean onTouchEvent(MotionEvent ev) {
if(!checkTransitionAnimation() && !inActionMode && fragmentsStack.size() > 1 && !animationInProgress) {
if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
if (!currentFragment.swipeBackEnabled) {
return false;
}
startedTrackingPointerId = ev.getPointerId(0);
maybeStartTracking = true;
startedTrackingX = (int) ev.getX();
startedTrackingY = (int) ev.getY();
if (velocityTracker != null) {
velocityTracker.clear();
}
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
int dy = Math.abs((int)ev.getY() - startedTrackingY);
velocityTracker.addMovement(ev);
if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.dp(10) && Math.abs(dx) / 3 > dy) {
prepareForMoving(ev);
} else if (startedTracking) {
if (!beginTrackingSent) {
if (parentActivity.getCurrentFocus() != null) {
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
}
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
currentFragment.onBeginSlide();
beginTrackingSent = true;
if(!checkTransitionAnimation() && !inActionMode && !animationInProgress) {
if (fragmentsStack.size() > 1) {
if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
if (!currentFragment.swipeBackEnabled) {
return false;
}
actionBar.moveActionBarByX(dx);
ViewProxy.setTranslationX(containerView, dx);
ViewProxy.setTranslationX(shadowView, dx - AndroidUtilities.dp(2));
}
} else if (ev != null && ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
velocityTracker.computeCurrentVelocity(1000);
if (!startedTracking) {
float velX = velocityTracker.getXVelocity();
float velY = velocityTracker.getYVelocity();
if (velX >= 3500 && velX > velY) {
startedTrackingPointerId = ev.getPointerId(0);
maybeStartTracking = true;
startedTrackingX = (int) ev.getX();
startedTrackingY = (int) ev.getY();
if (velocityTracker != null) {
velocityTracker.clear();
}
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
int dy = Math.abs((int) ev.getY() - startedTrackingY);
velocityTracker.addMovement(ev);
if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.dp(10) && Math.abs(dx) / 3 > dy) {
prepareForMoving(ev);
} else if (startedTracking) {
if (!beginTrackingSent) {
if (parentActivity.getCurrentFocus() != null) {
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
}
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
currentFragment.onBeginSlide();
beginTrackingSent = true;
}
actionBar.moveActionBarByX(dx);
ViewProxy.setTranslationX(containerView, dx);
ViewProxy.setTranslationX(shadowView, dx - AndroidUtilities.dp(2));
}
}
if (startedTracking) {
float x = ViewProxy.getX(containerView);
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
float velX = velocityTracker.getXVelocity();
float velY = velocityTracker.getYVelocity();
final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f && (velX < 3500 || velX < velY);
float distToMove = 0;
if (!backAnimation) {
distToMove = containerView.getMeasuredWidth() - x;
animatorSet.playTogether(
ObjectAnimatorProxy.ofFloat(containerView, "x", containerView.getMeasuredWidth()),
ObjectAnimatorProxy.ofFloat(shadowView, "x", containerView.getMeasuredWidth() - AndroidUtilities.dp(2)),
ObjectAnimatorProxy.ofFloat(actionBar.currentLayer, "x", actionBar.getMeasuredWidth()),
ObjectAnimatorProxy.ofFloat(actionBar.shadowView, "x", actionBar.getMeasuredWidth() - AndroidUtilities.dp(2)),
ObjectAnimatorProxy.ofFloat(actionBar.previousLayer, "alphaEx", 1.0f)
);
} else if (ev != null && ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
velocityTracker.computeCurrentVelocity(1000);
if (!startedTracking) {
float velX = velocityTracker.getXVelocity();
float velY = velocityTracker.getYVelocity();
if (velX >= 3500 && velX > velY) {
prepareForMoving(ev);
}
}
if (startedTracking) {
float x = ViewProxy.getX(containerView);
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
float velX = velocityTracker.getXVelocity();
float velY = velocityTracker.getYVelocity();
final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f && (velX < 3500 || velX < velY);
float distToMove = 0;
if (!backAnimation) {
distToMove = containerView.getMeasuredWidth() - x;
animatorSet.playTogether(
ObjectAnimatorProxy.ofFloat(containerView, "x", containerView.getMeasuredWidth()),
ObjectAnimatorProxy.ofFloat(shadowView, "x", containerView.getMeasuredWidth() - AndroidUtilities.dp(2)),
ObjectAnimatorProxy.ofFloat(actionBar.currentLayer, "x", actionBar.getMeasuredWidth()),
ObjectAnimatorProxy.ofFloat(actionBar.shadowView, "x", actionBar.getMeasuredWidth() - AndroidUtilities.dp(2)),
ObjectAnimatorProxy.ofFloat(actionBar.previousLayer, "alphaEx", 1.0f)
);
} else {
distToMove = x;
animatorSet.playTogether(
ObjectAnimatorProxy.ofFloat(containerView, "x", 0),
ObjectAnimatorProxy.ofFloat(shadowView, "x", -AndroidUtilities.dp(2)),
ObjectAnimatorProxy.ofFloat(actionBar.currentLayer, "x", 0),
ObjectAnimatorProxy.ofFloat(actionBar.shadowView, "x", -AndroidUtilities.dp(2)),
ObjectAnimatorProxy.ofFloat(actionBar.previousLayer, "alphaEx", 0)
);
}
animatorSet.setDuration(Math.max((int) (200.0f / containerView.getMeasuredWidth() * distToMove), 50));
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Object animator) {
onSlideAnimationEnd(backAnimation);
}
@Override
public void onAnimationCancel(Object animator) {
onSlideAnimationEnd(backAnimation);
}
});
animatorSet.start();
animationInProgress = true;
} else {
distToMove = x;
animatorSet.playTogether(
ObjectAnimatorProxy.ofFloat(containerView, "x", 0),
ObjectAnimatorProxy.ofFloat(shadowView, "x", -AndroidUtilities.dp(2)),
ObjectAnimatorProxy.ofFloat(actionBar.currentLayer, "x", 0),
ObjectAnimatorProxy.ofFloat(actionBar.shadowView, "x", -AndroidUtilities.dp(2)),
ObjectAnimatorProxy.ofFloat(actionBar.previousLayer, "alphaEx", 0)
);
maybeStartTracking = false;
startedTracking = false;
}
animatorSet.setDuration(Math.max((int) (200.0f / containerView.getMeasuredWidth() * distToMove), 50));
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Object animator) {
onSlideAnimationEnd(backAnimation);
}
@Override
public void onAnimationCancel(Object animator) {
onSlideAnimationEnd(backAnimation);
}
});
animatorSet.start();
animationInProgress = true;
} else {
if (velocityTracker != null) {
velocityTracker.recycle();
velocityTracker = null;
}
} else if (ev == null) {
maybeStartTracking = false;
startedTracking = false;
if (velocityTracker != null) {
velocityTracker.recycle();
velocityTracker = null;
}
}
if (velocityTracker != null) {
velocityTracker.recycle();
velocityTracker = null;
}
} else if (ev == null) {
maybeStartTracking = false;
startedTracking = false;
if (velocityTracker != null) {
velocityTracker.recycle();
velocityTracker = null;
} else if (drawerLayoutContainer != null && allowOpenDrawer && fragmentsStack.size() == 1) {
if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
startedTrackingPointerId = ev.getPointerId(0);
maybeStartTracking = true;
startedTrackingX = (int) ev.getX();
startedTrackingY = (int) ev.getY();
if (velocityTracker != null) {
velocityTracker.clear();
}
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
int dx = (int) (ev.getX() - startedTrackingX);
int dy = Math.abs((int) ev.getY() - startedTrackingY);
velocityTracker.addMovement(ev);
if (maybeStartTracking && !startedTracking && Math.abs(dx) >= AndroidUtilities.dp(10) && Math.abs(dx) / 3 > dy) {
prepareForDrawerOpen(ev);
} else if (startedTracking) {
if (!beginTrackingSent) {
if (parentActivity.getCurrentFocus() != null) {
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
}
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
currentFragment.onBeginSlide();
beginTrackingSent = true;
}
drawerLayoutContainer.moveDrawerByX(dx);
}
} else if (ev != null && ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
velocityTracker.computeCurrentVelocity(1000);
if (!startedTracking) {
float velX = velocityTracker.getXVelocity();
float velY = velocityTracker.getYVelocity();
if (Math.abs(velX) >= 3500 && velX > velY) {
prepareForDrawerOpen(ev);
}
}
if (startedTracking) {
float x = ViewProxy.getX(containerView);
float velX = velocityTracker.getXVelocity();
float velY = velocityTracker.getYVelocity();
final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f && (velX < 3500 || velX < velY);
float distToMove = 0;
if (!backAnimation) {
drawerLayoutContainer.openDrawer();
} else {
drawerLayoutContainer.closeDrawer();
}
AndroidUtilities.unlockOrientation(parentActivity);
startedTracking = false;
animationInProgress = false; //TODO animation check
} else {
maybeStartTracking = false;
startedTracking = false;
}
if (velocityTracker != null) {
velocityTracker.recycle();
velocityTracker = null;
}
} else if (ev == null) {
maybeStartTracking = false;
startedTracking = false;
if (velocityTracker != null) {
velocityTracker.recycle();
velocityTracker = null;
}
}
}
return startedTracking;
@ -462,15 +525,7 @@ public class ActionBarLayout extends FrameLayout {
if (actionBar.getVisibility() == View.VISIBLE) {
height = AndroidUtilities.getCurrentActionBarHeight();
}
if (needStatusBar) {
height += AndroidUtilities.statusBarHeight;
}
if (actionBar != null) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) actionBar.getLayoutParams();
layoutParams.topMargin = needStatusBar ? AndroidUtilities.statusBarHeight : 0;
actionBar.setLayoutParams(layoutParams);
}
if (containerView != null) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) containerView.getLayoutParams();
if (layoutParams.topMargin != height) {
@ -560,9 +615,6 @@ public class ActionBarLayout extends FrameLayout {
parent.bringChildToFront(containerView);
parent.bringChildToFront(shadowView);
parent.bringChildToFront(actionBar);
if (drawerLayout != null) {
parent.bringChildToFront(drawerLayout);
}
if (!needAnimation) {
presentFragmentInternalRemoveOld(removeLast, currentFragment);
@ -857,22 +909,11 @@ public class ActionBarLayout extends FrameLayout {
backgroundView = view;
}
public void setNeedStatusBar(boolean value) {
needStatusBar = value;
setWillNotDraw(!needStatusBar);
public void setDrawerLayout(DrawerLayoutContainer layout) {
drawerLayoutContainer = layout;
}
public void setStatusBarColor(int color) {
statusBarPaint.setColor(color);
}
public void createDrawerLayout() {
drawerLayout = new DrawerLayout(getContext());
addView(drawerLayout);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)drawerLayout.getLayoutParams();
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
layoutParams.width = AndroidUtilities.dp(100);
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
drawerLayout.setLayoutParams(layoutParams);
public void setAllowOpenDrawer(boolean value) {
allowOpenDrawer = value;
}
}

View File

@ -9,6 +9,8 @@
package org.telegram.ui.Views.ActionBar;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
@ -16,13 +18,25 @@ import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.FrameLayout;
public class DrawerLayout extends FrameLayout {
import org.telegram.android.AndroidUtilities;
import org.telegram.ui.AnimationCompat.ViewProxy;
private Object mLastInsets;
public class DrawerLayoutContainer extends FrameLayout {
public DrawerLayout(Context context) {
private static final int MIN_DRAWER_MARGIN = 64;
private View drawerLayout;
private Paint statusBarPaint = new Paint();
private Object lastInsets;
private boolean inLayout;
private int minDrawerMargin;
private float drawerOffset;
public DrawerLayoutContainer(Context context) {
super(context);
minDrawerMargin = (int) (MIN_DRAWER_MARGIN * AndroidUtilities.density + 0.5f);
setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
setFocusableInTouchMode(true);
@ -32,23 +46,23 @@ public class DrawerLayout extends FrameLayout {
}
}
static class InsetsListener implements View.OnApplyWindowInsetsListener {
private class InsetsListener implements View.OnApplyWindowInsetsListener {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
final DrawerLayout drawerLayout = (DrawerLayout) v;
final DrawerLayoutContainer drawerLayout = (DrawerLayoutContainer) v;
drawerLayout.setChildInsets(insets, insets.getSystemWindowInsetTop() > 0);
return insets.consumeSystemWindowInsets();
}
}
public void configureApplyInsets(View drawerLayout) {
private void configureApplyInsets(View drawerLayout) {
if (Build.VERSION.SDK_INT >= 21) {
drawerLayout.setOnApplyWindowInsetsListener(new InsetsListener());
drawerLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
}
public void dispatchChildInsets(View child, Object insets, int drawerGravity) {
private void dispatchChildInsets(View child, Object insets, int drawerGravity) {
WindowInsets wi = (WindowInsets) insets;
if (drawerGravity == Gravity.LEFT) {
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
@ -58,7 +72,7 @@ public class DrawerLayout extends FrameLayout {
child.dispatchApplyWindowInsets(wi);
}
public void applyMarginInsets(MarginLayoutParams lp, Object insets, int drawerGravity) {
private void applyMarginInsets(MarginLayoutParams lp, Object insets, int drawerGravity) {
WindowInsets wi = (WindowInsets) insets;
if (drawerGravity == Gravity.LEFT) {
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
@ -71,19 +85,135 @@ public class DrawerLayout extends FrameLayout {
lp.bottomMargin = wi.getSystemWindowInsetBottom();
}
public int getTopInset(Object insets) {
private int getTopInset(Object insets) {
if (Build.VERSION.SDK_INT >= 21) {
return insets != null ? ((WindowInsets) insets).getSystemWindowInsetTop() : 0;
}
return 0;
}
public void setChildInsets(Object insets, boolean draw) {
mLastInsets = insets;
private void setChildInsets(Object insets, boolean draw) {
lastInsets = insets;
setWillNotDraw(!draw && getBackground() == null);
requestLayout();
}
public void setStatusBarColor(int color) {
statusBarPaint.setColor(color);
}
public void setDrawerLayout(View layout) {
drawerLayout = layout;
addView(drawerLayout);
if (Build.VERSION.SDK_INT >= 21) {
drawerLayout.setFitsSystemWindows(true);
}
}
public void moveDrawerByX(int dx) {
if (dx > drawerLayout.getMeasuredWidth()) {
dx = drawerLayout.getMeasuredWidth();
}
ViewProxy.setTranslationX(drawerLayout, dx);
final int newVisibility = dx > 0 ? VISIBLE : INVISIBLE;
if (drawerLayout.getVisibility() != newVisibility) {
drawerLayout.setVisibility(newVisibility);
}
}
public void openDrawer() {
}
public void closeDrawer() {
}
public View getDrawerLayout() {
return drawerLayout;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (Build.VERSION.SDK_INT >= 21) {
canvas.drawRect(0, 0, getWidth(), AndroidUtilities.statusBarHeight, statusBarPaint);
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
inLayout = true;
final int width = r - l;
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (drawerLayout != child) {
child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight());
} else {
child.layout(-child.getMeasuredWidth(), lp.topMargin, 0, lp.topMargin + child.getMeasuredHeight());
}
}
inLayout = false;
}
@Override
public void requestLayout() {
if (!inLayout) {
super.requestLayout();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
final boolean applyInsets = lastInsets != null && Build.VERSION.SDK_INT >= 21;
int foundDrawers = 0;
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (applyInsets) {
if (child.getFitsSystemWindows()) {
dispatchChildInsets(child, lastInsets, lp.gravity);
} else {
applyMarginInsets(lp, lastInsets, lp.gravity);
}
}
if (drawerLayout != child) {
final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
final int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
child.measure(contentWidthSpec, contentHeightSpec);
} else {
final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, minDrawerMargin + lp.leftMargin + lp.rightMargin, lp.width);
final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin, lp.height);
child.measure(drawerWidthSpec, drawerHeightSpec);
}
}
}
/*private static final int MIN_DRAWER_MARGIN = 64; // dp
@ -164,18 +294,6 @@ public class DrawerLayout extends FrameLayout {
}
}
static {
final int version = Build.VERSION.SDK_INT;
if (version >= 21) {
IMPL = new DrawerLayoutCompatImplApi21();
} else {
IMPL = new DrawerLayoutCompatImplBase();
}
}
static final DrawerLayoutCompatImpl IMPL;
public void setDrawerShadow(Drawable shadowDrawable, @EdgeGravity int gravity) {
final int absGravity = GravityCompat.getAbsoluteGravity(gravity,
@ -465,160 +583,6 @@ public class DrawerLayout extends FrameLayout {
mFirstLayout = true;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
final boolean applyInsets = mLastInsets != null && ViewCompat.getFitsSystemWindows(this);
final int layoutDirection = ViewCompat.getLayoutDirection(this);
// Gravity value for each drawer we've seen. Only one of each permitted.
int foundDrawers = 0;
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (applyInsets) {
final int cgrav = GravityCompat.getAbsoluteGravity(lp.gravity, layoutDirection);
if (ViewCompat.getFitsSystemWindows(child)) {
IMPL.dispatchChildInsets(child, mLastInsets, cgrav);
} else {
IMPL.applyMarginInsets(lp, mLastInsets, cgrav);
}
}
if (isContentView(child)) {
// Content views get measured at exactly the layout's size.
final int contentWidthSpec = MeasureSpec.makeMeasureSpec(
widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
final int contentHeightSpec = MeasureSpec.makeMeasureSpec(
heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
child.measure(contentWidthSpec, contentHeightSpec);
} else if (isDrawerView(child)) {
final int childGravity =
getDrawerViewAbsoluteGravity(child) & Gravity.HORIZONTAL_GRAVITY_MASK;
if ((foundDrawers & childGravity) != 0) {
throw new IllegalStateException("Child drawer has absolute gravity " +
gravityToString(childGravity) + " but this " + TAG + " already has a " +
"drawer view along that edge");
}
final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec,
mMinDrawerMargin + lp.leftMargin + lp.rightMargin,
lp.width);
final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec,
lp.topMargin + lp.bottomMargin,
lp.height);
child.measure(drawerWidthSpec, drawerHeightSpec);
} else {
throw new IllegalStateException("Child " + child + " at index " + i +
" does not have a valid layout_gravity - must be Gravity.LEFT, " +
"Gravity.RIGHT or Gravity.NO_GRAVITY");
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
mInLayout = true;
final int width = r - l;
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (isContentView(child)) {
child.layout(lp.leftMargin, lp.topMargin,
lp.leftMargin + child.getMeasuredWidth(),
lp.topMargin + child.getMeasuredHeight());
} else { // Drawer, if it wasn't onMeasure would have thrown an exception.
final int childWidth = child.getMeasuredWidth();
final int childHeight = child.getMeasuredHeight();
int childLeft;
final float newOffset;
if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
childLeft = -childWidth + (int) (childWidth * lp.onScreen);
newOffset = (float) (childWidth + childLeft) / childWidth;
} else { // Right; onMeasure checked for us.
childLeft = width - (int) (childWidth * lp.onScreen);
newOffset = (float) (width - childLeft) / childWidth;
}
final boolean changeOffset = newOffset != lp.onScreen;
final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (vgrav) {
default:
case Gravity.TOP: {
child.layout(childLeft, lp.topMargin, childLeft + childWidth,
lp.topMargin + childHeight);
break;
}
case Gravity.BOTTOM: {
final int height = b - t;
child.layout(childLeft,
height - lp.bottomMargin - child.getMeasuredHeight(),
childLeft + childWidth,
height - lp.bottomMargin);
break;
}
case Gravity.CENTER_VERTICAL: {
final int height = b - t;
int childTop = (height - childHeight) / 2;
// Offset for margins. If things don't fit right because of
// bad measurement before, oh well.
if (childTop < lp.topMargin) {
childTop = lp.topMargin;
} else if (childTop + childHeight > height - lp.bottomMargin) {
childTop = height - lp.bottomMargin - childHeight;
}
child.layout(childLeft, childTop, childLeft + childWidth,
childTop + childHeight);
break;
}
}
if (changeOffset) {
setDrawerViewOffset(child, newOffset);
}
final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE;
if (child.getVisibility() != newVisibility) {
child.setVisibility(newVisibility);
}
}
}
mInLayout = false;
mFirstLayout = false;
}
@Override
public void requestLayout() {
if (!mInLayout) {
super.requestLayout();
}
}
@Override
public void computeScroll() {
final int childCount = getChildCount();