LightBlog

lundi 26 septembre 2016

Sony Xperia X Compact review

While we have seen a lot of "mini" iterations of popular flagship smartphones, these devices tend to fall in the mid-range category. Sony is the lone holdout in this regard, with their Compact devices only shrinking in size, while retaining the specifications and features of their flagship counterparts, which is the case with one of Sony's latest offerings, the Xperia X Compact.

Is there still a market for such compact smartphones, and what does this device have to offer? We find out, in this comprehensive Sony Xperia X Compact review!

Buy the Sony Xperia X Compact now

Design

Sony Xperia X Compact Review-1

While the Xperia X Compact is technically a smaller version of the Xperia X that was announced back at MWC this year, it borrows its design language from the flagship Xperia XZ that was launched alongside it at IFA 2016. However, it doesn't feature the premium build quality of its high-end counterpart, with the Xperia X Compact being made entirely of plastic.

The X Compact may not offer the same feel as other Sony devices that offer metal and glass builds, but the phone is surprisingly sturdy. It comes with a very glossy finish, that gives it a ceramic look that is really nice, but does make for a huge fingerprint magnet. The top and bottom of the phone are completely flat, which means that the device can stand on its own, and there are frosted matching color inserts that flow well with the rest of the design.

Sony Xperia X Compact Review-4

The X Compact also features what Sony is calling a "loop" design, which is essentially a fancy way of explaining the tapers along the sides the make the transition from glass to plastic seamless, and makes the phone more comfortable to hold. Despite some aesthetic changes, the signature rectangular shape that Sony is known for is still seen here.

The best part about the Sony Xperia X Compact is how easy it is to use with one hand, which is obviously the point of a mini smartphone. With so many large display phones out there, it is quite refreshing to use a device that is this compact, with a screen that you can reach across very easily and without any hand gymnastics.

Sony Xperia X Compact Review-7

Taking a look around the device, the headphone jack and USB Type C port are at the top and bottom respectively, on the left side is the slot for the SIM card and microSD card, and on the right are the power button, volume rocker, and a dedicated camera button. The physical camera shortcut key is extremely convenient, with it not only providing a quick and easy way to launch the camera, but also because it works as a shutter button.

However, having all these buttons on one side can make it feel a touch cluttered, and the volume rocker sits too far down to make it comfortable to reach with your thumb. The position of the volume keys do make sense when using them to adjust the digital zoom of the camera, but is not in the optimal position for controlling the volume, which is its primary purpose.

Sony Xperia X Compact Review-10

The Xperia X Compact also comes with a fingerprint sensor that is embedded into the power button, but for reasons unknown, this isn't available with the US version of the device, which is certainly an extremely odd choice. Unlike its flagship counterparts and previous Compact smartphones from Sony, the X Compact doesn't come with dust and water resistance, which is another surprising omission, and could be a deal breaker for some.

Display

Sony Xperia X Compact Review-15

The Xperia X Compact comes with a 4.6-inch IPS LCD display with 720p resolution, resulting in a pixel density of 319 ppi. 720p may not be particularly impressive in the current scheme of things, but is certainly more than enough with a display of this size. The display is plenty sharp, and there have been no issues with reading text.

The display is pretty good, offering nice color reproduction and saturation, and good viewing angles. The screen also gets surprisingly bright, allowing for a comfortable viewing experience even in direct sunlight. Typing on the small screen isn't much of an issue, but the media consumption experience isn't going to be as good, not because of the quality of the display, but because of its size. It's something that will take some getting used to, but is certainly not a deal breaker by any means.

Performance

Sony Xperia X Compact Review-12

Under the hood, the Xperia X Compact retains the same processing package as its larger namesake, the Qualcomm Snapdragon 650 processor, backed by the Adreno 510 GPU and 3 GB of RAM. Even though it doesn't feature top of the line specifications, performance hasn't been an issue with the X Compact.

Everything has been fast and responsive, and the device can even handle high-end games without struggling. Granted, the load times may be a little longer, but once a game loads, it runs very smoothly, with rarely any dropped frames to be seen. Overall, the performance has been quite impressive, and goes beyond what you would expect from a mid-range processor like the Snapdragon 650.

Hardware

Sony Xperia X Compact Review-11

As far as storage goes, 32 GB is your only option, but expandable storage via microSD card allows you to add up to 256GB additional storage, which should take care of all your needs.

