Create `signature area` for mobile app in dart (flutter) [closed] - mobile

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
i want to create a signature area like Here with dart in a mobile app!
I tried to use the CustomPaint class ... But it doesn't work.
Can anyone help me?

You can create a signature area using GestureDetector to record touches and CustomPaint to draw on the screen. Here are a few tips:
Use RenderBox.globalToLocal to convert the DragUpdateDetails provided by GestureDetector.onPanUpdate into relative coordinates
Use a GestureDetector.onPanEnd gesture handler to record the breaks between strokes.
Mutating the same List won't automatically trigger a repaint because the CustomPainter constructor arguments are the same. You can trigger a repaint by creating a new List each time a new point is provided.
Use Canvas.drawLine to draw a rounded line between each of the recorded points of the signature.
import 'package:flutter/material.dart';
class SignaturePainter extends CustomPainter {
SignaturePainter(this.points);
final List<Offset> points;
void paint(Canvas canvas, Size size) {
Paint paint = new Paint()
..color = Colors.black
..strokeCap = StrokeCap.round
..strokeWidth = 5.0;
for (int i = 0; i < points.length - 1; i++) {
if (points[i] != null && points[i + 1] != null)
canvas.drawLine(points[i], points[i + 1], paint);
}
}
bool shouldRepaint(SignaturePainter other) => other.points != points;
}
class Signature extends StatefulWidget {
SignatureState createState() => new SignatureState();
}
class SignatureState extends State<Signature> {
List<Offset> _points = <Offset>[];
Widget build(BuildContext context) {
return new Stack(
children: [
GestureDetector(
onPanUpdate: (DragUpdateDetails details) {
RenderBox referenceBox = context.findRenderObject();
Offset localPosition =
referenceBox.globalToLocal(details.globalPosition);
setState(() {
_points = new List.from(_points)..add(localPosition);
});
},
onPanEnd: (DragEndDetails details) => _points.add(null),
),
CustomPaint(painter: SignaturePainter(_points), size: Size.infinite),
],
);
}
}
class DemoApp extends StatelessWidget {
Widget build(BuildContext context) => new Scaffold(body: new Signature());
}
void main() => runApp(new MaterialApp(home: new DemoApp()));

Related

whats is alternate solution of fluent wait wait.until() method in selenium 3.x.x? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
whats is alternate solution of fluent wait wait.until() method in selenium 3.x.x ?
It is giving some functional reference for util method.
Please guide.
Advance Webdriver Waits
create our own Custom Waits or Advance WebDriver Waits.please refer to this link.
http://toolsqa.com/selenium-webdriver/advance-webdriver-waits/
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://toolsqa.wpengine.com/automation-practice-switch-windows/");
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
wait.pollingEvery(250, TimeUnit.MILLISECONDS);
wait.withTimeout(2, TimeUnit.SECONDS);
Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>()
{
public Boolean apply(WebDriver arg0) {
WebElement element = arg0.findElement(By.id("colorVar"));
String color = element.getAttribute("color");
System.out.println("The color if the button is " + color);
if(color.equals("red"))
{
return true;
}
return false;
}
};
wait.until(function);
}
You can integrate fluent wait with the explicit wait like below
/*
* wait until expected element is visible
*/
public boolean waitForElement(WebDriver driver, By expectedElement) {
boolean isFound = true;
try {
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds , 300);
wait.pollingEvery(2, TimeUnit.SECONDS);
wait.until(ExpectedConditions.visibilityOfElementLocated(expectedElement));
makeWait(1);
} catch (Exception e) {
//System.out.println(e.getMessage());
isFound = false;
}
return isFound;
}

Rectangles are not drawn as expected

