15
15
import android .view .View ;
16
16
import android .widget .Button ;
17
17
import android .widget .ImageView ;
18
+ import android .widget .ProgressBar ;
18
19
import android .widget .Toast ;
19
20
20
21
import com .adobe .creativesdk .foundation .auth .AdobeAuthException ;
@@ -36,6 +37,7 @@ public class MainActivity extends AppCompatActivity {
36
37
private Button mOpenGalleryButton ;
37
38
private Button mSendToPhotoshopButton ;
38
39
private ImageView mSelectedImageView ;
40
+ private ProgressBar mSendToDesktopProgressBar ;
39
41
40
42
private Uri mSelectedImageUri ;
41
43
@@ -52,6 +54,8 @@ protected void onCreate(Bundle savedInstanceState) {
52
54
mOpenGalleryButton = (Button ) findViewById (R .id .openGalleryButton );
53
55
mSendToPhotoshopButton = (Button ) findViewById (R .id .sendToPhotoshopButton );
54
56
mSelectedImageView = (ImageView ) findViewById (R .id .selectedImageView );
57
+ mSendToDesktopProgressBar = (ProgressBar ) findViewById (R .id .sendToDesktopProgressBar );
58
+ mSendToDesktopProgressBar .setVisibility (View .INVISIBLE );
55
59
56
60
FloatingActionButton fab = (FloatingActionButton ) findViewById (R .id .fab );
57
61
fab .setOnClickListener (new View .OnClickListener () {
@@ -109,16 +113,41 @@ public void onClick(View v) {
109
113
@ Override
110
114
public void onClick (View v ) {
111
115
112
- if (mSelectedImageUri != null ) {
113
- try {
114
- sendToDesktop ();
115
- } catch (IOException e ) {
116
- e .printStackTrace ();
116
+ mSendToDesktopProgressBar .setVisibility (View .VISIBLE );
117
+
118
+ new Thread (new Runnable () {
119
+ @ Override
120
+ public void run () {
121
+
122
+ if (mSelectedImageUri != null ) {
123
+ try {
124
+ sendToDesktop ();
125
+ } catch (IOException e ) {
126
+ e .printStackTrace ();
127
+
128
+ runOnUiThread (new Runnable () {
129
+ @ Override
130
+ public void run () {
131
+ mSendToDesktopProgressBar .setVisibility (View .INVISIBLE );
132
+ Toast .makeText (MainActivity .this , "Unable to send. Check your connection" , Toast .LENGTH_LONG ).show ();
133
+ }
134
+ });
135
+
136
+ }
137
+ }
138
+ else {
139
+
140
+ runOnUiThread (new Runnable () {
141
+ @ Override
142
+ public void run () {
143
+ mSendToDesktopProgressBar .setVisibility (View .INVISIBLE );
144
+ Toast .makeText (MainActivity .this , "Select an image from the Gallery" , Toast .LENGTH_LONG ).show ();
145
+ }
146
+ });
147
+ }
148
+
117
149
}
118
- }
119
- else {
120
- Toast .makeText (MainActivity .this , "Select an image from the Gallery" , Toast .LENGTH_LONG ).show ();
121
- }
150
+ }).start ();
122
151
}
123
152
};
124
153
mSendToPhotoshopButton .setOnClickListener (sendToPhotoshopButtonListener );
@@ -137,15 +166,27 @@ private void sendToDesktop() throws IOException {
137
166
@ Override
138
167
public void onSuccess () {
139
168
// Success case example
140
- Toast .makeText (MainActivity .this , "Opening in Photoshop on your desktop!" , Toast .LENGTH_LONG ).show ();
169
+
170
+ runOnUiThread (new Runnable () {
171
+ @ Override
172
+ public void run () {
173
+ mSendToDesktopProgressBar .setVisibility (View .INVISIBLE );
174
+ Toast .makeText (MainActivity .this , "Opening in Photoshop on your desktop!" , Toast .LENGTH_LONG ).show ();
175
+ }
176
+ });
141
177
}
142
178
143
179
@ Override
144
180
public void onError (AdobeSendToDesktopException e ) {
145
181
// Error case example
146
- Toast .makeText (MainActivity .this , "Failed!" , Toast .LENGTH_LONG ).show ();
147
-
148
182
e .printStackTrace ();
183
+
184
+ runOnUiThread (new Runnable () {
185
+ @ Override
186
+ public void run () {
187
+ Toast .makeText (MainActivity .this , "Couldn't send to Photoshop. Please try again." , Toast .LENGTH_LONG ).show ();
188
+ }
189
+ });
149
190
}
150
191
};
151
192
0 commit comments