Android OpenCV views other that CameraBridgeViewBase - android

Many of the examples available online show how to acquire and process an image from camera using CameraBridgeViewBase.
I would like to create a simple app that only one ImageView and several menu options for formatting that ImageView such as grayscale, sepia, etc.
The problem I have is how to enable OpenCV functionality on menu item click without using CameraBridgeViewBase.
Right now the following code is used to enable camera:
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
#Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
mOpenCvCameraView.enableView();
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
Question: is there something similar to mOpenCvCameraView.enableView(); that just uses image from the ImageView?

I was able to achieve the required functionality by setting background on OpenCvCameraView.

Related

How to open a dialog from Quick settings Tile?

I am developing an app for Quick settings Tile. I want to open a layout or a custom dialog when user click on the tile, whichever is a good option. Assume this as a custom dialog. I tried many examples, but I got no luck!
Thank you in advance.
You just have to #Override method of Tile service.
#Override
public void onClick() {
super.onClick();
Tile tile = getQsTile();
switch (tile.getState()) {
case Tile.STATE_INACTIVE:
// write code for start service or open activity according to your prefrrance
StaticUtils.closeNotificationTopPanel(this);
tile.setLabel(getString(R.string.service_running));
updateTileState(Tile.STATE_ACTIVE);
break;
case Tile.STATE_ACTIVE:
updateTileState(Tile.STATE_INACTIVE);
break;
default:
updateTileState(Tile.STATE_INACTIVE);
break;
}
}
when you Click of tile service button you have to close the notification panel below code will help for that.
public static void closeNotificationTopPanel(Context context) {
Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
context.sendBroadcast(closeIntent);
}
below method will help you to change the tile state and name of a button according to state.
private void updateTileState(int state) {
Tile tile = getQsTile();
if (tile != null) {
tile.setState(state);
Icon icon = tile.getIcon();
switch (state) {
case Tile.STATE_ACTIVE:
icon.setTint(Color.WHITE);
break;
case Tile.STATE_INACTIVE:
case Tile.STATE_UNAVAILABLE:
default:
icon.setTint(Color.GRAY);
break;
}
tile.updateTile();
}
}
Try to use this link: http://wintechtutorials.com/blog/android-customize-quick-setting-tiles-7-0-nougat/
Here in this link they use default Alert dialog. Try to create custom dialog as per need. Hope this will work for you.

Multiple Smart Lock dialogs on orientation change

