avatarCasira Copes

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

8995

Abstract

       </div>
        </div>
    </figure></iframe></div></div></figure><p id="a958">In Jetpack Compose, the Modifier.fillMaxSize() ensures that the layout takes up the available space, adapting to different screen sizes. Additionally, using a padding modifier can provide a consistent margin, maintaining a clean and organized appearance across various dimensions.</p><p id="cc20"><b>Managing Orientations:</b></p>
    <figure id="e303">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/LethalMaus/df4d1bf10cfa95fce51b5726f625cd1a.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="864f">By checking the current orientation using LocalConfiguration.current.orientation, you can conditionally define different layouts within a Composable function.</p><h2 id="e9ba">SlidingPaneLayout for Foldables</h2><div id="af7f" class="link-block">
      <a href="https://developer.android.com/jetpack/androidx/releases/slidingpanelayout">
        <div>
          <div>
            <h2>Slidingpanelayout | Jetpack | Android Developers</h2>
            <div><h3>Implement a sliding pane UI pattern. To add a dependency on SlidingPaneLayout, you must add the Google Maven repository…</h3></div>
            <div><p>developer.android.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*Mc7vQwPTUyZoP5KW)"></div>
          </div>
        </div>
      </a>
    </div><ul><li>Incorporate SlidingPaneLayout to create a sliding panel UI for foldable devices.</li></ul>
    <figure id="b2b5">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/LethalMaus/fd469a275aa7e2540f14e0eb889c47d0.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="6ee5">By leveraging these techniques in both Databinding and Jetpack Compose, you can create adaptive layouts that gracefully accommodate different screen sizes, orientations, and even the unique form factors of foldable devices. Whether adjusting dimensions or employing dynamic layouts, the goal is to provide users with a consistent and delightful experience across the diverse spectrum of devices.</p><h1 id="629e">Navigating the Pitfalls &amp; Best Practices</h1><h2 id="6483">Common Pitfalls and How to Avoid Them</h2><p id="c90b"><b>Fixed Dimensions:</b></p><ul><li><b>Pitfall:</b> Hardcoding dimensions can lead to layout distortion on different screen sizes.</li><li><b>Solution:</b> Use relative dimensions, such as wrap_content and match_parent, or utilize density-independent pixels (dp) for consistent sizing across screens.</li><li><b>XML Databinding Example:</b></li></ul>
    <figure id="4910">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/LethalMaus/97189675738255ea3f8326436851255e.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><ul><li><b>Jetpack Compose Example:</b></li></ul>
    <figure id="018c">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/LethalMaus/c6621ee3965756693058026eeb462b83.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="dc90"><b>Ignoring Density Independence:</b></p><ul><li><b>Pitfall</b>: Relying solely on fixed pixel values may lead to inconsistent UI across devices with different pixel densities.</li><li><b>Solution:</b> Use density-independent units (dp in XML, dp or sp in Compose) to ensure that UI elements scale appropriately on different screens.</li><li><b>XML DataBinding:</b></li></ul><div id="0838"><pre><span class="hljs-comment">&lt;!-- res/layout/activity_main.xml --&gt;</span>

<span class="hljs-tag"><<span class="hljs-name">TextView</span> <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">"wrap_content"</span> <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">"wrap_content"</span> <span class="hljs-attr">android:textSize</span>=<span class="hljs-string">"16sp"</span> <span class="hljs-attr">android:padding</span>=<span class="hljs-string">"8dp"</span> <span class="hljs-attr">android:text</span>=<span class="hljs-string">"Density-independent Text"</span> /></span></pre></div><ul><li><b>Jetpack Compose:</b></li></ul><div id="24b2"><pre>/<span class="hljs-regexp">/ src/main</span><span class="hljs-regexp">/kotlin/com</span><span class="hljs-regexp">/example/myapp</span><span class="hljs-regexp">/ui/</span><span class="hljs-title class_">MainScreen</span>.kt <span class="hljs-title class_">Text</span>( text = <span class="hljs-string">"Density-independent Text"</span>, fontSize = <span class="hljs-number">16</span>.sp, modifier = <span class="hljs-title class_">Modifier</span>.padding(<span class="hljs-number">8</span>.dp) )</pre></div><p id="c31d"><b>Ignoring Orientation Changes:</b></p><ul><li><b>Pitfall: </b>Neglecting landscape or portrait orientations may result in suboptimal user experiences.</li><li><b>Solution:</b> Design landscape-specific layouts for improved usability when the device is rotated.</li><li><b>XML Databinding Example:</b></li></ul><div id="6536"><pre><span class="hljs-comment"><!-- res/layout-land/activity_main.xml --></span> <span class="hljs-tag"><<span class="hljs-name">LinearLayout</span> <span class="hljs-attr">android:orientation</span>=<span class="hljs-string">"horizontal"</span> <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">"match_parent"</span> <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">"match_parent"</span>></span> <span class="hljs-comment"><!-- Landscape-specific UI components --></span> <span class="hljs-tag"></<span class="hljs-name">LinearLayout</span>></span></pre></div><ul><li><b>Jetpack Compose Example:</b></li></ul> <figure id="fcde"> <div> <div>

            <iframe class="gist-iframe" src="/gist/LethalMaus/c34e8858c7bf0d4ae15671d14f67b382.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="913c"><b>Neglecting Foldable Device Considerations:</b></p><ul><li><b>Pitfall:</b> Overlooking the unique form factor of foldable devices may lead to suboptimal user experiences.</li><li><b>Solution:</b> Incorporate resource qualifiers for foldable devices and tailor layouts to make the most of their capabilities.</li><li><b>XML Databinding Example:</b></li></ul><div id="f275"><pre><span class="hljs-comment">&lt;!-- res/layout-large/activity_main.xml --&gt;</span>

<span class="hljs-tag"><<span class="hljs-name">LinearLayout</span> <span class="hljs-attr">android:orientation</span>=<span class="hljs-string">"vertical"</span> <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">"match_parent"</span> <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">"match_parent"</span>></span> <span class="hljs-comment"><!-- Foldable device UI components --></span> <span class="hljs-tag"></<span class="hljs-name">LinearLayout</span>></span></pre></div><ul><li><b>Jetpack Compose Example:</b></li></ul> <figure id="6e49"> <div> <div>

            <iframe class="gist-iframe" src="/gist/LethalMaus/e3e1b19d494c32cae17f4908f2605805.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><h1 id="3fee">Extra Tricks for a Seamless Experience</h1><p id="0308"><b>Dynamic Spacing:</b></p><ul><li>Dynamically adjust spacing based on screen size using dimension resources.</li><li><b>XML Databinding Example:</b></li></ul><div id="1ddf"><pre><span class="hljs-tag">&lt;<span class="hljs-name">TextView</span>
<span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">"wrap_content"</span>
<span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">"wrap_content"</span>
<span class="hljs-attr">android:text</span>=<span class="hljs-string">"Dynamic Spacing"</span>
<span class="hljs-attr">android:layout_margin</span>=<span class="hljs-string">"@dimen/margin_standard"</span> /

Options

