Example usage for android.app ActionBar setDisplayHomeAsUpEnabled

List of usage examples for android.app ActionBar setDisplayHomeAsUpEnabled

Introduction

In this page you can find the example usage for android.app ActionBar setDisplayHomeAsUpEnabled.

Prototype

public abstract void setDisplayHomeAsUpEnabled(boolean showHomeAsUp);

Source Link

Document

Set whether home should be displayed as an "up" affordance.

Usage

From source file:com.android.settings.HWSettings.java

protected void setActionBarStyle() {
    ActionBar actionBar = getActionBar();
    if (actionBar == null) {
        return;/*from  w  w  w. jav  a2 s .  c  o  m*/
    }
    if (this.toString().contains("SubSettings")) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
        actionBar.setDisplayHomeAsUpEnabled(true);
    } else {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP ^ ActionBar.DISPLAY_HOME_AS_UP,
                ActionBar.DISPLAY_HOME_AS_UP);
        actionBar.setDisplayHomeAsUpEnabled(false);
    }
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void handleIntent() {
    if (!m_app.isAuthenticated()) {
        Log.v(TAG, "handleIntent: not authenticated");
        startLogin();//from www  . j a v  a2  s. c o m
        return;
    }
    if (!m_app.initialSyncDone()) {
        m_sync_dialog = new ProgressDialog(this, m_app.getActiveTheme());
        m_sync_dialog.setIndeterminate(true);
        m_sync_dialog.setMessage("Initial Dropbox sync in progress, please wait....");
        m_sync_dialog.setCancelable(false);
        m_sync_dialog.show();
    } else if (m_sync_dialog != null) {
        m_sync_dialog.cancel();
    }

    mFilter = new ActiveFilter();

    m_leftDrawerList = (ListView) findViewById(R.id.left_drawer);
    m_rightDrawerList = (ListView) findViewById(R.id.right_drawer_list);

    m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    // Set the list's click listener
    m_leftDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    if (m_drawerLayout != null) {
        m_drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
                m_drawerLayout, /* DrawerLayout object */
                R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
                R.string.changelist, /* "open drawer" description */
                R.string.app_label /* "close drawer" description */
        ) {

            /**
             * Called when a drawer has settled in a completely closed
             * state.
             */
            public void onDrawerClosed(View view) {
                // setTitle(R.string.app_label);
            }

            /** Called when a drawer has settled in a completely open state. */
            public void onDrawerOpened(View drawerView) {
                // setTitle(R.string.changelist);
            }
        };

        // Set the drawer toggle as the DrawerListener
        m_drawerLayout.setDrawerListener(m_drawerToggle);
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeButtonEnabled(true);
        }
        m_drawerToggle.syncState();
    }

    // Show search or filter results
    Intent intent = getIntent();
    if (Constants.INTENT_START_FILTER.equals(intent.getAction())) {
        mFilter.initFromIntent(intent);
        Log.v(TAG, "handleIntent: launched with filter" + mFilter);
        Log.v(TAG, "handleIntent: saving filter in prefs");
        mFilter.saveInPrefs(TodoApplication.getPrefs());
    } else {
        // Set previous filters and sort
        Log.v(TAG, "handleIntent: from m_prefs state");
        mFilter.initFromPrefs(TodoApplication.getPrefs());
    }

    // Initialize Adapter
    if (m_adapter == null) {
        m_adapter = new TaskAdapter(getLayoutInflater());
    }
    m_adapter.setFilteredTasks();

    getListView().setAdapter(this.m_adapter);

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    lv.setMultiChoiceModeListener(new ActionBarListener());
    lv.setClickable(true);
    lv.setOnItemClickListener(this);
    // If we were started with a selected task,
    // select it now and clear it from the intent
    String selectedTask = intent.getStringExtra(Constants.INTENT_SELECTED_TASK);
    if (!Strings.isEmptyOrNull(selectedTask)) {
        String[] parts = selectedTask.split(":", 2);
        setSelectedTask(Integer.valueOf(parts[0]), parts[1]);
        intent.removeExtra(Constants.INTENT_SELECTED_TASK);
        setIntent(intent);
    } else {
        // Set the adapter for the list view
        updateDrawers();
    }
    if (m_savedInstanceState != null) {
        ArrayList<String> selection = m_savedInstanceState.getStringArrayList("selection");
        int position = m_savedInstanceState.getInt("position");
        if (selection != null) {
            for (String selected : selection) {
                String[] parts = selected.split(":", 2);
                setSelectedTask(Integer.valueOf(parts[0]), parts[1]);
            }
        }
        lv.setSelectionFromTop(position, 0);
    }
}

