Seven Peaks Insights

Android Developer Guide

What is new in ConstraintLayout2.0?

 22f7e8d1-c831-4968-a99c-75b3060fda7a

 

Android developer guide – On the 29th of October we hosted an Android meetup at the Seven Peaks Software office to talk about the hidden features of Git & ConstraintLayout 2.0.

There were three presentations given by one of the Seven Peaks Software employees who came up with the subject to talk about as they are interested and passionate about and because they want to share their knowledge and discuss the topic with others.

 
 

ConstraintLayout2.0

Android Developer Guide – Meetup Summary ConstraintLayout2.0

Constraint Layout is one of the ViewGroup of Support Library.

It has better ability than the old ViewGroup Android by allowing you to organize the wide variety of interrelated layouts into many forms.

It implies the creating complex layouts in Android by making it possible to build most of your UI using the visual editor in Android Studio.

This is often described as a more powerful RelativeLayout. With Constraint Layout you can define complex layouts without building complicated view hierarchies.

 
 

What’s new in ConstraintLayout 2.0

In this topic we are going to introduce you to some of new cool modes that were added in ConstraintLayout 2.0.

Flow is a new virtual layout that was added to help you build chains that can wrap to the next line when they run out of room without adding levels to your layout hierarchy.

When you are laying out multiple items in a chain but still not sure about the size of the container at runtime, this layout would be very useful for you.

WrapMode is one of the most important options to Flow.

There are three options of wrapMode for you to choose: 

 

None

Simply create a chain, horizontal or vertical, out of the referenced elements.

 

Chain

It creates multiple chains (one after the other) if the referenced elements does not fit.

 

Aligned

Aligned is similar to wrap chain, but will align the elements by creating rows and columns.

 

Layer

One of the new views available in ConstraintLayout 2.0 which is similar to Guidline and Barrier.

It is a virtual flow similar to Flow but does not lay views out as Flow does.

It helps you create virtual layer from several different view to build animations and apply transformations on several views at once.

 

Motion Layout

This is a subclass of ConstraintLayout which has a separate XML file for the constraints and the motion elements called a MotionScene file using to handle motion and animation display.

It allows you to directly animate between two Constraint sets. It is a mixing of Property animation framework, TransitionManager, and CoordinatorLayout.

It also can be customized as how the views move, scroll, scale, rotate, fade, or even animate custom attributes.

 
 

The hidden features of Git

The second topic that was covered was about the hidden features of Git, presented by our Android Tech lead Gahfy.

 

What is Git?

Git consists of a distributed open source control system. Which is designed to run all kinds of projects, big or small, in an efficient and fast way.

It is a software that tracks changes in files, and is mostly used by programmers to work together on developing code and software.

The main goals involve fastness, data trustworthy, and contribute to distributed, non-linear workflows.

 

How does Git work?

Now that we know what Git is and how it stores files, it is really important to understand that Git is storing the full content of every single file every time. This is the main reason for the success of Git.

So far Git looks similar to other source code repositories. But, even though it might look like any other classical source code repository, it is certainly not the same. The biggest difference is that Git is decentralized. Which means that there is one central archive.

Numerous repositories can cooperate in software development. Actually, each developer’s repository communicates in an identical kind of way as all server-based Git storage.

 

How does Git work?

Git/object folder is the folder in which all the data is stored. The most basic data storage is the blob.

Git sees its data like a collection of snapshots of the filesystem. Git saves the state of your project, every time you make a commit.

You can see it as a picture being made of all your files and storing it with a reference to that snapshot.

To be efficient, files that are already saved will not be saved again. Instead it will save the file that has been saved before. In this way you will not have any duplicated files.

 
 

Different Git commands – Git log

You can use Git log2, short for online graph. But actually, Git log2 is not a Git command.

You have to use a config, which is: alias.log2 “log pretty = oneline graph’.

It is a nice shortcut that will save you a lot of time as you don’t have to type the whole line of code every time.

