Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voice recording #204

Merged
merged 105 commits into from
Nov 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
88deba1
Initial Audio Dialog
acappelli Dec 20, 2013
e595fbf
Implementing Audio Attachments
acappelli Jan 3, 2014
5870540
Added NineOldAndroids Library for API<11
acappelli Jan 7, 2014
e22a9f6
New CircularSeekBar.
acappelli Jan 31, 2014
69119b8
CircularSeekBar Improvements
acappelli Feb 7, 2014
8c18ab9
Merge branch 'master' into audio_message
acappelli Jun 11, 2014
cd52fec
Added Audio on Attachment Menu
acappelli Jun 11, 2014
bf4a0e7
AudioComponent Message.
acappelli Jun 13, 2014
5a9f04a
Merge branch 'master' into audio_message
acappelli Jun 13, 2014
938547c
Merge branch 'master' into audio_message
daniele-athome Jun 15, 2014
975f8cc
Merge branch 'master' into audio_message
acappelli Jun 23, 2014
7034354
Send Audio Message
acappelli Jul 1, 2014
0e38f25
Merge branch 'master' into audio_message
acappelli Jul 1, 2014
32d8aec
Added AudioComponent on CompositeMessage
acappelli Jul 1, 2014
0a69808
Merge branch 'master' into audio_message
acappelli Jul 4, 2014
658ef02
Improvements
acappelli Jul 4, 2014
d404633
Corrections and improvements
acappelli Jul 4, 2014
42032b9
Corrections and Improvements
acappelli Jul 4, 2014
922675c
Merge branch 'master' into audio_message
acappelli Jul 6, 2014
9ed9f8a
Merge branch 'master' into audio_message
acappelli Jul 6, 2014
eb07367
Corrections and Improvements
acappelli Jul 9, 2014
a31207b
Merge branch 'master' into audio_message
acappelli Jul 9, 2014
be3fc75
Corrections and Improvements
acappelli Jul 10, 2014
21e0053
Merge branch 'master' into audio_message
daniele-athome Jul 11, 2014
19b934b
Added nineoldandroids to gradle dependencies
acappelli Jul 12, 2014
fcb0a01
Merge branch 'master' into audio_message
daniele-athome Jul 12, 2014
2b1444d
Merge branch 'master' into audio_message
acappelli Jul 12, 2014
b2fedce
Merge branch 'composite_balloon' into audio_message
acappelli Jul 15, 2014
b3dfdba
Merge branch 'master' into audio_message
acappelli Jul 18, 2014
cc0c9c4
Merge branch 'master' into audio_message
daniele-athome Jul 21, 2014
d051a67
Added handling of Audio Component in Composite Message
acappelli Jul 21, 2014
cc3b72d
Merge branch 'audio_message' of https://github.com/kontalk/androidcli…
acappelli Jul 21, 2014
1094d7c
Merge branch 'composite_balloon' into audio_message
acappelli Jul 21, 2014
89f3fb3
Incoming Support Audio Message
acappelli Jul 21, 2014
9ee0e33
Added Open Audio to ContextualMenu
acappelli Jul 23, 2014
36fd9fe
Merge remote-tracking branch 'origin/composite_balloon' into audio_me…
daniele-athome Jul 24, 2014
444399e
Added Audio Player inside balloon
acappelli Jul 25, 2014
bd332e6
Merge branch 'audio_message' of https://github.com/kontalk/androidcli…
acappelli Jul 25, 2014
f97890e
Merge branch 'master' into audio_message
daniele-athome Jul 25, 2014
a956075
Merge branch 'audio_message' of github.com:kontalk/androidclient into…
daniele-athome Jul 25, 2014
37058a2
Merge branch 'master' into audio_message
acappelli Jul 26, 2014
daf6b98
Added tracking touch control to player seekbar
acappelli Jul 26, 2014
6d405f2
Improvements on AudioContentView
acappelli Jul 27, 2014
e3293f5
Removed Audio Player release() from onPause() of ComposeMessage
acappelli Jul 29, 2014
0a458dc
Merge branch 'master' into audio_message
daniele-athome Aug 3, 2014
e6d6760
Added callback for control MediaPlayer from ComposeMessage.
acappelli Aug 9, 2014
63c8a70
Merge branch 'audio_message' of https://github.com/kontalk/androidcli…
acappelli Aug 9, 2014
863c320
Merge branch 'master' into audio_message
acappelli Aug 9, 2014
995bab8
Merge branch 'master' into audio_message
acappelli Aug 9, 2014
e0dc245
Improvemnts on MediaPlayer logic
acappelli Aug 11, 2014
681dbb1
Merge branch 'master' into audio_message
acappelli Aug 11, 2014
6db04eb
Merge branch 'master' into audio_message
acappelli Aug 11, 2014
55df7ed
Improvements on logic and SeekBar update
acappelli Aug 11, 2014
f745e8c
Improvements on SeekBar
acappelli Aug 11, 2014
89cb81b
Merge branch 'master' into audio_message
acappelli Aug 11, 2014
19f988b
Fix ContentView Interface
acappelli Aug 11, 2014
00e2df6
Merge branch 'master' into audio_message
acappelli Aug 12, 2014
2876b16
Merge branch 'master' into audio_message
acappelli Aug 14, 2014
1a16236
Checkstyle fixes
acappelli Aug 14, 2014
ff340df
Fix API level compatibility
acappelli Aug 14, 2014
b02f371
Fix MediaPlayer issues
acappelli Aug 14, 2014
6fdfa0d
Merge branch 'master' into audio_message
acappelli Aug 14, 2014
6916917
Merge branch 'master' into audio_message
daniele-athome Aug 16, 2014
80d8a5e
Added Download Image if audio message is not downloaded yet
acappelli Aug 17, 2014
c5217d4
Added timestamp for audio message
acappelli Aug 17, 2014
e730f3f
Merge branch 'master' into audio_message
acappelli Aug 17, 2014
079605b
Improvement on timestamp and mediaplayer seekbar
acappelli Aug 17, 2014
8d81282
Checkstyle fixes
acappelli Aug 17, 2014
b4fb7b8
Fixed encryption on audio message
acappelli Aug 17, 2014
e329113
Merge branch 'master' into audio_message
acappelli Aug 17, 2014
35ded8a
Fix error handling on audio message
acappelli Aug 17, 2014
55e7bc3
Merge branch 'master' into audio_message
acappelli Aug 17, 2014
94e665b
Added error string to resource xml
acappelli Aug 18, 2014
6219131
Improvements
acappelli Aug 18, 2014
0a13196
Fixed audio error
acappelli Aug 18, 2014
703d188
Improvements
acappelli Aug 18, 2014
dedcaa0
Improvements on media player time stamp
acappelli Aug 18, 2014
d0ba188
Merge branch 'master' into audio_message
daniele-athome Aug 19, 2014
64e8070
Remove garbage
daniele-athome Aug 19, 2014
07fbbd8
Fix merge typo
daniele-athome Aug 19, 2014
7afa7d0
Merge branch 'master' into audio_message
acappelli Aug 19, 2014
630c418
Merge branch 'master' into audio_message
acappelli Aug 19, 2014
310f10f
Merge branch 'master' into audio_message
acappelli Aug 19, 2014
6cf6b34
Merge branch 'master' into audio_message
acappelli Aug 21, 2014
5c17815
Merge branch 'master' into audio_message
acappelli Aug 24, 2014
5119faf
Merge branch 'master' into audio_message
acappelli Aug 26, 2014
18d3a5d
Merge branch 'master' into audio_message
acappelli Aug 26, 2014
3c70b8d
Merge branch 'master' into audio_message
acappelli Aug 29, 2014
13fe14d
Merge branch 'master' into audio_message
acappelli Aug 29, 2014
dac5a1f
Merge branch 'master' into audio_message
acappelli Aug 31, 2014
c142c0a
Merge branch 'audio_message' of https://github.com/kontalk/androidcli…
acappelli Aug 31, 2014
4299b56
Merge branch 'master' into audio_message
acappelli Sep 1, 2014
a04494b
Merge branch 'audio_message' of https://github.com/kontalk/androidcli…
acappelli Sep 1, 2014
b82e49d
Added icons
acappelli Sep 2, 2014
66c8e67
New icons
acappelli Sep 2, 2014
40cb16d
Merge branch 'master' into audio_message
acappelli Sep 7, 2014
32c2b92
Merge remote-tracking branch 'origin/master' into audio_message
acappelli Sep 8, 2014
855a5cf
Merge branch 'master' into audio_message
acappelli Sep 9, 2014
6614c39
Merge branch 'master' into audio_message
acappelli Oct 2, 2014
ef08ebd
Merge branch 'master' into audio_message
acappelli Oct 7, 2014
42b900c
Merge branch 'master' into audio_message
daniele-athome Oct 15, 2014
e5e76ca
Merge branch 'master' into audio_message
daniele-athome Nov 11, 2014
24791b8
Fix various code style, behaviour and interface issues
daniele-athome Nov 11, 2014
2706aad
Be sure media player was not disposed before using it
daniele-athome Nov 11, 2014
771edd3
Fix i18n
daniele-athome Nov 11, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//src/org/kontalk/ui/CircularSeekBar.java=UTF-8
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ task checkstyle(type: Checkstyle){
'googleplay/java/org/kontalk/billing/ProductDetails.java',
'googleplay/java/org/kontalk/billing/Purchase.java'
// 3rd-party code
exclude '**/IconContextMenu.java',
exclude '**/IconContextMenu.java', '**/CircularSeekBar.java',
'**/KeyboardAwareFrameLayout.java'
classpath = files()
}
Expand Down Expand Up @@ -66,6 +66,8 @@ dependencies {
compile 'com.madgag.spongycastle:pg:1.51.0.0'
compile 'com.googlecode.libphonenumber:libphonenumber:6.2.2'
compile 'dnsjava:dnsjava:2.1.6'
compile 'com.jcraft:jzlib:+'
compile 'com.nineoldandroids:library:2.4.0+'
compile 'com.jcraft:jzlib:1.1.3'
compile 'org.igniterealtime.smack:smack-android:4.1.0-alpha5'
compile 'org.igniterealtime.smack:smack-core:4.1.0-alpha5'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<!-- do not make telephony and touchscreen mandatory -->
<uses-feature android:name="android.hardware.telephony" android:required="false"/>
Expand Down
83 changes: 83 additions & 0 deletions app/src/main/java/org/kontalk/message/AudioComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Kontalk Android client
* Copyright (C) 2014 Kontalk Devteam <devteam@kontalk.org>

* 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.kontalk.message;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

import org.kontalk.util.MediaStorage;

/**
* Audio component.
* @author Andrea Cappelli
*/

public class AudioComponent extends AttachmentComponent {

static Map<String, String> MIME_TYPES = new HashMap<String, String>();
static {
MIME_TYPES.put("audio/3gpp", "3gp");
MIME_TYPES.put("audio/mpeg", "mp3");
MIME_TYPES.put("audio/mp4", "mp4");
MIME_TYPES.put("audio/wav", "wav");
MIME_TYPES.put("audio/aac", "aac");
MIME_TYPES.put("audio/flac", "flac");
}

public AudioComponent(String mime, Uri localUri, String fetchUrl, long length, boolean encrypted, int securityFlags) {
super(mime, null, localUri, fetchUrl, length, encrypted, securityFlags);
}

public static boolean supportsMimeType(String mime) {
return MIME_TYPES.containsKey(mime);
}

/** FIXME not used yet */
public boolean isValidMedia(Context context) {
Uri localUri = mContent.getLocalUri();
if (localUri != null) {
try {
return (MediaStorage.getLength(context, localUri) == mLength);
}
catch (Exception e) {
return false;
}
}

return false;
}

@Override
protected void populateFromCursor(Context context, Cursor c) {
// Nothing to do here
}

public static String buildMediaFilename(String id, String mime) {
return "audio" + id.substring(id.length() - 5) + "." + getFileExtension(mime);
}

/** Returns the file extension from the mime type. */
public static String getFileExtension(String mime) {
return MIME_TYPES.get(mime);
}
}
164 changes: 85 additions & 79 deletions app/src/main/java/org/kontalk/message/CompositeMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class CompositeMessage {
@SuppressWarnings("unchecked")
private static final Class<AttachmentComponent>[] TRY_COMPONENTS = new Class[] {
ImageComponent.class,
AudioComponent.class,
VCardComponent.class,
};

Expand Down Expand Up @@ -130,7 +131,7 @@ public class CompositeMessage {

/** Creates a new composite message. */
public CompositeMessage(Context context, String id, long timestamp, String sender, boolean encrypted, int securityFlags) {
this();
this();

mContext = context;

Expand All @@ -147,7 +148,7 @@ public CompositeMessage(Context context, String id, long timestamp, String sende

/** Empty constructor for local use. */
private CompositeMessage() {
mComponents = new ArrayList<MessageComponent<?>>();
mComponents = new ArrayList<MessageComponent<?>>();
}

public String getId() {
Expand Down Expand Up @@ -201,7 +202,7 @@ public int getStatus() {

@Override
public String toString() {
// FIXME include components
// FIXME include components
return getClass().getSimpleName() + ": id=" + mId;
}

Expand Down Expand Up @@ -235,11 +236,11 @@ public void setSecurityFlags(int flags) {
}

public void addComponent(MessageComponent<?> c) {
mComponents.add(c);
mComponents.add(c);
}

public void clearComponents() {
mComponents.clear();
mComponents.clear();
}

/** Returns the first component of the given type. */
Expand All @@ -253,7 +254,7 @@ public MessageComponent<?> getComponent(Class<? extends MessageComponent<?>> typ
}

public List<MessageComponent<?>> getComponents() {
return mComponents;
return mComponents;
}

private void populateFromCursor(Cursor c) {
Expand Down Expand Up @@ -284,65 +285,70 @@ private void populateFromCursor(Cursor c) {

// encrypted message - single raw encrypted component
if (mEncrypted) {
RawComponent raw = new RawComponent(body, true, mSecurityFlags);
addComponent(raw);
RawComponent raw = new RawComponent(body, true, mSecurityFlags);
addComponent(raw);
}

else {

String mime = c.getString(COLUMN_BODY_MIME);

if (body != null) {

// text data
if (TextComponent.supportsMimeType(mime)) {
TextComponent txt = new TextComponent(new String(body));
addComponent(txt);
String mime = c.getString(COLUMN_BODY_MIME);

if (body != null) {

// text data
if (TextComponent.supportsMimeType(mime)) {
TextComponent txt = new TextComponent(new String(body));
addComponent(txt);
}

// unknown data
else {
RawComponent raw = new RawComponent(body, false, mSecurityFlags);
addComponent(raw);
}
}

// attachment
String attMime = c.getString(COLUMN_ATTACHMENT_MIME);
if (attMime != null) {

String attPreview = c.getString(COLUMN_ATTACHMENT_PREVIEW_PATH);
String attLocal = c.getString(COLUMN_ATTACHMENT_LOCAL_URI);
String attFetch = c.getString(COLUMN_ATTACHMENT_FETCH_URL);
long attLength = c.getLong(COLUMN_ATTACHMENT_LENGTH);
boolean attEncrypted = c.getInt(COLUMN_ATTACHMENT_ENCRYPTED) > 0;
int attSecurityFlags = c.getInt(COLUMN_ATTACHMENT_SECURITY_FLAGS);

AttachmentComponent att = null;
File previewFile = (attPreview != null) ? new File(attPreview) : null;
Uri localUri = (attLocal != null) ? Uri.parse(attLocal) : null;

if (ImageComponent.supportsMimeType(attMime)) {
att = new ImageComponent(attMime, previewFile,
localUri, attFetch, attLength,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will share my Android Studio code style configuration :-)

attEncrypted, attSecurityFlags);
}

else if (VCardComponent.supportsMimeType(attMime)) {
att = new VCardComponent(previewFile,
localUri, attFetch, attLength,
attEncrypted, attSecurityFlags);
}

else if (AudioComponent.supportsMimeType(attMime)) {
att = new AudioComponent(attMime,
localUri, attFetch,
attLength, attEncrypted, attSecurityFlags);
}

// unknown data
else {
RawComponent raw = new RawComponent(body, false, mSecurityFlags);
addComponent(raw);
}
}

// attachment
String attMime = c.getString(COLUMN_ATTACHMENT_MIME);
if (attMime != null) {

String attPreview = c.getString(COLUMN_ATTACHMENT_PREVIEW_PATH);
String attLocal = c.getString(COLUMN_ATTACHMENT_LOCAL_URI);
String attFetch = c.getString(COLUMN_ATTACHMENT_FETCH_URL);
long attLength = c.getLong(COLUMN_ATTACHMENT_LENGTH);
boolean attEncrypted = c.getInt(COLUMN_ATTACHMENT_ENCRYPTED) > 0;
int attSecurityFlags = c.getInt(COLUMN_ATTACHMENT_SECURITY_FLAGS);

AttachmentComponent att = null;
File previewFile = (attPreview != null) ? new File(attPreview) : null;
Uri localUri = (attLocal != null) ? Uri.parse(attLocal) : null;

if (ImageComponent.supportsMimeType(attMime)) {
att = new ImageComponent(attMime, previewFile,
localUri, attFetch, attLength,
attEncrypted, attSecurityFlags);
att.populateFromCursor(mContext, c);
}
// TODO other type of attachments

else if (VCardComponent.supportsMimeType(attMime)) {
att = new VCardComponent(previewFile,
localUri, attFetch, attLength,
attEncrypted, attSecurityFlags);
if (att != null) {
att.populateFromCursor(mContext, c);
}

// TODO other type of attachments


if (att != null)
addComponent(att);
}

}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs


}
}
Expand All @@ -364,9 +370,9 @@ protected void clear() {

/** Builds an instance from a {@link Cursor} row. */
public static CompositeMessage fromCursor(Context context, Cursor cursor) {
CompositeMessage msg = new CompositeMessage();
msg.populateFromCursor(cursor);
// TODO
CompositeMessage msg = new CompositeMessage();
msg.populateFromCursor(cursor);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs

// TODO
return msg;
}

Expand All @@ -380,27 +386,27 @@ public static void startQuery(AsyncQueryHandler handler, int token, long threadI

/** A sample text content from class name and mime type. */
public static String getSampleTextContent(String mime) {
// TODO i18n
// FIXME using reflection BAD BAD BAD !!!
for (Class<AttachmentComponent> klass : TRY_COMPONENTS) {
Boolean supported = null;
try {
Method m = klass.getMethod("supportsMimeType", new Class[] { String.class });
supported = (Boolean) m.invoke(klass, mime);
}
catch (Exception e) {
// ignored
}

if (supported != null && supported.booleanValue()) {
String cname = klass.getSimpleName();
return cname.substring(0, cname.length() - SUFFIX_LENGTH) +
": " + mime;
}
}

// no supporting component - return mime
return "Unknown: " + mime;
// TODO i18n
// FIXME using reflection BAD BAD BAD !!!
for (Class<AttachmentComponent> klass : TRY_COMPONENTS) {
Boolean supported = null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful using tabs!! Configure your IDE to always use spaces. Please also convert this code to spaces and commit it again.

try {
Method m = klass.getMethod("supportsMimeType", new Class[] { String.class });
supported = (Boolean) m.invoke(klass, mime);
}
catch (Exception e) {
// ignored
}

if (supported != null && supported.booleanValue()) {
String cname = klass.getSimpleName();
return cname.substring(0, cname.length() - SUFFIX_LENGTH) +
": " + mime;
}
}

// no supporting component - return mime
return "Unknown: " + mime;
}

/** Still unused.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.kontalk.client.ServerReceipt;
import org.kontalk.client.ServerReceiptRequest;
import org.kontalk.crypto.Coder;
import org.kontalk.message.AudioComponent;
import org.kontalk.message.CompositeMessage;
import org.kontalk.message.ImageComponent;
import org.kontalk.message.MessageComponent;
Expand Down Expand Up @@ -266,6 +267,8 @@ else if (ext instanceof AckServerReceipt) {

}

// TODO duplicated code (MessageUtils#decryptMessage)

// out of band data
PacketExtension _media = m.getExtension(OutOfBandData.ELEMENT_NAME, OutOfBandData.NAMESPACE);
if (_media != null && _media instanceof OutOfBandData) {
Expand Down Expand Up @@ -319,6 +322,11 @@ else if (VCardComponent.supportsMimeType(mime)) {
encrypted, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
}

else if (AudioComponent.supportsMimeType(mime)) {
attachment = new AudioComponent(mime, null, fetchUrl, length,
encrypted, encrypted ? Coder.SECURITY_BASIC : Coder.SECURITY_CLEARTEXT);
}

// TODO other types

if (attachment != null)
Expand Down
Loading