From 48f172fc9e9a464ee220afd2a82b719ec5b984e9 Mon Sep 17 00:00:00 2001 From: saqura Date: Mon, 26 Oct 2015 00:59:32 +0100 Subject: Reset the margins manually after rotating --- .../conversations/ui/ConferenceDetailsActivity.java | 10 ++++++++++ .../conversations/ui/ContactDetailsActivity.java | 9 +++++++++ .../siacs/conversations/ui/EditAccountActivity.java | 9 +++++++++ .../eu/siacs/conversations/ui/XmppActivity.java | 2 +- .../java/eu/siacs/conversations/utils/UIHelper.java | 21 +++++++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) (limited to 'src/main/java/eu') diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 42ce5349..20195256 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -6,6 +6,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.IntentSender.SendIntentException; +import android.content.res.Configuration; import android.graphics.Bitmap; import android.os.Build; import android.os.Bundle; @@ -41,6 +42,7 @@ import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate; +import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xmpp.jid.Jid; public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConferenceOptionsPushed { @@ -53,6 +55,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers inviteToConversation(mConversation); } }; + private LinearLayout mMainLayout; private TextView mYourNick; private ImageView mYourPhoto; private ImageButton mEditNickButton; @@ -187,6 +190,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_muc_details); + mMainLayout = (LinearLayout) findViewById(R.id.muc_main_layout); mYourNick = (TextView) findViewById(R.id.muc_your_nick); mYourPhoto = (ImageView) findViewById(R.id.your_photo); mEditNickButton = (ImageButton) findViewById(R.id.edit_nick_button); @@ -450,6 +454,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers } } + @Override + public void onConfigurationChanged (Configuration newConfig) { + super.onConfigurationChanged(newConfig); + UIHelper.resetChildMargins(mMainLayout); + } + private void updateView() { final MucOptions mucOptions = mConversation.getMucOptions(); final User self = mucOptions.getSelf(); diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 10bdaab1..ebac6feb 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -7,6 +7,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; @@ -99,6 +100,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd } } }; + private LinearLayout mainLayout; private Jid accountJid; private Jid contactJid; private TextView contactJidTv; @@ -197,6 +199,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd this.messageFingerprint = getIntent().getStringExtra("fingerprint"); setContentView(R.layout.activity_contact_details); + mainLayout = (LinearLayout) findViewById(R.id.details_main_layout); contactJidTv = (TextView) findViewById(R.id.details_contactjid); accountJidTv = (TextView) findViewById(R.id.details_account); lastseen = (TextView) findViewById(R.id.details_lastseen); @@ -297,6 +300,12 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd return true; } + @Override + public void onConfigurationChanged (Configuration newConfig) { + super.onConfigurationChanged(newConfig); + UIHelper.resetChildMargins(mainLayout); + } + private void populateView() { invalidateOptionsMenu(); setTitle(contact.getDisplayName()); diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index d58f0fc2..b782b2bf 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -5,6 +5,7 @@ import android.app.AlertDialog.Builder; import android.app.PendingIntent; import android.content.DialogInterface; import android.content.Intent; +import android.content.res.Configuration; import android.graphics.Bitmap; import android.os.Bundle; import android.security.KeyChain; @@ -51,6 +52,7 @@ import eu.siacs.conversations.xmpp.pep.Avatar; public class EditAccountActivity extends XmppActivity implements OnAccountUpdate, OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast { + private LinearLayout mMainLayout; private AutoCompleteTextView mAccountJid; private EditText mPassword; private EditText mPasswordConfirm; @@ -333,6 +335,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_account); + this.mMainLayout = (LinearLayout) findViewById(R.id.account_main_layout); this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid); this.mAccountJid.addTextChangedListener(this.mTextWatcher); this.mAccountJidLabel = (TextView) findViewById(R.id.account_jid_label); @@ -478,6 +481,12 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate updateSaveButton(); } + @Override + public void onConfigurationChanged (Configuration newConfig) { + super.onConfigurationChanged(newConfig); + UIHelper.resetChildMargins(mMainLayout); + } + @Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 0cdae2cd..aa03a61d 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -441,7 +441,7 @@ public abstract class XmppActivity extends Activity { } public void switchToAccount(Account account) { - switchToAccount(account,false); + switchToAccount(account, false); } public void switchToAccount(Account account, boolean init) { diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index cac23f07..8a73d35f 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -3,7 +3,11 @@ package eu.siacs.conversations.utils; import android.content.Context; import android.text.format.DateFormat; import android.text.format.DateUtils; +import android.util.DisplayMetrics; import android.util.Pair; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; import java.util.ArrayList; import java.util.Arrays; @@ -261,4 +265,21 @@ public class UIHelper { body = body.replace("?","").replace("¿",""); return LOCATION_QUESTIONS.contains(body); } + + public static void resetChildMargins(LinearLayout view) { + int childCount = view.getChildCount(); + for (int i = 0; i < childCount; i++) { + UIHelper.resetMargins(view.getChildAt(i)); + } + } + + private static void resetMargins(View view) { + LinearLayout.MarginLayoutParams marginLayoutParams = new LinearLayout.MarginLayoutParams(view.getLayoutParams()); + marginLayoutParams.setMargins(view.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), + view.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin), + view.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), + view.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin)); + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(marginLayoutParams); + view.setLayoutParams(layoutParams); + } } -- cgit v1.2.3