Create Simple Accordion with ionic and angular

Banyak trik bisa kita lakukan untuk membuat tampilan accordion, di jquery kita bisa tinggal pakai saja function yang ada. Nah kali ini saya mau share sedikit tentang ionic dan angular. Tapi kali ini saya melakukannya dengan ionic 1, karena memang sedang ada project dengan menggunakan framework ini meski pada beberapa post sebelumnya saya sempat ngeshare tentang ionic2, tenang, yang ionic 2 saya juga terus pakai kok, nanti akan saya share.

How to get start with Ionic 2

Choosing best mobile apps technology : native vs hybrid

About ionic creator

Ionic vs OnsenUI : UI Framework for Hybrid Mobile Apps 

How to install phonegap for android apps development

Kali ini, saya membuat tampilan accordion simple saja, saya tidak banyak cuma butuh 2, jadi untuk animasinya saya cukup pakai css. Saya menggunakan ng-show ini dari angular. Oke, langsung aja kita liat code nya

Sederhana, untuk header accordionnya saya cuma pakai list divider dari component ionic, tinggal saya modif sedikit seperti ini:

the html

<ion-item class=”item-icon-right item-divider”
ng-click=”toggleGroup(‘A’)”
ng-class=”{active: isGroupShown(‘A’)}”>
<i class=”icon” ng-class=”isGroupShown(‘A’) ? ‘ion-chevron-up icon-accessory’ : ‘ion-chevron-down icon-accessory'”></i>
List Group A
</ion-item>

<ion-list>

<!– ************************* LIST GROUP A *******************************************–>
<ion-item class=”item-remove-animate item-icon-right item-accordion” ng-repeat=”list in listdata” type=”item-text-wrap” ng-show=”isGroupShown(‘A’)” href=”#/detail”>
<h2>Barang {{list .name}}</h2>
<p>{{list .message}}</p>
<i class=”icon ion-chevron-right icon-accessory”></i>
</ion-item>
</ion-list>

 

itu untuk satu group, kalo mau nambah lagi tinggal tambahin code yang sama, cuma tinggal ganti nama grupnya aja itu misal jadi isGroupShown(‘B’). So its very simple, kalo mau yang lebih kompleks, bisa ja sih, but this is easier, hhaaaaaaa..

note : ini datanya saya ngambil dari service sederhana saja, cuma array :

