From d71407f294a3e5797a9babadc612316225d4f85d Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sun, 11 Jun 2017 21:49:05 +0800 Subject: [PATCH] kotlin migration --- .../twidere/view/ExtendedFrameLayout.java | 113 ----------- .../twidere/view/ExtendedImageView.java | 99 --------- .../twidere/view/ExtendedLinearLayout.java | 108 ---------- .../twidere/view/ExtendedRecyclerView.java | 34 ++-- .../view/ExtendedSwipeRefreshLayout.java | 106 ---------- .../twidere/view/ProfileBannerImageView.java | 112 ----------- .../twidere/view/TintedStatusFrameLayout.java | 189 ------------------ .../twidere/activity/HomeActivity.kt | 2 +- .../twidere/activity/MediaViewerActivity.kt | 11 +- .../activity/QuickSearchBarActivity.kt | 2 +- .../AbsContentRecyclerViewFragment.kt | 4 +- .../fragment/AbsToolbarTabPagesFragment.kt | 23 ++- .../twidere/fragment/UserFragment.kt | 33 +-- .../twidere/view/ExtendedFrameLayout.kt | 78 ++++++++ .../twidere/view/ExtendedImageView.kt | 67 +++++++ .../twidere/view/ExtendedLinearLayout.kt | 73 +++++++ .../twidere/view/ExtendedRelativeLayout.kt | 21 +- .../view/ExtendedSwipeRefreshLayout.kt | 77 +++++++ .../twidere/view/ExtendedViewPager.kt} | 45 ++--- .../twidere/view/ProfileBannerImageView.kt | 84 ++++++++ .../twidere/view/TintedStatusFrameLayout.kt | 137 +++++++++++++ .../twidere/view/TintedStatusLayout.kt} | 14 +- .../twidere/view/iface/IExtendedView.kt} | 28 ++- 23 files changed, 621 insertions(+), 839 deletions(-) delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/view/ExtendedFrameLayout.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/view/ExtendedImageView.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/view/ExtendedLinearLayout.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/view/ExtendedSwipeRefreshLayout.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/view/ProfileBannerImageView.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/view/TintedStatusFrameLayout.java create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedFrameLayout.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedImageView.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedLinearLayout.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedSwipeRefreshLayout.kt rename twidere/src/main/{java/org/mariotaku/twidere/view/ExtendedViewPager.java => kotlin/org/mariotaku/twidere/view/ExtendedViewPager.kt} (50%) create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/view/ProfileBannerImageView.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/view/TintedStatusFrameLayout.kt rename twidere/src/main/{java/org/mariotaku/twidere/view/iface/TintedStatusLayout.java => kotlin/org/mariotaku/twidere/view/TintedStatusLayout.kt} (68%) rename twidere/src/main/{java/org/mariotaku/twidere/view/iface/IExtendedView.java => kotlin/org/mariotaku/twidere/view/iface/IExtendedView.kt} (57%) diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedFrameLayout.java b/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedFrameLayout.java deleted file mode 100644 index 37f3ce2d9..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedFrameLayout.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.view; - -import android.content.Context; -import android.graphics.Rect; -import android.support.annotation.NonNull; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.widget.FrameLayout; - -import org.mariotaku.twidere.view.iface.IExtendedView; - -public class ExtendedFrameLayout extends FrameLayout implements IExtendedView { - - private TouchInterceptor mTouchInterceptor; - private OnSizeChangedListener mOnSizeChangedListener; - private OnFitSystemWindowsListener mOnFitSystemWindowsListener; - - public ExtendedFrameLayout(final Context context) { - super(context); - } - - public ExtendedFrameLayout(final Context context, final AttributeSet attrs) { - super(context, attrs); - } - - public ExtendedFrameLayout(final Context context, final AttributeSet attrs, final int defStyle) { - super(context, attrs, defStyle); - } - - @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 onInterceptTouchEvent(final MotionEvent event) { - if (mTouchInterceptor != null) { - final boolean ret = mTouchInterceptor.onInterceptTouchEvent(this, event); - if (ret) return true; - } - return super.onInterceptTouchEvent(event); - } - - @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 - @SuppressWarnings("deprecation") - protected boolean fitSystemWindows(@NonNull Rect insets) { - if (mOnFitSystemWindowsListener != null) { - mOnFitSystemWindowsListener.onFitSystemWindows(insets); - } - return super.fitSystemWindows(insets); - } - - @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(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } - - @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); - } - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedImageView.java b/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedImageView.java deleted file mode 100644 index 94e2f9bf9..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedImageView.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.view; - -import android.content.Context; -import android.graphics.Rect; -import android.support.annotation.NonNull; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.widget.ImageView; - -import org.mariotaku.twidere.view.iface.IExtendedView; - -public class ExtendedImageView extends ImageView implements IExtendedView { - - private OnSizeChangedListener mOnSizeChangedListener; - private TouchInterceptor mTouchInterceptor; - private OnFitSystemWindowsListener mOnFitSystemWindowsListener; - - public ExtendedImageView(final Context context) { - super(context); - } - - public ExtendedImageView(final Context context, final AttributeSet attrs) { - super(context, attrs); - } - - public ExtendedImageView(final Context context, final AttributeSet attrs, final int defStyle) { - super(context, attrs, defStyle); - } - - @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 - @SuppressWarnings("deprecation") - 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 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); - } - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedLinearLayout.java b/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedLinearLayout.java deleted file mode 100644 index 542c9cfcb..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedLinearLayout.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.view; - -import android.content.Context; -import android.graphics.Rect; -import android.support.annotation.NonNull; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.widget.LinearLayout; - -import org.mariotaku.twidere.view.iface.IExtendedView; - -public class ExtendedLinearLayout extends LinearLayout implements IExtendedView { - - private TouchInterceptor mTouchInterceptor; - private OnSizeChangedListener mOnSizeChangedListener; - private OnFitSystemWindowsListener mOnFitSystemWindowsListener; - - public ExtendedLinearLayout(final Context context) { - super(context); - } - - public ExtendedLinearLayout(final Context context, final AttributeSet attrs) { - super(context, attrs); - } - - public ExtendedLinearLayout(final Context context, final AttributeSet attrs, final int defStyle) { - super(context, attrs, defStyle); - } - - @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 onInterceptTouchEvent(final MotionEvent event) { - if (mTouchInterceptor != null) { - final boolean ret = mTouchInterceptor.onInterceptTouchEvent(this, event); - if (ret) return true; - } - return super.onInterceptTouchEvent(event); - } - - @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 - @SuppressWarnings("deprecation") - protected boolean fitSystemWindows(@NonNull Rect insets) { - if (mOnFitSystemWindowsListener != null) { - mOnFitSystemWindowsListener.onFitSystemWindows(insets); - } - return super.fitSystemWindows(insets); - } - - @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 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); - } - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedRecyclerView.java b/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedRecyclerView.java index 55a471866..34a84139d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedRecyclerView.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedRecyclerView.java @@ -36,10 +36,10 @@ import org.mariotaku.twidere.util.MouseScrollDirectionDecider; */ public class ExtendedRecyclerView extends RecyclerView { - private final MouseScrollDirectionDecider mMouseScrollDirectionDecider; + private final MouseScrollDirectionDecider mouseScrollDirectionDecider; // This value is used when handling generic motion events. - private float mScrollFactor = Float.MIN_VALUE; - private ContextMenuInfo mContextMenuInfo; + private float scrollFactor = Float.MIN_VALUE; + private ContextMenuInfo contextMenuInfo; public ExtendedRecyclerView(Context context) { this(context, null); @@ -51,18 +51,18 @@ public class ExtendedRecyclerView extends RecyclerView { public ExtendedRecyclerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - mMouseScrollDirectionDecider = new MouseScrollDirectionDecider(getScrollFactorBackport()); + mouseScrollDirectionDecider = new MouseScrollDirectionDecider(getScrollFactorBackport()); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - mMouseScrollDirectionDecider.attach(this); + mouseScrollDirectionDecider.attach(this); } @Override protected void onDetachedFromWindow() { - mMouseScrollDirectionDecider.detach(); + mouseScrollDirectionDecider.detach(); super.onDetachedFromWindow(); } @@ -77,24 +77,24 @@ public class ExtendedRecyclerView extends RecyclerView { final float vScroll, hScroll; if (lm.canScrollVertically()) { vScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); - if (!mMouseScrollDirectionDecider.isVerticalAvailable()) { - mMouseScrollDirectionDecider.guessDirection(event); + if (!mouseScrollDirectionDecider.isVerticalAvailable()) { + mouseScrollDirectionDecider.guessDirection(event); } } else { vScroll = 0f; } if (lm.canScrollHorizontally()) { hScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL); - if (!mMouseScrollDirectionDecider.isHorizontalAvailable()) { - mMouseScrollDirectionDecider.guessDirection(event); + if (!mouseScrollDirectionDecider.isHorizontalAvailable()) { + mouseScrollDirectionDecider.guessDirection(event); } } else { hScroll = 0f; } if (vScroll != 0 || hScroll != 0) { final float scrollFactor = getScrollFactorBackport(); - float horizontalDirection = mMouseScrollDirectionDecider.getHorizontalDirection(); - float verticalDirection = mMouseScrollDirectionDecider.getVerticalDirection(); + float horizontalDirection = mouseScrollDirectionDecider.getHorizontalDirection(); + float verticalDirection = mouseScrollDirectionDecider.getVerticalDirection(); final float hFactor = scrollFactor * (horizontalDirection != 0 ? horizontalDirection : -1); final float vFactor = scrollFactor * (verticalDirection != 0 ? verticalDirection : -1); scrollBy((int) (hScroll * hFactor), (int) (vScroll * vFactor)); @@ -142,7 +142,7 @@ public class ExtendedRecyclerView extends RecyclerView { @Override protected ContextMenu.ContextMenuInfo getContextMenuInfo() { - return mContextMenuInfo; + return contextMenuInfo; } @Override @@ -152,7 +152,7 @@ public class ExtendedRecyclerView extends RecyclerView { } final int position = getChildLayoutPosition(originalView); if (position == RecyclerView.NO_POSITION) return false; - mContextMenuInfo = new ContextMenuInfo(getId(), position); + contextMenuInfo = new ContextMenuInfo(getId(), position); return super.showContextMenuForChild(originalView); } @@ -160,18 +160,18 @@ public class ExtendedRecyclerView extends RecyclerView { * Ported from View.getVerticalScrollFactor. */ private float getScrollFactorBackport() { - if (mScrollFactor == Float.MIN_VALUE) { + if (scrollFactor == Float.MIN_VALUE) { TypedValue outValue = new TypedValue(); if (getContext().getTheme().resolveAttribute( android.R.attr.listPreferredItemHeight, outValue, true)) { - mScrollFactor = outValue.getDimension( + scrollFactor = outValue.getDimension( getContext().getResources().getDisplayMetrics()); } else { return 0; //listPreferredItemHeight is not defined, no generic scrolling } } - return mScrollFactor; + return scrollFactor; } public static class ContextMenuInfo implements ContextMenu.ContextMenuInfo { diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedSwipeRefreshLayout.java b/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedSwipeRefreshLayout.java deleted file mode 100644 index cad5459fe..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedSwipeRefreshLayout.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2015 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.view; - -import android.content.Context; -import android.graphics.Rect; -import android.support.annotation.NonNull; -import android.util.AttributeSet; -import android.view.MotionEvent; - -import org.mariotaku.chameleon.view.ChameleonSwipeRefreshLayout; -import org.mariotaku.twidere.view.iface.IExtendedView; - -/** - * Created by mariotaku on 15/4/25. - */ -public class ExtendedSwipeRefreshLayout extends ChameleonSwipeRefreshLayout implements IExtendedView { - - private TouchInterceptor mTouchInterceptor; - private OnSizeChangedListener mOnSizeChangedListener; - private OnFitSystemWindowsListener mOnFitSystemWindowsListener; - - public ExtendedSwipeRefreshLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public ExtendedSwipeRefreshLayout(Context context) { - super(context); - } - - @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 onInterceptTouchEvent(final MotionEvent event) { - if (mTouchInterceptor != null) { - final boolean ret = mTouchInterceptor.onInterceptTouchEvent(this, event); - if (ret) return true; - } - return super.onInterceptTouchEvent(event); - } - - @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 - @SuppressWarnings("deprecation") - protected boolean fitSystemWindows(@NonNull Rect insets) { - if (mOnFitSystemWindowsListener != null) { - mOnFitSystemWindowsListener.onFitSystemWindows(insets); - } - return super.fitSystemWindows(insets); - } - - @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 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); - } - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ProfileBannerImageView.java b/twidere/src/main/java/org/mariotaku/twidere/view/ProfileBannerImageView.java deleted file mode 100644 index 058634d48..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ProfileBannerImageView.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.view; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Rect; -import android.support.annotation.NonNull; -import android.util.AttributeSet; -import android.view.MotionEvent; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.view.iface.IExtendedView; - -public class ProfileBannerImageView extends ForegroundImageView implements IExtendedView { - - private OnSizeChangedListener mOnSizeChangedListener; - private TouchInterceptor mTouchInterceptor; - private OnFitSystemWindowsListener mOnFitSystemWindowsListener; - private float mBannerAspectRatio; - - public ProfileBannerImageView(final Context context, final AttributeSet attrs) { - super(context, attrs); - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileBannerImageView); - setBannerAspectRatio(a.getFraction(R.styleable.ProfileBannerImageView_bannerAspectRatio, 1, 1, 2f)); - a.recycle(); - 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 - @Deprecated - 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 = Math.round(width / mBannerAspectRatio); - 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); - } - } - - public void setBannerAspectRatio(final float bannerAspectRatio) { - mBannerAspectRatio = bannerAspectRatio; - } - - public float getBannerAspectRatio() { - return mBannerAspectRatio; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/TintedStatusFrameLayout.java b/twidere/src/main/java/org/mariotaku/twidere/view/TintedStatusFrameLayout.java deleted file mode 100644 index fa641e9e7..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/view/TintedStatusFrameLayout.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.view; - -import android.app.Activity; -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Rect; -import android.os.Build; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.view.ViewCompat; -import android.support.v4.view.WindowInsetsCompat; -import android.util.AttributeSet; -import android.view.View; -import android.view.Window; - -import org.mariotaku.chameleon.Chameleon; -import org.mariotaku.chameleon.Chameleon.Theme.LightStatusBarMode; -import org.mariotaku.chameleon.ChameleonUtils; -import org.mariotaku.chameleon.ChameleonView; -import org.mariotaku.chameleon.internal.SupportMethods; -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.view.iface.TintedStatusLayout; - -/** - * Created by mariotaku on 14/11/26. - */ -public class TintedStatusFrameLayout extends ExtendedFrameLayout implements TintedStatusLayout, - ChameleonView, ChameleonView.StatusBarThemeable { - - private final Paint mColorPaint; - private boolean mSetPadding; - - private int mStatusBarHeight; - private Rect mSystemWindowsInsets; - private WindowInsetsListener mWindowInsetsListener; - - public TintedStatusFrameLayout(Context context) { - this(context, null); - } - - public TintedStatusFrameLayout(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public TintedStatusFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TintedStatusLayout); - setSetPaddingEnabled(a.getBoolean(R.styleable.TintedStatusLayout_setPadding, false)); - a.recycle(); - mColorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mSystemWindowsInsets = new Rect(); - setWillNotDraw(false); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); - ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() { - @Override - public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { - final int top = insets.getSystemWindowInsetTop(); - final int left = insets.getSystemWindowInsetLeft(); - final int right = insets.getSystemWindowInsetRight(); - final int bottom = insets.getSystemWindowInsetBottom(); - if (mSetPadding) { - setPadding(left, top, right, bottom); - } - setStatusBarHeight(top); - if (mWindowInsetsListener != null) { - mWindowInsetsListener.onApplyWindowInsets(left, top, right, bottom); - } - return insets.consumeSystemWindowInsets(); - } - }); - } - } - - - @Override - public void setStatusBarColor(int color) { - mColorPaint.setColor(0xFF000000 | color); - mColorPaint.setAlpha(Color.alpha(color)); - invalidate(); - } - - @Override - public void setSetPaddingEnabled(boolean enabled) { - mSetPadding = enabled; - } - - public void setStatusBarHeight(int height) { - mStatusBarHeight = height; - invalidate(); - } - - @Override - protected void dispatchDraw(@NonNull Canvas canvas) { - super.dispatchDraw(canvas); - canvas.drawRect(0, 0, canvas.getWidth(), mStatusBarHeight, mColorPaint); - } - - @Override - protected boolean fitSystemWindows(@NonNull Rect insets) { - mSystemWindowsInsets.set(insets); - return true; - } - - public void setWindowInsetsListener(WindowInsetsListener listener) { - mWindowInsetsListener = listener; - } - - @Override - public boolean isPostApplyTheme() { - return false; - } - - @Nullable - @Override - public Appearance createAppearance(@NonNull Context context, @NonNull AttributeSet attributeSet, @NonNull Chameleon.Theme theme) { - Appearance appearance = new Appearance(); - appearance.setStatusBarColor(theme.getStatusBarColor()); - appearance.setLightStatusBarMode(theme.getLightStatusBarMode()); - return appearance; - } - - @Override - public void applyAppearance(@NonNull ChameleonView.Appearance appearance) { - Appearance a = (Appearance) appearance; - final int statusBarColor = a.getStatusBarColor(); - setStatusBarColor(statusBarColor); - final Activity activity = ChameleonUtils.getActivity(getContext()); - if (activity != null) { - final Window window = activity.getWindow(); - SupportMethods.setStatusBarColor(window, Color.TRANSPARENT); - ChameleonUtils.applyLightStatusBar(window, statusBarColor, a.getLightStatusBarMode()); - } - } - - @Override - public boolean isStatusBarColorHandled() { - return true; - } - - public static class Appearance implements ChameleonView.Appearance { - private int statusBarColor; - @LightStatusBarMode - private int lightStatusBarMode; - - public int getStatusBarColor() { - return statusBarColor; - } - - public void setStatusBarColor(int statusBarColor) { - this.statusBarColor = statusBarColor; - } - - @LightStatusBarMode - public int getLightStatusBarMode() { - return lightStatusBarMode; - } - - public void setLightStatusBarMode(@LightStatusBarMode int lightStatusBarMode) { - this.lightStatusBarMode = lightStatusBarMode; - } - } - - public interface WindowInsetsListener { - void onApplyWindowInsets(int left, int top, int right, int bottom); - } -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt index 3d1002f82..f4e5535e1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt @@ -210,7 +210,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp val refreshOnStart = preferences.getBoolean(SharedPreferenceConstants.KEY_REFRESH_ON_START, false) var tabDisplayOptionInt = Utils.getTabDisplayOptionInt(this) - homeContent.setOnFitSystemWindowsListener(this) + homeContent.onFitSystemWindowsListener = this mainPager.adapter = pagerAdapter mainTabs.setViewPager(mainPager) mainTabs.setOnPageChangeListener(this) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/MediaViewerActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/MediaViewerActivity.kt index 3e9fb4038..a0332667f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/MediaViewerActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/MediaViewerActivity.kt @@ -70,6 +70,7 @@ import org.mariotaku.twidere.util.PermissionUtils import org.mariotaku.twidere.util.ThemeUtils import org.mariotaku.twidere.util.dagger.GeneralComponent import org.mariotaku.twidere.util.support.WindowSupport +import org.mariotaku.twidere.view.TintedStatusFrameLayout import org.mariotaku.twidere.view.viewer.MediaSwipeCloseContainer import java.io.File import javax.inject.Inject @@ -154,10 +155,12 @@ class MediaViewerActivity : BaseActivity(), IMediaViewerActivity, MediaSwipeClos swipeContainer.backgroundAlpha = 1f WindowSupport.setStatusBarColor(window, Color.TRANSPARENT) activityLayout.setStatusBarColor(overrideTheme.colorToolbar) - activityLayout.setWindowInsetsListener { l, t, r, b -> - val statusBarHeight = t - ThemeUtils.getActionBarHeight(this) - activityLayout.setStatusBarHeight(statusBarHeight) - onFitSystemWindows(Rect(l, t, r, b)) + activityLayout.windowInsetsListener = object : TintedStatusFrameLayout.WindowInsetsListener { + override fun onApplyWindowInsets(left: Int, top: Int, right: Int, bottom: Int) { + val statusBarHeight = top - ThemeUtils.getActionBarHeight(this@MediaViewerActivity) + activityLayout.setStatusBarHeight(statusBarHeight) + onFitSystemWindows(Rect(left, top, right, bottom)) + } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/QuickSearchBarActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/QuickSearchBarActivity.kt index 41ea67d53..6faaac8f2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/QuickSearchBarActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/QuickSearchBarActivity.kt @@ -113,7 +113,7 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks< accountSpinner.setSelection(index) } } - mainContent.setOnFitSystemWindowsListener(this) + mainContent.onFitSystemWindowsListener = this suggestionsList.adapter = SuggestionsAdapter(this) suggestionsList.onItemClickListener = this diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentRecyclerViewFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentRecyclerViewFragment.kt index c1f39784d..eb368e2ab 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentRecyclerViewFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentRecyclerViewFragment.kt @@ -190,7 +190,7 @@ abstract class AbsContentRecyclerViewFragment - val pageLimit = viewPager.offscreenPageLimit - val currentItem = viewPager.currentItem - val count = pagerAdapter.count - for (i in 0 until count) { - if (i > currentItem - pageLimit - 1 || i < currentItem + pageLimit) { - val obj = pagerAdapter.instantiateItem(viewPager, i) - if (obj is IBaseFragment<*>) { - obj.requestFitSystemWindows() + toolbarContainer.onSizeChangedListener = object : IExtendedView.OnSizeChangedListener { + override fun onSizeChanged(view: View, w: Int, h: Int, oldw: Int, oldh: Int) { + val pageLimit = viewPager.offscreenPageLimit + val currentItem = viewPager.currentItem + val count = pagerAdapter.count + for (i in 0 until count) { + if (i > currentItem - pageLimit - 1 || i < currentItem + pageLimit) { + val obj = pagerAdapter.instantiateItem(viewPager, i) + if (obj is IBaseFragment<*>) { + obj.requestFitSystemWindows() + } } } } + } if (savedInstanceState == null) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt index e8cf4cb83..2f1643671 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt @@ -145,6 +145,7 @@ import org.mariotaku.twidere.util.support.ViewSupport import org.mariotaku.twidere.util.support.WindowSupport import org.mariotaku.twidere.view.HeaderDrawerLayout.DrawerCallback import org.mariotaku.twidere.view.TabPagerIndicator +import org.mariotaku.twidere.view.TintedStatusFrameLayout import org.mariotaku.twidere.view.iface.IExtendedView.OnSizeChangedListener import java.lang.ref.WeakReference import java.util.* @@ -673,22 +674,28 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, }) - userFragmentView.setWindowInsetsListener { _, top, _, _ -> - profileContentContainer.setPadding(0, top, 0, 0) - profileBannerSpace.statusBarHeight = top + userFragmentView.windowInsetsListener = object : TintedStatusFrameLayout.WindowInsetsListener { + override fun onApplyWindowInsets(left: Int, top: Int, right: Int, bottom: Int) { + profileContentContainer.setPadding(0, top, 0, 0) + profileBannerSpace.statusBarHeight = top - if (profileBannerSpace.toolbarHeight == 0) { - var toolbarHeight = toolbar.measuredHeight - if (toolbarHeight == 0) { - toolbarHeight = ThemeUtils.getActionBarHeight(context) + if (profileBannerSpace.toolbarHeight == 0) { + var toolbarHeight = toolbar.measuredHeight + if (toolbarHeight == 0) { + toolbarHeight = ThemeUtils.getActionBarHeight(context) + } + profileBannerSpace.toolbarHeight = toolbarHeight } - profileBannerSpace.toolbarHeight = toolbarHeight } } - profileContentContainer.setOnSizeChangedListener { _, _, _, _, _ -> - val toolbarHeight = toolbar.measuredHeight - userProfileDrawer.setPadding(0, toolbarHeight, 0, 0) - profileBannerSpace.toolbarHeight = toolbarHeight + + profileContentContainer.onSizeChangedListener = object : OnSizeChangedListener { + override fun onSizeChanged(view: View, w: Int, h: Int, oldw: Int, oldh: Int) { + val toolbarHeight = toolbar.measuredHeight + userProfileDrawer.setPadding(0, toolbarHeight, 0, 0) + profileBannerSpace.toolbarHeight = toolbarHeight + } + } userProfileDrawer.setDrawerCallback(this) @@ -710,7 +717,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, friendsContainer.setOnClickListener(this) errorIcon.setOnClickListener(this) urlContainer.setOnClickListener(this) - profileBanner.setOnSizeChangedListener(this) + profileBanner.onSizeChangedListener = this profileBannerSpace.setOnTouchListener(this) userProfileSwipeLayout.setOnRefreshListener { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedFrameLayout.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedFrameLayout.kt new file mode 100644 index 000000000..455d0ff5d --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedFrameLayout.kt @@ -0,0 +1,78 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.view + +import android.content.Context +import android.graphics.Rect +import android.util.AttributeSet +import android.view.MotionEvent +import android.widget.FrameLayout +import org.mariotaku.twidere.view.iface.IExtendedView + +open class ExtendedFrameLayout(context: Context, attrs: AttributeSet? = null) : + FrameLayout(context, attrs), IExtendedView { + + override var touchInterceptor: IExtendedView.TouchInterceptor? = null + override var onSizeChangedListener: IExtendedView.OnSizeChangedListener? = null + override var onFitSystemWindowsListener: IExtendedView.OnFitSystemWindowsListener? = null + + override fun dispatchTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.dispatchTouchEvent(this, event) + if (ret) return true + } + return super.dispatchTouchEvent(event) + } + + override fun onInterceptTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.onInterceptTouchEvent(this, event) + if (ret) return true + } + return super.onInterceptTouchEvent(event) + } + + override fun fitSystemWindows(insets: Rect): Boolean { + if (onFitSystemWindowsListener != null) { + onFitSystemWindowsListener!!.onFitSystemWindows(insets) + } + return super.fitSystemWindows(insets) + } + + override fun onTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.onTouchEvent(this, event) + if (ret) return true + } + return super.onTouchEvent(event) + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + if (onSizeChangedListener != null) { + onSizeChangedListener!!.onSizeChanged(this, w, h, oldw, oldh) + } + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedImageView.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedImageView.kt new file mode 100644 index 000000000..b7def7d68 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedImageView.kt @@ -0,0 +1,67 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.view + +import android.content.Context +import android.graphics.Rect +import android.support.v7.widget.AppCompatImageView +import android.util.AttributeSet +import android.view.MotionEvent +import org.mariotaku.twidere.view.iface.IExtendedView + +class ExtendedImageView(context: Context, attrs: AttributeSet? = null) : + AppCompatImageView(context, attrs), IExtendedView { + + override var onSizeChangedListener: IExtendedView.OnSizeChangedListener? = null + override var touchInterceptor: IExtendedView.TouchInterceptor? = null + override var onFitSystemWindowsListener: IExtendedView.OnFitSystemWindowsListener? = null + + + override fun fitSystemWindows(insets: Rect): Boolean { + if (onFitSystemWindowsListener != null) { + onFitSystemWindowsListener!!.onFitSystemWindows(insets) + } + return super.fitSystemWindows(insets) + } + + override fun dispatchTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.dispatchTouchEvent(this, event) + if (ret) return true + } + return super.dispatchTouchEvent(event) + } + + override fun onTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.onTouchEvent(this, event) + if (ret) return true + } + return super.onTouchEvent(event) + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + if (onSizeChangedListener != null) { + onSizeChangedListener!!.onSizeChanged(this, w, h, oldw, oldh) + } + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedLinearLayout.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedLinearLayout.kt new file mode 100644 index 000000000..ad6901440 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedLinearLayout.kt @@ -0,0 +1,73 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2014 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.view + +import android.content.Context +import android.graphics.Rect +import android.util.AttributeSet +import android.view.MotionEvent +import android.widget.LinearLayout +import org.mariotaku.twidere.view.iface.IExtendedView + +class ExtendedLinearLayout(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs), IExtendedView { + + override var touchInterceptor: IExtendedView.TouchInterceptor? = null + override var onSizeChangedListener: IExtendedView.OnSizeChangedListener? = null + override var onFitSystemWindowsListener: IExtendedView.OnFitSystemWindowsListener? = null + + override fun dispatchTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.dispatchTouchEvent(this, event) + if (ret) return true + } + return super.dispatchTouchEvent(event) + } + + override fun onInterceptTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.onInterceptTouchEvent(this, event) + if (ret) return true + } + return super.onInterceptTouchEvent(event) + } + + override fun fitSystemWindows(insets: Rect): Boolean { + if (onFitSystemWindowsListener != null) { + onFitSystemWindowsListener!!.onFitSystemWindows(insets) + } + return super.fitSystemWindows(insets) + } + + override fun onTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.onTouchEvent(this, event) + if (ret) return true + } + return super.onTouchEvent(event) + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + if (onSizeChangedListener != null) { + onSizeChangedListener!!.onSizeChanged(this, w, h, oldw, oldh) + } + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedRelativeLayout.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedRelativeLayout.kt index 3e5b8444b..cc8492af0 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedRelativeLayout.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedRelativeLayout.kt @@ -30,11 +30,12 @@ import android.widget.RelativeLayout import org.mariotaku.twidere.R import org.mariotaku.twidere.view.iface.IExtendedView -open class ExtendedRelativeLayout(context: Context, attrs: AttributeSet? = null) : RelativeLayout(context, attrs), IExtendedView { +open class ExtendedRelativeLayout(context: Context, attrs: AttributeSet? = null) : + RelativeLayout(context, attrs), IExtendedView { - private var touchInterceptor: IExtendedView.TouchInterceptor? = null - private var onSizeChangedListener: IExtendedView.OnSizeChangedListener? = null - private var onFitSystemWindowsListener: IExtendedView.OnFitSystemWindowsListener? = null + override var touchInterceptor: IExtendedView.TouchInterceptor? = null + override var onSizeChangedListener: IExtendedView.OnSizeChangedListener? = null + override var onFitSystemWindowsListener: IExtendedView.OnFitSystemWindowsListener? = null private var usePaddingBackup: Boolean = false private val paddingBackup = Rect() @@ -65,18 +66,6 @@ open class ExtendedRelativeLayout(context: Context, attrs: AttributeSet? = null) return super.onInterceptTouchEvent(event) } - override fun setOnFitSystemWindowsListener(listener: IExtendedView.OnFitSystemWindowsListener) { - onFitSystemWindowsListener = listener - } - - override fun setOnSizeChangedListener(listener: IExtendedView.OnSizeChangedListener) { - onSizeChangedListener = listener - } - - override fun setTouchInterceptor(listener: IExtendedView.TouchInterceptor) { - touchInterceptor = listener - } - @Deprecated("Deprecated in Android") override fun fitSystemWindows(insets: Rect): Boolean { onFitSystemWindowsListener?.onFitSystemWindows(insets) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedSwipeRefreshLayout.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedSwipeRefreshLayout.kt new file mode 100644 index 000000000..08788355d --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedSwipeRefreshLayout.kt @@ -0,0 +1,77 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.view + +import android.content.Context +import android.graphics.Rect +import android.util.AttributeSet +import android.view.MotionEvent + +import org.mariotaku.chameleon.view.ChameleonSwipeRefreshLayout +import org.mariotaku.twidere.view.iface.IExtendedView + +/** + * Created by mariotaku on 15/4/25. + */ +class ExtendedSwipeRefreshLayout(context: Context, attrs: AttributeSet? = null) : + ChameleonSwipeRefreshLayout(context, attrs), IExtendedView { + + override var touchInterceptor: IExtendedView.TouchInterceptor? = null + override var onSizeChangedListener: IExtendedView.OnSizeChangedListener? = null + override var onFitSystemWindowsListener: IExtendedView.OnFitSystemWindowsListener? = null + + override fun dispatchTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.dispatchTouchEvent(this, event) + if (ret) return true + } + return super.dispatchTouchEvent(event) + } + + override fun onInterceptTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.onInterceptTouchEvent(this, event) + if (ret) return true + } + return super.onInterceptTouchEvent(event) + } + + override fun fitSystemWindows(insets: Rect): Boolean { + if (onFitSystemWindowsListener != null) { + onFitSystemWindowsListener!!.onFitSystemWindows(insets) + } + return super.fitSystemWindows(insets) + } + + override fun onTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.onTouchEvent(this, event) + if (ret) return true + } + return super.onTouchEvent(event) + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + if (onSizeChangedListener != null) { + onSizeChangedListener!!.onSizeChanged(this, w, h, oldw, oldh) + } + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedViewPager.java b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedViewPager.kt similarity index 50% rename from twidere/src/main/java/org/mariotaku/twidere/view/ExtendedViewPager.java rename to twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedViewPager.kt index 945951551..02bef79df 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedViewPager.java +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedViewPager.kt @@ -17,43 +17,34 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.view; +package org.mariotaku.twidere.view -import android.content.Context; -import android.support.v4.view.ViewPager; -import android.util.AttributeSet; -import android.view.MotionEvent; +import android.content.Context +import android.support.v4.view.ViewPager +import android.util.AttributeSet +import android.view.MotionEvent -public class ExtendedViewPager extends ViewPager { +open class ExtendedViewPager(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) { - public ExtendedViewPager(final Context context) { - this(context, null); - } - - public ExtendedViewPager(final Context context, final AttributeSet attrs) { - super(context, attrs); - } - - - @Override - public boolean onTouchEvent(MotionEvent ev) { - if (!isEnabled()) return false; + override fun onTouchEvent(ev: MotionEvent): Boolean { + if (!isEnabled) return false try { - return super.onTouchEvent(ev); - } catch (IllegalArgumentException ex) { + return super.onTouchEvent(ev) + } catch (ex: IllegalArgumentException) { // Ignore } - return false; + + return false } - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - if (!isEnabled()) return false; + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { + if (!isEnabled) return false try { - return super.onInterceptTouchEvent(ev); - } catch (IllegalArgumentException ex) { + return super.onInterceptTouchEvent(ev) + } catch (ex: IllegalArgumentException) { // Ignore } - return false; + + return false } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/ProfileBannerImageView.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ProfileBannerImageView.kt new file mode 100644 index 000000000..fb22f0173 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ProfileBannerImageView.kt @@ -0,0 +1,84 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.view + +import android.content.Context +import android.graphics.Rect +import android.util.AttributeSet +import android.view.MotionEvent +import android.view.View +import android.widget.ImageView +import org.mariotaku.twidere.R +import org.mariotaku.twidere.view.iface.IExtendedView + +class ProfileBannerImageView(context: Context, attrs: AttributeSet) : + ForegroundImageView(context, attrs), IExtendedView { + + override var onSizeChangedListener: IExtendedView.OnSizeChangedListener? = null + override var touchInterceptor: IExtendedView.TouchInterceptor? = null + override var onFitSystemWindowsListener: IExtendedView.OnFitSystemWindowsListener? = null + + var bannerAspectRatio: Float = 0.toFloat() + + init { + val a = context.obtainStyledAttributes(attrs, R.styleable.ProfileBannerImageView) + bannerAspectRatio = a.getFraction(R.styleable.ProfileBannerImageView_bannerAspectRatio, 1, 1, 2f) + a.recycle() + scaleType = ImageView.ScaleType.CENTER_CROP + } + + @Deprecated("") + override fun fitSystemWindows(insets: Rect): Boolean { + if (onFitSystemWindowsListener != null) { + onFitSystemWindowsListener!!.onFitSystemWindows(insets) + } + return super.fitSystemWindows(insets) + } + + override fun dispatchTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.dispatchTouchEvent(this, event) + if (ret) return true + } + return super.dispatchTouchEvent(event) + } + + override fun onTouchEvent(event: MotionEvent): Boolean { + if (touchInterceptor != null) { + val ret = touchInterceptor!!.onTouchEvent(this, event) + if (ret) return true + } + return super.onTouchEvent(event) + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + val width = View.MeasureSpec.getSize(widthMeasureSpec) + val height = Math.round(width / bannerAspectRatio) + setMeasuredDimension(width, height) + super.onMeasure(widthMeasureSpec, View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY)) + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + if (onSizeChangedListener != null) { + onSizeChangedListener!!.onSizeChanged(this, w, h, oldw, oldh) + } + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/TintedStatusFrameLayout.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/TintedStatusFrameLayout.kt new file mode 100644 index 000000000..2b66d9528 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/TintedStatusFrameLayout.kt @@ -0,0 +1,137 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * 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 . + */ + +package org.mariotaku.twidere.view + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint +import android.graphics.Rect +import android.os.Build +import android.support.v4.view.ViewCompat +import android.util.AttributeSet +import android.view.View +import org.mariotaku.chameleon.Chameleon +import org.mariotaku.chameleon.Chameleon.Theme.LightStatusBarMode +import org.mariotaku.chameleon.ChameleonUtils +import org.mariotaku.chameleon.ChameleonView +import org.mariotaku.chameleon.internal.SupportMethods +import org.mariotaku.twidere.R + +/** + * Created by mariotaku on 14/11/26. + */ +class TintedStatusFrameLayout(context: Context, attrs: AttributeSet? = null) : + ExtendedFrameLayout(context, attrs), TintedStatusLayout, ChameleonView, + ChameleonView.StatusBarThemeable { + + override var setPaddingEnabled: Boolean = false + + private val colorPaint: Paint + private var statusBarHeight: Int = 0 + private val systemWindowsInsets: Rect + var windowInsetsListener: WindowInsetsListener? = null + + init { + val a = context.obtainStyledAttributes(attrs, R.styleable.TintedStatusLayout) + setPaddingEnabled = a.getBoolean(R.styleable.TintedStatusLayout_setPadding, false) + a.recycle() + colorPaint = Paint(Paint.ANTI_ALIAS_FLAG) + systemWindowsInsets = Rect() + setWillNotDraw(false) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets -> + val top = insets.systemWindowInsetTop + val left = insets.systemWindowInsetLeft + val right = insets.systemWindowInsetRight + val bottom = insets.systemWindowInsetBottom + if (setPaddingEnabled) { + setPadding(left, top, right, bottom) + } + setStatusBarHeight(top) + if (windowInsetsListener != null) { + windowInsetsListener!!.onApplyWindowInsets(left, top, right, bottom) + } + insets.consumeSystemWindowInsets() + } + } + } + + + override fun setStatusBarColor(color: Int) { + colorPaint.color = 0xFF000000.toInt() or color + colorPaint.alpha = Color.alpha(color) + invalidate() + } + + fun setStatusBarHeight(height: Int) { + statusBarHeight = height + invalidate() + } + + override fun dispatchDraw(canvas: Canvas) { + super.dispatchDraw(canvas) + canvas.drawRect(0f, 0f, canvas.width.toFloat(), statusBarHeight.toFloat(), colorPaint) + } + + override fun fitSystemWindows(insets: Rect): Boolean { + systemWindowsInsets.set(insets) + return true + } + + override fun isPostApplyTheme(): Boolean { + return false + } + + override fun createAppearance(context: Context, attributeSet: AttributeSet, theme: Chameleon.Theme): Appearance? { + val appearance = Appearance() + appearance.statusBarColor = theme.statusBarColor + appearance.lightStatusBarMode = theme.lightStatusBarMode + return appearance + } + + override fun applyAppearance(appearance: ChameleonView.Appearance) { + val a = appearance as Appearance + val statusBarColor = a.statusBarColor + setStatusBarColor(statusBarColor) + val activity = ChameleonUtils.getActivity(context) + if (activity != null) { + val window = activity.window + SupportMethods.setStatusBarColor(window, Color.TRANSPARENT) + ChameleonUtils.applyLightStatusBar(window, statusBarColor, a.lightStatusBarMode) + } + } + + override fun isStatusBarColorHandled(): Boolean { + return true + } + + class Appearance : ChameleonView.Appearance { + var statusBarColor: Int = 0 + @LightStatusBarMode + @get:LightStatusBarMode + var lightStatusBarMode: Int = 0 + } + + interface WindowInsetsListener { + fun onApplyWindowInsets(left: Int, top: Int, right: Int, bottom: Int) + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/iface/TintedStatusLayout.java b/twidere/src/main/kotlin/org/mariotaku/twidere/view/TintedStatusLayout.kt similarity index 68% rename from twidere/src/main/java/org/mariotaku/twidere/view/iface/TintedStatusLayout.java rename to twidere/src/main/kotlin/org/mariotaku/twidere/view/TintedStatusLayout.kt index 1616db57d..b61eae06d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/iface/TintedStatusLayout.java +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/TintedStatusLayout.kt @@ -1,7 +1,7 @@ /* - * Twidere - Twitter client for Android + * Twidere - Twitter client for Android * - * Copyright (C) 2012-2015 Mariotaku Lee + * Copyright (C) 2012-2017 Mariotaku Lee * * 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 @@ -17,14 +17,16 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.view.iface; +package org.mariotaku.twidere.view + +import org.mariotaku.twidere.view.iface.IExtendedView /** * Created by mariotaku on 15/4/27. */ -public interface TintedStatusLayout extends IExtendedView { - void setStatusBarColor(int color); +interface TintedStatusLayout : IExtendedView { + fun setStatusBarColor(color: Int) - void setSetPaddingEnabled(boolean enabled); + var setPaddingEnabled: Boolean } diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/iface/IExtendedView.java b/twidere/src/main/kotlin/org/mariotaku/twidere/view/iface/IExtendedView.kt similarity index 57% rename from twidere/src/main/java/org/mariotaku/twidere/view/iface/IExtendedView.java rename to twidere/src/main/kotlin/org/mariotaku/twidere/view/iface/IExtendedView.kt index b1a17cc42..2f46efe1f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/iface/IExtendedView.java +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/iface/IExtendedView.kt @@ -17,35 +17,33 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.view.iface; +package org.mariotaku.twidere.view.iface -import android.graphics.Rect; -import android.view.MotionEvent; -import android.view.View; +import android.graphics.Rect +import android.view.MotionEvent +import android.view.View -public interface IExtendedView { +interface IExtendedView { - void setOnFitSystemWindowsListener(final OnFitSystemWindowsListener listener); - - void setOnSizeChangedListener(final OnSizeChangedListener listener); - - void setTouchInterceptor(final TouchInterceptor listener); + var touchInterceptor: IExtendedView.TouchInterceptor? + var onSizeChangedListener: IExtendedView.OnSizeChangedListener? + var onFitSystemWindowsListener: IExtendedView.OnFitSystemWindowsListener? interface OnFitSystemWindowsListener { - void onFitSystemWindows(Rect insets); + fun onFitSystemWindows(insets: Rect) } interface OnSizeChangedListener { - void onSizeChanged(View view, int w, int h, int oldw, int oldh); + fun onSizeChanged(view: View, w: Int, h: Int, oldw: Int, oldh: Int) } interface TouchInterceptor { - boolean dispatchTouchEvent(View view, MotionEvent event); + fun dispatchTouchEvent(view: View, event: MotionEvent): Boolean - boolean onInterceptTouchEvent(View view, MotionEvent event); + fun onInterceptTouchEvent(view: View, event: MotionEvent): Boolean - boolean onTouchEvent(View view, MotionEvent event); + fun onTouchEvent(view: View, event: MotionEvent): Boolean } }