@Override public void onBackPressed() { if (System.currentTimeMillis() - firstTime < 3000) { finish(); } else { firstTime = System.currentTimeMillis(); T.showShort(this, R.string.press_again_exit); } }
@Override public void onClick(View v) { Intent mIntent; L.d("onClick", "click"); switch (v.getId()) { case R.id.setting_timeservice: L.d("settiong serivce"); initTnp(); break; case R.id.citysetting: mIntent = new Intent(MainActivity.this, SelectCtiyActivity.class); startActivity(mIntent); break; case R.id.cityName: mIntent = new Intent(MainActivity.this, WheatherActivity.class); startActivity(mIntent); break; case R.id.timesetting: if (!timeoutFlag) { if (!setTime(ntpTrustedTime.currentTimeMillis())) { Toast.makeText(MainActivity.this, "应用未获得ROOT权限", Toast.LENGTH_SHORT).show(); // Intent intent = new Intent("/"); // ComponentName cm = new ComponentName( // "com.android.settings", // "com.android.settings.DateTimeSettingsSetupWizard"); // intent.setComponent(cm); // intent.setAction("android.intent.action.VIEW"); // startActivityForResult(intent, 0); // Intent floatIntent = new Intent(MainActivity.this, // FxService.class); // startService(floatIntent); } // cancelTimer(); // wakeupTimer(); // mTimerTaskNet.cancel(); // initThread(); } else { Toast.makeText(MainActivity.this, "网络连接失败,无法对时", Toast.LENGTH_SHORT).show(); } break; case R.id.setTimeZone: dlg = new AlertDialog.Builder(MainActivity.this).create(); dlg.show(); View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog, null); dlg.getWindow().setContentView(view); ListView lv = (ListView) view.findViewById(R.id.lv); lv.setAdapter(new TimeZoneAdapter(MainActivity.this, timeZoneList)); break; case R.id.lv_sync: if (exitValue != 0) { T.show(getApplicationContext(), "该手机没有root权限", Toast.LENGTH_SHORT); } else { if (BaseApplication.isOpen) { lv_sync.setImageResource(R.drawable.sync_close); mIntent = new Intent(MainActivity.this, SyncService.class); stopService(mIntent); } else { lv_sync.setImageResource(R.drawable.sync_open); mIntent = new Intent(MainActivity.this, SyncService.class); startService(mIntent); } } break; case R.id.settime_frequent: dlg = new AlertDialog.Builder(MainActivity.this).create(); dlg.show(); View viewfrequent = LayoutInflater.from(MainActivity.this).inflate(R.layout.frequent, null); dlg.getWindow().setContentView(viewfrequent); ListView lvfrequent = (ListView) viewfrequent.findViewById(R.id.lv); lvfrequent.setAdapter(new TimeFrequentAdapter(MainActivity.this, timeFrequentList)); break; case R.id.background: dlg = new AlertDialog.Builder(MainActivity.this).create(); dlg.show(); View viewBackground = LayoutInflater.from(MainActivity.this).inflate(R.layout.background, null); dlg.getWindow().setContentView(viewBackground); ListView lvBackground = (ListView) viewBackground.findViewById(R.id.lv); lvBackground.setAdapter(new BackgroundAdapter(MainActivity.this, backgroundList)); break; case R.id.setting: scrollToMenu(); break; case R.id.notice: dlg = new AlertDialog.Builder(MainActivity.this).create(); dlg.show(); View viewNotice = LayoutInflater.from(MainActivity.this).inflate(R.layout.notice, null); dlg.getWindow().setContentView(viewNotice); break; case R.id.serverSetting: dlg = new AlertDialog.Builder(MainActivity.this).create(); dlg.show(); dlg.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); View viewServerSetting = LayoutInflater.from(MainActivity.this).inflate(R.layout.serversetting, null); dlg.getWindow().setContentView(viewServerSetting); break; case R.id.news: mIntent = new Intent(MainActivity.this, NewsListActivity.class); startActivity(mIntent); break; case R.id.openweb: Uri uri = Uri.parse("http://www.time.ac.cn/"); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); break; case R.id.uncached_ntp_time_button: refreshTime(); break; default: break; } }