mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 872388 - Create a buttonToast class. r=bnicholson
* * * Bug 872388 - Style button toasts. r=bnicholson
This commit is contained in:
parent
515a1cc924
commit
cb3a563479
@ -23,6 +23,7 @@ import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.util.UiAsyncTask;
|
||||
import org.mozilla.gecko.widget.AboutHome;
|
||||
import org.mozilla.gecko.widget.GeckoActionProvider;
|
||||
import org.mozilla.gecko.widget.ButtonToast;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -108,7 +109,7 @@ abstract public class BrowserApp extends GeckoApp
|
||||
}
|
||||
|
||||
private Vector<MenuItemInfo> mAddonMenuItemsCache;
|
||||
|
||||
private ButtonToast mToast;
|
||||
private PropertyAnimator mMainLayoutAnimator;
|
||||
|
||||
private static final Interpolator sTabsInterpolator = new Interpolator() {
|
||||
@ -381,6 +382,11 @@ abstract public class BrowserApp extends GeckoApp
|
||||
|
||||
RelativeLayout actionBar = (RelativeLayout) findViewById(R.id.browser_toolbar);
|
||||
|
||||
mToast = new ButtonToast(findViewById(R.id.toast), new ButtonToast.ToastListener() {
|
||||
public void onButtonClicked(CharSequence token) {
|
||||
}
|
||||
});
|
||||
|
||||
((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideTabsTouchListener());
|
||||
((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() {
|
||||
@Override
|
||||
|
@ -232,6 +232,7 @@ FENNEC_JAVA_FILES = \
|
||||
widget/AboutHomeSection.java \
|
||||
widget/ActivityChooserModel.java \
|
||||
widget/AddonsSection.java \
|
||||
widget/ButtonToast.java \
|
||||
widget/DateTimePicker.java \
|
||||
widget/Divider.java \
|
||||
widget/FaviconView.java \
|
||||
@ -648,6 +649,11 @@ RES_DRAWABLE_MDPI = \
|
||||
res/drawable-mdpi/tab_thumbnail_shadow.png \
|
||||
res/drawable-mdpi/tabs_count.png \
|
||||
res/drawable-mdpi/tabs_count_foreground.png \
|
||||
res/drawable-mdpi/toast.9.png \
|
||||
res/drawable-mdpi/toast_button_focused.9.png \
|
||||
res/drawable-mdpi/toast_button_focused.9.png \
|
||||
res/drawable-mdpi/toast_button_pressed.9.png \
|
||||
res/drawable-mdpi/toast_divider.9.png \
|
||||
res/drawable-mdpi/address_bar_url_default.9.png \
|
||||
res/drawable-mdpi/address_bar_url_default_pb.9.png \
|
||||
res/drawable-mdpi/address_bar_url_pressed.9.png \
|
||||
@ -1089,6 +1095,7 @@ MOZ_ANDROID_DRAWABLES += \
|
||||
mobile/android/base/resources/drawable/tab_thumbnail.xml \
|
||||
mobile/android/base/resources/drawable/tabs_panel_indicator.xml \
|
||||
mobile/android/base/resources/drawable/textbox_bg.xml \
|
||||
mobile/android/base/resources/drawable/toast_button.xml \
|
||||
mobile/android/base/resources/drawable/webapp_titlebar_bg.xml \
|
||||
$(NULL)
|
||||
|
||||
|
BIN
mobile/android/base/resources/drawable-mdpi/toast.9.png
Normal file
BIN
mobile/android/base/resources/drawable-mdpi/toast.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 839 B |
Binary file not shown.
After Width: | Height: | Size: 311 B |
Binary file not shown.
After Width: | Height: | Size: 311 B |
BIN
mobile/android/base/resources/drawable-mdpi/toast_divider.9.png
Normal file
BIN
mobile/android/base/resources/drawable-mdpi/toast_divider.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 963 B |
20
mobile/android/base/resources/drawable/toast_button.xml
Normal file
20
mobile/android/base/resources/drawable/toast_button.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<!--
|
||||
Copyright 2012 Roman Nurik
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/toast_button_pressed" android:state_pressed="true"/>
|
||||
<item android:drawable="@drawable/toast_button_focused" android:state_focused="true"/>
|
||||
<item android:drawable="@android:color/transparent"/>
|
||||
</selector>
|
@ -40,4 +40,18 @@
|
||||
android:layout_height="@dimen/browser_toolbar_height"/>
|
||||
</view>
|
||||
|
||||
<LinearLayout android:id="@+id/toast"
|
||||
style="@style/Toast">
|
||||
|
||||
<TextView android:id="@+id/toast_message"
|
||||
style="@style/ToastMessage" />
|
||||
|
||||
<ImageView android:id="@+id/toast_divider"
|
||||
style="@style/ToastDivider" />
|
||||
|
||||
<Button android:id="@+id/toast_button"
|
||||
style="@style/ToastButton" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@ -460,4 +460,57 @@
|
||||
<item name="@android:windowExitAnimation">@anim/popup_hide</item>
|
||||
</style>
|
||||
|
||||
<style name="Toast">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_alignParentBottom">true</item>
|
||||
<item name="android:layout_gravity">bottom</item>
|
||||
<item name="android:layout_marginLeft">8dp</item>
|
||||
<item name="android:layout_marginRight">8dp</item>
|
||||
<item name="android:layout_marginBottom">64dp</item>
|
||||
<item name="android:layout_marginTop">0dp</item>
|
||||
<item name="android:orientation">horizontal</item>
|
||||
<item name="android:background">@drawable/toast</item>
|
||||
<item name="android:clickable">true</item>
|
||||
<item name="android:showDividers">middle</item>
|
||||
<item name="android:dividerPadding">16dp</item>
|
||||
|
||||
<item name="android:paddingTop">0dp</item>
|
||||
<item name="android:paddingBottom">0dp</item>
|
||||
<item name="android:paddingLeft">0dp</item>
|
||||
<item name="android:paddingRight">0dp</item>
|
||||
</style>
|
||||
|
||||
<style name="ToastDivider">
|
||||
<item name="android:src">@drawable/toast_divider</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">match_parent</item>
|
||||
</style>
|
||||
|
||||
<style name="ToastMessage">
|
||||
<item name="android:layout_width">0dp</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_gravity">center_vertical</item>
|
||||
<item name="android:textColor">#fff</item>
|
||||
<item name="android:textAppearance">?android:textAppearanceSmall</item>
|
||||
<item name="android:paddingTop">0dp</item>
|
||||
<item name="android:paddingBottom">0dp</item>
|
||||
<item name="android:paddingLeft">8dp</item>
|
||||
<item name="android:paddingRight">0dp</item>
|
||||
<item name="android:layout_marginTop">0dp</item>
|
||||
<item name="android:layout_marginBottom">0dp</item>
|
||||
<item name="android:layout_marginLeft">8dp</item>
|
||||
<item name="android:layout_marginRight">0dp</item>
|
||||
</style>
|
||||
|
||||
<style name="ToastButton">
|
||||
<item name="android:background">@drawable/toast_button</item>
|
||||
<item name="android:textAppearance">?android:textAppearanceSmall</item>
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:textColor">#fff</item>
|
||||
<item name="android:layout_gravity">center_vertical</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
146
mobile/android/base/widget/ButtonToast.java
Normal file
146
mobile/android/base/widget/ButtonToast.java
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright 2012 Roman Nurik
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.mozilla.gecko.widget;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.mozilla.gecko.R;
|
||||
|
||||
public class ButtonToast {
|
||||
private final static int TOAST_DURATION = 5000;
|
||||
|
||||
private View mView;
|
||||
private TextView mMessageView;
|
||||
private Button mButton;
|
||||
private Handler mHideHandler = new Handler();
|
||||
|
||||
private ToastListener mListener;
|
||||
|
||||
// State objects
|
||||
private CharSequence mToken;
|
||||
private CharSequence mButtonMessage;
|
||||
private int mButtonIcon;
|
||||
private CharSequence mMessage;
|
||||
|
||||
public interface ToastListener {
|
||||
void onButtonClicked(CharSequence token);
|
||||
}
|
||||
|
||||
public ButtonToast(View view, ToastListener listener) {
|
||||
mView = view;
|
||||
mListener = listener;
|
||||
|
||||
mMessageView = (TextView) mView.findViewById(R.id.toast_message);
|
||||
mButton = (Button) mView.findViewById(R.id.toast_button);
|
||||
mButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
hide(false);
|
||||
mListener.onButtonClicked(mToken);
|
||||
}
|
||||
});
|
||||
|
||||
hide(true);
|
||||
}
|
||||
|
||||
public void show(boolean immediate, CharSequence message,
|
||||
CharSequence buttonMessage, int buttonIcon,
|
||||
CharSequence token) {
|
||||
mToken = token;
|
||||
mMessage = message;
|
||||
mButtonMessage = buttonMessage;
|
||||
mMessageView.setText(mMessage);
|
||||
|
||||
mButton.setText(buttonMessage);
|
||||
mButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, buttonIcon, 0);
|
||||
|
||||
mHideHandler.removeCallbacks(mHideRunnable);
|
||||
mHideHandler.postDelayed(mHideRunnable, TOAST_DURATION);
|
||||
|
||||
mView.setVisibility(View.VISIBLE);
|
||||
int duration = immediate ? 0 : mView.getResources().getInteger(android.R.integer.config_longAnimTime);
|
||||
|
||||
mView.clearAnimation();
|
||||
AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);
|
||||
alpha.setDuration(duration);
|
||||
alpha.setFillAfter(true);
|
||||
mView.startAnimation(alpha);
|
||||
}
|
||||
|
||||
public void hide(boolean immediate) {
|
||||
mHideHandler.removeCallbacks(mHideRunnable);
|
||||
int duration = immediate ? 0 : mView.getResources().getInteger(android.R.integer.config_longAnimTime);
|
||||
|
||||
mView.clearAnimation();
|
||||
if (immediate) {
|
||||
mView.setVisibility(View.GONE);
|
||||
mMessage = null;
|
||||
mToken = null;
|
||||
} else {
|
||||
AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
|
||||
alpha.setDuration(duration);
|
||||
alpha.setFillAfter(true);
|
||||
alpha.setAnimationListener(new Animation.AnimationListener () {
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
mView.setVisibility(View.GONE);
|
||||
mMessage = null;
|
||||
mToken = null;
|
||||
}
|
||||
public void onAnimationRepeat(Animation animation) { }
|
||||
public void onAnimationStart(Animation animation) { }
|
||||
});
|
||||
mView.startAnimation(alpha);
|
||||
}
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putCharSequence("toast_message", mMessage);
|
||||
outState.putCharSequence("toast_button_message", mButtonMessage);
|
||||
outState.putInt("toast_button_drawable", mButtonIcon);
|
||||
outState.putCharSequence("toast_token", mToken);
|
||||
}
|
||||
|
||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null) {
|
||||
mMessage = savedInstanceState.getCharSequence("toast_message");
|
||||
mButtonMessage = savedInstanceState.getCharSequence("toast_buttonmessage");
|
||||
mButtonIcon = savedInstanceState.getInt("toast_button_drawable");
|
||||
mToken = savedInstanceState.getCharSequence("toast_token");
|
||||
|
||||
if (mToken != null || !TextUtils.isEmpty(mMessage)) {
|
||||
show(true, mMessage, mButtonMessage, mButtonIcon, mToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable mHideRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
hide(false);
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user