From source file:org.floens.chan.ui.activity.BoardActivity.java

private void updateActionBarStateCallback() {
    final ActionBar actionBar = getActionBar();

    if (threadPane.isSlideable()) {
        if (threadPane.isOpen()) {
            int index = getBoardIndexNavigator(boardLoadable.board);

            if (index >= 0) {
                //                    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
                setActionBarListMode();//ww  w. ja v a 2 s. co m
                actionBar.setTitle("");
            } else {
                actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
                String niceTitle = ChanApplication.getBoardManager().getBoardKey(boardLoadable.board);
                if (niceTitle == null) {
                    actionBar.setTitle("/" + boardLoadable.board + "/");
                } else {
                    actionBar.setTitle(niceTitle);
                }
            }

            actionBar.setHomeButtonEnabled(true);
            pinDrawerListener.setDrawerIndicatorEnabled(true);

            if (boardLoadable.isBoardMode())
                setShareUrl(ChanUrls.getBoardUrlDesktop(boardLoadable.board));
        } else {
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
            actionBar.setTitle(threadLoadable.title);
            pinDrawerListener.setDrawerIndicatorEnabled(false);

            if (threadLoadable.isThreadMode())
                setShareUrl(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no));
        }

        actionBar.setDisplayHomeAsUpEnabled(true);
    } else {
        setActionBarListMode();
        //            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        pinDrawerListener.setDrawerIndicatorEnabled(true);
        actionBar.setTitle(threadLoadable.title);

        actionBar.setDisplayHomeAsUpEnabled(true);

        if (threadLoadable.isThreadMode())
            setShareUrl(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no));
    }

    actionBar.setDisplayShowTitleEnabled(true);

    invalidateOptionsMenu();
}

From source file:org.floens.chan.ui.activity.ChanActivity.java

private void updateActionBarStateCallback() {
    final ActionBar actionBar = getActionBar();

    if (threadPane.isSlideable()) {
        if (threadPane.isOpen()) {
            actionBar.setDisplayShowCustomEnabled(true);
            spinnerAdapter.setBoard(boardLoadable.board);
            actionBar.setTitle("");
            pinDrawerListener.setDrawerIndicatorEnabled(true);

            if (boardLoadable.isBoardMode()) {
                setShareUrl(ChanUrls.getBoardUrlDesktop(boardLoadable.board));
            } else if (boardLoadable.isCatalogMode()) {
                setShareUrl(ChanUrls.getCatalogUrlDesktop(boardLoadable.board));
            }//  w  ww . j  a v a2  s  .c o  m
        } else {
            actionBar.setDisplayShowCustomEnabled(false);
            actionBar.setTitle(threadLoadable.title);
            pinDrawerListener.setDrawerIndicatorEnabled(false);

            if (threadLoadable.isThreadMode())
                setShareUrl(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no));
        }
    } else {
        actionBar.setDisplayShowCustomEnabled(true);
        pinDrawerListener.setDrawerIndicatorEnabled(true);
        actionBar.setTitle(threadLoadable.title);

        if (threadLoadable.isThreadMode()) {
            setShareUrl(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no));
        }
    }

    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);

    invalidateOptionsMenu();
}

From source file:org.bohrmeista.chan.ui.activity.BoardActivity.java

private void updateActionBarStateCallback() {
    final ActionBar actionBar = getActionBar();

    if (threadPane.isSlideable()) {
        if (threadPane.isOpen()) {
            actionBar.setDisplayShowCustomEnabled(true);
            if (ChanApplication.getBoardManager().getBoardExists(boardLoadable.board)) {
                spinnerAdapter.setCustomBoard(null);
            } else {
                spinnerAdapter.setCustomBoard(boardLoadable.board);
            }// w  ww  .ja v  a 2s .c  o m

            spinnerAdapter.setBoard(boardLoadable.board);

            actionBar.setTitle("");
            pinDrawerListener.setDrawerIndicatorEnabled(true);

            if (boardLoadable.isBoardMode()) {
                setShareUrl(ChanUrls.getBoardUrlDesktop(boardLoadable.board));
            } else if (boardLoadable.isCatalogMode()) {
                setShareUrl(ChanUrls.getCatalogUrlDesktop(boardLoadable.board));
            }
        } else {
            actionBar.setDisplayShowCustomEnabled(false);
            actionBar.setTitle(threadLoadable.title);
            pinDrawerListener.setDrawerIndicatorEnabled(false);

            if (threadLoadable.isThreadMode())
                setShareUrl(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no));
        }
    } else {
        actionBar.setDisplayShowCustomEnabled(true);
        pinDrawerListener.setDrawerIndicatorEnabled(true);
        actionBar.setTitle(threadLoadable.title);

        if (threadLoadable.isThreadMode()) {
            setShareUrl(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no));
        }
    }

    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);

    invalidateOptionsMenu();
}

From source file:com.polychrom.cordova.ActionBarPlugin.java

