Android传入和传出服务器设置

时间:2014-03-10 11:12:54

标签: java android email-client

我开始开发电子邮件应用程序。我创建了几乎所有的屏幕..但我被困在“接收服务器设置屏幕”。我的问题是如何检查传入和传出服务器设置。

我的代码是用于页面布局,

       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"

             android:paddingLeft="@dimen/activity_horizontal_margin"
             android:paddingRight="@dimen/activity_horizontal_margin"

             tools:context=".Incomingsetting" >

        <TextView
            android:id="@+id/tvProtocol"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="Protocol" />

        <Spinner
             android:id="@+id/spnProtocol"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/tvProtocol"
          />

          <TextView
               android:id="@+id/tvPassword"
                 android:layout_width="fill_parent"
               android:layout_height="wrap_content"
              android:layout_alignLeft="@+id/etUsername"
               android:layout_below="@+id/etUsername"
               android:text="Password" />

          <Button
               android:id="@+id/bBack"
               android:layout_width="wrap_content" 
                  android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
              android:text="&lt;= Back" />

            <Button
                 android:id="@+id/bNext"
                  android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                 android:text="Next =>" />

            <EditText
                  android:id="@+id/etPort"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:layout_above="@+id/bBack"
                   android:layout_alignLeft="@+id/bBack"
                    android:ems="10"
                    android:inputType="number" />

               <TextView
                    android:id="@+id/tvPort"
                     android:layout_width="fill_parent"
                         android:layout_height="wrap_content"
    android:layout_above="@+id/etPort"
    android:layout_alignLeft="@+id/etPort"
    android:text="Server Port" />

<EditText
    android:id="@+id/etEmail"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/tvEmail"
    android:layout_below="@+id/tvEmail"
    android:ems="10"

    android:inputType="textEmailAddress" />

<TextView
    android:id="@+id/tvUsername"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/etEmail"
    android:layout_below="@+id/etEmail"
    android:text="Username" />

<EditText
    android:id="@+id/etUsername"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/etServer"
    android:layout_below="@+id/tvUsername"
    android:ems="10"

    android:inputType="textEmailAddress" />

<EditText
    android:id="@+id/etPassword"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/tvPassword"
    android:layout_below="@+id/tvPassword"
    android:ems="10"

    android:inputType="textPassword" />

<TextView
    android:id="@+id/tvServer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/etPassword"
    android:layout_below="@+id/etPassword"
    android:text="Server" />

<EditText
    android:id="@+id/etServer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/spnSecurity"
    android:layout_below="@+id/tvServer"
    android:ems="10" 
    android:hint="server full name"/>

<TextView
    android:id="@+id/tvEmail"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/spnProtocol"
    android:layout_below="@+id/spnProtocol"
    android:text="Email Address" />

<Spinner
    android:id="@+id/spnSecurity"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/tvPort"
    android:layout_alignLeft="@+id/tvPort" />

  <TextView
    android:id="@+id/tvSeurity"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/etServer"
    android:layout_below="@+id/etServer"
    android:text="Security Type" />

  </RelativeLayout>

我为服务器编码创建了一个类,但我不知道如何与服务器进行交互。 java类是这样的。

public class Incomingsetting extends Activity implements OnClickListener
    {
        Spinner DDprotocol, DDSecurity;
        String[] items_protocol = new String[]{"POP3", "IMAP", "Exchange"};
        String[] items_security = new String[]{"None", "Non-SSL","SSL", "SSL (Accept all certificate)"};
        ArrayAdapter<String> adapter_protocol, adapter_security;
        TextView TVprotocol, TVemail, TVpass, TVusername;
        TextView TVserver, TVport, TVsecurity;
        EditText ETemail, ETusername, ETpass, ETserver, ETport;
        Button btNext, btBack;
        String uriString1, uriString2;


        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.incomingsetting);
            Intent i = getIntent();
            uriString1 = i.getStringExtra("Email");
            uriString2 = i.getStringExtra("password");

          //  Bundle extras = getIntent().getExtras();
            //uriString1 = extras.getString("Email");
            //uriString1 = extras.getString("password");
            initialize();

        }

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

        }

        private void initialize() 
        {


            // TODO Auto-generated method stub

            DDprotocol = (Spinner)findViewById(R.id.spnProtocol);
            DDSecurity = (Spinner)findViewById(R.id.spnSecurity);

            adapter_protocol = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, items_protocol);
            adapter_security = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, items_security);

            DDprotocol.setAdapter(adapter_protocol);
            DDSecurity.setAdapter(adapter_security);
            DDprotocol.setOnItemSelectedListener(new OnItemSelectedListener()
            {

                @Override
                public void onItemSelected(AdapterView<?> adapter, View v,
                        int position, long id) 
                {
                    // On selecting a spinner item
                    String item = adapter.getItemAtPosition(position).toString();

                    // Showing selected spinner item
                    Toast.makeText(getApplicationContext(),
                            "Protocol:: " + item, Toast.LENGTH_LONG).show();
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) 
                {
                    // TODO Auto-generated method stub

                }


            });
            DDSecurity.setOnItemSelectedListener(new OnItemSelectedListener() 
            {

                @Override
                public void onItemSelected(AdapterView<?> adapter, View v,
                        int position, long id) 
                {
                    // On selecting a spinner item
                    String item = adapter.getItemAtPosition(position).toString();

                    // Showing selected spinner item
                    Toast.makeText(getApplicationContext(),
                            "Protocol:: " + item, Toast.LENGTH_LONG).show();
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) 
                {
                    // TODO Auto-generated method stub

                }


            });

            btNext =(Button)findViewById(R.id.bNext);
            btBack=(Button)findViewById(R.id.bBack);

            ETemail = (EditText)findViewById(R.id.etEmail);
            ETpass = (EditText)findViewById(R.id.etPassword);
            ETusername = (EditText)findViewById(R.id.etUsername);
            ETserver = (EditText)findViewById(R.id.etServer);
            ETport = (EditText)findViewById(R.id.etPort);

            ETemail.setText(uriString1);
            ETusername.setText(uriString1);
            ETpass.setText(uriString2);

            if((String.valueOf(DDprotocol.getSelectedItem())=="POP3"))//&&)
            {
                ETport.setText("110");
                if(String.valueOf(DDSecurity.getSelectedItem())=="Non-SSL")
                {
                    ETport.setText("112");
                }

            }

            btNext.setOnClickListener(this);
            btBack.setOnClickListener(this);
        }



        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            switch(v.getId())
            {
            case R.id.bNext:
                break;
            case R.id.bBack:
                break;
            }

        }

    }

在bNext上我想与服务器进行交互并检查设置。

0 个答案:

没有答案