Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
#3, add FlipViewController.ViewFlipListener and a simple deom
Browse files Browse the repository at this point in the history
  • Loading branch information
Aphid Mobile committed Nov 8, 2012
1 parent 3200a93 commit 0e0935d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions FlipView/Demo/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<activity android:name="com.aphidmobile.flip.demo.FlipButtonActivity"/>
<activity android:name="com.aphidmobile.flip.demo.FlipComplexLayoutActivity"/>
<activity android:name="com.aphidmobile.flip.demo.FlipAsyncContentActivity"/>
<activity android:name="com.aphidmobile.flip.demo.FlipTextViewAltActivity"/>

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.aphidmobile.flip.FlipViewController;
import com.aphidmobile.flip.demo.views.NumberTextView;
import com.aphidmobile.flipview.demo.R;

public class FlipTextViewActivity extends Activity {
private FlipViewController flipView;
protected FlipViewController flipView;

/**
* Called when the activity is first created.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2012 Aphid Mobile
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.aphidmobile.flip.demo;

import com.aphidmobile.flip.FlipViewController;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class FlipTextViewAltActivity extends FlipTextViewActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

flipView.setOnViewFlipListener(new FlipViewController.ViewFlipListener() {

@Override
public void onViewFlipped(View view, int position) {
Toast.makeText(view.getContext(), "Flipped to page " + position, Toast.LENGTH_SHORT).show();
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
addItem(data, "Flip Buttons", FlipButtonActivity.class);
addItem(data, "Flip Complex Layouts", FlipComplexLayoutActivity.class);
addItem(data, "Flip Async Content", FlipAsyncContentActivity.class);
addItem(data, "Flip with Event Listener", FlipTextViewAltActivity.class);
return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@
import com.aphidmobile.utils.AphidLog;
import junit.framework.Assert;

import java.io.BufferedInputStream;
import java.util.LinkedList;

public class FlipViewController extends AdapterView<Adapter> {

public static interface ViewFlipListener {
void onViewFlipped(View view, int position);
}

private static final int MSG_SURFACE_CREATED = 1;
private Handler handler = new Handler(new Handler.Callback() {
Expand Down Expand Up @@ -85,6 +90,8 @@ public void onChanged() {
private float touchSlop;
@SuppressWarnings("unused")
private float maxVelocity;

private ViewFlipListener onViewFlipListener;

public FlipViewController(Context context) {
super(context);
Expand All @@ -94,6 +101,16 @@ public FlipViewController(Context context) {

setupSurfaceView();
}

public ViewFlipListener getOnViewFlipListener() {
return onViewFlipListener;
}


public void setOnViewFlipListener(ViewFlipListener onViewFlipListener) {
this.onViewFlipListener = onViewFlipListener;
}


float getTouchSlop() {
return touchSlop;
Expand Down Expand Up @@ -351,7 +368,7 @@ private void debugBufferedViews() {
AphidLog.d("bufferedViews: " + bufferedViews + ", index: " + bufferIndex);
}

void flippedToView(int indexInAdapter) { //XXX: can be simplified and unified with setSelection
void flippedToView(final int indexInAdapter) { //XXX: can be simplified and unified with setSelection
if (AphidLog.ENABLE_DEBUG)
AphidLog.d("flippedToView: %d", indexInAdapter);

Expand Down Expand Up @@ -420,6 +437,9 @@ private void hideFlipAnimation() {
inFlipAnimation = false;

updateVisibleView(bufferIndex);

if (onViewFlipListener != null)
onViewFlipListener.onViewFlipped(bufferedViews.get(bufferIndex), adapterIndex);

handler.post(new Runnable() {
public void run() {
Expand Down

0 comments on commit 0e0935d

Please sign in to comment.