<commit_before>package org.metawatch.manager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.metawatch.manager.MetaWatchService.Preferences;
import org.metawatch.manager.widgets.InternalWidget.WidgetData;
import org.metawatch.manager.widgets.WidgetManager;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.SimpleExpandableListAdapter;

public class WidgetSetup extends Activity {
	
	private ExpandableListView widgetList;
	private SimpleExpandableListAdapter adapter;
	
	private List<Map<String, String>> groupData;
	private List<List<Map<String, String>>> childData;
	
	private Map<String,WidgetData> widgetMap;
	
    private static final String NAME = "NAME";
    private static final String ID = "ID";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.widget_setup);
   
    }
    
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        
        setContentView(R.layout.widget_setup);
        adapter = null;
        onStart();
    }
    
	@Override
	protected void onStart() {
		super.onStart();
		
		if(adapter!=null)
			return;
		
		widgetMap = WidgetManager.getCachedWidgets(null);
			
		widgetList = (ExpandableListView) findViewById(R.id.widgetList);		
		widgetList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
			
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				Intent i = new Intent(getApplicationContext(), WidgetPicker.class);
				i.putExtra("groupPosition", groupPosition);
				i.putExtra("childPosition", childPosition);
				startActivityForResult(i,  1);
				return false;
			}
		});
				
		groupData = new ArrayList<Map<String, String>>();
	    childData = new ArrayList<List<Map<String, String>>>();

	    // Add a dummy entry at the end, if all rows have content
		ArrayList<String> rows = new ArrayList<String>(Arrays.asList(Preferences.widgets.split("\\|")));
		if (rows.size()>0 && rows.get(rows.size()-1).length()>0) {
			rows.add("");
		}
			
		int i=1;
		for(String line : rows) {
	    	Map<String, String> curGroupMap = new HashMap<String, String>();
	        groupData.add(curGroupMap);
	        curGroupMap.put(NAME, "Row " + (i++));
	        curGroupMap.put(ID, "Id");
	        
	        List<Map<String, String>> children = new ArrayList<Map<String, String>>();
	        
			String[] widgets = (line+",").split(",");
			for(String widget : widgets) {
	        	Map<String, String> curChildMap = new HashMap<String, String>();
	            children.add(curChildMap);
	            String name = widget;
	            if(widgetMap.containsKey(widget))
	            	name = widgetMap.get(widget).description;
	            curChildMap.put(NAME, name);
	            curChildMap.put(ID, widget);
	        }
			
			while(children.size()<5) {
	        	Map<String, String> curChildMap = new HashMap<String, String>();
	            children.add(curChildMap);
	            curChildMap.put(NAME, "<empty>");
	            curChildMap.put(ID, "");
			}
			
	        childData.add(children);
		}	    
	            
	    // Set up our adapter
		adapter = new SimpleExpandableListAdapter(
			this,
			groupData,
			android.R.layout.simple_expandable_list_item_1,
			new String[] { NAME, ID },
			new int[] { android.R.id.text1, android.R.id.text2 },
			childData,
			android.R.layout.simple_expandable_list_item_2,
			new String[] { NAME, ID },
			new int[] { android.R.id.text1, android.R.id.text2 }
		);
	    widgetList.setAdapter(adapter);
		
		refreshPreview();
	}
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    	super.onActivityResult(requestCode, resultCode, data);

		widgetMap = WidgetManager.getCachedWidgets(null);
    	
        if (resultCode == Activity.RESULT_OK) {      	  
        	String id = data.getStringExtra("selectedWidget");
        	int groupPosition = data.getIntExtra("groupPosition", -1);
        	int childPosition = data.getIntExtra("childPosition", -1);
        	
        	if(groupPosition>-1 && childPosition>-1) {
        		Map<String,String> curChildMap = childData.get(groupPosition).get(childPosition);
        		if(id==null) {
    	            curChildMap.put(NAME, "<empty>");
    	            curChildMap.put(ID, "");
        		}<commit_msg>Attempts to improve widget setup<commit_after>package org.metawatch.manager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.metawatch.manager.MetaWatchService.Preferences;
import org.metawatch.manager.widgets.InternalWidget.WidgetData;
import org.metawatch.manager.widgets.WidgetManager;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.SimpleExpandableListAdapter;

public class WidgetSetup extends Activity {
	
	private ExpandableListView widgetList;
	private SimpleExpandableListAdapter adapter;
	
	private List<Map<String, String>> groupData;
	private List<List<Map<String, String>>> childData;
	
	private Map<String,WidgetData> widgetMap;
	
    private static final String NAME = "NAME";
    private static final String ID = "ID";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.widget_setup);
   
    }
    
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        
        setContentView(R.layout.widget_setup);
        adapter = null;
        onStart();
    }
    
	@Override
	protected void onStart() {
		super.onStart();
		
		if(adapter!=null)
			return;
		
		widgetMap = WidgetManager.getCachedWidgets(null);
			
		widgetList = (ExpandableListView) findViewById(R.id.widgetList);		
		widgetList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
			
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				Intent i = new Intent(getApplicationContext(), WidgetPicker.class);
				i.putExtra("groupPosition", groupPosition);
				i.putExtra("childPosition", childPosition);
				startActivityForResult(i,  1);
				return false;
			}
		});
				
		groupData = new ArrayList<Map<String, String>>();
	    childData = new ArrayList<List<Map<String, String>>>();

	    // Add a dummy entry at the end, if all rows have content
		ArrayList<String> rows = new ArrayList<String>(Arrays.asList(Preferences.widgets.split("\\|")));
		if (rows.size()>0 && rows.get(rows.size()-1).length()>0) {
			rows.add("");
		}
			
		int i=1;
		for(String line : rows) {
	    	Map<String, String> curGroupMap = new HashMap<String, String>();
	        groupData.add(curGroupMap);
	        curGroupMap.put(NAME, "Row " + (i++));
	        curGroupMap.put(ID, "Id");
	        
	        List<Map<String, String>> children = new ArrayList<Map<String, String>>();
	        
			String[] widgets = (line).split(",");
			for(String widget : widgets) {
				widget = widget.trim();
	        	Map<String, String> curChildMap = new HashMap<String, String>();
	            children.add(curChildMap);
	            String name = widget;
	            if(widget==null || widget=="")
	            	name="<empty>";
	            if(widgetMap.containsKey(widget))
	            	name = widgetMap.get(widget).description;
	            curChildMap.put(NAME, name);
	            curChildMap.put(ID, widget);
	        }
			
			while(children.size()<8) {
	        	Map<String, String> curChildMap = new HashMap<String, String>();
	            children.add(curChildMap);
	            curChildMap.put(NAME, "<empty>");
	            curChildMap.put(ID, "");
			}
			
	        childData.add(children);
		}	    
	            
	    // Set up our adapter
		adapter = new SimpleExpandableListAdapter(
			this,
			groupData,
			android.R.layout.simple_expandable_list_item_1,
			new String[] { NAME, ID },
			new int[] { android.R.id.text1, android.R.id.text2 },
			childData,
			android.R.layout.simple_expandable_list_item_2,
			new String[] { NAME, ID },
			new int[] { android.R.id.text1, android.R.id.text2 }
		);
	    widgetList.setAdapter(adapter);
		
		refreshPreview();
	}
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    	super.onActivityResult(requestCode, resultCode, data);

		widgetMap = WidgetManager.getCachedWidgets(null);
    	
        if (resultCode == Activity.RESULT_OK) {      	  
        	String id = data.getStringExtra("selectedWidget");
        	int groupPosition = data.getIntExtra("groupPosition", -1);
        	int childPosition = data.getIntExtra("childPosition", -1);
        	
        	if(groupPosition>-1 && childPosition>-1) {
        		Map<String,String> curChildMap = childData.get(groupPosition).get(childPosition);
        		if(id==null || id=="") {
    	            curChildMap.put(NAME, "<empty>");
    	            curChildMap.put(ID, "");
        		}
{'fraction_non_alphanumeric': 0.12101244639682042, 'fraction_numerical': 0.0033469302374228636, 'mean_word_length': 3.0828351836037573, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 64, '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': '3859036', 'n_tokens_mistral': 3092, 'n_tokens_neox': 2796, 'n_words': 562}