></span></pre></div><ul><li><b>Jetpack Compose Example:</b></li></ul><div id="a566"><pre><span class="hljs-selector-tag">Text</span>( text = <span class="hljs-string">"Dynamic Spacing"</span>, modifier = Modifier .<span class="hljs-built_in">padding</span>(<span class="hljs-built_in">dimensionResource</span>(id = R.dimen.margin_standard)) )</pre></div><p id="1ec8"><b>Responsive Font Sizes:</b></p><ul><li>Use dimension resources to adjust font sizes responsively.</li><li><b>XML Databinding Example:</b></li></ul><div id="7238"><pre><span class="hljs-tag"><<span class="hljs-name">TextView</span> <span class="hljs-attr">android:layout_width</span>=<span class="hljs-string">"wrap_content"</span> <span class="hljs-attr">android:layout_height</span>=<span class="hljs-string">"wrap_content"</span> <span class="hljs-attr">android:text</span>=<span class="hljs-string">"Responsive Font"</span> <span class="hljs-attr">android:textSize</span>=<span class="hljs-string">"@dimen/text_size_medium"</span> /></span></pre></div><ul><li><b>Jetpack Compose Example:</b></li></ul><div id="879d"><pre><span class="hljs-keyword">Text</span>( <span class="hljs-keyword">text</span> = <span class="hljs-string">"Responsive Font"</span>, fontSize = dimensionResource(id = R.dimen.text_size_medium).value )</pre></div><p id="ff03">Navigating the diverse landscape of screen sizes, orientations, and foldable devices requires attention to detail. By avoiding common pitfalls and implementing these extra tricks, you can create adaptive layouts that provide a seamless and enjoyable user experience across a wide range of devices.</p><h1 id="724b">Testing Across the Spectrum: Espresso, Firebase Device Farm, and Emulators</h1><p id="f7de">Ensuring your app performs seamlessly across diverse screen sizes and orientations requires a robust testing strategy. In this section, we’ll explore how to effectively test your application using Espresso, leverage Firebase Device Farm for comprehensive device coverage, and set up custom emulators tailored to your testing needs. Additionally, we’ll provide scripts for running these tests, both locally and within a continuous integration (CI) pipeline.</p><h2 id="d5d7">Espresso for Local Testing</h2><p id="3c72">Espresso is a powerful testing framework for Android that allows you to write concise and reliable UI tests. To test different screen sizes and orientations locally, you can use Espresso’s ViewMatchers and ViewActions in conjunction with the ViewAssertions to validate UI elements.</p><p id="1119"><b>Espresso Code Example:</b></p> <figure id="e57e"> <div> <div>

            <iframe class="gist-iframe" src="/gist/LethalMaus/d59c45ea83a143f9e81cabff1e5294b2.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><h2 id="ade1">Firebase Device Farm for Comprehensive Testing</h2><div id="c926" class="link-block">
      <a href="https://firebase.google.com/docs/test-lab">
        <div>
          <div>
            <h2>Firebase Test Lab</h2>
            <div><h3>Test your app on devices hosted in a Google data center.</h3></div>
            <div><p>firebase.google.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*_syWJhiB1iPapT92)"></div>
          </div>
        </div>
      </a>
    </div><p id="624c">Firebase Device Farm provides a cloud-based solution for testing your app on a wide range of real devices. You can create test matrices to cover different screen sizes, orientations, and devices, ensuring thorough testing across various configurations.</p>
    <figure id="f3c7">
        <div>
          <div>
            <img class="ratio" src="http://placehold.it/16x9">
            <iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F4_ZEEX1x17k%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D4_ZEEX1x17k&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F4_ZEEX1x17k%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" allowfullscreen="" frameborder="0" height="480" width="854">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="e689"><b>Firebase Test Lab Code Example:</b></p>
    <figure id="83a5">
        <div>
          <div>
            
            <iframe class="gist-iframe" src="/gist/LethalMaus/f4f1bc1cb5b2e0e9acd015c4b88d7697.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><h2 id="3b50">Emulator Setup for Custom Testing Environments</h2><p id="9c86">Android emulators provide a flexible way to create custom virtual devices for testing. You can configure emulators to match specific screen sizes, resolutions, and orientations to mimic real-world scenarios.</p><h2 id="d185">Custom Emulator Setup:</h2><p id="6b87"><b>Create a new emulator with AVD Manager: </b>Specify device details such as screen size, resolution, and orientation.</p><div id="cc39"><pre>emulator -avd <span class="hljs-title class_">Pixel</span>_6_API_32 -orientation portrait</pre></div><p id="2825"><b>Start the emulator:</b> Launch the emulator with the desired configuration.</p><h2 id="b314">Script for Running Tests Locally:</h2><div id="b14f"><pre><span class="hljs-meta">#!/bin/bash</span>

