Category Archives: Uncategorized

Will Write our Own App to Trigger Mi Band

10371404_10206191040355262_3352352559338119016_n
Xiaomi Mi Band is the world’s cheapest and branded fitness tracker. So why don’t we do some experiments so that we can make the Mi Band do what we say for a change?

I’ll be doing this code session for Android using Android Studio, hope others can understand the basics

Step 1
Firs of all we start a new empty project. And add 4 buttons. This is to test 4 basic functions of the Mi Band. Then initialize the buttons and ready the the setOnclick listners.

Step 2
Add Bluetooth Permissions in the Manifestfile, else you wont be able to connect to the band 😀

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

Step 3
Add the Xiaomi Mi Band dependencyto the gradle and sync it

compile 'com.zhaoxiaodan.miband:miband-sdk:1.1.2'

Step 4

In the oncreate you have to create and initialize an instance of the MiBand Class

private MiBand miband;
miband = new MiBand(this);

Step 5

I have not done the pairing part in the code, but I assume the Mi band of yours is already paired to the device. If you have paired more than one device you can populate all the paired devices and allow the user to select one. But for the demonstration purpose I have only paired with my Mi Band so it is the one and only device returns to me

Object[] devices = BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray();
final BluetoothDevice device = (BluetoothDevice) devices[0];

So I am getting my paired device from the available devices, as I only got my Mi band paired I get the 0th device. hope you people got that part 😀

Step 6
No you have to connect to the paired device

miband.connect(device, new ActionCallback() {
    @Override
    public void onSuccess(Object data) {
        pd.dismiss();
        Log.d(TAG, "Success !!!");
        miband.setDisconnectedListener(new NotifyListener() {
            @Override
            public void onNotify(byte[] data) {
                Log.d(TAG, "Disconnected!!!");
            }
        });
    }
    @Override
    public void onFail(int errorCode, String msg) {
        pd.dismiss();
        Log.d(TAG, "connect fail, code:" + errorCode + ",mgs:" + msg);
    }
});

Step 7

So if you have successfully connected to the device. You can start invoking functions of the MiBand in the button clicks
For example : You can make it Vibrate using this code snippet

miband.startVibration(VibrationMode.VIBRATION_WITH_LED);

You can check out some more commands in the sample code available in Git HubgitHub-download-button

Advertisements

A Myth comes true with Google Cloud Vision API

Cloud Vision API by Google Cloud is the latest addition for the Google Cloud platform. Last week it has been made a beta release and been allowed for the developers around the world to try and experience it. 2 month of free usage is offered by the Google at the moment as a promotion.

This API is already being used in the Google Photo app. You may have already experienced it’s power. Analyzing objects in a photo, face detection, geographical location detection and fast search are some of their features.

Features

So I was able to register for it lat week and was already able to build an app. But as it was still in the beta. Faced some problem(Can be found with solution in Stack overflow) on creating the API key for Android. But was able to find a quick fix as many people are facing the issue.

But when I was going through the API and I found many awesome feature that just a myth till today. Still there is no proper documentation but you can find some of the popular features and getting started docs listed here.

Here are the High Lighted APIs listed down
vision

You can also try Google Cloud Vision API here

Pricing is also seems reasonable compared to the amount of processing that they have promised to do. It will be a big break through in the history of the image processing technology.

You can check out the Android app I have developed using the ‘FACE_DETECTION’ API, if you love selfie you will Love it. Download the Selfie Mood app here
selfie mood

Application of Locke’s Goal Setting Theory in Agile Methodology

A theory I came across recently looked to adhere to some concepts of the Agile methodology. And I felt it seems to fill some kind of a black hole in the Agile methodology. The theory is called be Locke’s Goal Setting Theory.

Locke’s Goal setting theory is about setting up goals in a way, that when they are achieved they will also turn into a great motivator to the person/team who follows it accordingly.

In my working place we follow Agile methodology to develop software. I know some of the basic Agile process. So the basic concept of Agile according to my understanding is a recursive process of software development which goes under many changes and iterations to provide what the clients really wants. Also the process is transparent to the client so the client is always updated. This methodology is developed to create a better understanding between the client and the developers so that they will come up with the exact product that the client wants, including the changes through up to the final product release.

When you try to compare the 5 key factors of the Locke’s Goal Setting Theory with Agile process, you will see that some are very much similar to each other.