Above and below the display are two thin slits that house the dual front-facing stereo speakers. The overall volume is on the quieter side when compared to other front-facing setups, but the quality of the sound is actually quite good, with clean, clear sound, with no distortion.

Sony Xperia X Compact Review-2

However, you will have a far better audio experience when plugging in a pair of headphones. The Xperia X Compact has built in support for Hi-Res Audio like FLAC, ALAC, DSD, and LPCM, but if you don't have audio in these formats already, the device can also upscale any compressed audio files to give it a Hi-Res sound.

The Xperia X Compact comes with a 2,700 mAh battery, which allows for surprisingly good battery life, helped along by the relatively lower resolution display that it has to power. The battery comfortably provides a full day of use, and even with heavy usage that involved a lot of gaming and watching videos on Youtube, I rarely had to charge the device in the middle of the day.

The device comes with Qualcomm QuickCharge 3.0 support, and given the capacity of the battery, it doesn't take long to get back to a full charge at all. However, one thing to remember is that Sony doesn't include a QC 3.0 charger in the box, so you will have to pick up a third-party one to take advantage of the phone's fast charging capabilities.

Camera

Sony Xperia X Compact Review-6

Sony is also making a big deal about the camera of the Xperia X Compact. The front 5 MP shooter is a fairly standard wide angle lens camera, and gets the job done when it comes to taking selfies. On the back is a 23 MP camera, which is the same sensor that is found with Sony's higher-end offerings like the Xperia XZ.

To improve the camera, Sony has added a new laser auto focus system to help with sensing distance and taking better shots in low light situations, and there is also a new color sensor to help you get much better white balance. The real kicker here is that the X Compact has 5 axis image stabilization for both the front and rear cameras when recording video, but there is no physical hardware inside to make this stabilization happen, with all the stabilization being software based.

Sony Xperia X Compact Review-17

Before you get too excited though, the 5 axis stabilization is utilized only when recording "macro" shots, so unless you see the word macro pop up in the corner of the viewfinder, you only get 3 axis stabilization, which does work well to keep the footage stable and without any warping or distortion. It is somewhat strange that Sony hyped a feature that is used only in limited situations, since macro video isn't something a lot of people typically use their smartphones to record.

The camera application offers what we've come to expect from Sony devices, and it doesn't look like it has changed significantly over the years. You can swipe up or down on the viewfinder to switch between various modes, that include Superior Auto, manual, and video recording, along with the slew of camera effects that Sony always adds. It isn't the most intuitive camera app, and HDR still only works when using the manual mode, but the overall camera shooting experience is fairly straightforward.

Sony Xperia X Compact camera samples:

It is easy to quickly launch the camera and take a shot using the dedicated camera shutter button, and the image quality is well above average. Images are extremely sharp and well detailed, and while there is a good amount of color and saturation to be had, shots do look more natural when compared to the oversaturated photos that are taken with some other smartphones.

The camera also has a predictive hybrid auto focus feature that can continuously track moving objects and capture them without motion blur. As long as the object isn't moving ridiculously fast, this feature does work really well. In low light conditions, there is still a fair amount of detail to be had, and images generally tend to be noise free. However, the shutter speed can be really slow in such lighting situations, so very steady hands will be required to avoid blurry photos.

Software

Sony Xperia X Compact Review-13

On the software side of things, the Xperia X Compact is running Android 6.0 Marshmallow with Sony's custom skin on top. Calling it a custom skin is certainly a stretch however, considering how many stock Android elements are to be found throughout the user interface.

Sony has really scaled back on their own customizations, and has even gone as far as to add the Google Now homescreen to this launcher, which really makes the experience feel closer to stock. That said, it does come with a lot of bloatware, including pre-installed Sony apps and a few third-party ones, but all of these can be disabled and moved out of the way.

Overall, Sony has done a fantastic job with keeping the software experience clean and simple, which is also a contributing factor to the smooth performance that is available with the Xperia X Compact.

Specifications

  Sony Xperia X Compact
Display 4.6" HD Triluminos IPS LCD
Processor Hexa-core, 64-bit Snapdragon 650 (2 x 1.8 GHZ, 4 x 1.2 GHz)
RAM 3 GB
Storage 32 GB + microSD
Dimensions 129 x 65 x 9.5 mm
Weight 135g
IP rating No
Main camera 23 MP, predictive hybrid auto-focus, triple image sensing technology, 5-axis stabilization
Front camera 5 MP
Battery 2,700 mAh, Quick Charge 3.0, Qnovo Adaptive Charging, USB Type-C
Fingerprint sensor Yes
Networks GSM GPRS/EDGE (2G), UMTS HSPA+ (3G), Cat. 6 LTE
Connectivity A-GNSS (GPS + GLONASS), Wi-Fi Miracast, Bluetooth 4.2, NFC

Gallery

Pricing and final thoughts

So there you have it for this in-depth look at the Sony Xperia X Compact! The unlocked version of the Xperia X compact is available in the US for $500, which is really steep for what is basically a mid-range smartphone, and its price point puts this phone in a rather awkward position.

Sony Xperia X Compact Review-14

There are a lot of other options out there, like the Nexus 6P, that arguably offers a lot more value despite being a year old, for the same price or less, and if you are looking for something more current, great choices include the OnePlus 3, the ZTE Axon 7, or the Honor 8.

The Xperia X Compact is a great phone, and if you choose to buy one, you certainly won't be disappointed. However, without a fingerprint sensor (with the US version), or features like dust and water resistance, the $500 price tag is hard to accept, just for the convenience that its size offers. If you are looking for the best value for money, this phone isn't the one to get, but if you just want a compact phone that doesn't compromise a whole lot, that's when you might find this device to be worth every penny.

Buy the Sony Xperia X Compact now


from Android Authority http://ift.tt/2dwhK5v
via IFTTT

Are you using Google Allo? [Poll of the Week]

Google-Allo-sticker-packs-AA-1-AA Poll
Last week's poll summary: Alright, alright, we heard you. Out of over 5,000 total votes, an overwhelming 73% of our readers said they had no plans to purchase an iPhone 7 or 7 Plus. 14% of our readers said they plan on buying the iPhone 7 Plus, while 8.7% said they plan to buy the iPhone 7.

In case you missed it, Google Allo finally made its way to the Play Store last week. Featuring Google's smart new Assistant, tons of sticker packs, incognito chats and more, Allo is turning out to be a pretty awesome messaging app.

In the week or so since Allo has been out, I've really enjoyed using Google Assistant's subscription feature for getting daily weather and NFL reports. And, it's a small thing, but Whisper/Shout is actually super fun to use.

Of course, it's not all sunshine and rainbows, though. In its current form, Allo can't be used on more than one device at a time. And if you do happen to switch phones, your chat history won't transfer over for some reason. Plus, it can't be used as a default SMS application, so you'll need to get people to download Allo if you want to chat with them. There is a weird workaround called App Preview Messaging, but it's not something you should necessarily rely on.

With all that said, we want to know – are you using Google Allo, or is the new messaging app not for you? Be sure cast your vote in the poll below, and if there's something you need to add, feel free to speak up in the comment section. We look forward to hearing what you have to say!



from Android Authority http://ift.tt/2dtHqwI
via IFTTT

Artificial intelligence takes to the skies with Project Loon

Project Loon

Google's rather wacky sounding Project Loon continues to evolve, and has recently received a tune up to its navigation technology. The X Lab team behind the project has revealed that it is making use of artificial intelligence technology, or machine learning to be more specific, to help keep the balloons in the air for longer.

Originally, Project Loon has been using basic pre-crafted algorithms to help change the altitude of the balloons and keep them in roughly the same position. While this worked fairly well under static conditions, the balloons couldn't cope very well with unexpected weather conditions. These algorithms have since been replaced with artificial intelligence-like algorithms that are able to adapt to wind and other weather conditions that threaten to blown the balloons off course. Project Loon's navigation system does not use deep neural networks though, instead it uses a simpler form of machine learning called Gaussian processes.

Project Loon Peru flight path

An AI-powered Project Loon balloon remained over Peru for 98 days.

The algorithms comb through huge amounts of previous data and learn from it to make future predictions and adjust behaviour, in what is basically an ongoing feedback loop. However, using past data is no guarantee that the future will pan out in the same way. So, the team have also implemented something called "reinforcement learning", whereby Project Loon software alters and corrects its behaviour even after making predictions.

