Selaa lähdekoodia

create android library

wusuopu 8 vuotta sitten
vanhempi
commit
f729c130ad

+ 2
- 0
android/.gitignore Näytä tiedosto

@@ -0,0 +1,2 @@
1
+/build
2
+local.properties

+ 20
- 0
android/build.gradle Näytä tiedosto

@@ -0,0 +1,20 @@
1
+apply plugin: 'com.android.library'
2
+
3
+android {
4
+    compileSdkVersion 23
5
+    buildToolsVersion "23.0.3"
6
+
7
+    defaultConfig {
8
+        minSdkVersion 15
9
+        targetSdkVersion 23
10
+        versionCode 1
11
+        versionName "1.0"
12
+        ndk {
13
+            abiFilters "armeabi-v7a", "x86"
14
+        }
15
+    }
16
+}
17
+
18
+dependencies {
19
+    compile "com.facebook.react:react-native:+"
20
+}

+ 17
- 0
android/proguard-rules.pro Näytä tiedosto

@@ -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 /Users/lcj/soft/program/android/android-sdk-macosx/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
+#}

+ 13
- 0
android/src/androidTest/java/com/github/wusuopu/RNIdle/ApplicationTest.java Näytä tiedosto

@@ -0,0 +1,13 @@
1
+package com.github.wusuopu.RNIdle;
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
+}

+ 4
- 0
android/src/main/AndroidManifest.xml Näytä tiedosto

@@ -0,0 +1,4 @@
1
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+    package="com.github.wusuopu.RNIdle">
3
+
4
+</manifest>

+ 60
- 0
android/src/main/java/com/github/wusuopu/RNIdle/RNIdleModule.java Näytä tiedosto

@@ -0,0 +1,60 @@
1
+package com.github.wusuopu.RNIdle;
2
+
3
+import android.app.Activity;
4
+import android.content.BroadcastReceiver;
5
+import android.content.Context;
6
+import android.content.Intent;
7
+import android.content.IntentFilter;
8
+import android.content.pm.ActivityInfo;
9
+import android.content.res.Configuration;
10
+import android.util.Log;
11
+
12
+import com.facebook.common.logging.FLog;
13
+import com.facebook.react.bridge.Arguments;
14
+import com.facebook.react.bridge.Callback;
15
+import com.facebook.react.bridge.ReactApplicationContext;
16
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
17
+import com.facebook.react.bridge.ReactMethod;
18
+import com.facebook.react.bridge.WritableMap;
19
+import com.facebook.react.common.ReactConstants;
20
+import com.facebook.react.modules.core.DeviceEventManagerModule;
21
+
22
+import java.util.HashMap;
23
+import java.util.Map;
24
+
25
+import javax.annotation.Nullable;
26
+
27
+public class RNIdleModule extends ReactContextBaseJavaModule {
28
+    public RNIdleModule(ReactApplicationContext reactContext) {
29
+        super(reactContext);
30
+    }
31
+
32
+    @Override
33
+    public String getName() {
34
+        return "RNIdle";
35
+    }
36
+
37
+    @ReactMethod
38
+    public void disableIdleTimer() {
39
+        setIdleTimerDisabled(true);
40
+    }
41
+    @ReactMethod
42
+    public void enableIdleTimer() {
43
+        setIdleTimerDisabled(false);
44
+    }
45
+    public void setIdleTimerDisabled(final boolean disabled) {
46
+        final Activity activity = this.getCurrentActivity();
47
+        if (activity != null) {
48
+            activity.runOnUiThread(new Runnable() {
49
+                @Override
50
+                public void run() {
51
+                    if (disabled) {
52
+                        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
53
+                    } else {
54
+                        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
55
+                    }
56
+                }
57
+            });
58
+        }
59
+    }
60
+}

+ 34
- 0
android/src/main/java/com/github/wusuopu/RNIdle/RNIdlePackage.java Näytä tiedosto

@@ -0,0 +1,34 @@
1
+package com.github.wusuopu.RNIdle;
2
+
3
+import com.facebook.react.ReactPackage;
4
+import com.facebook.react.bridge.JavaScriptModule;
5
+import com.facebook.react.bridge.NativeModule;
6
+import com.facebook.react.bridge.ReactApplicationContext;
7
+import com.facebook.react.uimanager.ViewManager;
8
+
9
+import java.util.Arrays;
10
+import java.util.Collections;
11
+import java.util.List;
12
+
13
+public class RNIdlePackage implements ReactPackage {
14
+
15
+    public RNIdlePackage() {
16
+    }
17
+
18
+    @Override
19
+    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
20
+        return Arrays.<NativeModule>asList(
21
+                new RNIdleModule(reactContext)
22
+        );
23
+    }
24
+
25
+    @Override
26
+    public List<Class<? extends JavaScriptModule>> createJSModules() {
27
+        return Collections.emptyList();
28
+    }
29
+
30
+    @Override
31
+    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
32
+        return Arrays.asList();
33
+    }
34
+}

+ 15
- 0
android/src/test/java/com/github/wusuopu/RNIdle/ExampleUnitTest.java Näytä tiedosto

@@ -0,0 +1,15 @@
1
+package com.github.wusuopu.RNIdle;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+/**
8
+ * To work on unit tests, switch the Test Artifact in the Build Variants view.
9
+ */
10
+public class ExampleUnitTest {
11
+    @Test
12
+    public void addition_isCorrect() throws Exception {
13
+        assertEquals(4, 2 + 2);
14
+    }
15
+}