Category Archives: Android

Kotlin Pitfalls and How to remove them? 

Kotlin is all the rage lately. And while I do agree that the language is well thought out, it does have — as with everything else — its flaws.

As we already discuss about disadvantage of Kotlin but today in this article I’ll explain some of the Kotlin problems I encountered and try to help you avoid them.

You have to see : Advantage and why you should switch to Kotlin

Top 9 Kotlin problems with their solution:

The mystery null

Image result for null

In Kotlin you can write your code as if null never existed and this can make you forget that null is omnipresent but it hides. Let’s look at this simple and seemingly innocent class:

  1. class Foo {
  2. private val c: String
  3. init {
  4. bar()
  5. c = “”
  6. }
  7. private fun bar() {
  8. println(c.length)
  9. }
  10. }

If you try to instantiate this, you’ll get a NullPointerException because bartried to access the length of c before it was initialized.

Of course the application logic was flawed here, but you still got an Exception. The worst part of this is that your IDE won’t complain about this.

The takeaway here is that Kotlin will help you in a lot of cases (nearly all) to avoid null, but you can’t forget about it and from time to time you’ll encounter things like this.

For every Kotlin developer : Top 20 Daily used Kotlin Code Snippet

Handling nulls from the JDK

Image result for Handling nulls

Kotlin’s standard library handles nulls fine. But if you use classes from the JDK, you will have to handle possible null pointers from library functions by hand.

Most of the time the Kotlin classes are enough, but sometimes you have to use something like the ConcurrentHashMap:

  1. val map = ConcurrentHashMap<String, String>()
  2. map[“foo”] = “bar”
  3. val bar: String = map[“foo”]!!

In this case, you have to use the !! operator. But in other cases the nullsafety operator (?) can also work. Nevertheless, if you use Java libraries extensively you’ll have to litter your code with !!s and ?s or write adapters for Java classes. This is something you can’t really avoid.

There’s another more hideous problem you might bump into. When using methods on JDK classes, they can return null and don’t have syntactic sugar like the Map access above.

Source: Kotlin Problems and How to avoid them? 

Advertisements

How to Implement Vega Scroll Layout Android Slider?

Vega Scroll Layout is a lightweight animation flowlayout which fade and shrink the head itemView when scrolling.

example-plain

How i found Vega Scroll Layout library?

As you can see in above image its cool effect for your scroll layout and i used this library in my current project which is based on trading data. Previously we discuss infinite scroll in Kotlin and my author partner Ponglang Petrung suggest about Android DiscreteScrollViewto used for this. But i was looking for something new effect and after half hour googling i found Vega Scroll Layout library on dribble. And i am sharing tutorial on this with you.

Demo

 Example of Vega Scroll Layout Androidq

Source: Vega Scroll Layout Android Slider 

What is Android Rich Path Animator?

Animation in Android is a best way to give a valuable UI in any application. So today i am going to how to implement Android rich path animator which can draw as you want animate much as you can.

What is Android Rich Path Animator?

How to implement Android Rich Path Animator?

This library define in simple three line:

💪 Rich Android Path.

:clown_face: Draw as you want.

🎉 Animate much as you can.

That line is sufficient to tell much more about Android Rich Path Animator and now we dive in implementation of this library.

Source: Implement Android Rich Path Animator 

How to Create Android Topbar Menu with Guillotine animation?

How to Create Android Topbar Menu with Guillotine animation? Have you ever wondered why a sidebar in apps has to be a “side” bar? Why not to make it a “topbar,” or a “bottombar,” or a “cornerbar,” etc.?

Do you know : How to add Android Jelly Toolbar Animation?

A new animated trend in the generation of navigation bars is what we are going to talk about this time. Animations are fun but most importantly, they are useful. They can change your way of thinking, make your product catchy, and improve user experience.

Android Topbar Menu with Guillotine animation
Android Topbar Menu with Guillotine animation

“From time to time every designer gets bored. All these fixes, cuts, specifications – they leave very little space for imagination. In these minutes I feel like opening my Adobe After Effects and creating something interesting.

You should read : Uber Car Animation in Android

When I started thinking about what to create this time, I caught myself on a thought that a typical sidebar menu which sadly gets out of the left part of the screen moving all content to the right, is so unbearably boring! What if a sidebar becomes a topbar?

It’s going to drop down from the top of the page and turn in a unique way. Sounds like fun, doesn’t it?”

Source: Create Android Topbar Menu with Guillotine animation

How to implement Android Prevent Screen Off?

Android prevent screen off is the library that keeps the screen on until user is looking at the screen. If you are using Samsung devices you might know there is one feature called “Smart Stay”.

When this feature is enabled, the device will prevent your screen from turning off regardless of your screen timeout settings. But, this technology is only available on some Samsung devices. What if we want to use that technology in our application to solve above problem?

