-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
221 changed files
with
223 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/kk" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" > | ||
android:layout_height="match_parent" | ||
android:orientation="horizontal" | ||
android:background="#ffffff" > | ||
|
||
<ImageView | ||
android:id="@+id/imageView1" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentLeft="true" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentTop="true" | ||
android:src="@drawable/sun" | ||
|
||
android:contentDescription="A filler image" /> | ||
|
||
android:id="@+id/im" | ||
android:layout_width="400px" | ||
android:layout_height="400px" | ||
android:layout_marginTop="200px" | ||
android:adjustViewBounds="true" | ||
/> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 131 additions & 20 deletions
151
PenPal/src/edu/berkeley/cs160/off_by_1/DrawMessageFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,143 @@ | ||
package edu.berkeley.cs160.off_by_1; | ||
|
||
|
||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import android.app.Activity; | ||
import android.app.Fragment; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.graphics.Path; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.View.OnTouchListener; | ||
import android.view.ViewGroup.LayoutParams; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.ImageView; | ||
import android.widget.RelativeLayout; | ||
import android.widget.Toast; | ||
|
||
public class DrawMessageFragment extends MessageFragment { | ||
CustomView CusView; | ||
public Context context; | ||
CustomView first = null; | ||
CustomView Second = null; | ||
CustomView Third = null; | ||
OnTouchListener touchListener; | ||
int color = Color.BLACK; | ||
RelativeLayout layout; | ||
private Paint paint = new Paint(); | ||
private Path path = new Path(); | ||
ImageView image; | ||
ArrayList<View> views; | ||
Map<Path, Paint> pathMap; | ||
Context act; | ||
|
||
public class CustomView extends View { | ||
public CustomView(Context context) { | ||
super(context); | ||
Log.d("debug", "crashed?"); | ||
paint.setAntiAlias(true); | ||
paint.setColor(color); | ||
paint.setStyle(Paint.Style.STROKE); | ||
paint.setStrokeWidth(12); | ||
} | ||
|
||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
canvas.drawPath(path, paint); | ||
super.onDraw(canvas); | ||
for (Map.Entry<Path, Paint> p : pathMap.entrySet()) { | ||
canvas.drawPath(p.getKey(), p.getValue()); | ||
} | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.draw_message, container, false); | ||
} | ||
|
||
Intent getIntent() { | ||
Intent i = new Intent(); | ||
//i.putExtra("msg", msg); | ||
return i; | ||
|
||
} | ||
|
||
void clear() { | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void onAttach(Activity activity) { | ||
super.onAttach(activity); | ||
act = activity; | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
Log.d("debug", "before view"); | ||
Log.d("debug", "here"); | ||
if (act == null) { | ||
Log.d("debug", "it's nulllllllllllllllllllllllllllllllll"); | ||
} else { | ||
Log.d("debug", "itllll"); | ||
} | ||
CusView = new CustomView(act); | ||
View v = inflater.inflate(R.layout.draw_message, container, false); | ||
layout = (RelativeLayout) v.findViewById(R.id.kk); | ||
views = new ArrayList<View>(); | ||
pathMap = new HashMap<Path, Paint>(); | ||
Log.d("debug", "generated view"); | ||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, | ||
LayoutParams.WRAP_CONTENT); | ||
CusView.setLayoutParams(params); | ||
layout.addView(CusView); | ||
touchListener = new OnTouchListener() { | ||
public boolean onTouch(View v, MotionEvent event) { | ||
CusView.setDrawingCacheEnabled(true); | ||
float eventX = event.getX(); | ||
float eventY = event.getY(); | ||
switch (event.getAction()) { | ||
case MotionEvent.ACTION_DOWN: | ||
path = new Path(); | ||
path.reset(); | ||
path.moveTo(eventX, eventY); | ||
break; | ||
case MotionEvent.ACTION_MOVE: | ||
case MotionEvent.ACTION_UP: | ||
Paint newPaint = new Paint(); | ||
newPaint.set(paint); | ||
pathMap.put(path, newPaint); | ||
path.lineTo(eventX, eventY); | ||
break; | ||
} // ends switch statement | ||
CusView.invalidate(); | ||
return true; | ||
} | ||
}; | ||
CusView.setOnTouchListener(touchListener); | ||
return v; | ||
} | ||
|
||
public void clear() { | ||
for (Map.Entry<Path, Paint> p : pathMap.entrySet()) { | ||
p.getKey().rewind(); | ||
CusView.invalidate(); | ||
CusView.setDrawingCacheEnabled(false); | ||
} | ||
} | ||
|
||
|
||
Intent getIntent() { | ||
String msg = ""; | ||
Intent i = new Intent(); | ||
i.putExtra("msg", msg); | ||
return i; | ||
} | ||
} |
Oops, something went wrong.