Example usage for android.content Intent ACTION_SCREEN_OFF

List of usage examples for android.content Intent ACTION_SCREEN_OFF

Introduction

In this page you can find the example usage for android.content Intent ACTION_SCREEN_OFF.

Prototype

String ACTION_SCREEN_OFF

To view the source code for android.content Intent ACTION_SCREEN_OFF.

Click Source Link

Document

Broadcast Action: Sent when the device goes to sleep and becomes non-interactive.

Usage

From source file:com.nagopy.android.xposed.utilities.ModBrightness.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@XMinSdkVersion(Build.VERSION_CODES.JELLY_BEAN_MR1)
@HandleInitPackageResources(targetPackage = XConst.PKG_SYSTEM_UI, summary = "??")
public static void brightnessDebugger(final String modulePath, final InitPackageResourcesParam resparam,
        final ModBrightnessSettingsGen settings) throws Throwable {
    if (!settings.brightnessDebugger) {
        return;/* w w w.j  a va 2s.c  o  m*/
    }

    resparam.res.hookLayout(XConst.PKG_SYSTEM_UI, "layout", "super_status_bar", new XC_LayoutInflated() {
        @Override
        public void handleLayoutInflated(LayoutInflatedParam liparam) throws Throwable {
            LinearLayout parent = (LinearLayout) liparam.view
                    .findViewById(liparam.res.getIdentifier("system_icon_area", "id", XConst.PKG_SYSTEM_UI));

            // ?
            TextView luxTextView = new TextView(parent.getContext());
            luxTextView.setTextSize(8);
            luxTextView.setSingleLine(false);
            luxTextView.setTextColor(Color.WHITE);
            luxTextView.setText("");
            parent.setGravity(Gravity.CENTER_VERTICAL);
            parent.addView(luxTextView, 0);
            AutoBrightnessController autoBrightnessChangedReceiver = new AutoBrightnessController(luxTextView);
            IntentFilter intentFilter = new IntentFilter(
                    AutoBrightnessController.ACTION_AUTO_BRIGHTNESS_CHANGED);
            intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
            parent.getContext().registerReceiver(autoBrightnessChangedReceiver, intentFilter);
        }
    });
}

From source file:nu.yona.app.utils.AppUtils.java

/**
 * This will register receiver for different events like screen on-off, boot, connectivity etc.
 *
 * @param context the context/* w  ww  .  j  ava 2 s .  c o m*/
 */
public static void registerReceiver(Context context) {
    loge(TAG, "Register Receiver");

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_BOOT_COMPLETED);
    filter.addAction(AppConstant.RESTART_DEVICE);
    filter.addAction(AppConstant.RESTART_VPN);
    filter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);

    context.registerReceiver(receiver, filter);
}

From source file:rosmi.acagild.alarmclock.ringing.AlarmRingingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    UUID alarmId = (UUID) getIntent().getSerializableExtra(AlarmScheduler.ARGS_ALARM_ID);
    mAlarm = AlarmList.get(this).getAlarm(alarmId);

    Log.d(TAG, "Creating activity!");

    // This call must be made before setContentView to avoid the view being refreshed
    GeneralUtilities.setLockScreenFlags(getWindow());

    setContentView(R.layout.activity_fragment);

    mAlarmRingingFragment = AlarmRingingFragment.newInstance(mAlarm.getId().toString());

    // We do not want any animations when the ringing fragment is launched for the first time
    GeneralUtilities.showFragment(getSupportFragmentManager(), mAlarmRingingFragment,
            AlarmRingingFragment.RINGING_FRAGMENT_TAG);

    mAlarmCancelTask = new Runnable() {
        @Override/*from www.  j a va  2 s.c  o m*/
        public void run() {
            mAlarmTimedOut = true;
            if (!isGameRunning()) {
                finishActivity();
            }
        }
    };
    mHandler = new Handler();
    int ringingDuration = getAlarmRingingDuration();
    if (ringingDuration > 0) {
        mHandler.postDelayed(mAlarmCancelTask, ringingDuration);
    }

    registerReceiver(mScreenReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));

    bindRingingService();
}

From source file:com.android.screenspeak.SideTapManager.java

public static IntentFilter getFilter() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    return filter;
}

From source file:org.computeforcancer.android.client.Monitor.java

@Override
public void onCreate() {

    Log.d(Logging.TAG, "Monitor onCreate()");

    // populate attributes with XML resource values
    boincWorkingDir = getString(R.string.client_path);
    fileNameClient = getString(R.string.client_name);
    fileNameCLI = getString(R.string.client_cli);
    fileNameCABundle = getString(R.string.client_cabundle);
    fileNameClientConfig = getString(R.string.client_config);
    fileNameGuiAuthentication = getString(R.string.auth_file_name);
    fileNameAllProjectsList = getString(R.string.all_projects_list);
    clientStatusInterval = getResources().getInteger(R.integer.status_update_interval_ms);
    deviceStatusIntervalScreenOff = getResources()
            .getInteger(R.integer.device_status_update_screen_off_every_X_loop);
    clientSocketAddress = getString(R.string.client_socket_address);

    // initialize singleton helper classes and provide application context
    clientStatus = new ClientStatus(this);
    getAppPrefs().readPrefs(this);
    deviceStatus = new DeviceStatus(this, getAppPrefs());
    if (Logging.ERROR)
        Log.d(Logging.TAG, "Monitor onCreate(): singletons initialized");

    // set current screen on/off status
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    screenOn = pm.isScreenOn();//from   ww w  . j a  v a 2  s .c  o m

    // initialize DeviceStatus wrapper
    deviceStatus = new DeviceStatus(getApplicationContext(), getAppPrefs());

    // register screen on/off receiver
    IntentFilter onFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    IntentFilter offFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenOnOffReceiver, onFilter);
    registerReceiver(screenOnOffReceiver, offFilter);
}

From source file:com.android.talkback.SideTapManager.java

@Override
public void onReceive(Context context, Intent intent) {
    if (!TalkBackService.isServiceActive()) {
        return;/*from   w w w .j  a v  a  2 s  .c  o  m*/
    }

    String action = intent.getAction();
    if (action.equals(Intent.ACTION_SCREEN_ON)) {
        onReloadPreferences();
    }
    if (action.equals(Intent.ACTION_SCREEN_OFF)) {
        mIntegratedTapDetector.stop();
    }
}

From source file:com.android.screenspeak.SideTapManager.java

@Override
public void onReceive(Context context, Intent intent) {
    if (!ScreenSpeakService.isServiceActive()) {
        return;/*from   w w w . ja v  a2  s. c o  m*/
    }

    String action = intent.getAction();
    if (action.equals(Intent.ACTION_SCREEN_ON)) {
        onReloadPreferences();
    }
    if (action.equals(Intent.ACTION_SCREEN_OFF)) {
        mIntegratedTapDetector.stop();
    }
}

From source file:com.cleanwiz.applock.service.LockService.java

public void registerApplicationReceiver() {
    IntentFilter packageIntentFilter = new IntentFilter();
    IntentFilter eventIntentFilter = new IntentFilter();
    eventIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    eventIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
    eventIntentFilter.addAction(Intent.ACTION_TIME_TICK);
    eventIntentFilter.addAction(Intent.ACTION_USER_PRESENT);
    eventIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    packageIntentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageIntentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageIntentFilter.addDataScheme("package");
    getApplicationContext().registerReceiver(packageReceiver, packageIntentFilter);
    getApplicationContext().registerReceiver(eventReceiver, eventIntentFilter);
    IntentFilter filter = new IntentFilter();
    filter.addAction(LOCK_SERVICE_LASTTIME);
    filter.addAction(LOCK_SERVICE_LEAVEAMENT);
    filter.addAction(LOCK_SERVICE_LEAVERTIME);
    filter.addAction(LOCK_SERVICE_LOCKSTATE);

    lastUnlockTimeSeconds = 0;/*from  w ww  . j av  a  2s.  c  o m*/
    allowedLeaveAment = application.getAllowedLeaveAment();
    leaverTime = application.getLeaverTime();
    lockState = application.getAppLockState();
    registerReceiver(new ServiceReceiver(), filter);
}

From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessorTest.java

private void simulateScreenState(boolean screenOn) {
    Intent intent = new Intent(screenOn ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF);
    getService().getRingerModeAndScreenMonitor().onReceive(getService(), intent);
}

From source file:fm.krui.kruifm.StreamActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.stream_layout);

    // Instantiate class members
    prefManager = new PreferenceManager(this);
    favTrackManager = new FavoriteTrackManager(this);

    stationTag = getIntent().getIntExtra(KEY_STATION_TAG, -1);

    // Set ActionBar Title
    ActionBar actionBar = getActionBar();
    actionBar.setTitle(getString(R.string.listen_sidebar));
    actionBar.setSubtitle(getActivitySubtitle(getIntent()));

    // FIXME: Move these to PreferenceManager after expanding its scope for cleaner code
    trackPrefs = this.getSharedPreferences(StreamService.PREFS_NAME, 0);

    // Instantiate broadcast receiver
    broadcastReceiver = new BroadcastReceiver() {
        @Override/*from www . j  av  a  2  s  .c  o  m*/
        public void onReceive(Context context, Intent intent) {
            processBroadcastCommand(intent);
        }
    };

    // Retrieve player state to determine how to build this activity
    boolean playerState = prefManager.getPlayerState();

    // If audio is playing in StreamService, we don't want to rebuffer, and we want to restore the UI state from the cache.
    if (playerState) {
        restoreUIState();
    }

    // If audio is NOT playing, buffer and treat this launch like a clean startup.
    else {
        // Determine the URL we need to use to stream based on the station tag and quality preferences
        streamUrl = getStreamUrl(stationTag);
        Log.v(TAG, "streamUrl is now set to: " + streamUrl);

        // Perform initial configuration of audio server
        changeUrl(stationTag);

        // Begin buffering the audio
        startAudio((ImageView) this.findViewById(R.id.play_audio_imageview));
    }

    // Build play button listener
    final ImageView playButton = (ImageView) this.findViewById(R.id.play_audio_imageview);
    playButton.setOnClickListener(new View.OnClickListener() {

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

    // Build volume seek bar listener
    // ** DISABLED FOR NOW -- This might be completely thrown out. **
    /*final SeekBar volumeSeekBar = (SeekBar)this.findViewById(R.id.volume_seekbar);
    volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            
    // When seek bar progress is changed, change the audio of the media player appropriately.
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        // Send new volume via intent? Will this be slow?
    }
            
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    }
            
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
    }
    }); */

    // Build settings button listener and apply it to settings icon and submit button
    View.OnClickListener flipListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Card flip animation which toggles between stream controls and settings views
            flipCard();
        }
    };

    final ImageView settingsButton = (ImageView) this.findViewById(R.id.stream_settings_imageview);
    final Button saveSettingsButton = (Button) this.findViewById(R.id.set_stream_settings_button);
    settingsButton.setOnClickListener(flipListener);
    saveSettingsButton.setOnClickListener(flipListener);

    // Build favorite button listener
    final ImageView favoriteButton = (ImageView) this.findViewById(R.id.stream_favorite_imageview);
    favoriteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (trackIsFavorite) {
                favoriteButton.setImageResource(R.drawable.star_unfilled_white);
                trackIsFavorite = false;
                removeTrackFromFavorites();
            } else {
                favoriteButton.setImageResource(R.drawable.star_filled_white);
                trackIsFavorite = true;
                addTrackToFavorites();
            }
        }
    });

    // Build settings switches
    final Switch streamQualitySwitch = (Switch) this.findViewById(R.id.stream_quality_switch);
    final Switch albumArtSwitch = (Switch) this.findViewById(R.id.stream_album_art_switch);

    // Set initial state of switches
    albumArtSwitch.setChecked(prefManager.getAlbumArtDownloadPreference());
    if (prefManager.getStreamQuality() == prefManager.HIGH_QUALITY) {
        streamQualitySwitch.setChecked(true);
    } else {
        streamQualitySwitch.setChecked(false);
    }

    // Assign listeners to switches
    streamQualitySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                prefManager.setStreamQuality(prefManager.HIGH_QUALITY);
                Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality());
            } else {
                prefManager.setStreamQuality(prefManager.LOW_QUALITY);
                Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality());
            }
            changeUrl(stationSpinnerPosition);
        }
    });

    albumArtSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                prefManager.setAlbumArtDownloadPreference(true);
                Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference());
            } else {
                prefManager.setAlbumArtDownloadPreference(false);
                Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference());
            }
        }
    });

    // ***** Old onCreate function starts here!
    // Initialize screen lock/wake receiver
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    BroadcastReceiver screenReceiver = new ScreenReceiver();

    // Attach it to this activity
    this.getApplicationContext().registerReceiver(screenReceiver, filter);

}