Skip to content

Commit

Permalink
Merge pull request #15 from dmitrycrocodilys/master
Browse files Browse the repository at this point in the history
fixed crashes involving debug button.
  • Loading branch information
johannbarbie committed Jun 5, 2014
2 parents 7c40b0c + f06ec99 commit 0a1e9dc
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 79 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ local.properties
target
.settings
.project
.classpath
.classpath
.idea/
*.iml
*.apk
2 changes: 1 addition & 1 deletion mobile/btc2sms-it/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-18
target=android-17
3 changes: 2 additions & 1 deletion mobile/btc2sms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
<name>btc2sms - Application</name>

<dependencies>

<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
Expand Down
3 changes: 3 additions & 0 deletions mobile/btc2sms/res/menu/mainmenu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<item android:id="@+id/test"
android:icon="@drawable/ic_menu_link"
android:title="@string/test" />
<item android:id="@+id/debug_on"
android:icon="@drawable/ic_menu_puzzle"
android:title="@string/debug_on"/>
</menu>
16 changes: 3 additions & 13 deletions mobile/btc2sms/res/menu/mainmenu_debug.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/debug_off"
android:icon="@drawable/ic_menu_puzzle"
android:title="@string/debug_off"/>
<item android:id="@+id/settings"
android:icon="@drawable/ic_menu_equalizer"
android:title="@string/settings" />
<item android:id="@+id/test"
android:icon="@drawable/ic_menu_link"
android:title="@string/test" />
<item android:id="@+id/check_now"
android:icon="@drawable/ic_menu_tick"
android:title="@string/check_now" />
<item android:id="@+id/forward_saved"
android:icon="@drawable/ic_menu_dialog"
android:title="@string/forward_saved" />
<item android:id="@+id/retry_now"
android:icon="@drawable/ic_menu_magnet"
android:title="@string/retry_now" />
<item android:id="@+id/pending"
android:icon="@drawable/ic_menu_dialog"
android:title="@string/pending" />

</menu>
2 changes: 2 additions & 0 deletions mobile/btc2sms/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ in the normal Messaging inbox.)</string>
SMSgateway will ignore SMS messages from the phone numbers listed below.
Incoming messages from these senders will be saved in the normal Messaging inbox.</string>
<string name='splash_loading'>Loading...</string>
<string name="debug_on">Debug on</string>
<string name="debug_off">Debug off</string>

</resources>
4 changes: 2 additions & 2 deletions mobile/btc2sms/res/xml/expansion_packs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:summary="...">
<intent
android:action="android.intent.action.VIEW"
android:data="market://details?id=org.envaya.sms.pack01"
android:data="market://details?id=org.btc4all.btc2sms.pack01"
/>
</PreferenceScreen>
<PreferenceScreen
Expand All @@ -17,7 +17,7 @@
android:summary="...">
<intent
android:action="android.intent.action.VIEW"
android:data="market://details?id=org.envaya.sms.pack02"
android:data="market://details?id=org.btc4all.btc2sms.pack02"
/>
</PreferenceScreen>
</PreferenceScreen>
40 changes: 17 additions & 23 deletions mobile/btc2sms/src/main/java/org/btc4all/btc2sms/App.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.btc4all.btc2sms;

import org.btc4all.btc2sms.service.EnabledChangedService;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.Application;
Expand All @@ -19,36 +18,31 @@
import android.os.Bundle;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.util.Log;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.message.BasicNameValuePair;
import org.btc4all.btc2sms.receiver.OutgoingMessagePoller;
import org.btc4all.btc2sms.service.EnabledChangedService;
import org.btc4all.btc2sms.task.CheckConnectivityTask;
import org.btc4all.btc2sms.task.HttpTask;
import org.btc4all.btc2sms.task.PollerTask;
import org.json.JSONArray;
import org.json.JSONException;

import java.text.DateFormat;
import java.util.*;

