-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added message width adjust and single choose bug fixed
- Loading branch information
Showing
9 changed files
with
317 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/uk/openvk/android/refresh/user_interface/layouts/TightTextView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package uk.openvk.android.refresh.user_interface.layouts; | ||
|
||
import android.content.Context; | ||
import android.text.Layout; | ||
import android.util.AttributeSet; | ||
|
||
public class TightTextView extends androidx.appcompat.widget.AppCompatTextView { | ||
public TightTextView(Context context) { | ||
super(context); | ||
} | ||
|
||
public TightTextView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public TightTextView(Context context, AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
|
||
int specModeW = MeasureSpec.getMode(widthMeasureSpec); | ||
if (specModeW != MeasureSpec.EXACTLY) { | ||
Layout layout = getLayout(); | ||
if (layout != null) { | ||
int w = (int) Math.ceil(getMaxLineWidth(layout)) + getCompoundPaddingLeft() + getCompoundPaddingRight(); | ||
if (w < getMeasuredWidth()) { | ||
super.onMeasure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.AT_MOST), | ||
heightMeasureSpec); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private float getMaxLineWidth(Layout layout) { | ||
float max_width = 0.0f; | ||
int lines = layout.getLineCount(); | ||
for (int i = 0; i < lines; i++) { | ||
if (layout.getLineWidth(i) > max_width) { | ||
max_width = layout.getLineWidth(i); | ||
} | ||
} | ||
return max_width; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.