LightBlog

lundi 4 octobre 2021

Samsung’s next-gen Exynos chip with an AMD GPU will support ray tracing

While we’re still a few months away from Samsung’s next flagship smartphone lineup, leaks about the phones have already started popping up online. Over the last few weeks, we’ve seen leaked renders of all three devices in the upcoming Galaxy S22 series and learned quite a bit about their specifications. One of the recent leaks revealed that the Galaxy S22 Ultra would feature the Exynos 2200 chipset, featuring an ARM Cortex-X2 core clocked at 2.9GHz, three cores clocked at 2.8GHz, four cores clocked at 2.2GHz, and an AMD GPU clocked at 1250MHz.

Although Samsung hasn’t confirmed these specifications, it has previously announced that its next flagship Exynos chip would feature an AMD GPU. This adds some credibility to the aforementioned specifications. The AMD GPU in Samsung’s next-flagship Exynos chip will likely offer massive performance improvements over the Mali-G78MP14 on the Exynos 2100. In addition, Samsung claims that it will offer ray tracing support. In a recent post on Weibo (via Videocardz), the company said:

Ray tracing technology is an advanced graphics display technology supported on desktop GPUs. By calculating the position of light and the area of reflection, the pixels in the position area are rendered one by one to produce a lifelike effect. This technology is is also about to be carried on the mobile terminal of smartphones through Samsung Exynos GPU, taking the experience of mobile games to a higher level. (machine translated)

Along with the post, Samsung has shared an image that gives us a glimpse of the benefits of ray tracing on the upcoming Exynos GPU. However, the image is just for demonstration purposes, and it’s not actually rendered by a real GPU. It merely serves to show how ray tracing can illuminate objects better.

Samsung Exynos Ray Tracing Stock Image

Are you looking forward to experiencing ray tracing on a mobile device? Do you think it will offer significant benefits? Share your thoughts in the comments section below.

The post Samsung’s next-gen Exynos chip with an AMD GPU will support ray tracing appeared first on xda-developers.



from xda-developers https://ift.tt/3Beb6Yy
via IFTTT

It’s not just you: Facebook, Messenger, Instagram and Whatsapp are down

Facebook services across America, Europe, and Asia are being disrupted this morning, causing users of Facebook itself, Facebook Messenger, and its sister services Instagram and WhatsApp to throw up error messages when attempting to access any of the sites and services on any OS. The issue could be related to DNS, as none of the domains are returning an IP. The outage is also affecting services that offer a Facebook login, such as Pokemon Go.

Facebook has not yet publicly commented on the ongoing outages affecting all of its services. Even the Facebook Workplace Service Status is inaccessible at this moment. We’ll be sure to update this story as we learn more.

Down Detector shows a massive spike in reports from around 1130 EST today, across all four services.

At the time of writing, there has been no other acknowledgment from Facebook that the problem exists on any of its social media pages and as such, we’ve got no information on the cause of expected duration.

We’ll keep an eye on this Facebook outage and update you when we have some further information.

The post It’s not just you: Facebook, Messenger, Instagram and Whatsapp are down appeared first on xda-developers.



from xda-developers https://ift.tt/3oCuZSw
via IFTTT

T-Mobile announces Google One partnership with an exclusive 500GB storage plan

A leaked document back in August suggested T-Mobile would soon offer an exclusive Google One plan tier for its customers. That deal is now confirmed, with T-Mobile offering 500GB of cloud storage on Google One for $5/mo.

Via T-Mobile Newsroom, the Uncarrier will offer an exclusive storage tier to its customers starting October 12th. The plan comes with 500GB of family cloud storage for just $5/mo. This slots in perfectly between the 200GB for $2.99 and 2TB for $9.99 offerings Google currently has on their website. T-Mobile also mentions a 2TB plan for $10/mo available to customers, however this matches Google’s existing pricing.

The plan release was originally set for September 1st according to the leaked document from August. That date was delayed, possibly to align more with the upcoming shutdown of Sprint Complete’s cloud storage.

T-Mobile is offering a 30-day free trial for the new tier for a limited time, with auto renewal for $5/mo after that. Sprint customers who haven’t yet migrated to a T-Mobile plan will be able to claim the offer via the T-Mobile Tuesdays app at any point through the end of the year. According to the previous leak, all postpaid and business customers with 12 lines or less will be eligible for the offer. Customers on a tax-inclusive plan like T-Mobile ONE or T-Mobile Magenta will not pay tax on the Google One tier, however tax-exclusive plans will.

The 500GB plan can be shared with up to 5 other Google accounts. The new tier also appears to include the 10% cashback perk as well, however there’s no mention of the VPN service being included.

Customers interested in the 500GB Google One storage tier can sign up online or via support beginning October 12th.

Google One (Free+, Google Play) →

The post T-Mobile announces Google One partnership with an exclusive 500GB storage plan appeared first on xda-developers.



from xda-developers https://ift.tt/3a5BQig
via IFTTT

Get the AirPods Pro for $179 ($70 off) today, or regular AirPods for $109 ($50 off)

Apple’s line of AirPods products are some of the best wireless headphones around, but perhaps due to the abundance of competition, they’re more competitively-priced than most other Apple products. The normal AirPods and AirPods Pro are almost always on some level of discount, and now they have been lowered to $109.00 ($50 off original price) and $179.00 ($70 off MSRP), respectively. That’s within $10 of the lowest recorded prices for both products on Amazon.

The normal AirPods is one of the most popular pairs of true wireless earbuds, with easy pairing and one-tap Siri access on Apple devices. It charges through a Lightning connector, the same used on iPhones, but you can also get AirPods with a wireless charging case for $20 more. We’ve linked both below.

    AirPods Pro

    This pair of wireless earbuds has Active Noise Cancellation (ANC) and a case that supports wireless charging. It's on sale for $179, $70 below the original price.
    AirPods with Wireless Charging Case

    This is the regular AirPods, with the optional wireless charging case. It's on sale for $129, $70 below the original price.
    AirPods with Charging Case

    This is the regular Apple AirPods with no wireless charging in the case. It's priced at $109, $50 below the original price.

Finally, the AirPods Pro has an improved listening experience, with an in-ear design and support for Active Noise Cancellation (ANC). The case also supports charging with both Lightning cables and Qi wireless pads, like the upgraded case for the normal AirPods. It’s on sale for $179, which is $10 more than the lowest ever price on record from last year’s Black Friday sales.

The post Get the AirPods Pro for $179 ($70 off) today, or regular AirPods for $109 ($50 off) appeared first on xda-developers.



from xda-developers https://ift.tt/2ZXsJyb
via IFTTT

Surface Pro X vs Lenovo ThinkPad X12 Detachable: Which one is better?

Choosing a new PC is always a tough decision. There are lots of fantastic laptops out there, and nearly all of them have reasons why you might prefer them. Choosing between different devices isn’t always easy, but we’re here to help. We’re comparing Microsoft’s Surface Pro X to the Lenovo ThinkPad X12 Detachable, two detachable tablets that can also be used as laptops.

The Surface Pro X was recently updated to come in a Wi-Fi-only version as well, but it’s essentially still a two year old device. By comparison, the ThinkPad X12 Detachable was launched in 2021 with high-end components. You may already be able to guess where this is going, but let’s take a closer look.

Surface Pro X vs ThinkPad X12 Detachable: Specs

Surface Pro X Lenovo ThinkPad X12 Detachable
Processor
  • Microsoft SQ1 (up to 3GHz, 8-core)
  • Microsoft SQ2 (up to 3.15GHz, 8-core)
  • Intel Core i3-1110G4 (up to 3.9GHz, 2-core)
  • Intel Core i5-1130G7 (up to 4GHz, 4-core)
  • Intel Core i5-1140G7 vPro (up to 4.2GHz, 4-core)
  • Intel Core i7-1160G7 (up to 4.4GHz, 4-core)
  • Intel Core i7-1180G7 (up to 4.6GHz, 4-core)
Graphics
  • Adreno 685 (SQ1)
  • Andreno 690 (SQ2)
  • Intel UHD Graphics (Core i3)
  • Intel Iris Xe Graphics (Core i5, i7)
RAM
  • 8GB
  • 16GB
  • 8GB
  • 16GB
Storage
  • 128GB
  • 256GB
  • 512GB
  • 128GB
  • 256GB
  • 512GB
  • 1TB
Display
  • 13 inch PixelSense (2880 x 1920), touch, Surface Pen support
  • 12.3 inch Full HD+ (1020 x 1280) IPS, touch, 400 nits, COrning Gorilla Glass
Audio
  • Two 2W stereo speakers with Dolby audio
  • Two 1W stereo speakers with Dolby Audio
Webcam
  • 5MP, Full HD front-facing camera
  • 10MP, Full HD/4K rear-facing camera with autofocus
  • 5MP front-facing camera with privacy shutter
  • 8MP rear-facing camera
Biometric authentication
  • Windows Hello IR camera
  • Windows Hello IR camera
  • Optional: Fingerprint reader (on optional keyboard cover)
Battery life
  • Up to 15 hours of typical device usage
42Wh battery
  • Up to 10.36 hours of battery life (MobileMark 2018)
Ports
  • 2 USB Type-C
  • 1 Surface Connect port
  • Optional: nano SIM slot
  • 1 USB Type C 3.2 Gen 2 (with Power Delivery and DP 1.4)
  • 1 Thunderbolt 4/USB 4 (USB Type-C)
  • 3.5mm headphone jack
  • Pogo pin connector
  • Optional: nano SIM slot
Connectivity
  • Wi-Fi 5 + Bluetooth 5.0
  • Optional: LTE Advanced Pro (Qualcomm Snapdragon X24)
  • Wi-Fi 6 (2×2) + Bluetooth 5.1 (Intel Wi-Fi 6 AX201)
  • Optional: LTE (Fibocom L850-GL, Cat 9)
Colors
  • Platinum (SQ2 only)
  • Matte Black
  • Black
Size (WxDxH)
  • 11.3 x 8.2 x 0.28 in (287 x 208 x 7.3 mm)
  • 11.15 x 8.01 x 0.34 in (283.3 x 203.5 x 8.8 mm)
Weight
  • 1.7 lbs (774 g) (excluding keyboard)
  • 1.67 lbs (760 g) (excluding keyboard)
Starting price $899.99 $1,099.80 including keyboard (varies)

Performance: The Surface Pro X is aging rapidly

Comparing the Surface Pro X to any modern device is bound to be an unfair battle because Microsoft hasn’t done much to update the tablet since it debuted in 2019. It released a minor refresh in 2020, and this year, it just stripped LTE out to make it more affordable. Because of that, Intel processors now handily beat the Microsoft SQ1 and SQ2 processors inside the Surface Pro X. The only exception would be the Intel Core i3 model, which we probably wouldn’t recommend either way.

Here’s a quick comparison of these processors based on GeekBench scores:

Microsoft SQ2 Intel Core i3-1110G4 Intel Core i5-1130G7 Intel Core i7-1160G7
GeekBench 5 (single/multi-core) 796 / 3,206 1,025 / 1,893 1,287 / 4,793 1,413 / 4,992

One thing that’s worth noting is these Intel processors are what used to be called the Y-series, which means they use less power. That also means sustained performance won’t be quite as good as it would be on laptops with 15W processors, such as the Intel Core i5-1135G7. Still, it’s easy to see that these processors are significantly faster than the Qualcomm competition. Plus, with Intel Iris Xe graphics, integrated graphics are also faster on the ThinkPad X12 Detachable.

In terms of RAM and storage, the two tablets are fairly close, each maxing out at 16GB of RAM, with the caveat that you’ll need to opt for an Intel Core i5 processor or higher to get that configuration on the ThinkPad. For storage, the configurations are almost identical across the two, except the ThinkPad X12 Detachable can go up to 1TB, while the Surface Pro X maxes out at 512GB.

Lenovo ThinkPad X12 Detachable product image

Lenovo ThinkPad X12 Detachable

Finally, there’s battery life, and this is where the Surface Pro X gets its first win. Microsoft promises up to 15 hours of battery life with “typical usage”, while the Lenovo ThinkPad X12 Detachable is rated for 10.36 hours according to MobileMark 2018. These are different measurements, but MobileMark does test typical office scenarios, so the difference shouldn’t be too big. ARM-based processors like the Microsoft SQ2 are known for their efficiency, so this makes sense.

Display

One area where the Surface Pro X easily takes the win however, is the display. Featuring a 13 inch PixelSense display with a resolution of 2880 x 1920, the Surface Pro X is incredibly sharp. Plus, it comes in the tall 3:2 aspect ratio, which gives you more surface area both in landscape and portrait modes. The screen naturally supports touch and the Surface Slim Pen, but the pen isn’t included with the tablet.

The Surface Pro X has a sharper and bigger display, plus louder speakers.

On the other hand, the Lenovo ThinkPad X12 Detachable has a 12.3 inch Full HD+ (1920 x 1280) display, which is still fine, but nowhere near the sharpness of the Surface Pro X. It’s still an IPS panel, and protected by Corning Gorilla Glass, so it’s not like you’re getting a bad experience, but if you enjoy super-sharp screens, the Surface Pro X is better.

On the other hand, at least the Lenovo ThinkPad X12 Detachable includes the Lenovo Active Pen, so you can draw or jot down notes right away.

Screen on the Surface Pro X

Surface Pro X

Similarly, the Surface Pro X offers a better audio experience thanks to the dual 2W stereo speakers with Dolby Audio. The ThinkPad X12 Detachable also has two speakers and Dolby Audio support, but those speakers only have 1W of power, so they won’t be as loud or immersive.

As for the camera, both laptops have 5MP front-facing cameras with IR for facial recognition, but Lenovo has a privacy advantage since the camera includes a privacy shutter. On the back, the Surface Pro X takes the advantage with a 10MP camera that can record 4K video, while the ThinkPad X12 has an 8MP camera. Both laptops have dual far-field microphones for voice pickup, so you should sound great either way.

Design: The ThinkPad X12 Detachable has more ports

Turning to the design, the two tablets are fairly similar. Both being tablets, you can easily attach a keyboard to use as a laptop. Their dimensions are also fairly close, but the Surface Pro X is slightly taller and wider thanks to the larger screen. However, it’s also thinner, and in the end, both are super light at 774 grams for the Surface Pro X and 760 grams for the ThinkPad X12 Detachable.

Rear view of ThinkPad X12 Detachable with kickstand open

That’s without counting the keyboard since it’s detachable. It’s worth pointing out the ThinkPad X12 Detachable also includes a keyboard by default, at least on the configurations available from Lenovo’s website. With the Surface Pro X, you need to pay extra for the keyboard and pen. Aside from that, the keyboard on the ThinkPad X12 weighs in at 340 grams, and 5.4mm thick.

On the other hand, the Surface Pro Signature Keyboard weighs 281 grams (294 grams if you include the Surface Slim Pen 2) and 4.89mm thick. While the Surface Pro X is a bit more portable because of that, you’ll probably get a sturdier and more comfortable keyboard with the ThinkPad X12 Detachable due to its larger size.

With Thunderbolt, it’s easy to plug in docks, displays, and external GPUs on the ThinkPad X12 Detachable.

Where the biggest difference lies however, is the ports. Being powered by Intel processors, the ThinkPad X12 includes Thunderbolt 4 support, in addition to a standard USB Type-C port and a headphone jack. The Surface Pro X only has two USB Type-C ports, plus a Surface Connect port, and no headphone jack.

While Surface Connect offers somewhat similar capabilities, it doesn’t have as much bandwidth as Thunderbolt, and the ecosystem is much smaller. You can find a lot of Thunderbolt docks, but for Surface, you pretty much only have the Surface Dock 2.

Connectivity: The Surface Pro X has faster LTE

For mobile workers, LTE connectivity can be very important to stay connected to the internet without depending on Wi-Fi. Thankfully, both tablets support LTE in some capacity, but the Surface Pro X should be noticeably faster. It has a Qualcomm Snapdragon X24 modem, which supports LTE Cat 20, with downloads up to 2Gbps and upload speeds up to 316Mbps. Plus, adding LTE will generally only add $100 to the price of the tablet compared to the Wi-Fi-only versions.

Top angled view of Surface Pro X in Platinum

On the other hand, the ThinkPad X12 uses a Fibocom L850-GL model with support for LTE Cat 9. That gives you up to 450Mbps download speeds, and just 50Mbps for uploads, which isn’t fantastic. Plus, it’s going to add around $200 to the price, excluding any discounts Lenovo may be offering (it actually seems to add just $120 at the time of writing).

Aside from cellular, the ThinkPad X12 Detachable does offer faster Wi-Fi thanks to Wi-Fi 6 support and it also supports Bluetooth 5.1. By comparison, the Surface Pro X still only has Wi-Fi 5 and Bluetooth 5.0.

Bottom line

Comparing the Surface Pro X and Lenovo ThinkPad X12 Detachable more closely, it becomes easy to see where the two differ, and that those differences are actually very significant. In each of the categories we looked at, there’s a clear winner, and that makes it easier to choose between the two.

If you want better CPU and GPU performance, or if Thunderbolt connectivity is important to you, the ThinkPad X12 Detachable is clearly the way to go. The performance difference is significant, and Thunderbolt does offer a lot more connectivity options than the Surface Connect port. Plus, the ThinkPad X12 Detachable includes a keyboard and pen already, which you have to pay extra for when buying a Surface Pro X.

ThinkPad X12 Detachable tablet with pen underneath

On the other hand, Microsoft’s Surface Pro X has a much sharper and slightly larger display, better audio, and much faster LTE speeds if you want to go that route. While it’s slightly larger, it’s just as portable, and when you consider the add-on keyboard and pen, it’s actually lighter than Lenovo’s offering. It also touts better battery life and a slightly higher quality rear camera, so those are big benefits, too.

At the end of the day, your preference will dictate which option is best, but the benefits of one device over the other are clearer than in many other comparisons, so the choice should be easy to make. You can buy either one of the tablets using the links below.

Not looking for tablets? We also have a list of the best Lenovo ThinkPads you can check out if you’re looking for something else.

    Surface Pro X
    The Surface Pro X is a premium ARM-based tablet, offering great performance and battery life in a thin and lightweight design. It now comes in a Wi-Fi-only model.

For the Surface Pro X, you can also buy the Surface Pro Signature Keyboard with the Surface Slim Pen 2 to complete the experience.

    Lenovo ThinkPad X12 Detachable
    The Lenovo ThinkPad X12 Detachable is a lightweight and capable Intel-powered tablet, with a keyboard that can be attached whenever needed.

The post Surface Pro X vs Lenovo ThinkPad X12 Detachable: Which one is better? appeared first on xda-developers.



from xda-developers https://ift.tt/3mpr8J6
via IFTTT

ASUS partners with Noctua to make the coolest RTX 3070 GPU for enthusiast builds

The rumors about a possible collaboration between ASUS and Noctua have been afloat for quite some time now, and we finally have confirmation on the “ASUS x Noctua” themed GeForce RTX 3070 GPU. Yes, the very distinctive GPU design with the unmistakable brown Noctua fans is now official and it’s called ASUS GeForce RTX 3070 Noctua Edition.

According to the official release, the ASUS GeForce RTX 3070 Noctua Edition graphics card is the world’s first GPU to use Noctua fans and their tailored heatsink. It’s said to be “the Coolest & Quietest Graphics Card in Its Class”. We have been blessed with two variants of the GPU called the ASUS GeForce RTX 3070 Noctua Edition and the ASUS GeForce RTX 3070 Noctua OC Edition. Before we talk about the USP that makes these cards special, let’s take a quick look at the specifications –

ASUS GeForce RTX 3070 Noctua Edition GPU Specifications

Specification ASUS GeForce RTX 3070 Noctua Edition ASUS GeForce RTX 3070 Noctua OC Edition
Graphic Engine Nvidia GeForce RTX 3070 Nvidia GeForce RTX 3070
Bus Standard PCI Express 4.0 PCI Express 4.0
Video Memory 8GB GDDR6 8GB GDDR6
Engine Clock 1725 MHz (Boost Clock) @ Gaming mode
1755 MHz (Boost Clock) @ OC mode
1815 MHz (Boost Clock) @ Gaming mode
1845 MHz (Boost Clock) @ OC mode
CUDA Core 5888 5888
Memory Speed 14 Gbps 14 Gbps
Memory Interface 256-bit 256-bit
Interface Yes x 2 (Native HDMI 2.1)
Yes x 3 (Native DisplayPort 1.4a)
HDCP Support Yes (2.3)
Yes x 2 (Native HDMI 2.1)
Yes x 3 (Native DisplayPort 1.4a)
HDCP Support Yes (2.3)
Recommended PSU 750W 750W
Dimensions 310 x 147 x 87.5 mm
12.20 x 5.79 x 3.45 inches
310 x 147 x 87.5 mm
12.20 x 5.79 x 3.45 inches
Power Connectors 2 x 8-pin 2 x 8-pin
Maximum Display Support 4 4
Slot 4.3 Slot 4.3 Slot
NVlink/ Crossfire Support No No

ASUS GeForce RTX 3070 Noctua Edition Features

What you are essentially looking at is a combination of two iconic NF-A12x25 PWM fans with a custom-made thermal solution on a custom PCB. This unique design will be highly beneficial for the quiet cooling enthusiasts because Noctua says it allows for a reduction in noise levels of up to 15dB(A), making it the quietest card in its class.

How quiet, you ask? According to the internal testing under ideal testing conditions, Noctua says the GPU registers only 12.6dB(A). That makes it not only quiet but near inaudible. Noise reduction levels of up to 15dB(A) sounds good, but the fine print says that you will only see that much reduction in fan noise at medium fan speeds. At maximum fan speeds, that number goes down to 9dB(A). If you have a PC case with good ventilation and moderate ambient temperatures of 24°C or lower, then this GPU will achieve a reduction in noise levels of 5.7dB(A) as compared to the standard version.

In addition to a whole lot of numbers, the GPU also has some other nifty features that are not available on the Founders Edition cards. The GeForce RTX 3070 Noctua Edition features a semi-passive fan control setup (ASUS 0dB technology) that can switch the fans off completely whenever the GPU temperature goes below 50°C. This means the card can run entirely fanless at lower GPU loads such as during office productivity tasks, web browsing, or even light gaming. But don’t count on that unless you have a well-ventilated case and low to moderate ambient temperatures.

Since this is also a product of ASUS, you will be able to set custom fan curves via ASUS’ GPU Tweak software. That’s another value proposition for enthusiast PC builders. In fact, we think this GPU could potentially be a solid companion for Noctua’s NH-P1 passive cooler. Running a completely fanless system even for typical productivity tasks is quite challenging but it’s definitely doable. And this is where the ASUS GeForce GeForce RTX 3070 Noctua Edition enters the scene for quiet cooling enthusiasts.

ASUS GeForce RTX 3070 Noctua Edition Pricing & Availability

While we don’t have an official date of availability or the pricing info for these GPUs, you can expect to get your hands on them starting mid-October 2021. If you are lucky enough to find it in stock, of course. As for the pricing, we expect them to be priced similarly to the other ASUS RTX 3070 GPUs on the market.

The post ASUS partners with Noctua to make the coolest RTX 3070 GPU for enthusiast builds appeared first on xda-developers.



from xda-developers https://ift.tt/2YeKw38
via IFTTT

Android Development Basics: How to add View Binding to an Android Gradle project

Most Android developers are probably familiar with the classic findViewById() method. Pass it an ID of one of the Views in your XML layout and it’ll return a reference to the inflated version of that View. That’s all assuming you passed the right ID though, and that the View actually exists. findViewById() has no checks built in to prevent you from trying to retrieve a View you can’t retrieve. Enter View Binding.

Instead of using findViewById() on each View you want, View Binding automatically generates a binding class for each layout XML. Each View with an ID is automatically added to the class, so you can reference them directly.

Adding View Binding to an Android Gradle project is super simple.

Gradle Setup

View Binding is enabled at the module level in Gradle. If you have multiple modules, you’ll need to enable it individually for each one.

In the android block in your module-level build.gradle, add the option to enable View Binding.

android {
    ...

    buildFeatures {
        viewBinding true
    }
}

There may be a warning about illegal access, but that’s a lint bug and can be safely ignored.

Sync the project and View Binding will be enabled. It’s that easy.

Using View Binding

There are a few ways to use View Binding, but before any of that happens, let’s talk about how the binding classes are generated.

Class Name Syntax

Say you have a layout XML named some_layout.xml. Its corresponding binding class will be named SomeLayoutBinding. That pattern holds for all files.

Each word (separated by underscores in the file name) will be capitalized, and the underscores will be removed. “Binding” then gets added to the end.

Instantiating with Existing View

If you’ve already inflated the layout file and you have a reference to the root of the layout, you can tell the View binding class to use the existing layout.

