org.mariotaku.twidere.view.MessageCardItemFrameLayout.java Source code

Java tutorial

Introduction

Here is the source code for org.mariotaku.twidere.view.MessageCardItemFrameLayout.java

Source

/*
 *             Twidere - Twitter client for Android
 * 
 *  Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.mariotaku.twidere.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.util.AttributeSet;
import android.view.ViewConfiguration;
import android.widget.FrameLayout;

import org.apache.commons.lang3.ArrayUtils;
import org.mariotaku.twidere.util.ThemeUtils;

public class MessageCardItemFrameLayout extends FrameLayout {

    public MessageCardItemFrameLayout(final Context context) {
        this(context, null);
    }

    public MessageCardItemFrameLayout(final Context context, final AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MessageCardItemFrameLayout(final Context context, final AttributeSet attrs, final int defStyle) {
        super(context, attrs, defStyle);
        if (isInEditMode())
            return;
        ThemeUtils.applyThemeAlphaToDrawable(context, getBackground());
    }

    @Override
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        final Drawable d = getBackground();
        if (d != null && d.isStateful()) {
            final int[] state = getDrawableState();
            d.setState(state);
            final Drawable current = d.getCurrent();
            if (current instanceof TransitionDrawable) {
                final TransitionDrawable td = (TransitionDrawable) current;
                if (ArrayUtils.contains(state, android.R.attr.state_pressed)) {
                    td.startTransition(ViewConfiguration.getLongPressTimeout());
                } else {
                    td.resetTransition();
                }
            }
        }
    }
}