トラッキング コード

7/27/2014

How to handle to auto flip with ViewFlipper

ViewFlipper do not have a handler to auto flipping.
If do handing, we should get Animation Class via VewFlipper#getInAnimation().
We register to Listener.


The follow code is sample.
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_flashing_card, null);
        mVewFlipper = (ViewFlipper) view.findViewById(R.id.viewFlipper1);

        mVewFlipper.setAutoStart(true);
        mVewFlipper.setInAnimation(getActivity(), android.R.anim.slide_in_left);
        mVewFlipper.getInAnimation().setAnimationListener(this);
        mVewFlipper.setFlipInterval(2000);

        return view;
    }

    @Override
    public void onAnimationEnd(Animation animation) {
    }

    @Override
    public void onAnimationRepeat(Animation animation) {
    }

    @Override
    public void onAnimationStart(Animation animation) {
    }

3/30/2014

How to use SwipeRefreshLayout, like a twitter, facebook



Create the Layout

You need to use the android.support.v4.widget.SwipeRefreshLayout.
Content is included SwipeRefreshLayout for clild layout( or view).

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_widget"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <!-- some full screen pullable view that will be the offsetable content -->

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/content"/>
</android.support.v4.widget.SwipeRefreshLayout>


Update for Swipe

You need the following step, due to updating for Swipe.
1. call setOnRefreshListener methiod due to setting Listener which handles the update starting.
2. onRefresh() is handled the update starting.
3. Then your update process finish、call setRefreshing(false).
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sample_swipe_refresh_widget);
        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_widget);
        mSwipeRefreshLayout.setOnRefreshListener(this);
    }


    @Override
    public void onRefresh() {
        refresh();
    }

    private void refresh() {
        Message msg = mHander.obtainMessage(0, this);
        mHander.sendMessageDelayed(msg, 1000);
    }

    private static Handler mHander = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            SwipeRefreshLayoutActivity actibity = (SwipeRefreshLayoutActivity) msg.obj;
            actibity.mSwipeRefreshLayout.setRefreshing(false);
        }
    };

3/15/2014

How to use Google Play services

Ready to use Google Play services

If you need to use Google Play services API, you should do download of Google Play services on Android SDK Manager.Google Play services was saved in following directory.<AndroidSDK>\sdk\extras\google\google_play_services\libproject\google-play-services_lib

Importing this Android Project to eclipse.

You must write a meta-data in AndroidMaifest.xml using Google Play services API.

    <application
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>

Check to exist of Google Play services

You shoud Check to exist of Google Play services in a device.

public class UsingGooglePlayServiceSampleActivity extends FragmentActivity {

    private boolean isGooglePlayServicesAvailable() {
        int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        if (ConnectionResult.SUCCESS == resultCode) {
            return true;
        } else {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                    CONNECTION_FAILURE_RESOLUTION_REQUEST);
            if (dialog != null) {
                ErrorDialogFragment errorFragment = new ErrorDialogFragment();
                errorFragment.setDialog(dialog);
                errorFragment.show(getSupportFragmentManager(), "errro_dialog");
            }
        }

        return false;
    }

    public static class ErrorDialogFragment extends DialogFragment {

        private Dialog mDialog;

        public ErrorDialogFragment() {
            super();
            mDialog = null;
        }

        public void setDialog(Dialog dialog) {
            mDialog = dialog;
        }

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            return mDialog;
        }

        @Override
        public void onDestroy() {
            mDialog = null;
            super.onDestroy();
        }
    }
}

Calling a method of GooglePlayServicesUtil.isGooglePlayServicesAvailable(), you can get Result code.If Result code is error, you can get a Dialog Object from calling method GooglePlayServicesUtil.getErrorDialog().You must use a DialogFragment to show a dialog.

If User close a dialog, onActivityResult is called with Result Code.

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CONNECTION_FAILURE_RESOLUTION_REQUEST) {
            if (resultCode == Activity.RESULT_OK) {
                // retry process
            }
        }
    }

2/08/2014

About a permission "WRITE_EXTERNAL_STORAGE"

http://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE
Starting in API level 19, this permission is not required to read/write files in your application-specific directories returned by getExternalFilesDir(String) and getExternalCacheDir()


If appliction is waking up on Android 4.4 Device, WRITE_EXTERNAL_STORAGE is not required to call getExternalFilesDir(String) and getExternalCacheDir(). Not returned Null.

2/01/2014

Add "disable swipe" to ViewPager.

I want to stop swipe in ViewPager. But ViewPager does not have "disable swipe" API.

Creat a custom ViewPager

I creat a custom ViewPager. Custom ViewPager has a "disable swipe" API.

package jp.baroqueworksdev.myapidemo.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class MyViewPager extends ViewPager {
    private boolean mIsEnabledSwipe = true;

    public MyViewPager(Context context) {
        super(context);
    }

    public MyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (!mIsEnabledSwipe) {
            return false;
        }
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (!mIsEnabledSwipe) {
            return false;
        }
        return super.onInterceptTouchEvent(event);
    }

    public void setEnabledSwipe(boolean enabled) {
        mIsEnabledSwipe = enabled;
    }

}