-
-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor spinner lesson layout to share scroll scaffold #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| import com.d4rk.androidtutorials.java.R; | ||
| import com.d4rk.androidtutorials.java.ads.AdUtils; | ||
| import com.d4rk.androidtutorials.java.databinding.ActivitySpinnerBinding; | ||
| import com.d4rk.androidtutorials.java.databinding.ActivitySpinnerContentBinding; | ||
| import com.d4rk.androidtutorials.java.ui.components.navigation.UpNavigationActivity; | ||
| import com.d4rk.androidtutorials.java.utils.EdgeToEdgeHelper; | ||
|
|
||
|
|
@@ -22,6 +23,7 @@ | |
| public class SpinnerActivity extends UpNavigationActivity { | ||
| private final Handler handler = new Handler(Looper.getMainLooper()); | ||
| private ActivitySpinnerBinding binding; | ||
| private ActivitySpinnerContentBinding contentBinding; | ||
|
|
||
| @Override | ||
| protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
|
|
@@ -30,42 +32,53 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| binding = ActivitySpinnerBinding.inflate(getLayoutInflater()); | ||
| setContentView(binding.getRoot()); | ||
|
Comment on lines
32
to
33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 Badge Inflate merge-root binding without parent Changing Useful? React with 👍 / 👎. |
||
| EdgeToEdgeHelper.applyEdgeToEdge(getWindow(), binding.getRoot()); | ||
| binding.descriptionSection.descriptionHeader.getRoot().setText(R.string.description); | ||
| binding.layoutPreviewHeader.getRoot().setText(R.string.layout_preview); | ||
| binding.descriptionSection.descriptionText.setText(R.string.summary_spinner); | ||
| AdUtils.loadBanner(binding.descriptionSection.adView); | ||
|
|
||
| new FastScrollerBuilder(binding.scrollView).useMd2Style().build(); | ||
| contentBinding = ActivitySpinnerContentBinding.inflate( | ||
| getLayoutInflater(), | ||
| binding.lessonScaffold.lessonContentContainer, | ||
| true | ||
| ); | ||
|
|
||
| contentBinding.descriptionSection.descriptionHeader.getRoot().setText(R.string.description); | ||
| contentBinding.layoutPreviewHeader.getRoot().setText(R.string.layout_preview); | ||
| contentBinding.descriptionSection.descriptionText.setText(R.string.summary_spinner); | ||
| AdUtils.loadBanner(contentBinding.descriptionSection.adView); | ||
|
|
||
| new FastScrollerBuilder(binding.lessonScaffold.lessonScrollView).useMd2Style().build(); | ||
|
|
||
| ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( | ||
| this, | ||
| R.array.spinner_lessons_entries, | ||
| android.R.layout.simple_spinner_item | ||
| ); | ||
| adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | ||
| binding.spinnerOptions.setAdapter(adapter); | ||
| contentBinding.spinnerOptions.setAdapter(adapter); | ||
| if (adapter.getCount() > 0) { | ||
| CharSequence firstItem = adapter.getItem(0); | ||
| if (firstItem != null) { | ||
| binding.textSelectedItem.setText(getString(R.string.spinner_selected_format, firstItem)); | ||
| contentBinding.textSelectedItem.setText( | ||
| getString(R.string.spinner_selected_format, firstItem) | ||
| ); | ||
| } | ||
| } | ||
| binding.spinnerOptions.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | ||
| contentBinding.spinnerOptions.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | ||
| @Override | ||
| public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | ||
| CharSequence item = (CharSequence) parent.getItemAtPosition(position); | ||
| binding.textSelectedItem.setText(getString(R.string.spinner_selected_format, item)); | ||
| contentBinding.textSelectedItem.setText( | ||
| getString(R.string.spinner_selected_format, item) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public void onNothingSelected(AdapterView<?> parent) { | ||
| binding.textSelectedItem.setText(R.string.spinner_selected_none); | ||
| contentBinding.textSelectedItem.setText(R.string.spinner_selected_none); | ||
| } | ||
| }); | ||
|
|
||
| binding.floatingButtonShowSyntax.setOnClickListener(v -> | ||
| binding.lessonScaffold.lessonShowCodeFab.setOnClickListener(v -> | ||
| startActivity(new Intent(this, SpinnerCodeActivity.class))); | ||
| handler.postDelayed(() -> binding.floatingButtonShowSyntax.shrink(), 5000); | ||
| handler.postDelayed(() -> binding.lessonScaffold.lessonShowCodeFab.shrink(), 5000); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,95 +1,9 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| <merge xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:id="@+id/container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
| xmlns:tools="http://schemas.android.com/tools"> | ||
|
|
||
| <me.zhanghai.android.fastscroll.FastScrollScrollView | ||
| android:id="@+id/scroll_view" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:layout_marginBottom="80dp"> | ||
|
|
||
| <androidx.appcompat.widget.LinearLayoutCompat | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:orientation="vertical" | ||
| android:paddingHorizontal="24dp"> | ||
|
|
||
| <include | ||
| android:id="@+id/description_section" | ||
| layout="@layout/lesson_description_section" /> | ||
|
|
||
| <include | ||
| android:id="@+id/layout_preview_header" | ||
| layout="@layout/lesson_section_header" | ||
| tools:text="@string/layout_preview" /> | ||
|
|
||
| <com.google.android.material.textview.MaterialTextView | ||
| android:id="@+id/text_view_spinner_label" | ||
| style="@style/TextAppearance.Material3.HeadlineSmall" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="24dp" | ||
| android:text="@string/spinner_choose_label" /> | ||
|
|
||
| <com.google.android.material.card.MaterialCardView | ||
| android:id="@+id/spinner_card" | ||
| style="@style/Widget.Material3.CardView.Outlined" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="16dp" | ||
| android:layout_marginBottom="24dp" | ||
| app:contentPadding="24dp" | ||
| app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewTopRoundedOutlined"> | ||
|
|
||
| <androidx.appcompat.widget.LinearLayoutCompat | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:orientation="vertical"> | ||
|
|
||
| <com.google.android.material.textview.MaterialTextView | ||
| android:id="@+id/text_view_spinner_description" | ||
| style="@style/TextAppearance.Material3.BodyLarge" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:text="@string/spinner_description" /> | ||
|
|
||
| <Spinner | ||
| android:id="@+id/spinner_options" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="16dp" | ||
| android:prompt="@string/spinner_prompt" /> | ||
|
|
||
| <com.google.android.material.textview.MaterialTextView | ||
| android:id="@+id/text_selected_item" | ||
| style="@style/TextAppearance.Material3.BodyLarge" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="16dp" | ||
| android:text="@string/spinner_selected_none" | ||
| tools:text="@string/spinner_selected_example" /> | ||
| </androidx.appcompat.widget.LinearLayoutCompat> | ||
| </com.google.android.material.card.MaterialCardView> | ||
| </androidx.appcompat.widget.LinearLayoutCompat> | ||
| </me.zhanghai.android.fastscroll.FastScrollScrollView> | ||
|
|
||
| <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton | ||
| android:id="@+id/floating_button_show_syntax" | ||
| style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Surface" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginEnd="24dp" | ||
| android:layout_marginBottom="24dp" | ||
| android:contentDescription="@string/tooltip_show_java_code_snippet" | ||
| android:text="@string/show_code" | ||
| android:textSize="14sp" | ||
| android:tooltipText="@string/tooltip_show_java_code_snippet" | ||
| app:icon="@drawable/ic_code" | ||
| app:layout_constraintBottom_toBottomOf="parent" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| tools:targetApi="26" /> | ||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
| <include | ||
| android:id="@+id/lesson_scaffold" | ||
| layout="@layout/lesson_scroll_scaffold" /> | ||
| </merge> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <merge xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools"> | ||
|
|
||
| <include | ||
| android:id="@+id/description_section" | ||
| layout="@layout/lesson_description_section" /> | ||
|
|
||
| <include | ||
| android:id="@+id/layout_preview_header" | ||
| layout="@layout/lesson_section_header" | ||
| tools:text="@string/layout_preview" /> | ||
|
|
||
| <com.google.android.material.textview.MaterialTextView | ||
| android:id="@+id/text_view_spinner_label" | ||
| style="@style/TextAppearance.Material3.HeadlineSmall" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="24dp" | ||
| android:text="@string/spinner_choose_label" /> | ||
|
|
||
| <com.google.android.material.card.MaterialCardView | ||
| android:id="@+id/spinner_card" | ||
| style="@style/Widget.Material3.CardView.Outlined" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="16dp" | ||
| android:layout_marginBottom="24dp" | ||
| app:contentPadding="24dp" | ||
| app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewTopRoundedOutlined"> | ||
|
|
||
| <androidx.appcompat.widget.LinearLayoutCompat | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:orientation="vertical"> | ||
|
|
||
| <com.google.android.material.textview.MaterialTextView | ||
| android:id="@+id/text_view_spinner_description" | ||
| style="@style/TextAppearance.Material3.BodyLarge" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:text="@string/spinner_description" /> | ||
|
|
||
| <Spinner | ||
| android:id="@+id/spinner_options" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="16dp" | ||
| android:prompt="@string/spinner_prompt" /> | ||
|
|
||
| <com.google.android.material.textview.MaterialTextView | ||
| android:id="@+id/text_selected_item" | ||
| style="@style/TextAppearance.Material3.BodyLarge" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginTop="16dp" | ||
| android:text="@string/spinner_selected_none" | ||
| tools:text="@string/spinner_selected_example" /> | ||
| </androidx.appcompat.widget.LinearLayoutCompat> | ||
| </com.google.android.material.card.MaterialCardView> | ||
| </merge> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <merge xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools"> | ||
|
|
||
| <androidx.constraintlayout.widget.ConstraintLayout | ||
| android:id="@+id/lesson_scaffold_root" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent"> | ||
|
|
||
| <me.zhanghai.android.fastscroll.FastScrollScrollView | ||
| android:id="@+id/lesson_scroll_view" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:layout_marginBottom="80dp"> | ||
|
|
||
| <androidx.appcompat.widget.LinearLayoutCompat | ||
| android:id="@+id/lesson_content_container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:orientation="vertical" | ||
| android:paddingHorizontal="24dp" /> | ||
| </me.zhanghai.android.fastscroll.FastScrollScrollView> | ||
|
|
||
| <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton | ||
| android:id="@+id/lesson_show_code_fab" | ||
| style="@style/Widget.Material3.ExtendedFloatingActionButton.Icon.Surface" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginEnd="24dp" | ||
| android:layout_marginBottom="24dp" | ||
| android:contentDescription="@string/tooltip_show_java_code_snippet" | ||
| android:text="@string/show_code" | ||
| android:textSize="14sp" | ||
| android:tooltipText="@string/tooltip_show_java_code_snippet" | ||
| app:icon="@drawable/ic_code" | ||
| app:layout_constraintBottom_toBottomOf="parent" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| tools:targetApi="26" /> | ||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
| </merge> |