How to scale target webpage linked with parse - webview

I have a program with a button to login via GET method, it works perfectly, but when I log in, the form appears zoomed out far and little. I wanted to know if there is any option with WebSettings.ZoomDensity, or WebView class, to scale the form size to the screen of the device.
The button code is this:
public void IniciSessio_BTN_Click(View Target) {
if (U.getText().length() <= 0)
Toast.makeText(getApplicationContext(), "Username", Toast.LENGTH_SHORT).show();
else if (K.getText().length() <= 0)
Toast.makeText(getApplicationContext(), "Password", Toast.LENGTH_SHORT).show();
else
{
DadesUsuari = U.getText().toString();
DadesClau = K.getText().toString();
DadesDesar = Desar_CB.isChecked();
Uri uri = Uri.parse( "http://www.mypage.com/?U="+U.getText().toString()+"&K="+K.getText().toString() );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
}
}
I tryed to do this:
webview.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
But it doesn't works. It make me to create the WebView class and it crashes the app.
Also tryed this:
private WebView Navegador = null;
Navegador = new WebView(this);
Navegador.setVisibility(View.GONE);
Navegador.setPadding(0, 0, 0, 0);
Navegador.setInitialScale(73);
Uri uri = Uri.parse( "http://stats.serhstourism.com/?U="+U.getText().toString()+"&K="+K.getText().toString() );
startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
WebSettings webSettings = Navegador.getSettings();
webSettings.setJavaScriptEnabled(true);

You should take a look at this article.
I think you have to set the viewport size in your html. Something like this ...
<meta name="viewport" content="width=100px, height:100px" />
Obviously you're going to have to change the pixel values. For more information how this works look at the article mentioned above.

Related

SWT: Integrate clickable link into StyledText

With the help of this question I was able to figure out how I can display a link inside a StyledText widget in SwT. The color is correct and even the cursor changes shape when hovering over the link.
So far so good, but the link is not actually clickable. Although the cursor changes its shape, nothing happens if clicking on the link. Therefore I am asking how I can make clicking the link to actually open it in the browser.
I thought of using a MouseListener, tracking the click-location back to the respective text the click has been performed on and then deciding whether to open the link or not. However that seems way too complicated given that there already is some routine going on for changing the cursor accordingly. I believe that there is some easy way to do this (and assuring that the clicking-behavior is actually consistent to when the cursor changes its shape).
Does anyone have any suggestions?
Here's an MWE demonstrating what I have done so far:
public static void main(String[] args) throws MalformedURLException {
final URL testURL = new URL("https://stackoverflow.com/questions/1494337/can-html-style-links-be-added-to-swt-styledtext");
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, true));
StyledText sTextWidget = new StyledText(shell, SWT.READ_ONLY);
final String firstPart = "Some text before ";
String msg = firstPart + testURL.toString() + " some text after";
sTextWidget.setText(msg);
sTextWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
StyleRange linkStyleRange = new StyleRange(firstPart.length(), testURL.toString().length(), null, null);
linkStyleRange.underline = true;
linkStyleRange.underlineStyle = SWT.UNDERLINE_LINK;
linkStyleRange.data = testURL.toString();
sTextWidget.setStyleRange(linkStyleRange);
shell.open();
while(!shell.isDisposed()) {
display.readAndDispatch();
}
}
Okay I was being a little too fast on posting this question... There's a snippet that deals with exactly this problem and it shows, that one indeed has to use an extra MouseListener in order to get things working.
The snippet can be found here and this is the relevant part setting up the listener:
styledText.addListener(SWT.MouseDown, event -> {
// It is up to the application to determine when and how a link should be activated.
// In this snippet links are activated on mouse down when the control key is held down
if ((event.stateMask & SWT.MOD1) != 0) {
int offset = styledText.getOffsetAtLocation(new Point (event.x, event.y));
if (offset != -1) {
StyleRange style1 = null;
try {
style1 = styledText.getStyleRangeAtOffset(offset);
} catch (IllegalArgumentException e) {
// no character under event.x, event.y
}
if (style1 != null && style1.underline && style1.underlineStyle == SWT.UNDERLINE_LINK) {
System.out.println("Click on a Link");
}
}
}
});

Router Match not returning matchedRouteName

I have been slowly working my way through a few issues with the help of this website. I think I am onto my last problem now. In my boostrap I have the following code:
$eventManager = $event->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$serviceManager = $event->getApplication()->getServiceManager();
$eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function($event) use ($serviceManager ){
$exception = $event->getParam('exception');
if ($exception) {
do {
$serviceManager->get('Logger')->crit(
sprintf(
"%s:%d %s (%d) [%s]\n",
$exception->getFile(),
$exception->getLine(),
$exception->getMessage(),
$exception->getCode(),
get_class($exception)
)
);
} while ($ex = $exception->getPrevious());
$response = $event->getResponse();
$response->setHeaders(
$response->getHeaders()->addHeaderLine('Location', "/")
);
$response->setStatusCode(302);
$response->sendHeaders();
return $response;
} else {
//no route - redirect to cms handler
$newEvent = clone $event;
$eventManager = $newEvent->getApplication()->getEventManager();
$routeMatch = new Router\RouteMatch(array('controller'=>'Website\Controller\Index','action'=>'index'));
$event->stopPropagation(TRUE);
$newEvent->setRouteMatch($routeMatch);
$newEvent->getResponse()->setStatusCode(200);
$eventManager->trigger('dispatch', $newEvent);
}
});
This all works fine except that $routeMatch is not returning matchedRouteName - and so I get a 404. I know that the contoller and action names are correct as for now I am just redirecting to homepage and by echoing out $routeMatch on "Displatch" the same info is coming back.
So, it seems simply using the trigger "dispatch" is not enough.
Any help appreciated.
Thanks
Adam
Further Info: I have confirmed that the dispatch is actually working - however, the triggered 404 is still being acted upon. That is a 404 header status is being set and the default 404 handler (view etc) is being displayed.
Solved by adding: $newEvent->getResponse()->setStatusCode(200);

Android Attach Image between text with SpannableStringBuilder

Sory for my english. I want attach image from gallery and show in edit text with SpannableStringBuilder. I have success for get Image Path from Gallery. After picture selected, Picture Show. But, for the second attach image picture not show and first image attach became a text. any one give me solution ? big thanks.
this is my code:
private void IntentPict() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select File"),MY_INTENT_CLICK);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
if (requestCode == MY_INTENT_CLICK){
if (null == data) return;
String selectedImagePath;
Uri selectedImageUri = data.getData();
//there is no problem with get path
selectedImagePath = ImageFilePath.getPath(getApplicationContext(), selectedImageUri);
//pathImag is ListArray<String>
pathImg.add(selectedImagePath);
addImageBetweentext(pathImg);
}
}
}
private void addImageBetweentext(ArrayList<String> listPath) {
SpannableStringBuilder ssb = new SpannableStringBuilder();
for(int i=0;i<listPath.size();i++){
String path = listPath.get(i);
Drawable drawable = Drawable.createFromPath(path);
drawable.setBounds(0, 0, 400, 400);
ssb.append(mBodyText+"\n");
ssb.setSpan(new ImageSpan(drawable), ssb.length()-(path.length()+1),
ssb.length()-1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
mBodyText.setText(ssb);
}
Here's something that should work. I am loading resource drawables instead, just because it was quicker for me to validate, but I tried to keep as mich as possible for your original flow and variable names:
Drawable[] drawables = new Drawable[2];
drawables[0] = getResources().getDrawable(R.drawable.img1);
drawables[1] = getResources().getDrawable(R.drawable.img2);
SpannableStringBuilder ssb = new SpannableStringBuilder();
for (int i = 0; i < drawables.length; i++) {
Drawable drawable = drawables[i];
drawable.setBounds(0, 0, 400, 400);
String newStr = drawable.toString() + "\n";
ssb.append(newStr);
ssb.setSpan(
new ImageSpan(drawable),
ssb.length() - newStr.length(),
ssb.length() - "\n".length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
mBodyText.setText(ssb);
Long story short: the start position for the incremental builder needs to be set to the current length of it, minus what you just added.

C# VS WP8 Linking a created tile to a Uri Scheme

First i create a tile with this code:
private void btnIconicTile_Click(object sender, RoutedEventArgs e)
{
IconicTileData oIcontile = new IconicTileData();
oIcontile.Title = "Hello Iconic Tile!!";
oIcontile.Count = 7;
oIcontile.IconImage = new Uri("Assets/Tiles/Iconic/202x202.png", UriKind.Relative);
oIcontile.SmallIconImage = new Uri("Assets/Tiles/Iconic/110x110.png", UriKind.Relative);
oIcontile.WideContent1 = "windows phone 8 Live tile";
oIcontile.WideContent2 = "Icon tile";
oIcontile.WideContent3 = "All about Live tiles By WmDev";
oIcontile.BackgroundColor = System.Windows.Media.Colors.Black;
// find the tile object for the application tile that using "Iconic" contains string in it.
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Iconic".ToString()));
if (TileToFind != null && TileToFind.NavigationUri.ToString().Contains("Iconic"))
{
TileToFind.Delete();
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);
}
else
{
ShellTile.Create(new Uri("/MainPage.xaml?id=Iconic", UriKind.Relative), oIcontile, true);//
}
}
Now i want that the created tile in the homescreen links to an app (Uri Scheme?) like this on for ex:
await Windows.System.Launcher.LaunchUriAsync(new System.Uri("whatsapp:"));
How i can modify the "link" of that recently created tile?
Yes i need too.
Windows.System.Launcher.LaunchUriAsync(new System.Uri("whatsapp:"))
homescreen

How can I load HTML page in BrowserField?

I have one HTML page shows map which i want to display in BrowserField.
Here is my code.
BrowserFieldConfig _bfConfig = new BrowserFieldConfig();
_bfConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
_bfConfig.setProperty( BrowserFieldConfig.JAVASCRIPT_ENABLED, Boolean.TRUE );
_bfConfig.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");
BrowserFieldRequest request = new BrowserFieldRequest("page.html");
BrowserField myBrowserField = new BrowserField(_bfConfig);
add(myBrowserField);
myBrowserField.requestContent(request);
If the "page.html" is local file then,
Everything is OK, except here:
BrowserFieldRequest request = new BrowserFieldRequest("page.html");
Change here like:
BrowserFieldRequest request = new BrowserFieldRequest("local:///page.html");
you are calling the local file, that why we are giving like this.

Resources