Skip to content

Commit

Permalink
Just some initial testing to see if jtoxcore av works
Browse files Browse the repository at this point in the history
  • Loading branch information
markwinter committed Sep 4, 2014
1 parent ef0e5d8 commit 8a08b58
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void onClickRegisterAccount(View view) {
try {
AntoxFriendList antoxFriendList = new AntoxFriendList();
CallbackHandler callbackHandler = new CallbackHandler(antoxFriendList);
ToxOptions toxOptions = new ToxOptions(true, false, false);
ToxOptions toxOptions = new ToxOptions(true, true, false);
JTox jTox = new JTox(antoxFriendList, callbackHandler, toxOptions);
ToxDataFile toxDataFile = new ToxDataFile(this, account);
toxDataFile.saveFile(jTox.save());
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/java/im/tox/antox/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
import im.tox.antox.data.AntoxDB;
import im.tox.antox.fragments.DialogToxID;
import im.tox.antox.tox.ToxSingleton;
import im.tox.antox.utils.AntoxFriend;
import im.tox.antox.utils.BitmapManager;
import im.tox.antox.utils.Constants;
import im.tox.antox.utils.Triple;
import im.tox.antox.utils.Tuple;
import im.tox.jtoxcore.ToxCallType;
import im.tox.jtoxcore.ToxCodecSettings;
import im.tox.jtoxcore.ToxException;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
Expand Down Expand Up @@ -171,7 +175,19 @@ public void onClickAddFriend(View v) {
}

public void onClickVoiceCallFriend(View v) {

/** Curent error when using this code
* 09-04 03:05:12.075 13525-13525/im.tox.antox W/dalvikvm﹕ JNI WARNING: JNI method called with exception pending
* 09-04 03:05:12.075 13525-13525/im.tox.antox W/dalvikvm﹕ in Lim/tox/jtoxcore/JTox;.toxav_call:(JILim/tox/jtoxcore/ToxCodecSettings;I)I (GetFieldID)
* 09-04 03:05:12.075 13525-13525/im.tox.antox W/dalvikvm﹕ Pending exception is:
* 09-04 03:05:12.075 13525-13525/im.tox.antox I/dalvikvm﹕ java.lang.NoSuchFieldError: no field with name='call_type' signature='Lim/tox/jtoxcore/ToxCodecSettings' in class Lim/tox/jtoxcore/ToxCodecSettings;
*/
ToxCodecSettings toxCodecSettings = new ToxCodecSettings(ToxCallType.TYPE_AUDIO, 0, 0, 0, 64000, 20, 48000, 1);
AntoxFriend friend = toxSingleton.getAntoxFriend(toxSingleton.activeKey);
int userID = friend.getFriendnumber();
try {
toxSingleton.jTox.avCall(userID, toxCodecSettings, 10);
} catch (ToxException e) {
}
}

public void onClickVideoCallFriend(View v) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package im.tox.antox.callbacks;

import android.content.Context;
import android.util.Log;

import im.tox.antox.utils.AntoxFriend;
import im.tox.jtoxcore.callbacks.OnAudioDataCallback;
Expand All @@ -17,6 +18,6 @@ public AntoxOnAudioDataCallback(Context ctx) {
}

public void execute(int callID, byte[] data) {

Log.d("OnAudioDataCallback", "Received callback from: " + callID);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package im.tox.antox.callbacks;

import android.content.Context;
import android.util.Log;

import im.tox.antox.tox.ToxSingleton;
import im.tox.antox.utils.AntoxFriend;
import im.tox.jtoxcore.ToxAvCallbackID;
import im.tox.jtoxcore.ToxCallType;
import im.tox.jtoxcore.ToxCodecSettings;
import im.tox.jtoxcore.ToxException;
import im.tox.jtoxcore.callbacks.OnAvCallbackCallback;

/**
Expand All @@ -18,6 +23,12 @@ public AntoxOnAvCallbackCallback(Context ctx) {
}

public void execute(int callID, ToxAvCallbackID callbackID) {

Log.d("OnAvCallbackCallback", "Received a callback from: " + callID);
ToxSingleton toxSingleton = ToxSingleton.getInstance();
ToxCodecSettings toxCodecSettings = new ToxCodecSettings(ToxCallType.TYPE_AUDIO, 0, 0, 0, 64000, 20, 48000, 1);
try {
toxSingleton.jTox.avAnswer(0, toxCodecSettings);
} catch (ToxException e) {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package im.tox.antox.callbacks;

import android.content.Context;
import android.util.Log;

import im.tox.antox.utils.AntoxFriend;
import im.tox.jtoxcore.callbacks.OnVideoDataCallback;
Expand All @@ -17,6 +18,6 @@ public AntoxOnVideoDataCallback(Context ctx) {
}

public void execute(int callID, byte[] data, int width, int height) {

Log.d("OnVideoDataCallback", "Received a callback from: " + callID);
}
}
123 changes: 61 additions & 62 deletions app/src/main/java/im/tox/antox/fragments/ContactsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;

Expand Down Expand Up @@ -189,7 +190,7 @@ public boolean onItemLongClick(AdapterView<?> parent, View itemView, int index,
items = new CharSequence[]{
getResources().getString(R.string.friend_action_profile),
getResources().getString(R.string.friend_action_delete),
getResources().getString(R.string.friend_action_deletechat),
getResources().getString(R.string.friend_action_delete_chat),
getResources().getString(R.string.friend_action_block)
};
}
Expand Down Expand Up @@ -262,14 +263,12 @@ protected void onPostExecute(Void result) {
startActivity(profile);
break;
case 1:
//Delete friend
// Delete friend
showDeleteFriendDialog(getActivity(), key);
break;
case 2:
AntoxDB db = new AntoxDB(getActivity());
db.deleteChat(key);
db.close();
toxSingleton.updateMessages(getActivity());
// Delete chat logs
showDeleteChatDialog(getActivity(), key);
break;
case 3:
showBlockDialog(getActivity(), key);
Expand Down Expand Up @@ -313,7 +312,7 @@ public void afterTextChanged(Editable editable) {
public void showBlockDialog(final Context context, String fkey) {
final String key = fkey;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(getResources().getString(R.string.friend_action_block_confirmation))
builder.setMessage(getResources().getString(R.string.friend_action_block_friend_confirmation))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.button_yes),
new DialogInterface.OnClickListener() {
Expand All @@ -337,77 +336,77 @@ public void onClick(DialogInterface dialog,

public void showDeleteFriendDialog(Context context, String fkey) {
final String key= fkey;
View delete_friend_dialog = View.inflate(context, R.layout.dialog_delete_friend,null);
final CheckBox deleteLogsCheckboxView = (CheckBox) delete_friend_dialog.findViewById(R.id.deleteChatLogsCheckBox);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(getResources().getString(R.string.contacts_clear_saved_logs))
builder//.setMessage(getResources().getString(R.string.friend_action_delete_friend_confirmation))
.setView(delete_friend_dialog)
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.button_yes),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
class DeleteFriendAndChat extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
AntoxDB db = new AntoxDB(getActivity());
db.deleteChat(key);
db.deleteFriend(key);
db.close();
// Remove friend from tox friend list
AntoxFriend friend = toxSingleton.getAntoxFriend(key);
if (friend != null) {

try {
toxSingleton.jTox.deleteFriend(friend.getFriendnumber());
} catch (ToxException e) {
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
toxSingleton.updateFriendsList(getActivity());
toxSingleton.updateMessages(getActivity());
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
class DeleteFriendAndChat extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
AntoxDB db = new AntoxDB(getActivity());
if (deleteLogsCheckboxView.isChecked())
db.deleteChat(key);
db.deleteFriend(key);
db.close();
// Remove friend from tox friend list
AntoxFriend friend = toxSingleton.getAntoxFriend(key);
if (friend != null) {

try {
toxSingleton.jTox.deleteFriend(friend.getFriendnumber());
} catch (ToxException e) {
}
}
return null;
}

new DeleteFriendAndChat().execute();
@Override
protected void onPostExecute(Void result) {
toxSingleton.updateFriendsList(getActivity());
toxSingleton.updateMessages(getActivity());
}
}
)

new DeleteFriendAndChat().execute();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.show();
}

public void showDeleteChatDialog(Context context, String fkey) {
final String key= fkey;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(getResources().getString(R.string.friend_action_delete_chat_confirmation))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.button_yes),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
AntoxDB db = new AntoxDB(getActivity());
db.deleteChat(key);
db.close();
toxSingleton.updateMessages(getActivity());
}
})
.setNegativeButton(getResources().getString(R.string.button_no),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
class DeleteFriend extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
AntoxDB db = new AntoxDB(getActivity());
db.deleteFriend(key);
db.close();
// Remove friend from tox friend list
AntoxFriend friend = toxSingleton.getAntoxFriend(key);
if (friend != null) {

try {
toxSingleton.jTox.deleteFriend(friend.getFriendnumber());
} catch (ToxException e) {
}
}

return null;
}
@Override
protected void onPostExecute(Void result) {
toxSingleton.updateFriendsList(getActivity());
}
}

new DeleteFriend().execute();
}
}
);
builder.show();
}

private class NameComparator implements Comparator<FriendInfo> {
@Override
public int compare(FriendInfo a, FriendInfo b) {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/im/tox/antox/tox/ToxSingleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public void initTox(Context ctx) {
qrFile = ctx.getFileStreamPath("userkey_qr.png");
dataFile = new ToxDataFile(ctx);

ToxOptions options = new ToxOptions(true, false, false);
ToxOptions options = new ToxOptions(true, true, false);

/* Choose appropriate constructor depending on if data file exists */
if (!dataFile.doesFileExist()) {
Expand Down Expand Up @@ -714,6 +714,9 @@ public void initTox(Context ctx) {
callbackHandler.registerOnFileSendRequestCallback(antoxOnFileSendRequestCallback);
callbackHandler.registerOnFileControlCallback(antoxOnFileControlCallback);
callbackHandler.registerOnFileDataCallback(antoxOnFileDataCallback);
callbackHandler.registerOnAudioDataCallback(antoxOnAudioDataCallback);
callbackHandler.registerOnAvCallbackCallback(antoxOnAvCallbackCallback);
callbackHandler.registerOnVideoDataCallback(antoxOnVideoDataCallback);

/* Load user details */
try {
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,27 @@
<string name="friend_action_profile">Profile</string>
<string name="friend_action_sendfile">Send File</string>
<string name="friend_action_delete">Remove Friend</string>
<string name="friend_action_delete_chat">Delete chat logs</string>
<string name="friend_action_move_to_group">Move to Group</string>
<string name="friend_action_block">Block</string>
<string name="friend_action_unblock">Unblock</string>
<string name="group_action_leave">Leave Group</string>
<string name="friend_action_deletechat">Delete Chat Logs</string>
<string name="friend_action_block_confirmation"> Blocking this user will remove them from your friends list and you will no longer see friend
requests from them. Are you sure you wish to continue?</string>
<string name="toast_succ_move_user">Contact has been moved successfully</string>
<string name="contacts_actions_on">Actions on</string>
<string name="contacts_clear_saved_logs">Do you want to clear the saved chat logs as well?</string>
<string name="contacts_delimiter_requests">Requests</string>
<string name="contacts_delimiter_friends">Friends</string>

<!-- Delete Friend Dialog -->
<string name="friend_action_delete_friend_confirmation">Are you sure you want to remove this friend?</string>

<!-- Delete Chat Logs Dialog -->
<string name="friend_action_delete_chat_confirmation">Are you sure you want to delete the chat logs?</string>

<!-- Block Friend Dialog -->
<string name="friend_action_block_friend_confirmation">Blocking this user will remove them from your friends list and you will no longer see friend
requests from them.\n\nAre you sure you wish to continue?</string>

<!-- Chat Fragment -->
<string name="attachment_photo">Attach photo</string>
<string name="attachment_takephoto">Take photo</string>
Expand Down

0 comments on commit 8a08b58

Please sign in to comment.