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:com.prod.intelligent7.engineautostart.ConnectDaemonService.java

private IBinder confirmJob(Intent intent, int flags, int startId) {
    // A client is binding to the service with bindService()
    String command = intent.getExtras().getString(DAEMON_COMMAND);
    //Object obj1=intent.getExtras().getClassLoader();
    //confirmDaemonAlive();
    if (command != null) {
        if (command.length() < 3)
            return null;
        intent.putExtra(DAEMON_COMMAND, "EXECUTED");
        if (command.equalsIgnoreCase(GET_BINDER)) {
            String sType = intent.getExtras().getString(SERVICE_TYPE);
            if (sType != null && sType.equalsIgnoreCase(URGENT)) {
                serverHeartBit = 10 * 1000;
                urgentMailBox.clear();/*from  ww w  . j av a2 s. c o m*/
            }
            return new UrgentMailBinder();
        }
        sendCommand(command);
        return null;
    }
    command = intent.getExtras().getString(ALARM_DONE);
    if (command == null)
        return null;
    PowerManager.WakeLock wlR = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "KEEP_THREAD_ALIVE");
    wlR.acquire();
    switch (command) {
    case ALARM_BIT:
        //mDaemon.hasCommand=true;
        //mDaemon.interrupt();
        confirmDaemonAlive();
        //startServerHearBeatAlarm();
        break;
    case ALARM_1BOOT:
        String param = intent.getExtras().getString(ALARM_1BOOT);
        long on_time = Long.parseLong(param);
        sendCommand("M5-" + new DecimalFormat("00").format(on_time / 60000));
        //startOneBootAlarm();
        break;
    case ALARM_NBOOT:
        Log.i("ALARM_SET", "got recurring start intent");
        GregorianCalendar gToday = new GregorianCalendar(
                TimeZone.getTimeZone(getResources().getString(R.string.my_time_zone_en)));
        if (gToday.get(Calendar.HOUR_OF_DAY) >= 7 && gToday.get(Calendar.HOUR_OF_DAY) < 19)
            break;
        String params = intent.getExtras().getString(ALARM_NBOOT);
        int idx = params.indexOf("-");
        long last4 = Long.parseLong(params.substring(0, idx));
        sendCommand("M5-" + new DecimalFormat("00").format(last4 / 60000));
        long off_time = Long.parseLong(params.substring(idx + 1));
        setRecurringBootAlarm(last4, off_time);
        break;
    case ALARM_HOUR:
        //if (heartBitIntent==null) startServerHearBeatAlarm();
        if (oneBootIntent == null)
            startOneBootAlarm();
        if (recurringBootIntent == null)
            startRecurringBootAlarm();
        //reStartScheduleAlarms();
        startHourlyCheckAlarm();
        break;
    default:
        break;
    }
    wlR.release();

    return null;//mBinder;
}

From source file:com.liangxun.yuejiula.huanxin.chat.activity.ChatOldActivity.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 a 2s . 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.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);

    // ??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:edu.missouri.bas.service.SensorService.java

@SuppressWarnings("deprecation")
@Override//from   ww  w. java 2  s  .co  m
public void onCreate() {

    super.onCreate();
    Log.d(TAG, "Starting sensor service");
    mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
    soundsMap = new HashMap<Integer, Integer>();
    soundsMap.put(SOUND1, mSoundPool.load(this, R.raw.bodysensor_alarm, 1));
    soundsMap.put(SOUND2, mSoundPool.load(this, R.raw.voice_notification, 1));

    serviceContext = this;

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    bluetoothMacAddress = mBluetoothAdapter.getAddress();
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    //Get location manager
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    activityRecognition = new ActivityRecognitionScan(getApplicationContext());
    activityRecognition.startActivityRecognitionScan();

    mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    serviceWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorServiceLock");
    serviceWakeLock.acquire();

    //Initialize start time
    stime = System.currentTimeMillis();

    //Setup calendar object
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(stime);

    /*
     * Setup notification manager
     */

    notification = new Notification(R.drawable.icon2, "Recorded", System.currentTimeMillis());
    notification.defaults = 0;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent notifyIntent = new Intent(Intent.ACTION_MAIN);
    notifyIntent.setClass(this, MainActivity.class);

    /*
     * Display notification that service has started
     */
    notification.tickerText = "Sensor Service Running";
    PendingIntent contentIntent = PendingIntent.getActivity(SensorService.this, 0, notifyIntent,
            Notification.FLAG_ONGOING_EVENT);
    notification.setLatestEventInfo(SensorService.this, getString(R.string.app_name),
            "Recording service started at: " + cal.getTime().toString(), contentIntent);

    notificationManager.notify(SensorService.SERVICE_NOTIFICATION_ID, notification);

    // locationControl = new LocationControl(this, mLocationManager, 1000 * 60, 200, 5000);   

    IntentFilter activityResultFilter = new IntentFilter(XMLSurveyActivity.INTENT_ACTION_SURVEY_RESULTS);
    SensorService.this.registerReceiver(alarmReceiver, activityResultFilter);

    IntentFilter sensorDataFilter = new IntentFilter(SensorService.ACTION_SENSOR_DATA);
    SensorService.this.registerReceiver(alarmReceiver, sensorDataFilter);
    Log.d(TAG, "Sensor service created.");

    try {
        prepareIO();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    prepareAlarms();

    Intent startSensors = new Intent(SensorService.ACTION_START_SENSORS);
    this.sendBroadcast(startSensors);

    Intent scheduleCheckConnection = new Intent(SensorService.ACTION_SCHEDULE_CHECK);
    scheduleCheck = PendingIntent.getBroadcast(serviceContext, 0, scheduleCheckConnection, 0);
    mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime() + 1000 * 60 * 5, 1000 * 60 * 5, scheduleCheck);
    mLocationClient = new LocationClient(this, this, this);
}

From source file:app.view.chat.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 www. j a va2  s .  c  om*/
    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 {

        //todo
        // ?
        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,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.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.xxjwd.chat.ChatActivity.java

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

      if (chatType == CHATTYPE_SINGLE) { // ??
         toChatUsername = getIntent().getStringExtra("userId");
         toChatUsername = "3974";
         ((TextView) findViewById(R.id.name)).setText(toChatUsername);
          conversation =    ChatManager.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 = ChatGroupManager.getInstance().getGroup(toChatUsername);
         ((TextView) findViewById(R.id.name)).setText(group.getGroupName());
          conversation =
          ChatManager.getInstance().getConversation(toChatUsername,true);
      }
      conversation = ChatManager.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);
            emojiIconContainer.setVisibility(View.GONE);
            btnContainer.setVisibility(View.GONE);
            return false;
         }
      });
//      // ?
//      receiver = new NewMessageBroadcastReceiver();
//      IntentFilter intentFilter = new IntentFilter(ChatManager.getInstance().getNewMessageBroadcastAction());
//      // Mainacitivity,??chat??????
//      intentFilter.setPriority(5);
//      registerReceiver(receiver, intentFilter);
//
//      // ack?BroadcastReceiver
//      IntentFilter ackMessageIntentFilter = new IntentFilter(ChatManager.getInstance().getAckMessageBroadcastAction());
//      ackMessageIntentFilter.setPriority(5);
//      registerReceiver(ackMessageReceiver, ackMessageIntentFilter);
//
//      // ??BroadcastReceiver
//      IntentFilter deliveryAckMessageIntentFilter = new IntentFilter(ChatManager.getInstance().getDeliveryAckMessageBroadcastAction());
//      deliveryAckMessageIntentFilter.setPriority(5);
//      registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter);

      // ????T
      groupListener = new GroupListener();
      ChatGroupManager.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.siso.app.chat.ui.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  v  a 2 s. com*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

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

        initToolbar(userName);
        // conversation =
        // EMChatManager.getInstance().getConversation(toChatUsername,false);
    }
    //      else {
    //         // ?
    //         findViewById(R.id.container_to_group).setVisibility(View.VISIBLE);
    //         findViewById(R.id.container_remove).setVisibility(View.GONE);
    //         findViewById(R.id.container_voice_call).setVisibility(View.GONE);
    //         findViewById(R.id.container_video_call).setVisibility(View.GONE);
    //         toChatUsername = getIntent().getStringExtra("groupId");
    //         group = EMGroupManager.getInstance().getGroup(toChatUsername);
    //         if(group != null)
    //             ((TextView) findViewById(R.id.name)).setText(group.getGroupName());
    //         else
    //             ((TextView) findViewById(R.id.name)).setText(toChatUsername);
    //         // conversation =
    //         // EMChatManager.getInstance().getConversation(toChatUsername,true);
    //      }
    conversation = EMChatManager.getInstance().getConversation(toChatUsername);
    // ?0      
    conversation.resetUnreadMsgCount();

    // ?db?conversationgetChatOptions().getNumberOfMessagesLoaded
    // ???
    final List<EMMessage> msgs = conversation.getAllMessages();
    int msgCount = msgs != null ? msgs.size() : 0;
    if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
        String msgId = null;
        if (msgs != null && msgs.size() > 0) {
            msgId = msgs.get(0).getMsgId();
        }
        if (chatType == CHATTYPE_SINGLE) {
            conversation.loadMoreMsgFromDB(msgId, pagesize);
        } else {
            conversation.loadMoreGroupMsgFromDB(msgId, pagesize);
        }
    }
    adapter = new MessageAdapter(this, toChatUsername, chatType);
    // ?
    listView.setAdapter(adapter);
    listView.setOnScrollListener(new ListScrollListener());
    adapter.refreshSelectLast();

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

    // ????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.eveningoutpost.dexdrip.Home.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    mActivity = this;

    if (!xdrip.checkAppContext(getApplicationContext())) {
        toast("Unusual internal context problem - please report");
        Log.wtf(TAG, "xdrip.checkAppContext FAILED!");
        try {//from   w  w w  .j  a v a 2 s .com
            xdrip.initCrashlytics(getApplicationContext());
            Crashlytics.log("xdrip.checkAppContext FAILED!");
        } catch (Exception e) {
            // nothing we can do really
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // not much to do
        }
        if (!xdrip.checkAppContext(getApplicationContext())) {
            toast("Cannot start - please report context problem");
            finish();
        }
    }
    xdrip.checkForcedEnglish(Home.this);
    menu_name = getString(R.string.home_screen);

    super.onCreate(savedInstanceState);
    setTheme(R.style.AppThemeToolBarLite); // for toolbar mode

    set_is_follower();

    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    final boolean checkedeula = checkEula();

    //if (Build.VERSION.SDK_INT >= 21) {
    //    getWindow().setNavigationBarColor(Color.BLUE);
    //    getWindow().setStatusBarColor(getCol(X.color_home_chart_background));
    //}
    setContentView(R.layout.activity_home);

    Toolbar mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(mToolbar);

    //findViewById(R.id.home_layout_holder).setBackgroundColor(getCol(X.color_home_chart_background));
    this.dexbridgeBattery = (TextView) findViewById(R.id.textBridgeBattery);
    this.parakeetBattery = (TextView) findViewById(R.id.parakeetbattery);
    this.sensorAge = (TextView) findViewById(R.id.libstatus);
    this.extraStatusLineText = (TextView) findViewById(R.id.extraStatusLine);
    this.currentBgValueText = (TextView) findViewById(R.id.currentBgValueRealTime);

    extraStatusLineText.setText("");
    dexbridgeBattery.setText("");
    parakeetBattery.setText("");
    sensorAge.setText("");

    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        this.currentBgValueText.setTextSize(100);
    }
    this.notificationText = (TextView) findViewById(R.id.notices);
    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        this.notificationText.setTextSize(40);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Intent intent = new Intent();
        String packageName = getPackageName();
        Log.d(TAG, "Maybe ignoring battery optimization");
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isIgnoringBatteryOptimizations(packageName)
                && !prefs.getBoolean("requested_ignore_battery_optimizations_new", false)) {
            Log.d(TAG, "Requesting ignore battery optimization");
            // prefs.edit().putBoolean("requested_ignore_battery_optimizations", true).apply();
            intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);
            JoH.static_toast_long("Select YES for best performance!");
        }
    }

    // jamorham voice input et al
    this.voiceRecognitionText = (TextView) findViewById(R.id.treatmentTextView);
    this.textBloodGlucose = (TextView) findViewById(R.id.textBloodGlucose);
    this.textCarbohydrates = (TextView) findViewById(R.id.textCarbohydrate);
    this.textInsulinDose = (TextView) findViewById(R.id.textInsulinUnits);
    this.textTime = (TextView) findViewById(R.id.textTimeButton);
    this.btnBloodGlucose = (ImageButton) findViewById(R.id.bloodTestButton);
    this.btnCarbohydrates = (ImageButton) findViewById(R.id.buttonCarbs);
    this.btnInsulinDose = (ImageButton) findViewById(R.id.buttonInsulin);
    this.btnCancel = (ImageButton) findViewById(R.id.cancelTreatment);
    this.btnApprove = (ImageButton) findViewById(R.id.approveTreatment);
    this.btnTime = (ImageButton) findViewById(R.id.timeButton);
    this.btnUndo = (ImageButton) findViewById(R.id.btnUndo);
    this.btnRedo = (ImageButton) findViewById(R.id.btnRedo);
    this.btnVehicleMode = (ImageButton) findViewById(R.id.vehicleModeButton);

    hideAllTreatmentButtons();

    if (searchWords == null) {
        initializeSearchWords("");
    }

    this.btnSpeak = (ImageButton) findViewById(R.id.btnTreatment);
    btnSpeak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            promptTextInput();

        }
    });
    btnSpeak.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            promptSpeechInput();
            return true;
        }
    });

    this.btnNote = (ImageButton) findViewById(R.id.btnNote);
    btnNote.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (Home.getPreferencesBooleanDefaultFalse("default_to_voice_notes")) {
                showNoteTextInputDialog(v, 0);
            } else {
                promptSpeechNoteInput(v);
            }
            return false;
        }
    });
    btnNote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!Home.getPreferencesBooleanDefaultFalse("default_to_voice_notes")) {
                showNoteTextInputDialog(v, 0);
            } else {
                promptSpeechNoteInput(v);
            }
        }
    });

    btnCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            cancelTreatment();
        }
    });

    btnApprove.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            processAndApproveTreatment();
        }
    });

    btnInsulinDose.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // proccess and approve treatment
            textInsulinDose.setVisibility(View.INVISIBLE);
            btnInsulinDose.setVisibility(View.INVISIBLE);
            Treatments.create(0, thisinsulinnumber, Treatments.getTimeStampWithOffset(thistimeoffset));
            reset_viewport = true;
            if (hideTreatmentButtonsIfAllDone()) {
                updateCurrentBgInfo("insulin button");
            }
        }
    });
    btnCarbohydrates.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // proccess and approve treatment
            textCarbohydrates.setVisibility(View.INVISIBLE);
            btnCarbohydrates.setVisibility(View.INVISIBLE);
            reset_viewport = true;
            Treatments.create(thiscarbsnumber, 0, Treatments.getTimeStampWithOffset(thistimeoffset));
            if (hideTreatmentButtonsIfAllDone()) {
                updateCurrentBgInfo("carbs button");
            }
        }
    });

    btnBloodGlucose.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            reset_viewport = true;
            processCalibration();
        }
    });

    btnTime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // clears time if clicked
            textTime.setVisibility(View.INVISIBLE);
            btnTime.setVisibility(View.INVISIBLE);
            if (hideTreatmentButtonsIfAllDone()) {
                updateCurrentBgInfo("time button");
            }
        }
    });

    final DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int screen_width = dm.widthPixels;
    int screen_height = dm.heightPixels;

    if (screen_width <= 320) {
        small_width = true;
        small_screen = true;
    }
    if (screen_height <= 320) {
        small_height = true;
        small_screen = true;
    }
    final int refdpi = 320;
    Log.d(TAG, "Width height: " + screen_width + " " + screen_height + " DPI:" + dm.densityDpi);

    JoH.fixActionBar(this);
    try {
        getSupportActionBar().setTitle(R.string.app_name);
    } catch (NullPointerException e) {
        Log.e(TAG, "Couldn't set title due to null pointer");
    }
    activityVisible = true;

    // handle incoming extras
    Bundle bundle = getIntent().getExtras();
    processIncomingBundle(bundle);

    checkBadSettings();

    // lower priority
    PlusSyncService.startSyncService(getApplicationContext(), "HomeOnCreate");
    ParakeetHelper.notifyOnNextCheckin(false);

    if ((checkedeula) && (!getString(R.string.app_name).equals("xDrip+"))) {
        showcasemenu(SHOWCASE_VARIANT);
    }

}

From source file:com.example.Bama.chat.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");
    // ???/* www  .j  a  v  a 2 s . c om*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        //doctor avatar
        String name = getIntent().getStringExtra("name");
        if (!TextUtils.isEmpty(name)) {
            ((TextView) findViewById(R.id.name)).setText(name);
        } else {
            ((TextView) findViewById(R.id.name)).setText(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:niltor.net.chatuidemo.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 . ja  va 2  s. co  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);
        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.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.givon.anhao.activity.ChatActivity.java

private void setUpView() {
    activityInstance = this;
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???/*  w  ww . j a va 2  s .c  o  m*/
    Intent intent = getIntent();
    chatType = intent.getIntExtra("chatType", CHATTYPE_SINGLE);
    if (chatType == CHATTYPE_SINGLE) { // ??
        if (intent.hasExtra("userId")) {
            toChatUsername = intent.getStringExtra("userId");
            // ((TextView) findViewById(R.id.name)).setText(toChatUsername);
            // toChatUsername = intent.getStringExtra("userId");
            String title = intent.getStringExtra("location");
            ((TextView) findViewById(R.id.name)).setText(title);
            // if (intent.hasExtra("data")) {
            // mUserBean = (UserBean) intent.getSerializableExtra("data");
            // toChatUsername = mUserBean.getEasemobId();
            // }
            isFriend = AnhaoApplication.getInstance().getContactListOld().containsKey(toChatUsername);
            isHello = AnhaoApplication.getInstance().getHelloContactList().containsKey(toChatUsername);
        }
    } else {
        // TODO ?isCanAddFriend UserDao???? ? true
        // ?
        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());
        // toChatUsername = getIntent().getStringExtra("groupId");
        // if (intent.hasExtra("data")) {
        // mUserBean = (UserBean) intent.getParcelableExtra("data");
        // toChatUsername = mUserBean.getEasemobId();
        // }
        // isCanAddFriend = false;
        // group = EMGroupManager.getInstance().getGroup(toChatUsername);

        isFriend = AnhaoApplication.getInstance().getContactListOld().containsKey(toChatUsername);
        isHello = AnhaoApplication.getInstance().getHelloContactList().containsKey(toChatUsername);
        // ((TextView) findViewById(R.id.name)).setText(mRoomBean.getRoomName());
    }
    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);
    }

}