Example usage for android.content Context POWER_SERVICE

List of usage examples for android.content Context POWER_SERVICE

Introduction

In this page you can find the example usage for android.content Context POWER_SERVICE.

Prototype

String POWER_SERVICE

To view the source code for android.content Context POWER_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.os.PowerManager for controlling power management, including "wake locks," which let you keep the device on while you're running long tasks.

Usage

From source file:cn.ucai.SuperWechat.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 2  s .  c  om*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    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)) {
            } else {
                ((TextView) findViewById(R.id.name)).setText(toChatUsername);
            }
        } else {
            UserUtils.setAppUserNick(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);
        }
    }
    setUpdateMemberlistener();
}

From source file:com.example.chudong.telescope.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  ww  w .j  a va2s .c o  m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    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);
            } 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:com.devbrackets.android.exomedia.core.exoplayer.ExoMediaPlayer.java

/**
 * This function has the MediaPlayer access the low-level power manager
 * service to control the device's power usage while playing is occurring.
 * The parameter is a combination of {@link android.os.PowerManager} wake flags.
 * Use of this method requires {@link android.Manifest.permission#WAKE_LOCK}
 * permission.//www . j  a v  a  2s .  c om
 * By default, no attempt is made to keep the device awake during playback.
 *
 * @param context the Context to use
 * @param mode the power/wake mode to set
 * @see android.os.PowerManager
 */
public void setWakeMode(Context context, int mode) {
    boolean wasHeld = false;
    if (wakeLock != null) {
        if (wakeLock.isHeld()) {
            wasHeld = true;
            wakeLock.release();
        }

        wakeLock = null;
    }

    //Acquires the wakelock if we have permissions to
    if (context.getPackageManager().checkPermission(Manifest.permission.WAKE_LOCK,
            context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(mode | PowerManager.ON_AFTER_RELEASE, ExoMediaPlayer.class.getName());
        wakeLock.setReferenceCounted(false);
    } else {
        Log.w(TAG, "Unable to acquire WAKE_LOCK due to missing manifest permission");
    }

    stayAwake(wasHeld);
}

From source file:com.xuejian.client.lxp.module.toolbox.im.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    titleHeaderBar.enableBackKey(true);// ww  w  .  j  a  v a  2  s.  c  o  m

    findViewById(R.id.ly_title_bar_left).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(ChatActivity.this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivityWithNoAnim(intent);
            overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        }
    });

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

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        toChatUser = AccountManager.getInstance().getContactList(mContext).get(toChatUsername);
        if (toChatUser == null) {
            finish();
        }
        titleHeaderBar.getTitleTextView().setText(toChatUser.getNick());

        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,false);
    } else {
        // ?
        toChatUsername = getIntent().getStringExtra("groupId");
        titleHeaderBar.setRightViewImageRes(R.drawable.ic_more);
        group = EMGroupManager.getInstance().getGroup(toChatUsername);

        if (group != null) {
            titleHeaderBar.getTitleTextView().setText(group.getGroupName());
        }
        Fragment fragment = new GroupDetailFragment();
        Bundle args = new Bundle();
        args.putString("groupId", toChatUsername);
        fragment.setArguments(args); // FragmentActivity??Fragment
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.menu_frame, fragment).commit();
        titleHeaderBar.setRightOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //                    Intent intent = new Intent(mContext,GroupDetailsActivity.class);
                //                    intent.putExtra("groupId",toChatUsername);
                //                    startActivity(intent);
                //END?gravity.right ??   START?left  ??
                if (drawerLayout.isDrawerVisible(GravityCompat.END)) {
                    drawerLayout.closeDrawer(GravityCompat.END);//
                } else {
                    drawerLayout.openDrawer(GravityCompat.END);//
                }

            }
        });

        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,true);
    }
    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.GONE);
            expressionContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
        }
    });
    // cmd?BroadcastReceiver
    IntentFilter cmdIntentFilter = new IntentFilter(EMChatManager.getInstance().getCmdMessageBroadcastAction());
    cmdIntentFilter.setPriority(3);
    mContext.registerReceiver(cmdMessageReceiver, cmdIntentFilter);
    // ?
    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.hzx.luoyechat.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  w ww . j  ava2s  .  c o m
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

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

            setmyTitle(TextUtils.isEmpty(nick) ? toChatUsername : nick);
        } else {
            User user = UserUtils.getUserInfo(toChatUsername);
            if (user != null) {
                setToolbarTitle(user.getNick());
            } else {
                setToolbarTitle(toChatUsername);
            }
        }
    } 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:com.bluros.music.MusicService.java

