1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.toolbar;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.animation.PropertyAnimator.PropertyAnimationListener;
import org.mozilla.gecko.util.HardwareUtils;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
/**
* A toolbar implementation for phones.
*/
class BrowserToolbarPhone extends BrowserToolbarPhoneBase {
private final PropertyAnimationListener showEditingListener;
private final PropertyAnimationListener stopEditingListener;
protected boolean isAnimatingEntry;
protected BrowserToolbarPhone(final Context context, final AttributeSet attrs) {
super(context, attrs);
// Create these listeners here, once, to avoid constructing new listeners
// each time they are set on an animator (i.e. each time the url bar is clicked).
showEditingListener = new PropertyAnimationListener() {
@Override
public void onPropertyAnimationStart() { /* Do nothing */ }
@Override
public void onPropertyAnimationEnd() {
isAnimatingEntry = false;
}
};
stopEditingListener = new PropertyAnimationListener() {
@Override
public void onPropertyAnimationStart() { /* Do nothing */ }
@Override
public void onPropertyAnimationEnd() {
urlBarTranslatingEdge.setVisibility(View.INVISIBLE);
final PropertyAnimator buttonsAnimator = new PropertyAnimator(300);
urlDisplayLayout.prepareStopEditingAnimation(buttonsAnimator);
buttonsAnimator.start();
isAnimatingEntry = false;
// Trigger animation to update the tabs counter once the
// tabs button is back on screen.
updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
}
};
}
@Override
public boolean isAnimating() {
return isAnimatingEntry;
}
@Override
protected void triggerStartEditingTransition(final PropertyAnimator animator) {
if (isAnimatingEntry) {
return;
}
// The animation looks cleaner if the text in the URL bar is
// not selected so clear the selection by clearing focus.
urlEditLayout.clearFocus();
urlDisplayLayout.prepareStartEditingAnimation();
addAnimationsForEditing(animator, true);
showUrlEditLayout(animator);
urlBarTranslatingEdge.setVisibility(View.VISIBLE);
animator.addPropertyAnimationListener(showEditingListener);
isAnimatingEntry = true; // To be correct, this should be called last.
}
@Override
protected void triggerStopEditingTransition() {
final PropertyAnimator animator = new PropertyAnimator(250);
animator.setUseHardwareLayer(false);
addAnimationsForEditing(animator, false);
hideUrlEditLayout(animator);
animator.addPropertyAnimationListener(stopEditingListener);
isAnimatingEntry = true;
animator.start();
}
private void addAnimationsForEditing(final PropertyAnimator animator, final boolean isEditing) {
final int curveTranslation;
final int entryTranslation;
if (isEditing) {
curveTranslation = getUrlBarCurveTranslation();
entryTranslation = getUrlBarEntryTranslation();
} else {
curveTranslation = 0;
entryTranslation = 0;
}
// Slide toolbar elements.
animator.attach(urlBarTranslatingEdge,
PropertyAnimator.Property.TRANSLATION_X,
entryTranslation);
animator.attach(tabsButton,
PropertyAnimator.Property.TRANSLATION_X,
curveTranslation);
animator.attach(tabsCounter,
PropertyAnimator.Property.TRANSLATION_X,
curveTranslation);
animator.attach(menuButton,
PropertyAnimator.Property.TRANSLATION_X,
curveTranslation);
animator.attach(menuIcon,
PropertyAnimator.Property.TRANSLATION_X,
curveTranslation);
}
}
|