Using aliases is very important. For example, to do the checkout followed by a pull.

You should definitely use aliases on Git as it has so many shortcuts that make life easier.

 

Git help-w

Another famous command is the “Git help commit” which will give you all the menu’s of the available commits in the console.

Sometimes it might not be useful to read, but you can use the “Git help W commit” to open the manual in your web browser.

When you do this a more useful help page will show up.

This help page is also useful to understand how it works. Just in order to use this you need to install git htmldocs as it is not included in all packages.

If you are not on Linux it is quite difficult to build the documentation.

Git is something that is quite easy to do, so I encourage you to build Git from the source as it is not so complicated. But, actually for the documentation it is quite impossible unless you are on Linux.

 

Git-c clone

If you want to clone a repo you can use it with the c argument. The c argument will add a config before clowning. It allows you to have another ssh key.

For example, for clowning a repo if you are using multiple ssh keys on your computer.

Git -c core sshCommand= ‘ssh -i private_key_file’ clone@git.com/repo.git

 

Git bisect

The bisect can be done automatically with the branch script. It does the file.sh which will show you if we have succeeded in the result.

 

Git reflog

The most important one is the reflog. Sometimes it takes days to create a new commit. Can you imagine losing it after all the hard work you have put into it. That would be such a waste of time. With the Git reflog you can restore a version if you lose it. So basically, what it does is giving you all the history about what you have done so far. In this way you will never lose your commits. You can always find your last modification.

Watch the Seven Peaks Speaks: Android Meetup video on YouTube here to see the full presentation!

 
 

Getting ready for target SDK version 29 & 30 – Intro to Android SDK

The third and last speaker of the Android meetup was Ake from Line. His presentation was about Getting ready for target SDK version 29 & 30.

Google play has a policy that you have to update your app. We have to migrate the version of the Android into our app. Because Google Play told us that everyone will have to update to the SDK version 29 in November 2020. Otherwise you are not able to update your app to the Google Play store.

So, today I will talk about how to get your app ready for the target SDK version 29 & 30. You might be asking why 30 as well. Well, because the next Android event is already out now so there is not much time to update it.

 
 

Google Play’s Target API Level Requirement

If you are an android developer and you open the google play store you will receive the following warning: “upgrade your project to use SDK 29”.

If you don’t do this before November 2020 you will not be able to update your app anymore. In this way the Google Play store tries to make you update your app frequently.

This is mainly for privacy and security reasons. But, it is very hard for the developers to migrate so quickly. Therefore, they give you some time to update it.

 
 

Full screen intent notification

What happens when you have a full-screen intent notification. An example of this is when someone calls you and the application will show up on your screen immediately.

When you update the target SDK 29 you need to declare permission to use the full screen intent in the application to tell the platform that you have this kind of notification.

 
 

Background location access

You have to request permission for the background location access. In the past there were only two different permissions.

The access file location and access cost location, but that is not enough because our app has a lot of ways to use the location access. We can identify only two types of location accesses.

One is the forecast access and the other one is the background location access. The background can minimize and track the user location.

 
 

Physical activity recognition

It depends on how the app works. If you have a health related app it can track your activities like running, swimming, walking, etc. Sometimes you have to access this version to track the user.

After the target SDK version 29 is activated you have to declare this permission activity recognition in your manifest. The three methods that you have to declare are Sensor API, Activity Recognition API and Google Fit API.

 
 

Non-resettable Identifiers

This one is very important because some apps try to retrieve the unique ID of the device.

Not only your Google Cloud and user ID, but also apps try to get your unique ID to identify that people are logging in with for example the same account on different devices.

For the privacy in Android 10 they told the people that you cannot get the serial number of the device anymore. But what if you really need this information.

There are two options:

  • The first one is to track the unique ID for ad-tracking or user analytics with the Android Advertising ID.
  • Follow the best practices for unique identifiers guideline in Android developers.

Best practices for unique identifiers

 
 

