Code Complexity

      No Comments on Code Complexity

HOW TO HANDLE CODE COMPLEXITY IN SOFTWARE COMPANY

Working on software solutions is a difficult task and you can get stuck anywhere. Experience surely matters but sometimes even the most skilled professionals can face problems resulting in the pauses in projects. If you are willing to grow and get some experience then you should dive into complexities instead of avoiding them. Finding yourself stuck in some problem is an absolutely normal thing; the thing that matters most is whether you want to skip the problem and become a failure or whether you want to find the solution at any cost.

To overcome software complexities and to find solutions for new problems, the most important thing is consistency. The solution in solving code complexity is never more than a single verse which means whoever is trying to win the game can propose solutions.

If you work in Software Company and are tired of software complexities, then the list below can really help you out

  1. Collaborate Within Your Team

If you are the owner of the software company then it is better you should arrange multiple meetings in order to analyse and discuss the need to address and resolve software complexity. It happens most of the time that developers do not share the complexities of the software on which they are working. It is your responsibility to arrange meetings and collaborate with your team and discuss on what code they are working on currently. Compile a list of issues that any one or more members are facing and then try to find solutions.

  1. Arrange Formal Meetings

Once you are provided with the list of problems by all the members, now you can arrange a formal meeting and endeavor to find solutions. This is the time when you can approach code base to find solutions. The most important way to solve the problems would be addressing cause and effect relationships.

  1. Prioritize

Making a priority is a very essential thing because this way, you wouldn’t even miss the minutest problem. Since you have the list of all your problems now, therefore, it is better to prioritise that which solutions must be found instantly depending on your needs and project requirement. This is the most efficient way to handle the bugs in an efficient manner without missing anything crucial.

  1. Delegation of tasks

This is the point when – having identified all the complexities – you can assign one code complexity to one individual. It is a tiring task because before assigning you will have to thoroughly examine the performance of the individual. Another important factor is motivation; how motivated your team members are to deal with the code complexities.

Solving code complexities is not an instant process, rather it is an extended one in which the person you assign the task will have to write codes again and again. In this process, you will have to keep an eye on his performance. If you think there are problems that your team can resolve on its own then there is no need for extra interference; also give your team a little space.

  1. Results

Now as all the complexities are stated, individuals are assigned with multiple tasks and all the bugs are sorted out, this is the time when you can devise a regular monitoring of the code quality which will save you from any further problems. Checking your work on regular basis will save you from many complexities.

These were the simple and most practical ways to resolve software complexities.

This article is written by Lisa Myers, who works at Rebateszone. She is a software engineer by profession.

 

Android Multipicker Library

      1 Comment on Android Multipicker Library
Android Multipicker Library

Android Multipicker Library

Similar to image-chooser-library, but has some new features. Re-written from scratch. Android Multipicker Library is an open-source project which has the following objectives.

Makes it easy and simple to integrate “Attach that file” feature into your android apps.
  • Don’t worry about various devices/OS variations.
  • Don’t worry about out-of-memory errors.
  • Don’t worry about creating thumbnails to show a preview.
  • Picking up any file for your app, and it’s details.
  • Picking up audio files.
Code less for capturing images/videos/files
  • Choose images from device or take a photo
  • Choose videos from device or record one
  • Choose files available on your device
  • Choose audio files available on your device
  • Choose a contact from the phonebook
  • Works with almost all content providers
  • Get all metadata about the media that you would probably need
  • Similar code base to implement irrespective of Android version of device.
Media types supported
  • Pick images.
  • Capture a still photo.
  • Pick videos.
  • Record a video.
  • Pick/Record an audio.
  • Pick files.
  • Pick a contact (Display name, phones and emails).
Post Processing
  • Generate metadata of file (Size, MimeType, Extension)
  • Generate metadata of images (Width, Height, Orientation + metadata of files)
  • Generate metadata of videos (Width, Height, Orientation, Duration + metadata of files)
  • Generate metadata of audios (Duration + metadata of files)
  • Generate thumbnails of images (Big and Small)
  • Generate preview image of a video and it’s thumbnails.
