Skip to content

Commit

Permalink
merging with jorgesilva:develop and adding code so that confirmation …
Browse files Browse the repository at this point in the history
…dialog does not appear when back button is pressed while shield is being discovered
  • Loading branch information
rishabhjain08 committed Apr 11, 2012
2 parents 8dbcc25 + bab3a59 commit 76e8c0e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 31 deletions.
9 changes: 5 additions & 4 deletions source/src/ca/idi/tekla/TeclaApp.java
Expand Up @@ -37,7 +37,7 @@ public class TeclaApp extends Application {
/**
* Main debug switch, turns on/off debugging for the whole app
*/
public static final boolean DEBUG = false;
public static final boolean DEBUG = true;

public static final String TECLA_IME_ID = "ca.idi.tekla/.ime.TeclaIME";

Expand Down Expand Up @@ -86,7 +86,7 @@ public void onCreate() {

private void init() {

if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
//if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
Log.d(TAG, "TECLA APP STARTING ON " + Build.MODEL + " BY " + Build.MANUFACTURER);

persistence = new Persistence(this);
Expand Down Expand Up @@ -334,7 +334,7 @@ public void useSpeakerphone() {
}

public void holdKeyguardLock() {
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, "Unlocking screen...");
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, "Acquiring keyguard lock...");
mKeyguardLock.disableKeyguard();
}

Expand All @@ -355,10 +355,11 @@ public void holdWakeLock() {
* @param length the number of seconds to hold the wake lock for
*/
public void holdWakeLock(long length) {
if (DEBUG) Log.d(TeclaApp.TAG, "Aquiring wake lock...");
if (length > 0) {
if (DEBUG) Log.d(TeclaApp.TAG, "Aquiring temporal wake lock...");
mWakeLock.acquire(length);
} else {
if (DEBUG) Log.d(TeclaApp.TAG, "Aquiring wake lock...");
mWakeLock.acquire();
}
pokeUserActivityTimer();
Expand Down
70 changes: 49 additions & 21 deletions source/src/ca/idi/tekla/TeclaPrefs.java
Expand Up @@ -34,6 +34,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
Expand Down Expand Up @@ -87,7 +88,7 @@ public class TeclaPrefs extends PreferenceActivity
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);

if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
//if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();

init();

Expand Down Expand Up @@ -175,6 +176,7 @@ protected void onResume() {
@Override
protected void onPause() {
super.onPause();
cancelDialog();
finish();
}

Expand All @@ -188,8 +190,7 @@ protected void onDestroy() {

private void discoverShield() {
mShieldFound = false;
if (mBluetoothAdapter.isDiscovering())
mBluetoothAdapter.cancelDiscovery();
if (mBluetoothAdapter.isDiscovering()) mBluetoothAdapter.cancelDiscovery();
mBluetoothAdapter.startDiscovery();
showDiscoveryDialog();
}
Expand All @@ -205,29 +206,27 @@ public void onReceive(Context context, Intent intent) {
if ((dev.getName() != null) && (
dev.getName().startsWith(SwitchEventProvider.SHIELD_PREFIX_2) ||
dev.getName().startsWith(SwitchEventProvider.SHIELD_PREFIX_3) )) {
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Found a Tecla Access Shield candidate");
mShieldFound = true;
mShieldAddress = dev.getAddress();
mShieldName = dev.getName(); if (mBluetoothAdapter.isDiscovering())
mBluetoothAdapter.cancelDiscovery();
mShieldAddress = dev.getAddress();
mShieldName = dev.getName();
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Found a Tecla Access Shield candidate");
if (mBluetoothAdapter.isDiscovering()) mBluetoothAdapter.cancelDiscovery();
}
}

if (intent.getAction().equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {
if (mShieldFound) {
// Shield found, try to connect
if (!mProgressDialog.isShowing())
mProgressDialog.show();
mProgressDialog.setMessage(getString(R.string.connecting_tecla_shield) +
" " + mShieldName);
if(!SepManager.start(TeclaPrefs.this, mShieldAddress)) {
// Could not connect to switch
closeDialog();
// Could not connect to Shield
dismissDialog();
TeclaApp.getInstance().showToast(R.string.couldnt_connect_shield);
}
} else {
// Shield not found
closeDialog();
dismissDialog();
//set to true since we dont want the confirmation to pop up
mDisconnAlreadyAsked = true;
mPrefConnectToShield.setChecked(false);
Expand All @@ -239,7 +238,7 @@ public void onReceive(Context context, Intent intent) {
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Successfully started SEP");
mShieldConnected = true;
mPrefPersistentKeyboard.setChecked(true);
closeDialog();
dismissDialog();
TeclaApp.getInstance().showToast(R.string.shield_connected);
// Enable scanning checkboxes so they can be turned on/off
mPrefSelfScanning.setEnabled(true);
Expand All @@ -249,7 +248,7 @@ public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(SwitchEventProvider.ACTION_SHIELD_DISCONNECTED)) {
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "SEP broadcast stopped");
mShieldConnected = false;
closeDialog();
dismissDialog();
}
}
};
Expand Down Expand Up @@ -312,11 +311,14 @@ public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog altDialog = builder.create();
if(mShieldConnected && mPrefConnectToShield.isChecked()){
//confirmation dialog to be shown only if we are connected to a shield
if(mShieldConnected){
altDialog.show();
InputAccess.makeAccessible(altDialog);
}
//otherwise we just perform the actions defined in on positive button click listener
else{
//work around
altDialog.show();
altDialog.hide();
altDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
Expand Down Expand Up @@ -354,11 +356,14 @@ public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog altDialog = builder.create();
if(mShieldConnected && mPrefConnectToShield.isChecked()){
//confirmation dialog to be shown only if we are connected to a shield
if(mShieldConnected){
altDialog.show();
InputAccess.makeAccessible(altDialog);
}
//otherwise we just perform the actions defined in on positive button click listener
else{
//work around
altDialog.show();
altDialog.hide();
altDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
Expand All @@ -375,7 +380,7 @@ public void onClick(DialogInterface dialog, int which) {
// switch event provider without breaking
// connection with other potential clients.
// Should perhaps use Binding?
closeDialog();
dismissDialog();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.shield_disconnect_confirmation_msg);
builder.setCancelable(false);
Expand All @@ -395,6 +400,9 @@ public void onClick(DialogInterface dialog, int which) {
builder.setNegativeButton(R.string.shield_disconnect_confirmation_no, new OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
//unregistering the shared preference change listener because we want to reset
//the check state of mPrefConnectToShield without executing actions associated with it
//since it was already checked before being changed
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(TeclaPrefs.this);
mPrefConnectToShield.setChecked(true);
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(TeclaPrefs.this);
Expand All @@ -408,6 +416,7 @@ public void onClick(DialogInterface dialog, int which) {
}
else{
mDisconnAlreadyAsked = false;
//work around
altDialog.show();
altDialog.hide();
altDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
Expand Down Expand Up @@ -464,13 +473,32 @@ public void onClick(DialogInterface dialog, int which) {
}

private void showDiscoveryDialog() {
mProgressDialog = ProgressDialog.show(this, "",
getString(R.string.searching_for_shields), true, true);
mProgressDialog.setMessage(getString(R.string.searching_for_shields));
mProgressDialog.setOnCancelListener(new OnCancelListener() {
public void onCancel(DialogInterface arg0) {
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Tecla Shield discovery cancelled");
if (mBluetoothAdapter != null && mBluetoothAdapter.isDiscovering()) {
mBluetoothAdapter.cancelDiscovery();
}
//because we dont want the confirmation dialog to pop up in this case
mDisconnAlreadyAsked = true;
//since we have cancelled the discovery the check state needs to be reset
mPrefConnectToShield.setChecked(false);
}
});
mProgressDialog.show();
}

private void closeDialog() {
if (mProgressDialog != null && mProgressDialog.isShowing())
private void cancelDialog() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.cancel();
}
}

private void dismissDialog() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
}

}
2 changes: 1 addition & 1 deletion source/src/ca/idi/tekla/TeclaSplash.java
Expand Up @@ -34,7 +34,7 @@ public class TeclaSplash extends Activity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
//if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();

init();
}
Expand Down
6 changes: 3 additions & 3 deletions source/src/ca/idi/tekla/ime/TeclaIME.java
Expand Up @@ -188,7 +188,7 @@ public void handleMessage(Message msg) {
public void onCreate() {
super.onCreate();
// Setup Debugging
if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
//if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Creating IME...");

//setStatusIcon(R.drawable.ime_qwerty);
Expand Down Expand Up @@ -1480,7 +1480,7 @@ private void handleSwitchEvent(SwitchEvent switchEvent) {
}

if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Byte handled: " +
TeclaApp.getInstance().byte2Hex(switchEvent.getSwitchStates()) + "at " + SystemClock.uptimeMillis());
TeclaApp.getInstance().byte2Hex(switchEvent.getSwitchStates()) + " at " + SystemClock.uptimeMillis());
}

evaluateNavKbdTimeout();
Expand Down Expand Up @@ -1512,7 +1512,7 @@ private void cancelNavKbdTimeout() {
private void resetNavKbdTimeout() {
cancelNavKbdTimeout();
int navKbdTimeout = TeclaApp.persistence.getNavigationKeyboardTimeout();
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Timeout in: " + navKbdTimeout + "seconds");
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Navigation keyboard timeout in: " + navKbdTimeout + " seconds");
if (navKbdTimeout != Persistence.NEVER_AUTOHIDE)
mTeclaHandler.postDelayed(hideNavKbdRunnable, navKbdTimeout * 1000);
}
Expand Down
4 changes: 2 additions & 2 deletions source/src/ca/idi/tekla/sep/SwitchEventProvider.java
Expand Up @@ -113,7 +113,7 @@ public void onCreate() {
}

private void init() {
if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
//if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Creating SEP...");

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Expand Down Expand Up @@ -253,7 +253,7 @@ public void run() {
try {
inByte = mInStream.read();
if (TeclaApp.DEBUG) Log.v(TeclaApp.TAG, CLASS_TAG + "Byte received: " +
TeclaApp.getInstance().byte2Hex(inByte) + "at " + SystemClock.uptimeMillis());
TeclaApp.getInstance().byte2Hex(inByte) + " at " + SystemClock.uptimeMillis());
if (inByte != 0xffffffff) { // Work-around for Samsung Galaxy
if (inByte == STATE_PING) {
mPingCounter--;
Expand Down

0 comments on commit 76e8c0e

Please sign in to comment.