diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2013-09-09 13:19:43 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2013-09-09 13:19:43 +0200 |
commit | aae87b894f72a719a850ec32ad6944bd5c743331 (patch) | |
tree | b5a221fcb529c07b309f5bde0563155df28a472c /libraries/ActionBarSherlock/src/com/actionbarsherlock/internal/widget/IcsToast.java | |
parent | 5b6880d2e34f4c8a4bfba87b5ce53d3c6727b744 (diff) | |
download | open-keychain-aae87b894f72a719a850ec32ad6944bd5c743331.tar.gz open-keychain-aae87b894f72a719a850ec32ad6944bd5c743331.tar.bz2 open-keychain-aae87b894f72a719a850ec32ad6944bd5c743331.zip |
Update actionbarsherlock from 4.2 to 4.4
Diffstat (limited to 'libraries/ActionBarSherlock/src/com/actionbarsherlock/internal/widget/IcsToast.java')
-rw-r--r-- | libraries/ActionBarSherlock/src/com/actionbarsherlock/internal/widget/IcsToast.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/libraries/ActionBarSherlock/src/com/actionbarsherlock/internal/widget/IcsToast.java b/libraries/ActionBarSherlock/src/com/actionbarsherlock/internal/widget/IcsToast.java new file mode 100644 index 000000000..042648b24 --- /dev/null +++ b/libraries/ActionBarSherlock/src/com/actionbarsherlock/internal/widget/IcsToast.java @@ -0,0 +1,60 @@ + +package com.actionbarsherlock.internal.widget; + +import android.content.Context; +import android.util.Log; +import android.view.Gravity; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; +import android.widget.TextView; +import android.widget.Toast; + +import com.actionbarsherlock.R; + +public class IcsToast extends Toast { + public static final int LENGTH_LONG = Toast.LENGTH_LONG; + public static final int LENGTH_SHORT = Toast.LENGTH_SHORT; + private static final String TAG = "Toast"; + + public static Toast makeText(Context context, CharSequence s, int duration) { + if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) { + return Toast.makeText(context, s, duration); + } + IcsToast toast = new IcsToast(context); + toast.setDuration(duration); + TextView view = new TextView(context); + view.setText(s); + // Original AOSP using reference on @android:color/bright_foreground_dark + // bright_foreground_dark - reference on @android:color/background_light + // background_light - 0xffffffff + view.setTextColor(0xffffffff); + view.setGravity(Gravity.CENTER); + view.setBackgroundResource(R.drawable.abs__toast_frame); + toast.setView(view); + return toast; + } + + public static Toast makeText(Context context, int resId, int duration) { + return makeText(context, context.getResources().getString(resId), duration); + } + + public IcsToast(Context context) { + super(context); + } + + @Override + public void setText(CharSequence s) { + if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) { + super.setText(s); + return; + } + if (getView() == null) { + return; + } + try { + ((TextView) getView()).setText(s); + } catch (ClassCastException e) { + Log.e(TAG, "This Toast was not created with IcsToast.makeText", e); + } + } +} |