/*
 * Copyright (C) 2015 Yuya Tanaka
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.ypresto.recyclerview.absolutelayoutmanager.example;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import net.ypresto.recyclerview.absolutelayoutmanager.AbsoluteLayoutManager;

public class MainActivity extends AppCompatActivity {
    private SampleAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mAdapter.setCount(mAdapter.getCount() + 1);
                mAdapter.notifyDataSetChanged();
            }
        });

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        mAdapter = new SampleAdapter();
        recyclerView.setAdapter(mAdapter);
        recyclerView.setLayoutManager(new AbsoluteLayoutManager(new SquareVerticalLayoutProvider()));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -1041,16 +1041,49 @@
 nager;%0A%0A
+import java.lang.reflect.Field;%0A%0A
 public c
@@ -1956,101 +1956,772 @@
     
-recyclerView.setLayoutManager(new AbsoluteLayoutManager(new SquareVerticalLayoutProvider()));
+AbsoluteLayoutManager layoutManager = new AbsoluteLayoutManager(new SquareVerticalLayoutProvider());%0A        setDebugFlag(layoutManager);%0A        recyclerView.setLayoutManager(layoutManager);%0A    %7D%0A%0A    @SuppressWarnings(%22TryWithIdenticalCatches%22) // As it requires API %3E= 17 for reflection classes.%0A    private void setDebugFlag(AbsoluteLayoutManager layoutManager) %7B%0A        Field debugFlag;%0A        try %7B%0A            debugFlag = AbsoluteLayoutManager.class.getDeclaredField(%22DEBUG%22);%0A            debugFlag.setAccessible(true);%0A            debugFlag.setBoolean(layoutManager, true);%0A        %7D catch (NoSuchFieldException e) %7B%0A            throw new AssertionError(e);%0A        %7D catch (IllegalAccessException e) %7B%0A            throw new AssertionError(e);%0A        %7D
 %0A   

Enable debug log for sample app