fixed image button cast to button issues.
authorTrillGates <williamtrillgates@gmail.com>
Sat, 5 Jun 2021 06:42:45 +0000 (14:42 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Sat, 5 Jun 2021 06:42:45 +0000 (14:42 +0800)
app/src/main/java/mobile/miki/FactoryReset_activity.java
app/src/main/java/mobile/miki/MikeTest.java
app/src/main/java/mobile/miki/ageingmode/AgeingMikeTest.java
app/src/main/java/mobile/miki/shutdown_activity.java
app/src/main/res/layout/activity_shutdown_activity.xml

index c20e060..1575775 100644 (file)
@@ -4,19 +4,15 @@ import android.content.Context;
 import android.content.Intent;\r
 import android.os.Bundle;\r
 import android.os.Environment;\r
-import android.util.Log;\r
 import android.view.View;\r
 import android.widget.Button;\r
-import android.widget.ImageButton;\r
 import android.widget.TextView;\r
 \r
-import java.lang.reflect.Method;\r
-\r
 public class FactoryReset_activity extends BaseActivity {\r
 \r
     String TAG = "shutdown_activity";\r
-    ImageButton btn_yes;\r
-    ImageButton btn_no;\r
+    Button btn_yes;\r
+    Button btn_no;\r
     TextView tv;\r
 \r
     @Override\r
@@ -24,8 +20,8 @@ public class FactoryReset_activity extends BaseActivity {
         super.onCreate(savedInstanceState);\r
         setContentView(R.layout.activity_shutdown_activity);\r
         tv = (TextView) findViewById(R.id.shutdownText);\r
-        btn_yes = (ImageButton) findViewById(R.id.btn_yes);\r
-        btn_no = (ImageButton) findViewById(R.id.btn_no);\r
+        btn_yes =  (Button) findViewById(R.id.btn_yes);\r
+        btn_no =  (Button)findViewById(R.id.btn_no);\r
         btn_yes.setClickable(true);\r
         btn_no.setClickable(true);\r
         btn_no.setEnabled(true);\r
index a3455b0..5ca13ff 100644 (file)
@@ -5,7 +5,7 @@
  *  Creator  :  xuanyang.feng
  *  Date     :  2011/12/1
  *  Comment  :  CIT Test -> HeadSet Test  use  AudioTrack and AudioRecord
- *   
+ *
  */
 package mobile.miki;
 
@@ -25,8 +25,6 @@ import android.os.PowerManager.WakeLock;
 import android.preference.PreferenceManager;
 import android.util.Log;
 import android.view.View;
-import android.widget.ImageButton;
-import android.widget.TextView;
 
 import mobile.miki.mainui.ButtonViewTwo;
 import mobile.miki.mainui.TestMainActivity;
@@ -38,422 +36,415 @@ import mobile.miki.util.FTUtils;
 //import sim.android.mtkcit.R;
 //import sim.android.mtkcit.TestActivity;
 
-public class MikeTest  extends BaseActivity implements android.view.View.OnClickListener{
-       static final String TAG = "AgeingMikeTest";
-       private boolean isRun = false;
-       private boolean isClosing = false;
-       WakeLock mWakeLock;
-       private AudioManager mAudioManager;
-       private RecordThread mRecordThread;
-       int bufferReadResult;
-       ImageButton mRecordButton;
-       TextView txtDescript;
-       byte[]  tmpBuf;
-       public int state = 0;
-       public int mVolume = 0;
-       public int nCurrentMusicVolume;
-       public boolean flag = false;
-       public float LeftVolume;
-       public float RightVolume;
-       private ButtonViewTwo buttonView;
-       boolean running;
-       boolean pcbatest;
-
-       static final int mSourceType = MediaRecorder.AudioSource.MIC;
-
-       static final int SAMPLE_RATE_IN_HZ = 8000;
-
-       static final int channelConfiguration = AudioFormat.CHANNEL_IN_STEREO;
-//     private Button btn_success;
+public class MikeTest extends BaseActivity implements android.view.View.OnClickListener {
+    static final String TAG = "AgeingMikeTest";
+    private boolean isRun = false;
+    private boolean isClosing = false;
+    WakeLock mWakeLock;
+    private AudioManager mAudioManager;
+    private RecordThread mRecordThread;
+    public int state = 0;
+    public int mVolume = 0;
+    public int nCurrentMusicVolume;
+    public boolean flag = false;
+    private ButtonViewTwo buttonView;
+    boolean running;
+    boolean pcbatest;
+
+    static final int mSourceType = MediaRecorder.AudioSource.MIC;
+
+    static final int SAMPLE_RATE_IN_HZ = 8000;
+
+    static final int channelConfiguration = AudioFormat.CHANNEL_IN_STEREO;
+    // private Button btn_success;
 //     private Button btn_fail;
-       static final int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
-       public static final int PCBA_TEST = 0;
-       public static final int MACHINE_TEST = 1;
-       int recBufSize = 0, playBufSize = 0;
-       int mAudioBufferSize;
-       int mAudioBufferSimpleSize;
-       int mRecBufferSimpleSize;
-       VUMeter mVUMeter;
-       AudioRecord mAudioRecord;
-       AudioTrack mAudioTrack;
-       private int j;
-       int sampleRate = 8000;
-       int channelConfig = AudioFormat.CHANNEL_IN_MONO;
-       int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
-       final Handler mHandler = new Handler();
-       final Runnable mUpdataResults = new Runnable() {
-               public void run() {
-                       updateUI();
-               }
-       };
-       public static MikeTest instance = null;
-
-       @Override
-       public void onCreate(Bundle icycle) {
-
-               super.onCreate(icycle);
-               MyApplication.getInstance().addActivity(this);
-               setContentView(R.layout.test_mike);
-               Intent intent = getIntent();
-               instance = this;
-               running = false;
-               pcbatest =false;
-               if (intent != null) {
-                       running = intent.getBooleanExtra("running", false);
-                       pcbatest = intent.getBooleanExtra("pcbatest",false);
-               }
-               buttonView = (ButtonViewTwo) findViewById(R.id.btn_set);
-               buttonView.btn_left.setOnClickListener(this);
-               buttonView.btn_right.setOnClickListener(this);
-               buttonView.btn_left.setClickable(false);
-               getCameraIntent();
-               ageingMode();
-       }
-
-       @Override
-       protected void onResume() {
-               buttonView.setSuccessColor();
-               buttonView.btn_left.setClickable(true);
-               super.onResume();
-       }
-
-       @Override
-       protected void onStart() {
-               initResourceRefs();
-
-               super.onStart();
-       }
-
-       private void initResourceRefs() {
-               PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
-               mWakeLock = pm
-                               .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "MicTest");
-
-               mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
-               setVolumeControlStream(AudioManager.STREAM_MUSIC);
-
-               // add_s wangkang 2012.5.3 bug896
-               nCurrentMusicVolume = mAudioManager
-                               .getStreamVolume(AudioManager.STREAM_MUSIC);
-               mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
-                               mAudioManager
-                                               .getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
-
-               // initAudioRecord();
-               initAudioTrack();
-               mVUMeter = (VUMeter) findViewById(R.id.uvMeter);
-               mVUMeter.setVolume(0);
-               mVUMeter.invalidate();
-               mRecordThread = new RecordThread();
-               Log.v(TAG, "initResourceRefs");
-               mRecordThread.start();
-       }
-
-
-       private void initAudioRecord() {
-               Log.v(TAG, "initAudioRecord");
-
-               recBufSize = 2 * AudioRecord.getMinBufferSize(SAMPLE_RATE_IN_HZ,
-                               channelConfiguration, audioEncoding);
-
-               mAudioBufferSimpleSize = recBufSize / 2;
-               mAudioRecord = new AudioRecord(mSourceType, SAMPLE_RATE_IN_HZ,
-                               channelConfiguration, audioFormat, recBufSize);
-               int audioRecordState = mAudioRecord.getState();
-               if (audioRecordState != AudioRecord.STATE_INITIALIZED) {
-                       Log.v(TAG, "AudioRecord is initialized");
-                       finish();
-               }
-       }
-
-       private void initAudioTrack() {
-               Log.v(TAG, "initAudioTrack");
-
-               playBufSize = 2 * AudioTrack.getMinBufferSize(SAMPLE_RATE_IN_HZ,
-                               channelConfiguration, audioEncoding);
-
-               mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
-                               SAMPLE_RATE_IN_HZ, channelConfiguration, audioFormat,
-                               playBufSize, AudioTrack.MODE_STREAM);
-               int audioTrackState = mAudioTrack.getState();
-               if (audioTrackState != AudioTrack.STATE_INITIALIZED) {
-                       Log.v(TAG, "AudioTrack is initialized");
-                       finish();
-               }
-               initAudioRecord();
-       }
-
-       short[] audioBuffer;
-
-       class RecordThread extends Thread {
-
-               public RecordThread() {
-                       super();
-               }
-
-               public void run() {
-                       Log.d("CIT", "Run");
-                       super.run();
-
-                       if (mAudioRecord == null)
-                               return;
-                       audioBuffer = new short[mAudioBufferSimpleSize];
-                       mAudioRecord.startRecording();
-                       int audioRecordState = mAudioRecord.getRecordingState();
-                       if (audioRecordState != AudioRecord.RECORDSTATE_RECORDING) {
-                               Log.v(TAG, "not recording");
-                               return;
-                       } else {
-                               Log.v(TAG, "start recording");
-
-                       }
-                       
-                       if (mAudioTrack == null)
-                               return;
-                       mAudioTrack.play();
-                       int audioTracktate = mAudioTrack.getPlayState();
-                       if (audioTracktate != AudioTrack.PLAYSTATE_PLAYING) {
-                               Log.v(TAG, "not playing");
-                               return;
-
-                       }
-
-                       Log.v(TAG, "start playing");
-                       mAudioTrack.setStereoVolume(1.0f, 1.0f);
-                       isRun = true;
-                       while (isRun) {
-                               int sampleRate = mAudioRecord.read(audioBuffer, 0,
-                                               mAudioBufferSimpleSize);
-                               if (mAudioBufferSimpleSize < 0) {
-                                       mAudioBufferSimpleSize = 0;
-                               }
-                               
-                               if ((mAudioTrack != null) && (!isClosing))
-                                       try {
-                                               mAudioTrack.write(audioBuffer, 0, mAudioBufferSimpleSize);
-                                       } catch (Exception e) {
-                                               // TODO: handle exception
-                                               e.printStackTrace();
-                                       }
-                                       
-
-                               int v = 0;
-                               for (int i = 0; i < audioBuffer.length; i++) {
-                                       v += audioBuffer[i] * audioBuffer[i];
-                               }
-                               sampleRate = sampleRate < 0 ? 0 : sampleRate;
-                               mVolume = v / (50 * (sampleRate + 1));
-                               Log.v(TAG, "mVolume=" + mVolume);
-                               j++;
-                               if (j < 5) {
-                                       mVolume = 20;
-                               }
-                               mHandler.post(mUpdataResults);
-                               
-                       }
+    static final int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
+    public static final int PCBA_TEST = 0;
+    public static final int MACHINE_TEST = 1;
+    int recBufSize = 0, playBufSize = 0;
+    int mAudioBufferSize;
+    int mAudioBufferSimpleSize;
+    int mRecBufferSimpleSize;
+    VUMeter mVUMeter;
+    AudioRecord mAudioRecord;
+    AudioTrack mAudioTrack;
+    private int j;
+    int sampleRate = 8000;
+    int channelConfig = AudioFormat.CHANNEL_IN_MONO;
+    int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
+    final Handler mHandler = new Handler();
+    final Runnable mUpdataResults = new Runnable() {
+        public void run() {
+            updateUI();
+        }
+    };
+    public static MikeTest instance = null;
+
+    @Override
+    public void onCreate(Bundle icycle) {
+
+        super.onCreate(icycle);
+        MyApplication.getInstance().addActivity(this);
+        setContentView(R.layout.test_mike);
+        Intent intent = getIntent();
+        instance = this;
+        running = false;
+        pcbatest = false;
+        if (intent != null) {
+            running = intent.getBooleanExtra("running", false);
+            pcbatest = intent.getBooleanExtra("pcbatest", false);
+        }
+        buttonView = (ButtonViewTwo) findViewById(R.id.btn_set);
+        buttonView.btn_left.setOnClickListener(this);
+        buttonView.btn_right.setOnClickListener(this);
+        buttonView.btn_left.setClickable(false);
+        getCameraIntent();
+        ageingMode();
+    }
+
+    @Override
+    protected void onResume() {
+        buttonView.setSuccessColor();
+        buttonView.btn_left.setClickable(true);
+        super.onResume();
+    }
+
+    @Override
+    protected void onStart() {
+        initResourceRefs();
+
+        super.onStart();
+    }
+
+    private void initResourceRefs() {
+        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+        mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "MicTest");
+
+        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+        setVolumeControlStream(AudioManager.STREAM_MUSIC);
+
+        // add_s wangkang 2012.5.3 bug896
+        nCurrentMusicVolume = mAudioManager
+                .getStreamVolume(AudioManager.STREAM_MUSIC);
+        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
+                mAudioManager
+                        .getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
+
+        // initAudioRecord();
+        initAudioTrack();
+        mVUMeter = (VUMeter) findViewById(R.id.uvMeter);
+        mVUMeter.setVolume(0);
+        mVUMeter.invalidate();
+        mRecordThread = new RecordThread();
+        Log.v(TAG, "initResourceRefs");
+        mRecordThread.start();
+    }
+
+
+    private void initAudioRecord() {
+        Log.v(TAG, "initAudioRecord");
+
+        recBufSize = 2 * AudioRecord.getMinBufferSize(SAMPLE_RATE_IN_HZ,
+                channelConfiguration, audioEncoding);
+
+        mAudioBufferSimpleSize = recBufSize / 2;
+        mAudioRecord = new AudioRecord(mSourceType, SAMPLE_RATE_IN_HZ,
+                channelConfiguration, audioFormat, recBufSize);
+        int audioRecordState = mAudioRecord.getState();
+        if (audioRecordState != AudioRecord.STATE_INITIALIZED) {
+            Log.v(TAG, "AudioRecord is initialized");
+            finish();
+        }
+    }
+
+    private void initAudioTrack() {
+        Log.v(TAG, "initAudioTrack");
+
+        playBufSize = 2 * AudioTrack.getMinBufferSize(SAMPLE_RATE_IN_HZ,
+                channelConfiguration, audioEncoding);
+
+        mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
+                SAMPLE_RATE_IN_HZ, channelConfiguration, audioFormat,
+                playBufSize, AudioTrack.MODE_STREAM);
+        int audioTrackState = mAudioTrack.getState();
+        if (audioTrackState != AudioTrack.STATE_INITIALIZED) {
+            Log.v(TAG, "AudioTrack is initialized");
+            finish();
+        }
+        initAudioRecord();
+    }
+
+    short[] audioBuffer;
+
+    class RecordThread extends Thread {
+
+        public RecordThread() {
+            super();
+        }
+
+        public void run() {
+            Log.d("CIT", "Run");
+            super.run();
+
+            if (mAudioRecord == null)
+                return;
+            audioBuffer = new short[mAudioBufferSimpleSize];
+            mAudioRecord.startRecording();
+            int audioRecordState = mAudioRecord.getRecordingState();
+            if (audioRecordState != AudioRecord.RECORDSTATE_RECORDING) {
+                Log.v(TAG, "not recording");
+                return;
+            } else {
+                Log.v(TAG, "start recording");
+
+            }
+
+            if (mAudioTrack == null)
+                return;
+            mAudioTrack.play();
+            int audioTracktate = mAudioTrack.getPlayState();
+            if (audioTracktate != AudioTrack.PLAYSTATE_PLAYING) {
+                Log.v(TAG, "not playing");
+                return;
+
+            }
+
+            Log.v(TAG, "start playing");
+            mAudioTrack.setStereoVolume(1.0f, 1.0f);
+            isRun = true;
+            while (isRun) {
+                int sampleRate = mAudioRecord.read(audioBuffer, 0,
+                        mAudioBufferSimpleSize);
+                if (mAudioBufferSimpleSize < 0) {
+                    mAudioBufferSimpleSize = 0;
+                }
+
+                if ((mAudioTrack != null) && (!isClosing))
+                    try {
+                        mAudioTrack.write(audioBuffer, 0, mAudioBufferSimpleSize);
+                    } catch (Exception e) {
+                        // TODO: handle exception
+                        e.printStackTrace();
+                    }
+
+
+                int v = 0;
+                for (int i = 0; i < audioBuffer.length; i++) {
+                    v += audioBuffer[i] * audioBuffer[i];
+                }
+                sampleRate = sampleRate < 0 ? 0 : sampleRate;
+                mVolume = v / (50 * (sampleRate + 1));
+                Log.v(TAG, "mVolume=" + mVolume);
+                j++;
+                if (j < 5) {
+                    mVolume = 20;
+                }
+                mHandler.post(mUpdataResults);
+
+            }
 
 //                     finish();
 
-               }
-
-               public void pause() {
-                       isRun = false;
-               }
-
-               public void start() {
-                       if (!isRun) {
-                               super.start();
-                       }
-               }
-
-       }
-
-       @Override
-       public void onStop() {
-               releaseRec();
-               super.onStop();
-       }
-
-       private void releaseRec() {
-               if (mAudioManager != null) {
-                       //mod_s wangkang 2012.5.3       bug896
-                       mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
-                                       nCurrentMusicVolume, 0);
-                       //mod_s wangkang 2012.5.3       bug896
-               }
-               if (mAudioTrack != null) {
-                       mAudioTrack.release();
-
-               }
-               if (mAudioRecord != null) {
-                       mAudioRecord.release();
-
-               }
-               isRun = false;
-
-       }
-
-       @Override
-       public void onDestroy() {
-               if(mRecordThread != null){
-                       mRecordThread = null;
-               }
-               if(ageHandler != null && runnable != null) {
-                       ageHandler.removeCallbacks(runnable);
-               }
-               if (receiver != null) {
-                       unregisterReceiver(receiver);
-               }
-
-               if(handler != null) {
-                       handler.removeCallbacksAndMessages(handler.obtainMessage());
-               }
-               super.onDestroy();
-       }
-
-       private void updateUI() {
-               
+        }
+
+        public void pause() {
+            isRun = false;
+        }
+
+        public void start() {
+            if (!isRun) {
+                super.start();
+            }
+        }
+
+    }
+
+    @Override
+    public void onStop() {
+        releaseRec();
+        super.onStop();
+    }
+
+    private void releaseRec() {
+        if (mAudioManager != null) {
+            //mod_s wangkang 2012.5.3  bug896
+            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
+                    nCurrentMusicVolume, 0);
+            //mod_s wangkang 2012.5.3  bug896
+        }
+        if (mAudioTrack != null) {
+            mAudioTrack.release();
+
+        }
+        if (mAudioRecord != null) {
+            mAudioRecord.release();
+
+        }
+        isRun = false;
+
+    }
+
+    @Override
+    public void onDestroy() {
+        if (mRecordThread != null) {
+            mRecordThread = null;
+        }
+        if (ageHandler != null && runnable != null) {
+            ageHandler.removeCallbacks(runnable);
+        }
+        if (receiver != null) {
+            unregisterReceiver(receiver);
+        }
+
+        if (handler != null) {
+            handler.removeCallbacksAndMessages(handler.obtainMessage());
+        }
+        super.onDestroy();
+    }
+
+    private void updateUI() {
+
 //             Log.i("MikeTest000", "updateUI(), mVolume=" + mVolume);
-               
-               mVUMeter.setVolume(mVolume);
-               if ((!flag) && (mVolume > 3000)) {
+
+        mVUMeter.setVolume(mVolume);
+        if ((!flag) && (mVolume > 3000)) {
 //                     btn_success.setEnabled(true);
-                       flag = true;
-               }
-       }
-       
+            flag = true;
+        }
+    }
+
 
     @Override
-       public void onClick(View arg0) {
-               Intent intent =  Config.getNextTestIntent(this,this.getClass());//new Intent(this, SimDetectActivity.class);
-               intent.putExtra("running", true);
-               intent.putExtra("pcbatest",pcbatest);
-               Intent intent1 = new Intent(this, TestMainActivity.class);
-               // TestResult testResult = (TestResult) getApplicationContext();
-               switch (arg0.getId()) {
-
-               case R.id.btn_two_left:
-                       if (!running) {
-                               startActivity(intent1);
-                       } else {
-                               startActivity(intent);
-                       }
-                       PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("mic", "true")
-                                       .commit();
-                       finish();
-                       break;
-               case R.id.btn_two_right:
-                       if (!running) {
-                               startActivity(intent1);
-                       } else {
-                               startActivity(intent);
-                       }
-                       PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("mic", "false")
-                                       .commit();
-                       finish();
-                       break;
-               }
-       }
-    
+    public void onClick(View arg0) {
+        Intent intent = Config.getNextTestIntent(this, this.getClass());//new Intent(this, SimDetectActivity.class);
+        intent.putExtra("running", true);
+        intent.putExtra("pcbatest", pcbatest);
+        Intent intent1 = new Intent(this, TestMainActivity.class);
+        // TestResult testResult = (TestResult) getApplicationContext();
+        switch (arg0.getId()) {
+
+            case R.id.btn_two_left:
+                if (!running) {
+                    startActivity(intent1);
+                } else {
+                    startActivity(intent);
+                }
+                PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("mic", "true")
+                        .commit();
+                finish();
+                break;
+            case R.id.btn_two_right:
+                if (!running) {
+                    startActivity(intent1);
+                } else {
+                    startActivity(intent);
+                }
+                PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("mic", "false")
+                        .commit();
+                finish();
+                break;
+        }
+    }
+
     @Override
-       public void onBackPressed() {
-               // super.onBackPressed();
-               if (running) {
-                       Intent intent = new Intent(this, TestMainList.class);
-                       startActivity(intent);
-                       finish();
-               } else {
-                       finish();
-               }
-       }
-
-       boolean isEgeingMode = false;
-       private int TIME = 1000 * 10;
-       private int SINGLEITEM_OR_CYCLE_MODE;
-       private int WORK_TIME;
-       private MyReceiver receiver=null;
-
-       private void getCameraIntent() {
-               Intent intent = getIntent();
-               if (intent != null) {
-                       try {
-                               isEgeingMode = intent.getBooleanExtra("ageing_mode", false);
-                               SINGLEITEM_OR_CYCLE_MODE = intent.getIntExtra("singleitem_or_cycle_mode", 0);
-                               WORK_TIME = intent.getIntExtra("work_time", 0);
-                       } catch (Exception e) {
-                               e.printStackTrace();
-
-                       }
-               }
-       }
-       /**
-        * 处理老化模式的状态
-        */
-       private void ageingMode() {
-               if(isEgeingMode && SINGLEITEM_OR_CYCLE_MODE == 1) {
-                       // 单项无限循环
-                       if (WORK_TIME == -1) {
-                               WORK_TIME = 100000000;
-                       }
-                       TIME = WORK_TIME * Constants.SINGLEITEM_TIMES;
-                       ageHandler.postDelayed(runnable, TIME);
-                       sendBraodCaseReceiver();
-               } else if (isEgeingMode && SINGLEITEM_OR_CYCLE_MODE == 2) {
-                       TIME = Constants.CYCLE_ONE_ACTIVITY_TIMES;
-                       ageHandler.postDelayed(runnable, TIME);
-                       registerReceiver();
-               } else {
-                       sendBraodCaseReceiver();
-               }
-       }
-
-       Handler ageHandler = new Handler();
-       Runnable runnable = new Runnable() {
-
-               @Override
-               public void run() {
-                       // handler自带方法实现定时器
-                       try {
-                               if(SINGLEITEM_OR_CYCLE_MODE == 2) {
-                                       Intent ageingIntent = new Intent(MikeTest.this,RingtoneActivity.class);
+    public void onBackPressed() {
+        // super.onBackPressed();
+        if (running) {
+            Intent intent = new Intent(this, TestMainList.class);
+            startActivity(intent);
+            finish();
+        } else {
+            finish();
+        }
+    }
+
+    boolean isEgeingMode = false;
+    private int TIME = 1000 * 10;
+    private int SINGLEITEM_OR_CYCLE_MODE;
+    private int WORK_TIME;
+    private MyReceiver receiver = null;
+
+    private void getCameraIntent() {
+        Intent intent = getIntent();
+        if (intent != null) {
+            try {
+                isEgeingMode = intent.getBooleanExtra("ageing_mode", false);
+                SINGLEITEM_OR_CYCLE_MODE = intent.getIntExtra("singleitem_or_cycle_mode", 0);
+                WORK_TIME = intent.getIntExtra("work_time", 0);
+            } catch (Exception e) {
+                e.printStackTrace();
+
+            }
+        }
+    }
+
+    /**
+     * 处理老化模式的状态
+     */
+    private void ageingMode() {
+        if (isEgeingMode && SINGLEITEM_OR_CYCLE_MODE == 1) {
+            // 单项无限循环
+            if (WORK_TIME == -1) {
+                WORK_TIME = 100000000;
+            }
+            TIME = WORK_TIME * Constants.SINGLEITEM_TIMES;
+            ageHandler.postDelayed(runnable, TIME);
+            sendBraodCaseReceiver();
+        } else if (isEgeingMode && SINGLEITEM_OR_CYCLE_MODE == 2) {
+            TIME = Constants.CYCLE_ONE_ACTIVITY_TIMES;
+            ageHandler.postDelayed(runnable, TIME);
+            registerReceiver();
+        } else {
+            sendBraodCaseReceiver();
+        }
+    }
+
+    Handler ageHandler = new Handler();
+    Runnable runnable = new Runnable() {
+
+        @Override
+        public void run() {
+            // handler自带方法实现定时器
+            try {
+                if (SINGLEITEM_OR_CYCLE_MODE == 2) {
+                    Intent ageingIntent = new Intent(MikeTest.this, RingtoneActivity.class);
 //                                     if (FTUtils.isSugar()) {
 //                                             ageingIntent = new Intent(MikeTest.this,MotorTestActivity.class);
 //                                     }
-                                       ageingIntent.putExtra("ageing_mode", true);
-                                       ageingIntent.putExtra("singleitem_or_cycle_mode", SINGLEITEM_OR_CYCLE_MODE);
-                                       ageingIntent.putExtra("work_time", WORK_TIME);
-                                       ageingIntent.putExtra("first_start_service", false);
-                                       startActivity(ageingIntent);
-                               }
-
-                       } catch (Exception e) {
-                               e.printStackTrace();
-                               System.out.println("exception...");
-                       }
-               }
-       };
-
-       private void sendBraodCaseReceiver() {
-               Intent intent = new Intent();
-               intent.setAction("com.android.stopTiming");
-               sendBroadcast(intent);
-       }
-
-       private void registerReceiver() {
-               receiver = new MyReceiver();
-               IntentFilter filter = new IntentFilter();
-               filter.addAction("com.android.stopActivity");
-               registerReceiver(receiver, filter);
-       }
-
-       /**
-        * 获取广播数据
-        *
-        */
-       public class MyReceiver extends BroadcastReceiver {
-               @Override
-               public void onReceive(Context arg0, Intent arg1) {
-                       MikeTest.this.finish();
-               }
-       }
+                    ageingIntent.putExtra("ageing_mode", true);
+                    ageingIntent.putExtra("singleitem_or_cycle_mode", SINGLEITEM_OR_CYCLE_MODE);
+                    ageingIntent.putExtra("work_time", WORK_TIME);
+                    ageingIntent.putExtra("first_start_service", false);
+                    startActivity(ageingIntent);
+                }
+
+            } catch (Exception e) {
+                e.printStackTrace();
+                System.out.println("exception...");
+            }
+        }
+    };
+
+    private void sendBraodCaseReceiver() {
+        Intent intent = new Intent();
+        intent.setAction("com.android.stopTiming");
+        sendBroadcast(intent);
+    }
+
+    private void registerReceiver() {
+        receiver = new MyReceiver();
+        IntentFilter filter = new IntentFilter();
+        filter.addAction("com.android.stopActivity");
+        registerReceiver(receiver, filter);
+    }
+
+    /**
+     * 获取广播数据
+     */
+    public class MyReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context arg0, Intent arg1) {
+            MikeTest.this.finish();
+        }
+    }
 }
index 23bc79b..c1eacc8 100644 (file)
@@ -5,7 +5,7 @@
  *  Creator  :  xuanyang.feng
  *  Date     :  2011/12/1
  *  Comment  :  CIT Test -> HeadSet Test  use  AudioTrack and AudioRecord
- *   
+ *
  */
 package mobile.miki.ageingmode;
 
@@ -27,8 +27,6 @@ import android.os.PowerManager.WakeLock;
 import android.preference.PreferenceManager;
 import android.util.Log;
 import android.view.View;
-import android.widget.ImageButton;
-import android.widget.TextView;
 
 import java.lang.ref.WeakReference;
 
@@ -46,445 +44,443 @@ import mobile.miki.util.FTUtils;
 //import sim.android.mtkcit.R;
 //import sim.android.mtkcit.TestActivity;
 
-public class AgeingMikeTest extends AgeingBaseActivity implements View.OnClickListener{
-       static final String TAG = "AgeingMikeTest";
-       private boolean isRun = false;
-       private boolean isClosing = false;
-       WakeLock mWakeLock;
-       private AudioManager mAudioManager;
-       private RecordThread mRecordThread;
-       int bufferReadResult;
-       ImageButton mRecordButton;
-       TextView txtDescript;
-       byte[]  tmpBuf;
-       public int state = 0;
-       public int mVolume = 0;
-       public int nCurrentMusicVolume;
-       public boolean flag = false;
-       public float LeftVolume;
-       public float RightVolume;
-       private ButtonViewTwo buttonView;
-       boolean running;
-
-       static final int mSourceType = MediaRecorder.AudioSource.MIC;
-
-       static final int SAMPLE_RATE_IN_HZ = 8000;
-
-       static final int channelConfiguration = AudioFormat.CHANNEL_IN_STEREO;
-//     private Button btn_success;
+public class AgeingMikeTest extends AgeingBaseActivity implements View.OnClickListener {
+    static final String TAG = "AgeingMikeTest";
+    private boolean isRun = false;
+    private boolean isClosing = false;
+    WakeLock mWakeLock;
+    private AudioManager mAudioManager;
+    private RecordThread mRecordThread;
+    public int state = 0;
+    public int mVolume = 0;
+    public int nCurrentMusicVolume;
+    public boolean flag = false;
+    public float LeftVolume;
+    public float RightVolume;
+    private ButtonViewTwo buttonView;
+    boolean running;
+
+    static final int mSourceType = MediaRecorder.AudioSource.MIC;
+
+    static final int SAMPLE_RATE_IN_HZ = 8000;
+
+    static final int channelConfiguration = AudioFormat.CHANNEL_IN_STEREO;
+    // private Button btn_success;
 //     private Button btn_fail;
-       static final int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
-       public static final int PCBA_TEST = 0;
-       public static final int MACHINE_TEST = 1;
-       int recBufSize = 0, playBufSize = 0;
-       int mAudioBufferSize;
-       int mAudioBufferSimpleSize;
-       int mRecBufferSimpleSize;
-       VUMeter mVUMeter;
-       AudioRecord mAudioRecord;
-       AudioTrack mAudioTrack;
-       private int j;
-       int sampleRate = 8000;
-       int channelConfig = AudioFormat.CHANNEL_IN_MONO;
-       int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
-       /*final Handler mHandler = new Handler();
-       final Runnable mUpdataResults = new Runnable() {
-               public void run() {
-                       updateUI();
-               }
-       };*/
-       private MyHandler ageingHandler;
-
-       @Override
-       public void onCreate(Bundle icycle) {
-
-               super.onCreate(icycle);
-               MyApplication.getInstance().addActivity(this);
-               setContentView(R.layout.test_mike);
-               Intent intent = getIntent();
-               sendBraodCaseReceiver();
-               registerReceiver();
-               running = false;
-               if (intent != null) {
-                       running = intent.getBooleanExtra("running", false);;
-               }
-               ageingHandler = new MyHandler(this);
-               buttonView = (ButtonViewTwo) findViewById(R.id.btn_set);
-               buttonView.btn_left.setOnClickListener(this);
-               buttonView.btn_right.setOnClickListener(this);
-               buttonView.btn_left.setClickable(false);
-               buttonView.setVisibility(View.GONE);
-               getCameraIntent();
-               ageingMode();
-               initResourceRefs();
-       }
-
-       @Override
-       protected void onResume() {
-               buttonView.setSuccessColor();
-               buttonView.btn_left.setClickable(true);
-               super.onResume();
-       }
-
-       @Override
-       protected void onStart() {
-               super.onStart();
-       }
-
-       private void initResourceRefs() {
-               PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
-               mWakeLock = pm
-                               .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "MicTest");
-               mWakeLock.acquire();
-               mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
-               setVolumeControlStream(AudioManager.STREAM_MUSIC);
-
-               // add_s wangkang 2012.5.3 bug896
-               nCurrentMusicVolume = mAudioManager
-                               .getStreamVolume(AudioManager.STREAM_MUSIC);
-               mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
-                               mAudioManager
-                                               .getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
-
-               // initAudioRecord();
-               initAudioTrack();
-               mVUMeter = (VUMeter) findViewById(R.id.uvMeter);
-               mVUMeter.setVolume(0);
-               mVUMeter.invalidate();
-               mRecordThread = new RecordThread();
-               Log.v(TAG, "initResourceRefs");
-               mRecordThread.start();
-       }
-
-
-       private void initAudioRecord() {
-               Log.v(TAG, "initAudioRecord");
-
-               recBufSize = 2 * AudioRecord.getMinBufferSize(SAMPLE_RATE_IN_HZ,
-                               channelConfiguration, audioEncoding);
-
-               mAudioBufferSimpleSize = recBufSize / 2;
-               mAudioRecord = new AudioRecord(mSourceType, SAMPLE_RATE_IN_HZ,
-                               channelConfiguration, audioFormat, recBufSize);
-               int audioRecordState = mAudioRecord.getState();
-               if (audioRecordState != AudioRecord.STATE_INITIALIZED) {
-                       Log.v(TAG, "AudioRecord is initialized");
-                       finish();
-               }
-       }
-
-       private void initAudioTrack() {
-               Log.v(TAG, "initAudioTrack");
-
-               playBufSize = 2 * AudioTrack.getMinBufferSize(SAMPLE_RATE_IN_HZ,
-                               channelConfiguration, audioEncoding);
-
-               mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
-                               SAMPLE_RATE_IN_HZ, channelConfiguration, audioFormat,
-                               playBufSize, AudioTrack.MODE_STREAM);
-               int audioTrackState = mAudioTrack.getState();
-               if (audioTrackState != AudioTrack.STATE_INITIALIZED) {
-                       Log.v(TAG, "AudioTrack is initialized");
-                       finish();
-               }
-               initAudioRecord();
-       }
-
-       short[] audioBuffer;
-
-       class RecordThread extends Thread {
-
-               public RecordThread() {
-                       super();
-               }
-
-               public void run() {
-                       Log.d("CIT", "Run");
-                       super.run();
-
-                       if (mAudioRecord == null)
-                               return;
-                       audioBuffer = new short[mAudioBufferSimpleSize];
-                       mAudioRecord.startRecording();
-                       int audioRecordState = mAudioRecord.getRecordingState();
-                       if (audioRecordState != AudioRecord.RECORDSTATE_RECORDING) {
-                               Log.v(TAG, "not recording");
-                               return;
-                       } else {
-                               Log.v(TAG, "start recording");
-
-                       }
-                       
-                       if (mAudioTrack == null)
-                               return;
-                       mAudioTrack.play();
-                       int audioTracktate = mAudioTrack.getPlayState();
-                       if (audioTracktate != AudioTrack.PLAYSTATE_PLAYING) {
-                               Log.v(TAG, "not playing");
-                               return;
-
-                       }
-
-                       Log.v(TAG, "start playing");
-                       mAudioTrack.setStereoVolume(1.0f, 1.0f);
-                       isRun = true;
-                       while (isRun) {
-                               int sampleRate = mAudioRecord.read(audioBuffer, 0,
-                                               mAudioBufferSimpleSize);
-                               if (mAudioBufferSimpleSize < 0) {
-                                       mAudioBufferSimpleSize = 0;
-                               }
-                               
-                               if ((mAudioTrack != null) && (!isClosing))
-                                       try {
-                                               mAudioTrack.write(audioBuffer, 0, mAudioBufferSimpleSize);
-                                       } catch (Exception e) {
-                                               // TODO: handle exception
-                                               e.printStackTrace();
-                                       }
-                                       
-
-                               int v = 0;
-                               for (int i = 0; i < audioBuffer.length; i++) {
-                                       v += audioBuffer[i] * audioBuffer[i];
-                               }
-                               mVolume = v / (50 * (sampleRate + 1));
-                               Log.v(TAG, "mVolume=" + mVolume);
-                               j++;
-                               if (j < 5) {
-                                       mVolume = 20;
-                               }
+    static final int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
+    public static final int PCBA_TEST = 0;
+    public static final int MACHINE_TEST = 1;
+    int recBufSize = 0, playBufSize = 0;
+    int mAudioBufferSize;
+    int mAudioBufferSimpleSize;
+    int mRecBufferSimpleSize;
+    VUMeter mVUMeter;
+    AudioRecord mAudioRecord;
+    AudioTrack mAudioTrack;
+    private int j;
+    int sampleRate = 8000;
+    int channelConfig = AudioFormat.CHANNEL_IN_MONO;
+    int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
+    /*final Handler mHandler = new Handler();
+    final Runnable mUpdataResults = new Runnable() {
+        public void run() {
+            updateUI();
+        }
+    };*/
+    private MyHandler ageingHandler;
+
+    @Override
+    public void onCreate(Bundle icycle) {
+
+        super.onCreate(icycle);
+        MyApplication.getInstance().addActivity(this);
+        setContentView(R.layout.test_mike);
+        Intent intent = getIntent();
+        sendBraodCaseReceiver();
+        registerReceiver();
+        running = false;
+        if (intent != null) {
+            running = intent.getBooleanExtra("running", false);
+            ;
+        }
+        ageingHandler = new MyHandler(this);
+        buttonView = (ButtonViewTwo) findViewById(R.id.btn_set);
+        buttonView.btn_left.setOnClickListener(this);
+        buttonView.btn_right.setOnClickListener(this);
+        buttonView.btn_left.setClickable(false);
+        buttonView.setVisibility(View.GONE);
+        getCameraIntent();
+        ageingMode();
+        initResourceRefs();
+    }
+
+    @Override
+    protected void onResume() {
+        buttonView.setSuccessColor();
+        buttonView.btn_left.setClickable(true);
+        super.onResume();
+    }
+
+    @Override
+    protected void onStart() {
+        super.onStart();
+    }
+
+    private void initResourceRefs() {
+        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+        mWakeLock = pm
+                .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "MicTest");
+        mWakeLock.acquire();
+        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+        setVolumeControlStream(AudioManager.STREAM_MUSIC);
+
+        // add_s wangkang 2012.5.3 bug896
+        nCurrentMusicVolume = mAudioManager
+                .getStreamVolume(AudioManager.STREAM_MUSIC);
+        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
+                mAudioManager
+                        .getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
+
+        // initAudioRecord();
+        initAudioTrack();
+        mVUMeter = (VUMeter) findViewById(R.id.uvMeter);
+        mVUMeter.setVolume(0);
+        mVUMeter.invalidate();
+        mRecordThread = new RecordThread();
+        Log.v(TAG, "initResourceRefs");
+        mRecordThread.start();
+    }
+
+
+    private void initAudioRecord() {
+        Log.v(TAG, "initAudioRecord");
+
+        recBufSize = 2 * AudioRecord.getMinBufferSize(SAMPLE_RATE_IN_HZ,
+                channelConfiguration, audioEncoding);
+
+        mAudioBufferSimpleSize = recBufSize / 2;
+        mAudioRecord = new AudioRecord(mSourceType, SAMPLE_RATE_IN_HZ,
+                channelConfiguration, audioFormat, recBufSize);
+        int audioRecordState = mAudioRecord.getState();
+        if (audioRecordState != AudioRecord.STATE_INITIALIZED) {
+            Log.v(TAG, "AudioRecord is initialized");
+            finish();
+        }
+    }
+
+    private void initAudioTrack() {
+        Log.v(TAG, "initAudioTrack");
+
+        playBufSize = 2 * AudioTrack.getMinBufferSize(SAMPLE_RATE_IN_HZ,
+                channelConfiguration, audioEncoding);
+
+        mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
+                SAMPLE_RATE_IN_HZ, channelConfiguration, audioFormat,
+                playBufSize, AudioTrack.MODE_STREAM);
+        int audioTrackState = mAudioTrack.getState();
+        if (audioTrackState != AudioTrack.STATE_INITIALIZED) {
+            Log.v(TAG, "AudioTrack is initialized");
+            finish();
+        }
+        initAudioRecord();
+    }
+
+    short[] audioBuffer;
+
+    class RecordThread extends Thread {
+
+        public RecordThread() {
+            super();
+        }
+
+        public void run() {
+            Log.d("CIT", "Run");
+            super.run();
+
+            if (mAudioRecord == null)
+                return;
+            audioBuffer = new short[mAudioBufferSimpleSize];
+            mAudioRecord.startRecording();
+            int audioRecordState = mAudioRecord.getRecordingState();
+            if (audioRecordState != AudioRecord.RECORDSTATE_RECORDING) {
+                Log.v(TAG, "not recording");
+                return;
+            } else {
+                Log.v(TAG, "start recording");
+
+            }
+
+            if (mAudioTrack == null)
+                return;
+            mAudioTrack.play();
+            int audioTracktate = mAudioTrack.getPlayState();
+            if (audioTracktate != AudioTrack.PLAYSTATE_PLAYING) {
+                Log.v(TAG, "not playing");
+                return;
+
+            }
+
+            Log.v(TAG, "start playing");
+            mAudioTrack.setStereoVolume(1.0f, 1.0f);
+            isRun = true;
+            while (isRun) {
+                int sampleRate = mAudioRecord.read(audioBuffer, 0,
+                        mAudioBufferSimpleSize);
+                if (mAudioBufferSimpleSize < 0) {
+                    mAudioBufferSimpleSize = 0;
+                }
+
+                if ((mAudioTrack != null) && (!isClosing))
+                    try {
+                        mAudioTrack.write(audioBuffer, 0, mAudioBufferSimpleSize);
+                    } catch (Exception e) {
+                        // TODO: handle exception
+                        e.printStackTrace();
+                    }
+
+
+                int v = 0;
+                for (int i = 0; i < audioBuffer.length; i++) {
+                    v += audioBuffer[i] * audioBuffer[i];
+                }
+                mVolume = v / (50 * (sampleRate + 1));
+                Log.v(TAG, "mVolume=" + mVolume);
+                j++;
+                if (j < 5) {
+                    mVolume = 20;
+                }
 //                             mHandler.post(mUpdataResults);
-                               if (ageingHandler != null) {
+                if (ageingHandler != null) {
 //                                     ageingHandler.sendEmptyMessage(2);
-                               }
-                       }
+                }
+            }
 
 //                     finish();
 
-               }
-
-               public void pause() {
-                       isRun = false;
-               }
-
-               public void start() {
-                       if (!isRun) {
-                               super.start();
-                       }
-               }
-
-       }
-
-       @Override
-       public void onStop() {
-               releaseRec();
-               super.onStop();
-       }
-
-       private void releaseRec() {
-               if (mAudioManager != null) {
-                       //mod_s wangkang 2012.5.3       bug896
-                       mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
-                                       nCurrentMusicVolume, 0);
-                       //mod_s wangkang 2012.5.3       bug896
-               }
-               if (mAudioTrack != null) {
-                       mAudioTrack.release();
-
-               }
-               if (mAudioRecord != null) {
-                       mAudioRecord.release();
-
-               }
-               isRun = false;
-
-       }
-
-       @Override
-       public void onDestroy() {
-               if(mRecordThread != null){
-                       mRecordThread.pause();
-                       mRecordThread = null;
-               }
-               if(ageingHandler != null) {
-                       ageingHandler.removeCallbacksAndMessages(null);
-                       ageingHandler = null;
-               }
-               if (receiver != null) {
-                       unregisterReceiver(receiver);
-               }
-
-               if(mWakeLock != null) {
-                       //取消屏幕常亮,onPause()方法中执行
-                       mWakeLock.release();
-                       mWakeLock = null;
-               }
-
-               if(handler != null) {
-                       handler.removeCallbacksAndMessages(handler.obtainMessage());
-               }
-               super.onDestroy();
-       }
-
-       private void updateUI() {
-               
+        }
+
+        public void pause() {
+            isRun = false;
+        }
+
+        public void start() {
+            if (!isRun) {
+                super.start();
+            }
+        }
+
+    }
+
+    @Override
+    public void onStop() {
+        releaseRec();
+        super.onStop();
+    }
+
+    private void releaseRec() {
+        if (mAudioManager != null) {
+            //mod_s wangkang 2012.5.3  bug896
+            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
+                    nCurrentMusicVolume, 0);
+            //mod_s wangkang 2012.5.3  bug896
+        }
+        if (mAudioTrack != null) {
+            mAudioTrack.release();
+
+        }
+        if (mAudioRecord != null) {
+            mAudioRecord.release();
+
+        }
+        isRun = false;
+
+    }
+
+    @Override
+    public void onDestroy() {
+        if (mRecordThread != null) {
+            mRecordThread.pause();
+            mRecordThread = null;
+        }
+        if (ageingHandler != null) {
+            ageingHandler.removeCallbacksAndMessages(null);
+            ageingHandler = null;
+        }
+        if (receiver != null) {
+            unregisterReceiver(receiver);
+        }
+
+        if (mWakeLock != null) {
+            //取消屏幕常亮,onPause()方法中执行
+            mWakeLock.release();
+            mWakeLock = null;
+        }
+
+        if (handler != null) {
+            handler.removeCallbacksAndMessages(handler.obtainMessage());
+        }
+        super.onDestroy();
+    }
+
+    private void updateUI() {
+
 //             Log.i("MikeTest000", "updateUI(), mVolume=" + mVolume);
-               
-               mVUMeter.setVolume(mVolume);
-               if ((!flag) && (mVolume > 3000)) {
+
+        mVUMeter.setVolume(mVolume);
+        if ((!flag) && (mVolume > 3000)) {
 //                     btn_success.setEnabled(true);
-                       flag = true;
-               }
-       }
-       
+            flag = true;
+        }
+    }
+
 
     @Override
