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:com.liangxun.yuejiula.huanxin.chat.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(CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,
            "demo");
    // ??// w w w .  ja v  a2s.co m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUser = (Emp) getIntent().getSerializableExtra("emp");
        String hxUserName = getIntent().getStringExtra("userId");
        if (toChatUser != null) {
            toChatUsername = toChatUser.getHxUsername();
            toChatUserNick = toChatUser.getEmpName();
            ((TextView) findViewById(R.id.name)).setText(toChatUserNick);
            ((TextView) findViewById(R.id.name)).setOnClickListener(this);
            setUpView2();
            return;
        }
        if (toChatUser == null && TextUtils.isEmpty(hxUserName)) {
            return;
        } else if (!TextUtils.isEmpty(hxUserName)) {
            getEmpId2(hxUserName);
        }

        // 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_two).setVisibility(View.GONE);
        groupId = getIntent().getStringExtra("groupId");
        toChatUsername = groupId;
        //?groupId 
        for (EMGroup emGroup : MainActivity.grouplist) {
            if (emGroup.getGroupId().equals(groupId)) {
                group = emGroup;
                break;
            }
        }
        if (group != null) {
            ((TextView) findViewById(R.id.name)).setText(group.getGroupName());
        }
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,true);
        setUpView2();
    }

}

From source file:com.shengtao.chat.chatUI.activity.ChatActivity.java

private void setUpView() {
    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");

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
        try {//  w ww . jav a 2  s  . co  m
            if (robotMap != null && robotMap.containsKey(toChatUsername)) {
                isRobot = true;
                String nick = robotMap.get(toChatUsername).getNick();
                if (!TextUtils.isEmpty(nick)) {
                    //                  ((TextView) findViewById(R.id.name)).setText(getIntent().getStringExtra("friendsName"));
                } else {
                    //                  ((TextView) findViewById(R.id.name)).setText(getIntent().getStringExtra("friendsName"));
                }
            } else {
                //               UserUtils.setUserNick(getIntent().getStringExtra("friendsName"), (TextView) findViewById(R.id.name));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        // ?
        findViewById(R.id.container_to_group).setVisibility(View.GONE);
        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");
        try {
            if (chatType == CHATTYPE_GROUP) {
                onGroupViewCreation();
            } else {
                onChatRoomViewCreation();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // for chatroom type, we only init conversation and create view adapter on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // 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.efithealth.app.activity.ChatActivity.java

private void setUpView() {
    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 ava  2s.  co  m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId").toLowerCase();
        tonickname = getIntent().getStringExtra("nickname");
        String headimg = getIntent().getStringExtra("headimg");
        Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
        if (robotMap != null && robotMap.containsKey(toChatUsername)) {
            isRobot = true;
            String nick = tonickname;
            if (!TextUtils.isEmpty(nick)) {
                ((TextView) findViewById(R.id.name)).setText(nick);
            } else {
                ((TextView) findViewById(R.id.name)).setText(toChatUsername);
            }
        } else {
            User user = UserUtils.getUserInfo(toChatUsername);
            if (headimg != null) {
                user.setAvatar(headimg);
            }
            user.setNick(tonickname);

            UserUtils.saveUserInfo(user);
            UserUtils.setUserNick(tonickname, (TextView) findViewById(R.id.name));
        }
    } 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");

        if (chatType == CHATTYPE_GROUP) {
            onGroupViewCreation();
        } else {
            onChatRoomViewCreation();
        }
    }

    // for chatroom type, we only init conversation and create view adapter on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // 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:cn.yunluosoft.tonglou.activity.ChatActivity.java

private void setUpView() {
    back.setOnClickListener(new OnClickListener() {

        @Override//from   w  w w . j  a  v a 2  s.  c  o  m
        public void onClick(View v) {
            finish();
        }
    });

    //      icon.setVisibility(View.VISIBLE);
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    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");
    // ???
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        messageInfo = (MessageInfo) getIntent().getSerializableExtra("info");
        m = getIntent().getIntExtra("dic", 0);

        if (messageInfo != null) {
            if (m == 1) {
                MessageInfo info = new MessageInfo(messageInfo.receiverUserId, messageInfo.senderUserId,
                        messageInfo.receiverImUserName, messageInfo.senderImUserName,
                        messageInfo.receiverHeadUrl, messageInfo.senderHeadUrl, messageInfo.receiverNickName,
                        messageInfo.senderNickName);
                messageInfo = info;
            }
            toChatUsername = messageInfo.receiverImUserName;
            // toChatUsername = getIntent().getStringExtra("userId");
            ((TextView) findViewById(R.id.title_title)).setText(messageInfo.receiverNickName);
            //            bitmapUtils.display(icon, messageInfo.receiverHeadUrl);
            //
            //            icon.setOnClickListener(new OnClickListener() {
            //
            //               @Override
            //               public void onClick(View v) {
            //                  Intent intent = new Intent(ChatActivity.this,
            //                        ConstactActivity.class);
            //                  intent.putExtra("id", messageInfo.receiverUserId);
            //                  intent.putExtra("name", messageInfo.receiverNickName);
            //                  intent.putExtra("flag", 155);
            //                  startActivityForResult(intent, 8226);
            //               }
            //            });

        }
        // toChatUsername = getIntent().getStringExtra("userId");
        // Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper
        // .getInstance()).getRobotList();
        // if (robotMap != null && robotMap.containsKey(toChatUsername)) {
        // isRobot = true;
        // String nick = robotMap.get(toChatUsername).getNick();
        // if (!TextUtils.isEmpty(nick)) {
        // ((TextView) findViewById(R.id.title_title)).setText(nick);
        // } else {
        // ((TextView) findViewById(R.id.title_title))
        // .setText(toChatUsername);
        // }
        // }
        // else {
        // UserUtils.setUserNick(toChatUsername,
        // (TextView) findViewById(R.id.title_title));
        // }
    } else {
        // ?
        messageInfo = (MessageInfo) getIntent().getSerializableExtra("info");
        if (messageInfo == null) {
            return;
        }

        MessageInfo info = new MessageInfo(ShareDataTool.getUserId(this), messageInfo.receiverUserId,
                ShareDataTool.getImUsername(this), messageInfo.receiverImUserName, ShareDataTool.getIcon(this),
                messageInfo.receiverHeadUrl, ShareDataTool.getNickname(this), messageInfo.receiverNickName);

        info.groupDynamicID = messageInfo.receiverUserId;
        messageInfo = info;
        toChatUsername = messageInfo.receiverImUserName;
        LogManager.LogShow("222222", "----------", LogManager.ERROR);
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        ((TextView) findViewById(R.id.title_title)).setText(messageInfo.receiverNickName);
        ImageView groupchat = (ImageView) findViewById(R.id.title_groupchat);
        groupchat.setVisibility(View.VISIBLE);
        groupchat.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ChatActivity.this, GroupInfoActivity.class);
                intent.putExtra("id", messageInfo.receiverHeadUrl);
                intent.putExtra("groupId", messageInfo.receiverUserId);
                startActivity(intent);

            }
        });
    }

    // for chatroom type, we only init conversation and create view adapter
    // on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // 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.agency.activity.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    Intent intent = getIntent();//w w w.  j av a  2s .com
    if (intent == null) {
        return;
    }
    mChatUser = (ChatUser) intent.getExtras().getSerializable(EXTRA_USERINFO);
    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");
    // ???
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = intent.getStringExtra(EXTRA_USERID);
        String nick = "";
        if (mChatUser != null) {
            nick = mChatUser.getName();
        } else if (!TextUtils.isEmpty(Utils.getNickCache(this, toChatUsername))) {
            nick = Utils.getNickCache(this, toChatUsername);
        } else {
            nick = getString(R.string.default_nick);
        }
        if (toChatUsername.equals(NetEngine.getFeedbackId())) {
            mTitleName.setText(getString(R.string.xiaomishu));
        } else {
            mTitleName.setText(nick);
        }
    } 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);
        toChatUsername = getIntent().getStringExtra("groupId");
        group = EMGroupManager.getInstance().getGroup(toChatUsername);
        mTitleName.setText(group.getGroupName());
    }
    if (mChatUser == null) {
        new FetchInfoTask().execute(MODE_HUANXIN);
    } else {
        if (ChatUser.USER_DOCTOR.equals(mChatUser.getType())) {
            new FetchInfoTask().execute(MODE_DOCTOR);
        } else if (ChatUser.USER_PATIENT.equals(mChatUser.getType())) {
            new FetchInfoTask().execute(MODE_PATIENT);
        }
    }
    if (toChatUsername.equals(NetEngine.getFeedbackId())) {
        mBtnCall.setVisibility(View.VISIBLE);
    }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0
    conversation.resetUnsetMsgCount();
    adapter = new MessageAdapter(this, toChatUsername, chatType, new MessageAdapter.HeaderClickListener() {
        @Override
        public void click(int id) {
            if (id == CLICK_LEFT) {
                if (mUser == null) {
                    return;
                }
                //?
                if (mUser.getUserType() == UserInfo.ACCOUNT_DOCTOR) {
                    return;
                }
                Intent intent = new Intent(ChatActivity.this, PatientProfileActivity.class);
                intent.putExtra(PatientProfileActivity.EXTRA_USERID, toChatUsername);
                startActivity(intent);

            } else {
                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);
            expressionContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });

    if (toChatUsername.equals(NetEngine.getFeedbackId()) && conversation.getMsgCount() <= 0) {
        //???
        boolean notificationOn = EMChatManager.getInstance().getChatOptions().getNotificationEnable();
        boolean soundOn = EMChatManager.getInstance().getChatOptions().getNoticedBySound();
        boolean vibrateOn = EMChatManager.getInstance().getChatOptions().getNoticedByVibrate();
        if (notificationOn && soundOn) {
            mSoundID = initSoundPool();
            mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
                @Override
                public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                    playSound();
                }
            });
        }
        if (notificationOn && vibrateOn) {
            mVibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            playVibrator();
        }

        EMMessage message = EMMessage.createSendMessage(EMMessage.Type.TXT);
        String msgID = message.getMsgId();
        message.setMsgId("ieeton" + msgID);

        String content = getString(R.string.mishu_begin_conversation);
        TextMessageBody txtBody = new TextMessageBody(content);
        message.addBody(txtBody);

        message.setFrom(toChatUsername);
        message.setTo(DemoApplication.getInstance().getUserName());
        message.direct = EMMessage.Direct.RECEIVE;

        conversation.addMessage(message);
        EMChatManager.getInstance().saveMessage(message);
        adapter.refresh();

    }

    // ?
    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.saulcintero.moveon.services.MoveOnService.java

