Create moving background in live wallpaper using rajawali - background

I'm creating a live wallpaper using rajawali. I load an object on it (with this code: Rajawali object rotation match to camera) and now I want to set moving image in background for it. Has anyone advice for me?

I created Plane:
mPlane1 = new Plane();
Material material1 = new Material();
try {
material1.addTexture(new Texture("cloud2", R.drawable.cloud2));
} catch (TextureException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
material1.setColorInfluence(0);
mPlane1.setMaterial(material1);
mPlane1.setRotY(180);
mPlane1.setTransparent(true);
mPlane1.setPosition(Vector3.X);
mPlane1.setPosition(-1.6f, 1.2, 1.6);
getCurrentScene().addChild(mPlane1);
and translate it with TranslateAnimation3D:
plane1Anim = new TranslateAnimation3D(Vector3.X);
plane1Anim.setRepeatMode(RepeatMode.INFINITE);
plane1Anim.setTransformable3D(mPlane1);
plane1Anim.setDuration(16000);
getCurrentScene().registerAnimation(plane1Anim);
plane1Anim.play();

Related

How to share a recyclerview background image and text as one

I created a recyclerview for the purpose of sharing messages. Each item in the recyclerView has a different image(.png) background set as flower background with text set on it with TextView. It shows well. But whenever I clicked shareImage icon only image is shared.
Screenshot from recyclerview. This is how I want it to be
This is what I've got to share, the image and text are separated!
What I want to achieve?
I want to automatically crop and share but background image and text I set on it as a card.
This is what I did that didn't work
myHolder.mShareImage.setOnClickListener(v -> {
Drawable drawable= myHolder.mImageView.getDrawable();
Bitmap bitmap=((BitmapDrawable)drawable).getBitmap();
try {
File file = new File(mContext.getApplicationContext().getExternalCacheDir(), File.separator +models.get(i).getTitle()+models.get(i).getIcon()+".png");
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
file.setReadable(true, false);
final Intent shareImagerIntent = new Intent(android.content.Intent.ACTION_SEND);
shareImagerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri photoURI = FileProvider.getUriForFile(mContext.getApplicationContext(), BuildConfig.APPLICATION_ID +".provider", file);
shareImagerIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
shareImagerIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareImagerIntent.setType("*/*");
shareImagerIntent.putExtra(Intent.EXTRA_TEXT, models.get(i).getTitle());
mContext.startActivity(Intent.createChooser(shareImagerIntent, "Share image via"));
} catch (Exception e) {
e.printStackTrace();
}
});

How to create a camera view + a button to capture the photo in Xamarin.Forms?

I am trying to find a solution for an android app which I can have both camera preview and a button created with Xamarin Forms (XAML) that when I click that button photo should automatically save in device gallery. After 2 days of research the only best solution I found is this. Can someone please help me achieve this?
Refer to official sample , it implements creating camera preview , i just add the function of take picture and save into gallery .Call messaging center in forms project and get camera instance in android project ,
Call back of Picture Taken
public void OnPictureTaken(byte[] data, Camera camera)
{
camera.StopPreview();
FileOutputStream outStream = null;
Java.IO.File dataDir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim);
if (data != null)
{
try
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
var s = ts.TotalMilliseconds;
outStream = new FileOutputStream(dataDir + "/" + s + ".jpg");
outStream.Write(data);
outStream.Close();
}
catch (Java.IO.FileNotFoundException e)
{
System.Console.Out.WriteLine(e.Message);
}
catch (Java.IO.IOException ie)
{
System.Console.Out.WriteLine(ie.Message);
}
}
camera.StartPreview();
}
Check my sample on github.

How to animate SettingsFlyout on dismiss

