版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】怎么在Android中实现微信键盘切换效果
怎么在Android中实现微信键盘切换效果?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。xml:<?xml
version="1.0"
encoding="utf-8"?>
<RelativeLayout
xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:id="@+id/linearlayout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/M323535"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".ui.activity.ChatActivity">
<RelativeLayout
android:id="@+id/layout_title"
android:layout_width="match_parent"
android:layout_height="@dimen/dp44"
android:background="@color/title_bar"
android:orientation="horizontal">
<ImageView
android:id="@+id/img_finish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/dp3"
android:layout_marginStart="@dimen/dp3"
android:background="@drawable/select_image_finsh"
android:contentDescription="@null"
/>
<TextView
android:id="@+id/txt_finish"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_toEndOf="@+id/img_finish"
android:layout_toRightOf="@+id/img_finish"
android:gravity="center"
android:text="@string/img_finish"
android:textColor="@drawable/text_selector"
android:textSize="18sp"
/>
<TextView
android:id="@+id/txt_im_object_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:clickable="false"
android:gravity="center"
android:textColor="@color/MFFCE00"
android:textSize="@dimen/sp20"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/keyboardListenRelativeLayout"
android:layout_below="@+id/layout_title">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
/>
<!--<com.motoband.ui.Voice.RecordButton-->
<!--android:id="@+id/btn_record"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:layout_centerHorizontal="true"-->
<!--/>-->
<!--//语音-->
<RelativeLayout
android:id="@+id/layout_voice"
android:layout_width="@dimen/dp200"
android:layout_height="@dimen/dp200"
android:layout_centerInParent="true"
android:visibility="gone">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/chat_window_backgroud"
android:contentDescription="@null"
/>
<ImageView
android:id="@+id/img_im_microphone_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp16"
android:background="@mipmap/im_microphone"
android:contentDescription="@null"
/>
<ImageView
android:id="@+id/img_im_microphone_sound_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/img_im_microphone_state"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp11"
android:background="@mipmap/chat_volume_06"
android:contentDescription="@null"
/>
<TextView
android:id="@+id/txt_im_microphone_show_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/img_im_microphone_sound_size"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/dp26"
android:contentDescription="@null"
android:text="@string/slide_to_cancel_sending"
android:textColor="@color/M3C3C3C"
android:textSize="@dimen/sp16"
/>
</RelativeLayout>
<!--<TextView-->
<!--android:id="@+id/txt_start"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/dp44"-->
<!--android:background="@color/M44C494"-->
<!--android:text="播放语音"-->
<!--/>-->
</RelativeLayout>
<com.motoband.ui.view.KeyboardListenRelativeLayout
android:id="@+id/keyboardListenRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--发布评论-->
<LinearLayout
android:id="@+id/layout_release"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/M575A5B"
android:orientation="horizontal"
tools:ignore="UselessParent">
<ImageView
android:id="@+id/img_voice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/dp12"
android:layout_marginStart="@dimen/dp12"
android:contentDescription="@null"
/>
<!--//文字
与录音-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.motoband.ui.view.MyEditText
android:id="@+id/txt_im_message"
android:layout_width="280dp"
android:layout_height="@dimen/dp30"
android:layout_gravity="center_vertical"
android:layout_marginBottom="@dimen/dp8"
android:layout_marginLeft="@dimen/dp15"
android:layout_marginStart="@dimen/dp15"
android:layout_marginTop="@dimen/dp8"
android:background="@drawable/shape_d8d8d8"
android:gravity="start|top"
android:hint="@string/say_some"
android:imeOptions="actionDone"
android:inputType="textMultiLine"
android:maxLines="6"
android:paddingBottom="@dimen/dp7"
android:paddingLeft="@dimen/dp7"
android:paddingRight="@dimen/dp7"
android:paddingTop="@dimen/dp7"
android:singleLine="false"
android:textColor="@color/M828282"
android:textColorHint="@color/M828282"
android:textCursorDrawable="@drawable/shape_cursor_color"
android:textSize="@dimen/sp12"
/>
<TextView
android:id="@+id/txt_record"
android:layout_width="match_parent"
android:layout_height="@dimen/dp30"
android:layout_marginBottom="@dimen/dp8"
android:layout_marginLeft="@dimen/dp15"
android:layout_marginStart="@dimen/dp15"
android:layout_marginTop="@dimen/dp8"
android:background="@drawable/shape_im_chat_voice_up"
android:gravity="center"
android:paddingBottom="@dimen/dp7"
android:paddingLeft="@dimen/dp7"
android:paddingRight="@dimen/dp7"
android:paddingTop="@dimen/dp7"
android:text="@string/txt_record"
android:visibility="gone"
/>
</RelativeLayout>
<ImageView
android:id="@+id/img_expression"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/dp12"
android:layout_marginStart="@dimen/dp12"
android:contentDescription="@null"
/>
<ImageView
android:id="@+id/img_other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/dp12"
android:layout_marginLeft="@dimen/dp12"
android:layout_marginRight="@dimen/dp12"
android:layout_marginStart="@dimen/dp12"
android:contentDescription="@null"
/>
</LinearLayout>
<!--//表情-->
<RelativeLayout
android:id="@+id/layout_expression"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@+id/layout_release"
android:background="@color/MFFFFFF"
android:visibility="gone">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="180dp"
/>
<LinearLayout
android:id="@+id/viewGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/dp10"
android:background="@color/MFFFFFF"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingLeft="@dimen/dp20"
android:paddingRight="@dimen/dp20"
/>
</RelativeLayout>
<!--//其他
照片
拍摄
小视频
位置-->
<RelativeLayout
android:id="@+id/layout_other"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@+id/layout_release"
android:background="@color/M323535"
android:visibility="gone">
<LinearLayout
android:id="@+id/layout_other_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp25"
android:orientation="horizontal">
<ImageView
android:id="@+id/im_chat_poto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp16"
android:layout_marginStart="@dimen/dp16"
android:background="@mipmap/im_chat_poto"
android:contentDescription="@null"
/>
<ImageView
android:id="@+id/im_chat_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp16"
android:layout_marginStart="@dimen/dp16"
android:background="@mipmap/im_chat_camera"
android:contentDescription="@null"
/>
<ImageView
android:id="@+id/im_chat_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp16"
android:layout_marginStart="@dimen/dp16"
android:background="@mipmap/im_chat_video"
android:contentDescription="@null"
/>
<ImageView
android:id="@+id/im_chat_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp16"
android:layout_marginStart="@dimen/dp16"
android:background="@mipmap/im_chat_poto"
android:contentDescription="@null"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout_other_item"
android:layout_marginEnd="@dimen/dp8"
android:layout_marginLeft="@dimen/dp8"
android:layout_marginRight="@dimen/dp8"
android:layout_marginStart="@dimen/dp8"
android:layout_marginTop="@dimen/dp7"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="@string/newtype_photo"
android:textColor="@color/M969999"
android:textSize="@dimen/sp11"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="@string/select_takephoto"
android:textColor="@color/M969999"
android:textSize="@dimen/sp11"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="@string/newtype_video"
android:textColor="@color/M969999"
android:textSize="@dimen/sp11"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="@string/im_location"
android:textColor="@color/M969999"
android:textSize="@dimen/sp11"
/>
</LinearLayout>
<!--<ImageView-->
<!--android:id="@+id/img_bitmap"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"
/>-->
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</com.motoband.ui.view.KeyboardListenRelativeLayout>
<!--//存放当前位置照片-->
<ScrollView
android:id="@+id/scrollView_location_bitmap"
android:layout_width="match_parent"
android:layout_height="340dp"
android:layout_marginTop="@dimen/dp800">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="340dp"
android:orientation="vertical"
tools:ignore="ScrollViewSize">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="203dp">
<com.amap.api.maps.MapView
android:id="@+id/map_location"
android:layout_width="match_parent"
android:layout_height="203dp"
android:layout_gravity="center"
/>
<ImageView
android:id="@+id/img_location_map"
android:layout_width="match_parent"
android:layout_height="203dp"
android:layout_gravity="center"
android:contentDescription="@null"
android:scaleType="centerCrop"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>xml布局中用到了自定义KeyboardListenRelativeLayout(判断软键盘显示和隐藏的自定义控件)package
com.motoband.ui.view;
/**
*
Created
by
admin
on
2016/4/22.
*/
import
android.content.Context;
import
android.util.AttributeSet;
import
android.widget.RelativeLayout;
/**
*
@author
madreain
*/
public
class
KeyboardListenRelativeLayout
extends
RelativeLayout
{
private
static
final
String
TAG
=
KeyboardListenRelativeLayout.class.getSimpleName();
public
static
final
byte
KEYBOARD_STATE_SHOW
=
-3;
public
static
final
byte
KEYBOARD_STATE_HIDE
=
-2;
public
static
final
byte
KEYBOARD_STATE_INIT
=
-1;
private
boolean
mHasInit
=
false;
private
boolean
mHasKeyboard
=
false;
private
int
mHeight;
private
IOnKeyboardStateChangedListener
onKeyboardStateChangedListener;
public
KeyboardListenRelativeLayout(Context
context)
{
super(context);
}
public
KeyboardListenRelativeLayout(Context
context,
AttributeSet
attrs)
{
super(context,
attrs);
}
public
KeyboardListenRelativeLayout(Context
context,
AttributeSet
attrs,
int
defStyle)
{
super(context,
attrs,
defStyle);
}
public
void
setOnKeyboardStateChangedListener(IOnKeyboardStateChangedListener
onKeyboardStateChangedListener)
{
this.onKeyboardStateChangedListener
=
onKeyboardStateChangedListener;
}
@Override
protected
void
onLayout(boolean
changed,
int
l,
int
t,
int
r,
int
b)
{
super.onLayout(changed,
l,
t,
r,
b);
if(!mHasInit)
{
mHasInit
=
true;
mHeight
=
b;
if(onKeyboardStateChangedListener
!=
null)
{
onKeyboardStateChangedListener.onKeyboardStateChanged(KEYBOARD_STATE_INIT);
}
}
else
{
mHeight
=
mHeight
<
b
?
b
:
mHeight;
}
if(mHasInit
&&
mHeight
>
b)
{
mHasKeyboard
=
true;
if(onKeyboardStateChangedListener
!=
null)
{
onKeyboardStateChangedListener.onKeyboardStateChanged(KEYBOARD_STATE_SHOW);
}
}
if(mHasInit
&&
mHasKeyboard
&&
mHeight
==
b)
{
mHasKeyboard
=
false;
if(onKeyboardStateChangedListener
!=
null)
{
onKeyboardStateChangedListener.onKeyboardStateChanged(KEYBOARD_STATE_HIDE);
}
}
}
public
interface
IOnKeyboardStateChangedListener
{
public
void
onKeyboardStateChanged(int
state);
}
}下面直接步入正题来介绍代码中实现的键盘切换:package
com.motoband.ui.activity;
import
android.Manifest;
import
android.annotation.SuppressLint;
import
android.app.Activity;
import
android.app.AlertDialog;
import
android.content.Context;
import
android.content.Intent;
import
android.content.pm.PackageManager;
import
android.graphics.Bitmap;
import
android.graphics.Canvas;
import
android.graphics.Color;
import
android.graphics.PixelFormat;
import
android.location.Location;
import
android.location.LocationListener;
import
android.location.LocationManager;
import
android.media.MediaPlayer;
import
android.media.MediaRecorder;
import
.Uri;
import
android.os.Environment;
import
android.os.PowerManager;
import
android.os.SystemClock;
import
vider.MediaStore;
import
android.support.v4.app.ActivityCompat;
import
android.support.v4.content.ContextCompat;
import
android.support.v4.view.PagerAdapter;
import
android.support.v4.view.ViewPager;
import
android.support.v7.app.AppCompatActivity;
import
android.os.Bundle;
import
android.util.Log;
import
android.view.LayoutInflater;
import
android.view.MotionEvent;
import
android.view.View;
import
android.view.ViewGroup;
import
android.view.WindowManager;
import
android.widget.AbsListView;
import
android.widget.AdapterView;
import
android.widget.BaseAdapter;
import
android.widget.ImageView;
import
android.widget.LinearLayout;
import
android.widget.ListView;
import
android.widget.RelativeLayout;
import
android.widget.ScrollView;
import
android.widget.TextView;
import
android.widget.Toast;
import
com.amap.api.location.AMapLocation;
import
com.amap.api.location.AMapLocationClient;
import
com.amap.api.location.AMapLocationClientOption;
import
com.amap.api.location.AMapLocationListener;
import
com.amap.api.maps.AMap;
import
com.amap.api.maps.AMapOptions;
import
com.amap.api.maps.CameraUpdateFactory;
import
com.amap.api.maps.LocationSource;
import
com.amap.api.maps.MapView;
import
com.amap.api.maps.UiSettings;
import
com.amap.api.maps.model.BitmapDescriptorFactory;
import
com.amap.api.maps.model.CameraPosition;
import
com.amap.api.maps.model.LatLng;
import
com.amap.api.maps.model.MyLocationStyle;
import
com.amap.api.services.core.LatLonPoint;
import
com.amap.api.services.geocoder.GeocodeResult;
import
com.amap.api.services.geocoder.GeocodeSearch;
import
com.amap.api.services.geocoder.RegeocodeQuery;
import
com.amap.api.services.geocoder.RegeocodeResult;
import
com.motoband.R;
import
com.motoband.core.manager.LoginManager;
import
com.motoband.core.manager.MBUserManager;
import
com.motoband.core.model.MBUserModel;
import
com.motoband.core.utils.MBUtil;
import
com.motoband.mbcamera.camera.CameraConstants;
import
com.motoband.ui.Voice.AudioRecorder;
import
com.motoband.ui.Voice.RecordButton;
import
com.motoband.ui.manager.PixelOrdpManager;
import
com.motoband.ui.manager.SoftKeyboardManager;
import
com.motoband.ui.manager.StatusBarManager;
import
com.motoband.ui.view.KeyboardListenRelativeLayout;
import
com.motoband.ui.view.MyEditText;
import
com.motoband.ui.view.MyGridView;
import
com.motoband.widget.RoundImageView;
import
com.squareup.picasso.Picasso;
import
java.io.File;
import
java.io.FileNotFoundException;
import
java.io.FileOutputStream;
import
java.io.IOException;
import
java.text.SimpleDateFormat;
import
java.util.ArrayList;
import
java.util.Date;
import
java.util.List;
import
java.util.Locale;
public
class
ChatActivity
extends
AppCompatActivity
implements
LocationSource,AMapLocationListener,GeocodeSearch.OnGeocodeSearchListener
{
private
Intent
intent;
private
MBUserModel
mbUserModel;
private
MBUserModel
meMBUserModel;
//聊天对象
private
TextView
txt_im_object_name;
private
ListView
listView;
//
private
ChatAdapter
chatAdapter;
//信息内容
private
MyEditText
txt_im_message;
//键盘
//最外层判断软键盘是否弹出的
private
KeyboardListenRelativeLayout
keyboardListenRelativeLayout;
//语音
private
ImageView
img_voice;
//录音
private
TextView
txt_record;
private
RelativeLayout
layout_voice;
private
ImageView
img_im_microphone_state;
private
ImageView
img_im_microphone_sound_size;
private
TextView
txt_im_microphone_show_text;
//表情
private
ImageView
img_expression;
//其他
照片
拍摄
小视频
位置
private
ImageView
img_other;
//其他的显示
private
RelativeLayout
layout_other;
//照片
private
ImageView
im_chat_poto;
//
拍摄
private
ImageView
im_chat_camera;
//照片路径
private
String
picStringUrl;
//
小视频
private
ImageView
im_chat_video;
//
位置
private
ImageView
im_chat_location;
//位置的照片
//地图
private
ScrollView
scrollView_location_bitmap;
private
MapView
mapView;//骑行地图
TextureMapView
private
AMap
aMap;//骑行地图
private
ImageView
img_location_map;
//定位
private
AMapLocationClient
mLocationClient;
private
LocationSource.OnLocationChangedListener
mListener;
private
LatLonPoint
latLonPoint;
private
GeocodeSearch
geocodeSearch;
//获取的当前位置
private
LocationManager
locationManager;
private
String
locationProvider;
Location
location;
//经纬度
private
double
latitude;
private
double
longitude;
//判断是点击的还是移动地图的
false
移动地图
true
点击
private
boolean
isFirst=false;
private
boolean
isShowMoveLocationCenter=true;
//
获取当前地图中心点的坐标
LatLng
mTarget;
//地图中心点当前的具体位置
//
private
LatLng
currentlatLng;
private
String
currentSpecificPosition;
//
private
ImageView
img_bitmap;
//语音
private
boolean
isShowVoice
=
false;
//表情
private
boolean
isShowExpressionViewpager
=
false;
//其他
private
boolean
isShowOther
=
false;
private
RelativeLayout
layout_expression;
private
ViewPager
viewPager;
private
ViewPagerAdapter
viewPagerAdapter;
private
List<View>
viewsList;
/**
*
将小圆点的图片用数组表示
*/
private
ImageView[]
imageViews;
//包裹小圆点的LinearLayout
private
LinearLayout
viewPoints;
private
ImageView
imageView;
//第一组表情
private
MyGridView
myGridViewExpresionOne;
ArrayList<Integer>
unicodeOne
=
new
ArrayList<Integer>();
//第二组表情
private
MyGridView
myGridViewExpresionTwo;
ArrayList<Integer>
unicodeTwo
=
new
ArrayList<Integer>();
//第三组表情
private
MyGridView
myGridViewExpresionThere;
ArrayList<Integer>
unicodeThere
=
new
ArrayList<Integer>();
private
GridAdapter
gridAdapter;
//当前选择的是录音
表情
其他
并且显示
1
2
3
private
int
currentSelect
=
0;
//
RecordButton
button;
@Override
protected
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
//在进入有VideoView界面的Activity时会出现闪黑屏的情况(如论视频是否播放):
getWindow().setFormat(PixelFormat.TRANSLUCENT);
//状态栏颜色的设置
RelativeLayout
linearLayout
=
(RelativeLayout)
findViewById(R.id.linearlayout_main);
StatusBarManager.SetStatusBar(getWindow(),
this,
getResources(),
"#1F2B29",
linearLayout);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
initMap(savedInstanceState);
initView();
initData();
initListener();
//
button
=
(RecordButton)
findViewById(R.id.btn_record);
//
button.setAudioRecord(new
AudioRecorder());
//
button.setRecordListener(new
RecordButton.RecordListener()
{
//
@Override
//
public
void
recordEnd(String
filePath)
{
//
//
//
}
//
});
}
private
void
initView()
{
//
img_bitmap=
(ImageView)
findViewById(R.id.img_bitmap);
listView
=
(ListView)
findViewById(R.id.listView);
txt_im_object_name
=
(TextView)
findViewById(R.id.txt_im_object_name);
//说点什么
txt_im_message
=
(MyEditText)
findViewById(R.id.txt_im_message);
txt_im_message.setSelection(txt_im_message.getText().length());
//录音
txt_record
=
(TextView)
findViewById(R.id.txt_record);
//录音显示的控件
initVoice();
//
wakeLock
=
((PowerManager)
getSystemService(Context.POWER_SERVICE))
//
.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,
"demo");
//键盘
initKeyboard();
}
//录音显示的控件
private
void
initVoice()
{
layout_voice
=
(RelativeLayout)
findViewById(R.id.layout_voice);
img_im_microphone_state
=
(ImageView)
findViewById(R.id.img_im_microphone_state);
img_im_microphone_sound_size
=
(ImageView)
findViewById(R.id.img_im_microphone_sound_size);
txt_im_microphone_show_text
=
(TextView)
findViewById(R.id.txt_im_microphone_show_text);
}
private
void
initKeyboard()
{
//输入框栏
用来判断软键盘是否弹出
keyboardListenRelativeLayout
=
(KeyboardListenRelativeLayout)
findViewById(R.id.keyboardListenRelativeLayout);
layout_expression
=
(RelativeLayout)
findViewById(R.id.layout_expression);
viewPager
=
(ViewPager)
findViewById(R.id.viewPager);
viewPoints
=
(LinearLayout)
findViewById(R.id.viewGroup);
img_voice
=
(ImageView)
findViewById(R.id.img_voice);
img_expression
=
(ImageView)
findViewById(R.id.img_expression);
img_other
=
(ImageView)
findViewById(R.id.img_other);
layout_other
=
(RelativeLayout)
findViewById(R.id.layout_other);
//照片
im_chat_poto
=
(ImageView)
findViewById(R.id.im_chat_poto);
//
拍摄
im_chat_camera
=
(ImageView)
findViewById(R.id.im_chat_camera);
//
小视频
im_chat_video
=
(ImageView)
findViewById(R.id.im_chat_video);
//
位置
im_chat_location
=
(ImageView)
findViewById(R.id.im_chat_location);
//宽度高度适配
6
WindowManager
wm
=
ChatActivity.this.getWindowManager();
int
width
=
wm.getDefaultDisplay().getWidth();
LinearLayout.LayoutParams
layoutParams
=
new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.width
=
(width
-
PixelOrdpManager.dip2px(getBaseContext(),
16
*
5))
/
4;
layoutParams.height
=
(width
-
PixelOrdpManager.dip2px(getBaseContext(),
16
*
5))
/
4;
layoutParams.leftMargin
=
PixelOrdpManager.dip2px(getBaseContext(),
16);
im_chat_poto.setLayoutParams(layoutParams);
im_chat_camera.setLayoutParams(layoutParams);
im_chat_video.setLayoutParams(layoutParams);
im_chat_location.setLayoutParams(layoutParams);
//加载表情的
initViewPager();
//显示录音图标
img_voice.setImageResource(R.mipmap.im_chat_voice);
//显示表情图标
img_expression.setImageResource(R.mipmap.emoji_bw);
//显示其他图标
img_other.setImageResource(R.mipmap.im_chat_add_normal);
}
private
void
initData()
{
intent
=
getIntent();
if
(intent.getSerializableExtra("mbUserModel")
!=
null)
{
mbUserModel
=
(MBUserModel)
intent.getSerializableExtra("mbUserModel");
meMBUserModel=
MBUserManager.getInstance().getMBUser(LoginManager.userid);
txt_im_object_name.setText(mbUserModel.getNickname());
//
chatAdapter
=
new
ChatAdapter();
//
listView.setAdapter(chatAdapter);
}
}
private
void
initListener()
{
//返回
findViewById(R.id.img_finish).setOnClickListener(new
View.OnClickListener()
{
@Override
public
void
onClick(View
v)
{
SoftKeyboardManager.HideSoftKeyboard(v);
finish();
}
});
//键盘的点击事件
initKeyboardListener();
//
//播放语音
//
findViewById(R.id.txt_start).setOnClickListener(new
View.OnClickListener()
{
//
@Override
//
public
void
onClick(View
v)
{
//
//
mPlayer
=
new
MediaPlayer();
//
try{
//
mPlayer.setDataSource(FileName);
//
mPlayer.prepare();
//
mPlayer.start();
//
}catch(IOException
e){
//
Log.e("ChatActivity","播放失败");
//
}
//
//
}
//
});
}
/**
*
检测Sdcard是否存在
*
*
@return
*/
public
static
boolean
isExitsSdcard()
{
if
(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
return
true;
else
return
false;
}
//
private
PowerManager.WakeLock
wakeLock;
/**
*
按住说话listener
*/
//语音操作对象
private
MediaPlayer
mPlayer
=
null;
private
MediaRecorder
mRecorder
=
null;
//语音文件保存路径
private
String
FileName
=
null;
class
PressToSpeakListen
implements
View.OnTouchListener
{
@SuppressLint({"ClickableViewAccessibility",
"Wakelock"})
@Override
public
boolean
onTouch(View
v,
MotionEvent
event)
{
switch
(event.getAction())
{
case
MotionEvent.ACTION_DOWN:
//语音的显示
layout_voice.setVisibility(View.VISIBLE);
//语音按钮点下
txt_record.setText("松开结束");
txt_record.setBackgroundResource(R.drawable.shape_im_chat_voice_down);
if
(!isExitsSdcard())
{
Toast.makeText(ChatActivity.this,
"发送语音需要sdcard支持!",
Toast.LENGTH_SHORT).show();
return
false;
}
//
try
{
//
v.setPressed(true);
////
wakeLock.acquire();
////
if
(VoicePlayClickListener.isPlaying)
////
VoicePlayClickListener.currentPlayListener
////
.stopPlayVoice();
////
recordingContainer.setVisibility(View.VISIBLE);
////
recordingHint
////
.setText(getString(R.string.move_up_to_cancel));
////
recordingHint.setBackgroundColor(Color.TRANSPARENT);
////
voiceRecorder.startRecording(null,
toChatUsername,
////
getApplicationContext());
//
}
catch
(Exception
e)
{
//
e.printStackTrace();
//
v.setPressed(false);
////
if
(wakeLock.isHeld())
////
wakeLock.release();
////
if
(voiceRecorder
!=
null)
////
voiceRecorder.dis
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024房租租赁合同范本医疗设备租赁合同范本
- 2024华商盛世成长股票型证券投资基金基金合同
- 2024饭店合伙人合同范本
- 2024至2030年中国连续式电磁感应封口机行业投资前景及策略咨询研究报告
- 2024至2030年中国黄铜内螺纹承口接头行业投资前景及策略咨询研究报告
- 2024至2030年中国顺送精密铜料带数据监测研究报告
- 2023年浸渗胶项目成效分析报告
- 2024至2030年中国蝎子纹革数据监测研究报告
- 2024至2030年中国肝康宁行业投资前景及策略咨询研究报告
- 2024至2030年中国玉兰杯碟数据监测研究报告
- 机电安装单价表
- MSDS(T-09)快干水2x3
- 隧道衬砌环向裂缝的成因分析及预防建议
- 浅谈语文课程内容的横向联系
- 《烧烫伤的现场急救》ppt课件
- 职业卫生防护设施台账
- 危重新生儿的病情观察及护理要点
- 中国民航数据通信网项目情况介绍
- 旅游景区管理制度
- 五篇500字左右的短剧剧本
- 新形势下如何加强医院新闻宣传工作
评论
0/150
提交评论