diff --git a/.gitignore b/.gitignore index 1f04d7e..e6c6527 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ out/ # Local configuration file (sdk path, etc) local.properties + +#Mac folder files +.DS_Store \ No newline at end of file diff --git a/FlipView/Demo/.classpath b/FlipView/Demo/.classpath index a4763d1..3f9691c 100644 --- a/FlipView/Demo/.classpath +++ b/FlipView/Demo/.classpath @@ -1,8 +1,8 @@ - - + + diff --git a/FlipView/Demo/AndroidManifest.xml b/FlipView/Demo/AndroidManifest.xml index 15514be..f3c8e8e 100644 --- a/FlipView/Demo/AndroidManifest.xml +++ b/FlipView/Demo/AndroidManifest.xml @@ -27,6 +27,7 @@ + diff --git a/FlipView/Demo/src/com/aphidmobile/flip/demo/FlipHorizontalLayoutActivity.java b/FlipView/Demo/src/com/aphidmobile/flip/demo/FlipHorizontalLayoutActivity.java new file mode 100644 index 0000000..6a5c028 --- /dev/null +++ b/FlipView/Demo/src/com/aphidmobile/flip/demo/FlipHorizontalLayoutActivity.java @@ -0,0 +1,148 @@ +/* +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.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.text.Html; +import android.view.*; +import android.widget.*; +import com.aphidmobile.flip.FlipViewController; +import com.aphidmobile.flipview.demo.R; +import com.aphidmobile.utils.AphidLog; +import com.aphidmobile.utils.IO; + +import java.util.ArrayList; +import java.util.List; + +public class FlipHorizontalLayoutActivity extends Activity { + private FlipViewController flipView; + + /** + * Called when the activity is first created. + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setTitle(R.string.activity_title); + + flipView = new FlipViewController(this, false); + + flipView.setAdapter(new MyBaseAdapter(this)); + + setContentView(flipView); + } + + @Override + protected void onResume() { + super.onResume(); + flipView.onResume(); + } + + @Override + protected void onPause() { + super.onPause(); + flipView.onPause(); + } + + private static class MyBaseAdapter extends BaseAdapter { + private static List IMG_DESCRIPTIONS = new ArrayList(); + + static { + IMG_DESCRIPTIONS.add(new Data("Potala Palace", "potala_palace.jpg", "http://en.wikipedia.org/wiki/Potala_Palace", "The Potala Palace is located in Lhasa, Tibet Autonomous Region, China. It is named after Mount Potalaka, the mythical abode of Chenresig or Avalokitesvara.")); + IMG_DESCRIPTIONS.add(new Data("Drepung Monastery", "drepung_monastery.jpg", "http://en.wikipedia.org/wiki/Drepung", "Drepung Monastery, located at the foot of Mount Gephel, is one of the \"great three\" Gelukpa university monasteries of Tibet.")); + IMG_DESCRIPTIONS.add(new Data("Sera Monastery", "sera_monastery.jpg", "http://en.wikipedia.org/wiki/Sera_Monastery", "Sera Monastery is one of the 'great three' Gelukpa university monasteries of Tibet, located 1.25 miles (2.01 km) north of Lhasa.")); + IMG_DESCRIPTIONS.add(new Data("Samye Monastery", "samye_monastery.jpg", "http://en.wikipedia.org/wiki/Samye", "Samye Monastery is the first Buddhist monastery built in Tibet, was most probably first constructed between 775 and 779 CE.")); + IMG_DESCRIPTIONS.add(new Data("Tashilunpo Monastery", "tashilunpo_monastery.jpg", "http://en.wikipedia.org/wiki/Tashilhunpo_Monastery", "Tashilhunpo Monastery, founded in 1447 by Gendun Drup, the First Dalai Lama, is a historic and culturally important monastery next to Shigatse, the second-largest city in Tibet.")); + IMG_DESCRIPTIONS.add(new Data("Zhangmu Port", "zhangmu_port.jpg", "http://en.wikipedia.org/wiki/Zhangmu", "Zhangmu/Dram is a customs town and port of entry located in Nyalam County on the Nepal-China border, just uphill and across the Bhote Koshi River from the Nepalese town of Kodari.")); + IMG_DESCRIPTIONS.add(new Data("Kathmandu", "kathmandu.jpg", "http://en.wikipedia.org/wiki/Kathmandu", "Kathmandu is the capital and, with more than one million inhabitants, the largest metropolitan city of Nepal.")); + IMG_DESCRIPTIONS.add(new Data("Pokhara", "pokhara.jpg", "http://en.wikipedia.org/wiki/Pokhara", "Pokhara Sub-Metropolitan City is the second largest city of Nepal with approximately 250,000 inhabitants and is situated about 200 km west of the capital Kathmandu.")); + IMG_DESCRIPTIONS.add(new Data("Patan", "patan.jpg", "http://en.wikipedia.org/wiki/Patan,_Nepal", "Patan, officially Lalitpur Sub-Metropolitan City, is one of the major cities of Nepal located in the south-central part of Kathmandu Valley.")); + } + + private LayoutInflater inflater; + + private MyBaseAdapter(Context context) { + inflater = LayoutInflater.from(context); + } + + @Override + public int getCount() { + return IMG_DESCRIPTIONS.size(); + } + + @Override + public Object getItem(int position) { + return position; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View layout = convertView; + if (convertView == null) + layout = inflater.inflate(R.layout.complex1, null); + + final Data data = IMG_DESCRIPTIONS.get(position); + + TextView titleView = (TextView) layout.findViewById(R.id.title); + titleView.setText(AphidLog.format("%d. %s", position, data.title)); + + ImageView photoView = (ImageView) layout.findViewById(R.id.photo); + photoView.setImageBitmap(IO.readBitmap(inflater.getContext().getAssets(), data.imageFilename)); + + TextView textView = (TextView) layout.findViewById(R.id.description); + textView.setText(Html.fromHtml(data.description)); + + Button wikipedia = (Button) layout.findViewById(R.id.wikipedia); + wikipedia.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent( + Intent.ACTION_VIEW, + Uri.parse(data.link) + ); + inflater.getContext().startActivity(intent); + } + }); + + return layout; + } + + private static class Data { + public String title; + public String imageFilename; + public String link; + public String description; + + private Data(String title, String imageFilename, String link, String description) { + this.title = title; + this.imageFilename = imageFilename; + this.link = link; + this.description = description; + } + } + } +} diff --git a/FlipView/Demo/src/com/aphidmobile/flip/demo/MainActivity.java b/FlipView/Demo/src/com/aphidmobile/flip/demo/MainActivity.java index ba4ad37..d6e5fa5 100644 --- a/FlipView/Demo/src/com/aphidmobile/flip/demo/MainActivity.java +++ b/FlipView/Demo/src/com/aphidmobile/flip/demo/MainActivity.java @@ -70,6 +70,7 @@ protected void onListItemClick(ListView l, View v, int position, long id) { addItem(data, "Flip Complex Layouts", FlipComplexLayoutActivity.class); addItem(data, "Flip Async Content", FlipAsyncContentActivity.class); addItem(data, "Flip with Event Listener", FlipTextViewAltActivity.class); + addItem(data, "Flip Horizontal", FlipHorizontalLayoutActivity.class); return data; } diff --git a/FlipView/FlipLibrary/.classpath b/FlipView/FlipLibrary/.classpath index a4763d1..3f9691c 100644 --- a/FlipView/FlipLibrary/.classpath +++ b/FlipView/FlipLibrary/.classpath @@ -1,8 +1,8 @@ - - + + diff --git a/FlipView/FlipLibrary/src/com/aphidmobile/flip/Card.java b/FlipView/FlipLibrary/src/com/aphidmobile/flip/Card.java index d048ccf..2ff4fef 100644 --- a/FlipView/FlipLibrary/src/com/aphidmobile/flip/Card.java +++ b/FlipView/FlipLibrary/src/com/aphidmobile/flip/Card.java @@ -49,6 +49,8 @@ public class Card { private int axis = AXIS_TOP; + private boolean orientationVertical = true; + private boolean dirty = false; public Texture getTexture() { @@ -89,6 +91,10 @@ public void setAxis(int axis) { this.axis = axis; } + public void setOrientation(boolean orientationVertical) { + this.orientationVertical = orientationVertical; + } + public void draw(GL10 gl) { if (dirty) updateVertices(); @@ -121,17 +127,33 @@ public void draw(GL10 gl) { gl.glPushMatrix(); - if (angle > 0) { - if (axis == AXIS_TOP) { - gl.glTranslatef(0, cardVertices[1], 0f); - gl.glRotatef(-angle, 1f, 0f, 0f); - gl.glTranslatef(0, -cardVertices[1], 0f); - } else { - gl.glTranslatef(0, cardVertices[7], 0f); - gl.glRotatef(angle, 1f, 0f, 0f); - gl.glTranslatef(0, -cardVertices[7], 0f); + if(orientationVertical){ + if (angle > 0) { + if (axis == AXIS_TOP) { + gl.glTranslatef(0, cardVertices[1], 0f); + gl.glRotatef(-angle, 1f, 0f, 0f); + gl.glTranslatef(0, -cardVertices[1], 0f); + } else { + gl.glTranslatef(0, cardVertices[7], 0f); + gl.glRotatef(angle, 1f, 0f, 0f); + gl.glTranslatef(0, -cardVertices[7], 0f); + } + } + } else { + if (angle > 0) { + if (axis == AXIS_TOP) { + gl.glTranslatef(cardVertices[0], 0, 0f); + gl.glRotatef(-angle, 0f, 1f, 0f); + gl.glTranslatef(-cardVertices[0], 0, 0f); + } else { + gl.glTranslatef(cardVertices[6], 0, 0f); + gl.glRotatef(angle, 0f, 1f, 0f); + gl.glTranslatef(-cardVertices[6], 0, 0f); + } } + } + gl.glVertexPointer(3, GL_FLOAT, 0, vertexBuffer); gl.glDrawElements(GL_TRIANGLES, indices.length, GL_UNSIGNED_SHORT, indexBuffer); @@ -150,15 +172,31 @@ public void draw(GL10 gl) { gl.glDisable(GL_DEPTH_TEST); if (axis == AXIS_TOP) { - float w = cardVertices[9] - cardVertices[0]; - float h = (cardVertices[1] - cardVertices[4]) * (1f - FloatMath.cos(d2r(angle))); - float z = (cardVertices[1] - cardVertices[4]) * FloatMath.sin(d2r(angle)); - float[] shadowVertices = new float[]{ - cardVertices[0], h + cardVertices[4], z, - cardVertices[3], cardVertices[4], 0f, - w, cardVertices[7], 0f, - w, h + cardVertices[4], z - }; + float w,h,z; + float[] shadowVertices; + if(orientationVertical){ + w = cardVertices[9] - cardVertices[0]; + h = (cardVertices[1] - cardVertices[4]) * (1f - FloatMath.cos(d2r(angle))); + z = (cardVertices[1] - cardVertices[4]) * FloatMath.sin(d2r(angle)); + shadowVertices = new float[]{ + cardVertices[0], h + cardVertices[4], z, + cardVertices[3], cardVertices[4], 0f, + w, cardVertices[7], 0f, + w, h + cardVertices[4], z + }; + } else { + w = (cardVertices[9] - cardVertices[0]) * (1f - FloatMath.cos(d2r(angle))); + h = (cardVertices[1] - cardVertices[4]); + z = (cardVertices[1] - cardVertices[4]) * FloatMath.sin(d2r(angle)); + + shadowVertices = new float[]{ + cardVertices[9] - w, cardVertices[1], z, + cardVertices[6] - w, cardVertices[4], z, + cardVertices[6], cardVertices[7], 0f, + cardVertices[9], cardVertices[10], 0f + }; + + } float alpha = 1f * (90f - angle) / 90f; @@ -166,16 +204,29 @@ public void draw(GL10 gl) { gl.glVertexPointer(3, GL_FLOAT, 0, toFloatBuffer(shadowVertices)); gl.glDrawElements(GL_TRIANGLES, indices.length, GL_UNSIGNED_SHORT, indexBuffer); } else { - float w = cardVertices[9] - cardVertices[0]; - float h = (cardVertices[1] - cardVertices[4]) * (1f - FloatMath.cos(d2r(angle))); - float z = (cardVertices[1] - cardVertices[4]) * FloatMath.sin(d2r(angle)); - float[] shadowVertices = new float[]{ - cardVertices[0], cardVertices[1], 0f, - cardVertices[3], cardVertices[1] - h, z, - w, cardVertices[1] - h, z, - w, cardVertices[1], 0f - }; - + float w,h,z; + float[] shadowVertices; + if(orientationVertical){ + w = cardVertices[9] - cardVertices[0]; + h = (cardVertices[1] - cardVertices[4]) * (1f - FloatMath.cos(d2r(angle))); + z = (cardVertices[1] - cardVertices[4]) * FloatMath.sin(d2r(angle)); + shadowVertices = new float[]{ + cardVertices[0], cardVertices[1], 0f, + cardVertices[3], cardVertices[1] - h, z, + w, cardVertices[1] - h, z, + w, cardVertices[1], 0f + }; + } else { + w = (cardVertices[9] - cardVertices[0]) * (1f - FloatMath.cos(d2r(angle))); + h = (cardVertices[1] - cardVertices[4]); + z = (cardVertices[1] - cardVertices[4]) * FloatMath.sin(d2r(angle)); + shadowVertices = new float[]{ + cardVertices[0], cardVertices[1], 0f, + cardVertices[3], cardVertices[4], 0f, + cardVertices[0] + w, cardVertices[7], z, + cardVertices[3] + w, cardVertices[10], z + }; + } float alpha = 1f * (90f - angle) / 90f; gl.glColor4f(0f, 0.0f, 0f, alpha); diff --git a/FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java b/FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java index fa05f03..b0c425b 100644 --- a/FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java +++ b/FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java @@ -42,7 +42,9 @@ public class FlipCards { private int animatedFrame = 0; private int state = STATE_INIT; + private boolean orientationVertical = true; private float lastY = -1; + private float lastX = -1; @SuppressWarnings("unused") private VelocityTracker velocityTracker; @@ -52,12 +54,12 @@ public class FlipCards { private boolean visible = false; - public FlipCards(FlipViewController controller) { + public FlipCards(FlipViewController controller, boolean orientationVertical) { this.controller = controller; - frontCards = new ViewDualCards(); - backCards = new ViewDualCards(); - + frontCards = new ViewDualCards(orientationVertical); + backCards = new ViewDualCards(orientationVertical); + this.orientationVertical = orientationVertical; resetAxises(); } @@ -223,15 +225,24 @@ public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouc switch (event.getAction()) { case MotionEvent.ACTION_DOWN: lastY = event.getY(); + lastX = event.getX(); return isOnTouchEvent; case MotionEvent.ACTION_MOVE: - delta = lastY - event.getY(); + if(orientationVertical){ + delta = lastY - event.getY(); + } else { + delta = lastX - event.getX(); + } if (Math.abs(delta) > controller.getTouchSlop()) setState(STATE_TOUCH); //XXX: initialize views? if (state == STATE_TOUCH) { controller.showFlipAnimation(); - - final float angleDelta = 180 * delta / controller.getContentHeight() * MOVEMENT_RATE; + final float angleDelta ; + if(orientationVertical){ + angleDelta = 180 * delta / controller.getContentHeight() * MOVEMENT_RATE; + } else { + angleDelta = 180 * delta / controller.getContentWidth() * MOVEMENT_RATE; + } angle += angleDelta; if (backCards.getIndex() == -1) { if (angle >= MAX_TIP_ANGLE) @@ -252,7 +263,11 @@ public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouc angle += 180; } } - lastY = event.getY(); + if(orientationVertical){ + lastY = event.getY(); + } else { + lastX = event.getX(); + } controller.getSurfaceView().requestRender(); return true; } @@ -261,8 +276,13 @@ public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouc case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (state == STATE_TOUCH) { - delta = lastY - event.getY(); - rotateBy(180 * delta / controller.getContentHeight() * MOVEMENT_RATE); + if(orientationVertical){ + delta = lastY - event.getY(); + rotateBy(180 * delta / controller.getContentHeight() * MOVEMENT_RATE); + } else { + delta = lastX - event.getX(); + rotateBy(180 * delta / controller.getContentWidth() * MOVEMENT_RATE); + } forward = angle >= 90; setState(STATE_AUTO_ROTATE); controller.getSurfaceView().requestRender(); diff --git a/FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipViewController.java b/FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipViewController.java index f558fe7..5cda7e4 100644 --- a/FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipViewController.java +++ b/FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipViewController.java @@ -33,10 +33,13 @@ import java.util.LinkedList; public class FlipViewController extends AdapterView { + + public static final int ORIENTATION_VERTICAL = 0; + public static final int ORIENTATION_HORIZONTAL = 1; 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() { @@ -58,6 +61,8 @@ public boolean handleMessage(Message msg) { private int contentWidth; private int contentHeight; + + private boolean orientationVertical; private boolean enableFlipAnimation = true; @@ -94,11 +99,16 @@ public void onChanged() { private ViewFlipListener onViewFlipListener; public FlipViewController(Context context) { + this(context, true); + } + + + public FlipViewController(Context context, boolean orientationVertical) { super(context); ViewConfiguration configuration = ViewConfiguration.get(getContext()); touchSlop = configuration.getScaledTouchSlop(); maxVelocity = configuration.getScaledMaximumFlingVelocity(); - + this.orientationVertical = orientationVertical; setupSurfaceView(); } @@ -294,7 +304,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { private void setupSurfaceView() { surfaceView = new GLSurfaceView(getContext()); - cards = new FlipCards(this); + cards = new FlipCards(this, orientationVertical); renderer = new FlipRenderer(this, cards); surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); diff --git a/FlipView/FlipLibrary/src/com/aphidmobile/flip/ViewDualCards.java b/FlipView/FlipLibrary/src/com/aphidmobile/flip/ViewDualCards.java index 9ff5fe5..d3764f1 100644 --- a/FlipView/FlipLibrary/src/com/aphidmobile/flip/ViewDualCards.java +++ b/FlipView/FlipLibrary/src/com/aphidmobile/flip/ViewDualCards.java @@ -37,6 +37,14 @@ public class ViewDualCards { private Card topCard = new Card(); private Card bottomCard = new Card(); + private boolean orientationVertical = true; + + public ViewDualCards(boolean orientationVertical) { + topCard.setOrientation(orientationVertical); + bottomCard.setOrientation(orientationVertical); + this.orientationVertical = orientationVertical; + } + public int getIndex() { return index; } @@ -48,7 +56,8 @@ public View getView() { public boolean setView(int index, View view) { UI.assertInMainThread(); this.index = index; - if (getView() == view && (screenshot != null || TextureUtils.isValidTexture(texture))) + if (getView() == view + && (screenshot != null || TextureUtils.isValidTexture(texture))) return false; viewRef = null; if (texture != null) { @@ -109,33 +118,58 @@ public void buildTexture(FlipRenderer renderer, GL10 gl) { final float textureHeight = texture.getHeight(); final float textureWidth = texture.getWidth(); - topCard.setCardVertices(new float[]{ - 0f, viewHeight, 0f, //top left - 0f, viewHeight / 2.0f, 0f, //bottom left - viewWidth, viewHeight / 2f, 0f, //bottom right - viewWidth, viewHeight, 0f //top right - }); - - topCard.setTextureCoordinates(new float[]{ - 0f, 0f, - 0f, viewHeight / 2f / textureHeight, - viewWidth / textureWidth, viewHeight / 2f / textureHeight, - viewWidth / textureWidth, 0f - }); - - bottomCard.setCardVertices(new float[]{ - 0f, viewHeight / 2f, 0f, //top left - 0f, 0f, 0f, //bottom left - viewWidth, 0f, 0f, //bottom right - viewWidth, viewHeight / 2f, 0f //top right - }); - - bottomCard.setTextureCoordinates(new float[]{ - 0f, viewHeight / 2f / textureHeight, - 0f, viewHeight / textureHeight, - viewWidth / textureWidth, viewHeight / textureHeight, - viewWidth / textureWidth, viewHeight / 2f / textureHeight - }); + if (orientationVertical) { + topCard.setCardVertices(new float[] { 0f, viewHeight, 0f, // top left + 0f, viewHeight / 2.0f, 0f, // bottom left + viewWidth, viewHeight / 2f, 0f, // bottom right + viewWidth, viewHeight, 0f // top right + }); + + topCard.setTextureCoordinates(new float[] { 0f, 0f, 0f, + viewHeight / 2f / textureHeight, + viewWidth / textureWidth, + viewHeight / 2f / textureHeight, + viewWidth / textureWidth, 0f }); + + bottomCard.setCardVertices(new float[] { 0f, viewHeight / 2f, + 0f, // top left + 0f, 0f, 0f, // bottom left + viewWidth, 0f, 0f, // bottom right + viewWidth, viewHeight / 2f, 0f // top right + }); + + bottomCard.setTextureCoordinates(new float[] { 0f, + viewHeight / 2f / textureHeight, 0f, + viewHeight / textureHeight, viewWidth / textureWidth, + viewHeight / textureHeight, viewWidth / textureWidth, + viewHeight / 2f / textureHeight }); + } else { + topCard.setCardVertices(new float[] { 0f, viewHeight, 0f, // top left + 0f, 0f, 0f, // bottom left + viewWidth / 2f, 0f, 0f, // bottom right + viewWidth / 2f, viewHeight, 0f // top right + }); + + topCard.setTextureCoordinates(new float[] { 0f, 0f, 0f, + viewHeight / textureHeight, + viewWidth / 2f / textureWidth, + viewHeight / textureHeight, + viewWidth / 2f / textureWidth, 0f }); + + bottomCard.setCardVertices(new float[] { viewWidth / 2f, + viewHeight, 0f, // top left + viewWidth / 2f, 0f, 0f, // bottom left + viewWidth, 0f, 0f, // bottom right + viewWidth, viewHeight, 0f // top right + }); + + bottomCard.setTextureCoordinates(new float[] { + viewWidth / 2f / textureWidth, 0f, + viewWidth / 2f / textureWidth, + viewHeight / textureHeight, viewWidth / textureWidth, + viewHeight / textureHeight, viewWidth / textureWidth, + 0f }); + } checkError(gl); } diff --git a/Legacy/Demo-Animation/.classpath b/Legacy/Demo-Animation/.classpath index a4763d1..3f9691c 100644 --- a/Legacy/Demo-Animation/.classpath +++ b/Legacy/Demo-Animation/.classpath @@ -1,8 +1,8 @@ - - + +