Badge like notification (kotlin) : null object reference - kotlin

I want to show some value in my ActionBar thanks to the "badge".
But, when I run my app, I have this error :
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
On this line :
notifCount = count.findViewById(R.id.notif_count)
Here's my code :
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<item
android:id="#+id/badge"
android:orderInCategory="100"
android:title="#string/alertes"
android:actionLayout="#layout/feed_update_count"
app:showAsAction="always" />
</menu>
feed_update.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/notif_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="32dp"
android:minHeight="32dp"
android:background="#drawable/red_circle"
android:text="0"
android:textSize="16sp"
android:textColor="#android:color/white"
android:gravity="center"
android:padding="2dp"
android:singleLine="true">
</Button>
main_activity.kt
private lateinit var notifCount: Button
var mNotifCount = 0
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
val count = menu.findItem(R.id.badge).actionView
notifCount = count.findViewById(R.id.notif_count)
notifCount.text = "1"
return super.onCreateOptionsMenu(menu)
//return true
}

Count should be
val count = menu.findItem(R.id.badge)
notifCount = count.findViewById(R.id.notif_count)
notifCount.text = "1"

Got it :
change
android:actionLayout="#layout/feed_update_count"
to
app:actionLayout="#layout/feed_update_count"

Related

Why we should write List and DetailedUser in the variable <variable type = "list<DetailedUser" name="">

I don't understand this line of the code why we have list and DetailedUser?
<data>
//app class
<import type = "com.androidistanbul.databindingdemo.layoutdetails.DetailedUser/>
// java class
<import type= "java.util.List"/>
<variable
name = "userList"
type = "detailedUser" /> // import class
<variable
name="userList"
type = "list<DetailedUser" />
</data>
// List index
<TextView
// android:layout_midth = "wrap_content"
// android:layout_height= "wrap_content"
// android:layout_marginTop = "8dp"
android:text="#{userList[index].name + "" + userList[index].surnane}"/>
< and > are html entities and they represent < and >, respectively.
So List<DetailedUser> translates to List<DetailedUser>

ant store variable in scriptdef or call task in script def

My knowledge of ant is close to nothing.
i do understand it should not be used as a programming language but i'm a consumer of a certain ant project and want to modify something in my own project while using the libraries that project offers me.
the main point i want to do is I have a string and need to modify it before sending it to the parent project target.
i'll try providing a code easy to understand, but at the moment the part i have left is:
either store the value in a variable instead of a property (not sure how to do this)
directly call the other target from my javascript function.
so this is the code:
<target name="deploy-custom" depends="init">
<scriptdef name="replaceString" language="javascript">
<attribute name="fileIn" />
<attribute name="directoryFile" />
<![CDATA[echo = project.createTask("echo");
var fileName = attributes.get("filein"); //get attribute for scriptdef
var directoryIn = attributes.get("directoryfile"); //get attribute for scriptdef
echo.setMessage("file name: " + fileName );
echo.perform( );
echo.setMessage("dir in " + directoryIn );
echo.perform( );
var fileOut = fileName.replace(directoryIn, "");
echo.setMessage("replace " + fileOut );
echo.perform( );
project.setProperty("undeploy_name", fileOut);]]>
</scriptdef>
<echo message="executing target deploy-custom" />
<for param="file">
<path>
<fileset dir="${mydir}/content/custom-deploy">
<include name="*.war" />
</fileset>
</path>
<sequential>
<replaceString fileIn="#{file}" directoryFile="${mydir}/content/custom-deploy/" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="${undeploy_name}" />
</JBossCLI>
<deployToLiferay file="#{file}" />
</sequential>
</for>
<echo>ABRS custom banklets deployed!</echo>
</target>
so my question is at the time i try to save the undeploy_name property can I just call the target deployToLiferay? if not is there a way i can save that in a variable instead a property?
i don't mind using other language instead of javascript but not really sure how can i do what i need to do.
based on the info i found in here i'm now trying to focus on the using the script directly. this is the info i get:
https://coderanch.com/t/108191/call-ant-macrodef-groovy-script
i tried to modify my script to something like this:
<macrodef name="undeploy">
<attribute name="undplPattern" />
<sequential>
<echo message="undeploy undplPattern #{undplPattern}" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="#{undplPattern}" />
</JBossCLI>
</sequential>
</macrodef>
<scriptdef name="undeploy-pattern" language="javascript">
<attribute name="fileIn" />
<attribute name="directoryFile" />
<![CDATA[
var echo = project.createTask("echo");
var fileName = attributes.get("filein"); //get attribute for scriptdef
var directoryIn = attributes.get("directoryfile"); //get attribute for scriptdef
echo.setMessage("file name: " + fileName );
echo.perform( );
echo.setMessage("dir in " + directoryIn );
echo.perform( );
var fileOut = fileName.replace(directoryIn, "");
fileOut = fileOut.replace(/\d+/g, "");
fileOut = fileOut.replace("..",".*");
fileOut = fileOut.replace(/[.]/g,"\\.");
fileOut = fileOut.replace("web-\\.*\\.war","web.*");
echo.setMessage("undeploy pattern transformation: " + fileOut );
echo.perform( );
var undeploy_t = project.createTask("undeploy");
undeploy_t.setDynamicAttribute("undplPattern", fileOut);
undeploy_t.perform( );
]]>
</scriptdef>
called from:
<echo message="item #{file}" />
<undeploy-pattern fileIn="#{file}" directoryFile="${currentScriptDirectory}/content/custom-banklets/" />
<deployToLiferay file="#{file}" />
after this modifications it now fails when i try to set setDynamicAttribute and perform that task.
08:01:18.492: item /data/com.client-dshbrd-banklet-web-0.0.1.war
08:01:18.509: file name: /data/com.client-dshbrd-banklet-web-0.0.1.war
08:01:18.510: dir in /data/
08:01:18.520: undeploy pattern transformation: com\.client-dshbrd-banklet-web.*
08:01:18.528: COMMAND 'deploy-custom-banklets' FAILED (execution time: 2 seconds)
08:01:18.528: * /data/contribution.xml:250: The following error occurred while executing this line:
08:01:18.528: * /data/contribution.xml:259: required attribute undplpattern not set
I don't think you need an embedded script. I reviewed the logic and I think it would be simpler to use the ANT basename task in order to obtain the file name.
Example
├── build.xml
└── src
└── files
└── file1.war
Project run as follows
$ ant
build:
[echo] file1.war
build.xml
<project name="demo" default="build">
<target name="build">
<basename property="undeploy_name" file="src/files/file1.war"/>
<echo>${undeploy_name}</echo>
</target>
</project>

