From e66e3cc83d1026ca59dcccfd9771d6a42fcd9bb1 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Mon, 24 Oct 2016 20:08:46 +0200 Subject: [PATCH] Fixed Layout issues with ThemedEditTextPreferences EditTexts --- .../ui/ThemedIntEditTextPreference.java | 13 ++++++++++++- .../ui/ThemedStringEditTextPreference.java | 13 ++++++++++++- .../github/dfa/diaspora_android/util/Helpers.java | 6 ++++++ .../res/layout/settings_activity__dialog_proxy.xml | 3 +-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedIntEditTextPreference.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedIntEditTextPreference.java index 29083c54..c91d311a 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedIntEditTextPreference.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedIntEditTextPreference.java @@ -8,13 +8,16 @@ import android.text.InputType; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.data.AppSettings; import com.github.dfa.diaspora_android.util.AppLog; +import com.github.dfa.diaspora_android.util.Helpers; import butterknife.BindView; import butterknife.ButterKnife; @@ -93,6 +96,14 @@ public class ThemedIntEditTextPreference extends LinearLayout implements ThemedP AlertDialog.Builder builder = new AlertDialog.Builder(context); final EditText dialogLayout = (EditText) LayoutInflater.from(context).inflate(R.layout.settings_activity__dialog_proxy, null, false); 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))); builder.setTitle(title) .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) - .setView(dialogLayout) + .setView(container) .show(); } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedStringEditTextPreference.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedStringEditTextPreference.java index 39686dbe..fb80be55 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedStringEditTextPreference.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedStringEditTextPreference.java @@ -8,13 +8,16 @@ import android.text.InputType; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.data.AppSettings; import com.github.dfa.diaspora_android.util.AppLog; +import com.github.dfa.diaspora_android.util.Helpers; import butterknife.BindView; 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); dialogLayout.setInputType(InputType.TYPE_CLASS_TEXT); 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) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override @@ -102,7 +113,7 @@ public class ThemedStringEditTextPreference extends LinearLayout implements Them } } }).setNegativeButton(android.R.string.cancel, null) - .setView(dialogLayout) + .setView(container) .show(); } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java index c7a3df09..2b16a58a 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java @@ -27,6 +27,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.support.design.widget.Snackbar; +import android.util.DisplayMetrics; import android.view.View; import com.github.dfa.diaspora_android.R; @@ -149,4 +150,9 @@ public class Helpers { } return !isOnline; } + + public static int dpToPx(Context context, int dp) { + DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); + return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); + } } diff --git a/app/src/main/res/layout/settings_activity__dialog_proxy.xml b/app/src/main/res/layout/settings_activity__dialog_proxy.xml index 8f59e5e2..c6bb1fe4 100644 --- a/app/src/main/res/layout/settings_activity__dialog_proxy.xml +++ b/app/src/main/res/layout/settings_activity__dialog_proxy.xml @@ -1,5 +1,4 @@ \ No newline at end of file + android:layout_height="match_parent"/> \ No newline at end of file