File tree 17 files changed +38
-29
lines changed
java/com/androidwidgetpoc
17 files changed +38
-29
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,6 @@ import {
12
12
View
13
13
} from 'react-native' ;
14
14
15
- const instructions = Platform . select ( {
16
- ios : 'Press Cmd+R to reload,\n' +
17
- 'Cmd+D or shake for dev menu' ,
18
- android : 'Double tap R on your keyboard to reload,\n' +
19
- 'Shake or press menu button for dev menu' ,
20
- } ) ;
21
-
22
15
export default class App extends Component < { } > {
23
16
render ( ) {
24
17
return (
@@ -27,10 +20,11 @@ export default class App extends Component<{}> {
27
20
Welcome to React Native!
28
21
</ Text >
29
22
< Text style = { styles . instructions } >
30
- To get started, edit App.js
23
+ To get started, edit App.js and widgetTask.js
31
24
</ Text >
32
25
< Text style = { styles . instructions } >
33
- { instructions }
26
+ Edit your native code and define the business logic in
27
+ javascript
34
28
</ Text >
35
29
</ View >
36
30
) ;
Original file line number Diff line number Diff line change 2
2
xmlns : android =" http://schemas.android.com/apk/res/android" package =" com.androidwidgetpoc" android : versionCode =" 1" android : versionName =" 1.0" >
3
3
<uses-permission android : name =" android.permission.INTERNET" />
4
4
<uses-permission android : name =" android.permission.SYSTEM_ALERT_WINDOW" />
5
+ <uses-permission android : name =" android.permission.WAKE_LOCK" />
5
6
<uses-sdk android : minSdkVersion =" 16" android : targetSdkVersion =" 22" />
6
7
<application android : name =" .MainApplication" android : allowBackup =" true" android : label =" @string/app_name" android : icon =" @mipmap/ic_launcher" android : theme =" @style/AppTheme" >
7
8
<activity android : name =" .MainActivity" android : label =" @string/app_name" android : configChanges =" keyboard|keyboardHidden|orientation|screenSize" android : windowSoftInputMode =" adjustResize" >
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ public boolean getUseDeveloperSupport() {
24
24
protected List <ReactPackage > getPackages () {
25
25
return Arrays .<ReactPackage >asList (
26
26
new MainReactPackage (),
27
- new BackgroundTimerPackage (),
27
+ new BackgroundTimerPackage (),
28
28
new BackgroundTaskBridgePackage ()
29
29
);
30
30
}
Original file line number Diff line number Diff line change 31
31
android : layout_height =" match_parent"
32
32
android : gravity =" center_vertical"
33
33
android : paddingLeft =" 5dp"
34
- android : text =" Charms "
34
+ android : text =" React Native Widget "
35
35
android : textColor =" #FCFCFC"
36
36
android : textSize =" 14sp" />
37
37
51
51
android : layout_height =" match_parent"
52
52
android : textColor =" #FCFCFC"
53
53
android : gravity =" center"
54
- android : text =" Configure your charms " />
54
+ android : text =" Placeholder text " />
55
55
56
56
</LinearLayout >
Original file line number Diff line number Diff line change
1
+ import { AppRegistry } from 'react-native' ;
2
+ import App from './App' ;
3
+ import widgetTask from './widgetTask' ;
4
+
5
+ AppRegistry . registerHeadlessTask ( 'widgetTask' , ( ) => widgetTask ) ;
6
+ AppRegistry . registerComponent ( 'androidWidgetPoc' , ( ) => App ) ;
7
+
Original file line number Diff line number Diff line change 1
1
import { AppRegistry } from 'react-native' ;
2
2
import App from './App' ;
3
- import widgetTask from './widgetTask' ;
3
+ import WidgetTask from './widgetTask' ;
4
4
5
5
AppRegistry . registerComponent ( 'androidWidgetPoc' , ( ) => App ) ;
6
- AppRegistry . registerHeadlessTask ( 'widgetTask ' , ( ) => widgetTask ) ;
6
+ AppRegistry . registerHeadlessTask ( 'WidgetTask ' , ( ) => WidgetTask ) ;
7
7
Original file line number Diff line number Diff line change 3
3
*/
4
4
5
5
import { NativeModules , ToastAndroid } from 'react-native'
6
+ import bgTimer from 'react-native-background-timer'
7
+
6
8
const { BackgroundTaskBridge } = NativeModules
7
9
10
+ const charms = [
11
+ {
12
+ id : 'uuid1' ,
13
+ name : 'First' ,
14
+ cover : 'goodmorning' ,
15
+ } ,
16
+ {
17
+ id : 'uuid2' ,
18
+ name : 'Second' ,
19
+ cover : 'night' ,
20
+ }
21
+ ]
22
+
8
23
type TaskInfo = {
9
24
id : string ,
10
25
}
11
26
export default async function widgetTask ( taskData : TaskInfo ) {
12
27
const { id} = taskData || { }
13
- console . log ( 'Running widget task' )
14
- synchronizeWidget ( )
15
- triggerCharm ( id )
28
+ bgTimer . setTimeout ( ( ) => {
29
+ synchronizeWidget ( )
30
+ triggerCharm ( id )
31
+ } , 0 )
16
32
}
17
33
18
34
export function synchronizeWidget ( ) {
35
+ ToastAndroid . show ( `Initializing ...` , ToastAndroid . SHORT ) ;
19
36
BackgroundTaskBridge . initializeWidgetBridge ( charms )
20
37
}
21
38
22
39
function triggerCharm ( id ) {
40
+ if ( ! id ) return
23
41
ToastAndroid . show ( `Triggering ${ id } ...` , ToastAndroid . SHORT ) ;
24
- }
25
-
26
- const charms = {
27
- uuid1 : {
28
- id : 'uuid1' ,
29
- name : 'First' ,
30
- } ,
31
- uuid2 : {
32
- id : 'uuid2' ,
33
- name : 'Second' ,
34
- }
35
- }
42
+ }
You can’t perform that action at this time.
0 commit comments