1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-24 13:22:08 +01:00

Fixed Layout issues with ThemedEditTextPreferences EditTexts

This commit is contained in:
vanitasvitae 2016-10-24 20:08:46 +02:00
parent e3c2e91b70
commit e66e3cc83d
Signed by: vanitasvitae
GPG key ID: DCCFB3302C9E4615
4 changed files with 31 additions and 4 deletions

View file

@ -8,13 +8,16 @@ import android.text.InputType;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings; import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.Helpers;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -93,6 +96,14 @@ public class ThemedIntEditTextPreference extends LinearLayout implements ThemedP
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
final EditText dialogLayout = (EditText) LayoutInflater.from(context).inflate(R.layout.settings_activity__dialog_proxy, null, false); final EditText dialogLayout = (EditText) LayoutInflater.from(context).inflate(R.layout.settings_activity__dialog_proxy, null, false);
dialogLayout.setInputType(InputType.TYPE_CLASS_NUMBER); dialogLayout.setInputType(InputType.TYPE_CLASS_NUMBER);
dialogLayout.setSingleLine();
FrameLayout container = new FrameLayout(context);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int marginHoriz = Helpers.dpToPx(context, (int) context.getResources().getDimension(R.dimen.activity_horizontal_margin_half));
params.leftMargin = marginHoriz;
params.rightMargin = marginHoriz;
dialogLayout.setLayoutParams(params);
container.addView(dialogLayout);
dialogLayout.setText(Integer.toString(appSettings.getThemedIntEditTextPreferenceValue(this))); dialogLayout.setText(Integer.toString(appSettings.getThemedIntEditTextPreferenceValue(this)));
builder.setTitle(title) builder.setTitle(title)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@ -104,7 +115,7 @@ public class ThemedIntEditTextPreference extends LinearLayout implements ThemedP
} }
} }
}).setNegativeButton(android.R.string.cancel, null) }).setNegativeButton(android.R.string.cancel, null)
.setView(dialogLayout) .setView(container)
.show(); .show();
} }

View file

@ -8,13 +8,16 @@ import android.text.InputType;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings; import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.Helpers;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -92,6 +95,14 @@ public class ThemedStringEditTextPreference extends LinearLayout implements Them
final EditText dialogLayout = (EditText) LayoutInflater.from(context).inflate(R.layout.settings_activity__dialog_proxy, null, false); final EditText dialogLayout = (EditText) LayoutInflater.from(context).inflate(R.layout.settings_activity__dialog_proxy, null, false);
dialogLayout.setInputType(InputType.TYPE_CLASS_TEXT); dialogLayout.setInputType(InputType.TYPE_CLASS_TEXT);
dialogLayout.setText(appSettings.getThemedStringEditTextPreferenceValue(this)); dialogLayout.setText(appSettings.getThemedStringEditTextPreferenceValue(this));
dialogLayout.setSingleLine();
FrameLayout container = new FrameLayout(context);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int marginHoriz = Helpers.dpToPx(context, (int) context.getResources().getDimension(R.dimen.activity_horizontal_margin_half));
params.leftMargin = marginHoriz;
params.rightMargin = marginHoriz;
dialogLayout.setLayoutParams(params);
container.addView(dialogLayout);
builder.setTitle(title) builder.setTitle(title)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
@ -102,7 +113,7 @@ public class ThemedStringEditTextPreference extends LinearLayout implements Them
} }
} }
}).setNegativeButton(android.R.string.cancel, null) }).setNegativeButton(android.R.string.cancel, null)
.setView(dialogLayout) .setView(container)
.show(); .show();
} }

View file

@ -27,6 +27,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.util.DisplayMetrics;
import android.view.View; import android.view.View;
import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.R;
@ -149,4 +150,9 @@ public class Helpers {
} }
return !isOnline; return !isOnline;
} }
public static int dpToPx(Context context, int dp) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}
} }

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android" <EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"/>
android:layout_margin="@dimen/activity_horizontal_margin"/>