Friday, July 21, 2017

Android RecyclerView Ripple 이펙트

리스트 아이템의 layout에다가 다음을 추가한다.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:background="?android:attr/selectableItemBackground">


Android 볼륨키 이벤트

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)){
            //Do something
        }
        return true;
    }

Thursday, July 20, 2017

Android 7.0 APK 파일 설치

프로그램 코드로 APK 파일을 설치해 보자. 안드로이드 7.0에서는 직접 외부 폴더(External Storage)의 APK를 설치할수 없다.
따라서 다음과 같이 FileProvider를 만들어야 한다.

xml/provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>

AndroidManifest.xml
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.duongame.XXX.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>

JAVA
                final Intent intent = new Intent(Intent.ACTION_VIEW);
                final Uri apkURI = FileProvider.getUriForFile(getActivity(), getActivity().getApplicationContext().getPackageName() + ".provider", new File(item.path));
                intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
                intent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);

Tuesday, July 11, 2017

Android FragmentPagerAdapter vs FragmentStatePagerAdapter

FragmentPagerAdapter - 페이지 갯수가 고정적일때
About FragmentPagerAdapter Google's guide says:
This version of the pager is more useful when there are a large number of pages, working more like a list view. When pages are not visible to the user, their entire fragment may be destroyed, only keeping the saved state of that fragment. This allows the pager to hold on to much less memory associated with each visited page as compared to FragmentPagerAdapter at the cost of potentially more overhead when switching between pages.

FragmentStatePagerAdapter - 페이지 갯수가 가변적일때
And about FragmentStatePagerAdapter:
This version of the pager is best for use when there are a handful of typically more static fragments to be paged through, such as a set of tabs. The fragment of each page the user visits will be kept in memory, though its view hierarchy may be destroyed when not visible. This can result in using a significant amount of memory since fragment instances can hold on to an arbitrary amount of state. For larger sets of pages, consider FragmentStatePagerAdapter.