In
e-Legion, we try to keep track of everything that happens in the development world, and constantly try out different solutions for our projects. For 8 years on the application development market, we took on a variety of projects for various platforms and tried to tell about the most interesting cases in Habré.
We have been working with Yandex for more than 3 years and during this time i have been imbued with services and the entire ecosystem of the main search of the country. Therefore, when the SDK for Yandex.Disk was introduced last October, we wondered what it could do, and we decided to develop a simple Photo Frame application for Android and Windows.

')
The idea of ​​the application is simple: you upload photos to Yandex.Disk, synchronize the application with your account and get a slide show. To share photos with friends and parents, you just need to configure the application on their devices and share the folder with photos on Yandex.Disk to their accounts. Photos will automatically appear in the "Photo Frame" on other devices. In general, it is easier
to try once.
Our goal was to make a simple and convenient application for easy sharing of new photos with friends and family, so the program interface was made as simple and clear as possible. At initial start-up, a wizard is shown where the user can select a directory for synchronization and change some default settings. After selecting a folder for synchronization, “Photo Frame” recursively scans the entire directory structure. Next, the files are filtered, and only image files are loaded into the cache on the user's device.
After the synchronization operation is completed, PhotoFrame periodically polls the server to view changes in the directory structure or files. When a change is detected, the synchronization mechanism is restarted. If the user does not have an Internet connection, the PhotoFrame works in offline mode - all functions except for synchronization with the server remain in operation. By the way, the Windows application has a nice bonus: the ability to customize the screensaver and the automatic change of desktop wallpaper. This is easily implemented by changing several parameters in the registry and calling the WinAPI function.
Windows
The Windows version of Photoframe was written in C # on the .NET Framework 4.0. The choice is not the latest version of the .NET Framework due to the support of Windows XP.

The client application is built on the basis of the Windows Presentation Foundation (WPF), using the MVVM design pattern. The “Photo Frames” installer is written using the Windows Installer Xml (WiX) toolkits.
Android
Android application works on versions starting from 2.3. While developing the PhotoFrame application, we decided to try implementing a “slideshow” for the screen, the so-called Immersive mode, which was introduced in Android 4.4 (for more information about it you can read here
habrahabr.ru/post/200874 ). But our goal was to make an application that would work skillfully not only with version 4.4. You could hide both the statusbar and the on-screen buttons on previous versions of Android 4.x (as it was implemented in the YouTube app 4.3). With active Immersive Mode on version 4.4, tapE causes TouchEvent on the screen, while in fullscreen mode on version 4.3, the first tap is exited, and only the second tap goes to the view that was clicked. Our task was to catch tap across the screen and show an additional layer on top of the image, and therefore it was necessary to catch this first tap.
To find out about the exit from full-screen mode on 4.3, you had to call getWindow (). GetDecorView () from the activation and from the resulting view, put the listener setOnSystemUiVisibilityChangeListener (...).

But this was not all that smooth. The onSystemUiVisibilityChange method was called only a full second after we tapped and exited full-screen mode. Thus, I had to abandon this idea completely and hide the on-screen buttons on devices with versions up to 4.4. As a result, on the fours we set the fullscreen and low_profile flags, and on the other devices with 2.3 or 3.x - just fullscreen.
Yandex.Disk SDK
The Windows SDK is written in C # under .NET 4.0 and represents several Visual Studio projects. Among these projects there are examples of implementing your own application for each of the platforms. SDK without changes is connected to the development on Windows Phone 7.5 and higher, Windows Store and Silverlight 4 and higher applications. Looking at the example of a project under Windows, it was not difficult for us to build the entire logic of the Photoframe with Yandex.Disk.
User authentication is performed via OAuth protocol or using Basic authentication to choose from. To synchronize with the server, we used GetListAsync and DownloadFileAsync. It is seen that all methods are asynchronous, and this is undoubtedly a plus.
While working with the Windows SDK, we discovered a small error. If there is a file larger than two gigabytes on Yandex.Disk, then the GetListAsync method will not be able to return a list of files from this directory. The source code of the SDK quickly managed to detect the problem: the maximum permissible value for Int32 was exceeded. As a result, the decision took no more than five minutes.

Under the Android SDK is a plug-in library. All its features are discussed in detail in the sample application, which is distributed with the SDK in the GitHub repository. It also shows the most optimal way of how to implement authorization in an application: first, an existing Yandex account is searched for the device, which the user logged in through any of the official Yandex applications, and if there is one, then the input occurs through it. If not, then you should send the user to the browser to the login page of the account.
First you need to create an OAuth application on the
appropriate page . In the same place, fill in the "Callback URI" field with some url, the return to which we will later catch in our application via intent-filter Authorization Activity. Thus, we get access_token, which is required for working with the SDK.
To upload images in the PhotoFrame, it was necessary to use the API method that allows you to receive images in the required reduced resolution corresponding to the screen size. Unfortunately, access to this method in the current version of the SDK has not yet been implemented, so I had to tweak the method a bit to upload files and add the ability to pass an additional parameter “size” to it.
The source code for the SDK can be downloaded from GitHub using the links
for Windows and
for Android .
Conclusion
All development took a little more than a month. As a result, we got a simple application that will help you quickly make a slideshow of your photos and share it with your family and friends.
The application has already been released, you can download it from the links on
the project description page .
We will be glad to your feedback and questions.