Skip to content

Commit e79e7e4

Browse files
authored
Add Apply Window Insets Listener to Floating Action Button on Collaborators and Edit Tags Screens (#1739)
2 parents be33637 + 9f61fa1 commit e79e7e4

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

Simplenote/src/main/java/com/automattic/simplenote/CollaboratorsActivity.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import androidx.appcompat.widget.Toolbar
1313
import androidx.recyclerview.widget.LinearLayoutManager
1414
import com.automattic.simplenote.databinding.ActivityCollaboratorsBinding
1515
import com.automattic.simplenote.utils.CollaboratorsAdapter
16-
import com.automattic.simplenote.utils.CollaboratorsAdapter.*
1716
import com.automattic.simplenote.utils.CollaboratorsAdapter.CollaboratorDataItem.*
17+
import com.automattic.simplenote.utils.DisplayUtils
1818
import com.automattic.simplenote.utils.IntentUtils
1919
import com.automattic.simplenote.utils.SystemBarUtils
2020
import com.automattic.simplenote.utils.toast
@@ -48,7 +48,7 @@ class CollaboratorsActivity : ThemedAppCompatActivity() {
4848
setObservers()
4949

5050
viewModel.loadCollaborators(noteId)
51-
51+
5252
// Setup edge-to-edge display with proper WindowInsets handling
5353
// Use auto-theming to properly handle status bar appearance based on theme
5454
val toolbar = findViewById<Toolbar>(R.id.toolbar)
@@ -90,6 +90,9 @@ class CollaboratorsActivity : ThemedAppCompatActivity() {
9090
collaboratorsList.setEmptyView(empty.root)
9191

9292
buttonAddCollaborator.setOnClickListener { viewModel.clickAddCollaborator() }
93+
buttonAddCollaborator.setOnApplyWindowInsetsListener { view, insets ->
94+
DisplayUtils.applyWindowInsetsForFloatingActionButton(insets, resources, view)
95+
}
9396

9497
empty.image.setImageResource(R.drawable.ic_collaborate_24dp)
9598
empty.title.text = getString(R.string.no_collaborators)

Simplenote/src/main/java/com/automattic/simplenote/TagsActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TagsActivity : ThemedAppCompatActivity() {
3737
binding.setObservers()
3838

3939
viewModel.start()
40-
40+
4141
// Setup edge-to-edge display with proper WindowInsets handling
4242
// Use auto-theming to properly handle status bar appearance based on theme
4343
val toolbar = findViewById<Toolbar>(R.id.toolbar)
@@ -73,6 +73,9 @@ class TagsActivity : ThemedAppCompatActivity() {
7373
viewModel.longClickAddTag()
7474
true
7575
}
76+
buttonAdd.setOnApplyWindowInsetsListener { view, insets ->
77+
DisplayUtils.applyWindowInsetsForFloatingActionButton(insets, resources, view)
78+
}
7679
}
7780

7881
private fun ActivityTagsBinding.setObservers() {

Simplenote/src/main/java/com/automattic/simplenote/utils/DisplayUtils.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
import android.app.Activity;
44
import android.content.Context;
55
import android.content.res.Configuration;
6+
import android.content.res.Resources;
67
import android.graphics.Point;
8+
import android.os.Build;
79
import android.util.TypedValue;
810
import android.view.Display;
911
import android.view.View;
12+
import android.view.WindowInsets;
1013
import android.view.WindowManager;
1114
import android.view.inputmethod.InputMethodManager;
15+
import android.widget.RelativeLayout;
16+
import com.google.android.material.floatingactionbutton.FloatingActionButton;
1217

1318
import androidx.annotation.NonNull;
1419
import androidx.annotation.Nullable;
@@ -149,4 +154,39 @@ public static void showKeyboard(@Nullable final View view) {
149154
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
150155
}
151156
}
157+
158+
/**
159+
* Apply window insets for a {@link FloatingActionButton} in a {@link RelativeLayout} to the given {@link View}.
160+
*
161+
* @param insets {@link WindowInsets} to apply to {@link View}.
162+
* @param resources {@link Resources} to get dimension value from.
163+
* @param view {@link View} to apply {@link WindowInsets} to.
164+
*
165+
* @return {@link WindowInsets} supplied from a listener.
166+
*/
167+
public static WindowInsets applyWindowInsetsForFloatingActionButton(WindowInsets insets, Resources resources, View view) {
168+
int bottom;
169+
170+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
171+
bottom = insets.getInsets(WindowInsets.Type.systemBars()).bottom;
172+
} else {
173+
bottom = insets.getSystemWindowInsetBottom();
174+
}
175+
176+
int button = (int) resources.getDimension(R.dimen.button_floating);
177+
int margin = (int) resources.getDimension(R.dimen.margin_default);
178+
179+
RelativeLayout.LayoutParams buttonLayoutParams = new RelativeLayout.LayoutParams(
180+
RelativeLayout.LayoutParams.WRAP_CONTENT,
181+
RelativeLayout.LayoutParams.WRAP_CONTENT
182+
);
183+
buttonLayoutParams.setMargins(margin, 0, margin, bottom + margin);
184+
buttonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
185+
buttonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
186+
buttonLayoutParams.height = button;
187+
buttonLayoutParams.width = button;
188+
view.setLayoutParams(buttonLayoutParams);
189+
190+
return insets;
191+
}
152192
}

0 commit comments

Comments
 (0)