List of usage examples for android.content Context POWER_SERVICE
String POWER_SERVICE
To view the source code for android.content Context POWER_SERVICE.
Click Source Link
From source file:com.mobilyzer.util.PhoneUtils.java
/** Wakes up the CPU of the phone if it is sleeping. */ public synchronized void acquireWakeLock() { if (wakeLock == null) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "tag"); }//from w ww. ja v a 2s . c o m Logger.d("PowerLock acquired"); wakeLock.acquire(); }
From source file:com.gongpingjia.carplay.activity.chat.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 va 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)) { setTitle(nick); } else { setTitle(toChatUsername); } } else { UserUtils.setUserNick(toChatUsername, (TextView) findViewById(R.id.title)); } } 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.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 {//from w w w .j av a 2 s .c o 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.av.remusic.service.MediaService.java
@Override public void onCreate() { if (D)//from w w w.jav a 2s .c om Log.d(TAG, "Creating service"); super.onCreate(); mGetUrlThread.start(); mLrcThread.start(); mProxy = new MediaPlayerProxy(this); mProxy.init(); mProxy.start(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // 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(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(PREVIOUS_FORCE_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); filter.addAction(TRY_GET_TRACKINFO); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(LOCK_SCREEN); filter.addAction(SEND_PROGRESS); filter.addAction(SETQUEUE); // 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, MediaService.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.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"); // ???/*from w w w . ja v a 2 s . c om*/ 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 . ja v a 2 s . co 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.andrew.apolloMod.service.ApolloService.java
@SuppressLint({ "WorldWriteableFiles", "WorldReadableFiles" }) @Override//w ww . jav a2 s . com public void onCreate() { super.onCreate(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(rec); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(rec); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Constants.isApi14Supported()) { mRemoteControlClient = new RemoteControlClient(mediaPendingIntent); mAudioManager.registerRemoteControlClient(mRemoteControlClient); int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP; mRemoteControlClient.setTransportControlFlags(flags); } mPreferences = getSharedPreferences(APOLLO_PREFERENCES, MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE); mCardId = MusicUtils.getCardId(this); registerExternalStorageListener(); // Needs to be done in this thread, since otherwise // ApplicationContext.getPowerManager() crashes. mPlayer = new MultiPlayer(); mPlayer.setHandler(mMediaplayerHandler); reloadQueue(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); IntentFilter commandFilter = new IntentFilter(); commandFilter.addAction(SERVICECMD); commandFilter.addAction(TOGGLEPAUSE_ACTION); commandFilter.addAction(PAUSE_ACTION); commandFilter.addAction(NEXT_ACTION); commandFilter.addAction(PREVIOUS_ACTION); commandFilter.addAction(CYCLEREPEAT_ACTION); commandFilter.addAction(TOGGLESHUFFLE_ACTION); registerReceiver(mIntentReceiver, commandFilter); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); mWakeLock.setReferenceCounted(false); // If the service was idle, but got killed before it stopped itself, the // system will relaunch it. Make sure it gets stopped again in that // case. Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); }
From source file:org.tomahawk.tomahawk_android.services.PlaybackService.java
@Override public void onCreate() { super.onCreate(); EventBus.getDefault().register(this); mMediaPlayers.add(VLCMediaPlayer.get()); mMediaPlayers.add(DeezerMediaPlayer.get()); mMediaPlayers.add(SpotifyMediaPlayer.get()); mMediaPlayers.add(RdioMediaPlayer.get()); startService(new Intent(this, MicroService.class)); ServiceConnection connection = new ServiceConnection() { @Override/*from w ww . j a v a2s.c om*/ public void onServiceConnected(ComponentName name, IBinder service) { } @Override public void onServiceDisconnected(ComponentName name) { } }; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { bindService(new Intent(this, RemoteControllerService.class), connection, Context.BIND_AUTO_CREATE); } mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); // Initialize PhoneCallListener TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(mPhoneCallListener, PhoneStateListener.LISTEN_CALL_STATE); // Initialize WakeLock PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); mMediaButtonReceiverComponent = new ComponentName(this, MediaButtonReceiver.class); mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this); // Initialize killtime handler (watchdog style) mKillTimerHandler.removeCallbacksAndMessages(null); Message msg = mKillTimerHandler.obtainMessage(); mKillTimerHandler.sendMessageDelayed(msg, DELAY_TO_KILL); mPlaylist = Playlist.fromEmptyList(TomahawkMainActivity.getLifetimeUniqueStringId(), false, ""); mQueue = Playlist.fromEmptyList(TomahawkMainActivity.getLifetimeUniqueStringId(), false, ""); Log.d(TAG, "PlaybackService has been created"); }
From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Orientation listenever implementation myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override/*from w w w. java 2 s . c om*/ public void onOrientationChanged(int orientation) { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_270) { flipVideo = true; } else { flipVideo = false; } } }; myOrientationEventListener.enable(); // stopService(new Intent(StreamingActivity.this, // BackgroundService.class)); Log.e(TAG, "onCreate"); AndroidId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); frameInfo = new FrameInfo(); // openGL overlay overlay = new OverlayController(this); // orientation mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMag = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.activity_streaming); // Find the total number of cameras available numberOfCameras = Camera.getNumberOfCameras(); cookies = getSharedPreferences("RterUserCreds", MODE_PRIVATE); prefEditor = cookies.edit(); setUsername = cookies.getString("Username", "not-set"); setRterCredentials = cookies.getString("RterCreds", "not-set"); if (setRterCredentials.equalsIgnoreCase("not-set") || setRterCredentials == null) { Log.e("PREFS", "Login Not successful, please restart"); } Log.d("PREFS", "Prefs ==> rter_Creds:" + setRterCredentials); // Get the location manager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the location provider -> use // default if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Log.e(TAG, "GPS not available"); } Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); Log.d(TAG, "Requesting location"); locationManager.requestLocationUpdates(provider, 0, 1, this); // register the overlay control for location updates as well, so we get // the geomagnetic field locationManager.requestLocationUpdates(provider, 0, 1000, overlay); if (provider != null) { Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { System.out.println("Provider " + provider + " has been selected. and location " + location); onLocationChanged(location); } else { Toast toast = Toast.makeText(this, "Location not available", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); lati = (float) (45.505958f); longi = (float) (-73.576254f); Log.d(TAG, "Location not available"); } } // power manager PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, CLASS_LABEL); mWakeLock.acquire(); // test, set desired orienation to north overlay.letFreeRoam(false); overlay.setDesiredOrientation(0.0f); // CharSequence text = "Tap to start.."; // int duration = Toast.LENGTH_SHORT; // // Toast toast = Toast.makeText(this, text, duration); // toast.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0); // toast.show(); }
From source file:com.ieeton.agency.activity.ChatActivity.java
private void setUpView() { activityInstance = this; Intent intent = getIntent();//from ww w . j a v a 2 s . c o m 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); } }