public final class App extends Application {

public static final String ACTION_OUTGOING = "outgoing";
Expand Down Expand Up @@ -80,19 +74,19 @@ public final class App extends Application {
public static final String MESSAGE_TYPE_SMS = "sms";
public static final String MESSAGE_TYPE_CALL = "call";

public static final String LOG_NAME = "EnvayaSMS";
public static final String LOG_NAME = "Btc2Sms";

// intent to signal to Main activity (if open) that log has changed
public static final String LOG_CHANGED_INTENT = "org.envaya.sms.LOG_CHANGED";
public static final String SETTINGS_CHANGED_INTENT = "org.envaya.sms.SETTINGS_CHANGED";
public static final String LOG_CHANGED_INTENT = "org.btc4all.btc2sms.LOG_CHANGED";
public static final String SETTINGS_CHANGED_INTENT = "org.btc4all.btc2sms.SETTINGS_CHANGED";

public static final String EXPANSION_PACKS_CHANGED_INTENT = "org.envaya.sms.EXPANSION_PACKS_CHANGED";
public static final String EXPANSION_PACKS_CHANGED_INTENT = "org.btc4all.btc2sms.EXPANSION_PACKS_CHANGED";

// signal to PendingMessages activity (if open) that inbox/outbox has changed
public static final String INBOX_CHANGED_INTENT = "org.envaya.sms.INBOX_CHANGED";
public static final String OUTBOX_CHANGED_INTENT = "org.envaya.sms.OUTBOX_CHANGED";
public static final String INBOX_CHANGED_INTENT = "org.btc4all.btc2sms.INBOX_CHANGED";
public static final String OUTBOX_CHANGED_INTENT = "org.btc4all.btc2sms.OUTBOX_CHANGED";

public static final String QUERY_EXPANSION_PACKS_INTENT = "org.envaya.sms.QUERY_EXPANSION_PACKS";
public static final String QUERY_EXPANSION_PACKS_INTENT = "org.btc4all.btc2sms.QUERY_EXPANSION_PACKS";
public static final String QUERY_EXPANSION_PACKS_EXTRA_PACKAGES = "packages";

// Interface for sending outgoing messages to expansion packs
Expand All @@ -104,8 +98,8 @@ public final class App extends Application {

// intent for MessageStatusNotifier to receive status updates for outgoing SMS
// (even if sent by an expansion pack)
public static final String MESSAGE_STATUS_INTENT = "org.envaya.sms.MESSAGE_STATUS";
public static final String MESSAGE_DELIVERY_INTENT = "org.envaya.sms.MESSAGE_DELIVERY";
public static final String MESSAGE_STATUS_INTENT = "org.btc4all.btc2sms.MESSAGE_STATUS";
public static final String MESSAGE_DELIVERY_INTENT = "org.btc4all.btc2sms.MESSAGE_DELIVERY";

public static final String STATUS_EXTRA_INDEX = "status";
public static final String STATUS_EXTRA_NUM_PARTS = "num_parts";
Expand All @@ -119,9 +113,9 @@ public final class App extends Application {
public static final int MESSAGE_SEND_TIMEOUT = 30000; // ms

// Each QueuedMessage is identified within our internal Map by its Uri.
// Currently QueuedMessage instances are only available within EnvayaSMS,
// Currently QueuedMessage instances are only available within Btc2Sms,
// (but they could be made available to other applications later via a ContentProvider)
public static final Uri CONTENT_URI = Uri.parse("content://org.envaya.sms");
public static final Uri CONTENT_URI = Uri.parse("content://org.btc4all.btc2sms");
public static final Uri INCOMING_URI = Uri.withAppendedPath(CONTENT_URI, "incoming");
public static final Uri OUTGOING_URI = Uri.withAppendedPath(CONTENT_URI, "outgoing");

Expand Down Expand Up @@ -151,7 +145,7 @@ public final class App extends Application {

private PackageInfo packageInfo;

// list of package names (e.g. org.envaya.sms, or org.envaya.sms.packXX)
// list of package names (e.g. org.btc4all.btc2sms, or org.btc4all.btc2sms.packXX)
// for this package and all expansion packs
private List<String> outgoingMessagePackages = new ArrayList<String>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class DatabaseHelper extends SQLiteOpenHelper {

public static final String DATABASE_NAME = "envayasms.db";
public static final String DATABASE_NAME = "btc2sms.db";
public static final int DATABASE_VERSION = 4;

private App app;
Expand Down
58 changes: 24 additions & 34 deletions mobile/btc2sms/src/main/java/org/btc4all/btc2sms/ui/LogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.message.BasicNameValuePair;
import org.btc4all.btc2sms.App;
import org.btc4all.btc2sms.BuildConfig;
import org.btc4all.btc2sms.R;
import org.btc4all.btc2sms.task.HttpTask;

Expand Down Expand Up @@ -59,8 +58,10 @@ public void onReceive(Context context, Intent intent) {
private TextView heading;
private WebView loginWebView;
private LinearLayout logLayout;
private Menu appMenu;

private boolean firstTimeLoad;
private boolean debugMode;

private class TestTask extends HttpTask
{
Expand Down Expand Up @@ -122,7 +123,7 @@ public synchronized void updateLogView()
} });
}

private void preLoad(final Bundle savedInstanceState) {
private void loadWebView(final Bundle savedInstanceState) {

setContentView(R.layout.splash);
LayoutInflater li = getLayoutInflater();
Expand All @@ -140,6 +141,7 @@ public void run() {
public void run() {
setContentView(logLayout);
loginWebView.setVisibility(1);
loginWebView.requestFocus(View.FOCUS_DOWN);
if (firstTimeLoad) {
firstTimeLoad = false;
continueLoading(savedInstanceState);
Expand Down Expand Up @@ -196,9 +198,6 @@ public void run() {

private void continueLoading(Bundle savedInstanceState)
{
registerReceiver(logReceiver, new IntentFilter(App.LOG_CHANGED_INTENT));
registerReceiver(settingsReceiver, new IntentFilter(App.SETTINGS_CHANGED_INTENT));
registerReceiver(expansionPacksReceiver, new IntentFilter(App.EXPANSION_PACKS_CHANGED_INTENT));

PreferenceManager.setDefaultValues(this, R.xml.prefs, false);

Expand Down Expand Up @@ -246,7 +245,11 @@ public void onCreate(Bundle savedInstanceState) {

firstTimeLoad = true;

preLoad(savedInstanceState);
registerReceiver(logReceiver, new IntentFilter(App.LOG_CHANGED_INTENT));
registerReceiver(settingsReceiver, new IntentFilter(App.SETTINGS_CHANGED_INTENT));
registerReceiver(expansionPacksReceiver, new IntentFilter(App.EXPANSION_PACKS_CHANGED_INTENT));

loadWebView(savedInstanceState);

}

Expand Down Expand Up @@ -415,22 +418,20 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.settings:
startActivity(new Intent(this, Prefs.class));
return true;
case R.id.check_now:
app.checkOutgoingMessages();
return true;
case R.id.retry_now:
app.retryStuckMessages();
return true;
case R.id.forward_saved:
startActivity(new Intent(this, MessagingSmsInbox.class));
return true;
case R.id.pending:
startActivity(new Intent(this, PendingMessages.class));
return true;
case R.id.test:
app.log("Testing server connection...");
new TestTask().execute();
return true;
case R.id.debug_on:
debugMode = true;
loginWebView.setVisibility(View.GONE);
onCreateOptionsMenu(appMenu);
return true;
case R.id.debug_off:
debugMode = false;
loginWebView.setVisibility(View.VISIBLE);
onCreateOptionsMenu(appMenu);
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand All @@ -439,26 +440,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
// first time the Menu key is pressed
@Override
public boolean onCreateOptionsMenu(Menu menu) {
appMenu = menu;
menu.clear();
MenuInflater inflater = getMenuInflater();
if (BuildConfig.DEBUG) {
inflater.inflate(R.menu.mainmenu_debug, menu);
} else
{
if (!debugMode) {
inflater.inflate(R.menu.mainmenu, menu);
} else {
inflater.inflate(R.menu.mainmenu_debug, menu);
}

return(true);
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (BuildConfig.DEBUG) {
MenuItem retryItem = menu.findItem(R.id.retry_now);
int pendingTasks = app.getPendingTaskCount();
retryItem.setEnabled(pendingTasks > 0);
retryItem.setTitle("Retry All (" + pendingTasks + ")");
}
return true;
}

}
5 changes: 2 additions & 3 deletions mobile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version> 4.1.1.4
</platform.version>
<android.plugin.version>3.6.0</android.plugin.version>
<android.plugin.version>3.8.0</android.plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -60,7 +60,6 @@
<configuration>
<sdk>
<platform>17</platform>
<path>/Users/johann/adtBundleMac/sdk/</path>
</sdk>
<zipalign>
<verbose>true</verbose>
Expand Down Expand Up @@ -111,4 +110,4 @@
<module>btc2sms</module>
<module>btc2sms-it</module>
</modules>
</project>
</project>

0 comments on commit 0a1e9dc

Please sign in to comment.