Example usage for android.os PowerManager SCREEN_DIM_WAKE_LOCK

List of usage examples for android.os PowerManager SCREEN_DIM_WAKE_LOCK

Introduction

In this page you can find the example usage for android.os PowerManager SCREEN_DIM_WAKE_LOCK.

Prototype

int SCREEN_DIM_WAKE_LOCK

To view the source code for android.os PowerManager SCREEN_DIM_WAKE_LOCK.

Click Source Link

Document

Wake lock level: Ensures that the screen is on (but may be dimmed); the keyboard backlight will be allowed to go off.

Usage

From source file:name.setup.dance.StepService.java

private void acquireWakeLock() {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    int wakeFlags;
    if (mDanceStepAppSettings.wakeAggressively()) {
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP;
    } else if (mDanceStepAppSettings.keepScreenOn()) {
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK;
    } else {/*  www.j  a  va  2s.  c om*/
        wakeFlags = PowerManager.PARTIAL_WAKE_LOCK;
    }
    wakeLock = pm.newWakeLock(wakeFlags, TAG);
    wakeLock.acquire();
}

From source file:cn.kangeqiu.kq.activity.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");

    roomId = getIntent().getStringExtra("roomId");
    // ???/*from ww  w. j ava  2 s.  c  o m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        findViewById(R.id.container_dadu).setVisibility(View.GONE);
        findViewById(R.id.container_jingcai).setVisibility(View.GONE);

        toChatUsername = getIntent().getStringExtra("userId");
        String nickname = getIntent().getStringExtra("nickname");
        ((TextView) findViewById(R.id.name)).setText(nickname);
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,false);
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        findViewById(R.id.container_video_call).setVisibility(View.GONE);
        findViewById(R.id.container_file).setVisibility(View.GONE);
        // findViewById(R.id.container_photo).setVisibility(View.GONE);
        findViewById(R.id.container_location).setVisibility(View.GONE);
        findViewById(R.id.container_video).setVisibility(View.GONE);
        findViewById(R.id.score_lay).setVisibility(View.VISIBLE);

        toChatUsername = getIntent().getStringExtra("groupId");
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        ((TextView) findViewById(R.id.name)).setText(group.getGroupName());
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,true);

        doPullDate("2061", new MCHttpCallBack() {
            @Override
            public void onSuccess(MCHttpResp resp) {
                super.onSuccess(resp);
                try {
                    String resultCode = resp.getJson().getString("result_code");
                    if (resultCode.equals("0")) {

                        match = resp.getJson().getJSONObject("match");
                        loader.LoadImage(
                                resp.getJson().getJSONObject("match").getJSONObject("team1").getString("icon"),
                                team_icon1);
                        loader.LoadImage(
                                resp.getJson().getJSONObject("match").getJSONObject("team2").getString("icon"),
                                team_icon2);
                        score_textView.setText(
                                resp.getJson().getJSONObject("match").getJSONObject("team1").getString("score")
                                        + ":" + resp.getJson().getJSONObject("match").getJSONObject("team2")
                                                .getString("score"));
                        String stateStr = "";
                        String stateJson = resp.getJson().getJSONObject("match").getString("state");
                        if (stateJson.equals("0")) {
                            stateStr = "";
                        } else if (stateJson.equals("1")) {
                            stateStr = "";
                        } else if (stateJson.equals("2")) {
                            stateStr = "?";
                        }
                        tv_state.setText(stateStr);
                        // private CircleImageView team_icon1, team_icon2;
                        // private TextView tv_state, score_textView;

                    } else {
                        Toast.makeText(getApplicationContext(), resp.getJson().getString("message"),
                                Toast.LENGTH_SHORT).show();
                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(MCHttpResp resp) {
                super.onError(resp);
            }
        });

    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnreadMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    // ?
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,??chat??????
    intentFilter.setPriority(5);
    registerReceiver(receiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ??BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // ????T
    groupListener = new GroupListener();
    EMGroupManager.getInstance().addGroupChangeListener(groupListener);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // ?????
        forwardMessage(forward_msg_id);
    }

}

From source file:com.wemolian.app.wml.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    //         position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???//from   ww  w  .  j ava2 s.  c  o  m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);
    // type=getIntent().getIntExtra("type", 0);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra(LocalDBKey.CONTACTS_COLUMN_NAME_HXID);
        String toChatUserCName = getIntent().getStringExtra(LocalDBKey.CONTACTS_COLUMN_NAME_USERCNAME);
        ((TextView) findViewById(R.id.name)).setText(toChatUserCName);
        toUserCName = getIntent().getStringExtra(LocalDBKey.CONTACTS_COLUMN_NAME_USERCNAME);
        toUserImgName = getIntent().getStringExtra(LocalDBKey.CONTACTS_COLUMN_NAME_IMGNAME);
    } else {

        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupHxId");
        groupId = getIntent().getStringExtra("groupId");
        groupName = getIntent().getStringExtra("groupName");
        ((TextView) findViewById(R.id.name)).setText(groupName);
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnreadMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    //
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });

    // ?
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,??chat??????
    intentFilter.setPriority(5);
    registerReceiver(receiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ??BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // ????T
    groupListener = new GroupListener();
    EMGroupManager.getInstance().addGroupChangeListener(groupListener);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // ?????
        forwardMessage(forward_msg_id);
    }
    iv_setting = (ImageView) this.findViewById(R.id.iv_setting);
    iv_setting_group = (ImageView) this.findViewById(R.id.iv_setting_group);
    if (chatType == CHATTYPE_SINGLE) {
        iv_setting.setVisibility(View.VISIBLE);
        iv_setting_group.setVisibility(View.GONE);
        iv_setting.setOnClickListener(new OnClickListener() {

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

                startActivity(

                        new Intent(ChatActivity.this, ChatSingleSettingActivity.class).putExtra("userId",
                                toChatUsername));

            }

        });
    } else {
        iv_setting.setVisibility(View.GONE);
        iv_setting_group.setVisibility(View.VISIBLE);
        iv_setting_group.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                startActivityForResult((new Intent(ChatActivity.this, ChatRoomSettingActivity.class)
                        .putExtra("groupHxId", toChatUsername).putExtra("groupId", groupId)
                        .putExtra("groupName", groupName)), REQUEST_CODE_GROUP_DETAIL);

            }

        });
    }

}

From source file:com.ccxt.whl.activity.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???//  w w  w .  j a v  a2 s  .c o m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        UserDao userdao = new UserDao(this);
        User user = userdao.getUser(toChatUsername);
        //nickname = getIntent().getStringExtra("nickname");
        //headurl =  getIntent().getStringExtra("headurl");
        ((TextView) findViewById(R.id.name)).setText(user.getNick());
    } else if (chatType == 0) { // ? 
        toChatUsername = getIntent().getStringExtra("userId");
        ((TextView) findViewById(R.id.name)).setText("?");
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        ((TextView) findViewById(R.id.name)).setText(group.getGroupName());
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnsetMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            expressionContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    // ?
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,??chat??????
    intentFilter.setPriority(5);
    registerReceiver(receiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ????T
    groupListener = new GroupListener();
    EMGroupManager.getInstance().addGroupChangeListener(groupListener);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // ?????
        forwardMessage(forward_msg_id);
    }

}

From source file:com.TwentyCodes.android.IOIOTruck.NavigationActivity.java

/**
 * (non-Javadoc)/* www  .ja va  2  s  . c  om*/
 * @see android.support.v4.app.FragmentActivity#onResume()
 */
@Override
protected void onResume() {
    super.onResume();
    mMap = (MapFragment) this.getSupportFragmentManager().findFragmentById(R.id.map_fragment);
    mMap.setCompassListener(this);
    mMap.setGeoPointLocationListener(this);
    mMap.setLocationSelectedListener(this);
    mMap.setDirectionsCompleteListener(this);
    mMap.setRadius((int) (Debug.RADIUS * 1E3));
    mMap.enableGPSProgess();

    PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
    mWakeLock.acquire();
}

From source file:doext.easemob.activity.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???//from   w w  w.  j  ava2  s .co  m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        ((TextView) findViewById(DoResourcesHelper.getIdentifier("name", "id", this))).setText(toChatUsername);
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,false);
    } else {
        // ?
        findViewById(DoResourcesHelper.getIdentifier("container_to_group", "id", this))
                .setVisibility(View.VISIBLE);
        findViewById(DoResourcesHelper.getIdentifier("container_remove", "id", this)).setVisibility(View.GONE);
        findViewById(DoResourcesHelper.getIdentifier("container_voice_call", "id", this))
                .setVisibility(View.GONE);
        findViewById(DoResourcesHelper.getIdentifier("container_video_call", "id", this))
                .setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        if (group != null)
            ((TextView) findViewById(DoResourcesHelper.getIdentifier("name", "id", this)))
                    .setText(group.getGroupName());
        else
            ((TextView) findViewById(DoResourcesHelper.getIdentifier("name", "id", this)))
                    .setText(toChatUsername);
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,true);
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnreadMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    // ?
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,??chat??????
    intentFilter.setPriority(3);
    registerReceiver(receiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ??BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // ????T
    //groupListener = new GroupListener();
    //EMGroupManager.getInstance().addGroupChangeListener(groupListener);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // ?????
        forwardMessage(forward_msg_id);
    }

}

From source file:com.ieeton.user.activity.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");

    String name = Utils.getNickCache(this, toChatUsername);
    if (TextUtils.isEmpty(name)) {
        if (mUser != null) {
            name = mUser.getName();/*from  w w w. j  a v a2 s .co m*/
        } else {
            name = getResources().getString(R.string.default_doctor_nickname);
        }
    }
    if (toChatUsername.equals(NetEngine.getSecretaryID())) {
        mTvTitle.setText(R.string.secretary_default_name);
    } else {
        mTvTitle.setText(name);
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnsetMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, new MessageAdapter.HeaderClickListener() {
        @Override
        public void click(int id) {
            if (id == MessageAdapter.HeaderClickListener.CLICK_LEFT) {
                if (mUser != null) {
                    if (mUser.getUserType() == 1 || mUser.getUserType() == 2 || mUser.getUserType() == 3) {
                        Intent intent = new Intent(ChatActivity.this, DoctorProfileActivity.class);
                        intent.putExtra(Constants.EXTRA_USER, mUser);
                        intent.putExtra(Constants.EXTRA_UID, mUser.getUid());
                        startActivity(intent);
                    }
                }
            } else if (id == MessageAdapter.HeaderClickListener.CLICK_RIGHT) {
                Intent intent = new Intent(ChatActivity.this, MainActivity.class);
                intent.putExtra(MainActivity.INPUT_INDEX, MainActivity.INPUT_SETTING);
                startActivity(intent);
            }
        }
    });
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    // ?
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,??chat??????
    intentFilter.setPriority(5);
    registerReceiver(receiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ??BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // ????T
    groupListener = new GroupListener();
    EMGroupManager.getInstance().addGroupChangeListener(groupListener);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // ?????
        //forwardMessage(forward_msg_id);
    }

}

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

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???/* w ww .j  a va2 s.c o m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");

        //         ????
        HeadAndName mHeadAndName = new HeadAndName(this);
        UserHeadAndName mUserHeadAndName = mHeadAndName.selectOne(toChatUsername);
        ((TextView) findViewById(R.id.name)).setText(mUserHeadAndName.getNick());
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,false);
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        findViewById(R.id.container_video_call).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        ((TextView) findViewById(R.id.name)).setText(group.getGroupName());
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,true);
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnreadMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    // ?
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,??chat??????
    intentFilter.setPriority(5);
    registerReceiver(receiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ??BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // ????T
    groupListener = new GroupListener();
    EMGroupManager.getInstance().addGroupChangeListener(groupListener);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // ?????
        forwardMessage(forward_msg_id);
    }

}

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

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    btnMore.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // //w  w w .  j  a  v  a2s  .  co  m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);
    txt_title.setText(user_name);
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // 0
    conversation.resetUnsetMsgCount();
    adapter = new ChatAdapter(this, toChatUsername, chatType, user_id);
    // 
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            expressionContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    // 
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,chat
    intentFilter.setPriority(5);
    registerReceiver(receiver, intentFilter);

    // ackBroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // T
    groupListener = new GroupListener();
    EMGroupManager.getInstance().addGroupChangeListener(groupListener);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // 
        forwardMessage(forward_msg_id);
    }

}

From source file:com.hanyu.desheng.activity.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???//from   w  ww .  ja  va 2 s  .com
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        String username = getIntent().getStringExtra("username");
        if (username != null) {
            if (username.length() < 7) {
                ((TextView) findViewById(R.id.name)).setText(username);
            } else {
                ((TextView) findViewById(R.id.name)).setText(username.substring(0, 7) + "...");
            }
        } else {
            Gson gson = new Gson();
            List<String> userList = new ArrayList<String>();
            userList.add(toChatUsername);
            final String uns = gson.toJson(userList);
            new HttpTask<Void, Void, String>(ChatActivity.this) {

                // private AlertDialog errorDialog;

                @Override
                protected String doInBackground(Void... params) {
                    return EngineManager.getUserEngine().toGetHxUser(uns);
                }

                @Override
                protected void onPostExecute(String result) {
                    if (result != null) {
                        LogUtils.e(getClass(), "result:" + result);
                        ChatBean chatBean = GsonUtils.json2Bean(result, ChatBean.class);
                        if (chatBean != null && chatBean.code == 0) {
                            String username = chatBean.data.info_list.get(0).miname;
                            if (username.length() < 7) {
                                ((TextView) findViewById(R.id.name)).setText(username);
                            } else {
                                ((TextView) findViewById(R.id.name)).setText(username.substring(0, 7) + "...");
                            }
                        } else {

                        }
                    }
                }

                @Override
                protected void onPreExecute() {
                }

            }.executeProxy();
        }
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,false);
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
        findViewById(R.id.container_remove).setVisibility(View.GONE);
        findViewById(R.id.container_voice_call).setVisibility(View.GONE);
        findViewById(R.id.container_video_call).setVisibility(View.GONE);
        toChatUsername = getIntent().getStringExtra("groupId");
        ISCANCHAT = GroupDao.getGroup(toChatUsername, ExampleApplication.getInstance().getUserName());
        if (!ISCANCHAT) {
            CountDown cd = new CountDown(5000, 1000);
            cd.start();
        }
        group = EMGroupManager.getInstance().getGroup(toChatUsername);

        new Thread() {
            public void run() {
                try {
                    String checkUserChat = EngineManager.getUserEngine().checkUserChat(
                            ExampleApplication.getInstance().getUserName(),
                            getIntent().getStringExtra("groupId"));
                    JSONObject jsonObject = new JSONObject(checkUserChat);
                    JSONObject jsonObject2 = jsonObject.getJSONObject("data");
                    String isSilence = jsonObject2.getString("is_silence");
                    if (isSilence.equals("1")) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                // ?
                                mEditTextContent.setHint("?");
                                mEditTextContent.setEnabled(false);
                                buttonPressToSpeak.setEnabled(false);

                            }
                        });

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            };
        }.start();

        // ?
        registerBandListener();

        if (group != null) {
            if (group.getGroupName().length() < 7) {
                ((TextView) findViewById(R.id.name))
                        .setText(group.getGroupName() + "(" + group.getAffiliationsCount() + ")");
            } else {
                ((TextView) findViewById(R.id.name)).setText(
                        group.getGroupName().substring(0, 7) + "...(" + group.getAffiliationsCount() + ")");
            }
        } else
            ((TextView) findViewById(R.id.name)).setText(toChatUsername);
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,true);
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnreadMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    int count = listView.getCount();
    if (count > 0) {
        listView.setSelection(count - 1);
    }

    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            hideKeyboard();
            more.setVisibility(View.GONE);
            iv_emoticons_normal.setVisibility(View.VISIBLE);
            iv_emoticons_checked.setVisibility(View.INVISIBLE);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    //EMChatManager.getInstance().getChatOptions().setShowNotificationInBackgroud(false);
    // ?
    receiver = new NewMessageBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction());
    // Mainacitivity,??chat??????
    intentFilter.setPriority(5);
    registerReceiver(receiver, intentFilter);

    // ack?BroadcastReceiver
    IntentFilter ackMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getAckMessageBroadcastAction());
    ackMessageIntentFilter.setPriority(5);
    registerReceiver(ackMessageReceiver, ackMessageIntentFilter);

    // ??BroadcastReceiver
    IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(
            EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
    deliveryAckMessageIntentFilter.setPriority(5);
    registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

    // ????T
    groupListener = new GroupListener();
    EMGroupManager.getInstance().addGroupChangeListener(groupListener);

    // show forward message if the message is not null
    String forward_msg_id = getIntent().getStringExtra("forward_msg_id");
    if (forward_msg_id != null) {
        // ?????
        forwardMessage(forward_msg_id);
    }

}