Categories
discuss

Android Databinding Compile Warning: Method references using ‘.’ is deprecated

I see the following compiler warning when building my project:

warning: Method references using '.' is deprecated. Instead of 'item.onCardClicked', use 'item::onCardClicked'

I am using android plugin for gradle 2.1.0.

My layout file looks like the following:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

<data>
    <variable
        name="item"
        type="com.example.Card"/>
</data>
<LinearLayout android:layout_width="match_parent"
      android:layout_height="match_parent">
  <TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:clickable="true"
      android:onClick="@{item.onCardClicked}"/>
...
</LinearLayout>
</layout>

Can someone point me to the right direction to resolve this warning?

Answer

Per the error message:

warning: Method references using ‘.’ is deprecated. Instead of ‘item.onCardClicked’, use ‘item::onCardClicked’

So replace @{item.onCardClicked} with @{item::onCardClicked}

Categories
discuss

What is The Z at the end of Date in Elasticsearch

Why in Elasticsearch we have the ‘Z’ at the end of the date field?

For instance:

2016-05-16T00:00:00.000Z

What does it mean?

Is this something useful for anything?

Is it harmful?

Can I get rid of it?

What about joda time?

Answer

What does it mean?

The ‘Z’ means UTC.
Reference:
https://www.w3.org/TR/NOTE-datetime

Try not to store local dates. If you want to find a good thread on dates and why you should use UTC check this thread.

Is this something useful for anything?

It is very useful, storing all dates in UTC allows for easy conversion of dates from locale to locale. It also allows for date comparison and date visualisations to be consistent.

Is it harmful?

No.

Can I get rid of it?

If you wish? I wouldn’t recommend doing it… It’s a bit like removing the currency field from a transaction. The transaction doesn’t make any sense.

Another example with dates:

I rang my friend in Country X (+6 hours ahead) at 1pm December 24th 2016. For him it was 7pm. So we have two local date times.

One for me:

1pm December 24th 2016 in London

One for my friend:

7pm December 24th 2016 in Country X

If I delete the ‘in …’ Part these two become become two instances of time 5 hours apart of each other. Which means we couldn’t have possibly spoken on the phone? Right?

No, because they are the same instance in time, across two locales.

What about joda time?

What about it?…

I hope this helps.

Categories
discuss

How to exponentially increase the interval for retries in Spring RequestHandlerRetryAdvice

The retry is specified as follows:

<bean id="retryAdvice"
    class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice" >
    <property name="retryTemplate">
            <bean class="org.springframework.retry.support.RetryTemplate">
            <property name="backOffPolicy">
                    <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
                    <property name="initialInterval" value="5000"/>
                    <property name="multiplier" value="3.0"/>
                    </bean>
            </property>
            <property name="retryPolicy">
                    <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
                    <property name="maxAttempts" value="6" />
                    </bean>
            </property>
            </bean>
    </property>
</bean>

I expected that the interval would be increased by 3 times with every attempt. In reality I got the following intervals: 5, 15, 30, 30, 30 seconds. See the exact times and intervals below. What did I specify incorrectly?

2016-05-10 10:07:49,714 - 0
2016-05-10 10:07:55,085 - 5.2
2016-05-10 10:08:10,457 - 15.4
2016-05-10 10:08:40,830 - 30.4
2016-05-10 10:09:11,230 - 30.4
2016-05-10 10:09:41,639 - 30.4

Answer

There is maxInterval to consider:

/**
 * Setter for maximum back off period. Default is 30000 (30 seconds). the
 * value will be reset to 1 if this method is called with a value less than
 * 1. Set this to avoid infinite waits if backing off a large number of
 * times (or if the multiplier is set too high).
 *
 * @param maxInterval in milliseconds.
 */
public void setMaxInterval(long maxInterval) {
    this.maxInterval = maxInterval > 0 ? maxInterval : 1;
}

So, when your ExponentialBackOffPolicy reaches 30 secs (default) it stops to use multiplier afterwards.

Categories
discuss

Typescript module has no exported members – react

I am working on a react, redux Typescript application. I have a strange situation where after some changes one of the modules has stopped exporting its members.

The folder structure is:

src
|---- components
|---- containers

The ‘components’ folder has the .tsx files while the wrapping .ts files are in the ‘containers’ folder.

The module NodeList.tsx is listed below:

import * as React from "react";

export const NodeList = (props) => (
    <div id="NodeList">
        <ul>
        {props.items.map((item, i) => (
            <li key={i} >
                <span id={"Item_"+i}>{item}</span>
            </li>
            )
        )}
        </ul>
    </div>
    )

The wrapping container NodeListContainer is:

import { connect } from "react-redux";
import { Provider } from "react-redux";

import { Nodelist } from "../components/NodeList"

