Understanding WebView Code - java

What exactly does this block of code (below) do?
WebView browser = (WebView) findViewById(R.id.activity_main_webview)
I have used it in my WebView app I started, and it seems to be important, but I don't understand what it does.

It just references to your webview view on the basis of ID you have given to view.

To say simple and short:
In android you define UI (for example layout of your activities) in some xml file. Each component in layout of activities could have an Id.
Android automatically create some java files to relate defined id to real components (IDs will save in a file/class which android named it R.java)
So when you want to access real component defined in xml file in the java code (for example in activity source code) you could use method findById and send id of requested component to it. This method returns real component (java object) related to given id.

Related

Dynamically change the android id of an element

Is it possible to change the android id of a view or any of their elements, such as an imageView based on some code? That is, verifying a variable such as a bool and having a different id depending on the value such as image_true and image_false.
I am working on an automation project with Appium and I need to be able to differentiate a success pop-up from an error pop-up. They are essentially the same component but the image is different depending on the state of it.
You can use View#setId with some positive integer as ids are basically integers
Your answer is not clear enough but it's possible to change it by #setId method of View. And consider this issue that changing the view id when runtime may cause errors inside the code if it is using that view by hardcoded id so it can't be found by those components anymore.
An alternative is to dynamically change tags using View#setTag which can accept strings. To access the view using tags, you can use findViewWithTag.
Sample code to access view using tag:
LinearLayout layout = findViewById(R.id.layout);
TextView textView = layout.findViewWithTag("someTag");

how to get a blank canvas on which I can write using stylus

I am creating a service application where in the person who uses the service fills his data and signs it
Now I want to create a blank page where I can take the signature of the client on the TAB itself. So please help to do this.How can I implement it.
I have refereed to this http://tavmjong.free.fr/INKSCAPE/MANUAL/html/Paths-Creating.html link but some how I am not able to work with it.
Please help.Thanks
You can do it using GestureOverlayView. Example in the links: http://www.intertech.com/Blog/android-gestureoverlayview-to-capture-a-quick-signature-or-drawing/
Specifically, create a GestureOverlayView in your layout xml file, then in your Activity class capture the gesture and save it as bitmap image.
Go through the developer API if you want to have specific function for your page, especially for events like Gesturing or Gesture Finish : http://developer.android.com/reference/android/gesture/GestureOverlayView.html
Hope that helps

Android Testing: What do to when nothing has an id?

I'm trying to write some automation scripts for an app I have. I've done the tutorial on Robotium's site and have a basic understanding on how I can automation. However from what I can tell regarding the app I'm testing is by using the android hierarchy viewer I see that all of the views have no ids that were explicitly defined.
As you can see from the screen capture there are views upon nested views. The IDs for them read like 0x17e0 or 0x17de. How can I reference these, specifically, in a robotium script? The end result is I'm trying to get it to fire a click even on one of the Text Switcher views. So far I've only been able to make it work if I give it a pixel point to go to, or if I give it the text that appears in the button (but the text is dynamic and would make for a poor test).
Do I have to use the getCurrentViews() to filter down to the text switchers? Or do I have to figure out a way to traverse the entire tree going from FrameLayout>RelativeLayout>FrameLayout>LinearLayout>TextSwitcher ?
If I have to traverse the entire tree how do I get view upon view upon view?
While I couldn't get the ViewGroup() and getChildAt() methods to work for me I ended up doing something different:
// Grabbing all the LinearLayout views found under view with with id of 'content'
ArrayList<LinearLayout> linearLayouts = solo.getCurrentViews(LinearLayout.class, solo.getView(R.id.content));
// The 4th item in the linearLayouts list is the one I need
View pickerList = linearLayouts.get(3);
// Grabbing the buttons in the pickerList
ArrayList<TextSwitcher> buttons = solo.getCurrentViews(TextSwitcher.class,pickerList);
// Now I can click on the buttons
solo.clickOnView(buttons.get(0));
I will say this is slow. It takes about 10 seconds for the first button click to fire. But once it goes it flys.
I would vote to say you really probably want to get some IDs added somehwere in the hierarchy, it is a one line change that will make your life a hell of a lot easier.
But i am not without help if for some reason you cannot get this done, to do this you are going to have to walk the entire to get to the view you want.
Getting the top level view, you will be able to cast it into a ViewGroup. ViewGroups have a method called getChildAt() which you can then use to get a child at a given index, the index is 0 based and will match what you see in the hierarchy viewer so you can chain together theses commands to get to the view you want to interact with.
I have not used Robodtium very much, but i know that AndroidViewClient does exactly what you want. Here is a code snippet that dumps Id of the home view:
ViewClient(*ViewClient.connectToDeviceOrExit()).traverse(transform=ViewClient.TRAVERSE_CIT)
Here is the result dump:
com.android.launcher2.CellLayout id/cell3 None
com.android.launcher2.ShortcutAndWidgetContainer NO_ID None
com.android.launcher2.BubbleTextView NO_ID Email
com.android.launcher2.LauncherAppWidgetHostView NO_ID None
android.widget.AnalogClock id/0x7f0f0014 None
com.android.launcher2.BubbleTextView NO_ID Camera
com.android.launcher2.BubbleTextView NO_ID Settings
com.android.launcher2.BubbleTextView NO_ID Gallery
com.android.launcher2.LauncherAppWidgetHostView NO_ID None
android.widget.LinearLayout id/0x7f080167 None

