package com.ae.apps.lib.activities;

import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public abstract class ToolBarBaseActivity extends AppCompatActivity {
    Toolbar mToolbar = null;

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

        setContentView(getLayoutResourceId());

        // Find the toolbar and set it as action bar
        mToolbar = findViewById(getToolbarResourceId());
        if (null != mToolbar) {
            setSupportActionBar(mToolbar);
        }
    }

    /**
     * Sets the toolbartitle
     *
     * @param title Title for the toolbar
     */
    protected void setToolbarTitle(String title) {
        if (null != getSupportActionBar()) {
            getSupportActionBar().setTitle(title);
        }
    }

    /**
     * Returns the toolbar instance
     *
     * @return the toolbar instance
     */
    protected Toolbar getToolBar() {
        return mToolbar;
    }

    /**
     * Returns the toolbar resource id. Should be R.id.toolbar in most cases
     *
     * @return return the toolbar resource id
     */
    protected abstract int getToolbarResourceId();

    /**
     * Returns the layout resource id for the activity
     *
     * @return return the layout resource id
     */
    protected abstract int getLayoutResourceId();

    protected void displayHomeAsUp() {
        // Show the back arrow in toolbar to go back
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // Fix for NPE on LG Devices when pressing hardware menu button
        return keyCode == KeyEvent.KEYCODE_MENU && "LGE".equals(Build.BRAND)
                || super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        // Fix for NPE on LG Devices when pressing hardware menu button
        if (keyCode == KeyEvent.KEYCODE_MENU && "LGE".equals(Build.BRAND)) {
            openOptionsMenu();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

}

@@ -1,8 +1,605 @@
+/*%0A * Copyright 2018 Midhun Harikumar%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A
 package 
@@ -801,16 +801,101 @@
 olbar;%0A%0A
+/**%0A * Base Activity if using a NoActionBar theme and to supply a custom toolbar%0A */%0A
 public a
@@ -956,16 +956,67 @@
 ivity %7B%0A
+    private static final String BRAND_LGE = %22LGE%22;%0A
     Tool
@@ -2883,37 +2883,41 @@
 KEYCODE_MENU && 
-%22
+BRAND_
 LGE
-%22
 .equals(Build.BR

add license