@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    if (!plugin_actions.contains(action)) {
        return false;
    }/*from  w w w . ja v a2s  .  c om*/

    final Activity ctx = (Activity) cordova;

    if ("isAvailable".equals(action)) {
        JSONObject result = new JSONObject();
        result.put("value", ctx.getWindow().hasFeature(Window.FEATURE_ACTION_BAR));
        callbackContext.success(result);
        return true;
    }

    final ActionBar bar = ctx.getActionBar();
    if (bar == null) {
        Window window = ctx.getWindow();
        if (!window.hasFeature(Window.FEATURE_ACTION_BAR)) {
            callbackContext
                    .error("ActionBar feature not available, Window.FEATURE_ACTION_BAR must be enabled!");
        } else {
            callbackContext.error("Failed to get ActionBar");
        }

        return true;
    }

    if (menu == null) {
        callbackContext.error("Options menu not initialised");
        return true;
    }

    final StringBuffer error = new StringBuffer();
    JSONObject result = new JSONObject();

    if ("isShowing".equals(action)) {
        result.put("value", bar.isShowing());
    } else if ("getHeight".equals(action)) {
        result.put("value", bar.getHeight());
    } else if ("getDisplayOptions".equals(action)) {
        result.put("value", bar.getDisplayOptions());
    } else if ("getNavigationMode".equals(action)) {
        result.put("value", bar.getNavigationMode());
    } else if ("getSelectedNavigationItem".equals(action)) {
        result.put("value", bar.getSelectedNavigationIndex());
    } else if ("getSubtitle".equals(action)) {
        result.put("value", bar.getSubtitle());
    } else if ("getTitle".equals(action)) {
        result.put("value", bar.getTitle());
    } else {
        try {
            JSONException exception = new Runnable() {
                public JSONException exception = null;

                public void run() {
                    try {
                        // This is a bit of a hack (should be specific to the request, not global)
                        bases = new String[] { removeFilename(webView.getOriginalUrl()),
                                removeFilename(webView.getUrl()) };

                        if ("show".equals(action)) {
                            bar.show();
                        } else if ("hide".equals(action)) {
                            bar.hide();
                        } else if ("setMenu".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            menu_definition = args.getJSONArray(0);

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                ctx.invalidateOptionsMenu();
                            }
                        } else if ("setTabs".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            bar.removeAllTabs();
                            tab_callbacks.clear();

                            if (!buildTabs(bar, args.getJSONArray(0))) {
                                error.append("Invalid tab bar definition");
                            }
                        } else if ("setDisplayHomeAsUpEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHomeAsUp can not be null");
                                return;
                            }

                            bar.setDisplayHomeAsUpEnabled(args.getBoolean(0));
                        } else if ("setDisplayOptions".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("options can not be null");
                                return;
                            }

                            final int options = args.getInt(0);
                            bar.setDisplayOptions(options);
                        } else if ("setDisplayShowHomeEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHome can not be null");
                                return;
                            }

                            bar.setDisplayShowHomeEnabled(args.getBoolean(0));
                        } else if ("setDisplayShowTitleEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showTitle can not be null");
                                return;
                            }

                            bar.setDisplayShowTitleEnabled(args.getBoolean(0));
                        } else if ("setDisplayUseLogoEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("useLogo can not be null");
                                return;
                            }

                            bar.setDisplayUseLogoEnabled(args.getBoolean(0));
                        } else if ("setHomeButtonEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("enabled can not be null");
                                return;
                            }

                            bar.setHomeButtonEnabled(args.getBoolean(0));
                        } else if ("setIcon".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("icon can not be null");
                                return;
                            }

                            Drawable drawable = getDrawableForURI(args.getString(0));
                            bar.setIcon(drawable);
                        } else if ("setListNavigation".equals(action)) {
                            JSONArray items = null;
                            if (args.isNull(0) == false) {
                                items = args.getJSONArray(0);
                            }

                            navigation_adapter.setItems(items);
                            bar.setListNavigationCallbacks(navigation_adapter, navigation_listener);
                        } else if ("setLogo".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("logo can not be null");
                                return;
                            }

                            Drawable drawable = getDrawableForURI(args.getString(0));
                            bar.setLogo(drawable);
                        } else if ("setNavigationMode".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("mode can not be null");
                                return;
                            }

                            final int mode = args.getInt(0);
                            bar.setNavigationMode(mode);
                        } else if ("setSelectedNavigationItem".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("position can not be null");
                                return;
                            }

                            bar.setSelectedNavigationItem(args.getInt(0));
                        } else if ("setSubtitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("subtitle can not be null");
                                return;
                            }

                            bar.setSubtitle(args.getString(0));
                        } else if ("setTitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("title can not be null");
                                return;
                            }

                            bar.setTitle(args.getString(0));
                        }
                    } catch (JSONException e) {
                        exception = e;
                    } finally {
                        synchronized (this) {
                            this.notify();
                        }
                    }
                }

                // Run task synchronously
                {
                    synchronized (this) {
                        ctx.runOnUiThread(this);
                        this.wait();
                    }
                }
            }.exception;

            if (exception != null) {
                throw exception;
            }
        } catch (InterruptedException e) {
            error.append("Function interrupted on UI thread");
        }
    }

    if (error.length() == 0) {
        if (result.length() > 0) {
            callbackContext.success(result);
        } else {
            callbackContext.success();
        }
    } else {
        callbackContext.error(error.toString());
    }

    return true;
}

From source file:com.native5.plugins.ActionBarPlugin.java

@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    if (!plugin_actions.contains(action)) {
        return false;
    }//from   ww w  .  j  av a2  s  . c  o m

    final Activity ctx = (Activity) cordova;

    if ("isAvailable".equals(action)) {
        JSONObject result = new JSONObject();
        result.put("value", ctx.getWindow().hasFeature(Window.FEATURE_ACTION_BAR));
        callbackContext.success(result);
        return true;
    }

    final ActionBar bar = ctx.getActionBar();
    if (bar == null) {
        Window window = ctx.getWindow();
        if (!window.hasFeature(Window.FEATURE_ACTION_BAR)) {
            callbackContext
                    .error("ActionBar feature not available, Window.FEATURE_ACTION_BAR must be enabled!");
        } else {
            callbackContext.error("Failed to get ActionBar");
        }

        return true;
    }

    if (menu == null) {
        callbackContext.error("Options menu not initialised");
        return true;
    }

    final StringBuffer error = new StringBuffer();
    JSONObject result = new JSONObject();

    if ("isShowing".equals(action)) {
        result.put("value", bar.isShowing());
    } else if ("getHeight".equals(action)) {
        result.put("value", bar.getHeight());
    } else if ("getDisplayOptions".equals(action)) {
        result.put("value", bar.getDisplayOptions());
    } else if ("getNavigationMode".equals(action)) {
        result.put("value", bar.getNavigationMode());
    } else if ("getSelectedNavigationItem".equals(action)) {
        result.put("value", bar.getSelectedNavigationIndex());
    } else if ("getSubtitle".equals(action)) {
        result.put("value", bar.getSubtitle());
    } else if ("getTitle".equals(action)) {
        result.put("value", bar.getTitle());
    } else {
        try {
            JSONException exception = new Runnable() {
                public JSONException exception = null;

                public void run() {
                    try {
                        // This is a bit of a hack (should be specific to the request, not global)
                        bases = new String[] { removeFilename(webView.getOriginalUrl()),
                                removeFilename(webView.getUrl()) };

                        if ("show".equals(action)) {
                            LOG.d("native5-action-bar", "Showing Action Bar");
                            bar.show();
                        } else if ("hide".equals(action)) {
                            bar.hide();
                        } else if ("setMenu".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            menu_definition = args.getJSONArray(0);

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                ctx.invalidateOptionsMenu();
                            }
                        } else if ("setTabs".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            bar.removeAllTabs();
                            tab_callbacks.clear();

                            if (!buildTabs(bar, args.getJSONArray(0))) {
                                error.append("Invalid tab bar definition");
                            }
                        } else if ("setDisplayHomeAsUpEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHomeAsUp can not be null");
                                return;
                            }

                            bar.setDisplayHomeAsUpEnabled(args.getBoolean(0));
                        } else if ("setDisplayOptions".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("options can not be null");
                                return;
                            }

                            final int options = args.getInt(0);
                            bar.setDisplayOptions(options);
                        } else if ("setDisplayShowHomeEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHome can not be null");
                                return;
                            }

                            bar.setDisplayShowHomeEnabled(args.getBoolean(0));
                        } else if ("setDisplayShowTitleEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showTitle can not be null");
                                return;
                            }

                            bar.setDisplayShowTitleEnabled(args.getBoolean(0));
                        } else if ("setDisplayUseLogoEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("useLogo can not be null");
                                return;
                            }

                            bar.setDisplayUseLogoEnabled(args.getBoolean(0));
                        } else if ("setHomeButtonEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("enabled can not be null");
                                return;
                            }

                            bar.setHomeButtonEnabled(args.getBoolean(0));
                        } else if ("setIcon".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("icon can not be null");
                                return;
                            }

                            Drawable drawable = getDrawableForURI(args.getString(0));
                            bar.setIcon(drawable);
                        } else if ("setListNavigation".equals(action)) {
                            JSONArray items = null;
                            if (args.isNull(0) == false) {
                                items = args.getJSONArray(0);
                            }

                            navigation_adapter.setItems(items);
                            bar.setListNavigationCallbacks(navigation_adapter, navigation_listener);
                        } else if ("setLogo".equals(action)) {
                            String uri = args.getString(0);
                            if (args.isNull(0)) {
                                error.append("logo can not be null");
                                return;
                            }

                            //                        try {
                            //                           InputStream ims = ctx.getAssets().open(uri);
                            Drawable drawable = getDrawableForURI(uri);
                            //                                 Drawable.createFromStream(ims, null);
                            bar.setLogo(drawable);
                            bar.setBackgroundDrawable(getDrawableForURI("images/logo-bg.png"));
                            //                        } catch (IOException e) {
                            //                           e.printStackTrace();
                            //                        }
                        } else if ("setNavigationMode".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("mode can not be null");
                                return;
                            }

                            final int mode = args.getInt(0);
                            bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
                        } else if ("setSelectedNavigationItem".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("position can not be null");
                                return;
                            }
                            bar.setSelectedNavigationItem(args.getInt(0));
                        } else if ("setSelectedTab".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("position can not be null");
                                return;
                            }
                            LOG.d("setSelectedTab", bar.getTabCount() + "");
                            bar.selectTab(bar.getTabAt(args.getInt(0)));
                        } else if ("setSubtitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("subtitle can not be null");
                                return;
                            }

                            bar.setSubtitle(args.getString(0));
                        } else if ("setTitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("title can not be null");
                                return;
                            }

                            bar.setTitle(args.getString(0));
                        }
                    } catch (JSONException e) {
                        exception = e;
                    } finally {
                        synchronized (this) {
                            this.notify();
                        }
                    }
                }

                // Run task synchronously
                {
                    synchronized (this) {
                        ctx.runOnUiThread(this);
                        this.wait();
                    }
                }
            }.exception;

            if (exception != null) {
                throw exception;
            }
        } catch (InterruptedException e) {
            error.append("Function interrupted on UI thread");
        }
    }

    if (error.length() == 0) {
        if (result.length() > 0) {
            callbackContext.success(result);
        } else {
            callbackContext.success();
        }
    } else {
        callbackContext.error(error.toString());
    }

    return true;
}

From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java

/**
* 
*///from  w ww.j a va 2s.c o m
@Override
public void onCreate(final Bundle savedInstanceState) {
    //Log.i("MAIN ACTIVITY", "onCreate");
    restoreInstance(savedInstanceState);
    super.onCreate(savedInstanceState);
    NetworkInfoCollector.init(this);
    networkInfoCollector = NetworkInfoCollector.getInstance();

    preferencesUpdate();
    setContentView(R.layout.main_with_navigation_drawer);

    if (VIEW_HIERARCHY_SERVER_ENABLED) {
        ViewServer.get(this).addWindow(this);
    }

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setDisplayUseLogoEnabled(true);

    // initialize the navigation drawer with the main menu list adapter:
    String[] mainTitles = getResources().getStringArray(R.array.navigation_main_titles);
    int[] navIcons = new int[] { R.drawable.ic_action_home, R.drawable.ic_action_history,
            R.drawable.ic_action_map, R.drawable.ic_action_stat, R.drawable.ic_action_help,
            R.drawable.ic_action_about, R.drawable.ic_action_settings, R.drawable.ic_action_about };

    MainMenuListAdapter mainMenuAdapter = new MainMenuListAdapter(this, mainTitles, navIcons);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerList = (ListView) findViewById(R.id.left_drawer);
    drawerLayout.setBackgroundResource(R.drawable.ic_drawer);

    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer,
            R.string.page_title_title_page, R.string.page_title_title_page) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            //refreshActionBar(null);
            exitAfterDrawerClose = false;
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    drawerLayout.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (KeyEvent.KEYCODE_BACK == event.getKeyCode() && exitAfterDrawerClose) {
                onBackPressed();
                return true;
            }
            return false;
        }
    });
    drawerLayout.setDrawerListener(drawerToggle);
    drawerList.setAdapter(mainMenuAdapter);
    drawerList.setOnItemClickListener(new OnItemClickListener() {
        final int[] menuIds = new int[] { R.id.action_title_page, R.id.action_history, R.id.action_map,
                R.id.action_stats, R.id.action_help, R.id.action_info, R.id.action_settings,
                R.id.action_netstat, R.id.action_log };

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectMenuItem(menuIds[position]);
            drawerLayout.closeDrawers();
        }
    });

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // Do something against banding effect in gradients
    // Dither flag might mess up on certain devices??
    final Window window = getWindow();
    window.setFormat(PixelFormat.RGBA_8888);
    window.addFlags(WindowManager.LayoutParams.FLAG_DITHER);

    // Setzt Default-Werte, wenn noch keine Werte vorhanden
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    final String uuid = ConfigHelper.getUUID(getApplicationContext());

    fm = getFragmentManager();
    final Fragment fragment = fm.findFragmentById(R.id.fragment_content);
    if (!ConfigHelper.isTCAccepted(this)) {
        if (fragment != null && fm.getBackStackEntryCount() >= 1)
            // clear fragment back stack
            fm.popBackStack(fm.getBackStackEntryAt(0).getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);

        getActionBar().hide();
        setLockNavigationDrawer(true);

        showTermsCheck();
    } else {
        currentMapOptions.put("highlight", uuid);
        if (fragment == null) {
            if (false) // deactivated for si // ! ConfigHelper.isNDTDecisionMade(this))
            {
                showTermsCheck();
                showNdtCheck();
            } else
                initApp(true);
        }
    }

    geoLocation = new MainGeoLocation(getApplicationContext());

    mNetworkStateChangedFilter = new IntentFilter();
    mNetworkStateChangedFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);

    mNetworkStateIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(final Context context, final Intent intent) {
            if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                final boolean connected = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY,
                        false);
                final boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);

                if (connected) {
                    if (networkInfoCollector != null) {
                        networkInfoCollector.setHasConnectionFromAndroidApi(true);
                    }
                } else {
                    if (networkInfoCollector != null) {
                        networkInfoCollector.setHasConnectionFromAndroidApi(false);
                    }
                }

                Log.i(DEBUG_TAG, "CONNECTED: " + connected + " FAILOVER: " + isFailover);
            }
        }
    };
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

