FairEmail/app/src/main/java/eu/faircode/email/FixedImageButton.java

60 lines
1.9 KiB
Java
Raw Normal View History

2021-12-11 14:14:56 +00:00
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail 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.
FairEmail 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 FairEmail. If not, see <http://www.gnu.org/licenses/>.
2024-01-01 07:50:49 +00:00
Copyright 2018-2024 by Marcel Bokhorst (M66B)
2021-12-11 14:14:56 +00:00
*/
import android.content.Context;
import android.graphics.Canvas;
2021-12-11 15:00:02 +00:00
import android.graphics.Rect;
2021-12-11 14:14:56 +00:00
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageButton;
public class FixedImageButton extends AppCompatImageButton {
public FixedImageButton(@NonNull Context context) {
super(context);
}
public FixedImageButton(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public FixedImageButton(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
try {
super.onDraw(canvas);
} catch (RuntimeException ex) {
2021-12-11 14:45:58 +00:00
Log.e(new Throwable(Helper.getViewName(this), ex));
2022-01-10 09:58:41 +00:00
Drawable d = getContext().getDrawable(R.drawable.twotone_broken_image_24);
2021-12-11 15:00:02 +00:00
Rect b = getDrawable().getBounds();
int px = Math.min(b.width(), b.height());
d.setBounds(0, 0, px, px);
2021-12-11 14:14:56 +00:00
d.draw(canvas);
}
}
}