To import the library into the project, add the line in build.gradle assembly file (Module: app):<\/p>\n
allprojects {\r\n repositories {\r\n maven { url \"https:\/\/jitpack.io\" }\r\n }\r\n}\r\n\r\ndependencies {\r\n compile 'com.github.balrampandey19:AppLocker:1.0.1'\r\n}<\/pre>\nAlso needed are string resources in res \/ values \u200b\u200b\/ strings.xml file:<\/p>\n
<resources>\r\n <string name=\"app_name\">AppLock<\/string>\r\n\r\n <string name=\"manage_passcode\">Manage Pin<\/string>\r\n <string name=\"enter_passcode\">Enter Pin<\/string>\r\n <string name=\"enter_old_passcode\">Enter old Pin<\/string>\r\n <string name=\"reenter_passcode\">Re-enter Pin<\/string>\r\n <string name=\"change_passcode\">Change Pin<\/string>\r\n <string name=\"setup_passcode\">Setup pin<\/string>\r\n <string name=\"passcode_wrong\">Wrong pin, please try again.<\/string>\r\n <string name=\"enable_passcode\">Enable Pin<\/string>\r\n<\/resources><\/pre>\nIn the main class of the application package is created App.java, which initialize AppLocker:<\/p>\n
import android.app.Application;\r\n\r\nimport com.balram.locker.view.AppLocker;\r\n\r\n\r\npublic class App extends Application {\r\n @Override\r\n public void onCreate() {\r\n super.onCreate();\r\n AppLocker.getInstance().enableAppLock(this);\r\n }\r\n}<\/pre>\nDeclare App.java class in the manifest in the application section:<\/p>\n
<application\r\n android:name=\".App\"\r\n ...\r\n <\/application><\/pre>\n\u041c\u0430\u043a\u0435\u0442 \u0433\u043b\u0430\u0432\u043d\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430 activity_main.xml \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u0432\u0435 \u043a\u043d\u043e\u043f\u043a\u0438:<\/p>\n
<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n android:id=\"@+id\/activity_main\"\r\n android:layout_width=\"match_parent\"\r\n android:layout_height=\"match_parent\"\r\n android:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\n android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\n android:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\n android:paddingTop=\"@dimen\/activity_vertical_margin\"\r\n android:gravity=\"center\"\r\n tools:context=\"info.fandroid.applock.MainActivity\">\r\n\r\n <Button\r\n android:layout_width=\"match_parent\"\r\n android:layout_height=\"wrap_content\"\r\n android:id=\"@+id\/bt_change\"\r\n android:layout_above=\"@+id\/bt_on_off\"\r\n android:layout_alignParentStart=\"true\" \/>\r\n\r\n <Button\r\n android:layout_width=\"match_parent\"\r\n android:layout_height=\"wrap_content\"\r\n android:id=\"@+id\/bt_on_off\"\r\n android:layout_alignParentBottom=\"true\"\r\n android:layout_alignParentStart=\"true\"\r\n android:layout_marginBottom=\"156dp\" \/>\r\n<\/RelativeLayout><\/pre>\nAnd the code class MainActivity.java, which is inherited from the library class LockActivity:<\/p>\n
import android.content.Intent;\r\nimport android.os.Bundle;\r\nimport android.view.View;\r\nimport android.widget.Button;\r\nimport android.widget.Toast;\r\n\r\nimport com.balram.locker.utils.Locker;\r\nimport com.balram.locker.view.AppLocker;\r\nimport com.balram.locker.view.LockActivity;\r\n\r\npublic class MainActivity extends LockActivity implements View.OnClickListener {\r\n\r\n private Button btOnOff;\r\n private Button btChange;\r\n\r\n @Override\r\n protected void onCreate(Bundle savedInstanceState) {\r\n super.onCreate(savedInstanceState);\r\n setContentView(R.layout.activity_main);\r\n\r\n btOnOff = (Button) findViewById(R.id.bt_on_off);\r\n btChange = (Button) findViewById(R.id.bt_change);\r\n\r\n btOnOff.setOnClickListener(this);\r\n btChange.setOnClickListener(this);\r\n btChange.setText(R.string.change_passcode);\r\n\r\n updateUI();\r\n }\r\n\r\n @Override\r\n public void onClick(View view) {\r\n if (view.equals(btOnOff)) {\r\n int type = AppLocker.getInstance().getAppLock().isPasscodeSet() ? Locker.DISABLE_PASSLOCK : Locker.ENABLE_PASSLOCK;\r\n Intent intent = new Intent(this, LockActivity.class);\r\n intent.putExtra(Locker.TYPE, type);\r\n startActivityForResult(intent, type);\r\n } else if (view.equals(btChange)) {\r\n Intent intent = new Intent(this, LockActivity.class);\r\n intent.putExtra(Locker.TYPE, Locker.CHANGE_PASSWORD);\r\n intent.putExtra(Locker.MESSAGE, getString(R.string.enter_old_passcode));\r\n startActivityForResult(intent, Locker.CHANGE_PASSWORD);\r\n }\r\n\r\n }\r\n\r\n @Override\r\n protected void onActivityResult(int requestCode, int resultCode, Intent data) {\r\n super.onActivityResult(requestCode, resultCode, data);\r\n\r\n switch (requestCode) {\r\n case Locker.DISABLE_PASSLOCK:\r\n break;\r\n case Locker.ENABLE_PASSLOCK:\r\n case Locker.CHANGE_PASSWORD:\r\n if (resultCode == RESULT_OK) {\r\n Toast.makeText(this, getString(R.string.setup_passcode), Toast.LENGTH_SHORT).show();\r\n }\r\n break;\r\n default:\r\n break;\r\n }\r\n updateUI();\r\n\r\n }\r\n private void updateUI() {\r\n if (AppLocker.getInstance().getAppLock().isPasscodeSet()) {\r\n btOnOff.setText(R.string.disable_passcode);\r\n btChange.setEnabled(true);\r\n } else {\r\n btOnOff.setText(R.string.enable_passcode);\r\n btChange.setEnabled(false);\r\n }\r\n }\r\n}<\/pre>\nIn the method onCreate announced button and pressing the assigned handler. In the method onClick define the touch of a button as well as soda and send Intents with data sets that cause LockActivity class. Last displays the input screen to set or change the password. The method onActivityResult desired behavior can add applications, depending on what came intent. updateUI method changes the text on the buttons and make the change password button is disabled if the password protection is disabled.<\/p>\n
AppLocker Source code library — on the page<\/a> in GitHub.[:]<\/p>\n","protected":false},"excerpt":{"rendered":"[:ru]\u0412 \u044d\u0442\u043e\u043c \u0432\u0438\u0434\u0435\u043e\u0443\u0440\u043e\u043a\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 AppLocker. \u00a0\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434\u00a0— \u043d\u0438\u0436\u0435, \u043f\u043e\u0434 \u0432\u0438\u0434\u0435\u043e. \u0414\u043b\u044f \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0444\u0430\u0439\u043b \u0441\u0431\u043e\u0440\u043a\u0438 build.gradle (Module: app): allprojects { repositories { maven { url «https:\/\/jitpack.io» } } } dependencies { compile ‘com.github.balrampandey19:AppLocker:1.0.1’ } \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0432 \u0444\u0430\u0439\u043b\u0435 res\/values\/strings.xml: <resources> <string name=»app_name»>AppLock<\/string> […]<\/p>\n","protected":false},"author":1,"featured_media":5936,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[3,63,19,136,5,132,133],"_links":{"self":[{"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/posts\/5934"}],"collection":[{"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/comments?post=5934"}],"version-history":[{"count":4,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/posts\/5934\/revisions"}],"predecessor-version":[{"id":5939,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/posts\/5934\/revisions\/5939"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/media\/5936"}],"wp:attachment":[{"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/media?parent=5934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/categories?post=5934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fandroid.info\/wp-json\/wp\/v2\/tags?post=5934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}