Will see how much are they related to each other

Setting Goals and trying to achieving them, does not always works well for everyone. Some people achieve it and some people get stressed out or stuck and instead of getting motivated they get demotivated due to many reasons. In Agile we can consider it to the user stories created by clients , which we add into sprints as tasks and try to implement them withing that sprint time.

The 5 Factors that are need to affect the motivations according to Locke’s Goal setting theory are

Clear and Specific Goals

Challenging Goals

Handling Complex Problems

Commitment

Feedback

1 – The Goal has to be clear and specific, so in Agile we meet the client and their work environment and understand it and then we gather user stories which are then explained by the client to the developing team. This ensure that the requirement we have gathered are clear and specific.

2 – The next one is Challenge, we create sprints with user stories provided by the client, which we think we can achieve within the next sprint and we define our self a deadline. Easy challenges won’t be motivating, because they won’t feel important. So we select a set of challenging stories to achieve within the sprint. Achieving them gives us(developers) a big motivation.

3 – Handling complex problems, often there is chances of estimations made by the developers go wrong. So some times developers tend to get stuck on a problem that blocks the whole process, which leads to stress and the developers get demotivated. At times like this in Agile we split the complex task in to many sub tasks to visualize the problem in a better way so that we can handle them individually and solve them.

4 – Commitment is next, it is really important when it comes to team, we have to work together to achieve the goals. Software modules normally will be developed by different developers, which will at the end works together to provide a solution. So being committed to the goals that’s assigned to you will pave way to the ultimate team goal. Commitment is also affected by various kinds of internal and external causes. But keeping the developers committed is something that has to be handled by  the management or the team lead.

5 – Feedback is an important element. As a team lead, it’s important to give feed backs on the goals achieved by the team members and in which area they can improve. Not only the Team Lead, the client must be also trained in a way so that they give positive feedback about  the developers when they are present in a meeting or a scrum. This will enable the team members to work more efficiently and happily in future. Developers often consider positive feedback as another hidden goal. So it is the responsibility of the leads not to spoil it for the developers.

Even though the companies following Agile methodology these days does motivate the employees/developers by giving the team a lunch out or a pay increase/bonus. The motivation part is not mentioned theoretically any where. So I think if we can apply the Locke’s Goal setting theory into the Agile, we can get a better performance from the developer team with Good customer satisfaction.

How to Generate a PDF in Xamarin Android

It may sound simple, but when it comes to Xamarin, all the problems starts to emerge. So basically Xamarin does not provide any special class for PDF generation.

Failed Solution 1
So we were let alone to use the Android PDFDocument class. Which Unlike in the Native Android did not work. Actually it was giving me a White and blank document. When searching for the Xamarin Documentation what I found was the Xamarin documentation having the Android Reference Code which is very disappointing (Link to Documentation)

Here is the Code snippet for it(I may have made a mistake here, let me know if you guys found a solution for using PDFDocument class )

private String sdCardPathforPDF;
private String filePath;
private FileStream stream;

sdCardPathforPDF = Environment.ExternalStorageDirectory.AbsolutePath;
filePath = Path.Combine(sdCardPathforPDF, "MyPDF/test5.pdf");
stream = new FileStream(filePath, FileMode.Create);

tView = new TextView(context);
tView.SetTextColor(Color.ParseColor(resource.GetString(Resource.Color.black)));
tView.Text = "Hello";
tView.SetHeight(50);
tView.SetWidth(50);

var document = new PdfDocument();
var pageInfo = new PdfDocument.PageInfo.Builder(612, 792, 1).Create();

var page = document.StartPage(pageInfo);
tView.Draw(page.Canvas);
document.FinishPage(page);

document.WriteTo(stream);

stream.Close();
document.Close();

Toast.MakeText(context, "PDF Generated", ToastLength.Short).Show();

Failed Solution 2
Then I searched for a plugin or a 3rd party library, ohhh my god, I found some expensive plugins

Capture

Who would love to buy a plugin for 1600 usd??? Apitron and XFINIUM are some of them

Failed Solution 3
I found some Free open source libraries for Android, so I thought of  Java Bind it, but when i tried to Java Bind them, but I ended up getting lots of errors that i cannot fix it unless I am the developer of that library. So I dropped that Idea as well.

