package com.hadithbd.banglahadith.ui;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.hadithbd.banglahadith.R;
import com.hadithbd.banglahadith.util.Constants;
import com.hadithbd.banglahadith.util.Utils;

/**
 * Created by Sharif on 2/28/2015.
 */
public class BaseActivity extends ActionBarActivity {


    public void setHomeBackground() {
        BitmapDrawable whiteLayer = (BitmapDrawable) getResources().getDrawable(R.drawable.home_white_layer);
        BitmapDrawable iconCaliography = (BitmapDrawable) getResources().getDrawable(R.drawable.bg_caliography);
        iconCaliography.setGravity(Gravity.BOTTOM);
        BitmapDrawable blueLayer = (BitmapDrawable) getResources().getDrawable(R.drawable.home_blue_layer);
        Drawable[] drawables = new Drawable[]{blueLayer, iconCaliography, whiteLayer};
        LayerDrawable layerDrawable = new LayerDrawable(drawables);
        setLayerToBackground(layerDrawable);
    }


    private void setLayerToBackground(LayerDrawable layerDrawable) {
        View view = findViewById(android.R.id.content);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackgroundDrawable(layerDrawable);
        } else {
            view.setBackground(layerDrawable);
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId()!=android.R.id.home){
            Intent intent = new Intent(this, MenuActivity.class);
            intent.putExtra(Constants.MENU_ITEM_ID, item.getItemId());
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }

        return super.onOptionsItemSelected(item);
    }

    private void openLatestUpdateActivity() {

        final boolean isInternetConnectionAvailable = Utils.isNetworkAvailable(this);

        if (!isInternetConnectionAvailable) {
            Toast.makeText(this, getString(R.string.text_internet_connection_failed),
                    Toast.LENGTH_SHORT).show();
        }

        if (isInternetConnectionAvailable) {

        }

    }
}

@@ -228,16 +228,42 @@
 .Build;%0A
+import android.os.Bundle;%0A
 import a
@@ -299,24 +299,24 @@
 arActivity;%0A
-
 import andro
@@ -414,16 +414,55 @@
 w.View;%0A
+import android.view.ViewConfiguration;%0A
 import a
@@ -614,16 +614,49 @@
 Utils;%0A%0A
+import java.lang.reflect.Field;%0A%0A
 /**%0A * C
@@ -745,16 +745,164 @@
 vity %7B%0A%0A
+    @Override%0A    protected void onCreate(Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A        getOverflowMenu();%0A    %7D%0A
 %0A    pub
@@ -1518,24 +1518,484 @@
 le);%0A    %7D%0A%0A
+    private void getOverflowMenu() %7B%0A        try %7B%0A            ViewConfiguration config = ViewConfiguration.get(this);%0A            Field menuKeyField = ViewConfiguration.class.getDeclaredField(%22sHasPermanentMenuKey%22);%0A            if (menuKeyField != null) %7B%0A                menuKeyField.setAccessible(true);%0A                menuKeyField.setBoolean(config, false);%0A            %7D%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A
 %0A    private
@@ -2569,18 +2569,20 @@
 ItemId()
+ 
 !=
+ 
 android.
@@ -2591,16 +2591,17 @@
 id.home)
+ 
 %7B%0A      

Add hack to bring back overflow menu