@SuppressWarnings("deprecation")
private void acquireWakeLock() {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    int wakeFlags;

    if (prefs.getString("operation_level", "run_in_background").equals("wake_up"))
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP;
    else if (prefs.getString("operation_level", "run_in_background").equals("keep_screen_on"))
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK;
    else/*from  w  w  w.jav  a  2 s . c om*/
        wakeFlags = PowerManager.PARTIAL_WAKE_LOCK;

    wakeLock = pm.newWakeLock(wakeFlags, TAG);
    wakeLock.acquire();
}

From source file:com.xicheng.trid.hx.activity.ChatActivity.java

private void setUpView() {
    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   www.j  a  v a  2  s. c  o  m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        User user = UserUtils.getUserInfor(toChatUsername);
        //?
        if (user.getChatTitle() != null) {
            ((TextView) findViewById(R.id.name)).setText(user.getChatTitle());

        } else {
            ((TextView) findViewById(R.id.name)).setText(toChatUsername);

        }
        //?
        UserUtils.setDefaultBarColor(user.getType());
    }

    // for chatroom type, we only init conversation and create view adapter on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // 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.zfb.house.emchat.ChatActivity.java

private void setUpView() {
    //??//  ww w.ja  v a 2  s . c  o  m
    if (getIntent() != null) {
        toUserBean = (ChatUserBean) getIntent().getSerializableExtra("chatUser");
    }
    /*if(toUserBean==null){//??????
     toUserBean = new ChatUserBean();
     User user = UserUtils.getUserInfo(getIntent().getStringExtra("userId"));
     toUserBean.setUserName(user.getNick());
     toUserBean.setImageUrl();
    }*/
    fromUserBean = new ChatUserBean();

    UserBean localUserBean = UserBean.getInstance(this);
    if (localUserBean != null) {
        fromUserBean.setImageUrl(localUserBean.photo);
        //??  ???    ???
        Log.i("linwb3", "user type = " + localUserBean.userType);
        fromUserBean.setUserType(stringToInteger(localUserBean.userType));
        if (!TextUtils.isEmpty(localUserBean.name)) {
            fromUserBean.setUserName(localUserBean.name);
        } else {
            if (!TextUtils.isEmpty(localUserBean.loginName)) {
                fromUserBean.setUserName(localUserBean.loginName);
            } else {
                if (!TextUtils.isEmpty(localUserBean.phone)) {
                    fromUserBean.setUserName(localUserBean.phone);
                } else {
                    fromUserBean.setUserName("");
                }
            }
        }
    }

    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");
    // ???
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    LogUtils.e("ChatActivity", "chatType==" + chatType);
    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
        if (robotMap != null && robotMap.containsKey(toChatUsername)) {
            isRobot = true;
            String nick = robotMap.get(toChatUsername).getNick();
            if (!TextUtils.isEmpty(nick)) {
                ((TextView) findViewById(R.id.name)).setText(nick);
                Log.e("ChatActivity", "name:" + nick);
            } else {
                ((TextView) findViewById(R.id.name)).setText(toChatUsername);
            }
        } else {
            UserUtils.setUserNick(toChatUsername, (TextView) findViewById(R.id.name));
        }
    } 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");
                
              if(chatType == CHATTYPE_GROUP){
                  onGroupViewCreation();
              }else{ 
                  onChatRoomViewCreation();
              }*/
    }

    // for chatroom type, we only init conversation and create view adapter on success
    if (chatType != CHATTYPE_CHATROOM) {
        onConversationInit();

        onListViewCreation();

        // 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:org.cowboycoders.cyclisimo.turbo.TurboService.java

@Override
public void onCreate() {
    super.onCreate();
    trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
    // trackRecordingServiceConnection.startAndBind();
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    this.wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TurboService.WAKE_LOCK);
}

