Panagiotis Triantafyllou

step count manager, step callback, general fixes and changes

......@@ -47,7 +47,7 @@ dependencies {
api group: 'com.google.zxing', name: 'core', version: '3.4.1'
api group: 'com.google.zxing', name: 'javase', version: '3.4.1'
api 'com.github.siyamed:android-shape-imageview:0.9.3'
api 'org.greenrobot:eventbus:3.3.1'
//------------------------------ Firebase -----------------------------//
api platform('com.google.firebase:firebase-bom:29.0.3')
......
......@@ -27,10 +27,10 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
// ===========================================================
private ImageView mIvBack;
private TextView mTvUsername, mTvQuestionnaire, mTvActiveCoupons,
mTvActiveRewards;
private TextView mTvUsername, mTvActiveCoupons,
mTvActiveRewards, mTvUserBadge;
private ConstraintLayout mClActiveCoupons, mClActiveRewards;
private LinearLayout mLlAnalysisButton;
private LinearLayout mLlAnalysisButton, mLlQuestionnaire, mLlUserBadge;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -44,12 +44,14 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
mIvBack = findViewById(R.id.iv_back);
// mTvAnalysisButton = findViewById(R.id.rl_analysis_row).findViewById(R.id.cl_chart_info).findViewById(R.id.tv_analysis_details);
mTvUsername = findViewById(R.id.tv_name);
// mTvQuestionnaire = findViewById(R.id.cl_loyalty_info_banner).findViewById(R.id.tv_questionnaire);
mLlQuestionnaire = findViewById(R.id.ll_user_questionnaire);
mLlUserBadge = findViewById(R.id.ll_user_badge);
mClActiveCoupons = findViewById(R.id.cl_loyalty_coupon);
mTvActiveCoupons = findViewById(R.id.tv_active_coupons);
mClActiveRewards = findViewById(R.id.cl_loyalty_rewards);
mTvActiveRewards = findViewById(R.id.tv_active_rewards);
mLlAnalysisButton = findViewById(R.id.ll_analysis);
mTvUserBadge = findViewById(R.id.tv_type);
initViews();
}
......@@ -70,7 +72,7 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
startActivity(intent);
return;
}
if (view.getId() == R.id.tv_questionnaire) {
if (view.getId() == R.id.ll_user_questionnaire) {
CampaignList cl = WarplyManagerHelper.getUniqueCampaignList().get("more_for_you");
Campaign camp = null;
if (cl != null) {
......@@ -104,13 +106,25 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
// ===========================================================
private void initViews() {
if (WarplyManagerHelper.getConsumer() != null)
if (WarplyManagerHelper.getConsumer() != null) {
mTvUsername.setText(String.format(getResources().getString(R.string.cos_profile_loyalty_name),
WarplyManagerHelper.getConsumer().getFirstName(), WarplyManagerHelper.getConsumer().getLastName()));
if (WarplyManagerHelper.getConsumer().getProfileMetadata() != null) {
boolean answered = WarplyManagerHelper.getConsumer().getProfileMetadata().optBoolean("answered", false);
if (answered) {
//TODO: put badge also
mLlUserBadge.setVisibility(View.VISIBLE);
} else
mLlQuestionnaire.setVisibility(View.VISIBLE);
} else {
mLlQuestionnaire.setVisibility(View.VISIBLE);
}
}
mIvBack.setOnClickListener(this);
// mTvAnalysisButton.setOnClickListener(this);
// mTvQuestionnaire.setOnClickListener(this);
mLlQuestionnaire.setOnClickListener(this);
mTvActiveCoupons.setText(String.format(getResources().getString(R.string.cos_active_coupons), String.valueOf(WarplyManagerHelper.getCouponList().size())));
mClActiveCoupons.setOnClickListener(this);
//TODO: change the parameter, for testing purposes only
......
/*
* Copyright 2010-2013 Warply Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package ly.warp.sdk.io.callbacks;
public interface WarplyHealthCallback {
void onStepCount(long stepsCount);
}
......@@ -8,156 +8,18 @@ import java.util.ArrayList;
public class LoyaltyContextualOfferModel {
private String sessionId; //Needed for Interest/Accept/Reject
private String interactionPoint;
private String offerCode; //Offer Id. Needed for Interest/Accept/Reject
private String treatmentCode; //Needed for Interest/Accept/Reject
private ArrayList<String> eligibleAssets; //Array of the eligible assets for this offer
private String title; //title for tile and detail view
private String description; //detail view description
private String shortDescription; //tile description
private String price; // offer price
private String discount; // offer discount
private String termsAndConditions;
private String offerType; //neo, inform
private String offerType1; //sms, data, voice
private String offerType2; //sms, data, voice, pre2post
private String offerType3; //sms, data, voice
private String imageUrl; //Tile image
private String squareImageUrl; //Home contextual image
private String bigImageUrl; //Detail view image
private String tapOverType; //REDIRECT_TO_EXTERNAL,REDIRECT_TO_INTERNAL,DETAILED_PAGE
private String tapOverUrl; //for surveys
private String balancesDuration; //package duration for data,sms,voice
//denotes data gift
private String balancesDataType;
private String balancesDataValue;
//denotes voice gift
private String balancesVoiceType;
private String balancesVoiceValue;
//denotes sms gift
private String balancesSmsType;
private String balancesSmsValue;
private boolean surveyFlag; //If true the offer is survey
private String carouselPriority; //Carousel Position
private String acceptButtonText; //button wording
private String id;
public String getSessionId() {
return sessionId;
}
public String getInteractionPoint() {
return interactionPoint;
}
public String getOfferCode() {
return offerCode;
}
public String getTreatmentCode() {
return treatmentCode;
}
public ArrayList<String> getEligibleAssets() {
return eligibleAssets;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public String getShortDescription() {
return shortDescription;
}
public String getPrice() {
return price;
}
public String getDiscount() {
return discount;
}
public String getTermsAndConditions() {
return termsAndConditions;
}
public String getOfferType() {
return offerType;
}
public String getOfferType1() {
return offerType1;
}
public String getOfferType2() {
return offerType2;
}
public String getOfferType3() {
return offerType3;
}
public String getImageUrl() {
return imageUrl;
}
public String getSquareImageUrl() {
return squareImageUrl;
}
public String getBigImageUrl() {
return bigImageUrl;
}
public String getTapOverType() {
return tapOverType;
}
public String getTapOverUrl() {
return tapOverUrl;
}
public String getBalancesDuration() {
return balancesDuration;
}
public String getBalancesDataType() {
return balancesDataType;
}
public String getBalancesDataValue() {
return balancesDataValue;
}
public String getBalancesVoiceType() {
return balancesVoiceType;
}
public String getBalancesVoiceValue() {
return balancesVoiceValue;
}
public String getBalancesSmsType() {
return balancesSmsType;
}
public String getBalancesSmsValue() {
return balancesSmsValue;
}
public boolean isSurveyFlag() {
return surveyFlag;
}
public String getCarouselPriority() {
return carouselPriority;
}
public String getAcceptButtonText() {
return acceptButtonText;
public String getId() {
return id;
}
}
......
......@@ -42,11 +42,28 @@ import ly.warp.sdk.io.models.LoyaltyContextualOfferModel;
*/
public class WarplyManagerHelper {
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
private static Consumer mConsumer;
private static HashMap<String, CampaignList> mUniqueCampaignList = new HashMap<String, CampaignList>();
private static CouponList mCouponList = new CouponList();
private static CouponsetsList mCouponsetsList = new CouponsetsList();
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
// ===========================================================
// Methods
// ===========================================================
public static String constructCampaignUrl(Campaign item) {
item.setNew(false);
String url = item.getIndexUrl()
......@@ -127,4 +144,8 @@ public class WarplyManagerHelper {
public static void setCouponsets(CouponsetsList couponsets) {
mCouponsetsList = couponsets;
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
\ No newline at end of file
......
package ly.warp.sdk.utils.managers;
/**
* Created by Panagiotis Triantafyllou on 26/Απρ/2022.
*/
public class WarplyEventBusManager {
private String eventName;
public WarplyEventBusManager(String eventName) {
this.eventName = eventName;
}
}
package ly.warp.sdk.utils.managers;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
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 {
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
private long mSteps = 0;
private static SensorManager mSensorManager;
private static Sensor mSensor;
private static WarplyHealthManager mWarplyHealthManagerInstance;
private static final int ACCEL_RING_SIZE = 50;
private static final int VEL_RING_SIZE = 10;
// change this threshold according to your sensitivity preferences
private static final float STEP_THRESHOLD = 20f;
private static final int STEP_DELAY_NS = 250000000;
private int accelRingCounter = 0;
private float[] accelRingX = new float[ACCEL_RING_SIZE];
private float[] accelRingY = new float[ACCEL_RING_SIZE];
private float[] accelRingZ = new float[ACCEL_RING_SIZE];
private int velRingCounter = 0;
private float[] velRing = new float[VEL_RING_SIZE];
private long lastStepTimeNs = 0;
private float oldVelocityEstimate = 0;
//TODO: if we want to send the steps back to an activity/fragment/service etc
// private WarplyHealthCallback healthCallback;
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
updateSteps(
sensorEvent.timestamp,
sensorEvent.values[0],
sensorEvent.values[1],
sensorEvent.values[2]);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int i) {
}
// ===========================================================
// Methods
// ===========================================================
public static WarplyHealthManager getInstance(Context context) {
if (mWarplyHealthManagerInstance == null) {
mWarplyHealthManagerInstance = new WarplyHealthManager();
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
return mWarplyHealthManagerInstance;
}
public void registerStepSensor() {
mSensorManager.registerListener(mWarplyHealthManagerInstance, mSensor, SensorManager.SENSOR_DELAY_GAME);
}
public void unregisterStepSensor() {
mSensorManager.unregisterListener(mWarplyHealthManagerInstance);
}
private void updateSteps(long timeNs, float x, float y, float z) {
float[] currentAccel = new float[3];
currentAccel[0] = x;
currentAccel[1] = y;
currentAccel[2] = z;
// First step is to update our guess of where the global z vector is.
accelRingCounter++;
accelRingX[accelRingCounter % ACCEL_RING_SIZE] = currentAccel[0];
accelRingY[accelRingCounter % ACCEL_RING_SIZE] = currentAccel[1];
accelRingZ[accelRingCounter % ACCEL_RING_SIZE] = currentAccel[2];
float[] worldZ = new float[3];
worldZ[0] = sum(accelRingX) / Math.min(accelRingCounter, ACCEL_RING_SIZE);
worldZ[1] = sum(accelRingY) / Math.min(accelRingCounter, ACCEL_RING_SIZE);
worldZ[2] = sum(accelRingZ) / Math.min(accelRingCounter, ACCEL_RING_SIZE);
float normalization_factor = norm(worldZ);
worldZ[0] = worldZ[0] / normalization_factor;
worldZ[1] = worldZ[1] / normalization_factor;
worldZ[2] = worldZ[2] / normalization_factor;
float currentZ = dot(worldZ, currentAccel) - normalization_factor;
velRingCounter++;
velRing[velRingCounter % VEL_RING_SIZE] = currentZ;
float velocityEstimate = sum(velRing);
if (velocityEstimate > STEP_THRESHOLD
&& oldVelocityEstimate <= STEP_THRESHOLD
&& (timeNs - lastStepTimeNs > STEP_DELAY_NS)) {
//TODO: if we want to send the steps back to an activity/fragment/service etc
mSteps++;
// healthCallback.onStepCount(mSteps);
lastStepTimeNs = timeNs;
}
oldVelocityEstimate = velocityEstimate;
}
private float sum(float[] array) {
float retval = 0;
for (float v : array) {
retval += v;
}
return retval;
}
private float[] cross(float[] arrayA, float[] arrayB) {
float[] retArray = new float[3];
retArray[0] = arrayA[1] * arrayB[2] - arrayA[2] * arrayB[1];
retArray[1] = arrayA[2] * arrayB[0] - arrayA[0] * arrayB[2];
retArray[2] = arrayA[0] * arrayB[1] - arrayA[1] * arrayB[0];
return retArray;
}
private float norm(float[] array) {
float retval = 0;
for (float v : array) {
retval += v * v;
}
return (float) Math.sqrt(retval);
}
private float dot(float[] a, float[] b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
private float[] normalize(float[] a) {
float[] retval = new float[a.length];
float norm = norm(a);
for (int i = 0; i < a.length; i++) {
retval[i] = a[i] / norm;
}
return retval;
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
......@@ -50,6 +50,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -66,6 +67,7 @@ import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.WarplyUrlHandler;
import ly.warp.sdk.utils.constants.WarpConstants;
import ly.warp.sdk.utils.managers.WarplyAnalyticsManager;
import ly.warp.sdk.utils.managers.WarplyEventBusManager;
public class WarpView extends WebView {
......@@ -362,10 +364,13 @@ public class WarpView extends WebView {
public class JSInterface {
@JavascriptInterface
public void sendMessage(String message) {
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_TEXT, message);
getContext().startActivity(Intent.createChooser(intent, "Άνοιγμα με"));
// Intent intent = new Intent(android.content.Intent.ACTION_SEND);
// intent.setType("text/plain");
// intent.putExtra(android.content.Intent.EXTRA_TEXT, message);
// getContext().startActivity(Intent.createChooser(intent, "Άνοιγμα με"));
if (message.contains("event"))
EventBus.getDefault().post(new WarplyEventBusManager(message));
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/cos_grey2"/>
<corners android:radius="7dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1.5dp"
android:color="@color/cos_dark_blue" />
<corners
android:topLeftRadius="15dp"
android:topRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"/>
<solid android:color="@android:color/transparent" />
</shape>
\ No newline at end of file
......@@ -160,28 +160,28 @@
android:layout_height="50dp"
android:layout_marginHorizontal="32dp"
android:layout_marginTop="64dp"
android:background="@drawable/button_border_dark_blue"
android:background="@drawable/button_border_grey"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView17">
<ImageView
android:layout_width="34dp"
android:layout_height="25dp"
android:layout_marginRight="15dp"
android:adjustViewBounds="true"
android:src="@drawable/gift_icon" />
<!-- <ImageView-->
<!-- android:layout_width="34dp"-->
<!-- android:layout_height="25dp"-->
<!-- android:layout_marginRight="15dp"-->
<!-- android:adjustViewBounds="true"-->
<!-- android:src="@drawable/gift_icon" />-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Κάντο δώρο!"
android:textColor="@color/white"
android:textSize="17dp"
android:textStyle="bold" />
android:textColor="@color/cos_green6"
android:textFontWeight="600"
android:textSize="17dp" />
</LinearLayout>
<!-- <LinearLayout-->
......
......@@ -51,35 +51,61 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="6dp"
android:maxLines="1"
android:textColor="@color/grey"
app:layout_constraintLeft_toRightOf="@+id/iv_profile_photo"
app:layout_constraintTop_toTopOf="@+id/iv_profile_photo"
tools:text="Test Name" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="10dp"
android:background="@drawable/shape_cos_gradient"
android:gravity="center"
android:paddingHorizontal="4dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/iv_profile_photo"
app:layout_constraintLeft_toRightOf="@+id/iv_profile_photo">
app:layout_constraintStart_toEndOf="@+id/iv_profile_photo"
app:layout_constraintTop_toTopOf="@+id/iv_profile_photo">
<TextView
android:id="@+id/tv_type"
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="4dp"
android:maxLines="1"
android:textColor="@color/grey"
tools:text="Test Name" />
<LinearLayout
android:id="@+id/ll_user_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cos_profile_type"
android:textColor="@android:color/white" />
android:layout_marginStart="8dp"
android:background="@drawable/shape_cos_gradient"
android:gravity="center"
android:paddingHorizontal="4dp"
android:visibility="gone">
<TextView
android:id="@+id/tv_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
tools:text="@string/cos_profile_type" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_user_questionnaire"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:background="@drawable/shape_cos_transparent_rounded3"
android:gravity="center"
android:paddingHorizontal="8dp"
android:paddingVertical="4dp"
android:visibility="gone">
<TextView
android:id="@+id/tv_questionnaire"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cos_profile_questionnaire"
android:textColor="@color/cos_dark_blue"
android:textFontWeight="600" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
......
......@@ -37,4 +37,5 @@
<color name="cos_cyan3">#2EB2B9</color>
<color name="grey4">#F3F3F3</color>
<color name="grey_tr3">#7DF2F2F2</color>
<color name="cos_dark_blue">#355168</color>
</resources>
\ No newline at end of file
......
......@@ -54,6 +54,7 @@
<string name="cos_annual">12Μηνο</string>
<string name="cos_analysis2">Αναλυτικά</string>
<string name="euro"></string>
<string name="cos_profile_questionnaire">+ Ερωτηματολόγιο</string>
<string-array name="coupons_array">
<item>Κουπόνια</item>
......