From: <Rol...@us...> - 2010-12-14 04:10:16
|
Revision: 4030 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4030&view=rev Author: Rollsroyc3 Date: 2010-12-14 04:10:10 +0000 (Tue, 14 Dec 2010) Log Message: ----------- added worker thread code with dialogs to pictures. started swipe code with context menu. Modified Paths: -------------- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures.java trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturesfullscreen.java Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures.java 2010-12-11 11:49:00 UTC (rev 4029) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/pictures.java 2010-12-14 04:10:10 UTC (rev 4030) @@ -28,6 +28,7 @@ import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.util.Log; @@ -112,35 +113,50 @@ private Runnable mUpdateTimeTask = new Runnable() { public void run() { - update(); + new update().execute(); + //update(); } }; - private void update() { + + + private class update extends AsyncTask<String, Void, Void> { + private final ProgressDialog dialog = new ProgressDialog(pictures.this); + + // can use UI thread here + protected void onPreExecute() { + this.dialog.setMessage("Loading..."); + this.dialog.show(); + } + + // automatically done on worker thread (separate from UI thread) + protected Void doInBackground(final String... args) { + Log.d("update pictures", "do update folder : " + actualDir); + + ReceiveDirHandler h = ReceiveDirHandler.getinstance(); + pictureList = h.getPictureDir(actualDir); - ProgressDialog dialog = new ProgressDialog(this); - dialog.setCancelable(true); - dialog.setMessage("Loading..."); - dialog.show(); - + return null; + } + + // can use UI thread here + protected void onPostExecute(final Void unused) { + if (this.dialog.isShowing()) { + this.dialog.dismiss(); + } - Log.d("update pictures", "do update folder : " + actualDir); - - ReceiveDirHandler h = ReceiveDirHandler.getinstance(); - pictureList = h.getPictureDir(actualDir); - - if (pictureList.size() == 0) { + if (pictureList.size() == 0) { Toast.makeText(pictures.this, "TIME OUT SERVER", Toast.LENGTH_SHORT) .show(); - } else { - GridView gridview = (GridView) findViewById(R.id.GridView01); - gridview.setAdapter(new ImageAdapter2(this)); - } - - dialog.cancel(); - } - - public class ImageAdapter2 extends BaseAdapter { + } else { + GridView gridview = (GridView) findViewById(R.id.GridView01); + gridview.setAdapter(new ImageAdapter2(pictures.this)); + } + } + } + + + public class ImageAdapter2 extends BaseAdapter { private Context mContext; public static final int ACTIVITY_CREATE = 10; Modified: trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturesfullscreen.java =================================================================== --- trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturesfullscreen.java 2010-12-11 11:49:00 UTC (rev 4029) +++ trunk/plugins/AndroidRemote/Android/MediaPortalRemote/src/mediaportal/remote/picturesfullscreen.java 2010-12-14 04:10:10 UTC (rev 4030) @@ -29,30 +29,40 @@ import mediaportal.remote.R; import mediaportal.remote.ReceiveDirectoryXmlHandler.DirItems; import android.app.Activity; +import android.app.ProgressDialog; import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.util.Log; import android.view.ContextMenu; +import android.view.GestureDetector; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.ContextMenu.ContextMenuInfo; +import android.view.GestureDetector.OnGestureListener; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; -public class picturesfullscreen extends Activity { +public class picturesfullscreen extends Activity implements OnGestureListener { private Handler mHandler = new Handler(); - + private GestureDetector gestureScanner; + private static final int SWIPE_MIN_DISTANCE = 120; + private static final int SWIPE_MAX_OFF_PATH = 250; + private static final int SWIPE_THRESHOLD_VELOCITY = 200; private boolean slideShow; private boolean randomShow; + public static boolean SlideshowPaused = false; + private static long SlideInterval = 6000; /** Called when the activity is first created. */ @Override @@ -65,33 +75,63 @@ setContentView(R.layout.picturesfullscreen); ImageView imagev = (ImageView) findViewById(R.id.ImageView01); - registerForContextMenu(imagev); - - setPicture(); + //registerForContextMenu(imagev); + + gestureScanner = new GestureDetector(this); + + new setPicture().execute(); + } - private void setPicture() { - ImageView imagev = (ImageView) findViewById(R.id.ImageView01); - DirItems item = pictures.pictureList.get(pictures.selectedPicture); - if (!item.isFolder) { - httpHandler http = new httpHandler(); - String file = "http://" + Settings.Server + ":" + Settings.Port - + "/pictures/"; - file += pictures.actualDir + item.File; - item.Picture = http.DownloadImage(file.replaceAll(" ", "%20")); - imagev.setImageBitmap(item.Picture); + + + + private class setPicture extends AsyncTask<String, Void, Void> { + private final ProgressDialog dialog = new ProgressDialog(picturesfullscreen.this); + DirItems item = pictures.pictureList.get(pictures.selectedPicture); + + // can use UI thread here + protected void onPreExecute() { + this.dialog.setMessage("Loading..."); + this.dialog.show(); + } + + // automatically done on worker thread (separate from UI thread) + protected Void doInBackground(final String... args) { + if (!item.isFolder) { + httpHandler http = new httpHandler(); + String file = "http://" + Settings.Server + ":" + Settings.Port + + "/pictures/"; + file += pictures.actualDir + item.File; + item.Picture = http.DownloadImage(file.replaceAll(" ", "%20")); + } + + return null; + } + + // can use UI thread here + protected void onPostExecute(final Void unused) { + if (this.dialog.isShowing()) { + this.dialog.dismiss(); + } + + if (item.isFolder != true){ + ImageView imagev = (ImageView) findViewById(R.id.ImageView01); + imagev.setImageBitmap(item.Picture); + TextView txt = (TextView) findViewById(R.id.full_text); + txt.setText(item.File); + } - TextView txt = (TextView) findViewById(R.id.full_text); - txt.setText(item.File); - } - } + } + } + @Override public void onStart() { super.onStart(); mHandler.removeCallbacks(mUpdateTimeTask); - mHandler.postDelayed(mUpdateTimeTask, 2000); + mHandler.postDelayed(mUpdateTimeTask, SlideInterval); } private Runnable mUpdateTimeTask = new Runnable() { @@ -105,7 +145,8 @@ pictures.selectedPicture++; else pictures.selectedPicture = 0; - setPicture(); + + new setPicture().execute(); } else { String req = "http://" + Settings.Server + ":" + Settings.Port + "/random/pictures/random.jpg"; @@ -121,16 +162,26 @@ } } - mHandler.postDelayed(mUpdateTimeTask, 2000); + mHandler.postDelayed(mUpdateTimeTask, SlideInterval); } }; @Override public void onPause() { super.onPause(); + SlideshowPaused = true; mHandler.removeCallbacks(mUpdateTimeTask); } - + + + @Override + protected void onResume() { + super.onResume(); + SlideshowPaused = false; + mHandler.removeCallbacks(mUpdateTimeTask); + mHandler.postDelayed(mUpdateTimeTask, SlideInterval); + } + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); @@ -257,5 +308,88 @@ // e.printStackTrace(); } } + + + @Override + public boolean onTouchEvent(MotionEvent me) { + this.gestureScanner.onTouchEvent(me); + return super.onTouchEvent(me); + } + + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, + float velocityY) { + try { + int max = pictures.pictureList.size(); + + if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) + return false; + // right to left swipe + if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE + && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { + + if (pictures.selectedPicture < max - 1) { + pictures.selectedPicture++; + new setPicture().execute(); + } else + Toast.makeText(this, "reached end +", + Toast.LENGTH_SHORT).show(); + return true; + } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE + && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { + + if (pictures.selectedPicture > 0) { + pictures.selectedPicture--; + new setPicture().execute(); + } else + Toast.makeText(this, "reached end -", + Toast.LENGTH_SHORT).show(); + return true; + } + } catch (Exception e) { + // nothing + } + return false; + } + + public boolean onDown(MotionEvent arg0) { + return false; + } + + public void onLongPress(MotionEvent arg0) { + } + + public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, + float arg3) { + return false; + } + + public void onShowPress(MotionEvent arg0) { + } + + public boolean onSingleTapUp(MotionEvent arg0) { + if (slideShow == true || randomShow == true){ + if (SlideshowPaused == false) + { + onPause(); + Toast.makeText(this, "Pause", + Toast.LENGTH_SHORT).show(); + return true; + } + else + { + onResume(); + Toast.makeText(this, "Play", + Toast.LENGTH_SHORT).show(); + return true; + } + } + else + { + return false; + } + } + + + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |