【移動應(yīng)用開發(fā)技術(shù)】怎么在Android中實現(xiàn)微信鍵盤切換效果_第1頁
【移動應(yīng)用開發(fā)技術(shù)】怎么在Android中實現(xiàn)微信鍵盤切換效果_第2頁
【移動應(yīng)用開發(fā)技術(shù)】怎么在Android中實現(xiàn)微信鍵盤切換效果_第3頁
【移動應(yīng)用開發(fā)技術(shù)】怎么在Android中實現(xiàn)微信鍵盤切換效果_第4頁
【移動應(yīng)用開發(fā)技術(shù)】怎么在Android中實現(xiàn)微信鍵盤切換效果_第5頁
已閱讀5頁,還剩85頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

【移動應(yīng)用開發(fā)技術(shù)】怎么在Android中實現(xiàn)微信鍵盤切換效果

怎么在Android中實現(xiàn)微信鍵盤切換效果?相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。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">

<!--發(fā)布評論-->

<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>

<!--//存放當(dāng)前位置照片-->

<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);

}

}下面直接步入正題來介紹代碼中實現(xiàn)的鍵盤切換: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;

//信息內(nèi)容

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;

//獲取的當(dāng)前位置

private

LocationManager

locationManager;

private

String

locationProvider;

Location

location;

//經(jīng)緯度

private

double

latitude;

private

double

longitude;

//判斷是點擊的還是移動地圖的

false

移動地圖

true

點擊

private

boolean

isFirst=false;

private

boolean

isShowMoveLocationCenter=true;

//

獲取當(dāng)前地圖中心點的坐標(biāo)

LatLng

mTarget;

//地圖中心點當(dāng)前的具體位置

//

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;

/**

*

將小圓點的圖片用數(shù)組表示

*/

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;

//當(dāng)前選擇的是錄音

表情

其他

并且顯示

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時會出現(xiàn)閃黑屏的情況(如論視頻是否播放):

getWindow().setFormat(PixelFormat.TRANSLUCENT);

//狀態(tài)欄顏色的設(shè)置

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();

//顯示錄音圖標(biāo)

img_voice.setImageResource(R.mipmap.im_chat_voice);

//顯示表情圖標(biāo)

img_expression.setImageResource(R.mipmap.emoji_bw);

//顯示其他圖標(biāo)

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("松開結(jié)束");

txt_record.setBackgroundResource(R.drawable.shape_im_chat_voice_down);

if

(!isExitsSdcard())

{

Toast.makeText(ChatActivity.this,

"發(fā)送語音需要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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論