List of usage examples for android.app ActionBar setDisplayOptions
public abstract void setDisplayOptions(@DisplayOptions int options);
From source file:com.geotrackin.gpslogger.GpsMainActivity.java
public void SetUpActionBar() { ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.gps_main_views, android.R.layout.simple_spinner_dropdown_item); actionBar.setListNavigationCallbacks(spinnerAdapter, this); //Reload the user's previously selected view f73 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); actionBar.setSelectedNavigationItem(prefs.getInt("dropdownview", 0)); actionBar.setDisplayShowTitleEnabled(true); actionBar.setTitle(""); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(R.layout.actionbar); ImageButton helpButton = (ImageButton) actionBar.getCustomView().findViewById(R.id.imgHelp); helpButton.setOnClickListener(new View.OnClickListener() { @Override/*w ww . j av a2s . c o m*/ public void onClick(View view) { Intent faqtivity = new Intent(getApplicationContext(), Faqtivity.class); startActivity(faqtivity); } }); }
From source file:com.android.gallery3d.v5.filtershow.FilterShowActivity.java
private void loadXML() { setContentView(R.layout.filtershow_activity); ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(LayoutInflater.from(this).inflate(R.layout.filtershow_actionbar, null), new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT)); actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.background_screen))); View v = actionBar.getCustomView(); mEditorCancelButton = v.findViewById(R.id.editor_action_cancel); mEditorCancelButton.setOnClickListener(new View.OnClickListener() { @Override/* w w w .j a va 2 s . com*/ public void onClick(View v) { Fragment fragment = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); Fragment editorFrament = fragment.getChildFragmentManager() .findFragmentByTag(CategoryPanel.FRAGMENT_TAG); if (editorFrament instanceof LewaEditorBaseFragment) { ((LewaEditorBaseFragment) editorFrament).restorePreset(); showDefaultImageView(); } onBackPressed(); } }); mEditorApplyButton = v.findViewById(R.id.editor_action_apply); mEditorApplyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment fragment = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); Fragment editorFrament = fragment.getChildFragmentManager() .findFragmentByTag(CategoryPanel.FRAGMENT_TAG); if (editorFrament instanceof EditorPanel) { ((EditorPanel) editorFrament).apply(); if (((EditorPanel) editorFrament).getEditorId() == R.id.editorCrop) { backToMain(); } if (((EditorPanel) editorFrament).getEditorId() != R.id.editorCrop) { onBackPressed(); } } if (editorFrament instanceof CategoryPanel) { backToMain(); } } }); mResetButton = v.findViewById(R.id.filtershow_reset); mResetButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { resetHistory(); } }); mSaveButton = v.findViewById(R.id.filtershow_done); mSaveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { saveImage(); } }); mReturnButton = (ImageButton) actionBar.getCustomView().findViewById(R.id.filtershow_return); mReturnButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); mImageShow = (ImageShow) findViewById(R.id.imageShow); mImageViews.add(mImageShow); setupEditors(); mEditorPlaceHolder.hide(); mImageShow.attach(); setupStatePanel(); }
From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java
/** * This creates the WebKit. We need all our values initialized by this point. *///ww w . j a v a2s . c om private void assignContentView() { setContentView(R.layout.main_screen); ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO); actionBar.show(); }
From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); int showOption = MenuItem.SHOW_AS_ACTION_IF_ROOM; MenuItem item;//from ww w .j av a2 s .c o m if (currentFragment != ScreenList.WEBKIT) { ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE); actionBar.show(); item = menu.add(Menu.NONE, MENU_FILL_FORM, Menu.NONE, getString(R.string.enter_data_button)); item.setIcon(R.drawable.ic_action_collections_collection).setShowAsAction(showOption); // Using a file for this work now String get = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_GET_BLANK); if (get.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_PULL_FORMS, Menu.NONE, getString(R.string.get_forms)); item.setIcon(R.drawable.ic_action_av_download).setShowAsAction(showOption); item = menu.add(Menu.NONE, MENU_CLOUD_FORMS, Menu.NONE, getString(R.string.get_forms)); item.setIcon(R.drawable.ic_action_cloud).setShowAsAction(showOption); } String send = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_SEND_FINALIZED); if (send.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_PUSH_FORMS, Menu.NONE, getString(R.string.send_data)); item.setIcon(R.drawable.ic_action_av_upload).setShowAsAction(showOption); } String manage = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_MANAGE_FORMS); if (manage.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_MANAGE_FORMS, Menu.NONE, getString(R.string.manage_files)); item.setIcon(R.drawable.trash).setShowAsAction(showOption); } String settings = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_ACCESS_SETTINGS); if (settings.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_PREFERENCES, Menu.NONE, getString(R.string.general_preferences)); item.setIcon(R.drawable.ic_menu_preferences).setShowAsAction(showOption); } item = menu.add(Menu.NONE, MENU_ADMIN_PREFERENCES, Menu.NONE, getString(R.string.admin_preferences)); item.setIcon(R.drawable.ic_action_device_access_accounts).setShowAsAction(showOption); item = menu.add(Menu.NONE, MENU_ABOUT, Menu.NONE, getString(R.string.about)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } else { ActionBar actionBar = getActionBar(); actionBar.hide(); } return true; }
From source file:com.xenon.greenup.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set up the action bar. final ActionBar actionBar = getActionBar(); // Specify that the Home/Up button should not be enabled, since there is no hierarchical parent. actionBar.setHomeButtonEnabled(false); //Set the stacked background otherwise we get the gross dark gray color under the icon BitmapDrawable background = (BitmapDrawable) getResources().getDrawable(R.drawable.bottom_menu); background.setTileModeXY(TileMode.REPEAT, TileMode.MIRROR); actionBar.setStackedBackgroundDrawable(background); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setIcon(R.drawable.bottom_menu); _ViewPager = (ViewPager) findViewById(R.id.pager); mTabsAdapter = new TabsAdapter(this, _ViewPager); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < 3; i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. ActionBar.Tab tabToAdd = actionBar.newTab(); if (i == 0) //Set the home page as active since we'll start there: tabToAdd.setIcon(getActiveIcon(i)); else/* w w w .j a va 2 s . c o m*/ tabToAdd.setIcon(getRegularIcon(i)); mTabsAdapter.addTab(tabToAdd); } //Setting the display to custom will push the action bar to the top //which gives us more real estate actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.show(); Log.i("visible", "" + _ViewPager.VISIBLE); }
From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java
public void setActionBar() { try {/*w w w .j a v a 2 s .c o m*/ com.actionbarsherlock.app.ActionBar actionBar = getSupportActionBar(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); actionBar.setCustomView(R.layout.chatactionbar); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); pic = (ImageView) actionBar.getCustomView().findViewById(R.id.ab_userpic); name = (TextView) actionBar.getCustomView().findViewById(R.id.ab_userName); LinearLayout backfrChat = (LinearLayout) actionBar.getCustomView().findViewById(R.id.ll_backFromChat); tv_userStatus = (TextView) actionBar.getCustomView().findViewById(R.id.ab_userStatus); LinearLayout ll_userprofile = (LinearLayout) actionBar.getCustomView() .findViewById(R.id.ll_calluserProfile); btn_filetransfer = (Button) actionBar.getCustomView().findViewById(R.id.btnattechment); btn_filetransfer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub viewAttechmentPopup(v); } }); backfrChat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub callBack(); } }); ll_userprofile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { callUserProfileActivity(); } }); vv = detailFragment.getView(); bodyInput = (EditText) vv.findViewById(R.id.embedded_text_editor); Fl_Emoticon_Holder = (FrameLayout) vv.findViewById(R.id.fl_emojicons); btn_emoticon_show = (ImageButton) vv.findViewById(R.id.ib_enable_emoticon_frame); String user_number = prefs.getString(stored_chatuserNumber, "No Value"); if (user_number.contains("@")) { String[] nu = user_number.split("@"); nu = nu[0].split(":"); user_number = nu[1]; } supportnum = prefs.getString(stored_supportnumber, ""); String nu = detailFragment.stripNumber(user_number); String fileuri = Environment.getExternalStorageDirectory() + "/R4W/ProfilePic/" + nu + ".png"; Log.d("fileuri", fileuri + " !"); Log.d("supportnum", supportnum); Log.d("nu", nu); if (nu.equals(supportnum)) { pic.setImageResource(R.drawable.roaminglogo); } else { File imageDirectoryprofile = new File(fileuri); if (imageDirectoryprofile.exists()) { pic.setImageURI(Uri.parse(fileuri)); } else { pic.setImageResource(R.drawable.ic_contact_picture_180_holo_light); } } String username = nu; if (dbContacts == null) { dbContacts = new DBContacts(MessageActivity.this); } String nameServer = "", nameContact = ""; dbContacts.openToRead(); Cursor cursor = dbContacts.fetch_contact_from_R4W(nu); if (cursor.getCount() > 0) { cursor.moveToFirst(); nameServer = cursor.getString(5).toString(); nameContact = cursor.getString(2).toString(); cursor.close(); dbContacts.close(); Log.d("nameServer", nameServer + " in"); Log.d("nameContact", nameContact + " in"); if (!nameServer.equals("***no name***")) { username = nameServer; } else { username = nameContact; } name.setText(username); } else { name.setText(nu); } } catch (Exception e) { // TODO: handle exception } }
From source file:at.alladin.rmbt.android.main.RMBTMainActivity.java
/** * *///from w w w. j av a 2 s .c om @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:org.path.episample.android.activities.MainMenuActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); int showOption = MenuItem.SHOW_AS_ACTION_IF_ROOM; MenuItem item;/*w w w . java 2 s. c om*/ if (currentFragment != ScreenList.WEBKIT) { ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE); actionBar.show(); item = menu.add(Menu.NONE, MENU_MAIN_MENU, Menu.NONE, getString(R.string.main_menu)); item.setIcon(R.drawable.ic_action_home).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); //item = menu.add(Menu.NONE, MENU_FILL_FORM, Menu.NONE, getString(R.string.enter_data_button)); //item.setIcon(R.drawable.ic_action_collections_collection).setShowAsAction(showOption); // Using a file for this work now String get = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_GET_BLANK); if (get.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_PULL_FORMS, Menu.NONE, getString(R.string.get_forms)); item.setIcon(R.drawable.ic_action_av_download).setShowAsAction(showOption); //item = menu.add(Menu.NONE, MENU_CLOUD_FORMS, Menu.NONE, getString(R.string.get_forms)); //item.setIcon(R.drawable.ic_action_cloud).setShowAsAction(showOption); } String send = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_SEND_FINALIZED); if (send.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_PUSH_FORMS, Menu.NONE, getString(R.string.send_data)); item.setIcon(R.drawable.ic_action_av_upload).setShowAsAction(showOption); } String manage = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_MANAGE_FORMS); if (manage.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_MANAGE_FORMS, Menu.NONE, getString(R.string.manage_files)); item.setIcon(R.drawable.trash).setShowAsAction(showOption); } String settings = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_ACCESS_SETTINGS); if (settings.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_PREFERENCES, Menu.NONE, getString(R.string.general_preferences)); item.setIcon(R.drawable.ic_menu_preferences).setShowAsAction(showOption); } item = menu.add(Menu.NONE, MENU_ADMIN_PREFERENCES, Menu.NONE, getString(R.string.admin_preferences)); item.setIcon(R.drawable.ic_action_device_access_accounts).setShowAsAction(showOption); String backup = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_BACKUP_CENSUS); if (backup != null && backup.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_BACKUP_CENSUS, Menu.NONE, getString(R.string.backup_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } String restore = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_RESTORE_CENSUS); if (restore != null && restore.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_RESTORE_CENSUS, Menu.NONE, getString(R.string.restore_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } String invalidateCensus = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_INVALIDATE_CENSUS); if (invalidateCensus != null && invalidateCensus.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_MARK_CENSUS_AS_INVALID, Menu.NONE, getString(R.string.invalidate_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } String edit = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_EDIT_CENSUS); if (edit != null && edit.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_EDIT_CENSUS, Menu.NONE, getString(R.string.edit_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } String removeCensus = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_REMOVE_CENSUS); if (removeCensus != null && removeCensus.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_REMOVE_CENSUS, Menu.NONE, getString(R.string.remove_census)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } /*String send_receive_bt = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_SEND_RECEIVE_BLUETOOTH); if (send_receive_bt != null && send_receive_bt.equalsIgnoreCase("true")) { item = menu.add(Menu.NONE, MENU_SEND_REVEIVE_BLUETOOTH, Menu.NONE, getString(R.string.send_receive_bluetooth)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); }*/ item = menu.add(Menu.NONE, MENU_ABOUT, Menu.NONE, getString(R.string.about)); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } else { ActionBar actionBar = getActionBar(); actionBar.hide(); } return true; }
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; }// w w w .j a v a2 s. 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 www .j a v a 2s .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)) { 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; }