2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 05:37:43 +00:00

Fixed previous commit to work on Android API < 19

This commit is contained in:
Albert Vaca 2014-10-04 21:07:57 -07:00
parent 1b4ade0ae1
commit 03bcfecb88
3 changed files with 17 additions and 4 deletions

View File

@ -6,8 +6,12 @@ import android.util.AttributeSet;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import org.kde.kdeconnect_tp.R;
public class MaxWidthImageButton extends ImageButton {
int mMaxWidth = Integer.MAX_VALUE;
public MaxWidthImageButton(Context context) {
super(context);
@ -15,14 +19,16 @@ public class MaxWidthImageButton extends ImageButton {
public MaxWidthImageButton(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MaxWidthImageButton);
mMaxWidth = a.getDimensionPixelSize(R.styleable.MaxWidthImageButton_maxWidth, Integer.MAX_VALUE);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int maxWidth = getMaxWidth();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if(getMeasuredWidth() > maxWidth){
setMeasuredDimension(maxWidth, getMeasuredHeight());
if(getMeasuredWidth() > mMaxWidth){
setMeasuredDimension(mMaxWidth, getMeasuredHeight());
}
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -32,7 +33,7 @@
<org.kde.kdeconnect.UserInterface.MaxWidthImageButton
android:layout_width="fill_parent"
android:layout_height="75dip"
android:maxWidth="300dip"
app:maxWidth="300dip"
android:id="@+id/play_button"
android:src="@android:drawable/ic_media_play"
android:contentDescription="@string/mpris_play"

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MaxWidthImageButton">
<attr name="maxWidth" format="dimension" />
</declare-styleable>
</resources>