content: package io.agora.openvcall.ui;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.ActionBar;
  import android.text.Editable;
  import android.text.TextUtils;
  import android.text.TextWatcher;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.EditText;
  import android.widget.Spinner;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import io.agora.openvcall.R;
  import io.agora.openvcall.model.ConstantApp;
  
  public class MainActivity extends BaseActivity {
  
      private final static Logger log = LoggerFactory.getLogger(MainActivity.class);
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          ActionBar ab = getSupportActionBar();
          if (ab != null) {
              ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
              ab.setCustomView(R.layout.ard_agora_actionbar);
          }
      }
  
      @Override
      protected void initUIandEvent() {
          EditText v_channel = (EditText) findViewById(R.id.channel_name);
          v_channel.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  
              }
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before, int count) {
  
              }
  
              @Override
              public void afterTextChanged(Editable s) {
                  boolean isEmpty = TextUtils.isEmpty(s.toString());
                  findViewById(R.id.button_join).setEnabled(!isEmpty);
              }
          });
  
          Spinner encryptionSpinner = (Spinner) findViewById(R.id.encryption_mode);
          ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                  R.array.encryption_mode_values, R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          encryptionSpinner.setAdapter(adapter);
  
          encryptionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                  vSettings().mEncryptionModeIndex = position;
              }
  
              @Override
              public void onNothingSelected(AdapterView<?> parent) {
  
              }
          });
  
          encryptionSpinner.setSelection(vSettings().mEncryptionModeIndex);
  
          String lastChannelName = vSettings().mChannelName;
          if (!TextUtils.isEmpty(lastChannelName)) {
              v_channel.setText(lastChannelName);
              v_channel.setSelection(lastChannelName.length());
          }
  
          EditText v_encryption_key = (EditText) findViewById(R.id.encryption_key);
          String lastEncryptionKey = vSettings().mEncryptionKey;
          if (!TextUtils.isEmpty(lastEncryptionKey)) {
              v_encryption_key.setText(lastEncryptionKey);
          }
      }
  
      @Override
      protected void deInitUIandEvent() {
      }
  
      @Override
      public boolean onCreateOptionsMenu(final Menu menu) {
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle presses on the action bar items
          switch (item.getItemId()) {
              case R.id.action_settings:
                  forwardToSettings();
                  return true;
              default:
                  return super.onOptionsItemSelected(item);
          }
      }
  
      public void onClickJoin(View view) {
          forwardToRoom();
      }
  
      public void forwardToRoom() {
          EditText v_channel = (EditText) findViewById(R.id.channel_name);
          String channel = v_channel.getText().toString();
          vSettings().mChannelName = channel;
  
          EditText v_encryption_key = (EditText) findViewById(R.id.encryption_key);
          String encryption = v_encryption_key.getText().toString();
          vSettings().mEncryptionKey = encryption;
  
          Intent i = new Intent(MainActivity.this, CallActivity.class);
          i.putExtra(ConstantApp.ACTION_KEY_CHANNEL_NAME, channel);
          i.putExtra(ConstantApp.ACTION_KEY_ENCRYPTION_KEY, encryption);
          i.putExtra(ConstantApp.ACTION_KEY_ENCRYPTION_MODE, getResources().getStringArray(R.array.encryption_mode_values)[vSettings().mEncryptionModeIndex]);
  
          startActivity(i);
      }
  
      public void forwardToSettings() {
          Intent i = new Intent(this, SettingsActivity.class);
          startActivity(i);
      }
  
      public void onClickDoNetworkTest(View view) {
          Intent i = new Intent(MainActivity.this, NetworkTestActivity.class);
          startActivity(i);
      }
  
      @Override
      public void permissionGranted() {
  
      }
  
  
  }
  