Kotlin:

val binding = SomeLayoutBinding.bind(someLayoutRoot /* should be a View instance */)

Java:

SomeLayoutBinding binding = SomeLayoutBinding.bind(someLayoutRoot /* should be a View instance */);

For example, if you wanted to use the binding class in a Fragment, it would look something like this.

Kotlin:

class SomeFragment : Fragment(R.layout.some_layout) {
    //Lazy initialization means bind() won't be called until "binding" is referenced.
    private val binding by lazy { SomeLayoutBinding.bind(view) }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        
        //Once this method is called, you can start using the binding.
    }
}

Java:

public class SomeFragment extends Fragment {
    private SomeLayoutBinding binding = null;

    public SomeFragment() {
        super(R.layout.some_layout);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
   
        //Initialize the binding.
        binding = SomeLayoutBinding.bind(view);
    }
}

Instantiating with New View

The binding class can also take care of inflating the layout for you.

Kotlin:

val binding = SomeLayoutBinding.inflate(layoutInflater /* should be a LayoutInflater instance */)

Java:

SomeLayoutBinding binding = SomeLayoutBinding.inflate(layoutInflater /* should be a LayoutInflater instance */);

This method is useful in both Fragments and Activities.

An example Fragment would look something like the following.

Kotlin:

class SomeFragment : Fragment() {
    private val binding by lazy { SomeLayoutBinding.inflate(LayoutInflater.from(requireContext())) }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) {
        //The "root" of the binding class is the root of its layout.
        return binding.root
    }
}

Java:

public class SomeFragment extends Fragment {
    private SomeLayoutBinding binding = null;

    @Override
    public void onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //Initialize the binding.
        binding = SomeLayoutBinding.inflate(inflater);
        //The "getRoot()" method of the binding class returns the root of the layout.
        return binding.getRoot();
    }
}

An example Activity would look something like the following.

Kotlin:

class SomeActivity : AppCompatActivity() {
    private val binding by lazy { SomeLayoutBinding.inflate(layoutInflater) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        //This is equivalent to calling "setContentView(R.layout.some_layout)" but allows use of the binding class.
        setContentView(binding.root)
    }
}

Java:

public class SomeActivity extends AppCompatActivity {
    private SomeLayoutBinding binding = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Instantiate the binding.
        binding = SomeLayoutBinding.inflate(getLayoutInflater());
        //This is equivalent to calling "setContentView(R.layout.some_layout)" but allows use of the binding class.
        setContentView(binding.getRoot());
    }
}

Referencing Views

Now that the View binding class is set up and ready to use, it’s time to actually use it.

Let’s say the contents of the some_layout.xml are something like the following:

<LinearLayout
    android:id="@+id/root_view"
    ...>
    <FrameLayout
        android:id="@+id/some_frame_layout"
        ...
        />
    <ImageView
        android:id="@+id/some_imageview"
        ...
        />
    <LinearLayout
        android:id="@+id/inner_linear"
        ...>
        <ImageView
            android:id="@+id/inner_imageview"
            ...
            />
    </LinearLayout>
</LinearLayout>

There are a lot of IDs there to reference in code. But as long as you have the binding class instantiated, referencing will be easy.

In Kotlin, Views are referenced by variables matching their IDs, with some changes. Underscores are removed and the resulting string is camel-cased. For example, to reference some_frame_layout from code, you’d use binding.someFrameLayout. The someFrameLayout variable will be an instance of FrameLayout.

val someFrameLayout: FrameLayout = binding.someFrameLayout

In Java, Views are referenced by getter methods matching their IDs, with a similar format to Kotlin. For example, to reference some_frame_layout, you’d use binding.getSomeFrameLayout(). The method will return an instance of FrameLayout.

FrameLayout someFrameLayout = binding.getSomeFrameLayout();

The View references are also flattened in the binding. Referencing inner_imageview is the same as referencing some_frame_layout.

Conclusion

As I’m sure you can see, View Binding in Android is both easy to implement and easy to use. In many cases, it’s easier to use than findViewById().

For more details on implementing View Binding, along with some examples, check out Google’s official documentation.

The post Android Development Basics: How to add View Binding to an Android Gradle project appeared first on xda-developers.



from xda-developers https://ift.tt/3uCf6zy
via IFTTT