parent
daf695871d
commit
e537ceb805
Binary file not shown.
|
@ -371,6 +371,17 @@ public class ParcelableMedia implements Parcelable {
|
||||||
ParcelableMediaParcelablePlease.writeToParcel(this, dest, flags);
|
ParcelableMediaParcelablePlease.writeToParcel(this, dest, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasPlayIcon(@Type int type) {
|
||||||
|
switch (type) {
|
||||||
|
case Type.TYPE_VIDEO:
|
||||||
|
case Type.TYPE_ANIMATED_GIF:
|
||||||
|
case Type.TYPE_CARD_ANIMATED_GIF:
|
||||||
|
case Type.TYPE_EXTERNAL_PLAYER:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@IntDef({Type.TYPE_UNKNOWN, Type.TYPE_IMAGE, Type.TYPE_VIDEO, Type.TYPE_ANIMATED_GIF,
|
@IntDef({Type.TYPE_UNKNOWN, Type.TYPE_IMAGE, Type.TYPE_VIDEO, Type.TYPE_ANIMATED_GIF,
|
||||||
Type.TYPE_CARD_ANIMATED_GIF, Type.TYPE_EXTERNAL_PLAYER, Type.TYPE_VARIABLE_TYPE})
|
Type.TYPE_CARD_ANIMATED_GIF, Type.TYPE_EXTERNAL_PLAYER, Type.TYPE_VARIABLE_TYPE})
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
|
|
@ -236,6 +236,7 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
|
||||||
@Override
|
@Override
|
||||||
protected void displayMedia(CacheDownloadLoader.Result result) {
|
protected void displayMedia(CacheDownloadLoader.Result result) {
|
||||||
mVideoView.setVideoURI(result.cacheUri);
|
mVideoView.setVideoURI(result.cacheUri);
|
||||||
|
setMediaViewVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -348,6 +349,7 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
|
||||||
mPlayPauseButton.setOnClickListener(this);
|
mPlayPauseButton.setOnClickListener(this);
|
||||||
mVolumeButton.setOnClickListener(this);
|
mVolumeButton.setOnClickListener(this);
|
||||||
startLoading();
|
startLoading();
|
||||||
|
setMediaViewVisible(false);
|
||||||
updateVolume();
|
updateVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Activities;
|
||||||
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
|
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
|
||||||
import org.mariotaku.twidere.util.AsyncTaskUtils;
|
import org.mariotaku.twidere.util.AsyncTaskUtils;
|
||||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
||||||
|
import org.mariotaku.twidere.util.CheckUtils;
|
||||||
import org.mariotaku.twidere.util.CompareUtils;
|
import org.mariotaku.twidere.util.CompareUtils;
|
||||||
import org.mariotaku.twidere.util.DataStoreUtils;
|
import org.mariotaku.twidere.util.DataStoreUtils;
|
||||||
import org.mariotaku.twidere.util.HtmlSpanBuilder;
|
import org.mariotaku.twidere.util.HtmlSpanBuilder;
|
||||||
|
@ -1092,7 +1093,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||||
|
|
||||||
|
|
||||||
final String lang = status.lang;
|
final String lang = status.lang;
|
||||||
if (!Utils.isOfficialCredentials(context, account) || TextUtils.isEmpty(lang)) {
|
if (!Utils.isOfficialCredentials(context, account) || !CheckUtils.isValidLocale(lang)) {
|
||||||
translateLabelView.setText(R.string.unknown_language);
|
translateLabelView.setText(R.string.unknown_language);
|
||||||
translateContainer.setVisibility(View.GONE);
|
translateContainer.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1108,6 +1109,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
|
||||||
|
|
||||||
textView.setTextIsSelectable(true);
|
textView.setTextIsSelectable(true);
|
||||||
quotedTextView.setTextIsSelectable(true);
|
quotedTextView.setTextIsSelectable(true);
|
||||||
|
translateResultView.setTextIsSelectable(true);
|
||||||
|
|
||||||
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
quotedTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
quotedTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
|
|
@ -1405,14 +1405,14 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||||
mActionBarBackground.setColor(actionBarColor);
|
mActionBarBackground.setColor(actionBarColor);
|
||||||
}
|
}
|
||||||
ActivitySupport.setTaskDescription(activity, new TaskDescriptionCompat(null, null, actionBarColor));
|
ActivitySupport.setTaskDescription(activity, new TaskDescriptionCompat(null, null, actionBarColor));
|
||||||
final int optimalLinkColor = ThemeUtils.getOptimalLinkColor(color,
|
final int optimalAccentColor = ThemeUtils.getOptimalAccentColor(color,
|
||||||
mDescriptionView.getCurrentTextColor());
|
mDescriptionView.getCurrentTextColor());
|
||||||
mDescriptionView.setLinkTextColor(optimalLinkColor);
|
mDescriptionView.setLinkTextColor(optimalAccentColor);
|
||||||
mLocationView.setLinkTextColor(optimalLinkColor);
|
mLocationView.setLinkTextColor(optimalAccentColor);
|
||||||
mURLView.setLinkTextColor(optimalLinkColor);
|
mURLView.setLinkTextColor(optimalAccentColor);
|
||||||
mProfileBannerView.setBackgroundColor(color);
|
mProfileBannerView.setBackgroundColor(color);
|
||||||
ViewSupport.setBackground(mPagerIndicator, ThemeUtils.getActionBarStackedBackground(activity,
|
ViewSupport.setBackground(mPagerIndicator, ThemeUtils.getActionBarStackedBackground(activity,
|
||||||
themeRes, color, backgroundOption, true));
|
themeRes, optimalAccentColor, backgroundOption, true));
|
||||||
|
|
||||||
final HeaderDrawerLayout drawer = mHeaderDrawerLayout;
|
final HeaderDrawerLayout drawer = mHeaderDrawerLayout;
|
||||||
if (drawer != null) {
|
if (drawer != null) {
|
||||||
|
@ -1558,7 +1558,8 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
|
||||||
mPagerIndicator.setIconColor(tabContrastColor);
|
mPagerIndicator.setIconColor(tabContrastColor);
|
||||||
mPagerIndicator.setLabelColor(tabContrastColor);
|
mPagerIndicator.setLabelColor(tabContrastColor);
|
||||||
if (ThemeUtils.isDarkTheme(themeId)) {
|
if (ThemeUtils.isDarkTheme(themeId)) {
|
||||||
mPagerIndicator.setStripColor(mUiColor);
|
mPagerIndicator.setStripColor(ThemeUtils.getOptimalAccentColor(mUiColor,
|
||||||
|
tabContrastColor));
|
||||||
} else {
|
} else {
|
||||||
mPagerIndicator.setStripColor(tabContrastColor);
|
mPagerIndicator.setStripColor(tabContrastColor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,6 @@ public class BackgroundOperationService extends IntentService implements Constan
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
DebugModeUtils.watchReferenceLeak(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -229,7 +229,6 @@ public class RefreshService extends Service implements Constants {
|
||||||
startService(new Intent(this, getClass()));
|
startService(new Intent(this, getClass()));
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
DebugModeUtils.watchReferenceLeak(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isAutoRefreshAllowed() {
|
protected boolean isAutoRefreshAllowed() {
|
||||||
|
|
|
@ -108,7 +108,6 @@ public class StreamingService extends Service implements Constants {
|
||||||
Log.d(Constants.LOGTAG, "Stream service stopped.");
|
Log.d(Constants.LOGTAG, "Stream service stopped.");
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
DebugModeUtils.watchReferenceLeak(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearTwitterInstances() {
|
private void clearTwitterInstances() {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.mariotaku.twidere.util;
|
package org.mariotaku.twidere.util;
|
||||||
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common tool to check strings, objects etc.
|
* Common tool to check strings, objects etc.
|
||||||
|
@ -44,4 +45,8 @@ public class CheckUtils {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isValidLocale(String locale) {
|
||||||
|
return !TextUtils.isEmpty(locale) && !"und".equals(locale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,10 @@
|
||||||
package org.mariotaku.twidere.util;
|
package org.mariotaku.twidere.util;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.support.v4.content.res.ResourcesCompat;
|
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewParent;
|
import android.view.ViewParent;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||||
|
@ -34,7 +31,6 @@ import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;
|
import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;
|
||||||
|
|
||||||
import org.mariotaku.twidere.R;
|
import org.mariotaku.twidere.R;
|
||||||
import org.mariotaku.twidere.model.ParcelableMedia;
|
|
||||||
import org.mariotaku.twidere.util.support.ViewSupport;
|
import org.mariotaku.twidere.util.support.ViewSupport;
|
||||||
import org.mariotaku.twidere.view.ForegroundImageView;
|
import org.mariotaku.twidere.view.ForegroundImageView;
|
||||||
|
|
||||||
|
@ -58,8 +54,7 @@ public class MediaLoadingHandler implements ImageLoadingListener, ImageLoadingPr
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingStarted(final String imageUri, final View view) {
|
public void onLoadingStarted(final String imageUri, final View view) {
|
||||||
final int viewHashCode = System.identityHashCode(view);
|
final int viewHashCode = System.identityHashCode(view);
|
||||||
if (view == null || imageUri == null || imageUri.equals(mLoadingUris.get(viewHashCode)))
|
if (view == null || imageUri == null || imageUri.equals(getLoadingUri(view))) return;
|
||||||
return;
|
|
||||||
ViewGroup parent = (ViewGroup) view.getParent();
|
ViewGroup parent = (ViewGroup) view.getParent();
|
||||||
if (view instanceof ForegroundImageView) {
|
if (view instanceof ForegroundImageView) {
|
||||||
ViewSupport.setForeground(view, null);
|
ViewSupport.setForeground(view, null);
|
||||||
|
@ -76,12 +71,6 @@ public class MediaLoadingHandler implements ImageLoadingListener, ImageLoadingPr
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingFailed(final String imageUri, final View view, final FailReason reason) {
|
public void onLoadingFailed(final String imageUri, final View view, final FailReason reason) {
|
||||||
if (view == null) return;
|
if (view == null) return;
|
||||||
if (view instanceof ForegroundImageView) {
|
|
||||||
((ImageView) view).setImageDrawable(null);
|
|
||||||
final Drawable foreground = ResourcesCompat.getDrawable(view.getResources(),
|
|
||||||
R.drawable.image_preview_refresh, null);
|
|
||||||
ViewSupport.setForeground(view, foreground);
|
|
||||||
}
|
|
||||||
mLoadingUris.remove(System.identityHashCode(view));
|
mLoadingUris.remove(System.identityHashCode(view));
|
||||||
final ProgressBar progress = findProgressBar(view.getParent());
|
final ProgressBar progress = findProgressBar(view.getParent());
|
||||||
if (progress != null) {
|
if (progress != null) {
|
||||||
|
@ -94,35 +83,17 @@ public class MediaLoadingHandler implements ImageLoadingListener, ImageLoadingPr
|
||||||
if (view == null) return;
|
if (view == null) return;
|
||||||
mLoadingUris.remove(System.identityHashCode(view));
|
mLoadingUris.remove(System.identityHashCode(view));
|
||||||
final ViewGroup parent = (ViewGroup) view.getParent();
|
final ViewGroup parent = (ViewGroup) view.getParent();
|
||||||
setVideoIndicator(view, parent);
|
|
||||||
final ProgressBar progress = findProgressBar(parent);
|
final ProgressBar progress = findProgressBar(parent);
|
||||||
if (progress != null) {
|
if (progress != null) {
|
||||||
progress.setVisibility(View.GONE);
|
progress.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setVideoIndicator(View view, ViewGroup parent) {
|
|
||||||
if (view instanceof ForegroundImageView) {
|
|
||||||
final Drawable foreground;
|
|
||||||
if (isVideoItem(parent)) {
|
|
||||||
foreground = ResourcesCompat.getDrawable(view.getResources(),
|
|
||||||
R.drawable.ic_card_media_play, null);
|
|
||||||
} else {
|
|
||||||
foreground = null;
|
|
||||||
}
|
|
||||||
ViewSupport.setForeground(view, foreground);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingCancelled(final String imageUri, final View view) {
|
public void onLoadingCancelled(final String imageUri, final View view) {
|
||||||
final int viewHashCode = System.identityHashCode(view);
|
final int viewHashCode = System.identityHashCode(view);
|
||||||
if (view == null || imageUri == null || imageUri.equals(mLoadingUris.get(viewHashCode)))
|
if (view == null || imageUri == null || imageUri.equals(getLoadingUri(view))) return;
|
||||||
return;
|
|
||||||
mLoadingUris.remove(viewHashCode);
|
mLoadingUris.remove(viewHashCode);
|
||||||
if (view instanceof ForegroundImageView) {
|
|
||||||
ViewSupport.setForeground(view, null);
|
|
||||||
}
|
|
||||||
final ProgressBar progress = findProgressBar(view.getParent());
|
final ProgressBar progress = findProgressBar(view.getParent());
|
||||||
if (progress != null) {
|
if (progress != null) {
|
||||||
progress.setVisibility(View.GONE);
|
progress.setVisibility(View.GONE);
|
||||||
|
@ -130,7 +101,8 @@ public class MediaLoadingHandler implements ImageLoadingListener, ImageLoadingPr
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressUpdate(final String imageUri, final View view, final int current, final int total) {
|
public void onProgressUpdate(final String imageUri, final View view, final int current,
|
||||||
|
final int total) {
|
||||||
if (total == 0 || view == null) return;
|
if (total == 0 || view == null) return;
|
||||||
final ProgressBar progress = findProgressBar(view.getParent());
|
final ProgressBar progress = findProgressBar(view.getParent());
|
||||||
if (progress != null) {
|
if (progress != null) {
|
||||||
|
@ -149,14 +121,4 @@ public class MediaLoadingHandler implements ImageLoadingListener, ImageLoadingPr
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isVideoItem(ViewGroup parent) {
|
|
||||||
final Object tag = parent.getTag();
|
|
||||||
if (tag instanceof ParcelableMedia) {
|
|
||||||
final int type = ((ParcelableMedia) tag).type;
|
|
||||||
return type == ParcelableMedia.Type.TYPE_VIDEO || type == ParcelableMedia.Type.TYPE_ANIMATED_GIF
|
|
||||||
|| type == ParcelableMedia.Type.TYPE_CARD_ANIMATED_GIF
|
|
||||||
|| type == ParcelableMedia.Type.TYPE_EXTERNAL_PLAYER;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,8 @@ import java.lang.reflect.Field;
|
||||||
public class ThemeUtils implements Constants {
|
public class ThemeUtils implements Constants {
|
||||||
|
|
||||||
public static final int ACCENT_COLOR_THRESHOLD = 192;
|
public static final int ACCENT_COLOR_THRESHOLD = 192;
|
||||||
|
public static final int DARK_COLOR_THRESHOLD = 64;
|
||||||
|
|
||||||
public static final int[] ATTRS_TEXT_COLOR_PRIMARY = {android.R.attr.textColorPrimary};
|
public static final int[] ATTRS_TEXT_COLOR_PRIMARY = {android.R.attr.textColorPrimary};
|
||||||
public static final int[] ATTRS_TEXT_COLOR_PRIMARY_AND_INVERSE = {android.R.attr.textColorPrimary,
|
public static final int[] ATTRS_TEXT_COLOR_PRIMARY_AND_INVERSE = {android.R.attr.textColorPrimary,
|
||||||
android.R.attr.textColorPrimaryInverse};
|
android.R.attr.textColorPrimaryInverse};
|
||||||
|
@ -353,18 +355,18 @@ public class ThemeUtils implements Constants {
|
||||||
return R.style.Theme_Twidere_Light_NoDisplay;
|
return R.style.Theme_Twidere_Light_NoDisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getOptimalLinkColor(int linkColor, int textColor) {
|
public static int getOptimalAccentColor(int accentColor, int foregroundColor) {
|
||||||
final int[] yiq = new int[3];
|
final int[] yiq = new int[3];
|
||||||
TwidereColorUtils.colorToYIQ(textColor, yiq);
|
TwidereColorUtils.colorToYIQ(foregroundColor, yiq);
|
||||||
final int y = yiq[0];
|
final int foregroundColorY = yiq[0];
|
||||||
TwidereColorUtils.colorToYIQ(linkColor, yiq);
|
TwidereColorUtils.colorToYIQ(accentColor, yiq);
|
||||||
if (y < 32 && yiq[0] <= ACCENT_COLOR_THRESHOLD) {
|
if (foregroundColorY < DARK_COLOR_THRESHOLD && yiq[0] <= ACCENT_COLOR_THRESHOLD) {
|
||||||
return linkColor;
|
return accentColor;
|
||||||
} else if (y > ACCENT_COLOR_THRESHOLD && yiq[0] > 32) {
|
} else if (foregroundColorY > ACCENT_COLOR_THRESHOLD && yiq[0] > DARK_COLOR_THRESHOLD) {
|
||||||
return linkColor;
|
return accentColor;
|
||||||
}
|
}
|
||||||
yiq[0] = yiq[0] + (y - yiq[0]) / 2;
|
yiq[0] = yiq[0] + (foregroundColorY - yiq[0]) / 2;
|
||||||
return TwidereColorUtils.YIQToColor(Color.alpha(linkColor), yiq);
|
return TwidereColorUtils.YIQToColor(Color.alpha(accentColor), yiq);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getQuickSearchBarThemeResource(final Context context) {
|
public static int getQuickSearchBarThemeResource(final Context context) {
|
||||||
|
|
|
@ -132,6 +132,9 @@ public class CardMediaContainer extends ViewGroup implements Constants {
|
||||||
} else {
|
} else {
|
||||||
loader.displayPreviewImage(imageView, url, loadingHandler);
|
loader.displayPreviewImage(imageView, url, loadingHandler);
|
||||||
}
|
}
|
||||||
|
if (imageView instanceof MediaPreviewImageView) {
|
||||||
|
((MediaPreviewImageView) imageView).setHasPlayIcon(ParcelableMedia.hasPlayIcon(media.type));
|
||||||
|
}
|
||||||
child.setTag(media);
|
child.setTag(media);
|
||||||
child.setVisibility(VISIBLE);
|
child.setVisibility(VISIBLE);
|
||||||
if (i == j - 1) {
|
if (i == j - 1) {
|
||||||
|
|
|
@ -35,11 +35,13 @@ public class ForegroundImageView extends ImageView implements IForegroundView {
|
||||||
private final ForegroundViewHelper mForegroundViewHelper;
|
private final ForegroundViewHelper mForegroundViewHelper;
|
||||||
|
|
||||||
public ForegroundImageView(final Context context) {
|
public ForegroundImageView(final Context context) {
|
||||||
this(context, null);
|
super(context);
|
||||||
|
mForegroundViewHelper = new ForegroundViewHelper(this, context, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForegroundImageView(final Context context, final AttributeSet attrs) {
|
public ForegroundImageView(final Context context, final AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
super(context, attrs);
|
||||||
|
mForegroundViewHelper = new ForegroundViewHelper(this, context, attrs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForegroundImageView(final Context context, final AttributeSet attrs, final int defStyle) {
|
public ForegroundImageView(final Context context, final AttributeSet attrs, final int defStyle) {
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
package org.mariotaku.twidere.view;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import org.mariotaku.twidere.R;
|
||||||
|
import org.mariotaku.twidere.view.iface.IForegroundView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mariotaku on 16/1/30.
|
||||||
|
*/
|
||||||
|
public class MediaPreviewImageView extends ImageView {
|
||||||
|
|
||||||
|
private final IForegroundView.ForegroundViewHelper mForegroundViewHelper;
|
||||||
|
|
||||||
|
private boolean mHasPlayIcon;
|
||||||
|
|
||||||
|
public MediaPreviewImageView(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MediaPreviewImageView(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MediaPreviewImageView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
super(context, attrs, defStyle);
|
||||||
|
mForegroundViewHelper = new IForegroundView.ForegroundViewHelper(this, context, attrs, defStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setImageDrawable(Drawable drawable) {
|
||||||
|
super.setImageDrawable(drawable);
|
||||||
|
updatePlayIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updatePlayIcon() {
|
||||||
|
if (mHasPlayIcon && getDrawable() != null) {
|
||||||
|
mForegroundViewHelper.setForeground(ContextCompat.getDrawable(getContext(), R.drawable.ic_card_media_play));
|
||||||
|
} else {
|
||||||
|
mForegroundViewHelper.setForeground(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHasPlayIcon(boolean hasPlayIcon) {
|
||||||
|
mHasPlayIcon = hasPlayIcon;
|
||||||
|
updatePlayIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) {
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
|
if (mForegroundViewHelper != null) {
|
||||||
|
mForegroundViewHelper.dispatchOnSizeChanged(w, h, oldw, oldh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(final boolean changed, final int left, final int top, final int right, final int bottom) {
|
||||||
|
if (mForegroundViewHelper != null) {
|
||||||
|
mForegroundViewHelper.dispatchOnLayout(changed, left, top, right, bottom);
|
||||||
|
}
|
||||||
|
super.onLayout(changed, left, top, right, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean verifyDrawable(final Drawable who) {
|
||||||
|
return super.verifyDrawable(who) || (mForegroundViewHelper != null && mForegroundViewHelper.verifyDrawable(who));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void jumpDrawablesToCurrentState() {
|
||||||
|
super.jumpDrawablesToCurrentState();
|
||||||
|
if (mForegroundViewHelper != null) {
|
||||||
|
mForegroundViewHelper.jumpDrawablesToCurrentState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawableStateChanged() {
|
||||||
|
super.drawableStateChanged();
|
||||||
|
if (mForegroundViewHelper != null) {
|
||||||
|
mForegroundViewHelper.drawableStateChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
@Override
|
||||||
|
public void drawableHotspotChanged(float x, float y) {
|
||||||
|
super.drawableHotspotChanged(x, y);
|
||||||
|
if (mForegroundViewHelper != null) {
|
||||||
|
mForegroundViewHelper.dispatchDrawableHotspotChanged(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(@NonNull final Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
if (mForegroundViewHelper != null) {
|
||||||
|
mForegroundViewHelper.dispatchOnDraw(canvas);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,55 +0,0 @@
|
||||||
package org.mariotaku.twidere.view;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mariotaku on 14/11/5.
|
|
||||||
*/
|
|
||||||
public class MediaSizeImageView extends ImageView {
|
|
||||||
|
|
||||||
private int mMediaWidth, mMediaHeight;
|
|
||||||
|
|
||||||
public MediaSizeImageView(final Context context) {
|
|
||||||
this(context, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MediaSizeImageView(final Context context, final AttributeSet attrs) {
|
|
||||||
this(context, attrs, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MediaSizeImageView(final Context context, final AttributeSet attrs, final int defStyle) {
|
|
||||||
super(context, attrs, defStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMediaSize(int width, int height) {
|
|
||||||
mMediaWidth = width;
|
|
||||||
mMediaHeight = height;
|
|
||||||
requestLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
|
|
||||||
if (mMediaWidth == 0 || mMediaHeight == 0) {
|
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final float whRatio = (float) mMediaWidth / mMediaHeight;
|
|
||||||
final int width = MeasureSpec.getSize(widthMeasureSpec), height = MeasureSpec.getSize(heightMeasureSpec);
|
|
||||||
final ViewGroup.LayoutParams lp = getLayoutParams();
|
|
||||||
if (lp.height == ViewGroup.LayoutParams.MATCH_PARENT && lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) {
|
|
||||||
final int calcWidth = Math.round(height * whRatio);
|
|
||||||
super.onMeasure(MeasureSpec.makeMeasureSpec(calcWidth, MeasureSpec.EXACTLY), heightMeasureSpec);
|
|
||||||
setMeasuredDimension(calcWidth, height);
|
|
||||||
} else if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT && lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
|
|
||||||
final int calcHeight = Math.round(width / whRatio);
|
|
||||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(calcHeight, MeasureSpec.EXACTLY));
|
|
||||||
setMeasuredDimension(width, calcHeight);
|
|
||||||
} else {
|
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 882 B |
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB |
|
@ -23,7 +23,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<org.mariotaku.twidere.view.ForegroundImageView
|
<org.mariotaku.twidere.view.MediaPreviewImageView
|
||||||
android:id="@+id/media_preview"
|
android:id="@+id/media_preview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg width="48px" height="48px" viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
|
||||||
|
<!-- Generator: Sketch 3.5.1 (25234) - http://www.bohemiancoding.com/sketch -->
|
||||||
|
<title>ic_card_media_play-mdpi</title>
|
||||||
|
<desc>Created with Sketch.</desc>
|
||||||
|
<defs></defs>
|
||||||
|
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
|
||||||
|
<g id="ic_card_media_play-mdpi" sketch:type="MSArtboardGroup">
|
||||||
|
<circle id="Oval-1" stroke="#FFFFFF" stroke-width="4" fill="#0288D1" sketch:type="MSShapeGroup" cx="24" cy="24" r="20"></circle>
|
||||||
|
<polygon id="Triangle-1" fill="#FFFFFF" sketch:type="MSShapeGroup" transform="translate(26.000000, 24.000000) rotate(-270.000000) translate(-26.000000, -24.000000) " points="26 18 35 30 17 30 "></polygon>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 999 B |
Loading…
Reference in New Issue