@Override
protected void onStart() {
    super.onStart();
    boolean isSmsEnabled = MmsConfig.isSmsEnabled(this);
    if (isSmsEnabled != mIsSmsEnabled) {
        mIsSmsEnabled = isSmsEnabled;/*from w  ww.j  av a  2s .c  om*/
        invalidateOptionsMenu();
    }

    initFocus();

    // Register a BroadcastReceiver to listen on HTTP I/O process.
    registerReceiver(mHttpProgressReceiver, mHttpProgressFilter);

    registerReceiver(mDelayedSendProgressReceiver, DELAYED_SEND_COUNTDOWN_FILTER);

    // figure out whether we need to show the keyboard or not.
    // if there is draft to be loaded for 'mConversation', we'll show the keyboard;
    // otherwise we hide the keyboard. In any event, delay loading
    // message history and draft (controlled by DEFER_LOADING_MESSAGES_AND_DRAFT).
    int mode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;

    if (DraftCache.getInstance().hasDraft(mConversation.getThreadId())) {
        mode |= WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
    } else if (mConversation.getThreadId() <= 0) {
        // For composing a new message, bring up the softkeyboard so the user can
        // immediately enter recipients. This call won't do anything on devices with
        // a hard keyboard.
        mode |= WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
    } else {
        mode |= WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN;
    }

    getWindow().setSoftInputMode(mode);

    // reset mMessagesAndDraftLoaded
    mMessagesAndDraftLoaded = false;
    long threadId = mWorkingMessage.getConversation().getThreadId();
    // Same recipient for ForwardMms will not load draft
    if (MessageUtils.sSameRecipientList.contains(threadId)) {
        mShouldLoadDraft = false;
    }

    if (!DEFER_LOADING_MESSAGES_AND_DRAFT) {
        loadMessagesAndDraft(1);
    } else {
        // HACK: force load messages+draft after max delay, if it's not already loaded.
        // this is to work around when coming out of sleep mode. WindowManager behaves
        // strangely and hides the keyboard when it should be shown, or sometimes initially
        // shows it when we want to hide it. In that case, we never get the onSizeChanged()
        // callback w/ keyboard shown, so we wouldn't know to load the messages+draft.
        mHandler.postDelayed(new Runnable() {
            public void run() {
                loadMessagesAndDraft(2);
            }
        }, LOADING_MESSAGES_AND_DRAFT_MAX_DELAY_MS);
    }

    // Update the fasttrack info in case any of the recipients' contact info changed
    // while we were paused. This can happen, for example, if a user changes or adds
    // an avatar associated with a contact.
    mWorkingMessage.syncWorkingRecipients();

    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        log("update title, mConversation=" + mConversation.toString());
    }

    updateTitle(mConversation.getRecipients());

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}