Saturday, December 30, 2017

Agera Repository


In our previous blog post we have learnt about Agera, about Reactive programming  and Sample code of Hello World Example using Agera - Functional Reactive Programming for Android recommended by Google. In Hello World Example learn about Observable, Updatable, Supplier and Receiver

In this blog I am going to introduce Repository.


What is the Repository ??

The most important concept in Agera is the Repository. Repositories receive, supply, and store data and emit updates. The interfaces Observable, Supplier and Receiver are combined into two types of repositories:


InterfaceObservableSupplierReceiver
Repository
MutableRepository


In our hello world code, you could replace
implements Observable, Supplier<String>, Receiver<String>
with
 implements MutableRepository<String>
but Agera provides a Repository factory, so remove the MyDataSupplier class altogether and replace
  MyDataSupplier myDataSupplier = new MyDataSupplier();
with
 MutableRepository<String> mStringRepo = Repositories.mutableRepository("Initial value by Agera with Repository");
mutableRepository() creates a repository similar to our previous implementation, but that is thread-safe and has a more sophisticated update dispatcher, so let's use that from now on.
Also, remove the updatables (with removeUpdatable()) when you know you're done with them. In our example this is not needed but it is a good practice: it avoids potential leaks and prevents updating destroyed views. The class is now much shorter:
 public class JavaMainActivity extends AppCompatActivity {
     //    MyDataSupplier myDataSupplier = new MyDataSupplier();
     //    Updatable updatable;
     private MutableRepository<String> mStringRepo;
     private Updatable mLoggerUpdatable;


     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);

        mStringRepo = Repositories.mutableRepository("Initial value by Agera with Repository");

       final TextView textView = findViewById(R.id.textView);

          // Create an Updatable
          //        updatable = new Updatable() {
          //            @Override
          //            public void update() {
          //                Log.d("AGERA", myDataSupplier.get());
          //                textView.setText(myDataSupplier.get());
          //            }
          //        };
          //        myDataSupplier.addUpdatable(updatable);

          //        myDataSupplier.accept("Hello Agera!");


          // Create an Updatable by Respository
      mLoggerUpdatable = () -> {
          Log.d("AGERA", mStringRepo.get());
          textView.setText(mStringRepo.get());
      };
     }

      @Override
      protected void onStart() {
          super.onStart();
          mStringRepo.addUpdatable(mLoggerUpdatable);

          // Change the repository's value
          mStringRepo.accept("Hello World by Agera with Repository");
      }

    @Override
     protected void onStop() {
        mStringRepo.removeUpdatable(mLoggerUpdatable);
       super.onStop();
     }
 }

In summary:

Agera uses very simple interfaces you should be aware of:
 Observable, Updatable, Supplier and Receiver. These are combined in the Repository and MutableRepository interfaces.
  • Agera provides a factory of implementations of these simple Repositories: Repositories.mutableRepository(T)and Repositories.repository(T) for immutable repositories.
Source code for this can be found here Enjoy !!!!


Contact - Let's connect to each other


Thursday, December 14, 2017

Agera - Functional Reactive Programming for Android

What is Agera?

Agera is a super lightweight Android library that helps prepare data for consumption by the Android application components (such as Activities), or objects therein (such as Views), that have life-cycles in one form or another.
It introduces a flavor of functional reactive programming, facilitates clear separation of the whenwhere and what factors of a data processing flow, and enables describing such a complex and asynchronous flow with a single expression, in near natural language.

second question comes to any mind is 

What do we mean by reactive?


Reactive programming is a paradigm related to how changes are propagated in a program. A good example is a spreadsheet: cells contain formulas that depend on other cells' values. When one of these values are changed, there's no need to manually update the resulting values; the changes are propagated for you. Agera brings a reactive flavor to Android using an observer pattern.

Hello World Example

Lets start with simplest example of programming world, that is Hello World Example.
But to learn how to code for "Hello World", we need to learn basic components of Agera.

The foundation of Agera is a set of very simple interfaces including: Observable, Updatable, Supplier and Receiver:

Observable.java
public interface Observable {

  void addUpdatable(Updatable updatable);

  void removeUpdatable(Updatable updatable);
}


Updatable.java

public interface Updatable {

  void update();
}


Supplier.java

public interface Supplier<T> {

  T get();
}

Receiver.java

public interface Receiver<T> {

  void accept(T value);
}


As you can see, these four interfaces are very simple. This is what they're responsible for:

  • Observable => Something that can be observed for changes and stores a list of updatable objects. When a change occurs, the updatables are poked
  • Updatable => Called when an event has occurred. Its update() method will be called when the class it observes changes, but can also be called manually to force an update.
  • Supplier => Something that supplies data when the get() method is called. In this case, "Data" can be anything.
  • Receiver => Something that can receive (and normally store) a value send to it via accept().
lets see how to use them in our code.
I have already written Hello World Example on Github

All the best !!! Happy Coding !!!

Next Step is to learn Repository..

Repository => The most important concept in Agera is the Repository. Repositories receive, supply, and store data and emit updates. The interfaces Observable, Supplier and Receiver are combined into two types of repositories:
  Repository can replace Observable and Supplier
  MutableRepository can replace Observable, Supplier and Receiver
A complete blogpost is coming soon on Repository...!!

let's connect to learn together







Wednesday, March 22, 2017

Android O saves phone's battery

Top Android O features:

1. Better battery life:

The previous few Android refreshes Doze, Doze in a hurry went for enhancing battery life. With Android O, Google is further clipping down on unpredictable applications eating the battery out of sight.
Android O places specific limits on implicit broadcasts (signals sent by an application for other apps or activities to act upon), location updates and background services. All these happen automatically in the background, without users having to manage anything on their own.
This will prevent errant applications which you haven’t used in a long time from sapping your battery life whilst implementing background processes.

2. Managing/Grouping Notifications

O introduces notification channels that allow you to create a user-customizable channel for each type of notification you want to display. The user interface refers to notification channels as notification categories. To learn how to implement notification channels, check the Notification Channels guide by official website.
Notifications can be segmented into various different channels like sports news, text messages, music applications and so on and users can control each channel separately. The notification shade will also group notifications by channel, making it much easier to glance through relevant notifications. Users can also block or snooze a whole channel in one go if they wish.

3. AutoFill

While AutoFill in Android exists in certain applications like Messages and Chrome, the feature is app-specific and is not a part of the whole OS.
Android O makes filling out forms, such as login and credit card forms, easier with the introduction of the Autofill Framework. Existing and new apps work with Autofill Framework after the user opts in to autofill.

4. Picture-in-Picture mode

Android O allows activities to launch in picture-in-picture (PIP) mode. PIP is a special type of multi-window mode mostly used for video playback. PIP mode is already available for Android TV; Android O makes the feature available on other Android devices.
Developers can specify which aspect ratio they want for their application and can even set custom interactions on the PIP window. This feature is already available on devices running Android TV.

5. Audio improvements

With Android O, Google is presenting a few new components went for audiophiles. Android O carries with it bolster for amazing sound codecs, for example, LDAC.
Moreover, Google is additionally presenting AAudioanother local API for applications requiring support for elite, low-idleness sound.

6. Adaptive Icons

Adaptive icons will be supported in the launcher, device settings, the app overview screen and shortcuts.
Android O introduces adaptive launcher icons. Adaptive icons support visual effects, and can display a variety of shapes across different device models. To learn how to create adaptive icons, see the Adaptive Icons preview feature guide.

7. Better keyboard navigation

With Chromebooks now supporting Android applications, Google has introduced a new model for keyboard navigation in Android O.
Specifically, Android O brings with it a better way to navigate around Android using the arrow and tab keys on the keyboard.

8. Wide-gamut color for apps

Android developers of imaging apps can now take advantage of new devices that have a wide-gamut color capable display. To display wide gamut images, apps will need to enable a flag in their manifest (per activity) and load bitmaps with an embedded wide color profile (AdobeRGB, Pro Photo RGB, DCI-P3, etc.).

9. Support for third-party calling apps

Android O supports third-party calling apps natively. Google has introduced a new feature called ‘Telecom framework’, which allows for third-party calling applications to work with each other and with carriers.

10. WebView APIs

Android O provides several APIs to help you manage the WebView objects that display web content in your app. These APIs, which improve your app's stability and security, include the following:
·         Version API
·         Google SafeBrowsing API
·         Termination Handle API
·         Renderer Importance API
Android O also brings with it optimisations for new runtimes for better stability and performance in applications designed specifically for Android O