I understand that it's easier to set padding without changing drawable size on ImageButton, however I am extending Button for my custom view as I need to override the OnTextChanged method (since Button extends TextView).
I have tried to set the padding programatically also, without success.
Part of my xml below:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor">
<TableRow
android:layout_weight="1"
android:gravity="center">
<org.linphone.views.Digit
android:id="@+id/Digit1"
style="@style/DialerDigit"
android:background="@drawable/ws_numpad_1"
android:soundEffectsEnabled="true"
android:layout_weight="1"
android:text="1"/>
<org.linphone.views.Digit
android:id="@+id/Digit2"
style="@style/DialerDigit"
android:background="@drawable/ic_num2_group"
android:soundEffectsEnabled="true"
android:text="2"
android:layout_weight="1" />
<org.linphone.views.Digit
android:id="@+id/Digit3"
style="@style/DialerDigit"
android:background="@drawable/ic_num3_group"
android:soundEffectsEnabled="true"
android:text="3"
android:layout_weight="1" />
</TableRow>
Right now the buttons extend to match parent, but the drawables stretch as well. My aim is to achieve a dialpad similar to the native android one (i.e. where there is no gap in between digits and the numbers on the dialpad don't distort for different screen sizes).
Edit 1 (dialpad image added):
Edit 2 (dialpad listener implementation):
@Override
protected void onTextChanged(CharSequence text, int start, int before, int after) {
super.onTextChanged(text, start, before, after);
if (text == null || text.length() < 1) {
return;
}
DialKeyListener lListener = new DialKeyListener();
setOnClickListener(lListener);
setOnTouchListener(lListener);
// Assign button long clicks here
if ("0".equals(text.toString())) { // This was 0+, but they were separated, hence
// changed to 0 only
setOnLongClickListener(lListener);
}
if ("1".equals(text.toString())) {
setOnLongClickListener(lListener);
}
}
private class DialKeyListener implements OnClickListener, OnTouchListener, OnLongClickListener {
final char mKeyCode;
boolean mIsDtmfStarted;
DialKeyListener() {
mKeyCode = Digit.this.getText().subSequence(0, 1).charAt(0);
}
private boolean linphoneServiceReady() {
if (!LinphoneContext.isReady()) {
Log.e("[Numpad] Service is not ready while pressing digit");
return false;
}
return true;
}
...
}