As an example, a balloon headed out to catch winds over the Pacific Ocean before changing plans after determining that there wouldn't be enough wind for it to stay over land. OK, this isn't AI in the usual sci-fi human-brain simulation meaning of the of the term, but these self updating algorithms account for a lot of machine learning innovations right now.

Google Project LoonSee also: Google might start testing Project Loon in India5

The new AI-based upgrade is designed to keep the balloons up in the air longer and therefore leaving them able to providing internet access to users below more consistently. Using the new technology, one test balloon stayed in the Peruvian stratosphere for 98 days and made just under 20,000 tweaks to its flight plan over those 14 weeks, which works out to dozens of adjustments each day. This of all sounds pretty great for those that may soon rely on Project Loon for their internet access.



from Android Authority http://ift.tt/2d0jTaW
via IFTTT

Samsung Galaxy On8 likely to debut during Flipkart’s Big Billion Day in India

galaxy on 8

The long-rumored Samsung Galaxy On8 could soon see the light of day in India, where e-commerce titan Flipkart will be holding its annual Big Billion Day sale beginning October 2 to 6. Just a few days before the event, Flipkart has created a dedicated page on its website that teases the device's features.

There are not too many details about Samsung Galaxy On8 at this point, but Flipkart's teasers shared on its website and various social media platforms indicate the smartphone will be sporting a full-HD Super AMOLED display with a 1920×1080 resolution.

For camera lovers and selfie-addicts, Galaxy On8 features a 13-megapixel rear shooter and an 8-megapixel front camera, both with a wide-angle f/1.9 lens. The optical features do not really surpass those of Galaxy J7 Prime, which was recently launched in India along with Galaxy J5 Prime. But that's not to say a phone camera with this aperture isn't particularly performing.

Under the hood, Samsung Galaxy On8 is expected to be powered by an octa-core Qualcomm Snapdragon 625 processor clocked at 2GHz. It also incorporates 3GB of RAM, 32GB of internal storage (expandable up to 256GB with a microSD card) and an Adreno 506 GPU. Galaxy On8 will be running on Android 6.0.1 Marshmallow with a Touchwiz overlay.

There's no word for how much mAh the battery has, but Flipkart teased that it packs enough juice to provide a longer battery life. Like other mid-range Samsung smartphones, the Galaxy On8 includes a dual-SIM slot.

The upcoming launch of the Galaxy On8 in India marks Samsung's continued effort to make inroads in emerging economies in Asia such as India and China, where the Korean phone maker rolled out its Galaxy On5 (2016) and Galaxy On7 (2016) mid-range smartphones last week. In July, Samsung also unveiled the Galaxy On7 Pro and On5 Pro in India for Rs. 11,190 (~$167) and Rs. 9,190 (~$137), respectively.

Flipkart didn't say how much the Galaxy On8 will cost, but confirmed that it will be exclusively available on the e-commerce giant's online store.

Based on these specifications, how do you find Samsung Galaxy On8? Share us your thoughts in the comments.



from Android Authority http://ift.tt/2d03L9o
via IFTTT

Restart of Galaxy Note 7 sales delayed in South Korea

samsung galaxy note 7 aa autom3otices ryan vergara (10 of 23)

Now that the Samsung Galaxy Note 7 recall is well underway, talk is turning to when safe handset stock will return to store shelves. Unfortunately, the restart of sales in South Korea has been delayed by three days.

Samsung said on Sunday that it would be delaying the restart of sales in the country by three days until October 1st. The reason is apparently that the company needs more time and stock to speed up the completion of the recall in the country. The problem also seems to be compounded by the fact that Samsung believes the return of regular sales will cause a decline in the number of customers returning their phones.

"The recall rate will likely fall sharply should new sales have resumed on September 28," – Samsung

South Korean customers seem particularly reluctant to return their potentially dangerous Galaxy Note 7s. Data suggests that only about 200,000 customers have returned their handsets in the country so far, which Samsung says represents only half the number of customers asked to return their phones. The company says that the recall pace in Korea is proving to be much slower than in other markets, such as Singapore and the United States. Sales are expected to recommence in the these regions in October, with Europe seeing a slightly longer delay until November.

As well as a large number of handsets still due for recall sitting in consumer hands, Samsung has also been asked by the national government to extend its refund policy. On Monday, consumers were no longer entitled to refunds in South Korea and would instead only be offered a handset exchange if they returned their Note 7.

