<commit_before>/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */
package ti.modules.titanium.ui.widget.tabgroup;

import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.ActivityProxy;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiInsetsProvider;
import org.appcelerator.titanium.view.TiUIView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicLong;

import ti.modules.titanium.ui.TabGroupProxy;
import ti.modules.titanium.ui.TabProxy;

/**
 *  Abstract class representing Tab Navigation in Titanium. Abstract methods in it
 *  are declared to provide an interface to connect different UI components acting
 *  as a controller. All the work done by the ViewPager is happening in this class.
 */
public abstract class TiUIAbstractTabGroup extends TiUIView
{
	/**
	 * Adds the ViewPager and the Controller to the activity's layout.
	 *
	 * @param activity the activity to be attached to.
	 */
	public abstract void addViews(TiBaseActivity activity);

	/**
	 * Adds an item in the Controller for a corresponding tab.
	 *
	 * @param tabProxy proxy to be parsed for tab item.
	 */
	public abstract void addTabItemInController(TabProxy tabProxy);

	/**
	 * Removes an item from the TabGroup controller for a specific position.
	 *
	 * @param position the position of the removed item.
	 */
	public abstract void removeTabItemFromController(int position);

	/**
	 * Selects an item from the Controller with a specific position.
	 *
	 * @param position the position of the item to be selected.
	 */
	public abstract void selectTabItemInController(int position);

	/**
	 * Changes the controller's background color.
	 *
	 * @param colorInt the new background color.
	 */
	public abstract void setBackgroundColor(int colorInt);

	/**
	 * Changes the tabs background drawables to the proper color states.
	 */
	public abstract void setDrawables();

	// region protected fields
	protected static final String TAG = "TiUITabLayoutTabGroup";
	protected static final String WARNING_LAYOUT_MESSAGE =
		"Trying to customize an unknown layout, sticking to the default one";

	protected boolean swipeable = true;
	protected boolean smoothScrollOnTabClick = true;
	protected boolean tabsDisabled = false;
	protected int numTabsWhenDisabled;
	protected int colorPrimaryInt;
	protected PagerAdapter tabGroupPagerAdapter;
	protected ViewPager tabGroupViewPager;
	protected TiInsetsProvider insetsProvider = new TiInsetsProvider();
	// endregion

	// region private fields
	private int textColorInt;
	private AtomicLong fragmentIdGenerator = new AtomicLong();
	private ArrayList<Long> tabFragmentIDs = new ArrayList<Long>();
	private ArrayList<TiUITab> tabs = new ArrayList<TiUITab>();
	// endregion

	public TiUIAbstractTabGroup(final TabGroupProxy proxy, TiBaseActivity activity)
	{
		super(proxy);

		// Getting the value for colorPrimary from the currently used theme.
		TypedValue colorPrimaryTypedValue = new TypedValue();
		TypedArray colorPrimary =
			activity.obtainStyledAttributes(colorPrimaryTypedValue.data, new int[] { android.R.attr.colorPrimary });
		this.colorPrimaryInt = colorPrimary.getColor(0, 0);
		// Getting the value for textColorPrimary for the currently used theme.
		TypedValue typedValue = new TypedValue();
		TypedArray textColor =
			activity.obtainStyledAttributes(typedValue.data, new int[] { android.R.attr.textColorPrimary });
		this.textColorInt = textColor.getColor(0, 0);

		this.tabGroupPagerAdapter = new TabGroupFragmentPagerAdapter(activity.getSupportFragmentManager());

		this.tabGroupViewPager = (new ViewPager(proxy.getActivity()) {<commit_msg>fix(android): allow AbstractTabGroup to obtain theme colors on older apis<commit_after>/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */
package ti.modules.titanium.ui.widget.tabgroup;

import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.ActivityProxy;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiInsetsProvider;
import org.appcelerator.titanium.view.TiUIView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicLong;

import ti.modules.titanium.ui.TabGroupProxy;
import ti.modules.titanium.ui.TabProxy;

/**
 *  Abstract class representing Tab Navigation in Titanium. Abstract methods in it
 *  are declared to provide an interface to connect different UI components acting
 *  as a controller. All the work done by the ViewPager is happening in this class.
 */
public abstract class TiUIAbstractTabGroup extends TiUIView
{
	/**
	 * Adds the ViewPager and the Controller to the activity's layout.
	 *
	 * @param activity the activity to be attached to.
	 */
	public abstract void addViews(TiBaseActivity activity);

	/**
	 * Adds an item in the Controller for a corresponding tab.
	 *
	 * @param tabProxy proxy to be parsed for tab item.
	 */
	public abstract void addTabItemInController(TabProxy tabProxy);

	/**
	 * Removes an item from the TabGroup controller for a specific position.
	 *
	 * @param position the position of the removed item.
	 */
	public abstract void removeTabItemFromController(int position);

	/**
	 * Selects an item from the Controller with a specific position.
	 *
	 * @param position the position of the item to be selected.
	 */
	public abstract void selectTabItemInController(int position);

	/**
	 * Changes the controller's background color.
	 *
	 * @param colorInt the new background color.
	 */
	public abstract void setBackgroundColor(int colorInt);

	/**
	 * Changes the tabs background drawables to the proper color states.
	 */
	public abstract void setDrawables();

	// region protected fields
	protected static final String TAG = "TiUITabLayoutTabGroup";
	protected static final String WARNING_LAYOUT_MESSAGE =
		"Trying to customize an unknown layout, sticking to the default one";

	protected boolean swipeable = true;
	protected boolean smoothScrollOnTabClick = true;
	protected boolean tabsDisabled = false;
	protected int numTabsWhenDisabled;
	protected int colorPrimaryInt;
	protected PagerAdapter tabGroupPagerAdapter;
	protected ViewPager tabGroupViewPager;
	protected TiInsetsProvider insetsProvider = new TiInsetsProvider();
	// endregion

	// region private fields
	private int textColorInt;
	private AtomicLong fragmentIdGenerator = new AtomicLong();
	private ArrayList<Long> tabFragmentIDs = new ArrayList<Long>();
	private ArrayList<TiUITab> tabs = new ArrayList<TiUITab>();
	// endregion

	public TiUIAbstractTabGroup(final TabGroupProxy proxy, TiBaseActivity activity)
	{
		super(proxy);

		TypedValue colorPrimaryValue = new TypedValue();
		activity.getTheme().resolveAttribute(android.R.attr.colorPrimary, colorPrimaryValue, true);

		TypedValue textColorPrimaryValue = new TypedValue();
		activity.getTheme().resolveAttribute(android.R.attr.textColorPrimary, textColorPrimaryValue, true);

		this.colorPrimaryInt = colorPrimaryValue.data;
		this.textColorInt = textColorPrimaryValue.data;

		this.tabGroupPagerAdapter = new TabGroupFragmentPagerAdapter(activity.getSupportFragmentManager());

		this.tabGroupViewPager = (new ViewPager(proxy.getActivity()) {
{'fraction_non_alphanumeric': 0.08089536699635606, 'fraction_numerical': 0.002706923477355544, 'mean_word_length': 5.221502590673575, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '987785', 'n_tokens_mistral': 2809, 'n_tokens_neox': 2658, 'n_words': 801}