Skip to content

Commit 8ecb7bb

Browse files
committed
Merge pull request buckyroberts#43 from gabothekiller/master
add the Activity States Tutorial source code
2 parents db6ef60 + fe76eae commit 8ecb7bb

File tree

6 files changed

+313
-0
lines changed

6 files changed

+313
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.apps.gabothekiller.myapplication;
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.util.Log;
8+
9+
public class MainActivity extends ActionBarActivity {
10+
11+
private static final String TAG = "buckysMessage";
12+
13+
@Override
14+
protected void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
setContentView(R.layout.activity_main);
17+
Log.i(TAG, "onCreate");
18+
}
19+
20+
@Override
21+
protected void onStart() {
22+
super.onStart();
23+
Log.i(TAG, "onStart");
24+
}
25+
26+
27+
@Override
28+
protected void onResume() {
29+
super.onResume();
30+
Log.i(TAG, "onResume");
31+
}
32+
33+
34+
@Override
35+
protected void onPause() {
36+
super.onPause();
37+
Log.i(TAG, "onPause");
38+
}
39+
40+
41+
@Override
42+
protected void onStop() {
43+
super.onStop();
44+
Log.i(TAG, "onStop");
45+
}
46+
47+
48+
@Override
49+
protected void onRestart() {
50+
super.onRestart();
51+
Log.i(TAG, "onRestart");
52+
}
53+
54+
55+
@Override
56+
protected void onDestroy() {
57+
super.onDestroy();
58+
Log.i(TAG, "onDestroy");
59+
}
60+
61+
62+
@Override
63+
protected void onSaveInstanceState(Bundle outState) {
64+
super.onSaveInstanceState(outState);
65+
Log.i(TAG, "onSaveInstanceState");
66+
}
67+
68+
69+
@Override
70+
protected void onRestoreInstanceState(Bundle savedInstanceState) {
71+
super.onRestoreInstanceState(savedInstanceState);
72+
Log.i(TAG, "onRestoreInstanceState");
73+
}
74+
75+
76+
@Override
77+
public boolean onCreateOptionsMenu(Menu menu) {
78+
// Inflate the menu; this adds items to the action bar if it is present.
79+
getMenuInflater().inflate(R.menu.menu_main, menu);
80+
return true;
81+
}
82+
83+
@Override
84+
public boolean onOptionsItemSelected(MenuItem item) {
85+
// Handle action bar item clicks here. The action bar will
86+
// automatically handle clicks on the Home/Up button, so long
87+
// as you specify a parent activity in AndroidManifest.xml.
88+
int id = item.getItemId();
89+
90+
//noinspection SimplifiableIfStatement
91+
if (id == R.id.action_settings) {
92+
return true;
93+
}
94+
95+
return super.onOptionsItemSelected(item);
96+
}
97+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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:id="@+id/sadfasd"
8+
android:background="#2334ff">
9+
10+
<TextView
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:textAppearance="?android:attr/textAppearanceLarge"
14+
android:text="the new boston"
15+
android:id="@+id/textView"
16+
android:layout_centerVertical="true"
17+
android:layout_centerHorizontal="true"
18+
android:textColor="#FFFFFF" />
19+
20+
</RelativeLayout>
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)