Sunday, April 5, 2015

MVC - MVP : Difference between these design patterns?



In traditional UI development - developer used to create a View using window or usercontrol or page and then write all logical code (Event handling, initialization and data model, etc.) in code behind and hence they were basically making code as a part of view definition class itself. This approach increased the size of my view class and created a very strong dependency between my UI and data binding logic and business operations. In this situation, no two developers can work simultaneously on the same view and also one developer's changes might break the other code. So everything is in one place is always a bad idea for maintainability, extendibility and testability prospective. So if you look at the big picture, you can feel that all these problems exist because there is a very tight coupling between the following items.
  1. View (UI)
  1. Model (Data displayed in UI)
  1. Glue code (Event handling, binding, business logic)
MVVM: Model–View-ViewModel talks of creating a new model (in addition to your domain model). This model normally adds additonal properties from the prespective of View (as we understand that View has controls in addition to data which it’s displaying). For instance if View had a property IsChecked and Presenter was setting in classic MVP, in MVVM Presenter will have that IsChecked Property which View will sync up with (doesn’t it look like Strategy pattern has been replaced with Observer?). So now a Presenter becomes more like a combo of – View Properties & Model properties which would be synchronized with View. So why not rename Presenter to ViewModel? Do that and you get MVVM. MVVM is attractive for platforms which support bi-directional binding with less effort. Also a minor tradeoff is ViewModel unlike Presenter can stand on its own (Presenter normally requires a View’s interface)
Definition of Glue code is different in each pattern. Although view and model is used with the same definition in all patterns.
In case of MVC it is controller. In case of MVP it is presenter. In case of MVVM it is view model.


MVC: Three components – View (your UI), Model (your business entities / data – that view is displaying) & Controller (contains the logic that alters the model depending on the action triggered by UI, typically implementing a Use Case). It’s widely known that MVC is a compound pattern (View and Controller have Strategy implementation, View itself can be a Composite implementation & View and Model are synched through Observer). In this case Controller doesn’t know anything about View, and the idea is that a View can switch Controllers (for instance depending upon who has logged to the system) & a single controller can be used by multiple Views. View subscribes to the changes done to the model & hence both are sync from the data perspective. One of the disadvantages of MVC is that it’s difficult to unit test. Controller manipulates the data but how about asserting those changes from a view perspective. For instance on click of a button you raise an event to controller, and controller modifies the value in model. This value modification changes the font size / color in View. Unit testing this scenario is slightly difficult in MVC.






MVP: Again three components. But dependencies change (look at arrows in the diagram). Over here we replace Controller with Presenter (one which presents the changes done in model back to view). The main difference between both is that Presenter refers back to the view while Controller doesn’t. Normal pattern found here is to create an abstraction of the View (in terms of properties / events) & Presenter refers to it. This makes the mocking of View much easier & hence the Unit Testing aspect. Presenter here hence takes the responsibility of not only manipulating model but also updating the view. Of course the implementations of MVP differ in real world in terms of how much thin the view is, some prefer keeping basic logic still inside view & taking complex logic in presenter, while others prefer keeping the entire logic in Presenter. 




Saturday, April 4, 2015

Places to visit without visa (Indian passport)


