如何在python中生成当前活动代理的列表

时间:2015-06-24 07:17:07

标签: python proxy

我有一个python脚本,如果直接连接失败,我会通过代理连接到某些站点。我想要做的是获取当前活动代理的列表,我无法弄清楚如何这样做

我通过这个生成代理:

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Checkable;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivityTest extends ActionBarActivity {
    GridView gridView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gridView = (GridView)findViewById(R.id.gridview);
        gridView.setMultiChoiceModeListener(new MultiChoiceModeListener());
        gridView.setAdapter(new NumberAdapter(this));
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int numero = position+1;
                LayoutInflater inflater = getLayoutInflater();
                final View layout = inflater.inflate(R.layout.custom_toast_layout,
                        (ViewGroup) findViewById(R.id.custom_toast_layout));
                TextView selectedNumber = (TextView) layout.findViewById(R.id.selected_number);
                selectedNumber.setText(""+numero);

                Context context = getBaseContext();
                String text = ""+numero;
                int duration = Toast.LENGTH_SHORT;
                final Toast toast = Toast.makeText(context, text, duration);
                toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                toast.setView(layout);
                toast.show();
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        toast.cancel();
                    }
                }, 600);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public class CheckableLayout extends FrameLayout implements Checkable {
        private boolean mChecked;

        public CheckableLayout(Context context) {
            super(context);
        }

        @SuppressWarnings("deprecation")
        public void setChecked(boolean checked) {
            mChecked = checked;
            setBackgroundDrawable(checked ? getResources().getDrawable(
                    R.drawable.rounded_edittext_denim) : null);
        }

        public boolean isChecked() {
            return mChecked;
        }

        public void toggle() {
            setChecked(!mChecked);
        }

    }

    public class MultiChoiceModeListener implements GridView.MultiChoiceModeListener {
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.setTitle("Select Items");
            mode.setSubtitle("One item selected");
            return true;
        }

        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return true;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return true;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public void onItemCheckedStateChanged(ActionMode mode, int position,
                                              long id, boolean checked) {
            int selectCount = gridView.getCheckedItemCount();
            switch (selectCount) {
                case 1:
                    mode.setSubtitle("One item selected");
                    break;
                default:
                    mode.setSubtitle("" + selectCount + " items selected");
                    break;
            }
        }

    }

    public class NumberAdapter extends BaseAdapter {

        private Context context;

        public NumberAdapter(Context context) {
            this.context = context;
        }

        @Override
        public int getCount() {
            return 60;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            CheckableLayout checkableLayout;
            TextView numberView;

            if (convertView == null) {
                numberView = new TextView(context);
                numberView.setLayoutParams(new GridView.LayoutParams(110, 110));
                numberView.setPadding(0, 0, 0, 0);
                numberView.setTextColor(Color.WHITE);
                numberView.setBackgroundResource(R.drawable.rounded_edittext_zaffiro);
                numberView.setGravity(Gravity.CENTER);
                numberView.setTextSize(25);
                checkableLayout = new CheckableLayout(MainActivityTest.this);
                checkableLayout.addView(numberView);

            } else {
//ERROR AT THIS POINT
                checkableLayout = (CheckableLayout) convertView;
                numberView = (TextView) checkableLayout.getChildAt(0);
            }

            numberView.setText("" + (position + 1));
            return numberView;

        }
    }
}

请帮忙

0 个答案:

没有答案