aboutsummaryrefslogtreecommitdiffstats
path: root/include/cmake.mk
Commit message (Expand)AuthorAgeFilesLines
* cmake.mk,rules.mk: fix host builds using CMake and ccachePetr Štetiar2020-12-051-2/+16
* cmake.mk: set C/CXX compiler for host builds as wellRosen Penev2020-12-051-0/+2
* cmake: Install host packages to lib instead of lib64Rosen Penev2019-12-231-0/+1
* build: use CMAKE_SOURCE_SUBDIR variable to cmake.mkAmol Bhave2018-09-291-2/+2
* cmake: skip build system check on compileFelix Fietkau2017-02-211-0/+4
* build: move STAGING_DIR_HOSTPKG and BUILD_DIR_HOST back to a common directory...Matthias Schiffer2017-01-181-1/+1
* build: use CXXFLAGS if definedHauke Mehrtens2016-10-131-1/+1
* include/cmake.mk: fix host buildsFelix Fietkau2016-07-291-1/+2
* cmake: include/cmake.mk add CMAKE_BINARY_SUBDIR to allow out of source tree b...Luke McKee2016-07-291-2/+5
* include/cmake.mk: Add helper macro to handle conditionals for CMake boolean t...Vasilis Tsiligiannis2016-04-131-0/+2
* include/cmake.mk: search in $(STAGING_DIR)/usr instead of plain $(STAGING_DIR...Felix Fietkau2016-01-251-1/+1
* include/cmake.mk: adjust for STAGING_DIR_HOST splitFelix Fietkau2016-01-251-3/+3
* build: for cmake, always use ccache from staging dir instead of relying on th...Felix Fietkau2016-01-031-4/+1
* cmake.mk: enable -Bsymbolic-functions by default for linking shared libs, sli...Felix Fietkau2015-04-191-2/+3
* cmake.mk: add host build supportFelix Fietkau2015-04-061-0/+26
* build: fix CMake assembly builds with ccacheFelix Fietkau2015-03-291-0/+2
* cmake: include external toolchain directory in CMAKE_FIND_ROOT_PATH (fixes #1...Felix Fietkau2015-03-161-1/+3
* include: cmake: prevent inclusion of rpath in binariesJo-Philipp Wich2015-02-081-0/+1
* build: use gcc-provided ar, nm and ranlib where appropriateFelix Fietkau2014-12-271-2/+4
* include/cmake.mk: fix indentationFelix Fietkau2014-06-111-1/+1
* include/cmake.mk: define CMAKE_AR and CMAKE_RANLIB to fix build errorsFelix Fietkau2014-05-301-11/+14
* cmake.mk: fix support for ccacheFelix Fietkau2013-11-181-2/+2
* include: cmake: pass toolchain directory to default root find path as wellJo-Philipp Wich2013-08-071-1/+1
* cmake.mk: add support for overriding the source dir, and define the cmake pre...Felix Fietkau2012-12-291-1/+4
* cmake: add support for V=csFelix Fietkau2012-04-261-1/+3
* cmake.mk: fix passing of LDFLAGSJo-Philipp Wich2012-01-091-3/+4
* cmake: fix ccache command when using host ccache (patch from #9611)Felix Fietkau2011-07-241-2/+6
* cmake.mk: fix bogus values for FIND_ROOT_PATH_MODE_*; kept plplot from compil...Jo-Philipp Wich2011-06-221-3/+3
* add LD_LIBRARY to cmake.mkFelix Fietkau2011-05-201-0/+1
* cmake.mk: don't assume toolchain binaries in .../bin/ if an external toolchai...Jo-Philipp Wich2011-04-111-0/+7
* cmake: Fix ccacheMichael Büsch2011-03-051-2/+16
* cmake: Pass VERBOSE=1 to the generated makefile to reveal flags and commands ...Michael Büsch2011-02-051-0/+2
* cmake: Remove -O3 from release CFLAGS. Honor the OpenWRT -Os flag instead.Michael Büsch2011-02-051-0/+2
* add a template for cmake packagesFelix Fietkau2011-01-311-0/+33
#003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.sufficientlysecure.keychain.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.FixedDrawerLayout;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;

public abstract class DrawerActivity extends BaseActivity {
    private FixedDrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;

    private CharSequence mDrawerTitle;
    private CharSequence mTitle;
    private boolean mIsDrawerLocked = false;

    private Class mSelectedItem;

    private static final int MENU_ID_PREFERENCE = 222;
    private static final int MENU_ID_HELP = 223;

    protected void deactivateDrawerNavigation() {
        ((DrawerLayout) findViewById(R.id.drawer_layout)).setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }

    protected void activateDrawerNavigation(Bundle savedInstanceState) {
        mDrawerTitle = getString(R.string.app_name);
        mDrawerLayout = (FixedDrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        ViewGroup viewGroup = (ViewGroup) findViewById(R.id.content_frame);
        int leftMarginLoaded = ((ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams()).leftMargin;
        int leftMarginInTablets = (int) getResources().getDimension(R.dimen.drawer_size);
        int errorInMarginAllowed = 5;

        // if the left margin of the loaded layout is close to the
        // one used in tablets then set drawer as open and locked
        if (Math.abs(leftMarginLoaded - leftMarginInTablets) < errorInMarginAllowed) {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerList);
            mDrawerLayout.setScrimColor(Color.TRANSPARENT);
            mIsDrawerLocked = true;
        } else {
            // set a custom shadow that overlays the main content when the drawer opens
            mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
            mIsDrawerLocked = false;
        }

        NavItem mItemIconTexts[] = new NavItem[]{
                new NavItem(R.drawable.ic_action_accounts, getString(R.string.nav_keys)),
                new NavItem(R.drawable.ic_action_secure, getString(R.string.nav_encrypt_text)),
                new NavItem(R.drawable.ic_action_secure, getString(R.string.nav_encrypt_files)),
                new NavItem(R.drawable.ic_action_not_secure, getString(R.string.nav_decrypt)),
                new NavItem(R.drawable.ic_action_view_as_list, getString(R.string.nav_apps))};

        mDrawerList.setAdapter(new NavigationDrawerAdapter(this, R.layout.drawer_list_item,
                mItemIconTexts));

        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

        // enable ActionBar app icon to behave as action to toggle nav drawer
        // if the drawer is not locked
        if (!mIsDrawerLocked) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
        }

        // ActionBarDrawerToggle ties together the the proper interactions
        // between the sliding drawer and the action bar app icon
        mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
                mDrawerLayout, /* DrawerLayout object */
                R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
                R.string.drawer_open, /* "open drawer" description for accessibility */
                R.string.drawer_close /* "close drawer" description for accessibility */
        ) {
            public void onDrawerClosed(View view) {
                getSupportActionBar().setTitle(mTitle);

                callIntentForDrawerItem(mSelectedItem);
            }

            public void onDrawerOpened(View drawerView) {
                mTitle = getSupportActionBar().getTitle();
                getSupportActionBar().setTitle(mDrawerTitle);
                // creates call to onPrepareOptionsMenu()
                supportInvalidateOptionsMenu();
            }
        };

        if (!mIsDrawerLocked) {
            mDrawerLayout.setDrawerListener(mDrawerToggle);
        } else {
            // If the drawer is locked open make it un-focusable
            // so that it doesn't consume all the Back button presses
            mDrawerLayout.setFocusableInTouchMode(false);
        }
    }

    /**
     * Uses startActivity to call the Intent of the given class
     *
     * @param drawerItem the class of the drawer item you want to load. Based on Constants.DrawerItems.*
     */
    public void callIntentForDrawerItem(Class drawerItem) {
        // creates call to onPrepareOptionsMenu()
        supportInvalidateOptionsMenu();

        // call intent activity if selected
        if (drawerItem != null) {
            finish();
            overridePendingTransition(0, 0);

            Intent intent = new Intent(this, drawerItem);
            startActivity(intent);

            // disable animation of activity start
            overridePendingTransition(0, 0);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (mDrawerToggle == null) {
            return super.onCreateOptionsMenu(menu);
        }

        menu.add(42, MENU_ID_PREFERENCE, 100, R.string.menu_preferences);
        menu.add(42, MENU_ID_HELP, 101, R.string.menu_help);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (mDrawerToggle == null) {
            return super.onOptionsItemSelected(item);
        }

        // The action bar home/up action should open or close the drawer.
        // ActionBarDrawerToggle will take care of this.
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }

        switch (item.getItemId()) {
            case MENU_ID_PREFERENCE: {
                Intent intent = new Intent(this, SettingsActivity.class);
                startActivity(intent);
                return true;
            }
            case MENU_ID_HELP: {
                Intent intent = new Intent(this, HelpActivity.class);
                startActivity(intent);
                return true;
            }
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    /**
     * The click listener for ListView in the navigation drawer
     */
    private class DrawerItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    }

    private void selectItem(int position) {
        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        // set selected class
        mSelectedItem = Constants.DrawerItems.ARRAY[position];

        // setTitle(mDrawerTitles[position]);
        // If drawer isn't locked just close the drawer and
        // it will move to the selected item by itself (via drawer toggle listener)
        if (!mIsDrawerLocked) {
            mDrawerLayout.closeDrawer(mDrawerList);
            // else move to the selected item yourself
        } else {
            callIntentForDrawerItem(mSelectedItem);
        }
    }

    /**
     * When using the ActionBarDrawerToggle, you must call it during onPostCreate() and
     * onConfigurationChanged()...
     */
    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        if (mDrawerToggle != null) {
            mDrawerToggle.syncState();
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggles
        if (mDrawerToggle != null) {
            mDrawerToggle.onConfigurationChanged(newConfig);
        }
    }

    private class NavItem {
        public int icon; // res-id
        public String title;

        /**
         * NavItem constructor
         *
         * @param icon  The icons resource-id
         * @param title The title of the menu entry
         */
        public NavItem(int icon, String title) {
            super();
            this.icon = icon;
            this.title = title;
        }
    }

    private class NavigationDrawerAdapter extends ArrayAdapter<NavItem> {
        Context mContext;
        int mLayoutResourceId;
        NavItem mData[] = null;

        public NavigationDrawerAdapter(Context context, int layoutResourceId, NavItem[] data) {
            super(context, layoutResourceId, data);
            this.mLayoutResourceId = layoutResourceId;
            this.mContext = context;
            this.mData = data;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            NavItemHolder holder;

            if (row == null) {
                LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
                row = inflater.inflate(mLayoutResourceId, parent, false);

                holder = new NavItemHolder();
                holder.mImg = (ImageView) row.findViewById(R.id.drawer_item_icon);
                holder.mTxtTitle = (TextView) row.findViewById(R.id.drawer_item_text);

                row.setTag(holder);
            } else {
                holder = (NavItemHolder) row.getTag();
            }

            NavItem item = mData[position];
            holder.mTxtTitle.setText(item.title);
            holder.mImg.setImageResource(item.icon);

            return row;
        }

    }

    static class NavItemHolder {
        ImageView mImg;
        TextView mTxtTitle;
    }

}