tips dan third party library untuk android - part 1

26
Tips & Third Party Library for Android OLEH IBNU SINA WARDY

Upload: ibnu-sina-wardy

Post on 12-Jun-2015

630 views

Category:

Technology


1 download

DESCRIPTION

Actionbar, NavigationDrawer / SlidingMenu, JSON Parsing, Dimensi untuk Tablet

TRANSCRIPT

Page 1: Tips dan Third Party Library untuk Android - Part 1

Tips & Third Party Library for AndroidOLEH IBNU SINA WARDY

Page 2: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 2

Overview Action Bar

Sliding Menu

JSON Parsing

Tablet Dimension

Page 3: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 3

Action Bar

Page 4: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 4

Action Bar

ICS Froyo

Page 5: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 5

Action Bar

ICS Froyo

getActionBar().setDisplayHomeAsUpEnabled(true);

FORCE CLOSE

Page 6: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 6

Action Bar

ICS Froyo

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Library agar ActionBar tetap ada untuk device di bawah Honeycomb:

ActionBarSherlock http://actionbarsherlock.com

Page 7: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 7

Cara Pakai ActionBarSherlock

Import Project di Eclipse dan tambahkan sebagai library untuk aplikasi

Gunakan extend milik library◦ Activity SherlockActivity◦ Fragment SherlockFragment◦ FragmentActivity SherlockFragmentActivity◦ ListAcitivity SherlockListAcitivity

Untuk mengakses Action Bar, gunakan getSupportActionBar()

Pastikan gunakan class milik ActionBarSherlock◦ com.actionbarsherlock.app.ActionBar◦ com.actionbarsherlock.view.Menu◦ com.actionbarsherlock.view.MenuItem◦ com.actionbarsherlock.view.MenuInflater

Page 8: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 8

Sliding Menu

Page 9: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 9

Navigation Drawer

Page 10: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 10

Membuat Drawer Layout

Page 11: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 11

Membuat Aksi Buka / Tutup

DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,                R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {

            /** Called when a drawer has settled in a completely closed state. */            public void onDrawerClosed(View view) {                getActionBar().setTitle(mTitle);                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()            }

            /** Called when a drawer has settled in a completely open state. */            public void onDrawerOpened(View drawerView) {                getActionBar().setTitle(mDrawerTitle);                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()            }        };

        // Set the drawer toggle as the DrawerListener        mDrawerLayout.setDrawerListener(mDrawerToggle);

Page 12: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 12

Buka / Tutup dengan icon up

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);        mDrawerToggle = new ActionBarDrawerToggle(                this,                  /* host Activity */                mDrawerLayout,         /* DrawerLayout object */                R.drawable.ic_drawer,  /* nav drawer icon to replace 'Up' caret */                R.string.drawer_open,  /* "open drawer" description */                R.string.drawer_close  /* "close drawer" description */                ) {

            /** Called when a drawer has settled in a completely closed state. */            public void onDrawerClosed(View view) {                getActionBar().setTitle(mTitle);            }

            /** Called when a drawer has settled in a completely open state. */            public void onDrawerOpened(View drawerView) {                getActionBar().setTitle(mDrawerTitle);            }        };

        // Set the drawer toggle as the DrawerListener        mDrawerLayout.setDrawerListener(mDrawerToggle);

        getActionBar().setDisplayHomeAsUpEnabled(true);        getActionBar().setHomeButtonEnabled(true);

Page 13: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 13

Library SlidingMenu Url: https://github.com/jfeinstein10/SlidingMenu

Lebih mudah diimplementasikan

Dapat membuat sliding menu di kiri dan di kanan

Tetapi:◦ Tidak mempunyai icon garis tiga di actionbar◦ Menu tidak floating di atas konten

Page 14: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 14

Penggunakan SlidingMenu

Page 15: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 15

JSON Parsing

Page 16: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 16

JSON

Page 17: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 17

Basic Parsing

JSONObject jObj = new JSONObject(strFromUrl);int id = jObj.getInt("id");String name = jObj.getString("name");String address = jObj.getString("address");String contact = jObj.getString("contact");//.... dan seterusnya

Page 18: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 18

Gson Unduh library Gson

◦ https://code.google.com/p/google-gson/

Ekstrak hasil unduh dan letakkan library jar ke folder libs di project

Buat kelas model yang mempresentasikan json yang akan diparsing

Page 19: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 19

Contoh kelas modelpublic class RestaurantDao {

String id;String name;String address;String contact;String links;String about;String lat;String lng;String currency;String minprice;String maxprice;

//.... dan seterusnya}

Page 20: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 20

Parsing menggunakan GsonGson gson = new Gson();RestaurantDao restaurant = gson.fromJson(strFromUrl, RestaurantDao.class);

Page 21: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 21

Tablet Dimension

Page 22: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 22

Dimension for TabletNexus S Galaxy Tab 10.1

Page 23: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 23

dimens.xml/values/dimens.xml

/values-sw600dp/dimens.xml

<resources> <dimen name=“text_14sp”>14sp</dimen> <dimen name=“dimen_10dp”>10dp</dimen></resources>

<resources> <dimen name=“text_14sp”>24sp</dimen> <dimen name=“dimen_10dp”>20dp</dimen></resources>

Page 24: Tips dan Third Party Library untuk Android - Part 1

TIPS & THIRD PARTY LIBRARY FOR ANDROID 24

Dimension compatibilityNexus S Galaxy Tab 10.1

Page 25: Tips dan Third Party Library untuk Android - Part 1
Page 26: Tips dan Third Party Library untuk Android - Part 1

26

Work with Us - PT GITS IndonesiaJalan Jatimulya 1 No 14, BandungJalan Rembang No 17, Menteng, Jakarta Pusat