Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
scanqrwhite2copy1
Project
Project
Details
Activity
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
scanqrwhite2copy1
Commits
b3b3f240
Commit
b3b3f240
authored
Feb 13, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
47b0ec03
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
432 additions
and
1 deletion
+432
-1
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+3
-1
EarthquakeBean.kt
...src/main/java/com/base/scanqrclear/bean/EarthquakeBean.kt
+21
-0
WeatherInterface.kt
...c/main/java/com/base/scanqrclear/luma/WeatherInterface.kt
+6
-0
EarthquakeActivity.kt
.../com/base/scanqrclear/ui/earthquake/EarthquakeActivity.kt
+124
-0
activity_earthquake.xml
app/src/main/res/layout/activity_earthquake.xml
+260
-0
activity_weather.xml
app/src/main/res/layout/activity_weather.xml
+18
-0
earthquake.png
app/src/main/res/mipmap-xxhdpi/earthquake.png
+0
-0
wd_bg.png
app/src/main/res/mipmap-xxhdpi/wd_bg.png
+0
-0
wd_tu.png
app/src/main/res/mipmap-xxhdpi/wd_tu.png
+0
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
b3b3f240
...
...
@@ -40,7 +40,9 @@
android:supportsRtl=
"true"
android:theme=
"@style/Theme.ScanQR"
tools:targetApi=
"31"
>
<activity
android:name=
".ui.earthquake.EarthquakeActivity"
android:exported=
"false"
/>
<activity
android:name=
".ui.start.StartActivity"
android:exported=
"true"
...
...
app/src/main/java/com/base/scanqrclear/bean/EarthquakeBean.kt
0 → 100644
View file @
b3b3f240
package
com.base.scanqrclear.bean
data class
EarthquakeData
(
val
features
:
List
<
EarthquakeBean
>
)
data class
EarthquakeBean
(
val
properties
:
EarthquakeProperties
,
val
geometry
:
EarthquakeGeometry
,
)
data class
EarthquakeProperties
(
val
mag
:
Float
,
//震级
val
place
:
String
,
//地点
val
time
:
Long
,
//发生时间
val
mmi
:
Any
?,
//烈度(Intensity)通常用Modified Mercalli Intensity (MMI)
)
data class
EarthquakeGeometry
(
val
coordinates
:
DoubleArray
,
//第三个表示深度
)
app/src/main/java/com/base/scanqrclear/luma/WeatherInterface.kt
View file @
b3b3f240
package
com.base.scanqrclear.luma
import
android.annotation.SuppressLint
import
android.content.Intent
import
android.graphics.Color
import
android.os.Bundle
import
android.view.LayoutInflater
...
...
@@ -19,6 +20,7 @@ import com.base.scanqrclear.bean.ListBean
import
com.base.scanqrclear.bean.WeatherBean
import
com.base.scanqrclear.bean.config.AdConfigBean
import
com.base.scanqrclear.databinding.ActivityWeatherBinding
import
com.base.scanqrclear.ui.earthquake.EarthquakeActivity
import
com.base.scanqrclear.utils.BarUtils
import
kotlin.random.Random
...
...
@@ -80,6 +82,10 @@ class WeatherInterface : BaseActivity2() {
}
}
})
binding
.
ivEarthquake
.
setOnClickListener
{
startActivity
(
Intent
(
this
,
EarthquakeActivity
::
class
.
java
))
}
}
private
fun
getData
()
{
...
...
app/src/main/java/com/base/scanqrclear/ui/earthquake/EarthquakeActivity.kt
0 → 100644
View file @
b3b3f240
package
com.base.scanqrclear.ui.earthquake
import
android.annotation.SuppressLint
import
android.location.LocationManager
import
android.view.View
import
androidx.activity.addCallback
import
androidx.core.view.updatePadding
import
com.base.scanqrclear.R
import
com.base.scanqrclear.ads.AdsMgr
import
com.base.scanqrclear.base.BaseActivity
import
com.base.scanqrclear.bean.EarthquakeData
import
com.base.scanqrclear.databinding.ActivityEarthquakeBinding
import
com.base.scanqrclear.utils.BarUtils
import
com.base.scanqrclear.utils.KotlinExt.toFormatTime3
import
com.base.scanqrclear.utils.LogEx
import
com.google.gson.Gson
import
com.gyf.immersionbar.ktx.immersionBar
import
okhttp3.OkHttpClient
import
okhttp3.Request
class
EarthquakeActivity
:
BaseActivity
<
ActivityEarthquakeBinding
>(
ActivityEarthquakeBinding
::
inflate
)
{
@SuppressLint
(
"SetTextI18n"
,
"MissingPermission"
)
override
fun
initView
()
{
super
.
initView
()
binding
.
clTop
.
updatePadding
(
top
=
BarUtils
.
getStatusBarHeight
())
AdsMgr
.
showNative
(
binding
.
flAd
,
R
.
layout
.
layout_admob_item
)
Thread
{
val
data
=
fetchEarthquakeData
()
val
oneData
=
data
?.
features
?.
maxBy
{
it
.
properties
.
mag
}
oneData
?.
let
{
runOnUiThread
{
kotlin
.
runCatching
{
binding
.
tvWhere
.
text
=
it
.
properties
.
place
binding
.
tvTime
.
text
=
it
.
properties
.
time
.
toFormatTime3
()
binding
.
tvLevel
.
text
=
"Level "
+
"${it.properties.mag}"
binding
.
tvDepth
.
text
=
it
.
geometry
.
coordinates
[
2
].
toInt
().
toString
()
+
" Kilometers"
if
(
it
.
properties
.
mmi
!=
null
)
{
binding
.
tvIntensityTitle
.
visibility
=
View
.
VISIBLE
binding
.
tvIntensity
.
visibility
=
View
.
VISIBLE
binding
.
tvIntensity
.
text
=
it
.
properties
.
mmi
.
toString
()
}
// binding.tvWarningTime.text = "" + " S"
}
}
}
}.
start
()
launcher
.
launch
(
arrayOf
(
android
.
Manifest
.
permission
.
ACCESS_COARSE_LOCATION
,
android
.
Manifest
.
permission
.
LOCATION_HARDWARE
,
)
)
{
val
locationManager
=
getSystemService
(
LOCATION_SERVICE
)
as
LocationManager
locationManager
.
requestLocationUpdates
(
LocationManager
.
NETWORK_PROVIDER
,
0L
,
0f
)
{
location
->
LogEx
.
logDebug
(
TAG
,
"${location.altitude} ${location.longitude}"
)
}
}
}
override
fun
initListener
()
{
super
.
initListener
()
onBackPressedDispatcher
.
addCallback
{
finish
()
}
binding
.
flBack
.
setOnClickListener
{
onBackPressedDispatcher
.
onBackPressed
()
}
}
override
fun
configSystemBar
()
{
immersionBar
{
statusBarColor
(
"#00FFFFFF"
)
statusBarDarkFont
(
false
)
}
}
private
fun
fetchEarthquakeData
():
EarthquakeData
?
{
try
{
val
client
=
OkHttpClient
()
val
request
=
Request
.
Builder
()
.
url
(
"https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson"
)
.
build
()
val
response
=
client
.
newCall
(
request
).
execute
()
val
responseBody
=
response
.
body
?.
string
()
if
(
responseBody
==
null
)
{
LogEx
.
logDebug
(
TAG
,
"responseBody=null"
)
return
null
}
else
{
val
gson
=
Gson
()
val
earthquakeData
=
gson
.
fromJson
(
responseBody
,
EarthquakeData
::
class
.
java
)
return
earthquakeData
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
null
}
private
fun
haversineDistance
(
lat1
:
Double
,
lon1
:
Double
,
lat2
:
Double
,
lon2
:
Double
):
Double
{
val
R
=
6371
// 地球半径,单位:千米
val
latDistance
=
Math
.
toRadians
(
lat2
-
lat1
)
val
lonDistance
=
Math
.
toRadians
(
lon2
-
lon1
)
val
a
=
Math
.
sin
(
latDistance
/
2
)
*
Math
.
sin
(
latDistance
/
2
)
+
Math
.
cos
(
Math
.
toRadians
(
lat1
))
*
Math
.
cos
(
Math
.
toRadians
(
lat2
))
*
Math
.
sin
(
lonDistance
/
2
)
*
Math
.
sin
(
lonDistance
/
2
)
val
c
=
2
*
Math
.
atan2
(
Math
.
sqrt
(
a
),
Math
.
sqrt
(
1
-
a
))
return
R
*
c
// 返回距离,单位:千米
}
}
\ No newline at end of file
app/src/main/res/layout/activity_earthquake.xml
0 → 100644
View file @
b3b3f240
This diff is collapsed.
Click to expand it.
app/src/main/res/layout/activity_weather.xml
View file @
b3b3f240
...
...
@@ -31,6 +31,24 @@
app:layout_constraintTop_toTopOf=
"@+id/id_back"
tools:text=
"ChengDu"
/>
<androidx.appcompat.widget.AppCompatImageView
android:id=
"@+id/ivEarthquake"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"20dp"
android:src=
"@mipmap/earthquake"
app:layout_constraintBottom_toBottomOf=
"@id/id_back"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"@id/id_back"
/>
<ImageView
android:layout_width=
"6dp"
android:layout_height=
"6dp"
android:background=
"@drawable/bg_fb1f1f"
app:layout_constraintEnd_toEndOf=
"@id/ivEarthquake"
app:layout_constraintTop_toTopOf=
"@id/ivEarthquake"
tools:ignore=
"ContentDescription"
/>
<TextView
android:id=
"@+id/id_tv_date"
android:layout_width=
"wrap_content"
...
...
app/src/main/res/mipmap-xxhdpi/earthquake.png
0 → 100644
View file @
b3b3f240
2.3 KB
app/src/main/res/mipmap-xxhdpi/wd_bg.png
0 → 100644
View file @
b3b3f240
352 KB
app/src/main/res/mipmap-xxhdpi/wd_tu.png
0 → 100644
View file @
b3b3f240
134 KB
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