Пример #1
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
    Settings settings = Settings.getInstance(getActivity());

    String actionName;
    switch (getAction()) {
      case ADD_ACTION:
        actionName = getString(R.string.add);
        break;
      case EDIT_ACTION:
        actionName = getString(R.string.edit);
        break;
      case CONNECT_ACTION:
        actionName = getString(R.string.connect);
        break;
      default:
        throw new RuntimeException("Unknown action " + getAction());
    }
    adb.setPositiveButton(actionName, null);
    adb.setNegativeButton(android.R.string.cancel, null);

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View view = inflater.inflate(R.layout.dialog_server_edit, null, false);

    TextView titleLabel = (TextView) view.findViewById(R.id.server_edit_name_title);
    mNameEdit = (EditText) view.findViewById(R.id.server_edit_name);
    mHostEdit = (EditText) view.findViewById(R.id.server_edit_host);
    mPortEdit = (EditText) view.findViewById(R.id.server_edit_port);
    mUsernameEdit = (EditText) view.findViewById(R.id.server_edit_username);
    mUsernameEdit.setHint(settings.getDefaultUsername());
    mPasswordEdit = (EditText) view.findViewById(R.id.server_edit_password);

    Server oldServer = getServer();
    if (oldServer != null) {
      mNameEdit.setText(oldServer.getName());
      mHostEdit.setText(oldServer.getHost());
      mPortEdit.setText(String.valueOf(oldServer.getPort()));
      mUsernameEdit.setText(oldServer.getUsername());
      mPasswordEdit.setText(oldServer.getPassword());
    }

    if (shouldIgnoreTitle()) {
      titleLabel.setVisibility(View.GONE);
      mNameEdit.setVisibility(View.GONE);
    }

    // Fixes issues with text colour on light themes with pre-honeycomb devices.
    adb.setInverseBackgroundForced(true);

    adb.setView(view);

    return adb.create();
  }
Пример #2
0
    public UserListAdapter(final Context context, final Runnable visibleUsersChangedCallback) {
      this.context = context;
      this.visibleUsersChangedCallback = visibleUsersChangedCallback;
      this.dbAdapter = new DbAdapter(context);

      // Fetch theme dependent icon
      Settings settings = Settings.getInstance(context);
      chatDrawable =
          getResources()
              .getDrawable(
                  settings.getTheme().equals(Settings.ARRAY_THEME_LIGHTDARK)
                      ? R.drawable.ic_action_chat_light
                      : R.drawable.ic_action_chat_dark);
    }
Пример #3
0
  @Override
  public void onCreate() {
    super.onCreate();

    // Make sure our notification is gone.
    hideNotification();

    settings = Settings.getInstance(this);

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "plumbleLock");

    Log.i(Globals.LOG_TAG, "MumbleService: Created");
    serviceState = CONNECTION_STATE_DISCONNECTED;

    chatFormatter = new PlumbleChatFormatter(this);

    dbAdapter = new DbAdapter(this);
    dbAdapter.open();
  }
