Android 默认pin锁定屏幕布局

Android 默认pin锁定屏幕布局,android,layout,lockscreen,Android,Layout,Lockscreen,我想提供锁屏,所以每次用户打开我的应用程序时,他都会被迫输入pin。所以我正在寻找Android的默认pin锁布局(如图所示),它应该可以在Android 4.0上运行。你能告诉我在哪里找到这个布局或者如何正确地实现它吗 我从github下载了git项目,并对其进行了少量更改,以提供类似于您的图像的GUI: 因此,创建一个项目并在mainActivity中插入以下代码: public class PinEntryView extends Activity { String userEnte

我想提供锁屏,所以每次用户打开我的应用程序时,他都会被迫输入pin。所以我正在寻找Android的默认pin锁布局(如图所示),它应该可以在Android 4.0上运行。你能告诉我在哪里找到这个布局或者如何正确地实现它吗

我从github下载了git项目,并对其进行了少量更改,以提供类似于您的图像的GUI:

因此,创建一个项目并在mainActivity中插入以下代码:

public class PinEntryView extends Activity {

String userEntered;
String userPin="8888";

final int PIN_LENGTH = 4;
boolean keyPadLockedFlag = false;
Context appContext;

TextView titleView;

TextView pinBox0;
TextView pinBox1;
TextView pinBox2;
TextView pinBox3;



TextView statusView;

Button button0;
Button button1;
Button button2;
Button button3;
Button button4;
Button button5;
Button button6;
Button button7;
Button button8;
Button button9;
Button button10;
Button buttonExit;
Button buttonDelete;
EditText passwordInput;
ImageView backSpace;

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

    appContext = this;
    userEntered = "";


    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main_layout);

    //Typeface xpressive=Typeface.createFromAsset(getAssets(), "fonts/XpressiveBold.ttf");

    statusView = (TextView) findViewById(R.id.statusview);
    passwordInput = (EditText) findViewById(R.id.editText);
    backSpace = (ImageView) findViewById(R.id.imageView);
    buttonExit = (Button) findViewById(R.id.buttonExit);
    backSpace.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            passwordInput.setText(passwordInput.getText().toString().substring(0,passwordInput.getText().toString().length()-2));
        }
    });
    buttonExit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            //Exit app
            Intent i = new Intent();
            i.setAction(Intent.ACTION_MAIN);
            i.addCategory(Intent.CATEGORY_HOME);
            appContext.startActivity(i); 
            finish();

        }

        }
    );
    //buttonExit.setTypeface(xpressive);


    buttonDelete = (Button) findViewById(R.id.buttonDeleteBack);
    buttonDelete.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (keyPadLockedFlag == true)
            {
                return;
            }

            if (userEntered.length()>0)
            {
                userEntered = userEntered.substring(0,userEntered.length()-1);
                passwordInput.setText("");
            }


        }

        }
    );

    titleView = (TextView)findViewById(R.id.time);
    //titleView.setTypeface(xpressive);








    View.OnClickListener pinButtonHandler = new View.OnClickListener() {
        public void onClick(View v) {

            if (keyPadLockedFlag == true)
            {
                return;
            }

            Button pressedButton = (Button)v;


            if (userEntered.length()<PIN_LENGTH)
            {
                userEntered = userEntered + pressedButton.getText();
                Log.v("PinView", "User entered="+userEntered);

                //Update pin boxes
                passwordInput.setText(passwordInput.getText().toString()+"*");
                passwordInput.setSelection(passwordInput.getText().toString().length());

                if (userEntered.length()==PIN_LENGTH)
                {
                    //Check if entered PIN is correct
                    if (userEntered.equals(userPin))
                    {
                        statusView.setTextColor(Color.GREEN);
                        statusView.setText("Correct");
                        Log.v("PinView", "Correct PIN");
                        finish();
                    }
                    else
                    {
                        statusView.setTextColor(Color.RED);
                        statusView.setText("Wrong PIN. Keypad Locked");
                        keyPadLockedFlag = true;
                        Log.v("PinView", "Wrong PIN");

                        new LockKeyPadOperation().execute("");
                    }
                }   
            }
            else
            {
                //Roll over
                passwordInput.setText("");

                userEntered = "";

                statusView.setText("");

                userEntered = userEntered + pressedButton.getText();
                Log.v("PinView", "User entered="+userEntered);

                //Update pin boxes
                passwordInput.setText("8");

            }


        }
      };


    button0 = (Button)findViewById(R.id.button0);
    //button0.setTypeface(xpressive);
    button0.setOnClickListener(pinButtonHandler);

    button1 = (Button)findViewById(R.id.button1);
    //button1.setTypeface(xpressive);
    button1.setOnClickListener(pinButtonHandler);

    button2 = (Button)findViewById(R.id.button2);
    //button2.setTypeface(xpressive);
    button2.setOnClickListener(pinButtonHandler);


    button3 = (Button)findViewById(R.id.button3);
    //button3.setTypeface(xpressive);
    button3.setOnClickListener(pinButtonHandler);

    button4 = (Button)findViewById(R.id.button4);
    //button4.setTypeface(xpressive);
    button4.setOnClickListener(pinButtonHandler);

    button5 = (Button)findViewById(R.id.button5);
    //button5.setTypeface(xpressive);
    button5.setOnClickListener(pinButtonHandler);

    button6 = (Button)findViewById(R.id.button6);
    //button6.setTypeface(xpressive);
    button6.setOnClickListener(pinButtonHandler);

    button7 = (Button)findViewById(R.id.button7);
    //button7.setTypeface(xpressive);
    button7.setOnClickListener(pinButtonHandler);

    button8 = (Button)findViewById(R.id.button8);
    //button8.setTypeface(xpressive);
    button8.setOnClickListener(pinButtonHandler);

    button9 = (Button)findViewById(R.id.button9);
    //button9.setTypeface(xpressive);
    button9.setOnClickListener(pinButtonHandler);





    buttonDelete = (Button)findViewById(R.id.buttonDeleteBack);
    //buttonDelete.setTypeface(xpressive);



}

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub

    //App not allowed to go back to Parent activity until correct pin entered.
    return;
    //super.onBackPressed();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    //getMenuInflater().inflate(R.menu.activity_pin_entry_view, menu);
    return true;
}


private class LockKeyPadOperation extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... params) {
          for(int i=0;i<2;i++) {
              try {
                  Thread.sleep(1000);
              } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }

          return "Executed";
    }

    @Override
    protected void onPostExecute(String result) {
            statusView.setText("");

        //Roll over
        passwordInput.setText("");
            ;

            userEntered = "";

            keyPadLockedFlag = false;
    }

    @Override
    protected void onPreExecute() {
    }

    @Override
    protected void onProgressUpdate(Void... values) {
    }
注意:将以下行添加到mainfist.xml文件中的主活动节点

        android:theme="@android:style/Theme.NoTitleBar"
因此,您的活动节点必须类似于:

<activity
        android:name="com.example.MainActivity"
        android:theme="@android:style/Theme.NoTitleBar"

        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

        android:theme="@android:style/Theme.NoTitleBar"
<activity
        android:name="com.example.MainActivity"
        android:theme="@android:style/Theme.NoTitleBar"

        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>