Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
972da543
Commit
972da543
authored
Mar 22, 2017
by
Sarah Zakarias
Committed by
GitHub
Mar 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor platform_services sample (#8949)
* Refactor platform_services sample * removed exception
parent
9adf1bf1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
17 deletions
+13
-17
ExampleInstrumentedTest.java
...est/java/com/example/flutter/ExampleInstrumentedTest.java
+2
-6
AndroidManifest.xml
...latform_services/android/app/src/main/AndroidManifest.xml
+1
-1
MainActivity.java
...d/app/src/main/java/com/example/flutter/MainActivity.java
+10
-10
No files found.
examples/platform_services/android/app/src/androidTest/java/com/example/flutter/ExampleInstrumentedTest.java
View file @
972da543
...
@@ -8,12 +8,8 @@ import android.support.test.runner.AndroidJUnit4;
...
@@ -8,12 +8,8 @@ import android.support.test.runner.AndroidJUnit4;
import
io.flutter.view.FlutterView
;
import
io.flutter.view.FlutterView
;
import
android.app.Instrumentation
;
import
android.app.Instrumentation
;
import
android.support.test.InstrumentationRegistry
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
...
@@ -23,8 +19,8 @@ import static org.junit.Assert.*;
...
@@ -23,8 +19,8 @@ import static org.junit.Assert.*;
@RunWith
(
AndroidJUnit4
.
class
)
@RunWith
(
AndroidJUnit4
.
class
)
public
class
ExampleInstrumentedTest
{
public
class
ExampleInstrumentedTest
{
@Rule
@Rule
public
ActivityTestRule
<
Example
Activity
>
activityRule
=
public
ActivityTestRule
<
Main
Activity
>
activityRule
=
new
ActivityTestRule
<>(
Example
Activity
.
class
);
new
ActivityTestRule
<>(
Main
Activity
.
class
);
@Test
@Test
...
...
examples/platform_services/android/app/src/main/AndroidManifest.xml
View file @
972da543
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
<application
android:name=
"io.flutter.app.FlutterApplication"
android:label=
"@string/app_name"
>
<application
android:name=
"io.flutter.app.FlutterApplication"
android:label=
"@string/app_name"
>
<activity
<activity
android:name=
".
Example
Activity"
android:name=
".
Main
Activity"
android:launchMode=
"singleTop"
android:launchMode=
"singleTop"
android:theme=
"@android:style/Theme.Black.NoTitleBar"
android:theme=
"@android:style/Theme.Black.NoTitleBar"
android:configChanges=
"orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:configChanges=
"orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
...
...
examples/platform_services/android/app/src/main/java/com/example/flutter/
Example
Activity.java
→
examples/platform_services/android/app/src/main/java/com/example/flutter/
Main
Activity.java
View file @
972da543
...
@@ -18,7 +18,7 @@ import io.flutter.plugin.common.FlutterMethodChannel.MethodCallHandler;
...
@@ -18,7 +18,7 @@ import io.flutter.plugin.common.FlutterMethodChannel.MethodCallHandler;
import
io.flutter.plugin.common.FlutterMethodChannel.Response
;
import
io.flutter.plugin.common.FlutterMethodChannel.Response
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodCall
;
public
class
Example
Activity
extends
FlutterActivity
{
public
class
Main
Activity
extends
FlutterActivity
{
private
static
final
String
CHANNEL
=
"battery"
;
private
static
final
String
CHANNEL
=
"battery"
;
@Override
@Override
...
@@ -30,15 +30,19 @@ public class ExampleActivity extends FlutterActivity {
...
@@ -30,15 +30,19 @@ public class ExampleActivity extends FlutterActivity {
@Override
@Override
public
void
onMethodCall
(
MethodCall
call
,
Response
response
)
{
public
void
onMethodCall
(
MethodCall
call
,
Response
response
)
{
if
(
call
.
method
.
equals
(
"getBatteryLevel"
))
{
if
(
call
.
method
.
equals
(
"getBatteryLevel"
))
{
getBatteryLevel
(
response
);
int
batteryLevel
=
getBatteryLevel
();
}
else
{
throw
new
IllegalArgumentException
(
"Unknown method "
+
call
.
method
);
if
(
batteryLevel
!=
-
1
)
{
response
.
success
(
batteryLevel
);
}
else
{
response
.
error
(
"UNAVAILABLE"
,
"Battery level not available."
,
null
);
}
}
}
}
}
});
});
}
}
private
void
getBatteryLevel
(
Response
response
)
{
private
int
getBatteryLevel
(
)
{
int
batteryLevel
=
-
1
;
int
batteryLevel
=
-
1
;
if
(
VERSION
.
SDK_INT
>=
VERSION_CODES
.
LOLLIPOP
)
{
if
(
VERSION
.
SDK_INT
>=
VERSION_CODES
.
LOLLIPOP
)
{
BatteryManager
batteryManager
=
(
BatteryManager
)
getSystemService
(
BATTERY_SERVICE
);
BatteryManager
batteryManager
=
(
BatteryManager
)
getSystemService
(
BATTERY_SERVICE
);
...
@@ -50,10 +54,6 @@ public class ExampleActivity extends FlutterActivity {
...
@@ -50,10 +54,6 @@ public class ExampleActivity extends FlutterActivity {
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
);
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
);
}
}
if
(
batteryLevel
!=
-
1
)
{
return
batteryLevel
;
response
.
success
(
batteryLevel
);
}
else
{
response
.
error
(
"UNAVAILABLE"
,
"Battery level not available."
,
null
);
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment