Google Plus Profile Picture Google Play Game Services - eclipse

I've already seen all post in this forum but i haven't found anything.
How can i show in an ImageView the Profile picture of google plus of person who log in my app? with ImageManager?
can you show some code please?

The method below does what you want.
public class AvatarImage extends ImageView {
Bitmap image;
public static final String TAG = "AvatarImage";
public AvatarImage(Context context) {
super(context);
setImageResource(R.drawable.avatar);
}
/**
* This method takes the participant object and attempts to
* download avatar of the participant from google plus
* if this is unsuccesful default avatar is shown
* #param p
*/
public void setImageFromParticipant(Participant p) {
ImageManager im = ImageManager.create(getContext());
im.loadImage(this, p.getIconImageUri(), R.drawable.avatar);
try{
Bitmap bitmap = ((BitmapDrawable)this.getDrawable()).getBitmap();
setImageBitmap(bitmap);
}
catch(NullPointerException e)
{
e.printStackTrace();
}
}
}

The code as shown for the other answer from John is correct, however, there is currently an issue with Google Play Service Library as shown here Google Issue Tracker for anyone using ver 10 of the library (and perhaps ver 9.. version 8 is good). Unfortunately for this issue, if you even attempt to get the URI decoded by ImageManager, Google Play Services quits working. Either wait for next ver of the library, or try to get ahold of ver 8.
(I couldn't put this in as a comment on the answer above, so had to go with a new answer...)

Related

How to get the path and file size of some Unity built-in assets?

Background
I am developing a Unity editor plugin that enables users to send a selected image file to a REST API endpoint in the cloud for processing (e.g. adding transforms and optimizations). The plugin also shows a comparison of the selected image's details before and after processing (e.g. width/height/size before vs after).
The user selects the desired image through the following piece of code:
selected_texture = (Texture2D) EditorGUI.ObjectField(drawing_rect, selected_texture, typeof(Texture2D), false);
Once its selected, I can then get the respective file size by doing this:
file_size = new FileInfo(AssetDatabase.GetAssetPath(selected_texture)).Length;
Problem
This works for most textures selected, but I encounter an error when I choose a built-in Unity texture. Any guidance would be greatly appreciated.
FileNotFoundException: Could not find file 'Resources/unity_builtin_extra'
There are two built-in asset-librarys in Unity:
BuiltIn-Library in "Resources/unity_builtin_extra": contains UGUI sprite、Default-Material、Shader and so on.
BuiltIn-Library in "Library/unity default resources": contains built-in 3D mesh and OnGUI assets.
If you are using AssetDatabase.GetAssetPath, you will always get one or another path above.
To solve the problem, you need do something like below code:
public const string BuiltinResources = "Resources/unity_builtin_extra";
public const string BuiltinExtraResources = "Library/unity default resources";
public static bool IsBuiltInAsset(string assetPath)
{
return assetPath.Equals(BuiltinResources) || assetPath.Equals(BuiltinExtraResources);
}
public static long GetTextureFileLength(Texture texture)
{
string texturePath = AssetDatabase.GetAssetPath(texture);
if (IsBuiltInAsset(texturePath))
{
/*
* You can get all built-in assets by this way.
*
var allAssets = AssetDatabase.LoadAllAssetsAtPath(BuiltinResources);
var allExtraAssets = AssetDatabase.LoadAllAssetsAtPath(BuiltinExtraResources);
*/
// not supportted
// return -1;
// using MemorySize
return Profiler.GetRuntimeMemorySizeLong(texture);
}
else
{
return new FileInfo(texturePath).Length;
}
}

Click on Camera Shutter using UIAutomator

I am writing an Espresso test for my app, and am trying to automate clicking the shutter button after opening of a camera in my app.
I am using Espresso and UIAutomator in the Android Emulator. I managed to dump this UI in UIAutomatorViewer.
I can't figure out why I am unable to click on the shutter button using UIAutomator using this code:
public void clickCameraShutterButton() throws UiObjectNotFoundException
{
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiSelector shutterSelector = new UiSelector().resourceId("com.android.camera:id/shutter_button");
UiObject shutterButton = device.findObject(shutterSelector);
shutterButton.click();
}
The camera just sits there, and the shutter button is never clicked. This is the stack trace I'm getting in the Android Studio monitor:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference
Any advice would be appreciated.
You can try this code:
device.findObject(new UiSelector().resourceId("com.android.camera:id/shutter_button")).click();
or
device.findObject(new UiSelector().description("Shutter button")).click();
or
device.executeShellCommand("input keyevent 27");
this mean KEYCODE_CAMERA value is 27
or
device.click(x,y);
This worked for me
#Before
public void setUp() {
// Initialize UiDevice instance
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
mDevice = UiDevice.getInstance(instrumentation);
}
...
/**
* ##Test comment here##
*
* #throws Exception
*/
#Test
public void culebraGeneratedTest_CameraShutter() throws Exception {
mDevice.findObject(By.res("com.android.camera2:id/shutter_button").desc("Shutter").clazz("android.widget.ImageView").text(Pattern.compile("")).pkg("com.android.camera2")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
}
This test finds the shutter and clicks on it.
If you are interested this test was automatically generated using CulebraTester.
Just need to put the UI Automator Viewer "resource-id" value at the place of *
mdevice.findObject(new UiSelector().resourceId("*")).click();

Resetting after 3 seconds unity

I have a board manager in my game, that shows what is happening, for example, if I want to buy a car and you dont have the necessary money in this board appears a message saying "You dont have enough gold".
public void setTextMonitor (string mensaje) {
textScreen = mensaje;
}
public IEnumerator DoTheDance() {
yield return new WaitForSeconds(5); // Esperar 3 seconds
textScreen = "";
}
This is my code and it's working properly, when the board shows a message after 5 seconds it's deleted but the board doesn't shows new messages and I dont know why, probably because the couroutine doesn't let setTextMonitor method to work properly dunno.
If you have another idea or other method for doing this,
I'd be really grateful
For such behavior really easy to use LeanTween asset. It's free in asset store.
Code will be close to the following:
textScreen = "You have not enough of gold";
LeanTween.DelayedCall(5f,()=>{textScreen = "";});

Facebook Unity SDK FB.Feed causes NullReferenceException

I'm having a problem when using the Facebook Unity API, calling the FB.Feed() method. It winds up giving this error:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUILayoutUtility.DoGetRect (UnityEngine.GUIContent content,
UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at
C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayoutUtility.cs:264)
which is immediately followed by:
ArgumentException: Getting control 1's position in a group with only 1 controls
when doing Repaint
I know the second error is usually caused in Unity by GUI elements changing between GUI event calls, etc. In my case, however, I'm not doing anything within OnGUI at all. In fact, because of tearing my hair out trying to figure out what the problem is, I created a totally new project - 1 scene with basic buttons to login, and then "brag" using the FB.Feed. I've written it the exact way that their documents show, and I get the exact same error.
I'm hoping maybe someone might be able to shed some light on what I'm missing or doing wrong.
Here is complete code in my simple barebones scene that also causes this error:
void Start()
{
FB.Init(OnInitComplete, OnHideUnity);
}
void OnInitComplete()
{
Debug.Log("FB Initialized");
}
void OnHideUnity(bool isGameShown)
{
Debug.Log("OnHideUnity");
if (!isGameShown)
Time.timeScale = 0;
else
Time.timeScale = 1;
}
void Update()
{
}
void OnGUI()
{
if (!FB.IsLoggedIn)
{
if (GUI.Button(new Rect(10, 10, 100, 30), "Login"))
FBLogin();
}
else
{
if (GUI.Button(new Rect(10, 50, 100, 30), "Brag"))
{
Brag();
}
}
}
void Brag()
{
FB.Feed(
linkCaption: "This is testing the testapp FEED",
picture: "http://myapp.com/myapplogo.jpg",
linkName: "Foo Link",
link: "http://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")
);
}
void FBLogin()
{
FB.Login("email, publish_actions", OnLoggedIn);
}
void OnLoggedIn(FBResult result)
{
if (FB.IsLoggedIn)
Debug.Log("Logged in successfully");
}
My Facebook API is version 140220, and my Unity is 4.3.4
I'll do my best to answer any other questions for info I've missed
I've also tried using the FB API version 131022, and have the same results.
This error also happens with the FriendSmash example and as well with the InteractiveConsole example scene provided with the plugin.
I should also point out that the Window does open for the post, and loads the image, link, etc. The exception prevents anything else from working however
Additional Info: I've found that when the app is ran on an actual android device, the feed post works with no problem. It only appears to have this error within the Unity editor. I have another issue with test users logging in on the android device - they can't if the device has the Facebook app itself installed, but that issue probably warrants a separate question
I think it's just not getting all of the resources it's asking for. The docs say not to worry about it, the editor can only do so much. I get the one below. Unfortunately though, mine is not working on the device, but if yours is, I wouldn't worry about it too much.
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUILayoutUtility.DoGetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayoutUtility.cs:264)
UnityEngine.GUILayoutUtility.GetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUILayoutUtility.cs:257)
Facebook.FbSkinnedDialog.TwoButtonBar (System.String label, System.String cancelLabel)
Facebook.FeedDialog.UpdateDialog (Int32 windowID)
Facebook.FbSkinnedDialog.GeneralUpdateDialog (Int32 windowId)
UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUI.cs:1395)

How to get pictures metadatas on windows phone?

I choose a picture with a PhotoChooserTask and I would like to get metadatas (longitute, latitude, device, ect) from this picture. How can I do that ?
My code:
void photochoosertask_Completed(object sender, PhotoResult e)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(e.ChosenPhoto);
im.Source = bmp;
//get metadatas ?
}
If by chance you happen to be uploading the image to a service that has access to the full .NET Framework, you can also use the BitmapMetadata class - http://msdn.microsoft.com/en-us/library/ms619225.aspx.