Example usage for android.view MenuItem setActionView

List of usage examples for android.view MenuItem setActionView

Introduction

In this page you can find the example usage for android.view MenuItem setActionView.

Prototype

public MenuItem setActionView(@LayoutRes int resId);

Source Link

Document

Set an action view for this menu item.

Usage

From source file:com.echlabsw.android.drawertab.MainActivity.java

private void dismissProgressLoading() {
    SwipeRefreshLayout swipe = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    if (swipe != null) {
        swipe.setRefreshing(false);//w  w w .j  a va2s .  c  o  m
    }
    if (mOptionsMenu != null) {
        MenuItem item = mOptionsMenu.findItem(R.id.action_refresh);
        if (item != null) {
            item.setActionView(null);
        }
    }
}

From source file:securityantennas.viwer.android.mogaworks.securityantenna.FeedListFragment.java

/**
 * Respond to user gestures on the ActionBar.
 */// w  ww. j a v  a 2 s. c om
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // If the user clicks the "Refresh" button.
    case R.id.menu_refresh:
        SyncUtils.TriggerRefresh();
        item.setActionView(null);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.echlabsw.android.drawertab.MainActivity.java

private void showProgressLoading() {
    if (mOptionsMenu != null) {
        final MenuItem item = mOptionsMenu.findItem(R.id.action_refresh);
        if (item != null) {
            item.setActionView(R.layout.actionbar_indeterminate_progress);
        }/*from ww  w  .j  a va 2 s  .c o m*/
    }
}

From source file:fr.cph.chicago.activity.BusActivity.java

@Override
public final boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    this.mMenu = menu;

    // Inflate menu with no search
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_no_search, menu);

    // Modify action bar title
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle("Bus");

    // Load top bar animation
    MenuItem refreshMenuItem = menu.findItem(R.id.action_refresh);
    refreshMenuItem.setActionView(R.layout.progressbar);
    refreshMenuItem.expandActionView();/*w  w  w. j a  v a 2 s.  com*/

    return true;
}

From source file:be.brunoparmentier.openbikesharing.app.activities.StationsListActivity.java

private void setRefreshActionButtonState(final boolean refreshing) {
    if (optionsMenu != null) {
        final MenuItem refreshItem = optionsMenu.findItem(R.id.action_refresh);
        if (refreshItem != null) {
            if (refreshing) {
                refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
                refreshItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            } else {
                refreshItem.setActionView(null);
                refreshItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            }/*from w  w  w.j  a v a 2 s. c o m*/
        }
    }
}

From source file:com.dogar.geodesic.map.MainActivity.java

private void setRefreshActionButtonState(boolean refreshing) {
    if (mOptionsMenu == null) {
        return;// ww  w. j a  va  2 s .com
    }
    final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
    if (refreshItem != null) {
        if (refreshing) {
            refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
        } else {
            refreshItem.setActionView(null);
            GMFragment.clearMarkersAndDrawNew();
        }
    }
}

From source file:nyc.c4q.jordansmith.finefree.ActivityMain.java

public void addCarstoNav() {
    final Menu menu = navDrawerView.getMenu();
    if (submenu == null) {
        submenu = menu.addSubMenu("Your Cars");
        for (int i = 0; i < cars.size(); i++) {
            submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString())
                    .setIcon(R.drawable.ic_car_black_36dp);

            System.out.println(submenu.getItem(i).getItemId() + " " + submenu.getItem(i).getTitle());

            final MenuItem item = submenu.getItem(i);
            Button button = new Button(this);
            button.setText("Remove");
            button.setTextColor(ContextCompat.getColor(this, R.color.white));
            item.setActionView(button);
            button.setBackground(getDrawable(R.drawable.button_shape));
            item.getActionView().setOnClickListener(new View.OnClickListener() {
                @Override/*from w  ww. java 2s . co m*/
                public void onClick(View view) {
                    new AlertDialog.Builder(ActivityMain.this).setIcon(android.R.drawable.ic_dialog_alert)
                            .setTitle("Delete Car").setMessage("Are you sure you want to remove car?")
                            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    System.out.println("CLICKED " + item.getTitle());
                                    cupboard().withDatabase(db).delete(Car.class, "name = ?",
                                            (String) item.getTitle());

                                    updateSubmenu();
                                }
                            }).setNegativeButton("Cancel", null).show();

                }
            });
        }
    } else {
        //            for (int i = 0; i < cars.size(); i++) {
        //                submenu.clear();
        //                submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString())
        //                        .setIcon(R.drawable.ic_car_black_36dp);
        //
        //                final MenuItem item = submenu.getItem(i);
        //                Button button = new Button(this);
        //                button.setText("Remove");
        //                item.setActionView(button);
        //                item.getActionView().setOnClickListener(new View.OnClickListener() {
        //                    @Override
        //                    public void onClick(View view) {
        //
        //                        System.out.println("CLICKED " + item.getTitle());
        //                        cupboard().withDatabase(db).delete(Car.class, "name = ?", (String) item.getTitle());
        //
        //                        updateSubmenu();
        //                    }
        //                });
        //
        //            }
        setupCarMenu();

    }
}

From source file:wittgroupinc.com.authenticatordemo.fragments.EntryListFragment.java

/**
 * Set the state of the Refresh button. If a sync is active, turn on the ProgressBar widget.
 * Otherwise, turn it off./* w w w. ja  v a  2s .  com*/
 *
 * @param refreshing True if an active sync is occuring, false otherwise
 */
