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

Added fling support. #10

Merged
merged 3 commits into from
Dec 7, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions FlipView/Demo/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<activity android:name="com.aphidmobile.flip.demo.FlipAsyncContentActivity"/>
<activity android:name="com.aphidmobile.flip.demo.FlipTextViewAltActivity"/>
<activity android:name="com.aphidmobile.flip.demo.FlipHorizontalLayoutActivity"/>
<activity android:name="com.aphidmobile.flip.demo.FlipTextViewXmlActivity"/>

</application>

Expand Down
8 changes: 8 additions & 0 deletions FlipView/Demo/res/layout/xml_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<com.aphidmobile.flip.FlipViewController xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/flipView"
android:layout_width="match_parent"
android:layout_height="match_parent"
custom:orientation="horizontal" />

3 changes: 3 additions & 0 deletions FlipView/Demo/res/values/dimensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<dimen name="textSize">128sp</dimen>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package com.aphidmobile.flip.demo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.*;
import android.widget.BaseAdapter;
import com.aphidmobile.flip.FlipViewController;
import com.aphidmobile.flip.demo.views.NumberButton;
import com.aphidmobile.flip.demo.views.NumberTextView;
import com.aphidmobile.flipview.demo.R;

public class FlipButtonActivity extends Activity {
Expand Down Expand Up @@ -58,8 +60,9 @@ public long getItemId(int position) {
public View getView(int position, View convertView, ViewGroup parent) {
NumberButton button;
if (convertView == null) {
button = new NumberButton(parent.getContext(), position);
button.setTextSize(360);
final Context context = parent.getContext();
button = new NumberButton(context, position);
button.setTextSize(context.getResources().getDimension(R.dimen.textSize));
}
else {
button = (NumberButton) convertView;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.aphidmobile.flip.demo;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -44,8 +45,9 @@ public long getItemId(int position) {
public View getView(int position, View convertView, ViewGroup parent) {
NumberTextView view;
if (convertView == null) {
view = new NumberTextView(parent.getContext(), position);
view.setTextSize(360);
final Context context = parent.getContext();
view = new NumberTextView(context, position);
view.setTextSize(context.getResources().getDimension(R.dimen.textSize));
}
else {
view = (NumberTextView) convertView;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
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 android.view.View;
import android.widget.Adapter;

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

/**
* @author Paul Burke paulburke.co
*
*/
public class FlipTextViewXmlActivity extends FlipTextViewActivity {

@Override
public void setContentView(View view) {

setContentView(R.layout.xml_layout);

Adapter adapter = flipView.getAdapter();
flipView = (FlipViewController) findViewById(R.id.flipView);
flipView.setAdapter(adapter);
}

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

Expand Down
11 changes: 11 additions & 0 deletions FlipView/FlipLibrary/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<declare-styleable name="FlipViewController">
<attr name="orientation" format="enum">
<enum name="vertical" value="0" />
<enum name="horizontal" value="1" />
</attr>
</declare-styleable>

</resources>
6 changes: 5 additions & 1 deletion FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouc
if (Math.abs(delta) > controller.getTouchSlop())
setState(STATE_TOUCH); //XXX: initialize views?
if (state == STATE_TOUCH) {
forward = delta > 0; // We only want to know the direction of the last movement
controller.showFlipAnimation();
final float angleDelta ;
if(orientationVertical){
Expand Down Expand Up @@ -283,7 +284,10 @@ public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouc
delta = lastX - event.getX();
rotateBy(180 * delta / controller.getContentWidth() * MOVEMENT_RATE);
}
forward = angle >= 90;
if (frontCards.getIndex() == -1) // If at the first or last card
forward = true;
else if (backCards.getIndex() == -1)
forward = false;
setState(STATE_AUTO_ROTATE);
controller.getSurfaceView().requestRender();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.*;
import android.widget.*;
import com.aphidmobile.utils.AphidLog;
import com.openaphid.flip.R;

import junit.framework.Assert;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -101,15 +105,52 @@ public void onChanged() {
public FlipViewController(Context context) {
this(context, true);
}


public FlipViewController(Context context, boolean orientationVertical) {
super(context);
init(context, orientationVertical);
}

/**
* Constructor required for XML inflation.
*/
public FlipViewController(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, isOrientationVertical(context, attrs));
}

/**
* Constructor required for XML inflation.
*/
public FlipViewController(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, isOrientationVertical(context, attrs));
}

/**
* Check the attributes for a declared orientation. (Defaults to true)
*/
private boolean isOrientationVertical(Context context, AttributeSet attrs) {
boolean vertical = true;
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.FlipViewController,
0, 0);
try {
vertical = a.getInteger(R.styleable.FlipViewController_orientation,
0) == 0 ? true : false;
} finally {
a.recycle();
}
return vertical;
}

private void init(Context context, boolean orientationVertical) {
ViewConfiguration configuration = ViewConfiguration.get(getContext());
touchSlop = configuration.getScaledTouchSlop();
maxVelocity = configuration.getScaledMaximumFlingVelocity();
this.orientationVertical = orientationVertical;
setupSurfaceView();
setupSurfaceView();
}

public ViewFlipListener getOnViewFlipListener() {
Expand Down