samsung galaxy note 7 unboxing aa (15 of 27)See also: South Korea asks Samsung to extend its Note 7 refund deadline31

Samsung has apologised for the delay and confusion, and says that it will do its best to resolve the situation with the Galaxy Note 7 as quickly as possible.



from Android Authority http://ift.tt/2cPrrrL
via IFTTT

Google tests “Andromeda” Android/Chrome hybrid OS on the Nexus 9

Nexus 9 Keyboard Folio-16

Google is already lining up some new hardware for its October 4th event, but the company may also have important new software details to announce soon as well. An anonymous source states that users have been running early builds of an Android/Chrome OS hybrid, known as "Andromeda", on the HTC Nexus 9, and that Google has been internally testing its new OS.

An Android 7.0 Nougat AOSP file labelled "SurfaceCompositionTest.java" appears to be some sort of graphics performance test designed for Andromeda. The file specifically mentions that "Andromeda devices require higher performance score", and suggests that a minimum graphics score of 8.0 is required to run the OS. For comparison, a score of just 4.0 is required to run Android, and the Nexus 9 scores an 8.8.

Andromeda performance scores

It seems unlikely that Google would debut its new operating system on the old Nexus 9. Instead, the tablet may be being used for testing due to its more unique and powerful Tegra K1 processor, with Denver CPU cores and Kepler DX1 GPU. The fact that this code appears in the general ASOP directory also means that Andromeda could be planned for a wider range of devices.

A second hint also points to the free form window management feature that is hidden away inside Android Nougat. Perhaps this feature will makes its official debut with Andromeda.

Andromeda feature

The source code also suggests that this isn't a small code or feature insertion, but requires a complete rebuilding of the system image. This is hinted at by the fact that part of the ASOP page mentions a "Flushed Nexus 9 device using volantis and volantis-andromeda images".

The Andromeda hybrid OS has been in and out of rumors and leaks for a while now, but we don't know the exact make up of the new OS yet. An old report from the Wall Street Journal suggests that Google is planning to "fold" Chrome OS into Android, which would make it quite different to Google's efforts to bring Android apps to Chromebooks.

Google I-O 2016 chromebook update-1Up next: Android apps support finally arrives on Chrome OS stable channel 10

The growing number of leaks suggest that Google is planning to release a new OS with superior cross-platform capabilities for some future mobile devices, most likely aimed at the tablet and 2-in-1 market. Reports have previously pointed to a potential 2017 release, but if Hiroshi Lockheimer's recent Tweet is anything to go by, Google might just tease us with the new OS next Tuesday.



from Android Authority http://ift.tt/2cF2pxI
via IFTTT

Displaying large amounts of data with GridView and CardView

displaying-data-in-cardviews-and-gridviews-16x9-720p

Displaying large amounts of data in an Android app can be a tricky balancing act. Even on devices with larger screens (such as a laptop or computer) being confronted with a solid wall of data isn't particularly appealing! This is even more true on Android devices, as the smaller screen of a tablet or smartphone tends to make blocks of content appear even larger.

If your app needs to display a considerable amount of data, then presentation is everything. Android provides several UI components that can help you bring instant structure and design to even the largest data sets, so you can deliver data-packed screens that users won't mind scrolling through.

In this article, I'm going to show you how to use two data-focused UI components in your projects: CardViews and GridViews.

Working with CardViews

As the name suggests, CardView gives you an easy way of displaying data in Google Now-style cards. Each CardView can contain multiple child views and multiple content types, for example you can place TextViews and ImageViews inside the same CardView.

To ensure CardView fits with Android's Material Design makeover, each CardView component has its own elevation and shadow. The elevation is the card's position on the 'Z' axis, and the Android system dynamically generates a shadow based on this elevation.

When generating shadows, Android also takes into account factors such as the view's position in relation to the "virtual lights" that illuminate the Material Design environment, but even if your app winds up on a pre-Material Design device (i.e anything running KitKat or earlier) then the system will fall back on an emulated shadow implementation, so your CardViews will still have that shadow effect.

You can use the card_view:cardElevation attribute to define your card's elevation and shadow in one fell swoop.

Creating a CardView

The Android SDK doesn't include the CardView class, so you'll need to add the CardView support library before you can use cards in your project.

