Monday, 5 March 2018

Lost key-store or key pair?

If you had this experience , it's frustrating ...
Without your key-store and key-pair you can't even update your application, publishing a new app is out of the question.
While it's not possible to recover your lost key-store or key pair there is a solution for this problem.

What you will need to do

If you didn't lost the key-store skip step 1
Step 1 : Create a new key-store 
Step 2:  Generate a new key-pair 
Step 3:  Extract the certificate of the key-pair to pem format 
In command line type :
keytool -export -rfc -alias <upload> -file <upload_certificate.pem> -keystore <keystore.jks>

Step 4:  Contact Support Team by filling this form 

You should attach the exported certificate you created on step 3 and describe the problem in the form.
The support team responds usually in 2 working days

Step 5:  Avoiding future headaches

Always keep a copy of your key-store and your passwords in a safe location , i personally use google drive. 

More info:

Saturday, 24 February 2018

Pick an Image for Android

In this simple tutorial you will learn how to  create an image picker for android !
Creating an image picker for your app is simpler that you might have expected, by using a real working app you can see how you can implement it for your own projects.

Todo list

  •  Add permission WRITE_EXTERNAL_STORAGE
  •  create a button and an imageView
  •  launch an intent on button click
  •  get the result and update the imageView


Permissions : Add this permission to your AndroidManifest.xml :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

In our Main Activity we have a button and an image view , when we click our button we will prompt our user to select an image :

