forked from len0rd/rockbox
A bit of cleanup.
Replace // with /* */ style comments Cleanup copy&paste from the doc examples. Don't pretend to handle exception we don't handle actually. cleanup imports git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27754 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
4aa3d01066
commit
4a3e6dbe8f
5 changed files with 52 additions and 56 deletions
|
@ -86,8 +86,6 @@ public class RockboxActivity extends Activity {
|
||||||
ViewGroup g = (ViewGroup)RockboxService.fb.getParent();
|
ViewGroup g = (ViewGroup)RockboxService.fb.getParent();
|
||||||
g.removeView(RockboxService.fb);
|
g.removeView(RockboxService.fb);
|
||||||
setContentView(RockboxService.fb);
|
setContentView(RockboxService.fb);
|
||||||
} catch (Exception e) {
|
|
||||||
LOG(e.toString());
|
|
||||||
}
|
}
|
||||||
RockboxService.fb.resume();
|
RockboxService.fb.resume();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import java.nio.ByteBuffer;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.os.Handler;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -68,14 +67,14 @@ public class RockboxFramebuffer extends View
|
||||||
postInvalidate(x, y, x+w, y+h);
|
postInvalidate(x, y, x+w, y+h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private void LOG(CharSequence text)
|
private void LOG(CharSequence text)
|
||||||
{
|
{
|
||||||
Log.d("RockboxBootloader", (String) text);
|
Log.d("Rockbox", (String) text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onTouchEvent(MotionEvent me)
|
public boolean onTouchEvent(MotionEvent me)
|
||||||
{
|
{
|
||||||
LOG("onTouchEvent");
|
|
||||||
switch (me.getAction())
|
switch (me.getAction())
|
||||||
{
|
{
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
|
|
@ -138,7 +138,7 @@ public class RockboxPCM extends AudioTrack
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onMarkerReached(AudioTrack track) {
|
public void onMarkerReached(AudioTrack track) {
|
||||||
// push new data to the hardware
|
/* push new data to the hardware */
|
||||||
RockboxPCM pcm = (RockboxPCM)track;
|
RockboxPCM pcm = (RockboxPCM)track;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
pcm.pcmSamplesToByteArray(buf);
|
pcm.pcmSamplesToByteArray(buf);
|
||||||
|
@ -169,8 +169,7 @@ public class RockboxPCM extends AudioTrack
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPeriodicNotification(AudioTrack track) {
|
public void onPeriodicNotification(AudioTrack track) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package org.rockbox;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
@ -15,7 +17,6 @@ import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Binder;
|
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
@ -25,9 +26,9 @@ public class RockboxService extends Service
|
||||||
public static RockboxFramebuffer fb = null;
|
public static RockboxFramebuffer fb = null;
|
||||||
private static RockboxService instance;
|
private static RockboxService instance;
|
||||||
private Notification notification;
|
private Notification notification;
|
||||||
private static final Class[] mStartForegroundSignature = new Class[] {
|
private static final Class<?>[] mStartForegroundSignature = new Class[] {
|
||||||
int.class, Notification.class};
|
int.class, Notification.class};
|
||||||
private static final Class[] mStopForegroundSignature = new Class[] {
|
private static final Class<?>[] mStopForegroundSignature = new Class[] {
|
||||||
boolean.class};
|
boolean.class};
|
||||||
|
|
||||||
private NotificationManager mNM;
|
private NotificationManager mNM;
|
||||||
|
@ -45,7 +46,7 @@ public class RockboxService extends Service
|
||||||
mStopForeground = getClass().getMethod("stopForeground",
|
mStopForeground = getClass().getMethod("stopForeground",
|
||||||
mStopForegroundSignature);
|
mStopForegroundSignature);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
// Running on an older platform.
|
/* Running on an older platform: fall back to old API */
|
||||||
mStartForeground = mStopForeground = null;
|
mStartForeground = mStopForeground = null;
|
||||||
}
|
}
|
||||||
startservice();
|
startservice();
|
||||||
|
@ -63,6 +64,11 @@ public class RockboxService extends Service
|
||||||
{
|
{
|
||||||
Log.d("Rockbox", (String) text);
|
Log.d("Rockbox", (String) text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LOG(CharSequence text, Throwable tr)
|
||||||
|
{
|
||||||
|
Log.d("Rockbox", (String) text, tr);
|
||||||
|
}
|
||||||
|
|
||||||
public void onStart(Intent intent, int startId) {
|
public void onStart(Intent intent, int startId) {
|
||||||
do_start(intent);
|
do_start(intent);
|
||||||
|
@ -71,7 +77,7 @@ public class RockboxService extends Service
|
||||||
public int onStartCommand(Intent intent, int flags, int startId)
|
public int onStartCommand(Intent intent, int flags, int startId)
|
||||||
{
|
{
|
||||||
do_start(intent);
|
do_start(intent);
|
||||||
return 1; /* START_STICKY */
|
return 1; /* old API compatibility: 1 == START_STICKY */
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startservice()
|
private void startservice()
|
||||||
|
@ -83,8 +89,8 @@ public class RockboxService extends Service
|
||||||
* because there's no other way to ship files and have access
|
* because there's no other way to ship files and have access
|
||||||
* to them from native code
|
* to them from native code
|
||||||
*/
|
*/
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BufferedOutputStream dest = null;
|
BufferedOutputStream dest = null;
|
||||||
BufferedInputStream is = null;
|
BufferedInputStream is = null;
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
|
@ -127,8 +133,12 @@ public class RockboxService extends Service
|
||||||
is.close();
|
is.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
LOG("FileNotFoundException when unzipping", e);
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch(IOException e) {
|
||||||
|
LOG("IOException when unzipping", e);
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.loadLibrary("rockbox");
|
System.loadLibrary("rockbox");
|
||||||
|
@ -149,36 +159,25 @@ public class RockboxService extends Service
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
} /**
|
}
|
||||||
* Class for clients to access. Because we know this service always
|
|
||||||
* runs in the same process as its clients, we don't need to deal with
|
|
||||||
* IPC.
|
|
||||||
*/
|
|
||||||
public class LocalBinder extends Binder {
|
|
||||||
RockboxService getService() {
|
|
||||||
return RockboxService.this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* heavily based on the example found on
|
/* all below is heavily based on the examples found on
|
||||||
* http://developer.android.com/reference/android/app/Service.html
|
* http://developer.android.com/reference/android/app/Service.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private void create_notification()
|
private void create_notification()
|
||||||
{
|
{
|
||||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
/* For now we'll use the same text for the ticker and the expanded notification */
|
||||||
CharSequence text = getText(R.string.notification);
|
CharSequence text = getText(R.string.notification);
|
||||||
|
/* Set the icon, scrolling text and timestamp */
|
||||||
// Set the icon, scrolling text and timestamp
|
|
||||||
notification = new Notification(R.drawable.icon, text,
|
notification = new Notification(R.drawable.icon, text,
|
||||||
System.currentTimeMillis());
|
System.currentTimeMillis());
|
||||||
|
|
||||||
// The PendingIntent to launch our activity if the user selects this notification
|
/* The PendingIntent to launch our activity if the user selects this notification */
|
||||||
Intent intent = new Intent(this, RockboxActivity.class);
|
Intent intent = new Intent(this, RockboxActivity.class);
|
||||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
|
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
|
||||||
|
|
||||||
|
|
||||||
// Set the info for the views that show in the notification panel.
|
/* Set the info for the views that show in the notification panel. */
|
||||||
notification.setLatestEventInfo(this, getText(R.string.notification), text, contentIntent);
|
notification.setLatestEventInfo(this, getText(R.string.notification), text, contentIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,10 +185,11 @@ public class RockboxService extends Service
|
||||||
{
|
{
|
||||||
if (instance != null)
|
if (instance != null)
|
||||||
{
|
{
|
||||||
// Send the notification.
|
/*
|
||||||
// We use a layout id because it is a unique number. We use it later to cancel.
|
* Send the notification.
|
||||||
|
* We use a layout id because it is a unique number. We use it later to cancel.
|
||||||
|
*/
|
||||||
instance.mNM.notify(R.string.notification, instance.notification);
|
instance.mNM.notify(R.string.notification, instance.notification);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* this call makes the service run as foreground, which
|
* this call makes the service run as foreground, which
|
||||||
* provides enough cpu time to do music decoding in the
|
* provides enough cpu time to do music decoding in the
|
||||||
|
@ -212,24 +212,24 @@ public class RockboxService extends Service
|
||||||
* This is a wrapper around the new startForeground method, using the older
|
* This is a wrapper around the new startForeground method, using the older
|
||||||
* APIs if it is not available.
|
* APIs if it is not available.
|
||||||
*/
|
*/
|
||||||
void startForegroundCompat(int id, Notification notification) {
|
void startForegroundCompat(int id, Notification notification)
|
||||||
// If we have the new startForeground API, then use it.
|
{
|
||||||
if (mStartForeground != null) {
|
if (mStartForeground != null) {
|
||||||
mStartForegroundArgs[0] = Integer.valueOf(id);
|
mStartForegroundArgs[0] = Integer.valueOf(id);
|
||||||
mStartForegroundArgs[1] = notification;
|
mStartForegroundArgs[1] = notification;
|
||||||
try {
|
try {
|
||||||
mStartForeground.invoke(this, mStartForegroundArgs);
|
mStartForeground.invoke(this, mStartForegroundArgs);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
// Should not happen.
|
/* Should not happen. */
|
||||||
Log.w("ApiDemos", "Unable to invoke startForeground", e);
|
LOG("Unable to invoke startForeground", e);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
// Should not happen.
|
/* Should not happen. */
|
||||||
Log.w("ApiDemos", "Unable to invoke startForeground", e);
|
LOG("Unable to invoke startForeground", e);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back on the old API.
|
/* Fall back on the old API.*/
|
||||||
setForeground(true);
|
setForeground(true);
|
||||||
mNM.notify(id, notification);
|
mNM.notify(id, notification);
|
||||||
}
|
}
|
||||||
|
@ -238,31 +238,32 @@ public class RockboxService extends Service
|
||||||
* This is a wrapper around the new stopForeground method, using the older
|
* This is a wrapper around the new stopForeground method, using the older
|
||||||
* APIs if it is not available.
|
* APIs if it is not available.
|
||||||
*/
|
*/
|
||||||
void stopForegroundCompat(int id) {
|
void stopForegroundCompat(int id)
|
||||||
// If we have the new stopForeground API, then use it.
|
{
|
||||||
if (mStopForeground != null) {
|
if (mStopForeground != null) {
|
||||||
mStopForegroundArgs[0] = Boolean.TRUE;
|
mStopForegroundArgs[0] = Boolean.TRUE;
|
||||||
try {
|
try {
|
||||||
mStopForeground.invoke(this, mStopForegroundArgs);
|
mStopForeground.invoke(this, mStopForegroundArgs);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
// Should not happen.
|
/* Should not happen. */
|
||||||
Log.w("ApiDemos", "Unable to invoke stopForeground", e);
|
LOG("Unable to invoke stopForeground", e);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
// Should not happen.
|
/* Should not happen. */
|
||||||
Log.w("ApiDemos", "Unable to invoke stopForeground", e);
|
LOG("Unable to invoke stopForeground", e);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back on the old API. Note to cancel BEFORE changing the
|
/* Fall back on the old API. Note to cancel BEFORE changing the
|
||||||
// foreground state, since we could be killed at that point.
|
* foreground state, since we could be killed at that point. */
|
||||||
mNM.cancel(id);
|
mNM.cancel(id);
|
||||||
setForeground(false);
|
setForeground(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
// Make sure our notification is gone.
|
super.onDestroy();
|
||||||
|
/* Make sure our notification is gone. */
|
||||||
stopForegroundCompat(R.string.notification);
|
stopForegroundCompat(R.string.notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ public class RockboxTimer extends Timer
|
||||||
interval = period_inverval_in_ms;
|
interval = period_inverval_in_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private void LOG(CharSequence text)
|
private void LOG(CharSequence text)
|
||||||
{
|
{
|
||||||
Log.d("Rockbox", (String) text);
|
Log.d("Rockbox", (String) text);
|
||||||
|
@ -88,9 +89,7 @@ public class RockboxTimer extends Timer
|
||||||
try {
|
try {
|
||||||
this.wait();
|
this.wait();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
/* wakeup and return */
|
/* Not an error: wakeup and return */
|
||||||
} catch (Exception e) {
|
|
||||||
LOG(e.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue