Monday, 28 October 2013

How to add JAR library to the Android project in Android Studio?

Some times trivial things like adding a lib references becomes a big pain! Adding jar lib to an Android project in Android Studio on Mac was very problematic for me and of course, many other guys!
After checking different web sites and reading through a bunch of questions in stackoverflow, I managed to get it working.
The steps are:
Create a lib folder in your project folder (the inner one) and copy your jar file there.
Edit the build.gradle file (the inner one) and add: compile files ('lib/ks2.jar')
Close the project and open a terminal and go to the folder of your project. There you'll find a file named gradlew, change that to be executable (chmod +x gradlew), then execute it: ./gradlew clean
It would take a while to finish and you should see a 'BUILD SUCCESSFUL' message upon completion. Once done, open the project, and you're done!

Thursday, 10 October 2013

LaTeX: Make Bibliography appear in "Table of Contents"

Normally in report/book classes of documents, Bibliography will not appear in "Table of Contents", there are many workarounds for that; the easiest would be using the "tocbibind" package in preamble...

Saturday, 5 October 2013

Restart Ubuntu Desktop

Linux core is very stable, but that does not necessarily means that Ubuntu desktop is stable as well!
Many times Unity (Ubuntu's shell interface for GNOME) becomes totally unresponsive (at least for me!), since the core is stable and it is running, you can easily restart the desktop (without even having your running programs closed). If the desktop is totally unresponsive, then press Alt+Ctrl+F1 (to F6) to bring the console window. There you can run unity by (remember to detach the process by adding & disown, also redirect the output and error &> /dev/null. After it, simply hit Alr+Ctrl+F7 (or F8) to come back to the graphical desktop.
An alternative way is to restart compiz (since unity is a plugin of it): compiz --replace and if you're running from Alt+Ctrl+F1 terminal, then specify the display: compiz --display :0 --replace. You still need to add & disown.

Monday, 13 May 2013

Simple Events in Python

Having C# background and moving newly to Python, I was trying to find the easiest way to have some kind events in my Python classes and found this post very simple and useful.

All you need is to add this 'EventHook' class to your code and add events and event handlers to your code, exactly the same way as you did for your C# code.

Saturday, 9 February 2013

Focus method equivalent

In Windows Forms Application, when you wanted to set the focus to a specific control (e.g. a TextBox), you just needed to call its .Focus() method. The Objective C way of doing it on MonoMac and Xamarin.Mac world is to call:

Friday, 25 January 2013

Storing and Retrieving Setting Values

Some times it is required to store few setting of the application. The .NET programming world in Windows, setting can be used for this purpose. In Objective C, NSUserDefaults is used for this purpose. It is very simple and straight forward.
To store a setting value:

And to retrieve stored setting:
Please also note that in case of retrieving a value which is not stored, ValueForKey returns Null (nil in Objective C) and thus, calling .ToString() method, causes an exception.

Thursday, 24 January 2013

Auto close application after main form closes

Your Xamarin.Mac Cocoa application would not terminate after you close the main form. Automatically terminating application when the last form is closed is some thing that C# developers in Windows used to it. In Cocoa application, in order to have the same functionality, you need to override a method in AppDelegate.cs:

Get Mac Computer's Unique Id in Xamarin.Mac

I've been developing and publishing many betting tools for a while and for all of those applications, we had some kind of activation process in which a unique identifier for each computer is generated and based on that we authorize the computer and so forth. For Windows, I used a combination of MAC address with CPU serial number to generate this machine specific unique identifier. For Mac computers, I searched the internet for unique identifier and found many commands which return a supposedly unique identifier, here is a link of one of them.

As I said in my previous post, there is not that much code samples for MonoMac and Xamarin.Mac, but for Objective C, there are good samples. And that's why for a Xamarin.Mac developer it is really required to be familiar with Objective C.

In this post, I'm providing the code translation of the function which was originally written in Objective C (which is taken from the StackOverflow) to get the unique identifier of a Mac computer:

Hello Mac!

Being totally new to the development world of Mac, with my .NET and Windows programming background, I've experienced and actually experiencing many new things in this new world. I've decided to share my experience here on my blog.

Having .NET and C# background, I really preferred to use Mono and MonoMac. Eventually when I see the style of programming, I was totally disappointed. I was mostly thinking that because I'm not using the very original tools (mean the Objective C and XCode), that's why every thing seems to be this hard. I should also mention that when I'm talking Mono, I'm not really meaning to use WinForms on Mac. They really really look very odd and actually no Mac user prefers that style. So the option is MonoMac. Anyway, so I was convinced that I really need to learn Objective C in depth. So I started with few books and videos. Learner Objective C in depth (not really ;) ) and the Foundation framework and Cocoa and so forth. After around a week or a more, I was thinking that how easy was MonoMac! But I tried to continue with Objective C. I was thinking that Mac world is totally different form Windows world and I should not think the way I thought in Windows and etc. I talked with many Mac developers and .NET developers about my experience with Objective C. Mac developers mostly said that this is a completely new world, however, the amount of work to create simple things in XCode and Objective C was not really acceptable for me. With C# .NET and Visual Studio I was very very fast. XCode and Objective C remembered me MFC applications! You really need to take care of every details and write too much frustrating codes and so forth.

Objective C really looks like an out dated programming language. However, in its version 2.0 many new features have been added, but still too far from an elegant and modern language such as C#. As a result, I retried to use MonoMac as well as Xamarin.Mac. I go ahead and purchased a professional license of Xamarin.Mac and I'm actually experiencing new things with it. There are few issues with Xamarin.Mac. The developers are not that much and thus, you can not find many sample codes for it on internet. Furthermore, you hardly find answers to your questions. However, issues are them same for Objective C developers. Thus, you can find solutions to your problems in Objective C and by knowing a little bit of its weird syntax, you can easily convert that code in to C#.

Anyway, this was a brief history of my experience in Mac development world and I'll be posting new things here.