Failed Solution 4
Then after the disappointment of JavaBind, I came across an article saying that the iText library has been published for .Net in the name of iTextSharp. But when I added that Nuget Package I came across an error saying that

System.IO.FileNotFoundException: Could not load assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?

so It says there is an assembly called System.Drawing dll is missing. I tried to manually add it but it did not work. When I researched on it, it said that Mono for Android(Xamarin Android Framework) does not include that ‘dll’ I dont know how come a popular ‘dll’ got missed out of their framework.

At last a solution that Worked
So with all of the frustration I had, I did not give up on finding a solution till i came across problem where a guy has used ‘iTextSharp’ in Xamarin Android and its working. But he did not mention or reply my question in that thread. So I thought of giving a final look at the Nuget Manager. This time just like the previous time I searched for ‘iTextSharp’ but this time I went through each and every result the list showed.
And Hoooray I found It the one I am searching for, some one has made a nuget of ‘iTextSharp’ for Xamarin, its called “Xam.iTextSharpLGPL”

XamiTextSharp

And this worked like a Magic. And this library has more functionality than the default PDFDocument.
This library is based on iTextSharp 4.1.6  which means licensed under LGPL. Free to use and it is an Open source library.
Open source project can be found in Bit Bucket : https://bitbucket.org/smarongiu/xam.itextsharplgpl

So this is the Basic code of Writing a Simple PDF Doc

System.IO.FileStream fs = new FileStream(Server.MapPath("pdf") + "\\" + "First PDF document.pdf", FileMode.Create)

// Create an instance of the document class which represents the PDF document itself.
Document document = new Document(PageSize.A4, 25, 25, 30, 30);
// Create an instance to the PDF file by creating an instance of the PDF Writer class, using the document and the filestrem in the constructor.

PdfWriter writer = PdfWriter.GetInstance(document, fs);

Before we can write to the document, we need to open it.

// Open the document to enable you to write to the document

document.Open();

// Add a simple and well known phrase to the document in a flow layout manner

document.Add(new Paragraph("Hello World!"));

// Close the document

document.Close();
// Close the writer instance

writer.Close();
// Always close open file handles explicitly
fs.Close();

I grabbed this quick code snippet from Micke Blomquist

Hope this article will help people like me in future…!
See ya…!

Whatsapp Web – Desktop App Workaround

Hi guys, its cool to see whatsapp coming to the desktop, at least as a chrome app.
But I know there are a lot of people who use browsers other than Google Chrome, and the people who actually wants a hassle free separate desktop app, rather than opening a browser and going to the specific site to view the messages.

So here I am gona explain how to create a chrome application which, kind of create a dedicated browser app for you which you can place in your browser or task bar just like another app and when you click on it, it directly opens like another desktop app.

Step 1
So to do that first you need a Google Chrome browser. If u are a Google Chrome hater, please don’t worry, it only for the first time, after that you can forget about it . Use this link to download the Google Chrome

Step 2
Open the Google Chrome and get in to the Whatsapp web app, using this link https://web.whatsapp.com/

Step 3
Open your Android Whatsapp app and on the menu select the Whats app Web.
Screenshot_2015-01-26-10-28-42
Scan the QR code in the website you visited now using the QR scanner just opened in the Whatsapp android app. And you have successfully registered and accessed the chat.

Step 4
Now in the google Chrome Menu Go to
More Tools –> Create Application Shortcut
chrome

Now you will see the option to create the short cut in Taskbar Desktop or anywhere you like

app

TA DA , now you have a dedicated Whatsapp Desktop App which you can click open with a single click.

Whatsapp Desktop App

This technique can be used with all other websites as well, like facebook, twitter and many others.

Hope this article is helpful for you free feel to share with you friends
😀

Basic Swift for iOS: Core Syntax

Hi guys, I was given a Mac Book Pro recently and thought of learning some iOS development. So as a first step thought of going through the Basics first. And as you now sharing what I learn with other is the number one way of learning…! This blog will go in a format of short notes or points.
So here you go guys…!

Most of the basics are same as most other popular languages, but still there are some changes, Ill be high lighting the serous issues.

We don’t use semi colones at the end of the statements in Swift.
Also we avoid parenthesis when declaring a condition as much as possible, if there is a complex logic its advised you use it, other than that nope.

We follow the camel case naming convention in Swift

Playground

