Wednesday, September 3, 2014

RecyclerView setEmptyView

From Android Docs, RecyclerView is a more advanced and flexible version of ListView because it is more efficient and it doesnt care about the visuals. From the looks of it, it expects that the RecyclerView must always have data but thats not always possible, as i search how empty views is done in RecyclerView i cant seem to find one (If you know one or his better then the following codes, please comment below).
So here is what i did
private void checkAdapterIsEmpty () {
        if (mAdapter.getItemCount() == 0) {
            mEmptyView.setVisibility(View.VISIBLE);
        } else {
            mEmptyView.setVisibility(View.GONE);
        }
    }

    protected void setupRecyclerView() {
        mAdapter = new MyAdapter(mItemList);
        mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
            @Override
            public void onChanged() {
                super.onChanged();
                checkAdapterIsEmpty();
            }
        });

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setHasFixedSize(true);

        mRecyclerView.setAdapter(mAdapter);
        checkAdapterIsEmpty();
    }

Tuesday, September 2, 2014

Android Wish

My friends over altlimit network created chipnship and my wish is to get this android collectable :)


Wednesday, July 30, 2014

Super slow when debugging with a device with ART

As i was debugging an android app on my nexus 5 i found that its super slow in nexus 5 but really fast on other mobile, turns out if you have ART enabled (kitkat+) the device cannot ensure the compiled matches the bytecode instructions. From stackoverflow.com they recommended to switch back to dalvik. Thats a bummer for in L ART is the only runtime, i hope they fix this in the future.

Monday, May 26, 2014

RelativeLayout alignParentBottom DialogFragment Listview

I havent done android programming until recently so i havent stumble on anything that i could blog about (plus stackoverflow has the answer to almost everything :] ). I was trying to recreate how Google+ did the new post dialog, in my head i could use DialogFragment and RelativeLayout where i stick the action row to the bottom via alignParentBottom and an EditText on top with layout_below the action layout. But this has a problem, DialogFragment and alignParentBottom dont play along really well as it would just align the action layout to the bottom of the screen regardless of the onscreen keyboard.

Now there are some suggestion where you extends RelativeLayout and compute for the keyboard size and resize the RelativeLayout Here in stackoverflow, but i recently found that adding a listview with layout_below the actionbar would cause the parent to recompute the child layout. Now this might be a bug or its just how RelativeLayout is done since its quite complicated do the calculation. I tested it on 4.4.2 on nexus 5 and 7, 4.3.1 on cm 10.2 on xperia z, 4.3 on xiaomi mi3 and nexus 7 2012, 4.1.2 on xperia acro s, 4.0.3 Star N8000. I cant seem to find a phone lying around thats 4.2 but its safe to assume it would also work.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:id="@+id/editTxt"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="Write something"
        android:gravity="top|left"
        android:layout_above="@+id/actionLayout"
        />
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/actionLayout"
        />
    <LinearLayout
        android:id="@+id/actionLayout"
        android:layout_width="wrap_content"
        android:layout_height="52dp"
        android:layout_alignParentBottom="true"
        >
    </LinearLayout>
</RelativeLayout>

Friday, December 28, 2012

Card Camera App

Releasing our newest android app https://play.google.com/store/apps/details?id=com.ramentech.cardcamera.free with this app you could create cards (currently magic cards) and share to your friends.