Open your project's module-level build.gradle file, and add the following:

  dependencies {   ...  compile 'com.android.support:cardview-v7:24.2.1'  }   

A CardView is a ViewGroup, so the next step is opening your project's XML layout resource file and declaring a CardView, in exactly the same way you'd declare any other UI component:

  <LinearLayout xmlns:android="http://ift.tt/nIICcg"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:orientation="vertical" >    <android.support.v7.widget.CardView   xmlns:card_view="http://ift.tt/GEGVYd"   android:id="@+id/card_view"   android:layout_gravity="center"   android:layout_width="300dp"   android:layout_height="200dp"   android:layout_margin="5dp"   card_view:cardCornerRadius="6dp">     //Create a LinearLayout inside the CardView//  <LinearLayout   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:orientation="vertical">     //Add all the views you want to display//  <TextView   style="@style/Base.TextAppearance.AppCompat.Headline"   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="Hello, World!" />     <TextView   style="@style/Base.TextAppearance.AppCompat.Body1"   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="Text, text, text" />     <ImageView   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:src="@drawable/pancakes"/>        </LinearLayout>  </android.support.v7.widget.CardView>  </LinearLayout>    

Run this project on your Android device, and you'll see the following output:

Displaying data in CardView

Creating CardViews programmatically

Creating a CardView declaratively is far easier than delving into your Java code, however there are instances where you might need to define at least some of your UI elements programmatically. The major advantage of this approach, is that it allows you to create dynamic user interfaces that change based on user interaction, such as cards that can appear, disappear, or display different information in response to user activity.

In this section, I'm going to show you how you might use dynamic CardViews, by creating a simple app that displays a card when the user taps a button.

The first step is adding the CardView support library to your project's module-level build.gradle file:

  dependencies {  ...  compile 'com.android.support:cardview-v7:24.2.1'    }   

It's always a good idea to define as much of your UI via XML as possible, as this separation helps to keep your application code more human-readable and easier to maintain. For this reason, I'm going to create the 'default' version of my UI in my project's layout resource file:

  <?xml version="1.0" encoding="utf-8"?>    <LinearLayout xmlns:android="http://ift.tt/nIICcg"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical"    android:layout_marginLeft="20dp"    android:layout_marginRight="20dp"    android:layout_marginTop="20dp"    android:layout_marginBottom="20dp"    android:id="@+id/linearlayout">    //Create the button that'll eventually trigger our CardView//   <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Show me the CardView"        android:id="@+id/button"        android:layout_centerVertical="true"        android:layout_centerHorizontal="true"        android:layout_marginBottom="20dp"/>  </LinearLayout>  

creating a cardview programmatically