There is a tool called Play Ground in Xcode where you can write some code and observe the results soon as you write them. Its a great tool to learn the basics and to test some complex logics

Variables

In swift you don’t have to mention the type when you are creating a variable, it automatically decides itself according to the values you pass.

var myInt = 32
var myString = "cat"

But if you want to create a variable without assigning a value you can specify it like this

var myVariable :String
var myIntVariable :Int

Constants

Constants are variables with immutable values, so once a value is defined that value cannot be changed after that

So they are declared with the word “let”

let myConstVariable = 32
let myUnChangedVal = "car"

String Interpolation
Ooops don’t get scared by the word. Its basically a way of passing values or concatenating values in between strings.

var name = "Batzee"
var level = 11

just say you got 2 String values which u have to add in between a standard println() statement

println("\(name) is a Level \(level)" Agent in Ingress")

So the out put will be

"Batzee is a Level 11 Agent in Ingress"

So here instead of using ‘+’ operator we are using ‘\()’ operator

Functions

Functions in Swift are created with the key word ‘func’

func eatBurger(){
}

and called using the function name with the paranthesis

eatBurger()

If the function has a return type then the function is written as

func eatBurger() -> Int{
var burgerNo = 3
return burgerNo
}

‘->’ followed by the return type must follow the function before the curly braces starts.

if Statements

if statement is same as you have written an ‘if’ statement anywhere else, but there are certain things you have to consider when writing in Swift.
As always the Swift says it’s best practice if you can avoid the parenthesis around the condition
And on statements that has one line of executable line of code on success also must have it self surrounded by the curly braces unlike other languages, where you can avoid using the curly braces around the single line code.

if  x<500  {
return x
}

Loops

So there are 4 kinds of loops in Swift

The 1st one is the traditional for loop there is not much difference, only thing you have to consider is to remove the parenthesis around the condition

for  var x = 0; x<10 ; x++  {

}

The 2nd one is the for in loop this is something like foreach loop you specify a collection to loop through. Whatever you pass it converts it in to a collection. If you give a range, it loops through the range. If you pass an Array, it loops through the array element, and if you pass a string it converts the String in to character array and loops through the character array elements

Example 1

var total = 0

for x in 1...100{
total = total+x
println()
}

So the x will loop from 1 to 100

Example 2

var name  = "cat"

for y in name{
println(y)
}

here the variable name will be taken as a string array and the out put will be

c
a
t

The 3rd one is the While loop, it is same as any other while loops in other languages, only considerable change is, not necessarily to add the parenthesis around the condition

while condition {
// do if the condition is true
}

The 4th one is the Do While loop, in this there is some noticeable change, the condition is added at the end of the body, this is to run the code inside the body at least once before it checks on the condition

do{
//runs for the 1st time and runs for the second time and after, if the condition is satisfied
}while condition

Range

Range operator is something new in Swift

which is defined by ‘…’ this says to consider the number mentioned in the left of the operator and all the numbers in between it and the number mentioned in the right of the operator.
Also in the Range operator you can control the 1st and the last dot, like ‘..<‘ , ‘>..’ so this basically will work like a for loop

for  x in 1...100 {
println(x)
}

this will print 1 to 100

similarly

for y in 1..<100{
println(y)
}

will print 1 to 99

Switch Cases

So the Switch Statement in Swift has some points to consider .

The case range must be Exhaustive, unlike other languages you cant check only for a handful of conditions but for all the possible values.
for example if you are checking for integer cases, integer is never ending so u have to handle it. In that case you will use the default case to catch all the situations that you don’t want than what u actually wanted.

let chocoCount = 7
Switch chocoCount{

case 0:
//in case 0 do this
case 1:
// in case 1 do this
case 12:
//in case 12 do this
default:
// do this if the cases dont match the given cases

}

Also in Swift’s Switch statements they don’t have the ‘fall through’ option, which automatically falls into another case for a range of cases. In that case we can use the range case, We have already seen what is a range operator does above.
This is how it is done.

switch chocCount{

case 1...7:
//if the case is between 1 and 7 do this
case 8...15:
// if the case is between 8 and 15 do this
default:
break

}

This post is written after learning from a video, so there are some chances that I may have made some mistakes, so please feel free to comment them down, Ill me more happy to correct them. And stay tuned in for more blogs on Swift and iOS development.

Reference: Notes are taken by studying the Swift Essentials from Lynda.com