Is the first touch ignored?

I am working on an alarm clock. As part of this, I have IntentServiceone that starts the action when the alarm really turns off. In Activity, onCreateI wake up on the screen, getting the vocals blocked, causing the activity to go full screen and playing the sound. Here's everything onCreate:

super.onCreate(savedInstanceState);

// Get Alarm ID from the extras
Bundle extras = getIntent().getExtras();
int id = extras.getInt("AlarmID", -1);

// Get Alarm info from the DB 
DB = new DatabaseHelper(this);
alarm = DB.getAlarm(id);

if (alarm == null || !alarm.isEnabled()) finish();

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_alarm);

// My root view
View contentView = findViewById(R.id.fullscreen_content);

// Hide action bar for full screen
ActionBar bar = getActionBar();
if (bar != null) bar.hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

// Hide nav bar
mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
mSystemUiHider.setup();
mSystemUiHider.hide();

// Show over lock screen
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

// Wake up screen
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "MyWakeLock");
wakeLock.acquire();

// Get UI Elements
TextView time = (TextView)findViewById(R.id.Time);
TextView name = (TextView)findViewById(R.id.SmallAlarmName);

// Fill UI Elements
time.setText(Alarm.FormatTime(alarm.getHour(), alarm.getMinute()));
name.setText(alarm.getName());

// Play selected ringtone
tone = RingtoneManager.getRingtone(this, alarm.getSound());
tone.setStreamType(RingtoneManager.TYPE_ALARM);
tone.play();

The view is pretty simple: 2x TextViews to show the time and name of the alarm, and 2x clickable ImageViews for snooze and disable.

, , , , , . ImageViews Log.i, , , . . ImageView. , , . , , ?

Nexus 5, 4.4.3, Rooted, , Xposed Framework ( , ). - ( VM ).

, . , , .

EDIT: , - . , setFlags addFlags getWindow().setFlags(...). addFlags :

int flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
getWindow().addFlags(flags);

.

, , ?

onCreate , , . ImageViews, , .

2: , -. , , . logcat :

06-12 23:28:04.437      812-844/? W/InputEventReceiver﹕ Attempted to finish an input event but the input event receiver has already been disposed.

. , , .

, . , , , . , , .

+4
3

, .

:

int flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
        WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
        WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING |
        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
getWindow().addFlags(flags);

, ( , ) , :

getWindow().getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

, : ! , - UI hider . , , , . , , , , , . , , .

+2

, , .. - , :

getWindow().getDecorView().setSystemUiVisibility(
    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
          //| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
          //| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
          | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

, . , " Immersive", , ( ) , , , .. : -)

+6

I would suggest you put most of the code in onStart () and have a view of the content set to onCreate (). One more thing I would suggest. Instead of using an attribute android:onClick=""in an XML layout, use a listener and assign it to a button using code. But this is more of a "separation of concerns."

-1
source

Source: https://habr.com/ru/post/1544278/


All Articles