Other features
  • Multiple file/image/video selection.
  • Configurable storage location of all files.
  • Easy handling for incoming share intents.

The implementation code is more concise and meaningful. Do give it a try.

Why Android Multipicker Library?

A little bit of background:

Get it on Google Play

Multipicker Library Demo

Picking images/videos on Android is not that straight-forward. It might be easy if you want to pick media from a specific app or the phone’s gallery. But it becomes very tricky when you have to deal with all kinds of apps. ex. Dropbox, Google Drive, various File Manager applications, different types of camera applications and so on. Android Multipicker Library makes it super easy for you to deal with all these scenarios, with a single codebase. So that you don’t have to keep writing code to handle all these scenarios differently.

You can try out this sample app and see how it works. Let us know your feedback or suggestions.

Checkout the Wiki Pages on Github for code snippets.

File Upload from Webview on Android

      4 Comments on File Upload from Webview on Android

You have a form on WebView, with input type as “file”, and want to allow the user to upload a file from his device. Prior to Lollipop, this was not very straightforward, and you had to resort to using private APIs, which has always been discouraged. But, you had to do it. With Lollipop, there’s a new public API, which still isn’t very straight-forward to use, but at-least, should be reliable and compatible with newer Android/WebView versions. So, how do you implement File Upload from WebView on Android with the new public API? 

This has been a long pending request, and people have implemented workarounds by using various versions of some private API’s for various older versions of Android.


Steps to Implement (3 steps)

  • Attach WebViewChromeClient, and override method callback for a click event on and input field of type file.
mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
         public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,              FileChooserParams fileChooserParams) {
                 mFilePathCallback = filePathCallback;
                // Launch Intent for picking file
                return true;
         }
});
  • Launch Intent for picking the file
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
  • Pass the Uri of the selected file to WebView
@Override
protected void onActivityResult(int requestCode, int resultCode,
     Intent intent) {
     if (requestCode == PICKFILE_REQUEST_CODE) {
          Uri result = intent == null || resultCode != RESULT_OK ? null
              : intent.getData();
          Uri[] resultsArray = new Uri[1];
          resultsArray[0] = result;
          mFilePathCallback.onReceiveValue(resultsArray);
     }
}

 

I have created a small sample project with all the required code to achieve a simple input field taking in an image. You can get the source on Github.

Script for compressing images with tinypng API

TinyPng is a nice service which provides you 500 free image compressions a month. And this is nice, since in a typical Android project, you wouldn’t have more than 500 images in any given month :). I have a simple script that scans through all your images, and tries to compress them using the tinypng api. All you need to do is to copy the script, put it in the root folder of your project and run it.

Head over to TinyPng website to checkout how it works.

What does TinyPNG do?

TinyPNG uses smart lossy compression techniques to reduce the file size of your PNG files. By selectively decreasing the number of colors in the image, fewer bytes are required to store the data. The effect is nearly invisible but it makes a very large difference in file size!

Advanced lossy compression for PNG images that preserves full alpha transparency.

Let’s jump into it. This script will search for all the images(pngs) in your Android project, pick each one, call the API, and overwrite the images, with a compressed version. And since this is a lossless compression, you won’t notice any change in quality. The overwriting part is probably a bit dangerous. So, with a little modification, you could change the script so that it creates a copy of the files.

The initial script for tinypng was taken from this gist by rakuishi. Thanks :).

Image Crush Savings Report

  1. The first thing you would need to do is to get an API key here.
  2. Copy this file to the root of your android folder.
  3. Replace your API key in this file on the top.
  4. Run “ruby imgcrush.rb”
  5. View the generated HTML report. (Link to sample report)

That’s it. For an example above, you could see, the script reduced the size to almost half for each image. And the total savings is somewhere about a whooping 53%.

Note: There are other image compression APIs/tools which I haven’t tried yet. Android build system itself has a pngcrusher which tries to optimize all your assets.

Windows 10 Review – First impressions

      6 Comments on Windows 10 Review – First impressions

I have a laptop, 1 year old, HP Pavillion, with an Intel i5 processor (quite a recent one), with 8 GB RAM. It used to run Windows 7 before. And it was slow. I kept it as a backup incase my MacBook Pro failed (it never has). Well, I also have an octa-core AMD desktop running on Windows 8.1, which again is a backup when the first backup fails, or frustrates me enough.

The laptop, running Windows 7 was too slow to even use it just for browsing. And I tried all tricks to make it faster. Even then, it was only marginally better, which wasn’t good enough. So, I rarely used the laptop. Today, it prompted me that Windows 10 has arrived. I thought to myself, in worst case scenario, after the upgrade, I might stop using this laptop, and I pressed the “Download” button, anxiously. After a good 1 hour, it was up and running Windows 10. Read on for Windows 10 review and my first impressions.

The upgrade process was rather smooth. No problems at all.  All hardware seem to be working fine. And it didn’t lose any of my data, even my Wi-Fi passwords. All applications I checked worked fine.

After logging in for the first time, it wasn’t any better than Windows 7. I was just browsing through all parts of the OS, restarted it a few times, and it started showing signs of improvement.

Windows 10 promises very fast boot times. On this laptop, I didn’t notice much of an improvement than Windows 7. I did try to restart it a few times, but the boot time, and the logging in time seemed to take longer than I would have liked. From powering it on to getting to see the desktop, it was a good 3 minutes on this machine.

Interface: The whole UI has been refreshed, but I think, it could have been a little better. For now I am using the default theme. May be I should try a different theme. At first, you might get a little confused. As with all major OS upgrades, I shouldn’t be complaining about this.

  • The PIN login is something new on a desktop OS. You can enable this (4-digit PIN), after you verify your account (outlook.com or live.com) with which you would be logging in to the system.
  • The window styles have been refreshed with a minimalistic and less colorful theme (default).
  • The Task Bar, Start buttons are a welcome change from Windows 8. People coming from Windows 7 might be a tad more comfortable than those upgrading from Windows 8.
  • There are no hidden slide outs from all sides (as in Windows 8).
  • The controls at the right bottom corner of the Task bar looks nice.
  • Almost every icon on Windows 10 is more 3D-ish. You might find it a bit difficult at recognizing the familiar icons.
  • The start menu is definitely more cluttered than Windows 7, but a lot better than how it worked on Windows 8.
  • The new Task View is nice. I really liked it. It’s easier than ever to work with multiple desktops on Windows finally.

Coming to performance, for now, I am quite surprised with it. It’s fast and snappy as compared to Windows 7. Apart from the boot times, everything else starts up faster than before, and suddenly makes me feel using a brand new laptop. I am glad that I upgraded. Soon, I would be upgrading my desktop to Windows 10, but unfortunately, I have got no notification there. Probably because, that’s a custom built machine (AMD), and it would take some more time for Microsoft to support all kinds of hardware to ensure a smooth upgrade.

Microsoft Edge: The new browser is hell of an upgrade from the aeging Internet Explorer. Now, you won’t bang your head if you accidentally click on the browser from Microsoft. It starts up very very fast, and responds to clicks just like any other browser. Although I haven’t used it extensively, it’s definitely an welcome upgrade from IE. Bye Bye IE.

Cortana: Well, again, we have to see how it works, but at least, they made a start. The concept is like Google Now on Android and Apple’s Proactive Assistance. On the face of it, it seems very useful.

These are my first impressions of Windows 10 running on my laptop. So far, I would give it a thumbs up. However, I would probably wait for some more weeks before I give my final verdict.

PIN Screen Library for Android

      7 Comments on PIN Screen Library for Android
Here’s a simple and easy implementation for adding PIN lock support for your Android apps. The library can be themed with your app theme colors. It has smooth animations and vibrate cues when something’s wrong.

 

To use this, you just have to write about 10 lines of code, including layouts and everything. It’s so simple.

Steps to implement

  • Add as dependency

Maven:

<dependency>
<groupId>com.kbeanie</groupId>
<artifactId>pinscreenlibrary</artifactId>
<version>1.0.0</version>
</dependency>

Android Studio:

compile ‘com.kbeanie:pinscreenlibrary:1.0.0@aar’ 

  • Add PinView to your layout file.

<com.kbeanie.pinscreenlibrary.views.PinView
android:id=”@+id/pinView”
android:layout_width=”match_parent”
android:layout_height=”wrap_content” />

  • Initialize PinView in two modes

pinView.setModeSetup(PinEntrySetupListener);
pinView.setModeAuthenticate(PinEntryAuthenticationListener)

And finally, handle the callbacks for all events. The complete source code for this project can be found on Github. Let me know if you have any queries or issues. I would be happy to resolve them.

New Sensors in Android 5.0 (Lollipop)

      2 Comments on New Sensors in Android 5.0 (Lollipop)
I found a few non-documented sensors on Lollipop (Android 5.0) on a Nexus 5.

Tried looking for them, but could’t find any documentation on them on. Looks like they are mostly software sensors.

Android app on Google PlayHere’s the list that I have found. I have written a simple app that displays all the sensors and shows there values. Not to mention that, only for the ones that are documented. For the ones not documented, you can only see it’s details.

There are only a few which appear on developer.android.com.
Here’s an excerpt from the announcement.

New types of sensors

In Android 5.0, a new tilt detector sensor helps improve activity recognition on supported devices, and a heart rate sensor reports the heart rate of the person touching the device.
New interaction composite sensors are now available to detect special interactions such as a wake up gesture, a pick upgesture, and a glance gesture.

Since there’s no documentation, for some of them, I don’t really know what they do. The only thing that gives you a clue is the sensor name. And, I don’t know how to work with them as well.

Tilt Detector

AMD Sensor (No idea, whats that)

RMD Sensor (No idea, whats that)

Basic Gestures Sensor

Tap Sensor

Facing Sensor

Tilt Sensor

Pedometer

Pedestrian Activity Monitor

Update: Seems, the documentation is coming soon. XDA picked this up.

Easy Swipe to Refresh in Android

      No Comments on Easy Swipe to Refresh in Android
Swipe to Refresh Android

Recently, Google released a new version of the Support Library, which has an interesting component. It’s called SwipeRefreshLayout. With that, it’s become a child’s play to implement a quick Swipe-to-Refresh control for your apps.

A few things first

  1. Available only with android-support-v13. Which means that only apps target SDK level 13 and above can use this.
  2. It can only contain one scrollable direct child such as a ListView or a ScrollView.
That’s all you need to know. Well.. A few things more, basically some xml and java code.
For this example, we use a ListView with some demo data. Once the list view is scrolled, we do some task, wait for sometime, and update the list view’s adapter. Finally, ask the SwipeRefreshLayout to stop the progress indicator, since we are done with refreshing.
The layout file

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
    xmlns:tools=”http://schemas.android.com/tools”
    android:layout_width=”match_parent”
    android:layout_height=”match_parent”
    tools:context=”${packageName}.${activityClass}” >
    <android.support.v4.widget.SwipeRefreshLayout
        android:id=”@+id/swipeLayout”
        android:layout_width=”match_parent”
        android:layout_height=”match_parent” >
        <ListView
            android:id=”@+id/listView”
            android:layout_width=”match_parent”
            android:layout_height=”match_parent” >
        </ListView>
    </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>

The UI initialization

private void initializeViews() {
refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeLayout);
refreshLayout.setOnRefreshListener(this);
                // The default colors for the progress bar are not so nice.