public void setRefreshActionButtonState(boolean refreshing) {
    if (mOptionsMenu == null) {
        return;
    }

    final MenuItem refreshItem = mOptionsMenu.findItem(R.id.action_refresh);
    if (refreshItem != null) {
        if (refreshing) {
            refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
        } else {
            refreshItem.setActionView(null);
        }
    }
}

From source file:it.rignanese.leo.slimfacebook.MainActivity.java

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

    // setup the sharedPreferences
    savedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    //setup the theme
    //int savedThemeId = Integer.parseInt(savedPreferences.getString("pref_key_theme8", "2131361965"));//get the last saved theme id
    //setTheme(savedThemeId);//this refresh the theme if necessary
    // TODO fix the change of status bar

    setContentView(R.layout.activity_main);//load the layout

    // setup the refresh layout
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    swipeRefreshLayout.setColorSchemeResources(R.color.officialBlueFacebook, R.color.darkBlueSlimFacebookTheme);// set the colors
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override/*from   www.j  a va 2s  .c o  m*/
        public void onRefresh() {
            refreshPage();//reload the page
            swipeRefresh = true;
        }
    });

    // setup the webView
    webViewFacebook = (WebView) findViewById(R.id.webView);
    setUpWebViewDefaults(webViewFacebook);//set the settings

    goHome();//load homepage

    //WebViewClient that is the client callback.
    webViewFacebook.setWebViewClient(new WebViewClient() {//advanced set up

        // when there isn't a connetion
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            String summary = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body><h1 "
                    + "style='text-align:center; padding-top:15%;'>" + getString(R.string.titleNoConnection)
                    + "</h1> <h3 style='text-align:center; padding-top:1%; font-style: italic;'>"
                    + getString(R.string.descriptionNoConnection)
                    + "</h3>  <h5 style='text-align:center; padding-top:80%; opacity: 0.3;'>"
                    + getString(R.string.awards) + "</h5></body></html>";
            webViewFacebook.loadData(summary, "text/html; charset=utf-8", "utf-8");//load a custom html page

            noConnectionError = true;
            swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing
        }

        // when I click in a external link
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url == null || url.contains("facebook.com")) {
                //url is ok
                return false;
            } else {
                if (url.contains("https://scontent")) {
                    //TODO add the possibility to download and share directly

                    Toast.makeText(getApplicationContext(), getString(R.string.downloadOrShareWithBrowser),
                            Toast.LENGTH_LONG).show();
                    //TODO get bitmap from url
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(intent);
                    return true;
                }

                //if the link doesn't contain 'facebook.com', open it using the browser
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            }
        }

        //START management of loading
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            //TODO when I push on messages, open messanger
            //                if(url!=null){
            //                    if (url.contains("soft=messages") || url.contains("facebook.com/messages")) {
            //                        Toast.makeText(getApplicationContext(),"Open Messanger",
            //                                Toast.LENGTH_SHORT).show();
            //                        startActivity(new Intent(getPackageManager().getLaunchIntentForPackage("com.facebook.orca")));//messanger
            //                    }
            //                }

            // show you progress image
            if (!swipeRefresh) {
                final MenuItem refreshItem = optionsMenu.findItem(R.id.refresh);
                refreshItem.setActionView(R.layout.circular_progress_bar);
            }
            swipeRefresh = false;
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // hide your progress image
            final MenuItem refreshItem = optionsMenu.findItem(R.id.refresh);
            refreshItem.setActionView(null);
            super.onPageFinished(view, url);

            swipeRefreshLayout.setRefreshing(false); //when the page is loaded, stop the refreshing
        }
        //END management of loading

    });

    //WebChromeClient for handling all chrome functions.
    webViewFacebook.setWebChromeClient(new WebChromeClient() {
        //to upload files
        //thanks to gauntface
        //https://github.com/GoogleChrome/chromium-webview-samples
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                WebChromeClient.FileChooserParams fileChooserParams) {
            if (mFilePathCallback != null) {
                mFilePathCallback.onReceiveValue(null);
            }
            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getBaseContext().getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                } catch (IOException ex) {
                    // Error occurred while creating the File
                }

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                } else {
                    takePictureIntent = null;
                }
            }

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("image/*");

            Intent[] intentArray;
            if (takePictureIntent != null) {
                intentArray = new Intent[] { takePictureIntent };
            } else {
                intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

            startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            return true;
        }
    });
}

From source file:securityantennas.viwer.android.mogaworks.securityantenna.FeedListFragment.java

/**
 * Set the state of the Refresh button. If a sync is active, turn on the ProgressBar widget.
 * Otherwise, turn it off.//from ww  w  .  j a  v a2  s.c  o  m
 *
 * @param refreshing True if an active sync is occuring, false otherwise
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void setRefreshActionButtonState(boolean refreshing) {
    Log.d("aaaa", "refreshing");
    if (mOptionsMenu == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        Log.d("aaaa", "refreshing:return");
        return;
    }
    Log.d("aaaa", "refreshing:" + refreshing);
    final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
    if (refreshItem != null) {
        if (refreshing) {
            Log.d("aaaa", "refreshing:actionbar_indeterminate_progress:" + refreshing);
            refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
            // refreshItem.setActionView(null);
        } else {
            refreshItem.setActionView(null);
        }
    }
}