Android Open Source - FisgoDroid Smiley Span






From Project

Back to project page FisgoDroid.

License

The source code is released under:

The smiley icons bundled with this application belong to Meneame.NET and are licensed under the Creative Commons by-sa 3.0 license. For more information, please visit http://creativecommons.org/licens...

If you think the Android project FisgoDroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.meneame.fisgodroid;
/*from  www . j a  v a  2s.  c om*/
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.text.style.DynamicDrawableSpan;

class SmileySpan extends DynamicDrawableSpan
{
    public interface Listener
    {
        public void update();
    }

    private AnimatedGifDrawable mDrawable;
    private Listener mListener;
    private Handler mHandler = new Handler();

    public SmileySpan(Listener listener)
    {
        super();
        mListener = listener;
    }

    public SmileySpan(Listener listener, AnimatedGifDrawable d)
    {
        super();

        setDrawable(d);
        mListener = listener;
    }

    public void setDrawable(AnimatedGifDrawable d)
    {
        mDrawable = (AnimatedGifDrawable) d;

        if ( mDrawable.getNumberOfFrames() < 2 )
        {
            mDrawable.nextFrame();
        }
        else
        {
            // Use handler for 'ticks' to proceed to next frame
            mHandler.post(new Runnable()
            {
                public void run()
                {
                    if ( mListener != null )
                    {
                        mListener.update();
                    }

                    mDrawable.nextFrame();
                    // Set next with a delay depending on the duration for this
                    // frame
                    mHandler.postDelayed(this, mDrawable.getFrameDuration());
                }
            });
        }
    }

    /*
     * Return current frame from animated drawable. Also acts as replacement for
     * super.getCachedDrawable(), since we can't cache the 'image' of an
     * animated image.
     */
    @Override
    public Drawable getDrawable()
    {
        return mDrawable.getDrawable();
    }

    /*
     * Copy-paste of super.getSize(...) but use getDrawable() to get the
     * image/frame to calculate the size, in stead of the cached drawable.
     */
    @Override
    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm)
    {
        Drawable d = getDrawable();
        Rect rect = d.getBounds();

        if ( fm != null )
        {
            fm.ascent = -rect.bottom;
            fm.descent = 0;

            fm.top = fm.ascent;
            fm.bottom = 0;
        }

        return rect.right;
    }

    /*
     * Copy-paste of super.draw(...) but use getDrawable() to get the
     * image/frame to draw, in stead of the cached drawable.
     */
    @Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
    {
        Drawable b = getDrawable();
        canvas.save();

        int transY = bottom - b.getBounds().bottom;
        if ( mVerticalAlignment == ALIGN_BASELINE )
        {
            transY -= paint.getFontMetricsInt().descent;
        }

        canvas.translate(x, transY);
        b.draw(canvas);
        canvas.restore();

    }
}




Java Source Code List

jp.tomorrowkey.android.GifDecoder.java
net.meneame.fisgodroid.AnimatedGifDrawable.java
net.meneame.fisgodroid.ChatActivity.java
net.meneame.fisgodroid.ChatBaseView.java
net.meneame.fisgodroid.ChatBubbleView.java
net.meneame.fisgodroid.ChatLineView.java
net.meneame.fisgodroid.ChatMessage.java
net.meneame.fisgodroid.ChatType.java
net.meneame.fisgodroid.DynamicTextView.java
net.meneame.fisgodroid.FisgoScheduler.java
net.meneame.fisgodroid.FisgoService.java
net.meneame.fisgodroid.FisgodroidApplication.java
net.meneame.fisgodroid.FriendshipStatus.java
net.meneame.fisgodroid.HttpService.java
net.meneame.fisgodroid.IHttpService.java
net.meneame.fisgodroid.ImageUpload.java
net.meneame.fisgodroid.LogSaver.java
net.meneame.fisgodroid.LoginActivity.java
net.meneame.fisgodroid.LoginStatus.java
net.meneame.fisgodroid.Notifications.java
net.meneame.fisgodroid.ProfileActivity.java
net.meneame.fisgodroid.SettingsActivity.java
net.meneame.fisgodroid.SmileyPickerView.java
net.meneame.fisgodroid.SmileySpan.java
net.meneame.fisgodroid.Smiley.java
net.meneame.fisgodroid.Smileys.java
net.meneame.fisgodroid.ThreeStateChecboxHackView.java
net.meneame.fisgodroid.UserProfileFetcher.java
net.meneame.fisgodroid.UserProfile.java
net.meneame.fisgodroid.adapters.BubblesChatAdapter.java
net.meneame.fisgodroid.adapters.ChatMessageAdapter.java
net.meneame.fisgodroid.adapters.LegacyChatAdapter.java
net.meneame.fisgodroid.notifications.ElementAdapter.java
net.meneame.fisgodroid.notifications.NotificationElement.java
net.meneame.fisgodroid.notifications.NotificationView.java
net.meneame.fisgodroid.notifications.NotificationsIndicatorDrawable.java
net.meneame.fisgodroid.notifications.NotificationsLayout.java
net.meneame.fisgodroid.notifications.NotificationsPoller.java