Пример #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    settings = Settings.getInstance(this);
    settings.addObserver(this);

    // Use theme from settings
    int theme = 0;
    if (settings.getTheme().equals(Settings.ARRAY_THEME_LIGHTDARK)) {
      theme = R.style.Theme_Sherlock_Light_DarkActionBar;
    } else if (settings.getTheme().equals(Settings.ARRAY_THEME_DARK)) {
      theme = R.style.Theme_Sherlock;
    }
    setTheme(theme);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_channel);

    // Bind to service
    Intent serviceIntent = new Intent(this, MumbleService.class);
    bindService(serviceIntent, conn, 0);

    // Register bluetooth SCO monitor
    registerReceiver(
        bluetoothReceiver, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));

    // Handle differences in CallMode

    String callMode = settings.getCallMode();
    setVolumeControlStream(
        Settings.ARRAY_CALL_MODE_SPEAKER.equals(callMode)
            ? AudioManager.STREAM_MUSIC
            : AudioManager.STREAM_VOICE_CALL);

    // Set up proximity sensor
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    proximityLock = powerManager.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, Globals.LOG_TAG);

    // Set up PTT button.

    mTalkButton = (Button) findViewById(R.id.pushtotalk);
    pttView = findViewById(R.id.pushtotalk_view);
    mTalkButton.setOnTouchListener(
        new OnTouchListener() {

          private static final int TOGGLE_INTERVAL =
              250; // 250ms is the interval needed to toggle push to talk.
          private long lastTouch = 0;

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            if (mService == null) {
              return false;
            }

            if (event.getAction() == MotionEvent.ACTION_DOWN && !settings.isPushToTalkToggle()) {
              setPushToTalk(true);
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
              if (settings.isPushToTalkToggle()) setPushToTalk(!mService.isRecording());
              else {
                if (System.currentTimeMillis() - lastTouch <= TOGGLE_INTERVAL) {
                  // Do nothing. We leave the push to talk on, as it has toggled.
                } else {
                  setPushToTalk(false);
                  lastTouch = System.currentTimeMillis();
                }
              }
            }

            return true; // We return true so that the selector that changes the background does not
            // fire.
          }
        });

    updatePTTConfiguration();

    mViewPager = (ViewPager) findViewById(R.id.pager);
    FragmentManager fragmentManager = getSupportFragmentManager();

    listFragment = (ChannelListFragment) fragmentManager.findFragmentByTag(LIST_FRAGMENT_TAG);
    chatFragment = (ChannelChatFragment) fragmentManager.findFragmentByTag(CHAT_FRAGMENT_TAG);

    FragmentTransaction remove = fragmentManager.beginTransaction();
    if (listFragment == null) listFragment = new ChannelListFragment();
    else remove.remove(listFragment);

    if (chatFragment == null) chatFragment = new ChannelChatFragment();
    else remove.remove(chatFragment);

    if (!remove.isEmpty()) {
      remove.commit();
      fragmentManager.executePendingTransactions();
    }

    if (mViewPager != null) {
      // Set up the ViewPager with the sections adapter.
      mViewPager.setOnPageChangeListener(
          new OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg0) {
              // Hide keyboard if moving to channel list.
              if (arg0 == 0) {
                InputMethodManager imm =
                    (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mViewPager.getApplicationWindowToken(), 0);
              }
              // Update indicator
              channelsIndicator.setVisibility(arg0 == 0 ? View.VISIBLE : View.INVISIBLE);
              chatIndicator.setVisibility(arg0 == 1 ? View.VISIBLE : View.INVISIBLE);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {}

            @Override
            public void onPageScrollStateChanged(int arg0) {}
          });

      // Set up tabs
      getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

      View channelTabView = getLayoutInflater().inflate(R.layout.channel_tab_view, null);
      channelsIndicator = channelTabView.findViewById(R.id.tab_channels_indicator);
      chatIndicator = channelTabView.findViewById(R.id.tab_chat_indicator);

      ImageButton channelsButton = (ImageButton) channelTabView.findViewById(R.id.tab_channels);
      ImageButton chatButton = (ImageButton) channelTabView.findViewById(R.id.tab_chat);
      channelsButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              mViewPager.setCurrentItem(0, true);
            }
          });
      chatButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              mViewPager.setCurrentItem(1, true);
            }
          });

      getSupportActionBar().setCustomView(channelTabView);
      // Setup a pager that will return a fragment for each of the two primary sections of the app.
      mSectionsPagerAdapter =
          new PlumbleSectionsPagerAdapter(
              this, getSupportFragmentManager(), listFragment, chatFragment);
      mViewPager.setAdapter(mSectionsPagerAdapter);

    } else {
      // Create tablet UI
      leftSplit = findViewById(R.id.left_split);
      rightSplit = findViewById(R.id.right_split);
      fragmentManager
          .beginTransaction()
          .add(R.id.chat_fragment, chatFragment, CHAT_FRAGMENT_TAG)
          .add(R.id.list_fragment, listFragment, LIST_FRAGMENT_TAG)
          .commit();
    }

    if (savedInstanceState != null) {
      chatTarget = (User) savedInstanceState.getParcelable(SAVED_STATE_CHAT_TARGET);
    }
  }