Android Open Source - gokit-android Air Link Activity






From Project

Back to project page gokit-android.

License

The source code is released under:

Copyright (c) 2014~2015 Xtreme Programming Group, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software...

If you think the Android project gokit-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Project Name:Gokit/*from  www . ja v  a2 s  . c  o m*/
 * File Name:AirLinkActivity.java
 * Package Name:com.xpg.gokit.activity
 * Date:2014-11-18 10:03:44
 * Copyright (c) 2014~2015 Xtreme Programming Group, Inc.
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package com.xpg.gokit.activity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.xpg.gokit.R;
import com.xpg.gokit.utils.NetUtils;
import com.xtremeprog.xpgconnect.XPGWifiDevice;

/**
 * airlink ????
 * <P>
 * ?????airlink??.?????????????????????activity??app??airlink???????????????
 * 
 * @author Lien Li
 * */
public class AirLinkActivity extends BaseActivity implements OnClickListener {

  /** ??????. */
  protected static final int SUCCESS = 0;

  /** ?????. */
  protected static final int FAIL = 1;

  /** ?????. */
  protected static final int TIEMOUT = 2;

  /** The tv_wifi. */
  private TextView tv_wifi;

  /** The edt_psw. */
  private EditText edt_psw;

  /** The btn_set. */
  private Button btn_set;

  /** The btn_back. */
  private Button btn_back;

  /** The wifi. */
  private String wifi;

  /** The dialog. */
  private ProgressDialog dialog;

  /** The handler. */
  private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
      switch (msg.what) {
      case FAIL:
        dialog.cancel();
        Toast.makeText(AirLinkActivity.this, "?????", Toast.LENGTH_SHORT)
            .show();
        break;
      case SUCCESS:
        dialog.cancel();
        Toast.makeText(AirLinkActivity.this, "??????", Toast.LENGTH_SHORT)
            .show();
        finish();
        break;

      case TIEMOUT:
        dialog.cancel();
        Toast.makeText(AirLinkActivity.this, "?????", Toast.LENGTH_SHORT)
            .show();
        break;
      }

    }
  };

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_air_link);
    actionBar.setDisplayHomeAsUpEnabled(true);

    initView();
    initData();
    initListener();

  }

  public boolean onOptionsItemSelected(MenuItem menu) {
    super.onOptionsItemSelected(menu);
    switch (menu.getItemId()) {
    case android.R.id.home:
      finish();
      break;

    default:
      break;
    }

    return true;
  }

  /**
   * Inits the view.
   */
  private void initView() {
    tv_wifi = (TextView) findViewById(R.id.tv_wifi);
    edt_psw = (EditText) findViewById(R.id.edt_psw);
    btn_set = (Button) findViewById(R.id.btn_set);
    btn_back = (Button) findViewById(R.id.btn_back);
    dialog = new ProgressDialog(this);
    dialog.setMessage("?????????...");
  }

  /**
   * Inits the data.
   */
  private void initData() {
    // ????????????wifi?ssid
    wifi = NetUtils.getCurentWifiSSID(this);
    tv_wifi.setText(wifi);
  }

  /**
   * Inits the listener.
   */
  private void initListener() {
    btn_back.setOnClickListener(this);
    btn_set.setOnClickListener(this);
  }


  @Override
  public void onClick(View v) {
    if (v == btn_back) {
      finish();
    }
    if (v == btn_set) {
      dialog.show();
      String password = edt_psw.getText().toString().trim();
      // ?????airlink??????????wifi?ssid?password?????????
      mCenter.cSetAirLink(wifi, password);
    }
  }

  /*
   * ????????
   * 
   * @see
   * com.xpg.gokit.activity.BaseActivity#didSetDeviceWifi(int error, XPGWifiDevice device)
   */
  protected void didSetDeviceWifi(int error, XPGWifiDevice device) {
    // ??airlink?????????????????????????
    Log.i("air link device", "" + device.getMacAddress() + " ");
    handler.sendEmptyMessage(SUCCESS);
  }
  

}




Java Source Code List

com.xpg.gokit.WApplication.java
com.xpg.gokit.activity.AirLinkActivity.java
com.xpg.gokit.activity.BaseActivity.java
com.xpg.gokit.activity.DeviceApActivity.java
com.xpg.gokit.activity.DeviceListActivity.java
com.xpg.gokit.activity.ForgetPasswordActivity.java
com.xpg.gokit.activity.GokitControlActivity.java
com.xpg.gokit.activity.LoginActivity.java
com.xpg.gokit.activity.MainActivity.java
com.xpg.gokit.activity.RegisterActivity.java
com.xpg.gokit.adapter.DeviceListAdapter.java
com.xpg.gokit.adapter.WifiListAdapter.java
com.xpg.gokit.adapter.WifiSpinnerAdapter.java
com.xpg.gokit.bean.ControlDevice.java
com.xpg.gokit.dialog.SetWifiDialog.java
com.xpg.gokit.dialog.listener.SetWifiListener.java
com.xpg.gokit.sdk.MessageCenter.java
com.xpg.gokit.setting.SettingManager.java
com.xpg.gokit.utils.AssertsUtils.java
com.xpg.gokit.utils.NetUtils.java