Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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";

    /**
     * setDomain sets the current Kaltura domain. It strips off the protocol.
     *
     * @param context
     * @param kalturaDomain
     * @return
     */

    public static boolean setKalturaDomain(Context context, String kalturaDomain) {

        if (kalturaDomain == null || kalturaDomain.equals("")) {
            return false;
        }

        kalturaDomain = removeProtocol(kalturaDomain);

        SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(SHARED_PREFERENCES_KALTURA_DOMAIN, kalturaDomain);
        return editor.commit();
    }

    private static String removeProtocol(String domain) {
        if (domain.contains("https://")) {
            return domain.substring(8);
        }
        if (domain.startsWith("http://")) {
            return domain.substring(7);
        } else
            return domain;
    }
}