<commit_before>/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * 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 android.support.v17.leanback.widget;

import android.support.v17.leanback.tests.R;
import android.support.v7.widget.RecyclerView;
import android.support.v17.leanback.widget.BaseGridView;
import android.support.v17.leanback.widget.OnChildSelectedListener;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @hide from javadoc
 */
public class GridActivity extends Activity {
    private static final String TAG = "GridActivity";

    public static final String EXTRA_LAYOUT_RESOURCE_ID = "layoutResourceId";
    public static final String EXTRA_NUM_ITEMS = "numItems";
    public static final String EXTRA_ITEMS = "items";
    public static final String EXTRA_STAGGERED = "staggered";
    public static final String SELECT_ACTION = "android.test.leanback.widget.SELECT";

    static final int DEFAULT_LAYOUT_RESOURCE_ID = R.layout.horizontal_grid;
    static final int DEFAULT_NUM_ITEMS = 100;
    static final boolean DEFAULT_STAGGERED = true;

    private static final boolean DEBUG = false;

    int mLayoutId;
    int mOrientation;
    int mNumItems;
    boolean mStaggered;

    int[] mGridViewLayoutSize;
    BaseGridView mGridView;
    int[] mItemLengths;

    private int mBoundCount;

    private View createView() {

        View view = getLayoutInflater().inflate(mLayoutId, null, false);
        mGridView = (BaseGridView) view.findViewById(R.id.gridview);
        mOrientation = mGridView instanceof HorizontalGridView ? BaseGridView.HORIZONTAL :
                BaseGridView.VERTICAL;
        mGridView.setWindowAlignment(BaseGridView.WINDOW_ALIGN_BOTH_EDGE);
        mGridView.setWindowAlignmentOffsetPercent(35);
        mGridView.setOnChildSelectedListener(new OnChildSelectedListener() {
            @Override
            public void onChildSelected(ViewGroup parent, View view, int position, long id) {
                if (DEBUG) Log.d(TAG, "onChildSelected position=" + position +  " id="+id);
            }
        });
        return view;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();

        mLayoutId = intent.getIntExtra(EXTRA_LAYOUT_RESOURCE_ID, DEFAULT_LAYOUT_RESOURCE_ID);
        mStaggered = intent.getBooleanExtra(EXTRA_STAGGERED, DEFAULT_STAGGERED);
        mItemLengths = intent.getIntArrayExtra(EXTRA_ITEMS);
        if (mItemLengths == null) {
            mNumItems = intent.getIntExtra(EXTRA_NUM_ITEMS, DEFAULT_NUM_ITEMS);
            mItemLengths = new int[mNumItems];
            for (int i = 0; i < mItemLengths.length; i++) {
                if (mOrientation == BaseGridView.HORIZONTAL) {
                    mItemLengths[i] = mStaggered ? (int)(Math.random() * 180) + 180 : 240;
                } else {
                    mItemLengths[i] = mStaggered ? (int)(Math.random() * 120) + 120 : 160;
                }
            }
        } else {
            mNumItems = mItemLengths.length;
        }

        super.onCreate(savedInstanceState);

        if (DEBUG) Log.v(TAG, "onCreate " + this);<commit_msg>am af8a0b99: am 4576ab79: Fix javadoc error<commit_after>/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * 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 android.support.v17.leanback.widget;

import android.support.v17.leanback.tests.R;
import android.support.v7.widget.RecyclerView;
import android.support.v17.leanback.widget.BaseGridView;
import android.support.v17.leanback.widget.OnChildSelectedListener;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @hide from javadoc
 */
public class GridActivity extends Activity {
    private static final String TAG = "GridActivity";

    public static final String EXTRA_LAYOUT_RESOURCE_ID = "layoutResourceId";
    public static final String EXTRA_NUM_ITEMS = "numItems";
    public static final String EXTRA_ITEMS = "items";
    public static final String EXTRA_STAGGERED = "staggered";
    public static final String SELECT_ACTION = "android.test.leanback.widget.SELECT";

    static final int DEFAULT_NUM_ITEMS = 100;
    static final boolean DEFAULT_STAGGERED = true;

    private static final boolean DEBUG = false;

    int mLayoutId;
    int mOrientation;
    int mNumItems;
    boolean mStaggered;

    int[] mGridViewLayoutSize;
    BaseGridView mGridView;
    int[] mItemLengths;

    private int mBoundCount;

    private View createView() {

        View view = getLayoutInflater().inflate(mLayoutId, null, false);
        mGridView = (BaseGridView) view.findViewById(R.id.gridview);
        mOrientation = mGridView instanceof HorizontalGridView ? BaseGridView.HORIZONTAL :
                BaseGridView.VERTICAL;
        mGridView.setWindowAlignment(BaseGridView.WINDOW_ALIGN_BOTH_EDGE);
        mGridView.setWindowAlignmentOffsetPercent(35);
        mGridView.setOnChildSelectedListener(new OnChildSelectedListener() {
            @Override
            public void onChildSelected(ViewGroup parent, View view, int position, long id) {
                if (DEBUG) Log.d(TAG, "onChildSelected position=" + position +  " id="+id);
            }
        });
        return view;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();

        mLayoutId = intent.getIntExtra(EXTRA_LAYOUT_RESOURCE_ID, R.layout.horizontal_grid);
        mStaggered = intent.getBooleanExtra(EXTRA_STAGGERED, DEFAULT_STAGGERED);
        mItemLengths = intent.getIntArrayExtra(EXTRA_ITEMS);
        if (mItemLengths == null) {
            mNumItems = intent.getIntExtra(EXTRA_NUM_ITEMS, DEFAULT_NUM_ITEMS);
            mItemLengths = new int[mNumItems];
            for (int i = 0; i < mItemLengths.length; i++) {
                if (mOrientation == BaseGridView.HORIZONTAL) {
                    mItemLengths[i] = mStaggered ? (int)(Math.random() * 180) + 180 : 240;
                } else {
                    mItemLengths[i] = mStaggered ? (int)(Math.random() * 120) + 120 : 160;
                }
            }
        } else {
            mNumItems = mItemLengths.length;
        }

        super.onCreate(savedInstanceState);

        if (DEBUG) Log.v(TAG, "onCreate " + this);
{'fraction_non_alphanumeric': 0.0879641166209818, 'fraction_numerical': 0.01146274607525542, 'mean_word_length': 3.231418028465999, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5219987', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2234, 'n_words': 606}