<commit_before>package spit.matrix2017.Activities;

import android.Manifest;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Calendar;

import spit.matrix2017.R;

public class EventDetails
        extends AppCompatActivity
{
    private boolean isFavouriteEvent;
    private boolean isReminderSet;
    FloatingActionButton fab;
    private String event_name;
    private MenuItem mi_reminder;
    private long mEventID;
    private boolean visitedCalendar;
    View background;
    CollapsingToolbarLayout collapsingToolbarLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event_details);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");

        background =(View)findViewById(R.id.event_details_background);
        collapsingToolbarLayout=(CollapsingToolbarLayout)findViewById(R.id.collapsingToolbar_event);

        visitedCalendar = false;

        //get intent from eventlist adapter
        if (getIntent().getStringExtra("name") != null && getSupportActionBar() != null) {
            event_name = getIntent().getStringExtra("name");
            this.setTitle(event_name);
        }
        else
            this.setTitle("Some event");

        setDescription(getIntent().getStringExtra("description"));
        setVenueAndTime(getIntent().getStringExtra("venue"), getIntent().getStringExtra("time"));
        setRules();
        setPrizes();
        setContacts(getIntent().getStringExtra("contact1name"), getIntent().getStringExtra("contact1no"), getIntent().getStringExtra("contact2name"), getIntent().getStringExtra("contact2no"));

        isFavouriteEvent = getIntent().getLongExtra("favorite", 0) == 1;
        isReminderSet = getIntent().getLongExtra("reminder", 0) == 1;

        ImageView mainImageView = (ImageView) findViewById(R.id.main_imageView);
        assert mainImageView != null;
        mainImageView.setImageResource(getIntent().getIntExtra("image", R.drawable.virtual_stock_market));

        fab = (FloatingActionButton) findViewById(R.id.fab);
        assert fab != null;
        if (isFavouriteEvent)
            fab.setImageResource(R.drawable.svg_favorite_white_48px);

        Bitmap bitmap = ((BitmapDrawable)mainImageView.getDrawable()).getBitmap();

        Palette.from(bitmap).generate(new Palette.PaletteAsyncListener()
        {
            @Override
            public void onGenerated(Palette palette)
            {
                Palette.Swatch swatch = palette.getVibrantSwatch();
                if(swatch == null)
                    swatch = palette.getMutedSwatch();
                if(swatch != null)
                {
                    int color = swatch.getRgb();
                    if(Color.red(color)+Color.green(color)+Color.green(color) > 420)
                        color = Color.rgb((int)(Color.red(color)*0.8), (int)(Color.green(color)*0.8), (int)(Color.blue(color)*0.8));

                    fab.setBackgroundTintList(ColorStateList.valueOf(color));
                    fab.setRippleColor(swatch.getTitleTextColor());
                    collapsingToolbarLayout.setContentScrimColor(color);
                    collapsingToolbarLayout.setBackgroundColor(color);
                    collapsingToolbarLayout.setStatusBarScrimColor(color);

                    if(Build.VERSION.SDK_INT >= 21){
                        getWindow().setStatusBarColor(color);
                    }
                }

                /*if(swatch1 != null){
                    background.setBackgroundColor(swatch1.getRgb());
                }*/
            }
        });

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isFavouriteEvent = !isFavouriteEvent;
                ContentResolver contentResolver = getContentResolver();
                Uri uri = Uri.parse("content://spit.matrix2017.provider");
                String selection = "name = ?";<commit_msg>Set color from Palette for card title<commit_after>package spit.matrix2017.Activities;

import android.Manifest;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Calendar;

import spit.matrix2017.R;

public class EventDetails
        extends AppCompatActivity
{
    private boolean isFavouriteEvent;
    private boolean isReminderSet;
    FloatingActionButton fab;
    private String event_name;
    private MenuItem mi_reminder;
    private long mEventID;
    private boolean visitedCalendar;
    View background;
    CollapsingToolbarLayout collapsingToolbarLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event_details);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");

        final AppCompatTextView textViews[] = {
                (AppCompatTextView) findViewById(R.id.tv_event_description),
                (AppCompatTextView) findViewById(R.id.tv_event_venue_time),
                (AppCompatTextView) findViewById(R.id.tv_event_rules),
                (AppCompatTextView) findViewById(R.id.tv_event_prizes),
                (AppCompatTextView) findViewById(R.id.tv_event_organizers)
        };

        background =(View)findViewById(R.id.event_details_background);
        collapsingToolbarLayout=(CollapsingToolbarLayout)findViewById(R.id.collapsingToolbar_event);

        visitedCalendar = false;

        //get intent from eventlist adapter
        if (getIntent().getStringExtra("name") != null && getSupportActionBar() != null) {
            event_name = getIntent().getStringExtra("name");
            this.setTitle(event_name);
        }
        else
            this.setTitle("Some event");

        setDescription(getIntent().getStringExtra("description"));
        setVenueAndTime(getIntent().getStringExtra("venue"), getIntent().getStringExtra("time"));
        setRules();
        setPrizes();
        setContacts(getIntent().getStringExtra("contact1name"), getIntent().getStringExtra("contact1no"), getIntent().getStringExtra("contact2name"), getIntent().getStringExtra("contact2no"));

        isFavouriteEvent = getIntent().getLongExtra("favorite", 0) == 1;
        isReminderSet = getIntent().getLongExtra("reminder", 0) == 1;

        ImageView mainImageView = (ImageView) findViewById(R.id.main_imageView);
        assert mainImageView != null;
        mainImageView.setImageResource(getIntent().getIntExtra("image", R.drawable.virtual_stock_market));

        fab = (FloatingActionButton) findViewById(R.id.fab);
        assert fab != null;
        if (isFavouriteEvent)
            fab.setImageResource(R.drawable.svg_favorite_white_48px);

        Bitmap bitmap = ((BitmapDrawable)mainImageView.getDrawable()).getBitmap();

        Palette.from(bitmap).generate(new Palette.PaletteAsyncListener()
        {
            @Override
            public void onGenerated(Palette palette)
            {
                Palette.Swatch swatch = palette.getVibrantSwatch();
                if(swatch == null)
                    swatch = palette.getMutedSwatch();
                if(swatch != null)
                {
                    int color = swatch.getRgb();
                    if(Color.red(color)+Color.green(color)+Color.green(color) > 420)
                        color = Color.rgb((int)(Color.red(color)*0.8), (int)(Color.green(color)*0.8), (int)(Color.blue(color)*0.8));

                    fab.setBackgroundTintList(ColorStateList.valueOf(color));
                    fab.setRippleColor(swatch.getTitleTextColor());
                    collapsingToolbarLayout.setContentScrimColor(color);
                    collapsingToolbarLayout.setBackgroundColor(color);
                    collapsingToolbarLayout.setStatusBarScrimColor(color);

                    if(Build.VERSION.SDK_INT >= 21){
                        getWindow().setStatusBarColor(color);
                    }

                    for(int i=0; i<textViews.length; i++)
                        textViews[i].setTextColor(color);
                }

                /*if(swatch1 != null){
                    background.setBackgroundColor(swatch1.getRgb());
                }*/
            }
        });

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isFavouriteEvent = !isFavouriteEvent;
                ContentResolver contentResolver = getContentResolver();
                Uri uri = Uri.parse("content://spit.matrix2017.provider");
                String selection = "name = ?";
{'fraction_non_alphanumeric': 0.10490416163011569, 'fraction_numerical': 0.007338974270419616, 'mean_word_length': 3.055672268907563, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2890956', 'n_tokens_mistral': 3149, 'n_tokens_neox': 2981, 'n_words': 492}