Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; public class Main { /** * SharedPreferences tags */ //We would need migration code to update NAME and MASQUERADED_USER to snake case, so we will leave them as is for now. private final static String SHARED_PREFERENCES_NAME = "canvas-kit-sp"; private final static String SHARED_PREFERENCES_KALTURA_DOMAIN = "kaltura_domain"; private final static String SHARED_PREFERENCES_API_PROTOCOL = "api_protocol"; /** * getFullKalturaDomain returns the protocol plus the domain. * * Returns "" if context is null or if the domain/token isn't set. * @return */ public static String getFullKalturaDomain(Context context) { String protocol = loadProtocol(context); String domain = getKalturaDomain(context); if (protocol == null || domain == null || protocol.equals("") || domain.equals("")) { return ""; } return protocol + "://" + domain; } /** * loadProtocol returns the protocol or 'https' if there isn't one. * @param context * @return */ public static String loadProtocol(Context context) { if (context == null) { return "https"; } SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); return sharedPreferences.getString(SHARED_PREFERENCES_API_PROTOCOL, "https"); } /** * getKalturaDomain returns the current domain. This function strips off all trailing / characters and the protocol. * @link APIHelpers.loadProtocol(context) * @param context * @return */ public static String getKalturaDomain(Context context) { if (context == null) { return ""; } SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); String domain = sharedPreferences.getString(SHARED_PREFERENCES_KALTURA_DOMAIN, ""); while (domain != null && domain.endsWith("/")) { domain = domain.substring(0, domain.length() - 1); } return domain; } }