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

Commit

Permalink
Merge branch 'master' into develop with pull request #6
Browse files Browse the repository at this point in the history
Conflicts:
	FlipView/Demo/AndroidManifest.xml
	FlipView/Demo/src/com/aphidmobile/flip/demo/MainActivity.java
	FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java
	FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipViewController.java
  • Loading branch information
Aphid Mobile committed Nov 9, 2012
2 parents 0e0935d + b13e40f commit d5ff25e
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 75 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ out/

# Local configuration file (sdk path, etc)
local.properties

#Mac folder files
.DS_Store
4 changes: 2 additions & 2 deletions FlipView/Demo/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
1 change: 1 addition & 0 deletions FlipView/Demo/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<activity android:name="com.aphidmobile.flip.demo.FlipComplexLayoutActivity"/>
<activity android:name="com.aphidmobile.flip.demo.FlipAsyncContentActivity"/>
<activity android:name="com.aphidmobile.flip.demo.FlipTextViewAltActivity"/>
<activity android:name="com.aphidmobile.flip.demo.FlipHorizontalLayoutActivity"/>

</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Data> IMG_DESCRIPTIONS = new ArrayList<Data>();

static {
IMG_DESCRIPTIONS.add(new Data("Potala Palace", "potala_palace.jpg", "http://en.wikipedia.org/wiki/Potala_Palace", "The <b>Potala Palace</b> 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", "<b>Drepung Monastery</b>, 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", "<b>Sera Monastery</b> 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", "<b>Samye Monastery</b> 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", "<b>Tashilhunpo Monastery</b>, 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", "<b>Zhangmu/Dram</b> 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", "<b>Kathmandu</b> 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", "<b>Pokhara Sub-Metropolitan City</b> 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", "<b>Patan</b>, 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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions FlipView/FlipLibrary/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
107 changes: 79 additions & 28 deletions FlipView/FlipLibrary/src/com/aphidmobile/flip/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class Card {

private int axis = AXIS_TOP;

private boolean orientationVertical = true;

private boolean dirty = false;

public Texture getTexture() {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -150,32 +172,61 @@ 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;

gl.glColor4f(0f, 0.0f, 0f, alpha);
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);
Expand Down
Loading

0 comments on commit d5ff25e

Please sign in to comment.