Commit 18f4ba66 authored by Thomas Krex's avatar Thomas Krex
Browse files

Internetverbindung wird für services abgefragt

parent 00b9fb47
......@@ -8,24 +8,6 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/test_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/watch_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="72dp"
android:text="Test" />
<Button
android:id="@+id/liveChannel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:text="Feedback Channel" />
<Button
android:id="@+id/watch_button"
android:layout_width="wrap_content"
......
......@@ -3,6 +3,8 @@
<item
android:id="@+id/add"
android:icon="@android:drawable/ic_input_add"
android:showAsAction="always"
android:title="addFeed">
</item>
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">test</string>
<string name="app_name">TTTClient</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="wait">Please Wait. Reading File</string>
......
......@@ -21,8 +21,7 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import com.example.test.R;
import de.tum.in.tttclient.R;
public class FeedActivity extends Activity implements OnItemClickListener,
OnItemLongClickListener {
......
......@@ -20,6 +20,8 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
......@@ -33,8 +35,7 @@ import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import com.example.test.R;
import de.tum.in.tttclient.R;
public class FeedDetailActivity extends Activity implements
OnItemClickListener, OnItemLongClickListener {
......@@ -160,7 +161,11 @@ public class FeedDetailActivity extends Activity implements
intent.putExtra(Consts.SERVICE_ID, Consts.PARSE_SERVICE_ID);
intent.putExtra(ParseService.URL_STRING, feedUrl);
startService(intent);
if (isNetworkAvailable())
startService(intent);
else
Toast.makeText(getApplicationContext(),
"Internet Connection needed", Toast.LENGTH_LONG).show();
}
......@@ -228,15 +233,19 @@ public class FeedDetailActivity extends Activity implements
public void startDownloadService() {
progressDialog.show();
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra(DownloadService.FILE_NAME, title);
intent.putExtra(DownloadService.FILE_URL, link);
intent.putExtra(DownloadService.PROGRESS_RECEIVER,
new DownloadReceiver(new Handler()));
if (isNetworkAvailable()) {
progressDialog.show();
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra(DownloadService.FILE_NAME, title);
intent.putExtra(DownloadService.FILE_URL, link);
intent.putExtra(DownloadService.PROGRESS_RECEIVER,
new DownloadReceiver(new Handler()));
// Start download service
startService(intent);
// Start download service
startService(intent);
} else
Toast.makeText(getApplicationContext(),
"Internet Connection needed", Toast.LENGTH_LONG).show();
}
......@@ -311,6 +320,13 @@ public class FeedDetailActivity extends Activity implements
return false;
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager
.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
public class DownloadReceiver extends ResultReceiver {
public DownloadReceiver(Handler handler) {
......
package tttclient.activities;
import java.net.InetAddress;
import java.net.UnknownHostException;
import tttclient.services.DownloadService;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import com.example.test.R;
import de.tum.in.tttclient.R;
public class MainActivity extends Activity {
......@@ -35,65 +27,50 @@ public class MainActivity extends Activity {
}
});
Button testButton = (Button) findViewById(R.id.test_button);
testButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),
PlayerActivity.class);
intent.putExtra(DownloadService.FILE_NAME,
"Diskrete_Strukturen_2014_01_09");
intent.putExtra(DownloadService.FILE_PATH,
"/mnt/sdcard/ttt/Diskrete_Strukturen_2014_01_09");
startActivity(intent);
}
});
Button connectButton = (Button) findViewById(R.id.liveChannel_button);
connectButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// get prompts.xml view
Dialog dialog = new Dialog(MainActivity.this);
dialog.setTitle(getString(R.string.prompt_title));
dialog.setContentView(R.layout.dialog_connect);
final EditText severInput = (EditText) dialog
.findViewById(R.id.server_tx);
final EditText portInput = (EditText) dialog
.findViewById(R.id.port_tx);
final Button connectButton = (Button) dialog
.findViewById(R.id.connect_btn);
final CheckBox checkBox = (CheckBox) dialog
.findViewById(R.id.checkBox1);
connectButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
InetAddress serverAdress = InetAddress
.getByName(severInput.getText().toString());
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int port = Integer.parseInt(portInput.getText()
.toString());
final boolean multicast = checkBox.isChecked();
}
});
dialog.show();
}
});
// Button connectButton = (Button)
// findViewById(R.id.liveChannel_button);
// connectButton.setOnClickListener(new OnClickListener() {
//
// @Override
// public void onClick(View v) {
// // get prompts.xml view
//
// Dialog dialog = new Dialog(MainActivity.this);
// dialog.setTitle(getString(R.string.prompt_title));
// dialog.setContentView(R.layout.dialog_connect);
//
// final EditText severInput = (EditText) dialog
// .findViewById(R.id.server_tx);
// final EditText portInput = (EditText) dialog
// .findViewById(R.id.port_tx);
// final Button connectButton = (Button) dialog
// .findViewById(R.id.connect_btn);
// final CheckBox checkBox = (CheckBox) dialog
// .findViewById(R.id.checkBox1);
//
// connectButton.setOnClickListener(new OnClickListener() {
//
// @Override
// public void onClick(View v) {
// try {
// InetAddress serverAdress = InetAddress
// .getByName(severInput.getText().toString());
// } catch (UnknownHostException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// int port = Integer.parseInt(portInput.getText()
// .toString());
//
// final boolean multicast = checkBox.isChecked();
//
// }
// });
//
// dialog.show();
//
// }
// });
}
}
......@@ -14,12 +14,10 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
......@@ -29,8 +27,7 @@ import android.widget.ScrollView;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.ViewSwitcher;
import com.example.test.R;
import de.tum.in.tttclient.R;
public class PlayerActivity extends Activity implements MediaPlayerControl {
......@@ -42,9 +39,6 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
private Recording recording;
private MediaPlayer audioPlayer;
private MediaController audioController;
private SurfaceView surfaceView;
private int imgVHeight;
private int imgVWidth;
private SearchView searchView;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
......@@ -53,7 +47,6 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player_main);
scrollView = (ScrollView) findViewById(R.id.indexScrollView);
// surfaceView = (SurfaceView) findViewById(R.id.playerView_fullscreen);
switcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
......@@ -68,12 +61,6 @@ public class PlayerActivity extends Activity implements MediaPlayerControl {
File audioFile = new File(filePath + "/" + fileName + ".mp3");
audioPlayer = MediaPlayer.create(this, Uri.fromFile(audioFile));
Log.d("Player", " width: " + imgVWidth + " , height: " + imgVHeight);
Display display = getWindowManager().getDefaultDisplay();
final int screenWidth = display.getWidth(); // deprecated
final int screenHeight = display.getHeight(); // deprecated
audioController = new MediaController(this);
audioController.setMediaPlayer(this);
audioController.setHorizontalScrollBarEnabled(false);
......
......@@ -48,8 +48,19 @@ public class GraphicsContext implements MessageConsumer {
private final byte[] hextile_fg_encoded;
private final int[] pixels;
public Recording getRecording() {
return recording;
public static void fillRect(int[] array, Rect r, int color, int screenWidth) {
int x = r.left;
int y = r.top;
int w = r.width();
int h = r.height();
for (int i = y; i < y + h; i++) {
int offset = i * screenWidth + x;
for (int j = 0; j < w; j++) {
array[offset + j] = color;
}
}
}
public GraphicsContext(ImageView imgV, Recording record) {
......@@ -73,6 +84,9 @@ public class GraphicsContext implements MessageConsumer {
hextile_bg_encoded = new byte[prefs.bytesPerPixel];
hextile_fg_encoded = new byte[prefs.bytesPerPixel];
// hanlder do tasks, which has to be done in the UI-Thread
// Updating of ImageView
viewHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(android.os.Message inputMessage) {
......@@ -86,7 +100,7 @@ public class GraphicsContext implements MessageConsumer {
}
};
// Updating of ScrollView
scrollHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(android.os.Message inputMessage) {
......@@ -111,44 +125,29 @@ public class GraphicsContext implements MessageConsumer {
//
// }
public static void fillRect(int[] array, Rect r, int color, int screenWidth) {
int x = r.left;
int y = r.top;
int w = r.width();
int h = r.height();
for (int i = y; i < y + h; i++) {
int offset = i * screenWidth + x;
for (int j = 0; j < w; j++) {
array[offset + j] = color;
}
}
}
public static void borderRect(int[] array, Rect r, int color,
int screenWidth) {
int x = r.left;
int y = r.top;
int w = r.width();
int h = r.height();
for (int i = y; i < y + h; i++) {
int offset = i * screenWidth + x;
if (i == y || i == y + h - 1) {
for (int j = 0; j < w; j++) {
array[offset + j] = color;
}
} else {
for (int j = 0; j < w; j++) {
if (j == 0 || j == w - 1)
array[offset + j] = color;
}
}
}
}
// public static void borderRect(int[] array, Rect r, int color,
// int screenWidth) {
// int x = r.left;
// int y = r.top;
// int w = r.width();
// int h = r.height();
//
// for (int i = y; i < y + h; i++) {
// int offset = i * screenWidth + x;
// if (i == y || i == y + h - 1) {
// for (int j = 0; j < w; j++) {
//
// array[offset + j] = color;
// }
// } else {
// for (int j = 0; j < w; j++) {
// if (j == 0 || j == w - 1)
// array[offset + j] = color;
// }
//
// }
// }
// }
// public void updateOverlay() {
//
......@@ -184,6 +183,10 @@ public class GraphicsContext implements MessageConsumer {
return this.prefs;
}
public Recording getRecording() {
return recording;
}
public byte[] getHextile_bg_encoded() {
return hextile_bg_encoded;
}
......@@ -196,6 +199,7 @@ public class GraphicsContext implements MessageConsumer {
return this.scrollHandler;
}
// TODO welche Methoden werden wann benötigt
// draw Canvas on current Bitmap
public void updateCanvas() {
if (refreshEnabled) {
......@@ -272,7 +276,6 @@ public class GraphicsContext implements MessageConsumer {
bitmapContainer.getBimap().setPixels(pixels,
x + y * prefs.framebufferWidth, prefs.framebufferWidth, x,
y, w, h);
Rect change = new Rect(x, y, x + w, y + h);
// bitmapContainer.getBimap().setPixels(pixels, 0,
// prefs.framebufferWidth, 0, 0, prefs.framebufferWidth,
......@@ -376,8 +379,6 @@ public class GraphicsContext implements MessageConsumer {
}
// show desktop
return scaledScreenshot;
}
......
......@@ -122,15 +122,6 @@ public class Recording extends MessageProducerAdapter implements Runnable {
setTime(0, true);
}
// public void setIndexViewer(ScrollView scrollView) {
// this.indexViewer = scrollView;
// }
public ScrollView getIndexViewer() {
return indexViewer;
}
void read(File file) throws IOException {
DataInputStream in = new DataInputStream(new BufferedInputStream(
......@@ -157,9 +148,6 @@ public class Recording extends MessageProducerAdapter implements Runnable {
// read body of recording
messages.readMessages(in);
// read search bases
// TODO: upercase ending??
// readSearchbaseFromFile();
}
@Override
......@@ -269,9 +257,6 @@ public class Recording extends MessageProducerAdapter implements Runnable {
parseExtensions();
// no original, but modified recording
if (extensions.size() > 0)
original = false;
}
private void parseExtensions() throws IOException {
......@@ -421,11 +406,6 @@ public class Recording extends MessageProducerAdapter implements Runnable {
next_message = next;
}
// public void highlightSearchResults(Canvas canvas) {
// index.highlightSearchResultsOfCurrentIndex(canvas);
//
// }
public void highlightSearchResults(Canvas canvas) {
// int[] pixelCopy = new int[graphicsContext().getPixels().length];
// System.arraycopy(graphicsContext().getPixels(), 0, pixelCopy, 0,
......@@ -435,11 +415,14 @@ public class Recording extends MessageProducerAdapter implements Runnable {
}
// /*******************************************************************************************************************
// * playback control *
// ******************************************************************************************************************/
//
private Thread thread;
/*******************************************************************************************************************
* Index ScrollView *
******************************************************************************************************************/
public ScrollView getIndexViewer() {
return indexViewer;
}
public void initIndexView() {
......@@ -484,28 +467,11 @@ public class Recording extends MessageProducerAdapter implements Runnable {
return title;
}
// public void focusCurrentIndexEntry(int i) {
// if (index.thumbnailsAvailable()) {
// final IndexEntry entry = index.get(i);
//
// // display is not being updated to avoid to much work load
// graphicsContext.enableRefresh(false);
// // new Handler(Looper.getMainLooper()).post(new Runnable() {
// // @Override
// // public void run() {
// // int[] position = new int[2];
// // entry.getLocationInWindow(position);
// // // indexViewer.scrollTo(0, position[1] + entry.getWidth());
// // Log.d("Index", " scroll to x: " + position[1]);
// //
// // }
// // });
//
// graphicsContext.enableRefresh(true);
// }
// }
/*******************************************************************************************************************
* playback control *
******************************************************************************************************************/
private Thread thread;
//
// start playback
synchronized public void play() {
// ensure thread is running
......@@ -552,6 +518,13 @@ public class Recording extends MessageProducerAdapter implements Runnable {
setTime(index.getPreviousIndex().getTimestamp(), true);
}
synchronized public void stop() {
pause();
// blank framebuffer
whiteOut();
// setTime(0);
}
//
public int timeset;
......@@ -655,7 +628,8 @@ public class Recording extends MessageProducerAdapter implements Runnable {
public void fireIndexChangedEvent(int indexNumber) {
if (lastIndexFired != indexNumber) {
// highlighting of index entry has to be done in ui thread
// highlighting of index entry and scrolling has to be done in ui
// thread
if (lastIndexFired > 0) {
android.os.Message unMarkMessage = graphicsContext
.getScrollHandler().obtainMessage(0, lastIndexFired,
......@@ -667,9 +641,6 @@ public class Recording extends MessageProducerAdapter implements Runnable {
android.os.Message markMessage = graphicsContext.getScrollHandler()
.obtainMessage(0, indexNumber, Color.RED);
markMessage.sendToTarget();
// focusCurrentIndexEntry(index - 1);
// highlightSearchResults(graphicsContext().getCanvas());
}
}
......@@ -678,23 +649,4 @@ public class Recording extends MessageProducerAdapter implements Runnable {
return index.createScreenshots();
}
/*******************************************************************************************************************
* write to file *
******************************************************************************************************************/
// original recording flag - used for first backup name
private boolean original = true;
/**
* Save the recording in a new file
*
* @param OutputFile
* saves the recording into this file
*/
synchronized public void stop() {
pause();
// blank framebuffer
whiteOut();
// setTime(0);
}
}
\ No newline at end of file