Skip to content

Instantly share code, notes, and snippets.

Created April 14, 2013 17:54
Show Gist options
  • Save anonymous/5383594 to your computer and use it in GitHub Desktop.
Save anonymous/5383594 to your computer and use it in GitHub Desktop.
XML and Java code. Sets the Layout of the activity.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/clipboardLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/colorbballcourt"
android:orientation="vertical"
tools:context=".ClipboardActivity" >
<android.gesture.GestureOverlayView
android:id="@+id/gestures"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeEnabled="false"
android:fadeOffset="5000000000"
android:gestureColor="#000000"
android:gestureStrokeType="multiple"
android:gestureStrokeWidth="3"
android:uncertainGestureColor="#000000" >
</android.gesture.GestureOverlayView>
</RelativeLayout>
<LinearLayout
android:id="@+id/colorButtonLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/blueColor"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="setBlueInk"
android:text="@string/blue" />
<Button
android:id="@+id/redColor"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="setRedInk"
android:text="@string/red" />
<Button
android:id="@+id/greenColor"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="setGreenInk"
android:text="@string/green" />
<Button
android:id="@+id/eraser"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="eraseInk"
android:text="@string/eraser" />
</LinearLayout>
</LinearLayout>
package com.jeremy.basketballclipboard;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.gesture.GestureOverlayView;
import android.graphics.Color;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.RelativeLayout;
import android.support.v4.app.NavUtils;
public class ClipboardActivity extends Activity implements OnTouchListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_clipboard);
// Show the Up button in the action bar.
setupActionBar();
}
/**
* Set up the {@link android.app.ActionBar}.
*/
private void setupActionBar() {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.clipboard, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.action_new_clipboard:
newClipboard();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void newClipboard() {
Intent intent = getIntent();
finish();
startActivity(intent);
// GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
// gestures.clear(true);
}
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
return false;
}
public void setBlueInk(View view){
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.setGestureColor(Color.BLUE);
}
public void setRedInk(View view){
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.setGestureColor(Color.RED);
}
public void setGreenInk(View view){
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.setGestureColor(Color.GREEN);
}
public void eraseInk(View view){
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.setGestureColor(Color.TRANSPARENT);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment