Example usage for android.text TextWatcher TextWatcher

List of usage examples for android.text TextWatcher TextWatcher

Introduction

In this page you can find the example usage for android.text TextWatcher TextWatcher.

Prototype

TextWatcher

Source Link

Usage

From source file:com.blueshit.activity.ChatActivity.java

/**
 * initView//from w w w.  jav  a 2 s. c  om
 */
protected void initView() {
    recordingContainer = findViewById(R.id.recording_container);
    micImage = (ImageView) findViewById(R.id.mic_image);
    recordingHint = (TextView) findViewById(R.id.recording_hint);
    listView = (ListView) findViewById(R.id.list);
    mEditTextContent = (PasteEditText) findViewById(R.id.et_sendmessage);
    buttonSetModeKeyboard = findViewById(R.id.btn_set_mode_keyboard);
    edittext_layout = (RelativeLayout) findViewById(R.id.edittext_layout);
    buttonSetModeVoice = findViewById(R.id.btn_set_mode_voice);
    buttonSend = findViewById(R.id.btn_send);
    buttonPressToSpeak = findViewById(R.id.btn_press_to_speak);
    expressionViewpager = (ViewPager) findViewById(R.id.vPager);
    emojiIconContainer = (LinearLayout) findViewById(R.id.ll_face_container);
    btnContainer = (LinearLayout) findViewById(R.id.ll_btn_container);
    locationImgview = (ImageView) findViewById(R.id.btn_location);
    iv_emoticons_normal = (ImageView) findViewById(R.id.iv_emoticons_normal);
    iv_emoticons_checked = (ImageView) findViewById(R.id.iv_emoticons_checked);
    loadmorePB = (ProgressBar) findViewById(R.id.pb_load_more);
    btnMore = (Button) findViewById(R.id.btn_more);
    iv_emoticons_normal.setVisibility(View.VISIBLE);
    iv_emoticons_checked.setVisibility(View.INVISIBLE);
    more = findViewById(R.id.more);
    edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);

    // ?,
    micImages = new Drawable[] { getResources().getDrawable(R.drawable.record_animate_01),
            getResources().getDrawable(R.drawable.record_animate_02),
            getResources().getDrawable(R.drawable.record_animate_03),
            getResources().getDrawable(R.drawable.record_animate_04),
            getResources().getDrawable(R.drawable.record_animate_05),
            getResources().getDrawable(R.drawable.record_animate_06),
            getResources().getDrawable(R.drawable.record_animate_07),
            getResources().getDrawable(R.drawable.record_animate_08),
            getResources().getDrawable(R.drawable.record_animate_09),
            getResources().getDrawable(R.drawable.record_animate_10),
            getResources().getDrawable(R.drawable.record_animate_11),
            getResources().getDrawable(R.drawable.record_animate_12),
            getResources().getDrawable(R.drawable.record_animate_13),
            getResources().getDrawable(R.drawable.record_animate_14), };

    // list
    reslist = getExpressionRes(35);
    // ?viewpager
    List<View> views = new ArrayList<View>();
    View gv1 = getGridChildView(1);
    View gv2 = getGridChildView(2);
    views.add(gv1);
    views.add(gv2);
    expressionViewpager.setAdapter(new ExpressionPagerAdapter(views));
    edittext_layout.requestFocus();
    voiceRecorder = new VoiceRecorder(micImageHandler);
    buttonPressToSpeak.setOnTouchListener(new PressToSpeakListen());
    mEditTextContent.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            } else {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
            }

        }
    });
    mEditTextContent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
        }
    });
    // ?
    mEditTextContent.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!TextUtils.isEmpty(s)) {
                btnMore.setVisibility(View.GONE);
                buttonSend.setVisibility(View.VISIBLE);
            } else {
                btnMore.setVisibility(View.VISIBLE);
                buttonSend.setVisibility(View.GONE);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

}

From source file:com.erhuoapp.erhuo.activity.ChatActivity.java

/**
 * initView//w w  w .j a  va2 s  .c  om
 */
protected void initView() {
    recordingContainer = findViewById(R.id.recording_container);
    micImage = (ImageView) findViewById(R.id.mic_image);
    recordingHint = (TextView) findViewById(R.id.recording_hint);
    listView = (ListView) findViewById(R.id.list);
    mEditTextContent = (PasteEditText) findViewById(R.id.et_sendmessage);
    buttonSetModeKeyboard = findViewById(R.id.btn_set_mode_keyboard);
    edittext_layout = (RelativeLayout) findViewById(R.id.edittext_layout);
    buttonSetModeVoice = findViewById(R.id.btn_set_mode_voice);
    buttonSend = findViewById(R.id.btn_send);
    buttonPressToSpeak = findViewById(R.id.btn_press_to_speak);
    expressionViewpager = (ViewPager) findViewById(R.id.vPager);
    emojiIconContainer = (LinearLayout) findViewById(R.id.ll_face_container);
    btnContainer = (LinearLayout) findViewById(R.id.ll_btn_container);
    locationImgview = (ImageView) findViewById(R.id.btn_location);
    iv_emoticons_normal = (ImageView) findViewById(R.id.iv_emoticons_normal);
    iv_emoticons_checked = (ImageView) findViewById(R.id.iv_emoticons_checked);
    loadmorePB = (ProgressBar) findViewById(R.id.pb_load_more);
    btnMore = (Button) findViewById(R.id.btn_more);
    iv_emoticons_normal.setVisibility(View.VISIBLE);
    iv_emoticons_checked.setVisibility(View.INVISIBLE);
    more = findViewById(R.id.more);

    // ?,
    micImages = new Drawable[] { getResources().getDrawable(R.drawable.record_animate_01),
            getResources().getDrawable(R.drawable.record_animate_02),
            getResources().getDrawable(R.drawable.record_animate_03),
            getResources().getDrawable(R.drawable.record_animate_04),
            getResources().getDrawable(R.drawable.record_animate_05),
            getResources().getDrawable(R.drawable.record_animate_06),
            getResources().getDrawable(R.drawable.record_animate_07),
            getResources().getDrawable(R.drawable.record_animate_08),
            getResources().getDrawable(R.drawable.record_animate_09),
            getResources().getDrawable(R.drawable.record_animate_10),
            getResources().getDrawable(R.drawable.record_animate_11),
            getResources().getDrawable(R.drawable.record_animate_12),
            getResources().getDrawable(R.drawable.record_animate_13),
            getResources().getDrawable(R.drawable.record_animate_14), };

    // list
    reslist = getExpressionRes(35);
    // ?viewpager
    List<View> views = new ArrayList<View>();
    View gv1 = getGridChildView(1);
    View gv2 = getGridChildView(2);
    views.add(gv1);
    views.add(gv2);
    expressionViewpager.setAdapter(new ExpressionPagerAdapter(views));
    edittext_layout.requestFocus();
    voiceRecorder = new VoiceRecorder(micImageHandler);
    buttonPressToSpeak.setOnTouchListener(new PressToSpeakListen());
    mEditTextContent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
        }
    });
    // ?
    mEditTextContent.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!TextUtils.isEmpty(s)) {
                btnMore.setVisibility(View.GONE);
                buttonSend.setVisibility(View.VISIBLE);
            } else {
                btnMore.setVisibility(View.VISIBLE);
                buttonSend.setVisibility(View.GONE);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    note_click = (RelativeLayout) findViewById(R.id.note_click);
    user_name = (TextView) findViewById(R.id.user_name);
    et_sendphone = (PasteEditText) findViewById(R.id.et_sendphone);
    et_sendplace = (PasteEditText) findViewById(R.id.et_sendplace);
    finish_send = (TextView) findViewById(R.id.finish_send);
    btn_my_note = (ImageView) findViewById(R.id.btn_my_note);

    EntityUserInfo userInfo = AppUtil.getInstance().getBasicUserInfo();
    user_name.setText(userInfo.getNickName());

    btn_my_note.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            note_click.setVisibility(View.VISIBLE);
        }
    });
    note_click.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            note_click.setVisibility(View.INVISIBLE);
        }
    });
    finish_send.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            String phone = et_sendphone.getText().toString().trim();
            String place = et_sendplace.getText().toString().trim();

            if ("".equals(phone)) {
                ToastUtil.showShortToast(ChatActivity.this, "??");
                return;
            }
            if ("".equals(place)) {
                ToastUtil.showShortToast(ChatActivity.this, "??");
                return;
            }
            EntityUserInfo userInfo = AppUtil.getInstance().getBasicUserInfo();

            String s = "??:" + userInfo.getNickName() + "\n?:" + phone + "\n?:" + place;
            sendText(s);

            note_click.setVisibility(View.INVISIBLE);
        }
    });
}

From source file:com.insthub.O2OMobile.Activity.C1_PublishOrderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c1_publish_order);
    mFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    File file = new File(newFileName());
    if (file.exists()) {
        file.delete();//from ww  w.  j av  a2 s.  com
    }

    Intent intent = getIntent();
    mServiceType = (SERVICE_TYPE) intent.getSerializableExtra(O2OMobileAppConst.SERVICE_TYPE);
    mDefaultReceiverId = intent.getIntExtra(DEFAULT_RECEIVER_ID, 0);
    service_list = intent.getStringExtra("service_list");

    mBack = (ImageView) findViewById(R.id.top_view_back);
    mTitle = (TextView) findViewById(R.id.top_view_title);
    mBack.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }
    });
    mArrowImage = (ImageView) findViewById(R.id.top_view_arrow_image);
    mClose = (ImageView) findViewById(R.id.top_view_right_close);
    mTitleView = (LinearLayout) findViewById(R.id.top_view_title_view);
    mServiceTypeView = (FrameLayout) findViewById(R.id.c1_publish_order_service_type_view);
    mServiceTypeListview = (ListView) findViewById(R.id.c1_publish_order_service_type_list);
    mPrice = (EditText) findViewById(R.id.c1_publish_order_price);
    mTime = (TextView) findViewById(R.id.c1_publish_order_time);
    mLocation = (EditText) findViewById(R.id.c1_publish_order_location);
    mText = (EditText) findViewById(R.id.c1_publish_order_text);
    mVoice = (Button) findViewById(R.id.c1_publish_order_voice);
    mVoicePlay = (Button) findViewById(R.id.c1_publish_order_voicePlay);
    mVoiceReset = (ImageView) findViewById(R.id.c1_publish_order_voiceReset);
    mPublish = (Button) findViewById(R.id.c1_publish_order_publish);
    mVoiceView = (FrameLayout) findViewById(R.id.c1_publish_order_voice_view);
    mVoiceAnim = (ImageView) findViewById(R.id.c1_publish_order_voice_anim);
    mVoiceAnim.setImageResource(R.anim.voice_animation);
    mAnimationDrawable = (AnimationDrawable) mVoiceAnim.getDrawable();
    mAnimationDrawable.setOneShot(false);
    mTitleView.setEnabled(false);
    mServiceTypeView.setOnClickListener(null);
    mServiceTypeListview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            if (mDefaultReceiverId == 0) {
                mTitle.setText(mHomeModel.publicServiceTypeList.get(position).title);
                mServiceTypeId = mHomeModel.publicServiceTypeList.get(position).id;
                mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this,
                        mHomeModel.publicServiceTypeList, position);
                mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                mClose.setVisibility(View.GONE);
                mArrowImage.setImageResource(R.drawable.b3_arrow_down);
                AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        mServiceTypeView.setVisibility(View.GONE);
                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 200);
            } else {
                mTitle.setText(mServiceTypeList.get(position).title);
                mServiceTypeId = mServiceTypeList.get(position).id;
                mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this,
                        mServiceTypeList, position);
                mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                mClose.setVisibility(View.GONE);
                mArrowImage.setImageResource(R.drawable.b3_arrow_down);
                AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        mServiceTypeView.setVisibility(View.GONE);
                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 200);
            }

        }
    });

    mTitleView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            if (mServiceTypeView.getVisibility() == View.GONE) {
                mServiceTypeView.setVisibility(View.VISIBLE);
                mClose.setVisibility(View.VISIBLE);
                mArrowImage.setImageResource(R.drawable.b4_arrow_up);
                AnimationUtil.showAnimationFromTop(mServiceTypeListview);
                closeKeyBoard();
            } else {
                mClose.setVisibility(View.GONE);
                mArrowImage.setImageResource(R.drawable.b3_arrow_down);
                AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        mServiceTypeView.setVisibility(View.GONE);
                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 200);
            }
        }
    });

    mClose.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mClose.setVisibility(View.GONE);
            mArrowImage.setImageResource(R.drawable.b3_arrow_down);
            AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
            Handler mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    mServiceTypeView.setVisibility(View.GONE);
                }
            };
            mHandler.sendEmptyMessageDelayed(0, 200);
        }
    });

    mPrice.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            if (s.toString().length() > 0) {
                if (s.toString().substring(0, 1).equals(".")) {
                    s = s.toString().substring(1, s.length());
                    mPrice.setText(s);
                }
            }
            if (s.toString().length() > 1) {
                if (s.toString().substring(0, 1).equals("0")) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        s = s.toString().substring(1, s.length());
                        mPrice.setText(s);
                        CharSequence charSequencePirce = mPrice.getText();
                        if (charSequencePirce instanceof Spannable) {
                            Spannable spanText = (Spannable) charSequencePirce;
                            Selection.setSelection(spanText, charSequencePirce.length());
                        }
                    }
                }
            }
            boolean flag = false;
            for (int i = 0; i < s.toString().length() - 1; i++) {
                String getstr = s.toString().substring(i, i + 1);
                if (getstr.equals(".")) {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                int i = s.toString().indexOf(".");
                if (s.toString().length() - 3 > i) {
                    String getstr = s.toString().substring(0, i + 3);
                    mPrice.setText(getstr);
                    CharSequence charSequencePirce = mPrice.getText();
                    if (charSequencePirce instanceof Spannable) {
                        Spannable spanText = (Spannable) charSequencePirce;
                        Selection.setSelection(spanText, charSequencePirce.length());
                    }
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
        }
    });

    initData();

    mHomeModel = new HomeModel(this);
    mHomeModel.addResponseListener(this);
    if (mDefaultReceiverId == 0) {
        mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0);
        mHomeData = mShared.getString("home_data", "");
        if ("".equals(mHomeData)) {
            mHomeModel.getServiceTypeList();
        } else {
            try {
                servicetypelistResponse response = new servicetypelistResponse();
                response.fromJson(new JSONObject(mHomeData));
                mHomeModel.publicServiceTypeList = response.services;
                setServiceTypeAdater();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    } else {
        if (service_list != null && !"".equals(service_list)) {
            try {
                JSONObject userJson = new JSONObject(service_list);
                myservicelistResponse response = new myservicelistResponse();
                response.fromJson(userJson);
                for (int i = 0; i < response.services.size(); i++) {
                    SERVICE_TYPE service = new SERVICE_TYPE();
                    service = response.services.get(i).service_type;
                    mServiceTypeList.add(service);
                }
                if (mServiceTypeList.size() > 0) {
                    mTitleView.setEnabled(true);
                    mArrowImage.setVisibility(View.VISIBLE);
                    if (mServiceType != null) {
                        for (int i = 0; i < mServiceTypeList.size(); i++) {
                            if (mServiceType.id == mServiceTypeList.get(i).id) {
                                mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList, i);
                                mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                                mTitle.setText(mServiceTypeList.get(i).title);
                                mServiceTypeId = mServiceTypeList.get(i).id;
                                break;
                            }
                        }
                    } else {
                        mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList);
                        mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                        mTitle.setText(getString(R.string.select_service));
                    }

                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0);
            mHomeData = mShared.getString("home_data", "");
            if ("".equals(mHomeData)) {
                mHomeModel.getServiceTypeList();
            } else {
                try {
                    servicetypelistResponse response = new servicetypelistResponse();
                    response.fromJson(new JSONObject(mHomeData));
                    mHomeModel.publicServiceTypeList = response.services;
                    setServiceTypeAdater();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    mLocationInfoModel = new LocationInfoModel(this);
    mLocationInfoModel.addResponseListener(this);
    mLocationInfoModel.get();

    mOrderPublishModel = new OrderPublishModel(this);
    mOrderPublishModel.addResponseListener(this);

    //??
    CharSequence charSequencePirce = mPrice.getText();
    if (charSequencePirce instanceof Spannable) {
        Spannable spanText = (Spannable) charSequencePirce;
        Selection.setSelection(spanText, charSequencePirce.length());
    }
    CharSequence charSequenceLocation = mLocation.getText();
    if (charSequenceLocation instanceof Spannable) {
        Spannable spanText = (Spannable) charSequenceLocation;
        Selection.setSelection(spanText, charSequenceLocation.length());
    }

    mVoice.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                closeKeyBoard();
                mVoice.setKeepScreenOn(true);
                mMaxTime = MAX_TIME;
                mVoiceView.setVisibility(View.VISIBLE);
                mAnimationDrawable.start();
                startRecording();
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                mVoice.setKeepScreenOn(false);
                mVoiceView.setVisibility(View.GONE);
                mAnimationDrawable.stop();
                if (mMaxTime > 28) {
                    mVoice.setEnabled(false);
                    Handler mHandler = new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                            super.handleMessage(msg);
                            stopRecording();
                            mVoice.setEnabled(true);
                        }
                    };
                    mHandler.sendEmptyMessageDelayed(0, 500);
                } else {
                    stopRecording();
                }
            } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
                mVoice.setKeepScreenOn(false);
                mVoiceView.setVisibility(View.GONE);
                mAnimationDrawable.stop();
                if (mMaxTime > 28) {
                    mVoice.setEnabled(false);
                    Handler mHandler = new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                            super.handleMessage(msg);
                            stopRecording();
                            mVoice.setEnabled(true);
                        }
                    };
                    mHandler.sendEmptyMessageDelayed(0, 500);
                } else {
                    stopRecording();
                }
            } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
                mVoice.getParent().requestDisallowInterceptTouchEvent(true);
            }
            return false;
        }
    });

    mVoicePlay.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (mPlayer == null) {
                File file = new File(mFileName);
                if (file.exists()) {
                    mPlayer = new MediaPlayer();
                    mVoicePlay.setBackgroundResource(R.anim.record_animation);
                    mAnimationDrawable2 = (AnimationDrawable) mVoicePlay.getBackground();
                    mAnimationDrawable2.setOneShot(false);
                    mAnimationDrawable2.start();
                    try {
                        mPlayer.setDataSource(mFileName);
                        mPlayer.prepare();
                        mPlayer.start();
                        mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                            @Override
                            public void onCompletion(MediaPlayer mp) {
                                mp.reset();
                                mPlayer = null;
                                mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn);
                                mAnimationDrawable2.stop();
                            }
                        });
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } else {
                    Toast.makeText(C1_PublishOrderActivity.this, getString(R.string.file_does_not_exist),
                            Toast.LENGTH_SHORT).show();
                }
            } else {
                mPlayer.release();
                mPlayer = null;
                mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn);
                mAnimationDrawable2.stop();
            }
        }
    });

    mVoiceReset.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (mPlayer != null) {
                mPlayer.release();
                mPlayer = null;
                mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn);
                mAnimationDrawable2.stop();
            }
            File file = new File(mFileName);
            if (file.exists()) {
                file.delete();
            }
            mVoice.setVisibility(View.VISIBLE);
            mVoicePlay.setVisibility(View.GONE);
            mVoiceReset.setVisibility(View.GONE);
        }
    });

    mPublish.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            File file = new File(newFileName());
            int duration = 0;
            if (file.exists()) {
                MediaPlayer mp = MediaPlayer.create(C1_PublishOrderActivity.this, Uri.parse(mFileName));
                if (null != mp) {
                    duration = mp.getDuration();//? ms
                    mp.release();
                }
                if (duration % 1000 > 500) {
                    duration = duration / 1000 + 1;
                } else {
                    duration = duration / 1000;
                }
            } else {
                file = null;
            }
            int num = 0;
            try { // ??
                Date date = new Date();
                Date date1 = mFormat.parse(mFormat.format(date));
                Date date2 = mFormat.parse(mTime.getText().toString());
                num = date2.compareTo(date1);

                if (num < 0) {
                    long diff = date1.getTime() - date2.getTime();
                    long mins = diff / (1000 * 60);
                    if (mins < 3) {
                        num = 1;
                    }
                }
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (mServiceTypeId == 0) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                        getString(R.string.select_service));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mPrice.getText().toString().equals("")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.price_range));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mPrice.getText().toString().equals("0.")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.right_price));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mTime.getText().toString().equals("")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.appoint_time));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (num < 0) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                        getString(R.string.wrong_appoint_time_hint));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mLocation.getText().toString().equals("")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                        getString(R.string.appoint_location_hint));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else {
                mOrderPublishModel.publish(mPrice.getText().toString(), mTime.getText().toString(),
                        mLocation.getText().toString(), mText.getText().toString(), file, mServiceTypeId,
                        mDefaultReceiverId, duration);
            }
        }
    });
}

From source file:com.mezcaldev.hotlikeme.ChatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat_hlm);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*  www. ja va2s .co  m*/

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    Bundle bundle = getIntent().getExtras();

    if (bundle.getString("userChat") != null) {
        mUserChatId = bundle.getString("userChat");
        MESSAGES_CHILD = "/chats/" + mUserChatId;
        MESSAGES_RESUME = "/chats_resume/" + mUserChatId;

        myKey = FireConnection.getInstance().genHashKey(mUserChatId);
        secureMessage = new SecureMessage(myKey);
    }
    if (bundle.getString("userName") != null) {
        setTitle(bundle.getString("userName"));
    }
    if (fireConfigMessageLimit > 0) {
        MESSAGE_LIMIT = fireConfigMessageLimit;
    }
    if (fireConfigMessageOld > 0) {
        ADD_OLD_MESSAGES = fireConfigMessageOld;
    }
    if (fireConfigMessageLength > 0) {
        MSG_LENGTH_LIMIT = fireConfigMessageLength;
    }
    if (fireConfigMessagesMax > 0) {
        MAX_MESSAGES_DECRYPTED = fireConfigMessagesMax;
    }

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mUsername = ANONYMOUS;

    // Initialize Firebase Auth
    mFirebaseAuth = FirebaseAuth.getInstance();
    mFirebaseUser = mFirebaseAuth.getCurrentUser();

    if (mFirebaseUser == null) {
        // Not signed in, launch the Sign In activity
        startActivity(new Intent(this, HLMActivity.class));
        finish();
        return;
    } else {
        mUsername = mFirebaseUser.getDisplayName();
        if (mFirebaseUser.getPhotoUrl() != null) {
            mPhotoUrl = mFirebaseUser.getPhotoUrl().toString();
        } else {
            mPhotoUrl = null;
        }
    }

    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    fab_send = (FloatingActionButton) findViewById(R.id.fab_send);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshChat);
    mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView);
    mMessageRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    fab_send.setClickable(false);
    fab_send.setEnabled(false);

    mMessageRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
            hideSoftKeyboard(ChatActivity.this);
            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
            hideSoftKeyboard(ChatActivity.this);
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });

    mLinearLayoutManager = new LinearLayoutManager(this);
    mLinearLayoutManager.setStackFromEnd(true);

    mFirebaseDatabaseReference = databaseGlobal.getReference();
    databaseReferenceLastMessages = mFirebaseDatabaseReference.child(MESSAGES_CHILD);

    recentMessages = databaseReferenceLastMessages.limitToLast(MESSAGE_LIMIT);
    preloadMessages = databaseReferenceLastMessages.limitToLast(MAX_MESSAGES_DECRYPTED);

    preloadMessages.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            totalMessages = dataSnapshot.getChildrenCount();
            if (totalMessages == 0) {
                flagMessagesDecrypted = true;
                Log.v(TAG, "Zero Message to decrypt!");
            }
            Log.i(TAG, "Childrens: " + totalMessages);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            final int currentMessagePosition = mLinearLayoutManager.findFirstCompletelyVisibleItemPosition();
            MESSAGE_LIMIT += ADD_OLD_MESSAGES;
            Log.i(TAG, "New Message Limit: " + MESSAGE_LIMIT);
            Toast.makeText(getApplicationContext(), "Loading Old Messages", Toast.LENGTH_LONG).show();

            recentMessages = databaseReferenceLastMessages.limitToLast(MESSAGE_LIMIT);

            mProgressBar.setVisibility(View.VISIBLE);
            mLinearLayoutManager.setStackFromEnd(false);
            updateFireBaseRecyclerAdapter();

            Handler handlerRefreshSign = new Handler();
            handlerRefreshSign.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (swipeRefreshLayout.isRefreshing()) {
                        swipeRefreshLayout.setRefreshing(false);
                    }
                }
            }, ONE_SECOND);

            Handler handlerShowOldMessages = new Handler();
            handlerShowOldMessages.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mProgressBar.setVisibility(View.INVISIBLE);
                    mMessageRecyclerView
                            .smoothScrollToPosition(currentMessagePosition + (ADD_OLD_MESSAGES / 2));
                }
            }, bigDelay);
        }
    });

    mMessageEditText = (EditText) findViewById(R.id.messageEditText);
    mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
            mSharedPreferences.getInt(ChatRemotePreferences.FRIENDLY_MSG_LENGTH, MSG_LENGTH_LIMIT)) });
    mMessageEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            mLinearLayoutManager.setStackFromEnd(true);
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            if (charSequence.toString().trim().length() > 0) {
                fab_send.setClickable(true);
                fab_send.setEnabled(true);

            } else {
                fab_send.setClickable(false);
                fab_send.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    fab_send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            checkNetworkAccess();

            if (mLinearLayoutManager.getItemCount() - 1 >= 0) {
                mMessageRecyclerView.smoothScrollToPosition(mLinearLayoutManager.getItemCount() - 1);
            }
            new SendOnBackground().execute(mMessageEditText.getText().toString());

        }
    });

    //Check if Network is available
    checkNetworkAccess();
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            preloadDecryptedMessages();
        }
    }, 200);
}

From source file:com.hybris.mobile.app.commerce.adapter.ProductListAdapterBase.java

@Override
public void bindView(View rowView, final Context context, final Cursor cursor) {

    // When clicking outside a EditText, hide keyboard, remove focus and
    // reset to the default value
    // Clicking on the main view
    rowView.setOnTouchListener(new OnTouchListener() {

        @Override/* w w  w.j a  v a  2  s .co  m*/
        public boolean onTouch(View v, MotionEvent event) {
            UIUtils.hideKeyboard(getContext());
            v.performClick();
            return false;
        }
    });

    final ProductViewHolder productViewHolder = (ProductViewHolder) rowView.getTag();
    final ProductBase product = getData();

    if (mCurrentSelectedPosition == cursor.getPosition()) {
        //TODO when item is in scrapview, index changed and wrong item is opened
        //createExpandedView(mProductViewHolder, cursor.getPosition());
    } else {

        // Populate name and code for a product when row collapsed
        productViewHolder.productName.setText(product.getName());
        productViewHolder.productNo.setText(product.getCode());
        productViewHolder.quantityEditText.setText(getContext().getString(R.string.default_qty));
        String rangeFormattedPrice = product.getPriceRangeFormattedValue();

        if (product.getPriceRange().getMaxPrice() != null) {
            rangeFormattedPrice = StringUtils
                    .isNotBlank(product.getPriceRange().getMaxPrice().getFormattedValue())
                    && StringUtils.isNotBlank(product.getPriceRange().getMinPrice().getFormattedValue())
                            ? product.getPriceRangeFormattedValue()
                            : "";

            if (StringUtils.isBlank(rangeFormattedPrice)) {
                if (product.getPriceRange().getMaxPrice().getValue() != null
                        && product.getPriceRange().getMinPrice().getValue() != null) {

                    rangeFormattedPrice = "$" + product.getPriceRange().getMinPrice().getValue() + ".00 - "
                            + "$" + product.getPriceRange().getMaxPrice().getValue() + ".00";
                }
            }
        }
        productViewHolder.productPrice.setText(rangeFormattedPrice);

        //Rating
        if (product.getAverageRating() != null) {
            productViewHolder.productItemRating.setVisibility(View.VISIBLE);
            productViewHolder.productItemRating.setRating(product.getAverageRating().floatValue());

            productViewHolder.productItemRatingExpanded.setVisibility(View.VISIBLE);
            productViewHolder.productItemRatingExpanded.setRating(product.getAverageRating().floatValue());
        } else {
            productViewHolder.productItemRating.setVisibility(View.GONE);
            productViewHolder.productItemRatingExpanded.setVisibility(View.GONE);
        }

        // Loading the product image
        loadProductImage(product.getImageThumbnailUrl(), productViewHolder.productImage,
                productViewHolder.productImageLoading, product.getCode());
        productViewHolder.collapse();

        if (product.getMultidimensional() != null && product.getMultidimensional()) {
            // Show arrow down with variants
            productViewHolder.productPriceTotal.setVisibility(View.GONE);
            productViewHolder.productImageViewCartIcon.setVisibility(View.GONE);
            productViewHolder.productImageViewExpandIcon.setVisibility(View.VISIBLE);
            productViewHolder.productItemAddQuantityLayout.setVisibility(View.GONE);
            productViewHolder.quantityEditText.setVisibility(View.GONE);
            productViewHolder.productAvailability.setVisibility(View.GONE);
            productViewHolder.productItemInStock.setVisibility(View.GONE);

            productViewHolder.productImageLoadingExpanded.setVisibility(View.VISIBLE);
            productViewHolder.productItemStockLevelLoadingExpanded.setVisibility(View.VISIBLE);
            productViewHolder.productImageExpanded.setVisibility(View.GONE);
            productViewHolder.productAvailabilityExpanded.setVisibility(View.GONE);

            /**
             * Gray out button
             */
            productViewHolder.setAddCartButton(true);
        } else {
            // Show cart icon without variants
            productViewHolder.productItemAddQuantityLayout.setVisibility(View.VISIBLE);
            productViewHolder.productPriceTotal.setVisibility(View.VISIBLE);
            productViewHolder.productPriceTotal.setText(productViewHolder.setTotalPrice(product.getPrice(),
                    productViewHolder.quantityEditText.getText().toString()));
            productViewHolder.productImageViewCartIcon.setVisibility(View.VISIBLE);
            productViewHolder.productImageViewExpandIcon.setVisibility(View.GONE);
            productViewHolder.quantityEditText.setEnabled(true);
            productViewHolder.quantityEditText.setVisibility(View.VISIBLE);
            productViewHolder.productAvailability.setText(product.getStock().getStockLevel() + "");
            productViewHolder.productItemInStock.setVisibility(View.VISIBLE);

            productViewHolder.setAddCartButton(true);

            if (product.isLowStock() || product.isOutOfStock()) {
                productViewHolder.productAvailability
                        .setTextColor(getContext().getResources().getColor(R.color.product_item_low_stock));
                productViewHolder.productItemInStock
                        .setTextColor(getContext().getResources().getColor(R.color.product_item_low_stock));
                productViewHolder.productAvailability
                        .setContentDescription(getContext().getString(R.string.product_item_low_stock));

                if (product.isOutOfStock()) {
                    productViewHolder.quantityEditText.setEnabled(false);
                    productViewHolder.quantityEditText.setText("");

                }

            }

            if (product.isInStock()) {
                productViewHolder.productAvailability.setText("");
                productViewHolder.productItemInStock
                        .setTextColor(getContext().getResources().getColor(R.color.product_item_in_stock));
            }

        }

    }

    /**
     * Product item row is collapsed and user click the arrow down icon to expand
     */
    productViewHolder.productImageViewExpandIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            // Expanded
            getContext().getLoaderManager().restartLoader(0, null, getProductLoaderExpandView(product,
                    getContext(), CommerceApplication.getContentServiceHelper(), new OnRequestListener() {

                        @Override
                        public void beforeRequest() {
                            // Expanded
                            productViewHolder.productImageLoadingExpanded.setVisibility(View.VISIBLE);
                            productViewHolder.productItemStockLevelLoadingExpanded.setVisibility(View.VISIBLE);
                            productViewHolder.productImageExpanded.setVisibility(View.GONE);
                            productViewHolder.productAvailabilityExpanded.setVisibility(View.GONE);
                            UIUtils.showLoadingActionBar(getContext(), true);
                        }

                        @Override
                        public void afterRequestBeforeResponse() {
                            if (mCurrentSelectedViewHolder != null) {
                                mCurrentSelectedViewHolder.collapse();
                            }

                            mCurrentSelectedPosition = cursor.getPosition();
                            mCurrentSelectedViewHolder = productViewHolder;
                        }

                        @Override
                        public void afterRequest(boolean isDataSynced) {
                            productViewHolder.productImageLoadingExpanded.setVisibility(View.GONE);
                            productViewHolder.productItemStockLevelLoadingExpanded.setVisibility(View.GONE);
                            productViewHolder.productImageExpanded.setVisibility(View.VISIBLE);
                            productViewHolder.productAvailabilityExpanded.setVisibility(View.VISIBLE);
                            productViewHolder.productImageLoading.setVisibility(View.GONE);
                            UIUtils.showLoadingActionBar(getContext(), false);

                        }
                    }, new OnProductLoaded() {
                        @Override
                        public void onProductLoaded(ProductBase productBase, String productCodeFirstVariant) {

                            if (productBase != null) {
                                createExpandedView(mCurrentSelectedViewHolder, productBase);

                                if (!mTriggerSpinnerOnChange) {
                                    mNbVariantLevels = populateVariants(mSpinnersVariants, productBase);

                                    if (StringUtils.isNotBlank(productCodeFirstVariant)) {
                                        selectVariant(productCodeFirstVariant);
                                    }
                                }

                            }

                        }
                    }));

        }
    });

    /**
     * Detect when text is changed
     */
    productViewHolder.quantityEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            try {

                if (cursor.getCount() > cursor.getPosition() && product != null) {
                    if (product.getPrice() != null) {
                        productViewHolder.productPriceTotal.setText(productViewHolder.setTotalPrice(
                                product.getPrice(), productViewHolder.quantityEditText.getText().toString()));
                    }
                }
                productViewHolder.setAddCartButton(true);
            } catch (NumberFormatException e) {
                Log.e(TAG, e.getLocalizedMessage());
            }

        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    /**
     * Detect when text is changed
     */
    productViewHolder.quantityEditTextExpanded.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            try {
                if (cursor.getCount() > cursor.getPosition() && product.getPrice() != null) {
                    productViewHolder.productPriceTotalExpanded
                            .setText(productViewHolder.setTotalPrice(product.getPrice(),
                                    productViewHolder.quantityEditTextExpanded.getText().toString()));
                }
                productViewHolder.setAddCartButton(true);
            } catch (NumberFormatException e) {
                Log.e(TAG, e.getLocalizedMessage());
            }

        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    /**
     * Add to cart when user click on cartIcon in Product item collapsed row
     */
    productViewHolder.productImageViewCartIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            addToCart(product.getCode(), productViewHolder.quantityEditText.getText().toString(),
                    productViewHolder);
            productViewHolder.quantityEditText.setText(getContext().getString(R.string.default_qty));
        }
    });

    productViewHolder.quantityEditText.setOnEditorActionListener(new SubmitListener() {

        @Override
        public void onSubmitAction() {
            addToCart(product.getCode(), productViewHolder.quantityEditText.getText().toString(),
                    productViewHolder);
            productViewHolder.quantityEditText.setText(getContext().getString(R.string.default_qty));
        }
    });

    /**
     * Product item row is expanded and user click the arrow up icon to collapse
     */
    productViewHolder.productItemButtonCollpaseLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            // collapsed
            productViewHolder.collapse();
            mCurrentSelectedViewHolder.collapse();

        }
    });

    /**
     * Product item row is collapsed and user click on the main part of the row to navigate to the product detail page
     */
    productViewHolder.productItemClickableLayoutCollapsed.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ProductHelper.redirectToProductDetail(getContext(),
                    StringUtils.isNotBlank(getFirstVariantCode(product)) ? getFirstVariantCode(product)
                            : product.getCode());
        }
    });

    /**
     * Product item row is collapsed and user click on the main part of the row to navigate to the product detail page
     */
    productViewHolder.productItemClickableLayoutExpanded.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ProductHelper.redirectToProductDetail(getContext(),
                    StringUtils.isNotBlank(getFirstVariantCode(product)) ? getFirstVariantCode(product)
                            : product.getCode());
        }
    });

}

From source file:com.speedtong.example.ui.chatting.ChattingActivity.java

/**
 * ????//from   ww  w  .  j  a v a2  s  . c o m
 */
private void initView() {
    mPullDownView = (RefreshableView) findViewById(R.id.chatting_pull_down_view);
    mPullDownView.setOnRefreshListener(new RefreshableView.PullToRefreshListener() {

        @Override
        public void onRefresh() {
            long lastTime = System.currentTimeMillis();
            if (mChattingAdapter != null) {
                ECMessage item = mChattingAdapter.getItem(0);
                if (item != null) {
                    lastTime = item.getMsgTime();
                }
            }
            try {
                Thread.sleep(400);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            final ArrayList<ECMessage> queryIMessageList = IMessageSqlManager.queryIMessageList(mThread, 20,
                    lastTime + "");
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    mChattingAdapter.insertDataArrays(queryIMessageList);
                    if (queryIMessageList != null && (queryIMessageList.size()) > 0) {
                        mPageCount -= queryIMessageList.size();
                        LogUtil.d(TAG, "onRefreshing history msg count " + queryIMessageList.size());
                        mListView.setSelectionFromTop(queryIMessageList.size() + 1,
                                mListViewHeadView.getHeight() + mPullDownView.getTopViewHeight());
                    } else {
                        mListView.setSelectionFromTop(1,
                                mListViewHeadView.getHeight() + mPullDownView.getTopViewHeight());
                        mPageCount = 0;
                        mPullDownView.setPullEnabled(false);
                    }

                    mPullDownView.finishRefreshing();
                }
            });
        }
    }, 0);
    mListView = (ListView) findViewById(R.id.chatting_history_lv);
    mListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
    mListView.setItemsCanFocus(false);
    mListView.setOnScrollListener(this);
    mListView.setKeepScreenOn(true);
    mListView.setStackFromBottom(false);
    mListView.setFocusable(false);
    mListView.setFocusableInTouchMode(false);

    mListViewHeadView = getLayoutInflater().inflate(R.layout.chatting_list_header, null);
    mListView.addHeaderView(mListViewHeadView);

    mPullDownView.setOnPullDownOnTouchListener(new RefreshableView.OnPullDownOnTouchListener() {

        @Override
        public void OnPullDownOnTouch() {
            // ??
            hideSoftKeyboard();
            // ?????
            mChattingFooter.hideBottomPanel();
        }
    });

    // ????
    mChattingFooter = (CCPChattingFooter2) findViewById(R.id.nav_footer);
    // ?????
    mChattingFooter.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
    // ???????
    mChattingFooter.setOnChattingFooterLinstener(mChattingFooterImpl);
    // ??????
    mChattingFooter.setOnChattingPanelClickListener(mChattingPanelImpl);

    mChattingAdapter = new ChattingListAdapter(this);
    mListView.setAdapter(mChattingAdapter);
}

From source file:com.hx.hxchat.activity.ChatActivity.java

/**
 * initView// w  ww  .  j  a v a 2 s . c o  m
 */
protected void initView() {
    recordingContainer = findViewById(R.id.recording_container);
    micImage = (ImageView) findViewById(R.id.mic_image);
    recordingHint = (TextView) findViewById(R.id.recording_hint);
    listView = (ListView) findViewById(R.id.list);
    mEditTextContent = (PasteEditText) findViewById(R.id.et_sendmessage);
    buttonSetModeKeyboard = findViewById(R.id.btn_set_mode_keyboard);
    edittext_layout = (RelativeLayout) findViewById(R.id.edittext_layout);
    buttonSetModeVoice = findViewById(R.id.btn_set_mode_voice);
    buttonSend = findViewById(R.id.btn_send);
    buttonPressToSpeak = findViewById(R.id.btn_press_to_speak);
    expressionViewpager = (ViewPager) findViewById(R.id.vPager);
    emojiIconContainer = (LinearLayout) findViewById(R.id.ll_face_container);
    btnContainer = (LinearLayout) findViewById(R.id.ll_btn_container);
    locationImgview = (ImageView) findViewById(R.id.btn_location);
    iv_emoticons_normal = (ImageView) findViewById(R.id.iv_emoticons_normal);
    iv_emoticons_checked = (ImageView) findViewById(R.id.iv_emoticons_checked);
    loadmorePB = (ProgressBar) findViewById(R.id.pb_load_more);
    btnMore = (Button) findViewById(R.id.btn_more);
    iv_emoticons_normal.setVisibility(View.VISIBLE);
    iv_emoticons_checked.setVisibility(View.INVISIBLE);
    more = findViewById(R.id.more);
    edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
    /** ? */
    rl_bottom = (LinearLayout) findViewById(R.id.rl_bottom);
    // ?,
    micImages = new Drawable[] { getResources().getDrawable(R.drawable.record_animate_01),
            getResources().getDrawable(R.drawable.record_animate_02),
            getResources().getDrawable(R.drawable.record_animate_03),
            getResources().getDrawable(R.drawable.record_animate_04),
            getResources().getDrawable(R.drawable.record_animate_05),
            getResources().getDrawable(R.drawable.record_animate_06),
            getResources().getDrawable(R.drawable.record_animate_07),
            getResources().getDrawable(R.drawable.record_animate_08),
            getResources().getDrawable(R.drawable.record_animate_09),
            getResources().getDrawable(R.drawable.record_animate_10),
            getResources().getDrawable(R.drawable.record_animate_11),
            getResources().getDrawable(R.drawable.record_animate_12),
            getResources().getDrawable(R.drawable.record_animate_13),
            getResources().getDrawable(R.drawable.record_animate_14), };

    // list
    reslist = getExpressionRes(35);
    // ?viewpager
    List<View> views = new ArrayList<View>();
    View gv1 = getGridChildView(1);
    View gv2 = getGridChildView(2);
    views.add(gv1);
    views.add(gv2);
    expressionViewpager.setAdapter(new ExpressionPagerAdapter(views));
    edittext_layout.requestFocus();
    voiceRecorder = new VoiceRecorder(micImageHandler);
    buttonPressToSpeak.setOnTouchListener(new PressToSpeakListen());
    mEditTextContent.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            } else {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
            }

        }
    });
    mEditTextContent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
        }
    });
    // ?
    mEditTextContent.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!TextUtils.isEmpty(s)) {
                btnMore.setVisibility(View.GONE);
                buttonSend.setVisibility(View.VISIBLE);
            } else {
                btnMore.setVisibility(View.VISIBLE);
                buttonSend.setVisibility(View.GONE);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

}

From source file:com.ayuget.redface.ui.fragment.TopicFragment.java

public void showGoToPageDialog() {
    MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
            .customView(R.layout.dialog_go_to_page, true).positiveText(R.string.dialog_go_to_page_positive_text)
            .negativeText(android.R.string.cancel).theme(themeManager.getMaterialDialogTheme())
            .callback(new MaterialDialog.ButtonCallback() {
                @Override//w ww  .j  av  a  2  s .  c o  m
                public void onPositive(MaterialDialog dialog) {
                    try {
                        int pageNumber = Integer.valueOf(goToPageEditText.getText().toString());
                        pager.setCurrentItem(pageNumber - 1);
                    } catch (NumberFormatException e) {
                        Log.e(LOG_TAG, String.format("Invalid page number entered : %s",
                                goToPageEditText.getText().toString()), e);
                        SnackbarHelper.make(TopicFragment.this, R.string.invalid_page_number).show();
                    }
                }

                @Override
                public void onNegative(MaterialDialog dialog) {
                }
            }).build();

    final View positiveAction = dialog.getActionButton(DialogAction.POSITIVE);
    goToPageEditText = (MaterialEditText) dialog.getCustomView().findViewById(R.id.page_number);

    goToPageEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.toString().trim().length() > 0) {
                try {
                    int pageNumber = Integer.valueOf(s.toString());
                    positiveAction.setEnabled(pageNumber >= 1 && pageNumber <= topic.getPagesCount());
                } catch (NumberFormatException e) {
                    positiveAction.setEnabled(false);
                }
            } else {
                positiveAction.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    dialog.show();
    positiveAction.setEnabled(false);
}

From source file:com.indoorsy.frash.easemob.activity.ChatActivity.java

@Override
public void initUI() {
    customTitleView = (CustomTitleView) findViewById(R.id.customTitleView);
    customTitleView.setLeftImageBg(R.drawable.comm_back);
    customTitleView.setRightImageVisibility(View.VISIBLE);
    customTitleView.setRightImageBg(R.drawable.personal_manage_editor2);
    customTitleView.setVisibility(View.VISIBLE);
    customTitleView.setOnClickListener(this);
    stImage = getIntent().getStringExtra("image");
    stPrice = getIntent().getStringExtra("price");

    mTextView1 = (TextView) findViewById(R.id.textview_question1);
    mTextView2 = (TextView) findViewById(R.id.textview_question2);
    mTextView3 = (TextView) findViewById(R.id.textview_question3);
    mTextView4 = (TextView) findViewById(R.id.textview_question4);
    mTextView1.setOnClickListener(new OnClickListener() {
        @Override/*from   w  w  w  .j a  v a  2  s.c o m*/
        public void onClick(View v) {
            mEditTextContent.setText(getResources().getString(R.string.text_fahuo));
        }
    });
    mTextView2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mEditTextContent.setText(R.string.text_weight);
        }
    });
    mTextView3.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mEditTextContent.setText(R.string.text_color);
        }
    });
    mTextView4.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mEditTextContent.setText(R.string.text_kuaidi);
        }
    });

    listView = (ListView) findViewById(R.id.list);
    mEditTextContent = (PasteEditText) findViewById(R.id.et_sendmessage);
    buttonSetModeKeyboard = findViewById(R.id.btn_set_mode_keyboard);
    edittext_layout = (RelativeLayout) findViewById(R.id.edittext_layout);
    buttonSend = findViewById(R.id.btn_send);
    expressionViewpager = (ViewPager) findViewById(R.id.vPager);
    emojiIconContainer = (LinearLayout) findViewById(R.id.ll_face_container);
    btnContainer = (LinearLayout) findViewById(R.id.ll_btn_container);
    iv_emoticons_normal = (ImageView) findViewById(R.id.iv_emoticons_normal);
    iv_emoticons_checked = (ImageView) findViewById(R.id.iv_emoticons_checked);
    loadmorePB = (ProgressBar) findViewById(R.id.pb_load_more);
    btnMore = (Button) findViewById(R.id.btn_more);
    iv_emoticons_normal.setVisibility(View.VISIBLE);
    iv_emoticons_checked.setVisibility(View.INVISIBLE);
    more = findViewById(R.id.more);
    more_new = findViewById(R.id.more_new);
    edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);

    // list
    reslist = getExpressionRes(35);
    // ?viewpager
    List<View> views = new ArrayList<View>();
    View gv1 = getGridChildView(1);
    View gv2 = getGridChildView(2);
    views.add(gv1);
    views.add(gv2);
    expressionViewpager.setAdapter(new ExpressionPagerAdapter(views));
    edittext_layout.requestFocus();
    mEditTextContent.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            } else {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
            }

        }
    });
    mEditTextContent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            more.setVisibility(View.GONE);
            more_new.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
        }
    });
    // ?
    mEditTextContent.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!TextUtils.isEmpty(s)) {
                btnMore.setVisibility(View.GONE);
                buttonSend.setVisibility(View.VISIBLE);
            } else {
                btnMore.setVisibility(View.VISIBLE);
                buttonSend.setVisibility(View.GONE);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
}

From source file:com.feytuo.chat.activity.ChatActivity.java

/**
 * initView/*from  w w  w.ja  v  a2 s  .c o  m*/
 */
protected void initView() {
    recordingContainer = findViewById(R.id.recording_container);
    micImage = (ImageView) findViewById(R.id.mic_image);
    recordingHint = (TextView) findViewById(R.id.recording_hint);
    listView = (ListView) findViewById(R.id.list);
    mEditTextContent = (PasteEditText) findViewById(R.id.et_sendmessage);
    buttonSetModeKeyboard = findViewById(R.id.btn_set_mode_keyboard);
    edittext_layout = (RelativeLayout) findViewById(R.id.edittext_layout);
    buttonSetModeVoice = findViewById(R.id.btn_set_mode_voice);
    buttonSend = findViewById(R.id.btn_send);
    buttonPressToSpeak = findViewById(R.id.btn_press_to_speak);
    expressionViewpager = (ViewPager) findViewById(R.id.vPager);
    expressionContainer = (LinearLayout) findViewById(R.id.ll_face_container);
    btnContainer = (LinearLayout) findViewById(R.id.ll_btn_container);
    locationImgview = (ImageView) findViewById(R.id.btn_location);
    iv_emoticons_normal = (ImageView) findViewById(R.id.iv_emoticons_normal);
    iv_emoticons_checked = (ImageView) findViewById(R.id.iv_emoticons_checked);
    loadmorePB = (ProgressBar) findViewById(R.id.pb_load_more);
    btnMore = (Button) findViewById(R.id.btn_more);
    iv_emoticons_normal.setVisibility(View.VISIBLE);
    iv_emoticons_checked.setVisibility(View.INVISIBLE);
    more = findViewById(R.id.more);
    edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);

    // ?,
    micImages = new Drawable[] { getResources().getDrawable(R.drawable.record_animate_01),
            getResources().getDrawable(R.drawable.record_animate_02),
            getResources().getDrawable(R.drawable.record_animate_03),
            getResources().getDrawable(R.drawable.record_animate_04),
            getResources().getDrawable(R.drawable.record_animate_05),
            getResources().getDrawable(R.drawable.record_animate_06),
            getResources().getDrawable(R.drawable.record_animate_07),
            getResources().getDrawable(R.drawable.record_animate_08),
            getResources().getDrawable(R.drawable.record_animate_09),
            getResources().getDrawable(R.drawable.record_animate_10),
            getResources().getDrawable(R.drawable.record_animate_11),
            getResources().getDrawable(R.drawable.record_animate_12),
            getResources().getDrawable(R.drawable.record_animate_13),
            getResources().getDrawable(R.drawable.record_animate_14), };
    // list
    reslist = getExpressionRes(90);
    // ?viewpager
    List<View> views = new ArrayList<View>();
    View gv1 = getGridChildView(1);
    View gv2 = getGridChildView(2);
    View gv3 = getGridChildView(3);
    View gv4 = getGridChildView(4);
    View gv5 = getGridChildView(5);
    views.add(gv1);
    views.add(gv2);
    views.add(gv3);
    views.add(gv4);
    views.add(gv5);
    expressionViewpager.setAdapter(new ExpressionPagerAdapter(views));
    edittext_layout.requestFocus();
    voiceRecorder = new VoiceRecorder(micImageHandler);
    buttonPressToSpeak.setOnTouchListener(new PressToSpeakListen());
    mEditTextContent.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            } else {
                edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_normal);
            }

        }
    });
    mEditTextContent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            edittext_layout.setBackgroundResource(R.drawable.input_bar_bg_active);
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            expressionContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
        }
    });
    // ?
    mEditTextContent.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!TextUtils.isEmpty(s)) {
                btnMore.setVisibility(View.GONE);
                buttonSend.setVisibility(View.VISIBLE);
            } else {
                btnMore.setVisibility(View.VISIBLE);
                buttonSend.setVisibility(View.GONE);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

}