The next task is modifying our MainActivity.java file to generate a CardView (complete with content) in response to the user tapping the button.

  package com.jessicathornsby.myapplication;  import android.support.v7.app.AppCompatActivity;  import android.os.Bundle;   import android.widget.Button;  import android.support.v7.widget.CardView;  import android.graphics.Color;  import android.content.Context;  import android.view.View;  import android.widget.ImageView;  import android.widget.LinearLayout.LayoutParams;  import android.widget.LinearLayout;  import android.widget.TextView;    public class MainActivity extends AppCompatActivity {    Context context;    LinearLayout LinearLayout;    Button button;    TextView textview;    ImageView imageview1;    CardView cardview;    LayoutParams layoutparams;      @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        button = (Button)findViewById(R.id.button);        context = getApplicationContext();        LinearLayout = (LinearLayout)findViewById(R.id.linearlayout);         // Create an View.OnClickListener and assign it to the button       button.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                CreateMyCardView();            }       });    }      public void CreateMyCardView(){        // Initialise the CardView        cardview = new CardView(context);          // Create the "wrap_content" layout params that you'll apply to the various        // UI elements we're going to create        layoutparams = new LayoutParams(                LayoutParams.WRAP_CONTENT,                LayoutParams.WRAP_CONTENT        );         // Set the layoutParams on the CardView       cardview.setLayoutParams(layoutparams);         // Set the card's corner radius       cardview.setRadius(6);         // Set its background color       cardview.setCardBackgroundColor(Color.GRAY);         // Set its maximum elevation       cardview.setMaxCardElevation(6);         // Create a TextView       textview = new TextView(context);         // Apply the layoutParams (wrap_content) to this TextView       textview.setLayoutParams(layoutparams);         // Define the text you want to display       textview.setText("Hello, World!");         // Define the text's appearance, including its color       textview.setTextAppearance(android.R.style.TextAppearance_Material_Headline);       textview.setTextColor(Color.BLACK);         // Create an ImageView       imageview1 = new ImageView(context);         // Specify the drawable this ImageView should display       imageview1.setImageResource(R.drawable.scenery);         // Apply the layoutParams       imageview1.setLayoutParams(layoutparams);         // Add the content to your CardView. Here, we're adding the TextView//       cardview.addView(textview);         // Add the ImageView       cardview.addView(imageview1);         // Add the CardView to your layout       LinearLayout.addView(cardview);    }  }  

Install the finished project on your Android device or AVD. Give the button a click and the CardView should appear, complete with the content you specified.

creating dynamic cardviews

Working with GridViews

A GridView is a view that displays items in a two-dimensional, scrollable grid of rows and columns. GridViews are particularly useful for displaying images in a structured fashion, for example if you're designing a gallery app.

To populate a GridView with data (whether that's images, text, or a combination of the two) you'll need to bind your data to the GridView using a ListAdapter. In the following example, I'm going to use a ListAdapter to retrieve data and create a view for each data entry.

The first step is adding the GridView UI component to your project's XML layout file:

    <?xml version="1.0" encoding="utf-8"?>  <RelativeLayout    xmlns:android="http://ift.tt/nIICcg"   xmlns:tools="http://ift.tt/LrGmb4"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:paddingBottom="@dimen/activity_vertical_margin"   android:paddingLeft="@dimen/activity_horizontal_margin"   android:paddingRight="@dimen/activity_horizontal_margin"   android:paddingTop="@dimen/activity_vertical_margin"   tools:context="com.jessicathornsby.gridviewexample.MainActivity">     <GridView    xmlns:android="http://ift.tt/nIICcg"   android:id="@+id/gridview"   android:layout_width="match_parent"   android:layout_height="match_parent"     // Define how many columns you want to display in the GridView//   android:numColumns="3"     // Set the vertical spacing between each row. You may also want to use the android:horizontalSpacing   // to set the horizontal space between each column   android:verticalSpacing="5dp"/>  </RelativeLayout>    

Depending on the style of GridView you have in mind, you may also want to use the android:stretchMode attribute to define how your GridView's columns should stretch to fill any available space. Choose from the following values:

  • None.
  • spacingWidth. The spacing between each column is stretched equally.
  • columnWidth. Each column is stretched equally.
  • spacingWidthUniform. The spacing between each column is uniformly stretched.

You can also define the padding that should be added to your GridView, using the 'setPadding' attribute.

Once you've created and styled your GridView UI component, the next step is to modify your project's MainActivity.java file:

  import android.support.v7.app.AppCompatActivity;  import android.os.Bundle;  import android.widget.GridView;  public class MainActivity extends AppCompatActivity { @Override    protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      setContentView(R.layout.activity_main);        // Initialise the GridView      GridView gridview = (GridView) findViewById(R.id.gridview);         // Use the setAdapter method to tell your app to use a custom adapter (ImageAdapter) as its data source.      // We'll create this adapter in a moment      gridview.setAdapter(new ImageAdapter(this));    }  }  

The last thing we need to do, is create the custom adapter and attach it to the GridView:

  import android.widget.BaseAdapter;  import android.content.Context;  import android.view.ViewGroup;  import android.view.View;  import android.widget.ImageView;  import android.widget.GridView;    // Extend the BaseAdapter class//    public class ImageAdapter extends BaseAdapter {  private Context mContext;    // Define an array of drawables that'll be displayed in the GridView//  public Integer[] gridviewImages = {             R.drawable.image1, R.drawable.image2, R.drawable.image3,              R.drawable.image4, R.drawable.image5, R.drawable.image6,              R.drawable.image7, R.drawable.image8, R.drawable.image9,    };      public ImageAdapter(Context c) {    mContext = c;  }    // Get the number of images in the gridviewImages array//  public int getCount() {      return gridviewImages.length;  }    public Object getItem(int position) {    return null;  }    public long getItemId(int position) {    return 0;  }    // The getView method is responsible for creating an ImageView for each image in our array.  // To provide a better user experience, I'm using the convertView method to specify that the  // Adapter should recycle views whenever possible, instead of creating a new view for every single  // item in our data set. Reusing views that are no longer visible to the user, improves the app's  // performance, as the system doesn't have to keep inflating views and doesn't waste memory keeping  // a bunch of unnecessary views alive in the background  public View getView(int position, View convertView, ViewGroup parent) {      ImageView imageView;        // Check whether convertView is null      if (convertView == null) {           // If convert is null, then this means we cannot recycle an old view,          // and need to create a new one          imageView = new ImageView(mContext);             // To make sure each image is displayed as you intended, you may need to assign some properties to          // your ImageViews. I'm going to use setLayoutParams to specify how each image should be resized          imageView.setLayoutParams(new GridView.LayoutParams(300, 300));             // setScaleType defines how the image should be scaled and positioned. I'm using the CENTER_CROP          // value as this maintains the image's aspect ratio by scaling it in both directions, and then          // centers the newly-scaled image.          imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);      } else {           // If the view passed to getView is not null, then recycle the view          imageView = (ImageView) convertView;      }        // Use the position integer to select an image from the gridviewImages array, and set it to the      // ImageView we just created      imageView.setImageResource(gridviewImages[position]);      return imageView;    }  }  

At this point you can run the application and check out the GridView in action.

Displaying data in GridView

Data Binding

Gridviews and CardViews are just two examples of many Android UI components that are designed to display data. Despite data being such an important part of many Android apps, until recently data binding required a considerable amount of code.

Typically, developers had to inflate their layout, use findViewbyID to locate the element that was going to use the data, assign it a local variable, retrieve a value from the data, and then assign this value to the UI element. This is already a significant amount of code, but if the layout featured multiple elements that needed to use data (such as multiple CardViews) then this could cause the data binding code to really spiral out of control.

An improvement to Android's data binding was long overdue, and that's exactly what we got at Google I/O 2015, when Google announced the Data Binding support library.

This library helps you bind data to a UI element without having to write so much "glue" code. Eliminating findViewById lookups in particular means faster code, as the view hierarchy is only traversed once, rather than every time findViewById is called.

To configure your app to use data binding, open your project's module-level build.gradle file and add the dataBinding element:

  android {      ....      dataBinding {        enabled = true      }  }    

If you want to use data binding in a layout resource file, you need to configure this file slightly differently. Instead of declaring the target root View, you need to use 'layout' as your root tag, followed by a 'data' element, for example:

  <?xml version="1.0" encoding="utf-8"?>  //The layout tag indicates that this layout file should be configured for data binding//  <layout xmlns:android="http://ift.tt/nIICcg">      // Add a data tag before the UI view root, and declare the variables and the classes you want    // to use inside your layout    <data>        <variable name="contact" type="com.jessicathornsby.contact"/>    </data>  

Next, I'm going to use this data binding to set the value of a TextView inside a CardView:

  <android.support.v7.widget.CardView    xmlns:card_view="http://ift.tt/GEGVYd"  ...  ...  <TextView android:layout_width="wrap_content"           android:layout_height="wrap_content"    //Set the value of our TextView, using the "@{}" syntax//             android:text="@{contact.contactName}"/>  

The data objects that can be used for data binding don't need to be a special type, so in this example the "Contact" target object could simply be a POJO.

The Gradle plugin auto generates a binding class from your layout file and assigns it the name of your layout resource file, with the addition of the "Binding" suffix. So, if our layout file was main_activity.xml, Gradle would generate a MainActivityBinding class. To associate this auto generated binding class with your code, you can either use:

  MainActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);  

Or:

  MainActivityBinding binding = MainActivityBinding.inflate(getLayoutInflater());  

Data binding is a huge topic that's well worth exploring in more detail, particularly if you're planning on displaying large amounts of data, or your layouts include multiple elements that need to use data in some way. For a more detailed look at the Data Binding library, take a look at our Data Binding in Android article.

Wrapping up

In this article we looked at two ways of displaying large amounts of data in a structured, accessible way, by adding cards and grids to your layouts. We also looked at how to use a simple custom Adapter and the Data Binding library to supply your UI with data.

Do you have anymore tips for the best ways of displaying large amounts of data in your Android apps?  Share them in the comments below!



from Android Authority http://ift.tt/2cP2Hj9
via IFTTT