Permalink
Browse files

merging with jorgesilva:develop and adding code so that confirmation …

…dialog does not appear when back button is pressed while shield is being discovered
  • Loading branch information...
2 parents 8dbcc25 + bab3a59 commit 76e8c0e8fb51a86c6e02c26ff1f510ba5ffcafb3 @rishabhjain08 committed Apr 11, 2012
@@ -37,7 +37,7 @@
/**
* 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";
@@ -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);
@@ -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();
}
@@ -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();
@@ -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;
@@ -87,7 +88,7 @@
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
- if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
+ //if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
init();
@@ -175,6 +176,7 @@ protected void onResume() {
@Override
protected void onPause() {
super.onPause();
+ cancelDialog();
finish();
}
@@ -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();
}
@@ -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);
@@ -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);
@@ -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();
}
}
};
@@ -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();
@@ -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();
@@ -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);
@@ -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);
@@ -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();
@@ -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();
+ }
}
}
@@ -34,7 +34,7 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
+ //if (TeclaApp.DEBUG) android.os.Debug.waitForDebugger();
init();
}
@@ -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);
@@ -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();
@@ -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);
}
@@ -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();
@@ -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--;

0 comments on commit 76e8c0e

Please sign in to comment.