Skip to content

Commit

Permalink
Improved exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
iiordanov committed Apr 17, 2019
1 parent d32773a commit 351d9b3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Opaque/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.undatech.opaque"
android:versionCode="1480"
android:versionName="1.4.8" >
android:versionCode="1490"
android:versionName="1.4.9" >

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
Expand Down
14 changes: 9 additions & 5 deletions Opaque/src/main/java/com/undatech/opaque/ClipboardMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ public ClipboardMonitor (Context c, RemoteCanvas vc) {
* Grab the current clipboard contents.
*/
private String getClipboardContents () {
if (clipboard != null && clipboard.getText() != null)
return clipboard.getText().toString();
else
return null;
CharSequence clipboardContents = null;
if (clipboard != null) {
clipboardContents = clipboard.getText();
}
if (clipboardContents != null) {
return clipboardContents.toString();
}
return null;
}

/*
* (non-Javadoc)
* @see java.util.TimerTask#run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ public void onClick(View arg0) {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
android.util.Log.e(TAG, new Integer(position).toString() + ((TextView)view).getText().toString());
// TODO Auto-generated method stub
if (view != null) {
android.util.Log.e(TAG, "Selected connection type: " +
Integer.toString(position) + ((TextView)view).getText());
}
}

@Override
Expand Down Expand Up @@ -171,10 +173,15 @@ public void onNothingSelected(AdapterView<?> parent) {}
private String nextLargestNumber(String[] numbers) {
int maxValue = 0;
if (numbers != null) {
for (int i = 0; i < numbers.length; i++) {
int currValue = Integer.parseInt(numbers[i]);
if (currValue >= maxValue) {
maxValue = currValue + 1;
for (String num : numbers) {
int currValue = 0;
try {
currValue = Integer.parseInt(num);
if (currValue >= maxValue) {
maxValue = currValue + 1;
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
Expand All @@ -190,7 +197,7 @@ private String nextLargestNumber(String[] numbers) {
private void loadConnections() {
SharedPreferences sp = appContext.getSharedPreferences("generalSettings", Context.MODE_PRIVATE);
connectionsList = sp.getString("connections", null);
if (connectionsList != null && !connectionsList.equals("")) {
if (connectionsList != null && !connectionsList.trim().equals("")) {
connectionsArray = connectionsList.split(" ");
}
}
Expand Down Expand Up @@ -231,12 +238,12 @@ private void deleteConnection() {

String newListOfConnections = new String();
if (connectionsArray != null) {
for (int i = 0; i < connectionsArray.length; i++) {
if (!connectionsArray[i].equals(currentSelectedConnection)) {
newListOfConnections += " " + connectionsArray[i];
for (String connection : connectionsArray) {
if (!connection.equals(currentSelectedConnection)) {
newListOfConnections += " " + connection;
}
}

android.util.Log.d(TAG, "Deleted connection, current list: " + newListOfConnections);
SharedPreferences sp = appContext.getSharedPreferences("generalSettings", Context.MODE_PRIVATE);
Editor editor = sp.edit();
Expand Down Expand Up @@ -332,7 +339,7 @@ public void onResume() {

/**
* Automatically linked with android:onClick to the add new connection action bar item.
* @param view
* @param menuItem
*/
public void deleteConnection (MenuItem menuItem) {
deleteConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
gridView = convertView;
ImageView iView = (ImageView) convertView.findViewById(R.id.grid_item_image);
Bitmap tmp = ((BitmapDrawable)iView.getDrawable()).getBitmap();
if (!tmp.equals(defaultBitmap)) {
if (tmp != null && !tmp.equals(defaultBitmap)) {
tmp.recycle();
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@ public void run () {
outputToFile(getContentResolver().openInputStream(data), new File(tempVvFile));
vvFileName = tempVvFile;
} catch (IOException e) {
android.util.Log.e(TAG, "Could not write temp file out.");
android.util.Log.e(TAG, "Could not write temp file: IOException.");
e.printStackTrace();
} catch (SecurityException e) {
android.util.Log.e(TAG, "Could not write temp file: SecurityException.");
e.printStackTrace();
}
}
Expand Down

0 comments on commit 351d9b3

Please sign in to comment.