2014-06-04 01:31:48 +02:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 1.4.x.
|
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013-2014.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Views.ActionBar;
|
|
|
|
|
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2014-06-04 01:31:48 +02:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.Utilities;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class ActionBar extends FrameLayout {
|
|
|
|
|
|
|
|
private static Drawable logoDrawable;
|
|
|
|
protected ActionBarLayer currentLayer = null;
|
|
|
|
private ActionBarLayer previousLayer = null;
|
|
|
|
private View shadowView = null;
|
2014-06-12 17:53:20 +02:00
|
|
|
private boolean isBackOverlayVisible;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
public ActionBar(Context context) {
|
|
|
|
super(context);
|
|
|
|
createComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionBar(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
createComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
createComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void createComponents() {
|
|
|
|
shadowView = new View(getContext());
|
|
|
|
addView(shadowView);
|
|
|
|
shadowView.setVisibility(INVISIBLE);
|
|
|
|
ViewGroup.LayoutParams layoutParams = shadowView.getLayoutParams();
|
2014-07-03 00:39:05 +02:00
|
|
|
layoutParams.width = AndroidUtilities.dp(2);
|
2014-06-04 01:31:48 +02:00
|
|
|
layoutParams.height = LayoutParams.MATCH_PARENT;
|
|
|
|
shadowView.setLayoutParams(layoutParams);
|
|
|
|
shadowView.setBackgroundResource(R.drawable.shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionBarLayer createLayer() {
|
|
|
|
return new ActionBarLayer(getContext(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void detachActionBarLayer(ActionBarLayer layer) {
|
|
|
|
if (layer == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
removeView(layer);
|
|
|
|
if (currentLayer == layer) {
|
|
|
|
currentLayer = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCurrentActionBarLayer(ActionBarLayer layer) {
|
|
|
|
if (layer == null || layer.getParent() != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentLayer != null) {
|
|
|
|
removeView(currentLayer);
|
|
|
|
}
|
|
|
|
currentLayer = layer;
|
|
|
|
addView(layer);
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)layer.getLayoutParams();
|
|
|
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
layer.setLayoutParams(layoutParams);
|
2014-06-12 17:53:20 +02:00
|
|
|
currentLayer.setBackOverlayVisible(isBackOverlayVisible);
|
2014-06-04 01:31:48 +02:00
|
|
|
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
|
|
|
layer.setAlpha(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-12 17:53:20 +02:00
|
|
|
public void setBackOverlayVisible(boolean visible) {
|
|
|
|
isBackOverlayVisible = visible;
|
2014-06-04 01:31:48 +02:00
|
|
|
if (currentLayer != null) {
|
2014-06-12 17:53:20 +02:00
|
|
|
currentLayer.setBackOverlayVisible(visible);
|
|
|
|
}
|
|
|
|
if (previousLayer != null) {
|
|
|
|
previousLayer.setBackOverlayVisible(visible);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void prepareForMoving(ActionBarLayer layer) {
|
|
|
|
if (currentLayer == null || layer == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
previousLayer = layer;
|
|
|
|
ViewGroup parent = (ViewGroup) previousLayer.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(previousLayer);
|
|
|
|
}
|
|
|
|
this.addView(previousLayer, 0);
|
|
|
|
ViewGroup.LayoutParams layoutParams = layer.getLayoutParams();
|
|
|
|
layoutParams.width = LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutParams.MATCH_PARENT;
|
|
|
|
layer.setLayoutParams(layoutParams);
|
2014-07-03 00:39:05 +02:00
|
|
|
shadowView.setX(-AndroidUtilities.dp(2));
|
2014-06-04 01:31:48 +02:00
|
|
|
shadowView.setVisibility(VISIBLE);
|
2014-06-12 17:53:20 +02:00
|
|
|
previousLayer.setBackOverlayVisible(isBackOverlayVisible);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void stopMoving(boolean backAnimation) {
|
|
|
|
if (currentLayer == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentLayer.setX(0);
|
|
|
|
if (!backAnimation) {
|
|
|
|
removeView(currentLayer);
|
|
|
|
currentLayer = previousLayer;
|
|
|
|
currentLayer.setAlpha(1);
|
2014-06-12 17:53:20 +02:00
|
|
|
previousLayer = null;
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
|
|
|
removeView(previousLayer);
|
|
|
|
previousLayer = null;
|
|
|
|
}
|
|
|
|
shadowView.setVisibility(INVISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void moveActionBarByX(int dx) {
|
|
|
|
if (currentLayer == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentLayer.setX(dx);
|
2014-07-03 00:39:05 +02:00
|
|
|
shadowView.setX(dx - AndroidUtilities.dp(2));
|
2014-06-04 01:31:48 +02:00
|
|
|
if (dx != 0) {
|
|
|
|
if (previousLayer != null) {
|
|
|
|
previousLayer.setAlpha(Math.min(1, (float) dx / (float) currentLayer.getMeasuredWidth()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (previousLayer != null) {
|
|
|
|
previousLayer.setAlpha(0);
|
|
|
|
}
|
|
|
|
currentLayer.setAlpha(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setupAnimations(ArrayList<Animator> animators, boolean back) {
|
|
|
|
if (back) {
|
|
|
|
animators.add(ObjectAnimator.ofFloat(currentLayer, "x", 0));
|
2014-07-03 00:39:05 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(shadowView, "x", -AndroidUtilities.dp(2)));
|
2014-06-04 01:31:48 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(previousLayer, "alpha", 0));
|
|
|
|
} else {
|
|
|
|
animators.add(ObjectAnimator.ofFloat(currentLayer, "x", getMeasuredWidth()));
|
2014-07-03 00:39:05 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(shadowView, "x", getMeasuredWidth() - AndroidUtilities.dp(2)));
|
2014-06-04 01:31:48 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(previousLayer, "alpha", 1.0f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2014-06-20 02:18:13 +02:00
|
|
|
if (!Utilities.isTablet(getContext()) && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
2014-07-03 00:39:05 +02:00
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(40), MeasureSpec.EXACTLY));
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
2014-07-03 00:39:05 +02:00
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48), MeasureSpec.EXACTLY));
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onMenuButtonPressed() {
|
|
|
|
if (currentLayer != null) {
|
|
|
|
currentLayer.onMenuButtonPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|