Recently I was somewhat unsure about the presentation of my app and therefore I created a small tester app to look at this topic more closely.
For that I derived my own component class which did nothing els than draw the outer bounds of itself and was surprised that it wasn't completely shown - neither in the simulator, nor on my iPhone 5S.
Now to my question: Why is it that a component drawn as aGraphics.drawRect(getX() + 2, getY() + 2, 10, 10) shows as eleven pixels wide and high in the simulator and on my iPhone 5S?
Here is some code which can be used to demonstrate this:
public class FormRectangleComponent extends Form {
private class RectangleComponent extends Component {
private int color;
public RectangleComponent(int aColor) {
color = aColor;
}
#Override
public void paint(Graphics aGraphics) {
aGraphics.setColor(color);
aGraphics.drawRect(getX(), getY(), getWidth(), getHeight());
Map<String,Object> map = new LinkedHashMap<String,Object>() {{
put("Display.displayWidth", Display.getInstance().getDisplayWidth());
put("rectangleComponent.x", getX());
put("rectangleComponent.y", getY());
put("rectangleComponent.width", getWidth());
put("rectangleComponent.height", getHeight());
}};
aGraphics.setColor(0xffffff);
aGraphics.drawRect(getX() + 2, getY() + 2, 10, 10);
report(map);
}
#Override
protected Dimension calcPreferredSize() {
int side = Display.getInstance().getDisplayHeight() / 10;
return new Dimension(side, side);
}
}
public FormRectangleComponent() {
Display.getInstance().areMutableImagesFast();
setTitle("FormRectangleComponent");
setScrollable(false);
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
contentPane.setScrollableY(true);
contentPane.getAllStyles().setBgPainter((Graphics aGraphics, Rectangle aRectangle) -> {
aGraphics.setColor(0x00c0c0);
aGraphics.fillRect(aRectangle.getX(), aRectangle.getY(), aRectangle.getWidth(), aRectangle.getHeight());
});
contentPane.add(new SpanLabel(
"Below should be some frames showing all sides."));
contentPane.add(new RectangleComponent(0xff0000));
contentPane.add(new RectangleComponent(0x0000ff));
contentPane.add(new RectangleComponent(0x00ff00));
}
private void report(Map<String, Object> map) {
int maximumLength = 0;
for (Entry<String, Object> entry: map.entrySet()) {
maximumLength = Math.max(maximumLength, entry.getKey().length());
}
for (Entry<String, Object> entry: map.entrySet()) {
StringBuilder stringBuilder = new StringBuilder();
for (int tally = 0; tally < (maximumLength - entry.getKey().length()); tally ++) {
stringBuilder.append(' ');
}
stringBuilder
.append(entry.getKey())
.append(": ")
.append(entry.getValue());
Log.p(stringBuilder.toString());
}
}
}
It's mentioned here in brief but this behavior is based on the convention within the Java graphics API's documented here.
Graphics is a low level API and we tried to keep it consistent with the way Java works. All our samples rely on the width/height -1 convention so it's documented by example & consistency if by nothing else.
The logic for this is mathematical, you don't draw on pixels but in a virtual co-ordinate space that resides between the pixels which makes more sense as you start to transform graphics operations.

Codename one Android Sidemenu

I'm trying to implement an Android style side menu and I'm having an issue implementing the rounded icon on top and labels below it before the sideCommands are added.
How do I implement this please?
You can use Toolbar API which allows you to add components to the Sidemenu.
Have a look at Flickr demo.
Instead of using tool.addCommandToSideMenu(Command) you should use tool.addComponentToSideMenu(yourComponent, CommandToPerform)
Example:
#Override
protected void beforeMain(Form f) {
//Store your commands before setting toolbar
List<Command> cmds = new ArrayList();
for (int i = 0; i < f.getCommandCount(); i++) {
cmds.add(f.getCommand(i));
}
Toolbar toolbar = new Toolbar();
f.setToolBar(toolbar);
Label lblTitle = new Label("My Form", "Title");
lblTitle.setEndsWith3Points(false);
toolbar.setTitleComponent(lblTitle);
// Use your stored commands after setting toolbar
for (Command cmd : cmds) {
toolbar.addCommandToSideMenu(cmd);
}
Container CustomContainer = ...
toolbar.addComponentToSideMenu(CustomContainer, new Command("") {
#Override
public void actionPerformed(ActionEvent evt) {
//What CustomContainer should do (if any)
}
});
f.revalidate();
}

How to get FixedDocument from PageDocuments [duplicate]

