1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.email.activity.setup; 18 19 import com.android.email.Email; 20 import com.android.email.Preferences; 21 import com.android.email.R; 22 import com.android.email.activity.UiUtilities; 23 import com.android.email.service.EmailServiceUtils; 24 import com.android.email.service.MailService; 25 import com.android.emailcommon.Logging; 26 27 import android.app.Fragment; 28 import android.content.Context; 29 import android.os.Bundle; 30 import android.util.Log; 31 import android.view.LayoutInflater; 32 import android.view.View; 33 import android.view.ViewGroup; 34 import android.webkit.WebView; 35 import android.widget.CheckBox; 36 import android.widget.CompoundButton; 37 import android.widget.CompoundButton.OnCheckedChangeListener; 38 import android.widget.TextView; 39 40 public class DebugFragment extends Fragment implements OnCheckedChangeListener, 41 View.OnClickListener { 42 private TextView mVersionView; 43 private CheckBox mEnableDebugLoggingView; 44 private CheckBox mEnableExchangeLoggingView; 45 private CheckBox mEnableExchangeFileLoggingView; 46 private CheckBox mInhibitGraphicsAccelerationView; 47 private CheckBox mForceOneMinuteRefreshView; 48 private CheckBox mEnableStrictModeView; 49 50 private Preferences mPreferences; 51 52 @Override 53 public View onCreateView(LayoutInflater inflater, ViewGroup container, 54 Bundle savedInstanceState) { 55 if (Logging.DEBUG_LIFECYCLE && Email.DEBUG) { 56 Log.d(Logging.LOG_TAG, "AccountSetupBasicsFragment onCreateView"); 57 } 58 View view = inflater.inflate(R.layout.debug, container, false); 59 60 Context context = getActivity(); 61 mPreferences = Preferences.getPreferences(context); 62 63 mVersionView = (TextView) UiUtilities.getView(view, R.id.version); 64 mVersionView.setText(String.format(context.getString(R.string.debug_version_fmt).toString(), 65 context.getString(R.string.build_number))); 66 67 mEnableDebugLoggingView = (CheckBox) UiUtilities.getView(view, R.id.debug_logging); 68 mEnableDebugLoggingView.setChecked(Email.DEBUG); 69 70 mEnableExchangeLoggingView = (CheckBox) UiUtilities.getView(view, R.id.exchange_logging); 71 mEnableExchangeFileLoggingView = 72 (CheckBox) UiUtilities.getView(view, R.id.exchange_file_logging); 73 74 // Note: To prevent recursion while presetting checkboxes, assign all listeners last 75 mEnableDebugLoggingView.setOnCheckedChangeListener(this); 76 77 boolean exchangeAvailable = EmailServiceUtils.isExchangeAvailable(context); 78 if (exchangeAvailable) { 79 mEnableExchangeLoggingView.setChecked(Email.DEBUG_EXCHANGE_VERBOSE); 80 mEnableExchangeFileLoggingView.setChecked(Email.DEBUG_EXCHANGE_FILE); 81 mEnableExchangeLoggingView.setOnCheckedChangeListener(this); 82 mEnableExchangeFileLoggingView.setOnCheckedChangeListener(this); 83 } else { 84 mEnableExchangeLoggingView.setVisibility(View.GONE); 85 mEnableExchangeFileLoggingView.setVisibility(View.GONE); 86 } 87 88 UiUtilities.getView(view, R.id.clear_webview_cache).setOnClickListener(this); 89 90 mInhibitGraphicsAccelerationView = (CheckBox) 91 UiUtilities.getView(view, R.id.debug_disable_graphics_acceleration); 92 mInhibitGraphicsAccelerationView.setChecked(Email.sDebugInhibitGraphicsAcceleration); 93 mInhibitGraphicsAccelerationView.setOnCheckedChangeListener(this); 94 95 mForceOneMinuteRefreshView = (CheckBox) 96 UiUtilities.getView(view, R.id.debug_force_one_minute_refresh); 97 mForceOneMinuteRefreshView.setChecked(mPreferences.getForceOneMinuteRefresh()); 98 mForceOneMinuteRefreshView.setOnCheckedChangeListener(this); 99 100 mEnableStrictModeView = (CheckBox) 101 UiUtilities.getView(view, R.id.debug_enable_strict_mode); 102 mEnableStrictModeView.setChecked(mPreferences.getEnableStrictMode()); 103 mEnableStrictModeView.setOnCheckedChangeListener(this); 104 105 return view; 106 } 107 108 @Override 109 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 110 switch (buttonView.getId()) { 111 case R.id.debug_logging: 112 mPreferences.setEnableDebugLogging(isChecked); 113 Email.DEBUG = isChecked; 114 Email.DEBUG_EXCHANGE = isChecked; 115 break; 116 case R.id.exchange_logging: 117 mPreferences.setEnableExchangeLogging(isChecked); 118 Email.DEBUG_EXCHANGE_VERBOSE = isChecked; 119 break; 120 case R.id.exchange_file_logging: 121 mPreferences.setEnableExchangeFileLogging(isChecked); 122 Email.DEBUG_EXCHANGE_FILE = isChecked; 123 break; 124 case R.id.debug_disable_graphics_acceleration: 125 Email.sDebugInhibitGraphicsAcceleration = isChecked; 126 mPreferences.setInhibitGraphicsAcceleration(isChecked); 127 break; 128 case R.id.debug_force_one_minute_refresh: 129 mPreferences.setForceOneMinuteRefresh(isChecked); 130 MailService.actionReschedule(getActivity()); 131 break; 132 case R.id.debug_enable_strict_mode: 133 mPreferences.setEnableStrictMode(isChecked); 134 Email.enableStrictMode(isChecked); 135 break; 136 } 137 138 Email.updateLoggingFlags(getActivity()); 139 } 140 141 @Override 142 public void onClick(View v) { 143 switch (v.getId()) { 144 case R.id.clear_webview_cache: 145 clearWebViewCache(); 146 break; 147 } 148 } 149 150 private void clearWebViewCache() { 151 WebView webview = new WebView(getActivity()); 152 try { 153 webview.clearCache(true); 154 Log.w(Logging.LOG_TAG, "Cleard WebView cache."); 155 } finally { 156 webview.destroy(); 157 } 158 } 159 } 160