<commit_before>package com.github.andlyticsproject;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.github.andlyticsproject.Preferences.Timeframe;
import com.github.andlyticsproject.admob.AdmobRequest;
import com.github.andlyticsproject.admob.AdmobRequest.SyncCallback;
import com.github.andlyticsproject.exception.NetworkException;
import com.github.andlyticsproject.model.Admob;
import com.github.andlyticsproject.model.AdmobList;
import com.github.andlyticsproject.view.ViewSwitcher3D;

public class AdmobActivity extends BaseChartActivity { 
  public static final String TAG = AdmobActivity.class.getSimpleName();
  
  protected ContentAdapter db;
  private AdmobListAdapter admobListAdapter;
  public Integer heighestRatingChange;
  public Integer lowestRatingChange;
  private ViewSwitcher3D mainViewSwitcher;
  private ViewGroup accountList;
  
  private View addAccountButton;
  
  private ViewSwitcher configSwitcher;
  
  protected String admobToken;
  
  private ViewGroup siteList;
  
  @Override
  protected void executeLoadData(Timeframe timeFrame)
  {
    new LoadDbEntiesTask().execute(new Object[] { false, timeFrame });
    
  }
  
  private void executeLoadDataDefault(boolean executeRemoteCall)
  {
    new LoadDbEntiesTask().execute(new Object[] { executeRemoteCall, getCurrentTimeFrame() });
    
  }
  
	public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		super.onCreate(savedInstanceState);
        setSupportProgressBarIndeterminateVisibility(false);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);

		db = getDbAdapter();

		mainViewSwitcher = new ViewSwitcher3D(
				(ViewGroup) findViewById(R.id.base_chart_main_frame));
		mainViewSwitcher.setListener(this);

		admobListAdapter = new AdmobListAdapter(this);

		setAdapter(admobListAdapter);

		String currentAdmobAccount = null;
		String currentSiteId = Preferences.getAdmobSiteId(AdmobActivity.this,
				packageName);
		if (currentSiteId != null) {
			currentAdmobAccount = Preferences.getAdmobAccount(this,
					currentSiteId);
		}

		if (currentAdmobAccount == null) {
			mainViewSwitcher.swap();
			if (configSwitcher.getCurrentView().getId() != R.id.base_chart_config) {
				configSwitcher.showPrevious();
			}
			showAccountList();
		} else {
			executeLoadDataDefault(false);
		}

	}
  
  @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		getSupportMenuInflater().inflate(R.menu.admob_menu, menu);
		return true;
	}
	
	/**
	 * Called if item in option menu is selected.
	 * 
	 * @param item
	 *            The chosen menu item
	 * @return boolean true/false
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			startActivityAfterCleanup(Main.class);
			return true;
		case R.id.itemAdmobsmenuRefresh:
			setChartIgnoreCallLayouts(true);
			new LoadRemoteEntiesTask().execute();
			return true;
		case R.id.itemAdmobsmenuSettings:
			setChartIgnoreCallLayouts(true);

			String admobSiteId = Preferences.getAdmobSiteId(AdmobActivity.this,
					packageName);

			if (admobSiteId == null) {

				View currentView = configSwitcher.getCurrentView();
				if (currentView.getId() != R.id.base_chart_config) {
					configSwitcher.showPrevious();
				}
				mainViewSwitcher.swap();
				showAccountList();
			} else {
				getListViewSwitcher().swap();
			}
			return true;
		default:
			return (super.onOptionsItemSelected(item));
		}
	}
	
	/**
	 * starts a given activity with a clear flag.
	 * 
	 * @param activity
	 *            Activity to be started
	 */
	private void startActivityAfterCleanup(Class<?> activity) {
		Intent intent = new Intent(getApplicationContext(), activity);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(intent);
	}
  
  @Override
  protected String getChartHint()
  {
    return "8 " + this.getString(R.string.admob__charts_available) + " ->";
  }
  
  protected void showAccountList()
  {
    
    final AccountManager manager = AccountManager.get(this);
    final Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE_ADMOB);
    final int size = accounts.length;
    String[] names = new String[size];
    accountList.removeAllViews();
    for(int i = 0; i < size; i++ )
    {
      names[i] = accounts[i].name;
      
      View inflate = getLayoutInflater().inflate(R.layout.login_list_item, null);
      TextView accountName = (TextView) inflate.findViewById(R.id.login_list_item_text);
      accountName.setText(accounts[i].name);
      inflate.setTag(accounts[i].name);
      inflate.setOnClickListener(new OnClickListener() {
        
        @Override
        public void onClick(View view)
        {
          
          String currentAdmobAccount = (String) view.getTag();
          
          configSwitcher.showNext();
          new LoadRemoteSiteListTask(currentAdmobAccount).execute();
          
        }
      });
      accountList.addView(inflate);
    }
  }
  
  private void addNewAdmobAccount()<commit_msg>Use the admob account layout in the admob activity<commit_after>package com.github.andlyticsproject;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