-       public void onClick(View arg0) {
-               Intent intent = new Intent(this, SimDetectActivity.class);
-               intent.putExtra("running", true);
-               Intent intent1 = new Intent(this, TestMainActivity.class);
-               // TestResult testResult = (TestResult) getApplicationContext();
-               switch (arg0.getId()) {
-
-               case R.id.btn_two_left:
-                       if (!running) {
-                               startActivity(intent1);
-                       } else {
-                               startActivity(intent);
-                       }
-                       PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("mic", "true")
-                                       .commit();
-                       finish();
-                       break;
-               case R.id.btn_two_right:
-                       if (!running) {
-                               startActivity(intent1);
-                       } else {
-                               startActivity(intent);
-                       }
-                       PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("mic", "false")
-                                       .commit();
-                       finish();
-                       break;
-               }
-       }
-    
+    public void onClick(View arg0) {
+        Intent intent = new Intent(this, SimDetectActivity.class);
+        intent.putExtra("running", true);
+        Intent intent1 = new Intent(this, TestMainActivity.class);
+        // TestResult testResult = (TestResult) getApplicationContext();
+        switch (arg0.getId()) {
+
+            case R.id.btn_two_left:
+                if (!running) {
+                    startActivity(intent1);
+                } else {
+                    startActivity(intent);
+                }
+                PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("mic", "true")
+                        .commit();
+                finish();
+                break;
+            case R.id.btn_two_right:
+                if (!running) {
+                    startActivity(intent1);
+                } else {
+                    startActivity(intent);
+                }
+                PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString("mic", "false")
+                        .commit();
+                finish();
+                break;
+        }
+    }
+
     @Override
