Quantcast
Jump to content


Report

  • Similar Topics

    • By Samsung Newsroom
      In the dynamic landscape of mobile technology, the introduction of the Jetpack Compose toolkit has opened a lot of opportunities for developers to create beautiful, seamless applications using declarative UI. Using this new model of UI development, developers can create adaptable applications targeting a wide range of mobile devices.
      In this post, we learn how to integrate Android's new adaptive library into a pre-built compose application and leverage its APIs to create a dynamic user interface.
      Overview of the application
      Figure 1: Application UI on the Galaxy Z Flip5

      The example application is a simple list of mobile devices for sale. It is built using an ElevatedCard composable that is displayed by a LazyVerticalGrid composable. Each card is modeled after a data class named Mobile. Let’s take a look at the data class and composable functions below:
      /// Data class to hold Mobile data data class Mobile( @StringRes val name: Int, @DrawableRes val photoId: Int, val price: String ) /// MainActivity.kt class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { ComposeAppTheme { MyApp() } } } } @Composable fun MyApp(){ Surface( modifier = Modifier .fillMaxSize() .statusBarsPadding(), color = MaterialTheme.colorScheme.background ) { MobileGrid( modifier = Modifier.padding( start = 8.dp, top = 8.dp, end = 8.dp, ) ) } } @Composable fun MobileGrid(modifier: Modifier = Modifier){ LazyVerticalGrid( columns = GridCells.Fixed(2), verticalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = modifier ) { items(MobileDataSource.mobiles) { mobile -> MobileCard(mobile) } } } @Composable fun MobileCard(mobile: Mobile, modifier: Modifier=Modifier){ ElevatedCard() { Row { Image( painter = painterResource(id = mobile.photoId), contentDescription = null, modifier = modifier .size(width = 68.dp, height = 68.dp), contentScale = ContentScale.Crop ) Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { Text( text = stringResource(id = mobile.name), modifier = Modifier.padding( start = 16.dp, top = 16.dp, end = 16.dp, ), style = MaterialTheme.typography.labelLarge, ) Text( text = mobile.price, style = MaterialTheme.typography.labelSmall, ) } } } } As we’ve seen, the application UI looks good on the Samsung Galaxy Z Flip5. But how does it look on the Galaxy Z Fold5?
      Figure 2: Application UI on the Galaxy Z Fold5

      On the Galaxy Z Fold5, the cards are now very stretched and contain a lot of blank space. The unfolded state of foldable devices has a larger screen size and it is important to keep large screens in mind when developing your application. Otherwise, the application may look great on conventional mobile devices, but very off putting on larger devices such as tablets, foldables, and so on.
      Create an adaptive layout for your application
      The material-3 adaptive library provides some top-level functions that we can leverage to adapt our applications to different form factors. We will use the currentWindowAdaptiveInfo() function to retrieve the WindowSizeClass. The WindowSizeClass allows us to catch breakpoints in the viewport and change the application UI for different form factors. Follow the steps below to change the application's appearance depending on the screen size.
      Add the following dependencies to the app-level build.grade file ... implementation "androidx.compose.material3.adaptive:adaptive:1.0.0-beta04" ...
      Create a variable called windowSizeClass to store the WindowSizeClass from currentWindowAdaptiveInfo() in the MobileGrid() composable. It contains a member variable named widthSizeClass that is a type of WindowWidthSizeClass. The possible values of this class are Compact, Medium, and Expanded. We will use this value to change the layout of the application. Create a new variable named numberOfColumns to dynamically set the number of grid columns in the MobileGrid() composable depending on the width of the screen.fun MobileGrid(modifier: Modifier = Modifier){ val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass val numberOfColumns: Int = when(windowSizeClass.windowWidthSizeClass) { WindowWidthSizeClass.COMPACT -> 2 WindowWidthSizeClass.MEDIUM -> 3 else -> 4 } LazyVerticalGrid( modifier = modifier, columns = GridCells.Fixed(numberOfColumns), verticalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp) ) { items(MobileDataSource.mobiles) { mobile -> MobileCard(mobile) } } } NoteTo learn more about the viewport breakpoints of WindowSizeClass, check out the official documentation by Android. That's all! Your application now has a seamless, responsive UI that changes based on the size of the screen it is being displayed on. Let's see what it looks like now on the Galaxy Z Fold5.
      Figure 3: Updated UI on the Galaxy Z Fold5

      Add support for pop-up view
      Android enables users to improve their efficiency by leveraging its multi-tasking features. More than half of foldable users use the split-screen, multi window, or pop-up modes daily, so it is imperative that modern applications integrate support for these viewing modes. Let's have a look at the UI in pop-up mode.
      Figure 4: UI on the Galaxy Z Fold5 - pop-up mode

      As you can see, the UI is completely broken in pop-up mode. The mode has a much smaller viewport width and height, so it'd be better to display just 1 column of tiles. We can do this by using the currentWindowSize() function from the adaptive library that uses the WindowMetrics class to calculate the width and height of the viewport. Create a variable named currentWindowWidthSize and retrieve the window width size using the function. If the viewport width is too low, less than 800 pixels in the example below, we can set the numberOfColumns variable to 1.
      @Composable fun MobileGrid(modifier: Modifier = Modifier){ val windowSizeClass = currentWindowAdaptiveInfo().windowSizeClass val currentWindowWidthSize = currentWindowSize().width val numberOfColumns: Int = when(windowSizeClass.windowWidthSizeClass) { WindowWidthSizeClass.COMPACT -> { if(currentWindowWidthSize < 800) 1 else 2 } WindowWidthSizeClass.MEDIUM -> 3 else -> 4 } LazyVerticalGrid( modifier = modifier, columns = GridCells.Fixed(numberOfColumns), verticalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp) ) { items(MobileDataSource.mobiles) { mobile -> MobileCard(mobile) } } } Figure 5: Updated UI on the Galaxy Z Fold5 - pop-up mode

      Conclusion
      You have now successfully used the new material-3 adaptive library to change the layout of your application to support foldables and large screen devices in portrait, landscape, split-screen or pop-up modes. By leveraging Jetpack Compose and Android APIs, you can create a consistent and optimized user experience across various screen sizes and device types. If you are interested in developing adaptive applications in XML, check out the links in the section below.
      Related content
      Best Practices of App Development for Various Screen Sizes Foldables and Large Screens Develop a Widget For Flex Window Implement Flex Mode on a Video Player Galaxy Z Documentation View the full blog at its source
    • By BGR
      The Galaxy S22 has been a big success for Samsung so far, but the new flagship series isn’t without problems or controversies. The latest issue concerns the Galaxy S22 Ultra, as Samsung’s new Note model seems unable to hold a GPS connection.
      That’s the kind of problem that would impact any app that relies on location data. You’ll need GPS for Google Maps and other navigation apps. And you’ll also be using it whenever you want to share your location with someone else.
      Don't Miss: Wednesday’s deals: $50 Echo Buds, secret Fire TV deal, Oral-B sale, Samsung monitors, more The current controversies
      Before we get to the GPS issues, let’s look at the Galaxy S22’s other problems.
      I’ve recently highlighted four reasons not to buy the Galaxy S22, even when better price deals arrive. One of those concerns the Galaxy S22’s ability to survive drops, but it’s immediately fixable. The Galaxy S22 Ultra seems especially fragile in such accidents. You can reduce the risk by getting protective accessories from the first day.
      We then have Samsung misleading buyers regarding the Galaxy S22 and Galaxy S22 Plus display efficiency. Similarly, the 45W fast charging support available on the Plus and the Galaxy S22 Ultra seems to be a marketing gimmick.
      The most important issue concerns the phone’s performance. The throttling issue that was widely covered in the past few weeks might be hiding a more significant problem with Samsung’s flagships. It might be a chip a cooling issue. Samsung said in an explanation to shareholders that it hasn’t been cutting costs, however.
      That’s to say that the Galaxy S22 series is already drawing attention for the kind of faults you wouldn’t expect from a flagship. The GPS signal loss problem falls in the same category.
      Samsung Galaxy S22 Ultra in white, with stylus. Image source: Samsung The Galaxy S22 Ultra GPS problems
      Addressing camera quality issues, leaker Ice Universe also observed on Twitter that the Galaxy S22 is the best-selling Samsung flagship in years. But also the one suffering from the most problems. The leaker previously criticized Samsung for the throttling issue.
      The GPS connectivity complaints come from elsewhere, however. Android World detailed the problem, explaining that Galaxy S22 Ultra users would encounter GPS issues from the first boot. The problem can persist even after updates, and the GPS won’t work.
      A post on a Samsung Community forum in Europe has some 202 replies showing that some Galaxy S22 Ultra buyers have experienced the GPS problem. But the issue doesn’t appear to be widespread at the moment.
      There’s no fix for it either. The blog notes that resetting the APN settings might work. You can also consider resetting network settings. Whatever it is, it might be a problem with the phone rather than apps that need location data to work.
      If you’ve experienced any Galaxy S22 Ultra GPS issues, you can consider reaching out to Samsung for help.
      The post Some Galaxy S22 Ultra units might have a GPS connectivity issue appeared first on BGR.
      View the full article




×
×
  • Create New...