fixed aspect ratio of large profile image in user profile
This commit is contained in:
parent
fface0d9f2
commit
97b8487c56
|
@ -29,6 +29,7 @@ import android.graphics.Canvas;
|
|||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Matrix.ScaleToFit;
|
||||
import android.graphics.Outline;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
|
@ -313,8 +314,36 @@ public class CircularImageView extends ImageView {
|
|||
Shader.TileMode.CLAMP);
|
||||
mMatrix.reset();
|
||||
|
||||
switch (getScaleType()) {
|
||||
case CENTER_CROP: {
|
||||
final float srcRatio = source.width() / source.height();
|
||||
final float dstRatio = dest.width() / dest.height();
|
||||
if (srcRatio > dstRatio) {
|
||||
// Source is wider than destination, fit height
|
||||
tempDest.top = dest.top;
|
||||
tempDest.bottom = dest.bottom;
|
||||
final float dstWidth = dest.height() * srcRatio;
|
||||
tempDest.left = dest.centerX() - dstWidth / 2;
|
||||
tempDest.right = dest.centerX() + dstWidth / 2;
|
||||
} else if (srcRatio < dstRatio) {
|
||||
tempDest.left = dest.left;
|
||||
tempDest.right = dest.right;
|
||||
final float dstHeight = dest.width() / srcRatio;
|
||||
tempDest.top = dest.centerY() - dstHeight / 2;
|
||||
tempDest.bottom = dest.centerY() + dstHeight / 2;
|
||||
} else {
|
||||
tempDest.set(dest);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
tempDest.set(dest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Fit bitmap to bounds.
|
||||
mMatrix.setRectToRect(source, dest, Matrix.ScaleToFit.FILL);
|
||||
mMatrix.setRectToRect(source, tempDest, ScaleToFit.CENTER);
|
||||
|
||||
shader.setLocalMatrix(mMatrix);
|
||||
mBitmapPaint.setShader(shader);
|
||||
|
@ -323,6 +352,8 @@ public class CircularImageView extends ImageView {
|
|||
|
||||
}
|
||||
|
||||
private RectF tempDest = new RectF();
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private static class CircularOutlineProvider extends ViewOutlineProvider {
|
||||
@Override
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<size android:height="0.2dp"/>
|
||||
|
||||
<solid android:color="@color/divider_color"/>
|
||||
|
||||
</shape>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<size android:width="0.2dp"/>
|
||||
|
||||
<solid android:color="@color/divider_color"/>
|
||||
|
||||
</shape>
|
|
@ -16,8 +16,17 @@
|
|||
-->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@drawable/ic_action_assist_twidere_normal" android:state_active="false" android:state_enabled="true" android:state_focused="false"/>
|
||||
<item android:drawable="@drawable/ic_action_assist_twidere_activated" android:state_active="true" android:state_enabled="true" android:state_focused="false"/>
|
||||
<item android:drawable="@drawable/ic_action_assist_twidere_activated" android:state_active="false" android:state_enabled="true" android:state_focused="true"/>
|
||||
<item android:drawable="@drawable/ic_action_assist_twidere_normal"
|
||||
android:state_active="false"
|
||||
android:state_enabled="true"
|
||||
android:state_focused="false"/>
|
||||
<item android:drawable="@drawable/ic_action_assist_twidere_activated"
|
||||
android:state_active="true"
|
||||
android:state_enabled="true"
|
||||
android:state_focused="false"/>
|
||||
<item android:drawable="@drawable/ic_action_assist_twidere_activated"
|
||||
android:state_active="false"
|
||||
android:state_enabled="true"
|
||||
android:state_focused="true"/>
|
||||
|
||||
</selector>
|
|
@ -233,7 +233,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/action_button_size"
|
||||
android:baselineAligned="false"
|
||||
android:divider="@drawable/divider_vertical_small_holo"
|
||||
android:divider="?android:dividerHorizontal"
|
||||
android:orientation="horizontal"
|
||||
android:showDividers="middle"
|
||||
android:splitMotionEvents="false">
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
</style>
|
||||
|
||||
<style name="Widget.ProfileType" parent="Widget.Base">
|
||||
<item name="android:scaleType">centerInside</item>
|
||||
<item name="android:elevation">@dimen/elevation_card</item>
|
||||
<item name="android:outlineProvider">none</item>
|
||||
</style>
|
||||
|
|
|
@ -144,5 +144,6 @@
|
|||
</style>
|
||||
|
||||
<style name="Widget.ProfileType" parent="Widget.Base">
|
||||
<item name="android:scaleType">centerInside</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in New Issue