Option to secure particular albums in Phimpme Android Application

In the Phimpme Android application, users can perform various operations on the albums available such as creating a zip file of the album, rename an album and many more. However, one another useful functionality that has been added to the Phimpme Android application is the option to secure particular albums. So in this post, I will be discussing the implementation of this security feature. Step 1 Firstly, a view item for providing the option to enable security for particular albums is required to be added to the security settings layout. The two-state toggle switch widget provided by the Android framework along with a textview has been added as the required view item. A screenshot depicting the layout change is provided below. The code snippet representing the operation is provided below. <TextView   android:id="@+id/security_body_apply_folders_title"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:text="@string/local_folder"   android:textColor="@color/md_dark_background"   android:textSize="@dimen/medium_text" /> <android.support.v7.widget.SwitchCompat   android:id="@+id/security_body_apply_folder_switch"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_alignParentEnd="true"   android:layout_centerVertical="true"   android:layout_gravity="center_vertical"   android:button="@null"   android:hapticFeedbackEnabled="true" /> Step 2 Now we need to keep track of the albums selected by the user to secure. This can be done by storing the selected album/albums paths in an ArrayList<String> which can be referred later when required in the process. The required code snippet to perform the above mentioned operation is provided below. holder.foldercheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if(b){ securedfol.add(a.getPath()); a.setsecured(true); }else{ securedfol.remove(a.getPath()); a.setsecured(false); } } }); Step 3 Now we need to store the selected albums preference in the SharedPreference so that the user’s security preference persists even when the user exits the application and the user doesn’t have to redo the securing operation the next time user launches the application. The ArrayList<String> object containing the path of the user choice albums are converted to JSON representation by the use of the Gson Java library and the string key denoting the JSON representation of the list is saved in the SharedPreference thereafter. if(securedfol.size()>0){   SharedPreferences.Editor editor = SP.getEditor();   Gson gson = new Gson();   String securedfolders = gson.toJson(securedfol);   editor.putString(getString(R.string.preference_use_password_secured_local_folders), securedfolders);   editor.commit();} Now at the time of performing other operations on the secured folders, the list containing the secured folder paths is retrieved from SharedPreference and the choosen folder’s path is searched in the obtained list, then the user is asked to authenticate accordingly. This is how we have implemented the functionality to secure particular albums in the Phimpme Android application. To get the full source code, please refer to the Phimpme Android Github repository listed in the resource section below. Resources 1.Android Developer Guide - https://developer.android.com/training/data-storage/shared-preferences 2.Github-Phimpme Android Repository - https://github.com/fossasia/phimpme-android/ 3.Gson Java library tutorial - http://www.vogella.com/tutorials/JavaLibrary-Gson/article.html

Continue ReadingOption to secure particular albums in Phimpme Android Application

Serialisation, Deserialisation and gson in Open Event Android

JSON is a format to exchange and inter-change data. It has almost become a universal means for transferring data because of it being lightweight, human understandable, machine readable and most importantly, it’s language independence. It can be used with, and in any programming language. (Reference) FOSSASIA’s Open Event project makes extensive use of JSON for transferring information about events, their speakers, sessions and other event information. The Open Event Android application itself loads all it’s data in JSON format. This JSON is uploaded by the user in the form of a .zip compressed file or by giving an API link. Now before we use this data in the app, we have to parse the data to get Java objects that can be used in Android. Deserialisation is the process of converting JSON to Java objects. In the same way, Serialisation refers to converting Java objects into JSON. In most applications and frameworks, JSON is serialized and deserialized on multiple instances. The most common approach is to create objects corresponding to the JSON format and then use functions to convert them to JSON line-by-line, attribute by attribute. While this approach will work, it will mean writing unnecessary code and spending a lot more time on it. In Open-event-Android, we are using Google’s gson library to  serialise and deserialise JSON and corresponding Java objects respectively. Why are we using gson specifically? And why do we need any library in the first place? Yes, we can obviously make functions in Java by defining all the JSON parameters and converting the JSON into Java objects manually. It is indeed the obvious approach, but the entire process will be time-consuming, complex and definitely not error-free. Also, as projects become bigger, it is inevitable to take care of the code size and reduce it to only what is necessary. Let’s take a look at the one of the Open Event JSON file as a sample to try and understand things in a better way. This is an example of event.json in the FBF8'2017 sample. { "id": 180, "name": "F8-Facebook Developer Conference 2017", "latitude": 37.329008, "longitude": -121.888794, "location_name": "San Jose Convention Center, 150 W San Carlos St San Jose CA USA 95113 ", "start_time": "2017-04-18T10:00:00-07:00", "end_time": "2017-04-19T10:00:00-07:00", "timezone": "US / Pacific", "description": "Join us for our annual 2-day event, where developers and businesses come together to explore the future of technology. Learn how Facebook connects the world through new products and innovation. This year's event is bigger than ever – with more than 50 sessions, interactive experiences, and the opportunity to meet one-on-one with members of the Facebook team.", "background_image": "/images/background.jpg", "logo": "/images/fbf8.png", "organizer_name": "Facebook", "organizer_description": "Join us for our annual 2-day event, where developers and businesses come together to explore the future of technology. Learn how Facebook connects the world through new products and innovation. This year's event is bigger than ever – with more than 50 sessions, interactive experiences, and the opportunity to meet one-on-one with members of the Facebook team.", "event_url": "https://www.fbf8.com", "social_links": […

Continue ReadingSerialisation, Deserialisation and gson in Open Event Android