Mac Address

In Android 10 your MAC address in your Android device will be randomized by default. So, for some apps they try to get your MAC address and remember the device. As they cannot get the unique ID directly from the device, instead they will try it from the MAC address.

 
 

USB Device Serial Number

When the user connects the USB device in the phone you can get the serial number in previous Android versions, but for the target SDK version 29 & 30 you cannot access the serial number until the user grants you permission to access the device.

 
 

Clipboard Data

You cannot access the clipboard data. It is unlike IOS, in which the application that accesses the clipboard data will show the message to the user.

But, for Android you cannot access the clipboard if your app is not active at that time. It can only be accessed if the app is active.

 
 

Wi-Fi Settings

Sometimes the application automatically enables or disables the WiFi from our device. But not all users like it when this automatically happens.

So, Android 10 disabled this function and therefore you cannot do this anymore. You have to change your code to be able to Settings Panels API.

It will show a dialogue to make the user decision to enable the Bluetooth or network by themselves and not by the app.

 
 

Firebase

There are two types. The first one is JobDispatcher and the second one is GcmNetworkManager.

It will be disabled in Android 11 and targeting in version 30. So, you have to change your code and start using WorkManager, it is much better as it is cleaner.

 
 

Package Visibility

This is about privacy. The last two versions of Android have been focusing on privacy and security.

When we have to interact with another app we use intent as the medium for the Android platform. You can check how many apps the user has installed on their device.

But, since this is against the privacy regulations you have to follow the security rules. As apps can define the set of other packages that they can access.

There are 3 types of the package visibility:

  • Package name
  • Intent signature
  • Provider authority
 
 

Package Name

You have to declare the package name in the query tag if you want to interact. For the user who installs the application like Facebook.

When you share your image to the Facebook app , the previous version you will see the Facebook.

In android 11 the user only sees the system application. Some apps are hiding this for the user, depending on which platform you are using.

 
 

Intent Signature

Sometimes we have to use an intent and send the action to another application by declaring it in the query tag. You can define any intent inside the query to tell the platform what to do and the platform will query another app that match with the intent showing up.

 
 

Provider Authority

If your app has to access the content provider in another app, you have to declare the authority of the content provider in the query tag.

For the apps that use TTS Service or recognition service, you will have to declare the query as well. If not, you will only see the system application for the TTS or voice recognition.

Watch the Seven Peaks Speaks: Android Meetup video on YouTube here to see the full presentation!

 
 

ConstraintLayout2.0

Constraint Layout is one of the ViewGroup of Support Library. It has better ability than the old ViewGroup Android by allowing you to organize the wide variety of interrelated layouts into many forms.

It implies the creating complex layouts in Android by making it possible to build most of your UI using the visual editor in Android Studio. This is often described as a more powerful RelativeLayout.

With Constraint Layout you can define complex layouts without building complicated view hierarchies.

 
 

Git

Git consists of a distributed open source control system. Which is designed to run all kinds of projects, big or small, in an efficient and fast way.

It is a software that tracks changes in files, and is mostly used by programmers to work together on developing code and software.

The most important is reflog. Sometimes it takes days to create a new commit. Can you imagine losing it after all the hard work you have done.

It would be such a waste of time. With the Git reflog you can restore a version if you have lost it. So, what it does is giving you all the history about what you have done so far.

In this way you will never lose your commits. You can always find your last modification.

 
 

Target SDK version 29 & 30

Google play has a policy that you have to update your app. We have to migrate the version of the Android into our app. Because Google Play told us that everyone will have to update to the SDK version 29 in November 2020. Otherwise you are not able to update your app to the Google Play store. In this way the Google Play store tries to make you update your app frequently.

In Android 10 your MAC address in your Android device will be randomized by default. So, for some apps they try to get your MAC address and remember the device. As they cannot get the unique ID directly from the device, instead they will try it from the MAC address.


Do you want to join our fast-growing team?
See our open positions!
See open positions!