<span class="hljs-comment"># Assuming your Espresso tests are in the 'androidTest' directory</span> ./gradlew connectedAndroidTest</pre></div><h2 id="8c3b">Script for CI Pipeline (Firebase Device Farm Integration):</h2> <figure id="411f"> <div> <div>

            <iframe class="gist-iframe" src="/gist/LethalMaus/f42ef9d5be37616ab0d3f7c4fe74245e.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
          </div>
        </div>
    </figure></iframe></div></div></figure><p id="2828">By incorporating these testing strategies into your development workflow, you can ensure that your app functions seamlessly across a spectrum of screen sizes, resolutions, and orientations. Whether testing locally with Espresso, exploring diverse configurations on Firebase Device Farm, or creating custom emulators, a comprehensive testing approach is essential for delivering a high-quality user experience.</p><h1 id="1d6d">Conclusion</h1><p id="123e">It is more important than ever to design experiences that work seamlessly across a wide range of screen sizes, orientations, and foldable devices. This exploration of the nuances of multi-form factor testing and development has made the way clearer for developers trying to figure out how to deal with the challenges of the digital world.</p><p id="7a08">Using the ideas of adaptable design in both Jetpack Compose and XML databinding, developers can create layouts that fluidly adjust to the ever-widening range of devices. The adaptability provided by these methods guarantees that customers, irrespective of the device they use, get a consistent and enjoyable experience on smartphones, tablets, and foldables.</p><p id="8650">Testing, a cornerstone of app development, has been explored through the lenses of Espresso, Firebase Device Farm, and emulator setups. From local testing to cloud-based solutions, developers can employ a variety of tools to ensure their apps perform flawlessly across diverse environments. Whether running Espresso tests for specific configurations, leveraging Firebase for comprehensive device coverage, or scripting emulator setups for local and CI/CD pipeline testing, the arsenal is rich with options.</p><p id="bdba">As we approach to the end of this investigation, it is clear that embracing diversity is essential for success. By grasping the subtleties of various form factors, avoiding typical mistakes, and adding extra tactics, developers can make applications that are capable of surpassing constraints. In a world where creativity has no boundaries, progressive developers continue to be distinguished by their commitment to creating inclusive and flexible digital experiences.</p><p id="7b0b">I hope that this article acts as a compass for developers, helping them navigate the complexities of developing and testing multi-screen applications and providing inspiration for the construction of programmes that not only fulfil current needs but also remain robust in the face of future technological breakthroughs. We look forward to a time when consumers everywhere will be able to explore a universe of seamless possibilities with each tap, swipe, and fold.</p></article></body>

How Reading Fiction Can Make You A Better Ally

Photo by Seven Shooter on Unsplash

Since the galvanizing events of late May, I’ve seen a lot of (white) people recently turn to books for the answer on how to unlearn racism and “decolonize” their minds. Articles have been popping up left and right about what to read and watch for people who are newly concerned about their unconscious bias. These lists typically feature nonfiction books and essays by New York Times favorites like Ibram X. Kendi and Ijeoma Oluo. Don’t get me wrong — definitely read those. But it seems fiction has been mostly left out of that limelight in favor of textbook-style reading lists for people who want to graduate to Good Person™ as quickly as possible.

Nonfiction is necessary, powerful, and often gets to the heart of many issues in ways that are well-researched and expertly defined. But there comes a point where the social divide lies less in people’s ignorance of historical facts and present-day realities of racial discrimination, and more with a general lack of empathy for people who are different. Kayla Chadwick’s viral essay, “I Don’t Know How to Explain To You That You Should Care About Other People” summed it up best:

“I don’t know how to convince someone how to experience the basic human emotion of empathy…Our disagreement is not merely political, but a fundamental divide on what it means to live in a society, how to be a good person, and why any of that matters.”