1. Bahrain – eVisa
2. Bhutan – No Visa
3. Bolivia – Visa on Arrival
4. Cambodia – Visa on Arrival
5. Cape Verde - Visa on Arrival
6. Comoros -Visa on Arrival
7. Dominica – No Visa
8. Eucador - No Visa
9. El Salvador - No Visa
10. Ethiopia - Visa on Arrival
11. Fiji - No Visa
12. Gabon – eVisa
13. Georgia – eVisa
14. Grenada – No Visa
15. Guinea-Bissau – Visa on Arrival
16. Guyana – Visa on Arrival
17. Haiti – No Visa
18. Indonesia – Visa on Arrival
19. Jamaica – No Visa
20. Jordan – Visa on Arrival
21. Kenya – eVisa
22. Laos – Visa on Arrival
23. Madagascar – Visa on Arrival
24. Maldives – Visa on Arrival
25. Mauritania – Visa on Arrival
26. Mauritius – No Visa
27. Micronesia – No Visa
28. Moldova – eVisa
29. Myanmar – eVisa
30. Nepal – No Visa
31. Palau – Visa on Arrival
32. Rwanda – eVisa
33. Saint Kitts and Nevis – No Visa
34. Saint Lucia – Visa on Arrival
35. Saint Vincent and the Grenadines – No Visa
36. Samoa – Permit on Arrival
37. São Tomé and Príncipe – eVisa
38. Senegal – Visa on Arrival
39. Seychelles – Visa on Arrival
40. Somalia – Visa on Arrival
41. Sri Lanka – No Visa but special permit required
42. Tanzania - Visa on Arrival
43. Thailand - Visa on Arrival
44. Togo - Visa on Arrival
45. Timor-Leste – Visa on Arrival
46. Trinidad and Tobago – No Visa
47. Tuvalu – Visa on Arrival
48. Uganda – Visa on Arrival
49. Vanuatu – No Visa
50. Zambia – eVisa
51. Zimbabwe – eVisa
52. Djibouti - Visa on Arrival
53. Hong Kong – No Visa
54. Antartica -Visa on Arrival
55. South Korea – No Visa
56. FYRO Macedonia - No Visa
57. Svalbard - No Visa
58. Montserrat - No Visa
59. Turks & Caicos Islands - No Visa
60. Cote d’Ivoire – eVisa











Tuesday, April 23, 2013

The All New BlackBerry - BlackBerry 10

BlackBerry Z10



BlackBerry Z10 Keep Moving Commercial - 60sec




Z10 reviews





Features


BlackBerry 10 - BlackBerry Browser 

http://www.youtube.com/watch?v=s60U1IdLmPM&list=PLSV1iA-lr7ykoKsJ3popveqDJkgtCoaB1&index=8






















Thursday, July 12, 2012

How to start an activity just after booting of a mobile device

This post is an example of how an application will work just after the booting of the device.Here the example shows an authentication app which will work as a lock to the device.

1) Define in the AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.boot"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="8" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
  <receiver android:enabled="true" android:name=".BootActivity"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
  </receiver>
  <activity android:name=".AutoStartActivity">
    </activity>
    </application>
    </manifest>


2) Create BootActivity.java in src with the following code
Here AutoStartActivity is the activity we have to run after booting


package com.boot;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class BootActivity extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent i = new Intent(context, AutoStartActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
}
}

3)The XML (main.xml) for the activity is


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" android:gravity="center">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" android:gravity="center_horizontal">

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/button1"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="Login" />

    </LinearLayout>

</LinearLayout>




4) Create the activity AutoStartActivity

package com.boot;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AutoStartActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText ed=(EditText)findViewById(R.id.editText1);
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
if(ed.getText().toString().equals("abc123"))
{
AutoStartActivity.this.finish();
}
else
{
Toast.makeText(AutoStartActivity.this, "Failed", Toast.LENGTH_SHORT).show();
}
}
});
}

@Override
public void onAttachedToWindow() {
   this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
   super.onAttachedToWindow();
}
}


  • Run it in a new avd


Using Google Maps in Android

To use google map in our application follow the steps below:

  • Getting the MD5 Fingerprint of the SDK Debug Certificate    
          For getting the MD5 certificate open your command prompt 
                  * change the path to the jdk's bin ie. the command will be like  [ cd C:\your path\bin ]
                  * now type the command 
                       keytool -list -alias androiddebugkey -keystore "your debug key store path" -storepass android 
                        -keypass android
                  * 'your debug key store path' can be obtained from Eclipse-window>preferences>android>build.
  • Registering the Certificate Fingerprint with the Google Maps Service 
          For getting the API key using MD5 key go to http://code.google.com/android/maps-api-signup.html
and type your MD5 key there, accept the agreement and click the "Generate API Key" button.
  • Add the Maps API Key to your Application
         <com.google.android.maps.MapView android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:enabled="true"
                android:clickable="true"
                android:apiKey="example_Maps_ApiKey_String"/>