setColorSchemeForProgressBar();
ListView listView = (ListView) findViewById(R.id.listView);
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1);
adapter.addAll(getDemoData(5));
listView.setAdapter(adapter);
  }

The Refresh Task

       @Override
public void onRefresh() {
Log.i(TAG, “Refresh Requested”);
doRefresh();
}
// Fetch data and update listview’s adapter
private void doRefresh() {
RefreshTask task = new RefreshTask();
task.execute((Void) null);

The Completion Work

private void postRefreshComplete() {
// Stop the refresh animation
refreshLayout.setRefreshing(false);
// Update adapter with new data
adapter.clear();
adapter.addAll(getDemoData(new Random().nextInt(20)));
adapter.notifyDataSetChanged();
   }

And there you go, a simple swipe to refresh usage for your Android apps. You can find the whole source code here

Step Detector and Step Counter Sensors on Android

Android KitKat has added a few more hardware sensors to it’s API list. Step Sensors are one of them, which looks very promising. Although, not a lot of phones yet have these Step Sensors, in the future, this would gradually become a standard I think. Currently, Nexus 5 has them.

Let’s see how we can interact with these sensors. Basically, there are 2 sensors.

  1. Step Counter: This keeps a count of the number of steps that you have taken. The counter is only reset when you re-boot the device, else, for every step you take (or the phone thinks you took, you counts up).
  2. Step Detector: This sensor just detects when you take a step. That’s it. 
The example project shows you how to initialize and setup the SensorManager and respond to events from the Sensors.

// Step Counter
sManager.registerListener(new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float steps = event.values[0];
textViewStepCounter.setText((int) steps + “”);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER),
SensorManager.SENSOR_DELAY_UI);

// Step Detector
sManager.registerListener(new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
// Time is in nanoseconds, convert to millis
timestamp = event.timestamp / 1000000;
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR),
SensorManager.SENSOR_DELAY_UI); 

No special permissions are required.

Head over to Github to get the full source code.

Making your Android apps crash-proof

      No Comments on Making your Android apps crash-proof
Image courtesy: Crittercism Website

Do you have an android app on the Play Store, and get lots of negative comments/feedback?

Most of the time, apps crash on the first interaction with the user. And that’s the reason most users are frustrated of even downloading your app, and that’s when most of the negative comments start pouring in.

Of course, you have to look for crashes everywhere in your app, but crashing on the first page itself, is a really really bad situation. When that happens, and the user leaves a bad comment, instead of sending you a support mail, you have no idea how to fix it. You have no idea about the user’s device, and other important information that would help you in determining the problem, and fixing it. And if you continue having such a build even for a week on the store, that puts a dent on your overall app reviews. People generally look at the first few reviews, and make a decision based on that, whether to try your app or not.

I have had an app on the store for years now, which I didn’t update for a long time. And finally, when I got the time to work on it again, I decided to integrate Crittercism SDK within my app, along with Google Analytics SDK.

The very first update with +Crittercism along with +Google Analytics , my inbox was flooded with crash reports. I was amazed at how many un-reported crashes my app had. I was living in the dark, as to what all problems users were having with my app. Crittercism logs had more information about the crashes than I could have asked for. They were pretty detailed, in terms of the user’s device name, and OS versions, the version of the application, and a device snapshot (Memory/Storage) when the crash occurred.

After about a week, I made the next update, and this time, the crash notifications reduced dramatically, although the number of users and the average usage of my app went up. From this, I can guess that the users who are still using my app are a happy lot. And that makes me happy as well.

I would strongly recommend integrating such a live error reporting tool into your apps to get live feedback for your apps. Specifically for Crittercism, there are free and paid plans. Currently, I am on the free plan, and it gives me the almost everything that I need to know to fix those random crashes. With paid plans, you have more reporting, which I think I don’t need right away. Receiving crash notifications is just the one part of Crittercism. They call this solution as a “Mobile Application Performance Management” solution. Rightly so?

Have you used Crittercism in your apps? Do you have anything to say?