Skip to content

add the Activity States Tutorial source code #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions Android_Beginners/010_States of an Activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.apps.gabothekiller.myapplication;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.util.Log;

public class MainActivity extends ActionBarActivity {

private static final String TAG = "buckysMessage";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG, "onCreate");
}

@Override
protected void onStart() {
super.onStart();
Log.i(TAG, "onStart");
}


@Override
protected void onResume() {
super.onResume();
Log.i(TAG, "onResume");
}


@Override
protected void onPause() {
super.onPause();
Log.i(TAG, "onPause");
}


@Override
protected void onStop() {
super.onStop();
Log.i(TAG, "onStop");
}


@Override
protected void onRestart() {
super.onRestart();
Log.i(TAG, "onRestart");
}


@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG, "onDestroy");
}


@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.i(TAG, "onSaveInstanceState");
}


@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.i(TAG, "onRestoreInstanceState");
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
20 changes: 20 additions & 0 deletions Android_Beginners/010_States of an Activity/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/sadfasd"
android:background="#2334ff">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="the new boston"
android:id="@+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="#FFFFFF" />

</RelativeLayout>
113 changes: 113 additions & 0 deletions Android_Beginners/021-022_Gestures App/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.thenewboston.swiperdiaper;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.view.MotionEvent;
import android.view.GestureDetector;
import android.support.v4.view.GestureDetectorCompat;


public class MainActivity extends ActionBarActivity implements GestureDetector.OnGestureListener,
GestureDetector.OnDoubleTapListener {
private TextView buckysMessage;
private GestureDetectorCompat gestureDetector;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

buckysMessage = (TextView) findViewById(R.id.buckysMessage);
this.gestureDetector = new GestureDetectorCompat(this, this);
gestureDetector.setOnDoubleTapListener(this);
}

///////// GESTURE METHODS //////////
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
buckysMessage.setText("onSingleTapConfirmed");
return true;
}

@Override
public boolean onDoubleTap(MotionEvent e) {
buckysMessage.setText("onDoubleTap");
return true;
}

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
buckysMessage.setText("onDoubleTapEvent");
return true;
}

@Override
public boolean onDown(MotionEvent e) {
buckysMessage.setText("onDown");
return true;
}

@Override
public void onShowPress(MotionEvent e) {
buckysMessage.setText("onShowPress");

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
buckysMessage.setText("onSingleTapUp");
return true;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
buckysMessage.setText("onScroll");
return true;
}

@Override
public void onLongPress(MotionEvent e) {
buckysMessage.setText("onLongPress");

}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
buckysMessage.setText("onFling");
return true;
}

///////// GESTURE METHODS //////////


@Override
public boolean onTouchEvent(MotionEvent event) {
this.gestureDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
16 changes: 16 additions & 0 deletions Android_Beginners/021-022_Gestures App/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="hello"
android:id="@+id/buckysMessage"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
48 changes: 48 additions & 0 deletions Android_Beginners/037_SendingBroadcastIntents/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.thenewboston.sendbroadcast;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Intent;
import android.view.View;


public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void sendBroadcast(View view){
Intent i = new Intent();
i.setAction("com.thenewboston.sendbroadcast");
i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(i);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
19 changes: 19 additions & 0 deletions Android_Beginners/037_SendingBroadcastIntents/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#FFD700"
android:id="@+id/layout">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Broadcast"
android:id="@+id/sendButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:onClick="sendBroadcast" />

</RelativeLayout>