Thursday, 1 December 2022

My method does not work inside of onKeyEntered

I am trying to create an app that will allow users to rent a car nearest to them. I want to build a cardView with a textView and imageView once i find the nearest car, I created the method buildCardView to do that. My problem is that the cardView is not getting created when its called. buildCardView works fine when I call it directly, but not when called inside of the Geoquery onKeyEntered method. I debugged the code and the method buildCardView is getting called inside of on onKeyEntered but the cardView is not visible. Below is the code for that calls the firebase method.

FindCar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
                   findClosestCars();
        }
    });

Below is the firebase method that calls buildCardView

private void findClosestCars() {
    if (ActivityCompat.checkSelfPermission(RentersMenuPageActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

     //  turnOnLocationUpdates();
        //fusedLocationClient.requestLocationUpdates(mLocationRequest, locationCallback, Looper.myLooper());

        databaseReference = FirebaseDatabase.getInstance().getReference("Users").child("Lenders");
        GeoFire geoFire = new GeoFire(databaseReference);
        GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(latitude, longitude), radius);
        geoQuery.removeAllListeners();

        geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
            @Override
            public void onKeyEntered(String key, GeoLocation location) {
           //
                //  Toast.makeText(RentersMenuPageActivity.this, "You Found a Lender",Toast.LENGTH_LONG);
                  //      Toast.LENGTH_LONG).show();


                //showPictureAndPrice();

                if (!driverFound) {
                    driverFound = true;
                    driverFoundID = key;

                    closestLender = FirebaseDatabase.getInstance().getReference("Users").child("Lenders").child(driverFoundID);

                    String [] lenderLocations;

                    buildCardView();
                }

               radius++;
            }

Below is buildCardView that inflates a smaller view inside the main one (works when called directly but not from onkeyentered)

private void buildCardView(){
    Toast.makeText(RentersMenuPageActivity.this, "You Found a Lender",Toast.LENGTH_LONG).show();

    LayoutInflater mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    View view =getLayoutInflater().inflate(R.layout.card,null);

   // CardView cardView = view.findViewById(R.id.cardView);
    Button rentCarButton = view.findViewById(R.id.rentCarButton);
    TextView price= view.findViewById(R.id.price);
    TextView makeandmodel = view.findViewById(R.id.makeandmodel);
    ImageView imageView =view.findViewById(R.id.imageViewScroll);

    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    linearLayout.addView(view);
}


from My method does not work inside of onKeyEntered

Proguard rules with Excel fail on release build - Android

Edit: Updated with dependencies

Dependencies:

implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
implementation group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '3.1.0'
implementation 'com.fasterxml:aalto-xml:1.2.2'

In my proguard file I have the following:

-keep class org.apache.poi.** {*;}
-keep class org.apache.xmlbeans.** {*;}
-keep class com.fasterxml.** {*;}
-keep class com.microsoft.schemas.** {*;}
-keep class org.openxmlformats.** {*;}
-keep class org.openxmlformats.schemas.** {*;}
-keep class schemaorg_apache_xmlbeans.** {*;}

This works fine in the debug build, but causes a crash when axcessing one of the methods in the release build.

The full stack trace:

java.lang.ExceptionInInitializerError
    at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Unknown Source:0)
    at j7.a.a(SourceFile:2)
    at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook.<clinit>(SourceFile:1)
    at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.newInstance(Unknown Source:0)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(SourceFile:1)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(SourceFile:5)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(SourceFile:1)
    at com.shervinkoushan.anyTracker.shared.utils.FileUtils.pointsToWorkBook(SourceFile:2)
    at com.shervinkoushan.anyTracker.shared.utils.FileUtils.dataPointsToExcelFile(SourceFile:1)
    at f9.k.invokeSuspend(SourceFile:17)
    at sa.a.resumeWith(SourceFile:3)
    at qd.o0.run(SourceFile:18)
    at xd.a$a.run(SourceFile:14)
Caused by: java.lang.IllegalStateException: Cannot load nodeToCursor: verify that xbean.jar is on the classpath
    at org.apache.xmlbeans.XmlBeans.buildMethod(SourceFile:4)
    at org.apache.xmlbeans.XmlBeans.buildNodeMethod(Unknown Source:18)
    at org.apache.xmlbeans.XmlBeans.buildNodeToCursorMethod(Unknown Source:4)
    at org.apache.xmlbeans.XmlBeans.<clinit>(SourceFile:11)
    at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Unknown Source:0) 
    at j7.a.a(SourceFile:2) 
    at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook.<clinit>(SourceFile:1) 
    at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.newInstance(Unknown Source:0) 
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(SourceFile:1) 
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(SourceFile:5) 
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(SourceFile:1) 
    at com.shervinkoushan.anyTracker.shared.utils.FileUtils.pointsToWorkBook(SourceFile:2) 
    at com.shervinkoushan.anyTracker.shared.utils.FileUtils.dataPointsToExcelFile(SourceFile:1) 
    at f9.k.invokeSuspend(SourceFile:17) 
    at sa.a.resumeWith(SourceFile:3) 
    at qd.o0.run(SourceFile:18) 
    at xd.a$a.run(SourceFile:14) 