From source file:me.spadival.podmode.PodModeService.java

@Override
public void onCreate() {

    IntentFilter usbFilter = new IntentFilter();
    usbFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    usbFilter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    registerReceiver(mUsbReceiver, usbFilter);
    // mProvider = RemoteMetadataProvider.getInstance(this);

    // mProvider.setOnMetadataChangeListener(mMetadataListner);
    // mProvider.acquireRemoteControls();
    LocalBroadcastManager bManager = LocalBroadcastManager.getInstance(this);
    IntentFilter notifyFilter = new IntentFilter();
    notifyFilter.addAction(NOTIFYACTION);
    bManager.registerReceiver(mNotifyReceiver, notifyFilter);

    mSerialHost = new FTDriver((UsbManager) getSystemService(Context.USB_SERVICE));

    mSerialDevice = new FT311UARTInterface(this, null);

    // Get the local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // Get a set of currently paired devices
    Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();

    mBluetoothDevice = null;//  ww  w . ja  va 2  s . co  m

    /*   // If there are paired devices, add each one to the ArrayAdapter
       if (pairedDevices.size() > 0) {
          for (BluetoothDevice device : pairedDevices) {
    if (device.getName().equals("PodModeBT"))
       mBluetoothDevice = device;
          }
       }
            
       if (mBluetoothDevice != null) {
          mBTDevice = new BluetoothSerialService(this, mHandler);
          mBTDevice.connect(mBluetoothDevice);
       } */

    // Create the Wifi lock (this does not acquire the lock, this just
    // creates it)
    mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock");

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    // Create the retriever and start an asynchronous task that will prepare
    // it.

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    mRetriever = new MusicRetriever(getContentResolver(), getApplicationContext(), true, prefs);

    // mRetriever.switchToMainPlaylist();

    prefs.registerOnSharedPreferenceChangeListener((OnSharedPreferenceChangeListener) this);

    mNowPlaying = prefs.getInt("nowplaying", 0);

    String mBaudrate = prefs.getString("baud_rate", "57600");

    if (mBaudrate.equals("57600"))
        mSerialBaudRate = FTDriver.BAUD57600;
    else if (mBaudrate.equals("38400"))
        mSerialBaudRate = FTDriver.BAUD38400;
    else if (mBaudrate.equals("19200"))
        mSerialBaudRate = FTDriver.BAUD19200;

    (new PrepareMusicRetrieverTask(mRetriever, this)).execute();

    // create the Audio Focus Helper, if the Audio Focus feature is
    // available (SDK 8 or above)
    if (android.os.Build.VERSION.SDK_INT >= 8)
        mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this);
    else
        mAudioFocus = AudioFocus.Focused; // no focus feature, so we always
    // "have" audio focus

    boolean wakeLockPreferred = prefs.getBoolean("wakelock", false);

    if (podWakeLock == null && wakeLockPreferred) {
        PowerManager powerMgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
        podWakeLock = powerMgr.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, WAKETAG);
        podWakeLock.acquire();
    }

    PackageManager pxm = getPackageManager();
    Intent mediaIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);

    List<ResolveInfo> mAppsInfo = pxm.queryBroadcastReceivers(mediaIntent, 0);

    mSimpleRemoteApp = prefs.getString("selectapp", null);
    mAdvancedRemoteApp = prefs.getString("selectadvancedapp", PACKAGENAME);

    // Make sure App preferences are still valid and Apps haven't been
    // uninstalled.

    if (mAppsInfo.size() > 0) {

        CharSequence[] entryValues = new CharSequence[mAppsInfo.size()];
        CharSequence[] advEntryValues = new CharSequence[mAppsInfo.size() + 1];

        advEntryValues[0] = PACKAGENAME;

        int i = 0;
        for (ResolveInfo info : mAppsInfo) {
            entryValues[i] = (String) info.activityInfo.packageName;
            advEntryValues[i + 1] = (String) info.activityInfo.packageName;

            i++;
        }

        boolean entryFound = false;

        if (mSimpleRemoteApp != null) {
            for (i = 0; i < entryValues.length; i++) {
                if (mSimpleRemoteApp.equals(entryValues[i])) {
                    entryFound = true;
                }
            }
        }

        if (!entryFound) {
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("selectapp", (String) entryValues[0]);
            editor.commit();
            mSimpleRemoteApp = (String) entryValues[0];
        }

        entryFound = false;

        if (mAdvancedRemoteApp != null) {
            for (i = 0; i < advEntryValues.length; i++) {
                if (mAdvancedRemoteApp.equals(advEntryValues[i])) {
                    entryFound = true;
                }
            }
        }

        if (!entryFound) {
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("selectadvancedapp", (String) advEntryValues[0]);
            editor.commit();
            mAdvancedRemoteApp = (String) advEntryValues[0];

        }
    } else {
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString("selectadvancedapp", PACKAGENAME);
        editor.commit();
        mAdvancedRemoteApp = PACKAGENAME;
    }

    mAccessoryName = prefs.getString("accessoryName", null);
    mAccessoryMnf = prefs.getString("accessoryMnf", null);
    mAccessoryModel = prefs.getString("accessoryModel", null);

}