I'm developing a watch face on Android.
In onCreate method when I set watch face style, I see that a bunch of methods are deprecated, but on Android official website they are not. What should I do to get rid of these deprecated methods, or leave them as they are?
#Override
public void onCreate(SurfaceHolder holder) {
super.onCreate(holder);
setWatchFaceStyle(new WatchFaceStyle.Builder(DigitalWatchFace.this)
.setCardPeekMode(WatchFaceStyle.PEEK_MODE_VARIABLE)
.setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE)
.setShowSystemUiTime(false)
.setAcceptsTapEvents(true)
.build());
// ...
}
Those methods are deprecated because of this changes in android wear 2.
The notifications will be shown for few seconds and then the watch face will be visible again. For this reason those methods don't have sense anymore.
Related
Image available listener picks up an image of the fragment and onimageavailble() is invoked continuously as soon as the image is available. An instance of the code is as below:
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(null);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_camera);
setFragment();
}
The setFragment() code is:
protected void setFragment() {
final Fragment fragment =
CameraConnectionFragment.newInstance(
new CameraConnectionFragment.ConnectionCallback() {
#Override
public void onPreviewSizeChosen(final Size size, final int rotation) {
CameraActivity.this.onPreviewSizeChosen(size, rotation);
}
},
this,
getLayoutId(),
getDesiredPreviewFrameSize());
getFragmentManager()
.beginTransaction()
.replace(R.id.container, fragment)
.commit();
}
The code runs correctly on Android and so I wanted it to implement on Android Things device but I was getting a warning stating 'A TextureView or a subclass can only be used with hardware acceleration enabled' and the onimageavailble() is never called. I made required changes in the code to resolve the warning but still, onimageavailble() is never called.
On debugging the code in raspberry Pi3 for android things, I noticed that camera stream is not being displayed in the fragment because of which image listener is unable to pick one.
please provide me with the solution for this problem
You are using WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED (with AndroidThings 0.3.0)
Hardware Acceleration for the R Pi was only introduced in AndroidThings 0.5.0
See the release notes here:
https://developer.android.com/things/preview/releases.html
With the update to Android O, OpenGL ES 2.0 is now supported. Platforms with a GPU (such as Raspberry Pi 3) also now support hardware acceleration.
Please update the version of AndroidThings you are using.
The demand is that saving a video frame in the video call. I have made a demo that take a screenshot through the GLSurfaceView's method "onDrawFrame". But when I use the webrtc, it have its own renderer "VideoRendererGUI" .And then when I want to override it, I find it can't be overrided. the main part code :
vsv = (GLSurfaceView) findViewById(R.id.glviewchild_call);
vsv.setPreserveEGLContextOnPause(true);
vsv.setKeepScreenOn(true);
VideoRendererGui.setView(vsv, new Runnable() {
#Override
public void run() {
init();
}
});
And If you have another way to take a screenshot, you can also share with me.
Thanks a lot!
If you use a SurfaceViewRenderer to display the stream, you can use the solution in this answer to capture a frame on the call.
Basically, using surfaceViewRenderer.AddFrameListener with a class that implements EGLRenderer.FrameListener
I will assume that the SurfaceViewRenderer of the peer you want to take a screenshot of is called remotePeerSurfaceViewRenderer, also I will asume that the button that you will use to take a screenshot is called btnScreenshot
So all what you need to do is as "Webo80" said in the answer above use the FrameListener, the issue is the FrameListener implementation of the webrtc takes only the first frame available once the Listener is attached to the SurfaceViewRenderer, so my approach to do that is by attaching the webrtc implementation of the FrameListsner at the second I need to take a screenshot and remove it once it is taken:
btnScreenshot.setOnClickListener((view)-> {
remotePeerSurfaceViewRenderer.addFrameListsner(new EglRenderer.FrameListener() {
#Override
public void onFrame(Bitmap bitmap) {
runOnUiThread(() -> {
/*
do what ever you want with the bitmap for example
imgView.setImageBitmap(bitmap);
*/
localVideoView.removeFrameListener(this);
});
}
}, 1);
})
Important note:
1. Please don't forget to runOnUiThread as Iam doing
2. Please don't forget to remove the listener inside the button onClick() method
I have tried this solution and it is working more than fine, if you want to make your custom solution you have to completely implement the interface "EglRenderer.FrameListener"
I am sorry to say due to unavailability of canvas and other facilities in Android It's not possible to capture screenshot programatically using WebRTC. One can dodge this situation by animating the app's UI and capturing the screenshot manually , store it at configured location and exchange it with other party.
I am trying to render a checkbox in a Xamarin Forms app. There is nothing rendered at runtime, as far as I can tell the renderer is not even getting called.
Does anyone understand what I am missing or doing incorrectly?
Here is my class in Forms:
public class LegalCheckbox : View
{
public LegalCheckbox ()
{
}
}
And my custom renderer class in Droid:
public class CheckBoxRenderer : ViewRenderer<LegalCheckbox, CheckBox>
{
protected override void OnElementChanged (ElementChangedEventArgs<LegalCheckbox> e)
{
base.OnElementChanged (e);
CheckBox control = new Android.Widget.CheckBox(this.Context);
control.Checked = false;
control.Text = "I agree to terms";
control.SetTextColor (Android.Graphics.Color.Rgb (60, 60, 60));
this.SetNativeControl(control);
}
}
Along with the Assembly Directive:
[assembly: ExportRenderer(typeof(demo.LegalCheckbox), typeof(demo.Droid.CheckBoxRenderer))]
Took your code and fired up a new project with it. The code appears to function fine.
Only thin I can think that might be causing you an issue is the location of you assembly attribute. I typically place them just above the namespace declaration in the same file as my renderer.
I threw what I created up on my github maybe you can spot the difference.
https://github.com/DavidStrickland0/Xamarin-Forms-Samples/tree/master/RendererDemo
#Thibault D.
Xlabs isn't a bad project but its basically just all the code the opensource community came up with during the first year or so of Xamarin.Forms life. Its not really "Their Labs projects" and considering how much of it is marked up with Alpha Beta and the number of bugs in their issues page it's probably best not to imply that the Xamarin company has anything to do with it.
I am not sure if that is the issue but it would make more sense to me if your LegalCheckbox would inherit from a InputView rather than View.
Also, even if Xamarin.Forms does not have a Checkbox control you can still have a look at their "Labs" project here:
https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Checkbox-Control
(And I can actually see that they inherit from View...)
i wrote an application that run on round and square watches, with two layouts and a watchViewStub.
Since the moto 360 is sold over Europe i have many reports that Moto 360 doesn't load the rounded layout. With emulator, i can't reproduce this behavior even if i change locale as explain here : https://developer.android.com/guide/topics/resources/localization.html#testing
So i guess it's my code ...
Here's is how i've implemented it :
<android.support.wearable.view.WatchViewStub
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/watch_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rectLayout="#layout/rect_activity_camera"
app:roundLayout="#layout/round_activity_camera">
Then in a fragment i inflate the WatchViewStub
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final WatchViewStub stub = (WatchViewStub) getView().findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
#Override
public void onLayoutInflated(WatchViewStub stub) {
...
}
}
The fragment is used in a FragmentViewPager/FragmentGridPagerAdapter.
Until i get a Moto 360, any ideas on how i can debug this ?
Edit
WatchViewStub sample in Wear Sdk has two different behavior depends on language settings so i fill this issue : https://code.google.com/p/android/issues/detail?id=77642
Important
This issue is discussed on different posts. to avoid repeating the updated information only the issue on google code will be updated, and i'll complete this posts once the issue will be solved :
https://code.google.com/p/android/issues/detail?id=77642
There are many problems with inflating layouts that are caused by not correctly using WatchViewStub. I don't see enough code above to know exactly, but one common issue is when you register a listener for watch insets:
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
#Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
// Need to also call the original insets since we have overridden the original
// https://developer.android.com/reference/android/view/View.OnApplyWindowInsetsListener.html
stub.onApplyWindowInsets(windowInsets);
return windowInsets;
}
});
I see cases where people forget to return the windowInsets, or forget to call stub.onApplyWindowInsets(). This has the effect of giving a square layout instead of a round layout.
Other issues are caused by forgetting to put the same XML elements into the round.xml as the square.xml.
What is the error message you are getting in adb logcat?
I have some information for you about this bug.
The problem is triggered by the watch switching languages when pairing with a phone after a factory reset. You can avoid the issue by selecting the same language on the wearable as you are using on the phone, so that no change occurs afterwards when the devices are paired.
Instructions to fix the problem:
Factory reset the Moto 360.
When the wearable restarts, it will ask what language you would like to use. Select the same language that you are using on the phone (do not select the default of English)
On the phone, start the Android Wear companion app, and select from the overflow menu the option "Pair with a new wearable".
Pair the phone with the Moto 360.
I am trying to implement the example shown on this page. I have tried on three different devices running android 4 and above, and in all cases I get a black screen with this warning:
01-27 20:01:22.683: W/TextureView(4728): A TextureView or a subclass can only be used with hardware acceleration enabled.
I have turned on hardware acceleration in the application manifest:
<application
android:hardwareAccelerated="true"
[etc...]
But the following check my custom view's onAttachedToWindow method always returns false
private class MyTextureView extends TextureView
{
public MyTextureView(Context context) {
super(context);
}
#Override
protected void onAttachedToWindow()
{
super.onAttachedToWindow();
Log.d("", Boolean.toString(mTextureView.isHardwareAccelerated()));
}
}
Does anyone know what is wrong here?
Thanks
If you testing with Emulator then please check configuration for hardware acceleration.
Please check this thread for more info:
http://developer.android.com/tools/devices/emulator.html#acceleration