Caused by: java.lang.NoSuchMethodException: org.apache.xmlbeans.impl.store.Locale.nodeToCursor [interface org.w3c.dom.Node]
    at java.lang.Class.getMethod(Class.java:2103)
    at java.lang.Class.getMethod(Class.java:1724)
    at org.apache.xmlbeans.XmlBeans.buildMethod(SourceFile:1)
    at org.apache.xmlbeans.XmlBeans.buildNodeMethod(Unknown Source:18) 
    at org.apache.xmlbeans.XmlBeans.buildNodeToCursorMethod(Unknown Source:4) 
    at org.apache.xmlbeans.XmlBeans.<clinit>(SourceFile:11) 
    at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(Unknown Source:0) 
    at j7.a.a(SourceFile:2) 
    at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook.<clinit>(SourceFile:1) 
    at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.newInstance(Unknown Source:0) 
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(SourceFile:1) 
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(SourceFile:5) 
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(SourceFile:1) 
    at com.shervinkoushan.anyTracker.shared.utils.FileUtils.pointsToWorkBook(SourceFile:2) 
    at com.shervinkoushan.anyTracker.shared.utils.FileUtils.dataPointsToExcelFile(SourceFile:1) 
    at f9.k.invokeSuspend(SourceFile:17) 
    at sa.a.resumeWith(SourceFile:3) 
    at qd.o0.run(SourceFile:18) 

Is there anything I am missing in my proguard file? I have tried various code snippets from Stack Overflow with no success.



from Proguard rules with Excel fail on release build - Android

Pandas: resample hourly values to monthly values with offset

I want to aggregate a pandas.Series with an hourly DatetimeIndex to monthly values - while considering the offset to midnight.

Example

Consider the following (uniform) timeseries that spans about 1.5 months.

import pandas as pd
hours = pd.Series(1, pd.date_range('2020-02-23 06:00', freq = 'H', periods=1008))
hours
# 2020-02-23 06:00:00    1
# 2020-02-23 07:00:00    1
#                       ..
# 2020-04-05 04:00:00    1
# 2020-04-05 05:00:00    1
# Freq: H, Length: 1000, dtype: int64

I would like to sum these to months while considering, that days start at 06:00 in this use-case. The result should be:

2020-02-01 06:00:00    168
2020-03-01 06:00:00    744
2020-04-01 06:00:00     96
freq: MS, dtype: int64

How do I do that??


What I've tried and what works

  • I can aggregate to days while considering the offset, using the offset parameter:

    days = hours.resample('D', offset=pd.Timedelta('06:00:00')).sum()
    days
    # 2020-02-23 06:00:00    24
    # 2020-02-24 06:00:00    24
    # ..
    # 2020-04-03 06:00:00    24
    # 2020-04-04 06:00:00    24  
    # Freq: D, dtype: int64
    
  • Using the same method to aggregate to months does not work. The timestamps do not have a time component, and the values are incorrect:

    months = hours.resample('MS', offset=pd.Timedelta('06:00:00')).sum()
    months
    # 2020-02-01    162 # wrong
    # 2020-03-01    744
    # 2020-04-01    102 # wrong
    # Freq: MS, dtype: int64
    
  • I could do the aggregation to months as a second step after aggregating to days. In that case, the values are correct, but the time component is still missing from the timestamps:

    days = hours.resample('D', offset=pd.Timedelta('06:00:00')).sum()
    months = days.resample('MS', offset=pd.Timedelta('06:00:00')).sum()
    months
    # 2020-02-01    168
    # 2020-03-01    744
    # 2020-04-01     96
    # Freq: MS, dtype: int64
    
  • My current workaround is adding the timedelta and resetting the frequency manually.

    months.index += pd.Timedelta('06:00:00')
    months.index.freq = 'MS' 
    months
    # 2020-02-01 06:00:00    168
    # 2020-03-01 06:00:00    744
    # 2020-04-01 06:00:00     96
    # freq: MS, dtype: int64
    


from Pandas: resample hourly values to monthly values with offset