{"id":18269766,"url":"https://github.com/skyfe79/androidactivity","last_synced_at":"2026-06-10T16:31:05.347Z","repository":{"id":137746162,"uuid":"58226366","full_name":"skyfe79/AndroidActivity","owner":"skyfe79","description":"AndroidActivity provides lifecycle callback methods from the aspect of view. If you use these callback methods, you don't have to use ViewTreeObserver.","archived":false,"fork":false,"pushed_at":"2016-06-29T03:12:23.000Z","size":373,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T03:15:41.851Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skyfe79.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-06T18:14:57.000Z","updated_at":"2016-05-09T05:24:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"f2e83587-db32-4ccf-a4d6-59b0e7c40e75","html_url":"https://github.com/skyfe79/AndroidActivity","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/skyfe79/AndroidActivity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyfe79%2FAndroidActivity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyfe79%2FAndroidActivity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyfe79%2FAndroidActivity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyfe79%2FAndroidActivity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skyfe79","download_url":"https://codeload.github.com/skyfe79/AndroidActivity/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyfe79%2FAndroidActivity/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34161283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:37:06.678Z","updated_at":"2026-06-10T16:31:05.324Z","avatar_url":"https://github.com/skyfe79.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# AndroidActivity\n\n![](art/logo.png)\n\nThere are many questions about timing for finding Android's view size and detecting appear or disappear of soft keyboard.\n\n * When can I get android's view size?\n * How to find view width and height before it's drawn?\n * How to detect appear and disappear of soft keyboad?\n * How to get the keyboard size?\n\nIf you want to find view size in an activity, using ViewTreeObserver is the answer. However, you have to write some dirty code to use ViewTreeObserver. \n\nIf you find some simple method, AndroidActivity is the solution.\n\n## Setup Gradle\n\n```groovy\ndependencies {\n    ...\n    compile 'kr.pe.burt.android.lib:androidactivity:0.0.3'\n}\n```\n## Activities\n \n * AndroidAppCompatActivity extends AppCompatActivity\n * AndroidActivity extends Activity\n\n \n## Bye Bye ViewTreeObserver\n\nAndroidActivity provides lifecycle callback methods from the aspect of view. If you use these callback methods, you don't have to use ViewTreeObserver. \n\n* viewDidLoad\n * Called when the content view of activity is setted. \n* viewDidLayout\n * Called when the view's layout is completed.\n* viewWillAppear\n * Called when the view's appearance is about to draw. \n* viewWillDisappear\n * Called when the view is about to disappear. \n* viewDidDisappear\n * Called when the view is disappeared.  \n* keyboardDidAppear\n * Called when the soft keyboard is appear with keyboard's height in pixel.\n* keyboardDidDisappear\n * Called when the soft keyboard is disappear.   \n\nIt is similar to the lifecycle of view which is in UIViewController on the iOS.\n\n## When can you get view's size?\n\n* viewDidLayout\n* viewWillAppear\n\nYou can get the size of view and the position of view on the viewDidLayout, viewWillAppear method. If you need to use view's geometry, you just override that methods and use the view's geometry methods like view.left(), view.top(), view.width() and view.height()\n\n## Callback ordering.\n\n### Launch App\n\n 1. viewDidLoad\n 2. viewDidLayout\n 3. viewWillAppear\n\n### Rotate App\n\n 1. viewWillDisappear\n 2. viewDidDisappear\n 3. viewDidLoad\n 4. viewDidLayout\n 5. viewWillAppear\n\n### Tap the Home button.\n\n 1. viewWillDisappear\n 2. viewDidDisappear\n\n### Restore from app history stack.\n \n 1. viewWillAppear\n\n### Go to another activity\n\n 1. viewWillDisappear\n 2. viewDidDisappear\n\n### Back from another activity\n\n 1. viewWillAppear\n\n## How to use AndroidActivity?\n\nYou just inherit AndroidActivity and override above methods.\n\n```java\npublic class MainActivity extends AndroidActivity {\n\n    private static final String TAG = MainActivity.class.getSimpleName();\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n    }\n\n    @Override\n    protected void viewDidLoad() {\n        Log.v(TAG, \"viewDidLoad \" + buttonGeometryInfo());\n    }\n\n    @Override\n    protected void viewDidLayout() {\n        Log.v(TAG, \"viewDidLayout \" + buttonGeometryInfo());\n    }\n\n    @Override\n    protected void viewWillAppear() {\n        Log.v(TAG, \"viewWillAppear \" + buttonGeometryInfo());\n    }\n\n\n    @Override\n    protected void viewWillDisappear() {\n        Log.v(TAG, \"viewWillDisappear \" + buttonGeometryInfo());\n    }\n\n    @Override\n    protected void viewDidDisappear() {\n        Log.v(TAG, \"viewDidDisappear \" + buttonGeometryInfo());\n    }\n\n    private String buttonGeometryInfo() {\n        Button button = (Button) findViewById(R.id.button);\n        return \" [button] :: Left = \" + button.getLeft() + \", Top = \" + button.getTop() + \", Width = \" + button.getWidth() + \", Height = \" + button.getHeight();\n    }\n\n    void onButtonClicked(View sender) {\n        Intent intent = new Intent(this, SecondActivity.class);\n        startActivity(intent);\n    }\n}\n```\n\n## How to use keyboard callbacks?\n\nYou don't need to set the proprty `android:windowSoftInputMode=\"adjustResize\"` in the AndroidManifest.xml file. You just inherit AndroidActivity and override `keyboardDidAppear` and `keyboardDidDisappear` methods.\n\n```java\nprivate int lastKeyboardHeight = 0;\n\n@Override\npublic void keyboardDidAppear(int keyboardHeight) {\n    Log.v(\"TAG\", \"MainActivity : keyboardDidAppear\");\n    scrollUp(keyboardHeight);\n}\n\n@Override\npublic void keyboardDidDisappear() {\n    Log.v(\"TAG\", \"MainActivity : keyboardDidDisappear\");\n    scrollDown();\n}\n\nprivate void scrollUp(int keyboardHeight) {\n    View layout = findViewById(R.id.layout);\n    layout.scrollBy(0, keyboardHeight/2);\n    lastKeyboardHeight = keyboardHeight/2;\n}\n\nprivate void scrollDown() {\n    View layout = findViewById(R.id.layout);\n    layout.scrollBy(0, -lastKeyboardHeight);\n    lastKeyboardHeight = 0;\n}\n```\n\n## MIT License\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 Sungcheol Kim, [https://github.com/skyfe79/AndroidActivity](https://github.com/skyfe79/AndroidActivity)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyfe79%2Fandroidactivity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskyfe79%2Fandroidactivity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyfe79%2Fandroidactivity/lists"}