Skip to content

Commit fe76eae

Browse files
committed
code for tutorials 21-22 and 37
1 parent 83a8056 commit fe76eae

File tree

4 files changed

+196
-0
lines changed

4 files changed

+196
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package com.thenewboston.swiperdiaper;
2+
3+
import android.support.v7.app.ActionBarActivity;
4+
import android.os.Bundle;
5+
import android.view.Menu;
6+
import android.view.MenuItem;
7+
import android.widget.TextView;
8+
import android.view.MotionEvent;
9+
import android.view.GestureDetector;
10+
import android.support.v4.view.GestureDetectorCompat;
11+
12+
13+
public class MainActivity extends ActionBarActivity implements GestureDetector.OnGestureListener,
14+
GestureDetector.OnDoubleTapListener {
15+
private TextView buckysMessage;
16+
private GestureDetectorCompat gestureDetector;
17+
18+
@Override
19+
protected void onCreate(Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
setContentView(R.layout.activity_main);
22+
23+
buckysMessage = (TextView) findViewById(R.id.buckysMessage);
24+
this.gestureDetector = new GestureDetectorCompat(this, this);
25+
gestureDetector.setOnDoubleTapListener(this);
26+
}
27+
28+
///////// GESTURE METHODS //////////
29+
@Override
30+
public boolean onSingleTapConfirmed(MotionEvent e) {
31+
buckysMessage.setText("onSingleTapConfirmed");
32+
return true;
33+
}
34+
35+
@Override
36+
public boolean onDoubleTap(MotionEvent e) {
37+
buckysMessage.setText("onDoubleTap");
38+
return true;
39+
}
40+
41+
@Override
42+
public boolean onDoubleTapEvent(MotionEvent e) {
43+
buckysMessage.setText("onDoubleTapEvent");
44+
return true;
45+
}
46+
47+
@Override
48+
public boolean onDown(MotionEvent e) {
49+
buckysMessage.setText("onDown");
50+
return true;
51+
}
52+
53+
@Override
54+
public void onShowPress(MotionEvent e) {
55+
buckysMessage.setText("onShowPress");
56+
57+
}
58+
59+
@Override
60+
public boolean onSingleTapUp(MotionEvent e) {
61+
buckysMessage.setText("onSingleTapUp");
62+
return true;
63+
}
64+
65+
@Override
66+
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
67+
buckysMessage.setText("onScroll");
68+
return true;
69+
}
70+
71+
@Override
72+
public void onLongPress(MotionEvent e) {
73+
buckysMessage.setText("onLongPress");
74+
75+
}
76+
77+
@Override
78+
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
79+
buckysMessage.setText("onFling");
80+
return true;
81+
}
82+
83+
///////// GESTURE METHODS //////////
84+
85+
86+
@Override
87+
public boolean onTouchEvent(MotionEvent event) {
88+
this.gestureDetector.onTouchEvent(event);
89+
return super.onTouchEvent(event);
90+
}
91+
92+
@Override
93+
public boolean onCreateOptionsMenu(Menu menu) {
94+
// Inflate the menu; this adds items to the action bar if it is present.
95+
getMenuInflater().inflate(R.menu.menu_main, menu);
96+
return true;
97+
}
98+
99+
@Override
100+
public boolean onOptionsItemSelected(MenuItem item) {
101+
// Handle action bar item clicks here. The action bar will
102+
// automatically handle clicks on the Home/Up button, so long
103+
// as you specify a parent activity in AndroidManifest.xml.
104+
int id = item.getItemId();
105+
106+
//noinspection SimplifiableIfStatement
107+
if (id == R.id.action_settings) {
108+
return true;
109+
}
110+
111+
return super.onOptionsItemSelected(item);
112+
}
113+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
3+
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
4+
android:paddingRight="@dimen/activity_horizontal_margin"
5+
android:paddingTop="@dimen/activity_vertical_margin"
6+
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
7+
8+
<TextView
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:textAppearance="?android:attr/textAppearanceLarge"
12+
android:text="hello"
13+
android:id="@+id/buckysMessage"
14+
android:layout_centerVertical="true"
15+
android:layout_centerHorizontal="true" />
16+
</RelativeLayout>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.thenewboston.sendbroadcast;
2+
3+
import android.support.v7.app.ActionBarActivity;
4+
import android.os.Bundle;
5+
import android.view.Menu;
6+
import android.view.MenuItem;
7+
import android.content.Intent;
8+
import android.view.View;
9+
10+
11+
public class MainActivity extends ActionBarActivity {
12+
13+
@Override
14+
protected void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
setContentView(R.layout.activity_main);
17+
}
18+
19+
public void sendBroadcast(View view){
20+
Intent i = new Intent();
21+
i.setAction("com.thenewboston.sendbroadcast");
22+
i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
23+
sendBroadcast(i);
24+
}
25+
26+
27+
@Override
28+
public boolean onCreateOptionsMenu(Menu menu) {
29+
// Inflate the menu; this adds items to the action bar if it is present.
30+
getMenuInflater().inflate(R.menu.menu_main, menu);
31+
return true;
32+
}
33+
34+
@Override
35+
public boolean onOptionsItemSelected(MenuItem item) {
36+
// Handle action bar item clicks here. The action bar will
37+
// automatically handle clicks on the Home/Up button, so long
38+
// as you specify a parent activity in AndroidManifest.xml.
39+
int id = item.getItemId();
40+
41+
//noinspection SimplifiableIfStatement
42+
if (id == R.id.action_settings) {
43+
return true;
44+
}
45+
46+
return super.onOptionsItemSelected(item);
47+
}
48+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
3+
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
4+
android:paddingRight="@dimen/activity_horizontal_margin"
5+
android:paddingTop="@dimen/activity_vertical_margin"
6+
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
7+
android:background="#FFD700"
8+
android:id="@+id/layout">
9+
10+
<Button
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text="Send Broadcast"
14+
android:id="@+id/sendButton"
15+
android:layout_centerVertical="true"
16+
android:layout_centerHorizontal="true"
17+
android:onClick="sendBroadcast" />
18+
19+
</RelativeLayout>

0 commit comments

Comments
 (0)