mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-03 15:11:42 +01:00
Clean up key/identity verification Activites.
1) Get ride of the crazy button situation. 2) Actionbar-ify and abstract out the common actions. 3) Switch to full activities from dialog themes.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
@@ -10,62 +10,68 @@
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockActivity;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.SerializableKey;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.thoughtcrime.securesms.util.Dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
/**
|
||||
* Activity for initiating/receiving key QR code scans.
|
||||
*
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
public abstract class KeyScanningActivity extends Activity {
|
||||
|
||||
private static final int MENU_ITEM_SCAN = 1;
|
||||
private static final int MENU_ITEM_GET_SCANNED = 2;
|
||||
public abstract class KeyScanningActivity extends SherlockActivity {
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
menu.add(0, MENU_ITEM_SCAN, Menu.NONE, getScanString());
|
||||
menu.add(0, MENU_ITEM_GET_SCANNED, Menu.NONE, getDisplayString());
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
|
||||
MenuInflater inflater = this.getSupportMenuInflater();
|
||||
menu.clear();
|
||||
|
||||
inflater.inflate(R.menu.key_scanning, menu);
|
||||
|
||||
menu.findItem(R.id.menu_scan).setTitle(getScanString());
|
||||
menu.findItem(R.id.menu_get_scanned).setTitle(getDisplayString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
|
||||
switch(item.getItemId()) {
|
||||
case MENU_ITEM_SCAN: initiateScan(); return true;
|
||||
case MENU_ITEM_GET_SCANNED: initiateDisplay(); return true;
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
super.onOptionsItemSelected(item);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_scan: initiateScan(); return true;
|
||||
case R.id.menu_get_scanned: initiateDisplay(); return true;
|
||||
case android.R.id.home: finish(); return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
||||
|
||||
|
||||
if ((scanResult != null) && (scanResult.getContents() != null)) {
|
||||
String data = scanResult.getContents();
|
||||
|
||||
|
||||
if (data.equals(Base64.encodeBytes(getIdentityKeyToCompare().serialize()))) {
|
||||
Dialogs.displayAlert(this, getVerifiedTitle(), getVerifiedMessage(), android.R.drawable.ic_dialog_info);
|
||||
} else {
|
||||
@@ -75,11 +81,11 @@ public abstract class KeyScanningActivity extends Activity {
|
||||
Toast.makeText(this, "No scanned key found!", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void initiateScan() {
|
||||
IntentIntegrator.initiateScan(this);
|
||||
}
|
||||
|
||||
|
||||
protected void initiateDisplay() {
|
||||
IntentIntegrator.shareText(this, Base64.encodeBytes(getIdentityKeyToDisplay().serialize()));
|
||||
}
|
||||
@@ -92,8 +98,8 @@ public abstract class KeyScanningActivity extends Activity {
|
||||
|
||||
protected abstract SerializableKey getIdentityKeyToCompare();
|
||||
protected abstract SerializableKey getIdentityKeyToDisplay();
|
||||
|
||||
|
||||
protected abstract String getVerifiedTitle();
|
||||
protected abstract String getVerifiedMessage();
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user