<commit_before>package com.kaltura.localassetsdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

import com.kaltura.playersdk.KPPlayerConfig;
import com.kaltura.playersdk.LocalAssetsManager;
import com.kaltura.playersdk.PlayerViewController;
import com.kaltura.playersdk.Utilities;
import com.kaltura.playersdk.events.KPEventListener;
import com.kaltura.playersdk.events.KPlayerState;
import com.kaltura.playersdk.types.KPError;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

public class MainActivity extends AppCompatActivity implements KPEventListener {

    private static final String TAG = "MainActivity";
    
    private PlayerViewController mPlayer;
    private ViewGroup mPlayerContainer;
    private boolean mPlayerDetached;
    private Item mSelectedItem;
    private ArrayList<Item> mContentItems;
    private HashMap<String, Integer> mContentMap;

    private PlayerViewController.SourceURLProvider mSourceURLProvider = new PlayerViewController.SourceURLProvider() {
        @Override
        public String getURL(String entryId, String currentURL) {
            
            Item item = mContentItems.get(mContentMap.get(entryId));

            if (item != null) {
                if (item.isDownloaded()) {
                    return item.localPath;
                } else {
                    return item.contentUrl;
                }
            }
            return null;
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        loadItems();
        
        mPlayerContainer = (ViewGroup) findViewById(R.id.layout_player_container);
        
        setButtonAction(R.id.btn_register, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSelectedItem.localPath == null) {
                    uiLog("Content is not downloaded");
                    return;
                }
                KPPlayerConfig config = mSelectedItem.config;
                LocalAssetsManager.registerAsset(MainActivity.this, config, mSelectedItem.flavorId, mSelectedItem.localPath, new LocalAssetsManager.AssetRegistrationListener() {
                    @Override
                    public void onRegistered(String assetPath) {
                        uiLog("Register successful", null);
                    }

                    @Override
                    public void onFailed(String assetPath, Exception error) {
                        uiLog("Register failed", error);
                    }
                });
            }
        });
        
        setButtonAction(R.id.btn_load, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getPlayer().getMediaControl().start();
            }
        });

        setButtonAction(R.id.btn_detach, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mPlayer != null) {
                    mPlayerContainer.removeView(mPlayer);
                    mPlayerDetached = true;
                }
            }
        });

<commit_msg>fixed for android 6 permission (#225)<commit_after>package com.kaltura.localassetsdemo;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.kaltura.playersdk.KPPlayerConfig;
import com.kaltura.playersdk.LocalAssetsManager;
import com.kaltura.playersdk.PlayerViewController;
import com.kaltura.playersdk.Utilities;
import com.kaltura.playersdk.events.KPEventListener;
import com.kaltura.playersdk.events.KPlayerState;
import com.kaltura.playersdk.types.KPError;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

public class MainActivity extends AppCompatActivity implements KPEventListener {

    private static final String TAG = "MainActivity";
    private static final int REQUEST_WRITE_STORAGE = 200;

    private PlayerViewController mPlayer;
    private ViewGroup mPlayerContainer;
    private boolean mPlayerDetached;
    private Item mSelectedItem;
    private ArrayList<Item> mContentItems;
    private HashMap<String, Integer> mContentMap;

    private PlayerViewController.SourceURLProvider mSourceURLProvider = new PlayerViewController.SourceURLProvider() {
        @Override
        public String getURL(String entryId, String currentURL) {
            
            Item item = mContentItems.get(mContentMap.get(entryId));

            if (item != null) {
                if (item.isDownloaded()) {
                    return item.localPath;
                } else {
                    return item.contentUrl;
                }
            }
            return null;
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        askPermission();
        loadItems();
        
        mPlayerContainer = (ViewGroup) findViewById(R.id.layout_player_container);
        
        setButtonAction(R.id.btn_register, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSelectedItem.localPath == null) {
                    uiLog("Content is not downloaded");
                    return;
                }
                KPPlayerConfig config = mSelectedItem.config;
                LocalAssetsManager.registerAsset(MainActivity.this, config, mSelectedItem.flavorId, mSelectedItem.localPath, new LocalAssetsManager.AssetRegistrationListener() {
                    @Override
                    public void onRegistered(String assetPath) {
                        uiLog("Register successful", null);
                    }

                    @Override
                    public void onFailed(String assetPath, Exception error) {
                        uiLog("Register failed", error);
                    }
                });
            }
        });
        
        setButtonAction(R.id.btn_load, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getPlayer().getMediaControl().start();
            }
        });

        setButtonAction(R.id.btn_detach, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mPlayer != null) {
                    mPlayerContainer.removeView(mPlayer);
                    mPlayerDetached = true;
                }
            }
        });


    }

    private void askPermission() {
        boolean hasPermission = (ContextCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
        if (!hasPermission) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                    REQUEST_WRITE_STORAGE);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case REQUEST_WRITE_STORAGE: {
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    //if permission granted
                } else {
                    Toast.makeText(this, "The app was not allowed to write to your storage.", Toast.LENGTH_LONG).show();
                }
            }
        }
{'fraction_non_alphanumeric': 0.08221909453436547, 'fraction_numerical': 0.0015247478301665493, 'mean_word_length': 2.182904068682344, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3755426', 'n_tokens_mistral': 2224, 'n_tokens_neox': 2112, 'n_words': 441}