How to import the ControlsFx SpreadsheetView into my FXML-File?

i have Problems including the SpreadsheetView by ControlsFX into my FXML-file, is it even possible? Maybe someone could show some of his/her Code?
Thanks in advance!
As you can read here, it seems ControlsFX and Scene Builder don't play well together (yet).
All I can managed to integrate was just the SpreadsheetView on a FXML file, more like a placeholder for the control, since we can't add a GridBase object.
<?xml version="1.0" encoding="UTF-8"?>
<?import org.controlsfx.control.*?>
<?import org.controlsfx.control.spreadsheet.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
<children>
<SpreadsheetView fx:id="spreadsheet" editable="true" showRowHeader="true" showColumnHeader="true" prefHeight="300.0" prefWidth="400.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"/>
</children>
</AnchorPane>
And then, in Controller:
#FXML private SpreadsheetView spreadsheet;
/**
* Initializes the controller class.
* #param url
* #param rb
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
int rowCount = 5;
int columnCount = 3;
GridBase grid = new GridBase(rowCount, columnCount);
ObservableList<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
for (int row = 0; row < grid.getRowCount(); ++row) {
final ObservableList<SpreadsheetCell> list = FXCollections.observableArrayList();
for (int column = 0; column < grid.getColumnCount(); ++column) {
list.add(SpreadsheetCellType.STRING.createCell(row, column, 1, 1,"value"));
}
rows.add(list);
}
grid.setRows(rows);
spreadsheet.setGrid(grid);
}

androidplot line not displayed

I'm expecting to see a straight line defined by 2 points on my graph but nothing shows up.
I followed the tutorial and everything worked fine, then I tried to change the series of numbers. Here is the code:
plotList is of type List and it contains 2 values 12.634 and 12.634
XYSeries series1 = new SimpleXYSeries(plotList,
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
"Series1");
// Create a formatter to use for drawing a series using
// LineAndPointRenderer
// and configure it from xml:
LineAndPointFormatter series1Format = new LineAndPointFormatter();
series1Format.setPointLabelFormatter(new PointLabelFormatter());
series1Format.configure(parentActivity.getApplicationContext(),
R.xml.line_point_formatter_with_plf1);
//plot.setDomainRightMax(plotList.size());
//plot.setDomainBoundaries(0, 5, BoundaryMode.AUTO);
// plot.setDomainStepValue(1);
//plot.setRangeBoundaries(0,40,BoundaryMode.AUTO);
// add a new series' to the xyplot:
plot.addSeries(series1, series1Format);
// reduce the number of range labels
plot.setTicksPerRangeLabel(3);
plot.getGraphWidget().setDomainLabelOrientation(-45);
Try this
List<Number> plotList = new ArrayList<Number>();
plotList.add(1212);
plotList.add(12334);
XYSeries series1 = new SimpleXYSeries(plotList,SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1");
LineAndPointFormatter series1Format = new LineAndPointFormatter(
Color.rgb(0, 200, 0), // line color
Color.rgb(0, 100, 0), // point color
Color.rgb(150, 190, 150)); // fill color (optional)
XYPlot plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);;
plot.addSeries(series1, series1Format);
// reduce the number of range labels
plot.setTicksPerRangeLabel(3);
// plot.getGraphWidget().setDomainLabelOrientation(-45);
and ur xml should be
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.androidplot.xy.XYPlot
android:id="#+id/mySimpleXYPlot"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
title="Stats" />
</LinearLayout>

Deploy BrowserFormWebPart declaratively without BinarySerializedWebPart Element

Does anyone know if there is a way to deploy a BrowserFormWebPart (custom InfoPath form for a list content type) using standard AllUsersWebPart element and a CDATA section for the properties? So far I have tried without success. Any help is appreciated.
After 2 days of research - Following code works
private void UpdateInfoPathForms(SPSite oSite)
{
UpdateInfoPath(oSite, "Lists/Audit Calendar/Item/newifs.aspx");
UpdateInfoPath(oSite, "Lists/Audit Calendar/Item/displayifs.aspx");
UpdateInfoPath(oSite, "Lists/Audit Calendar/Item/editifs.aspx");
}
private void UpdateInfoPath(SPSite oSite, string formFileLocation)
{
var file = oSite.RootWeb.GetFile(formFileLocation);
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
try
{
var wp1 = new Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart();
wp1.SubmitBehavior = Microsoft.Office.InfoPath.Server.Controls.WebUI.SubmitBehavior.FormDefault;
wp1.FormLocation = "~list/Item/template.xsn";
wp1.ContentTypeId = oSite.RootWeb.Lists["Audit Calendar"].ContentTypes["Item"].Id.ToString();
IListWebPart listWebpart = wp1 as IListWebPart;
listWebpart.ListId = oSite.RootWeb.Lists["Audit Calendar"].ID;
if (formFileLocation.Contains("newifs.aspx"))
{
listWebpart.PageType = PAGETYPE.PAGE_NEWFORM;
}
else if (formFileLocation.Contains("displayifs.aspx"))
{
wp1.ListFormMode = Microsoft.Office.InfoPath.Server.Controls.WebUI.ListFormMode.ReadOnly;
listWebpart.PageType = PAGETYPE.PAGE_DISPLAYFORM;
}
else if (formFileLocation.Contains("editifs.aspx"))
{
listWebpart.PageType = PAGETYPE.PAGE_EDITFORM;
}
listWebpart.ViewFlags = SPViewFlags.None;
manager.AddWebPart(wp1, "Main", 0);
manager.SaveChanges(wp1);
}
finally
{
manager.Web.Dispose();
}
}
I have had the same problem. Here is what I tried:
<AllUsersWebPart WebPartZoneID="Main" WebPartOrder="2">
<![CDATA[
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart, Microsoft.Office.InfoPath.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="ChromeType" type="chrometype">None</property>
<property name="HelpMode" type="helpmode">Modeless</property>
<property name="ChromeState" type="chromestate">Normal</property>
</properties>
</data>
</webPart>
</webParts>]]>
</AllUsersWebPart>
I then have a Feature Receiver that configures the web part:
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
try
{
BrowserFormWebPart webpart = GetWebPart(manager);
webpart.SubmitBehavior = SubmitBehavior.FormDefault;
webpart.FormLocation = "~list/MyList/template.xsn";
webpart.ContentTypeId = "0x01003C8AD6E14DAD5342BBFAA84E63F8022C";
manager.SaveChanges(webpart);
}
finally
{
manager.Web.Dispose();
}
}
The BrowserFormWebPart properties are required for getting the form to display, but for some reason, setting those properties in the AllUsersWebPart section did not work. The form displays and I can fill it out, but the values from the form do not get inserted into the fields of the list item. I added the following section to the Feature Receiver to try to get the form to tie into the fields of the list item:
IListWebPart listWebpart = webpart as IListWebPart;
listWebpart.PageType = PAGETYPE.PAGE_EDITFORM;
listWebpart.ViewFlags = SPViewFlags.None;
Unfortunately, no joy. And that is as far as I got. Hopefully you'll have better luck.