<commit_before>/*
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 * Copyright (C) 2010 <NAME> <http://markupartist.com>
 *
 * 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.v4.app;

import java.util.ArrayList;
import java.util.List;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ActionMode;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.support.v4.view.Window;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.SpinnerAdapter;
import com.actionbarsherlock.internal.view.MenuBuilder;
import com.actionbarsherlock.internal.view.MenuItemImpl;
import com.actionbarsherlock.internal.view.MenuView;
import com.actionbarsherlock.internal.widget.ActionBarWatson;
import com.actionbarsherlock.R;

final class ActionBarHandlerWatson extends ActionBar {
	/** Maximum action bar items in portrait mode. */
	private static final int MAX_ACTION_BAR_ITEMS_PORTRAIT = 3;
	
	/** Maximum action bar items in landscape mode. */
	private static final int MAX_ACTION_BAR_ITEMS_LANDSCAPE = 4;
	
	
	
	/** Action bar view. */
	private ActionBarWatson mActionBar;
	
	/** Activity content view. */
	private FrameLayout mContentView;
	
	/** List of listeners to the menu visibility. */
	private final List<OnMenuVisibilityListener> mMenuListeners = new ArrayList<OnMenuVisibilityListener>();
	
	
	
	// ------------------------------------------------------------------------
	// ACTION BAR SHERLOCK SUPPORT
	// ------------------------------------------------------------------------

	@Override
	void performAttach() {
		getActivity().requestWindowFeature(Window.FEATURE_NO_TITLE);
		getActivity().setSuperContentView(R.layout.actionbarwatson_wrapper);
		
		mActionBar = (ActionBarWatson)getActivity().findViewById(R.id.actionbarwatson);
		mContentView = (FrameLayout)getActivity().findViewById(R.id.actionbarsherlock_content);
		
		final ActionBarWatson.Item homeItem = mActionBar.getHomeItem();
		final WatsonItemViewWrapper homeWrapper = new WatsonItemViewWrapper(homeItem);
		getActivity().getHomeMenuItem().setItemView(MenuBuilder.TYPE_WATSON, homeWrapper);

		final PackageManager pm = getActivity().getPackageManager();
		final ApplicationInfo appInfo = getActivity().getApplicationInfo();
		ActivityInfo actInfo = null;
		try {
			actInfo = pm.getActivityInfo(getActivity().getComponentName(), PackageManager.GET_ACTIVITIES);
		} catch (NameNotFoundException e) {}

		
		if ((actInfo != null) && (actInfo.labelRes != 0)) {
			//Load label string resource from the activity entry
			mActionBar.setTitle(actInfo.labelRes);
		} else if (mActionBar.getTitle() == null) {
			//No activity label string resource and none in theme
			mActionBar.setTitle(actInfo.loadLabel(pm));
		}
		
		if ((actInfo != null) && (actInfo.icon != 0)) {
			//Load the icon from the activity entry
			homeItem.setIcon(actInfo.icon);
		} else if (homeItem.getIcon() == null) {
			//No activity icon and none in theme
			homeItem.setIcon(pm.getApplicationIcon(appInfo));
		}
		
		//XXX LOGO LOADING DOES NOT WORK
		//XXX SEE: http://stackoverflow.com/questions/6105504/load-activity-and-or-application-logo-programmatically-from-manifest
		//XXX SEE: https://groups.google.com/forum/#!topic/android-developers/UFR4l0ZwJWc
		//if ((actInfo != null) && (actInfo.logo != 0)) {
		//	//Load the logo from the activity entry
		//	homeItem.setLogo(actInfo.logo);
		//} else if ((homeItem.getLogo() == null) && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)) {
		//	//No activity logo and none in theme
		//	homeItem.setLogo(appInfo.logo);
		//}
	}

	@Override
	void onMenuInflated(Menu menu) {
		int maxItems = MAX_ACTION_BAR_ITEMS_PORTRAIT;
		if (getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
			maxItems = MAX_ACTION_BAR_ITEMS_LANDSCAPE;
		}
		
		//Iterate and grab as many actions as we can up to maxItems honoring
		//their showAsAction values
		int ifItems = 0;
		final int count = menu.size();
		List<MenuItemImpl> keep = new ArrayList<MenuItemImpl>();
		for (int i = 0; i < count; i++) {
			MenuItemImpl item = (MenuItemImpl)menu.getItem(i);
			if ((item.getShowAsAction() & MenuItem.SHOW_AS_ACTION_ALWAYS) != 0) {
				//Show always therefore add to keep list<commit_msg>Skip action items which do not have an icon on pre-3.0.<commit_after>/*
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 * Copyright (C) 2010 <NAME> <http://markupartist.com>
 *
 * 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.v4.app;

import java.util.ArrayList;
import java.util.List;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ActionMode;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.support.v4.view.Window;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.SpinnerAdapter;
import com.actionbarsherlock.internal.view.MenuBuilder;
import com.actionbarsherlock.internal.view.MenuItemImpl;
import com.actionbarsherlock.internal.view.MenuView;
import com.actionbarsherlock.internal.widget.ActionBarWatson;
import com.actionbarsherlock.R;

final class ActionBarHandlerWatson extends ActionBar {
	/** Maximum action bar items in portrait mode. */
	private static final int MAX_ACTION_BAR_ITEMS_PORTRAIT = 3;
	
	/** Maximum action bar items in landscape mode. */
	private static final int MAX_ACTION_BAR_ITEMS_LANDSCAPE = 4;
	
	
	
	/** Action bar view. */
	private ActionBarWatson mActionBar;
	
	/** Activity content view. */
	private FrameLayout mContentView;
	
	/** List of listeners to the menu visibility. */
	private final List<OnMenuVisibilityListener> mMenuListeners = new ArrayList<OnMenuVisibilityListener>();
	
	
	
	// ------------------------------------------------------------------------
	// ACTION BAR SHERLOCK SUPPORT
	// ------------------------------------------------------------------------

	@Override
	void performAttach() {
		getActivity().requestWindowFeature(Window.FEATURE_NO_TITLE);
		getActivity().setSuperContentView(R.layout.actionbarwatson_wrapper);
		
		mActionBar = (ActionBarWatson)getActivity().findViewById(R.id.actionbarwatson);
		mContentView = (FrameLayout)getActivity().findViewById(R.id.actionbarsherlock_content);
		
		final ActionBarWatson.Item homeItem = mActionBar.getHomeItem();
		final WatsonItemViewWrapper homeWrapper = new WatsonItemViewWrapper(homeItem);
		getActivity().getHomeMenuItem().setItemView(MenuBuilder.TYPE_WATSON, homeWrapper);

		final PackageManager pm = getActivity().getPackageManager();
		final ApplicationInfo appInfo = getActivity().getApplicationInfo();
		ActivityInfo actInfo = null;
		try {
			actInfo = pm.getActivityInfo(getActivity().getComponentName(), PackageManager.GET_ACTIVITIES);
		} catch (NameNotFoundException e) {}

		
		if ((actInfo != null) && (actInfo.labelRes != 0)) {
			//Load label string resource from the activity entry
			mActionBar.setTitle(actInfo.labelRes);
		} else if (mActionBar.getTitle() == null) {
			//No activity label string resource and none in theme
			mActionBar.setTitle(actInfo.loadLabel(pm));
		}
		
		if ((actInfo != null) && (actInfo.icon != 0)) {
			//Load the icon from the activity entry
			homeItem.setIcon(actInfo.icon);
		} else if (homeItem.getIcon() == null) {
			//No activity icon and none in theme
			homeItem.setIcon(pm.getApplicationIcon(appInfo));
		}
		
		//XXX LOGO LOADING DOES NOT WORK
		//XXX SEE: http://stackoverflow.com/questions/6105504/load-activity-and-or-application-logo-programmatically-from-manifest
		//XXX SEE: https://groups.google.com/forum/#!topic/android-developers/UFR4l0ZwJWc
		//if ((actInfo != null) && (actInfo.logo != 0)) {
		//	//Load the logo from the activity entry
		//	homeItem.setLogo(actInfo.logo);
		//} else if ((homeItem.getLogo() == null) && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)) {
		//	//No activity logo and none in theme
		//	homeItem.setLogo(appInfo.logo);
		//}
	}

	@Override
	void onMenuInflated(Menu menu) {
		int maxItems = MAX_ACTION_BAR_ITEMS_PORTRAIT;
		if (getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
			maxItems = MAX_ACTION_BAR_ITEMS_LANDSCAPE;
		}
		
		//Iterate and grab as many actions as we can up to maxItems honoring
		//their showAsAction values
		int ifItems = 0;
		final int count = menu.size();
		List<MenuItemImpl> keep = new ArrayList<MenuItemImpl>();
		for (int i = 0; i < count; i++) {
			MenuItemImpl item = (MenuItemImpl)menu.getItem(i);
			
			if (item.getIcon() == null) {
				//Items without an icon are not currently supported on the
				//action bar, force into the overflow menu
				continue;
			}
			
			if ((item.getShowAsAction() & MenuItem.SHOW_AS_ACTION_ALWAYS) != 0) {
				//Show always therefore add to keep list
{'fraction_non_alphanumeric': 0.13589990375360925, 'fraction_numerical': 0.006737247353224254, 'mean_word_length': 3.871542428504454, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '4822609', 'n_tokens_mistral': 3332, 'n_tokens_neox': 2994, 'n_words': 796}