**  How to get MD5 fingerprint when you get  SHA1 from your command prompt???


    • While generating MD5 fingerprint for jdk version 1.7, it generates the fingerprint with SHA1  by default.But  the Google Maps doesn't recognize it.So you have to give the below command in the command prompt to get MD5 and SHA1 fingerprint.                                                               
    keytool -list -v -alias androiddebugkey -keystore "your debug key store path" -storepass android -keypass android

    Monday, May 14, 2012

    BB10 the future of mobile world

    Blackberry 10

    Blackberry 10 is an upcoming proprietary mobile operating system, developed by Research In Motion for its BlackBerry line of smartphone and tablet handheld devices. It is based on QNX which was acquired by RIM in April 2010. The platform was originally called BBX but this was changed when RIM was blocked from using the BBX trademark after legal action from BASIS International, who already use it for their software.
    BB10 is the super phone that RIM is gonna release in the coming fall 2012.BB10 is the next generation phone in-short super phone that is going to get released for those people who believe in success and want to get things get done perfectly. RIM is having a super hero team to give us a powerful mobile tool.

    Why Blackberry 10?
    QNX (Best Real time OS) + QT (Best C++ opensource Application development framework) + Cascades (Best UI Framework) + BB Native app integration + High data efficiency (patented compression mechanism) + High battery efficiency ( push technologies and acquisition of Paratek ) + High security  + High Social connectivity (FB, Twitter,BBM,  Social calendaring , Social gaming etc) +  cloud storage (Newbay acqusition).





    My PhoneGap Experience

    PhoneGap (was called by the name Apache Callback, but now Apache Cordova) is an open-source mobile development framework produced by Nitobi, purchased by Adobe Systems. It enables software programmers to build applications for mobile devices using JavaScriptHTML5 and CSS3, instead of lower-level languages such as Objective-C.The resulting applications are hybrid, meaning that they are neither truly native (all layout rendering is done via the webview instead of the platform's native UI framework) nor purely web based (they are not just web apps but packed for appstore distribution, and have access to part of the device application programming interface).
    The mobile framework allows web developers to natively target all smartphones with a single codebase (JavaScriptHTML and CSS) by enabling a Foreign Function Interface (FFI) to an embedded WebView or Webkit on the device.



    PhoneGap currently supports development for the operating systems Apple iOS, Google Android, HP webOS, Microsoft Windows Phone, Nokia Symbian OS and RIMBlackBerry. Support for recent versions, such as BlackBerry 5 and 6 and Windows Phone 7, is being implemented now. Bada (the operating system used by the SamsungWave S8500) support is "coming soon". The table below is a list of supported features for each operating system.

    FeatureiPhone /iPhone 3GiPhone 3GS and newerAndroid robot.svg
    Android 1.0 – 4.0
    Windows Phone 7Blackberry Logo.svg
    5.x–6.0+
    Blackberry Logo.svg
    4.6–4.7
    Bada operating system.png
    Bada
    SymbianHP D B RGB 72 MX+space.png
    webOS
    Tizen logo
    Tizen
    AccelerometerYesYesYesYesYesN/AYesYesYesN/A
    CameraYesYesYesYesYesN/AYesYesYesN/A
    CompassN/AYesYesYesN/AN/AYesN/AN/AN/A
    ContactsYesYesYesYesYesN/AYesYesN/AN/A
    FileYesYesYesYesYesN/AN/AN/AN/AN/A
    GeolocationYesYesYesYesYesYesYesYesYesN/A
    MediaYesYesYesYesN/AN/AN/AN/AN/AN/A
    NetworkYesYesYesYesYesYesYesYesYesN/A
    Notification (alert)YesYesYesYesYesYesYesYesYesN/A
    Notification (sound)YesYesYesYesYesYesYesYesYesN/A
    Notification (vibration)YesYesYesYesYesYesYesYesYesN/A
    StorageYesYesYesYesYesN/AN/AYesYesN/A
    Barcode scannerYesYesYesN/AYesYesN/AN/AN/AN/A

    • I have published my PhoneGap project in Google Play.Its a yoga guide called, Abacus Yoga Guide

    MVC - MVP : Difference between these design patterns?

    In traditional UI development - developer used to create a  View  using window or usercontrol or page and then write all logical code ...