import com.github.andlyticsproject.Preferences.Timeframe;
import com.github.andlyticsproject.admob.AdmobRequest;
import com.github.andlyticsproject.admob.AdmobRequest.SyncCallback;
import com.github.andlyticsproject.exception.NetworkException;
import com.github.andlyticsproject.model.Admob;
import com.github.andlyticsproject.model.AdmobList;
import com.github.andlyticsproject.view.ViewSwitcher3D;

public class AdmobActivity extends BaseChartActivity { 
  public static final String TAG = AdmobActivity.class.getSimpleName();
  
  protected ContentAdapter db;
  private AdmobListAdapter admobListAdapter;
  public Integer heighestRatingChange;
  public Integer lowestRatingChange;
  private ViewSwitcher3D mainViewSwitcher;
  private ViewGroup accountList;
  
  private View addAccountButton;
  
  private ViewSwitcher configSwitcher;
  
  protected String admobToken;
  
  private ViewGroup siteList;
  
  @Override
  protected void executeLoadData(Timeframe timeFrame)
  {
    new LoadDbEntiesTask().execute(new Object[] { false, timeFrame });
    
  }
  
  private void executeLoadDataDefault(boolean executeRemoteCall)
  {
    new LoadDbEntiesTask().execute(new Object[] { executeRemoteCall, getCurrentTimeFrame() });
    
  }
  
	public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		super.onCreate(savedInstanceState);
        setSupportProgressBarIndeterminateVisibility(false);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);

		db = getDbAdapter();

		mainViewSwitcher = new ViewSwitcher3D(
				(ViewGroup) findViewById(R.id.base_chart_main_frame));
		mainViewSwitcher.setListener(this);

		admobListAdapter = new AdmobListAdapter(this);

		setAdapter(admobListAdapter);

		String currentAdmobAccount = null;
		String currentSiteId = Preferences.getAdmobSiteId(AdmobActivity.this,
				packageName);
		if (currentSiteId != null) {
			currentAdmobAccount = Preferences.getAdmobAccount(this,
					currentSiteId);
		}

		if (currentAdmobAccount == null) {
			mainViewSwitcher.swap();
			if (configSwitcher.getCurrentView().getId() != R.id.base_chart_config) {
				configSwitcher.showPrevious();
			}
			showAccountList();
		} else {
			executeLoadDataDefault(false);
		}

	}
  
  @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		getSupportMenuInflater().inflate(R.menu.admob_menu, menu);
		return true;
	}
	
	/**
	 * Called if item in option menu is selected.
	 * 
	 * @param item
	 *            The chosen menu item
	 * @return boolean true/false
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			startActivityAfterCleanup(Main.class);
			return true;
		case R.id.itemAdmobsmenuRefresh:
			setChartIgnoreCallLayouts(true);
			new LoadRemoteEntiesTask().execute();
			return true;
		case R.id.itemAdmobsmenuSettings:
			setChartIgnoreCallLayouts(true);

			String admobSiteId = Preferences.getAdmobSiteId(AdmobActivity.this,
					packageName);

			if (admobSiteId == null) {

				View currentView = configSwitcher.getCurrentView();
				if (currentView.getId() != R.id.base_chart_config) {
					configSwitcher.showPrevious();
				}
				mainViewSwitcher.swap();
				showAccountList();
			} else {
				getListViewSwitcher().swap();
			}
			return true;
		default:
			return (super.onOptionsItemSelected(item));
		}
	}
	
	/**
	 * starts a given activity with a clear flag.
	 * 
	 * @param activity
	 *            Activity to be started
	 */
	private void startActivityAfterCleanup(Class<?> activity) {
		Intent intent = new Intent(getApplicationContext(), activity);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(intent);
	}
  
  @Override
  protected String getChartHint()
  {
    return "8 " + this.getString(R.string.admob__charts_available) + " ->";
  }
  
  protected void showAccountList()
  {
    
    final AccountManager manager = AccountManager.get(this);
    final Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE_ADMOB);
    final int size = accounts.length;
    String[] names = new String[size];
    accountList.removeAllViews();
    for(int i = 0; i < size; i++ )
    {
      names[i] = accounts[i].name;
      
      View inflate = getLayoutInflater().inflate(R.layout.admob_account_list_item, null);
      TextView accountName = (TextView) inflate.findViewById(R.id.admob_account_list_item_text);
      accountName.setText(accounts[i].name);
      inflate.setTag(accounts[i].name);
      inflate.setOnClickListener(new OnClickListener() {
        
        @Override
        public void onClick(View view)
        {
          
          String currentAdmobAccount = (String) view.getTag();
          
          configSwitcher.showNext();
          new LoadRemoteSiteListTask(currentAdmobAccount).execute();
          
        }
      });
      accountList.addView(inflate);
    }
  }
  
  private void addNewAdmobAccount()
{'fraction_non_alphanumeric': 0.09626638094453144, 'fraction_numerical': 0.0008241984669908514, 'mean_word_length': 4.273359408952629, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7481320', 'n_tokens_mistral': 3873, 'n_tokens_neox': 3602, 'n_words': 683}