Multiple Page Development in Java with Eclipse and GWT

I have been writing some basic code for an application I am designing. I have learned the basics and gotten some simple database connection working with RPC calls etc. What I need to do now and am completely lost (as I am traditionally a c# developer with windows forms).
In c# if I wanted a new form I would just create it, and then call the show method.
How does one create multiple pages in GWT, and switch between them?
Thanks in advance,
Chris
The simplest way would be to
Make a new java class (GwtHome.java, GwtHelp.java etc)
Extend these classes by using the Composite class
Make the equivalent of a Master Page and add it to the rootPanel as a class with the appropriate headers, menu, footer and Content Placeholder (Could be any of the AbsolutePanel, VerticalPanel, HorizontalPanel objects provided by the GWT Framework)
By clicking on the menu clear the Placeholder and add the appropriate object of GwtHome, GwtHelp etc.
After getting aquanted with the above procedure, you might want to break up the code in many files using a design pattern as suggested by Andrei.
Simply clear the root panel (RootPanel.get().clear()) and add the widget for your new "page", the same way you added your first one.
If you're using LayoutPanels, do RootLayoutPanel.get().clear() instead.
Look at Activities and Places design pattern: https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces
I highly recommend it for a multipage GWT app. It explains pretty well how you create different "views", that are driven by their "activities", and tied to specific "places" (pages) that users can navigate.
Typically you use a LayoutPanel as your "page" container that occupies the entire available browser window. You split this LayoutPanel into 2-3 layers (zones), like top menu, side menu, main area. Each area contains one widget, usually a ScrollPanel, FlowPanel, or HtmlPanel. Then you use different widgets or HTML inside each of these widgets to display whatever you need. You may also create your own composite widgets that you can reuse in different pages.

accessing the children views of a View in Android

I am quite new to Java, let alone Android. I am stuck with a problem
that I encountered while instrumenting (using the instrumentation
framework of android) the code of a Android project. I have a ListView
and using the getTouchables() API I have store the view in a
ArrayList. When in debug session, I saw that each view has children
(mChildren) when expanded I could see that there is a "ImageView" and
"TextView" present. when the "TextView" is expanded, I could access
the mText variable which contains the text value I am looking for. In
brief, the value I am looking for, when looking at the "variables"
window of the debug perspective of Eclipse, is present at
'myview->mChildren->[1] (TextView)->mText->value'
Here "myview" is the name of the object of View class.
how do I access/ read the content of the "value" variable?
Please let me know if you need any info in this regard?
Thank you
-BA
You could access via the findViewByID method of the mView object;
For example
TextEdit mText = (TextView)myView.findViewById(R.id.mText);
mText.setText("Hello!");
Hope that's what you're after or helps.
Damon

Categories

Resources