Android Map Shows Direction Images in ListView - android

My android application uses android mapView.It shows location map and driving direction in an listview like google map.Now i want to show images corresponding to directions in lisview. ie, if the direction is to left,then i want to s*how an image which indicate to turn left in the listview*.
How can i solve this?
Thanks in Advance

I did this using String operations, but it is not stable, give 90% accuracy. See the code below:
Drawable draw;
if(direction.contains("Slight right"))
{
draw=getResources().getDrawable(R.drawable.slightright);
}
else if(direction.contains("Slight left"))
{
draw=getResources().getDrawable(R.drawable.slightleft);
}
else if(direction.contains("right"))
{
if(direction.contains("left"))
{
int index = direction.indexOf("right");
int index2 = direction.indexOf("left");
if(index<index2)
{
draw=getResources().getDrawable(R.drawable.turnright);
}
else
{
draw=getResources().getDrawable(R.drawable.turnleft);
}
}
else
{
draw=getResources().getDrawable(R.drawable.turnright);
}
}
else if(direction.contains("left"))
{
draw=getResources().getDrawable(R.drawable.turnleft);
}
else if(direction.contains("roundabout") && direction.contains("exit"))
{
draw=getResources().getDrawable(R.drawable.roundabout);
}
else if(direction.contains("Continue"))
{
draw=getResources().getDrawable(R.drawable.straight);
}
else if(direction.contains("U-turn"))
{
draw=getResources().getDrawable(R.drawable.uturn);
}
else
{
draw=null;
}
//then set the drawable to your ImageView
You can play around with the code if you see something missing or you have more images.
These are the images I used:

Related

Android: How I can take Bracketing photos using SonyCamera remote API

This issue is troubling me until 1 week. I want to take picture like bracketing but in Sony Camera API its not support. so I coded it like continuously take 5 pictures with different value (0,+2,-2,-4,+4) using loop. (using button for it, and when press the button it should take picture 5 times) U can see the code in below:
This code for set Shutter Speed on camera
This code for taking picture:
private void takePicture() {
if (mLiveviewSurface == null || !mLiveviewSurface.isStarted()) {
DisplayHelper.toast(getApplicationContext(), R.string.msg_error_take_picture);
return;
}
new Thread() {
#Override
public void run() {
try {
JSONObject replyJson = mRemoteApi.actTakePicture();
JSONArray resultsObj = replyJson.getJSONArray("result");
JSONArray imageUrlsObj = resultsObj.getJSONArray(0);
String postImageUrl = null;
if (1 <= imageUrlsObj.length()) {
postImageUrl = imageUrlsObj.getString(0); continousShottingWithDifferentShutterValue();
}
if (postImageUrl == null) {
Log.w(TAG, "takePicture: post image URL is null.");
DisplayHelper.toast(getApplicationContext(), //
R.string.msg_error_take_picture);
return;
}
// Show progress indicator
DisplayHelper.setProgressIndicator(SonyCameraActivity.this, false);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
and this is for loop:
int val, posVal = 0;
int currentShutterSpeed = 0;
private void continousShottingWithDifferentShutterValue() {
if (val == 0) {
currentShutterSpeed = -5;
setShutterSpeed(currentShutterSpeed);
val++;
} else if (val == 1) {
currentShutterSpeed = 5;
setShutterSpeed(currentShutterSpeed);
val++;
} else if (val == 2) {
currentShutterSpeed = -10;
setShutterSpeed(currentShutterSpeed);
val++;
} else if (val == 3) {
currentShutterSpeed = 10;
setShutterSpeed(currentShutterSpeed);
val++;
} else if (val == 4) {
setShutterSpeedVal0(0);
posVal++;
}
if (posVal == 3) {
posVal = 0;
val = 0;
}
}
But when I take picture sometimes shutterSpeed or takePicture is getting error and loop is stop.
Error types are: setShutterSpeed IOExeption error: 500; or setShutterSpeed is not set. Someone works with Sonycamera remote API and has any idea how to fix it or take picture 5 times with different value. will thankful for any idea. Thanks
I solved the problem. it was a shutter speed value error. As u know in Sony Camera Api there is not have the value of shutter speed and I wrote it as in camera settings. and JSON request and response is not match so its shows error 500. If someone wants to use shutter speed value: here it is:
String shutterValue[] = {"30\"", "25\"", "20\"", "15\"", "13\"", "10\"", "8\"", "6\"",
"5\"", "4\"", "3.2\"", "2.5\"", "2\"", "1.6\"", "1.3\"", "1\"", "0.8\"", "0.6\"", "0.5\"",
"0.4\"", "1/3", "1/4", "1/5", "1/6", "1/8", "1/10", "1/13", "1/15", "1/20", "1/25", "1/30",
"1/40", "1/50", "1/60", "1/80", "1/100", "1/125", "1/160", "1/200", "1/250", "1/320", "1/400",
"1/500", "1/640", "1/800", "1/1000", "1/1250", "1/1600", "1/2000", "1/2500", "1/3200", "1/4000"};

Setting Map Type in Android, constant problems

I am playing around with com.example.mapdemo, all java files compile except the LayersDemoActivity.java which contains
private void setLayer(String layerName) {
if (!checkReady()) {
return;
}
if (layerName.equals(getString(R.string.normal))) {
mMap.setMapType(MAP_TYPE_NORMAL);
} else if (layerName.equals(getString(R.string.hybrid))) {
mMap.setMapType(MAP_TYPE_HYBRID);
} else if (layerName.equals(getString(R.string.satellite))) {
mMap.setMapType(MAP_TYPE_SATELLITE);
} else if (layerName.equals(getString(R.string.terrain))) {
mMap.setMapType(MAP_TYPE_TERRAIN);
} else {
Log.i("LDA", "Error setting layer with name " + layerName);
}
}
the compiler doesn't recognizes MAP_TYPE_NORMAL, MAP_TYPE_HYBRID etc. constants. What is it wrong?
This
mMap.setMapType(MAP_TYPE_NORMAL);
should be
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
Same for other map types also
Check the doc under change the Map Type
https://developers.google.com/maps/documentation/android/map

How to get XML content with matching tags in Pull Parser for Android?

I am trying to use the Pull Parser in Android to get values of image2 and image3.
<item>
<title>Title Goes Here!</title>
<picture><![CDATA[http://blahblah.image.jpg]]></picture>
<picture><![CDATA[http://blahblah.image2.jpg]]></picture>
<picture><![CDATA[http://blahblah.image3.jpg]]></picture>
</item>
...
case XmlPullParser.END_TAG
if (tagname.equalsIgnoreCase("item")
_feed.addItem(_item);
} else if (tagname.equalsIgnoreCase("title")) {
_item.setTitle(theString)
} else if (tagname.equalsIgnoreCase("picture")) {
_item.setLargeImage(theString)
} else if (tagname.equalsIgnoreCase("picture")) {
_item.setLargeImage2(theString)
} else if (tagname.equalsIgnoreCase("picture")) {
_item.setLargeImage3(theString)
}
break;
...
I can parse and load the first image but, I don't know what the next step is to get the other images? Thanks for the help.
There's a logic error in your code:
} else if (tagname.equalsIgnoreCase("picture")) {
_item.setLargeImage(theString)
} else if (tagname.equalsIgnoreCase("picture")) {
_item.setLargeImage2(theString)
} else if (tagname.equalsIgnoreCase("picture")) {
_item.setLargeImage3(theString)
}
The code that follows the second and third else if condition test will never be executed, if the encountered tag is picture, the control flow will end at the first if (tagname.equalsIgnoreCase("picture")).
You may do the following to achieve what you want:
List<String> imageList = new ArrayList<String>();
} else if (tagname.equalsIgnoreCase("picture")) {
imageList.add(theString);
}
// after you finish parsing the xml file, set the image URLs on your item.
_item.setLargeImage(imageList.get(0));
_item.setLargeImage2(imageList.get(1));
_item.setLargeImage3(imageList.get(2));

android emulator hangs while running selenium script

I am using selenium to test an android web app. My test is running fine initially but hangs at particular point. It selects the first text field on the web page and writes the values while in zoom-in mode but it hangs at this point and does not select the second text field. Where am I going wrong?
My code is as follows:
public void testRegister() throws Exception
{
driver.get("file:///android_asset/www/aboutus.html");
driver.findElement(By.xpath("html/body/div/div/ul/li[2]")).click();
List<WebElement> w1=driver.findElements(By.tagName("input"));
System.out.println(w1.size());
for(int i=0;i<w1.size();i++)
{
System.out.println("************");
System.out.println(i + w1.get(i).getAttribute("id") +"*****" + w1.get(i).getAttribute("name"));
}
for(WebElement option:w1)
{
String str=option.getAttribute("id");
if(str.equals("name"))
{
option.click();
option.sendKeys("Vaishali");
}
else if(str.equals("dateofbirth"))
{
option.click();
option.sendKeys("28-09-1991");
}
else if(str.equals("club"))
{
option.click();
option.sendKeys("Manchester United");
}
else if(str.equals("username"))
{
option.click();
option.sendKeys("vishchan");
}
else if(str.equals("password"))
{
option.click();
option.sendKeys("vishchan");
}
else if(str.equals("sendbutton"))
{
option.click();
}
}
the id can be '' and it'l return null value
in the list of elements can be hidden element with the same id
for more reasons please post stack trace.
Best Regards Taras

If statement within If statement's else

Still new to Java/android so trying to figure out the best way to code a multilevel if statement. What I'm trying to do is for a combat system that needs to check if player/npc is alive. If they are alive it then will check to see if they scored a critical hit. If they didn't critical hit then will see if they hit or missed.
combat = mydbhelper.getCombat();
startManagingCursor(combat);
if (playerCurHp == 0) {
combat.moveToPosition(11);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
if (playerCritFlag.equals("Critical")) {
combat.moveToPosition(2);
playerCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
if (playerHitFlag.equals("Hit")) {
combat.moveToPosition(1);
playerCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
}
if (playerHitFlag.equals("Miss")) {
combat.moveToPosition(3);
playerCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
}
}
}
if (npcCurHp == 0) {
combat.moveToPosition(10);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
if (npcCritFlag.equals("Critical")) {
combat.moveToPosition(5);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
} else {
if (npcHitFlag.equals("Hit")) {
combat.moveToPosition(4);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
}
if(npcHitFlag.equals("Miss")) {
combat.moveToPosition(6);
npcCombatStory = combat.getString(combat.getColumnIndex(dbhelper.KEY_COMBATDESC));
}
}
}
Is what I'm using. Was working when I had the if statements all separate. But it would check each one and do actions I don't need (If they hit, pull String, if crit pull another, then if dead pull again). Trying to make it stop when it finds the "Flag" that matches. When doing my rolls if the player hits it sets the flag to "Hit" like below code.
Random attackRandom = new Random();
int attackRoll = attackRandom.nextInt(100);
totalAtt = attackRoll + bonusAttack + weaponAtt + stanceAtt;
Random defensiveRandom = new Random();
int defenseRoll = defensiveRandom.nextInt(100);
npcDef = defenseRoll + npcDodge + npcBonusDodge;
if (totalAtt > npcDef) {
playerHitFlag = "Hit";
playerDamage();
} else {
playerHitFlag = "Miss";
npcAttack();
}
At the end it takes these playerCombatStory and npcCombatStory strings and uses them to setText to show the player what happened on that turn of combat.
I think you are looking for the else if statement:
if (condition) {
}
else if (other_condition) {
}
else if (another_condition) {
}
else {
// There can only be one else statement in a given if-else block
}
Your question isn't clear. But meaningful advice can still be offered.
Personally, I find this code hard to read. I think it'll be hard to maintain in the future as your logic becomes more complex.
I think you need to decouple the logic of what's done from how you decide. Encapsulate what's done in a Command object and use a map or state machine to look up what to do.
I would change the type of npcCritFlag to int or enum. Then use switch statement with case
This should look much better and easier to understand

Categories

Resources