.service(‘listdata’, function() {
return {
lists: [
{id: “1”,name : “A”,message: “Detail Informasi A”},
{id: “2”, name : “B”,message: “Detail Informasi B”},
{id: “3”, name : “C”,message: “Detail Informasi C”},
{id: “4”, name : “D”,message: “Detail Informasi D”},
{id: “5”, name : “E”,message: “Detail Informasi E”},
{id: “6”, name : “F”,message: “Detail Informasi F”}

],
getLists: function() {
return this.lists;
},
getList: function(listId) {
for(i=0;i<this.lists.length;i++) {
if(this.lists[i].id == listId) {
return this.lists[i];
}
}
}
}

 

okey, then the css; ini penting yah buat transisi pas itemnya dibuka dan ditutup, biar lebih halus, coba liat sendiri perbedannya yah, hapus aja line yang pertama dan bandingkan hasilnya..

.list .item.item-accordion {transition: 0.09s all linear;}
.list .item.item-accordion.ng-hide {line-height: 0px;}
.list .item.item-accordion.ng-hide-add,
.list .item.item-accordion.ng-hide-remove {display: block !important;}

 

and then the .js file tinggal taruh didalam controller nya saja:

$scope.shownGroup=null; //default nutup semua

$scope.isGroupShown = function(group) {
return $scope.shownGroup === group;
};
$scope.toggleGroup = function(group) {
if ($scope.isGroupShown(group)) {
$scope.shownGroup = null;
} else {
$scope.shownGroup = group;
}
};

 

Enjoyyy, atau kalian bisa mampir kesini -> https://codepen.io/ionic/pen/uJkCz

Advertisements

Onsen UI vs Ionic Framework for Hybrid Mobile Apps

Hello Guys, hmm.. Yesterday, one of my friend ask me how to work with mobile apps, how to start ? A very good designer with a very good design product. He also a game developer, and build game using HTML5 and javaScript. He want to build a mobile application to discover some nice place to hang out. Need to display maps, and he want to work with AngularJS.

So, i think he sould try to build a hybrid apps. Why hybrid? Cz formerly he work with html5+css+angular and hybrid apps alows you to work with it, cz its build in a webView. So it is easier to adapt, instead of build a native apps.

But, what is hybrid mobile apps? Okay, i find a nice quote to help you understand :

Hybrid mobile apps are like any other apps you’ll find on your phone. They install on your device. You can find them in app stores.

Like the websites on the internet, hybrid mobile apps are built with a combination of web technologies like HTML, CSS, and JavaScript. The key difference is that hybrid apps are hosted inside a native application that utilizes a mobile platform’s WebView. (You can think of the WebView as a chromeless browser window that’s typically configured to run fullscreen.) This enables them to access device capabilities such as the accelerometer, camera, contacts, and more.

In easy way, its a webview application (just like you see in other web browser like chrome), it is viewed in full screen, and the url is  hidden, and it is installed on your mobile phone 😀 Get it?

Ah, and why you should try with hyrbid apps? You can take a look and read this nice article : http://developer.telerik.com/featured/what-is-a-hybrid-mobile-app/

Oh ya, and hybrid apps is cross-paltform. So you can build on android, iOS, Blackberry ect. For me, i’ve try to build it on android and iOS. Still, to build iOS app, you need MAC with its XCode to compile your apps on your phone 😀

And, how to build it ? You can start form installing phonegap to try. Apache cordova  is a platform that provides a consistent set of JavaScript APIs to access device capabilities through plug-ins, which are built with native code. I already wrote an article about it and you can find it here https://mylovelycode.wordpress.com/2015/05/06/cara-menginstall-phonegap-untuk-android-apps-development/

But, in this article, actually i want to talk about the framework. A sets of UI components that can help you to build hybrid mobile apps. I read some article and found 2 framework that most popular. And then i found some issue form the developers who confuse :  to decide which is better? Which one i should use for my applications?

For me, i’ve try both of them : Onsen and Ionic. I’ve download onsen and try to make a little project to try it. Oh, and it is so lightweight when i install it on my phone, smooth animation and easy to use it. As for ionic, i just try to install demo version on my phone, it also lighweight. But, i prefer onsen still, cz i think it has nice ui sets, hehe. And i think its easier for my friend since he knows a lot about JavaScipt, AngularJS, so, he can adapt from web apps to mobile apps 😀

Ahh, and i found this good answer, so i quote it

One year has passed since both frameworks are available on the market. Onsen UI is currently in stable 1.2 version while Ionic is in the last release candidate state.
I have worked with both of them so let me give you a short overview, I also wrote a much larger blog article, you’ll find it at the end of this answer.
I won’t go into much details about the core framework; if you have a previous AngularJS knowledge you will easily transition to Ionic or Onsen UI.

  • Both frameworks are built around AngularJS and they heavily depend on directives, you can also easily build your own custom directives. Onsen UI also features a jQuery support (unnecessary if you ask me).
  • Both frameworks support Android 4+, iOS 6+ (some features are available on Android 2.3), Onsen UI also officially supports Firefox OS and desktop browsers. Ionic don’t have an official desktop support, but it will still work (it will not be pretty, imagine ).
  • Ionic currently don’t support Windows Mobile platform (it will have it in the future), Onsen UI support is currently in development (since November 2014).
  • Both frameworks support some kind of splitview feature so they can be used for table development.
  • Both frameworks have a distinctive nice looking flat UI. I prefer Ionic over Onsen UI look and feel, but this is a matter of personal taste. Both default themes look iOS 7 like.
  • Onsen UI supports native looking themes for Android and iOS. Ionic framework uses the same theme for all platforms, but some features will depend on the platform (for example tab look and feel)
  • Both frameworks have a working theme builder.
  • Ionic supports SASS while Onsen UI is built around Topcoat CSS library.
  • Both frameworks have a large widget support (directives)
  • Onsen UI has a better documentation. It is separated at two different locations. First one is “Components” where you can see different directives and each one has a working example you can use and replicate. Second part is a “Guide” where you are guided through the application creation process.
  • Ionic has a disorganized documentation (heavily fragmented). It lacks a real “getting started” tutorial, even if you have previous AngularJS experience. It shows you pieces, but not how to connect them correctly.
  • On the other hand Ionic has much larger community so you will easily find problem solutions.
  • Ionic framework has a great official forum + large StackOverflow community. At the same time, Onsen UI uses only StackOverflow as a help center (I would call this a fail).
  • Onsen UI has an HTML5 IDE called MONACA IDE (great tool), Ionic IDE is currently in production, you can participate in beta test.
  • Ionic has a growing 3rd party plugin community (for example date picker), I couldn’t find any 3rd party Onsen UI plugin

I wrote a much larger article covering Ionic / Onsen UI changes, find ithere.

 

And finally, which one you decide to use?

Ahh, and for question form my friend : how do i start ? And my answer is :

  1. Try to install phonegap untill you can successfully install .apk.
  2. For android, since this is hybrid apps, i prefer use genymotion as emulator.
  3. Not only on the emulator, but try to install it directly on your phone.
  4. Try to download and isntall the framework ( Have you decide it? hha )
  5. Is it can work with angular? Oh yeah of coure yes. Onsen and ionic both built in angular, so, absolutey yes! Just do it like you do on web apps.
  6. Try to viewing maps on your apps
  7. Server side? Lets read about webservice API. It use http response, and for client side you can request data with ajax.
  8. Oh, last but not least. Instead of build on emulator/hp each time you make a change and want to see it works, you bettertry to emulate in chrome 😀 Chrome have a very good device emulator. Right click -> Inspect Elemet -> On the left the is icon seacrh, and then icon “mobile phone” just click it and you will see, also you can choose many model device on it.

Taraaaaa…. Next, build your own applications 😀

Keuntungannya pakai framework ya lebih mudah, lebih cepet kan tinggal pakai UI sets yang disediakan, dan yang peling penting animasi2 seperti pull down, slide, transition itu udah ada, jadi ga perluu repot2 bikin animasi *kalo aku dulu repot karna cuma pakai jquery dan dibantu dengan css3 untuk bikin animasi2, itu pun patah2, nggak smooth jadinya setelah diinstall di hape :(*

Some nice site/article for you :

https://onsen.io/

http://www.gajotres.net/best-html5-mobile-app-frameworks-onsen-ui/

http://stackoverflow.com/questions/23715679/onsen-ui-angular-js-google-maps

http://onsen.io/blog/onsen-ui-tutorial-angularjs-essentials-for-using-onsen-ui-part-1/

http://ionicframework.com/

http://phonegap.com/2012/03/19/phonegap-cordova-and-what%E2%80%99s-in-a-name/

http://www.drdobbs.com/web-development/restful-web-services-a-tutorial/240169069

http://rest.elkstein.org/

 

Cara Menginstall Phonegap untuk Android Apps Development

Screens are small, apps are big, and life as we know it is on its head again. In a world that’s increasingly social and open, mobile apps play a vital role, and have changed the focus from what’s on the Web, to the apps on our mobile device. Mobile apps are no longer an option, they’re an imperative. You need a mobile app, but where do you start?

Sebenarnya build hybrid apps itu gampang aja kok, yg penting adalah bisa sampai running appsnya, jadi prepare apa apa saja yang kita butuhkan. Like node.js, ants, phonegap dll.

Ini singkat saja ya, hehe, untuk instalasi phonegap sampai bisa run di android Emulator.

  1. Yang pertama dan utama, wajib punya android sdk.  Kalau belum punya, bisa download di http://developer.android.com/sdk/index.html –
  2. Java SDK latest version
  3. Install node.js, ini disini -> http://nodejs.org/download/
  4. Install phonegap, liat docsnya phonegap nih -> http://phonegap.com/install/
    1. Setelah berhasil install nodejs, lalu buka nodejs command prompt.. emm, ini command promt nya node js ya, jadi ntar setelah install nodejs, trs search aja command prompt dari start menu, pilih yg nodejs command prompt.
    2.  Kemudian Jalankan : npm install -g phonegap , ntar dia ngedownload, tunggu aja sampe selesai.
    3. Create apps? Liat lebih lengkapnya di CLI interface ini : http://docs.phonegap.com/en/edge/guide_cli_index.md.html#The%20Command-Line%20Interface
    4. Contoh create project, misal saya buat di drive D, masuk ke dir D, so

      C:\Users\Feni\ D:
      D:\ phonegap create hello com.example.hello HelloWorld
      Cek d drive D, akan ada folder hello 😀

      Oke, sampai sini udah berhasil install phonegap dan create project helloworld di drive D. Yang selanjutnya caranya biar bisa run d emulator kitah 😀

  5. Oiya, download juga  http://ant.apache.org/, extract aja di C:\.
    Dan ini dia link downloadnya => http://www.mediafire.com/download/0v4cmor7s2188m2/apache-ant-1.9.3-bin.zip
  6. Kalo udah add path nya di ->
    Buka explorer, klik kanan My computer -> Properties -> Advanced System Settings -> Pilih Tab Advaced -> Klik Environtment variables.
    1. Saya menambahkan 3 path untuk Android SDK, ants,sama java sdk tadi 😀
    2. Caranya, klik new aja, terus isikan variable name dan value nya:

    Misal kaya punya saya ini :

    ANDROID_HOME itu path ke sdknya, misal punya saya ,
    [variable name -> value], seperti dibawah ini:
    D:\Masandro Dev\adt-bundle-windows-x86-20130917\sdk
    JAVA_HOME -> C:\Program Files (x86)\Java\jdk1.6.0_22
    ANT_HOME -> C:\apache-ant-1.9.3

    And finally, EDIT variable PATH, valuenya menjadi :

    C:\Users\Feni\AppData\Roaming\npm;%JAVA_HOME%\bin;%ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

    Perhatikan ada tambahan2 dibelakangnya, /bin dan untuk ANDROID_HOME di tambah dua kali, untuk tools sama platform-tools 😀

    Kalo udah, saatnya mencoba menjalankan di emulator kita.  Kalo download yg bundle dari developer.android.com ada AVD nya, bisa add player dan play emulator seperti biasa dari situ.

    Tapi kalo saya lebih suka pake emulator dari Genymotion, lebih ringan dan lebih cepat soalnya 😀 Caranya tinggal mampir aja ke genymotion.com – register, kemudian download genymotion, kalo temen2 pake windows, pilih yg sekalian bundlded sama VirtualBoxnya.

    Install, kemudian login. Lalu klik +Add, nanti akan muncul list device yg disediakan oleh genymotion, pilih kemudiandownload emulator sesuai yang temen2 inginkan, banyak kok pilihannya. 🙂  Ini screenshot punya saya 😀

    Kalo udah, pilih emulator yg mau dijalankan , lalu Play , terus buka command prompt.
    Masuk ke dir project yang kita buat tadi, kalo saya berarti :

    D:\hello>

    Lalu jalankan perintah :

    D:\hello> phonegap platform add android

    D:\hello> phonegap run android

    tunggu beberapa saat, nanti dia akan nginstall ke emulator kita, ingat, emulatornya harus udah jalan dulu ya ^_^

    sampe sini sih harusnya udah bisa, muncul splash screen helloworld gitu. Oke, kurang lebih seperti ini:


    Selamat Mencoba ^_^

  7. Oya, buat yg mau develop, disini saya pake jquery, tp agak berat ya kalo buat mobile apps.
    Saran saya , bisa coba pake AngularJS atau Backbonejs + Topcoat.css , oh yaa.. ada OnsenUI itu juga keren banget, ringan, great UX,  HTML5 UI Framework, Onsen work with jquery and angularJS, nah , keren kan. Saya udah nyoba, dan emang simple n easy to use, nice design, multiscreen support.Great.

    Oiya satu lagi, ada ionic framework , masih beta sih, but i keep my eyes on it. Ini juga bakal keren nih 😀