package com.peer1.internetmap;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;


public class VisualizationPopupWindow extends PopupWindow{


    private class VisualizationArrayAdapter extends ArrayAdapter<String> {
        public int selectedRow;

        public VisualizationArrayAdapter(Context context, int resource, int textViewResourceId, String[] objects) {
            super(context, resource, textViewResourceId, objects);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView textView = (TextView) super.getView(position, convertView, parent);
            if (position == selectedRow) {
                textView.setBackgroundColor(Color.RED);
                textView.setTextColor(Color.BLACK);
            }else {
                textView.setBackgroundColor(Color.parseColor("#80000000"));
                textView.setTextColor(Color.WHITE);
            }
            return textView;
        }
    }

    public VisualizationPopupWindow(final InternetMap context, final MapControllerWrapper controller, View view) {
        super(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        setBackgroundDrawable(new ColorDrawable(context.getResources().getColor(R.color.translucentBlack)));
        setOutsideTouchable(true);
        setFocusable(true);

        final ListView listView = (ListView) getContentView().findViewById(R.id.visualizationList);
        String[] values = controller.visualizationNames();
        final VisualizationArrayAdapter adapter = new VisualizationArrayAdapter(context, android.R.layout.simple_list_item_1, android.R.id.text1, values);
        adapter.selectedRow = context.mCurrentVisualization;
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                //this isn't quite the cleanest way to cache the index, but it's easy
                context.mCurrentVisualization = position;
                
                controller.setVisualization(position);
                VisualizationPopupWindow.this.dismiss();
            }
        });
    }


}

@@ -279,16 +279,45 @@
 Window%7B%0A
+    private Context mContext;
 %0A%0A    pr
@@ -890,17 +890,56 @@
 lor(
+m
 Co
-lor.RED
+ntext.getResources().getColor(R.color.orange)
 );%0A 
@@ -1002,16 +1002,17 @@
        %7D
+ 
 else %7B%0A 
@@ -1064,31 +1064,19 @@
 lor.
-parseColor(%22#80000000%22)
+TRANSPARENT
 );%0A 
@@ -1567,16 +1567,44 @@
 e(true);
+%0A        mContext = context;
 %0A%0A      

Fix colour of visualization popup