I am using metaio sdk 6.0.2. i am working on metaio INSTANT_2D_GRAVITY tracking and was able to display 3d model. I want to display same 3d model when tracking is lost.but I am failing to do so. I tried by adding trackingValuesVector in onTrackingEvent of MetaioSDKCallbackHandler with no success. can anyone tell me where am I going wrong?
private TrackingValues mTrackingValues;// declared globally
private IGeometry mModel; // declared globally
private boolean mPreview=true;// declared globally
// start INSTANT_2D_GRAVITY tracking
public void onTakePicture(View v)
{
captureTrackingValues = true;
metaioSDK.startInstantTracking("INSTANT_2D_GRAVITY", new File(""), mPreview);
mPreview = !mPreview;
}
final class MetaioSDKCallbackHandler extends IMetaioSDKCallback
{
#Override
public void onInstantTrackingEvent(final boolean success,final File filePath) {
super.onInstantTrackingEvent(success, filePath);
if(mSurfaceView != null)
{
mSurfaceView.queueEvent(new Runnable() {
#Override
public void run() {
if(success)
{
if(captureTrackingValues == true)
{
metaioSDK.setTrackingConfiguration(filePath);
Log.i("Tracking value success","good");
}
}
else
{
Log.i("Tracking value failure","bad");
}
}
});
}
}
#Override
public void onTrackingEvent(TrackingValuesVector trackingValuesVector) {
super.onTrackingEvent(trackingValuesVector);
if (!trackingValuesVector.isEmpty())
{
for(int i =0;i< trackingValuesVector.size();i++)
{
if(trackingValuesVector.get(i).isTrackingState() && mModel!=null)
{
mTrackingValues = metaioSDK.getTrackingValues(i);
mModel.setCoordinateSystemID(trackingValuesVector.get(i).getCoordinateSystemID());
}
else {
if(mModel!= null && mTrackingValues != null) {
metaioSDK.setCosOffset(1, mTrackingValues);
//mChairModel.setCoordinateSystemID(0);
Log.e("TestAR","isTrackingState is null");
}
}
}
}
else{
if(mModel!= null && mTrackingValues != null) {
metaioSDK.setCosOffset(1, mTrackingValues);
//mModel.setCoordinateSystemID(0);
Log.e("TestAR","trackingValuesVector is null");
}
}
}
}
loading 3d model:
private void loadModel()
{
if (mSurfaceView != null) {
mSurfaceView.queueEvent(new Runnable() {
#Override
public void run() {
File chairModel = AssetsManager.getAssetPathAsFile(getApplicationContext(),"chair.obj");
if (chairModel != null) {
mModel = metaioSDK.createGeometry(chairModel);
mModel.setScale(3f);
mModel.setTranslation(new Vector3d(0f,0f,-60f));
mGestureHandler.addObject(mModel, 1);
mModel.setRotation(new Rotation(0f, 0.5f, 0f));
mModel.setCoordinateSystemID(1);
}
}
});
}
else
{
Log.e("exception", "msurfaceview is null");
}
}
I see that you also tried setting the model to COS 0. This should actually work, if the tracking is lost.
If you do not see the model, you would have to play around with the scale value (i.e. set a low value like 0.01) and with the Z translation value. Set a negative Z value in order to move the model away from the camera clipping plane.
Related
I must push a object just with one note and to push his media files, but it do not want to do this. I do not know why is difference , but if i do this without changing notes its work fine , but I need to send just changed notes , please help. What is my problem? I need to understand why this happen
private void pushMediaFiles(Task task,Note newNote, PushTaskListener listener)
{
PushTaskModel pushTaskModel=new PushTaskModel(Realm.getDefaultInstance().copyFromRealm(task));
pushTaskModel.notes.clear();
Note oldNote = new Note();
oldNote.update(newNote);
pushTaskModel.notes.add(oldNote);
service.pushData(pushTaskModel)
.map(taskResponse ->
{
ArrayList<MediaFile> filesToSave = new ArrayList<>();
for (Note note : task.getNotes())
{
for (MediaFile mediaFile : note.getMediaFiles())
{
if (mediaFile.hasChanges() && mediaFile.getFileAbsolutePath() != null)
{
filesToSave.add(Realm.getDefaultInstance().copyFromRealm(mediaFile));
}
}
}
return filesToSave;
})
.subscribe(taskMediaFiles ->
{
Log.d("PUSH_TASK_EVENT","3 GOOD");
if (taskMediaFiles.size() == 0)
{
listener.onSuccess();
return;
}
for (MediaFile mediaFile: taskMediaFiles)
{
saveMediaFile(mediaFile, new OnResponseListener()
{
#Override
public void onStart()
{
}
#Override
public void onComplete(boolean successfully)
{
listener.onSuccess();
}
#Override
public void onError(Throwable throwable)
{
listener.onError(throwable);
}
});
}
});
}
I've implemented native ZXing-embedded library in my Xamarin.Android project and everything's working fine except one issue that when I try to scan the QR or Barcodes from some distance, then it returns some random irrelevant values which are totally different from the original ones. After checking this post I've tried restricting the scan modes but it made no difference and it is still returning wrong values. Any help would be really appreciable.
Thanks in advance!
Update 2:
Here's is my code, you can check and let me know if there's something that needs to be corrected in it:
public class CustomScannerActivity : Activity, DecoratedBarcodeView.ITorchListener
{
public const int CUSTOMIZED_REQUEST_CODE = 1;
private CaptureManager capture;
private DecoratedBarcodeView barcodeScannerView;
private ImageButton switchFlashlightButton;
private ImageButton cameraButton;
private ViewfinderView viewfinderView;
TextView txtViewBottomText;
private bool torchOn;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
this.ActionBar.Hide();
SetContentView(Resource.Layout.activity_custom_scannerview);
barcodeScannerView = (DecoratedBarcodeView)FindViewById(Resource.Id.zxing_barcode_scanner);
barcodeScannerView.SetTorchListener(this);
var greenOverlay = (View)FindViewById(Resource.Id.view1);
Android.Util.DisplayMetrics displayMetrics = Resources.DisplayMetrics;
var scanWidth = (int)(displayMetrics.WidthPixels * 0.65);
barcodeScannerView.BarcodeView.FramingRectSize = new Size(scanWidth, 100);
greenOverlay.LayoutParameters.Width = scanWidth;
greenOverlay.LayoutParameters.Height = scanWidth;
CameraSettings settings = barcodeScannerView.BarcodeView.CameraSettings;
switchFlashlightButton = (ImageButton)FindViewById(Resource.Id.switch_flashlight);
cameraButton = (ImageButton)FindViewById(Resource.Id.camera);
viewfinderView = (ViewfinderView)FindViewById(Resource.Id.zxing_viewfinder_view);
txtViewBottomText = (TextView)FindViewById(Resource.Id.zxing_status_view);
txtViewBottomText.Text = AppResources.ScanAutomatically;
if (MainActivity.camPosition)
{
settings.RequestedCameraId = Convert.ToInt32(Android.Hardware.CameraFacing.Front);
switchFlashlightButton.Visibility = ViewStates.Gone;
barcodeScannerView.BarcodeView.CameraSettings = settings;
barcodeScannerView.Resume();
}
else
{
settings.RequestedCameraId = Convert.ToInt32(Android.Hardware.CameraFacing.Back);
switchFlashlightButton.Visibility = ViewStates.Visible;
barcodeScannerView.BarcodeView.CameraSettings = settings;
barcodeScannerView.Resume();
}
switchFlashlightButton.Click += (s, e) =>
{
if (!torchOn && !MainActivity.camPosition)
{
barcodeScannerView.SetTorchOn();
}
else
{
barcodeScannerView.SetTorchOff();
}
torchOn = !torchOn;
};
cameraButton.Click += (s, e) =>
{
//CameraSettings settings = barcodeScannerView.BarcodeView.CameraSettings;
if (barcodeScannerView.BarcodeView.IsPreviewActive)
{
barcodeScannerView.Pause();
}
//swap the id of the camera to be used
if (settings.RequestedCameraId == Convert.ToInt32(Android.Hardware.CameraFacing.Front))
{
settings.RequestedCameraId = Convert.ToInt32(Android.Hardware.CameraFacing.Back);
switchFlashlightButton.Visibility = ViewStates.Visible;
barcodeScannerView.SetTorchOff();
MainActivity.camPosition = false;
barcodeScannerView.BarcodeView.CameraSettings = settings;
barcodeScannerView.Resume();
}
else
{
settings.RequestedCameraId = Convert.ToInt32(Android.Hardware.CameraFacing.Front);
switchFlashlightButton.Visibility = ViewStates.Gone;
barcodeScannerView.SetTorchOff();
MainActivity.camPosition = true;
barcodeScannerView.BarcodeView.CameraSettings = settings;
barcodeScannerView.Resume();
}
};
// if the device does not have flashlight in its camera,
// then remove the switch flashlight button...
if (!hasFlash())
{
switchFlashlightButton.Visibility = ViewStates.Gone;
}
capture = new CaptureManager(this, barcodeScannerView);
capture.InitializeFromIntent(Intent, savedInstanceState);
capture.Decode();
}
protected override void OnResume()
{
base.OnResume();
if (capture != null)
{
capture.OnResume();
}
}
protected override void OnPause()
{
base.OnPause();
if (capture != null)
{
capture.OnPause();
}
}
protected override void OnDestroy()
{
base.OnDestroy();
if (capture != null)
{
capture.OnDestroy();
}
}
protected override void OnSaveInstanceState(Bundle outState)
{
base.OnSaveInstanceState(outState);
if (capture != null)
{
capture.OnSaveInstanceState(outState);
}
}
//public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e)
//{
// return barcodeScannerView.OnKeyDown(keyCode, e) || base.OnKeyDown(keyCode, e);
//}
private bool hasFlash()
{
return this.ApplicationContext.PackageManager.HasSystemFeature(Android.Content.PM.PackageManager.FeatureCameraFlash);//"android.hardware.camera.flash"
}
public void OnTorchOff()
{
}
public void OnTorchOn()
{
}
}
I am fetching data from database. My views are updating only first time when I open the activity. Then when I again open the activity, my views are not updated.(Activity is starting again, hence onCreate() is called again & all settings are same). If I getText() after setting the text, I am getting proper values in log but nothing is displayed in view.
Here is my code snippet:
//My Call Back method
#Override
public void onRatingDataLoaded(ReviewJsonModel review) {
int ratingCount = 0, ownRating = 0;
String averageRating = "0";
if (review != null) {
ratingCount = review.review_count;
DecimalFormat format = new DecimalFormat("##.00");
averageRating = format.format(review.rating);
if (review.ownreviews != null) {
try {
ownRating = Integer.parseInt(review.ownreviews.rating);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
} else {
// do something
}
mTotalRatingCount.setText(String.format(getResources().getString(R.string.review_count), ratingCount));
mAverageRating.setText(averageRating);
// Log.v("LoggingReview", mTotalRatingCount.getText().toString().trim);
myRating.setRating(ownRating);
}
//Here I am setting listner as well as loading data.
public void loadReviewData(RatingDataLoadListener listener, int destinationId) {
if (mDataLoadListener == null)
mDataLoadListener = listener;
new getReviews().execute(destinationId);
}
Next is my asyntask
private class getReviews extends AsyncTask<Integer, Void, ReviewJsonModel> {
#Override
protected ReviewJsonModel doInBackground(Integer... integers) {
Cursor appCursor = mRatingApi.getDestinationReview(integers[0]);
ReviewJsonModel mReviewData = new ReviewJsonModel();
if (appCursor != null && appCursor.getCount() > 0) {
appCursor.moveToFirst();
while (!appCursor.isAfterLast()) {
mReviewData = getDocument(appCursor);
appCursor.moveToNext();
}
appCursor.close();
}
return mReviewData;
}
#Override
protected void onPostExecute(ReviewJsonModel result) {
super.onPostExecute(result);
if (mDataLoadListener != null)
mDataLoadListener.onRatingDataLoaded(result);
}
}
Can't find cause of problem. Any help is appreciated.
Looks like there is callback issue, can you please try below
public void loadReviewData(RatingDataLoadListener listener, int destinationId) {
mDataLoadListener = listener;
new getReviews().execute(destinationId);
}
I am currently writing an Android app in Android Studio for the Microsoft band that will record data from the GSR, HR, and Skin Temp.
I have the data for GSR and Skin Temp. currently reading on the application but the rate that it is updated is very slow, especially for the Skin Temp. I was wondering if there was a way to make these sensors send data more frequently because the data I have now has too long of intervals for the purpose I am using it for. Here is my MainPage.java file.
public class MainPage extends Activity {
private BandClient client = null;
TextView tvGSR;
TextView tvHeartRate;
TextView tvTemperature;
Button updateTest;
private BandGsrEventListener mGsrEventListener = new BandGsrEventListener() {
#Override
public void onBandGsrChanged(final BandGsrEvent event) {
if (event != null) {
appendGSRToUI(String.format("%d kΩ\n", event.getResistance()));
}
}
};
private BandSkinTemperatureEventListener tempEventListener = new BandSkinTemperatureEventListener() {
#Override
public void onBandSkinTemperatureChanged(final BandSkinTemperatureEvent event) {
if (event != null) {
appendTempToUI(String.format("%.2f ºF\n", event.getTemperature()*1.800 + 32.00));
}
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
tvGSR = (TextView) findViewById(R.id.tvGSR);
tvTemperature = (TextView) findViewById(R.id.tvTemperature);
updateTest = (Button) findViewById(R.id.updateTest);
updateTest.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
tvGSR.setText("");
tvTemperature.setText("");
new GsrSubscriptionTask().execute(); // Put first (runs connection)
new TempSubscriptionTask().execute();
}
});
}
#Override
protected void onResume() {
super.onResume();
tvGSR.setText("");
tvTemperature.setText("");
}
#Override
protected void onPause() {
super.onPause();
if (client != null) {
try {
client.getSensorManager().unregisterGsrEventListener(mGsrEventListener);
client.getSensorManager().unregisterSkinTemperatureEventListener(tempEventListener);
} catch (BandIOException e) {
appendGSRToUI(e.getMessage());
appendTempToUI(e.getMessage());
}
}
}
#Override
protected void onDestroy() {
if (client != null) {
try {
client.disconnect().await();
} catch (InterruptedException e) {
// Do nothing as this is happening during destroy
} catch (BandException e) {
// Do nothing as this is happening during destroy
}
}
super.onDestroy();
}
private class GsrSubscriptionTask extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
try {
if (getConnectedBandClient()) {
int hardwareVersion = Integer.parseInt(client.getHardwareVersion().await());
if (hardwareVersion >= 20) {
appendGSRToUI("Band is connected.\n");
client.getSensorManager().registerGsrEventListener(mGsrEventListener);
} else {
appendGSRToUI("The Gsr sensor is not supported with your Band version. Microsoft Band 2 is required.\n");
}
} else {
appendGSRToUI("Band isn't connected. Check Bluetooth.\n");
}
} catch (BandException e) {
String exceptionMessage="";
switch (e.getErrorType()) {
case UNSUPPORTED_SDK_VERSION_ERROR:
exceptionMessage = "SDK Version Outdated.\n";
break;
case SERVICE_ERROR:
exceptionMessage = "GSR Not Supported\n";
break;
default:
exceptionMessage = "Unknown error occured: " + e.getMessage() + "\n";
break;
}
appendGSRToUI(exceptionMessage);
} catch (Exception e) {
appendGSRToUI(e.getMessage());
}
return null;
}
}
private class TempSubscriptionTask extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
try {
if (true) {
int hardwareVersion = Integer.parseInt(client.getHardwareVersion().await());
if (hardwareVersion >= 20) {
appendTempToUI("Band is connected.\n");
client.getSensorManager().registerSkinTemperatureEventListener(tempEventListener);
} else {
appendTempToUI("Temperature Not Supported.\n");
}
} else {
appendTempToUI("Band isn't connected. Check Bluetooth\n");
}
} catch (BandException e) {
String exceptionMessage="";
switch (e.getErrorType()) {
case UNSUPPORTED_SDK_VERSION_ERROR:
exceptionMessage = "SDK Version Outdated\n";
break;
case SERVICE_ERROR:
exceptionMessage = "Microsoft Health App Error\n";
break;
default:
exceptionMessage = "Unknown error occured: " + e.getMessage() + "\n";
break;
}
appendTempToUI(exceptionMessage);
} catch (Exception e) {
appendTempToUI(e.getMessage());
}
return null;
}
}
private void appendGSRToUI(final String string) {
this.runOnUiThread(new Runnable() {
#Override
public void run() {
tvGSR.setText(string);
}
});
}
private void appendTempToUI(final String string) {
this.runOnUiThread(new Runnable() {
#Override
public void run() {
tvTemperature.setText(string);
}
});
}
private boolean getConnectedBandClient() throws InterruptedException, BandException {
if (client == null) {
BandInfo[] devices = BandClientManager.getInstance().getPairedBands();
if (devices.length == 0) {
appendGSRToUI("Band isn't paired with your phone.\n");
return false;
}
client = BandClientManager.getInstance().create(getBaseContext(), devices[0]);
} else if (ConnectionState.CONNECTED == client.getConnectionState()) {
return true;
}
appendGSRToUI("Band is connecting...\n");
return ConnectionState.CONNECTED == client.connect().await();
}
}
There is currently no way to get data at a faster rate than provided by the Microsoft Band SDK.
Also, depending on what you want the data for, the skin temperature data might not be useful for you. Looking at the sensors you want to subscribe to, it looks like your application might be health related. But the skin temperature data contains the raw values from one of several thermometers inside of the band. And the band itself will generate some heat internally, so the data is unlikely to represent the skin temperature of the wearer exactly.
I have strange issue, I am creating mediaprovider for chromecast using following code that works fine for first instance, list of devices is shown and once slected I use router.selectRoute(routeinfo);
but once I exit app this code unable to find Chromecast device, how ever when I remove app from running apps stack this code works fine again and show devices.
If no device is selected and app is exited using back press then also this code works fine
So what I am doing wrong here? what I think is resources are not cleared when my app exit in simple back pressed.
public class ChromecastRouteProviderService extends MediaRouteProviderService {
final String LOGTAG = "Chromecast";
private static final String CONTROL_CATEGORY = CastMediaControlIntent.categoryForCast(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID);
private static final MediaRouteSelector SELECTOR = new MediaRouteSelector.Builder().addControlCategory(CONTROL_CATEGORY)
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK).build();
private IntentFilter controlFilter;
public ChromecastRouteProviderService() {
controlFilter = new IntentFilter();
}
public void onCreate() {
super.onCreate();
controlFilter.addCategory(IAppConstants.CATEGORY);
controlFilter.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
}
#Override
public MediaRouteProvider onCreateMediaRouteProvider() {
return new ChromecastRouteProvider(this);
}
class ChromecastRouteProvider extends MediaRouteProvider {
MediaRouter.Callback callback;
Hashtable routes;
public ChromecastRouteProvider(Context context) {
super(context);
routes = new Hashtable();
callback = new CastCallBack();
}
#Nullable
#Override
public RouteController onCreateRouteController(String routeId) {
MediaRouter.RouteInfo routeInfo = (MediaRouter.RouteInfo) routes.get(routeId);
if (routeInfo == null) {
return super.onCreateRouteController(routeId);
} else {
return new ChromecastRouteController(getContext(), routeInfo);
}
}
#Override
public void onDiscoveryRequestChanged(#Nullable MediaRouteDiscoveryRequest request) {
super.onDiscoveryRequestChanged(request);
if (request == null || !request.isActiveScan() || !request.isValid()) {
stopScan();
return;
}
if (!request.getSelector().hasControlCategory(IAppConstants.CATEGORY)) {
Log.i(LOGTAG, "Not scanning for non remote playback");
stopScan();
return;
} else {
Log.i(LOGTAG, "Scanning...");
mediarouter.addCallback(ChromecastRouteProviderService.SELECTOR, callback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
return;
}
}
void updateDescriptor() {
final MediaRouteProviderDescriptor.Builder descriptor = new MediaRouteProviderDescriptor.Builder();
for (Iterator iterator = routes.values().iterator(); iterator.hasNext(); ) {
MediaRouter.RouteInfo routeinfo = (MediaRouter.RouteInfo) iterator.next();
try {
Bundle bundle = new Bundle();
bundle.putBoolean("has_upsell", true);
descriptor.addRoute(new MediaRouteDescriptor.Builder(routeinfo.getId(), routeinfo.getName())
.addControlFilter(controlFilter).setPlaybackStream(3)
.setDescription(routeinfo.getDescription())
.setEnabled(true).setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
.setVolumeHandling(1).setVolumeMax(100).setVolume(100)
.setExtras(bundle).build());
} catch (Exception e) {
throw new Error("wtf");
}
}
getHandler().post(new Runnable() {
#Override
public void run() {
setDescriptor(descriptor.build());
}
});
}
void stopScan() {
Log.i(LOGTAG, "Stopping scan...");
try {
MediaRouter.getInstance(getContext()).removeCallback(callback);
return;
} catch (Exception exception) {
return;
}
}
class CastCallBack extends MediaRouter.Callback {
void check(MediaRouter mediarouter, MediaRouter.RouteInfo routeinfo) {
Log.i(LOGTAG, new StringBuilder().append("Checking route ").append
(routeinfo.getName()).toString());
CastDevice device = CastDevice.getFromBundle(routeinfo.getExtras());
if (routeinfo.matchesSelector(ChromecastRouteProviderService.SELECTOR)
&& device != null && device.isOnLocalNetwork()) {
routes.put(routeinfo.getId(), routeinfo);
updateDescriptor();
return;
} else {
return;
}
}
public void onRouteAdded(MediaRouter mediarouter, MediaRouter.RouteInfo routeinfo) {
super.onRouteAdded(mediarouter, routeinfo);
check(mediarouter, routeinfo);
}
public void onRouteChanged(MediaRouter mediarouter, MediaRouter.RouteInfo routeinfo) {
super.onRouteChanged(mediarouter, routeinfo);
check(mediarouter, routeinfo);
}
public void onRouteRemoved(MediaRouter mediarouter, MediaRouter.RouteInfo routeinfo) {
super.onRouteRemoved(mediarouter, routeinfo);
if (routeinfo.matchesSelector(ChromecastRouteProviderService.SELECTOR)) ;
}
}
}
}
Ok finally I found answer on my own,
Problem is when any provider is selected it's not added using onRouteAdded why? I really dont understand google logic
So the solution is to unselect the router when you want or better select default route when so that your route is released
MediaRouter.getInstance(this).getDefaultRoute().select();
But again 1 out of 10 times it will not work
Hope will help someone