Today, I am going to present the solution of this problem.

Here is the solution:

Prevent-Screen-Off” library handles screen on/off timing smartly. It prevents device display from turning off when the user is looking at the screen and he/she might be reading some textual content provided by your application. As soon as the user stop looking at the screen it will allow phone screen to turn off.

What is Android prevent screen off library for?

  • Ideally, when you user is looking at the screen, your application should not turn the screen off. This is huge deal for the blogging, messaging applications because those applications displays textual content to the user. Reading those textual content takes more time to the user. While reading that content (let say anu article) if the screen turns off, because of the screen timeout that is frustrating to the user.
  • This library provides smart handling of the screen on-off. This library prevents screen from turning off if your user is looking at the screen might reading some textual content on the screen. As soon as the user stop looking at the screen it will allow phone screen to turn off.

Source: What and How implement Android Prevent Screen Off?

Will Android support Java 9?

With work moving forward on the next edition of standard Java, developers can start looking forward to what they will get with the planned upgrade.

Will Android support Java 9 after Kotlin updates?

Jigsaw isn’t the only new addition slated for Java 9. Support for the popular JSON (JavaScript Object Notation) data interchange format is key feature as well, along with process API, code cache, and locking improvements. “The key message is that there’s a tremendous investment in the continuing evolution of Java,” says Scott Sellers, CEO at Azul Systems, which offers JVM technology.

See this : How to Create Your Own Ransomware Virus

Here is a rundown of what’s in store with JDK 9.

Modular source code

JDK source code will get reorganized into modules, the build system will get enhanced to compile modules, and module boundaries will be enforced at build time. “Project Jigsaw aims to design and implement a standard module system for the Java SE Platform and to apply that system to the platform itself and to the JDK. Its primary goals are to make implementations of the platform more easily scalable down to small devices, improve the security and maintainability, enable improved application performance, and provide developers with better tools for programming,” the JEP document says.

Lightweight JSON API

This is an API for consuming and generating documents and data streams via the JavaScript Object Notation data interchange format, which is based on a subset of JavaScript and serves as an alternative to XML. “JSON has become the lingua franca for Web services, and it is time for Java SE to adopt functionality for interacting with and utilizing JSON documents and data streams,” the corresponding JEP document says. “This proposal is designed [to] provide the most commonly needed functionality and take advantage of Java 8/9 language and library features.”

You must know ; Create Android Studio Live Templates for Writing Less Code

Process API updates

This will improve the API for managing operating system processes and is intended to overcome limitations of the current API that often forces developers to use native code. Java SE 7, the JEP notes, offers limited support for native operating system processes; the new API, though, needs to account for operating system differences, particularly on Windows. “The design of this API needs to accommodate possible deployment on smaller devices with different operating system models. It should also take into account environments where multiple Java virtual machines are running in the same operating system process,” the JEP document states.

Improve contended locking

The goal is to improve contended Java object monitors. The documentation says that “improving contended locking will significantly benefit real-world applications in addition to industry benchmarks such as Volano and DaCapo.”

Do you know : Comparison of All Android Image Loading Library

Segmented code cache

This effort is intended to divide code cache into segments, each containing compiled code of a particular type, to improve performance and allow extensions.

Smart Java Compilation, Phase 2

This project is intended to improve the sjavac (Java programming language compiler) tool enabling it to be used by default in the JDK build and also to generalize it so it can be used to build large projects other than the JDK. “The current implementation has proved to be useful and does indeed improve build speed and allow for incremental builds. The quality of the code and stability of the tool as a whole, however, is not satisfactory and it is certainly not ready for public release,” the JEP document states.

Source: Will Android support Java 9 after Kotlin updates?

ARCore SDK Tutorial : Create Augmented Reality in Android

ARCore is a platform for building augmented reality apps on Android. ARCore uses three key technologies to integrate virtual content with the real world as seen through your phone’s camera:

Video Player

What is ARCore SDK ?

Motion tracking :

It allows the phone to understand and track its position relative to the world. As your phone moves through the world, ARCore uses a process called concurrent odometry and mapping, or COM, to understand where the phone is relative to the world around it. ARCore detects visually distinct features in the captured camera image called feature points and uses these points to compute its change in location.

The visual information is combined with inertial measurements from the device’s IMU to estimate the pose (position and orientation) of the camera relative to the world over time.

The device compatibility situation will change in the future, though, as Google assures us that it’s working together with Samsung, Huawei, LG, Asus, and others to make ARCore available on many more phones. ARCore is expected to eventually run on “millions of devices”. It works with Java/OpenGL, Unity, and Unreal, and has three main areas of focus: motion tracking, environmental understanding, and light estimation.

Source: Create Augmented Reality in Kotlin Using ARCore SDK