5
5
package org .chromium .chrome .browser .customtabs ;
6
6
7
7
import android .app .PendingIntent ;
8
- import android .app .PendingIntent .CanceledException ;
9
8
import android .content .Context ;
10
9
import android .content .Intent ;
11
10
import android .content .res .Resources ;
16
15
import android .support .annotation .NonNull ;
17
16
import android .support .customtabs .CustomTabsIntent ;
18
17
import android .text .TextUtils ;
18
+ import android .view .Gravity ;
19
19
import android .view .LayoutInflater ;
20
20
import android .view .View ;
21
+ import android .view .View .OnClickListener ;
22
+ import android .view .View .OnLongClickListener ;
21
23
import android .view .ViewGroup ;
22
24
import android .widget .ImageButton ;
23
25
24
26
import org .chromium .base .Log ;
25
27
import org .chromium .chrome .R ;
26
28
import org .chromium .chrome .browser .util .IntentUtils ;
27
29
import org .chromium .chrome .browser .widget .TintedDrawable ;
30
+ import org .chromium .ui .widget .Toast ;
28
31
29
32
import java .util .ArrayList ;
30
33
import java .util .HashSet ;
@@ -108,9 +111,10 @@ PendingIntent getPendingIntent() {
108
111
* Builds an {@link ImageButton} from the data in this params. Generated buttons should be
109
112
* placed on the bottom bar. The button's tag will be its id.
110
113
* @param parent The parent that the inflated {@link ImageButton}.
114
+ * @param listener {@link OnClickListener} that should be used with the button.
111
115
* @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid.
112
116
*/
113
- ImageButton buildBottomBarButton (Context context , ViewGroup parent ) {
117
+ ImageButton buildBottomBarButton (Context context , ViewGroup parent , OnClickListener listener ) {
114
118
if (mIsOnToolbar ) return null ;
115
119
116
120
ImageButton button = (ImageButton ) LayoutInflater .from (context )
@@ -121,18 +125,26 @@ ImageButton buildBottomBarButton(Context context, ViewGroup parent) {
121
125
if (mPendingIntent == null ) {
122
126
button .setEnabled (false );
123
127
} else {
124
- // TODO(ianwen): add UMA for button clicking.
125
- button .setOnClickListener (new View .OnClickListener () {
126
- @ Override
127
- public void onClick (View v ) {
128
- try {
129
- mPendingIntent .send ();
130
- } catch (CanceledException e ) {
131
- Log .e (TAG , "CanceledException while sending pending intent in custom tab" );
132
- }
133
- }
134
- });
128
+ button .setOnClickListener (listener );
135
129
}
130
+ button .setOnLongClickListener (new OnLongClickListener () {
131
+ @ Override
132
+ public boolean onLongClick (View view ) {
133
+ final int screenWidth = view .getResources ().getDisplayMetrics ().widthPixels ;
134
+ final int [] screenPos = new int [2 ];
135
+ view .getLocationOnScreen (screenPos );
136
+ final int width = view .getWidth ();
137
+
138
+ Toast toast = Toast .makeText (
139
+ view .getContext (), view .getContentDescription (), Toast .LENGTH_SHORT );
140
+ toast .setGravity (Gravity .BOTTOM | Gravity .END ,
141
+ screenWidth - screenPos [0 ] - width / 2 ,
142
+ view .getResources ().getDimensionPixelSize (
143
+ R .dimen .toolbar_height_no_shadow ));
144
+ toast .show ();
145
+ return true ;
146
+ }
147
+ });
136
148
return button ;
137
149
}
138
150
@@ -148,13 +160,11 @@ static List<CustomButtonParams> fromIntent(Context context, Intent intent) {
148
160
Bundle singleBundle = IntentUtils .safeGetBundleExtra (intent ,
149
161
CustomTabsIntent .EXTRA_ACTION_BUTTON_BUNDLE );
150
162
ArrayList <Bundle > bundleList = IntentUtils .getParcelableArrayListExtra (intent ,
151
- CustomTabsIntent .EXTRA_ACTION_BUTTON_BUNDLE );
163
+ CustomTabsIntent .EXTRA_ACTION_BAR_ITEMS );
152
164
boolean tinted = IntentUtils .safeGetBooleanExtra (intent ,
153
165
CustomTabsIntent .EXTRA_TINT_ACTION_BUTTON , false );
154
- if (singleBundle != null ) {
155
- CustomButtonParams params = fromBundle (context , singleBundle , tinted , false );
156
- paramsList .add (params );
157
- } else if (bundleList != null ) {
166
+ if (singleBundle != null ) paramsList .add (fromBundle (context , singleBundle , tinted , false ));
167
+ if (bundleList != null ) {
158
168
Set <Integer > ids = new HashSet <>();
159
169
for (Bundle bundle : bundleList ) {
160
170
CustomButtonParams params = fromBundle (context , bundle , tinted , true );
0 commit comments