Skip to content

Commit fa87fde

Browse files
author
Nilanchal Panigrahy
committed
Consolidated all UI examples into single repo
1 parent e452db3 commit fa87fde

File tree

28 files changed

+707
-0
lines changed

28 files changed

+707
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="java-gradle" name="Java-Gradle">
5+
<configuration>
6+
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
</configuration>
8+
</facet>
9+
</component>
10+
<component name="NewModuleRootManager" inherit-compiler-output="true">
11+
<exclude-output />
12+
<content url="file://$MODULE_DIR$">
13+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
14+
</content>
15+
<orderEntry type="inheritedJdk" />
16+
<orderEntry type="sourceFolder" forTests="false" />
17+
</component>
18+
</module>
19+
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Android-Alarm-Service-Example
2+
=============================
3+
4+
Android Alarm Service Example
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AlarmService" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":app" />
7+
</configuration>
8+
</facet>
9+
<facet type="android" name="Android">
10+
<configuration>
11+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
12+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
13+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
14+
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
15+
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
16+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
17+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
18+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
19+
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
20+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
21+
</configuration>
22+
</facet>
23+
</component>
24+
<component name="NewModuleRootManager" inherit-compiler-output="false">
25+
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
26+
<exclude-output />
27+
<content url="file://$MODULE_DIR$">
28+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
29+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
30+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
31+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
32+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
33+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
38+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
39+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
40+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
41+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
42+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
43+
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
44+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
45+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
48+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
49+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
51+
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
59+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
60+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
61+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
62+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
63+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
64+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
65+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
66+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
67+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
68+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
69+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
70+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
71+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
72+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
73+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
74+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
75+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
76+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
77+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
78+
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
79+
</content>
80+
<orderEntry type="jdk" jdkName="Android API 20 Platform" jdkType="Android SDK" />
81+
<orderEntry type="sourceFolder" forTests="false" />
82+
</component>
83+
</module>
84+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 20
5+
buildToolsVersion "20.0.0"
6+
7+
defaultConfig {
8+
applicationId "com.javatechig.alarmservice"
9+
minSdkVersion 14
10+
targetSdkVersion 20
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
runProguard false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Applications/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.javatechig.alarmservice;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.javatechig.alarmservice" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@drawable/ic_launcher"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme" >
10+
11+
<!-- Permission to start Alarm on device reboot -->
12+
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
13+
14+
<activity
15+
android:name=".MyActivity"
16+
android:label="@string/app_name" >
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
24+
25+
<!-- Will not be called unless the application explicitly enables it -->
26+
<receiver android:name=".DeviceBootReceiver"
27+
android:enabled="false">
28+
<intent-filter>
29+
<action android:name="android.intent.action.BOOT_COMPLETED"/>
30+
</intent-filter>
31+
</receiver>
32+
33+
</application>
34+
35+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.javatechig.alarmservice;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.widget.Toast;
7+
8+
public class AlarmReceiver extends BroadcastReceiver {
9+
10+
@Override
11+
public void onReceive(Context context, Intent intent) {
12+
13+
// For our recurring task, we'll just display a message
14+
Toast.makeText(context, "I'm running", Toast.LENGTH_SHORT).show();
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.javatechig.alarmservice;
2+
3+
import android.app.AlarmManager;
4+
import android.app.PendingIntent;
5+
import android.content.BroadcastReceiver;
6+
import android.content.Context;
7+
import android.content.Intent;
8+
import android.widget.Toast;
9+
10+
11+
/**
12+
* @author Neel
13+
* <p/>
14+
* Broadcast reciever, starts when the device gets starts.
15+
* Start your repeating alarm here.
16+
*/
17+
public class DeviceBootReceiver extends BroadcastReceiver {
18+
19+
@Override
20+
public void onReceive(Context context, Intent intent) {
21+
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
22+
/* Setting the alarm here */
23+
24+
Intent alarmIntent = new Intent(context, AlarmReceiver.class);
25+
26+
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
27+
28+
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
29+
30+
int interval = 8000;
31+
32+
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);
33+
34+
Toast.makeText(context, "Alarm Set", Toast.LENGTH_SHORT).show();
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.javatechig.alarmservice;
2+
3+
import android.app.Activity;
4+
import android.app.AlarmManager;
5+
import android.app.PendingIntent;
6+
import android.content.Context;
7+
import android.content.Intent;
8+
import android.os.Bundle;
9+
import android.view.View;
10+
import android.widget.Toast;
11+
import java.util.Calendar;
12+
13+
//https://developer.android.com/training/scheduling/alarms.html
14+
public class MyActivity extends Activity {
15+
16+
private PendingIntent pendingIntent;
17+
18+
@Override
19+
protected void onCreate(Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
setContentView(R.layout.activity_my);
22+
23+
/* Retrieve a PendingIntent that will perform a broadcast */
24+
Intent alarmIntent = new Intent(MyActivity.this, AlarmReceiver.class);
25+
pendingIntent = PendingIntent.getBroadcast(MyActivity.this, 0, alarmIntent, 0);
26+
27+
findViewById(R.id.startAlarm).setOnClickListener(new View.OnClickListener() {
28+
@Override
29+
public void onClick(View v) {
30+
start();
31+
}
32+
});
33+
34+
findViewById(R.id.stopAlarm).setOnClickListener(new View.OnClickListener() {
35+
@Override
36+
public void onClick(View v) {
37+
cancel();
38+
}
39+
});
40+
41+
findViewById(R.id.stopAlarmAt10).setOnClickListener(new View.OnClickListener() {
42+
@Override
43+
public void onClick(View v) {
44+
startAt10();
45+
}
46+
});
47+
}
48+
49+
public void start() {
50+
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
51+
int interval = 8000;
52+
53+
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);
54+
Toast.makeText(this, "Alarm Set", Toast.LENGTH_SHORT).show();
55+
}
56+
57+
public void cancel() {
58+
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
59+
manager.cancel(pendingIntent);
60+
Toast.makeText(this, "Alarm Canceled", Toast.LENGTH_SHORT).show();
61+
}
62+
63+
public void startAt10() {
64+
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
65+
int interval = 1000 * 60 * 20;
66+
67+
/* Set the alarm to start at 10:30 AM */
68+
Calendar calendar = Calendar.getInstance();
69+
calendar.setTimeInMillis(System.currentTimeMillis());
70+
calendar.set(Calendar.HOUR_OF_DAY, 10);
71+
calendar.set(Calendar.MINUTE, 30);
72+
73+
/* Repeating on every 20 minutes interval */
74+
manager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
75+
1000 * 60 * 20, pendingIntent);
76+
}
77+
78+
}
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:paddingBottom="@dimen/activity_vertical_margin"
6+
android:paddingLeft="@dimen/activity_horizontal_margin"
7+
android:paddingRight="@dimen/activity_horizontal_margin"
8+
android:paddingTop="@dimen/activity_vertical_margin"
9+
tools:context=".MyActivity">
10+
11+
<TextView
12+
android:id="@+id/textView"
13+
android:layout_width="wrap_content"
14+
android:layout_height="wrap_content"
15+
android:layout_marginBottom="20dp"
16+
android:text="@string/hint"
17+
android:textAppearance="?android:attr/textAppearanceLarge" />
18+
19+
<Button
20+
android:id="@+id/startAlarm"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
android:layout_alignParentLeft="true"
24+
android:layout_alignParentStart="true"
25+
android:layout_below="@+id/textView"
26+
android:layout_marginBottom="20dp"
27+
android:text="Start Alarm Service" />
28+
29+
<Button
30+
android:id="@+id/stopAlarm"
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content"
33+
android:layout_below="@+id/startAlarm"
34+
android:layout_marginBottom="20dp"
35+
android:text="Stop Alarm" />
36+
37+
38+
<Button
39+
android:id="@+id/stopAlarmAt10"
40+
android:layout_width="match_parent"
41+
android:layout_height="wrap_content"
42+
android:layout_below="@+id/stopAlarm"
43+
android:text="Stop Alarm at 10:30" />
44+
45+
</RelativeLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
tools:context=".MyActivity" >
4+
<item android:id="@+id/action_settings"
5+
android:title="@string/action_settings"
6+
android:orderInCategory="100"
7+
android:showAsAction="never" />
8+
</menu>

0 commit comments

Comments
 (0)