• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
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.ide.eclipse.adt.internal.preferences;
18 
19 
20 import com.android.annotations.NonNull;
21 import com.android.ide.common.xml.XmlAttributeSortOrder;
22 import com.android.ide.eclipse.adt.AdtPlugin;
23 import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor;
24 import com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderPreviewMode;
25 import com.android.prefs.AndroidLocation.AndroidLocationException;
26 import com.android.sdklib.internal.build.DebugKeyProvider;
27 import com.android.sdklib.internal.build.DebugKeyProvider.KeytoolException;
28 import com.android.sdkstats.DdmsPreferenceStore;
29 
30 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
31 import org.eclipse.jface.preference.IPreferenceStore;
32 import org.eclipse.jface.util.PropertyChangeEvent;
33 
34 import java.io.File;
35 import java.util.Locale;
36 
37 public final class AdtPrefs extends AbstractPreferenceInitializer {
38     public final static String PREFS_SDK_DIR = AdtPlugin.PLUGIN_ID + ".sdk"; //$NON-NLS-1$
39 
40     public final static String PREFS_BUILD_RES_AUTO_REFRESH = AdtPlugin.PLUGIN_ID + ".resAutoRefresh"; //$NON-NLS-1$
41 
42     public final static String PREFS_BUILD_FORCE_ERROR_ON_NATIVELIB_IN_JAR = AdtPlugin.PLUGIN_ID + ".forceErrorNativeLibInJar"; //$NON-NLS-1$
43 
44     public final static String PREFS_BUILD_SKIP_POST_COMPILE_ON_FILE_SAVE = AdtPlugin.PLUGIN_ID + ".skipPostCompileOnFileSave"; //$NON-NLS-1$
45 
46     public final static String PREFS_BUILD_VERBOSITY = AdtPlugin.PLUGIN_ID + ".buildVerbosity"; //$NON-NLS-1$
47 
48     public final static String PREFS_DEFAULT_DEBUG_KEYSTORE = AdtPlugin.PLUGIN_ID + ".defaultDebugKeyStore"; //$NON-NLS-1$
49 
50     public final static String PREFS_CUSTOM_DEBUG_KEYSTORE = AdtPlugin.PLUGIN_ID + ".customDebugKeyStore"; //$NON-NLS-1$
51 
52     public final static String PREFS_HOME_PACKAGE = AdtPlugin.PLUGIN_ID + ".homePackage"; //$NON-NLS-1$
53 
54     public final static String PREFS_EMU_OPTIONS = AdtPlugin.PLUGIN_ID + ".emuOptions"; //$NON-NLS-1$
55 
56     public final static String PREFS_MONITOR_DENSITY = AdtPlugin.PLUGIN_ID + ".monitorDensity"; //$NON-NLS-1$
57 
58     public final static String PREFS_FORMAT_GUI_XML = AdtPlugin.PLUGIN_ID + ".formatXml"; //$NON-NLS-1$
59     public final static String PREFS_PREFER_XML = AdtPlugin.PLUGIN_ID + ".xmlEditor"; //$NON-NLS-1$
60     public final static String PREFS_USE_CUSTOM_XML_FORMATTER = AdtPlugin.PLUGIN_ID + ".androidForm"; //$NON-NLS-1$
61 
62     public final static String PREFS_PALETTE_MODE = AdtPlugin.PLUGIN_ID + ".palette"; //$NON-NLS-1$
63 
64     public final static String PREFS_USE_ECLIPSE_INDENT = AdtPlugin.PLUGIN_ID + ".eclipseIndent"; //$NON-NLS-1$
65     public final static String PREVS_REMOVE_EMPTY_LINES = AdtPlugin.PLUGIN_ID + ".removeEmpty"; //$NON-NLS-1$
66     public final static String PREFS_ONE_ATTR_PER_LINE = AdtPlugin.PLUGIN_ID + ".oneAttrPerLine"; //$NON-NLS-1$
67     public final static String PREFS_SPACE_BEFORE_CLOSE = AdtPlugin.PLUGIN_ID + ".spaceBeforeClose"; //$NON-NLS-1$
68     public final static String PREFS_FORMAT_ON_SAVE = AdtPlugin.PLUGIN_ID + ".formatOnSave"; //$NON-NLS-1$
69     public final static String PREFS_LINT_ON_SAVE = AdtPlugin.PLUGIN_ID + ".lintOnSave"; //$NON-NLS-1$
70     public final static String PREFS_LINT_ON_EXPORT = AdtPlugin.PLUGIN_ID + ".lintOnExport"; //$NON-NLS-1$
71     public final static String PREFS_ATTRIBUTE_SORT = AdtPlugin.PLUGIN_ID + ".attrSort"; //$NON-NLS-1$
72     public final static String PREFS_LINT_SEVERITIES = AdtPlugin.PLUGIN_ID + ".lintSeverities"; //$NON-NLS-1$
73     public final static String PREFS_FIX_LEGACY_EDITORS = AdtPlugin.PLUGIN_ID + ".fixLegacyEditors"; //$NON-NLS-1$
74     public final static String PREFS_SHARED_LAYOUT_EDITOR = AdtPlugin.PLUGIN_ID + ".sharedLayoutEditor"; //$NON-NLS-1$
75     public final static String PREFS_PREVIEWS = AdtPlugin.PLUGIN_ID + ".previews"; //$NON-NLS-1$
76     public final static String PREFS_SKIP_LINT_LIBS = AdtPlugin.PLUGIN_ID + ".skipLintLibs"; //$NON-NLS-1$
77     public final static String PREFS_AUTO_PICK_TARGET = AdtPlugin.PLUGIN_ID + ".autoPickTarget"; //$NON-NLS-1$
78     public final static String PREFS_REFACTOR_IDS = AdtPlugin.PLUGIN_ID + ".refactorIds"; //$NON-NLS-1$
79 
80     /** singleton instance */
81     private final static AdtPrefs sThis = new AdtPrefs();
82 
83     /** default store, provided by eclipse */
84     private IPreferenceStore mStore;
85 
86     /** cached location for the sdk folder */
87     private String mOsSdkLocation;
88 
89     /** Verbosity of the build */
90     private BuildVerbosity mBuildVerbosity = BuildVerbosity.NORMAL;
91 
92     private boolean mBuildForceResResfresh = false;
93     private boolean mBuildForceErrorOnNativeLibInJar = true;
94     private boolean mBuildSkipPostCompileOnFileSave = true;
95     private float mMonitorDensity = 0.f;
96     private String mPalette;
97 
98     private boolean mFormatGuiXml;
99     private boolean mCustomXmlFormatter;
100     private boolean mUseEclipseIndent;
101     private boolean mRemoveEmptyLines;
102     private boolean mOneAttributeOnFirstLine;
103     private boolean mSpaceBeforeClose;
104     private boolean mFormatOnSave;
105     private boolean mLintOnSave;
106     private boolean mLintOnExport;
107     private XmlAttributeSortOrder mAttributeSort;
108     private boolean mSharedLayoutEditor;
109     private boolean mAutoPickTarget;
110     private RenderPreviewMode mPreviewMode = RenderPreviewMode.NONE;
111     private int mPreferXmlEditor;
112     private boolean mSkipLibrariesFromLint;
113 
114     public static enum BuildVerbosity {
115         /** Build verbosity "Always". Those messages are always displayed, even in silent mode */
116         ALWAYS(0),
117         /** Build verbosity level "Normal" */
118         NORMAL(1),
119         /** Build verbosity level "Verbose". Those messages are only displayed in verbose mode */
120         VERBOSE(2);
121 
122         private int mLevel;
123 
BuildVerbosity(int level)124         BuildVerbosity(int level) {
125             mLevel = level;
126         }
127 
getLevel()128         public int getLevel() {
129             return mLevel;
130         }
131 
132         /**
133          * Finds and returns a {@link BuildVerbosity} whose {@link #name()} matches a given name.
134          * <p/>This is different from {@link Enum#valueOf(Class, String)} in that it returns null
135          * if no matches are found.
136          *
137          * @param name the name to look up.
138          * @return returns the matching enum or null of no match where found.
139          */
find(String name)140         public static BuildVerbosity find(String name) {
141             for (BuildVerbosity v : values()) {
142                 if (v.name().equals(name)) {
143                     return v;
144                 }
145             }
146 
147             return null;
148         }
149     }
150 
init(IPreferenceStore preferenceStore)151     public static void init(IPreferenceStore preferenceStore) {
152         sThis.mStore = preferenceStore;
153     }
154 
getPrefs()155     public static AdtPrefs getPrefs() {
156         return sThis;
157     }
158 
loadValues(PropertyChangeEvent event)159     public synchronized void loadValues(PropertyChangeEvent event) {
160         // get the name of the property that changed, if any
161         String property = event != null ? event.getProperty() : null;
162 
163         if (property == null || PREFS_SDK_DIR.equals(property)) {
164             mOsSdkLocation = mStore.getString(PREFS_SDK_DIR);
165 
166             // Make it possible to override the SDK path using an environment variable.
167             // The value will only be used if it matches an existing directory.
168             // Useful for testing from Eclipse.
169             // Note: this is a hack that does not change the preferences, so if the user
170             // looks at Window > Preferences > Android, the path will be the preferences
171             // one and not the overridden one.
172             String override = System.getenv("ADT_TEST_SDK_PATH");   //$NON-NLS-1$
173             if (override != null && override.length() > 0 && new File(override).isDirectory()) {
174                 mOsSdkLocation = override;
175             }
176 
177             // make sure it ends with a separator. Normally this is done when the preference
178             // is set. But to make sure older version still work, we fix it here as well.
179             if (mOsSdkLocation.length() > 0 && mOsSdkLocation.endsWith(File.separator) == false) {
180                 mOsSdkLocation = mOsSdkLocation + File.separator;
181             }
182         }
183 
184         if (property == null || PREFS_BUILD_VERBOSITY.equals(property)) {
185             mBuildVerbosity = BuildVerbosity.find(mStore.getString(PREFS_BUILD_VERBOSITY));
186             if (mBuildVerbosity == null) {
187                 mBuildVerbosity = BuildVerbosity.NORMAL;
188             }
189         }
190 
191         if (property == null || PREFS_BUILD_RES_AUTO_REFRESH.equals(property)) {
192             mBuildForceResResfresh = mStore.getBoolean(PREFS_BUILD_RES_AUTO_REFRESH);
193         }
194 
195         if (property == null || PREFS_BUILD_FORCE_ERROR_ON_NATIVELIB_IN_JAR.equals(property)) {
196             mBuildForceErrorOnNativeLibInJar =
197                     mStore.getBoolean(PREFS_BUILD_FORCE_ERROR_ON_NATIVELIB_IN_JAR);
198         }
199 
200         if (property == null || PREFS_BUILD_SKIP_POST_COMPILE_ON_FILE_SAVE.equals(property)) {
201             mBuildSkipPostCompileOnFileSave =
202                 mStore.getBoolean(PREFS_BUILD_SKIP_POST_COMPILE_ON_FILE_SAVE);
203         }
204 
205         if (property == null || PREFS_MONITOR_DENSITY.equals(property)) {
206             mMonitorDensity = mStore.getFloat(PREFS_MONITOR_DENSITY);
207         }
208 
209         if (property == null || PREFS_FORMAT_GUI_XML.equals(property)) {
210             mFormatGuiXml = mStore.getBoolean(PREFS_FORMAT_GUI_XML);
211         }
212 
213         if (property == null || PREFS_PREFER_XML.equals(property)) {
214             mPreferXmlEditor = mStore.getInt(PREFS_PREFER_XML);
215         }
216 
217         if (property == null || PREFS_USE_CUSTOM_XML_FORMATTER.equals(property)) {
218             mCustomXmlFormatter = mStore.getBoolean(PREFS_USE_CUSTOM_XML_FORMATTER);
219         }
220 
221         if (property == null || PREFS_PALETTE_MODE.equals(property)) {
222             mPalette = mStore.getString(PREFS_PALETTE_MODE);
223         }
224 
225         if (property == null || PREFS_USE_ECLIPSE_INDENT.equals(property)) {
226             mUseEclipseIndent = mStore.getBoolean(PREFS_USE_ECLIPSE_INDENT);
227         }
228 
229         if (property == null || PREVS_REMOVE_EMPTY_LINES.equals(property)) {
230             mRemoveEmptyLines = mStore.getBoolean(PREVS_REMOVE_EMPTY_LINES);
231         }
232 
233         if (property == null || PREFS_ONE_ATTR_PER_LINE.equals(property)) {
234             mOneAttributeOnFirstLine = mStore.getBoolean(PREFS_ONE_ATTR_PER_LINE);
235         }
236 
237         if (property == null || PREFS_ATTRIBUTE_SORT.equals(property)) {
238             String order = mStore.getString(PREFS_ATTRIBUTE_SORT);
239             mAttributeSort = XmlAttributeSortOrder.LOGICAL;
240             if (XmlAttributeSortOrder.ALPHABETICAL.key.equals(order)) {
241                 mAttributeSort = XmlAttributeSortOrder.ALPHABETICAL;
242             } else if (XmlAttributeSortOrder.NO_SORTING.key.equals(order)) {
243                 mAttributeSort = XmlAttributeSortOrder.NO_SORTING;
244             }
245         }
246 
247         if (property == null || PREFS_SPACE_BEFORE_CLOSE.equals(property)) {
248             mSpaceBeforeClose = mStore.getBoolean(PREFS_SPACE_BEFORE_CLOSE);
249         }
250 
251         if (property == null || PREFS_FORMAT_ON_SAVE.equals(property)) {
252             mFormatOnSave = mStore.getBoolean(PREFS_FORMAT_ON_SAVE);
253         }
254 
255         if (property == null || PREFS_LINT_ON_SAVE.equals(property)) {
256             mLintOnSave = mStore.getBoolean(PREFS_LINT_ON_SAVE);
257         }
258 
259         if (property == null || PREFS_LINT_ON_EXPORT.equals(property)) {
260             mLintOnExport = mStore.getBoolean(PREFS_LINT_ON_EXPORT);
261         }
262 
263         if (property == null || PREFS_SHARED_LAYOUT_EDITOR.equals(property)) {
264             mSharedLayoutEditor = mStore.getBoolean(PREFS_SHARED_LAYOUT_EDITOR);
265         }
266 
267         if (property == null || PREFS_AUTO_PICK_TARGET.equals(property)) {
268             mAutoPickTarget = mStore.getBoolean(PREFS_AUTO_PICK_TARGET);
269         }
270 
271         if (property == null || PREFS_PREVIEWS.equals(property)) {
272             mPreviewMode = RenderPreviewMode.NONE;
273             String previewMode = mStore.getString(PREFS_PREVIEWS);
274             if (previewMode != null && !previewMode.isEmpty()) {
275                 try {
276                     mPreviewMode = RenderPreviewMode.valueOf(previewMode.toUpperCase(Locale.US));
277                 } catch (IllegalArgumentException iae) {
278                     // Ignore: Leave it as RenderPreviewMode.NONE
279                 }
280             }
281         }
282 
283         if (property == null || PREFS_SKIP_LINT_LIBS.equals(property)) {
284             mSkipLibrariesFromLint = mStore.getBoolean(PREFS_SKIP_LINT_LIBS);
285         }
286     }
287 
288     /**
289      * Returns the SDK folder.
290      * Guaranteed to be terminated by a platform-specific path separator.
291      */
getOsSdkFolder()292     public synchronized String getOsSdkFolder() {
293         return mOsSdkLocation;
294     }
295 
getBuildVerbosity()296     public synchronized BuildVerbosity getBuildVerbosity() {
297         return mBuildVerbosity;
298     }
299 
getBuildForceResResfresh()300     public boolean getBuildForceResResfresh() {
301         return mBuildForceResResfresh;
302     }
303 
304     /**
305      * Should changes made by GUI editors automatically format the corresponding XML nodes
306      * affected by the edit?
307      *
308      * @return true if the GUI editors should format affected XML regions
309      */
getFormatGuiXml()310     public boolean getFormatGuiXml() {
311         // The format-GUI-editors flag only applies when the custom formatter is used,
312         // since the built-in formatter has problems editing partial documents
313         return mFormatGuiXml && mCustomXmlFormatter;
314     }
315 
316     /**
317      * Should the XML formatter use a custom Android XML formatter (following
318      * Android code style) or use the builtin Eclipse XML formatter?
319      *
320      * @return true if the Android formatter should be used instead of the
321      *         default Eclipse one
322      */
getUseCustomXmlFormatter()323     public boolean getUseCustomXmlFormatter() {
324         return mCustomXmlFormatter;
325     }
326 
327     /**
328      * Should the Android XML formatter use the Eclipse XML indentation settings
329      * (usually one tab character) instead of the default 4 space character
330      * indent?
331      *
332      * @return true if the Eclipse XML indentation settings should be use
333      */
isUseEclipseIndent()334     public boolean isUseEclipseIndent() {
335         return mUseEclipseIndent;
336     }
337 
338     /**
339      * Should the Android XML formatter try to avoid inserting blank lines to
340      * make the format as compact as possible (no blank lines between elements,
341      * no blank lines surrounding comments, etc).
342      *
343      * @return true to remove blank lines
344      */
isRemoveEmptyLines()345     public boolean isRemoveEmptyLines() {
346         return mRemoveEmptyLines;
347     }
348 
349     /**
350      * Should the Android XML formatter attempt to place a single attribute on
351      * the same line as the element open tag?
352      *
353      * @return true if single-attribute elements should place the attribute on
354      *         the same line as the element open tag
355      */
isOneAttributeOnFirstLine()356     public boolean isOneAttributeOnFirstLine() {
357         return mOneAttributeOnFirstLine;
358     }
359 
360     /**
361      * Returns the sort order to be applied to the attributes (one of which can
362      * be {@link com.android.ide.common.xml.XmlAttributeSortOrder#NO_SORTING}).
363      *
364      * @return the sort order to apply to the attributes
365      */
getAttributeSort()366     public XmlAttributeSortOrder getAttributeSort() {
367         if (mAttributeSort == null) {
368             return XmlAttributeSortOrder.LOGICAL;
369         }
370         return mAttributeSort;
371     }
372 
373     /**
374      * Returns whether a space should be inserted before the closing {@code >}
375      * character in open tags and before the closing {@code />} characters in
376      * empty tag. Note that the {@link com.android.ide.common.xml.XmlFormatStyle#RESOURCE} style overrides
377      * this setting to make it more compact for the {@code <item>} elements.
378      *
379      * @return true if an empty space should be inserted before {@code >} or
380      *         {@code />}.
381      */
isSpaceBeforeClose()382     public boolean isSpaceBeforeClose() {
383         return mSpaceBeforeClose;
384     }
385 
386     /**
387      * Returns whether the file should be automatically formatted on save.
388      *
389      * @return true if the XML files should be formatted on save.
390      */
isFormatOnSave()391     public boolean isFormatOnSave() {
392         return mFormatOnSave;
393     }
394 
isLintOnSave()395     public boolean isLintOnSave() {
396         return mLintOnSave;
397     }
398 
setLintOnSave(boolean on)399     public void setLintOnSave(boolean on) {
400         mLintOnSave = on;
401         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
402         store.setValue(PREFS_LINT_ON_SAVE, on);
403     }
404 
isLintOnExport()405     public boolean isLintOnExport() {
406         return mLintOnExport;
407     }
408 
setLintOnExport(boolean on)409     public void setLintOnExport(boolean on) {
410         mLintOnExport = on;
411         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
412         store.setValue(PREFS_LINT_ON_EXPORT, on);
413     }
414 
415     /**
416      * Returns whether the layout editor is sharing a single editor for all variations
417      * of a single resource. The default is false.
418      *
419      * @return true if the editor should be shared
420      */
isSharedLayoutEditor()421     public boolean isSharedLayoutEditor() {
422         return mSharedLayoutEditor;
423     }
424 
425     /**
426      * Sets whether the layout editor should share a single editor for all variations
427      * of a single resource
428      *
429      * @param on if true, use a single editor
430      */
setSharedLayoutEditor(boolean on)431     public void setSharedLayoutEditor(boolean on) {
432         mSharedLayoutEditor = on;
433         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
434         store.setValue(PREFS_SHARED_LAYOUT_EDITOR, on);
435 
436         // TODO: If enabling a shared editor, go and close all editors that are aliasing
437         // the same resource except for one of them.
438     }
439 
440 
getBuildForceErrorOnNativeLibInJar()441     public boolean getBuildForceErrorOnNativeLibInJar() {
442         return mBuildForceErrorOnNativeLibInJar;
443     }
444 
getBuildSkipPostCompileOnFileSave()445     public boolean getBuildSkipPostCompileOnFileSave() {
446         return mBuildSkipPostCompileOnFileSave;
447     }
448 
getPaletteModes()449     public String getPaletteModes() {
450         return mPalette;
451     }
452 
setPaletteModes(String palette)453     public void setPaletteModes(String palette) {
454         mPalette = palette;
455 
456         // need to save this new value to the store
457         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
458         store.setValue(PREFS_PALETTE_MODE, palette);
459     }
460 
getMonitorDensity()461     public float getMonitorDensity() {
462         return mMonitorDensity;
463     }
464 
setMonitorDensity(float density)465     public void setMonitorDensity(float density) {
466         mMonitorDensity = density;
467 
468         // need to save this new value to the store
469         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
470         store.setValue(PREFS_MONITOR_DENSITY, density);
471     }
472 
473     /**
474      * Sets the new location of the SDK
475      *
476      * @param location the location of the SDK
477      */
setSdkLocation(File location)478     public void setSdkLocation(File location) {
479         mOsSdkLocation = location != null ? location.getPath() : null;
480 
481         // TODO: Also store this location in the .android settings directory
482         // such that we can support using multiple workspaces without asking
483         // over and over.
484         if (mOsSdkLocation != null && mOsSdkLocation.length() > 0) {
485             DdmsPreferenceStore ddmsStore = new DdmsPreferenceStore();
486             ddmsStore.setLastSdkPath(mOsSdkLocation);
487         }
488 
489         // need to save this new value to the store
490         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
491         store.setValue(PREFS_SDK_DIR, mOsSdkLocation);
492     }
493 
494     @Override
initializeDefaultPreferences()495     public void initializeDefaultPreferences() {
496         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
497         initializeStoreWithDefaults(store);
498     }
499 
initializeStoreWithDefaults(IPreferenceStore store)500     public void initializeStoreWithDefaults(IPreferenceStore store) {
501         store.setDefault(PREFS_BUILD_RES_AUTO_REFRESH, true);
502         store.setDefault(PREFS_BUILD_FORCE_ERROR_ON_NATIVELIB_IN_JAR, true);
503         store.setDefault(PREFS_BUILD_SKIP_POST_COMPILE_ON_FILE_SAVE, true);
504 
505         store.setDefault(PREFS_BUILD_VERBOSITY, BuildVerbosity.ALWAYS.name());
506 
507         store.setDefault(PREFS_HOME_PACKAGE, "android.process.acore"); //$NON-NLS-1$
508 
509         store.setDefault(PREFS_MONITOR_DENSITY, 0.f);
510 
511         store.setDefault(PREFS_FORMAT_GUI_XML, true);
512         store.setDefault(PREFS_USE_CUSTOM_XML_FORMATTER, true);
513         store.setDefault(PREFS_ONE_ATTR_PER_LINE, true);
514         store.setDefault(PREFS_SPACE_BEFORE_CLOSE, true);
515         store.setDefault(PREFS_LINT_ON_SAVE, true);
516         store.setDefault(PREFS_LINT_ON_EXPORT, true);
517         store.setDefault(PREFS_AUTO_PICK_TARGET, true);
518 
519         // Defaults already handled; no need to write into map:
520         //store.setDefault(PREFS_ATTRIBUTE_SORT, XmlAttributeSortOrder.LOGICAL.key);
521         //store.setDefault(PREFS_USE_ECLIPSE_INDENT, false);
522         //store.setDefault(PREVS_REMOVE_EMPTY_LINES, false);
523         //store.setDefault(PREFS_FORMAT_ON_SAVE, false);
524         //store.setDefault(PREFS_SHARED_LAYOUT_EDITOR, false);
525         //store.setDefault(PREFS_SKIP_LINT_LIBS, false);
526 
527         try {
528             store.setDefault(PREFS_DEFAULT_DEBUG_KEYSTORE,
529                     DebugKeyProvider.getDefaultKeyStoreOsPath());
530         } catch (KeytoolException e) {
531             AdtPlugin.log(e, "Get default debug keystore path failed"); //$NON-NLS-1$
532         } catch (AndroidLocationException e) {
533             AdtPlugin.log(e, "Get default debug keystore path failed"); //$NON-NLS-1$
534         }
535     }
536 
537     /**
538      * Returns whether the most recent page switch was to XML
539      *
540      * @param editorType the editor to check a preference for; corresponds to
541      *            one of the persistence class ids returned by
542      *            {@link AndroidXmlEditor#getPersistenceCategory}
543      * @return whether the most recent page switch in the given editor was to
544      *         XML
545      */
isXmlEditorPreferred(int editorType)546     public boolean isXmlEditorPreferred(int editorType) {
547         return (mPreferXmlEditor & editorType) != 0;
548     }
549 
550     /**
551      * Set whether the most recent page switch for a given editor type was to
552      * XML
553      *
554      * @param editorType the editor to check a preference for; corresponds to
555      *            one of the persistence class ids returned by
556      *            {@link AndroidXmlEditor#getPersistenceCategory}
557      * @param xml whether the last manual page switch in the given editor type
558      *            was to XML
559      */
setXmlEditorPreferred(int editorType, boolean xml)560     public void setXmlEditorPreferred(int editorType, boolean xml) {
561         if (xml != isXmlEditorPreferred(editorType)) {
562             if (xml) {
563                 mPreferXmlEditor |= editorType;
564             } else {
565                 mPreferXmlEditor &= ~editorType;
566             }
567             assert ((mPreferXmlEditor & editorType) != 0) == xml;
568             IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
569             store.setValue(PREFS_PREFER_XML, xml);
570         }
571     }
572 
573     /**
574      * Gets the {@link RenderPreviewMode}
575      *
576      * @return the preview mode
577      */
578     @NonNull
getRenderPreviewMode()579     public RenderPreviewMode getRenderPreviewMode() {
580         return mPreviewMode;
581     }
582 
583     /**
584      * Sets the {@link RenderPreviewMode}
585      *
586      * @param previewMode the preview mode
587      */
setPreviewMode(@onNull RenderPreviewMode previewMode)588     public void setPreviewMode(@NonNull RenderPreviewMode previewMode) {
589         mPreviewMode = previewMode;
590         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
591         if (previewMode != RenderPreviewMode.NONE) {
592             store.setValue(PREFS_PREVIEWS, previewMode.name().toLowerCase(Locale.US));
593         } else {
594             store.setToDefault(PREFS_PREVIEWS);
595         }
596     }
597 
598     /**
599      * Sets whether auto-pick render target mode is enabled.
600      *
601      * @return whether the layout editor should automatically pick the best render target
602      */
isAutoPickRenderTarget()603     public boolean isAutoPickRenderTarget() {
604         return mAutoPickTarget;
605     }
606 
607     /**
608      * Sets whether auto-pick render target mode is enabled.
609      *
610      * @param autoPick if true, auto pick the best render target in the layout editor
611      */
setAutoPickRenderTarget(boolean autoPick)612     public void setAutoPickRenderTarget(boolean autoPick) {
613         mAutoPickTarget = autoPick;
614         IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
615         if (autoPick) {
616             store.setToDefault(PREFS_AUTO_PICK_TARGET);
617         } else {
618             store.setValue(PREFS_AUTO_PICK_TARGET, autoPick);
619         }
620     }
621 
622     /**
623      * Sets whether libraries should be excluded when running lint on a project
624      *
625      * @param exclude if true, exclude library projects
626      */
setSkipLibrariesFromLint(boolean exclude)627     public void setSkipLibrariesFromLint(boolean exclude) {
628         if (exclude != mSkipLibrariesFromLint) {
629             mSkipLibrariesFromLint = exclude;
630             IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
631             if (exclude) {
632                 store.setValue(PREFS_SKIP_LINT_LIBS, true);
633             } else {
634                 store.setToDefault(PREFS_SKIP_LINT_LIBS);
635             }
636         }
637     }
638 
639     /**
640      * Returns whether libraries should be excluded when running lint on a project
641      *
642      * @return if true, exclude library projects
643      */
getSkipLibrariesFromLint()644     public boolean getSkipLibrariesFromLint() {
645         return mSkipLibrariesFromLint;
646     }
647 }
648