11 package com.freerdp.freerdpcore.domain;
13 import android.content.SharedPreferences;
14 import android.os.Parcel;
15 import android.os.Parcelable;
17 import com.freerdp.freerdpcore.application.GlobalApp;
19 import java.util.Locale;
23 public static final int TYPE_INVALID = -1;
24 public static final int TYPE_MANUAL = 1;
25 public static final int TYPE_QUICKCONNECT = 2;
26 public static final int TYPE_PLACEHOLDER = 3;
27 public static final int TYPE_CUSTOM_BASE = 1000;
28 public static final Parcelable.Creator<
BookmarkBase> CREATOR =
43 private String username;
44 private String password;
45 private String domain;
53 type = parcel.readInt();
54 id = parcel.readLong();
55 label = parcel.readString();
56 username = parcel.readString();
57 password = parcel.readString();
58 domain = parcel.readString();
60 screenSettings = parcel.readParcelable(
ScreenSettings.class.getClassLoader());
61 performanceFlags = parcel.readParcelable(
PerformanceFlags.class.getClassLoader());
62 advancedSettings = parcel.readParcelable(
AdvancedSettings.class.getClassLoader());
63 debugSettings = parcel.readParcelable(
DebugSettings.class.getClassLoader());
86 @SuppressWarnings(
"unchecked") public <T extends BookmarkBase> T
get()
101 public void setId(
long id)
106 public String getLabel()
111 public void setLabel(String label)
116 public String getUsername()
121 public void setUsername(String username)
123 this.username = username;
126 public String getPassword()
131 public void setPassword(String password)
133 this.password = password;
136 public String getDomain()
141 public void setDomain(String domain)
143 this.domain = domain;
148 return screenSettings;
153 this.screenSettings = screenSettings;
158 return performanceFlags;
163 this.performanceFlags = performanceFlags;
168 return advancedSettings;
173 this.advancedSettings = advancedSettings;
178 return debugSettings;
183 this.debugSettings = debugSettings;
188 return (
GlobalApp.ConnectedTo3G && advancedSettings.getEnable3GSettings())
189 ? advancedSettings.getScreen3G()
195 return (
GlobalApp.ConnectedTo3G && advancedSettings.getEnable3GSettings())
196 ? advancedSettings.getPerformance3G()
200 @Override
public int describeContents()
205 @Override
public void writeToParcel(Parcel out,
int flags)
209 out.writeString(label);
210 out.writeString(username);
211 out.writeString(password);
212 out.writeString(domain);
214 out.writeParcelable(screenSettings, flags);
215 out.writeParcelable(performanceFlags, flags);
216 out.writeParcelable(advancedSettings, flags);
217 out.writeParcelable(debugSettings, flags);
221 public void writeToSharedPreferences(SharedPreferences sharedPrefs)
224 Locale locale = Locale.ENGLISH;
226 SharedPreferences.Editor editor = sharedPrefs.edit();
228 editor.putString(
"bookmark.label", label);
229 editor.putString(
"bookmark.username", username);
230 editor.putString(
"bookmark.password", password);
231 editor.putString(
"bookmark.domain", domain);
233 editor.putInt(
"bookmark.colors", screenSettings.getColors());
234 editor.putString(
"bookmark.resolution",
235 screenSettings.getResolutionString().toLowerCase(locale));
236 editor.putInt(
"bookmark.width", screenSettings.getWidth());
237 editor.putInt(
"bookmark.height", screenSettings.getHeight());
239 editor.putBoolean(
"bookmark.perf_remotefx", performanceFlags.getRemoteFX());
240 editor.putBoolean(
"bookmark.perf_gfx", performanceFlags.getGfx());
241 editor.putBoolean(
"bookmark.perf_gfx_h264", performanceFlags.getH264());
242 editor.putBoolean(
"bookmark.perf_wallpaper", performanceFlags.getWallpaper());
243 editor.putBoolean(
"bookmark.perf_font_smoothing", performanceFlags.getFontSmoothing());
244 editor.putBoolean(
"bookmark.perf_desktop_composition",
245 performanceFlags.getDesktopComposition());
246 editor.putBoolean(
"bookmark.perf_window_dragging", performanceFlags.getFullWindowDrag());
247 editor.putBoolean(
"bookmark.perf_menu_animation", performanceFlags.getMenuAnimations());
248 editor.putBoolean(
"bookmark.perf_themes", performanceFlags.getTheming());
250 editor.putBoolean(
"bookmark.enable_3g_settings", advancedSettings.getEnable3GSettings());
252 editor.putInt(
"bookmark.colors_3g", advancedSettings.getScreen3G().getColors());
253 editor.putString(
"bookmark.resolution_3g",
254 advancedSettings.getScreen3G().getResolutionString().toLowerCase(locale));
255 editor.putInt(
"bookmark.width_3g", advancedSettings.getScreen3G().getWidth());
256 editor.putInt(
"bookmark.height_3g", advancedSettings.getScreen3G().getHeight());
258 editor.putBoolean(
"bookmark.perf_remotefx_3g",
259 advancedSettings.getPerformance3G().getRemoteFX());
260 editor.putBoolean(
"bookmark.perf_gfx_3g", advancedSettings.getPerformance3G().getGfx());
261 editor.putBoolean(
"bookmark.perf_gfx_h264_3g",
262 advancedSettings.getPerformance3G().getH264());
263 editor.putBoolean(
"bookmark.perf_wallpaper_3g",
264 advancedSettings.getPerformance3G().getWallpaper());
265 editor.putBoolean(
"bookmark.perf_font_smoothing_3g",
266 advancedSettings.getPerformance3G().getFontSmoothing());
267 editor.putBoolean(
"bookmark.perf_desktop_composition_3g",
268 advancedSettings.getPerformance3G().getDesktopComposition());
269 editor.putBoolean(
"bookmark.perf_window_dragging_3g",
270 advancedSettings.getPerformance3G().getFullWindowDrag());
271 editor.putBoolean(
"bookmark.perf_menu_animation_3g",
272 advancedSettings.getPerformance3G().getMenuAnimations());
273 editor.putBoolean(
"bookmark.perf_themes_3g",
274 advancedSettings.getPerformance3G().getTheming());
276 editor.putBoolean(
"bookmark.redirect_sdcard", advancedSettings.getRedirectSDCard());
277 editor.putInt(
"bookmark.redirect_sound", advancedSettings.getRedirectSound());
278 editor.putBoolean(
"bookmark.redirect_microphone", advancedSettings.getRedirectMicrophone());
279 editor.putInt(
"bookmark.security", advancedSettings.getSecurity());
280 editor.putString(
"bookmark.remote_program", advancedSettings.getRemoteProgram());
281 editor.putString(
"bookmark.work_dir", advancedSettings.getWorkDir());
282 editor.putBoolean(
"bookmark.console_mode", advancedSettings.getConsoleMode());
284 editor.putBoolean(
"bookmark.async_channel", debugSettings.getAsyncChannel());
285 editor.putBoolean(
"bookmark.async_update", debugSettings.getAsyncUpdate());
286 editor.putString(
"bookmark.debug_level", debugSettings.getDebugLevel());
292 public void readFromSharedPreferences(SharedPreferences sharedPrefs)
294 label = sharedPrefs.getString(
"bookmark.label",
"");
295 username = sharedPrefs.getString(
"bookmark.username",
"");
296 password = sharedPrefs.getString(
"bookmark.password",
"");
297 domain = sharedPrefs.getString(
"bookmark.domain",
"");
299 screenSettings.setColors(sharedPrefs.getInt(
"bookmark.colors", 16));
300 screenSettings.setResolution(sharedPrefs.getString(
"bookmark.resolution",
"automatic"),
301 sharedPrefs.getInt(
"bookmark.width", 800),
302 sharedPrefs.getInt(
"bookmark.height", 600));
304 performanceFlags.setRemoteFX(sharedPrefs.getBoolean(
"bookmark.perf_remotefx",
false));
305 performanceFlags.setGfx(sharedPrefs.getBoolean(
"bookmark.perf_gfx",
true));
306 performanceFlags.setH264(sharedPrefs.getBoolean(
"bookmark.perf_gfx_h264",
true));
307 performanceFlags.setWallpaper(sharedPrefs.getBoolean(
"bookmark.perf_wallpaper",
false));
308 performanceFlags.setFontSmoothing(
309 sharedPrefs.getBoolean(
"bookmark.perf_font_smoothing",
false));
310 performanceFlags.setDesktopComposition(
311 sharedPrefs.getBoolean(
"bookmark.perf_desktop_composition",
false));
312 performanceFlags.setFullWindowDrag(
313 sharedPrefs.getBoolean(
"bookmark.perf_window_dragging",
false));
314 performanceFlags.setMenuAnimations(
315 sharedPrefs.getBoolean(
"bookmark.perf_menu_animation",
false));
316 performanceFlags.setTheming(sharedPrefs.getBoolean(
"bookmark.perf_themes",
false));
318 advancedSettings.setEnable3GSettings(
319 sharedPrefs.getBoolean(
"bookmark.enable_3g_settings",
false));
321 advancedSettings.getScreen3G().setColors(sharedPrefs.getInt(
"bookmark.colors_3g", 16));
322 advancedSettings.getScreen3G().setResolution(
323 sharedPrefs.getString(
"bookmark.resolution_3g",
"automatic"),
324 sharedPrefs.getInt(
"bookmark.width_3g", 800),
325 sharedPrefs.getInt(
"bookmark.height_3g", 600));
327 advancedSettings.getPerformance3G().setRemoteFX(
328 sharedPrefs.getBoolean(
"bookmark.perf_remotefx_3g",
false));
329 advancedSettings.getPerformance3G().setGfx(
330 sharedPrefs.getBoolean(
"bookmark.perf_gfx_3g",
false));
331 advancedSettings.getPerformance3G().setH264(
332 sharedPrefs.getBoolean(
"bookmark.perf_gfx_h264_3g",
false));
333 advancedSettings.getPerformance3G().setWallpaper(
334 sharedPrefs.getBoolean(
"bookmark.perf_wallpaper_3g",
false));
335 advancedSettings.getPerformance3G().setFontSmoothing(
336 sharedPrefs.getBoolean(
"bookmark.perf_font_smoothing_3g",
false));
337 advancedSettings.getPerformance3G().setDesktopComposition(
338 sharedPrefs.getBoolean(
"bookmark.perf_desktop_composition_3g",
false));
339 advancedSettings.getPerformance3G().setFullWindowDrag(
340 sharedPrefs.getBoolean(
"bookmark.perf_window_dragging_3g",
false));
341 advancedSettings.getPerformance3G().setMenuAnimations(
342 sharedPrefs.getBoolean(
"bookmark.perf_menu_animation_3g",
false));
343 advancedSettings.getPerformance3G().setTheming(
344 sharedPrefs.getBoolean(
"bookmark.perf_themes_3g",
false));
346 advancedSettings.setRedirectSDCard(
347 sharedPrefs.getBoolean(
"bookmark.redirect_sdcard",
false));
348 advancedSettings.setRedirectSound(sharedPrefs.getInt(
"bookmark.redirect_sound", 0));
349 advancedSettings.setRedirectMicrophone(
350 sharedPrefs.getBoolean(
"bookmark.redirect_microphone",
false));
351 advancedSettings.setSecurity(sharedPrefs.getInt(
"bookmark.security", 0));
352 advancedSettings.setRemoteProgram(sharedPrefs.getString(
"bookmark.remote_program",
""));
353 advancedSettings.setWorkDir(sharedPrefs.getString(
"bookmark.work_dir",
""));
354 advancedSettings.setConsoleMode(sharedPrefs.getBoolean(
"bookmark.console_mode",
false));
356 debugSettings.setAsyncChannel(sharedPrefs.getBoolean(
"bookmark.async_channel",
true));
357 debugSettings.setAsyncUpdate(sharedPrefs.getBoolean(
"bookmark.async_update",
true));
358 debugSettings.setDebugLevel(sharedPrefs.getString(
"bookmark.debug_level",
"INFO"));
362 public Object clone()
366 return super.clone();
368 catch (CloneNotSupportedException e)
389 private boolean remotefx;
391 private boolean h264;
392 private boolean wallpaper;
393 private boolean theming;
394 private boolean fullWindowDrag;
395 private boolean menuAnimations;
396 private boolean fontSmoothing;
397 private boolean desktopComposition;
406 fullWindowDrag =
false;
407 menuAnimations =
false;
408 fontSmoothing =
false;
409 desktopComposition =
false;
414 remotefx = parcel.readInt() == 1;
415 gfx = parcel.readInt() == 1;
416 h264 = parcel.readInt() == 1;
417 wallpaper = parcel.readInt() == 1;
418 theming = parcel.readInt() == 1;
419 fullWindowDrag = (parcel.readInt() == 1);
420 menuAnimations = parcel.readInt() == 1;
421 fontSmoothing = parcel.readInt() == 1;
422 desktopComposition = parcel.readInt() == 1;
425 public boolean getRemoteFX()
430 public void setRemoteFX(
boolean remotefx)
432 this.remotefx = remotefx;
435 public boolean getGfx()
440 public void setGfx(
boolean gfx)
445 public boolean getH264()
450 public void setH264(
boolean h264)
455 public boolean getWallpaper()
460 public void setWallpaper(
boolean wallpaper)
462 this.wallpaper = wallpaper;
465 public boolean getTheming()
470 public void setTheming(
boolean theming)
472 this.theming = theming;
475 public boolean getFullWindowDrag()
477 return fullWindowDrag;
480 public void setFullWindowDrag(
boolean fullWindowDrag)
482 this.fullWindowDrag = fullWindowDrag;
485 public boolean getMenuAnimations()
487 return menuAnimations;
490 public void setMenuAnimations(
boolean menuAnimations)
492 this.menuAnimations = menuAnimations;
495 public boolean getFontSmoothing()
497 return fontSmoothing;
500 public void setFontSmoothing(
boolean fontSmoothing)
502 this.fontSmoothing = fontSmoothing;
505 public boolean getDesktopComposition()
507 return desktopComposition;
510 public void setDesktopComposition(
boolean desktopComposition)
512 this.desktopComposition = desktopComposition;
515 @Override
public int describeContents()
520 @Override
public void writeToParcel(Parcel out,
int flags)
522 out.writeInt(remotefx ? 1 : 0);
523 out.writeInt(gfx ? 1 : 0);
524 out.writeInt(h264 ? 1 : 0);
525 out.writeInt(wallpaper ? 1 : 0);
526 out.writeInt(theming ? 1 : 0);
527 out.writeInt(fullWindowDrag ? 1 : 0);
528 out.writeInt(menuAnimations ? 1 : 0);
529 out.writeInt(fontSmoothing ? 1 : 0);
530 out.writeInt(desktopComposition ? 1 : 0);
537 public static final int FITSCREEN = -2;
538 public static final int AUTOMATIC = -1;
539 public static final int CUSTOM = 0;
540 public static final int PREDEFINED = 1;
553 private int resolution;
565 resolution = parcel.readInt();
566 colors = parcel.readInt();
567 width = parcel.readInt();
568 height = parcel.readInt();
571 private void validate()
586 if ((width <= 0) || (width > 65536))
591 if ((height <= 0) || (height > 65536))
604 resolution = AUTOMATIC;
611 resolution = AUTOMATIC;
617 public void setResolution(String resolution,
int width,
int height)
619 if (resolution.contains(
"x"))
621 String[] dimensions = resolution.split(
"x");
622 this.width = Integer.parseInt(dimensions[0]);
623 this.height = Integer.parseInt(dimensions[1]);
624 this.resolution = PREDEFINED;
626 else if (resolution.equalsIgnoreCase(
"custom"))
629 this.height = height;
630 this.resolution = CUSTOM;
632 else if (resolution.equalsIgnoreCase(
"fitscreen"))
634 this.width = this.height = 0;
635 this.resolution = FITSCREEN;
639 this.width = this.height = 0;
640 this.resolution = AUTOMATIC;
644 public int getResolution()
649 public void setResolution(
int resolution)
651 this.resolution = resolution;
653 if (resolution == AUTOMATIC || resolution == FITSCREEN)
660 public String getResolutionString()
663 return (width +
"x" + height);
665 return (isFitScreen() ?
"fitscreen" : isAutomatic() ?
"automatic" :
"custom");
668 public boolean isPredefined()
671 return (resolution == PREDEFINED);
674 public boolean isAutomatic()
677 return (resolution == AUTOMATIC);
680 public boolean isFitScreen()
683 return (resolution == FITSCREEN);
686 public boolean isCustom()
689 return (resolution == CUSTOM);
692 public int getWidth()
698 public void setWidth(
int width)
703 public int getHeight()
709 public void setHeight(
int height)
711 this.height = height;
714 public int getColors()
720 public void setColors(
int colors)
722 this.colors = colors;
725 @Override
public int describeContents()
730 @Override
public void writeToParcel(Parcel out,
int flags)
732 out.writeInt(resolution);
733 out.writeInt(colors);
735 out.writeInt(height);
742 public static final Parcelable.Creator<
DebugSettings> CREATOR =
754 private String debug;
755 private boolean asyncChannel;
756 private boolean asyncTransport;
757 private boolean asyncUpdate;
767 asyncChannel = parcel.readInt() == 1;
768 asyncTransport = parcel.readInt() == 1;
769 asyncUpdate = parcel.readInt() == 1;
770 debug = parcel.readString();
777 asyncTransport =
false;
781 private void validate()
783 final String[] levels = {
"OFF",
"FATAL",
"ERROR",
"WARN",
"INFO",
"DEBUG",
"TRACE" };
785 for (String level : levels)
787 if (level.equalsIgnoreCase(
this.debug))
796 public String getDebugLevel()
802 public void setDebugLevel(String debug)
807 public boolean getAsyncUpdate()
812 public void setAsyncUpdate(
boolean enabled)
814 asyncUpdate = enabled;
817 public boolean getAsyncChannel()
822 public void setAsyncChannel(
boolean enabled)
824 asyncChannel = enabled;
827 @Override
public int describeContents()
832 @Override
public void writeToParcel(Parcel out,
int flags)
834 out.writeInt(asyncChannel ? 1 : 0);
835 out.writeInt(asyncTransport ? 1 : 0);
836 out.writeInt(asyncUpdate ? 1 : 0);
837 out.writeString(debug);
856 private boolean enable3GSettings;
859 private boolean redirectSDCard;
860 private int redirectSound;
861 private boolean redirectMicrophone;
862 private int security;
863 private boolean consoleMode;
864 private String remoteProgram;
865 private String workDir;
874 enable3GSettings = parcel.readInt() == 1;
875 screen3G = parcel.readParcelable(
ScreenSettings.class.getClassLoader());
876 performance3G = parcel.readParcelable(
PerformanceFlags.class.getClassLoader());
877 redirectSDCard = parcel.readInt() == 1;
878 redirectSound = parcel.readInt();
879 redirectMicrophone = parcel.readInt() == 1;
880 security = parcel.readInt();
881 consoleMode = parcel.readInt() == 1;
882 remoteProgram = parcel.readString();
883 workDir = parcel.readString();
888 enable3GSettings =
false;
891 redirectSDCard =
false;
893 redirectMicrophone =
false;
900 private void validate()
902 switch (redirectSound)
926 public boolean getEnable3GSettings()
928 return enable3GSettings;
931 public void setEnable3GSettings(
boolean enable3GSettings)
933 this.enable3GSettings = enable3GSettings;
943 this.screen3G = screen3G;
948 return performance3G;
953 this.performance3G = performance3G;
956 public boolean getRedirectSDCard()
958 return redirectSDCard;
961 public void setRedirectSDCard(
boolean redirectSDCard)
963 this.redirectSDCard = redirectSDCard;
966 public int getRedirectSound()
969 return redirectSound;
972 public void setRedirectSound(
int redirect)
974 this.redirectSound = redirect;
977 public boolean getRedirectMicrophone()
979 return redirectMicrophone;
982 public void setRedirectMicrophone(
boolean redirect)
984 this.redirectMicrophone = redirect;
987 public int getSecurity()
993 public void setSecurity(
int security)
995 this.security = security;
998 public boolean getConsoleMode()
1003 public void setConsoleMode(
boolean consoleMode)
1005 this.consoleMode = consoleMode;
1008 public String getRemoteProgram()
1010 return remoteProgram;
1013 public void setRemoteProgram(String remoteProgram)
1015 this.remoteProgram = remoteProgram;
1018 public String getWorkDir()
1023 public void setWorkDir(String workDir)
1025 this.workDir = workDir;
1028 @Override
public int describeContents()
1033 @Override
public void writeToParcel(Parcel out,
int flags)
1035 out.writeInt(enable3GSettings ? 1 : 0);
1036 out.writeParcelable(screen3G, flags);
1037 out.writeParcelable(performance3G, flags);
1038 out.writeInt(redirectSDCard ? 1 : 0);
1039 out.writeInt(redirectSound);
1040 out.writeInt(redirectMicrophone ? 1 : 0);
1041 out.writeInt(security);
1042 out.writeInt(consoleMode ? 1 : 0);
1043 out.writeString(remoteProgram);
1044 out.writeString(workDir);