diff --git a/BroadcasrReceiverTutorial2/app/.gitignore b/BroadcasrReceiverTutorial2/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/BroadcasrReceiverTutorial2/app/app.iml b/BroadcasrReceiverTutorial2/app/app.iml new file mode 100644 index 0000000..9724666 --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/app.iml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BroadcasrReceiverTutorial2/app/build.gradle b/BroadcasrReceiverTutorial2/app/build.gradle new file mode 100644 index 0000000..d215175 --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + applicationId "de.vogella.android.alarm" + minSdkVersion 16 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:21.0.3' +} diff --git a/BroadcasrReceiverTutorial2/app/proguard-rules.pro b/BroadcasrReceiverTutorial2/app/proguard-rules.pro new file mode 100644 index 0000000..142abec --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\winsxx\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/BroadcasrReceiverTutorial2/app/src/androidTest/java/de/vogella/android/alarm/ApplicationTest.java b/BroadcasrReceiverTutorial2/app/src/androidTest/java/de/vogella/android/alarm/ApplicationTest.java new file mode 100644 index 0000000..1a990bb --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/androidTest/java/de/vogella/android/alarm/ApplicationTest.java @@ -0,0 +1,13 @@ +package de.vogella.android.alarm; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/BroadcasrReceiverTutorial2/app/src/main/AndroidManifest.xml b/BroadcasrReceiverTutorial2/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..bc92a91 --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + diff --git a/BroadcasrReceiverTutorial2/app/src/main/java/de/vogella/android/alarm/AlarmActivity.java b/BroadcasrReceiverTutorial2/app/src/main/java/de/vogella/android/alarm/AlarmActivity.java new file mode 100644 index 0000000..19e626a --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/main/java/de/vogella/android/alarm/AlarmActivity.java @@ -0,0 +1,34 @@ +package de.vogella.android.alarm; + +import android.app.Activity; +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +public class AlarmActivity extends Activity { + + /** Called when the activity is first created. */ + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_alarm); + } + + public void startAlert(View view) { + EditText text = (EditText) findViewById(R.id.time); + int i = Integer.parseInt(text.getText().toString()); + Intent intent = new Intent(this, MyBroadcastReceiver.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 234324243, intent, 0); + AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); + alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + + (i * 1000), pendingIntent); + Toast.makeText(this, "Alarm set in " + i + " seconds", + Toast.LENGTH_LONG).show(); + } + +} \ No newline at end of file diff --git a/BroadcasrReceiverTutorial2/app/src/main/java/de/vogella/android/alarm/MyBroadcastReceiver.java b/BroadcasrReceiverTutorial2/app/src/main/java/de/vogella/android/alarm/MyBroadcastReceiver.java new file mode 100644 index 0000000..501aaf7 --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/main/java/de/vogella/android/alarm/MyBroadcastReceiver.java @@ -0,0 +1,21 @@ +package de.vogella.android.alarm; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Vibrator; +import android.widget.Toast; + +public class MyBroadcastReceiver extends BroadcastReceiver { + public MyBroadcastReceiver() { + } + + @Override + public void onReceive(Context context, Intent intent) { + Toast.makeText(context, "Don't panic but your time is up!!!!.", + Toast.LENGTH_LONG).show(); + // Vibrate the mobile phone + Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + vibrator.vibrate(2000); + } +} diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/drawable-hdpi/ic_launcher.png b/BroadcasrReceiverTutorial2/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..96a442e Binary files /dev/null and b/BroadcasrReceiverTutorial2/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/drawable-mdpi/ic_launcher.png b/BroadcasrReceiverTutorial2/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..359047d Binary files /dev/null and b/BroadcasrReceiverTutorial2/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/drawable-xhdpi/ic_launcher.png b/BroadcasrReceiverTutorial2/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..71c6d76 Binary files /dev/null and b/BroadcasrReceiverTutorial2/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/BroadcasrReceiverTutorial2/app/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..4df1894 Binary files /dev/null and b/BroadcasrReceiverTutorial2/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/layout/activity_alarm.xml b/BroadcasrReceiverTutorial2/app/src/main/res/layout/activity_alarm.xml new file mode 100644 index 0000000..145689d --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/main/res/layout/activity_alarm.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/menu/menu_alarm.xml b/BroadcasrReceiverTutorial2/app/src/main/res/menu/menu_alarm.xml new file mode 100644 index 0000000..aed6bc4 --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/main/res/menu/menu_alarm.xml @@ -0,0 +1,6 @@ + + + diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/values-w820dp/dimens.xml b/BroadcasrReceiverTutorial2/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/values/dimens.xml b/BroadcasrReceiverTutorial2/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/values/strings.xml b/BroadcasrReceiverTutorial2/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..eb8be6d --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/main/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + Alarm Receiver + Hello world! + Settings + + diff --git a/BroadcasrReceiverTutorial2/app/src/main/res/values/styles.xml b/BroadcasrReceiverTutorial2/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..766ab99 --- /dev/null +++ b/BroadcasrReceiverTutorial2/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/BroadcastReceiverTutorial/app/.gitignore b/BroadcastReceiverTutorial/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/BroadcastReceiverTutorial/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/BroadcastReceiverTutorial/app/app.iml b/BroadcastReceiverTutorial/app/app.iml new file mode 100644 index 0000000..9724666 --- /dev/null +++ b/BroadcastReceiverTutorial/app/app.iml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BroadcastReceiverTutorial/app/build.gradle b/BroadcastReceiverTutorial/app/build.gradle new file mode 100644 index 0000000..542ad73 --- /dev/null +++ b/BroadcastReceiverTutorial/app/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + applicationId "de.vogella.android.receiver.phone" + minSdkVersion 16 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:21.0.3' +} diff --git a/BroadcastReceiverTutorial/app/proguard-rules.pro b/BroadcastReceiverTutorial/app/proguard-rules.pro new file mode 100644 index 0000000..142abec --- /dev/null +++ b/BroadcastReceiverTutorial/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\winsxx\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/BroadcastReceiverTutorial/app/src/androidTest/java/de/vogella/android/receiver/phone/ApplicationTest.java b/BroadcastReceiverTutorial/app/src/androidTest/java/de/vogella/android/receiver/phone/ApplicationTest.java new file mode 100644 index 0000000..32cec34 --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/androidTest/java/de/vogella/android/receiver/phone/ApplicationTest.java @@ -0,0 +1,13 @@ +package de.vogella.android.receiver.phone; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/BroadcastReceiverTutorial/app/src/main/AndroidManifest.xml b/BroadcastReceiverTutorial/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..f25ec33 --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/main/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/BroadcastReceiverTutorial/app/src/main/java/de/vogella/android/receiver/phone/MainActivity.java b/BroadcastReceiverTutorial/app/src/main/java/de/vogella/android/receiver/phone/MainActivity.java new file mode 100644 index 0000000..283b7e2 --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/main/java/de/vogella/android/receiver/phone/MainActivity.java @@ -0,0 +1,39 @@ +package de.vogella.android.receiver.phone; + +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + + +public class MainActivity extends ActionBarActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + + + @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); + } +} diff --git a/BroadcastReceiverTutorial/app/src/main/java/de/vogella/android/receiver/phone/MyPhoneReceiver.java b/BroadcastReceiverTutorial/app/src/main/java/de/vogella/android/receiver/phone/MyPhoneReceiver.java new file mode 100644 index 0000000..f81fa50 --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/main/java/de/vogella/android/receiver/phone/MyPhoneReceiver.java @@ -0,0 +1,28 @@ +package de.vogella.android.receiver.phone; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.telecom.TelecomManager; +import android.telephony.TelephonyManager; +import android.util.Log; + +public class MyPhoneReceiver extends BroadcastReceiver { + public MyPhoneReceiver() { + } + + @Override + public void onReceive(Context context, Intent intent) { + Bundle extras = intent.getExtras(); + + if (extras != null) { + String state = extras.getString(TelephonyManager.EXTRA_STATE); + Log.w("MY_DEBUG_TAG", state); + if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { + String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); + Log.w("MY_DEBUG_TAG", phoneNumber); + } + } + } +} diff --git a/BroadcastReceiverTutorial/app/src/main/res/drawable-hdpi/ic_launcher.png b/BroadcastReceiverTutorial/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..96a442e Binary files /dev/null and b/BroadcastReceiverTutorial/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/BroadcastReceiverTutorial/app/src/main/res/drawable-mdpi/ic_launcher.png b/BroadcastReceiverTutorial/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..359047d Binary files /dev/null and b/BroadcastReceiverTutorial/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/BroadcastReceiverTutorial/app/src/main/res/drawable-xhdpi/ic_launcher.png b/BroadcastReceiverTutorial/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..71c6d76 Binary files /dev/null and b/BroadcastReceiverTutorial/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/BroadcastReceiverTutorial/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/BroadcastReceiverTutorial/app/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..4df1894 Binary files /dev/null and b/BroadcastReceiverTutorial/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/BroadcastReceiverTutorial/app/src/main/res/layout/activity_main.xml b/BroadcastReceiverTutorial/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..794e2bb --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/BroadcastReceiverTutorial/app/src/main/res/menu/menu_main.xml b/BroadcastReceiverTutorial/app/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000..f979f13 --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/main/res/menu/menu_main.xml @@ -0,0 +1,10 @@ + + + diff --git a/BroadcastReceiverTutorial/app/src/main/res/values-w820dp/dimens.xml b/BroadcastReceiverTutorial/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/BroadcastReceiverTutorial/app/src/main/res/values/dimens.xml b/BroadcastReceiverTutorial/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/BroadcastReceiverTutorial/app/src/main/res/values/strings.xml b/BroadcastReceiverTutorial/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..c1a613f --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/main/res/values/strings.xml @@ -0,0 +1,9 @@ + + + + BroadcastReceiver Tutorial + MainActivity + Hello world! + Settings + + diff --git a/BroadcastReceiverTutorial/app/src/main/res/values/styles.xml b/BroadcastReceiverTutorial/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..766ab99 --- /dev/null +++ b/BroadcastReceiverTutorial/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/IntentTutorial/app/.gitignore b/IntentTutorial/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/IntentTutorial/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/IntentTutorial/app/app.iml b/IntentTutorial/app/app.iml new file mode 100644 index 0000000..9724666 --- /dev/null +++ b/IntentTutorial/app/app.iml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/IntentTutorial/app/build.gradle b/IntentTutorial/app/build.gradle new file mode 100644 index 0000000..beeff0b --- /dev/null +++ b/IntentTutorial/app/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + applicationId "com.vogella.android.intent.explicit" + minSdkVersion 16 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:21.0.3' +} diff --git a/IntentTutorial/app/proguard-rules.pro b/IntentTutorial/app/proguard-rules.pro new file mode 100644 index 0000000..142abec --- /dev/null +++ b/IntentTutorial/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\winsxx\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/IntentTutorial/app/src/androidTest/java/com/vogella/android/intent/explicit/ApplicationTest.java b/IntentTutorial/app/src/androidTest/java/com/vogella/android/intent/explicit/ApplicationTest.java new file mode 100644 index 0000000..057b189 --- /dev/null +++ b/IntentTutorial/app/src/androidTest/java/com/vogella/android/intent/explicit/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.vogella.android.intent.explicit; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/IntentTutorial/app/src/main/AndroidManifest.xml b/IntentTutorial/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..3899e48 --- /dev/null +++ b/IntentTutorial/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/IntentTutorial/app/src/main/java/com/vogella/android/intent/explicit/MainActivity.java b/IntentTutorial/app/src/main/java/com/vogella/android/intent/explicit/MainActivity.java new file mode 100644 index 0000000..a318ba8 --- /dev/null +++ b/IntentTutorial/app/src/main/java/com/vogella/android/intent/explicit/MainActivity.java @@ -0,0 +1,42 @@ +package com.vogella.android.intent.explicit; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; + +public class MainActivity extends Activity { + + private static final int REQUEST_CODE = 10; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + + public void onClick(View view) { + EditText text = (EditText) findViewById(R.id.inputforintent); + // used later + String value = text.getText().toString(); + + Intent intent = new Intent(this, ResultActivity.class); + intent.putExtra("mainText", value); + + startActivityForResult(intent, REQUEST_CODE); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) { + if (data.hasExtra("returnString")) { + String result = data.getExtras().getString("returnString"); + if (result != null && result.length() > 0) { + Toast.makeText(this, result, Toast.LENGTH_SHORT).show(); + } + } + } + } +} \ No newline at end of file diff --git a/IntentTutorial/app/src/main/java/com/vogella/android/intent/explicit/ResultActivity.java b/IntentTutorial/app/src/main/java/com/vogella/android/intent/explicit/ResultActivity.java new file mode 100644 index 0000000..0fb8a75 --- /dev/null +++ b/IntentTutorial/app/src/main/java/com/vogella/android/intent/explicit/ResultActivity.java @@ -0,0 +1,37 @@ +package com.vogella.android.intent.explicit; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.widget.EditText; +import android.widget.TextView; + +public class ResultActivity extends Activity { + + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + setContentView(R.layout.activity_result); + + Bundle extras = getIntent().getExtras(); + String toBeShownText = extras.getString("mainText"); + + TextView textView = (TextView) findViewById(R.id.displayintentextra); + textView.setText(toBeShownText); + } + + @Override + public void finish() { + + Intent intent = new Intent(); + + EditText et = (EditText) findViewById(R.id.returnValue); + String returnText = et.getText().toString(); + + intent.putExtra("returnString", returnText); + + setResult(RESULT_OK, intent); + + super.finish(); + } +} \ No newline at end of file diff --git a/IntentTutorial/app/src/main/res/drawable-hdpi/ic_launcher.png b/IntentTutorial/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..96a442e Binary files /dev/null and b/IntentTutorial/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/IntentTutorial/app/src/main/res/drawable-mdpi/ic_launcher.png b/IntentTutorial/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..359047d Binary files /dev/null and b/IntentTutorial/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/IntentTutorial/app/src/main/res/drawable-xhdpi/ic_launcher.png b/IntentTutorial/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..71c6d76 Binary files /dev/null and b/IntentTutorial/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/IntentTutorial/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/IntentTutorial/app/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..4df1894 Binary files /dev/null and b/IntentTutorial/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/IntentTutorial/app/src/main/res/layout/activity_main.xml b/IntentTutorial/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..e25f7b8 --- /dev/null +++ b/IntentTutorial/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + + + + + + \ No newline at end of file diff --git a/IntentTutorial4/app/src/main/res/menu/menu_call_intents.xml b/IntentTutorial4/app/src/main/res/menu/menu_call_intents.xml new file mode 100644 index 0000000..8e515e1 --- /dev/null +++ b/IntentTutorial4/app/src/main/res/menu/menu_call_intents.xml @@ -0,0 +1,6 @@ + + + diff --git a/IntentTutorial4/app/src/main/res/values-w820dp/dimens.xml b/IntentTutorial4/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/IntentTutorial4/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/IntentTutorial4/app/src/main/res/values/dimens.xml b/IntentTutorial4/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/IntentTutorial4/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/IntentTutorial4/app/src/main/res/values/strings.xml b/IntentTutorial4/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..199bf6d --- /dev/null +++ b/IntentTutorial4/app/src/main/res/values/strings.xml @@ -0,0 +1,17 @@ + + + + Implicit Intent + Hello world! + Settings + + Open Browser + Call Someone + Dial + Show Map + Search on Map + Take picture + Show contacts + Edit first contact + + diff --git a/IntentTutorial4/app/src/main/res/values/styles.xml b/IntentTutorial4/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..766ab99 --- /dev/null +++ b/IntentTutorial4/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/LifeCycleTutorial/LifeCycleTutorial.iml b/LifeCycleTutorial/LifeCycleTutorial.iml new file mode 100644 index 0000000..2a02201 --- /dev/null +++ b/LifeCycleTutorial/LifeCycleTutorial.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/LifeCycleTutorial/app/app.iml b/LifeCycleTutorial/app/app.iml new file mode 100644 index 0000000..9724666 --- /dev/null +++ b/LifeCycleTutorial/app/app.iml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LifeCycleTutorial/app/src/main/java/com/vogella/android/lifecycle/activity/MainActivity.java b/LifeCycleTutorial/app/src/main/java/com/vogella/android/lifecycle/activity/MainActivity.java new file mode 100644 index 0000000..a4ef20f --- /dev/null +++ b/LifeCycleTutorial/app/src/main/java/com/vogella/android/lifecycle/activity/MainActivity.java @@ -0,0 +1,29 @@ +package com.vogella.android.lifecycle.activity; + + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Spinner; + +public class MainActivity extends TracerActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + // configure the spinner in code + Spinner spinner = (Spinner) findViewById(R.id.spinner); + String[] values = getResources().getStringArray(R.array.operating_systems); + ArrayAdapter adapter = + new ArrayAdapter(this, android.R.layout.simple_list_item_1, values); + spinner.setAdapter(adapter); + } + + public void onClick(View view) { + Intent intent = new Intent(this, SecondActivity.class); + startActivity(intent); + } + +} \ No newline at end of file diff --git a/LifeCycleTutorial/app/src/main/java/com/vogella/android/lifecycle/activity/SecondActivity.java b/LifeCycleTutorial/app/src/main/java/com/vogella/android/lifecycle/activity/SecondActivity.java new file mode 100644 index 0000000..c2a759b --- /dev/null +++ b/LifeCycleTutorial/app/src/main/java/com/vogella/android/lifecycle/activity/SecondActivity.java @@ -0,0 +1,13 @@ +package com.vogella.android.lifecycle.activity; + +import android.os.Bundle; + +public class SecondActivity extends TracerActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_second); + } + +} diff --git a/LifeCycleTutorial/app/src/main/java/com/vogella/android/lifecycle/activity/TracerActivity.java b/LifeCycleTutorial/app/src/main/java/com/vogella/android/lifecycle/activity/TracerActivity.java new file mode 100644 index 0000000..dcf11d8 --- /dev/null +++ b/LifeCycleTutorial/app/src/main/java/com/vogella/android/lifecycle/activity/TracerActivity.java @@ -0,0 +1,65 @@ +package com.vogella.android.lifecycle.activity; + +import android.app.Activity; +import android.app.Notification; +import android.app.NotificationManager; +import android.os.Bundle; + +public class TracerActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + notify("onCreate"); + } + + @Override + protected void onPause() { + super.onPause(); + notify("onPause"); + } + + @Override + protected void onResume() { + super.onResume(); + notify("onResume"); + } + + @Override + protected void onStop() { + super.onStop(); + notify("onStop"); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + notify("onDestroy"); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + notify("onRestoreInstanceState"); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + notify("onSaveInstanceState"); + } + + private void notify(String methodName) { + String name = this.getClass().getName(); + String[] strings = name.split("\\."); + Notification noti = new Notification.Builder(this) + .setContentTitle(methodName + " " + strings[strings.length - 1]).setAutoCancel(true) + .setSmallIcon(R.drawable.ic_launcher) + .setContentText(name).build(); + NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + notificationManager.notify((int) System.currentTimeMillis(), noti); + } + +} + + diff --git a/LifeCycleTutorial/app/src/main/res/layout/activity_main.xml b/LifeCycleTutorial/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..cc75799 --- /dev/null +++ b/LifeCycleTutorial/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,27 @@ + + + + +