-       public void onBackPressed() {
-               // super.onBackPressed();
-               if (running) {
-                       Intent intent = new Intent(this, TestMainList.class);
-                       startActivity(intent);
-                       finish();
-               } else {
-                       finish();
-               }
-       }
-
-       boolean isEgeingMode = false;
-       private int TIME = 1000 * 10;
-       private int SINGLEITEM_OR_CYCLE_MODE;
-       private int WORK_TIME;
-       private MyReceiver receiver=null;
-
-       private void getCameraIntent() {
-               Intent intent = getIntent();
-               if (intent != null) {
-                       try {
-                               isEgeingMode = intent.getBooleanExtra("ageing_mode", false);
-                               SINGLEITEM_OR_CYCLE_MODE = intent.getIntExtra("singleitem_or_cycle_mode", 0);
-                               WORK_TIME = intent.getIntExtra("work_time", 0);
-                       } catch (Exception e) {
-                               e.printStackTrace();
-
-                       }
-               }
-       }
-       /**
-        * 处理老化模式的状态
-        */
-       private void ageingMode() {
-               if(isEgeingMode && SINGLEITEM_OR_CYCLE_MODE == 1) {
-                       // 单项无限循环
-                       if (WORK_TIME == -1) {
-                               WORK_TIME = 100000000;
-                       }
-                       TIME = WORK_TIME * Constants.SINGLEITEM_TIMES;
-                       ageingHandler.sendEmptyMessageDelayed(1, TIME);
+    public void onBackPressed() {
+        // super.onBackPressed();
+        if (running) {
+            Intent intent = new Intent(this, TestMainList.class);
+            startActivity(intent);
+            finish();
+        } else {
+            finish();
+        }
+    }
+
+    boolean isEgeingMode = false;
+    private int TIME = 1000 * 10;
+    private int SINGLEITEM_OR_CYCLE_MODE;
+    private int WORK_TIME;
+    private MyReceiver receiver = null;
+
+    private void getCameraIntent() {
+        Intent intent = getIntent();
+        if (intent != null) {
+            try {
+                isEgeingMode = intent.getBooleanExtra("ageing_mode", false);
+                SINGLEITEM_OR_CYCLE_MODE = intent.getIntExtra("singleitem_or_cycle_mode", 0);
+                WORK_TIME = intent.getIntExtra("work_time", 0);
+            } catch (Exception e) {
+                e.printStackTrace();
+
+            }
+        }
+    }
+
+    /**
+     * 处理老化模式的状态
+     */
+    private void ageingMode() {
+        if (isEgeingMode && SINGLEITEM_OR_CYCLE_MODE == 1) {
+            // 单项无限循环
+            if (WORK_TIME == -1) {
+                WORK_TIME = 100000000;
+            }
+            TIME = WORK_TIME * Constants.SINGLEITEM_TIMES;
+            ageingHandler.sendEmptyMessageDelayed(1, TIME);
 //                     sendBraodCaseReceiver();
-               } else if (isEgeingMode && SINGLEITEM_OR_CYCLE_MODE == 2) {
-                       TIME = Constants.CYCLE_ONE_ACTIVITY_TIMES;
-                       ageingHandler.sendEmptyMessageDelayed(1, TIME);
+        } else if (isEgeingMode && SINGLEITEM_OR_CYCLE_MODE == 2) {
+            TIME = Constants.CYCLE_ONE_ACTIVITY_TIMES;
+            ageingHandler.sendEmptyMessageDelayed(1, TIME);
 //                     registerReceiver();
-               } else {
+        } else {
 //                     sendBraodCaseReceiver();
-               }
-       }
-
-
-       private void sendBraodCaseReceiver() {
-               Intent intent = new Intent();
-               intent.setAction("com.android.stopCameraActivity");
-               sendBroadcast(intent);
-       }
-
-       private void registerReceiver() {
-               receiver = new MyReceiver();
-               IntentFilter filter = new IntentFilter();
-               filter.addAction("com.android.stopMicActivity");
-               registerReceiver(receiver, filter);
-       }
-
-       /**
-        * 获取广播数据
-        *
-        */
-       public class MyReceiver extends BroadcastReceiver {
-               @Override
-               public void onReceive(Context arg0, Intent arg1) {
-                       AgeingMikeTest.this.finish();
-               }
-       }
-
-       class MyHandler extends Handler {
-               WeakReference<Activity > mActivityReference;
-
-               MyHandler(Activity activity) {
-                       mActivityReference= new WeakReference<Activity>(activity);
-               }
-               @Override
-               public void handleMessage(Message msg) {
-                       final Activity activity = mActivityReference.get();
-                       if (activity != null) {
-                               switch (msg.what) {
-                                       case 1:
-                                               try {
-                                                       if(SINGLEITEM_OR_CYCLE_MODE == 2) {
-                                                               Intent ageingIntent = new Intent(AgeingMikeTest.this,AgeingRingtoneActivity.class);
-                                                               if (FTUtils.isSugar()) {
-                                                                       ageingIntent = new Intent(AgeingMikeTest.this,AgeingMotorTestActivity.class);
-                                                               }
-                                                               ageingIntent.putExtra("ageing_mode", true);
-                                                               ageingIntent.putExtra("singleitem_or_cycle_mode", SINGLEITEM_OR_CYCLE_MODE);
-                                                               ageingIntent.putExtra("work_time", WORK_TIME);
-                                                               ageingIntent.putExtra("first_start_service", false);
-                                                               startActivity(ageingIntent);
-                                                       } else {
-                                                               finish();
-                                                       }
-                                               } catch (Exception e) {
-                                                       e.printStackTrace();
-                                                       System.out.println("exception...");
-                                               }
-                                               break;
-
-                                       case 2:
-                                               updateUI();
-                                               break;
-                               }
-
-                       }
-               }
-       }
+        }
+    }
+
+
+    private void sendBraodCaseReceiver() {
+        Intent intent = new Intent();
+        intent.setAction("com.android.stopCameraActivity");
+        sendBroadcast(intent);
+    }
+
+    private void registerReceiver() {
+        receiver = new MyReceiver();
+        IntentFilter filter = new IntentFilter();
+        filter.addAction("com.android.stopMicActivity");
+        registerReceiver(receiver, filter);
+    }
+
+    /**
+     * 获取广播数据
+     */
+    public class MyReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context arg0, Intent arg1) {
+            AgeingMikeTest.this.finish();
+        }
+    }
+
+    class MyHandler extends Handler {
+        WeakReference<Activity> mActivityReference;
+
+        MyHandler(Activity activity) {
+            mActivityReference = new WeakReference<Activity>(activity);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            final Activity activity = mActivityReference.get();
+            if (activity != null) {
+                switch (msg.what) {
+                    case 1:
+                        try {
+                            if (SINGLEITEM_OR_CYCLE_MODE == 2) {
+                                Intent ageingIntent = new Intent(AgeingMikeTest.this, AgeingRingtoneActivity.class);
+                                if (FTUtils.isSugar()) {
+                                    ageingIntent = new Intent(AgeingMikeTest.this, AgeingMotorTestActivity.class);
+                                }
+                                ageingIntent.putExtra("ageing_mode", true);
+                                ageingIntent.putExtra("singleitem_or_cycle_mode", SINGLEITEM_OR_CYCLE_MODE);
+                                ageingIntent.putExtra("work_time", WORK_TIME);
+                                ageingIntent.putExtra("first_start_service", false);
+                                startActivity(ageingIntent);
+                            } else {
+                                finish();
+                            }
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                            System.out.println("exception...");
+                        }
+                        break;
+
+                    case 2:
+                        updateUI();
+                        break;
+                }
+
+            }
+        }
+    }
 }
index e4df103..aca37a3 100644 (file)
@@ -1,15 +1,12 @@
 package mobile.miki;\r
 \r
 import android.content.Context;\r
-import android.os.Build;\r
 import android.os.Bundle;\r
 import android.os.SystemProperties;\r
 import android.util.Log;\r
 import android.view.MotionEvent;\r
 import android.view.View;\r
 import android.widget.Button;\r
-import android.widget.ImageButton;\r
-import android.widget.Toast;\r
 \r
 import java.lang.reflect.Method;\r
 \r
index 8e501f8..c1fc1a3 100644 (file)
         android:layout_marginRight="2.0dip"\r
         android:layout_marginBottom="2.0dip">\r
 \r
-        <ImageButton\r
+        <Button\r
             android:id="@+id/btn_no"\r
             android:layout_width="90dp"\r
             android:layout_height="48dp"\r
             android:layout_alignParentLeft="true"\r
             android:background="@drawable/button_no_s09" />\r
 \r
-        <ImageButton\r
+        <Button\r
             android:id="@+id/btn_yes"\r
             android:layout_width="90dp"\r
             android:layout_height="48dp"\r