Skip to content

Commit

Permalink
Merge pull request benjymous#5 from garthy/master
Browse files Browse the repository at this point in the history
A bunch of cleanups and one crashing fix
  • Loading branch information
benjymous committed Mar 9, 2012
2 parents d4b70f4 + efaec03 commit 76a4247
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 79 deletions.
17 changes: 8 additions & 9 deletions src/org/metawatch/manager/AppBlacklist.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ protected void onPostExecute(List<AppInfo> appInfos) {
ListView listView = (ListView) findViewById(android.R.id.list);
// listView.setAdapter(new ArrayAdapter<String>(this,
// android.R.layout.simple_list_item_1, menuList));
listView.setAdapter(new BlacklistAdapter(AppBlacklist.this,
appInfos));
listView.setAdapter(new BlacklistAdapter(appInfos));
AppBlacklist.this.appInfos = appInfos;
pdWait.dismiss();

Expand All @@ -107,20 +106,20 @@ public int compareTo(AppInfo another) {
}

class BlacklistAdapter extends ArrayAdapter<AppInfo> {
private final Activity context;
private final List<AppInfo> apps;

public BlacklistAdapter(Activity context, List<AppInfo> apps) {
super(context, R.layout.app_blacklist_list_item, apps);
this.context = context;
public BlacklistAdapter( List<AppInfo> apps) {
super(AppBlacklist.this, R.layout.app_blacklist_list_item, apps);
this.apps = apps;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
LayoutInflater inflater = context.getLayoutInflater();
view = inflater.inflate(R.layout.app_blacklist_list_item, null);
View view = convertView;
LayoutInflater inflater = AppBlacklist.this.getLayoutInflater();
if(view == null) {
view = inflater.inflate(R.layout.app_blacklist_list_item, null);
}
ImageView icon = (ImageView) view
.findViewById(R.id.app_blacklist_list_item_icon);
TextView appName = (TextView) view
Expand Down
19 changes: 10 additions & 9 deletions src/org/metawatch/manager/DeviceSelection.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,19 @@ public void onReceive(Context context, Intent intent) {
ListView listView;
//static ArrayList<String> menuList = new ArrayList<String>();
List<Map<String, String>> list = new ArrayList<Map<String, String>>();

private Receiver receiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;

// No point in discovering if it's switched off
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
if((defaultAdapter == null) || (!BluetoothAdapter.getDefaultAdapter().isEnabled())) {
finish();
return;
}

pdWait = ProgressDialog.show(this, "Please wait", "Searching Bluetooth devices...");
pdWait.setCancelable(true);
pdWait.setOnCancelListener(new OnCancelListener() {
Expand Down Expand Up @@ -155,7 +162,7 @@ public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
}

Receiver receiver = new Receiver();
receiver = new Receiver();
IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
intentFilter.addAction(BluetoothDevice.ACTION_FOUND);

Expand Down Expand Up @@ -203,13 +210,7 @@ public void handleMessage(Message msg) {

@Override
protected void onDestroy() {

super.onDestroy();
unregisterReceiver(receiver);
}






}
7 changes: 3 additions & 4 deletions src/org/metawatch/manager/MediaControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ public static void updateNowPlaying(Context context, String artist, String album
if (artist.equals(MediaControl.lastArtist) && track.equals(MediaControl.lastTrack) && album.equals(MediaControl.lastAlbum)) {
if (Preferences.logging) Log.d(MetaWatch.TAG, "updateNowPlaying(): Track info hasn't changed, ignoring");
return;
} else {
MediaControl.lastArtist = artist;
MediaControl.lastTrack = track;
MediaControl.lastAlbum = album;
}
MediaControl.lastArtist = artist;
MediaControl.lastTrack = track;
MediaControl.lastAlbum = album;

if(MediaControl.mediaPlayerActive)
Idle.updateLcdIdle(context);
Expand Down
25 changes: 13 additions & 12 deletions src/org/metawatch/manager/MetaWatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,6 @@ protected void onCreate(Bundle savedInstanceState) {
textView = MetaWatchStatus.textView;
toggleButton = MetaWatchStatus.toggleButton;
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}

@Override
protected void onStart() {
super.onStart();

MetaWatchService.loadPreferences(this);

Expand All @@ -186,6 +174,19 @@ public void onClick(View v) {
if (isServiceRunning() || Preferences.autoConnect) {
startService();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}

@Override
protected void onStart() {
super.onStart();

}

@Override
Expand Down
77 changes: 40 additions & 37 deletions src/org/metawatch/manager/Monitors.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,8 @@ private static synchronized void updateWeatherDataGoogle(Context context) {
WeatherData.forecast[i].day = wfc.getDayofWeek();

if (Preferences.weatherCelsius) {
WeatherData.forecast[i].tempHigh =
Integer.toString(wfc.getTempMaxCelsius());
WeatherData.forecast[i].tempLow =
Integer.toString(wfc.getTempMinCelsius());
WeatherData.forecast[i].tempHigh = wfc.getTempMaxCelsius().toString();
WeatherData.forecast[i].tempLow = wfc.getTempMinCelsius().toString();
} else {
WeatherData.forecast[i].tempHigh =
Integer.toString(WeatherUtils
Expand Down Expand Up @@ -759,43 +757,48 @@ public static JSONObject getJSONfromURL(String url){
}

//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
if (is != null) {
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
if (Preferences.logging)
Log.e(MetaWatch.TAG,
"Error converting result " + e.toString());
}
is.close();
result=sb.toString();
}catch(Exception e){
if (Preferences.logging) Log.e(MetaWatch.TAG, "Error converting result "+e.toString());
}

//dump to sdcard for debugging
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard, "weather.json");
// dump to sdcard for debugging
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard, "weather.json");

try {
FileWriter writer = new FileWriter(file);
writer.append(result);
writer.flush();
writer.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
FileWriter writer = new FileWriter(file);
writer.append(result);
writer.flush();
writer.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

//try parse the string to a JSON object
try{
jArray = new JSONObject(result);
}catch(JSONException e){
if (Preferences.logging) Log.e(MetaWatch.TAG, "Error parsing data "+e.toString());
// try parse the string to a JSON object
try {
jArray = new JSONObject(result);
} catch (JSONException e) {
if (Preferences.logging)
Log.e(MetaWatch.TAG, "Error parsing data " + e.toString());
}
}

return jArray;
}

Expand Down
8 changes: 4 additions & 4 deletions src/org/metawatch/manager/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static synchronized void stopProtocolSender() {
}
}

public static Boolean sendLcdBitmap(Bitmap bitmap, int bufferType) {
public static boolean sendLcdBitmap(Bitmap bitmap, int bufferType) {
if (bitmap==null)
return false;

Expand All @@ -162,7 +162,7 @@ public static Boolean sendLcdBitmap(Bitmap bitmap, int bufferType) {
return sendLcdArray(pixelArray, bufferType);
}

static Boolean sendLcdArray(int[] pixelArray, int bufferType) {
static boolean sendLcdArray(int[] pixelArray, int bufferType) {
byte send[] = new byte[1152];

for (int i = 0; i < 1152; i++) {
Expand All @@ -186,7 +186,7 @@ static Boolean sendLcdArray(int[] pixelArray, int bufferType) {
return sendLcdBuffer(send, bufferType);
}

static Boolean sendLcdBuffer(byte[] buffer, int bufferType) {
static boolean sendLcdBuffer(byte[] buffer, int bufferType) {
if (MetaWatchService.connectionState != MetaWatchService.ConnectionState.CONNECTED)
return false;

Expand Down Expand Up @@ -703,7 +703,7 @@ public static void setNvalTime(boolean militaryTime) {
enqueue(bytes);
}

public static void ledChange(Boolean ledOn) {
public static void ledChange(boolean ledOn) {
if (Preferences.logging) Log.d(MetaWatch.TAG, "Protocol.ledChange()");
byte[] bytes = new byte[4];

Expand Down
4 changes: 0 additions & 4 deletions src/org/metawatch/manager/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,8 @@ public static String getContactNameFromNumber(Context context, String number) {

if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndex(PhoneLookup.DISPLAY_NAME));
c.close();

if (name.length() > 0)
return name;
else
return number;
}

c.close();
Expand Down

0 comments on commit 76a4247

Please sign in to comment.