Intent intent = new Intent(Intent.ACTION_PICK,

startActivityForResult(intent, IMG_RESULT);

because we care about the image our user selected we will retrieve it using onActivityResult :

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 super.onActivityResult(requestCode, resultCode, data);
 try {

    if (requestCode == IMG_RESULT && resultCode == RESULT_OK && null != data) {
// get the selected image

Uri imageUri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
// display the image


} catch (Exception e) {
    Toast.makeText(this,"oops something went wrong", Toast.LENGTH_LONG)

Now our users can select images from their devices using our cool app... Well done!

Get the code on Github

You can see the applications code for reference here :

Happy coding!

Thursday, 1 February 2018

QR Code Scanner

I have built a simple qr code scanner , by using it you can connect to WiFi hot-spots, import contact information, browse websites and generally gain access to lots information by just scanning the qr code with the app.

QR codes can be found almost everywhere : cafes, airports , public spaces , WiFi hot spots , in products , stores and in any place where there is a need to share information about a product or a service.

They can contain information about WiFi connection details, contact information , websites , maps , text, sms , e-mails , phone numbers, even events .
You can quickly access that information to get information from promotions and special offers to contact details with just a scan!

Although similar tasks can be accomplished using NFC technology , NFC has some drawbacks :
  • Not all devices support it : newer devices support NFC but the majority is not.
  • Special circuits :  NFC requires tags embedded in labels or smart posters to share information the same way qr codes do.
Qr codes can be read by almost any smartphone with a camera and an app, qr codes can be generated and printed with ease in almost any surface inexpensively. 

 QR Code Scanner

QR Code Scanner Download

With QR Code scanner or your favorite QR Scanner (hoping to make mine your new favorite) you can have access to that valuable information!

The app is designed with simplicity in mind , big buttons located close to a users finger can help make a better experience using the app.

 If the scanner finds WiFi information it will prompt you to connect to that network , with one click will automatically enter the required details to join the WiFi !
Hassles like copy paste and manually entering WiFi details are now in the past.

You can view and  import a contact with a simple tap


Other Features :

  •  Scan and connect to WiFi networks that provide qr code within the app!  no more typing and time wasting!
  • Scan images for qr codes or barcodes
  • QR codes containing websites are automatically opened in your preferred browser!
  • Supports : email , sms , maps , phone numbers, websites and WiFi !
  • In low light conditions press the volume up button (when the scanner is running) and the flashlight will be activated! 

Friday, 1 December 2017

Design Patterns - Adapter

The adapter design pattern is about creating a layer where  two different components can work together, just like a real life adapter you use it to connect things that couldn't work together otherwise, following is a story to help you understand what is this about. 

You are a software engineer in SoftCorp , after several months of trials and other challenges you and your team are almost done working on an innovative GPS software for self driving cars, the release date is close and all are happy...

 The problem :

Suddenly your manager is calling you at her office and wants to change the weather api!

The software is using the WeatherPoint api to get weather updates so your software can make calculations for long distance trips, your manager wants to change the api to a different vendor : WeatherOracle.

The Solution:

Of course one option is to completely refactor your code base of thousands lines of code to use the new api , or you can use the easy way of the adapter pattern and be the hero of the day!

Project : SelfDrivingCarGPS

get the code

Before we dive in to the specifics of the pattern lets take a moment to explain in a high level what we are going to do:
Our CarGPS currently is expecting a WeatherPoint class but we need to use a WeatherOracle instead.

The adapter solution is to create a class WeatherPointToOracleAdapter where we will wrap a WeatherOracle obj adapting it to a WeatherPoint so the rest of your software does not need to know about the change!

here there is a simplified UML about the adapter pattern:

The first step is to create our adapter, the WeatherPointToOracleAdapter class :
 we will  place it in the adapter package.

public class WeatherPointToOracleAdapter implements WeatherPoint {

    private WeatherOracle weatherOracle;

    public WeatherPointToOracleAdapter(WeatherOracle weatherOracle){
        this.weatherOracle = weatherOracle;

    public String getWeather(String location) {
        // we use the weather oracle method to get weather 
       return weatherOracle.getWeatherData(location);

   public String getLocation() {
        // we use the weather oracle method to get location 
       return weatherOracle.getTheLocation();

Take a look in our adapter:
  • Implements the WeatherPoint interface because we will adapt the given object to a WeatherPoint
  • has a field WeatherOracle 
  • takes a WeatherOracle obj in the constructor , this object will be adapted !

we can use it like this:

public class Demo {
    public static void main(String[] args) {
        // Our new api
     WeatherOracleApi weatherOracle = new WeatherOracleApi("London");
        // adapting the api from WeatherOracle to WeatherPoint 
     WeatherPoint adaptedApi = new WeatherPointToOracleAdapter(weatherOracle);
        // using our class with no changes! 
     CarGPS carGPS = new CarGPS(adaptedApi,adaptedApi.getLocation());


Our CarGPS has no knowledge that we have placed an adapter or that the api is changed and just works like before using our new api!

Now our implementation looks like :

Well done , with your new skills you have saved your colleagues many hours of trivial work!
Explore the code and try to build your own adapters!

Happy coding!

Wednesday, 29 November 2017

Design Patterns - Composite

The composite design pattern is about a hierarchy where nodes with children have different behavior than childless nodes.

The pattern consists of three elements:
  • Component : a super-class typically an interface 
  • Composite : a node with children implements Component
  • Leaf : a childless node  implements Component

A typical example is a file system where there are folders and files:
Folders can contain files , other folders  or just being empty. On the other hand files don't contain folders or other files!

Project : FileSystem

 get the code here.

Here you will explore a simple file system , where you can see a simple implementation of the pattern.

Here you can see a UML of our File System  :

take a moment to explore the code and:
  •  note what component of the pattern each class represents 
  •  observe the output of the code and see the difference between a file and a folder 
  •  in what scenarios do you think this pattern would be useful?

Project : Extending our FileSystem


 Time to get your hands dirty!
 Extend our FileSystem by adding new file types!

Take the code and implement a new File type: Img

General Guidelines:
  • The Img should implement FileComponent
  • Img must have a data field, you can use anything you like
  • You can use the display method of the file to customize it for the new file
  • Create an Img object and add it to a folder!

Happy coding !!!

Sunday, 26 November 2017

Design Patterns - Advanced Iterator

In the Basic Iterator article you have used an existing iterator to simplify our Car Parts Store , having learned about iterators you might have wondered if you can create your own iterator...

Project : CarPartsStore - Advanced

At some point our Car Parts Store has become more sophisticated , at the beginning we had only one List<CarPart> carPartList with all the available parts, but the Warehouse manager also wants to have a log where he/she can keep track of what parts have been sold.

The soldLog is also a List<CarPart> where we have all the parts that we have sold to our customers, things are getting more interesting for our Warehouse class and we need to use the advanced iterator pattern to accommodate our new needs.

As we have done in the basic iterator pattern we will start by making our Warehouse class to implement Iterable :

public class Warehouse implements Iterable<CarPart> 

 and implement :

public Iterator<CarPart> iterator() {
     return new WarehouseIterator();

WarehouseIterator is not existing right now, this will be our custom iterator !
We will make it a private inner class as it needs access to our Warehouse inner workings, we can name it anything the important things are:
  • it is an inner class
  • implements Iterator<CarPart>
Our inner class will look like:

private class WarehouseIterator implements Iterator<CarPart> {
 public boolean hasNext() {
        return false;
 public CarPart next() {
        return null;

now it's time to get it done:
 we add the following cursors in our WarehouseIterator class:

 // Here we put our cursors: 
Iterator<CarPart> partsInStockIterator = carPartList.iterator();
Iterator<CarPart> soldPartsIterator = soldLog.iterator();

now we can keep tracking both Lists using their iterators

 public boolean hasNext() {
    // if any of the iterators have next return it till there is no next 
 return partsInStockIterator.hasNext()|| soldPartsIterator.hasNext();

as long either iterator has a next we return it till there are no more.

 public CarPart next() {
    CarPart carPart;
        System.out.print("Stocked : ");
        carPart =;
    }else {
        System.out.print("Sold : ");
        carPart =;
    return carPart;

The print statements are added so you can see what is going on when the code is running.
You should remove or comment them out when you verify the code works as expected!

Now our code has the ability to iterate through both lists in our Warehouse class!

Happy coding!

Friday, 24 November 2017

Design Patterns - Basic Iterator

Among the most common things in a collection of items is the ability to iterate through the collection , in Java for example there are data structures that allowing us to create collections for primitive data or our custom classes.
Here some : ArrayList<T>, LinkedList<T> , HashSet<T> and others...

The above have something in common , all are implementing  the Interfaces : Collection and Iterable.

Below there is a simplified UML diagram  illustrating the ArrayList <T>:

The above relationships are allowing us to use the magic:

for(String s: stringList){
     // do something with s

The above is a convenient way to write a foreach  loop in Java, but the language it self translates it to:

Iterator<String> si = stringList.iterator();

   String s = si.getNext();
   // do something with s

Now armed with this knowledge we can go beyond the default behaviors of the build in collections and can customize it for our own needs!

Basic Iterator Pattern:

Project : CarPartsStore

Here we will illustrate the customized behavior by exploring a Store that sells car parts, in this code-base we have the Warehouse class that contains a List of CarPart .

What we do here: We will use the basic Iterator Pattern to iterate through our Warehouse class for CarPart .

We will make something like the following to work:

for(CarPart part: Warehouse){
  // do interesting stuff ...

by default the above is not working as our warehouse has a field of ArrayList<CarPart> ,  but having the new awesome Iterator powers we can can do it !

 In our Warehouse class we added the implements Iterable :

public class Warehouse implements Iterable<CarPart> 

notice we used the CarPart type , as we want to iterate through a collection of CarPart.

also we have implemented the following :

public Iterator<CarPart> iterator() {
    return carPartList.iterator();

Now when we try to iterate through our warehouse we iterate through the carPartList !
Congratulations ! now you have learned how to take iteration to your hands!

Feel free to experiment with the code!!!