Android Open Source - BluetoothSppPro Base Activity






From Project

Back to project page BluetoothSppPro.

License

The source code is released under:

Apache License

If you think the Android project BluetoothSppPro 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

package mobi.dzs.android.BLE_SPP_PRO;
//from  w  w w.  ja va2  s .  com
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import mobi.dzs.android.util.LocalIOTools;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Environment;
import android.widget.Toast;

public class BaseActivity extends Activity{
  /**
   * ??Action Bar?????
   * @return void
   * */
  protected void enabledBack(){
    /*????????????????????*/
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
  }
  
  /**
   * ????????SD???
   * @param sData String ?????????
   * @return void
   * */
  protected void save2SD(String sData){
    String sRoot = null;
    String sFileName = null;
    String sPath = null;
    //??sd?????????,????????(?????'/')
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
      sRoot = Environment.getExternalStorageDirectory().toString();//???????
    else
      return;

    //????????
    sFileName = (new SimpleDateFormat("MMddHHmmss", Locale.getDefault())).format(new Date()) + ".txt";
    //???????????
    sPath = sRoot.concat("/").concat(this.getString(R.string.app_name));
    if (LocalIOTools.coverByte2File(sPath, sFileName, sData.getBytes())){
      String sMsg = ("save to:").concat(sPath).concat("/").concat(sFileName);
      Toast.makeText(this, sMsg, Toast.LENGTH_LONG).show();//???? ????????
    }else{
      Toast.makeText(this, //???? ???????
         getString(R.string.msg_save_file_fail),
         Toast.LENGTH_SHORT).show();
    }
  }
  
    /**
     * ???????????????
     * @param int iRawID ?????ID
     * @return String / null
     */
    public String getStringFormRawFile(int iRawID){
      InputStream is = this.getResources().openRawResource(iRawID);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      int i;
    try{
      i = is.read();
        while(i != -1){
          baos.write(i);
          i = is.read();
        }
        is.close();
        return baos.toString().trim();
    }catch (IOException e){
      return null;
    }
    }
}




Java Source Code List

mobi.dzs.android.BLE_SPP_PRO.BaseActivity.java
mobi.dzs.android.BLE_SPP_PRO.BaseCommActivity.java
mobi.dzs.android.BLE_SPP_PRO.actAbout.java
mobi.dzs.android.BLE_SPP_PRO.actByteStream.java
mobi.dzs.android.BLE_SPP_PRO.actCmdLine.java
mobi.dzs.android.BLE_SPP_PRO.actDiscovery.java
mobi.dzs.android.BLE_SPP_PRO.actKeyBoard.java
mobi.dzs.android.BLE_SPP_PRO.actMain.java
mobi.dzs.android.BLE_SPP_PRO.globalPool.java
mobi.dzs.android.bluetooth.BTSerialComm.java
mobi.dzs.android.bluetooth.BluetoothCtrl.java
mobi.dzs.android.bluetooth.BluetoothSppClient.java
mobi.dzs.android.bluetooth.CResourcePV.java
mobi.dzs.android.control.button.ButtonPassListener.java
mobi.dzs.android.control.button.RepeatingButton.java
mobi.dzs.android.storage.CJsonStorage.java
mobi.dzs.android.storage.CKVStorage.java
mobi.dzs.android.storage.CSharedPreferences.java
mobi.dzs.android.util.CHexConver.java
mobi.dzs.android.util.LocalIOTools.java