This question already has answers here:
How to Print Preview when using a DocumentPaginator to print?
(6 answers)
Closed 4 years ago.
I am working with printing in WPF.
I implement a class which inherit from DocumentPaginator class
public class ReportPaginator : DocumentPaginator
{
private double pageUpperLimit;
private double pageDownLimit;
private Model.Report printedReport;
private int pageCount;
public override IDocumentPaginatorSource Source
{
get
{
return null;
}
}
public override bool IsPageCountValid
{
get { return true; }
}
public override int PageCount
{
get { return pageCount; }
}
public override Size PageSize
{
get
{
return new Size(printedReport.PageSize.Width, printedReport.PageSize.Height);
}
set
{
// validate the value.
if (value != null)
{
throw new ArgumentException("page size can not be null");
}
// TODO: here we have to validate if the page is A3, A4, A5. this is to set the SizeName.
// if you did not set the sizeName here we will get an exception.
printedReport.PageSize = new Model.PageSize { Height = value.Height, Width = value.Width };
CalculatesPage();
// if we have to set the PageSize (I do not think so), do not forget to call the PaginateData method.
}
}
public ReportPaginator( Model.Report report)
{
printedReport = report;
CalculatesPage();
}
public override DocumentPage GetPage(int pageNumber)
{
// validate the argument.
if (pageNumber < 0)
{
throw new ArgumentException("pageNumber parameter could not be negative number", "pageNumber");
}
// if the argument is outside of the available pages, return
if (pageNumber > pageCount - 1)
{
return DocumentPage.Missing;
}
// specify the start pixel and end pixel of the page according to the height of the report.
pageUpperLimit = pageNumber * PageSize.Height;
pageDownLimit = (pageNumber + 1) * PageSize.Height;
// create DrawingVisual for this DocumentPage
DrawingVisual visual = new DrawingVisual();
// get the DrawingContext for this DrawingVisual for this page.
using (DrawingContext pageContext = visual.RenderOpen())
{
// drawing operations for elements and sections go here.
// we will use the for loop instead of the foreach loop to enumerate the sections
// because we will need the know in which section we draw.
for (int sectionIndex = 0; sectionIndex < printedReport.Sections.Count; sectionIndex++)
{
PrintSection(pageContext, sectionIndex);
foreach (Model.BaseReportControl control in printedReport.Sections[sectionIndex].Controls)
{
PrintControl(pageContext, sectionIndex, control);
}
}
} // close the DrawingContext.
return new DocumentPage(visual);
}
}
there is more helper methods to do the jobs.
I want to create FixedDocument object to return it from the Source property
using DocumentPage object that returned from GetPage Method.
I need a FixedDocument to be returned from the source Property
Because I want to make a preview to the File before printing
ReportPreviewerWindow window = new ReportPreviewerWindow();
window.previewer.Document = new ReportPaginator(printedSurface.ModelReport).Source;
window.ShowDialog();
the previewer is DocumentViewer Object exists in the ReportPreviewerWindow
<Window x:Class="TanmiaGrp.Report.Designer.ReportPreviewerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Report Previewer" >
<Grid>
<DocumentViewer x:Name="previewer"/>
</Grid>
</Window>
After I asked this question I found something worked very correctly for me.
if you have problem like the described above please refer this link
How to Print Preview when using a DocumentPaginator to print?

System.Reflection.PropertyInfo.SetValue() calling default event handler of button [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 14 years ago.
Improve this question
So i'm not really sure why this is happening but I'm running through some DataRows where I have the control name, property, and value that I want to set. Everything works fine except when I set the TEXT property of a button. For some reason, the click event is called...
Here's some of the code I've got:
string controlName, value, property;
Control currentControl = null;
System.Reflection.PropertyInfo propertyInfo = null;
// run through all rows in the table and set the property
foreach (DataRow r in languageDataset.Tables[_parentForm.Name].Rows)
{
controlName = r["ControlName"].ToString().ToUpper();
value = r["Value"].ToString();
property = r["Property"].ToString();
// check all controls on the form
foreach (Control c in formControls)
{
// only change it if its the right control
if (c.Name.ToUpper() == controlName)
{
propertyInfo = c.GetType().GetProperty(property);
if (propertyInfo != null)
propertyInfo.SetValue(c, value, null); ******Calls Event Handler?!?!******
//
currentControl = c;
break;
}
}
}
So why in the world would it call the event handler when setting the value? Here's what I'm setting it with that's causing this:
<SnappletChangePassword>
<ControlName>buttonAcceptPassword</ControlName>
<Property>Text</Property>
<Value>Accept</Value>
</SnappletChangePassword>
I can't reproduce this with a simple short but complete program:
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
class Test
{
static void Main()
{
Button goButton = new Button {
Text = "Go!",
Location = new Point(5, 5)
};
Button targetButton = new Button {
Text = "Target",
Location = new Point(5, 50)
};
goButton.Click += (sender, args) => SetProperty(targetButton, "Text", "Changed");
targetButton.Click += (sender, args) => MessageBox.Show("Target clicked!");
Form f = new Form { Width = 200, Height = 120,
Controls = { goButton, targetButton }
};
Application.Run(f);
}
private static void SetProperty(object target, string propertyName, object value)
{
PropertyInfo property = target.GetType().GetProperty(propertyName);
property.SetValue(target, value, null);
}
}
Can you come up with a similarly complete program which does demonstrate it?
Sadly, no I couldn't reproduce it either. I'm not sure what was causing it but all I did to fix it was delete the button and put it back on there.
not sure what it was, but thanks for the code.
You didn't write that in .Net2.0 did you?

Resources