欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android仿微信键盘切换效果

程序员文章站 2022-06-12 20:30:53
android 仿微信的键盘切换(录音,表情,文字,其他),im通讯,类似朋友圈只要涉及到文字等相关的app都会要涉及到键盘的处理,今天就给大家分享一下android 仿微信的键盘切换...

android 仿微信的键盘切换(录音,表情,文字,其他),im通讯,类似朋友圈只要涉及到文字等相关的app都会要涉及到键盘的处理,今天就给大家分享一下android 仿微信的键盘切换。

效果图如下:

Android仿微信键盘切换效果

Android仿微信键盘切换效果

Android仿微信键盘切换效果

Android仿微信键盘切换效果

android 仿微信的键盘切换,实现了录音、表情、其他和软键盘显示之间的切换,其中解决了很多博客介绍的键盘切换时,软键盘显示切换到表情(其他)时,出现屏幕晃动的情况,以及点击和滑动键盘显示区域外时,软键盘隐藏的功能等,废话不多说直接上代码,以供大家参考:

xml:

<?xml version="1.0" encoding="utf-8"?>
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/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 android.net.uri;
import android.os.environment;
import android.os.powermanager;
import android.os.systemclock;
import android.provider.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.discardrecording();
////  recordingcontainer.setvisibility(view.invisible);
////  toast.maketext(chatactivity.this, r.string.recoding_fail,
////  toast.length_short).show();
//  return false;
//  }
  //设置sdcard的路径
  filename = environment.getexternalstoragedirectory().getabsolutepath();
  filename += "/audiorecordtest.3gp";
  mrecorder = new mediarecorder();
  mrecorder.setaudiosource(mediarecorder.audiosource.mic);
  mrecorder.setoutputformat(mediarecorder.outputformat.three_gpp);
  mrecorder.setoutputfile(filename);
  mrecorder.setaudioencoder(mediarecorder.audioencoder.amr_nb);
  try {
  mrecorder.prepare();
  } catch (ioexception e) {
  log.e("chatactivity", "prepare() failed");
  }
  mrecorder.start();


  return true;
 case motionevent.action_move: {
  if (event.gety() < 0) {
  txt_im_microphone_show_text.settext("松指取消发送");

//  txt_record.settext("松开结束");
//  txt_record.setbackgroundresource(r.drawable.shape_im_chat_voice_down);
  } else {
  txt_im_microphone_show_text.settext("上滑取消发送");

//  txt_record.settext("按住说话");
//  txt_record.setbackgroundresource(r.drawable.shape_im_chat_voice_up);
  }
  return true;
 }
 case motionevent.action_up:
  //语音的显示
  layout_voice.setvisibility(view.gone);
  //语音按钮点下
  txt_record.settext("按住说话");
  txt_record.setbackgroundresource(r.drawable.shape_im_chat_voice_up);

//  v.setpressed(false);
////  recordingcontainer.setvisibility(view.invisible);
////  if (wakelock.isheld())
////  wakelock.release();
//  if (event.gety() < 0) {
//  // discard the recorded audio.
////  voicerecorder.discardrecording();
//
//  } else {
//  // stop recording and send voice file
////  try {
////  int length = voicerecorder.stoprecoding();
////  if (length > 0) {
////  sendvoice(voicerecorder.getvoicefilepath(),
////   voicerecorder
////   .getvoicefilename(tochatusername),
////   integer.tostring(length), false);
////  } else if (length == emerror.invalid_file) {
////  toast.maketext(getapplicationcontext(), "无录音权限",
////   toast.length_short).show();
////  } else {
////  toast.maketext(getapplicationcontext(), "录音时间太短",
////   toast.length_short).show();
////  }
////  } catch (exception e) {
////  e.printstacktrace();
////  toast.maketext(chatactivity.this, "发送失败,请检测服务器是否连接",
////   toast.length_short).show();
////  }
//
//  }

  mrecorder.stop();
  mrecorder.release();
  mrecorder = null;

  return true;
 default:
//  recordingcontainer.setvisibility(view.invisible);
//  if (voicerecorder != null)
//  voicerecorder.discardrecording();
  return false;
 }
 }
 }


 private void initkeyboardlistener() {

 //录音的点击
 txt_record.setontouchlistener(new presstospeaklisten());

 //照片
 im_chat_poto.setonclicklistener(new view.onclicklistener() {
 @override
 public void onclick(view v) {

 intent intent = new intent();
 intent.settype("image/*");
 intent.setaction(intent.action_get_content);
 intent.addcategory(intent.category_openable);

 startactivityforresult(intent, cameraconstants.request_pick);

 }
 });
 // 拍摄
 im_chat_camera.setonclicklistener(new view.onclicklistener() {
 @override
 public void onclick(view v) {

 if (!(contextcompat.checkselfpermission(getapplicationcontext(), manifest.permission.camera) == packagemanager.permission_granted)) {
  activitycompat.requestpermissions(chatactivity.this, new string[]{manifest.permission.camera}, request_code_camera_permission);
 } else {
  startcamera();
 }

 }
 });
 // 小视频
 im_chat_video.setonclicklistener(new view.onclicklistener() {
 @override
 public void onclick(view v) {

 }
 });
 // 位置
 im_chat_location.setonclicklistener(new view.onclicklistener() {
 @override
 public void onclick(view v) {

 amap.getmapscreenshot(new amap.onmapscreenshotlistener() {
  @override
  public void onmapscreenshot(bitmap bitmap) {

  img_location_map.setimagebitmap(bitmap);
  systemclock.sleep(100);

  runonuithread(new runnable() {
  @override
  public void run() {
  //照片
  bitmap bitmapfinish = getbitmapbyview(scrollview_location_bitmap);
  //照片路径
  string filepath = savepic(bitmapfinish);
  //经纬度 latitude; longitude;
  //位置的描述 currentspecificposition
//  img_bitmap.setimagebitmap(bitmapfinish);
  log.d("chatactivity", filepath);
  log.d("chatactivity", "latitude:" + latitude);
  log.d("chatactivity", "longitude:" + longitude);
  log.d("chatactivity", currentspecificposition);
  // todo: 2016/8/13 位置的信息



  }
  });

  }

  @override
  public void onmapscreenshot(bitmap bitmap, int i) {

  }
 });

 }
 });


 //键盘上边区域被点击键盘收回
 listview.setontouchlistener(new view.ontouchlistener() {
 @override
 public boolean ontouch(view v, motionevent event) {
 currentselect = 0;
 softkeyboardmanager.hidesoftkeyboard(v);
 //显示录音图标
 img_voice.setimageresource(r.mipmap.im_chat_voice);
 //显示表情图标
 img_expression.setimageresource(r.mipmap.emoji_bw);
 //显示其他图标
 img_other.setimageresource(r.mipmap.im_chat_add_normal);

 //表情 其他隐藏
 layout_expression.setvisibility(view.gone);
 layout_other.setvisibility(view.gone);

 txt_im_message.setvisibility(view.visible);
 txt_record.setvisibility(view.gone);

 return false;
 }
 });
 listview.setonscrolllistener(new abslistview.onscrolllistener() {
 @override
 public void onscrollstatechanged(abslistview view, int scrollstate) {
 currentselect = 0;
 softkeyboardmanager.hidesoftkeyboard(view);
 //显示录音图标
 img_voice.setimageresource(r.mipmap.im_chat_voice);
 //显示表情图标
 img_expression.setimageresource(r.mipmap.emoji_bw);
 //显示其他图标
 img_other.setimageresource(r.mipmap.im_chat_add_normal);

 //表情 其他隐藏
 layout_expression.setvisibility(view.gone);
 layout_other.setvisibility(view.gone);

 txt_im_message.setvisibility(view.visible);
 txt_record.setvisibility(view.gone);

 }

 @override
 public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) {

 }
 });
 //评论内容被点击时viewpager
 txt_im_message.setontouchlistener(new view.ontouchlistener() {
 @override
 public boolean ontouch(view v, motionevent event) {
 layout_expression.setvisibility(view.gone);
 isshowexpressionviewpager = false;
 return false;
 }
 });

 //录音
 img_voice.setonclicklistener(new view.onclicklistener() {
 @override
 public void onclick(view v) {

 if (isshowvoice == false) {

  //显示键盘图标
  img_voice.setimageresource(r.mipmap.im_chat_keyboard);
  currentselect = 1;
  //显示录音
  txt_record.setvisibility(view.visible);
  //隐藏输入框
  txt_im_message.setvisibility(view.gone);
  isshowvoice = true;
  softkeyboardmanager.hidesoftkeyboard(v);

 } else if (isshowvoice == true) {

  //显示录音图标
  img_voice.setimageresource(r.mipmap.im_chat_voice);
  currentselect = 0;
  //隐藏录音
  txt_record.setvisibility(view.gone);
  //显示输入框
  txt_im_message.setvisibility(view.visible);
  isshowvoice = false;
  softkeyboardmanager.showsoftkeyboard(v, chatactivity.this);

 }

 //隐藏表情
 layout_expression.setvisibility(view.gone);
 // 隐藏其他
 layout_other.setvisibility(view.gone);


// //显示录音图标
// img_voice.setimageresource(r.mipmap.im_chat_voice);
 //显示表情图标
 img_expression.setimageresource(r.mipmap.emoji_bw);
 //显示其他图标
 img_other.setimageresource(r.mipmap.im_chat_add_normal);

 }
 });

 //表情按钮
 img_expression.setonclicklistener(new view.onclicklistener() {
 @override
 public void onclick(view v) {

 //显示输入框
 txt_im_message.setvisibility(view.visible);

 if (isshowexpressionviewpager == true) {

  //显示表情图标
  img_expression.setimageresource(r.mipmap.emoji_bw);

  currentselect = 0;
  //隐藏表情输入框
  layout_expression.setvisibility(view.gone);
  isshowexpressionviewpager = false;
  softkeyboardmanager.showsoftkeyboard(v, chatactivity.this);
 } else {

  //显示键盘图标
  img_expression.setimageresource(r.mipmap.im_chat_keyboard);

  currentselect = 2;
  //显示表情输入框
//  layout_expression.setvisibility(view.visible);
  new thread(new runnable() {
  @override
  public void run() {
  systemclock.sleep(200);
  runonuithread(new runnable() {
  @override
  public void run() {
   layout_expression.setvisibility(view.visible);
  }
  });

  }
  }).start();

  isshowexpressionviewpager = true;
  softkeyboardmanager.hidesoftkeyboard(v);
 }

 //隐藏录音
 txt_record.setvisibility(view.gone);
 // 隐藏其他
 layout_other.setvisibility(view.gone);


 //显示录音图标
 img_voice.setimageresource(r.mipmap.im_chat_voice);
 //显示表情图标
// img_expression.setimageresource(r.mipmap.emoji_bw);
 //显示其他图标
 img_other.setimageresource(r.mipmap.im_chat_add_normal);

 }
 });

 //其他
 img_other.setonclicklistener(new view.onclicklistener() {
 @override
 public void onclick(view v) {

 //显示输入框
 txt_im_message.setvisibility(view.visible);

 if (isshowother == false) {

  //显示键盘图标
  img_other.setimageresource(r.mipmap.im_chat_keyboard);

  currentselect = 3;
  //显示其他
//  layout_other.setvisibility(view.visible);
  new thread(new runnable() {
  @override
  public void run() {
  systemclock.sleep(200);
  runonuithread(new runnable() {
  @override
  public void run() {
   layout_other.setvisibility(view.visible);
  }
  });

  }
  }).start();

  isshowother = true;
  softkeyboardmanager.hidesoftkeyboard(v);
 } else if (isshowother == true) {

  //显示其他图标
  img_other.setimageresource(r.mipmap.im_chat_add_normal);

  currentselect = 0;
  //隐藏其他
  layout_other.setvisibility(view.gone);
  isshowother = false;
  softkeyboardmanager.showsoftkeyboard(v, chatactivity.this);
 }

 //隐藏录音
 txt_record.setvisibility(view.gone);
 // 隐藏表情
 layout_expression.setvisibility(view.gone);
 //显示录音图标
 img_voice.setimageresource(r.mipmap.im_chat_voice);
 //显示表情图标
 img_expression.setimageresource(r.mipmap.emoji_bw);
 //显示其他图标
// img_other.setimageresource(r.mipmap.im_chat_add_normal);

 }
 });

 //判断软键盘显示隐藏
 keyboardlistenrelativelayout.setonkeyboardstatechangedlistener(new keyboardlistenrelativelayout.ionkeyboardstatechangedlistener() {
 @override
 public void onkeyboardstatechanged(int state) {

 switch (state) {
  case keyboardlistenrelativelayout.keyboard_state_hide://软键盘隐藏
  if (currentselect == 0) {
  //没有点击 录音 表情 其他
  txt_im_message.setvisibility(view.visible);
  txt_record.setvisibility(view.gone);
  layout_expression.setvisibility(view.gone);
  layout_other.setvisibility(view.gone);

  //语音
  isshowvoice = false;
  //表情
  isshowexpressionviewpager = false;
  //其他
  isshowother = false;

  } else if (currentselect == 1) {
  //点击录音
  txt_im_message.setvisibility(view.gone);
  txt_record.setvisibility(view.visible);
  layout_expression.setvisibility(view.gone);
  layout_other.setvisibility(view.gone);

  //语音
  isshowvoice = false;
  //表情
  isshowexpressionviewpager = false;
  //其他
  isshowother = false;

  } else if (currentselect == 2) {
  //点击表情
  txt_im_message.setvisibility(view.visible);
  txt_record.setvisibility(view.gone);

  layout_expression.setvisibility(view.visible);

  layout_other.setvisibility(view.gone);
  //表情
  isshowexpressionviewpager = true;
  //语音
  isshowvoice = false;
  //其他
  isshowother = false;

  } else if (currentselect == 3) {
  //点击其他
  txt_im_message.setvisibility(view.visible);
  txt_record.setvisibility(view.gone);
  layout_expression.setvisibility(view.gone);
  layout_other.setvisibility(view.visible);
  //其他
  isshowother = true;
  //语音
  isshowvoice = false;
  //表情
  isshowexpressionviewpager = false;

  }

  break;
  case keyboardlistenrelativelayout.keyboard_state_show://软键盘显示

  //隐藏录音
  txt_record.setvisibility(view.gone);
  // 隐藏表情
  layout_expression.setvisibility(view.gone);
  //隐藏其他
  layout_other.setvisibility(view.gone);

  isshowexpressionviewpager = false;
  isshowvoice = false;
  isshowother = false;
  break;
  default:
  break;
 }

 }
 });


 listview.setonscrolllistener(new abslistview.onscrolllistener() {
 @override
 public void onscrollstatechanged(abslistview view, int scrollstate) {

 switch (scrollstate) {
  // 当不滚动时
  case abslistview.onscrolllistener.scroll_state_idle:
  case abslistview.onscrolllistener.scroll_state_touch_scroll:
  case abslistview.onscrolllistener.scroll_state_fling:
  softkeyboardmanager.hidesoftkeyboard(view);
  layout_expression.setvisibility(view.gone);
  isshowexpressionviewpager = false;
  break;


 }
 }

 @override
 public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) {

 }
 });


 }

 //聊天适配器
 private class chatadapter extends baseadapter {

 //类型
 //聊天对象文字
 private int typeobjectcharacter = 0;
 // 语音
 private int typeobjectvoice = 1;
 // 照片
 private int typeobjectimg = 2;
 // 位置
 private int typeobjectlocation = 3;

 //自己文字
 private int typemecharacter = 4;
 // 语音
 private int typemevoice = 5;
 // 照片
 private int typemeimg = 6;
 // 位置
 private int typemelocation = 7;

 @override
 public int getcount() {
 return 100;
 }

 @override
 public object getitem(int position) {
 return null;
 }

 @override
 public long getitemid(int position) {
 return 0;
 }

 @override
 public int getitemviewtype(int position) {
// return super.getitemviewtype(position);
 if (position % 11 == 0) {
 return typeobjectcharacter;
 } else if (position % 9 == 0) {
 return typeobjectvoice;
 } else if (position % 8 == 0) {
 return typeobjectimg;
 } else if (position % 7 == 0) {
 return typeobjectlocation;
 } else if (position % 5 == 0) {
 return typemecharacter;
 } else if (position % 3 == 0) {
 return typemevoice;
 } else if (position % 2 == 0) {
 return typemeimg;
 } else {
 return typemelocation;
 }

 }

 @override
 public int getviewtypecount() {
 return 8;
 }

 @override
 public view getview(int position, view convertview, viewgroup parent) {
 objectcharacterviewholder objectcharacterviewholder = null;
 objectvoiceviewholder objectvoiceviewholder = null;
 objectimgviewholder objectimgviewholder = null;
 objectlocationviewholder objectlocationviewholder = null;
 mecharacterviewholder mecharacterviewholder = null;
 mevoiceviewholder mevoiceviewholder = null;
 meimgviewholder meimgviewholder = null;
 melocationviewholder melocationviewholder = null;

 int type = getitemviewtype(position);
 if (convertview == null) {

 if (type == typeobjectcharacter) {
  convertview = getlayoutinflater().inflate(r.layout.inflate_im_chat_object_character, parent, false);
  objectcharacterviewholder = new objectcharacterviewholder();
  objectcharacterviewholder.txt_im_chat_time = (textview) convertview.findviewbyid(r.id.txt_im_chat_time);
  objectcharacterviewholder.img_head_portrait = (roundimageview) convertview.findviewbyid(r.id.img_head_portrait);
  objectcharacterviewholder.txt_im_chat_object_character = (textview) convertview.findviewbyid(r.id.txt_im_chat_object_character);
  convertview.settag(objectcharacterviewholder);
 } else if (type == typeobjectvoice) {
  convertview = getlayoutinflater().inflate(r.layout.inflate_im_chat_object_voice, parent, false);
  objectvoiceviewholder = new objectvoiceviewholder();
  objectvoiceviewholder.txt_im_chat_time = (textview) convertview.findviewbyid(r.id.txt_im_chat_time);
  objectvoiceviewholder.img_head_portrait = (roundimageview) convertview.findviewbyid(r.id.img_head_portrait);
  objectvoiceviewholder.txt_im_chat_object_voice = (textview) convertview.findviewbyid(r.id.txt_im_chat_object_voice);
  objectvoiceviewholder.img_im_chat_object_voice = (imageview) convertview.findviewbyid(r.id.img_im_chat_object_voice);
  objectvoiceviewholder.txt_im_chat_object_voice_seconds = (textview) convertview.findviewbyid(r.id.txt_im_chat_object_voice_seconds);
  objectvoiceviewholder.img_im_chat_object_voice_read_or_noread = (imageview) convertview.findviewbyid(r.id.img_im_chat_object_voice_read_or_noread);
  convertview.settag(objectvoiceviewholder);
 } else if (type == typeobjectimg) {
  convertview = getlayoutinflater().inflate(r.layout.inflate_im_chat_object_img, parent, false);
  objectimgviewholder = new objectimgviewholder();
  objectimgviewholder.txt_im_chat_time = (textview) convertview.findviewbyid(r.id.txt_im_chat_time);
  objectimgviewholder.img_head_portrait = (roundimageview) convertview.findviewbyid(r.id.img_head_portrait);
  objectimgviewholder.img_im_chat_object_img = (imageview) convertview.findviewbyid(r.id.img_im_chat_object_img);
  convertview.settag(objectimgviewholder);
 } else if (type == typeobjectlocation) {
  convertview = getlayoutinflater().inflate(r.layout.inflate_im_chat_object_location, parent, false);
  objectlocationviewholder = new objectlocationviewholder();
  objectlocationviewholder.txt_im_chat_time = (textview) convertview.findviewbyid(r.id.txt_im_chat_time);
  objectlocationviewholder.img_head_portrait = (roundimageview) convertview.findviewbyid(r.id.img_head_portrait);
  objectlocationviewholder.img_im_chat_object_location = (imageview) convertview.findviewbyid(r.id.img_im_chat_object_location);
  convertview.settag(objectlocationviewholder);
 } else if (type == typemecharacter) {
  convertview = getlayoutinflater().inflate(r.layout.inflate_im_chat_me_character, parent, false);
  mecharacterviewholder = new mecharacterviewholder();
  mecharacterviewholder.txt_im_chat_time = (textview) convertview.findviewbyid(r.id.txt_im_chat_time);
  mecharacterviewholder.img_head_portrait = (roundimageview) convertview.findviewbyid(r.id.img_head_portrait);
  mecharacterviewholder.txt_im_chat_me_character = (textview) convertview.findviewbyid(r.id.txt_im_chat_me_character);
  convertview.settag(mecharacterviewholder);
 } else if (type == typemevoice) {
  convertview = getlayoutinflater().inflate(r.layout.inflate_im_chat_me_voice, parent, false);
  mevoiceviewholder = new mevoiceviewholder();
  mevoiceviewholder.txt_im_chat_time = (textview) convertview.findviewbyid(r.id.txt_im_chat_time);
  mevoiceviewholder.img_head_portrait = (roundimageview) convertview.findviewbyid(r.id.img_head_portrait);
  mevoiceviewholder.txt_im_chat_me_voice = (textview) convertview.findviewbyid(r.id.txt_im_chat_me_voice);
  mevoiceviewholder.img_im_chat_me_voice = (imageview) convertview.findviewbyid(r.id.img_im_chat_me_voice);
  mevoiceviewholder.txt_im_chat_me_voice_seconds = (textview) convertview.findviewbyid(r.id.txt_im_chat_me_voice_seconds);
  mevoiceviewholder.img_im_chat_me_voice_read_or_noread = (imageview) convertview.findviewbyid(r.id.img_im_chat_me_voice_read_or_noread);
  convertview.settag(mevoiceviewholder);
 } else if (type == typemeimg) {
  convertview = getlayoutinflater().inflate(r.layout.inflate_im_chat_me_img, parent, false);
  meimgviewholder = new meimgviewholder();
  meimgviewholder.txt_im_chat_time = (textview) convertview.findviewbyid(r.id.txt_im_chat_time);
  meimgviewholder.img_head_portrait = (roundimageview) convertview.findviewbyid(r.id.img_head_portrait);
  meimgviewholder.img_im_chat_me_img = (imageview) convertview.findviewbyid(r.id.img_im_chat_me_img);
  convertview.settag(meimgviewholder);
 } else if (type == typemelocation) {
  convertview = getlayoutinflater().inflate(r.layout.inflate_im_chat_me_location, parent, false);
  melocationviewholder = new melocationviewholder();
  melocationviewholder.txt_im_chat_time = (textview) convertview.findviewbyid(r.id.txt_im_chat_time);
  melocationviewholder.img_head_portrait = (roundimageview) convertview.findviewbyid(r.id.img_head_portrait);
  melocationviewholder.img_im_chat_me_location = (imageview) convertview.findviewbyid(r.id.img_im_chat_me_location);
  convertview.settag(melocationviewholder);
 }

 } else {

 if (type == typeobjectcharacter) {
  objectcharacterviewholder = (objectcharacterviewholder) convertview.gettag();
 } else if (type == typeobjectvoice) {
  objectvoiceviewholder = (objectvoiceviewholder) convertview.gettag();
 } else if (type == typeobjectimg) {
  objectimgviewholder = (objectimgviewholder) convertview.gettag();
 } else if (type == typeobjectlocation) {
  objectlocationviewholder = (objectlocationviewholder) convertview.gettag();
 } else if (type == typemecharacter) {
  mecharacterviewholder = (mecharacterviewholder) convertview.gettag();
 } else if (type == typemevoice) {
  mevoiceviewholder = (mevoiceviewholder) convertview.gettag();
 } else if (type == typemeimg) {
  meimgviewholder = (meimgviewholder) convertview.gettag();
 } else if (type == typemelocation) {
  melocationviewholder = (melocationviewholder) convertview.gettag();
 }

 }


 //设置数据
 if (type == typeobjectcharacter) {
 setobjectcharacterdata(objectcharacterviewholder);
 } else if (type == typeobjectvoice) {
 setobjectvoicedata(objectvoiceviewholder);
 } else if (type == typeobjectimg) {
 setobjectimgdata(objectimgviewholder);
 } else if (type == typeobjectlocation) {
 setobjectlocationdata(objectlocationviewholder);
 } else if (type == typemecharacter) {
 setmecharacterdata(mecharacterviewholder);
 } else if (type == typemevoice) {
 setmevoicedata(mevoiceviewholder);
 } else if (type == typemeimg) {
 setmeimgdata(meimgviewholder);
 } else if (type == typemelocation) {
 setmelocationdata(melocationviewholder);
 }


 return convertview;
 }

 //设置对象文字
 private void setobjectcharacterdata(objectcharacterviewholder objectcharacterviewholder) {

 objectcharacterviewholder.txt_im_chat_time.settext("2013111");
 picasso.with(chatactivity.this).load(mbusermodel.getheadurl() + "!thumb").into(objectcharacterviewholder.img_head_portrait);
 objectcharacterviewholder.txt_im_chat_object_character.settext("哈哈哈老客户卡哈斯的发生哈哈镜和司法斯蒂芬回来好伐啦开始的发生");

 }

 //设置对象语音
 private void setobjectvoicedata(objectvoiceviewholder objectvoiceviewholder) {
 objectvoiceviewholder.txt_im_chat_time.settext("2013111");
 picasso.with(chatactivity.this).load(mbusermodel.getheadurl() + "!thumb").into(objectvoiceviewholder.img_head_portrait);
 }


 //设置对象的照片
 private void setobjectimgdata(objectimgviewholder objectimgviewholder) {
 objectimgviewholder.txt_im_chat_time.settext("32123132");
 picasso.with(chatactivity.this).load(mbusermodel.getheadurl() + "!thumb").into(objectimgviewholder.img_head_portrait);
 }

 //设置对象位置的
 private void setobjectlocationdata(objectlocationviewholder objectlocationviewholder) {
 objectlocationviewholder.txt_im_chat_time.settext("32123132");
 picasso.with(chatactivity.this).load(mbusermodel.getheadurl() + "!thumb").into(objectlocationviewholder.img_head_portrait);
 }


 //设置自己的文字
 private void setmecharacterdata(mecharacterviewholder mecharacterviewholder) {
 mecharacterviewholder.txt_im_chat_time.settext("465654564");
 picasso.with(chatactivity.this).load(membusermodel.getheadurl() + "!thumb").into(mecharacterviewholder.img_head_portrait);
 mecharacterviewholder.txt_im_chat_me_character.settext("离开家电费卡坚实的法律会计师");
 }

 //设置自己的语音
 private void setmevoicedata(mevoiceviewholder mevoiceviewholder) {
 mevoiceviewholder.txt_im_chat_time.settext("465654564");
 picasso.with(chatactivity.this).load(membusermodel.getheadurl() + "!thumb").into(mevoiceviewholder.img_head_portrait);
// mevoiceviewholder.img_im_chat_me_voice

 }

 //设置自己的照片
 private void setmeimgdata(meimgviewholder meimgviewholder) {
 meimgviewholder.txt_im_chat_time.settext("32123132");
 picasso.with(chatactivity.this).load(membusermodel.getheadurl() + "!thumb").into(meimgviewholder.img_head_portrait);
// meimgviewholder.img_im_chat_me_img
 }

 //设置自己的位置
 private void setmelocationdata(melocationviewholder melocationviewholder) {
 melocationviewholder.txt_im_chat_time.settext("51321321");
 picasso.with(chatactivity.this).load(membusermodel.getheadurl() + "!thumb").into(melocationviewholder.img_head_portrait);
// melocationviewholder.img_im_chat_me_location

 }


 //聊天对象文字
 private class objectcharacterviewholder {
 private textview txt_im_chat_time;
 private roundimageview img_head_portrait;
 private textview txt_im_chat_object_character;

 }

 // 语音
 private class objectvoiceviewholder {
 private textview txt_im_chat_time;
 private roundimageview img_head_portrait;
 private textview txt_im_chat_object_voice;
 private imageview img_im_chat_object_voice;
 private textview txt_im_chat_object_voice_seconds;
 private imageview img_im_chat_object_voice_read_or_noread;
 }

 // 照片
 private class objectimgviewholder {
 private textview txt_im_chat_time;
 private roundimageview img_head_portrait;
 private imageview img_im_chat_object_img;
 }

 // 位置
 private class objectlocationviewholder {
 private textview txt_im_chat_time;
 private roundimageview img_head_portrait;
 private imageview img_im_chat_object_location;
 }

 //自己文字
 private class mecharacterviewholder {
 private textview txt_im_chat_time;
 private roundimageview img_head_portrait;
 private textview txt_im_chat_me_character;
 }

 // 语音
 private class mevoiceviewholder {
 private textview txt_im_chat_time;
 private roundimageview img_head_portrait;
 private textview txt_im_chat_me_voice;
 private imageview img_im_chat_me_voice;
 private textview txt_im_chat_me_voice_seconds;
 private imageview img_im_chat_me_voice_read_or_noread;
 }

 // 照片
 private class meimgviewholder {
 private textview txt_im_chat_time;
 private roundimageview img_head_portrait;
 private imageview img_im_chat_me_img;
 }

 // 位置
 private class melocationviewholder {
 private textview txt_im_chat_time;
 private roundimageview img_head_portrait;
 private imageview img_im_chat_me_location;
 }

 }

 private void initviewpager() {

 viewslist = new arraylist<view>();
 view view1 = layoutinflater.from(this).inflate(r.layout.inflate_expression_one, null);
 view view2 = layoutinflater.from(this).inflate(r.layout.inflate_expression_two, null);
 view view3 = layoutinflater.from(this).inflate(r.layout.inflate_expression_there, null);

 viewslist.add(view1);
 viewslist.add(view2);
 viewslist.add(view3);


 //添加小圆点的图片
 imageviews = new imageview[viewslist.size()];
 for (int i = 0; i < viewslist.size(); i++) {
 imageview = new imageview(this);
 //设置小圆点imageview的参数
 linearlayout.layoutparams layoutparams = new linearlayout.layoutparams(20, 20);
 layoutparams.setmargins(10, 0, 10, 0);
// imageview.setlayoutparams(new viewgroup.layoutparams(20,20));//创建一个宽高均为20 的布局
 imageview.setlayoutparams(layoutparams);//创建一个宽高均为20 的布局
 imageview.setpadding(20, 0, 20, 0);
 //默认选中的是第一张图片,此时第一个小圆点是选中状态,其他不是
 if (i == 0) {
 imageview.setbackgroundresource(r.drawable.shape_expression_click);
 } else {
 imageview.setbackgroundresource(r.drawable.shape_expression_unclick);
 }
 //将imageviews添加到小圆点视图组
 viewpoints.addview(imageview);
 imageviews[i] = imageview;

 }
 viewpageradapter = new viewpageradapter(viewslist);
 viewpager.setadapter(viewpageradapter);
 viewpager.setonpagechangelistener(new guidepagechangelistener());

 //设置第一组表情
 initgridviewexpresionone(view1);
 //设置第二组表情
 initgridviewexpresiontwo(view2);
 //设置第三组表情
 initgridviewexpresionthere(view3);
 }

 private string getemojistringbyunicode(int unicode) {
 return new string(character.tochars(unicode));
 }

 //键盘
 private void initgridviewexpresionone(view view) {
 mygridviewexpresionone = (mygridview) view.findviewbyid(r.id.gridview_expression);
 gridadapter = new gridadapter(chatactivity.this);
 unicodeone.add(0, 0x1f604);
 unicodeone.add(1, 0x1f60a);
 unicodeone.add(2, 0x1f603);
 unicodeone.add(3, 0x263a);
 unicodeone.add(4, 0x1f609);
 unicodeone.add(5, 0x1f60d);
 unicodeone.add(6, 0x1f618);
 unicodeone.add(7, 0x1f61a);
 unicodeone.add(8, 0x1f633);
 unicodeone.add(9, 0x1f60c);
 unicodeone.add(10, 0x1f601);
 unicodeone.add(11, 0x1f61c);
 unicodeone.add(12, 0x1f61d);
 unicodeone.add(13, 0x1f612);
 unicodeone.add(14, 0x1f60f);
 unicodeone.add(15, 0x1f613);
 unicodeone.add(16, 0x1f614);
 unicodeone.add(17, 0x1f61e);
 unicodeone.add(18, 0x1f616);
 unicodeone.add(19, 0x1f625);
 unicodeone.add(20, 0x1f630);
 unicodeone.add(21, 0x1f628);
 unicodeone.add(22, 0x1f623);
 unicodeone.add(23, 0x1f622);
 unicodeone.add(24, 0x1f62d);
 unicodeone.add(25, 0x1f602);
 unicodeone.add(26, 0x1f632);
 unicodeone.add(27, 0x1f631);


 mygridviewexpresionone.setadapter(gridadapter);
 gridadapter.setdatatoadapter(unicodeone);
 gridadapter.notifydatasetchanged();

 //点击选择是那一项
 mygridviewexpresionone.setonitemclicklistener(new adapterview.onitemclicklistener() {
 @override
 public void onitemclick(adapterview<?> parent, view view, int position, long id) {

 if (position == 27) {
//  toast.maketext(dynamicdetailactivity.this, "删除" + position, toast.length_short).show();
  if (txt_im_message.gettext().tostring().length() > 0) {
  if (txt_im_message.gettext().tostring().length() == 1) {
  string commentstring = txt_im_message.gettext().tostring().substring(0,
   txt_im_message.gettext().tostring().length() - 1);
  txt_im_message.settext(commentstring);
  } else {
  int lastindex = txt_im_message.gettext().tostring().lastindexof("�");
  if (lastindex == -1) {
  //判断当前的是不是表情
  string commentstring = txt_im_message.gettext().tostring().substring(0,
   txt_im_message.gettext().tostring().length() - 2);
  txt_im_message.settext(commentstring);
  } else {
  //判断当前的是不是表情
  string commentstring = txt_im_message.gettext().tostring().substring(0,
   txt_im_message.gettext().tostring().length() - 1);
  txt_im_message.settext(commentstring);
  }
  }

  }

 } else {
  int unicodejoy = unicodeone.get(position);
  string emojistring = getemojistringbyunicode(unicodejoy);
  txt_im_message.settext(txt_im_message.gettext().tostring().trim() + emojistring);
 }

 txt_im_message.setselection(txt_im_message.gettext().length());

 }
 });


 }

 private void initgridviewexpresiontwo(view view) {

 mygridviewexpresiontwo = (mygridview) view.findviewbyid(r.id.gridview_expression);
 gridadapter = new gridadapter(chatactivity.this);
 unicodetwo.add(0, 0x1f631);
 unicodetwo.add(1, 0x1f620);
 unicodetwo.add(2, 0x1f621);
 unicodetwo.add(3, 0x1f62a);
 unicodetwo.add(4, 0x1f637);
 unicodetwo.add(5, 0x1f47f);
 unicodetwo.add(6, 0x1f47d);
 unicodetwo.add(7, 0x1f49b);
 unicodetwo.add(8, 0x1f499);
 unicodetwo.add(9, 0x1f49c);
 unicodetwo.add(10, 0x1f497);
 unicodetwo.add(11, 0x1f49a);
 unicodetwo.add(12, 0x2764);
 unicodetwo.add(13, 0x1f494);
 unicodetwo.add(14, 0x1f493);
 unicodetwo.add(15, 0x1f498);
 unicodetwo.add(16, 0x2728);
 unicodetwo.add(17, 0x2b50);
 unicodetwo.add(18, 0x1f31f);
 unicodetwo.add(19, 0x1f4a2);
 unicodetwo.add(20, 0x2757);
 unicodetwo.add(21, 0x2755);
 unicodetwo.add(22, 0x2753);
 unicodetwo.add(23, 0x2754);
 unicodetwo.add(24, 0x1f4a4);
 unicodetwo.add(25, 0x1f4a8);
 unicodetwo.add(26, 0x1f4a6);
 unicodetwo.add(27, 0x1f631);


 mygridviewexpresiontwo.setadapter(gridadapter);
 gridadapter.setdatatoadapter(unicodetwo);
 gridadapter.notifydatasetchanged();

 //点击选择是那一项
 mygridviewexpresiontwo.setonitemclicklistener(new adapterview.onitemclicklistener() {
 @override
 public void onitemclick(adapterview<?> parent, view view, int position, long id) {

 if (position == 27) {
  if (txt_im_message.gettext().tostring().length() > 0) {
  if (txt_im_message.gettext().tostring().length() == 1) {
  string commentstring = txt_im_message.gettext().tostring().substring(0,
   txt_im_message.gettext().tostring().length() - 1);
  txt_im_message.settext(commentstring);
  } else {
  int lastindex = txt_im_message.gettext().tostring().lastindexof("�");
  if (lastindex == -1) {
  //判断当前的是不是表情
  string commentstring = txt_im_message.gettext().tostring().substring(0,
   txt_im_message.gettext().tostring().length() - 2);
  txt_im_message.settext(commentstring);
  } else {
  //判断当前的是不是表情
  string commentstring = txt_im_message.gettext().tostring().substring(0,
   txt_im_message.gettext().tostring().length() - 1);
  txt_im_message.settext(commentstring);
  }
  }


  }
 } else {

  int unicodejoy = unicodetwo.get(position);
  string emojistring = getemojistringbyunicode(unicodejoy);
  txt_im_message.settext(txt_im_message.gettext().tostring().trim() + emojistring);
 }

 txt_im_message.setselection(txt_im_message.gettext().length());

 }
 });

 }

 private void initgridviewexpresionthere(view view) {

 mygridviewexpresionthere = (mygridview) view.findviewbyid(r.id.gridview_expression);
 gridadapter = new gridadapter(chatactivity.this);
 unicodethere.add(0, 0x1f3b6);
 unicodethere.add(1, 0x1f3b5);
 unicodethere.add(2, 0x1f525);
 unicodethere.add(3, 0x1f4a9);
 unicodethere.add(4, 0x1f44d);
 unicodethere.add(5, 0x1f44e);
 unicodethere.add(6, 0x1f44c);
 unicodethere.add(7, 0x1f44a);
 unicodethere.add(8, 0x270a);
 unicodethere.add(9, 0x270c);
 unicodethere.add(10, 0x1f44b);
 unicodethere.add(11, 0x270b);
 unicodethere.add(12, 0x1f450);
 unicodethere.add(13, 0x1f446);
 unicodethere.add(14, 0x1f447);
 unicodethere.add(15, 0x1f449);
 unicodethere.add(16, 0x1f448);
 unicodethere.add(17, 0x1f64c);
 unicodethere.add(18, 0x1f64f);
 unicodethere.add(19, 0x261d);
 unicodethere.add(20, 0x1f44f);
 unicodethere.add(21, 0x1f4aa);
 unicodethere.add(22, 0x1f6b6);
 unicodethere.add(23, 0x1f3c3);
 unicodethere.add(24, 0x1f46b);
 unicodethere.add(25, 0x1f483);
 unicodethere.add(26, 0x1f46f);
 unicodethere.add(27, 0x1f631);


 mygridviewexpresionthere.setadapter(gridadapter);
 gridadapter.setdatatoadapter(unicodethere);
 gridadapter.notifydatasetchanged();

 //点击选择是那一项
 mygridviewexpresionthere.setonitemclicklistener(new adapterview.onitemclicklistener() {
 @override
 public void onitemclick(adapterview<?> parent, view view, int position, long id) {

 if (position == 27) {
  if (txt_im_message.gettext().tostring().length() > 0) {
  if (txt_im_message.gettext().tostring().length() == 1) {
  string commentstring = txt_im_message.gettext().tostring().substring(0,
   txt_im_message.gettext().tostring().length() - 1);
  txt_im_message.settext(commentstring);
  } else {
  int lastindex = txt_im_message.gettext().tostring().lastindexof("�");
  if (lastindex == -1) {
  //判断当前的是不是表情
  string commentstring = txt_im_message.gettext().tostring().substring(0,
   txt_im_message.gettext().tostring().length() - 2);
  txt_im_message.settext(commentstring);
  } else {
  //判断当前的是不是表情
  string commentstring = txt_im_message.gettext().tostring().substring(0,
   txt_im_message.gettext().tostring().length() - 1);
  txt_im_message.settext(commentstring);
  }
  }

  }
 } else {

  int unicodejoy = unicodethere.get(position);
  string emojistring = getemojistringbyunicode(unicodejoy);
  txt_im_message.settext(txt_im_message.gettext().tostring().trim() + emojistring);
 }

 txt_im_message.setselection(txt_im_message.gettext().length());

 }
 });

 }


 class guidepagechangelistener implements viewpager.onpagechangelistener {

 @override
 public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) {

 }

 @override
 public void onpageselected(int position) {
 for (int i = 0; i < imageviews.length; i++) {

 imageviews[position].setbackgroundresource(r.drawable.shape_expression_click);

 //不是当前选中的page,其小圆点设置为未选中的状态
 if (position != i) {

  imageviews[i].setbackgroundresource(r.drawable.shape_expression_unclick);

 }

 }

 }

 @override
 public void onpagescrollstatechanged(int state) {

 }
 }

 //适配器
 public class viewpageradapter extends pageradapter {

 private list<view> views;

 public viewpageradapter(list<view> views) {
 this.views = views;
 }

 @override
 public void destroyitem(viewgroup container, int position, object object) {
// super.destroyitem(container, position, object);
 container.removeview(views.get(position));
 }

 @override
 public void finishupdate(viewgroup container) {
// super.finishupdate(container);
 }

 @override
 public int getcount() {
 if (views != null) {
 return views.size();
 }
 return 0;
 }

 @override
 public object instantiateitem(viewgroup container, int position) {
 container.addview(views.get(position));
 return views.get(position);
 }

 @override
 public boolean isviewfromobject(view view, object object) {
 return view == object;
// return false;
 }

 }

 //表情适配器
 private class gridadapter extends baseadapter {
 private layoutinflater layoutinflater;
 arraylist<integer> unicodelist = new arraylist<integer>();

 public void setdatatoadapter(arraylist<integer> picdatas) {
 if (picdatas != null) {
 unicodelist.clear();
 unicodelist.addall(picdatas);
 }
 }

 public gridadapter(context context) {
 layoutinflater = layoutinflater.from(context);
 }

 @override
 public int getcount() {
 if (unicodelist == null) {
 return 0;
 }
 return unicodelist.size();
 }

 @override
 public object getitem(int position) {
 return unicodelist.get(position);
 }

 @override
 public long getitemid(int position) {
 return position;
 }

 @override
 public view getview(int position, view convertview, viewgroup parent) {
 final hodelview hodelview;
 if (convertview == null) {
 convertview = layoutinflater.inflate(r.layout.inflate_expression, parent, false);
 hodelview = new hodelview();
 hodelview.txt_expresion = (textview) convertview.findviewbyid(r.id.txt_expresion);
 convertview.settag(hodelview);
 } else {
 hodelview = (hodelview) convertview.gettag();
 }

// 设置表情数据
 if (unicodelist.size() > 0) {
 if (position < unicodelist.size() - 1) {
  int unicodejoy = unicodelist.get(position);
  string emojistring = getemojistringbyunicode(unicodejoy);
  hodelview.txt_expresion.settext(emojistring);
 } else {
//  relativelayout.layoutparams params = new relativelayout.layoutparams(pixelordpmanager.dip2px(getbasecontext(),30),
//  pixelordpmanager.dip2px(getbasecontext(),20));
  linearlayout.layoutparams params = new linearlayout.layoutparams(viewgroup.layoutparams.wrap_content,
  viewgroup.layoutparams.wrap_content);
  params.setmargins(pixelordpmanager.dip2px(getbasecontext(), 7),
  pixelordpmanager.dip2px(getbasecontext(), 12),
  pixelordpmanager.dip2px(getbasecontext(), 7),
  pixelordpmanager.dip2px(getbasecontext(), 12)
  );
  hodelview.txt_expresion.setlayoutparams(params);
//  hodelview.txt_expresion.setgravity(view.text_alignment_center);
  hodelview.txt_expresion.setbackgroundresource(r.mipmap.delete_emoji);
 }

 }
 return convertview;
 }

 private string getemojistringbyunicode(int unicode) {
 return new string(character.tochars(unicode));
 }

 public class hodelview {
 textview txt_expresion;

 }

 }

 public static final int request_code_camera_permission = 106;

 @override
 public void onrequestpermissionsresult(int requestcode, string[] permissions, int[] grantresults) {

 super.onrequestpermissionsresult(requestcode, permissions, grantresults);

 switch (requestcode) {
 case request_code_camera_permission:

 if (grantresults[0] == packagemanager.permission_granted) {

  startcamera();

 } else {
  if (activitycompat.shouldshowrequestpermissionrationale(this, manifest.permission.camera)) {
  alertdialog.builder builder = new alertdialog.builder(this);
  builder.setmessage("缺少“相机”权限");
  builder.setpositivebutton("知道了", null);
  builder.setcancelable(false);
  builder.show();
  } else {
  alertdialog.builder builder = new alertdialog.builder(this);
  builder.setmessage("缺少“相机”权限\n请到\"工具\"->\"应用\"->\"摩托邦骑行\"->\"权限\"中进行设置");
  builder.setpositivebutton("知道了", null);
  builder.setcancelable(false);
  builder.show();
  }
 }

 break;

 }
 }

 private uri imageuri;

 private void startcamera() {
 intent intent = new intent(mediastore.action_image_capture);

 file filefolder = new file(environment.getexternalstoragedirectory().getabsolutepath() + "/dcim/camera");
 if (!filefolder.exists()) {
 boolean mkdirs = filefolder.mkdirs();
 if (!mkdirs) {
 return;
 }
 }

 imageuri = uri.fromfile(new file(filefolder, system.currenttimemillis() + ".jpg"));
 intent.putextra(mediastore.extra_output, imageuri);

 startactivityforresult(intent, cameraconstants.request_take);
 }


 /***
 * 地图模块获取位置
 * @param savedinstancestate
 */

 private void initmap(bundle savedinstancestate) {
 scrollview_location_bitmap= (scrollview) findviewbyid(r.id.scrollview_location_bitmap);
 img_location_map= (imageview) findviewbyid(r.id.img_location_map);
 mapview = (mapview) findviewbyid(r.id.map_location);
 mapview.oncreate(savedinstancestate);
 if (amap == null) {
 amap = mapview.getmap();
 }
 uisettings muisettings = amap.getuisettings();
 muisettings.setzoomcontrolsenabled(false);// 是否显示放大缩小按钮
 muisettings.setmylocationbuttonenabled(false);// 是否显示定位按钮
 muisettings.setcompassenabled(false);// 是否显示指南针
 muisettings.setscalecontrolsenabled(false); // 是否显示比例尺
 muisettings.setlogoposition(amapoptions.logo_position_bottom_left);// logo位置
 /**
 * 自定义定位图标
 */
 setmylocationstyle();
 /**
 * 设置定位资源
 */
 amap.setlocationsource(this);
 amap.setmylocationenabled(true);
 amap.setmylocationtype(amap.location_type_locate);
 amap.movecamera(cameraupdatefactory.zoomto(16));
 getlocation();
 //准确位置获取
 geocodesearch = new geocodesearch(chatactivity.this);
 geocodesearch.setongeocodesearchlistener(chatactivity.this);
 getaddress(latlonpoint);
 /**
 * 设置地图加载完成回调
 */
 amap.setonmaploadedlistener(new amap.onmaploadedlistener() {
 @override
 public void onmaploaded() {
 /**
  * 设置缩放级别为16
  */
 amap.movecamera(cameraupdatefactory.zoomto(16));
 amap.showmaptext(true);
 amap.showindoormap(false);

 //移动地图
 amap.setoncamerachangelistener(new amap.oncamerachangelistener() {
  @override
  public void oncamerachange(cameraposition cameraposition) {

  }

  @override
  public void oncamerachangefinish(cameraposition cameraposition) {
  if(isfirst==false){
  // 获取当前地图中心点的坐标
  mtarget = amap.getcameraposition().target;
//  currentlatlng=mtarget;
  //准确位置获取
  geocodesearch = new geocodesearch(chatactivity.this);
  geocodesearch.setongeocodesearchlistener(chatactivity.this);
  latlonpoint = new latlonpoint(mtarget.latitude, mtarget.longitude);
  getaddress(latlonpoint);
  isfirst=true;
  //第一次定位移动到定位点作为地图的中心点
  if(isshowmovelocationcenter==true){
  amap.setmylocationtype(amap.location_type_locate);
  isshowmovelocationcenter=false;
  }

  }

  }
 });

 }
 });
 }

 /**
 * 自定义定位图标
 */
 private void setmylocationstyle() {
 mylocationstyle mylocationstyle = new mylocationstyle();// 自定义系统定位小蓝点
 mylocationstyle.mylocationicon(bitmapdescriptorfactory.fromresource(r.mipmap.o_map));// 设置小蓝点的图标
 mylocationstyle.strokecolor(color.transparent);// 设置圆形的边框颜色
 mylocationstyle.radiusfillcolor(color.transparent);// 设置圆形的填充颜色
 mylocationstyle.anchor(0.5f, 0.5f);// 设置小蓝点的锚点
 mylocationstyle.strokewidth(0);// 设置圆形的边框粗细
 amap.setmylocationstyle(mylocationstyle);
 }

 private void getlocation() {
 //经纬度获取
 locationmanager = (locationmanager) getsystemservice(context.location_service);
 list<string> providers = locationmanager.getproviders(true);
 if (providers.contains(locationmanager.network_provider)) {
 locationprovider = locationmanager.network_provider;
 } else if (providers.contains(locationmanager.gps_provider)) {//gps的定位放在第一个 得不到数据
 locationprovider = locationmanager.gps_provider;
 } else {
 return;
 }
 if (activitycompat.checkselfpermission(this, manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(this, manifest.permission.access_coarse_location) != packagemanager.permission_granted) {
 return;
 }
 location = locationmanager.getlastknownlocation(locationprovider);
 if (location != null) {
 showlocation(location);
 latlonpoint = new latlonpoint(location.getlatitude(), location.getlongitude());
 } else {

 }
 locationmanager.requestlocationupdates(locationprovider, 0, 0, locationlistener);

 }

 locationlistener locationlistener = new locationlistener() {
 @override
 public void onlocationchanged(location location) {
 showlocation(location);
 }

 @override
 public void onstatuschanged(string provider, int status, bundle extras) {

 }

 @override
 public void onproviderenabled(string provider) {

 }

 @override
 public void onproviderdisabled(string provider) {

 }
 };


 private void showlocation(location location) {
 latitude = location.getlatitude();
 longitude = location.getlongitude();
 }

 @override
 public void activate(onlocationchangedlistener onlocationchangedlistener) {
 mlistener = onlocationchangedlistener;
 if (mlocationclient == null) {
 mlocationclient = new amaplocationclient(mbutil.getcontext());
 amaplocationclientoption mlocationoption = new amaplocationclientoption();
 mlocationclient.setlocationlistener(this);
 mlocationoption.setlocationmode(amaplocationclientoption.amaplocationmode.hight_accuracy);
 mlocationclient.setlocationoption(mlocationoption);
 mlocationclient.startlocation();
 }
 }

 @override
 public void deactivate() {
 mlistener = null;
 if (mlocationclient != null) {
 mlocationclient.stoplocation();
 mlocationclient.ondestroy();
 }
 mlocationclient = null;
 }

 @override
 public void onlocationchanged(amaplocation amaplocation) {
 if (mlistener != null && amaplocation != null) {
 if (amaplocation.geterrorcode() == 0) {
 mlistener.onlocationchanged(amaplocation);// 显示系统蓝点

 latitude = amaplocation.getlatitude();// 纬度
 longitude = amaplocation.getlongitude();// 经度
 // todo: 2016/6/2
 } else {
 string errtext = "定位失败," + amaplocation.geterrorcode() + ": " + amaplocation.geterrorinfo();
 system.out.println(errtext);
 }
 } else {


 }
 }

 @override
 public void onregeocodesearched(regeocoderesult result, int rcode) {

 if (rcode == 1000) {
 if (result != null && result.getregeocodeaddress() != null && result.getregeocodeaddress().getformataddress() != null) {

 string province = result.getregeocodeaddress().getprovince();
 string district = result.getregeocodeaddress().getdistrict();
 string township = result.getregeocodeaddress().gettownship();
 string neighborhood = result.getregeocodeaddress().getneighborhood();

 //当前具体位置
 currentspecificposition = result.getregeocodeaddress().getformataddress();

 } else {
 toast.maketext(chatactivity.this, "定位失败,请重试", toast.length_short);
 }
 } else if (rcode == 27) {
 toast.maketext(chatactivity.this, "定位失败,请重试", toast.length_short);
 } else if (rcode == 32) {
 toast.maketext(chatactivity.this, "定位失败,请重试", toast.length_short);
 } else {
 toast.maketext(chatactivity.this, "定位失败,请重试", toast.length_short);
 }

 }

 @override
 public void ongeocodesearched(geocoderesult geocoderesult, int i) {

 }
 /**
 * 逆地理编码
 */
 public void getaddress(final latlonpoint latlonpoint) {
 regeocodequery regeocodequery = new regeocodequery(latlonpoint, 200, geocodesearch.amap);
 geocodesearch.getfromlocationasyn(regeocodequery);
 }

 /***
 * scrollview截图
 *
 * @param scrollview
 * @return
 */
 public static bitmap getbitmapbyview(scrollview scrollview) {
 int h = 0;
 bitmap bitmap = null;

 for (int i = 0; i < scrollview.getchildcount(); i++) {
 h += scrollview.getchildat(i).getheight();
 scrollview.getchildat(i).setbackgroundresource(r.mipmap.riding_report);
// scrollview.getchildat(i).setbackgroundcolor(
//  color.parsecolor("0xffffffff"));
 }

 bitmap = bitmap.createbitmap(scrollview.getwidth(), h,
 bitmap.config.rgb_565);
 final canvas canvas = new canvas(bitmap);
 scrollview.draw(canvas);
 return bitmap;
 }

 /**
 * 保存到sdcard
 *
 * @param b
 * @return
 */
 public static string savepic(bitmap b) {
 simpledateformat sdf = new simpledateformat("yyyy-mm-dd_hh-mm-ss",
 locale.us);
 file outfile = new file("/sdcard/image");
 // 如果文件不存在,则创建一个新文件
 if (!outfile.isdirectory()) {
 try {
 outfile.mkdir();
 } catch (exception e) {
 e.printstacktrace();
 }
 }
 string fname = outfile + "/" + sdf.format(new date()) + ".png";
 fileoutputstream fos = null;
 try {
 fos = new fileoutputstream(fname);
 if (null != fos) {
 b.compress(bitmap.compressformat.png, 90, fos);
 fos.flush();
 fos.close();
 }
 } catch (filenotfoundexception e) {
 e.printstacktrace();
 } catch (ioexception e) {
 e.printstacktrace();
 }
 return fname;
 }

 public static final int choose_image = 3;
 @override
 protected void onactivityresult(int requestcode, int resultcode, intent data) {


 if (requestcode == cameraconstants.request_take && resultcode == activity.result_ok) {

 log.d("chatactivity", "imageuri:" + imageuri);
// picasso.with(chatactivity.this).load(imageuri).into(img_bitmap);
// intent intent = new intent(this, cropphotoactivity.class);
// intent.setdata(imageuri);
// intent.putextra("exist", true);
// startactivityforresult(intent, choose_image);
 }

 if (requestcode == cameraconstants.request_pick && resultcode == activity.result_ok) {

// picasso.with(chatactivity.this).load(data.getdata()).into(img_bitmap);
 log.d("chatactivity", "data.getdata():" + data.getdata());

// uri uri = data.getdata();
// intent intent = new intent(this, cropphotoactivity.class);
// intent.setdata(uri);
// intent.putextra("exist", true);
// startactivityforresult(intent, choose_image);
 }

 //纯照片
// if (requestcode == choose_image && resultcode == result_ok) {
// picstringurl = data.getstringextra("filepath");
// log.d("chatactivity", picstringurl);
//
// }
 super.onactivityresult(requestcode, resultcode, data);
 }


}

闲暇之余把相册选取照片,拍摄也给大家提供了,另外我基于高德地图把位置的获取也做了(位置的照片,照片的路径,位置的描述及经纬度都获取了,大家可以自行借鉴,选取自己所需的)

android 仿微信的键盘切换demo

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。