Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccim_sdk_android
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
ccim_sdk_android
Commits
b573ce5e
Commit
b573ce5e
authored
Dec 06, 2021
by
sheteng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开始测试 1
parent
6cf704cf
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
182 additions
and
91 deletions
+182
-91
app/build.gradle
app/build.gradle
+0
-2
app/src/main/java/com/ccwangluo/im/FirstFragment.java
app/src/main/java/com/ccwangluo/im/FirstFragment.java
+6
-1
app/src/main/java/com/ccwangluo/im/MainActivity.java
app/src/main/java/com/ccwangluo/im/MainActivity.java
+2
-10
app/src/main/java/com/ccwangluo/im/adapter/ChannelMsgAdapter.java
...main/java/com/ccwangluo/im/adapter/ChannelMsgAdapter.java
+16
-0
app/src/main/java/com/ccwangluo/im/ui/dashboard/ConnectFragment.java
...n/java/com/ccwangluo/im/ui/dashboard/ConnectFragment.java
+16
-1
app/src/main/java/com/ccwangluo/im/ui/dashboard/ContactsFragment.java
.../java/com/ccwangluo/im/ui/dashboard/ContactsFragment.java
+9
-0
app/src/main/java/com/ccwangluo/im/ui/login/LoginActivity.java
...rc/main/java/com/ccwangluo/im/ui/login/LoginActivity.java
+0
-2
app/src/main/java/com/ccwangluo/im/ui/notifications/ConnectChannelFragment.java
...ccwangluo/im/ui/notifications/ConnectChannelFragment.java
+16
-1
app/src/main/java/com/ccwangluo/im/ui/notifications/NotificationsFragment.java
.../ccwangluo/im/ui/notifications/NotificationsFragment.java
+16
-0
app/src/main/res/layout/activity_login.xml
app/src/main/res/layout/activity_login.xml
+2
-2
ccim/src/main/java/com/ccwangluo/ccim/CCIMClient.java
ccim/src/main/java/com/ccwangluo/ccim/CCIMClient.java
+22
-17
ccim/src/main/java/com/ccwangluo/ccim/manage/ChannelManager.java
...c/main/java/com/ccwangluo/ccim/manage/ChannelManager.java
+1
-1
ccim/src/main/java/com/ccwangluo/ccim/manage/ContactManager.java
...c/main/java/com/ccwangluo/ccim/manage/ContactManager.java
+22
-1
ccim/src/main/java/com/ccwangluo/ccim/manage/MessageManager.java
...c/main/java/com/ccwangluo/ccim/manage/MessageManager.java
+9
-7
ccim/src/main/java/com/ccwangluo/ccim/manage/SocketManager.java
...rc/main/java/com/ccwangluo/ccim/manage/SocketManager.java
+2
-5
ccim/src/main/java/com/ccwangluo/ccim/socket/NettyChatClient.java
.../main/java/com/ccwangluo/ccim/socket/NettyChatClient.java
+17
-18
ccim/src/main/java/com/ccwangluo/ccim/util/ErrorCode.java
ccim/src/main/java/com/ccwangluo/ccim/util/ErrorCode.java
+1
-0
ccim/src/main/java/com/ccwangluo/ccim/util/FileUtils.java
ccim/src/main/java/com/ccwangluo/ccim/util/FileUtils.java
+12
-10
ccim/src/main/java/com/ccwangluo/ccim/util/MediaHelper.java
ccim/src/main/java/com/ccwangluo/ccim/util/MediaHelper.java
+13
-13
No files found.
app/build.gradle
View file @
b573ce5e
...
@@ -44,9 +44,7 @@ dependencies {
...
@@ -44,9 +44,7 @@ dependencies {
implementation
'androidx.recyclerview:recyclerview:1.2.0'
implementation
'androidx.recyclerview:recyclerview:1.2.0'
def
multidex_version
=
"2.0.1"
def
multidex_version
=
"2.0.1"
implementation
"androidx.multidex:multidex:$multidex_version"
implementation
"androidx.multidex:multidex:$multidex_version"
def
lifecycle_version
=
"2.3.1"
def
lifecycle_version
=
"2.3.1"
implementation
"androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation
"androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation
"androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation
"androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation
'androidx.appcompat:appcompat:1.3.1'
implementation
'androidx.appcompat:appcompat:1.3.1'
...
...
app/src/main/java/com/ccwangluo/im/FirstFragment.java
View file @
b573ce5e
...
@@ -277,7 +277,12 @@ public class FirstFragment extends Fragment {
...
@@ -277,7 +277,12 @@ public class FirstFragment extends Fragment {
binding
.
startRecordAudioMessage
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
binding
.
startRecordAudioMessage
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
View
v
)
{
public
void
onClick
(
View
v
)
{
CCIMClient
.
getInstance
().
startRecordAudioMessage
(
getActivity
());
CCIMClient
.
getInstance
().
startRecordAudioMessage
(
getActivity
(),
new
ResultCallback
()
{
@Override
public
void
onSuccess
()
{
}
});
}
}
});
});
binding
.
stopAndSendAudioMessage
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
binding
.
stopAndSendAudioMessage
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
...
...
app/src/main/java/com/ccwangluo/im/MainActivity.java
View file @
b573ce5e
package
com.ccwangluo.im
;
package
com.ccwangluo.im
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.view.Menu
;
import
com.ccwangluo.ccim.util.HmacUtil
;
import
android.view.MenuItem
;
import
com.google.android.material.snackbar.Snackbar
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.view.View
;
import
androidx.navigation.NavController
;
import
androidx.navigation.NavController
;
import
androidx.navigation.Navigation
;
import
androidx.navigation.Navigation
;
import
androidx.navigation.ui.AppBarConfiguration
;
import
androidx.navigation.ui.AppBarConfiguration
;
...
@@ -16,9 +11,6 @@ import androidx.navigation.ui.NavigationUI;
...
@@ -16,9 +11,6 @@ import androidx.navigation.ui.NavigationUI;
import
com.ccwangluo.im.databinding.ActivityMainBinding
;
import
com.ccwangluo.im.databinding.ActivityMainBinding
;
import
android.view.Menu
;
import
android.view.MenuItem
;
public
class
MainActivity
extends
AppCompatActivity
{
public
class
MainActivity
extends
AppCompatActivity
{
private
AppBarConfiguration
appBarConfiguration
;
private
AppBarConfiguration
appBarConfiguration
;
...
...
app/src/main/java/com/ccwangluo/im/adapter/ChannelMsgAdapter.java
View file @
b573ce5e
...
@@ -7,10 +7,13 @@ import android.view.View;
...
@@ -7,10 +7,13 @@ import android.view.View;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.BaseAdapter
;
import
android.widget.BaseAdapter
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
com.ccwangluo.ccim.CCIMClient
;
import
com.ccwangluo.ccim.listener.ResultCallback
;
import
com.ccwangluo.ccim.modle.MessageContent
;
import
com.ccwangluo.ccim.modle.MessageContent
;
import
com.ccwangluo.im.R
;
import
com.ccwangluo.im.R
;
...
@@ -75,6 +78,19 @@ public class ChannelMsgAdapter extends BaseAdapter {
...
@@ -75,6 +78,19 @@ public class ChannelMsgAdapter extends BaseAdapter {
}
else
{
}
else
{
mHolder
.
msg_content
.
setText
(
"语音消息"
);
mHolder
.
msg_content
.
setText
(
"语音消息"
);
}
}
convertView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
if
(
messageContent
.
getMsgType
()
==
MessageContent
.
MessageType
.
MESSAGE_TYPE_VOICE
)
{
CCIMClient
.
getInstance
().
startPlayAudio
(
messageContent
.
getMsgId
(),
new
ResultCallback
()
{
@Override
public
void
onSuccess
()
{
Toast
.
makeText
(
context
,
"播放成功"
,
Toast
.
LENGTH_SHORT
).
show
();
}
});
}
}
});
return
convertView
;
return
convertView
;
}
}
...
...
app/src/main/java/com/ccwangluo/im/ui/dashboard/ConnectFragment.java
View file @
b573ce5e
...
@@ -12,6 +12,7 @@ import androidx.lifecycle.Observer;
...
@@ -12,6 +12,7 @@ import androidx.lifecycle.Observer;
import
androidx.lifecycle.ViewModelProvider
;
import
androidx.lifecycle.ViewModelProvider
;
import
com.ccwangluo.ccim.CCIMClient
;
import
com.ccwangluo.ccim.CCIMClient
;
import
com.ccwangluo.ccim.listener.ResultCallback
;
import
com.ccwangluo.ccim.modle.Contact
;
import
com.ccwangluo.ccim.modle.Contact
;
import
com.ccwangluo.ccim.modle.MessageContent
;
import
com.ccwangluo.ccim.modle.MessageContent
;
import
com.ccwangluo.ccim.listener.ResultEventCallback
;
import
com.ccwangluo.ccim.listener.ResultEventCallback
;
...
@@ -73,6 +74,11 @@ public class ConnectFragment extends Fragment {
...
@@ -73,6 +74,11 @@ public class ConnectFragment extends Fragment {
loginViewModel
.
addPrivateMsg
(
messageContent
);
loginViewModel
.
addPrivateMsg
(
messageContent
);
Toast
.
makeText
(
getContext
(),
"send Success"
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
getContext
(),
"send Success"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
@Override
public
void
onFailed
(
int
errorCode
)
{
Toast
.
makeText
(
getContext
(),
"send onFailed :"
+
errorCode
,
Toast
.
LENGTH_LONG
).
show
();
}
});
});
}
}
});
});
...
@@ -88,10 +94,19 @@ public class ConnectFragment extends Fragment {
...
@@ -88,10 +94,19 @@ public class ConnectFragment extends Fragment {
loginViewModel
.
addPrivateMsg
(
message
);
loginViewModel
.
addPrivateMsg
(
message
);
Toast
.
makeText
(
getContext
(),
"send Success"
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
getContext
(),
"send Success"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
@Override
public
void
onFailed
(
int
errorCode
)
{
Toast
.
makeText
(
getContext
(),
"send onFailed :"
+
errorCode
,
Toast
.
LENGTH_LONG
).
show
();
}
});
});
}
}
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_DOWN
)
{
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_DOWN
)
{
CCIMClient
.
getInstance
().
startRecordAudioMessage
(
getActivity
());
CCIMClient
.
getInstance
().
startRecordAudioMessage
(
getActivity
(),
new
ResultCallback
()
{
@Override
public
void
onSuccess
()
{
}
});
}
}
return
false
;
return
false
;
...
...
app/src/main/java/com/ccwangluo/im/ui/dashboard/ContactsFragment.java
View file @
b573ce5e
...
@@ -109,6 +109,10 @@ public class ContactsFragment extends Fragment {
...
@@ -109,6 +109,10 @@ public class ContactsFragment extends Fragment {
showSearchResultdialog
(
users
);
showSearchResultdialog
(
users
);
}
}
}
}
@Override
public
void
onFailed
(
int
errorCode
)
{
Toast
.
makeText
(
getContext
(),
" onFailed :"
+
errorCode
,
Toast
.
LENGTH_LONG
).
show
();
}
});
});
}
}
});
});
...
@@ -140,6 +144,11 @@ public class ContactsFragment extends Fragment {
...
@@ -140,6 +144,11 @@ public class ContactsFragment extends Fragment {
Toast
.
makeText
(
getContext
(),
"createContactGroup success"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getContext
(),
"createContactGroup success"
,
Toast
.
LENGTH_SHORT
).
show
();
loginViewModel
.
getContactList
();
loginViewModel
.
getContactList
();
}
}
@Override
public
void
onFailed
(
int
errorCode
)
{
Toast
.
makeText
(
getContext
(),
" onFailed :"
+
errorCode
,
Toast
.
LENGTH_LONG
).
show
();
}
});
});
}
}
});
});
...
...
app/src/main/java/com/ccwangluo/im/ui/login/LoginActivity.java
View file @
b573ce5e
...
@@ -6,7 +6,6 @@ import android.text.TextUtils;
...
@@ -6,7 +6,6 @@ import android.text.TextUtils;
import
android.view.View
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.EditText
;
import
android.widget.ProgressBar
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.app.AppCompatActivity
;
...
@@ -36,7 +35,6 @@ public class LoginActivity extends AppCompatActivity {
...
@@ -36,7 +35,6 @@ public class LoginActivity extends AppCompatActivity {
final
EditText
usernameEditText
=
binding
.
username
;
final
EditText
usernameEditText
=
binding
.
username
;
final
EditText
UserIdEditText
=
binding
.
password
;
final
EditText
UserIdEditText
=
binding
.
password
;
final
Button
loginButton
=
binding
.
login
;
final
Button
loginButton
=
binding
.
login
;
final
ProgressBar
loadingProgressBar
=
binding
.
loading
;
loginViewModel
.
loginState
.
observe
(
this
,
new
Observer
<
Boolean
>()
{
loginViewModel
.
loginState
.
observe
(
this
,
new
Observer
<
Boolean
>()
{
@Override
@Override
...
...
app/src/main/java/com/ccwangluo/im/ui/notifications/ConnectChannelFragment.java
View file @
b573ce5e
...
@@ -12,6 +12,7 @@ import androidx.lifecycle.Observer;
...
@@ -12,6 +12,7 @@ import androidx.lifecycle.Observer;
import
androidx.lifecycle.ViewModelProvider
;
import
androidx.lifecycle.ViewModelProvider
;
import
com.ccwangluo.ccim.CCIMClient
;
import
com.ccwangluo.ccim.CCIMClient
;
import
com.ccwangluo.ccim.listener.ResultCallback
;
import
com.ccwangluo.ccim.listener.ResultEventCallback
;
import
com.ccwangluo.ccim.listener.ResultEventCallback
;
import
com.ccwangluo.ccim.modle.MessageContent
;
import
com.ccwangluo.ccim.modle.MessageContent
;
import
com.ccwangluo.im.adapter.ChannelMsgAdapter
;
import
com.ccwangluo.im.adapter.ChannelMsgAdapter
;
...
@@ -71,6 +72,10 @@ public class ConnectChannelFragment extends Fragment {
...
@@ -71,6 +72,10 @@ public class ConnectChannelFragment extends Fragment {
loginViewModel
.
addChannelMsg
(
messageContent
);
loginViewModel
.
addChannelMsg
(
messageContent
);
Toast
.
makeText
(
getContext
(),
"send Success"
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
getContext
(),
"send Success"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
@Override
public
void
onFailed
(
int
errorCode
)
{
Toast
.
makeText
(
getContext
(),
"send onFailed :"
+
errorCode
,
Toast
.
LENGTH_LONG
).
show
();
}
});
});
}
}
});
});
...
@@ -86,10 +91,20 @@ public class ConnectChannelFragment extends Fragment {
...
@@ -86,10 +91,20 @@ public class ConnectChannelFragment extends Fragment {
loginViewModel
.
addChannelMsg
(
message
);
loginViewModel
.
addChannelMsg
(
message
);
Toast
.
makeText
(
getContext
(),
"send Success"
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
getContext
(),
"send Success"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
@Override
public
void
onFailed
(
int
errorCode
)
{
Toast
.
makeText
(
getContext
(),
"send onFailed :"
+
errorCode
,
Toast
.
LENGTH_LONG
).
show
();
}
});
});
}
}
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_DOWN
)
{
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_DOWN
)
{
CCIMClient
.
getInstance
().
startRecordAudioMessage
(
getActivity
());
CCIMClient
.
getInstance
().
startRecordAudioMessage
(
getActivity
(),
new
ResultCallback
()
{
@Override
public
void
onSuccess
()
{
}
});
}
}
return
false
;
return
false
;
...
...
app/src/main/java/com/ccwangluo/im/ui/notifications/NotificationsFragment.java
View file @
b573ce5e
...
@@ -97,6 +97,11 @@ public class NotificationsFragment extends Fragment {
...
@@ -97,6 +97,11 @@ public class NotificationsFragment extends Fragment {
Toast
.
makeText
(
getContext
(),
"join success"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getContext
(),
"join success"
,
Toast
.
LENGTH_SHORT
).
show
();
loginViewModel
.
addChannelId
(
Id
);
loginViewModel
.
addChannelId
(
Id
);
}
}
@Override
public
void
onFailed
(
int
errorCode
)
{
Toast
.
makeText
(
getContext
(),
" onFailed :"
+
errorCode
,
Toast
.
LENGTH_LONG
).
show
();
}
});
});
}
}
...
@@ -141,11 +146,17 @@ public class NotificationsFragment extends Fragment {
...
@@ -141,11 +146,17 @@ public class NotificationsFragment extends Fragment {
@Override
@Override
public
void
onSuccess
(
Long
aLong
)
{
public
void
onSuccess
(
Long
aLong
)
{
//获取剪贴板管理器:
//获取剪贴板管理器:
loginViewModel
.
addChannelId
(
aLong
);
ClipboardManager
cm
=
(
ClipboardManager
)
getContext
().
getSystemService
(
Context
.
CLIPBOARD_SERVICE
);
ClipboardManager
cm
=
(
ClipboardManager
)
getContext
().
getSystemService
(
Context
.
CLIPBOARD_SERVICE
);
ClipData
mClipData
=
ClipData
.
newPlainText
(
"Label"
,
aLong
.
toString
());
ClipData
mClipData
=
ClipData
.
newPlainText
(
"Label"
,
aLong
.
toString
());
cm
.
setPrimaryClip
(
mClipData
);
cm
.
setPrimaryClip
(
mClipData
);
Toast
.
makeText
(
getContext
(),
"create success,id copy success"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getContext
(),
"create success,id copy success"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
@Override
public
void
onFailed
(
int
errorCode
)
{
Toast
.
makeText
(
getContext
(),
" onFailed :"
+
errorCode
,
Toast
.
LENGTH_LONG
).
show
();
}
});
});
}
}
});
});
...
@@ -170,6 +181,11 @@ public class NotificationsFragment extends Fragment {
...
@@ -170,6 +181,11 @@ public class NotificationsFragment extends Fragment {
loginViewModel
.
removeChannelId
(
id
);
loginViewModel
.
removeChannelId
(
id
);
Toast
.
makeText
(
getContext
(),
"退出成功"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getContext
(),
"退出成功"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
@Override
public
void
onFailed
(
int
errorCode
)
{
Toast
.
makeText
(
getContext
(),
" onFailed :"
+
errorCode
,
Toast
.
LENGTH_LONG
).
show
();
}
});
});
break
;
break
;
}
}
...
...
app/src/main/res/layout/activity_login.xml
View file @
b573ce5e
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:hint=
"Username"
android:hint=
"Username"
android:text=
"1
5
"
android:text=
"1
8
"
android:inputType=
"textEmailAddress"
android:inputType=
"textEmailAddress"
android:selectAllOnFocus=
"true"
android:selectAllOnFocus=
"true"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"8dp"
android:layout_marginTop=
"8dp"
android:hint=
"UserId"
android:hint=
"UserId"
android:text=
"1
5
"
android:text=
"1
8
"
android:imeActionLabel=
"@string/action_sign_in_short"
android:imeActionLabel=
"@string/action_sign_in_short"
android:imeOptions=
"actionDone"
android:imeOptions=
"actionDone"
android:selectAllOnFocus=
"true"
android:selectAllOnFocus=
"true"
...
...
ccim/src/main/java/com/ccwangluo/ccim/CCIMClient.java
View file @
b573ce5e
...
@@ -4,9 +4,7 @@ import android.Manifest;
...
@@ -4,9 +4,7 @@ import android.Manifest;
import
android.content.Context
;
import
android.content.Context
;
import
android.os.Environment
;
import
android.os.Environment
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
androidx.fragment.app.FragmentActivity
;
import
androidx.fragment.app.FragmentActivity
;
import
com.ccwangluo.ccim.listener.ContactsCallBack
;
import
com.ccwangluo.ccim.listener.ContactsCallBack
;
import
com.ccwangluo.ccim.listener.OnClientConnectListener
;
import
com.ccwangluo.ccim.listener.OnClientConnectListener
;
import
com.ccwangluo.ccim.listener.OnConnectListener
;
import
com.ccwangluo.ccim.listener.OnConnectListener
;
...
@@ -28,13 +26,11 @@ import com.ccwangluo.ccim.util.MediaHelper;
...
@@ -28,13 +26,11 @@ import com.ccwangluo.ccim.util.MediaHelper;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.protobuf.util.JsonFormat
;
import
com.google.protobuf.util.JsonFormat
;
import
com.permissionx.guolindev.PermissionX
;
import
com.permissionx.guolindev.PermissionX
;
import
java.io.File
;
import
java.io.File
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
ccim.protocol.Chat
;
import
ccim.protocol.Chat
;
import
ccim.protocol.Message
;
import
ccim.protocol.Message
;
import
ccim.protocol.MessageSpec
;
import
ccim.protocol.MessageSpec
;
...
@@ -53,6 +49,7 @@ public class CCIMClient {
...
@@ -53,6 +49,7 @@ public class CCIMClient {
private
Long
lastSendTimemillis
=
0L
;
//上次发送消息时间,用于时间间隔
private
Long
lastSendTimemillis
=
0L
;
//上次发送消息时间,用于时间间隔
private
int
maxSendMsgInterval
=
0
;
private
int
maxSendMsgInterval
=
0
;
private
int
maxAudioDuration
=
0
;
private
int
maxAudioDuration
=
0
;
private
int
minAudioDuration
=
500
;
private
String
downloadPrefix
;
private
String
downloadPrefix
;
private
String
cachePath
;
private
String
cachePath
;
...
@@ -60,7 +57,11 @@ public class CCIMClient {
...
@@ -60,7 +57,11 @@ public class CCIMClient {
private
CCIMClient
()
{
private
CCIMClient
()
{
callBackManager
=
new
CallBackManager
<>();
socketManager
=
new
SocketManager
(
callBackManager
);
contactManager
=
new
ContactManager
(
socketManager
,
callBackManager
);
channelManager
=
new
ChannelManager
(
socketManager
,
callBackManager
);
messageManager
=
new
MessageManager
(
socketManager
,
callBackManager
,
executor
);
}
}
private
static
CCIMClient
mInstance
;
private
static
CCIMClient
mInstance
;
...
@@ -70,10 +71,6 @@ public class CCIMClient {
...
@@ -70,10 +71,6 @@ public class CCIMClient {
synchronized
(
CCIMClient
.
class
)
{
synchronized
(
CCIMClient
.
class
)
{
if
(
mInstance
==
null
)
{
if
(
mInstance
==
null
)
{
mInstance
=
new
CCIMClient
();
mInstance
=
new
CCIMClient
();
callBackManager
=
new
CallBackManager
<>();
socketManager
=
new
SocketManager
(
callBackManager
);
contactManager
=
new
ContactManager
(
socketManager
,
callBackManager
);
channelManager
=
new
ChannelManager
(
socketManager
,
callBackManager
);
}
}
}
}
}
}
...
@@ -85,12 +82,13 @@ public class CCIMClient {
...
@@ -85,12 +82,13 @@ public class CCIMClient {
}
}
public
void
initSDK
(
Context
context
,
String
appKey
,
String
userName
,
String
extData
,
Long
userId
,
Long
ts
,
String
sign
,
OnConnectListener
resultCallback
)
{
public
void
initSDK
(
Context
context
,
String
appKey
,
String
userName
,
String
extData
,
Long
userId
,
Long
ts
,
String
sign
,
OnConnectListener
resultCallback
)
{
messageManager
=
new
MessageManager
(
executor
,
context
,
userId
,
socketManager
,
callBackManager
);
this
.
userId
=
userId
;
messageManager
.
init
(
context
,
userId
);
socketManager
.
initChat
(
context
,
appKey
,
userName
,
extData
,
userId
,
ts
,
sign
,
new
OnClientConnectListener
()
{
socketManager
.
initChat
(
context
,
appKey
,
userName
,
extData
,
userId
,
ts
,
sign
,
new
OnClientConnectListener
()
{
@Override
@Override
public
void
onSocketConnection
(
Chat
.
ConnectResponse
.
ClientConfig
clientConfig
)
{
public
void
onSocketConnection
(
Chat
.
ConnectResponse
.
ClientConfig
clientConfig
)
{
maxSendMsgInterval
=
clientConfig
.
getSendMsgInterval
();
maxSendMsgInterval
=
clientConfig
.
getSendMsgInterval
();
maxAudioDuration
=
clientConfig
.
getMaxAudioDuration
();
maxAudioDuration
=
clientConfig
.
getMaxAudioDuration
()
*
1000
;
downloadPrefix
=
clientConfig
.
getDownloadPrefix
();
downloadPrefix
=
clientConfig
.
getDownloadPrefix
();
getContactList
((
contacts
,
contactGroups
,
dialog
)
->
{
getContactList
((
contacts
,
contactGroups
,
dialog
)
->
{
if
(!
isConnected
)
{
if
(!
isConnected
)
{
...
@@ -149,6 +147,7 @@ public class CCIMClient {
...
@@ -149,6 +147,7 @@ public class CCIMClient {
MessageContent
messageContent
=
gson
.
fromJson
(
print
,
MessageContent
.
class
);
MessageContent
messageContent
=
gson
.
fromJson
(
print
,
MessageContent
.
class
);
messageContent
.
setChannelId
(
channelMsgRes
.
getChannelId
());
messageContent
.
setChannelId
(
channelMsgRes
.
getChannelId
());
pushMsgListener
.
pushChannelMsg
(
messageContent
);
pushMsgListener
.
pushChannelMsg
(
messageContent
);
messageManager
.
pushNewMessage
(
messageContent
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -297,7 +296,7 @@ public class CCIMClient {
...
@@ -297,7 +296,7 @@ public class CCIMClient {
}
}
/**
/**
*
加入频道
*
频道拉黑
*/
*/
public
void
blockChannelUser
(
Long
channelId
,
Long
userId
,
ResultCallback
callback
)
{
public
void
blockChannelUser
(
Long
channelId
,
Long
userId
,
ResultCallback
callback
)
{
channelManager
.
blockChannelUser
(
channelId
,
userId
,
callback
);
channelManager
.
blockChannelUser
(
channelId
,
userId
,
callback
);
...
@@ -408,14 +407,16 @@ public class CCIMClient {
...
@@ -408,14 +407,16 @@ public class CCIMClient {
* 开始录音
* 开始录音
*/
*/
public
void
startRecordAudioMessage
(
FragmentActivity
activity
)
{
public
void
startRecordAudioMessage
(
FragmentActivity
activity
,
ResultCallback
resultCallback
)
{
PermissionX
.
init
(
activity
)
PermissionX
.
init
(
activity
)
.
permissions
(
Manifest
.
permission
.
RECORD_AUDIO
)
.
permissions
(
Manifest
.
permission
.
RECORD_AUDIO
)
.
onExplainRequestReason
((
scope
,
deniedList
,
beforeRequest
)
->
scope
.
showRequestReasonDialog
(
deniedList
,
"即将申请的权限是程序必须依赖的权限"
,
"我已明白"
))
.
onExplainRequestReason
((
scope
,
deniedList
,
beforeRequest
)
->
scope
.
showRequestReasonDialog
(
deniedList
,
"即将申请的权限是程序必须依赖的权限"
,
"我已明白"
))
.
onForwardToSettings
((
scope
,
deniedList
)
->
scope
.
showForwardToSettingsDialog
(
deniedList
,
"您需要去应用程序设置当中手动开启权限"
,
"我已明白"
))
.
onForwardToSettings
((
scope
,
deniedList
)
->
scope
.
showForwardToSettingsDialog
(
deniedList
,
"您需要去应用程序设置当中手动开启权限"
,
"我已明白"
))
.
request
((
allGranted
,
grantedList
,
deniedList
)
->
{
.
request
((
allGranted
,
grantedList
,
deniedList
)
->
{
if
(
allGranted
)
{
if
(
allGranted
)
{
MediaHelper
.
getInstance
().
prepare
(
activity
,
cachePath
);
MediaHelper
.
getInstance
().
prepare
(
cachePath
,
maxAudioDuration
,
resultCallback
);
}
else
{
resultCallback
.
onFailed
(
ErrorCode
.
START_VOICE_FAILED
);
}
}
});
});
}
}
...
@@ -424,7 +425,9 @@ public class CCIMClient {
...
@@ -424,7 +425,9 @@ public class CCIMClient {
* 停止录音并上传 私聊
* 停止录音并上传 私聊
*/
*/
public
void
stopAndSendAudioMessage
(
Long
receiveUserId
,
String
receiveUserName
,
ResultEventCallback
<
MessageContent
>
callback
)
{
public
void
stopAndSendAudioMessage
(
Long
receiveUserId
,
String
receiveUserName
,
ResultEventCallback
<
MessageContent
>
callback
)
{
if
(
checkAudio
(
callback
))
return
;
if
(
checkAudio
(
callback
))
{
return
;
}
messageManager
.
uploadFileMessage
(
cachePath
,
new
ResultEventCallback
<
String
>()
{
messageManager
.
uploadFileMessage
(
cachePath
,
new
ResultEventCallback
<
String
>()
{
@Override
@Override
public
void
onSuccess
(
String
fileName
)
{
public
void
onSuccess
(
String
fileName
)
{
...
@@ -453,7 +456,9 @@ public class CCIMClient {
...
@@ -453,7 +456,9 @@ public class CCIMClient {
* 停止录音并上传 频道
* 停止录音并上传 频道
*/
*/
public
void
stopAndSendChannelAudioMessage
(
Long
channelID
,
ResultEventCallback
<
MessageContent
>
callback
)
{
public
void
stopAndSendChannelAudioMessage
(
Long
channelID
,
ResultEventCallback
<
MessageContent
>
callback
)
{
if
(
checkAudio
(
callback
))
return
;
if
(
checkAudio
(
callback
))
{
return
;
}
messageManager
.
uploadFileMessage
(
cachePath
,
new
ResultEventCallback
<
String
>()
{
messageManager
.
uploadFileMessage
(
cachePath
,
new
ResultEventCallback
<
String
>()
{
@Override
@Override
public
void
onSuccess
(
String
fileName
)
{
public
void
onSuccess
(
String
fileName
)
{
...
@@ -469,7 +474,7 @@ public class CCIMClient {
...
@@ -469,7 +474,7 @@ public class CCIMClient {
private
boolean
checkAudio
(
ResultEventCallback
<
MessageContent
>
callback
)
{
private
boolean
checkAudio
(
ResultEventCallback
<
MessageContent
>
callback
)
{
Long
release
=
MediaHelper
.
getInstance
().
release
();
Long
release
=
MediaHelper
.
getInstance
().
release
();
if
(
release
<
500
)
{
if
(
release
<
minAudioDuration
)
{
callback
.
onFailed
(
ErrorCode
.
VOICE_TOO_SHORT
);
callback
.
onFailed
(
ErrorCode
.
VOICE_TOO_SHORT
);
MediaHelper
.
getInstance
().
cancel
();
MediaHelper
.
getInstance
().
cancel
();
return
true
;
return
true
;
...
...
ccim/src/main/java/com/ccwangluo/ccim/manage/ChannelManager.java
View file @
b573ce5e
...
@@ -102,7 +102,7 @@ public class ChannelManager {
...
@@ -102,7 +102,7 @@ public class ChannelManager {
}
}
/**
/**
*
加入频道
*
频道拉黑
*/
*/
public
void
blockChannelUser
(
Long
channelId
,
Long
userId
,
ResultCallback
callback
)
{
public
void
blockChannelUser
(
Long
channelId
,
Long
userId
,
ResultCallback
callback
)
{
Chat
.
ChatRequestMessage
.
Builder
builder
=
Chat
.
ChatRequestMessage
.
newBuilder
();
Chat
.
ChatRequestMessage
.
Builder
builder
=
Chat
.
ChatRequestMessage
.
newBuilder
();
...
...
ccim/src/main/java/com/ccwangluo/ccim/manage/ContactManager.java
View file @
b573ce5e
...
@@ -386,11 +386,19 @@ public class ContactManager {
...
@@ -386,11 +386,19 @@ public class ContactManager {
});
});
}
}
/**
*
* @param strangerDialog
*/
public
void
putStrangerDialog
(
Dialog
strangerDialog
)
{
public
void
putStrangerDialog
(
Dialog
strangerDialog
)
{
dialogs
.
put
(
strangerDialog
.
getContactUserId
(),
strangerDialog
);
dialogs
.
put
(
strangerDialog
.
getContactUserId
(),
strangerDialog
);
}
}
/**
* 新增对话列表
* @param senderUserId
* @param userName
*/
public
void
putContactDialog
(
Long
senderUserId
,
String
userName
)
{
public
void
putContactDialog
(
Long
senderUserId
,
String
userName
)
{
if
(!
dialogs
.
containsKey
(
senderUserId
))
{
if
(!
dialogs
.
containsKey
(
senderUserId
))
{
Dialog
dialog
=
new
Dialog
();
Dialog
dialog
=
new
Dialog
();
...
@@ -413,6 +421,10 @@ public class ContactManager {
...
@@ -413,6 +421,10 @@ public class ContactManager {
}
}
/**
* 新联系人
* @param contact
*/
public
void
pushNewContact
(
Contact
contact
)
{
public
void
pushNewContact
(
Contact
contact
)
{
contacts
.
put
(
contact
.
getContactUserId
(),
contact
);
contacts
.
put
(
contact
.
getContactUserId
(),
contact
);
Dialog
dialog
=
dialogs
.
get
(
contact
.
getContactUserId
());
Dialog
dialog
=
dialogs
.
get
(
contact
.
getContactUserId
());
...
@@ -421,11 +433,20 @@ public class ContactManager {
...
@@ -421,11 +433,20 @@ public class ContactManager {
}
}
}
}
/**
* 删除联系人
* @param contactUserId
*/
public
void
pushDeleteContact
(
long
contactUserId
)
{
public
void
pushDeleteContact
(
long
contactUserId
)
{
contacts
.
remove
(
contactUserId
);
contacts
.
remove
(
contactUserId
);
dialogs
.
remove
(
contactUserId
);
dialogs
.
remove
(
contactUserId
);
}
}
/**
* 更新联系人网络状态
* @param contactUserId
* @param netStatus
*/
public
void
pushContactNetStatus
(
long
contactUserId
,
NetStatus
netStatus
)
{
public
void
pushContactNetStatus
(
long
contactUserId
,
NetStatus
netStatus
)
{
Contact
contact
=
contacts
.
get
(
contactUserId
);
Contact
contact
=
contacts
.
get
(
contactUserId
);
if
(
contact
!=
null
)
{
if
(
contact
!=
null
)
{
...
...
ccim/src/main/java/com/ccwangluo/ccim/manage/MessageManager.java
View file @
b573ce5e
...
@@ -29,17 +29,21 @@ public class MessageManager {
...
@@ -29,17 +29,21 @@ public class MessageManager {
private
CallBackManager
<
Chat
.
ChatResponseMessage
>
callBackManager
;
private
CallBackManager
<
Chat
.
ChatResponseMessage
>
callBackManager
;
private
ExecutorService
executor
;
private
ExecutorService
executor
;
private
Long
lastSendTimemillis
=
0L
;
private
long
userId
;
private
long
userId
;
private
AppDatabase
db
;
private
AppDatabase
db
;
public
MessageManager
(
ExecutorService
executor
,
Context
context
,
Long
userId
,
SocketManager
socketManager
,
CallBackManager
<
Chat
.
ChatResponseMessage
>
callBackManager
)
{
public
MessageManager
(
SocketManager
socketManager
,
CallBackManager
<
Chat
.
ChatResponseMessage
>
callBackManager
,
ExecutorService
executor
)
{
this
.
userId
=
userId
;
this
.
socketManager
=
socketManager
;
this
.
socketManager
=
socketManager
;
this
.
callBackManager
=
callBackManager
;
this
.
callBackManager
=
callBackManager
;
this
.
executor
=
executor
;
this
.
executor
=
executor
;
}
public
void
init
(
Context
context
,
Long
userId
)
{
this
.
userId
=
userId
;
if
(
db
==
null
)
{
db
=
Room
.
databaseBuilder
(
context
.
getApplicationContext
(),
AppDatabase
.
class
,
"ccim_db"
).
build
();
db
=
Room
.
databaseBuilder
(
context
.
getApplicationContext
(),
AppDatabase
.
class
,
"ccim_db"
).
build
();
}
}
}
/**
/**
...
@@ -163,7 +167,6 @@ public class MessageManager {
...
@@ -163,7 +167,6 @@ public class MessageManager {
FileUtils
.
uploadFile
(
filePath
,
preSignedUrl
,
new
ResultCallback
()
{
FileUtils
.
uploadFile
(
filePath
,
preSignedUrl
,
new
ResultCallback
()
{
@Override
@Override
public
void
onSuccess
()
{
public
void
onSuccess
()
{
// sendVoidMessage(filename, receiveUserId, callback);
callback
.
onSuccess
(
filename
);
callback
.
onSuccess
(
filename
);
}
}
...
@@ -184,11 +187,10 @@ public class MessageManager {
...
@@ -184,11 +187,10 @@ public class MessageManager {
}
}
public
void
playAudio
(
Long
msgId
,
String
downloadPrefix
,
String
cachePath
,
ResultCallback
resultCallback
)
{
public
void
playAudio
(
Long
msgId
,
String
downloadPrefix
,
String
cachePath
,
ResultCallback
resultCallback
)
{
executor
.
execute
(()
->
{
executor
.
execute
(()
->
{
MessageContent
messageContent
=
db
.
messageDao
().
getMsgById
(
msgId
);
MessageContent
messageContent
=
db
.
messageDao
().
getMsgById
(
msgId
);
if
(
messageContent
==
null
){
if
(
messageContent
==
null
)
{
resultCallback
.
onFailed
(
ErrorCode
.
MSG_NOT_EXISTS
);
resultCallback
.
onFailed
(
ErrorCode
.
MSG_NOT_EXISTS
);
return
;
return
;
}
}
...
...
ccim/src/main/java/com/ccwangluo/ccim/manage/SocketManager.java
View file @
b573ce5e
...
@@ -20,8 +20,7 @@ import ccim.protocol.Common;
...
@@ -20,8 +20,7 @@ import ccim.protocol.Common;
public
class
SocketManager
{
public
class
SocketManager
{
private
final
Logger
logger
=
Logger
.
getLogger
(
CCIMClient
.
class
.
getName
());
private
final
Logger
logger
=
Logger
.
getLogger
(
CCIMClient
.
class
.
getName
());
// private static final String SERVER_IP = "117.144.156.2";
private
static
String
SERVER_IP
=
"106.15.237.67"
;
private
static
String
SERVER_IP
=
"10.4.5.134"
;
private
static
int
SERVER_PORT
=
8000
;
private
static
int
SERVER_PORT
=
8000
;
private
static
final
int
version
=
1
;
private
static
final
int
version
=
1
;
...
@@ -58,7 +57,7 @@ public class SocketManager {
...
@@ -58,7 +57,7 @@ public class SocketManager {
@Override
@Override
public
void
onSuccess
(
Chat
.
ChatResponseMessage
chatResponseMessage
)
{
public
void
onSuccess
(
Chat
.
ChatResponseMessage
chatResponseMessage
)
{
Chat
.
ConnectResponse
connectRes
=
chatResponseMessage
.
getConnectRes
();
Chat
.
ConnectResponse
connectRes
=
chatResponseMessage
.
getConnectRes
();
long
l
=
connectRes
.
getHeartBeatInterval
()
*
1000L
;
long
l
=
connectRes
.
getHeartBeatInterval
();
pulseData
(
l
);
pulseData
(
l
);
Chat
.
ConnectResponse
.
ClientConfig
clientCfg
=
connectRes
.
getClientCfg
();
Chat
.
ConnectResponse
.
ClientConfig
clientCfg
=
connectRes
.
getClientCfg
();
onConnectListener
.
onSocketConnection
(
clientCfg
);
onConnectListener
.
onSocketConnection
(
clientCfg
);
...
@@ -94,7 +93,6 @@ public class SocketManager {
...
@@ -94,7 +93,6 @@ public class SocketManager {
String
json
=
JsonFormat
.
printer
().
print
(
data
);
String
json
=
JsonFormat
.
printer
().
print
(
data
);
logger
.
info
(
json
);
logger
.
info
(
json
);
if
(
data
.
hasHeartbeatRes
())
{
if
(
data
.
hasHeartbeatRes
())
{
// OkSocket.open(chatInfo).getPulseManager().feed();
return
;
return
;
}
}
if
(
data
.
hasConnectionStateRes
())
{
if
(
data
.
hasConnectionStateRes
())
{
...
@@ -165,7 +163,6 @@ public class SocketManager {
...
@@ -165,7 +163,6 @@ public class SocketManager {
}
}
public
void
disConnect
()
{
public
void
disConnect
()
{
socketClient
.
destroy
();
socketClient
.
destroy
();
}
}
...
...
ccim/src/main/java/com/ccwangluo/ccim/socket/NettyChatClient.java
View file @
b573ce5e
...
@@ -8,10 +8,10 @@ import android.net.NetworkInfo;
...
@@ -8,10 +8,10 @@ import android.net.NetworkInfo;
import
com.ccwangluo.ccim.CCIMClient
;
import
com.ccwangluo.ccim.CCIMClient
;
import
com.ccwangluo.ccim.listener.MessageListener
;
import
com.ccwangluo.ccim.listener.MessageListener
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
java.util.logging.Logger
;
import
java.util.logging.Logger
;
import
ccim.protocol.Chat
;
import
ccim.protocol.Chat
;
...
@@ -48,9 +48,7 @@ public class NettyChatClient implements SocketClient {
...
@@ -48,9 +48,7 @@ public class NettyChatClient implements SocketClient {
EventLoopGroup
group
=
new
NioEventLoopGroup
();
EventLoopGroup
group
=
new
NioEventLoopGroup
();
private
ExecutorService
executor
=
Executors
.
newSingleThreadExecutor
();
private
ExecutorService
executor
=
Executors
.
newSingleThreadExecutor
();
ScheduledExecutorService
timerExcutor
;
// 计时器
private
Timer
timer
;
public
NettyChatClient
(
Context
context
,
String
ip
,
int
port
)
{
public
NettyChatClient
(
Context
context
,
String
ip
,
int
port
)
{
this
.
ip
=
ip
;
this
.
ip
=
ip
;
...
@@ -87,11 +85,13 @@ public class NettyChatClient implements SocketClient {
...
@@ -87,11 +85,13 @@ public class NettyChatClient implements SocketClient {
private
void
connect
()
{
private
void
connect
()
{
executor
.
execute
(()
->
{
try
{
try
{
channelFuture
=
bootstrap
.
connect
(
ip
,
port
).
sync
();
channelFuture
=
bootstrap
.
connect
(
ip
,
port
).
sync
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
});
}
}
...
@@ -127,8 +127,8 @@ public class NettyChatClient implements SocketClient {
...
@@ -127,8 +127,8 @@ public class NettyChatClient implements SocketClient {
@Override
@Override
public
void
destroy
()
{
public
void
destroy
()
{
if
(
timer
!=
null
)
{
if
(
timer
Excutor
!=
null
)
{
timer
.
cancel
();
timer
Excutor
.
shutdown
();
}
}
if
(
channelFuture
!=
null
)
{
if
(
channelFuture
!=
null
)
{
channelFuture
.
channel
().
close
();
channelFuture
.
channel
().
close
();
...
@@ -146,11 +146,11 @@ public class NettyChatClient implements SocketClient {
...
@@ -146,11 +146,11 @@ public class NettyChatClient implements SocketClient {
@Override
@Override
public
void
heartBeat
(
Long
frequency
,
Chat
.
ChatRequestMessage
build
)
{
public
void
heartBeat
(
Long
frequency
,
Chat
.
ChatRequestMessage
build
)
{
if
(
timer
!=
null
)
{
if
(
timer
Excutor
!=
null
)
{
timer
.
cancel
();
timer
Excutor
.
shutdown
();
}
}
timer
=
new
Timer
(
);
timer
Excutor
=
Executors
.
newScheduledThreadPool
(
1
);
TimerTask
timerTask
=
new
TimerTask
()
{
timerExcutor
.
schedule
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
if
(
getConnectivityStatus
(
context
))
{
if
(
getConnectivityStatus
(
context
))
{
...
@@ -167,8 +167,7 @@ public class NettyChatClient implements SocketClient {
...
@@ -167,8 +167,7 @@ public class NettyChatClient implements SocketClient {
}
}
}
}
}
}
};
},
frequency
,
TimeUnit
.
MILLISECONDS
);
timer
.
schedule
(
timerTask
,
frequency
,
frequency
);
}
}
...
...
ccim/src/main/java/com/ccwangluo/ccim/util/ErrorCode.java
View file @
b573ce5e
...
@@ -13,5 +13,6 @@ public class ErrorCode {
...
@@ -13,5 +13,6 @@ public class ErrorCode {
public
static
final
int
MSG_NOT_EXISTS
=
908
;
//播放类型错误
public
static
final
int
MSG_NOT_EXISTS
=
908
;
//播放类型错误
public
static
final
int
MSG_CONTENT_IS_EMPTY
=
910
;
//发送消息体为空
public
static
final
int
MSG_CONTENT_IS_EMPTY
=
910
;
//发送消息体为空
public
static
final
int
START_VOICE_FAILED
=
911
;
//录音创建失败
}
}
ccim/src/main/java/com/ccwangluo/ccim/util/FileUtils.java
View file @
b573ce5e
...
@@ -58,7 +58,7 @@ public class FileUtils {
...
@@ -58,7 +58,7 @@ public class FileUtils {
return
null
;
return
null
;
}
}
File
oldFile
=
new
File
(
oldPath
);
File
oldFile
=
new
File
(
oldPath
);
File
newFile
=
new
File
(
newPath
,
newFileName
);
File
newFile
=
new
File
(
newPath
,
newFileName
);
if
(
oldFile
.
exists
()
&&
oldFile
.
isFile
())
{
if
(
oldFile
.
exists
()
&&
oldFile
.
isFile
())
{
boolean
b
=
oldFile
.
renameTo
(
newFile
);
boolean
b
=
oldFile
.
renameTo
(
newFile
);
}
}
...
@@ -74,35 +74,37 @@ public class FileUtils {
...
@@ -74,35 +74,37 @@ public class FileUtils {
call
.
enqueue
(
new
Callback
()
{
call
.
enqueue
(
new
Callback
()
{
@Override
@Override
public
void
onFailure
(
Call
call
,
IOException
e
)
{
public
void
onFailure
(
Call
call
,
IOException
e
)
{
e
.
printStackTrace
(
);
logger
.
info
(
e
.
toString
()
);
resultEventCallback
.
onFailed
(
ErrorCode
.
DOWNLOAD_ERR
);
resultEventCallback
.
onFailed
(
ErrorCode
.
DOWNLOAD_ERR
);
}
}
@Override
@Override
public
void
onResponse
(
Call
call
,
Response
response
)
throws
IOException
{
public
void
onResponse
(
Call
call
,
Response
response
)
throws
IOException
{
writeFile
(
file
,
response
);
writeFile
(
file
,
response
);
resultEventCallback
.
onSuccess
(
file
);
resultEventCallback
.
onSuccess
(
file
);
}
}
});
});
}
}
private
static
void
writeFile
(
File
file
,
Response
response
)
{
private
static
void
writeFile
(
File
file
,
Response
response
)
{
OutputStream
outputStream
=
null
;
OutputStream
outputStream
=
null
;
InputStream
inputStream
=
response
.
body
().
byteStream
();
InputStream
inputStream
=
response
.
body
().
byteStream
();
try
{
try
{
outputStream
=
new
FileOutputStream
(
file
);
outputStream
=
new
FileOutputStream
(
file
);
int
len
=
0
;
int
len
=
0
;
byte
[]
buffer
=
new
byte
[
1024
*
10
];
byte
[]
buffer
=
new
byte
[
1024
*
10
];
while
((
len
=
inputStream
.
read
(
buffer
))
!=-
1
)
{
while
((
len
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
outputStream
.
write
(
buffer
,
0
,
len
);
outputStream
.
write
(
buffer
,
0
,
len
);
}
}
}
catch
(
FileNotFoundException
e
)
{
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
try
{
try
{
if
(
inputStream
!=
null
)
if
(
inputStream
!=
null
)
inputStream
.
close
();
inputStream
.
close
();
if
(
outputStream
!=
null
)
if
(
outputStream
!=
null
)
outputStream
.
close
();
outputStream
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
ccim/src/main/java/com/ccwangluo/ccim/util/MediaHelper.java
View file @
b573ce5e
package
com.ccwangluo.ccim.util
;
package
com.ccwangluo.ccim.util
;
import
android.app.Activity
;
import
android.media.MediaPlayer
;
import
android.media.MediaPlayer
;
import
android.media.MediaRecorder
;
import
android.media.MediaRecorder
;
import
android.os.Build
;
import
android.os.Build
;
...
@@ -8,7 +7,6 @@ import android.os.Build;
...
@@ -8,7 +7,6 @@ import android.os.Build;
import
com.ccwangluo.ccim.listener.ResultCallback
;
import
com.ccwangluo.ccim.listener.ResultCallback
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
public
class
MediaHelper
{
public
class
MediaHelper
{
private
MediaRecorder
mMediaRecorder
;
private
MediaRecorder
mMediaRecorder
;
...
@@ -32,15 +30,15 @@ public class MediaHelper {
...
@@ -32,15 +30,15 @@ public class MediaHelper {
}
}
return
mInstance
;
return
mInstance
;
}
}
/**
/**
* 准备录音
* 准备录音
*/
*/
public
void
prepare
(
Activity
activity
,
String
path
)
{
public
void
prepare
(
String
path
,
int
maxAudioDuration
,
ResultCallback
resultCallback
)
{
try
{
try
{
if
(
mMediaRecorder
!=
null
){
if
(
mMediaRecorder
!=
null
)
{
cancel
();
cancel
();
}
}
String
fileName
=
System
.
currentTimeMillis
()
+
".aac"
;
// 文件名字
String
fileName
=
System
.
currentTimeMillis
()
+
".aac"
;
// 文件名字
File
file
=
new
File
(
path
,
fileName
);
// 文件路径
File
file
=
new
File
(
path
,
fileName
);
// 文件路径
mMediaRecorder
=
new
MediaRecorder
();
mMediaRecorder
=
new
MediaRecorder
();
...
@@ -61,12 +59,12 @@ public class MediaHelper {
...
@@ -61,12 +59,12 @@ public class MediaHelper {
mMediaRecorder
.
prepare
();
mMediaRecorder
.
prepare
();
mMediaRecorder
.
start
();
mMediaRecorder
.
start
();
start_record_millis
=
System
.
currentTimeMillis
();
start_record_millis
=
System
.
currentTimeMillis
();
}
catch
(
IllegalStateException
e
)
{
resultCallback
.
onSuccess
();
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
}
catch
(
IOException
e
)
{
resultCallback
.
onFailed
(
ErrorCode
.
START_VOICE_FAILED
);
e
.
printStackTrace
();
}
}
}
}
/**
/**
* 释放资源,获取录音时长
* 释放资源,获取录音时长
*/
*/
...
@@ -75,13 +73,14 @@ public class MediaHelper {
...
@@ -75,13 +73,14 @@ public class MediaHelper {
mMediaRecorder
.
release
();
mMediaRecorder
.
release
();
mMediaRecorder
=
null
;
mMediaRecorder
=
null
;
}
}
if
(
start_record_millis
!=
0L
){
if
(
start_record_millis
!=
0L
)
{
long
l
=
System
.
currentTimeMillis
()
-
start_record_millis
;
long
l
=
System
.
currentTimeMillis
()
-
start_record_millis
;
start_record_millis
=
0L
;
start_record_millis
=
0L
;
return
l
;
return
l
;
}
}
return
0L
;
return
0L
;
}
}
/**
/**
* 取消
* 取消
*/
*/
...
@@ -99,6 +98,7 @@ public class MediaHelper {
...
@@ -99,6 +98,7 @@ public class MediaHelper {
/**
/**
* 播放
* 播放
*
* @param filePath
* @param filePath
*/
*/
public
void
play
(
String
filePath
,
ResultCallback
resultCallback
)
{
public
void
play
(
String
filePath
,
ResultCallback
resultCallback
)
{
...
@@ -114,7 +114,7 @@ public class MediaHelper {
...
@@ -114,7 +114,7 @@ public class MediaHelper {
}
}
//获取生成的文件路径
//获取生成的文件路径
public
String
getFilePath
(
String
filename
,
String
path
)
{
public
String
getFilePath
(
String
filename
,
String
path
)
{
return
FileUtils
.
renameFile
(
mFilePath
,
path
,
filename
);
return
FileUtils
.
renameFile
(
mFilePath
,
path
,
filename
);
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment