Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_android_sdk_maven_plugin
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Panagiotis Triantafyllou
2022-05-05 13:02:40 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1e81e87b352d01c09f063d4890635e7b502210ad
1e81e87b
1 parent
145f332e
push services fix for android 12, steps demo activity
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
232 additions
and
13 deletions
warply_android_sdk/src/main/AndroidManifest.xml
warply_android_sdk/src/main/java/ly/warp/sdk/activities/StepsActivity.java
warply_android_sdk/src/main/java/ly/warp/sdk/fragments/HomeFragment.java
warply_android_sdk/src/main/java/ly/warp/sdk/services/FCMBaseMessagingService.java
warply_android_sdk/src/main/java/ly/warp/sdk/services/HMSBaseMessagingService.java
warply_android_sdk/src/main/java/ly/warp/sdk/services/WarpBaseIntentService.java
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyHealthManager.java
warply_android_sdk/src/main/res/layout/activity_steps.xml
warply_android_sdk/src/main/AndroidManifest.xml
View file @
1e81e87
...
...
@@ -57,6 +57,11 @@
android:screenOrientation=
"portrait"
/>
<activity
android:name=
"ly.warp.sdk.activities.StepsActivity"
android:exported=
"false"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
"ly.warp.sdk.activities.PastCouponsActivity"
android:exported=
"false"
android:screenOrientation=
"portrait"
/>
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/activities/StepsActivity.java
0 → 100644
View file @
1e81e87
package
ly
.
warp
.
sdk
.
activities
;
import
android.app.Activity
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
ly.warp.sdk.R
;
import
ly.warp.sdk.io.callbacks.WarplyHealthCallback
;
import
ly.warp.sdk.utils.managers.WarplyHealthManager
;
public
class
StepsActivity
extends
Activity
implements
View
.
OnClickListener
{
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
private
TextView
mTvStepsValue
;
private
ImageView
mIvBack
;
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_steps
);
mIvBack
=
findViewById
(
R
.
id
.
iv_back
);
mTvStepsValue
=
findViewById
(
R
.
id
.
tv_counter_value
);
initViews
();
}
@Override
protected
void
onStart
()
{
super
.
onStart
();
WarplyHealthManager
.
getInstance
(
this
,
mWarplyHealthCallback
)
.
registerStepSensor
();
}
@Override
public
void
onResume
()
{
super
.
onResume
();
}
@Override
protected
void
onStop
()
{
super
.
onStop
();
WarplyHealthManager
.
getInstance
(
this
)
.
unregisterStepSensor
();
}
@Override
public
void
onClick
(
View
view
)
{
if
(
view
.
getId
()
==
R
.
id
.
iv_back
)
{
onBackPressed
();
}
}
// ===========================================================
// Methods
// ===========================================================
private
void
initViews
()
{
mIvBack
.
setOnClickListener
(
this
);
}
private
final
WarplyHealthCallback
mWarplyHealthCallback
=
new
WarplyHealthCallback
()
{
@Override
public
void
onStepCount
(
long
stepsCount
)
{
mTvStepsValue
.
setText
(
String
.
valueOf
(
stepsCount
));
}
};
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
warply_android_sdk/src/main/java/ly/warp/sdk/fragments/HomeFragment.java
View file @
1e81e87
...
...
@@ -19,6 +19,7 @@ import androidx.recyclerview.widget.RecyclerView;
import
ly.warp.sdk.R
;
import
ly.warp.sdk.activities.ActiveCouponsActivity
;
import
ly.warp.sdk.activities.BillPaymentActivity
;
import
ly.warp.sdk.activities.StepsActivity
;
import
ly.warp.sdk.activities.WarpViewActivity
;
import
ly.warp.sdk.utils.WarplyManagerHelper
;
import
ly.warp.sdk.views.adapters.HomeCampaignAdapter
;
...
...
@@ -31,6 +32,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
private
LinearLayout
mLlBillPayment
;
private
TextView
mTvUsername
,
mTvActiveCoupons
;
private
ConstraintLayout
mClActiveCoupons
;
private
ImageView
mIvStepsActivity
;
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
...
...
@@ -66,6 +68,9 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
mLlBillPayment
=
view
.
findViewById
(
R
.
id
.
ll_bill_payment
);
mLlBillPayment
.
setOnClickListener
(
this
);
mIvStepsActivity
=
view
.
findViewById
(
R
.
id
.
iv_settings
);
mIvStepsActivity
.
setOnClickListener
(
this
);
mTvUsername
=
view
.
findViewById
(
R
.
id
.
welcome_user_txt
);
if
(
WarplyManagerHelper
.
getConsumer
()
!=
null
)
mTvUsername
.
setText
(
String
.
format
(
getResources
().
getString
(
R
.
string
.
welcome_user
),
...
...
@@ -100,6 +105,11 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
Intent
intent
=
new
Intent
(
getContext
(),
ActiveCouponsActivity
.
class
);
intent
.
putExtra
(
"couponlist"
,
WarplyManagerHelper
.
getCouponList
());
startActivity
(
intent
);
return
;
}
if
(
view
.
getId
()
==
R
.
id
.
iv_settings
)
{
Intent
intent
=
new
Intent
(
getContext
(),
StepsActivity
.
class
);
startActivity
(
intent
);
}
}
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/services/FCMBaseMessagingService.java
View file @
1e81e87
...
...
@@ -214,7 +214,11 @@ public class FCMBaseMessagingService extends FirebaseMessagingService {
b
.
setContentTitle
(
pc
.
getTitle
());
b
.
setContentText
(
pc
.
getSubtitle
());
b
.
setSubText
(
pc
.
getContent
());
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
|
PendingIntent
.
FLAG_MUTABLE
));
}
else
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
));
}
b
.
setAutoCancel
(
true
);
b
.
setOngoing
(
true
);
b
.
setAutoCancel
(
true
);
...
...
@@ -331,8 +335,12 @@ public class FCMBaseMessagingService extends FirebaseMessagingService {
builder.setOngoing(true);
newIntent.setAction(Long.toString(System.currentTimeMillis()));
PendingIntent pi = PendingIntent.getActivity(context, uid, newIntent,
PendingIntent.FLAG_ONE_SHOT);
PendingIntent pi;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pi = PendingIntent.getActivity(context, uid, newIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_MUTABLE);
} else {
pi = PendingIntent.getActivity(context, uid, newIntent, PendingIntent.FLAG_ONE_SHOT);
}
builder.setContentIntent(pi);
NotificationManager nm = (NotificationManager) context
...
...
@@ -390,7 +398,11 @@ public class FCMBaseMessagingService extends FirebaseMessagingService {
b
.
setContentTitle
(
pc
.
getTitle
());
b
.
setContentText
(
pc
.
getSubtitle
());
b
.
setSubText
(
pc
.
getContent
());
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
|
PendingIntent
.
FLAG_MUTABLE
));
}
else
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
));
}
b
.
setAutoCancel
(
true
);
b
.
setOngoing
(
true
);
b
.
setAutoCancel
(
true
);
...
...
@@ -433,7 +445,12 @@ public class FCMBaseMessagingService extends FirebaseMessagingService {
// Do not allow sound or anything else.
newIntent
.
setAction
(
Long
.
toString
(
System
.
currentTimeMillis
()));
PendingIntent
pi
=
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
);
PendingIntent
pi
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
pi
=
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
|
PendingIntent
.
FLAG_MUTABLE
);
}
else
{
pi
=
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
);
}
b
.
setContentIntent
(
pi
);
NotificationManager
nm
=
(
NotificationManager
)
context
.
getSystemService
(
NOTIFICATION_SERVICE
);
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/services/HMSBaseMessagingService.java
View file @
1e81e87
...
...
@@ -259,7 +259,11 @@ public class HMSBaseMessagingService extends HmsMessageService {
b
.
setContentTitle
(
pc
.
getTitle
());
b
.
setContentText
(
pc
.
getSubtitle
());
b
.
setSubText
(
pc
.
getContent
());
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
|
PendingIntent
.
FLAG_MUTABLE
));
}
else
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
));
}
b
.
setAutoCancel
(
true
);
b
.
setOngoing
(
true
);
b
.
setAutoCancel
(
true
);
...
...
@@ -374,8 +378,12 @@ public class HMSBaseMessagingService extends HmsMessageService {
builder.setOngoing(true);
newIntent.setAction(Long.toString(System.currentTimeMillis()));
PendingIntent pi = PendingIntent.getActivity(context, uid, newIntent,
PendingIntent.FLAG_ONE_SHOT);
PendingIntent pi;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pi = PendingIntent.getActivity(context, uid, newIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_MUTABLE);
} else {
pi = PendingIntent.getActivity(context, uid, newIntent, PendingIntent.FLAG_ONE_SHOT);
}
builder.setContentIntent(pi);
NotificationManager nm = (NotificationManager) context
...
...
@@ -433,7 +441,11 @@ public class HMSBaseMessagingService extends HmsMessageService {
b
.
setContentTitle
(
pc
.
getTitle
());
b
.
setContentText
(
pc
.
getSubtitle
());
b
.
setSubText
(
pc
.
getContent
());
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
|
PendingIntent
.
FLAG_MUTABLE
));
}
else
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
));
}
b
.
setAutoCancel
(
true
);
b
.
setOngoing
(
true
);
b
.
setAutoCancel
(
true
);
...
...
@@ -475,8 +487,12 @@ public class HMSBaseMessagingService extends HmsMessageService {
// Do not allow sound or anything else.
newIntent
.
setAction
(
Long
.
toString
(
System
.
currentTimeMillis
()));
PendingIntent
pi
=
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
);
PendingIntent
pi
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
pi
=
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
|
PendingIntent
.
FLAG_MUTABLE
);
}
else
{
pi
=
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
);
}
b
.
setContentIntent
(
pi
);
NotificationManager
nm
=
(
NotificationManager
)
context
.
getSystemService
(
NOTIFICATION_SERVICE
);
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/services/WarpBaseIntentService.java
View file @
1e81e87
...
...
@@ -194,7 +194,11 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService {
b
.
setContentTitle
(
pc
.
getTitle
());
b
.
setContentText
(
pc
.
getSubtitle
());
b
.
setSubText
(
pc
.
getContent
());
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
|
PendingIntent
.
FLAG_MUTABLE
));
}
else
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
));
}
b
.
setAutoCancel
(
true
);
b
.
setOngoing
(
true
);
b
.
setAutoCancel
(
true
);
...
...
@@ -310,8 +314,12 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService {
builder.setOngoing(true);
newIntent.setAction(Long.toString(System.currentTimeMillis()));
PendingIntent pi = PendingIntent.getActivity(context, uid, newIntent,
PendingIntent.FLAG_ONE_SHOT);
PendingIntent pi;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
pi = PendingIntent.getActivity(context, uid, newIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_MUTABLE);
} else {
pi = PendingIntent.getActivity(context, uid, newIntent, PendingIntent.FLAG_ONE_SHOT);
}
builder.setContentIntent(pi);
NotificationManager nm = (NotificationManager) context
...
...
@@ -369,7 +377,11 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService {
b
.
setContentTitle
(
pc
.
getTitle
());
b
.
setContentText
(
pc
.
getSubtitle
());
b
.
setSubText
(
pc
.
getContent
());
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
|
PendingIntent
.
FLAG_MUTABLE
));
}
else
{
b
.
setContentIntent
(
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
));
}
b
.
setAutoCancel
(
true
);
b
.
setOngoing
(
true
);
b
.
setAutoCancel
(
true
);
...
...
@@ -411,8 +423,12 @@ public abstract class WarpBaseIntentService extends GCMBaseIntentService {
// Do not allow sound or anything else.
newIntent
.
setAction
(
Long
.
toString
(
System
.
currentTimeMillis
()));
PendingIntent
pi
=
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
);
PendingIntent
pi
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
pi
=
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
|
PendingIntent
.
FLAG_MUTABLE
);
}
else
{
pi
=
PendingIntent
.
getActivity
(
context
,
uid
,
newIntent
,
PendingIntent
.
FLAG_ONE_SHOT
);
}
b
.
setContentIntent
(
pi
);
NotificationManager
nm
=
(
NotificationManager
)
context
.
getSystemService
(
NOTIFICATION_SERVICE
);
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyHealthManager.java
View file @
1e81e87
...
...
@@ -10,6 +10,7 @@ import ly.warp.sdk.io.callbacks.WarplyHealthCallback;
/**
* Created by Panagiotis Triantafyllou on 27/Απρ/2022.
*
* @guide http://www.gadgetsaint.com/android/create-pedometer-step-counter-android/#.Weg2KmiCyM8
*/
public
class
WarplyHealthManager
implements
SensorEventListener
{
...
...
@@ -41,7 +42,7 @@ public class WarplyHealthManager implements SensorEventListener {
private
float
oldVelocityEstimate
=
0
;
//TODO: if we want to send the steps back to an activity/fragment/service etc
// private
WarplyHealthCallback mHealthCallback;
private
static
WarplyHealthCallback
mHealthCallback
;
// ===========================================================
// Methods for/from SuperClass/Interfaces
...
...
@@ -76,6 +77,16 @@ public class WarplyHealthManager implements SensorEventListener {
return
mWarplyHealthManagerInstance
;
}
public
static
WarplyHealthManager
getInstance
(
Context
context
,
WarplyHealthCallback
callback
)
{
if
(
mWarplyHealthManagerInstance
==
null
)
{
mWarplyHealthManagerInstance
=
new
WarplyHealthManager
();
mSensorManager
=
(
SensorManager
)
context
.
getSystemService
(
Context
.
SENSOR_SERVICE
);
mSensor
=
mSensorManager
.
getDefaultSensor
(
Sensor
.
TYPE_ACCELEROMETER
);
mHealthCallback
=
callback
;
}
return
mWarplyHealthManagerInstance
;
}
public
void
registerStepSensor
()
{
mSensorManager
.
registerListener
(
mWarplyHealthManagerInstance
,
mSensor
,
SensorManager
.
SENSOR_DELAY_GAME
);
}
...
...
@@ -118,7 +129,7 @@ public class WarplyHealthManager implements SensorEventListener {
&&
(
timeNs
-
lastStepTimeNs
>
STEP_DELAY_NS
))
{
//TODO: if we want to send the steps back to an activity/fragment/service etc
mSteps
++;
//
mHealthCallback.onStepCount(mSteps);
mHealthCallback
.
onStepCount
(
mSteps
);
lastStepTimeNs
=
timeNs
;
}
oldVelocityEstimate
=
velocityEstimate
;
...
...
warply_android_sdk/src/main/res/layout/activity_steps.xml
0 → 100644
View file @
1e81e87
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/grey4"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/cl_loyalty_wallet_header"
android:layout_width=
"match_parent"
android:layout_height=
"50dp"
android:background=
"@android:color/white"
>
<ImageView
android:id=
"@+id/iv_back"
android:layout_width=
"20dp"
android:layout_height=
"20dp"
android:layout_marginStart=
"16dp"
android:src=
"@drawable/ic_back"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Steps"
android:textColor=
"@color/grey"
android:textSize=
"17sp"
android:textStyle=
"bold"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id=
"@+id/tv_counter"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerInParent=
"true"
android:text=
"Counter"
android:textSize=
"18sp"
/>
<TextView
android:id=
"@+id/tv_counter_value"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/tv_counter"
android:layout_centerInParent=
"true"
android:textColor=
"@color/grey"
android:textSize=
"17sp"
android:textStyle=
"bold"
android:text=
"0"
/>
</RelativeLayout>
Please
register
or
login
to post a comment