I recently integrated Google's Smart Lock for Passwords feature into my app and almost everything is running smoothly as expected.
There is just one small issue I was not able to fix yet: In ResultCallback#onResult, if status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED the following command leads to the presentation of a Google resolution dialog that is asking whether to save the credentials via Smart Lock (see attached image) or which credentials to use, if there are already multiple credentials saved in Smart Lock:
status.startResolutionForResult(getActivity(), REQUEST_CODE_READ);
When the resolution dialog is presented, and the user does some orientation changes, then the resolution dialog multiplies, each of them overlapping the others. As a user, you first don’t see that there are multiple copies of the dialog, but if you close the first (by tapping on „Never“ or „Save Password“) then the uppermost dialog disappears, revealing another identical dialog below.
You can handle this by maintaining some state between the activity starting and stopping.
See use of the mIsResolving variable in this sample code. Simply save whether there is a pending dialog already when onSaveInstanceState() is called and restore in onCreate(), and guard against calling the API again if so, clearing the state once onActivityResult() is received for the intent.
private void resolveResult(Status status, int requestCode) {
// We don't want to fire multiple resolutions at once since that can result
// in stacked dialogs after rotation or another similar event.
if (mIsResolving) {
Log.w(TAG, "resolveResult: already resolving.");
return;
}
if (status.hasResolution()) {
try {
status.startResolutionForResult(MainActivity.this, requestCode);
mIsResolving = true;
...
#Override
protected void onCreate(Bundle savedInstanceState) {
...
if (savedInstanceState != null) {
mIsResolving = savedInstanceState.getBoolean(KEY_IS_RESOLVING);
}
...
#Override
protected void onSaveInstanceState(Bundle outState) {
...
outState.putBoolean(KEY_IS_RESOLVING, mIsResolving);
...
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
...
mIsResolving = false;
...
This is a common pitfall for many apps, so we'll look into whether we can support this state in Play Services layer, but for now, using the boolean for the activity is the current and general recommendation for maintaining resolution state.
I know, that it's an old question, but recently i have to fight with this issue, in my case I was using status.startResolutionForResult() in custom class and i didn't have any access to onSaveInstanceState() (I could make some custom callback with interface, but i didn't want to), but in my custom class i had an instance of an activity, so always before calling startResolutionForResult() I'm checking mActivity.hasWindowFocus() to see if activity lose focus, becouse of dialog that show, if it's true, then I call startResolutionForResult(), otherwise i do nothing
#Override
public void onResult(#NonNull LocationSettingsResult result) {
final Status status = result.getStatus();
switch (status.getStatusCode()){
case LocationSettingsStatusCodes.SUCCESS:
getLocation();
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
if (mActivity.hasWindowFocus()) {
try {
status.startResolutionForResult(mActivity, SETTINGS_CHECK);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
mReceiver.unableToObtainLocation();
break;
}
}

Unity3D iBeacon Android Application has stopped

I have just started using Unity3D and my school project consists of using iBeacons and detecting them with my mobile device. I'm doing a 2D project and in my scene, I have an empty game object that contains code handling the detection of the iBeacon:
public class iBeaconReceiverExample : MonoBehaviour
{
private Vector2 scrolldistance;
private List<Beacon> mybeacons = new List<Beacon>();
private bool scanning = true;
private bool guion = false;
public GameObject Nipper;
// Use this for initialization
void Start()
{
iBeaconReceiver.BeaconRangeChangedEvent += OnBeaconRangeChanged;
iBeaconReceiver.BluetoothStateChangedEvent += OnBluetoothStateChanged;
iBeaconReceiver.CheckBluetoothLEStatus();
Debug.Log("Listening for beacons");
}
void OnDestroy()
{
iBeaconReceiver.BeaconRangeChangedEvent -= OnBeaconRangeChanged;
iBeaconReceiver.BluetoothStateChangedEvent -= OnBluetoothStateChanged;
}
// Update is called once per frame
void Update()
{
foreach (Beacon b in mybeacons)
{
if (0.00 < b.accuracy && b.accuracy < 2.00)
{
CreateNipper();
}
}
}
public void CreateNipper()
{
GameObject nipper = Instantiate(Nipper, new Vector3(1, 1, -7), Quaternion.identity) as GameObject;
nipper.transform.SetParent(transform);
}
private void OnBluetoothStateChanged(BluetoothLowEnergyState newstate)
{
switch (newstate)
{
case BluetoothLowEnergyState.POWERED_ON:
iBeaconReceiver.Init();
Debug.Log("It is on, go searching");
break;
case BluetoothLowEnergyState.POWERED_OFF:
//iBeaconReceiver.EnableBluetooth();
Debug.Log("It is off, switch it on");
break;
case BluetoothLowEnergyState.UNAUTHORIZED:
Debug.Log("User doesn't want this app to use Bluetooth, too bad");
break;
case BluetoothLowEnergyState.UNSUPPORTED:
Debug.Log("This device doesn't support Bluetooth Low Energy, we should inform the user");
break;
case BluetoothLowEnergyState.UNKNOWN:
case BluetoothLowEnergyState.RESETTING:
default:
Debug.Log("Nothing to do at the moment");
break;
}
}
private void OnBeaconRangeChanged(List<Beacon> beacons)
{
//
foreach (Beacon b in beacons)
{
if (mybeacons.Contains(b))
{
mybeacons[mybeacons.IndexOf(b)] = b;
}
else
{
// this beacon was not in the list before
// this would be the place where the BeaconArrivedEvent would have been spawned in the the earlier versions
mybeacons.Add(b);
}
}
foreach (Beacon b in mybeacons)
{
if (b.lastSeen.AddSeconds(10) < DateTime.Now)
{
// we delete the beacon if it was last seen more than 10 seconds ago
// this would be the place where the BeaconOutOfRangeEvent would have been spawned in the earlier versions
mybeacons.Remove(b);
}
}
}
The "Init()" method starts the iBeacon plugin and starts searching for an iBeacon around my mobile device. My only concern here is that I have two scenes and once I go to another scene (a random scene) and go back to the original scene (the one containing the iBeaconReceiverExample script), my application crashes "Unfortunately, (Game Name) has stopped."
I have used adb Logcat to track the log of my device but it hasn't helped me at all. I have tried making two whole new scenes (thinking that maybe my scene was going crazy) but nothing worked. When I don't attach this script to my game object, my application doesn't crash so clearly the problem has to be somewhere here.
Have someone played with iBeacons on Unity and encountered this problem? What is the solution to this problem?
Thank you in advance! :)

What is ERROR_INTERNAL

I want to mount .obb file from external storage. I wrote these codes.
storageManager.mountObb(obbPath, key, new OnObbStateChangeListener() {
#Override
public void onObbStateChange(String path, int state) {
switch (state) {
case ERROR_ALREADY_MOUNTED:
storageManager.unmountObb(rawPath, true, this);
break;
case UNMOUNTED:
storageManager.mountObb(rawPath, key, this);
break;
case MOUNTED:
File mountedDir = new File(storageManager.getMountedObbPath(path));
// do something with mountedDir
break;
case ERROR_COULD_NOT_MOUNT:
case ERROR_INTERNAL:
case ERROR_PERMISSION_DENIED:
// Error occurred!!
break;
}
}
});
Now I execute this, my OnObbStateChangeListener gets state = ERROR_INTERNAL (20).
What is this error code? How to fix this?
Addition: I found this post: What causes jobb tool to throw FAT Full IOException?
Probably this is an answer. My obb file is broken.
thank you.
It looks like this constant is set in the MountService class (package com.android.server). You can take a look at the source code here : http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/com/android/server/MountService.java but as you can see, there are various reasons for setting the state at ERROR_INTERNAL

ZXing barcode for ANDROID app

I've code an app to scan barcodes. I've tried to use ZXing and all works fine, but I would use directly camera without external App (like Anobii), there is any way to do this whit ZXing?
CaptureActivity has the method:
public void handleDecode(Result rawResult, Bitmap barcode)
This method decides if will call to an external or internal app, you should comment the following code into switch(source){...} to avoid exit to external apps.:
case NATIVE_APP_INTENT:
case PRODUCT_SEARCH_LINK:
handleDecodeExternally(rawResult, resultHandler, barcode);
break;
case ZXING_LINK:
if (returnUrlTemplate == null) {
handleDecodeInternally(rawResult, resultHandler, barcode);
} else {
handleDecodeExternally(rawResult, resultHandler, barcode);
}
break;
In the next method you can call to your activity, you should comment all and add the next code:
private void handleDecodeInternally(Result rawResult,
ResultHandler resultHandler, Bitmap barcode) {
String resultString = resultHandler.getDisplayContents().toString();
if (resultString.startsWith("some"))//define a regular expression in the qr code{
//do something as call a new activity
}else{
//show error message
}
}
Expanding Flavio's answer you need to look at com.google.zxing.client.android.camera package which contains classes for working with android camera

Categories

Resources