Skip to content

Commit

Permalink
Adding features and fixing bugs. Now usable!
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmwarner committed Oct 6, 2013
1 parent be18621 commit c3765f5
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 62 deletions.
3 changes: 2 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme"
android:hardwareAccelerated="true" >
</application>

</manifest>
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ To be made.

Installation
--------------
Download the .zip, in Eclipse, right click, import existing code, select unziped content.
1. Download the .zip, in Eclipse, right click, import existing code, select unziped content.

Right click project to use with, properties, Android, Add..., Select GestureTutorial
2. Right click project to use with, properties, Android, Add..., Select GestureTutorial

3. Because of limitations in Android libraries, this isn't all you'd have to do like normal. The gif files are in the assets folder of GestureTutorial and must be moved to your own projects assets folder. This is currently the only way it's supported.

Bugs
----
Expand Down
Binary file modified assets/LeftToRight.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/RightToLeft.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/doubletap.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/downtoup.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/singletap.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/uptodown.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion bin/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme"
android:hardwareAccelerated="true" >
</application>

</manifest>
Binary file modified bin/classes/com/gesturetutorial/awesomeness/TutorialView.class
Binary file not shown.
Binary file modified bin/gesturetutorial.jar
Binary file not shown.
150 changes: 92 additions & 58 deletions src/com/gesturetutorial/awesomeness/TutorialView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,32 @@

import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class TutorialView extends WebView {
import java.io.IOException;

public class TutorialView extends WebView implements OnTouchListener {

// Swipe Types.
final public static int LeftToRight = 0;
final public static int RightToLeft = 1;
final public static int Pinch = 2;
final public static int UpToDown = 3;
final public static int DownToUp = 4;
final public static int SingleFingerTap = 5;
final public static int DoubleFingerTap = 6;

// Swipe Locations.
final public static int UpperLeft = 0;
final public static int UpperCenter = 1;
final public static int UpperRight = 2;
Expand All @@ -34,50 +41,53 @@ public class TutorialView extends WebView {

private static final String TAG = "TutorialView";

private static int swipeWidth = 550, swipeHeight = 550;

/*
* Start an animation corresponding to the given Swipe and Location.
* @param s A Swipe type you'd like to display to the user.
* @param l A Location on the screen you want the tutorial to appear.
* @param activity A activity we can use.
* @param swipe A Swipe type you'd like to display to the user.
* @param location A Location on the screen you want the tutorial to appear.
* @param view A View that you want to add the tutorial to. You can use
* findViewById(android.R.id.content).
*/
public static TutorialView create(final Activity a, final int swipe, final int location,
final View v)
public static TutorialView create(final Activity activity, final int swipe, final int location,
final View view)
{
final TutorialView tv = new TutorialView(a);

final FrameLayout fl = new FrameLayout(a);
fl.addView(tv);

final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
final FrameLayout.LayoutParams rlp = new FrameLayout.LayoutParams(400, 550);
rlp.height = 400;
rlp.width = 550;
// 550 X 400
rlp.gravity = locationToGravity(location);
// rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, v.getId());
// rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, v.getId());
tv.setLayoutParams(rlp);
((ViewGroup) v).addView(fl, rlp);
final TutorialView tv = new TutorialView(activity);

final FrameLayout fl = new FrameLayout(activity);
fl.addView(tv, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
// tv.loadUrl(swipeToAsset(swipe));
Log.d(TAG, swipeWidth + " " + swipeHeight);
tv.loadUrl(swipeToAsset(swipe));
final FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(swipeWidth, swipeHeight);
flp.gravity = locationToGravity(location);
tv.setLayoutParams(flp);
((ViewGroup) view).addView(fl, flp);
// tv.loadUrl(swipeToAsset(swipe));

// final AssetManager mgr = activity.getAssets();
// displayFiles(mgr, "");

return tv;
}

/*
* Start an animation corresponding to the given Swipe and Location.
* @param s A Swipe type you'd like to display to the user.
* @param l A Location on the screen you want the tutorial to appear.
*/
public static TutorialView create(final Activity a, final int s, final int l,
final View v, final ViewGroup.LayoutParams lp)
{
final TutorialView tv = new TutorialView(a);
// 550 X 400
((ViewGroup) v).addView(tv, lp);
final String url = "file:///android_asset/" + s;
tv.loadUrl(url);
static void displayFiles(final AssetManager mgr, final String path) {
try {
final String list[] = mgr.list(path);
if (list != null) {
for (int i = 0; i < list.length; ++i)
{
Log.v("Assets:", path + "/" + list[i]);
displayFiles(mgr, path + "/" + list[i]);
}
}
} catch (final IOException e) {
Log.v("List error:", "can't list" + path);
}

return tv;
}

private static int locationToGravity(final int location)
Expand Down Expand Up @@ -111,69 +121,93 @@ private static String swipeToAsset(final int swipe) {
String url = "file:///android_asset/";
switch (swipe)
{
case 0:
url += "LeftToRight.gif";
case TutorialView.LeftToRight:
swipeWidth = 550;
swipeHeight = 315;
url += "lefttoright.gif";
break;

case 1:
url += "RightToLeft.gif";
case TutorialView.RightToLeft:
swipeWidth = 550;
swipeHeight = 307;
url += "righttoleft.gif";
break;

case 2:
url += "Pinch.gif";
case TutorialView.Pinch:
Log.e(TAG, "Pinch is not supported!");
swipeWidth = 0;
swipeHeight = 0;
url += "test.gif";
break;

case 3:
url += "UpToDown.gif";
case TutorialView.UpToDown:
swipeWidth = 266;
swipeHeight = 509;
url += "uptodown.gif";
break;

case 4:
url += "DownToUp.gif";
case TutorialView.DownToUp:
swipeWidth = 267;
swipeHeight = 500;
url += "downtoup.gif";
break;

case 5:
url += "SingleFingerTap.gif";
case TutorialView.SingleFingerTap:
swipeWidth = 267;
swipeHeight = 318;
url += "singletap.gif";
break;

case 6:
url += "DoubleFingerTap.gif";
case TutorialView.DoubleFingerTap:
swipeWidth = 275;
swipeHeight = 340;
url += "doubletap.gif";
break;
default:
swipeWidth = 0;
swipeHeight = 0;
url += "test.gif";
break;

}
return url;
}

private final Context myContext;

public TutorialView(final Context context) {
super(context);
this.myContext = context;
this.setBackgroundColor(Color.TRANSPARENT);
this.init();
}

public TutorialView(final Context context, final AttributeSet attrs) {
super(context, attrs);
this.myContext = context;
this.setBackgroundColor(Color.TRANSPARENT);
this.init();
}

public TutorialView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
this.myContext = context;
this.setBackgroundColor(Color.TRANSPARENT);
this.init();
}

public void hide()
{
this.setVisibility(View.INVISIBLE);
this.clearCache(true);
}

private void init() {
this.setBackgroundColor(Color.TRANSPARENT); // Background color
this.setInitialScale(100); // Make whole image viewable.
}

@Override
public boolean onTouch(final View arg0, final MotionEvent arg1) {
return true; // Ignore touches.
}

public TutorialView show()
{
this.setVisibility(View.VISIBLE);
return this;
}

}

0 comments on commit c3765f5

Please sign in to comment.