Category Archives: Android

Best 10 Kotlin Tips You must Know

Advanced Kotlin Tips on writing good Kotlin code and using what the language has to offer. There are many benefits of using Kotlin; it is concise, safe and most importantly it is 100% interoperable with Java. It also tries to solve some of the limitations of Java.

Top 12 Advanced Kotlin Tips For Pro Developers

Now is a good time to consider Kotlin for your next big feature or project, because Google finally announced it to be a first-class language for writing Android apps in Google I/O 17.

So here are some advanced Kotlin tips to help you start making use of what the language has to offer and writing good Kotlin code.

1. Singleton

Implementing lazy loaded and thread-safe singletons in Kotlin is really easy, unlike Java where you would have to rely on the complex double-checked locking pattern. And although Java enum singletons are thread-safe, they are not lazy loaded.

You must see this : Kotlin Parcelize – Developer need to know

  1. object Singleton {
  2. var s: String? = null
  3. }

Contrary to a Kotlinclass, an object can’t have any constructor, but initblocks can be used if some initialization code is required.

  1. Singleton.s = “test” // class is initialized at this point

The object will be instantiated and its init blocks will be executed lazily upon first access, in a thread-safe way.

 

Advertisements

Kotlin Parcelize Features you must know

You are going to delete lots of lines of code! Yes, it is not a clickbait!

Kotlin Parcelize - Developer need to know

How do you pass your model between activities?

  • Serializable?
  • EventBus / Otto ?
  • Parcelable?

Serializable = Reflection! Run Forest Run!!! It is terrible for Android performance.

Bus libraries like EventBus or Otto are easy to use and have good performance but after some time they cause too much complexity in your code.

Parcelable interface is great for Android performance but it has too much boilerplate.

Parcelize 😍

Kotlin added parcelable support in version 1.1.4.

Android Extensions plugin now includes an automatic Parcelable implementation generator. Declare the serialized properties in a primary constructor and add a @Parcelize annotation, and writeToParcel()/createFromParcel() methods will be created automatically.

Source

Create Food Order Tracking app using Android Timeline View Library

Food Tracking Android Timeline View Example
Food Tracking Android Timeline View Example

Android Timeline View Library (Using RecyclerView) is simple implementation used to display view like Tracking of shipment/order, steppers etc. Previously we discuss Android Vertical Steppers library which may display a transient feedback message after a step is saved.

Demo : Vertical Stepper Form Library

And today we’re going to see a cool library which help you to implement that Android Timeline View in your applications.

Want something new ? : HollyViewPager – Android Navigation Animation Library

Android Timeline View
Android Timeline View

Source: Add Android Timeline View 

First Firefox Extension with Kotlin Javascript

Kotlin, my favourite programming language, has seen a fast adoption on platforms like Android or Server where the code is compiled to Java bytecode. However, as Kotlin also supports compilation to Javascript, the language is starting to receive attention in the Web ecosystem as well. So today i am going to show you How to create Firefox Extension Using KotlinJS.

While some content on writing web applications in Kotlin has been published, the niche of writing browser extensions has seemed to be ignored until now. That’s why in this post we are going explore the process of writing a simple extension for Firefox using Kotlin JS.

You must see this : Top 20 Daily used Kotlin Code Snippet

How to Create Firefox Extension Using KotlinJS?

The extension is based on Your first extension by Mozilla and will simply add a red border to the kotlinlang.org website.

Requirements

For testing our Firefox extension, we will use the web-ext tool from Mozilla. To obtain it you need to install node.js and then run the following command in a terminal:

  1. npm install –global web-ext

Apart from that, we will be using IntelliJ IDEA 2017.2.6 with the Kotlin plugin version 1.1.60 to develop the extension.

You must aware of it : Kotlin Problems and How to avoid them?

Setting up the project with KotlinJS

Creating a new project using the KotlinJS (JavaScript) variant

In Intelli IDEA, we create a new Gradle based project and check the Kotlin (JavaScript) option.

We proceed through the wizard until the empty project is created and opened.

As the next step, we will enable the Dead Code Elimination plugin for KotlinJS. This is necessary because a Kotlin JS program needs to bundle the Kotlin stdlib which is over a megabyte in size. However, we can reduce the size of our compiled code drastically by removing code that’s never getting called.

You must see : Bye bye Gradle and Maven !! Say hello Kotlin Kobalt

To enable the plugin, simply add the following line to the build.gradle file.

  1. apply plugin: ‘kotlin-dce-js’

Creating the extension manifest

In the next step, we add the manifest file which is required for a Firefox extension. This fileis called manifest.json and resided in the root directory of our project. The file should have the following content.

{

“manifest_version”: 2,

“name”: “Kotlin Borderify”,

“version”: “1.0”,

“description”: “Adds a red border to kotlinlang.org”,

“content_scripts”: [

{

“matches”: [

“*://kotlinlang.org/*”

],

“js”: [

“build/classes/kotlin/main/min/kotlin.js”,

“build/classes/kotlin/main/min/kt-borderify.js”

]

}

]

}

In this file we declare that our extension will inject a content script in any website matching the pattern *://kotlinlang.org/* . The necessary script files are are the Kotlin stdlib kotlin.js as well as our code in the kt-borderify.js file.

Full article and Source : http://www.tellmehow.co/create-firefox-extension-using-kotlinjs/

Google Pixel 2 XL vs iPhone X: Which phone win the battle?

Google is challenging Apple with its second generation of smartphones, the Pixel 2. The Pixel 2 XL is the one closest in size to the iPhone X

Apple’s iPhone X and Google’s Pixel 2 XL has something common which both aiming to be come with the best smartphones on the market, and we’re all desperately waiting to be released.

maxresdefault (1).jpg

Both leading mobile company use very different OLED displays from different manufacturers. How do they compare and which is the best?

maxresdefault.jpg

Let’s find out who will winner of this battle by some comparison which are given below :

Display

The competition for displays is a close one between the iPhone X and Pixel 2 XL.

DISPLAY Pixel 2 XL iPhone X
Screen size (inches) 6.00 5.80
Resolution 1440×2880 pixels 1125×2436 pixels

According to above table Pixel 2 XL take a valuable lead against iPhone X.

See this also : Android Oreo Vs iOS 11 : Comparison you should know about this

Battery

The battery competition isn’t so close.

BATTERY Pixel 2 XL iPhone X
Battery capacity (mAh) 3520 2716
Removable battery No No
Weight (g) 175.00 174.00

The Pixel 2 XL packs a serious 3,520mAh battery that Google says can get up to seven hours of life in just 15 minutes of charging and took another lead against iPhone X.

Camera

A killer flagship phone needs a killer camera. Google and Apple both know this. iPhones always come with an impressive camera that Android cameras try to beat.

CAMERA Pixel 2 XL iPhone X
Rear camera 12.2-megapixel 12-megapixel
Flash Yes Yes
Front camera 8-megapixel 7-megapixel

Pixel 2 XL has high number features in this section also but due to iPhone’s camera quality reputations. iPhone X got a lead and battle is on 2-1 now.

Hardware

Perhaps the most distinct and hardest to compare aspects of the Pixel 2 XL and iPhone X are the hardware inside and the software they run.

HARDWARE Pixel 2 XL iPhone X
Processor 1.9GHz octa-core hexa-core
Processor make Qualcomm Snapdragon 835 Apple A11 Bionic
RAM 4GB 3GB
Internal storage 64GB 64GB
Expandable storage No No
Expandable storage type
Expandable storage up to (GB)

Performance of the iPhone X is a bit more clear. The iPhone 8 and iPhone 8 Plus are already out, and they run the same operating system and hexa-core A11 Bionic chipset that come in the iPhone X. It snatched another one point with great comeback. Point is 2-2 now.

Sensors

SENSORS Pixel 2 XL iPhone X
Compass/ Magnetometer Yes No
Proximity sensor Yes Yes
Accelerometer Yes Yes
Ambient light sensor Yes Yes
Gyroscope Yes Yes
Barometer Yes Yes
Temperature sensor No No

Google’s Pixel 2 XL take lead due to they have extra Compass/ Magnetometer sensor and now point table is elevate towards Google phone with 3-2 points.

Connectivity

CONNECTIVITY Pixel 2 XL iPhone X
Wi-Fi standards supported 802.11 a/b/g/n/ac 802.11 a/b/g/n/ac
Bluetooth Yes, v 5.00 Yes, v 5.00
NFC Yes Yes
Number of SIMs 1 1
SIM Type Nano-SIM Nano-SIM
4G/LTE Yes Yes

Connectivity configuration is all equal so we decide to give one-one point to both.

Winner

Comparing the iPhone X and the Pixel 2 XL and naming a winner is just as hard as comparing iOS and Android. They’re two different beasts, and each has ways of beating the other depending on what they’re competing over.

OVERALL POINTS Pixel 2 XL iPhone X
Points 4 3

When we get our hands on review units, we’ll have a better idea of which phone is really the best, but there’s no doubt both will be great.

Which Android Dependency Injection is best?

This post is a summary of first impressions of a few android related frameworks that we (Tell Me How Blog) tried out during a competences session recently.

What is Android Dependency Injection?

Dagger

“Dagger constructs instances of your application classes and satisfies their dependencies. ”
Dagger is a dependency injection framework, unfortunately most of us did not manage to setupdagger or failed to get dagger running once setup. So I can not give a proper overview of dagger2.
Read more: http://google.github.io/dagger/

Butterknife

“Annotate fields with @InjectView and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout.”
Butterkife is a view injection lib for android. As such it only handles injection of view components and does this using a InjectView annotation. So some boilerplate is removed and less code has to be written. Some of us found the result a bit harder to read and in some cases the reduction of code was not noticeably, but this is most likely true for the other injection frameworks to and not something specific for Butterknife. Setup was easy with just one dependency. Stack-traces was reportedly difficult to read when Butterknife was used.
Read more: http://jakewharton.github.io/butterknife/

RoboGuice 3

“RoboGuice 3 takes the guesswork out of development. Inject your View, Resource, System Service, or any other object, and let RoboGuice 3 take care of the details.”
RoboGuice 3 is similar to AndroidAnnotations and Butterknife, easy to setup, two dependency’s needs to be added to the build file. This framework seems like it should be easy to use if you are already familiar with Guice, and even if you don’t its not that hard to understand and use. It is similar to the other dependency injection frameworks that you don’t get all that much for your money, but it’s easy to use and removes some boilerplate. The documentation could use a touch-up.
Read more: https://github.com/roboguice/roboguice

Final Verdict:

The views on the frameworks above is the result of a 3 hour session where we tried them out and had a short discussion about each of them to sum up the experiences. Given the limited time we spent on each of the frameworks we might have missed some important things, if you find and mistakes or are missing some important information please post a comment below.

Read more >> Comparison of All Android Dependency Injection 

MVC V/s MVP V/s MVVM

The user interface often contains a lot of cluttered code primarily because of the complicated logic it needs to handle. The presentation patterns are design primarily with one objective in mind, reducing the complex code in the presentation layer and making the code in the user interface clean and manageable.

In this post, I will present a discussion on the MVC, MVP, and MVVM design patterns and highlight when one should be the design of choice over the other.

Model View Controller

The Model View Controller (commonly known as MVC) framework helps you to build applications that are easier to test and maintain. It comprises of three major components, namely:

  1. Model — this is the layer that represents the application’s data
  2. View — this represents the presentation or the user interface layer
  3. Controller — this layer typically contains the business logic of your application

The primary objective of the MVC design pattern is separation of concerns to facilitate testability. The Model View Controller design pattern enables you to isolate the concerns and makes your application’s code easier to test and maintain. In a typical MVC design, the request first arrives at the controller which binds the model with the corresponding view. In the MVC design pattern, the view and the controller makes use of strategy design and the view and the model are synchronized using the observer design. Hence, we may say that MVC is a compound pattern. The controller and the view are loosely coupled and one controller can be used by multiple views. The view subscribes to the changes in the model.

Model View Presenter

The MVP (Model View Presenter) design pattern also comprises of three components – the model, the view and the presenter. In the MVP design pattern, the Controller (in MVC) is replaced by the Presenter.

You can see : Android MVP Pattern Example

Unlike the MVC design pattern, the Presenter refers back to the view due to which mocking of the view is easier and unit testing of applications that leverage the MVP design pattern over the MVC design pattern are much easier. In the MVP design pattern, the presenter manipulates the model and also updates the view. There are two variations of this design. These include the following.

  1. Passive View — in this strategy, the view is not aware of the model and the presenter updates the view to reflect the changes in the model.
  2. Supervising Controller — in this strategy, the view interacts with the model directly to bind data to the data controls without the intervention of the presenter. The presenter is responsible for updating the model. It manipulates the view only if needed — if you need a complex user interface logic to be executed.

While both these variants promote testability of the presentation logic, the passive view variant is preferred over the other variant (supervising controller) as far as testability is concerned primarily because you have all the view updated logic inside the presenter.

The MVP design pattern is preferred over MVC when your application needs to provide support for multiple user interface technologies. It is also preferred if you have complex user interface with a lot of user interaction. If you would like to have automated unit test on the user interface of your application, the MVP design pattern is well suited and preferred over the traditional MVC design.

Model – View – ViewModel (MVVM)

The Model – View – ViewModel (MVVM) is a variation of Martin Fowler’s Presentation Model design pattern. The MVVM is a refinement of the popular MVC design and the ViewModel in MVVM is used to facilitation Presentation Separation. In the MVVM the logic is stored in the presenter and the view is completely isolated from the model.

See this : Top 10 Programming Architectural Patterns

While the presenter isn’t aware of the view, the view is aware of the presenter — the presenter in MVVM is used to represent an abstract view of the user interface. A passive view implies that the view doesn’t have any knowledge of the model. In the MVVM design pattern, the View is active and contains behaviors, events and data binding information. Note that the view in MVVM is not responsible for managing the state information — the view is rather synchronized with the viewmodel. The viewmodel in MVVM is responsible for presentation separation and exposes methods and commands to manage the state of a view and manipulate the model.

How does the view and the viewmodel in MVVM communicate? Well, the view and the viewmodel in MVVM communicates using methods, properties and events. The bi-directional databinding or the two way databinding between the view and the viewmodel ensures that the models and properties in the viewmodel is in sync with the view. The MVVM design pattern is well suited in applications that need support for bi-directional databinding.