const nodesAsArrayOfType = (state, nodeType: string) => {
    console.log("Going for nodes of type ", nodeType)
    let a = state.data.model.nodes
    let k = Object.keys(a);
    let sub = k.filter((e) => {
                   return a[e].nodeType == nodeType
        }).map((e) => a[e])
    console.log("Got nodes ", sub)    
    return sub
}

const mapStateToProps = (state) => {
    var list = nodesAsArrayOfType(state, state.UIstate.focusNodeType).map((e) => {return JSON.stringify(e)})
    console.log("Returning ", list, list.length)
    return {
        items: list
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        newTextValue: (e) => {dispatch({type: "ON_CHANGE", text: e.target.value})}
    }
}

export const NodeListContainer = connect(
    mapStateToProps,
    mapDispatchToProps
    )(NodeList)

The import of NodeList above is being flagged with the error message

ERROR in ./src/containers/NodeListContainer.ts
(4,10): error TS2305: Module '"MyProject/src/components/NodeList"' has no exported member 'Nodelist'.

Can anyone provide any insight into what might have happened here?

Answer

Your code should work if you fix your typo.

Instead of

import { Nodelist } from "../components/NodeList"

you should write :

import { NodeList } from "../components/NodeList"
//           ^ capital L
Categories
discuss

how can i save the state of my webview when changing orientation using a webviewfragment

I have a small webView in one of my layouts that act as a news feed from my website.Every time I changed rotation it would reload the web page.

so I edited the code to include a on config change and on restore state.Then adjusted my android manifest to include the config changes which from the dev site says to include orientation and screen size.

This solves the problem of saving the state but in turn creates a new problem which is I have different size layouts for when its in landscape mode on certain devices. but with the manifest set how it is it overrides screen size. is there away to save the state but with out using screen size in my manifest. so then i could use my landscape layout

here is my code for the orientation changes.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();

    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);



    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_homescreen);
    if (savedInstanceState != null)
        ((WebView)findViewById(R.id.neweview)).restoreState(savedInstanceState);
    svHomeScreen = (ScrollView) findViewById(R.id.svHomeScreen);
    svHomeScreen.setScrollbarFadingEnabled(false);

    wv = (WebView) findViewById(R.id.neweview
    );
    wv.setScrollbarFadingEnabled(false);

    wv.getSettings().setJavaScriptEnabled(true);
    wv.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    wv.getSettings().setRenderPriority(WebSettings.RenderPriority.NORMAL);
    wv.getSettings().setLoadsImagesAutomatically(true);
    wv.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

    if (Build.VERSION.SDK_INT >= 19) {
        // chromium, enable hardware acceleration
        wv.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else {
        // older android version, disable hardware acceleration
        wv.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    wv.canGoBackOrForward(5);
    wv.getSettings().setLoadWithOverviewMode(true);
    wv.getSettings().setUseWideViewPort(true);
    wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);


    wv.setPadding(0, 0, 0, 0);
    wv.loadUrl(NEWS);

then my manifest file has

 <activity
        android:name=".Homescreen"
        android:label="@string/title_activity_homescreen"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        />

ive added a container an a web view fragment but now the view disappears when rotation is landscape. then disappears completly when i switch back. so i tried adding the save out state and savestate to it which loaded the webview when rotated to landscape but crashed the app when going back to portrait

Answer

Here’s some sample code that places the WebView in the activity layout as a fragment. In portrait mode, the view is centered, in landscape, it is positioned at the bottom. Both orientations use the same single WebView instance.

public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // load the fragment - we only need to do this when the activity is first created
        // - not on a recreation due to screen rotation, etc
        if (savedInstanceState == null) {
            FragmentManager fm = this.getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(R.id.container, new WebViewFragment());
            ft.commit();
        }

    }

    // this could go in a separate file
    public static class WebViewFragment extends Fragment {
        WebView mWebView;

        @Override
        public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
            View v = layoutInflater.inflate(R.layout.webviewfrag, null, false);
            this.mWebView = (WebView)v.findViewById(R.id.NewsFeedWbview);
            this.mWebView.loadUrl("https://google.com");
            return v;
        }

    }
}

res/layout/main.xml (default/portrait mode)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
    <!-- container layout for the webview fragment
    - note the id for this view is the same in both this and the landscape version -->
   <FrameLayout
   android:id="@+id/container"
   android:layout_width="match_parent"
   android:layout_height="240dp"
   android:layout_centerVertical="true"
    />

</RelativeLayout>

res/layout-land/main.xml (landscape)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
    <!-- container layout for the webview fragment
    - note the id for this view is the same in both this and the portrait version -->
   <FrameLayout
   android:id="@+id/container"
   android:layout_width="match_parent"
   android:layout_height="100dp"
   android:layout_alignParentBottom="true"
   />

</RelativeLayout>

res/layout/webviewfrag.xml

<!-- make the WebView fill its container -->
    <WebView
      xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/NewsFeedWbview"
          android:layout_width="match_parent"
          android:layout_height="match_parent" 
      />
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..