In Windows 8.1, I'm using the new SettingsFlyout control. The flyout animates in correctly and will animate out if you use the control's built-in back button to return to the Settings Charm flyout. But if you light dismiss by clicking outside the flyout, it disappears without a transition animation.
How do you animate a transition out when you light dismiss the SettingsFlyout? (I don't want to return to the Settings Charm flyout, I just want it to slide out on a light dismiss.)
Matt, what you want to do should be easily achievable but is currently not supported by the XAML SettingsFlyout API out of the box. As Jerry points out, there are transitions that allow an animate out effect (in XAML you want EdgeUIThemeTransition). Unfortunately, there is no API support on SettingsFlyout to add this transition, but you can get it to work using your own private popup to host the SettingsFlyout (more on this below):
public sealed partial class SettingsFlyout1 : SettingsFlyout
{
Popup _p;
Border _b;
public SettingsFlyout1()
{
this.InitializeComponent();
BackClick += SettingsFlyout1_BackClick;
Unloaded += SettingsFlyout1_Unloaded;
Tapped += SettingsFlyout1_Tapped;
}
void SettingsFlyout1_BackClick(object sender, BackClickEventArgs e)
{
_b.Child = null;
SettingsPane.Show();
}
void SettingsFlyout1_Unloaded(object sender, RoutedEventArgs e)
{
if (_p != null)
{
_p.IsOpen = false;
}
}
void SettingsFlyout1_Tapped(object sender, TappedRoutedEventArgs e)
{
e.Handled = true;
}
public void ShowCustom()
{
_p = new Popup();
_b = new Border();
_b.ChildTransitions = new TransitionCollection();
// TODO: if you support right-to-left builds, make sure to test all combinations of RTL operating
// system build (charms on left) and RTL flow direction for XAML app. EdgeTransitionLocation.Left
// may need to be used for RTL (and HorizontalAlignment.Left on the SettingsFlyout below).
_b.ChildTransitions.Add(new EdgeUIThemeTransition() { Edge = EdgeTransitionLocation.Right });
_b.Background = new SolidColorBrush(Colors.Transparent);
_b.Width = Window.Current.Bounds.Width;
_b.Height = Window.Current.Bounds.Height;
_b.Tapped += b_Tapped;
this.HorizontalAlignment = HorizontalAlignment.Right;
_b.Child = this;
_p.Child = _b;
_p.IsOpen = true;
}
void b_Tapped(object sender, TappedRoutedEventArgs e)
{
Border b = (Border)sender;
b.Child = null;
}
}
Full solution for this sample: https://github.com/finnigantime/Samples/tree/master/examples/Win8Xaml/SettingsFlyout_AnimateOut
I think SettingsFlyout should have API support for your scenario, so I filed a work item on the XAML team. In the future, such requests/issues can be raised on the MSDN forum as well (moderated by MSFT folks). The limitation here is that SettingsFlyout is implemented on top of Popup with IsLightDismissEnabled="True", and the light-dismiss event currently closes the Popup immediately without allowing unloading child transitions to run. I think this can be overcome and transitions can be supported at the SettingsFlyout API level to enable your scenario.
You need to use the HideEdgeUI animation
Read this: http://msdn.microsoft.com/en-us/library/windows/apps/jj655412.aspx

Using front camera on wp8 code

I was using this Microsoft sample http://code.msdn.microsoft.com/wpapps/Basic-Camera-Sample-52dae359#content because I needed to implement camera functionality in my application. Ans this is working fine until I try to switch to front camera then the app just closes and I get this
The program '[3032] TaskHost.exe' has exited with code -532265403 (0xe0464645)
I was going through the code and I found out that this part of code causes the problem
public FlashState FlashState
{
get { return (FlashState) (uint) PhotoCaptureDevice.GetProperty(KnownCameraPhotoProperties.FlashMode); }
set
{
try
{
PhotoCaptureDevice.SetProperty(KnownCameraPhotoProperties.FlashMode, value);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
}
It doesn't hit catch, just closes the app. The same thing is happening if I set Front Camera as a default one. Did anyone had this problem?
[SOLUTION]
Ok, after trying everything - event posting here, now I have a solution. In the try block above I added this line
if (CameraSensorLocation == CameraSensorLocation.Front)
return;
so now it doesn't crush, and the front camera is working fine. They should change this in official sample.
Ok, after trying everything - even posting here, now I have a solution. In the try block above I added this line
if (CameraSensorLocation == CameraSensorLocation.Front) return;
so now it doesn't crush, and the front camera is working fine.

Android ViewPager and Camera Preview issue on Gingerbread

I did extensive documentation study on ViewPagers and on Camera apps, infact everything works quite fine, except for a major issue on GingerBread, which I haven't found any question about on S.O. so I'll try asking this one...
In my application there is a ViewPager (support library v4) which shows two fragments:
One, will call it the main fragment, the one showing when the activity starts, certain information are shown to the user, including an imageview, which is initially empty and hidden.
By swyping to the next fragment, the user sees the camera preview, which gets created when the activity is created (even if it not showing until the swype) and the button to take a picture.
When the picture is taken, the view is programmatically taken back to the main fragment, the
imageview is loaded with the new photo and unhidden so the user can see the image mixed with the other preexisting information.
If the user does not like picture, he can swype back again to the camera fragment and take another one, and so all over until he is satisfied with the result.
For this reason, before flipping back to the main fragment, I call mCamera.restartPreview() and ensure the camera is ready should the user swype back.
Everything works smoothly and fine on Android 4.x, but when I test this on a 2.3.3 (API Level 10) the camera preview remains in foreground when the main fragment is called back, and hides the view. You can see, and even scroll, the remainder of the view, in the portion of teh screen where the camerafragment shows the buttons, but the rest is overlapped by the camera preview.
Here is the code of the relevant functions:
CameraFragment onPictureTaken()
private PictureCallback mPicture = new PictureCallback() {
#Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null){
Log.d(TAG, "Error creating media file, check storage permissions: ");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
Log.e(TAG, "FILE " +pictureFile.getAbsoluteFile().toString());
Bitmap bitmap = rotated(data);
bitmap.compress(CompressFormat.JPEG, PICTURE_QUALITY, fos);
bitmap.recycle(); //devo davvero chiamarla esplicitamente ??
mediaFile = pictureFile;
mPreview.restartPreview();
// go back to newpin activity to show it
((NewPinActivity) myActivity).newPin.setMedia(mediaFile.getAbsoluteFile().toString());
((NewPinActivity) myActivity).takeBack();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
}
}
};
and the mainfragment takeBack() method
public void takeBack(){
mViewPager.setCurrentItem(0, true);
String mainFragTag = "android:switcher:"+R.id.newpinpager+":0";
Fragment fragMain = this.getSupportFragmentManager().findFragmentByTag(mainFragTag);
try {
((NewPinMainFragment)fragMain).showPhoto(newPin.getMedia());
} catch (NullPointerException e){
}
}
Does anybody have a clue if this is an issue with the ViewPager and GingerBread or with the CameraPreview and Gingerbread or what ?
I found the answer by myself, I'll post it here in case it's going to be useful to others.
Apparently the problem was cause by the smoothscroll option of setCurrentItem method.
The issue was fixed by changing
mViewPager.setCurrentItem(0, true);
to
mViewPager.setCurrentItem(0, false);