• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

methods detected as variables

N3ur0t

Lurker
I can't find the error

Code:
package com.blackcover;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class Cover extends Activity {

    protected int sleep = 0;

    HomeKeyLocker homeKeyLocker;

    [USER=1021285]@override[/USER]
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.cover);

        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        byte port = extras.getByte("port");

                try {
                    switch (port) {
                        case 0:
                            sleep = 1800000;//1.800.000 - 30'
                        case 1:
                            sleep = 3600000;//3.600.000 - 1h
                        case 2:
                            sleep = 5400000;//5.400.000 - 1h30'
                        case 3:
                            sleep = 7200000;//7.200.000 -2h
                    }


                    new CountDownTimer(sleep, 1000) {

                        [USER=1021285]@override[/USER]
                        public void onTick(long l) {}

                        [USER=1021285]@override[/USER]
                        public void onFinish() {}
                    }.start();


                    [USER=1021285]@override[/USER]//Evitar presión larga de power
                    public void onWindowFocusChanged(boolean hasFocus) {
                        super.onWindowFocusChanged(hasFocus);
                        if(!hasFocus) {
                            // Close every kind of system dialog
                            Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
                            sendBroadcast(closeDialog);
                        }
                    }

                    [USER=1021285]@override[/USER]
                    public void onBackPressed(){}

                    homeKeyLocker = new HomeKeyLocker();
                    homeKeyLocker.lock(this);

                    //[USER=1021285]@override[/USER]
                    public boolean onKeyLongPress(final int keyCode, final KeyEvent event){
                        if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP){return true;}
                        return super.onKeyLongPress(keyCode, event);
                    }

                }//end try
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
}//end main
 
Last edited by a moderator:
I think you're not closing your onCreate() method correctly with a terminating "}"
See modified code below, containing the missing brace.
I haven't run this code through the compiler, but you get the idea.


Code:
package com.blackcover;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class Cover extends Activity {

    protected int sleep = 0;

    HomeKeyLocker homeKeyLocker;

    [USER=1021285]@override[/USER]
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.cover);

        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        byte port = extras.getByte("port");

                try {
                    switch (port) {
                        case 0:
                            sleep = 1800000;//1.800.000 - 30'
                        case 1:
                            sleep = 3600000;//3.600.000 - 1h
                        case 2:
                            sleep = 5400000;//5.400.000 - 1h30'
                        case 3:
                            sleep = 7200000;//7.200.000 -2h
                    }


                    new CountDownTimer(sleep, 1000) {

                        [USER=1021285]@override[/USER]
                        public void onTick(long l) {}

                        [USER=1021285]@override[/USER]
                        public void onFinish() {}
                    }.start();
             }  // <--------------------------------- onCreate METHOD CLOSING BRACE HERE


                    [USER=1021285]@override[/USER]//Evitar presión larga de power
                    public void onWindowFocusChanged(boolean hasFocus) {
                        super.onWindowFocusChanged(hasFocus);
                        if(!hasFocus) {
                            // Close every kind of system dialog
                            Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
                            sendBroadcast(closeDialog);
                        }
                    }

                    [USER=1021285]@override[/USER]
                    public void onBackPressed(){}

                    homeKeyLocker = new HomeKeyLocker();
                    homeKeyLocker.lock(this);

                    //[USER=1021285]@override[/USER]
                    public boolean onKeyLongPress(final int keyCode, final KeyEvent event){
                        if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP){return true;}
                        return super.onKeyLongPress(keyCode, event);
                    }

                }//end try
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
}//end main
 
oh I was thinking that all that code goes into the onCreate. his Brace is the second counting from the bottom.
 
Another thing.the "homeKeyLocker.lock(this);" goes in onCreate or outside can't figure out were it goes. don't matter were I put shows me error.
Code:
package com.blackcover;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class Cover extends Activity {

    int sleep = 0;

    private HomeKeyLocker homeKeyLocker;

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

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.cover);

        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        byte port = extras.getByte("port");

        homeKeyLocker = new HomeKeyLocker();
        
        switch (port) {
            case 0:
                sleep = 1800000;//1.800.000 - 30'
            case 1:
                sleep = 3600000;//3.600.000 - 1h
            case 2:
                sleep = 5400000;//5.400.000 - 1h30'
            case 3:
                sleep = 7200000;//7.200.000 -2h
        }
        new CountDownTimer(sleep, 1000) {

            @Override
            public void onTick(long l) {
            }

            @Override
            public void onFinish() {
            }
        }.start();
    }//onCreate

    homeKeyLocker.lock(this);

    @Override//Evitar presión larga de power
        public void onWindowFocusChanged(boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
            if(!hasFocus) {
                // Close every kind of system dialog
                Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
                sendBroadcast(closeDialog);
            }
        }

        @Override
        public void onBackPressed(){}

        @Override
        public boolean onKeyLongPress(final int keyCode, final KeyEvent event){
            if(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP){return true;}
            return super.onKeyLongPress(keyCode, event);
        }
}//end main
 
homeKeyLocker.lock(this) is not in any method. You can't have a line of code floating around like that, it's got to be within the scope of a method.
Put that line in your onCreate() method.
 
homeKeyLocker.lock(this) is not in any method. You can't have a line of code floating around like that, it's got to be within the scope of a method.
Put that line in your onCreate() method.
Thank you now it's working. Sorry I can't answer you yesterday. Let's resolve next bug hehe. Cheers.
 
Back
Top Bottom