mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Remove dead RedPhone code.
// FREEBIE
This commit is contained in:
parent
26979b1c62
commit
826dc601c1
@ -37,9 +37,7 @@ import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.redphone.codec.CodecSetupException;
|
||||
import org.thoughtcrime.redphone.crypto.zrtp.SASInfo;
|
||||
import org.thoughtcrime.redphone.ui.CallControls;
|
||||
import org.thoughtcrime.redphone.ui.CallScreen;
|
||||
@ -47,8 +45,6 @@ import org.thoughtcrime.redphone.util.AudioUtils;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
|
||||
import java.security.Security;
|
||||
|
||||
/**
|
||||
* The main UI class for RedPhone. Most of the heavy lifting is
|
||||
* done by RedPhoneService, so this activity is mostly responsible
|
||||
@ -59,10 +55,6 @@ import java.security.Security;
|
||||
*
|
||||
*/
|
||||
public class RedPhone extends Activity {
|
||||
static {
|
||||
Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
|
||||
}
|
||||
|
||||
|
||||
private static final int REMOTE_TERMINATE = 0;
|
||||
private static final int LOCAL_TERMINATE = 1;
|
||||
@ -84,7 +76,6 @@ public class RedPhone extends Activity {
|
||||
public static final int HANDLE_CONNECTING_TO_INITIATOR = 5;
|
||||
public static final int HANDLE_CALL_DISCONNECTED = 6;
|
||||
public static final int HANDLE_CALL_RINGING = 7;
|
||||
public static final int HANDLE_CODEC_INIT_FAILED = 8;
|
||||
public static final int HANDLE_SERVER_MESSAGE = 9;
|
||||
public static final int HANDLE_RECIPIENT_UNAVAILABLE = 10;
|
||||
public static final int HANDLE_INCOMING_CALL = 11;
|
||||
@ -98,7 +89,6 @@ public class RedPhone extends Activity {
|
||||
private final Handler callStateHandler = new CallStateHandler();
|
||||
|
||||
private int state;
|
||||
private boolean deliveringTimingData = false;
|
||||
private RedPhoneService redPhoneService;
|
||||
private CallScreen callScreen;
|
||||
private BroadcastReceiver bluetoothStateReceiver;
|
||||
@ -107,7 +97,6 @@ public class RedPhone extends Activity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// startServiceIfNecessary();
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.redphone);
|
||||
|
||||
@ -138,26 +127,6 @@ public class RedPhone extends Activity {
|
||||
public void onConfigurationChanged(Configuration newConfiguration) {
|
||||
super.onConfigurationChanged(newConfiguration);
|
||||
}
|
||||
//
|
||||
// private void startServiceIfNecessary() {
|
||||
// Intent intent = this.getIntent();
|
||||
// String action = null;
|
||||
//
|
||||
// if (intent != null)
|
||||
// action = intent.getAction();
|
||||
//
|
||||
// if (action != null &&
|
||||
// (action.equals(Intent.ACTION_CALL) || action.equals(Intent.ACTION_DIAL) ||
|
||||
// action.equals("android.intent.action.CALL_PRIVILEGED")))
|
||||
// {
|
||||
// Log.w("RedPhone", "Calling startService from within RedPhone!");
|
||||
// String number = Uri.decode(intent.getData().getEncodedSchemeSpecificPart());
|
||||
// Intent serviceIntent = new Intent();
|
||||
// serviceIntent.setClass(this, RedPhoneService.class);
|
||||
// serviceIntent.putExtra(Constants.REMOTE_NUMBER, number);
|
||||
// startService(serviceIntent);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void initializeServiceBinding() {
|
||||
Log.w("RedPhone", "Binding to RedPhoneService...");
|
||||
@ -173,20 +142,8 @@ public class RedPhone extends Activity {
|
||||
callScreen.setIncomingCallActionListener(new IncomingCallActionListener());
|
||||
callScreen.setMuteButtonListener(new MuteButtonListener());
|
||||
callScreen.setAudioButtonListener(new AudioButtonListener());
|
||||
callScreen.setConfirmSasButtonListener(new ConfirmSasButtonListener());
|
||||
|
||||
// PeriodicActionUtils.scheduleUpdate(this, DirectoryUpdateReceiver.class);
|
||||
}
|
||||
|
||||
// private void sendInstallLink(String user) {
|
||||
// String message =
|
||||
// String.format(getString(R.string.RedPhone_id_like_to_call_you_securely_using_redphone_you_can_install_redphone_from_the_play_store_s),
|
||||
// "https://play.google.com/store/apps/details?id=org.thoughtcrime.redphone");
|
||||
//
|
||||
// ArrayList<String> messages = SmsManager.getDefault().divideMessage(message);
|
||||
// SmsManager.getDefault().sendMultipartTextMessage(user, null, messages, null, null);
|
||||
// }
|
||||
|
||||
private void handleSetMute(boolean enabled) {
|
||||
Intent intent = new Intent(this, RedPhoneService.class);
|
||||
intent.setAction(RedPhoneService.ACTION_SET_MUTE);
|
||||
@ -349,12 +306,6 @@ public class RedPhone extends Activity {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void handleCodecFailure(CodecSetupException e) {
|
||||
Log.w("RedPhone", e);
|
||||
Toast.makeText(this, "Codec failed to initialize", Toast.LENGTH_LONG).show();
|
||||
handleTerminate(LOCAL_TERMINATE);
|
||||
}
|
||||
|
||||
private void delayedFinish() {
|
||||
delayedFinish(STANDARD_DELAY_FINISH);
|
||||
}
|
||||
@ -382,7 +333,6 @@ public class RedPhone extends Activity {
|
||||
case HANDLE_SERVER_MESSAGE: handleServerMessage((String)message.obj); break;
|
||||
case HANDLE_NO_SUCH_USER: handleNoSuchUser((Recipient)message.obj); break;
|
||||
case HANDLE_RECIPIENT_UNAVAILABLE: handleRecipientUnavailable(); break;
|
||||
case HANDLE_CODEC_INIT_FAILED: handleCodecFailure( (CodecSetupException) message.obj ); break;
|
||||
case HANDLE_INCOMING_CALL: handleIncomingCall((Recipient)message.obj); break;
|
||||
case HANDLE_OUTGOING_CALL: handleOutgoingCall((Recipient)message.obj); break;
|
||||
case HANDLE_CALL_BUSY: handleCallBusy(); break;
|
||||
@ -393,14 +343,6 @@ public class RedPhone extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private class ConfirmSasButtonListener implements CallControls.ConfirmSasButtonListener {
|
||||
public void onClick() {
|
||||
Intent intent = new Intent(RedPhone.this, RedPhoneService.class);
|
||||
intent.setAction(RedPhoneService.ACTION_CONFIRM_SAS);
|
||||
startService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private class HangupButtonListener implements CallControls.HangupButtonListener {
|
||||
public void onClick() {
|
||||
Log.w("RedPhone", "Hangup pressed, handling termination now...");
|
||||
|
@ -37,7 +37,6 @@ import org.thoughtcrime.redphone.call.CallStateListener;
|
||||
import org.thoughtcrime.redphone.call.InitiatingCallManager;
|
||||
import org.thoughtcrime.redphone.call.LockManager;
|
||||
import org.thoughtcrime.redphone.call.ResponderCallManager;
|
||||
import org.thoughtcrime.redphone.codec.CodecSetupException;
|
||||
import org.thoughtcrime.redphone.crypto.zrtp.SASInfo;
|
||||
import org.thoughtcrime.redphone.pstn.CallStateView;
|
||||
import org.thoughtcrime.redphone.pstn.IncomingPstnCallListener;
|
||||
@ -84,7 +83,7 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
|
||||
private static final String TAG = RedPhoneService.class.getName();
|
||||
|
||||
private final List<Message> bufferedEvents = new LinkedList<Message>();
|
||||
private final List<Message> bufferedEvents = new LinkedList<>();
|
||||
private final IBinder binder = new RedPhoneServiceBinder();
|
||||
private final Handler serviceHandler = new Handler();
|
||||
|
||||
@ -105,10 +104,7 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
// if (Release.DEBUG) Log.w("RedPhoneService", "Service onCreate() called...");
|
||||
|
||||
initializeResources();
|
||||
// initializeApplicationContext();
|
||||
initializeRingers();
|
||||
initializePstnCallListener();
|
||||
registerUncaughtExceptionHandler();
|
||||
@ -116,11 +112,8 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
// if (Release.DEBUG) Log.w("RedPhoneService", "Service onStart() called...");
|
||||
if (intent == null) return;
|
||||
new Thread(new IntentRunnable(intent)).start();
|
||||
|
||||
// GCMRegistrarHelper.registerClient(this, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -146,7 +139,6 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
else if (intent.getAction().equals(ACTION_DENY_CALL)) handleDenyCall(intent);
|
||||
else if (intent.getAction().equals(ACTION_HANGUP_CALL)) handleHangupCall(intent);
|
||||
else if (intent.getAction().equals(ACTION_SET_MUTE)) handleSetMute(intent);
|
||||
else if (intent.getAction().equals(ACTION_CONFIRM_SAS)) handleConfirmSas(intent);
|
||||
}
|
||||
|
||||
///// Initializers
|
||||
@ -269,11 +261,6 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
}
|
||||
}
|
||||
|
||||
private void handleConfirmSas(Intent intent) {
|
||||
if (currentCallManager != null)
|
||||
currentCallManager.setSasVerified();
|
||||
}
|
||||
|
||||
/// Helper Methods
|
||||
|
||||
private boolean isBusy() {
|
||||
@ -311,10 +298,6 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
}
|
||||
}
|
||||
|
||||
// public PersonInfo getRemotePersonInfo() {
|
||||
// return PersonInfo.getInstance(this, remoteNumber);
|
||||
// }
|
||||
|
||||
private byte[] getZID() {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
@ -345,16 +328,6 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
}
|
||||
}
|
||||
|
||||
// private String extractRemoteNumber(Intent i) {
|
||||
// String number = i.getStringExtra(Constants.REMOTE_NUMBER);
|
||||
//
|
||||
// if (number == null)
|
||||
// number = i.getData().getSchemeSpecificPart();
|
||||
//
|
||||
// if (number.endsWith("*")) return number.substring(0, number.length()-1);
|
||||
// else return number;
|
||||
// }
|
||||
|
||||
private void startCallCardActivity() {
|
||||
Intent activityIntent = new Intent();
|
||||
activityIntent.setClass(this, RedPhone.class);
|
||||
@ -370,11 +343,6 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
incomingRinger.stop();
|
||||
outgoingRinger.stop();
|
||||
|
||||
// if (currentCallRecord != null) {
|
||||
// currentCallRecord.finishCall();
|
||||
// currentCallRecord = null;
|
||||
// }
|
||||
|
||||
if (currentCallManager != null) {
|
||||
currentCallManager.terminate();
|
||||
currentCallManager = null;
|
||||
@ -384,9 +352,6 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
|
||||
state = RedPhone.STATE_IDLE;
|
||||
lockManager.updatePhoneState(LockManager.PhoneState.IDLE);
|
||||
// XXX moxie@thoughtcrime.org -- Do we still need to stop the Service?
|
||||
// Log.d("RedPhoneService", "STOP SELF" );
|
||||
// this.stopSelf();
|
||||
}
|
||||
|
||||
public void setCallStateHandler(Handler handler) {
|
||||
@ -531,11 +496,6 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
|
||||
this.terminate();
|
||||
}
|
||||
|
||||
public void notifyCodecInitFailed(CodecSetupException e) {
|
||||
sendMessage(RedPhone.HANDLE_CODEC_INIT_FAILED, e);
|
||||
this.terminate();
|
||||
}
|
||||
|
||||
public void notifyClientError(String msg) {
|
||||
sendMessage(RedPhone.HANDLE_CLIENT_FAILURE,msg);
|
||||
this.terminate();
|
||||
|
@ -1,31 +0,0 @@
|
||||
package org.thoughtcrime.redphone.call;
|
||||
|
||||
import android.support.v4.util.LruCache;
|
||||
|
||||
public class CallChooserCache {
|
||||
|
||||
private final long CHOICE_CACHED_INTERVAL = 10 * 1000;
|
||||
|
||||
private static final CallChooserCache instance = new CallChooserCache();
|
||||
|
||||
public static CallChooserCache getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final LruCache<String, Long> insecureChoices = new LruCache<String, Long>(2);
|
||||
|
||||
private CallChooserCache() {}
|
||||
|
||||
public synchronized void addInsecureChoice(String number) {
|
||||
insecureChoices.put(number, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public synchronized boolean isRecentInsecureChoice(String number) {
|
||||
Long timestamp = insecureChoices.get(number);
|
||||
|
||||
if (timestamp == null)
|
||||
return false;
|
||||
|
||||
return System.currentTimeMillis() - timestamp < CHOICE_CACHED_INTERVAL;
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
///*
|
||||
// * 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.call;
|
||||
//
|
||||
//import android.content.BroadcastReceiver;
|
||||
//import android.content.Context;
|
||||
//import android.content.Intent;
|
||||
//import android.net.Uri;
|
||||
//import android.util.Log;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.Constants;
|
||||
//import org.thoughtcrime.redphone.RedPhone;
|
||||
//import org.thoughtcrime.redphone.RedPhoneService;
|
||||
//import org.thoughtcrime.redphone.directory.NumberFilter;
|
||||
//import org.thoughtcrime.redphone.ui.ApplicationPreferencesActivity;
|
||||
//import org.thoughtcrime.redphone.ui.RedPhoneChooser;
|
||||
//
|
||||
///**
|
||||
// * CallListener inspects broadcast events for outgoing
|
||||
// * calls. We intercept them and act on them if:
|
||||
// *
|
||||
// * 1) The number has an '*' appended to it.
|
||||
// * 2) The number is present in the RedPhone directory.
|
||||
// *
|
||||
// * @author Moxie Marlinspike
|
||||
// *
|
||||
// */
|
||||
//public class CallListener extends BroadcastReceiver {
|
||||
//
|
||||
// public static final String IGNORE_SUFFIX = "###";
|
||||
// public static final String INTENT_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
|
||||
// private static final String REDPHONE_SUFFIX = "*";
|
||||
//
|
||||
// private void redirectToRedphone(Context context, Intent intent, String phoneNumber) {
|
||||
// setResultData(null);
|
||||
//
|
||||
// intent.setClass(context, RedPhoneService.class);
|
||||
// intent.setAction(RedPhoneService.ACTION_OUTGOING_CALL);
|
||||
//
|
||||
// String destNumber = phoneNumber.substring(0, phoneNumber.length()-1);
|
||||
// intent.putExtra(Constants.REMOTE_NUMBER, destNumber );
|
||||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// context.startService(intent);
|
||||
//
|
||||
// Intent activityIntent = new Intent();
|
||||
// activityIntent.setClass(context, RedPhone.class);
|
||||
// activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// context.startActivity(activityIntent);
|
||||
// }
|
||||
//
|
||||
// private void redirectToOpportunisticRedphone(Context context, Intent intent, String phoneNumber) {
|
||||
// setResultData(null);
|
||||
//
|
||||
// intent.setClass(context, RedPhoneChooser.class);
|
||||
// intent.putExtra(Constants.REMOTE_NUMBER, phoneNumber);
|
||||
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// context.startActivity(intent);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onReceive(Context context, Intent intent) {
|
||||
// String phoneNumber = intent.getExtras().getString(INTENT_PHONE_NUMBER);
|
||||
// NumberFilter numberFilter = NumberFilter.deserializeFromFile(context);
|
||||
//
|
||||
// if( phoneNumber == null )
|
||||
// return;
|
||||
//
|
||||
// if (phoneNumber.endsWith(IGNORE_SUFFIX)) {
|
||||
// phoneNumber = phoneNumber.substring(0, phoneNumber.length() - IGNORE_SUFFIX.length());
|
||||
// intent.removeExtra(INTENT_PHONE_NUMBER);
|
||||
// intent.removeExtra("android.phone.extra.ORIGINAL_URI");
|
||||
//
|
||||
// intent.putExtra(INTENT_PHONE_NUMBER, phoneNumber);
|
||||
// intent.putExtra("android.phone.extra.ORIGINAL_URI", "tel:" + Uri.encode(phoneNumber));
|
||||
//
|
||||
// setResultData(phoneNumber);
|
||||
// } else if (phoneNumber.endsWith(REDPHONE_SUFFIX)) {
|
||||
// Log.w("CallListener", "Redirecting to RedPhone dialer...");
|
||||
// redirectToRedphone(context, intent, phoneNumber);
|
||||
// } else if (ApplicationPreferencesActivity.getPromptUpgradePreference(context) &&
|
||||
// numberFilter.containsNumber(context, phoneNumber) &&
|
||||
// !CallChooserCache.getInstance().isRecentInsecureChoice(phoneNumber))
|
||||
// {
|
||||
// Log.w("CallListener", "Redirecting to RedPhone opportunistic dialog...");
|
||||
// redirectToOpportunisticRedphone(context, intent, phoneNumber);
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -35,10 +35,8 @@ import org.thoughtcrime.redphone.util.AudioUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
|
||||
//import org.thoughtcrime.redphone.audio.CallAudioManager;
|
||||
|
||||
/**
|
||||
* The base class for both Initiating and Responder call
|
||||
@ -56,7 +54,6 @@ public abstract class CallManager extends Thread {
|
||||
protected final Context context;
|
||||
|
||||
private boolean terminated;
|
||||
// private boolean loopbackMode;
|
||||
protected CallAudioManager callAudioManager;
|
||||
private SignalManager signalManager;
|
||||
private SASInfo sasInfo;
|
||||
@ -76,7 +73,6 @@ public abstract class CallManager extends Thread {
|
||||
this.callStateListener = callStateListener;
|
||||
this.terminated = false;
|
||||
this.context = context;
|
||||
// this.loopbackMode = ApplicationPreferencesActivity.getLoopbackEnabled(context);
|
||||
|
||||
AudioUtils.resetConfiguration(context);
|
||||
}
|
||||
@ -144,11 +140,6 @@ public abstract class CallManager extends Thread {
|
||||
return this.sasInfo;
|
||||
}
|
||||
|
||||
public void setSasVerified() {
|
||||
// if (zrtpSocket != null)
|
||||
// zrtpSocket.setSasVerified();
|
||||
}
|
||||
|
||||
protected void processSignals() {
|
||||
Log.w("CallManager", "Starting signal processing loop...");
|
||||
this.signalManager = new SignalManager(callStateListener, signalingSocket, sessionDescriptor);
|
||||
@ -174,17 +165,4 @@ public abstract class CallManager extends Thread {
|
||||
return callConnected;
|
||||
}
|
||||
|
||||
///**********************
|
||||
// Methods below are SOA's loopback and testing shims.
|
||||
//For loopback operation
|
||||
public void doLoopback() throws AudioException, IOException {
|
||||
DatagramSocket socket = new DatagramSocket(2222);
|
||||
socket.connect(new InetSocketAddress("127.0.0.1", 2222));
|
||||
|
||||
this.callAudioManager = new CallAudioManager(socket, "127.0.0.1", 2222,
|
||||
new byte[16], new byte[20], new byte[14],
|
||||
new byte[16], new byte[20], new byte[14]);
|
||||
|
||||
this.callAudioManager.start();
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package org.thoughtcrime.redphone.call;
|
||||
|
||||
import org.thoughtcrime.redphone.codec.CodecSetupException;
|
||||
import org.thoughtcrime.redphone.crypto.zrtp.SASInfo;
|
||||
|
||||
/**
|
||||
@ -42,7 +41,6 @@ public interface CallStateListener {
|
||||
public void notifyPerformingHandshake();
|
||||
public void notifyHandshakeFailed();
|
||||
public void notifyRecipientUnavailable();
|
||||
public void notifyCodecInitFailed(CodecSetupException loadException);
|
||||
public void notifyBusy();
|
||||
public void notifyLoginFailed();
|
||||
public void notifyDebugInfo(String info);
|
||||
|
@ -52,7 +52,6 @@ public class InitiatingCallManager extends CallManager {
|
||||
private final String localNumber;
|
||||
private final String password;
|
||||
private final byte[] zid;
|
||||
// private boolean loopbackMode;
|
||||
|
||||
public InitiatingCallManager(Context context, CallStateListener callStateListener,
|
||||
String localNumber, String password,
|
||||
@ -62,16 +61,10 @@ public class InitiatingCallManager extends CallManager {
|
||||
this.localNumber = localNumber;
|
||||
this.password = password;
|
||||
this.zid = zid;
|
||||
// this.loopbackMode = ApplicationPreferencesActivity.getLoopbackEnabled(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// if( loopbackMode ) {
|
||||
// runLoopback();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
try {
|
||||
callStateListener.notifyCallConnecting();
|
||||
|
||||
@ -106,7 +99,7 @@ public class InitiatingCallManager extends CallManager {
|
||||
} catch (LoginFailedException lfe) {
|
||||
Log.w("InitiatingCallManager", lfe);
|
||||
callStateListener.notifyLoginFailed();
|
||||
} catch (SignalingException se) {
|
||||
} catch (SignalingException | SessionInitiationFailureException se) {
|
||||
Log.w("InitiatingCallManager", se);
|
||||
callStateListener.notifyServerFailure();
|
||||
} catch (SocketException e) {
|
||||
@ -116,9 +109,6 @@ public class InitiatingCallManager extends CallManager {
|
||||
Log.e("InitiatingCallManager", "Died with unhandled exception!");
|
||||
Log.w("InitiatingCallManager", e);
|
||||
callStateListener.notifyClientFailure();
|
||||
} catch (SessionInitiationFailureException e) {
|
||||
Log.w("InitiatingCallManager", e);
|
||||
callStateListener.notifyServerFailure();
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,18 +127,4 @@ public class InitiatingCallManager extends CallManager {
|
||||
this.callAudioManager.setMute(muteEnabled);
|
||||
this.callAudioManager.start();
|
||||
}
|
||||
|
||||
// //***************************
|
||||
// // SOA's Loopback Code, for debugging.
|
||||
//
|
||||
// private void runLoopback() {
|
||||
// try {
|
||||
// super.doLoopback();
|
||||
// } catch( Exception e ) {
|
||||
// Log.e("InitiatingCallManager", "Died with exception!");
|
||||
// Log.w("InitiatingCallManager", e);
|
||||
// callStateListener.notifyClientFailure();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -31,22 +31,6 @@ public class SignalManager {
|
||||
this.queue.execute(new SignalListenerTask());
|
||||
}
|
||||
|
||||
// public void sendBusySignal(String remoteNumber, final long sessionId) {
|
||||
// Log.w("SignalManager", "Queuing busy signal...");
|
||||
// queue.execute(new Runnable() {
|
||||
// public void run() {
|
||||
// try {
|
||||
// Log.w("SignalManager", "Sending busy signal...");
|
||||
// signalingSocket.setBusy(sessionId);
|
||||
// } catch (SignalingException se) {
|
||||
// Log.w("SignalManager", se);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// interrupted = true;
|
||||
// }
|
||||
|
||||
public void terminate() {
|
||||
Log.w("SignalManager", "Queuing hangup signal...");
|
||||
queue.execute(new Runnable() {
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.codec;
|
||||
|
||||
|
||||
/**
|
||||
* Provides the basic interface for all audio codecs as well as default implementations
|
||||
* for some less common methods. .
|
||||
*
|
||||
* New codecs need to be added to this static factory method in this class.
|
||||
*
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
public abstract class AudioCodec {
|
||||
private final static String TAG = "AudioCodec";
|
||||
public static int SAMPLE_RATE = 8000;
|
||||
public static int FRAME_RATE = 50;
|
||||
public static int SAMPLES_PER_FRAME = SAMPLE_RATE/FRAME_RATE;
|
||||
|
||||
//returns the number of raw samples written to rawData
|
||||
public abstract int decode( byte [] encodedData, short [] rawData, int encodedBytes );
|
||||
|
||||
//returns the number of encoded bytes written to encodedData
|
||||
public abstract int encode( short [] rawData, byte [] encodedData, int rawSamples );
|
||||
|
||||
public void waitForInitializationComplete() {
|
||||
return;
|
||||
}
|
||||
|
||||
public void terminate() {}
|
||||
|
||||
public static AudioCodec getInstance(String codecID) {
|
||||
if( codecID.equals( "SPEEX" ) )
|
||||
return new SpeexCodec();
|
||||
if( codecID.equals( "G711" ) )
|
||||
return new G711AudioCodec();
|
||||
if( codecID.equals( "NullAudioCodec"))
|
||||
return new NullAudioCodec();
|
||||
|
||||
throw new AssertionError("Unknown codec: " + codecID);
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.codec;
|
||||
|
||||
/**
|
||||
* Indicates an exception related to an {@link AudioCodec}
|
||||
*
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
public class CodecSetupException extends Exception {
|
||||
|
||||
public CodecSetupException(String string) {
|
||||
super(string);
|
||||
}
|
||||
public CodecSetupException(String msg, Throwable reason ) {
|
||||
super(msg, reason);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
@ -1,235 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.codec;
|
||||
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
/**
|
||||
* An implementation of G.711 audio companding. This is a stateless codec that
|
||||
* transforms each input short of 16 bit audio by representing the 16 bit value
|
||||
* according to a modified log scale.
|
||||
*
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
|
||||
public class G711AudioCodec extends AudioCodec {
|
||||
|
||||
private static final boolean ZEROTRAP = false; /*
|
||||
* turn on the trap as per
|
||||
* the MIL-STD
|
||||
*/
|
||||
private static final int BIAS = 0x84; /*
|
||||
* define the add-in bias for 16 bit
|
||||
* samples
|
||||
*/
|
||||
private static final int CLIP = 32635;
|
||||
|
||||
private static final int exp_lut[] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7 };
|
||||
private static final int decoder_exp_lut[] = { 0, 132, 396, 924, 1980,
|
||||
4092, 8316, 16764 };
|
||||
|
||||
@Override
|
||||
public int decode(byte[] encodedData, short[] rawData, int encLen ) {
|
||||
int nBytes = encodedPacketSize();
|
||||
for (int i = 0; i < nBytes; i++) {
|
||||
rawData[i] = ulaw2linear(encodedData[i]);
|
||||
}
|
||||
return nBytes;
|
||||
}
|
||||
|
||||
public static void test() {
|
||||
for( short i=-32768; i < 32767; i+=10 ) {
|
||||
byte b = linear2ulaw(i);
|
||||
short u = ulaw2linear(b);
|
||||
|
||||
Log.d("ULAW TEST:", i + ", " + b + ", " + u);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int encode(short[] rawData, byte[] encodedData, int rawLen ) {
|
||||
int nBytes = encodedPacketSize();
|
||||
for (int i = 0; i < nBytes; i++) {
|
||||
encodedData[i] = linear2ulaw(rawData[i]);
|
||||
}
|
||||
return nBytes;
|
||||
}
|
||||
|
||||
private static byte linear2ulaw(short sample) {
|
||||
int sign, exponent, mantissa;
|
||||
byte ulawbyte;
|
||||
|
||||
/* Get the sample into sign-magnitude. */
|
||||
sign = (sample > 0) ? 1 : 0; /* set aside the sign */
|
||||
if (sign == 0)
|
||||
sample = (short) -sample; /* get magnitude */
|
||||
if (sample > CLIP)
|
||||
sample = CLIP; /* clip the magnitude */
|
||||
|
||||
/* Convert from 16 bit linear to ulaw. */
|
||||
sample = (short) (sample + BIAS);
|
||||
exponent = exp_lut[(sample >> 7) & 0xFF];
|
||||
mantissa = (sample >> (exponent + 3)) & 0x0F;
|
||||
ulawbyte = (byte) ~( (sign<<7) | (exponent << 4) | mantissa);
|
||||
if (ZEROTRAP)
|
||||
if (ulawbyte == 0)
|
||||
ulawbyte = 0x02; /* optional CCITT trap */
|
||||
|
||||
return (ulawbyte);
|
||||
}
|
||||
|
||||
private static short ulaw2linear(byte ulawbyte) {
|
||||
|
||||
int sign, exponent, mantissa;
|
||||
short sample;
|
||||
|
||||
ulawbyte = (byte) ~ulawbyte;
|
||||
sign = (ulawbyte & 0x80);
|
||||
exponent = (ulawbyte >> 4) & 0x07;
|
||||
mantissa = ulawbyte & 0x0F;
|
||||
sample = (short) (decoder_exp_lut[exponent] + (mantissa << (exponent + 3)));
|
||||
if (sign == 0)
|
||||
sample = (short) -sample;
|
||||
|
||||
return (sample);
|
||||
}
|
||||
|
||||
public int encodedPacketSize() {
|
||||
return AudioCodec.SAMPLES_PER_FRAME;
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// ** Signal conversion routines for use with Sun4/60 audio chip
|
||||
// **/
|
||||
//
|
||||
// #include stdio.h
|
||||
//
|
||||
// unsigned char linear2ulaw(/* int */);
|
||||
// int ulaw2linear(/* unsigned char */);
|
||||
//
|
||||
// /*
|
||||
// ** This routine converts from linear to ulaw
|
||||
// **
|
||||
// ** Craig Reese: IDA/Supercomputing Research Center
|
||||
// ** Joe Campbell: Department of Defense
|
||||
// ** 29 September 1989
|
||||
// **
|
||||
// ** References:
|
||||
// ** 1) CCITT Recommendation G.711 (very difficult to follow)
|
||||
// ** 2) "A New Digital Technique for Implementation of Any
|
||||
// ** Continuous PCM Companding Law," Villeret, Michel,
|
||||
// ** et al. 1973 IEEE Int. Conf. on Communications, Vol 1,
|
||||
// ** 1973, pg. 11.12-11.17
|
||||
// ** 3) MIL-STD-188-113,"Interoperability and Performance Standards
|
||||
// ** for Analog-to_Digital Conversion Techniques,"
|
||||
// ** 17 February 1987
|
||||
// **
|
||||
// ** Input: Signed 16 bit linear sample
|
||||
// ** Output: 8 bit ulaw sample
|
||||
// */
|
||||
//
|
||||
// #define ZEROTRAP /* turn on the trap as per the MIL-STD */
|
||||
// #define BIAS 0x84 /* define the add-in bias for 16 bit samples */
|
||||
// #define CLIP 32635
|
||||
//
|
||||
// unsigned char
|
||||
// linear2ulaw(sample)
|
||||
// int sample; {
|
||||
// static int exp_lut[256] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
|
||||
// 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
// 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
|
||||
// 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
|
||||
// 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
// 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
// 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
// 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
||||
// 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
// 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
// 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
// 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
// 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
// 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
// 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
||||
// 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
|
||||
// int sign, exponent, mantissa;
|
||||
// unsigned char ulawbyte;
|
||||
//
|
||||
// /* Get the sample into sign-magnitude. */
|
||||
// sign = (sample >> 8) & 0x80; /* set aside the sign */
|
||||
// if (sign != 0) sample = -sample; /* get magnitude */
|
||||
// if (sample > CLIP) sample = CLIP; /* clip the magnitude */
|
||||
//
|
||||
// /* Convert from 16 bit linear to ulaw. */
|
||||
// sample = sample + BIAS;
|
||||
// exponent = exp_lut[(sample >> 7) & 0xFF];
|
||||
// mantissa = (sample >> (exponent + 3)) & 0x0F;
|
||||
// ulawbyte = ~(sign | (exponent << 4) | mantissa);
|
||||
// #ifdef ZEROTRAP
|
||||
// if (ulawbyte == 0) ulawbyte = 0x02; /* optional CCITT trap */
|
||||
// #endif
|
||||
//
|
||||
// return(ulawbyte);
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// ** This routine converts from ulaw to 16 bit linear.
|
||||
// **
|
||||
// ** Craig Reese: IDA/Supercomputing Research Center
|
||||
// ** 29 September 1989
|
||||
// **
|
||||
// ** References:
|
||||
// ** 1) CCITT Recommendation G.711 (very difficult to follow)
|
||||
// ** 2) MIL-STD-188-113,"Interoperability and Performance Standards
|
||||
// ** for Analog-to_Digital Conversion Techniques,"
|
||||
// ** 17 February 1987
|
||||
// **
|
||||
// ** Input: 8 bit ulaw sample
|
||||
// ** Output: signed 16 bit linear sample
|
||||
// */
|
||||
//
|
||||
// int
|
||||
// ulaw2linear(ulawbyte)
|
||||
// unsigned char ulawbyte;
|
||||
// {
|
||||
// static int exp_lut[8] = {0,132,396,924,1980,4092,8316,16764};
|
||||
// int sign, exponent, mantissa, sample;
|
||||
//
|
||||
// ulawbyte = ~ulawbyte;
|
||||
// sign = (ulawbyte & 0x80);
|
||||
// exponent = (ulawbyte >> 4) & 0x07;
|
||||
// mantissa = ulawbyte & 0x0F;
|
||||
// sample = exp_lut[exponent] + (mantissa << (exponent + 3));
|
||||
// if (sign != 0) sample = -sample;
|
||||
//
|
||||
// return(sample);
|
||||
// }
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.codec;
|
||||
|
||||
import org.thoughtcrime.redphone.util.Conversions;
|
||||
|
||||
/**
|
||||
* An audio codec that does nothing. Encoded audio is precisely equal
|
||||
* to the unencoded audio, except represented in a byte[] instead of a
|
||||
* short[].
|
||||
*
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
public class NullAudioCodec extends AudioCodec {
|
||||
|
||||
@Override
|
||||
public int decode(byte[] encodedData, short[] rawData, int encLen) {
|
||||
for (int i = 0; i < AudioCodec.SAMPLES_PER_FRAME; i++) {
|
||||
rawData[i] = Conversions.byteArrayToShort(encodedData, i * 2);
|
||||
}
|
||||
return encodedPacketSize();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int encode(short[] rawData, byte[] encodedData, int rawLen) {
|
||||
for( int i = 0; i < AudioCodec.SAMPLES_PER_FRAME; i++) {
|
||||
Conversions.shortToByteArray(encodedData, i*2, rawData[i]);
|
||||
}
|
||||
return AudioCodec.SAMPLES_PER_FRAME;
|
||||
}
|
||||
|
||||
public int encodedPacketSize() {
|
||||
return AudioCodec.SAMPLES_PER_FRAME * 2;
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.codec;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* An audio codec that uses the Speex library to encode packets.
|
||||
* Calls through to the native library implementations of encode and decode.
|
||||
*
|
||||
* @author Stuat O. Anderson
|
||||
*/
|
||||
public class SpeexCodec extends AudioCodec {
|
||||
public static final String TAG = SpeexCodec.class.getSimpleName();
|
||||
public Thread loadThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
System.loadLibrary("redspeex");
|
||||
} catch (Throwable e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
Log.d(TAG, "loaded redspeex, now opening it");
|
||||
int result = openSpeex();
|
||||
if (result != 0 ) {
|
||||
throw new AssertionError("Speex initialization failed");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void waitForInitializationComplete() {
|
||||
if( loadThread.isAlive() ) {
|
||||
Log.d(TAG, "Waiting for Speex to load...");
|
||||
try {
|
||||
loadThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SpeexCodec() {
|
||||
loadThread.start();
|
||||
}
|
||||
|
||||
public native int openSpeex();
|
||||
|
||||
public native void closeSpeex();
|
||||
|
||||
@Override
|
||||
public void terminate() {
|
||||
closeSpeex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public native int decode(byte[] encodedData, short[] rawData, int encLen);
|
||||
|
||||
@Override
|
||||
public native int encode(short[] rawData, byte[] encodedData, int rawLen);
|
||||
}
|
@ -21,7 +21,7 @@ import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.redphone.network.RtpPacket;
|
||||
import org.thoughtcrime.redphone.util.Conversions;
|
||||
import org.thoughtcrime.redphone.util.Hex;
|
||||
import org.thoughtcrime.securesms.util.Hex;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
@ -118,9 +118,7 @@ public class ConfirmPacket extends HandshakePacket {
|
||||
mac.update(this.data, PREIMAGE_OFFSET, ENCRYPTED_LENGTH);
|
||||
|
||||
return mac.doFinal();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} catch (InvalidKeyException e) {
|
||||
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.signaling;
|
||||
|
||||
/**
|
||||
* Exception for account creation failure.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
public class AccountCreationException extends Exception {
|
||||
|
||||
public AccountCreationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AccountCreationException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
|
||||
public AccountCreationException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
public AccountCreationException(String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
}
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
///*
|
||||
// * Copyright (C) 2015 Open 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.signaling;
|
||||
//
|
||||
//import android.content.Context;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.signaling.signals.CreateAccountSignal;
|
||||
//import org.thoughtcrime.redphone.signaling.signals.VerifyAccountSignal;
|
||||
//import org.thoughtcrime.securesms.BuildConfig;
|
||||
//
|
||||
//
|
||||
//public class AccountCreationSocket extends SignalingSocket {
|
||||
//
|
||||
// public AccountCreationSocket(Context context, String localNumber, String password)
|
||||
// throws SignalingException
|
||||
// {
|
||||
// super(context, BuildConfig.REDPHONE_MASTER_HOST, 31337, localNumber, password, null);
|
||||
// }
|
||||
//
|
||||
// public void createAccount(boolean voice)
|
||||
// throws SignalingException, AccountCreationException, RateLimitExceededException
|
||||
// {
|
||||
// sendSignal(new CreateAccountSignal(localNumber, password, voice));
|
||||
// SignalResponse response = readSignalResponse();
|
||||
//
|
||||
// switch (response.getStatusCode()) {
|
||||
// case 200: return;
|
||||
// case 413: throw new RateLimitExceededException("Rate limit exceeded.");
|
||||
// default: throw new AccountCreationException("Account creation failed: " +
|
||||
// response.getStatusCode());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void verifyAccount(String challenge, String key)
|
||||
// throws SignalingException, AccountCreationException, RateLimitExceededException
|
||||
// {
|
||||
// sendSignal(new VerifyAccountSignal(localNumber, password, challenge, key));
|
||||
// SignalResponse response = readSignalResponse();
|
||||
//
|
||||
// switch (response.getStatusCode()) {
|
||||
// case 200: return;
|
||||
// case 413: throw new RateLimitExceededException("Verify rate exceeded!");
|
||||
// default: throw new AccountCreationException("Account verification failed: " +
|
||||
// response.getStatusCode());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.signaling;
|
||||
|
||||
/**
|
||||
* A helper tuple that encapsulates both a directory filter and
|
||||
* hash count, as delivered in a directory update response signal.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
|
||||
public class DirectoryResponse {
|
||||
|
||||
private final int hashCount;
|
||||
private final byte[] filter;
|
||||
|
||||
public DirectoryResponse(int hashCount, byte[] filter) {
|
||||
this.hashCount = hashCount;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public int getHashCount() {
|
||||
return hashCount;
|
||||
}
|
||||
|
||||
public byte[] getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
}
|
@ -28,7 +28,6 @@ import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -92,12 +91,8 @@ public class NetworkConnector {
|
||||
socket.close();
|
||||
return localPort;
|
||||
|
||||
} catch (SocketException e) {
|
||||
} catch (IOException | SignalingException e) {
|
||||
Log.w("NetworkConnector", e);
|
||||
} catch (IOException e) {
|
||||
Log.w("NetworkConnector", e);
|
||||
} catch (SignalingException se) {
|
||||
Log.w("NetworkConnector", se);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
package org.thoughtcrime.redphone.signaling;
|
||||
|
||||
|
||||
public class RateLimitExceededException extends Throwable {
|
||||
public RateLimitExceededException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
@ -18,28 +18,19 @@
|
||||
package org.thoughtcrime.redphone.signaling;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.thoughtcrime.redphone.network.LowLatencySocketConnector;
|
||||
import org.thoughtcrime.redphone.signaling.signals.BusySignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.C2DMRegistrationSignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.C2DMUnregistrationSignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.DirectoryRequestSignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.GCMRegistrationSignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.GCMUnregistrationSignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.HangupSignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.InitiateSignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.RingingSignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.ServerSignal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.Signal;
|
||||
import org.thoughtcrime.redphone.signaling.signals.SignalPreferenceSignal;
|
||||
import org.thoughtcrime.redphone.util.LineReader;
|
||||
import org.whispersystems.textsecure.api.push.TrustStore;
|
||||
import org.whispersystems.textsecure.api.util.PhoneNumberFormatter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -51,7 +42,6 @@ import java.security.KeyManagementException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.Map;
|
||||
|
||||
@ -93,15 +83,6 @@ public class SignalingSocket {
|
||||
|
||||
private boolean connectionAttemptComplete;
|
||||
|
||||
// public SignalingSocket(Context context) throws SignalingException {
|
||||
// this(context,
|
||||
// BuildConfig.RE.MASTER_SERVER_HOST,
|
||||
// Release.SERVER_PORT,
|
||||
// PreferenceManager.getDefaultSharedPreferences(context).getString(Constants.NUMBER_PREFERENCE, "NO_SAVED_NUMBER!"),
|
||||
// PreferenceManager.getDefaultSharedPreferences(context).getString(Constants.PASSWORD_PREFERENCE, "NO_SAVED_PASSWORD!"),
|
||||
// null);
|
||||
// }
|
||||
|
||||
public SignalingSocket(Context context, String host, int port,
|
||||
String localNumber, String password,
|
||||
OtpCounterProvider counterProvider)
|
||||
@ -115,7 +96,6 @@ public class SignalingSocket {
|
||||
this.socket = constructSSLSocket(context, signalingHost, signalingPort);
|
||||
this.outputStream = this.socket.getOutputStream();
|
||||
this.lineReader = new LineReader(socket.getInputStream());
|
||||
// this.localNumber = PhoneNumberFormatter.formatNumber(localNumber);
|
||||
this.localNumber = localNumber;
|
||||
this.password = password;
|
||||
this.counterProvider = counterProvider;
|
||||
@ -132,35 +112,11 @@ public class SignalingSocket {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, trustManagers, null);
|
||||
|
||||
|
||||
//
|
||||
// AssetManager assetManager = context.getAssets();
|
||||
// InputStream keyStoreInputStream = assetManager.open("whisper.store");
|
||||
// KeyStore trustStore = KeyStore.getInstance("BKS");
|
||||
//
|
||||
// trustStore.load(keyStoreInputStream, "whisper".toCharArray());
|
||||
//
|
||||
// SSLSocketFactory sslSocketFactory = new SSLSocketFactory(trustStore);
|
||||
// sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
|
||||
// } else {
|
||||
// Log.w("SignalingSocket", "Disabling hostname verification...");
|
||||
// sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
// }
|
||||
|
||||
// return timeoutHackConnect(sslSocketFactory, host, port);
|
||||
return timeoutHackConnect(sslContext.getSocketFactory(), host, port);
|
||||
} catch (IOException ioe) {
|
||||
throw new SignalingException(ioe);
|
||||
} catch (NoSuchAlgorithmException | KeyManagementException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
// } catch (KeyStoreException e) {
|
||||
// throw new IllegalArgumentException(e);
|
||||
// } catch (CertificateException e) {
|
||||
// throw new IllegalArgumentException(e);
|
||||
// } catch (KeyManagementException e) {
|
||||
// throw new IllegalArgumentException(e);
|
||||
// } catch (UnrecoverableKeyException e) {
|
||||
// throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,15 +178,12 @@ public class SignalingSocket {
|
||||
|
||||
SignalResponse response = readSignalResponse();
|
||||
|
||||
// Gson gson = new Gson();
|
||||
|
||||
try {
|
||||
switch (response.getStatusCode()) {
|
||||
case 404: throw new NoSuchUserException("No such redphone user.");
|
||||
case 402: throw new ServerMessageException(new String(response.getBody()));
|
||||
case 401: throw new LoginFailedException("Initiate threw 401");
|
||||
case 200: return new ObjectMapper().readValue(response.getBody(), SessionDescriptor.class);
|
||||
// .gson.fromJson(new String(response.getBody()), SessionDescriptor.class);
|
||||
default: throw new SignalingException("Unknown response: " + response.getStatusCode());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -272,89 +225,6 @@ public class SignalingSocket {
|
||||
readSignalResponse();
|
||||
}
|
||||
|
||||
public void registerSignalingPreference(String preference) throws SignalingException {
|
||||
sendSignal(new SignalPreferenceSignal(localNumber, password, preference));
|
||||
SignalResponse response = readSignalResponse();
|
||||
|
||||
switch (response.getStatusCode()) {
|
||||
case 200: return;
|
||||
default: throw new SignalingException("Received error from server: " +
|
||||
new String(response.getBody()));
|
||||
}
|
||||
}
|
||||
|
||||
public void registerGcm(String registrationId) throws SignalingException {
|
||||
sendSignal(new GCMRegistrationSignal(localNumber, password, registrationId));
|
||||
SignalResponse response = readSignalResponse();
|
||||
|
||||
switch (response.getStatusCode()) {
|
||||
case 200: return;
|
||||
default: throw new SignalingException("Received error from server: " +
|
||||
new String(response.getBody()));
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterGcm(String registrationId) throws SignalingException {
|
||||
sendSignal(new GCMUnregistrationSignal(localNumber, password, registrationId));
|
||||
SignalResponse response = readSignalResponse();
|
||||
|
||||
switch (response.getStatusCode()) {
|
||||
case 200: return;
|
||||
default: throw new SignalingException("Received error from server: " +
|
||||
new String(response.getBody()));
|
||||
}
|
||||
}
|
||||
|
||||
public void registerC2dm(String registrationId) throws SignalingException {
|
||||
sendSignal(new C2DMRegistrationSignal(localNumber, password, registrationId));
|
||||
SignalResponse response = readSignalResponse();
|
||||
|
||||
switch (response.getStatusCode()) {
|
||||
case 200: return;
|
||||
default: throw new SignalingException("Received error from server: " +
|
||||
new String(response.getBody()));
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterC2dm() throws SignalingException {
|
||||
sendSignal(new C2DMUnregistrationSignal(localNumber, password));
|
||||
SignalResponse response = readSignalResponse();
|
||||
|
||||
switch (response.getStatusCode()) {
|
||||
case 200: return;
|
||||
default: throw new SignalingException("Received error from server: " +
|
||||
new String(response.getBody()));
|
||||
}
|
||||
}
|
||||
|
||||
public DirectoryResponse getNumberFilter() throws SignalingException {
|
||||
sendSignal(new DirectoryRequestSignal(localNumber, password));
|
||||
SignalResponse response = readSignalResponse();
|
||||
|
||||
switch (response.getStatusCode()) {
|
||||
case 200:
|
||||
try {
|
||||
if (!response.getHeaders().containsKey("X-Hash-Count"))
|
||||
break;
|
||||
|
||||
int hashCount = Integer.parseInt(response.getHeaders().get("X-Hash-Count"));
|
||||
|
||||
Log.w("SignalingSocket", "Got directory response: " + hashCount +
|
||||
" , " + response.getBody());
|
||||
|
||||
return new DirectoryResponse(hashCount, response.getBody());
|
||||
} catch (NumberFormatException nfe) {
|
||||
Log.w("SignalingSocket", nfe);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Log.w("SignalingSocket", "Unknown response from directory request: " +
|
||||
response.getStatusCode());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sendOkResponse() throws SignalingException {
|
||||
try {
|
||||
this.outputStream.write("HTTP/1.0 200 OK\r\nContent-Length: 0\r\n\r\n".getBytes());
|
||||
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.signaling.signals;
|
||||
|
||||
/**
|
||||
* A signal that requests a verification code via SMS
|
||||
* in order to initiate the account creation process.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
|
||||
public class CreateAccountSignal extends Signal {
|
||||
|
||||
private final boolean voice;
|
||||
|
||||
public CreateAccountSignal(String localNumber, String password, boolean voice) {
|
||||
super(localNumber, password, -1);
|
||||
this.voice = voice;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMethod() {
|
||||
return "GET";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocation() {
|
||||
if (!voice) return "/users/verification/sms";
|
||||
else return "/users/verification/voice";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBody() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.signaling.signals;
|
||||
|
||||
/**
|
||||
* A signal which requests a RedPhone Directory update.
|
||||
* The server responds with its current bloom filter.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
|
||||
public class DirectoryRequestSignal extends Signal {
|
||||
|
||||
public DirectoryRequestSignal(String localNumber, String password) {
|
||||
super(localNumber, password, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMethod() {
|
||||
return "GET";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocation() {
|
||||
return "/users/directory";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package org.thoughtcrime.redphone.signaling.signals;
|
||||
|
||||
public class GCMRegistrationSignal extends Signal {
|
||||
|
||||
private final String registrationId;
|
||||
|
||||
public GCMRegistrationSignal(String localNumber, String password, String registrationId) {
|
||||
super(localNumber, password, -1);
|
||||
this.registrationId = registrationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMethod() {
|
||||
return "PUT";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocation() {
|
||||
return "/gcm/" + registrationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBody() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.thoughtcrime.redphone.signaling.signals;
|
||||
|
||||
public class GCMUnregistrationSignal extends Signal {
|
||||
|
||||
private final String registrationId;
|
||||
|
||||
public GCMUnregistrationSignal(String localNumber, String password, String registrationId) {
|
||||
super(localNumber, password, -1);
|
||||
this.registrationId = registrationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMethod() {
|
||||
return "DELETE";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocation() {
|
||||
return "/gcm/" + registrationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.thoughtcrime.redphone.signaling.signals;
|
||||
|
||||
public class SignalPreferenceSignal extends Signal {
|
||||
|
||||
private final String preference;
|
||||
|
||||
public SignalPreferenceSignal(String localNumber, String password, String preference) {
|
||||
super(localNumber, password, -1);
|
||||
this.preference = preference;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMethod() {
|
||||
return "PUT";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocation() {
|
||||
return "/users/signaling_method/" + preference;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.signaling.signals;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* A verification signal used to confirm an account creation.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
|
||||
public class VerifyAccountSignal extends Signal {
|
||||
|
||||
private final String challenge;
|
||||
private final String key;
|
||||
private final String localNumber;
|
||||
|
||||
public VerifyAccountSignal(String localNumber, String password, String challenge, String key) {
|
||||
super(localNumber, password, -1);
|
||||
this.challenge = challenge;
|
||||
this.key = key;
|
||||
this.localNumber = localNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMethod() {
|
||||
return "PUT";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocation() {
|
||||
return "/users/verification/" + localNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBody() {
|
||||
try {
|
||||
return new ObjectMapper().writeValueAsString(new VerifyArguments(challenge, key));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
// Gson gson = new Gson();
|
||||
// return gson.toJson(new VerifyArguments(challenge, key));
|
||||
}
|
||||
|
||||
private static class VerifyArguments {
|
||||
public String key;
|
||||
public String challenge;
|
||||
|
||||
public VerifyArguments(String challenge, String key) {
|
||||
this.key = key;
|
||||
this.challenge = challenge;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
///*
|
||||
// * 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.ui;
|
||||
//
|
||||
//import android.content.pm.PackageInfo;
|
||||
//import android.content.pm.PackageManager.NameNotFoundException;
|
||||
//import android.os.Bundle;
|
||||
//import android.support.v7.app.AppCompatActivity;
|
||||
//import android.view.MenuItem;
|
||||
//import android.widget.TextView;
|
||||
//
|
||||
//import org.thoughtcrime.securesms.R;
|
||||
//
|
||||
//`
|
||||
///**
|
||||
// * The RedPhone "about" dialog.
|
||||
// *
|
||||
// * @author Moxie Marlinspike
|
||||
// *
|
||||
// */
|
||||
//public class AboutActivity extends AppCompatActivity {
|
||||
//
|
||||
// @Override
|
||||
// public void onCreate(Bundle icicle) {
|
||||
// super.onCreate(icicle);
|
||||
// setContentView(R.layout.about_activity);
|
||||
//
|
||||
// getSupportActionBar().setTitle(R.string.AboutActivity_about_redphone);
|
||||
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
//
|
||||
// TextView versionTextView = (TextView)findViewById(R.id.versionText);
|
||||
// versionTextView.setText(String.format(getString(R.string.AboutActivity_redphone_beta_s),
|
||||
// getCurrentVersion()));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// switch (item.getItemId()) {
|
||||
// case android.R.id.home:
|
||||
// finish();
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private String getCurrentVersion() {
|
||||
// try {
|
||||
// PackageInfo packageInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0);
|
||||
// return packageInfo.versionName;
|
||||
// } catch (NameNotFoundException e) {
|
||||
// throw new AssertionError(e);
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,25 +0,0 @@
|
||||
package org.thoughtcrime.redphone.ui;
|
||||
|
||||
public class AccountVerificationTimeoutException extends Exception {
|
||||
|
||||
public AccountVerificationTimeoutException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public AccountVerificationTimeoutException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public AccountVerificationTimeoutException(Throwable throwable) {
|
||||
super(throwable);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public AccountVerificationTimeoutException(String detailMessage,
|
||||
Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
///*
|
||||
// * 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.ui;
|
||||
//
|
||||
//import android.content.Context;
|
||||
//import android.os.Bundle;
|
||||
//import android.preference.PreferenceManager;
|
||||
//import android.support.v7.app.AppCompatActivity;
|
||||
//
|
||||
//import com.actionbarsherlock.app.SherlockPreferenceActivity;
|
||||
//import com.actionbarsherlock.view.MenuItem;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.R;
|
||||
//import org.thoughtcrime.redphone.Release;
|
||||
//
|
||||
///**
|
||||
// * Preferences menu Activity.
|
||||
// *
|
||||
// * Also provides methods for setting and getting application preferences.
|
||||
// *
|
||||
// * @author Stuart O. Anderson
|
||||
// */
|
||||
////TODO(Stuart Anderson): Consider splitting this into an Activity and a utility class
|
||||
//public class ApplicationPreferencesActivity extends AppCompatActivity {
|
||||
//
|
||||
// public static final String LOOPBACK_MODE_PREF = "pref_loopback";
|
||||
// public static final String OPPORTUNISTIC_UPGRADE_PREF = "pref_prompt_upgrade";
|
||||
// public static final String BLUETOOTH_ENABLED = "pref_bluetooth_enabled";
|
||||
//
|
||||
// @Override
|
||||
// protected void onCreate(Bundle icicle) {
|
||||
// super.onCreate(icicle);
|
||||
// addPreferencesFromResource(R.xml.preferences);
|
||||
//
|
||||
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
// getSupportActionBar().setTitle(R.string.ApplicationPreferencesActivity_redphone_settings);
|
||||
//
|
||||
// if(Release.DEBUG) {
|
||||
// addPreferencesFromResource(R.xml.debug);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onDestroy() {
|
||||
// super.onDestroy();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// switch (item.getItemId()) {
|
||||
// case android.R.id.home:
|
||||
// finish();
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// public static boolean getPromptUpgradePreference(Context context) {
|
||||
// return PreferenceManager
|
||||
// .getDefaultSharedPreferences(context).getBoolean(OPPORTUNISTIC_UPGRADE_PREF, true);
|
||||
// }
|
||||
//
|
||||
// public static boolean getLoopbackEnabled(Context context) {
|
||||
// return Release.DEBUG &&
|
||||
// PreferenceManager
|
||||
// .getDefaultSharedPreferences(context).getBoolean(LOOPBACK_MODE_PREF, false);
|
||||
// }
|
||||
//
|
||||
// public static boolean getBluetoothEnabled(Context context) {
|
||||
// return PreferenceManager
|
||||
// .getDefaultSharedPreferences(context).getBoolean(BLUETOOTH_ENABLED, false);
|
||||
// }
|
||||
//}
|
@ -63,15 +63,9 @@ public class CallCard extends LinearLayout {
|
||||
}
|
||||
|
||||
private void setPersonInfo(Recipient recipient) {
|
||||
// if (recipient.getImage() == null) this.photo.setImageResource(R.drawable.picture_unknown);
|
||||
// else this.photo.setImageBitmap(personInfo.getImage());
|
||||
|
||||
|
||||
|
||||
this.photo.setImageDrawable(recipient.getContactPhoto().asCallCard(getContext()));
|
||||
this.name.setText(recipient.getName());
|
||||
this.phoneNumber.setText(recipient.getNumber());
|
||||
// this.label.setText(recipient.getLabel());
|
||||
}
|
||||
|
||||
public void setCard(Recipient recipient, String status) {
|
||||
|
@ -48,9 +48,6 @@ public class CallControls extends RelativeLayout {
|
||||
|
||||
private ImageButton endCallButton;
|
||||
private TextView sasTextView;
|
||||
// private ImageButton confirmSasButton;
|
||||
// private View confirmSasWrapper;
|
||||
|
||||
private View activeCallWidget;
|
||||
private MultiWaveView incomingCallWidget;
|
||||
private TextView redphoneLabel;
|
||||
@ -96,7 +93,6 @@ public class CallControls extends RelativeLayout {
|
||||
incomingCallWidget.reset(false);
|
||||
incomingCallWidget.setVisibility(View.VISIBLE);
|
||||
redphoneLabel.setVisibility(View.VISIBLE);
|
||||
// confirmSasWrapper.setVisibility(View.GONE);
|
||||
|
||||
handler.sendEmptyMessageDelayed(0, 500);
|
||||
}
|
||||
@ -106,21 +102,12 @@ public class CallControls extends RelativeLayout {
|
||||
redphoneLabel.setVisibility(View.GONE);
|
||||
activeCallWidget.setVisibility(View.VISIBLE);
|
||||
sasTextView.setVisibility(View.GONE);
|
||||
// confirmSasWrapper.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void setActiveCall(SASInfo sas) {
|
||||
setActiveCall();
|
||||
sasTextView.setText(sas.getSasText());
|
||||
sasTextView.setVisibility(View.VISIBLE);
|
||||
|
||||
// if (sas.isVerified()) {
|
||||
// confirmSasWrapper.setVisibility(View.GONE);
|
||||
// sasTextView.setTextColor(Color.parseColor("#ffffff"));
|
||||
// } else{
|
||||
// confirmSasWrapper.setVisibility(View.VISIBLE);
|
||||
// sasTextView.setTextColor(Color.parseColor("#f0a621"));
|
||||
// }
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
@ -132,16 +119,6 @@ public class CallControls extends RelativeLayout {
|
||||
muteButton.setChecked(false);
|
||||
}
|
||||
|
||||
public void setConfirmSasButtonListener(final ConfirmSasButtonListener listener) {
|
||||
// confirmSasButton.setOnClickListener(new OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// setActiveCall(new SASInfo(sasTextView.getText().toString(), true));
|
||||
// listener.onClick();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
public void setHangupButtonListener(final HangupButtonListener listener) {
|
||||
endCallButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -191,8 +168,6 @@ public class CallControls extends RelativeLayout {
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
inflater.inflate(R.layout.redphone_call_controls, this, true);
|
||||
|
||||
// this.confirmSasButton = (ImageButton)findViewById(R.id.confirm_sas);
|
||||
// this.confirmSasWrapper = findViewById(R.id.confirm_wrapper);
|
||||
this.endCallButton = (ImageButton)findViewById(R.id.endButton);
|
||||
this.incomingCallWidget = (MultiWaveView)findViewById(R.id.incomingCallWidget);
|
||||
this.redphoneLabel = (TextView)findViewById(R.id.redphone_banner);
|
||||
@ -207,11 +182,9 @@ public class CallControls extends RelativeLayout {
|
||||
public void updateAudioButton() {
|
||||
audioButton.setAudioMode(AudioUtils.getCurrentAudioMode(getContext()));
|
||||
|
||||
// if(ApplicationPreferencesActivity.getBluetoothEnabled(getContext())) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(AudioUtils.getScoUpdateAction());
|
||||
handleBluetoothIntent(getContext().registerReceiver(null, filter));
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -226,18 +199,12 @@ public class CallControls extends RelativeLayout {
|
||||
|
||||
Integer state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
|
||||
if (state.equals(AudioManager.SCO_AUDIO_STATE_CONNECTED)) {
|
||||
// && ApplicationPreferencesActivity.getBluetoothEnabled(getContext())) {
|
||||
audioButton.setHeadsetAvailable(true);
|
||||
} else if (state.equals(AudioManager.SCO_AUDIO_STATE_DISCONNECTED)) {
|
||||
audioButton.setHeadsetAvailable(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static interface ConfirmSasButtonListener {
|
||||
public void onClick();
|
||||
}
|
||||
|
||||
public static interface HangupButtonListener {
|
||||
public void onClick();
|
||||
}
|
||||
|
@ -73,10 +73,6 @@ public class CallScreen extends FrameLayout {
|
||||
callControls.reset();
|
||||
}
|
||||
|
||||
public void setConfirmSasButtonListener(CallControls.ConfirmSasButtonListener listener) {
|
||||
callControls.setConfirmSasButtonListener(listener);
|
||||
}
|
||||
|
||||
public void setHangupButtonListener(CallControls.HangupButtonListener listener) {
|
||||
callControls.setHangupButtonListener(listener);
|
||||
}
|
||||
|
@ -1,343 +0,0 @@
|
||||
///*
|
||||
// * 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.ui;
|
||||
//
|
||||
//import android.annotation.SuppressLint;
|
||||
//import android.content.Context;
|
||||
//import android.content.Intent;
|
||||
//import android.database.Cursor;
|
||||
//import android.graphics.Bitmap;
|
||||
//import android.graphics.Typeface;
|
||||
//import android.os.Build;
|
||||
//import android.os.Bundle;
|
||||
//import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||
//import android.support.v4.app.LoaderManager;
|
||||
//import android.support.v4.content.Loader;
|
||||
//import android.support.v7.app.AppCompatActivity;
|
||||
//import android.view.LayoutInflater;
|
||||
//import android.view.View;
|
||||
//import android.view.ViewGroup;
|
||||
//import android.widget.CursorAdapter;
|
||||
//import android.widget.ImageView;
|
||||
//import android.widget.ListView;
|
||||
//import android.widget.RelativeLayout;
|
||||
//import android.widget.SectionIndexer;
|
||||
//import android.widget.TextView;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.Constants;
|
||||
//import org.thoughtcrime.redphone.RedPhone;
|
||||
//import org.thoughtcrime.redphone.RedPhoneService;
|
||||
//import org.thoughtcrime.redphone.contacts.ContactAccessor;
|
||||
//import org.thoughtcrime.redphone.contacts.ContactsSectionIndexer;
|
||||
//import org.thoughtcrime.redphone.util.BitmapUtil;
|
||||
//
|
||||
//import java.lang.ref.SoftReference;
|
||||
//import java.util.HashMap;
|
||||
//
|
||||
///**
|
||||
// * Activity that displays a listview of contacts for the RedPhone "dialer."
|
||||
// * Both for straight contacts and "frequently contacted" tabs.
|
||||
// *
|
||||
// * @author Moxie Marlinspike
|
||||
// *
|
||||
// */
|
||||
//
|
||||
//public class ContactsListActivity extends AppCompatActivity
|
||||
// implements LoaderManager.LoaderCallbacks<Cursor>
|
||||
//{
|
||||
//
|
||||
// private HashMap<Long, SoftReference<Bitmap>> photoCache
|
||||
// = new HashMap<Long, SoftReference<Bitmap>>();
|
||||
//
|
||||
// private boolean showSectionHeaders = true;
|
||||
// private String queryFilter = "";
|
||||
//
|
||||
// @Override
|
||||
// public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// super.onOptionsItemSelected(item);
|
||||
//
|
||||
// switch (item.getItemId()) {
|
||||
// case R.id.searchItem:
|
||||
// this.getSherlockActivity().getSupportActionBar().setIcon(R.drawable.ic_tab_contacts);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onActivityCreated(Bundle icicle) {
|
||||
// super.onActivityCreated(icicle);
|
||||
// displayContacts();
|
||||
//
|
||||
// if (!isFavoritesFragment() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
// setHasOptionsMenu(true);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// return inflater.inflate(R.layout.contacts_list_content, container, false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// inflater.inflate(R.menu.contact_list_options_menu, menu);
|
||||
// initializeSearch((android.widget.SearchView)menu.findItem(R.id.searchItem).getActionView());
|
||||
// }
|
||||
//
|
||||
// @SuppressLint("NewApi")
|
||||
// private void initializeSearch(android.widget.SearchView searchView) {
|
||||
// searchView.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() {
|
||||
// @Override
|
||||
// public boolean onQueryTextSubmit(String query) {
|
||||
// ContactsListActivity.this.queryFilter = query;
|
||||
// ContactsListActivity.this.getLoaderManager().restartLoader(0, null, ContactsListActivity.this);
|
||||
// return true;
|
||||
// }
|
||||
// @Override
|
||||
// public boolean onQueryTextChange(String newText) {
|
||||
// return onQueryTextSubmit(newText);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
// ContactItemView contactItemView = (ContactItemView)v;
|
||||
// String number = contactItemView.getNumber();
|
||||
// Intent intent = new Intent(getActivity(), RedPhoneService.class);
|
||||
//
|
||||
// intent.setAction(RedPhoneService.ACTION_OUTGOING_CALL);
|
||||
// intent.putExtra(Constants.REMOTE_NUMBER, number );
|
||||
// getActivity().startService(intent);
|
||||
//
|
||||
// Intent activityIntent = new Intent(getActivity(), RedPhone.class);
|
||||
// activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// startActivity(activityIntent);
|
||||
//
|
||||
// getActivity().finish();
|
||||
// }
|
||||
//
|
||||
// private void displayContacts() {
|
||||
// this.showSectionHeaders = !isFavoritesFragment();
|
||||
// setListAdapter(new ContactsListAdapter(getActivity(), null));
|
||||
// this.getLoaderManager().initLoader(0, null, this);
|
||||
// getListView().setDivider(null);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private class ContactsListAdapter extends CursorAdapter implements SectionIndexer {
|
||||
// private ContactsSectionIndexer indexer;
|
||||
// private HashMap<String, Integer> groupingTable;
|
||||
//
|
||||
// public ContactsListAdapter(Context context, Cursor c) {
|
||||
// super(context, c, false);
|
||||
// this.indexer = new ContactsSectionIndexer(c, Phone.DISPLAY_NAME);
|
||||
// this.groupingTable = new HashMap<String, Integer>();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void changeCursor(Cursor cursor) {
|
||||
// this.groupingTable = new HashMap<String, Integer>();
|
||||
// this.indexer = new ContactsSectionIndexer(cursor, Phone.DISPLAY_NAME);
|
||||
// super.changeCursor(cursor);
|
||||
// }
|
||||
//
|
||||
//// @Override
|
||||
//// public Cursor swapCursor(Cursor cursor) {
|
||||
//// this.groupingTable = new HashMap<String, Integer>();
|
||||
//// this.indexer = new ContactsSectionIndexer(cursor, Phone.DISPLAY_NAME);
|
||||
//// return super.swapCursor(cursor);
|
||||
//// }
|
||||
//
|
||||
// public int getPositionForSection(int section) {
|
||||
// return indexer.getPositionForSection(section);
|
||||
// }
|
||||
//
|
||||
// public int getSectionForPosition(int position) {
|
||||
// return indexer.getSectionForPosition(position);
|
||||
// }
|
||||
//
|
||||
// public Object[] getSections() {
|
||||
// return indexer.getSections();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
// ContactItemView view = new ContactItemView(context);
|
||||
// bindView(view, context, cursor);
|
||||
//
|
||||
// return view;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void bindView(View view, Context context, Cursor cursor) {
|
||||
// String contactName = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
|
||||
// int personId = cursor.getInt(cursor.getColumnIndex(Phone.CONTACT_ID));
|
||||
// String number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
|
||||
// int type = cursor.getInt(cursor.getColumnIndex(Phone.TYPE));
|
||||
// int rowId = cursor.getInt(cursor.getColumnIndex(Phone._ID));
|
||||
//
|
||||
// int section = indexer.getSectionForPosition(cursor.getPosition());
|
||||
//
|
||||
// if (showSectionHeaders && (cursor.getPosition() == indexer.getPositionForSection(section))) {
|
||||
// ((ContactItemView)view).setSectionLabel((String)indexer.getSections()[section]);
|
||||
// } else {
|
||||
// ((ContactItemView)view).disableSectionLabel();
|
||||
// }
|
||||
//
|
||||
// if (!groupingTable.containsKey(contactName) ||
|
||||
// (groupingTable.containsKey(contactName) &&
|
||||
// groupingTable.get(contactName) == rowId))
|
||||
// {
|
||||
// groupingTable.put(contactName, rowId);
|
||||
// ((ContactItemView)view).set(contactName, personId, number, type);
|
||||
// } else {
|
||||
// ((ContactItemView)view).setGrouped(contactName, personId, number, type);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class ContactItemView extends RelativeLayout {
|
||||
// private ImageView divider;
|
||||
// private View sectionDivider;
|
||||
// private TextView sectionLabel;
|
||||
// private TextView name;
|
||||
// private TextView number;
|
||||
// private TextView type;
|
||||
// private ImageView avatar;
|
||||
//
|
||||
// public ContactItemView(Context context) {
|
||||
// super(context.getApplicationContext());
|
||||
//
|
||||
// LayoutInflater li = (LayoutInflater) context
|
||||
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
// li.inflate(R.layout.contact_list_item, this, true);
|
||||
//
|
||||
// this.name = (TextView)findViewById(R.id.name);
|
||||
// this.number = (TextView)findViewById(R.id.number);
|
||||
// this.type = (TextView)findViewById(R.id.type);
|
||||
// this.sectionLabel = (TextView)findViewById(R.id.section_label);
|
||||
// this.divider = (ImageView)findViewById(R.id.divider);
|
||||
// this.sectionDivider = findViewById(R.id.section_divider);
|
||||
// this.avatar = (ImageView)findViewById(R.id.contact_photo_image);
|
||||
// }
|
||||
//
|
||||
// public void setSectionLabel(String label) {
|
||||
// this.sectionLabel.setText(label);
|
||||
// this.sectionLabel.setTypeface(sectionLabel.getTypeface(), Typeface.BOLD);
|
||||
// this.sectionLabel.setVisibility(View.VISIBLE);
|
||||
// this.divider.setVisibility(View.GONE);
|
||||
// this.sectionDivider.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
//
|
||||
// public void disableSectionLabel() {
|
||||
// this.sectionLabel.setVisibility(View.GONE);
|
||||
// this.divider.setVisibility(View.VISIBLE);
|
||||
// this.sectionDivider.setVisibility(View.GONE);
|
||||
// }
|
||||
//
|
||||
// public void set(String name, int personId, String number, int type) {
|
||||
// this.avatar.setImageBitmap(loadContactPhoto(personId));
|
||||
// this.name.setText(name);
|
||||
// this.number.setText(number);
|
||||
// this.type.setText(Phone.getTypeLabel(ContactsListActivity.this.getResources(), type, "").toString().toUpperCase());
|
||||
// this.avatar.setVisibility(View.VISIBLE);
|
||||
// this.name.setVisibility(View.VISIBLE);
|
||||
// this.divider.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
//
|
||||
// public void setGrouped(String name, int personId, String number, int type) {
|
||||
// set(name, personId, number, type);
|
||||
// this.name.setVisibility(View.INVISIBLE);
|
||||
// this.divider.setVisibility(View.GONE);
|
||||
// this.avatar.setVisibility(View.INVISIBLE);
|
||||
// }
|
||||
//
|
||||
// public String getNumber() {
|
||||
// return this.number.getText().toString();
|
||||
// }
|
||||
//
|
||||
// private Bitmap getCachedBitmapIfAvailable(long id) {
|
||||
// SoftReference<Bitmap> bitmapReference = photoCache.get(id);
|
||||
// if( bitmapReference != null ) {
|
||||
// Bitmap cachedBitmap = bitmapReference.get();
|
||||
// if( cachedBitmap != null ) {
|
||||
// return cachedBitmap;
|
||||
// } else {
|
||||
// photoCache.remove(id);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private Bitmap constructNewBitmap(long id) {
|
||||
// Bitmap newBitmap = ContactAccessor.getInstance()
|
||||
// .getPhoto(ContactsListActivity.this.getActivity(), id);
|
||||
// Bitmap croppedBitmap = BitmapUtil.getCircleCroppedBitmap(newBitmap);
|
||||
// SoftReference<Bitmap> newSR = new SoftReference<Bitmap>(croppedBitmap);
|
||||
// photoCache.put(id,newSR);
|
||||
// return croppedBitmap;
|
||||
// }
|
||||
//
|
||||
// private Bitmap loadContactPhoto(long id) {
|
||||
// Bitmap contactBitmap = getCachedBitmapIfAvailable(id);
|
||||
//
|
||||
// if (contactBitmap != null) return contactBitmap;
|
||||
// else return constructNewBitmap(id);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private boolean isFavoritesFragment() {
|
||||
// return getArguments() != null && getArguments().getBoolean("favorites", false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
// ((TextView)getListView().getEmptyView()).setText(R.string.ContactsListActivity_loading);
|
||||
//
|
||||
// if (isFavoritesFragment()) {
|
||||
// if (this.queryFilter == null || this.queryFilter.trim().length() == 0) {
|
||||
// return ContactAccessor.getInstance().getRegisteredFavoritesCursor(getActivity());
|
||||
// } else {
|
||||
// return ContactAccessor.getInstance().getRegisteredFavoritesCursor(getActivity(), queryFilter);
|
||||
// }
|
||||
// } else {
|
||||
// if (this.queryFilter == null || this.queryFilter.trim().length() == 0) {
|
||||
// return ContactAccessor.getInstance().getRegisteredContactsCursor(getActivity());
|
||||
// } else {
|
||||
// return ContactAccessor.getInstance().getRegisteredContactsCursor(getActivity(), queryFilter);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
||||
// ((TextView)getListView().getEmptyView()).setText(R.string.ContactsListActivity_no_contacts_found);
|
||||
// ((CursorAdapter)getListAdapter()).changeCursor(cursor);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onLoaderReset(Loader<Cursor> arg0) {
|
||||
// ((CursorAdapter)getListAdapter()).changeCursor(null);
|
||||
// }
|
||||
//
|
||||
//}
|
@ -1,30 +0,0 @@
|
||||
//package org.thoughtcrime.redphone.ui;
|
||||
//
|
||||
//import android.content.Intent;
|
||||
//import android.os.Bundle;
|
||||
//
|
||||
//import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.R;
|
||||
//
|
||||
//public class CountrySelectionActivity extends SherlockFragmentActivity
|
||||
// implements CountrySelectionFragment.CountrySelectedListener
|
||||
//
|
||||
//{
|
||||
//
|
||||
// @Override
|
||||
// public void onCreate(Bundle bundle) {
|
||||
// super.onCreate(bundle);
|
||||
// this.setContentView(R.layout.country_selection);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void countrySelected(String countryName, int countryCode) {
|
||||
// Intent result = getIntent();
|
||||
// result.putExtra("country_name", countryName);
|
||||
// result.putExtra("country_code", countryCode);
|
||||
//
|
||||
// this.setResult(RESULT_OK, result);
|
||||
// this.finish();
|
||||
// }
|
||||
//}
|
@ -1,101 +0,0 @@
|
||||
//package org.thoughtcrime.redphone.ui;
|
||||
//
|
||||
//import android.app.Activity;
|
||||
//import android.os.Bundle;
|
||||
//import android.support.v4.app.LoaderManager;
|
||||
//import android.support.v4.content.Loader;
|
||||
//import android.text.Editable;
|
||||
//import android.text.TextWatcher;
|
||||
//import android.view.LayoutInflater;
|
||||
//import android.view.View;
|
||||
//import android.view.ViewGroup;
|
||||
//import android.widget.EditText;
|
||||
//import android.widget.ListView;
|
||||
//import android.widget.SimpleAdapter;
|
||||
//
|
||||
//import com.actionbarsherlock.app.SherlockListFragment;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.R;
|
||||
//import org.thoughtcrime.redphone.registration.CountryListLoader;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//public class CountrySelectionFragment extends SherlockListFragment implements LoaderManager.LoaderCallbacks<ArrayList<Map<String, String>>> {
|
||||
//
|
||||
// private EditText countryFilter;
|
||||
// private CountrySelectedListener listener;
|
||||
//
|
||||
// @Override
|
||||
// public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
||||
// return inflater.inflate(R.layout.country_selection_fragment, container, false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onActivityCreated(Bundle bundle) {
|
||||
// super.onActivityCreated(bundle);
|
||||
// this.countryFilter = (EditText)getView().findViewById(R.id.country_search);
|
||||
// this.countryFilter.addTextChangedListener(new FilterWatcher());
|
||||
// getLoaderManager().initLoader(0, null, this).forceLoad();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onAttach(Activity activity) {
|
||||
// super.onAttach(activity);
|
||||
// this.listener = (CountrySelectedListener)activity;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onListItemClick(ListView listView, View view, int position, long id) {
|
||||
// Map<String, String> item = (Map<String, String>)this.getListAdapter().getItem(position);
|
||||
// if (this.listener != null) {
|
||||
// this.listener.countrySelected(item.get("country_name"),
|
||||
// Integer.parseInt(item.get("country_code").substring(1)));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Loader<ArrayList<Map<String, String>>> onCreateLoader(int arg0, Bundle arg1) {
|
||||
// return new CountryListLoader(getActivity());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onLoadFinished(Loader<ArrayList<Map<String, String>>> loader,
|
||||
// ArrayList<Map<String, String>> results)
|
||||
// {
|
||||
// String[] from = {"country_name", "country_code"};
|
||||
// int[] to = {R.id.country_name, R.id.country_code};
|
||||
// this.setListAdapter(new SimpleAdapter(getActivity(), results, R.layout.country_list_item, from, to));
|
||||
//
|
||||
// if (this.countryFilter != null && this.countryFilter.getText().length() != 0) {
|
||||
// ((SimpleAdapter)getListAdapter()).getFilter().filter(this.countryFilter.getText().toString());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onLoaderReset(Loader<ArrayList<Map<String, String>>> arg0) {
|
||||
// this.setListAdapter(null);
|
||||
// }
|
||||
//
|
||||
// public interface CountrySelectedListener {
|
||||
// public void countrySelected(String countryName, int countryCode);
|
||||
// }
|
||||
//
|
||||
// private class FilterWatcher implements TextWatcher {
|
||||
//
|
||||
// @Override
|
||||
// public void afterTextChanged(Editable s) {
|
||||
// if (getListAdapter() != null) {
|
||||
// ((SimpleAdapter)getListAdapter()).getFilter().filter(s.toString());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,294 +0,0 @@
|
||||
///*
|
||||
// * 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.ui;
|
||||
//
|
||||
//import android.app.AlertDialog;
|
||||
//import android.content.Context;
|
||||
//import android.content.DialogInterface;
|
||||
//import android.content.Intent;
|
||||
//import android.os.Bundle;
|
||||
//import android.telephony.TelephonyManager;
|
||||
//import android.text.Editable;
|
||||
//import android.text.TextWatcher;
|
||||
//import android.util.Log;
|
||||
//import android.view.MotionEvent;
|
||||
//import android.view.View;
|
||||
//import android.widget.ArrayAdapter;
|
||||
//import android.widget.Button;
|
||||
//import android.widget.Spinner;
|
||||
//import android.widget.TextView;
|
||||
//import android.widget.Toast;
|
||||
//
|
||||
//import com.actionbarsherlock.app.ActionBar;
|
||||
//import com.actionbarsherlock.app.SherlockActivity;
|
||||
//import com.actionbarsherlock.view.Menu;
|
||||
//import com.actionbarsherlock.view.MenuInflater;
|
||||
//import com.actionbarsherlock.view.MenuItem;
|
||||
//import com.google.i18n.phonenumbers.AsYouTypeFormatter;
|
||||
//import com.google.i18n.phonenumbers.NumberParseException;
|
||||
//import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
//import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.ApplicationContext;
|
||||
//import org.thoughtcrime.redphone.R;
|
||||
//import org.thoughtcrime.redphone.util.PhoneNumberFormatter;
|
||||
//import org.thoughtcrime.redphone.util.Util;
|
||||
//
|
||||
///**
|
||||
// * The create account activity. Kicks off an account creation event, then waits
|
||||
// * the server to respond with a challenge via SMS, receives the challenge, and
|
||||
// * verifies it with the server.
|
||||
// *
|
||||
// * @author Moxie Marlinspike
|
||||
// *
|
||||
// */
|
||||
//
|
||||
//public class CreateAccountActivity extends SherlockActivity {
|
||||
//
|
||||
// private static final int PICK_COUNTRY = 1;
|
||||
//
|
||||
// private AsYouTypeFormatter countryFormatter;
|
||||
// private ArrayAdapter<String> countrySpinnerAdapter;
|
||||
// private Spinner countrySpinner;
|
||||
// private TextView countryCode;
|
||||
// private TextView number;
|
||||
// private Button createButton;
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void onCreate(Bundle icicle) {
|
||||
// super.onCreate(icicle);
|
||||
// setContentView(R.layout.create_account);
|
||||
//
|
||||
// ActionBar actionBar = this.getSupportActionBar();
|
||||
// actionBar.setTitle(R.string.CreateAccountActivity_register_your_redphone);
|
||||
//
|
||||
// initializeResources();
|
||||
// initializeNumber();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// MenuInflater inflater = this.getSupportMenuInflater();
|
||||
// inflater.inflate(R.menu.about_menu, menu);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// switch (item.getItemId()) {
|
||||
// case R.id.aboutItem:
|
||||
// Intent aboutIntent = new Intent(this, AboutActivity.class);
|
||||
// startActivity(aboutIntent);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// if (requestCode == PICK_COUNTRY && resultCode == RESULT_OK && data != null) {
|
||||
// this.countryCode.setText(data.getIntExtra("country_code", 1)+"");
|
||||
// setCountryDisplay(data.getStringExtra("country_name"));
|
||||
// setCountryFormatter(data.getIntExtra("country_code", 1));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void initializeResources() {
|
||||
// ApplicationContext.getInstance().setContext(this);
|
||||
//
|
||||
// this.countrySpinner = (Spinner)findViewById(R.id.country_spinner);
|
||||
// this.countryCode = (TextView)findViewById(R.id.country_code);
|
||||
// this.number = (TextView)findViewById(R.id.number);
|
||||
// this.createButton = (Button)findViewById(R.id.registerButton);
|
||||
//
|
||||
// this.countrySpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
|
||||
// this.countrySpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
// setCountryDisplay(getString(R.string.CreateAccountActivity_select_your_country));
|
||||
//
|
||||
// this.countrySpinner.setAdapter(this.countrySpinnerAdapter);
|
||||
// this.countrySpinner.setOnTouchListener(new View.OnTouchListener() {
|
||||
// @Override
|
||||
// public boolean onTouch(View v, MotionEvent event) {
|
||||
// if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
// Intent intent = new Intent(CreateAccountActivity.this, CountrySelectionActivity.class);
|
||||
// startActivityForResult(intent, PICK_COUNTRY);
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// this.countryCode.addTextChangedListener(new CountryCodeChangedListener());
|
||||
// this.number.addTextChangedListener(new NumberChangedListener());
|
||||
// this.createButton.setOnClickListener(new CreateButtonListener());
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void initializeNumber() {
|
||||
// String localNumber = ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE))
|
||||
// .getLine1Number();
|
||||
//
|
||||
// if (!Util.isEmpty(localNumber) && !localNumber.startsWith("+")) {
|
||||
// if (localNumber.length() == 10) localNumber = "+1" + localNumber;
|
||||
// else localNumber = "+" + localNumber;
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// if (!Util.isEmpty(localNumber)) {
|
||||
// PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();
|
||||
// PhoneNumber localNumberObject = numberUtil.parse(localNumber, null);
|
||||
//
|
||||
// if (localNumberObject != null) {
|
||||
// this.countryCode.setText(localNumberObject.getCountryCode()+"");
|
||||
// this.number.setText(localNumberObject.getNationalNumber()+"");
|
||||
// }
|
||||
// }
|
||||
// } catch (NumberParseException npe) {
|
||||
// Log.w("CreateAccountActivity", npe);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void setCountryDisplay(String value) {
|
||||
// this.countrySpinnerAdapter.clear();
|
||||
// this.countrySpinnerAdapter.add(value);
|
||||
// }
|
||||
//
|
||||
// private void setCountryFormatter(int countryCode) {
|
||||
// PhoneNumberUtil util = PhoneNumberUtil.getInstance();
|
||||
// String regionCode = util.getRegionCodeForCountryCode(countryCode);
|
||||
//
|
||||
// if (regionCode == null) {
|
||||
// this.countryFormatter = null;
|
||||
// } else {
|
||||
// this.countryFormatter = util.getAsYouTypeFormatter(regionCode);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private String getConfiguredE164Number() {
|
||||
// return PhoneNumberFormatter.formatE164(countryCode.getText().toString(),
|
||||
// number.getText().toString());
|
||||
// }
|
||||
//
|
||||
// private class CreateButtonListener implements View.OnClickListener {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// final CreateAccountActivity self = CreateAccountActivity.this;
|
||||
//
|
||||
// if (Util.isEmpty(countryCode.getText())) {
|
||||
// Toast.makeText(self,
|
||||
// R.string.CreateAccountActivity_you_must_specify_your_country_code,
|
||||
// Toast.LENGTH_LONG).show();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (Util.isEmpty(number.getText())) {
|
||||
// Toast.makeText(self,
|
||||
// R.string.CreateAccountActivity_you_must_specify_your_phone_number,
|
||||
// Toast.LENGTH_LONG).show();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// final String e164number = getConfiguredE164Number();
|
||||
//
|
||||
// if (!PhoneNumberFormatter.isValidNumber(e164number)) {
|
||||
// Util.showAlertDialog(self,
|
||||
// getString(R.string.CreateAccountActivity_invalid_number),
|
||||
// String.format(getString(R.string.CreateAccountActivity_the_number_you_specified_s_is_invalid), e164number));
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// AlertDialog.Builder dialog = new AlertDialog.Builder(self);
|
||||
// dialog.setMessage(String.format(getString(R.string.CreateAccountActivity_we_will_now_verify_that_the_following_number_is_associated),
|
||||
// PhoneNumberFormatter.getInternationalFormatFromE164(e164number)));
|
||||
// dialog.setPositiveButton(getString(R.string.CreateAccountActivity_continue),
|
||||
// new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// Intent intent = new Intent(self, RegistrationProgressActivity.class);
|
||||
// intent.putExtra("e164number", e164number);
|
||||
// startActivity(intent);
|
||||
// finish();
|
||||
// }
|
||||
// });
|
||||
// dialog.setNegativeButton(getString(R.string.CreateAccountActivity_edit), null);
|
||||
// dialog.show();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class CountryCodeChangedListener implements TextWatcher {
|
||||
// @Override
|
||||
// public void afterTextChanged(Editable s) {
|
||||
// if (Util.isEmpty(s)) {
|
||||
// setCountryDisplay(getString(R.string.CreateAccountActivity_select_your_country));
|
||||
// countryFormatter = null;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// int countryCode = Integer.parseInt(s.toString());
|
||||
// String regionCode = PhoneNumberUtil.getInstance().getRegionCodeForCountryCode(countryCode);
|
||||
// setCountryFormatter(countryCode);
|
||||
// setCountryDisplay(PhoneNumberFormatter.getRegionDisplayName(regionCode));
|
||||
//
|
||||
// if (!Util.isEmpty(regionCode) && !regionCode.equals("ZZ")) {
|
||||
// number.requestFocus();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class NumberChangedListener implements TextWatcher {
|
||||
//
|
||||
// @Override
|
||||
// public void afterTextChanged(Editable s) {
|
||||
// if (countryFormatter == null)
|
||||
// return;
|
||||
//
|
||||
// if (Util.isEmpty(s))
|
||||
// return;
|
||||
//
|
||||
// countryFormatter.clear();
|
||||
//
|
||||
// String number = s.toString().replaceAll("[^\\d.]", "");
|
||||
// String formattedNumber = null;
|
||||
//
|
||||
// for (int i=0;i<number.length();i++) {
|
||||
// formattedNumber = countryFormatter.inputDigit(number.charAt(i));
|
||||
// }
|
||||
//
|
||||
// if (!s.toString().equals(formattedNumber)) {
|
||||
// s.replace(0, s.length(), formattedNumber);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,235 +0,0 @@
|
||||
///*
|
||||
// * Copyright (C) 2014 Open 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.ui;
|
||||
//
|
||||
//import android.content.Intent;
|
||||
//import android.os.Build;
|
||||
//import android.os.Bundle;
|
||||
//import android.support.v4.app.Fragment;
|
||||
//import android.text.Editable;
|
||||
//import android.view.KeyEvent;
|
||||
//import android.view.LayoutInflater;
|
||||
//import android.view.View;
|
||||
//import android.view.ViewGroup;
|
||||
//import android.widget.EditText;
|
||||
//import android.widget.ImageView;
|
||||
//import android.widget.TableRow;
|
||||
//import android.widget.TextView;
|
||||
//import android.widget.Toast;
|
||||
//
|
||||
//
|
||||
//import org.thoughtcrime.redphone.Constants;
|
||||
//import org.thoughtcrime.redphone.RedPhone;
|
||||
//import org.thoughtcrime.redphone.RedPhoneService;
|
||||
//import org.thoughtcrime.redphone.dialer.DialpadKeyButton;
|
||||
//import org.thoughtcrime.redphone.util.Util;
|
||||
//
|
||||
///**
|
||||
// * Activity that displays a dial pad.
|
||||
// *
|
||||
// * @author Moxie Marlinspike
|
||||
// *
|
||||
// */
|
||||
//
|
||||
//public class DialPadActivity extends Fragment
|
||||
// implements DialpadKeyButton.OnPressedListener, View.OnLongClickListener, View.OnClickListener {
|
||||
//
|
||||
// private EditText digitEntry;
|
||||
// private View deleteButton;
|
||||
//
|
||||
// @Override
|
||||
// public void onActivityCreated(Bundle icicle) {
|
||||
// super.onActivityCreated(icicle);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// View fragmentView = inflater.inflate(R.layout.dialpad_fragment, container, false);
|
||||
//
|
||||
// initializeDeleteButton(fragmentView);
|
||||
// initializeDigitEntry(fragmentView);
|
||||
// initializeKeyPad(fragmentView);
|
||||
// initializeCallButton(fragmentView);
|
||||
//
|
||||
// return fragmentView;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// inflater.inflate(R.menu.contact_list_options_menu, menu);
|
||||
// }
|
||||
//
|
||||
// private void initializeCallButton(View fragmentView) {
|
||||
// ImageView callButton = (ImageView)fragmentView.findViewById(R.id.call_button);
|
||||
// callButton.setOnClickListener(this);
|
||||
// }
|
||||
//
|
||||
// private void initializeDigitEntry(View fragmentView) {
|
||||
// digitEntry = (EditText) fragmentView.findViewById(R.id.digits);
|
||||
// digitEntry.setOnClickListener(this);
|
||||
// digitEntry.setOnLongClickListener(this);
|
||||
// }
|
||||
//
|
||||
// private void initializeDeleteButton(View fragmentView) {
|
||||
// deleteButton = fragmentView.findViewById(R.id.deleteButton);
|
||||
// if (deleteButton != null) {
|
||||
// deleteButton.setOnClickListener(this);
|
||||
// deleteButton.setOnLongClickListener(this);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void initializeKeyPad(View fragmentView) {
|
||||
// int[] buttonIds = new int[] {R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four,
|
||||
// R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine,
|
||||
// R.id.star, R.id.pound};
|
||||
//
|
||||
// String[] numbers = new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "#"};
|
||||
// String[] letters = new String[] {"+", "", "ABC", "DEF", "GHI","JKL", "MNO", "PQRS", "TUV", "WXYZ", "", ""};
|
||||
//
|
||||
// DialpadKeyButton dialpadKey;
|
||||
// TextView numberView;
|
||||
// TextView lettersView;
|
||||
//
|
||||
// for (int i = 0; i < buttonIds.length; i++) {
|
||||
// dialpadKey = (DialpadKeyButton) fragmentView.findViewById(buttonIds[i]);
|
||||
// dialpadKey.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
|
||||
// TableRow.LayoutParams.MATCH_PARENT));
|
||||
// dialpadKey.setOnPressedListener(this);
|
||||
// numberView = (TextView) dialpadKey.findViewById(R.id.dialpad_key_number);
|
||||
// lettersView = (TextView) dialpadKey.findViewById(R.id.dialpad_key_letters);
|
||||
//
|
||||
// numberView.setText(numbers[i]);
|
||||
// dialpadKey.setContentDescription(numbers[i]);
|
||||
//
|
||||
// if (lettersView != null) {
|
||||
// lettersView.setText(letters[i]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fragmentView.findViewById(R.id.zero).setOnLongClickListener(this);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void onPressed(View view, boolean pressed) {
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN ? !pressed : pressed) return;
|
||||
//
|
||||
// switch (view.getId()) {
|
||||
// case R.id.one: keyPressed(KeyEvent.KEYCODE_1); break;
|
||||
// case R.id.two: keyPressed(KeyEvent.KEYCODE_2); break;
|
||||
// case R.id.three: keyPressed(KeyEvent.KEYCODE_3); break;
|
||||
// case R.id.four: keyPressed(KeyEvent.KEYCODE_4); break;
|
||||
// case R.id.five: keyPressed(KeyEvent.KEYCODE_5); break;
|
||||
// case R.id.six: keyPressed(KeyEvent.KEYCODE_6); break;
|
||||
// case R.id.seven: keyPressed(KeyEvent.KEYCODE_7); break;
|
||||
// case R.id.eight: keyPressed(KeyEvent.KEYCODE_8); break;
|
||||
// case R.id.nine: keyPressed(KeyEvent.KEYCODE_9); break;
|
||||
// case R.id.zero: keyPressed(KeyEvent.KEYCODE_0); break;
|
||||
// case R.id.pound: keyPressed(KeyEvent.KEYCODE_POUND); break;
|
||||
// case R.id.star: keyPressed(KeyEvent.KEYCODE_STAR); break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onLongClick(View view) {
|
||||
// Editable digits = digitEntry.getText();
|
||||
// int id = view.getId();
|
||||
//
|
||||
// switch (id) {
|
||||
// case R.id.deleteButton: {
|
||||
// digits.clear();
|
||||
// // TODO: The framework forgets to clear the pressed
|
||||
// // status of disabled button. Until this is fixed,
|
||||
// // clear manually the pressed status. b/2133127
|
||||
// deleteButton.setPressed(false);
|
||||
// return true;
|
||||
// }
|
||||
// case R.id.zero: {
|
||||
// // Remove tentative input ('0') done by onTouch().
|
||||
// removePreviousDigitIfPossible();
|
||||
// keyPressed(KeyEvent.KEYCODE_PLUS);
|
||||
// return true;
|
||||
// }
|
||||
// case R.id.digits: {
|
||||
// digitEntry.setCursorVisible(true);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void keyPressed(int keyCode) {
|
||||
//// if (getView().getTranslationY() != 0) {
|
||||
//// return;
|
||||
//// }
|
||||
// KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
|
||||
// digitEntry.onKeyDown(keyCode, event);
|
||||
//
|
||||
// final int length = digitEntry.length();
|
||||
// if (length == digitEntry.getSelectionStart() && length == digitEntry.getSelectionEnd()) {
|
||||
// digitEntry.setCursorVisible(false);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void removePreviousDigitIfPossible() {
|
||||
// final int currentPosition = digitEntry.getSelectionStart();
|
||||
//
|
||||
// if (currentPosition > 0) {
|
||||
// digitEntry.setSelection(currentPosition);
|
||||
// digitEntry.getText().delete(currentPosition - 1, currentPosition);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// switch (view.getId()) {
|
||||
// case R.id.deleteButton:
|
||||
// keyPressed(KeyEvent.KEYCODE_DEL);
|
||||
// return;
|
||||
// case R.id.digits:
|
||||
// if (!(digitEntry.length() == 0)) {
|
||||
// digitEntry.setCursorVisible(true);
|
||||
// }
|
||||
// return;
|
||||
// case R.id.call_button:
|
||||
// String number = digitEntry.getText().toString();
|
||||
//
|
||||
// if (Util.isEmpty(number)) {
|
||||
// Toast.makeText(getActivity(),
|
||||
// getActivity().getString(R.string.DialPadActivity_you_must_dial_a_number_first),
|
||||
// Toast.LENGTH_LONG).show();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Intent intent = new Intent(getActivity(), RedPhoneService.class);
|
||||
//
|
||||
// intent.setAction(RedPhoneService.ACTION_OUTGOING_CALL);
|
||||
// intent.putExtra(Constants.REMOTE_NUMBER, number );
|
||||
// getActivity().startService(intent);
|
||||
//
|
||||
// Intent activityIntent = new Intent(getActivity(), RedPhone.class);
|
||||
// activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// startActivity(activityIntent);
|
||||
//
|
||||
// getActivity().finish();
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,218 +0,0 @@
|
||||
///*
|
||||
// * 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.ui;
|
||||
//
|
||||
//import android.content.Intent;
|
||||
//import android.content.SharedPreferences;
|
||||
//import android.os.Bundle;
|
||||
//import android.preference.PreferenceManager;
|
||||
//import android.support.v4.app.Fragment;
|
||||
//import android.support.v4.app.FragmentManager;
|
||||
//import android.support.v4.app.FragmentPagerAdapter;
|
||||
//import android.support.v4.app.FragmentTransaction;
|
||||
//import android.support.v4.view.ViewPager;
|
||||
//import android.support.v7.app.ActionBar;
|
||||
//import android.support.v7.app.AppCompatActivity;
|
||||
//import android.util.Log;
|
||||
//import android.view.Menu;
|
||||
//import android.view.MenuInflater;
|
||||
//import android.view.MenuItem;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.Constants;
|
||||
//import org.thoughtcrime.redphone.directory.DirectoryUpdateReceiver;
|
||||
//import org.thoughtcrime.redphone.gcm.GCMRegistrarHelper;
|
||||
//import org.thoughtcrime.redphone.util.PeriodicActionUtils;
|
||||
//import org.thoughtcrime.securesms.R;
|
||||
//
|
||||
///**
|
||||
// * The base dialer activity. A tab container for the contacts, call log, and favorites tab.
|
||||
// *
|
||||
// * @author Moxie Marlinspike
|
||||
// *
|
||||
// */
|
||||
//
|
||||
//public class DialerActivity extends AppCompatActivity {
|
||||
//
|
||||
// public static final int MISSED_CALL = 1;
|
||||
// public static final String CALL_LOG_ACTION = "org.thoughtcrime.redphone.ui.DialerActivity";
|
||||
//
|
||||
// private static final int CALL_LOG_TAB_INDEX = 1;
|
||||
//
|
||||
// private ViewPager viewPager;
|
||||
//
|
||||
// @Override
|
||||
// protected void onCreate(Bundle icicle) {
|
||||
// super.onCreate(icicle);
|
||||
//
|
||||
// ActionBar actionBar = this.getSupportActionBar();
|
||||
// actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
// actionBar.setDisplayShowHomeEnabled(false);
|
||||
// actionBar.setDisplayShowTitleEnabled(false);
|
||||
// actionBar.setDisplayUseLogoEnabled(false);
|
||||
//
|
||||
// checkForFreshInstall();
|
||||
// setContentView(R.layout.dialer_activity);
|
||||
//
|
||||
// setupViewPager();
|
||||
// setupTabs();
|
||||
//
|
||||
//// GCMRegistrarHelper.registerClient(this, false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNewIntent(Intent intent) {
|
||||
// setIntent(intent);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onResume() {
|
||||
// super.onResume();
|
||||
// if (getIntent().getAction() != null &&
|
||||
// getIntent().getAction().equals(CALL_LOG_ACTION))
|
||||
// {
|
||||
// getIntent().setAction(null);
|
||||
// getSupportActionBar().setSelectedNavigationItem(CALL_LOG_TAB_INDEX);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void setupViewPager() {
|
||||
// viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
// viewPager.setAdapter(new DialerPagerAdapter(getSupportFragmentManager()));
|
||||
// viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
// @Override
|
||||
// public void onPageScrolled(int i, float v, int i2) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onPageSelected(int i) {
|
||||
// getSupportActionBar().setSelectedNavigationItem(i);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onPageScrollStateChanged(int i) {
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private void setupTabs() {
|
||||
// int[] icons = new int[] { R.drawable.ic_tab_contacts, R.drawable.ic_tab_recent, R.drawable.ic_tab_favorites, R.drawable.ic_dialpad };
|
||||
//
|
||||
// for (int i = 0; i < icons.length; i++) {
|
||||
// ActionBar.Tab tab = getSupportActionBar().newTab();
|
||||
// tab.setIcon(icons[i]);
|
||||
//
|
||||
// final int tabIndex = i;
|
||||
// tab.setTabListener(new ActionBar.TabListener() {
|
||||
// @Override
|
||||
// public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
// viewPager.setCurrentItem(tabIndex);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
// }
|
||||
// });
|
||||
// getSupportActionBar().addTab(tab);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//// private void checkForFreshInstall() {
|
||||
//// SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
////
|
||||
//// if (preferences.getBoolean(Constants.VERIFYING_PREFERENCE, false)) {
|
||||
//// Log.w("DialerActivity", "Verification underway...");
|
||||
//// startActivity(new Intent(this, RegistrationProgressActivity.class));
|
||||
//// finish();
|
||||
//// }
|
||||
////
|
||||
//// if (!preferences.getBoolean(Constants.REGISTERED_PREFERENCE, false)) {
|
||||
//// Log.w("DialerActivity", "Not registered and not verifying...");
|
||||
//// startActivity(new Intent(this, CreateAccountActivity.class));
|
||||
//// finish();
|
||||
//// }
|
||||
////
|
||||
//// PeriodicActionUtils.scheduleUpdate(this, DirectoryUpdateReceiver.class);
|
||||
//// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// MenuInflater inflater = this.getSupportMenuInflater();
|
||||
// inflater.inflate(R.menu.dialer_options_menu, menu);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// switch (item.getItemId()) {
|
||||
// case R.id.resetPasswordItem: launchResetPasswordActivity(); return true;
|
||||
// case R.id.aboutItem: launchAboutActivity(); return true;
|
||||
// case R.id.settingsItem: launchPreferencesActivity(); return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
//// private void launchPreferencesActivity() {
|
||||
//// startActivity(new Intent(this, ApplicationPreferencesActivity.class));
|
||||
//// }
|
||||
////
|
||||
//// private void launchResetPasswordActivity() {
|
||||
//// startActivity(new Intent(this, CreateAccountActivity.class));
|
||||
//// finish();
|
||||
//// }
|
||||
//
|
||||
//// private void launchAboutActivity() {
|
||||
//// startActivity(new Intent(this, AboutActivity.class));
|
||||
//// }
|
||||
//
|
||||
// private static class DialerPagerAdapter extends FragmentPagerAdapter {
|
||||
//
|
||||
// public DialerPagerAdapter(FragmentManager fm) {
|
||||
// super(fm);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Fragment getItem(int i) {
|
||||
// switch (i) {
|
||||
// case 0:
|
||||
// return new ContactsListActivity();
|
||||
// case 1:
|
||||
// return new RecentCallListActivity();
|
||||
// case 2:
|
||||
// ContactsListActivity fragment = new ContactsListActivity();
|
||||
// Bundle args = new Bundle();
|
||||
// args.putBoolean("favorites", true);
|
||||
// fragment.setArguments(args);
|
||||
// return fragment;
|
||||
// case 3:
|
||||
// default:
|
||||
// return new DialPadActivity();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getCount() {
|
||||
// return 4;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
@ -28,10 +28,8 @@ import static org.thoughtcrime.redphone.util.AudioUtils.AudioMode.SPEAKER;
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
public class InCallAudioButton {
|
||||
|
||||
private static final String TAG = InCallAudioButton.class.getName();
|
||||
// private static final int HANDSET_ID = 0x10;
|
||||
// private static final int HEADSET_ID = 0x20;
|
||||
// private static final int SPEAKER_ID = 0x30;
|
||||
|
||||
private final CompoundButton mAudioButton;
|
||||
private boolean headsetAvailable;
|
||||
@ -159,52 +157,14 @@ public class InCallAudioButton {
|
||||
}
|
||||
|
||||
private void displayAudioChoiceDialog() {
|
||||
// MenuBuilder mb = new MenuBuilder(context);
|
||||
// mb.add(0, HANDSET_ID, 0, "Handset");
|
||||
// mb.add(0, HEADSET_ID, 0, "Headset");
|
||||
// mb.add(0, SPEAKER_ID, 0, "Speaker");
|
||||
// mb.setCallback(new AudioRoutingPopupListener());
|
||||
|
||||
// View attachmentView = ((View) mAudioButton.getParent()).findViewById(R.id.menuAttachment);
|
||||
Log.w(TAG, "Displaying popup...");
|
||||
PopupMenu popupMenu = new PopupMenu(context, mAudioButton);
|
||||
popupMenu.getMenuInflater().inflate(R.menu.redphone_audio_popup_menu, popupMenu.getMenu());
|
||||
popupMenu.setOnMenuItemClickListener(new AudioRoutingPopupListener());
|
||||
popupMenu.show();
|
||||
// MenuPopupHelper mph = new MenuPopupHelper(context, mb, attachmentView);
|
||||
//
|
||||
// mph.show();
|
||||
}
|
||||
|
||||
private class AudioRoutingPopupListener implements PopupMenu.OnMenuItemClickListener {
|
||||
|
||||
// @Override
|
||||
// public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
|
||||
// switch (item.getItemId()) {
|
||||
// case HANDSET_ID:
|
||||
// currentMode = DEFAULT;
|
||||
// break;
|
||||
// case HEADSET_ID:
|
||||
// currentMode = HEADSET;
|
||||
// break;
|
||||
// case SPEAKER_ID:
|
||||
// currentMode = SPEAKER;
|
||||
// break;
|
||||
// default:
|
||||
// Log.w(TAG, "Unknown item selected in audio popup menu: " + item.toString());
|
||||
// }
|
||||
// Log.d(TAG, "Selected: " + currentMode + " -- " + item.getItemId());
|
||||
//
|
||||
// listener.onAudioChange(currentMode);
|
||||
// updateView();
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onMenuModeChange(MenuBuilder menu) {
|
||||
// //To change body of implemented methods use File | Settings | File Templates.
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
@ -1,211 +0,0 @@
|
||||
///*
|
||||
// * 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.ui;
|
||||
//
|
||||
//import android.app.Activity;
|
||||
//import android.app.NotificationManager;
|
||||
//import android.content.Context;
|
||||
//import android.content.Intent;
|
||||
//import android.database.Cursor;
|
||||
//import android.graphics.drawable.Drawable;
|
||||
//import android.os.Bundle;
|
||||
//import android.provider.CallLog.Calls;
|
||||
//import android.support.v4.app.LoaderManager;
|
||||
//import android.support.v4.content.Loader;
|
||||
//import android.text.format.DateUtils;
|
||||
//import android.view.LayoutInflater;
|
||||
//import android.view.View;
|
||||
//import android.view.ViewGroup;
|
||||
//import android.widget.CursorAdapter;
|
||||
//import android.widget.ImageView;
|
||||
//import android.widget.ListView;
|
||||
//import android.widget.RelativeLayout;
|
||||
//import android.widget.TextView;
|
||||
//
|
||||
//import com.actionbarsherlock.app.SherlockListFragment;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.Constants;
|
||||
//import org.thoughtcrime.redphone.R;
|
||||
//import org.thoughtcrime.redphone.RedPhone;
|
||||
//import org.thoughtcrime.redphone.RedPhoneService;
|
||||
//import org.thoughtcrime.redphone.contacts.ContactAccessor;
|
||||
//import org.thoughtcrime.redphone.contacts.RegisteredUserCursorLoader;
|
||||
//import org.thoughtcrime.redphone.util.BitmapUtil;
|
||||
//import org.thoughtcrime.redphone.util.Util;
|
||||
//
|
||||
///**
|
||||
// * A tab for the dialer activity which displays recent call history.
|
||||
// *
|
||||
// * @author Moxie Marlinspike
|
||||
// *
|
||||
// */
|
||||
//public class RecentCallListActivity extends SherlockListFragment
|
||||
// implements LoaderManager.LoaderCallbacks<Cursor>
|
||||
//{
|
||||
//
|
||||
// @Override
|
||||
// public void onActivityCreated(Bundle icicle) {
|
||||
// super.onCreate(icicle);
|
||||
// displayCalls();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// return inflater.inflate(R.layout.recent_calls, container, false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onResume() {
|
||||
// super.onResume();
|
||||
// NotificationManager notificationManager =
|
||||
// (NotificationManager)getActivity().getSystemService(Activity.NOTIFICATION_SERVICE);
|
||||
// notificationManager.cancel(DialerActivity.MISSED_CALL);
|
||||
// }
|
||||
//
|
||||
// private void displayCalls() {
|
||||
// setListAdapter(new CallListAdapter(getActivity(), null));
|
||||
// this.getLoaderManager().initLoader(0, null, this);
|
||||
// }
|
||||
//
|
||||
// private class CallListAdapter extends CursorAdapter {
|
||||
//
|
||||
// public CallListAdapter(Context context, Cursor c) {
|
||||
// super(context, c, false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
// CallItemView view = new CallItemView(context);
|
||||
// bindView(view, context, cursor);
|
||||
//
|
||||
// return view;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void bindView(View view, Context context, Cursor cursor) {
|
||||
// String name = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NAME));
|
||||
// String number = cursor.getString(cursor.getColumnIndexOrThrow(Calls.NUMBER));
|
||||
// int type = cursor.getInt(cursor.getColumnIndexOrThrow(Calls.TYPE));
|
||||
// long date = cursor.getLong(cursor.getColumnIndexOrThrow(Calls.DATE));
|
||||
//
|
||||
// ((CallItemView)view).set(name, number, type, date);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class CallItemView extends RelativeLayout {
|
||||
// private Context context;
|
||||
// private ImageView avatar;
|
||||
// private ImageView callTypeIcon;
|
||||
// private TextView date;
|
||||
// private TextView name;
|
||||
//// private TextView label;
|
||||
// private TextView number;
|
||||
//// private TextView line1;
|
||||
//
|
||||
// private Drawable incomingCallIcon;
|
||||
// private Drawable outgoingCallIcon;
|
||||
// private Drawable missedCallIcon;
|
||||
//
|
||||
// public CallItemView(Context context) {
|
||||
// super(context.getApplicationContext());
|
||||
//
|
||||
// LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
// li.inflate(R.layout.recent_call_item, this, true);
|
||||
//
|
||||
// this.context = context.getApplicationContext();
|
||||
// this.callTypeIcon = (ImageView) findViewById(R.id.call_type_icon);
|
||||
// this.date = (TextView) findViewById(R.id.date);
|
||||
// this.avatar = (ImageView) findViewById(R.id.contact_photo_image);
|
||||
// this.number = (TextView) findViewById(R.id.number);
|
||||
// this.name = (TextView) findViewById(R.id.name);
|
||||
// this.incomingCallIcon = getResources().getDrawable(R.drawable.ic_call_log_list_incoming_call);
|
||||
// this.outgoingCallIcon = getResources().getDrawable(R.drawable.ic_call_log_list_outgoing_call);
|
||||
// this.missedCallIcon = getResources().getDrawable(R.drawable.ic_call_log_list_missed_call);
|
||||
// }
|
||||
//
|
||||
// public void set(String name, String number, int type, long date) {
|
||||
// this.name.setText(Util.isEmpty(name) ? number : name);
|
||||
// this.number.setText(Util.isEmpty(name) ? "" : number);
|
||||
// this.date.setText(DateUtils.getRelativeDateTimeString(context, date,
|
||||
// System.currentTimeMillis(),
|
||||
// DateUtils.MINUTE_IN_MILLIS,
|
||||
// DateUtils.FORMAT_ABBREV_RELATIVE));
|
||||
//
|
||||
// this.avatar.setImageBitmap(BitmapUtil.getCircleCroppedBitmap(ContactAccessor.getInstance().getDefaultContactPhoto(context)));
|
||||
//
|
||||
// if (type == Calls.INCOMING_TYPE) {
|
||||
// callTypeIcon.setImageDrawable(incomingCallIcon);
|
||||
// } else if (type == Calls.OUTGOING_TYPE) {
|
||||
// callTypeIcon.setImageDrawable(outgoingCallIcon);
|
||||
// } else if (type == Calls.MISSED_TYPE) {
|
||||
// callTypeIcon.setImageDrawable(missedCallIcon);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public String getNumber() {
|
||||
// if (this.number.getText().toString().equals(""))
|
||||
// return this.name.getText().toString();
|
||||
//
|
||||
// return this.number.getText().toString();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
// Intent intent = new Intent(getActivity(), RedPhoneService.class);
|
||||
// intent.setAction(RedPhoneService.ACTION_OUTGOING_CALL);
|
||||
// intent.putExtra(Constants.REMOTE_NUMBER, ((CallItemView)v).getNumber());
|
||||
// getActivity().startService(intent);
|
||||
//
|
||||
// Intent activityIntent = new Intent(getActivity(), RedPhone.class);
|
||||
// activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// startActivity(activityIntent);
|
||||
//
|
||||
// getActivity().finish();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
// // NOTE: To fix a weird bug:
|
||||
// // http://stackoverflow.com/questions/11810547/runtimeexception-at-calllog-calls
|
||||
// String[] projection = {
|
||||
// Calls._ID,
|
||||
// Calls.CACHED_NAME,
|
||||
// Calls.CACHED_NUMBER_LABEL,
|
||||
// Calls.NUMBER,
|
||||
// Calls.TYPE,
|
||||
// Calls.DATE
|
||||
// };
|
||||
//
|
||||
// ((TextView)getListView().getEmptyView()).setText(R.string.RecentCallListActivity_loading);
|
||||
// return new RegisteredUserCursorLoader(getActivity(), Calls.CONTENT_URI, projection, null,
|
||||
// Calls.DEFAULT_SORT_ORDER, Calls.NUMBER, false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
||||
// ((TextView)getListView().getEmptyView()).setText(R.string.RecentCallListActivity_empty_call_log);
|
||||
// ((CursorAdapter)getListAdapter()).changeCursor(cursor);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onLoaderReset(Loader<Cursor> arg0) {
|
||||
// ((CursorAdapter)getListAdapter()).changeCursor(null);
|
||||
// }
|
||||
//
|
||||
//}
|
@ -1,45 +0,0 @@
|
||||
///*
|
||||
// * 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.ui;
|
||||
//
|
||||
//import android.os.Bundle;
|
||||
//import android.support.v4.app.FragmentActivity;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.Constants;
|
||||
//
|
||||
///**
|
||||
// * A lightweight dialog for prompting the user to upgrade their outgoing call.
|
||||
// *
|
||||
// * @author Moxie Marlinspike
|
||||
// *
|
||||
// */
|
||||
//public class RedPhoneChooser extends FragmentActivity {
|
||||
//
|
||||
// @Override
|
||||
// public void onCreate(Bundle bundle) {
|
||||
// super.onCreate(bundle);
|
||||
//
|
||||
// initializeResources();
|
||||
// }
|
||||
//
|
||||
// private void initializeResources() {
|
||||
//
|
||||
// UpgradeCallDialogFragment dialogFragment = new UpgradeCallDialogFragment(getIntent().getStringExtra(Constants.REMOTE_NUMBER));
|
||||
// dialogFragment.show(getSupportFragmentManager(), "upgrade");
|
||||
// }
|
||||
//}
|
@ -1,25 +0,0 @@
|
||||
//package org.thoughtcrime.redphone.ui;
|
||||
//
|
||||
//import android.app.Activity;
|
||||
//import android.os.Bundle;
|
||||
//import android.view.View;
|
||||
//import android.widget.Button;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.R;
|
||||
//
|
||||
//public class RegistrationProblemsActivity extends Activity {
|
||||
//
|
||||
// @Override
|
||||
// public void onCreate(Bundle bundle) {
|
||||
// super.onCreate(bundle);
|
||||
// setContentView(R.layout.registration_problems);
|
||||
// setTitle(getString(R.string.RegistrationProblemsActivity_possible_problems));
|
||||
//
|
||||
// ((Button)findViewById(R.id.close_button)).setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// finish();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//}
|
@ -1,536 +0,0 @@
|
||||
//package org.thoughtcrime.redphone.ui;
|
||||
//
|
||||
//import android.app.ProgressDialog;
|
||||
//import android.content.BroadcastReceiver;
|
||||
//import android.content.ComponentName;
|
||||
//import android.content.Context;
|
||||
//import android.content.Intent;
|
||||
//import android.content.IntentFilter;
|
||||
//import android.content.ServiceConnection;
|
||||
//import android.graphics.Color;
|
||||
//import android.os.AsyncTask;
|
||||
//import android.os.Bundle;
|
||||
//import android.os.Handler;
|
||||
//import android.os.IBinder;
|
||||
//import android.os.Message;
|
||||
//import android.text.SpannableString;
|
||||
//import android.text.Spanned;
|
||||
//import android.text.method.LinkMovementMethod;
|
||||
//import android.text.style.ClickableSpan;
|
||||
//import android.util.Log;
|
||||
//import android.view.View;
|
||||
//import android.widget.Button;
|
||||
//import android.widget.EditText;
|
||||
//import android.widget.ImageView;
|
||||
//import android.widget.LinearLayout;
|
||||
//import android.widget.ProgressBar;
|
||||
//import android.widget.TextView;
|
||||
//import android.widget.Toast;
|
||||
//
|
||||
//import com.actionbarsherlock.app.SherlockActivity;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.R;
|
||||
//import org.thoughtcrime.redphone.registration.RegistrationService;
|
||||
//import org.thoughtcrime.redphone.registration.RegistrationService.RegistrationState;
|
||||
//import org.thoughtcrime.redphone.signaling.AccountCreationException;
|
||||
//import org.thoughtcrime.redphone.signaling.AccountCreationSocket;
|
||||
//import org.thoughtcrime.redphone.signaling.RateLimitExceededException;
|
||||
//import org.thoughtcrime.redphone.signaling.SignalingException;
|
||||
//import org.thoughtcrime.redphone.util.PhoneNumberFormatter;
|
||||
//import org.thoughtcrime.redphone.util.Util;
|
||||
//
|
||||
//public class RegistrationProgressActivity extends SherlockActivity {
|
||||
//
|
||||
// private static final int FOCUSED_COLOR = Color.parseColor("#ff333333");
|
||||
// private static final int UNFOCUSED_COLOR = Color.parseColor("#ff808080");
|
||||
//
|
||||
// private ServiceConnection serviceConnection = new RegistrationServiceConnection();
|
||||
// private Handler registrationStateHandler = new RegistrationStateHandler();
|
||||
// private RegistrationReceiver registrationReceiver = new RegistrationReceiver();
|
||||
//
|
||||
// private RegistrationService registrationService;
|
||||
//
|
||||
// private LinearLayout registrationLayout;
|
||||
// private LinearLayout verificationFailureLayout;
|
||||
// private LinearLayout connectivityFailureLayout;
|
||||
//
|
||||
// private ProgressBar registrationProgress;
|
||||
// private ProgressBar connectingProgress;
|
||||
// private ProgressBar verificationProgress;
|
||||
// private ImageView connectingCheck;
|
||||
// private ImageView verificationCheck;
|
||||
// private TextView connectingText;
|
||||
// private TextView verificationText;
|
||||
// private TextView registrationTimerText;
|
||||
// private EditText codeEditText;
|
||||
// private Button editButton;
|
||||
// private Button verificationFailureButton;
|
||||
// private Button connectivityFailureButton;
|
||||
// private Button callButton;
|
||||
// private Button verifyButton;
|
||||
//
|
||||
// private volatile boolean visible;
|
||||
//
|
||||
// @Override
|
||||
// public void onCreate(Bundle bundle) {
|
||||
// super.onCreate(bundle);
|
||||
// this.getSupportActionBar().setTitle(R.string.RegistrationProgressActivity_verifying_number);
|
||||
// setContentView(R.layout.registration_progress);
|
||||
//
|
||||
// initializeResources();
|
||||
// initializeLinks();
|
||||
// initializeServiceBinding();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onDestroy() {
|
||||
// super.onDestroy();
|
||||
// shutdownServiceBinding();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onResume() {
|
||||
// super.onResume();
|
||||
// handleActivityVisible();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onPause() {
|
||||
// super.onPause();
|
||||
// handleActivityNotVisible();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onBackPressed() {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void initializeServiceBinding() {
|
||||
// Intent intent = new Intent(this, RegistrationService.class);
|
||||
// bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
// }
|
||||
//
|
||||
// private void initializeResources() {
|
||||
// this.registrationLayout = (LinearLayout)findViewById(R.id.registering_layout);
|
||||
// this.verificationFailureLayout = (LinearLayout)findViewById(R.id.verification_failure_layout);
|
||||
// this.connectivityFailureLayout = (LinearLayout)findViewById(R.id.connectivity_failure_layout);
|
||||
// this.registrationProgress = (ProgressBar) findViewById(R.id.registration_progress);
|
||||
// this.connectingProgress = (ProgressBar) findViewById(R.id.connecting_progress);
|
||||
// this.verificationProgress = (ProgressBar) findViewById(R.id.verification_progress);
|
||||
// this.connectingCheck = (ImageView) findViewById(R.id.connecting_complete);
|
||||
// this.verificationCheck = (ImageView) findViewById(R.id.verification_complete);
|
||||
// this.connectingText = (TextView) findViewById(R.id.connecting_text);
|
||||
// this.verificationText = (TextView) findViewById(R.id.verification_text);
|
||||
// this.registrationTimerText = (TextView) findViewById(R.id.registration_timer);
|
||||
// this.codeEditText = (EditText) findViewById(R.id.telephone_code);
|
||||
// this.editButton = (Button) findViewById(R.id.edit_button);
|
||||
// this.verificationFailureButton = (Button) findViewById(R.id.verification_failure_edit_button);
|
||||
// this.connectivityFailureButton = (Button) findViewById(R.id.connectivity_failure_edit_button);
|
||||
// this.callButton = (Button) findViewById(R.id.call_button);
|
||||
// this.verifyButton = (Button) findViewById(R.id.verify_button);
|
||||
//
|
||||
// this.editButton.setOnClickListener(new EditButtonListener());
|
||||
// this.verificationFailureButton.setOnClickListener(new EditButtonListener());
|
||||
// this.connectivityFailureButton.setOnClickListener(new EditButtonListener());
|
||||
// }
|
||||
//
|
||||
// private void initializeLinks() {
|
||||
// TextView failureText = (TextView) findViewById(R.id.sms_failed_text);
|
||||
// String pretext = getString(R.string.registration_progress__redphone_timed_out_while_waiting_for_an_sms_message_to_verify_your_phone_number);
|
||||
// String link = getString(R.string.RegistrationProgressActivity_possible_problems);
|
||||
// SpannableString spannableString = new SpannableString(pretext + " " + link);
|
||||
//
|
||||
// spannableString.setSpan(new ClickableSpan() {
|
||||
// @Override
|
||||
// public void onClick(View widget) {
|
||||
// Intent intent = new Intent(RegistrationProgressActivity.this,
|
||||
// RegistrationProblemsActivity.class);
|
||||
// startActivity(intent);
|
||||
// }
|
||||
// }, pretext.length() + 1, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
//
|
||||
// failureText.setText(spannableString);
|
||||
// failureText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
// }
|
||||
//
|
||||
// private void handleActivityVisible() {
|
||||
// IntentFilter filter = new IntentFilter(RegistrationService.REGISTRATION_EVENT);
|
||||
// filter.setPriority(1000);
|
||||
// registerReceiver(registrationReceiver, filter);
|
||||
// visible = true;
|
||||
// }
|
||||
//
|
||||
// private void handleActivityNotVisible() {
|
||||
// unregisterReceiver(registrationReceiver);
|
||||
// visible = false;
|
||||
// }
|
||||
//
|
||||
// private void handleStateIdle() {
|
||||
// if (hasNumberDirective()) {
|
||||
// Intent intent = new Intent(this, RegistrationService.class);
|
||||
// intent.setAction(RegistrationService.REGISTER_NUMBER_ACTION);
|
||||
// intent.putExtra("e164number", getNumberDirective());
|
||||
// startService(intent);
|
||||
// } else {
|
||||
// startActivity(new Intent(this, CreateAccountActivity.class));
|
||||
// finish();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void handleStateConnecting() {
|
||||
// this.registrationLayout.setVisibility(View.VISIBLE);
|
||||
// this.verificationFailureLayout.setVisibility(View.GONE);
|
||||
// this.connectivityFailureLayout.setVisibility(View.GONE);
|
||||
// this.connectingProgress.setVisibility(View.VISIBLE);
|
||||
// this.connectingCheck.setVisibility(View.INVISIBLE);
|
||||
// this.verificationProgress.setVisibility(View.INVISIBLE);
|
||||
// this.verificationCheck.setVisibility(View.INVISIBLE);
|
||||
// this.connectingText.setTextColor(FOCUSED_COLOR);
|
||||
// this.verificationText.setTextColor(UNFOCUSED_COLOR);
|
||||
// }
|
||||
//
|
||||
// private void handleStateVerifyingSms() {
|
||||
// this.verificationText.setText(getString(R.string.registration_progress__waiting_for_sms_verification));
|
||||
// handleStateVerifying();
|
||||
// }
|
||||
//
|
||||
// private void handleStateVerifyingVoice() {
|
||||
// this.verificationText.setText(getString(R.string.RegistrationProgressActivity_verifying_voice_code));
|
||||
// handleStateVerifying();
|
||||
// }
|
||||
//
|
||||
// private void handleStateVerifying() {
|
||||
// this.registrationLayout.setVisibility(View.VISIBLE);
|
||||
// this.verificationFailureLayout.setVisibility(View.GONE);
|
||||
// this.connectivityFailureLayout.setVisibility(View.GONE);
|
||||
// this.connectingProgress.setVisibility(View.INVISIBLE);
|
||||
// this.connectingCheck.setVisibility(View.VISIBLE);
|
||||
// this.verificationProgress.setVisibility(View.VISIBLE);
|
||||
// this.verificationCheck.setVisibility(View.INVISIBLE);
|
||||
// this.connectingText.setTextColor(UNFOCUSED_COLOR);
|
||||
// this.verificationText.setTextColor(FOCUSED_COLOR);
|
||||
// }
|
||||
//
|
||||
// private void handleVerificationRequestedVoice(RegistrationState state) {
|
||||
// handleVerificationTimeout(state);
|
||||
// verifyButton.setOnClickListener(new VerifyClickListener(state.number, state.password));
|
||||
// verifyButton.setEnabled(true);
|
||||
// codeEditText.setEnabled(true);
|
||||
// }
|
||||
//
|
||||
// private void handleVerificationTimeout(RegistrationState state) {
|
||||
// this.callButton.setOnClickListener(new CallClickListener(state.number));
|
||||
// this.verifyButton.setEnabled(false);
|
||||
// this.codeEditText.setEnabled(false);
|
||||
// this.registrationLayout.setVisibility(View.GONE);
|
||||
// this.connectivityFailureLayout.setVisibility(View.GONE);
|
||||
// this.verificationFailureLayout.setVisibility(View.VISIBLE);
|
||||
// this.verificationFailureButton.setText(String.format(getString(R.string.RegistrationProgressActivity_edit_s),
|
||||
// PhoneNumberFormatter.formatNumberInternational(state.number)));
|
||||
// }
|
||||
//
|
||||
// private void handleConnectivityError(RegistrationState state) {
|
||||
// this.registrationLayout.setVisibility(View.GONE);
|
||||
// this.verificationFailureLayout.setVisibility(View.GONE);
|
||||
// this.connectivityFailureLayout.setVisibility(View.VISIBLE);
|
||||
// this.connectivityFailureButton.setText(String.format(getString(R.string.RegistrationProgressActivity_edit_s),
|
||||
// PhoneNumberFormatter.formatNumberInternational(state.number)));
|
||||
// }
|
||||
//
|
||||
// private void handleVerificationComplete() {
|
||||
// if (visible) {
|
||||
// Toast.makeText(this, R.string.RegistrationProgressActivity_registration_complete, Toast.LENGTH_LONG).show();
|
||||
// }
|
||||
//
|
||||
// shutdownService();
|
||||
// startActivity(new Intent(this, DialerActivity.class));
|
||||
// finish();
|
||||
// }
|
||||
//
|
||||
// private void handleTimerUpdate() {
|
||||
// if (registrationService == null)
|
||||
// return;
|
||||
//
|
||||
// int totalSecondsRemaining = registrationService.getSecondsRemaining();
|
||||
// int minutesRemaining = totalSecondsRemaining / 60;
|
||||
// int secondsRemaining = totalSecondsRemaining - (minutesRemaining * 60);
|
||||
// double percentageComplete = (double)((60 * 2) - totalSecondsRemaining) / (double)(60 * 2);
|
||||
// int progress = (int) Math.round(((double) registrationProgress.getMax()) * percentageComplete);
|
||||
//
|
||||
// this.registrationProgress.setProgress(progress);
|
||||
// this.registrationTimerText.setText(String.format("%02d:%02d", minutesRemaining, secondsRemaining));
|
||||
//
|
||||
// registrationStateHandler.sendEmptyMessageDelayed(RegistrationState.STATE_TIMER, 1000);
|
||||
// }
|
||||
//
|
||||
// private boolean hasNumberDirective() {
|
||||
// return getIntent().getStringExtra("e164number") != null;
|
||||
// }
|
||||
//
|
||||
// private String getNumberDirective() {
|
||||
// return getIntent().getStringExtra("e164number");
|
||||
// }
|
||||
//
|
||||
// private void shutdownServiceBinding() {
|
||||
// if (serviceConnection != null) {
|
||||
// unbindService(serviceConnection);
|
||||
// serviceConnection = null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void shutdownService() {
|
||||
// if (registrationService != null) {
|
||||
// registrationService.shutdown();
|
||||
// registrationService = null;
|
||||
// }
|
||||
//
|
||||
// shutdownServiceBinding();
|
||||
//
|
||||
// Intent serviceIntent = new Intent(RegistrationProgressActivity.this, RegistrationService.class);
|
||||
// stopService(serviceIntent);
|
||||
// }
|
||||
//
|
||||
// private class RegistrationServiceConnection implements ServiceConnection {
|
||||
// @Override
|
||||
// public void onServiceConnected(ComponentName className, IBinder service) {
|
||||
// registrationService = ((RegistrationService.RegistrationServiceBinder)service).getService();
|
||||
// registrationService.setRegistrationStateHandler(registrationStateHandler);
|
||||
//
|
||||
// RegistrationState state = registrationService.getRegistrationState();
|
||||
// registrationStateHandler.obtainMessage(state.state, state).sendToTarget();
|
||||
//
|
||||
// handleTimerUpdate();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onServiceDisconnected(ComponentName name) {
|
||||
// registrationService.setRegistrationStateHandler(null);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class RegistrationStateHandler extends Handler {
|
||||
// @Override
|
||||
// public void handleMessage(Message message) {
|
||||
// RegistrationState state = (RegistrationState)message.obj;
|
||||
//
|
||||
// switch (message.what) {
|
||||
// case RegistrationState.STATE_IDLE: handleStateIdle(); break;
|
||||
// case RegistrationState.STATE_CONNECTING: handleStateConnecting(); break;
|
||||
// case RegistrationState.STATE_VERIFYING_SMS: handleStateVerifyingSms(); break;
|
||||
// case RegistrationState.STATE_VERIFYING_VOICE: handleStateVerifyingVoice(); break;
|
||||
// case RegistrationState.STATE_TIMER: handleTimerUpdate(); break;
|
||||
// case RegistrationState.STATE_TIMEOUT: handleVerificationTimeout(state); break;
|
||||
// case RegistrationState.STATE_COMPLETE: handleVerificationComplete(); break;
|
||||
// case RegistrationState.STATE_NETWORK_ERROR: handleConnectivityError(state); break;
|
||||
// case RegistrationState.STATE_VOICE_REQUESTED: handleVerificationRequestedVoice(state); break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class EditButtonListener implements View.OnClickListener {
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// shutdownService();
|
||||
//
|
||||
// Intent activityIntent = new Intent(RegistrationProgressActivity.this, CreateAccountActivity.class);
|
||||
// startActivity(activityIntent);
|
||||
// finish();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class RegistrationReceiver extends BroadcastReceiver {
|
||||
// @Override
|
||||
// public void onReceive(Context context, Intent intent) {
|
||||
// abortBroadcast();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private class VerifyClickListener implements View.OnClickListener {
|
||||
// private static final int SUCCESS = 0;
|
||||
// private static final int NETWORK_ERROR = 1;
|
||||
// private static final int RATE_LIMIT_ERROR = 2;
|
||||
// private static final int VERIFICATION_ERROR = 3;
|
||||
//
|
||||
// private final String e164number;
|
||||
// private final String password;
|
||||
// private final String key;
|
||||
// private final Context context;
|
||||
//
|
||||
// private ProgressDialog progressDialog;
|
||||
//
|
||||
// public VerifyClickListener(String e164number, String password) {
|
||||
// this.e164number = e164number;
|
||||
// this.password = password;
|
||||
// this.context = RegistrationProgressActivity.this;
|
||||
// this.key = Util.getSecret(40);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// final String code = codeEditText.getText().toString();
|
||||
//
|
||||
// if (Util.isEmpty(code)) {
|
||||
// Toast.makeText(context,
|
||||
// getString(R.string.RegistrationProgressActivity_you_must_enter_the_code_you_received_first),
|
||||
// Toast.LENGTH_LONG).show();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// new AsyncTask<Void, Void, Integer>() {
|
||||
//
|
||||
// @Override
|
||||
// protected void onPreExecute() {
|
||||
// progressDialog = ProgressDialog.show(context,
|
||||
// getString(R.string.RegistrationProgressActivity_connecting),
|
||||
// getString(R.string.RegistrationProgressActivity_connecting_for_verification),
|
||||
// true, false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPostExecute(Integer result) {
|
||||
// if (progressDialog != null) progressDialog.dismiss();
|
||||
//
|
||||
// switch (result) {
|
||||
// case SUCCESS:
|
||||
// Intent intent = new Intent(context, RegistrationService.class);
|
||||
// intent.setAction(RegistrationService.VOICE_REGISTER_NUMBER_ACTION);
|
||||
// intent.putExtra("e164number", e164number);
|
||||
// intent.putExtra("password", password);
|
||||
// intent.putExtra("key", key);
|
||||
// startService(intent);
|
||||
// break;
|
||||
// case NETWORK_ERROR:
|
||||
// Util.showAlertDialog(context, getString(R.string.RegistrationProgressActivity_network_error),
|
||||
// getString(R.string.RegistrationProgressActivity_unable_to_connect));
|
||||
// break;
|
||||
// case VERIFICATION_ERROR:
|
||||
// Util.showAlertDialog(context, getString(R.string.RegistrationProgressActivity_verification_failed),
|
||||
// getString(R.string.RegistrationProgressActivity_the_verification_code_you_submitted_is_incorrect));
|
||||
// break;
|
||||
// case RATE_LIMIT_ERROR:
|
||||
// Util.showAlertDialog(context, getString(R.string.RegistrationProgressActivity_too_many_attempts),
|
||||
// getString(R.string.RegistrationProgressActivity_youve_submitted_an_incorrect_verification_code_too_many_times));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Integer doInBackground(Void... params) {
|
||||
// AccountCreationSocket socket = null;
|
||||
//
|
||||
// try {
|
||||
// socket = new AccountCreationSocket(context, e164number, password);
|
||||
// socket.verifyAccount(code, key);
|
||||
// return SUCCESS;
|
||||
// } catch (SignalingException e) {
|
||||
// Log.w("RegistrationProgressActivity", e);
|
||||
// return NETWORK_ERROR;
|
||||
// } catch (AccountCreationException e) {
|
||||
// Log.w("RegistrationProgressActivity", e);
|
||||
// return VERIFICATION_ERROR;
|
||||
// } catch (RateLimitExceededException e) {
|
||||
// Log.w("RegistrationProgressActivity", e);
|
||||
// return RATE_LIMIT_ERROR;
|
||||
// } finally {
|
||||
// if (socket != null)
|
||||
// socket.close();
|
||||
// }
|
||||
// }
|
||||
// }.execute();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private class CallClickListener implements View.OnClickListener {
|
||||
//
|
||||
// private static final int SUCCESS = 0;
|
||||
// private static final int NETWORK_ERROR = 1;
|
||||
// private static final int RATE_LIMIT_EXCEEDED = 2;
|
||||
// private static final int CREATE_ERROR = 3;
|
||||
//
|
||||
// private final String e164number;
|
||||
// private final String password;
|
||||
// private final Context context;
|
||||
//
|
||||
// public CallClickListener(String e164number) {
|
||||
// this.e164number = e164number;
|
||||
// this.password = Util.getSecret(18);
|
||||
// this.context = RegistrationProgressActivity.this;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// new AsyncTask<Void, Void, Integer>() {
|
||||
// private ProgressDialog progressDialog;
|
||||
//
|
||||
// @Override
|
||||
// protected void onPreExecute() {
|
||||
// progressDialog = ProgressDialog.show(context, getString(R.string.RegistrationProgressActivity_requesting_call),
|
||||
// getString(R.string.RegistrationProgressActivity_requesting_incoming_call),
|
||||
// true, false);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPostExecute(Integer result) {
|
||||
// if (progressDialog != null) progressDialog.dismiss();
|
||||
//
|
||||
// switch (result) {
|
||||
// case SUCCESS:
|
||||
// Intent intent = new Intent(context, RegistrationService.class);
|
||||
// intent.setAction(RegistrationService.VOICE_REQUESTED_ACTION);
|
||||
// intent.putExtra("e164number", e164number);
|
||||
// intent.putExtra("password", password);
|
||||
// startService(intent);
|
||||
//
|
||||
// callButton.setEnabled(false);
|
||||
// new Handler().postDelayed(new Runnable(){
|
||||
// @Override
|
||||
// public void run() {
|
||||
// callButton.setEnabled(true);
|
||||
// }
|
||||
// }, 15000);
|
||||
// break;
|
||||
// case NETWORK_ERROR:
|
||||
// Util.showAlertDialog(context,
|
||||
// getString(R.string.RegistrationProgressActivity_network_error),
|
||||
// getString(R.string.RegistrationProgressActivity_unable_to_connect));
|
||||
// break;
|
||||
// case CREATE_ERROR:
|
||||
// Util.showAlertDialog(context,
|
||||
// getString(R.string.RegistrationProgressActivity_server_error),
|
||||
// getString(R.string.RegistrationProgressActivity_the_server_encountered_an_error));
|
||||
// break;
|
||||
// case RATE_LIMIT_EXCEEDED:
|
||||
// Util.showAlertDialog(context,
|
||||
// getString(R.string.RegistrationProgressActivity_too_many_requests),
|
||||
// getString(R.string.RegistrationProgressActivity_youve_already_requested_a_voice_call));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Integer doInBackground(Void... params) {
|
||||
// AccountCreationSocket socket = null;
|
||||
//
|
||||
// try {
|
||||
// socket = new AccountCreationSocket(context, e164number, password);
|
||||
// socket.createAccount(true);
|
||||
// return SUCCESS;
|
||||
// } catch (SignalingException se) {
|
||||
// Log.w("RegistrationProgressActivity", se);
|
||||
// return NETWORK_ERROR;
|
||||
// } catch (AccountCreationException e) {
|
||||
// Log.w("RegistrationProgressActivity", e);
|
||||
// return CREATE_ERROR;
|
||||
// } catch (RateLimitExceededException e) {
|
||||
// Log.w("RegistrationProgressActivity", e);
|
||||
// return RATE_LIMIT_EXCEEDED;
|
||||
// } finally {
|
||||
// if (socket != null)
|
||||
// socket.close();
|
||||
// }
|
||||
// }
|
||||
// }.execute();
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,38 +0,0 @@
|
||||
//package org.thoughtcrime.redphone.ui;
|
||||
//
|
||||
//import android.content.Context;
|
||||
//import android.util.AttributeSet;
|
||||
//import android.view.View;
|
||||
//
|
||||
//import com.actionbarsherlock.internal.view.View_HasStateListenerSupport;
|
||||
//import com.actionbarsherlock.internal.view.View_OnAttachStateChangeListener;
|
||||
//
|
||||
///**
|
||||
// * The ABS MenuPopupHelper will only attach to a view that implements View_HasStateListenerSupport.
|
||||
// *
|
||||
// * This view can be included in layouts to provide attachment points for PopupMenus. We use it in
|
||||
// * the InCallAudioButton to provide an attachment point for the audio routing selection popup.
|
||||
// *
|
||||
// * @author Stuart O. Anderson
|
||||
//*/
|
||||
//public class StateListenerView extends View implements View_HasStateListenerSupport {
|
||||
// public StateListenerView(Context context) {
|
||||
// super(context);
|
||||
// }
|
||||
//
|
||||
// public StateListenerView(Context context, AttributeSet attrs) {
|
||||
// super(context, attrs);
|
||||
// }
|
||||
//
|
||||
// public StateListenerView(Context context, AttributeSet attrs, int defStyle) {
|
||||
// super(context, attrs, defStyle);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void addOnAttachStateChangeListener(View_OnAttachStateChangeListener listener) {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void removeOnAttachStateChangeListener(View_OnAttachStateChangeListener listener) {
|
||||
// }
|
||||
//}
|
@ -1,126 +0,0 @@
|
||||
///*
|
||||
// * Copyright (C) 2013 Open 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.ui;
|
||||
//
|
||||
//import android.app.AlertDialog;
|
||||
//import android.app.Dialog;
|
||||
//import android.content.DialogInterface;
|
||||
//import android.content.Intent;
|
||||
//import android.net.Uri;
|
||||
//import android.os.Build;
|
||||
//import android.os.Bundle;
|
||||
//import android.support.v4.app.DialogFragment;
|
||||
//import android.text.SpannableStringBuilder;
|
||||
//import android.text.Spanned;
|
||||
//import android.text.style.AbsoluteSizeSpan;
|
||||
//import android.view.ContextThemeWrapper;
|
||||
//import android.widget.Button;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.Constants;
|
||||
//import org.thoughtcrime.redphone.R;
|
||||
//import org.thoughtcrime.redphone.RedPhone;
|
||||
//import org.thoughtcrime.redphone.RedPhoneService;
|
||||
//import org.thoughtcrime.redphone.call.CallChooserCache;
|
||||
//import org.thoughtcrime.redphone.call.CallListener;
|
||||
//
|
||||
//
|
||||
//public class UpgradeCallDialogFragment extends DialogFragment {
|
||||
//
|
||||
// private final String number;
|
||||
// public UpgradeCallDialogFragment(final String number) {
|
||||
// this.number = number;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
//
|
||||
// final AlertDialog.Builder builder;
|
||||
// if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
|
||||
// builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.RedPhone_Light_Dialog));
|
||||
// } else {
|
||||
// builder = new AlertDialog.Builder(getActivity(), R.style.RedPhone_Light_Dialog);
|
||||
// }
|
||||
//
|
||||
// builder.setIcon(R.drawable.red_call);
|
||||
//
|
||||
// final String upgradeString = getActivity().getResources().getString(R.string.RedPhoneChooser_upgrade_to_redphone);
|
||||
// SpannableStringBuilder titleBuilder = new SpannableStringBuilder(upgradeString);
|
||||
// titleBuilder.setSpan(new AbsoluteSizeSpan(20, true), 0, upgradeString.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
// builder.setTitle(titleBuilder);
|
||||
//
|
||||
// //builder.setMessage(R.string.RedPhoneChooser_this_contact_also_uses_redphone_would_you_like_to_upgrade_to_a_secure_call);
|
||||
//
|
||||
// builder.setPositiveButton(R.string.RedPhoneChooser_secure_call, new DialogInterface.OnClickListener() {
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// Intent intent = new Intent(getActivity(), RedPhoneService.class);
|
||||
// intent.setAction(RedPhoneService.ACTION_OUTGOING_CALL);
|
||||
// intent.putExtra(Constants.REMOTE_NUMBER, number);
|
||||
// getActivity().startService(intent);
|
||||
//
|
||||
// Intent activityIntent = new Intent();
|
||||
// activityIntent.setClass(getActivity(), RedPhone.class);
|
||||
// activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// startActivity(activityIntent);
|
||||
//
|
||||
// getActivity().finish();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// builder.setNegativeButton(R.string.RedPhoneChooser_insecure_call, new DialogInterface.OnClickListener() {
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// CallChooserCache.getInstance().addInsecureChoice(number);
|
||||
//
|
||||
// Intent intent = new Intent("android.intent.action.CALL",
|
||||
// Uri.fromParts("tel", number + CallListener.IGNORE_SUFFIX,
|
||||
// null));
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// startActivity(intent);
|
||||
// getActivity().finish();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// AlertDialog alert = builder.create();
|
||||
//
|
||||
// alert.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
// @Override
|
||||
// public void onShow(DialogInterface dialog) {
|
||||
// ((AlertDialog) dialog).setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
// @Override
|
||||
// public void onCancel(DialogInterface dialogInterface) {
|
||||
// getActivity().finish();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// ((AlertDialog) dialog).setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
// @Override
|
||||
// public void onDismiss(DialogInterface dialogInterface) {
|
||||
// getActivity().finish();
|
||||
// }
|
||||
// });
|
||||
// Button positiveButton = ((AlertDialog) dialog)
|
||||
// .getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
//
|
||||
// Button negativeButton = ((AlertDialog) dialog)
|
||||
// .getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return alert;
|
||||
// }
|
||||
//
|
||||
//}
|
@ -7,6 +7,8 @@ import android.util.Log;
|
||||
|
||||
/**
|
||||
* Utilities for manipulating device audio configuration
|
||||
*
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
public class AudioUtils {
|
||||
private static final String TAG = AudioUtils.class.getName();
|
||||
|
@ -1,40 +0,0 @@
|
||||
package org.thoughtcrime.redphone.util;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
|
||||
public class BitmapUtil {
|
||||
|
||||
public static Bitmap getCircleCroppedBitmap(Bitmap bitmap) {
|
||||
if (bitmap == null) return null;
|
||||
final int srcSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
|
||||
return getScaledCircleCroppedBitmap(bitmap, srcSize);
|
||||
}
|
||||
|
||||
public static Bitmap getScaledCircleCroppedBitmap(Bitmap bitmap, int destSize) {
|
||||
if (bitmap == null) return null;
|
||||
Bitmap output = Bitmap.createBitmap(destSize, destSize, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
|
||||
final int srcSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
|
||||
final int srcX = (bitmap.getWidth() - srcSize) / 2;
|
||||
final int srcY = (bitmap.getHeight() - srcSize) / 2;
|
||||
final Rect srcRect = new Rect(srcX, srcY, srcX + srcSize, srcY + srcSize);
|
||||
final Rect destRect = new Rect(0, 0, destSize, destSize);
|
||||
final int color = 0xff424242;
|
||||
final Paint paint = new Paint();
|
||||
|
||||
paint.setAntiAlias(true);
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
paint.setColor(color);
|
||||
canvas.drawCircle(destSize / 2, destSize / 2, destSize / 2, paint);
|
||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
canvas.drawBitmap(bitmap, srcRect, destRect, paint);
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
//package org.thoughtcrime.redphone.util;
|
||||
//
|
||||
//import android.content.ContentValues;
|
||||
//import android.content.Context;
|
||||
//import android.net.Uri;
|
||||
//import android.provider.CallLog.Calls;
|
||||
//import android.util.Log;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.contacts.PersonInfo;
|
||||
//
|
||||
//public class CallLogger {
|
||||
// private static final String TAG = CallLogger.class.getName();
|
||||
// private static ContentValues getCallLogContentValues(Context context, String number, long timestamp) {
|
||||
// PersonInfo pi = PersonInfo.getInstance(context, number);
|
||||
// ContentValues values = new ContentValues();
|
||||
//
|
||||
// values.put(Calls.DATE, System.currentTimeMillis());
|
||||
// values.put(Calls.NUMBER, number);
|
||||
// values.put(Calls.CACHED_NAME, pi.getName() );
|
||||
// values.put(Calls.TYPE, pi.getType() );
|
||||
//
|
||||
// return values;
|
||||
// }
|
||||
//
|
||||
// private static ContentValues getCallLogContentValues(Context context, String number) {
|
||||
// return getCallLogContentValues(context, number, System.currentTimeMillis());
|
||||
// }
|
||||
//
|
||||
// public static void logMissedCall(Context context, String number, long timestamp) {
|
||||
// ContentValues values = getCallLogContentValues(context, number, timestamp);
|
||||
// values.put(Calls.TYPE, Calls.MISSED_TYPE);
|
||||
// context.getContentResolver().insert(Calls.CONTENT_URI, values);
|
||||
// }
|
||||
//
|
||||
// public static CallRecord logOutgoingCall(Context context, String number) {
|
||||
// ContentValues values = getCallLogContentValues(context, number);
|
||||
// values.put(Calls.TYPE, Calls.OUTGOING_TYPE);
|
||||
// try{
|
||||
// Uri uri = context.getContentResolver().insert(Calls.CONTENT_URI, values);
|
||||
// return new CallRecord(context, uri);
|
||||
// } catch (IllegalArgumentException e ) {
|
||||
// Log.w(TAG, "Failed call log insert", e);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public static CallRecord logIncomingCall(Context context, String number) {
|
||||
// ContentValues values = getCallLogContentValues(context, number);
|
||||
// values.put(Calls.TYPE, Calls.INCOMING_TYPE);
|
||||
// Uri recordUri = context.getContentResolver().insert(Calls.CONTENT_URI, values);
|
||||
// return new CallRecord(context, recordUri);
|
||||
// }
|
||||
//
|
||||
// public static class CallRecord {
|
||||
// private final Context context;
|
||||
// private final Uri uri;
|
||||
// private final long startTimeMillis;
|
||||
//
|
||||
// private CallRecord(Context context, Uri callRecordUri) {
|
||||
// this.context = context;
|
||||
// this.uri = callRecordUri;
|
||||
// startTimeMillis = System.currentTimeMillis();
|
||||
// }
|
||||
//
|
||||
// public void finishCall() {
|
||||
// int duration = (int)((System.currentTimeMillis() - startTimeMillis)/1000);
|
||||
// ContentValues values = new ContentValues();
|
||||
// values.put(Calls.DURATION, duration);
|
||||
// if (uri != null) {
|
||||
// context.getContentResolver().update(uri, values, null, null);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.util;
|
||||
|
||||
/**
|
||||
* Factory interface
|
||||
* @param <T> product type
|
||||
*/
|
||||
public interface Factory<T> {
|
||||
T getInstance();
|
||||
}
|
@ -1,373 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Clover Network, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.redphone.util;
|
||||
|
||||
import android.database.CharArrayBuffer;
|
||||
import android.database.Cursor;
|
||||
import android.database.CursorWrapper;
|
||||
|
||||
/**
|
||||
* Wraps a Cursor and allowing its positions to be filtered out, repeated, or reordered. Common ways of creating
|
||||
* FilteredCursor objects are provided by the {@link FilteredCursorFactory}.
|
||||
*
|
||||
* Note that if the source Cursor exceeds the size of the {@link android.database.CursorWindow} the FilteredCursor
|
||||
* may end up having extremely poor performance due to frequent CursorWindow cache misses. In those cases it is
|
||||
* recommended that source Cursor contain less data.
|
||||
*
|
||||
* @author Jacob Whitaker Abrams
|
||||
*/
|
||||
public class FilteredCursor extends CursorWrapper {
|
||||
|
||||
// Globally map master Cursor to FilteredCursors, when all FilteredCursors are closed go ahead and close the master
|
||||
// This would need to go into a singleton if other classes similar to FilteredCursor exist
|
||||
// private static final Map<Cursor, Set<FilteredCursor>> sMasterCursorMap =
|
||||
// Collections.synchronizedMap(new WeakHashMap<Cursor, Set<FilteredCursor>>());
|
||||
|
||||
private int[] mFilterMap;
|
||||
private int mPos = -1;
|
||||
private final Cursor mCursor;
|
||||
private boolean mClosed;
|
||||
|
||||
// /**
|
||||
// * Create a FilteredCursor that appears identical to its wrapped Cursor.
|
||||
// */
|
||||
// public static FilteredCursor createUsingIdentityFilter(Cursor cursor) {
|
||||
// if (cursor == null) {
|
||||
// return null;
|
||||
// }
|
||||
// return new FilteredCursor(cursor);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Create a new FilteredCursor using the given filter. The filter specifies where rows of the given Cursor should
|
||||
* appear in the FilteredCursor. For example if filter = { 5, 9 } then the FilteredCursor will have two rows, the
|
||||
* first row maps to row 5 in the source Cursor and the second row maps to row 9 in the source cursor. Returns null
|
||||
* if the provided cursor is null. A value of -1 in the filter is treated as an empty row in the Cursor with no data,
|
||||
* see {@link FilteredCursor#isPositionEmpty()}.
|
||||
*/
|
||||
public static FilteredCursor createUsingFilter(Cursor cursor, int[] filter) {
|
||||
if (cursor == null) {
|
||||
return null;
|
||||
}
|
||||
if (filter == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return new FilteredCursor(cursor, filter);
|
||||
}
|
||||
|
||||
// private FilteredCursor(Cursor cursor) {
|
||||
// this(cursor, null);
|
||||
// resetToIdentityFilter();
|
||||
// }
|
||||
|
||||
private FilteredCursor(Cursor cursor, int[] filterMap) {
|
||||
super(cursor);
|
||||
mCursor = cursor;
|
||||
mFilterMap = filterMap;
|
||||
// attachToMasterCursor();
|
||||
}
|
||||
|
||||
public int[] getFilterMap() {
|
||||
return mFilterMap;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Reset the filter so it appears identical to its wrapped Cursor.
|
||||
// */
|
||||
// public FilteredCursor resetToIdentityFilter() {
|
||||
// int count = mCursor.getCount();
|
||||
// int[] filterMap = new int[count];
|
||||
//
|
||||
// for (int i = 0; i < count; i++) {
|
||||
// filterMap[i] = i;
|
||||
// }
|
||||
//
|
||||
// mFilterMap = filterMap;
|
||||
// mPos = -1;
|
||||
// return this;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Returns true if the FilteredCursor appears identical to its wrapped Cursor.
|
||||
// */
|
||||
// public boolean isIdentityFilter() {
|
||||
// int count = mCursor.getCount();
|
||||
// if (mFilterMap.length != count) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// for (int i = 0; i < count; i++) {
|
||||
// if (mFilterMap[i] != i) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Rearrange the filter. The new arrangement is based on the current filter arrangement, not on the source Cursor's
|
||||
// * arrangement.
|
||||
// */
|
||||
// public FilteredCursor refilter(int[] newArrangement) {
|
||||
// final int newMapSize = newArrangement.length;
|
||||
// int[] newMap = new int[newMapSize];
|
||||
// for (int i = 0; i < newMapSize; i++) {
|
||||
// newMap[i] = mFilterMap[newArrangement[i]];
|
||||
// }
|
||||
//
|
||||
// mFilterMap = newMap;
|
||||
// mPos = -1;
|
||||
// return this;
|
||||
// }
|
||||
|
||||
/**
|
||||
* True if the current cursor position has no data. Attempting to access data in an empty row with any of the getters
|
||||
* will throw {@link UnsupportedOperationException}.
|
||||
*/
|
||||
public boolean isPositionEmpty() {
|
||||
return mFilterMap[mPos] == -1;
|
||||
}
|
||||
|
||||
private void throwIfEmptyRow() {
|
||||
if (isPositionEmpty()) {
|
||||
throw new UnsupportedOperationException("Cannot access data in an empty row");
|
||||
}
|
||||
}
|
||||
|
||||
// public void swapItems(int itemOne, int itemTwo) {
|
||||
// int temp = mFilterMap[itemOne];
|
||||
// mFilterMap[itemOne] = mFilterMap[itemTwo];
|
||||
// mFilterMap[itemTwo] = temp;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mFilterMap.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPosition() {
|
||||
return mPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToPosition(int position) {
|
||||
// Make sure position isn't past the end of the cursor
|
||||
final int count = getCount();
|
||||
if (position >= count) {
|
||||
mPos = count;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure position isn't before the beginning of the cursor
|
||||
if (position < 0) {
|
||||
mPos = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
final int realPosition = mFilterMap[position];
|
||||
|
||||
// When moving to an empty position, just pretend we did it
|
||||
boolean moved = realPosition == -1 ? true : super.moveToPosition(realPosition);
|
||||
if (moved) {
|
||||
mPos = position;
|
||||
} else {
|
||||
mPos = -1;
|
||||
}
|
||||
return moved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean move(int offset) {
|
||||
return moveToPosition(mPos + offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean moveToFirst() {
|
||||
return moveToPosition(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean moveToLast() {
|
||||
return moveToPosition(getCount() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean moveToNext() {
|
||||
return moveToPosition(mPos + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean moveToPrevious() {
|
||||
return moveToPosition(mPos - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isFirst() {
|
||||
return mPos == 0 && getCount() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isLast() {
|
||||
int count = getCount();
|
||||
return mPos == (count - 1) && count != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isBeforeFirst() {
|
||||
if (getCount() == 0) {
|
||||
return true;
|
||||
}
|
||||
return mPos == -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isAfterLast() {
|
||||
if (getCount() == 0) {
|
||||
return true;
|
||||
}
|
||||
return mPos == getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull(int columnIndex) {
|
||||
throwIfEmptyRow();
|
||||
return mCursor.isNull(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyStringToBuffer(int columnIndex, CharArrayBuffer buffer) {
|
||||
throwIfEmptyRow();
|
||||
mCursor.copyStringToBuffer(columnIndex, buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBlob(int columnIndex) {
|
||||
throwIfEmptyRow();
|
||||
return mCursor.getBlob(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(int columnIndex) {
|
||||
throwIfEmptyRow();
|
||||
return mCursor.getDouble(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloat(int columnIndex) {
|
||||
throwIfEmptyRow();
|
||||
return mCursor.getFloat(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(int columnIndex) {
|
||||
throwIfEmptyRow();
|
||||
return mCursor.getInt(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(int columnIndex) {
|
||||
throwIfEmptyRow();
|
||||
return mCursor.getLong(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getShort(int columnIndex) {
|
||||
throwIfEmptyRow();
|
||||
return mCursor.getShort(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int columnIndex) {
|
||||
throwIfEmptyRow();
|
||||
return mCursor.getString(columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return mClosed || getMasterCursor().isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Mark this Cursor as closed
|
||||
mClosed = true;
|
||||
|
||||
// Find the master Cursor and close it if all linked cursors are closed
|
||||
Cursor masterCursor = getMasterCursor();
|
||||
|
||||
// Set<FilteredCursor> linkedFilteredCursorSet = sMasterCursorMap.get(masterCursor);
|
||||
// if (linkedFilteredCursorSet == null) {
|
||||
masterCursor.close(); // Shouldn't ever happen?
|
||||
// } else {
|
||||
// linkedFilteredCursorSet.remove(this);
|
||||
// if (linkedFilteredCursorSet.isEmpty()) {
|
||||
// masterCursor.close();
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (masterCursor.isClosed()) {
|
||||
// sMasterCursorMap.remove(masterCursor);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean requery() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// private void attachToMasterCursor() {
|
||||
// Cursor masterCursor = getMasterCursor();
|
||||
// Set<FilteredCursor> filteredCursorSet = sMasterCursorMap.get(masterCursor);
|
||||
// if (filteredCursorSet == null) {
|
||||
// filteredCursorSet = Collections.synchronizedSet(new HashSet<FilteredCursor>());
|
||||
// sMasterCursorMap.put(masterCursor, filteredCursorSet);
|
||||
// }
|
||||
// filteredCursorSet.add(this);
|
||||
// }
|
||||
|
||||
// /** Returns the first non-CursorWrapper instance contained within this object. */
|
||||
// public Cursor getMasterCursor() {
|
||||
// Cursor cursor = mCursor;
|
||||
//
|
||||
// while (cursor instanceof CursorWrapper) {
|
||||
// cursor = ((CursorWrapper) cursor).getWrappedCursor();
|
||||
// }
|
||||
//
|
||||
// return cursor;
|
||||
// }
|
||||
|
||||
public Cursor getMasterCursor() {
|
||||
return mCursor;
|
||||
}
|
||||
|
||||
// /** Returns the first FilteredCursor wrapped by the provided cursor or null if no FilteredCursor is found. */
|
||||
// public static FilteredCursor unwrapFilteredCursor(Cursor cursor) {
|
||||
// while (cursor instanceof CursorWrapper) {
|
||||
// if (cursor instanceof FilteredCursor) {
|
||||
// return (FilteredCursor)cursor;
|
||||
// } else {
|
||||
// cursor = ((CursorWrapper) cursor).getWrappedCursor();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package org.thoughtcrime.redphone.util;
|
||||
|
||||
import android.database.Cursor;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class FilteredCursorFactory {
|
||||
|
||||
public interface CursorFilter {
|
||||
public boolean isIncluded(Cursor cursor);
|
||||
}
|
||||
|
||||
public static Cursor getFilteredCursor(Cursor cursor, CursorFilter filter) {
|
||||
List<Integer> map = new LinkedList<Integer>();
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
if (filter.isIncluded(cursor)) {
|
||||
map.add(cursor.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
return FilteredCursor.createUsingFilter(cursor, toArray(map));
|
||||
}
|
||||
|
||||
private static int[] toArray(List<Integer> map) {
|
||||
int[] array = new int[map.size()];
|
||||
int index = 0;
|
||||
|
||||
for (int position : map) {
|
||||
array[index++] = position;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.util;
|
||||
|
||||
/**
|
||||
* Utility for generating hex dumps a la hexl-mode in emacs.
|
||||
*/
|
||||
public class Hex {
|
||||
|
||||
private final static int HEX_DIGITS_START = 10;
|
||||
private final static int ASCII_TEXT_START = HEX_DIGITS_START + (16*2 + (16/2));
|
||||
|
||||
final static String EOL = System.getProperty("line.separator");
|
||||
|
||||
private final static char[] HEX_DIGITS = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
||||
};
|
||||
|
||||
public static String toString(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return toString(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
public static String toString(byte[] bytes, int offset, int length) {
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < length; i++) {
|
||||
appendHexChar(buf, bytes[offset + i]);
|
||||
buf.append(' ');
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String dump(byte[] bytes) {
|
||||
return dump(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
public static String dump(byte[] bytes, int offset, int length) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
int lines = ((length - 1) / 16) + 1;
|
||||
int lineOffset;
|
||||
int lineLength;
|
||||
|
||||
for (int i = 0; i < lines; i++) {
|
||||
lineOffset = (i * 16) + offset;
|
||||
lineLength = Math.min(16, (length - (i * 16)));
|
||||
appendDumpLine(buf, i, bytes, lineOffset, lineLength);
|
||||
buf.append(EOL);
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static void appendDumpLine(StringBuffer buf, int line,
|
||||
byte[] bytes, int lineOffset,
|
||||
int lineLength)
|
||||
{
|
||||
buf.append(HEX_DIGITS[(line >> 28) & 0xf]);
|
||||
buf.append(HEX_DIGITS[(line >> 24) & 0xf]);
|
||||
buf.append(HEX_DIGITS[(line >> 20) & 0xf]);
|
||||
buf.append(HEX_DIGITS[(line >> 16) & 0xf]);
|
||||
buf.append(HEX_DIGITS[(line >> 12) & 0xf]);
|
||||
buf.append(HEX_DIGITS[(line >> 8) & 0xf]);
|
||||
buf.append(HEX_DIGITS[(line >> 4) & 0xf]);
|
||||
buf.append(HEX_DIGITS[(line ) & 0xf]);
|
||||
buf.append(": ");
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int idx = i + lineOffset;
|
||||
if (i < lineLength) {
|
||||
int b = bytes[idx];
|
||||
appendHexChar(buf, b);
|
||||
} else {
|
||||
buf.append(" ");
|
||||
}
|
||||
if ((i % 2) == 1) {
|
||||
buf.append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16 && i < lineLength; i++) {
|
||||
int idx = i + lineOffset;
|
||||
int b = bytes[idx];
|
||||
if (b >= 0x20 && b <= 0x7e) {
|
||||
buf.append((char)b);
|
||||
} else {
|
||||
buf.append('.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendHexChar(StringBuffer buf, int b) {
|
||||
buf.append(HEX_DIGITS[(b >> 4) & 0xf]);
|
||||
buf.append(HEX_DIGITS[b & 0xf]);
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.util;
|
||||
|
||||
/**
|
||||
* Integrates observations over time, but decays the sum exponentially with each observation.
|
||||
*
|
||||
* This is useful for producing a cheap approximation to 'sum over the last N observations'
|
||||
*
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
public class LeakyIntegrator {
|
||||
private float value;
|
||||
private float decayConstant;
|
||||
|
||||
public LeakyIntegrator( int decayTimeInSamples ) {
|
||||
decayConstant = (float)(1 - 1.0/decayTimeInSamples);
|
||||
}
|
||||
|
||||
public void observe( float x ) {
|
||||
value = value * decayConstant + x;
|
||||
}
|
||||
|
||||
public float get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
public void reset( float x ) {
|
||||
value = x;
|
||||
}
|
||||
}
|
@ -19,6 +19,8 @@ package org.thoughtcrime.redphone.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Hex;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -1,347 +0,0 @@
|
||||
package org.thoughtcrime.redphone.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
/**
|
||||
* Adapted from: http://stackoverflow.com/questions/3118234/how-to-get-memory-usage-and-cpu-usage-in-android
|
||||
* Stackoverflow user: slash33
|
||||
*
|
||||
* Utilities available only on Linux Operating System.
|
||||
*
|
||||
* <p>
|
||||
* A typical use is to assign a thread to CPU monitoring:
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* @Override
|
||||
* public void run() {
|
||||
* while (CpuUtil.monitorCpu) {
|
||||
*
|
||||
* LinuxUtils linuxUtils = new LinuxUtils();
|
||||
*
|
||||
* int pid = android.os.Process.myPid();
|
||||
* String cpuStat1 = linuxUtils.readSystemStat();
|
||||
* String pidStat1 = linuxUtils.readProcessStat(pid);
|
||||
*
|
||||
* try {
|
||||
* Thread.sleep(CPU_WINDOW);
|
||||
* } catch (Exception e) {
|
||||
* }
|
||||
*
|
||||
* String cpuStat2 = linuxUtils.readSystemStat();
|
||||
* String pidStat2 = linuxUtils.readProcessStat(pid);
|
||||
*
|
||||
* float cpu = linuxUtils.getSystemCpuUsage(cpuStat1, cpuStat2);
|
||||
* if (cpu >= 0.0f) {
|
||||
* _printLine(mOutput, "total", Float.toString(cpu));
|
||||
* }
|
||||
*
|
||||
* String[] toks = cpuStat1.split(" ");
|
||||
* long cpu1 = linuxUtils.getSystemUptime(toks);
|
||||
*
|
||||
* toks = cpuStat2.split(" ");
|
||||
* long cpu2 = linuxUtils.getSystemUptime(toks);
|
||||
*
|
||||
* cpu = linuxUtils.getProcessCpuUsage(pidStat1, pidStat2, cpu2 - cpu1);
|
||||
* if (cpu >= 0.0f) {
|
||||
* _printLine(mOutput, "" + pid, Float.toString(cpu));
|
||||
* }
|
||||
*
|
||||
* try {
|
||||
* synchronized (this) {
|
||||
* wait(CPU_REFRESH_RATE);
|
||||
* }
|
||||
* } catch (InterruptedException e) {
|
||||
* e.printStackTrace();
|
||||
* return;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Log.i("THREAD CPU", "Finishing");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
public final class LinuxUtils {
|
||||
|
||||
private LinuxUtils() {
|
||||
//util
|
||||
}
|
||||
|
||||
/** Return the first line of /proc/stat or null if failed. */
|
||||
public static String readSystemStat() {
|
||||
|
||||
RandomAccessFile reader = null;
|
||||
String load = null;
|
||||
|
||||
try {
|
||||
reader = new RandomAccessFile("/proc/stat", "r");
|
||||
load = reader.readLine();
|
||||
} catch (IOException ex) {
|
||||
Log.e("LinuxUtils", "Failed to read /proc/stat", ex);
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
Log.e("LinuxUtils", "Failed to close stream");
|
||||
}
|
||||
}
|
||||
|
||||
return load;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute and return the total CPU usage, in percent.
|
||||
*
|
||||
* @param start
|
||||
* first content of /proc/stat. Not null.
|
||||
* @param end
|
||||
* second content of /proc/stat. Not null.
|
||||
* @return the CPU use in percent, or -1f if the stats are inverted or on
|
||||
* error
|
||||
* @see {@link #readSystemStat()}
|
||||
*/
|
||||
public static float getSystemCpuUsage(String start, String end) {
|
||||
String[] stat = start.split(" ");
|
||||
long idle1 = getSystemIdleTime(stat);
|
||||
long up1 = getSystemUptime(stat);
|
||||
|
||||
stat = end.split(" ");
|
||||
long idle2 = getSystemIdleTime(stat);
|
||||
long up2 = getSystemUptime(stat);
|
||||
|
||||
// don't know how it is possible but we should care about zero and
|
||||
// negative values.
|
||||
float cpu = -1f;
|
||||
if (idle1 >= 0 && up1 >= 0 && idle2 >= 0 && up2 >= 0) {
|
||||
if ((up2 + idle2) > (up1 + idle1) && up2 >= up1) {
|
||||
cpu = (up2 - up1) / (float) ((up2 + idle2) - (up1 + idle1));
|
||||
cpu *= 100.0f;
|
||||
}
|
||||
}
|
||||
|
||||
return cpu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sum of uptimes read from /proc/stat.
|
||||
*
|
||||
* @param stat
|
||||
* see {@link #readSystemStat()}
|
||||
*/
|
||||
public static long getSystemUptime(String[] stat) {
|
||||
/*
|
||||
* (from man/5/proc) /proc/stat kernel/system statistics. Varies with
|
||||
* architecture. Common entries include: cpu 3357 0 4313 1362393
|
||||
*
|
||||
* The amount of time, measured in units of USER_HZ (1/100ths of a
|
||||
* second on most architectures, use sysconf(_SC_CLK_TCK) to obtain the
|
||||
* right value), that the system spent in user mode, user mode with low
|
||||
* priority (nice), system mode, and the idle task, respectively. The
|
||||
* last value should be USER_HZ times the second entry in the uptime
|
||||
* pseudo-file.
|
||||
*
|
||||
* In Linux 2.6 this line includes three additional columns: iowait -
|
||||
* time waiting for I/O to complete (since 2.5.41); irq - time servicing
|
||||
* interrupts (since 2.6.0-test4); softirq - time servicing softirqs
|
||||
* (since 2.6.0-test4).
|
||||
*
|
||||
* Since Linux 2.6.11, there is an eighth column, steal - stolen time,
|
||||
* which is the time spent in other operating systems when running in a
|
||||
* virtualized environment
|
||||
*
|
||||
* Since Linux 2.6.24, there is a ninth column, guest, which is the time
|
||||
* spent running a virtual CPU for guest operating systems under the
|
||||
* control of the Linux kernel.
|
||||
*/
|
||||
|
||||
// with the following algorithm, we should cope with all versions and
|
||||
// probably new ones.
|
||||
long l = 0L;
|
||||
for (int i = 2; i < stat.length; i++) {
|
||||
if (i != 5) { // bypass any idle mode. There is currently only one.
|
||||
try {
|
||||
l += Long.parseLong(stat[i]);
|
||||
} catch (NumberFormatException ex) {
|
||||
Log.e("LinuxUtils", "Failed to parse stats", ex);
|
||||
return -1L;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sum of idle times read from /proc/stat.
|
||||
*
|
||||
* @param stat
|
||||
* see {@link #readSystemStat()}
|
||||
*/
|
||||
public static long getSystemIdleTime(String[] stat) {
|
||||
try {
|
||||
return Long.parseLong(stat[5]);
|
||||
} catch (NumberFormatException ex) {
|
||||
Log.e("LinuxUtils", "Failed to parse stats", ex);
|
||||
}
|
||||
|
||||
return -1L;
|
||||
}
|
||||
|
||||
/** Return the first line of /proc/pid/stat or null if failed. */
|
||||
public static String readProcessStat(int pid) {
|
||||
|
||||
RandomAccessFile reader = null;
|
||||
String line = null;
|
||||
|
||||
try {
|
||||
reader = new RandomAccessFile("/proc/" + pid + "/stat", "r");
|
||||
line = reader.readLine();
|
||||
} catch (IOException ex) {
|
||||
Log.e("LinuxUtils", "Failed to read process stats", ex);
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
Log.e("LinuxUtils", "Failed to close stream");
|
||||
}
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute and return the CPU usage for a process, in percent.
|
||||
*
|
||||
* <p>
|
||||
* The parameters {@code totalCpuTime} is to be the one for the same period
|
||||
* of time delimited by {@code statStart} and {@code statEnd}.
|
||||
* </p>
|
||||
*
|
||||
* @param start
|
||||
* first content of /proc/pid/stat. Not null.
|
||||
* @param end
|
||||
* second content of /proc/pid/stat. Not null.
|
||||
* @return the CPU use in percent or -1f if the stats are inverted or on
|
||||
* error
|
||||
* @param uptime
|
||||
* sum of user and kernel times for the entire system for the
|
||||
* same period of time.
|
||||
* @return 12.7 for a cpu usage of 12.7% or -1 if the value is not available
|
||||
* or an error occurred.
|
||||
* @see {@link #readProcessStat(int)}
|
||||
*/
|
||||
public static float getProcessCpuUsage(String start, String end, long uptime) {
|
||||
|
||||
String[] stat = start.split(" ");
|
||||
long up1 = getProcessUptime(stat);
|
||||
|
||||
stat = end.split(" ");
|
||||
long up2 = getProcessUptime(stat);
|
||||
|
||||
float ret = -1f;
|
||||
if (up1 >= 0 && up2 >= up1 && uptime > 0.) {
|
||||
ret = 100.f * (up2 - up1) / (float) uptime;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the fields of the file {@code /proc/pid/stat} and return (utime +
|
||||
* stime)
|
||||
*
|
||||
* @param stat
|
||||
* obtained with {@link #readProcessStat(int)}
|
||||
*/
|
||||
public static long getProcessUptime(String[] stat) {
|
||||
return Long.parseLong(stat[14]) + Long.parseLong(stat[15]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the fields of the file {@code /proc/pid/stat} and return (cutime +
|
||||
* cstime)
|
||||
*
|
||||
* @param stat
|
||||
* obtained with {@link #readProcessStat(int)}
|
||||
*/
|
||||
public static long getProcessIdleTime(String[] stat) {
|
||||
return Long.parseLong(stat[16]) + Long.parseLong(stat[17]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the total CPU usage, in percent.
|
||||
* <p>
|
||||
* The call is blocking for the time specified by elapse.
|
||||
* </p>
|
||||
*
|
||||
* @param elapse
|
||||
* the time in milliseconds between reads.
|
||||
* @return 12.7 for a CPU usage of 12.7% or -1 if the value is not
|
||||
* available.
|
||||
*/
|
||||
public static float syncGetSystemCpuUsage(long elapse) {
|
||||
|
||||
String stat1 = readSystemStat();
|
||||
if (stat1 == null) {
|
||||
return -1.f;
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(elapse);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
String stat2 = readSystemStat();
|
||||
if (stat2 == null) {
|
||||
return -1.f;
|
||||
}
|
||||
|
||||
return getSystemCpuUsage(stat1, stat2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the CPU usage of a process, in percent.
|
||||
* <p>
|
||||
* The call is blocking for the time specified by elapse.
|
||||
* </p>
|
||||
*
|
||||
* @param pid
|
||||
* @param elapse
|
||||
* the time in milliseconds between reads.
|
||||
* @return 6.32 for a CPU usage of 6.32% or -1 if the value is not
|
||||
* available.
|
||||
*/
|
||||
public static float syncGetProcessCpuUsage(int pid, long elapse) {
|
||||
|
||||
String pidStat1 = readProcessStat(pid);
|
||||
String totalStat1 = readSystemStat();
|
||||
if (pidStat1 == null || totalStat1 == null) {
|
||||
return -1.f;
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(elapse);
|
||||
} catch (InterruptedException e) {
|
||||
throw new AssertionError("Wait interrupted in LinuxUtils");
|
||||
}
|
||||
|
||||
String pidStat2 = readProcessStat(pid);
|
||||
String totalStat2 = readSystemStat();
|
||||
if (pidStat2 == null || totalStat2 == null) {
|
||||
return -1.f;
|
||||
}
|
||||
|
||||
String[] toks = totalStat1.split(" ");
|
||||
long cpu1 = getSystemUptime(toks);
|
||||
|
||||
toks = totalStat2.split(" ");
|
||||
long cpu2 = getSystemUptime(toks);
|
||||
|
||||
return getProcessCpuUsage(pidStat1, pidStat2, cpu2 - cpu1);
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* Utility functions specific to logging
|
||||
*
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
public final class LogUtil {
|
||||
private LogUtil() { }
|
||||
|
||||
public static Uri generateCompressedLogFile() {
|
||||
String logFileName = Environment.getExternalStorageDirectory() + "/redphone-log.txt.gz";
|
||||
String cmd[] = {"sh", "-c", "logcat -v long -d V | gzip > " + logFileName };
|
||||
try {
|
||||
Process logProc = Runtime.getRuntime().exec( cmd );
|
||||
BufferedReader br = new BufferedReader( new InputStreamReader( logProc.getErrorStream() ),
|
||||
1024 );
|
||||
String line;
|
||||
while( (line = br.readLine()) != null ) {
|
||||
Log.d("RedPhone", "logerr: " + line);
|
||||
}
|
||||
|
||||
try {
|
||||
logProc.waitFor();
|
||||
}
|
||||
catch( InterruptedException e ) {
|
||||
throw new AssertionError( e );
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
catch( IOException e ) {
|
||||
Log.w("RedPhone", "generateCompressedLogFile: ", e);
|
||||
}
|
||||
return Uri.fromFile(new File(logFileName));
|
||||
}
|
||||
|
||||
public static Uri copyDataToSdCard(Context ctx, String fileName) {
|
||||
try {
|
||||
File outputFile = new File(Environment.getExternalStorageDirectory() + "/" +
|
||||
fileName + ".gz");
|
||||
FileOutputStream fos = new FileOutputStream( outputFile );
|
||||
GZIPOutputStream outputStream = new GZIPOutputStream( fos );
|
||||
InputStream inputStream = ctx.openFileInput(fileName);
|
||||
byte[] buf = new byte[4096];
|
||||
int read;
|
||||
|
||||
while ((read = inputStream.read(buf)) > 0) {
|
||||
//Log.w("RedPhone", "Read: " + read);
|
||||
outputStream.write(buf, 0, read);
|
||||
}
|
||||
|
||||
Log.w("RedPhone", "read: " + read);
|
||||
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
|
||||
return Uri.fromFile(outputFile);
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
Log.w("RedPhone", fnfe);
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
Log.w("RedPhone", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Open 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.util;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Helpers for periodically scheduling actions to random intervals
|
||||
*
|
||||
* @author Stuart O. Anderson
|
||||
*/
|
||||
public class PeriodicActionUtils {
|
||||
|
||||
private PeriodicActionUtils() {
|
||||
//util
|
||||
}
|
||||
|
||||
public static <T extends BroadcastReceiver> void scheduleUpdate(Context context, Class<T> clazz) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
|
||||
Intent intent = new Intent(context, clazz);
|
||||
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Random random = new Random(System.currentTimeMillis());
|
||||
long offset = random.nextLong() % (12 * 60 * 60 * 1000);
|
||||
long interval = (24 * 60 * 60 * 1000) + offset;
|
||||
String prefKey = "pref_scheduled_monitor_config_update_" + clazz.getCanonicalName();
|
||||
long scheduledTime = preferences.getLong(prefKey, -1);
|
||||
|
||||
if (scheduledTime == -1 ) {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
if (scheduledTime <= System.currentTimeMillis()) {
|
||||
context.sendBroadcast(intent);
|
||||
scheduledTime = System.currentTimeMillis() + interval;
|
||||
preferences.edit().putLong(prefKey, scheduledTime).commit();
|
||||
Log.w("PeriodicActionUtils", "Scheduling for all new time: " + scheduledTime
|
||||
+ " (" + clazz.getSimpleName() + ")");
|
||||
} else {
|
||||
Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime
|
||||
+ " (" + clazz.getSimpleName() + ")");
|
||||
}
|
||||
|
||||
am.cancel(sender);
|
||||
am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender);
|
||||
|
||||
Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime
|
||||
+ " (" + clazz.getSimpleName() + ")");
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
///*
|
||||
// * 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
|
||||
// * (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * 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.redphone.util;
|
||||
//
|
||||
//import android.content.Context;
|
||||
//import android.content.SharedPreferences;
|
||||
//import android.preference.PreferenceManager;
|
||||
//import android.util.Log;
|
||||
//
|
||||
//import com.google.i18n.phonenumbers.NumberParseException;
|
||||
//import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
//import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
|
||||
//import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
|
||||
//
|
||||
//import org.thoughtcrime.redphone.ApplicationContext;
|
||||
//import org.thoughtcrime.redphone.Constants;
|
||||
//
|
||||
//import java.util.Locale;
|
||||
//
|
||||
///**
|
||||
// * Phone number formats are a pain.
|
||||
// *
|
||||
// * @author Moxie Marlinspike
|
||||
// *
|
||||
// */
|
||||
//public class PhoneNumberFormatter {
|
||||
//
|
||||
// public static boolean isValidNumber(String number) {
|
||||
// return number.matches("^\\+[0-9]{10,}");
|
||||
// }
|
||||
//
|
||||
// private static String impreciseFormatNumber(String number, String localNumber) {
|
||||
// number = number.replaceAll("[^0-9+]", "");
|
||||
//
|
||||
// if (number.charAt(0) == '+')
|
||||
// return number;
|
||||
//
|
||||
// if (localNumber.charAt(0) == '+')
|
||||
// localNumber = localNumber.substring(1);
|
||||
//
|
||||
// if (localNumber.length() == number.length() || number.length() > localNumber.length())
|
||||
// return "+" + number;
|
||||
//
|
||||
// int difference = localNumber.length() - number.length();
|
||||
//
|
||||
// return "+" + localNumber.substring(0, difference) + number;
|
||||
// }
|
||||
//
|
||||
// public static String formatNumberInternational(String number) {
|
||||
// try {
|
||||
// PhoneNumberUtil util = PhoneNumberUtil.getInstance();
|
||||
// PhoneNumber parsedNumber = util.parse(number, null);
|
||||
// return util.format(parsedNumber, PhoneNumberFormat.INTERNATIONAL);
|
||||
// } catch (NumberParseException e) {
|
||||
// Log.w("PhoneNumberFormatter", e);
|
||||
// return number;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static String formatNumber(Context context, String number) {
|
||||
// SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
// String localNumber = preferences.getString(Constants.NUMBER_PREFERENCE, "No Stored Number");
|
||||
// number = number.replaceAll("[^0-9+]", "");
|
||||
//
|
||||
// if (Util.isEmpty(number))
|
||||
// return number;
|
||||
//
|
||||
// if (number.charAt(0) == '+')
|
||||
// return number;
|
||||
//
|
||||
// try {
|
||||
// PhoneNumberUtil util = PhoneNumberUtil.getInstance();
|
||||
// PhoneNumber localNumberObject = util.parse(localNumber, null);
|
||||
//
|
||||
// String localCountryCode = util.getRegionCodeForNumber(localNumberObject);
|
||||
// Log.w("PhoneNumberFormatter", "Got local CC: " + localCountryCode);
|
||||
//
|
||||
// PhoneNumber numberObject = util.parse(number, localCountryCode);
|
||||
// return util.format(numberObject, PhoneNumberFormat.E164);
|
||||
// } catch (NumberParseException e) {
|
||||
// Log.w("PhoneNumberFormatter", e);
|
||||
// return impreciseFormatNumber(number, localNumber);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static String formatNumber(String number) {
|
||||
// return formatNumber(ApplicationContext.getInstance().getContext(), number);
|
||||
// }
|
||||
//
|
||||
// public static String getRegionDisplayName(String regionCode) {
|
||||
// return (regionCode == null || regionCode.equals("ZZ") || regionCode.equals(PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY))
|
||||
// ? "Unknown country" : new Locale("", regionCode).getDisplayCountry(Locale.getDefault());
|
||||
// }
|
||||
//
|
||||
// public static String formatE164(String countryCode, String number) {
|
||||
// try {
|
||||
// PhoneNumberUtil util = PhoneNumberUtil.getInstance();
|
||||
// int parsedCountryCode = Integer.parseInt(countryCode);
|
||||
// PhoneNumber parsedNumber = util.parse(number,
|
||||
// util.getRegionCodeForCountryCode(parsedCountryCode));
|
||||
//
|
||||
// return util.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
|
||||
// } catch (NumberParseException npe) {
|
||||
// Log.w("CreateAccountActivity", npe);
|
||||
// } catch (NumberFormatException nfe) {
|
||||
// Log.w("CreateAccountActivity", nfe);
|
||||
// }
|
||||
//
|
||||
// return "+" +
|
||||
// countryCode.replaceAll("[^0-9]", "").replaceAll("^0*", "") +
|
||||
// number.replaceAll("[^0-9]", "");
|
||||
// }
|
||||
//
|
||||
// public static String getInternationalFormatFromE164(String e164number) {
|
||||
// try {
|
||||
// PhoneNumberUtil util = PhoneNumberUtil.getInstance();
|
||||
// PhoneNumber parsedNumber = util.parse(e164number, null);
|
||||
// return util.format(parsedNumber, PhoneNumberFormat.INTERNATIONAL);
|
||||
// } catch (NumberParseException e) {
|
||||
// Log.w("PhoneNumberFormatter", e);
|
||||
// return e164number;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* 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.redphone.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Stores a collection of objects allowing instances to be checked out and returned.
|
||||
*
|
||||
* The intent is that this allows reuse of large objects with short lifetimes without loading the
|
||||
* GC
|
||||
* @param <T> type of object held in the pool
|
||||
*
|
||||
* @author Stuart O Anderson
|
||||
*/
|
||||
//TODO(Stuart Anderson): Refactor audio pipeline to eliminate the need for this
|
||||
public class Pool<T> {
|
||||
List<T> pool = Collections.synchronizedList(new ArrayList<T>());
|
||||
Factory<T> itemFactory;
|
||||
|
||||
public Pool( Factory<T> factory) {
|
||||
itemFactory = factory;
|
||||
}
|
||||
|
||||
public T getItem() {
|
||||
T item;
|
||||
try {
|
||||
item =pool.remove(0);
|
||||
} catch( IndexOutOfBoundsException e ) {
|
||||
Log.d("Pool", "new Instance");
|
||||
return itemFactory.getInstance();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public void returnItem( T item ) {
|
||||
pool.add( item );
|
||||
}
|
||||
}
|
@ -58,16 +58,6 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSecret(int size) {
|
||||
try {
|
||||
byte[] secret = new byte[size];
|
||||
SecureRandom.getInstance("SHA1PRNG").nextBytes(secret);
|
||||
return Base64.encodeBytes(secret);
|
||||
} catch (NoSuchAlgorithmException nsae) {
|
||||
throw new AssertionError(nsae);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String value) {
|
||||
return (value == null || value.trim().length() == 0);
|
||||
}
|
||||
@ -80,26 +70,5 @@ public class Util {
|
||||
return value == null || isEmpty(value.toString());
|
||||
}
|
||||
|
||||
public static void showAlertDialog(Context context, String title, String message) {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
||||
dialog.setTitle(title);
|
||||
dialog.setMessage(message);
|
||||
dialog.setIcon(android.R.drawable.ic_dialog_alert);
|
||||
dialog.setPositiveButton(android.R.string.ok, null);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
// // XXX-S The consumers of these are way way down in the audio/microphone code.
|
||||
// // Is it possible to refactor them so that they bubble up their errors in a way
|
||||
// // that's a little cleaner than reaching back up from all the way down there?
|
||||
// public static void dieWithError(int msgId) {
|
||||
// ApplicationContext.getInstance().getCallStateListener().notifyClientError( msgId );
|
||||
// Log.d("RedPhone:AC", "Dying with error.");
|
||||
// }
|
||||
//
|
||||
// public static void dieWithError(Exception e) {
|
||||
// Log.w("RedPhone:AC", e);
|
||||
// ApplicationContext.getInstance().getCallStateListener().notifyClientError( e.getMessage() );
|
||||
// }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user