|
@@ -3,12 +3,16 @@ package com.reactnativenavigation.views;
|
3
|
3
|
import android.animation.Animator;
|
4
|
4
|
import android.animation.AnimatorListenerAdapter;
|
5
|
5
|
import android.content.Context;
|
|
6
|
+import android.graphics.Point;
|
|
7
|
+import android.graphics.Typeface;
|
6
|
8
|
import android.graphics.drawable.Drawable;
|
7
|
9
|
import android.support.annotation.Nullable;
|
8
|
10
|
import android.support.v7.widget.ActionMenuView;
|
9
|
11
|
import android.support.v7.widget.Toolbar;
|
|
12
|
+import android.view.Display;
|
10
|
13
|
import android.view.Menu;
|
11
|
14
|
import android.view.View;
|
|
15
|
+import android.view.WindowManager;
|
12
|
16
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
13
|
17
|
import android.view.animation.AccelerateInterpolator;
|
14
|
18
|
import android.widget.TextView;
|
|
@@ -25,11 +29,28 @@ public class TitleBar extends Toolbar {
|
25
|
29
|
private static final int TITLE_VISIBILITY_ANIMATION_DURATION = 320;
|
26
|
30
|
private LeftButton leftButton;
|
27
|
31
|
private ActionMenuView actionMenuView;
|
|
32
|
+ private boolean titleBarTitleTextCentered;
|
28
|
33
|
|
29
|
34
|
public TitleBar(Context context) {
|
30
|
35
|
super(context);
|
31
|
36
|
}
|
32
|
37
|
|
|
38
|
+ @Override
|
|
39
|
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
40
|
+ super.onLayout(changed, l, t, r, b);
|
|
41
|
+
|
|
42
|
+ if (titleBarTitleTextCentered) {
|
|
43
|
+ WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
|
|
44
|
+ Display display = windowManager.getDefaultDisplay();
|
|
45
|
+ Point screenSize = new Point();
|
|
46
|
+ display.getSize(screenSize);
|
|
47
|
+
|
|
48
|
+ int[] location = new int[2];
|
|
49
|
+ getTitleView().getLocationOnScreen(location);
|
|
50
|
+ getTitleView().setTranslationX(getTitleView().getTranslationX() + (-location[0] + screenSize.x / 2 - getTitleView().getWidth() / 2));
|
|
51
|
+ }
|
|
52
|
+ }
|
|
53
|
+
|
33
|
54
|
@Override
|
34
|
55
|
public void onViewAdded(View child) {
|
35
|
56
|
super.onViewAdded(child);
|
|
@@ -68,8 +89,10 @@ public class TitleBar extends Toolbar {
|
68
|
89
|
}
|
69
|
90
|
|
70
|
91
|
public void setStyle(StyleParams params) {
|
|
92
|
+ titleBarTitleTextCentered = params.titleBarTitleTextCentered;
|
71
|
93
|
setVisibility(params.titleBarHidden ? GONE : VISIBLE);
|
72
|
94
|
setTitleTextColor(params);
|
|
95
|
+ setTitleTextFont(params);
|
73
|
96
|
setSubtitleTextColor(params);
|
74
|
97
|
colorOverflowButton(params);
|
75
|
98
|
setBackground(params);
|
|
@@ -102,6 +125,31 @@ public class TitleBar extends Toolbar {
|
102
|
125
|
}
|
103
|
126
|
}
|
104
|
127
|
|
|
128
|
+ protected void setTitleTextFont(StyleParams params) {
|
|
129
|
+ if (params.titleBarTitleFont == null || params.titleBarTitleFont.isEmpty()) {
|
|
130
|
+ return;
|
|
131
|
+ }
|
|
132
|
+
|
|
133
|
+ View titleView = getTitleView();
|
|
134
|
+
|
|
135
|
+ if (titleView == null || !(titleView instanceof TextView)) {
|
|
136
|
+ return;
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ Typeface typeface = null;
|
|
140
|
+
|
|
141
|
+ try {
|
|
142
|
+ typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + params.titleBarTitleFont + ".ttf");
|
|
143
|
+ } catch (RuntimeException re) {
|
|
144
|
+ try {
|
|
145
|
+ typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + params.titleBarTitleFont + ".otf");
|
|
146
|
+ } catch (RuntimeException re2) {
|
|
147
|
+ return;
|
|
148
|
+ }
|
|
149
|
+ }
|
|
150
|
+ ((TextView) titleView).setTypeface(typeface);
|
|
151
|
+ }
|
|
152
|
+
|
105
|
153
|
protected void setSubtitleTextColor(StyleParams params) {
|
106
|
154
|
if (params.titleBarSubtitleColor.hasColor()) {
|
107
|
155
|
setSubtitleTextColor(params.titleBarSubtitleColor.getColor());
|