@Override
public void onCreate() {
    if (D)/*ww  w.  j a  v  a 2  s.c  o  m*/
        Log.d(TAG, "Creating service");
    super.onCreate();

    mNotificationManager = NotificationManagerCompat.from(this);

    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);

    mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();

    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(),
            MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        setUpMediaSession();

    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();

    registerExternalStorageListener();

    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);

    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(SLEEP_MODE_STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    filter.addAction(RemoteSelectDialog.REMOTE_START_SCAN);
    filter.addAction(RemoteSelectDialog.REMOTE_STOP_SCAN);
    filter.addAction(RemoteSelectDialog.REMOTE_CONNECT);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);

    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true,
            mMediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true,
            mMediaStoreObserver);

    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);

    final Intent shutdownIntent = new Intent(this, MusicService.class);
    shutdownIntent.setAction(SHUTDOWN);

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);

    scheduleDelayedShutdown();

    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}

From source file:com.parttime.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  ww  w  .jav  a2 s . c  o  m*/
    // chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    // if (chatType == CHATTYPE_SINGLE) { // ??
    toChatUsername = getIntent().getStringExtra("userId");
    ((TextView) findViewById(R.id.name)).setText(toChatUsername);
    // 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);
    // 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);

    // 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.sentaroh.android.SMBSync2.ActivityMain.java

@SuppressLint("NewApi")
private void checkBatteryOptimization() {
    if (Build.VERSION.SDK_INT >= 23) {
        Intent intent = new Intent();
        String packageName = mContext.getPackageName();
        PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        if (pm.isIgnoringBatteryOptimizations(packageName))
            intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
        else {/*  w  ww  . j av a 2 s.  c  o  m*/
            intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
        }
        startActivity(intent);
    }
}

From source file:com.example.administrator.bazipaipan.chat.huanxin.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  a  v a2s.  c  o m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    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);
            } else {
                ((TextView) findViewById(R.id.name)).setText(toChatUsername);
            }
        } else {
            //
            UserUtils.setUserNick(toChatUsername, (TextView) findViewById(R.id.name));
        }
    } else {
        // ? ?groupid  ??
        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:com.eason.marker.emchat.chatuidemo.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  a  v a2  s . c  om*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    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);
            } else {
                ((TextView) findViewById(R.id.name)).setText(toChatUsername);
            }
        } else {

            HttpResponseHandler getUserByUsernameHandler = new HttpResponseHandler() {
                @Override
                public void getResult() {
                    if (this.resultVO.getStatus() == ErroCode.ERROR_CODE_CORRECT) {
                        User user = (User) this.result;
                        UserUtils.setUserNick(user.getNickname(), (TextView) findViewById(R.id.name));
                    }
                }
            };

            HttpRequest.getUserByUserId(toChatUsername, getUserByUsernameHandler);
        }
    } 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);
        }
    }

    //????ViewGONE
    if (MainActivity.getInstance() != null) {
        MenuLeftFragment menuLeftFragment = (MenuLeftFragment) ((MainActivity) MainActivity.getInstance())
                .getFragment(IntentUtil.MENU_LEFT_FRAGMENT);
        menuLeftFragment.setNewMessageRemindView(View.GONE);
    }
}