long[] mHits = new long[3];
long[] mHits5 = new long[5];
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (preference.getKey().equals(KEY_SERIAL_NUMBER)) {
Log.e(LOG_TAG, "zhanbing.li");
System.arraycopy(mHits, 1, mHits, 0, mHits.length-1);
mHits[mHits.length-1] = SystemClock.uptimeMillis();
if (mHits[0] >= (SystemClock.uptimeMillis()-500)) {
ComponentName toActivity = new ComponentName("com.test.pcbatest","com.test.pcbatest.PcbaTestActivity");
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(toActivity);
intent.setAction("android.intent.action.VIEW");
try {
startActivity(intent);
} catch (Exception e) {
Log.e(LOG_TAG, "Unable to start activity " + intent.toString());
}
}
} else if (preference.getKey().equals(KEY_GAUGE_VERSION)) {
Log.e(LOG_TAG, "zhanbing.li Gauge three clicks");
System.arraycopy(mHits5, 1, mHits5, 0, mHits5.length-1);
mHits5[mHits5.length-1] = SystemClock.uptimeMillis();
if (mHits5[0] >= (SystemClock.uptimeMillis()-1000)) {
if (!mBatteryCharging) {
File writeGaugeFile = new File("/sys/power/wakeups/needtoreset_gauge");
FileWriter fr;
int reboot_flag = 0;
try{
fr = new FileWriter(writeGaugeFile);
fr.write("1");
Log.e(LOG_TAG, "/************************* reset gauge write success ***************************/\n");
fr.close();
reboot_flag = 1;
} catch (IOException e) {
e.printStackTrace();
}
if (reboot_flag == 1){
Toast.makeText(Status.this, "Reset gauge sucess, system will restart", Toast.LENGTH_LONG).show();
Log.e(LOG_TAG, "/***********************start to reboot ***************************/\n");
Intent intent = new Intent(Intent.ACTION_REBOOT);
intent.putExtra("nowait", 1);
intent.putExtra("interval", 1);
intent.putExtra("window", 0);
sendBroadcast(intent);
} else {
Log.e(LOG_TAG, "fail to reset gauge\n");
}
} else {
Toast.makeText(Status.this, "Please remove your DC or Usb first!", Toast.LENGTH_SHORT).show();
}
}
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}