@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_logout: // 退出登录 logout(); break; case R.id.layout_help_instructions: // 帮助说明 Intent intent = new Intent(SettingsActivity.this, HelpActivity.class); startActivity(intent); break; case R.id.layout_cache_clear: boolean isDeleted = FileUtil.deleteDirFromSD( Environment.getExternalStorageDirectory().getAbsolutePath() + "/.truelove2"); if (isDeleted) { showToast("缓存已清除"); // mTvCacheSize.setText((int) // (FileUtil.getDirSize(Environment.getExternalStorageDirectory().getAbsolutePath() + // "/.truelove2") / 1024.0f) + "kb"); mTvCacheSize.setText( String.format( "%.2f", (FileUtil.getDirSize( Environment.getExternalStorageDirectory().getAbsolutePath() + "/.truelove2") / 1024.0f / 1024)) + "mb"); } break; } }
private void init() { readAndSetTopBackgroundColor(); TextView tvTopTitle = (TextView) findViewById(R.id.layout_nav_top).findViewById(R.id.tv_top_title); tvTopTitle.setText("设置"); TextView tvTopAction = (TextView) findViewById(R.id.layout_nav_top).findViewById(R.id.tv_top_action); tvTopAction.setText(""); tvTopAction.setVisibility(View.GONE); TextView tvCurrentVersion = getViewById(R.id.tv_current_version); // 当前版本 tvCurrentVersion.setText("v" + ActivityUtil.getVersionName(this)); // 立即检查更新 getViewById(R.id.layout_checkupdate) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub checkUpdate(); } private void checkUpdate() { // TODO Auto-generated method stub final AlertDialog dialog = new AlertDialog.Builder(SettingsActivity.this).create(); dialog.setMessage(""); dialog.setTitle("检查新版本中,请稍候..."); dialog.show(); CheckUpdateParams params = new CheckUpdateParams(); params.currentVersion = ActivityUtil.getVersionCode(SettingsActivity.this); AppServiceImpl.getInstance() .checkUpdate( params, new OnCheckUpdateListener() { @Override public void onSuccess(CheckUpdateVersion v) { // TODO Auto-generated method stub dialog.dismiss(); if (v != null) { // Intent intent = new Intent(SettingsActivity.this, // CheckUpdateActivity.class); // Bundle bundle = new Bundle(); // bundle.putSerializable("updateVersion", v); // intent.putExtras(bundle); // startActivity(intent); mUpdateVersion = v; showDownloadDialog(); } else { showToast("当前已是最新版本"); } } @Override public void onFailure(String errormsg) { // TODO Auto-generated method stub dialog.dismiss(); showToast("连接超时"); } }); }; }); // 配置颜色 findViewById(R.id.layout_settings_color) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(SettingsActivity.this, ColorSettingsActivity.class); startActivity(intent); } }); final SharedPreferences sp = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE); final CheckBox cbVibrator = (CheckBox) findViewById(R.id.cb_vibrator_switch); cbVibrator.setChecked(sp.getBoolean(USE_VIBRATOR_WHEN_NEWMSG, true)); // 新提醒时震动 findViewById(R.id.layout_settings_vibrator) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub cbVibrator.setChecked(!cbVibrator.isChecked()); sp.edit().putBoolean(USE_VIBRATOR_WHEN_NEWMSG, cbVibrator.isChecked()).commit(); } }); // 捐助我 findViewById(R.id.layout_offerme) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // Intent intent = new Intent(SettingsActivity.this, OffermeActivity.class); // startActivity(intent); View view = findViewById(R.id.layout_offerme_container); if (view.getVisibility() == View.VISIBLE) { view.setVisibility(View.GONE); findViewById(R.id.tv_offerme_label).setVisibility(View.VISIBLE); } else { view.setVisibility(View.VISIBLE); findViewById(R.id.tv_offerme_label).setVisibility(View.GONE); } } }); // 默认隐藏支付输入框 findViewById(R.id.layout_offerme_container).setVisibility(View.GONE); // 输入捐助金额 final EditText etOffermeMoney = getViewById(R.id.et_offerme_money); // 进入支付 final TextView tvEnterPay = getViewById(R.id.tv_enter_offerme); // 取消支付 final TextView tvEnterPayCancle = getViewById(R.id.tv_enter_offerme_cancle); tvEnterPayCancle.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub findViewById(R.id.layout_offerme_container).setVisibility(View.GONE); findViewById(R.id.tv_offerme_label).setVisibility(View.VISIBLE); } }); etOffermeMoney.addTextChangedListener( new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if (etOffermeMoney.getText().toString().trim().length() != 0) { tvEnterPay.setVisibility(View.VISIBLE); } else { tvEnterPay.setVisibility(View.GONE); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); tvEnterPay.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (etOffermeMoney.getText().toString().trim().length() == 0) { showToast("请输入捐助金额"); return; } // TODO Auto-generated method stub PayConnect.getInstance( "8025cff144f83cf6252bd92eaf0ce588", "WAPS", SettingsActivity.this); String orderId = "truelove2" + StringUtils.md5(System.currentTimeMillis() + ""); // 用户标识 String userId = MyApplication.getInstance().getCurrentLoginedUser().getUserId() + ""; // 支付商品名称 String goodsName = "捐助 恋恋"; // 支付金额 float price = Float.parseFloat(etOffermeMoney.getText().toString()) * 1.0f; // 支付时间 String time = ""; // 支付描述 String goodsDesc = "捐助 恋恋"; // 应用或游戏商服务器端回调接口(无服务器可不填写) String notifyUrl = Constants.URL_VIP_NOTIFY; PayConnect.getInstance(SettingsActivity.this) .pay( SettingsActivity.this, orderId, userId, price, goodsName, goodsDesc, notifyUrl, new PayResultListener() { @Override public void onPayFinish( Context payViewContext, String orderId, int resultCode, String resultString, int payType, float amount, String goodsName) { // TODO Auto-generated method stub // showToast(resultString); if (resultCode == 0) { showToast("捐助成功,感谢您的大力支持!"); } else { showToast("支付失败," + resultString + "请再试一次"); } } }); } }); // 帮助说明 findViewById(R.id.layout_help_instructions).setOnClickListener(this); // 清除缓存 findViewById(R.id.layout_cache_clear).setOnClickListener(this); // 缓存文件size mTvCacheSize = getViewById(R.id.tv_cache_size); mTvCacheSize.setText( String.format( "%.2f", (FileUtil.getDirSize( Environment.getExternalStorageDirectory().getAbsolutePath() + "/.truelove2") / 1024.0f / 1024)) + "mb"); // 退出登录 Button btnLogout = (Button) findViewById(R.id.btn_logout); btnLogout.setOnClickListener(this); }