FreeRDP
SessionState.java
1 /*
2  Session State class
3 
4  Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5 
6  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7  If a copy of the MPL was not distributed with this file, You can obtain one at
8  http://mozilla.org/MPL/2.0/.
9 */
10 
11 package com.freerdp.freerdpcore.application;
12 
13 import android.content.Context;
14 import android.graphics.Bitmap;
15 import android.graphics.drawable.BitmapDrawable;
16 import android.net.Uri;
17 import android.os.Parcel;
18 import android.os.Parcelable;
19 
20 import com.freerdp.freerdpcore.domain.BookmarkBase;
21 import com.freerdp.freerdpcore.services.LibFreeRDP;
22 
23 public class SessionState implements Parcelable
24 {
25  public static final Parcelable.Creator<SessionState> CREATOR =
26  new Parcelable.Creator<SessionState>() {
27  public SessionState createFromParcel(Parcel in)
28  {
29  return new SessionState(in);
30  }
31 
32  @Override public SessionState[] newArray(int size)
33  {
34  return new SessionState[size];
35  }
36  };
37  private long instance;
38  private BookmarkBase bookmark;
39  private Uri openUri;
40  private BitmapDrawable surface;
41  private LibFreeRDP.UIEventListener uiEventListener;
42 
43  public SessionState(Parcel parcel)
44  {
45  instance = parcel.readLong();
46  bookmark = parcel.readParcelable(null);
47  openUri = parcel.readParcelable(null);
48 
49  Bitmap bitmap = parcel.readParcelable(null);
50  surface = new BitmapDrawable(bitmap);
51  }
52 
53  public SessionState(long instance, BookmarkBase bookmark)
54  {
55  this.instance = instance;
56  this.bookmark = bookmark;
57  this.openUri = null;
58  this.uiEventListener = null;
59  }
60 
61  public SessionState(long instance, Uri openUri)
62  {
63  this.instance = instance;
64  this.bookmark = null;
65  this.openUri = openUri;
66  this.uiEventListener = null;
67  }
68 
69  public void connect(Context context)
70  {
71  if (bookmark != null)
72  {
73  LibFreeRDP.setConnectionInfo(context, instance, bookmark);
74  }
75  else
76  {
77  LibFreeRDP.setConnectionInfo(context, instance, openUri);
78  }
79  LibFreeRDP.connect(instance);
80  }
81 
82  public long getInstance()
83  {
84  return instance;
85  }
86 
87  public BookmarkBase getBookmark()
88  {
89  return bookmark;
90  }
91 
92  public Uri getOpenUri()
93  {
94  return openUri;
95  }
96 
97  public LibFreeRDP.UIEventListener getUIEventListener()
98  {
99  return uiEventListener;
100  }
101 
102  public void setUIEventListener(LibFreeRDP.UIEventListener uiEventListener)
103  {
104  this.uiEventListener = uiEventListener;
105  }
106 
107  public BitmapDrawable getSurface()
108  {
109  return surface;
110  }
111 
112  public void setSurface(BitmapDrawable surface)
113  {
114  this.surface = surface;
115  }
116 
117  @Override public int describeContents()
118  {
119  return 0;
120  }
121 
122  @Override public void writeToParcel(Parcel out, int flags)
123  {
124  out.writeLong(instance);
125  out.writeParcelable(bookmark, flags);
126  out.writeParcelable(openUri, flags);
127  out.writeParcelable(surface.getBitmap(), flags);
128  }
129 }