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.dragon4.owo.ar_trace.ARCore.MixView.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DataSource.createIcons(getResources()); try {/* w w w. j a va2 s . com*/ // ?? final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // ? ?? ? this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag"); // ?? locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // ?? . 2 ?? (1/1000s), 3 ?? (m)? ? locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 3, this); //orientation sensor sensorMgr_ori = (SensorManager) getSystemService(Context.SENSOR_SERVICE); orientationSensor = sensorMgr_ori.getDefaultSensor(Sensor.TYPE_ORIENTATION); killOnError(); // ? ? requestWindowFeature(Window.FEATURE_NO_TITLE); // ? ? // ?? FrameLayout frameLayout = new FrameLayout(this); // ? ?, ? frameLayout.setMinimumWidth(3000); frameLayout.setPadding(10, 0, 10, 10); // ? ? ? ?? ? camScreen = new CameraSurface(this); augScreen = new AugmentedView(this); setContentView(camScreen); // ? ?? ? ? // ? ?? ? addContentView(augScreen, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // ? ? ? ? ?. // ? ? ? ?? ? ? ? addContentView(frameLayout, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM)); topLayoutOnMixView = new TopLayoutOnMixView(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); addContentView(topLayoutOnMixView.mainArView, params); // ? ? ? topLayoutOnMixView ? ? handleIntent(getIntent()); // ?? // ? ? ? if (!isInited) { mixContext = new MixContext(this); // ? ? // ? ? mixContext.downloadManager = new DownloadManager(mixContext); //? ? ? navigator = new Navigator(mixContext, topLayoutOnMixView.naverFragment); // ? ? ?? ? ? dWindow = new PaintScreen(); dataView = new DataView(mixContext); isInited = true; // true } if (mixContext.isActualLocation() == false) { Toast.makeText(this, getString(DataView.CONNECTION_GPS_DIALOG_TEXT), Toast.LENGTH_LONG).show(); } } catch (Exception ex) { doError(ex); // ? ? } // ? IntentFilter naviBraodFilter = new IntentFilter(); naviBraodFilter.addAction("NAVI"); registerReceiver(naviRecevicer, naviBraodFilter); }
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"); // ???//w w w . j a va 2s .c om 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 w ww . j ava 2 s . c om*/ 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"); // ???/* ww w . ja v a2 s . com*/ 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.devbrackets.android.exomedia.core.exoplayer.EMExoPlayer.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.//from w ww. ja va2 s.c o m * 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, EMExoPlayer.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.TwentyCodes.android.IOIOTruck.NavigationActivity.java
/** * (non-Javadoc)/*from ww w. jav a 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:uk.co.spookypeanut.wake_me_at.WakeMeAtService.java
public void soundAlarm() { mAlarm = true;//ww w . jav a2 s. c o m // This method of waking up the device seems to be required on <= 4.0 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LOG_NAME); if ((wl != null) && (wl.isHeld() == false)) { wl.acquire(); } Intent alarmIntent = new Intent(WakeMeAtService.this.getApplication(), Alarm.class); alarmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); alarmIntent.putExtra("rowId", mRowId); alarmIntent.putExtra("metresAway", mMetresAway); alarmIntent.putExtra("alarm", mAlarm); startActivity(alarmIntent); updateAlarm(); }
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"); // ???/* w w w. j av a 2 s. c om*/ 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:de.tubs.ibr.dtn.chat.service.ChatService.java
@Override protected void onHandleIntent(Intent intent) { String action = intent.getAction(); // create a task to process concurrently if (ACTION_PRESENCE_ALARM.equals(action)) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ChatService.this); // check if the screen is active PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); Boolean screenOn = pm.isScreenOn(); String presence_tag = preferences.getString("presencetag", "auto"); String presence_nick = preferences.getString("editNickname", "Nobody"); String presence_text = preferences.getString("statustext", ""); if (presence_tag.equals("auto")) { if (screenOn) { presence_tag = "chat"; } else { presence_tag = "away"; }//from w w w .j a v a 2 s . c o m } Log.i(TAG, "push out presence; " + presence_tag); actionRefreshPresence(presence_tag, presence_nick, presence_text); Editor edit = preferences.edit(); edit.putLong("lastpresenceupdate", (new Date().getTime())); edit.commit(); } // create a task to check for messages else if (de.tubs.ibr.dtn.Intent.RECEIVE.equals(action)) { try { while (_client.getSession().queryNext()) ; } catch (SessionDestroyedException e) { Log.e(TAG, "Can not query for bundle", e); } catch (InterruptedException e) { Log.e(TAG, "Can not query for bundle", e); } } else if (MARK_DELIVERED_INTENT.equals(action)) { actionMarkDelivered(intent); } else if (REPORT_DELIVERED_INTENT.equals(action)) { actionReportDelivered(intent); } else if (ACTION_SEND_MESSAGE.equals(action)) { Long buddyId = intent.getLongExtra(ChatService.EXTRA_BUDDY_ID, -1); String text = intent.getStringExtra(ChatService.EXTRA_TEXT_BODY); // abort if there is no buddyId if (buddyId < 0) return; actionSendMessage(buddyId, text); } else if (ACTION_REFRESH_PRESENCE.equals(action)) { String presence = intent.getStringExtra(ChatService.EXTRA_PRESENCE); String nickname = intent.getStringExtra(ChatService.EXTRA_DISPLAY_NAME); String status = intent.getStringExtra(ChatService.EXTRA_STATUS); actionRefreshPresence(presence, nickname, status); } else if (ACTION_NEW_MESSAGE.equals(action)) { showNotification(intent); } }
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 ww .java2s . com*/ } 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); } }