Example usage for android.app ActionBar setCustomView

List of usage examples for android.app ActionBar setCustomView

Introduction

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

Prototype

public abstract void setCustomView(@LayoutRes int resId);

Source Link

Document

Set the action bar into custom navigation mode, supplying a view for custom navigation.

Usage

From source file:com.swisscom.safeconnect.activity.PipeActivity.java

protected void initActionBar(Activity activity, int stringId, View.OnClickListener listener) {
    ActionBar ab = activity.getActionBar();

    //Tutorial with NoTitle Theme returns null here
    if (ab == null) {
        return;/* ww w  . ja  va  2 s  .  c  om*/
    }
    ab.setDisplayShowCustomEnabled(true);
    ab.setDisplayShowTitleEnabled(false);
    ab.setDisplayShowHomeEnabled(false);

    actionBarView = activity.getLayoutInflater().inflate(R.layout.actionbar, null);

    tvTitle = (TextView) actionBarView.findViewById(R.id.tv_title);
    imgBackBtn = (ImageView) actionBarView.findViewById(R.id.img_back_btn);
    if (tvTitle != null && stringId != 0) {
        tvTitle.setText(stringId);
    }

    setOnBackPressedListener(listener);

    ab.setCustomView(actionBarView);
}

From source file:com.bt.download.android.gui.activities.MainActivity.java

private void setupActionBar() {
    ActionBar bar = getActionBar();

    bar.setCustomView(R.layout.view_custom_actionbar);

    bar.setDisplayShowCustomEnabled(true);
    bar.setDisplayHomeAsUpEnabled(true);
    bar.setHomeButtonEnabled(true);//from   w w  w.  j a va2s  .  c  o m
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.widget.ListWidgetConfig.java

void setupActionBar() {
    final WidgetPrefs widgetPrefs = new WidgetPrefs(this, appWidgetId);

    LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done, null);
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override/*from  ww w  . j a  v  a2s  .c o  m*/
        public void onClick(View v) {
            // "Done"
            // // Set success
            widgetPrefs.setPresent();
            Intent resultValue = new Intent();
            resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            setResult(RESULT_OK, resultValue);
            // Build/Update widget
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
            // Log.d(TAG, "finishing WidgetId " + appWidgetId);
            appWidgetManager.updateAppWidget(appWidgetId, ListWidgetProvider
                    .buildRemoteViews(getApplicationContext(), appWidgetManager, appWidgetId, widgetPrefs));
            // Update list items
            appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.notesList);
            // Destroy activity
            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);
}

From source file:se.toxbee.sleepfighter.activity.EditGPSFilterAreaActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
    String name = this.printName();

    if (Build.VERSION.SDK_INT >= 11) {
        // add the custom view to the action bar.
        ActionBar actionBar = getActionBar();
        actionBar.setCustomView(R.layout.gpsfilter_area_actionbar);
        actionBar.setDisplayOptions(/*  w w w.jav a2  s. c  om*/
                ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM);

        View customView = actionBar.getCustomView();

        // Setup edit name component.
        EditText editNameView = (EditText) customView.findViewById(R.id.edit_gpsfilter_area_title_edit);
        editNameView.setText(name);
        editNameView.setOnEditorActionListener(new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                area.setName(GPSFilterTextUtils.printName(getResources(), v.getText().toString()));
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                return false;
            }
        });
        editNameView.clearFocus();

        // Setup enabled switch.
        CompoundButton activatedSwitch = (CompoundButton) customView
                .findViewById(R.id.edit_gpsfilter_area_toggle);
        activatedSwitch.setChecked(this.area.isEnabled());
        activatedSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                area.setEnabled(isChecked);
            }
        });
    } else {
        this.setTitle(name);
    }
}

From source file:com.frostwire.android.gui.activities.MainActivity.java

private void setupActionBar() {
    ActionBar bar = getActionBar();
    if (bar != null) {
        bar.setCustomView(R.layout.view_custom_actionbar);
        bar.setDisplayShowCustomEnabled(true);
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(true);/*  w  w  w.j a  v  a2 s .  c o  m*/
    }
}

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

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

    ChanApplication.getBoardManager().addListener(this);

    boardLoadable = new Loadable();
    threadLoadable = new Loadable();

    boardFragment = ThreadFragment.newInstance(this);
    setBoardFragmentViewMode();//  www  . ja  v a  2 s  .  co  m

    threadFragment = ThreadFragment.newInstance(this);

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.left_pane, boardFragment);
    ft.replace(R.id.right_pane, threadFragment);
    ft.commitAllowingStateLoss();

    final ActionBar actionBar = getActionBar();

    boardSpinner = new Spinner(actionBar.getThemedContext());
    spinnerAdapter = new BoardSpinnerAdapter(this, boardSpinner);
    boardSpinner.setAdapter(spinnerAdapter);
    boardSpinner.setOnItemSelectedListener(this);

    actionBar.setCustomView(boardSpinner);
    actionBar.setDisplayShowCustomEnabled(true);

    updatePaneState();

    Intent startIntent = getIntent();
    Uri startUri = startIntent.getData();

    if (savedInstanceState != null) {
        threadLoadable.readFromBundle(this, "thread", savedInstanceState);
        startLoadingThread(threadLoadable);

        // Reset page etc.
        Loadable tmp = new Loadable();
        tmp.readFromBundle(this, "board", savedInstanceState);
        startLoadingBoard(new Loadable(tmp.board));
    } else {
        if (startUri != null) {
            handleIntentURI(startUri);
        }

        if (boardLoadable.mode == Loadable.Mode.INVALID) {
            List<Board> savedValues = ChanApplication.getBoardManager().getSavedBoards();
            if (savedValues.size() > 0) {
                startLoadingBoard(new Loadable(savedValues.get(0).value));
            }
        }
    }

    if (startIntent.getExtras() != null) {
        handleExtraBundle(startIntent.getExtras());
    }

    ignoreNextOnItemSelected = true;
}

From source file:com.inc.playground.playground.MainActivity.java

public void setPlayGroundActionBar() {
    String userLoginId, userFullName, userEmail, userPhoto;
    Bitmap imageBitmap = null;/*from w w  w  .j a  v  a 2  s .co  m*/
    GlobalVariables globalVariables;
    final ActionBar actionBar = getActionBar();

    final String MY_PREFS_NAME = "Login";
    SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
    globalVariables = ((GlobalVariables) this.getApplication());
    if (prefs.getString("userid", null) != null) {
        userLoginId = prefs.getString("userid", null);
        userFullName = prefs.getString("fullname", null);
        userEmail = prefs.getString("emilid", null);
        userPhoto = prefs.getString("picture", null);
        globalVariables.GetCurrentUser().setPhotoUrl(userPhoto);
        actionBar.setCustomView(R.layout.actionbar_custom_view_home);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayUseLogoEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);

        ImageView logo_image = (ImageView) findViewById(R.id.img_profile_action_bar);
        logo_image.setBackgroundResource(R.drawable.pg_logo2);
        TextView userName = (TextView) findViewById(R.id.email);
        userName.setText(userFullName.replace("%20", "  "));
        ImageView img_profile = (ImageView) findViewById(R.id.profile_image);
        imageBitmap = globalVariables.GetUserPictureBitMap();
        if (imageBitmap == null) {
            Log.i(TAG, "downloading");
            try {
                imageBitmap = new DownloadImageBitmapTask().execute(userPhoto).get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }

        } else {
            Log.i(TAG, "Image found");
        }
        img_profile.setImageBitmap(imageBitmap);

        ImageView notificationBtn = (ImageView) findViewById(R.id.notification_btn);
        notificationBtn.setVisibility(View.VISIBLE);
        notificationBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent iv = new Intent(MainActivity.this, NotificationsList.class);
                startActivity(iv);
                finish();
            }
        });
        TextView notificationNumber = (TextView) findViewById(R.id.notification__numberTxt);
        if (globalVariables.GetNotifications() != null && globalVariables.GetNotifications().size() != 0) {
            notificationNumber.setText(Integer.toString(globalVariables.GetNotifications().size()));
            notificationNumber.setVisibility(View.VISIBLE);
        } else {
            notificationNumber.setVisibility(View.INVISIBLE);
        }

        TextView loginTxt = (TextView) findViewById(R.id.login_txt);
        ImageView loginImg = (ImageView) findViewById(R.id.login_img);
        globalVariables.SetUserPictureBitMap(imageBitmap); // Make the imageBitMap global to all activities to avoid downloading twice
        loginTxt.setText("Logout");
        loginImg.setImageResource(R.drawable.pg_action_lock_close);
        // Register to notifications
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);

    }
}

From source file:com.android.contacts.activities.ContactDetailActivity.java

/**
 * M:update rcs-e icon/*from  w  w w .  java  2  s.  com*/
 */
public void updateRCSIcon(long id) {
    ///@ update the rcs-e icon
    LogUtils.i(TAG, "updateRCSIcon,Need to remove the code...");
    ActionBar actionBar = getActionBar();
    Drawable drawable = ExtensionManager.getInstance().getContactDetailExtension().getRCSIcon(id);
    if (drawable != null) {
        View view = LayoutInflater.from(this).inflate(com.android.contacts.R.layout.mtk_action_bar_rcs_icon,
                null);
        ImageView iv = (ImageView) view.findViewById(com.android.contacts.R.id.rcs_icon);
        iv.setImageDrawable(drawable);
        actionBar.setCustomView(view);
    }
}

From source file:org.billthefarmer.tuner.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Find the views, not all may be present
    spectrum = (Spectrum) findViewById(R.id.spectrum);
    display = (Display) findViewById(R.id.display);
    strobe = (Strobe) findViewById(R.id.strobe);
    status = (Status) findViewById(R.id.status);
    meter = (Meter) findViewById(R.id.meter);
    scope = (Scope) findViewById(R.id.scope);

    // Add custom view to action bar
    ActionBar actionBar = getActionBar();
    actionBar.setCustomView(R.layout.signal_view);
    actionBar.setDisplayShowCustomEnabled(true);

    signal = (SignalView) actionBar.getCustomView();

    // Create audio
    audio = new Audio();

    // Connect views to audio
    if (spectrum != null)
        spectrum.audio = audio;/*from   w  w  w  . jav  a  2s  .c om*/

    if (display != null)
        display.audio = audio;

    if (strobe != null)
        strobe.audio = audio;

    if (status != null)
        status.audio = audio;

    if (signal != null)
        signal.audio = audio;

    if (meter != null)
        meter.audio = audio;

    if (scope != null)
        scope.audio = audio;

    // Set up the click listeners
    setClickListeners();
}

From source file:se.liu.tddd77.bilsensor.MainActivity.java

/**
 * The menu consists of two parts, the record button and the settings. 
 * The record button is a checkable button. The settings is the collection 
 * of the other available options. They should all be added through the 
 * XML-file with the definition of the event here in onOptionsItemSelected.
 *//*from  w ww .  ja  v  a 2  s .c o m*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    View view = getLayoutInflater().inflate(R.layout.actionbar, null);
    actionBar.setCustomView(view);

    final TextView projectName = (TextView) findViewById(R.id.project_name);
    Log.i("MainActivity", "Getting project name");
    Bundle projectnamebundle = getIntent().getExtras();
    projectname = projectnamebundle.getString("Project_name");
    serverIP = projectnamebundle.getString("Server_IP");
    if (projectname == null) {
        Log.i("MainActivity", "Projectname == null");
    } else {
        Log.i("MainActivity", "Projectname != null");
    }
    Log.i("MainActivity", projectname);
    projectName.setText(projectname);

    final ImageButton button = (ImageButton) findViewById(R.id.recButton);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            handleRecord(button);
        }
    });
    /*   final ImageButton playButton = (ImageButton) findViewById(R.id.playButton);
       playButton.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
    handlePlay(playButton);
          }
       });*/
    final ImageButton buttonMenu = (ImageButton) findViewById(R.id.menuButton);
    buttonMenu.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {
                saveProfile("profil.txt");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
    final ImageButton loadMenu = (ImageButton) findViewById(R.id.loadButton);
    loadMenu.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            //try {
            //SelectViewNameDialog dialog = new SelectViewNameDialog(avb);
            //dialog.show(getFragmentManager(), null);
            try {
                loadProfile("profil.txt");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (BackendError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

    //playButton.setMaxWidth(playButton.getHeight());

    return super.onCreateOptionsMenu(menu);
}