Monday, 21 May 2012
Imagetarget
/*==============================================================================
Copyright (c) 2012 QUALCOMM Austria Research Center GmbH.
All Rights Reserved.
Qualcomm Confidential and Proprietary
@file
ImageTargets.java
@brief
Sample for ImageTargets
==============================================================================*/
package com.qualcomm.QCARSamples.ImageTargets;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;
import com.qualcomm.QCAR.QCAR;
/** The main activity for the ImageTargets sample. */
public class ImageTargets extends Activity implements LocationListener,
SensorListener {
// Application status constants:
private static final int APPSTATUS_UNINITED = -1;
private static final int APPSTATUS_INIT_APP = 0;
private static final int APPSTATUS_INIT_QCAR = 1;
private static final int APPSTATUS_INIT_TRACKER = 2;
private static final int APPSTATUS_INIT_APP_AR = 3;
private static final int APPSTATUS_LOAD_TRACKER = 4;
private static final int APPSTATUS_INITED = 5;
private static final int APPSTATUS_CAMERA_STOPPED = 6;
private static final int APPSTATUS_CAMERA_RUNNING = 7;
TextView tv, left1, left2, right1, right2;
ImageView center, first, fourth, second, fifth;
// Name of the native dynamic libraries to load:
private static final String NATIVE_LIB_SAMPLE = "ImageTargets";
private static final String NATIVE_LIB_QCAR = "QCAR";
// Our OpenGL view:
private QCARSampleGLView mGlView;
FrameLayout frame;
// The view to display the sample splash screen:
private ImageView mSplashScreenView;
// The handler and runnable for the splash screen time out task.
private Handler mSplashScreenHandler;
private Runnable mSplashScreenRunnable;
// The minimum time the splash screen should be visible:
private static final long MIN_SPLASH_SCREEN_TIME = 2000;
// The time when the splash screen has become visible:
long mSplashScreenStartTime = 0;
private LocationManager locationManager;
private String provider;
// Our renderer:
private ImageTargetsRenderer mRenderer;
// Display size of the device
private int mScreenWidth = 0;
private int mScreenHeight = 0;
// The current application status
private int mAppStatus = APPSTATUS_UNINITED;
// The async tasks to initialize the QCAR SDK
private InitQCARTask mInitQCARTask;
private LoadTrackerTask mLoadTrackerTask;
// An object used for synchronizing QCAR initialization, dataset loading and
// the Android onDestroy() life cycle event. If the application is destroyed
// while a data set is still being loaded, then we wait for the loading
// operation to finish before shutting down QCAR.
private Object mShutdownLock = new Object();
// QCAR initialization flags
private int mQCARFlags = 0;
LinearLayout nearby;
// The textures we will use for rendering:
private Vector mTextures;
private int mSplashScreenImageResource = 0;
// The menu item for swapping data sets:
MenuItem mDataSetMenuItem = null;
boolean mIsStonesAndChipsDataSetActive = false;
/** Static initializer block to load native libraries on start-up. */
static {
loadLibrary(NATIVE_LIB_QCAR);
loadLibrary(NATIVE_LIB_SAMPLE);
}
StringBuilder result;
double lat, lng;
SensorManager sensorManager;
static final int sensor = SensorManager.SENSOR_ORIENTATION;
Rose rose;
String URL = MainURL.URL + "getlocation";
String URL_lng = MainURL.URL + "getlocation1";
int total = 10, total_lng = 10, k1, k2, k3, k4;
ProgressDialog dialog;
String responseBody;
JSONArray jArray, jSubArray;
String[] items;
String[] loc_id, longitude, latitude, thumb, type, type_id, name, cat_id,
cat_name, one_liner, name_temp_lat_left, thumb_temp_lat_left,
name_temp_lat_right, thumb_temp_lat_right, name_temp_lng_left,
thumb_temp_lng_left, name_temp_lng_right, thumb_temp_lng_right;
String Location;
String responseBody_lng;
JSONArray jArray_lng, jSubArray_lng;
String[] items_lng;
String[] loc_id_lng, longitude_lng, latitude_lng, thumb_lng, type_lng,
type_id_lng, name_lng, cat_id_lng, cat_name_lng, one_liner_lng;
String Location_lng;
Boolean flag0 = false, flag90 = false, flag270 = false, flag180 = false,
flag1q = false, flag2q = false, flag3q = false, flag4q = false;
LayoutInflater inflater;
ImageLoader1 imageLoader;
/** An async task to initialize QCAR asynchronously. */
private class InitQCARTask extends AsyncTask {
// Initialize with invalid value
private int mProgressValue = -1;
protected Boolean doInBackground(Void... params) {
// Prevent the onDestroy() method to overlap with initialization:
synchronized (mShutdownLock) {
QCAR.setInitParameters(ImageTargets.this, mQCARFlags);
do {
// QCAR.init() blocks until an initialization step is
// complete,
// then it proceeds to the next step and reports progress in
// percents (0 ... 100%)
// If QCAR.init() returns -1, it indicates an error.
// Initialization is done when progress has reached 100%.
mProgressValue = QCAR.init();
// Publish the progress value:
publishProgress(mProgressValue);
// We check whether the task has been canceled in the
// meantime
// (by calling AsyncTask.cancel(true))
// and bail out if it has, thus stopping this thread.
// This is necessary as the AsyncTask will run to completion
// regardless of the status of the component that started
// is.
} while (!isCancelled() && mProgressValue >= 0
&& mProgressValue < 100);
return (mProgressValue > 0);
}
}
protected void onProgressUpdate(Integer... values) {
// Do something with the progress value "values[0]", e.g. update
// splash screen, progress bar, etc.
}
protected void onPostExecute(Boolean result) {
// Done initializing QCAR, proceed to next application
// initialization status:
if (result) {
DebugLog.LOGD("InitQCARTask::onPostExecute: QCAR initialization"
+ " successful");
updateApplicationStatus(APPSTATUS_INIT_TRACKER);
} else {
// Create dialog box for display error:
AlertDialog dialogError = new AlertDialog.Builder(
ImageTargets.this).create();
dialogError.setButton("Close",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// Exiting application
System.exit(1);
}
});
String logMessage;
// NOTE: Check if initialization failed because the device is
// not supported. At this point the user should be informed
// with a message.
if (mProgressValue == QCAR.INIT_DEVICE_NOT_SUPPORTED) {
logMessage = "Failed to initialize QCAR because this "
+ "device is not supported.";
} else {
logMessage = "Failed to initialize QCAR.";
}
// Log error:
DebugLog.LOGE("InitQCARTask::onPostExecute: " + logMessage
+ " Exiting.");
// Show dialog box with error message:
dialogError.setMessage(logMessage);
dialogError.show();
}
}
}
/** An async task to load the tracker data asynchronously. */
private class LoadTrackerTask extends AsyncTask {
protected Boolean doInBackground(Void... params) {
// Prevent the onDestroy() method to overlap:
synchronized (mShutdownLock) {
// Load the tracker data set:
return (loadTrackerData() > 0);
}
}
protected void onPostExecute(Boolean result) {
DebugLog.LOGD("LoadTrackerTask::onPostExecute: execution "
+ (result ? "successful" : "failed"));
if (result) {
// The stones and chips data set is now active:
mIsStonesAndChipsDataSetActive = true;
// Done loading the tracker, update application status:
updateApplicationStatus(APPSTATUS_INITED);
} else {
// Create dialog box for display error:
AlertDialog dialogError = new AlertDialog.Builder(
ImageTargets.this).create();
dialogError.setButton("Close",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
// Exiting application
System.exit(1);
}
});
// Show dialog box with error message:
dialogError.setMessage("Failed to load tracker data.");
dialogError.show();
}
}
}
private void storeScreenDimensions() {
// Query display dimensions
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mScreenWidth = metrics.widthPixels;
mScreenHeight = metrics.heightPixels;
}
/**
* Called when the activity first starts or the user navigates back to an
* activity.
*/
protected void onCreate(Bundle savedInstanceState) {
DebugLog.LOGD("ImageTargets::onCreate");
super.onCreate(savedInstanceState);
// Set the splash screen image to display during initialization:
mSplashScreenImageResource = R.drawable.splash_screen_image_targets;
// Load any sample specific textures:
mTextures = new Vector();
loadTextures();
// Query the QCAR initialization flags:
mQCARFlags = getInitializationFlags();
// mSplashScreenView.setVisibility(View.INVISIBLE);
// mRenderer.mIsActive = true;
// tv = new TextView(ImageTargets.this);
// addContentView(mGlView, new LayoutParams(
// LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// addContentView(tv, new LayoutParams(
// LayoutParams.WRAP_CONTENT,
// LayoutParams.WRAP_CONTENT));
//
// Update the application status to start initializing application
updateApplicationStatus(APPSTATUS_INIT_APP);
}
/* Request updates at startup */
void getAddress() {
try {
Geocoder gcd = new Geocoder(this, Locale.getDefault());
List addresses = gcd.getFromLocation(lat, lng, 5);
if (addresses.size() > 0) {
result = new StringBuilder();
/*
* for (int i = 0; i < addresses.size(); i++) { Address address
* = addresses.get(i);
*
* int maxIndex = address.getMaxAddressLineIndex(); for (int x =
* 0; x <= maxIndex; x++) {
* result.append(address.getAddressLine(x)); result.append(",");
* } result.append(address.getLocality()); result.append(",");
* result.append(address.getPostalCode());
* result.append("\n\n"); }
*/
Address address = addresses.get(0);
result.append(address.getAddressLine(0));
// result.append("" + lat + lng);
tv.setText(result);
}
} catch (IOException ex) {
// editTextShowLocation.append(ex.getMessage().toString());
} catch (NullPointerException f) {
}
}
@Override
public void onLocationChanged(Location location) {
lat = (double) (location.getLatitude());
lng = (double) (location.getLongitude());
getAddress();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Enabled new provider " + provider,
Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(this, "Disabled provider " + provider,
Toast.LENGTH_SHORT).show();
}
/**
* We want to load specific textures from the APK, which we will later use
* for rendering.
*/
private void loadTextures() {
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
getAssets()));
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",
getAssets()));
mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png",
getAssets()));
}
/** Configure QCAR with the desired version of OpenGL ES. */
private int getInitializationFlags() {
int flags = 0;
// Query the native code:
if (getOpenGlEsVersionNative() == 1) {
flags = QCAR.GL_11;
} else {
flags = QCAR.GL_20;
}
return flags;
}
/**
* native method for querying the OpenGL ES version. Returns 1 for OpenGl ES
* 1.1, returns 2 for OpenGl ES 2.0.
*/
public native int getOpenGlEsVersionNative();
/** Native tracker initialization and deinitialization. */
public native int initTracker();
public native void deinitTracker();
/** Native functions to load and destroy tracking data. */
public native int loadTrackerData();
public native void destroyTrackerData();
/** Native sample initialization. */
public native void onQCARInitializedNative();
/** Native methods for starting and stoping the camera. */
private native void startCamera();
private native void stopCamera();
/**
* Native method for setting / updating the projection matrix for AR content
* rendering
*/
private native void setProjectionMatrix();
/** Called when the activity will start interacting with the user. */
protected void onResume() {
DebugLog.LOGD("ImageTargets::onResume");
super.onResume();
// super.onResume();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
locationManager.requestLocationUpdates(provider, 400, 1, this);
// QCAR-specific resume operation
QCAR.onResume();
locationManager.requestLocationUpdates(provider, 400, 1, this);
// We may start the camera only if the QCAR SDK has already been
// initialized
if (mAppStatus == APPSTATUS_CAMERA_STOPPED) {
updateApplicationStatus(APPSTATUS_CAMERA_RUNNING);
// Reactivate flash if it was active before pausing the app
if (mFlash) {
boolean result = activateFlash(mFlash);
DebugLog.LOGI("Turning flash " + (mFlash ? "ON" : "OFF") + " "
+ (result ? "WORKED" : "FAILED") + "!!");
}
}
// Resume the GL view:
if (mGlView != null) {
mGlView.setVisibility(View.VISIBLE);
mGlView.onResume();
}
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this, sensor);
}
public void onConfigurationChanged(Configuration config) {
DebugLog.LOGD("ImageTargets::onConfigurationChanged");
super.onConfigurationChanged(config);
storeScreenDimensions();
// Set projection matrix:
if (QCAR.isInitialized())
setProjectionMatrix();
}
/** Called when the system is about to start resuming a previous activity. */
protected void onPause() {
DebugLog.LOGD("ImageTargets::onPause");
super.onPause();
locationManager.removeUpdates(this);
sensorManager.unregisterListener(this);
if (mGlView != null) {
mGlView.setVisibility(View.INVISIBLE);
mGlView.onPause();
}
locationManager.removeUpdates(this);
if (mAppStatus == APPSTATUS_CAMERA_RUNNING) {
updateApplicationStatus(APPSTATUS_CAMERA_STOPPED);
}
// QCAR-specific pause operation
QCAR.onPause();
}
/** Native function to deinitialize the application. */
private native void deinitApplicationNative();
/** The final call you receive before your activity is destroyed. */
protected void onDestroy() {
DebugLog.LOGD("ImageTargets::onDestroy");
super.onDestroy();
// Dismiss the splash screen time out handler:
if (mSplashScreenHandler != null) {
mSplashScreenHandler.removeCallbacks(mSplashScreenRunnable);
mSplashScreenRunnable = null;
mSplashScreenHandler = null;
}
// Cancel potentially running tasks
if (mInitQCARTask != null
&& mInitQCARTask.getStatus() != InitQCARTask.Status.FINISHED) {
mInitQCARTask.cancel(true);
mInitQCARTask = null;
}
if (mLoadTrackerTask != null
&& mLoadTrackerTask.getStatus() != LoadTrackerTask.Status.FINISHED) {
mLoadTrackerTask.cancel(true);
mLoadTrackerTask = null;
}
// Ensure that all asynchronous operations to initialize QCAR and
// loading
// the tracker datasets do not overlap:
synchronized (mShutdownLock) {
// Do application deinitialization in native code
deinitApplicationNative();
// Unload texture
mTextures.clear();
mTextures = null;
// Destroy the tracking data set:
destroyTrackerData();
// Deinit the tracker:
deinitTracker();
// Deinitialize QCAR SDK
QCAR.deinit();
}
System.gc();
}
/**
* NOTE: this method is synchronized because of a potential concurrent
* access by ImageTargets::onResume() and InitQCARTask::onPostExecute().
*/
private synchronized void updateApplicationStatus(int appStatus) {
// Exit if there is no change in status
if (mAppStatus == appStatus)
return;
// Store new status value
mAppStatus = appStatus;
// Execute application state-specific actions
switch (mAppStatus) {
case APPSTATUS_INIT_APP:
// Initialize application elements that do not rely on QCAR
// initialization
initApplication();
// Proceed to next application initialization status
updateApplicationStatus(APPSTATUS_INIT_QCAR);
break;
case APPSTATUS_INIT_QCAR:
// Initialize QCAR SDK asynchronously to avoid blocking the
// main (UI) thread.
// This task instance must be created and invoked on the UI
// thread and it can be executed only once!
try {
mInitQCARTask = new InitQCARTask();
mInitQCARTask.execute();
} catch (Exception e) {
DebugLog.LOGE("Initializing QCAR SDK failed");
}
break;
case APPSTATUS_INIT_TRACKER:
// Initialize the ImageTracker
if (initTracker() > 0) {
// Proceed to next application initialization status
updateApplicationStatus(APPSTATUS_INIT_APP_AR);
}
break;
case APPSTATUS_INIT_APP_AR:
// Initialize Augmented Reality-specific application elements
// that may rely on the fact that the QCAR SDK has been
// already initialized
initApplicationAR();
// Proceed to next application initialization status
updateApplicationStatus(APPSTATUS_LOAD_TRACKER);
break;
case APPSTATUS_LOAD_TRACKER:
// Load the tracking data set
//
// This task instance must be created and invoked on the UI
// thread and it can be executed only once!
try {
mLoadTrackerTask = new LoadTrackerTask();
mLoadTrackerTask.execute();
} catch (Exception e) {
DebugLog.LOGE("Loading tracking data set failed");
}
break;
case APPSTATUS_INITED:
// Hint to the virtual machine that it would be a good time to
// run the garbage collector.
//
// NOTE: This is only a hint. There is no guarantee that the
// garbage collector will actually be run.
System.gc();
// Native post initialization:
onQCARInitializedNative();
// The elapsed time since the splash screen was visible:
long splashScreenTime = System.currentTimeMillis()
- mSplashScreenStartTime;
long newSplashScreenTime = 0;
if (splashScreenTime < MIN_SPLASH_SCREEN_TIME) {
newSplashScreenTime = MIN_SPLASH_SCREEN_TIME - splashScreenTime;
}
// Request a callback function after a given timeout to dismiss
// the splash screen:
mSplashScreenHandler = new Handler();
mSplashScreenRunnable = new Runnable() {
public void run() {
// Hide the splash screen
mSplashScreenView.setVisibility(View.INVISIBLE);
// Activate the renderer
mRenderer.mIsActive = true;
// Now add the GL surface view. It is important
// that the OpenGL ES surface view gets added
// BEFORE the camera is started and video
// background is configured.
setContentView(R.layout.main);
frame = (FrameLayout) findViewById(R.id.frame);
frame.addView(mGlView, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
tv = (TextView) findViewById(R.id.tv);
left1 = (TextView) findViewById(R.id.left1);
left2 = (TextView) findViewById(R.id.left2);
right1 = (TextView) findViewById(R.id.right1);
right2 = (TextView) findViewById(R.id.right2);
center = (ImageView) findViewById(R.id.imagecenter);
first = (ImageView) findViewById(R.id.imageleft1);
second = (ImageView) findViewById(R.id.imageleft2);
fourth = (ImageView) findViewById(R.id.imageright1);
fifth = (ImageView) findViewById(R.id.imageright2);
tv.setText(result);
try {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin
// provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria,
false);
Location location = locationManager
.getLastKnownLocation(provider);
// Initialize the location fields
if (location != null) {
System.out.println("Provider " + provider
+ " has been selected.");
lat = (double) (location.getLatitude());
lng = (double) (location.getLongitude());
getAddress();
} else {
Toast.makeText(getApplicationContext(),
"Provider not available", 4000).show();
}
onLocationChanged(location);
dialog = ProgressDialog.show(ImageTargets.this, "",
"Loading Data ...Please Wait", true);
fetchData.start();
} catch (NullPointerException g) {
}
// Start the camera:
updateApplicationStatus(APPSTATUS_CAMERA_RUNNING);
}
};
mSplashScreenHandler.postDelayed(mSplashScreenRunnable,
newSplashScreenTime);
break;
case APPSTATUS_CAMERA_STOPPED:
// Call the native function to stop the camera
stopCamera();
break;
case APPSTATUS_CAMERA_RUNNING:
// Call the native function to start the camera
startCamera();
rose = new Rose(ImageTargets.this);
// setContentView(rose);
// get sensor manager
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
setProjectionMatrix();
break;
default:
throw new RuntimeException("Invalid application state");
}
}
/** Tells native code whether we are in portait or landscape mode */
private native void setActivityPortraitMode(boolean isPortrait);
/** Initialize application GUI elements that are not related to AR. */
private void initApplication() {
// Set the screen orientation
//
// NOTE: It is recommended to set this because of the following reasons:
//
// 1.) Before Android 2.2 there is no reliable way to query the
// absolute screen orientation from an activity, therefore using
// an undefined orientation is not recommended. Screen
// orientation matching orientation sensor measurements is also
// not recommended as every screen orientation change triggers
// deinitialization / (re)initialization steps in internal QCAR
// SDK components resulting in unnecessary overhead during
// application run-time.
//
// 2.) Android camera drivers seem to always deliver landscape images
// thus QCAR SDK components (e.g. camera capturing) need to know
// when we are in portrait mode. Before Android 2.2 there is no
// standard, device-independent way to let the camera driver know
// that we are in portrait mode as each device seems to require a
// different combination of settings to rotate camera preview
// frames images to match portrait mode views. Because of this,
// we suggest that the activity using the QCAR SDK be locked
// to landscape mode if you plan to support Android 2.1 devices
// as well. Froyo is fine with both orientations.
int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
// Apply screen orientation
setRequestedOrientation(screenOrientation);
// Pass on screen orientation info to native code
setActivityPortraitMode(screenOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
storeScreenDimensions();
// As long as this window is visible to the user, keep the device's
// screen turned on and bright.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Create and add the splash screen view
mSplashScreenView = new ImageView(this);
mSplashScreenView.setImageResource(mSplashScreenImageResource);
addContentView(mSplashScreenView, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mSplashScreenStartTime = System.currentTimeMillis();
}
/** Native function to initialize the application. */
private native void initApplicationNative(int width, int height);
/** Initializes AR application components. */
private void initApplicationAR() {
// Do application initialization in native code (e.g. registering
// callbacks, etc.)
initApplicationNative(mScreenWidth, mScreenHeight);
// Create OpenGL ES view:
int depthSize = 16;
int stencilSize = 0;
boolean translucent = QCAR.requiresAlpha();
mGlView = new QCARSampleGLView(this);
mGlView.init(mQCARFlags, translucent, depthSize, stencilSize);
mRenderer = new ImageTargetsRenderer();
mGlView.setRenderer(mRenderer);
}
/**
* Invoked the first time when the options menu is displayed to give the
* Activity a chance to populate its Menu with menu items.
*/
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
mDataSetMenuItem = menu.add("Switch to Tarmac dataset");
menu.add("Toggle flash");
menu.add("Trigger autofocus");
SubMenu focusModes = menu.addSubMenu("Focus Modes");
focusModes.add("Normal").setCheckable(true);
focusModes.add("Continuous Autofocus").setCheckable(true);
focusModes.add("Infinity").setCheckable(true);
focusModes.add("Macro Mode").setCheckable(true);
return true;
}
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
try {
// int start = responseBody.indexOf("{");
// int end = responseBody.length();
// String result = responseBody.substring(start, end);
// // Toast.makeText(getApplicationContext(), result,
// 9000).show();
int start = responseBody.indexOf("status");
int end = responseBody.length();
String result = responseBody.substring(start, end);
String result1 = "[{" + '"' + result.toString().trim();
// Toast.makeText(getApplicationContext(), result1,
// 9000).show();
// Log.e("result", "" + result1);
try {
jArray = new JSONArray(result1.toString());
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
try {
items = new String[jArray.length()];
for (int i = 0; i < jArray.length(); i++) {
items[i] = jArray.getJSONObject(i).getString("status")
.toString();
Location = jArray.getJSONObject(i)
.getString("Location").toString();
}
jSubArray = new JSONArray(Location.toString());
loc_id = new String[jSubArray.length()];
longitude = new String[jSubArray.length()];
latitude = new String[jSubArray.length()];
thumb = new String[jSubArray.length()];
type = new String[jSubArray.length()];
type_id = new String[jSubArray.length()];
name = new String[jSubArray.length()];
cat_id = new String[jSubArray.length()];
cat_name = new String[jSubArray.length()];
one_liner = new String[jSubArray.length()];
for (int j = 0; j < jSubArray.length(); j++) {
loc_id[j] = jSubArray.getJSONObject(j)
.getString("loc_id").toString();
longitude[j] = jSubArray.getJSONObject(j)
.getString("longitude").toString();
latitude[j] = jSubArray.getJSONObject(j)
.getString("latitude").toString();
thumb[j] = jSubArray.getJSONObject(j)
.getString("thumb").toString();
type[j] = jSubArray.getJSONObject(j).getString("type")
.toString();
type_id[j] = jSubArray.getJSONObject(j)
.getString("type_id").toString();
name[j] = jSubArray.getJSONObject(j).getString("name")
.toString();
cat_id[j] = jSubArray.getJSONObject(j)
.getString("cat_id").toString();
cat_name[j] = jSubArray.getJSONObject(j)
.getString("cat_name").toString();
one_liner[j] = jSubArray.getJSONObject(j)
.getString("one_liner").toString();
// Toast.makeText(getApplicationContext(),
// "lat" + thumb[j], 7000).show();
Log.e("lat thumb[j]", thumb[j]);
total = jSubArray.length();
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
if (items[0].equalsIgnoreCase("OK")) {
if ((dialog.isShowing()))
dialog.dismiss();
} else {
if ((dialog.isShowing()))
dialog.dismiss();
Toast.makeText(getApplicationContext(),
"try after some time", 4000).show();
}
} catch (NullPointerException e) {
if ((dialog.isShowing()))
dialog.dismiss();
Toast.makeText(getApplicationContext(), "try after some time",
4000).show();
}
// try {
//
// Activity activity;
//
// activity = CityAboutActivity.this;
//
// inflater = (LayoutInflater) activity
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//
// imageLoader = new ImageLoader1(activity.getApplicationContext());
//
// // for (int i = 0; i < total; i++) {
//
// // imageview_left[i].setImageBitmap(bmp[i]);
// thumbpic.setTag(thumb[0]);
//
// imageLoader.DisplayImage(thumb[0], activity, thumbpic);
//
// // }
// } catch (NullPointerException f) {
// Toast.makeText(getApplicationContext(), "reload the page", 5000)
// .show();
// } catch (ArrayIndexOutOfBoundsException g) {
// Toast.makeText(getApplicationContext(), "reload the page", 5000)
// .show();
// }
// Toast.makeText(
// getApplicationContext(),
// longitude[0] + latitude[0] + thumb[0]
// + longitude[total - 1] + thumb[total - 1]
// + latitude[total - 1], 4000).show();
// for (int k = 0; k < total; k++) {
// drawable[k] = ImageOperations(getApplicationContext(), thumb[k]);
//
// }
// =================================
try {
// int start = responseBody.indexOf("{");
// int end = responseBody.length();
// String result = responseBody.substring(start, end);
// // Toast.makeText(getApplicationContext(), result,
// 9000).show();
int start_lng = responseBody_lng.indexOf("status");
int end_lng = responseBody_lng.length();
String result_lng = responseBody_lng.substring(start_lng,
end_lng);
String result1_lng = "[{" + '"' + result_lng.toString().trim();
// Toast.makeText(getApplicationContext(), result1,
// 9000).show();
// Log.e("result", "" + result1);
try {
jArray_lng = new JSONArray(result1_lng.toString());
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
try {
items_lng = new String[jArray_lng.length()];
for (int i = 0; i < jArray_lng.length(); i++) {
items_lng[i] = jArray_lng.getJSONObject(i)
.getString("status").toString();
Location_lng = jArray_lng.getJSONObject(i)
.getString("Location").toString();
}
jSubArray_lng = new JSONArray(Location_lng.toString());
loc_id_lng = new String[jSubArray_lng.length()];
longitude_lng = new String[jSubArray_lng.length()];
latitude_lng = new String[jSubArray_lng.length()];
thumb_lng = new String[jSubArray_lng.length()];
type_lng = new String[jSubArray_lng.length()];
type_id_lng = new String[jSubArray_lng.length()];
name_lng = new String[jSubArray_lng.length()];
cat_id_lng = new String[jSubArray_lng.length()];
cat_name_lng = new String[jSubArray_lng.length()];
one_liner_lng = new String[jSubArray_lng.length()];
for (int j = 0; j < jSubArray_lng.length(); j++) {
loc_id_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("loc_id").toString();
longitude_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("longitude").toString();
latitude_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("latitude").toString();
thumb_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("thumb").toString();
type_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("type").toString();
type_id_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("type_id").toString();
name_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("name").toString();
cat_id_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("cat_id").toString();
cat_name_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("cat_name").toString();
one_liner_lng[j] = jSubArray_lng.getJSONObject(j)
.getString("one_liner").toString();
// Toast.makeText(getApplicationContext(),
// "lng" + thumb_lng[j], 7000).show();
// Log.e("lng thumb[j]", thumb_lng[j]);
total_lng = jSubArray_lng.length();
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
if (items[0].equalsIgnoreCase("OK")) {
if ((dialog.isShowing()))
dialog.dismiss();
} else {
if ((dialog.isShowing()))
dialog.dismiss();
Toast.makeText(getApplicationContext(),
"try after some time", 4000).show();
}
} catch (NullPointerException e) {
if ((dialog.isShowing()))
dialog.dismiss();
Toast.makeText(getApplicationContext(), "try after some time",
4000).show();
}
setdata();
if ((dialog.isShowing()))
dialog.dismiss();
}
};
public void setdata() {
name_temp_lat_left = new String[total];
thumb_temp_lat_left = new String[total];
k1 = -1;
for (int i = 0; i < total; i++) {
Double x1 = Double.parseDouble(latitude[i]);
if ((x1 > lat - 0.5) && (x1 < lat)) {
k1++;
name_temp_lat_left[k1] = name[i];
thumb_temp_lat_left[k1] = thumb[i];
} else {
}
}
name_temp_lat_right = new String[total];
thumb_temp_lat_right = new String[total];
k2 = -1;
for (int i = 0; i < total; i++) {
Double x1 = Double.parseDouble(latitude[i]);
if ((x1 < lat + 0.5) && (x1 > lat)) {
k2++;
name_temp_lat_right[k2] = name[i];
thumb_temp_lat_right[k2] = thumb[i];
} else {
}
}
name_temp_lng_right = new String[total];
thumb_temp_lng_right = new String[total];
k3 = -1;
for (int i = 0; i < total; i++) {
Double x1 = Double.parseDouble(longitude_lng[i]);
if ((x1 < lng + 0.5) && (x1 > lng)) {
k3++;
name_temp_lng_right[k3] = name_lng[i];
thumb_temp_lng_right[k3] = thumb_lng[i];
} else {
}
}
name_temp_lng_left = new String[total];
thumb_temp_lng_left = new String[total];
k4 = -1;
for (int i = 0; i < total; i++) {
Double x1 = Double.parseDouble(longitude_lng[i]);
if ((x1 > lng - 0.5) && (x1 < lng)) {
k4++;
name_temp_lng_left[k4] = name_lng[i];
thumb_temp_lng_left[k4] = thumb_lng[i];
} else {
}
}
if (flag1q == true) {
left1.setText(name_temp_lat_left[0]);
left2.setText(name_temp_lat_left[1]);
right1.setText(name_temp_lat_right[k2 - 1]);
right2.setText(name_temp_lat_right[k2]);
try {
Activity activity;
activity = ImageTargets.this;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader1(activity.getApplicationContext());
// for (int i = 0; i < total; i++) {
// imageview_left[i].setImageBitmap(bmp[i]);
first.setTag(thumb_temp_lat_left[0]);
second.setTag(thumb_temp_lat_left[1]);
fourth.setTag(thumb_temp_lat_right[k2 - 1]);
fifth.setTag(thumb_temp_lat_right[k2]);
imageLoader.DisplayImage(thumb_temp_lat_left[0], activity,
first);
imageLoader.DisplayImage(thumb_temp_lat_left[1], activity,
second);
imageLoader.DisplayImage(thumb_temp_lat_right[k2 - 1],
activity, fourth);
imageLoader.DisplayImage(thumb_temp_lat_right[k2], activity,
fifth);
// }
} catch (NullPointerException f) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
} catch (ArrayIndexOutOfBoundsException g) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
}
} else if (flag2q == true) {
left1.setText(name_temp_lng_left[k4]);
left2.setText(name_temp_lng_left[k4 - 1]);
right1.setText(name_temp_lng_right[0]);
right2.setText(name_temp_lng_right[1]);
try {
Activity activity;
activity = ImageTargets.this;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader1(activity.getApplicationContext());
// for (int i = 0; i < total; i++) {
// imageview_left[i].setImageBitmap(bmp[i]);
first.setTag(thumb_temp_lng_left[k4]);
second.setTag(thumb_temp_lng_left[k4 - 1]);
fourth.setTag(thumb_temp_lng_right[0]);
fifth.setTag(thumb_temp_lng_right[1]);
imageLoader.DisplayImage(thumb_temp_lng_left[k4], activity,
first);
imageLoader.DisplayImage(thumb_temp_lng_left[k4 - 1], activity,
second);
imageLoader.DisplayImage(thumb_temp_lng_right[0], activity,
fourth);
imageLoader.DisplayImage(thumb_temp_lng_right[1], activity,
fifth);
// }
} catch (NullPointerException f) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
} catch (ArrayIndexOutOfBoundsException g) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
}
} else if (flag3q == true) {
left1.setText(name_temp_lat_left[k1]);
left2.setText(name_temp_lat_left[k1 - 1]);
right1.setText(name_temp_lat_right[0]);
right2.setText(name_temp_lat_right[1]);
try {
Activity activity;
activity = ImageTargets.this;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader1(activity.getApplicationContext());
// for (int i = 0; i < total; i++) {
// imageview_left[i].setImageBitmap(bmp[i]);
first.setTag(thumb_temp_lat_left[k1]);
second.setTag(thumb_temp_lat_left[k1 - 1]);
fourth.setTag(thumb_temp_lat_right[0]);
fifth.setTag(thumb_temp_lat_right[1]);
imageLoader.DisplayImage(thumb_temp_lat_left[k1], activity,
first);
imageLoader.DisplayImage(thumb_temp_lat_left[k1 - 1], activity,
second);
imageLoader.DisplayImage(thumb_temp_lat_right[0], activity,
fourth);
imageLoader.DisplayImage(thumb_temp_lat_right[1], activity,
fifth);
// }
} catch (NullPointerException f) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
} catch (ArrayIndexOutOfBoundsException g) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
}
} else if (flag4q == true) {
left1.setText(name_temp_lng_left[0]);
left2.setText(name_temp_lng_left[1]);
right1.setText(name_temp_lng_right[k3]);
right2.setText(name_temp_lng_right[k3 - 1]);
try {
Activity activity;
activity = ImageTargets.this;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader1(activity.getApplicationContext());
// for (int i = 0; i < total; i++) {
// imageview_left[i].setImageBitmap(bmp[i]);
first.setTag(thumb_temp_lng_left[0]);
second.setTag(thumb_temp_lng_left[1]);
fourth.setTag(thumb_temp_lng_right[k3]);
fifth.setTag(thumb_temp_lng_right[k3 - 1]);
imageLoader.DisplayImage(thumb_temp_lng_left[0], activity,
first);
imageLoader.DisplayImage(thumb_temp_lng_left[1], activity,
second);
imageLoader.DisplayImage(thumb_temp_lng_right[k3], activity,
fourth);
imageLoader.DisplayImage(thumb_temp_lng_right[k3 - 1],
activity, fifth);
// }
} catch (NullPointerException f) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
} catch (ArrayIndexOutOfBoundsException g) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
}
} else if (flag0 == true) {
left1.setText(name_temp_lat_left[0]);//<----------
left2.setText(name_temp_lat_left[1]);//<----------
right1.setText(name_temp_lat_right[k2 - 1]);//--------------->
right2.setText(name_temp_lat_right[k2]);//------------------->
try {
Activity activity;
activity = ImageTargets.this;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader1(activity.getApplicationContext());
// for (int i = 0; i < total; i++) {
// imageview_left[i].setImageBitmap(bmp[i]);
first.setTag(thumb_temp_lat_left[0]);
second.setTag(thumb_temp_lat_left[1]);
fourth.setTag(thumb_temp_lat_right[k2 - 1]);
fifth.setTag(thumb_temp_lat_right[k2]);
imageLoader.DisplayImage(thumb_temp_lat_left[0], activity,
first);
imageLoader.DisplayImage(thumb_temp_lat_left[1], activity,
second);
imageLoader.DisplayImage(thumb_temp_lat_right[k2 - 1],
activity, fourth);
imageLoader.DisplayImage(thumb_temp_lat_right[k2], activity,
fifth);
// }
} catch (NullPointerException f) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
} catch (ArrayIndexOutOfBoundsException g) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
}
} else if (flag90 == true) {
left1.setText(name_temp_lng_left[k4]);
left2.setText(name_temp_lng_left[k4 - 1]);
right1.setText(name_temp_lng_right[0]);
right2.setText(name_temp_lng_right[1]);
try {
Activity activity;
activity = ImageTargets.this;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader1(activity.getApplicationContext());
// for (int i = 0; i < total; i++) {
// imageview_left[i].setImageBitmap(bmp[i]);
first.setTag(thumb_temp_lng_left[k4]);
second.setTag(thumb_temp_lng_left[k4 - 1]);
fourth.setTag(thumb_temp_lng_right[0]);
fifth.setTag(thumb_temp_lng_right[1]);
imageLoader.DisplayImage(thumb_temp_lng_left[k4], activity,
first);
imageLoader.DisplayImage(thumb_temp_lng_left[k4 - 1], activity,
second);
imageLoader.DisplayImage(thumb_temp_lng_right[0], activity,
fourth);
imageLoader.DisplayImage(thumb_temp_lng_right[1], activity,
fifth);
// }
} catch (NullPointerException f) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
} catch (ArrayIndexOutOfBoundsException g) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
}
} else if (flag270 == true) {
left1.setText(name_temp_lng_left[0]);
left2.setText(name_temp_lng_left[1]);
right1.setText(name_temp_lng_right[k3]);
right2.setText(name_temp_lng_right[k3 - 1]);
try {
Activity activity;
activity = ImageTargets.this;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader1(activity.getApplicationContext());
// for (int i = 0; i < total; i++) {
// imageview_left[i].setImageBitmap(bmp[i]);
first.setTag(thumb_temp_lng_left[0]);
second.setTag(thumb_temp_lng_left[1]);
fourth.setTag(thumb_temp_lng_right[k3]);
fifth.setTag(thumb_temp_lng_right[k3 - 1]);
imageLoader.DisplayImage(thumb_temp_lng_left[0], activity,
first);
imageLoader.DisplayImage(thumb_temp_lng_left[1], activity,
second);
imageLoader.DisplayImage(thumb_temp_lng_right[k3], activity,
fourth);
imageLoader.DisplayImage(thumb_temp_lng_right[k3 - 1],
activity, fifth);
// }
} catch (NullPointerException f) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
} catch (ArrayIndexOutOfBoundsException g) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
}
} else if (flag180 == true) {
left1.setText(name_temp_lat_left[k1]);
left2.setText(name_temp_lat_left[k1 - 1]);
right1.setText(name_temp_lat_right[0]);
right2.setText(name_temp_lat_right[1]);
try {
Activity activity;
activity = ImageTargets.this;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader1(activity.getApplicationContext());
// for (int i = 0; i < total; i++) {
// imageview_left[i].setImageBitmap(bmp[i]);
first.setTag(thumb_temp_lat_left[k1]);
second.setTag(thumb_temp_lat_left[k1 - 1]);
fourth.setTag(thumb_temp_lat_right[0]);
fifth.setTag(thumb_temp_lat_right[1]);
imageLoader.DisplayImage(thumb_temp_lat_left[k1], activity,
first);
imageLoader.DisplayImage(thumb_temp_lat_left[k1 - 1], activity,
second);
imageLoader.DisplayImage(thumb_temp_lat_right[0], activity,
fourth);
imageLoader.DisplayImage(thumb_temp_lat_right[1], activity,
fifth);
// }
} catch (NullPointerException f) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
} catch (ArrayIndexOutOfBoundsException g) {
Toast.makeText(getApplicationContext(), "reload the page", 5000)
.show();
}
}
}
Thread fetchData = new Thread() {// worker thread or background thread
public void run() {
double TIMEOUT_MILLISEC = 1234567890;
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,
(int) TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams,
(int) TIMEOUT_MILLISEC);
//
HttpParams p = new BasicHttpParams();
// p.setParameter("name", pvo.getName());
p.setParameter("View location", "View location");
p.setParameter("key", "c89a7662dae613ea3d20d334339b6dff");
// Instantiate an HttpClient
HttpClient httpclient = new DefaultHttpClient(p);
HttpPost httppost = new HttpPost(URL);
List nameValuePairs = new ArrayList(2);
nameValuePairs.add(new BasicNameValuePair("View location",
"View location"));
nameValuePairs.add(new BasicNameValuePair("key",
"c89a7662dae613ea3d20d334339b6dff"));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) { // TODO Auto-generated
// catch
;
}
ResponseHandler responseHandler = new BasicResponseHandler();
try {
responseBody = httpclient.execute(httppost, responseHandler);
Log.e("aaaaaaaaaaaaaaaaaaaaaaaaa+++", responseBody.toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// ===============
HttpParams httpParams_lng = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams_lng,
(int) TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams_lng,
(int) TIMEOUT_MILLISEC);
//
HttpParams p_lng = new BasicHttpParams();
// p.setParameter("name", pvo.getName());
p_lng.setParameter("View location", "View location");
p_lng.setParameter("key", "c89a7662dae613ea3d20d334339b6dff");
// Instantiate an HttpClient
HttpClient httpclient_lng = new DefaultHttpClient(p);
HttpPost httppost_lng = new HttpPost(URL_lng);
List nameValuePairs_lng = new ArrayList(
2);
nameValuePairs_lng.add(new BasicNameValuePair("View location",
"View location"));
nameValuePairs_lng.add(new BasicNameValuePair("key",
"c89a7662dae613ea3d20d334339b6dff"));
try {
httppost_lng.setEntity(new UrlEncodedFormEntity(
nameValuePairs_lng));
} catch (UnsupportedEncodingException e) { // TODO Auto-generated
// catch
;
}
ResponseHandler responseHandler_lng = new BasicResponseHandler();
try {
responseBody_lng = httpclient_lng.execute(httppost_lng,
responseHandler_lng);
Log.e("aaaaaaaaaaaaaaaaaaaaaaaaa+++",
responseBody_lng.toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
handler.sendEmptyMessage(0);
}
};
/** Tells native code to switch dataset as soon as possible */
private native void switchDatasetAsap();
/** Invoked when the user selects an item from the Menu */
public boolean onOptionsItemSelected(MenuItem item) {
if (item == mDataSetMenuItem) {
switchDatasetAsap();
mIsStonesAndChipsDataSetActive = !mIsStonesAndChipsDataSetActive;
if (mIsStonesAndChipsDataSetActive) {
item.setTitle("Switch to Tarmac dataset");
} else {
item.setTitle("Switch to StonesAndChips dataset");
}
} else if (item.getTitle().equals("Toggle flash")) {
mFlash = !mFlash;
boolean result = activateFlash(mFlash);
DebugLog.LOGI("Turning flash " + (mFlash ? "ON" : "OFF") + " "
+ (result ? "WORKED" : "FAILED") + "!!");
} else if (item.getTitle().equals("Trigger autofocus")) {
boolean result = autofocus();
DebugLog.LOGI("Autofocus requested"
+ (result ? " successfully."
: ". Not supported in current mode or on this device."));
} else {
int arg = -1;
if (item.getTitle().equals("Normal"))
arg = 0;
if (item.getTitle().equals("Continuous Autofocus"))
arg = 1;
if (item.getTitle().equals("Infinity"))
arg = 2;
if (item.getTitle().equals("Macro Mode"))
arg = 3;
if (arg != -1) {
boolean result = setFocusMode(arg);
if (result) {
item.setChecked(true);
if (checked != null && item != checked)
checked.setChecked(false);
checked = item;
}
DebugLog.LOGI("Requested Focus mode "
+ item.getTitle()
+ (result ? " successfully."
: ". Not supported on this device."));
}
}
return true;
}
private MenuItem checked;
private boolean mFlash = false;
private native boolean activateFlash(boolean flash);
private native boolean autofocus();
private native boolean setFocusMode(int mode);
/** Returns the number of registered textures. */
public int getTextureCount() {
return mTextures.size();
}
/** Returns the texture object at the specified index. */
public Texture getTexture(int i) {
return mTextures.elementAt(i);
}
/** A helper for loading native libraries stored in "libs/armeabi*". */
public static boolean loadLibrary(String nLibName) {
try {
System.loadLibrary(nLibName);
DebugLog.LOGI("Native library lib" + nLibName + ".so loaded");
return true;
} catch (UnsatisfiedLinkError ulee) {
DebugLog.LOGE("The library lib" + nLibName
+ ".so could not be loaded");
} catch (SecurityException se) {
DebugLog.LOGE("The library lib" + nLibName
+ ".so was not allowed to be loaded");
}
return false;
}
@Override
public void onAccuracyChanged(int sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(int sensor, float[] values) {
// TODO Auto-generated method stub
if (sensor != ImageTargets.sensor)
return;
int orientation = (int) values[0];
// Toast.makeText(getApplicationContext(), "" + orientation,
// 4000).show();
// rose.setDirection(orientation);
// Toast.makeText(getApplicationContext(), "" + orientation,
// 4000).show();
try {
center.setBackgroundResource(R.drawable.icon_vuforia);
if ((orientation > 0) && (orientation < 90)) {
// Toast.makeText(getApplicationContext(), "north-east" +
// orientation,
// 4000).show();
// left1.setText("iskcon");
// left2.setText("gandhinagar");
// right1.setText("honest");
// right2.setText("sarkhej");
// first.setBackgroundResource(R.drawable.isckon);
// second.setBackgroundResource(R.drawable.gandhinagar);
// fourth.setBackgroundResource(R.drawable.honest);
// fifth.setBackgroundResource(R.drawable.sarkhej);
flag1q = true;
flag2q = false;
flag3q = false;
flag4q = false;
flag0 = false;
flag90 = false;
flag180 = false;
flag270 = false;
setdata();
} else if ((orientation > 90) && (orientation < 180)) {
// Toast.makeText(getApplicationContext(), "east-south" +
// orientation,
// 4000).show();
// left1.setText("laldaravaja");
// left2.setText("minara");
// right1.setText("place a");
// right2.setText("place b");
// first.setBackgroundResource(R.drawable.laldaravaja);
// second.setBackgroundResource(R.drawable.minara);
// fourth.setBackgroundResource(R.drawable.placea);
// fifth.setBackgroundResource(R.drawable.placeb);
flag1q = false;
flag2q = true;
flag3q = false;
flag4q = false;
flag0 = false;
flag90 = false;
flag180 = false;
flag270 = false;
setdata();
} else if (orientation == 180) {
// Toast.makeText(getApplicationContext(), "south" +
// orientation, 4000)
// .show();
// right1.setText("iskcon");
// right2.setText("gandhinagar");
// left1.setText("honest");
// left2.setText("sarkhej");
// fourth.setBackgroundResource(R.drawable.isckon);
// fifth.setBackgroundResource(R.drawable.gandhinagar);
// first.setBackgroundResource(R.drawable.honest);
// second.setBackgroundResource(R.drawable.sarkhej);
flag1q = false;
flag2q = false;
flag3q = false;
flag4q = false;
flag0 = false;
flag90 = false;
flag180 = true;
flag270 = false;
setdata();
} else if (orientation == 270) {
// Toast.makeText(getApplicationContext(), "west" + orientation,
// 4000)
// .show();
// right1.setText("laldaravaja");
// right2.setText("minara");
// left1.setText("place a");
// left2.setText("place b");
// fourth.setBackgroundResource(R.drawable.laldaravaja);
// fifth.setBackgroundResource(R.drawable.minara);
// first.setBackgroundResource(R.drawable.placea);
// second.setBackgroundResource(R.drawable.placeb);
flag1q = false;
flag2q = false;
flag3q = false;
flag4q = false;
flag0 = false;
flag90 = false;
flag180 = false;
flag270 = true;
setdata();
} else if (orientation == 90) {
// Toast.makeText(getApplicationContext(), "east" + orientation,
// 4000)
// .show();
// left1.setText("laldaravaja");
// left2.setText("minara");
// right1.setText("place a");
// right2.setText("place b");
// fourth.setBackgroundResource(R.drawable.placea);
// fifth.setBackgroundResource(R.drawable.placeb);
// first.setBackgroundResource(R.drawable.laldaravaja);
// second.setBackgroundResource(R.drawable.minara);
flag1q = false;
flag2q = false;
flag3q = false;
flag4q = false;
flag0 = false;
flag90 = true;
flag180 = false;
flag270 = false;
setdata();
} else if (orientation == 0) {
// left1.setText("iskcon");
// left2.setText("gandhinagar");
// right1.setText("honest ");
// right2.setText("sarkhej");
// // Toast.makeText(getApplicationContext(), "north" +
// // orientation, 4000)
// // .show();
// fourth.setBackgroundResource(R.drawable.honest);
// fifth.setBackgroundResource(R.drawable.sarkhej);
// first.setBackgroundResource(R.drawable.isckon);
// second.setBackgroundResource(R.drawable.gandhinagar);
flag1q = false;
flag2q = false;
flag3q = false;
flag4q = false;
flag0 = true;
flag90 = false;
flag180 = false;
flag270 = false;
setdata();
} else if ((orientation > 180) && (orientation < 270)) {
// Toast.makeText(getApplicationContext(), "south-west" +
// orientation,
// 4000).show();
// right1.setText("iskcon");
// right2.setText("gandhinagar");
// left1.setText("honest");
// left2.setText("sarkhej");
// fourth.setBackgroundResource(R.drawable.isckon);
// fifth.setBackgroundResource(R.drawable.gandhinagar);
// first.setBackgroundResource(R.drawable.honest);
// second.setBackgroundResource(R.drawable.sarkhej);
flag1q = false;
flag2q = false;
flag3q = true;
flag4q = false;
flag0 = false;
flag90 = false;
flag180 = false;
flag270 = false;
setdata();
} else if (orientation > 270) {
// Toast.makeText(getApplicationContext(), "west-north" +
// orientation,
// 4000).show();
// right1.setText("laldaravaja");
// right2.setText("minara");
// left1.setText("place a");
// left2.setText("place b");
// fourth.setBackgroundResource(R.drawable.laldaravaja);
// fifth.setBackgroundResource(R.drawable.minara);
// first.setBackgroundResource(R.drawable.placea);
// second.setBackgroundResource(R.drawable.placeb);
// 1)get present lat and long 2)get direction i.e.,north 3)get
// nearby lat and long from webservice
// 4)for ex let present be 70 and 22 and nearby is 71,22 and
// 69,22 5)from north 71,22 is at right and 69,22
// is at left
// Truth=>the heighest longitudial place is in north most
// direction of gujarat and lowest is
// at south most direction same way most latitudeal place is at
// west and least longitudial
// place is at east side of gujarat.
flag1q = false;
flag2q = false;
flag3q = false;
flag4q = true;
flag0 = false;
flag90 = false;
flag180 = false;
flag270 = false;
setdata();
}
} catch (NullPointerException f) {
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment