-
Notifications
You must be signed in to change notification settings - Fork 194
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
Voice recording #204
Changes from 87 commits
88deba1
e595fbf
5870540
e22a9f6
69119b8
8c18ab9
cd52fec
bf4a0e7
5a9f04a
938547c
975f8cc
7034354
0e38f25
32d8aec
0a69808
658ef02
d404633
42032b9
922675c
9ed9f8a
eb07367
a31207b
be3fc75
21e0053
19b934b
fcb0a01
2b1444d
b2fedce
b3dfdba
cc0c9c4
d051a67
cc3b72d
1094d7c
89f3fb3
9ee0e33
36fd9fe
444399e
bd332e6
f97890e
a956075
37058a2
daf6b98
6d405f2
e3293f5
0a458dc
e6d6760
63c8a70
863c320
995bab8
e0dc245
681dbb1
6db04eb
55df7ed
f745e8c
89cb81b
19f988b
00e2df6
2876b16
1a16236
ff340df
b02f371
6fdfa0d
6916917
80d8a5e
c5217d4
e730f3f
079605b
8d81282
b4fb7b8
e329113
35ded8a
55e7bc3
94e665b
6219131
0a13196
703d188
dedcaa0
d0ba188
64e8070
07fbbd8
7afa7d0
630c418
310f10f
6cf6b34
5c17815
5119faf
18d3a5d
3c70b8d
13fe14d
dac5a1f
c142c0a
4299b56
a04494b
b82e49d
66c8e67
40cb16d
32c2b92
855a5cf
6614c39
ef08ebd
42b900c
e5e76ca
24791b8
2706aad
771edd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ public class CompositeMessage { | |
@SuppressWarnings("unchecked") | ||
private static final Class<AttachmentComponent>[] TRY_COMPONENTS = new Class[] { | ||
ImageComponent.class, | ||
AudioComponent.class, | ||
VCardComponent.class, | ||
}; | ||
|
||
|
@@ -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; | ||
|
||
|
@@ -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() { | ||
|
@@ -201,7 +202,7 @@ public int getStatus() { | |
|
||
@Override | ||
public String toString() { | ||
// FIXME include components | ||
// FIXME include components | ||
return getClass().getSimpleName() + ": id=" + mId; | ||
} | ||
|
||
|
@@ -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. */ | ||
|
@@ -253,7 +254,7 @@ public MessageComponent<?> getComponent(Class<? extends MessageComponent<?>> typ | |
} | ||
|
||
public List<MessageComponent<?>> getComponents() { | ||
return mComponents; | ||
return mComponents; | ||
} | ||
|
||
private void populateFromCursor(Cursor c) { | ||
|
@@ -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, | ||
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); | ||
} | ||
|
||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tabs |
||
|
||
} | ||
} | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tabs |
||
// TODO | ||
return msg; | ||
} | ||
|
||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
There was a problem hiding this comment.
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 :-)