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 android.app.Fragment; 20 import android.content.Context; 21 import android.os.Bundle; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.webkit.WebView; 26 import android.widget.CheckBox; 27 import android.widget.CompoundButton; 28 import android.widget.CompoundButton.OnCheckedChangeListener; 29 30 import com.android.email.Preferences; 31 import com.android.email.R; 32 import com.android.email.activity.UiUtilities; 33 import com.android.email.service.EmailServiceUtils; 34 import com.android.email2.ui.MailActivityEmail; 35 import com.android.emailcommon.Logging; 36 import com.android.mail.utils.LogUtils; 37 38 public class DebugFragment extends Fragment implements OnCheckedChangeListener, 39 View.OnClickListener { 40 private CheckBox mEnableDebugLoggingView; 41 private CheckBox mEnableVerboseLoggingView; 42 private CheckBox mEnableFileLoggingView; 43 private CheckBox mInhibitGraphicsAccelerationView; 44 private CheckBox mEnableStrictModeView; 45 46 private Preferences mPreferences; 47 48 // Public no-args constructor needed for fragment re-instantiation 49 public DebugFragment() {} 50 51 @Override 52 public View onCreateView(LayoutInflater inflater, ViewGroup container, 53 Bundle savedInstanceState) { 54 if (Logging.DEBUG_LIFECYCLE && MailActivityEmail.DEBUG) { 55 LogUtils.d(Logging.LOG_TAG, "AccountSetupBasicsFragment onCreateView"); 56 } 57 View view = inflater.inflate(R.layout.debug, container, false); 58 59 Context context = getActivity(); 60 mPreferences = Preferences.getPreferences(context); 61 62 mEnableDebugLoggingView = (CheckBox) UiUtilities.getView(view, R.id.debug_logging); 63 mEnableDebugLoggingView.setChecked(MailActivityEmail.DEBUG); 64 65 mEnableVerboseLoggingView = (CheckBox) UiUtilities.getView(view, R.id.verbose_logging); 66 mEnableFileLoggingView = 67 (CheckBox) UiUtilities.getView(view, R.id.file_logging); 68 69 // Note: To prevent recursion while presetting checkboxes, assign all listeners last 70 mEnableDebugLoggingView.setOnCheckedChangeListener(this); 71 72 if (EmailServiceUtils.areRemoteServicesInstalled(context)) { 73 mEnableVerboseLoggingView.setChecked(MailActivityEmail.DEBUG_VERBOSE); 74 mEnableFileLoggingView.setChecked(MailActivityEmail.DEBUG_FILE); 75 mEnableVerboseLoggingView.setOnCheckedChangeListener(this); 76 mEnableFileLoggingView.setOnCheckedChangeListener(this); 77 } else { 78 mEnableVerboseLoggingView.setVisibility(View.GONE); 79 mEnableFileLoggingView.setVisibility(View.GONE); 80 } 81 82 UiUtilities.getView(view, R.id.clear_webview_cache).setOnClickListener(this); 83 84 mInhibitGraphicsAccelerationView = (CheckBox) 85 UiUtilities.getView(view, R.id.debug_disable_graphics_acceleration); 86 mInhibitGraphicsAccelerationView.setChecked( 87 MailActivityEmail.sDebugInhibitGraphicsAcceleration); 88 mInhibitGraphicsAccelerationView.setOnCheckedChangeListener(this); 89 90 mEnableStrictModeView = (CheckBox) 91 UiUtilities.getView(view, R.id.debug_enable_strict_mode); 92 mEnableStrictModeView.setChecked(mPreferences.getEnableStrictMode()); 93 mEnableStrictModeView.setOnCheckedChangeListener(this); 94 95 return view; 96 } 97 98 @Override 99 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 100 switch (buttonView.getId()) { 101 case R.id.debug_logging: 102 mPreferences.setEnableDebugLogging(isChecked); 103 MailActivityEmail.DEBUG = isChecked; 104 MailActivityEmail.DEBUG_EXCHANGE = isChecked; 105 break; 106 case R.id.verbose_logging: 107 mPreferences.setEnableExchangeLogging(isChecked); 108 MailActivityEmail.DEBUG_VERBOSE = isChecked; 109 break; 110 case R.id.file_logging: 111 mPreferences.setEnableExchangeFileLogging(isChecked); 112 MailActivityEmail.DEBUG_FILE = isChecked; 113 break; 114 case R.id.debug_disable_graphics_acceleration: 115 MailActivityEmail.sDebugInhibitGraphicsAcceleration = isChecked; 116 mPreferences.setInhibitGraphicsAcceleration(isChecked); 117 break; 118 case R.id.debug_enable_strict_mode: 119 mPreferences.setEnableStrictMode(isChecked); 120 MailActivityEmail.enableStrictMode(isChecked); 121 break; 122 } 123 124 MailActivityEmail.updateLoggingFlags(getActivity()); 125 } 126 127 @Override 128 public void onClick(View v) { 129 switch (v.getId()) { 130 case R.id.clear_webview_cache: 131 clearWebViewCache(); 132 break; 133 } 134 } 135 136 private void clearWebViewCache() { 137 WebView webview = new WebView(getActivity()); 138 try { 139 webview.clearCache(true); 140 LogUtils.w(Logging.LOG_TAG, "Cleard WebView cache."); 141 } finally { 142 webview.destroy(); 143 } 144 } 145 } 146