Exemple #1
0
  protected void updateUi() {

    WifiManager wifiMgr = (WifiManager) mActivity.getSystemService(Context.WIFI_SERVICE);
    int wifiState = wifiMgr.getWifiState();
    WifiInfo info = wifiMgr.getConnectionInfo();
    String wifiId = info != null ? info.getSSID() : null;
    boolean isWifiReady = FTPServerService.isWifiEnabled();

    setText(R.id.wifi_state, isWifiReady ? wifiId : getString(R.string.no_wifi_hint));
    ImageView wifiImg = (ImageView) findViewById(R.id.wifi_state_image);
    wifiImg.setImageResource(isWifiReady ? R.drawable.wifi_state4 : R.drawable.wifi_state0);

    boolean running = FTPServerService.isRunning();
    if (running) {
      // Put correct text in start/stop button
      // Fill in wifi status and address
      InetAddress address = FTPServerService.getWifiIp();
      if (address != null) {
        String port = ":" + FTPServerService.getPort();
        ipText.setText(
            "ftp://" + address.getHostAddress() + (FTPServerService.getPort() == 21 ? "" : port));

      } else {
        // could not get IP address, stop the service
        Context context = mActivity.getApplicationContext();
        Intent intent = new Intent(context, FTPServerService.class);
        context.stopService(intent);
        ipText.setText("");
      }
    }

    startStopButton.setEnabled(isWifiReady);
    TextView startStopButtonText = (TextView) findViewById(R.id.start_stop_button_text);
    if (isWifiReady) {
      startStopButtonText.setText(running ? R.string.stop_server : R.string.start_server);
      startStopButtonText.setCompoundDrawablesWithIntrinsicBounds(
          running ? R.drawable.disconnect : R.drawable.connect, 0, 0, 0);
      startStopButtonText.setTextColor(
          running
              ? getResources().getColor(R.color.remote_disconnect_text)
              : getResources().getColor(R.color.remote_connect_text));
    } else {
      if (FTPServerService.isRunning()) {
        Context context = mActivity.getApplicationContext();
        Intent intent = new Intent(context, FTPServerService.class);
        context.stopService(intent);
      }

      startStopButtonText.setText(R.string.no_wifi);
      startStopButtonText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
      startStopButtonText.setTextColor(Color.GRAY);
    }

    ipText.setVisibility(running ? View.VISIBLE : View.INVISIBLE);
    instructionText.setVisibility(running ? View.VISIBLE : View.GONE);
    instructionTextPre.setVisibility(running ? View.GONE : View.VISIBLE);
  }
Exemple #2
0
 public void l(int level, String str, boolean sysOnly) {
   synchronized (MyLog.class) {
     str = str.trim();
     // Messages of this severity are handled specially
     if (level == Log.ERROR || level == Log.WARN) {
       Globals.setLastError(str);
     }
     if (level >= Defaults.getConsoleLogLevel()) {
       Log.println(level, tag, str);
     }
     if (!sysOnly) { // some messages only go to the Android log
       if (level >= Defaults.getUiLogLevel()) {
         FTPServerService.log(level, str);
       }
     }
   }
 }
Exemple #3
0
  @Override
  public void onClick(View v) {
    if (v.getId() == R.id.start_stop_button) {
      File file = new File(Defaults.chrootDir);
      if (!file.isDirectory()) {
        return;
      }
      Intent intent = new Intent(MainActivity.this, FTPServerService.class);
      if (!FTPServerService.isRunning()) {
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
          startService(intent);
        } else {
          Toast.makeText(MainActivity.this, "外部存储不可用", Toast.LENGTH_LONG);
        }

      } else {
        stopService(intent);
      }
    }
  }