While Chadwick’s essay was not specifically about race, I believe the sentiment applies to the core of all issues stemming from prejudice and discrimination. White people need to care about Black people. Straight people need to care about queer people. Rich people need to care about poor people. It all boils down to empathy.

So why read fiction?

I love novels.

In 2018, I made it my mission to read 100 books exclusively by authors of color. At the time, that decision was primarily motivated by a desire to get away from the predominantly white reading material that dominated by childhood, adolescence, and academic career. I was hoping to find representation that looked and felt more like myself than anything.

Yet in that process I have read stories about immigration, stories centering disabled characters, stories featuring religions and cultures I have never encountered — stories about identities and experiences that I have no personal connection to at all. And I have come to appreciate those stories more than I could have ever imagined. Even as a queer Black woman, I still have a lot of room to grow as an ally to communities I am not a part of, and fiction is continuously helping me do that.

Fiction plays a unique role in empathy building. A 2014 study demonstrated that there is a positive relationship between increased levels of fiction reading and multiple types of empathy. The research article noted that “written fiction can provide deeper insight into the minds of characters” than other forms of visual media. This can translate to real-world behaviors, such as the tendency towards helping other people.

Developing this emotional intelligence is important because the way marginalized people experience bigotry is inherently emotional. It cuts into a part of the human experience that fiction captures best. Nonfiction does not necessarily ask you to put yourself in the narrator’s shoes so much as it asks that you trust and believe their experiences and expertise. Fiction, on the other hand, asks you to think and feel alongside them.

One of the greatest strengths of fictional stories is giving readers the ability to occupy the head-space of a character as though they were that person. You spend time living their life with them, familiarizing yourself with their morals and values, and subsequently feeling the emotional weight of the various challenges they face in the story. When you are going through this process with characters that are of a different ethnicity, sexuality, religion, etc. you are better able to appreciate the humanity of other people.

“But I don’t like fiction/reading.”

Is that really true?

For most of us, the overwhelming majority of the media we consume is fiction. Unless you watch news reports and documentaries pretty exclusively, you probably enjoy far more fictitious media than you recognize. Think about your favorite movies and TV shows and figure out what appeals to you in those stories.

This is not homework.

Reading shouldn’t feel like a chore or a burden. If the novel you chose feels like a textbook and you’re counting down the pages until you can be done with it, put it down. Pick up something different. If you are unused to this type of reading, it will definitely feel like a challenge to open your mind to stories like this, but it shouldn’t feel unbearable.

A good book will play with your emotions. It will convey despair and anger and grief (as well as joy and hope and pride) in ways that seem almost tangible. If you are having strong negative emotions related to a story, that’s probably a sign of growth. But if you’re having strong negative emotions about the act of reading, chances are that’s not the book for you. As you come to read more, you will be able to better distinguish between material that is challenging your thoughts and perceptions in a good way, and material that you just don’t enjoy.

Not all fiction is created equal.

There are many authors, especially now, that have jumped on the bandwagon of performative allyship by peppering characters into their work for diversity brownie points. As we know from some of media’s most enduring tropes, not all representation is good or valuable. Some depictions hurt more than they help.

An easy way to avoid this is to choose stories that center diverse characters written by diverse authors. If you are seeking to gain a better understanding of a particular perspective, that experience is best sought out from the most direct source.

Read Black fiction from Black authors, read queer stories by queer writers, and read from a wide variety of sources because no one voice can capture an entire community.

Additionally, whenever possible buy the books. Support the authors and help demonstrate that there is a large demand for more diverse stories in literature.

Allyship is not a class you take once, pass, and never have to revisit. Reading one book is not going to “fix” you. Being a true ally is ongoing and lifelong. If you are actually committed to it, consider building this habit to continually improve your outlook. Above all, go into it with the expectation that this particular part of the growth process is something to look forward to. It will not always be easy, but there are genuinely enjoyable moments along the road to becoming a better person.

Especially when there are good books involved.

More on reading:

Books
Self Improvement
Personal Development
Social Justice
BlackLivesMatter
Recommended from ReadMedium