1515import android .view .View ;
1616import android .widget .Button ;
1717import android .widget .ImageView ;
18+ import android .widget .ProgressBar ;
1819import android .widget .Toast ;
1920
2021import com .adobe .creativesdk .foundation .auth .AdobeAuthException ;
@@ -36,6 +37,7 @@ public class MainActivity extends AppCompatActivity {
3637 private Button mOpenGalleryButton ;
3738 private Button mSendToPhotoshopButton ;
3839 private ImageView mSelectedImageView ;
40+ private ProgressBar mSendToDesktopProgressBar ;
3941
4042 private Uri mSelectedImageUri ;
4143
@@ -52,6 +54,8 @@ protected void onCreate(Bundle savedInstanceState) {
5254 mOpenGalleryButton = (Button ) findViewById (R .id .openGalleryButton );
5355 mSendToPhotoshopButton = (Button ) findViewById (R .id .sendToPhotoshopButton );
5456 mSelectedImageView = (ImageView ) findViewById (R .id .selectedImageView );
57+ mSendToDesktopProgressBar = (ProgressBar ) findViewById (R .id .sendToDesktopProgressBar );
58+ mSendToDesktopProgressBar .setVisibility (View .INVISIBLE );
5559
5660 FloatingActionButton fab = (FloatingActionButton ) findViewById (R .id .fab );
5761 fab .setOnClickListener (new View .OnClickListener () {
@@ -109,16 +113,41 @@ public void onClick(View v) {
109113 @ Override
110114 public void onClick (View v ) {
111115
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+
117149 }
118- }
119- else {
120- Toast .makeText (MainActivity .this , "Select an image from the Gallery" , Toast .LENGTH_LONG ).show ();
121- }
150+ }).start ();
122151 }
123152 };
124153 mSendToPhotoshopButton .setOnClickListener (sendToPhotoshopButtonListener );
@@ -137,15 +166,27 @@ private void sendToDesktop() throws IOException {
137166 @ Override
138167 public void onSuccess () {
139168 // 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+ });
141177 }
142178
143179 @ Override
144180 public void onError (AdobeSendToDesktopException e ) {
145181 // Error case example
146- Toast .makeText (MainActivity .this , "Failed!" , Toast .LENGTH_LONG ).show ();
147-
148182 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+ });
149190 }
150191 };
151192
0 commit comments