List of usage examples for android.app ActionBar setCustomView
public abstract void setCustomView(View view, LayoutParams layoutParams);
From source file:com.fihtdc.smartbracelet.activity.FaceBookSettingActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login_fragment_activity); FragmentManager fragmentManager = getSupportFragmentManager(); userSettingsFragment = (FacebookSettingsFragment) fragmentManager.findFragmentById(R.id.login_fragment); mActionBarCustomView = getLayoutInflater().inflate(R.layout.action_bar_custom, null); final ActionBar bar = getActionBar(); bar.setCustomView(mActionBarCustomView, new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); userSettingsFragment.setSessionStatusCallback(new Session.StatusCallback() { @Override//from w w w . ja v a 2 s. c om public void call(Session session, SessionState state, Exception exception) { Log.d("LoginUsingLoginFragmentActivity", String.format("New session state: %s", state.toString())); } }); mLeft = (ImageView) mActionBarCustomView.findViewById(R.id.left); mTitle = (TextView) mActionBarCustomView.findViewById(R.id.middle); mRight = (ImageView) mActionBarCustomView.findViewById(R.id.right); mLeft.setImageResource(R.drawable.ic_menu_back); mRight.setImageResource(R.drawable.ic_menu_home); mLeft.setOnClickListener(this); mRight.setOnClickListener(this); mTitle.setText(getTitle()); }
From source file:org.jraf.android.bikey.app.ride.edit.RideEditActivity.java
private void setupActionBar() { ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); View customActionBarView = getLayoutInflater().inflate(R.layout.ride_edit_actionbar, null); actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); View btnDone = customActionBarView.findViewById(R.id.actionbar_done); btnDone.setOnClickListener(new OnClickListener() { @Override//from w w w . j ava 2 s . c o m public void onClick(View v) { saveRide(); } }); View btnDiscard = customActionBarView.findViewById(R.id.actionbar_discard); btnDiscard.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); }
From source file:com.klinker.android.twitter.settings.configure_pages.ConfigurePagerActivity.java
public void setUpDoneDiscard() { LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext() .getSystemService(LAYOUT_INFLATER_SERVICE); final View customActionBarView = inflater.inflate(R.layout.actionbar_done_discard, null); TextView doneButton = (TextView) customActionBarView.findViewById(R.id.done); doneButton.setText(getResources().getString(R.string.done_label)); customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() { @Override//from w w w .j a v a 2s.c o m public void onClick(View v) { int currentAccount = sharedPrefs.getInt("current_account", 1); SharedPreferences.Editor editor = sharedPrefs.edit(); editor.putInt("account_" + currentAccount + "_page_1", PageOneFragment.type); editor.putInt("account_" + currentAccount + "_page_2", PageTwoFragment.type); editor.putLong("account_" + currentAccount + "_list_1_long", PageOneFragment.listId); editor.putLong("account_" + currentAccount + "_list_2_long", PageTwoFragment.listId); editor.putString("account_" + currentAccount + "_name_1", PageOneFragment.listName); editor.putString("account_" + currentAccount + "_name_2", PageTwoFragment.listName); editor.commit(); onBackPressed(); } }); customActionBarView.findViewById(R.id.actionbar_discard).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(); } }); // Show the custom action bar view and hide the normal Home icon and title. final ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); }
From source file:com.example.android.donebar.DoneBarActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // BEGIN_INCLUDE (inflate_set_custom_view) // Inflate a "Done/Cancel" custom action bar view. final LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext() .getSystemService(LAYOUT_INFLATER_SERVICE); final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done_cancel, null); customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() { @Override//ww w . ja v a2 s .c o m public void onClick(View v) { // "Done" int id = generateId(); EditText number = (EditText) findViewById(R.id.caller_phone_number); EditText information = (EditText) findViewById(R.id.caller_information); checkAvailability(id, number.getText().toString(), information.getText().toString()); finish(); } }); customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // "Cancel" finish(); } }); // Show the custom action bar view and hide the normal Home icon and title. final ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // END_INCLUDE (inflate_set_custom_view) setContentView(R.layout.activity_done_bar); }
From source file:com.linkedin.android.eventsapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); pager = new ViewPager(this); pager.setId(R.id.pager);/*from w w w . j av a2s . c o m*/ pager.setOffscreenPageLimit(5); setContentView(pager); final ActionBar bar = getActionBar(); View viewActionBar = getLayoutInflater().inflate(R.layout.layout_action_bar, null); TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.actionbar_textview); ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER); textviewTitle.setText("UPCOMING EVENTS"); bar.setCustomView(viewActionBar, params); bar.setDisplayShowCustomEnabled(true); bar.setDisplayShowTitleEnabled(false); bar.setIcon(new ColorDrawable(Color.TRANSPARENT)); bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F15153"))); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mEventTabsAdapter = new com.linkedin.android.eventsapp.EventTabsAdapter(this, pager); SimpleDateFormat ft = new SimpleDateFormat("E dd MMM"); ArrayList<Event> events = EventsManager.getInstance(this).getEvents(); for (Event event : events) { String eventDay = ft.format(new Date(event.getEventDate())); mEventTabsAdapter.addTab(bar.newTab().setText(eventDay), EventFragment.class, event); } }
From source file:com.ternup.caddisfly.activity.SurveyActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setTheme(((MainApp) getApplicationContext()).CurrentTheme); setContentView(R.layout.fragment_survey); // BEGIN_INCLUDE (inflate_set_custom_view) // Inflate a "Done/Cancel" custom action bar view. final LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext() .getSystemService(LAYOUT_INFLATER_SERVICE); final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done_cancel, null, false); final Context context = this; customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() { @Override/*from w w w. j a v a 2 s. c o m*/ public void onClick(View v) { long locationId = saveData(); if (locationId == -1) { mViewPager.setCurrentItem(1, true); AlertUtils.showMessage(context, R.string.incomplete, R.string.incompleteMessage); } else { Intent intent = new Intent(); intent.putExtra(getString(R.string.currentLocationId), locationId); setResult(Activity.RESULT_OK, intent); //todo: change to finished method isCancelled = true; finish(); } } }); customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cancelSurvey(); } }); // Show the custom action bar view and hide the normal Home icon and title. final ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // END_INCLUDE (inflate_set_custom_view) // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.viewpager); mViewPager.setOffscreenPageLimit(6); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { switch (position) { case 1: //mFormFragment.showKeyboard(); break; case 4: mNotesFragment.showKeyboard(); break; default: (new Handler()).postDelayed(new Runnable() { public void run() { ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } }, 300); } } @Override public void onPageScrollStateChanged(int state) { } }); // END_INCLUDE (setup_viewpager) // BEGIN_INCLUDE (setup_slidingTabLayout) // Give the SlidingTabLayout the ViewPager, this must be done AFTER the ViewPager has had // it's PagerAdapter set. /* A custom {@link android.support.v4.view.ViewPager} title strip which looks much like Tabs present in Android v4.0 and above, but is designed to give continuous feedback to the user when scrolling. */ SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs); slidingTabLayout.setViewPager(mViewPager); }
From source file:com.readystatesoftware.ghostlog.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Switch mainSwitch = new Switch(this); mainSwitch.setChecked(LogService.isRunning()); mainSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/* www. ja v a 2s .co m*/ public void onCheckedChanged(CompoundButton compoundButton, boolean b) { Intent intent = new Intent(MainActivity.this, LogService.class); if (b) { if (!LogService.isRunning()) { startService(intent); } } else { stopService(intent); } } }); final ActionBar bar = getActionBar(); final ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; lp.rightMargin = getResources().getDimensionPixelSize(R.dimen.main_switch_margin_right); bar.setCustomView(mainSwitch, lp); bar.setDisplayShowCustomEnabled(true); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); if (!mPrefs.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) { PreferenceManager.setDefaultValues(this, R.xml.pref_filters, true); PreferenceManager.setDefaultValues(this, R.xml.pref_appearance, true); SharedPreferences.Editor edit = mPrefs.edit(); edit.putBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, true); edit.apply(); } }
From source file:io.oceanos.shaderbox.ShaderEditorActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final LayoutInflater inflater = getLayoutInflater(); final View customActionBarView = inflater.inflate(R.layout.actionbar_view_save, null); final View shaderActionView = customActionBarView.findViewById(R.id.actionbar_view); final View shaderActionSave = customActionBarView.findViewById(R.id.actionbar_save); shaderActionView.setOnClickListener(new View.OnClickListener() { @Override/*from w w w .ja va2s . c o m*/ public void onClick(View v) { if (result.isSuccess()) onView(shader); else { Toast errorMsg = Toast.makeText(getBaseContext(), result.getError(), Toast.LENGTH_LONG); errorMsg.getView().setBackgroundColor(getResources().getColor(R.color.editor_color_error)); errorMsg.show(); } } }); shaderActionSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSave(shader); } }); fps = (TextView) customActionBarView.findViewById(R.id.text_fps); viewError = (TextView) shaderActionView.findViewById(R.id.viewError); final ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); setContentView(R.layout.activity_editor); Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); ShaderDatabase database = new ShaderDatabase(getBaseContext()); if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); long id = database.newShader(); Cursor cursor = database.findById(id); if (cursor.moveToFirst()) shader = Shader.getValues(cursor); cursor.close(); if (sharedText != null) shader.setText(sharedText); else shader.setText(""); } } else { long id = intent.getLongExtra("ID", 0); Cursor cursor = database.findById(id); if (cursor.moveToFirst()) shader = Shader.getValues(cursor); cursor.close(); } database.close(); setSymbolListener(R.id.action_tab, '\t'); setSymbolListener(R.id.action_rpo, '('); setSymbolListener(R.id.action_rpc, ')'); setSymbolListener(R.id.action_cpo, '{'); setSymbolListener(R.id.action_cpc, '}'); setSymbolListener(R.id.action_dotcoma, ';'); setSymbolListener(R.id.action_coma, ','); setSymbolListener(R.id.action_dot, '.'); setSymbolListener(R.id.action_plus, '+'); setSymbolListener(R.id.action_minus, '-'); setSymbolListener(R.id.action_times, '*'); setSymbolListener(R.id.action_div, '/'); setSymbolListener(R.id.action_equal, '='); setSymbolListener(R.id.action_spo, '['); setSymbolListener(R.id.action_spc, ']'); setSymbolListener(R.id.action_and, '&'); setSymbolListener(R.id.action_or, '|'); setSymbolListener(R.id.action_greater, '>'); setSymbolListener(R.id.action_lesser, '<'); setSymbolListener(R.id.action_cardinal, '#'); final Handler uiHandler = new Handler(this); renderer = new ShaderRenderer(shader, uiHandler); shaderView = (ShaderGLView) findViewById(R.id.shader_view); shaderView.setRenderer(renderer); shaderView.setVRModeEnabled(false); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); int textSize = Integer.parseInt(prefs.getString("pref_editor_text_size", "14")); int opacity = Integer.parseInt(prefs.getString("pref_editor_opacity", "127")); editor = (ShaderEditor) findViewById(R.id.editor); editor.setTextSize(textSize); editor.setBackgroundColor(opacity << 24); editor.setHorizontallyScrolling(true); editor.setHorizontalScrollBarEnabled(true); editor.setText(shader.getText()); ScrollView scroll = (ScrollView) findViewById(R.id.scroll); editor.setScrollView(scroll); compileRT = prefs.getBoolean("pref_compile_rt", true); }
From source file:com.linkedin.android.eventsapp.ProfileActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile); Bundle extras = getIntent() != null ? getIntent().getExtras() : new Bundle(); final Person person = extras.getParcelable("person"); final Activity currentActivity = this; final ActionBar bar = getActionBar(); View viewActionBar = getLayoutInflater().inflate(R.layout.layout_action_bar, null); ImageView backView = (ImageView) viewActionBar.findViewById(R.id.actionbar_left); backView.setImageResource(R.drawable.arrow_left); backView.setVisibility(View.VISIBLE); backView.setClickable(true);//from w ww. ja v a2 s. c om backView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { currentActivity.finish(); } }); ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.MATCH_PARENT); bar.setCustomView(viewActionBar, params); bar.setDisplayShowCustomEnabled(true); bar.setDisplayShowTitleEnabled(false); bar.setIcon(new ColorDrawable(Color.TRANSPARENT)); bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F15153"))); TextView attendeeNameView = (TextView) findViewById(R.id.attendeeName); attendeeNameView.setText(person.getFirstName() + " " + person.getLastName()); final ImageView attendeeImageView = (ImageView) findViewById(R.id.attendeeImage); final TextView attendeeHeadlineView = (TextView) findViewById(R.id.attendeeHeadline); final TextView attendeeLocationView = (TextView) findViewById(R.id.attendeeLocation); boolean isAccessTokenValid = LISessionManager.getInstance(currentActivity).getSession().isValid(); if (isAccessTokenValid) { String url = Constants.personByIdBaseUrl + person.getLinkedinId() + Constants.personProjection; APIHelper.getInstance(currentActivity).getRequest(currentActivity, url, new ApiListener() { @Override public void onApiSuccess(ApiResponse apiResponse) { try { JSONObject s = apiResponse.getResponseDataAsJson(); String headline = s.has("headline") ? s.getString("headline") : ""; String pictureUrl = s.has("pictureUrl") ? s.getString("pictureUrl") : null; JSONObject location = s.getJSONObject("location"); String locationName = location != null && location.has("name") ? location.getString("name") : ""; attendeeHeadlineView.setText(headline); attendeeLocationView.setText(locationName); if (pictureUrl != null) { new FetchImageTask(attendeeImageView).execute(pictureUrl); } else { attendeeImageView.setImageResource(R.drawable.ghost_person); } } catch (JSONException e) { } } @Override public void onApiError(LIApiError apiError) { } }); ViewStub viewOnLIStub = (ViewStub) findViewById(R.id.viewOnLIStub); View viewOnLI = viewOnLIStub.inflate(); Button viewOnLIButton = (Button) viewOnLI.findViewById(R.id.viewOnLinkedInButton); viewOnLIButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DeepLinkHelper.getInstance().openOtherProfile(currentActivity, person.getLinkedinId(), new DeepLinkListener() { @Override public void onDeepLinkSuccess() { } @Override public void onDeepLinkError(LIDeepLinkError error) { } }); } }); } else { attendeeImageView.setImageResource(R.drawable.ghost_person); } }
From source file:com.roque.rueda.cashflows.fragments.AddMovementFragment.java
/** * Show a custom action bar in the activity. * @param inflater Inflater used to create the widgets. *///from w w w .j a va 2 s . c o m private void createActionBar(LayoutInflater inflater) { final View customActionBarView = inflater.inflate(R.layout.actionbar_done_cancel, null); customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Done. //Toast.makeText(getActivity(), R.string.accept, Toast.LENGTH_SHORT).show(); Movement cashMovement = new Movement(); cashMovement.setAmount(getInputAmount()); cashMovement.setDate(new Date(getInputDate())); cashMovement.setDescription(getInputNotes()); if (mIsNegative) { cashMovement.setSing("-"); } else { cashMovement.setSing("+"); } cashMovement.setIdAccount(mAccountsSpinner.getSelectedItemId()); mCashState.saveCashMovement(cashMovement); Toast.makeText(getActivity(), R.string.movement_save_message, Toast.LENGTH_SHORT).show(); Intent intent = new Intent(); // Indicate to parent activity that the information was store. intent.putExtra(MainActivity.ADD_MOVEMENT_RESULT, true); getActivity().setResult(MainActivity.REQUEST_CODE, intent); getActivity().finish(); } }); customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Cancel getActivity().finish(); } }); final ActionBar actionBar = getActivity().getActionBar(); if (actionBar != null) { actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } }