/* * Firetweet - 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.getlantern.firetweet.view; import android.content.Context; import android.graphics.Rect; import android.support.annotation.NonNull; import android.util.AttributeSet; import android.view.MotionEvent; import org.getlantern.firetweet.Constants; import org.getlantern.firetweet.view.iface.IExtendedView; public class ProfileBannerImageView extends ForegroundImageView implements IExtendedView, Constants { private OnSizeChangedListener mOnSizeChangedListener; private TouchInterceptor mTouchInterceptor; private OnFitSystemWindowsListener mOnFitSystemWindowsListener; public ProfileBannerImageView(final Context context) { this(context, null); } public ProfileBannerImageView(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public ProfileBannerImageView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; setScaleType(ScaleType.CENTER_CROP); } @Override public void setOnFitSystemWindowsListener(OnFitSystemWindowsListener listener) { mOnFitSystemWindowsListener = listener; } @Override public final void setOnSizeChangedListener(final OnSizeChangedListener listener) { mOnSizeChangedListener = listener; } @Override public final void setTouchInterceptor(final TouchInterceptor listener) { mTouchInterceptor = listener; } @Override protected boolean fitSystemWindows(@NonNull Rect insets) { if (mOnFitSystemWindowsListener != null) { mOnFitSystemWindowsListener.onFitSystemWindows(insets); } return super.fitSystemWindows(insets); } @Override public final boolean dispatchTouchEvent(@NonNull final MotionEvent event) { if (mTouchInterceptor != null) { final boolean ret = mTouchInterceptor.dispatchTouchEvent(this, event); if (ret) return true; } return super.dispatchTouchEvent(event); } @Override public final boolean onTouchEvent(@NonNull final MotionEvent event) { if (mTouchInterceptor != null) { final boolean ret = mTouchInterceptor.onTouchEvent(this, event); if (ret) return true; } return super.onTouchEvent(event); } @Override protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { final int width = MeasureSpec.getSize(widthMeasureSpec), height = width / 2; setMeasuredDimension(width, height); super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); } @Override protected final void onSizeChanged(final int w, final int h, final int oldw, final int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (mOnSizeChangedListener != null) { mOnSizeChangedListener.onSizeChanged(this, w, h, oldw, oldh); } } }