Example usage for android.app ActionBar setBackgroundDrawable

List of usage examples for android.app ActionBar setBackgroundDrawable

Introduction

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

Prototype

public abstract void setBackgroundDrawable(@Nullable Drawable d);

Source Link

Document

Set the ActionBar's background.

Usage

From source file:com.ls.sip.CameraFragment.java

@Override
public void onHiddenChanged(boolean isHidden) {
    super.onHiddenChanged(isHidden);

    if (!isHidden) {
        ActionBar ab = getActivity().getActionBar();

        if (ab != null) {
            ab.setBackgroundDrawable(
                    ContextCompat.getDrawable(getActivity(), R.drawable.cwac_cam2_action_bar_bg_transparent));
            ab.setTitle("");

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                ab.setDisplayHomeAsUpEnabled(false);
            } else {
                ab.setDisplayShowHomeEnabled(false);
                ab.setHomeButtonEnabled(false);
            }//  ww  w . j a va 2 s  .  co m
        }

        if (btnTakePicture != null) {
            btnTakePicture.setEnabled(true);
            btnSwitch.setEnabled(true);
        }
    }
}

From source file:edu.pdx.cecs.orcycle.TabsConfig.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {/*from ww w . jav  a 2 s  .c o m*/
        myApp = MyApplication.getInstance();
        myApp.setRunning(true);
        myApp.clearReminderNotifications();

        setContentView(R.layout.tabs_config);

        Log.v(MODULE_TAG, "Cycle: TabsConfig onCreate");

        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        // Toast.makeText(this, "Tab Created", Toast.LENGTH_LONG).show();

        fragment1 = new FragmentMainInput();
        fragment2 = new FragmentSavedTripsSection();
        fragment3 = new FragmentSavedNotesSection();
        //fragment4 = new FragmentUserInfo();
        fragment4 = new FragmentSettings();

        // Set up the action bar.
        final ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.psu_green));

        // Create the adapter that will return a fragment for each of the four
        // primary sections of the app.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // When swiping between different sections, select the corresponding
        // tab. We can also use ActionBar.Tab#select() to do this if we have
        // a reference to the Tab.
        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });

        // For each of the sections in the app, add a tab to the action bar.
        for (int i = 0; i < mSectionsPagerAdapter.getCount(); 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 callback (listener) for when
            // this tab is selected.

            actionBar.addTab(
                    actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
        }

        mViewPager.setOffscreenPageLimit(4);

        Intent intent;
        Bundle bundle;
        if (null != (intent = getIntent())) {
            if (null != (bundle = intent.getExtras())) {
                fragmentToShow = bundle.getInt(TabsConfig.EXTRA_SHOW_FRAGMENT, FRAG_INDEX_MAIN_INPUT);
            }
        }
    } catch (Exception ex) {
        Log.e(MODULE_TAG, ex.getMessage());
    }
}

From source file:com.digium.respoke.ChatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    Button buttonSend = (Button) findViewById(R.id.buttonSend);

    EditText chatText = (EditText) findViewById(R.id.chatText);
    chatText = (EditText) findViewById(R.id.chatText);
    chatText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                sendChatMessage();//  w w w  .j  av a2  s.  c om
                return true;
            }
            return false;
        }
    });
    buttonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            sendChatMessage();
        }
    });

    String remoteEndpointID = null;
    boolean shouldStartDirectConnection = false;

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        remoteEndpointID = savedInstanceState.getString(ENDPOINT_ID_KEY);
        shouldStartDirectConnection = savedInstanceState.getBoolean(DIRECT_CONNECTION_KEY, false);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            remoteEndpointID = extras.getString(ENDPOINT_ID_KEY);
            shouldStartDirectConnection = extras.getBoolean(DIRECT_CONNECTION_KEY, false);
        } else {
            // The activity must have been destroyed while it was hidden to save memory. Use the most recent persistent data.
            SharedPreferences prefs = getSharedPreferences(ConnectActivity.RESPOKE_SETTINGS, 0);
            remoteEndpointID = prefs.getString(ENDPOINT_ID_KEY, "");
            shouldStartDirectConnection = prefs.getBoolean(DIRECT_CONNECTION_KEY, false);
        }
    }

    conversation = ContactManager.sharedInstance().conversations.get(remoteEndpointID);
    remoteEndpoint = ContactManager.sharedInstance().sharedClient.getEndpoint(remoteEndpointID, true);
    setTitle(remoteEndpoint.getEndpointID());

    listAdapter = new ListDataAdapter();

    ListView lv = (ListView) findViewById(R.id.list); //retrieve the instance of the ListView from your main layout
    lv.setAdapter(listAdapter); //assign the Adapter to be used by the ListView

    if (shouldStartDirectConnection && (null == remoteEndpoint.directConnection())) {
        // If the direct connection has not been started yet, start it now
        remoteEndpoint.startDirectConnection();
    }

    directConnection = remoteEndpoint.directConnection();
    if (null != directConnection) {
        directConnection.setListener(this);
        RespokeCall call = directConnection.getCall();
        boolean caller = false;

        if (null != call) {
            call.setListener(this);
            caller = call.isCaller();
        }

        View answerView = findViewById(R.id.answer_view);
        View connectingView = findViewById(R.id.connecting_view);
        TextView callerNameView = (TextView) findViewById(R.id.caller_name_text);

        if (caller) {
            answerView.setVisibility(View.INVISIBLE);
            connectingView.setVisibility(View.VISIBLE);
        } else {
            answerView.setVisibility(View.VISIBLE);
            connectingView.setVisibility(View.INVISIBLE);
        }

        if (null != remoteEndpoint) {
            callerNameView.setText(remoteEndpoint.getEndpointID());
        } else {
            callerNameView.setText("Unknown Caller");
        }

        ActionBar actionBar = getActionBar();
        actionBar.setBackgroundDrawable(new ColorDrawable(R.color.incoming_connection_bg));
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
    }
}

From source file:com.keithcassidy.finishline.HomeActivity.java

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

    //volume controls will adjust media playback when this app has focus
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();// getSupportActionBar();
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.pinstripe_actionbar_tile));

    currentFragment = PreferencesUtils.getCurrentFragment(this);

    homeFragment = new HomeFragment();
    setupFragment1 = new SetupFragment();
    ((SetupFragment) setupFragment1).setBuoyNumber(1);
    setupFragment2 = new SetupFragment();
    ((SetupFragment) setupFragment2).setBuoyNumber(2);
    lineCrossFragment = new LineCrossingsFragment();
    mapFragment = new FinishLineMapFragment();

    // Create the adapter that will return a fragment for each of the 
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setCurrentItem(currentFragment);

    mIndicator = (TitlePageIndicator) findViewById(R.id.indicator);
    mIndicator.setViewPager(mViewPager);

    mIndicator.setClipPadding(-10);//from   www. j av  a 2 s .  co  m
    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            try {
                currentFragment = position;
                //               PreferencesUtils.setCurrentFragment(context, currentFragment);

                TabFocusInterface frag = (TabFocusInterface) mSectionsPagerAdapter.getItem(position);
                frag.tabSetFocus();

                if (lastPosition != -1) {
                    frag = (TabFocusInterface) mSectionsPagerAdapter.getItem(lastPosition);
                    frag.tabLoseFocus();
                }

                lastPosition = position;
            } catch (Exception e) {
                Log.e(TAG, "onPageSelected " + e);
            }

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }
    });

    LocalBroadcastManager.getInstance(this).registerReceiver(onBroadcastServiceStatusReceived,
            new IntentFilter(Constants.SERVICE_STATUS_MESSAGE));

    new SimpleEula(this).show();
}

From source file:at.tomtasche.reader.ui.activity.DocumentActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //  ?/*from  www  . j a  v a2  s .  c  o  m*/
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        String msg = "";
        if (loadCurrentLanguage().equals("en")) {
            msg = "An ability to open odt files is  available only for devices with a version of Android 3.0 and above";
        } else if (loadCurrentLanguage().equals("de")) {
            msg = "Die Fhigkeit, odt-Datei zu ffnen, ist nur fr Gerte mit Android-Version 3.0 und hher verfgbar";
        } else if (loadCurrentLanguage().equals("fr")) {
            msg = "Possibilit d'ouvrir odt n'est disponible que pour les appareils avec une version d'Android 3.0 et au-dessus";
        } else if (loadCurrentLanguage().equals("uk")) {
            msg = "? ? odt  ?  ? ?  ? Android 3.0  ";
        } else if (loadCurrentLanguage().equals("ru")) {
            msg = "? ? odt  ?  ? ?? ? ? Android 3.0  ";
        } else {
            if (Locale.getDefault().getDisplayLanguage().equals("??")) {
                msg = "? ? odt  ?  ? ?? ? ? Android 3.0  ";
            } else if (Locale.getDefault().getDisplayLanguage().equals("?")) {
                msg = "? ? odt  ?  ? ?  ? Android 3.0  ";
            } else {
                msg = "An ability to open odt files is  available only for devices with a version of Android 3.0 and above";
            }
        }
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        finish();
    } else {
        setTitle("");
        setContentView(R.layout.open_document_main);

        handler = new Handler();
        loadingListeners = new LinkedList<LoadingListener>();

        getSupportLoaderManager().initLoader(0, null, this);
        getSupportLoaderManager().initLoader(1, null, this);

        pageFragment = (PageFragment) getSupportFragmentManager().findFragmentByTag(PageFragment.FRAGMENT_TAG);
        if (pageFragment == null) {
            pageFragment = new PageFragment();
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.document_container, pageFragment, PageFragment.FRAGMENT_TAG).commit();

            Uri uri = getIntent().getData();
            if (Intent.ACTION_VIEW.equals(getIntent().getAction()) && uri != null) {
                loadUri(uri);
            }
        }

        //  
        int theme = PreferenceManager.getDefaultSharedPreferences(this).getInt(IConstants.THEME_PREF,
                IConstants.THEME_REDTREE);
        ActionBar bar = getActionBar();
        switch (theme) {
        case IConstants.THEME_MYBLACK:
            bar.setBackgroundDrawable(
                    getResources().getDrawable(com.fullreader.R.drawable.theme_black_action_bar));
            break;
        case IConstants.THEME_LAMINAT:
            bar.setBackgroundDrawable(
                    getResources().getDrawable(com.fullreader.R.drawable.theme_laminat_action_bar));
            break;
        case IConstants.THEME_REDTREE:
            bar.setBackgroundDrawable(
                    getResources().getDrawable(com.fullreader.R.drawable.theme_redtree_action_bar));
            break;
        }
    }

}

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.  ja va2  s  .com
    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.inc.playground.playgroundApp.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    globalVariables = ((GlobalVariables) getApplication());
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    setPlayGroundActionBar();//from   www  .  j  av a 2s  . c  o m
    //set actionBar color
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor)));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor)));
    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    //actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); 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.addTab(actionBar.newTab().setTabListener(this));
    }
    actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view);
    actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view);
    //NavigationDrawer handling (e.g the list from leftside):
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */
    ) {

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

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

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.closeDrawers();
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // all linear layout from slider menu

    /*Home button */
    LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home);
    ll_Home.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, MainActivity.class);
            startActivity(iv);
            finish();
        }
    });
    /*Login button */
    LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login);
    ll_Login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            LinearLayout ll_Login = (LinearLayout) v;
            TextView loginTxt = (TextView) findViewById(R.id.login_txt);
            if (loginTxt.getText().equals("Login")) {
                Intent iv = new Intent(MainActivity.this, Login.class);
                startActivity(iv);
                finish();
            } else if (loginTxt.getText().equals("Logout")) {
                final Dialog alertDialog = new Dialog(MainActivity.this);
                alertDialog.setContentView(R.layout.logout_dilaog);
                alertDialog.setTitle("Logout");
                alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.clear();
                        editor.commit();
                        ImageView loginImg = (ImageView) findViewById(R.id.login_img);
                        TextView loginTxt = (TextView) findViewById(R.id.login_txt);
                        loginTxt.setText("Login");
                        loginImg.setImageResource(R.drawable.pg_action_lock_open);

                        globalVariables = ((GlobalVariables) getApplication());
                        globalVariables.SetCurrentUser(null);
                        globalVariables.SetUserPictureBitMap(null);
                        globalVariables.SetUsersList(null);
                        globalVariables.SetUsersImagesMap(null);

                        Util.clearCookies(getApplicationContext());

                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.show(); //<-- See This!
            }

        }
    });
    //
    //        /*Setting button*/
    //        LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings);
    //        ll_Setting.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                // TODO Auto-generated method stub
    //                // new changes
    //                Intent iv = new Intent(MainActivity.this,
    //                        com.inc.playground.playgroundApp.upLeft3StripesButton.
    //                                SettingsActivity.class);
    //                startActivity(iv);
    //                finish();
    //            }
    //        });

    /*My profile button*/
    LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile);
    ll_my_profile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // new changes
            globalVariables = ((GlobalVariables) getApplication());
            User currentUser = globalVariables.GetCurrentUser();
            if ((currentUser == null) || (currentUser != null && currentUser.GetUserId() == null)) {
                Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show();
            } else {

                Intent iv = new Intent(MainActivity.this,
                        com.inc.playground.playgroundApp.upLeft3StripesButton.MyProfile.class);

                //for my profile
                iv.putExtra("name", currentUser.getName());
                iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents());
                //pass events
                iv.putExtra("events", currentUser.getEvents());
                iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval());
                iv.putExtra("events_decline", currentUser.getEvents_decline());

                iv.putExtra("photoUrl", currentUser.getPhotoUrl());
                startActivity(iv);
                //
            }
        }
    });

    LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about);
    ll_aboutUs.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, AboutUs.class);
            startActivity(iv);
            finish();
        }
    });

}

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

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    globalVariables = ((GlobalVariables) getApplication());
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    setPlayGroundActionBar();//from   ww  w. j a v a2  s .com
    //set actionBar color
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor)));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor)));
    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    //actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); 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.addTab(actionBar.newTab().setTabListener(this));
    }
    actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view);
    actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view);
    actionBar.getTabAt(2).setIcon(R.drawable.pg_calendar_view);
    //NavigationDrawer handling (e.g the list from leftside):
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */
    ) {

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

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

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.closeDrawers();
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // all linear layout from slider menu

    /*Home button */
    LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home);
    ll_Home.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, MainActivity.class);
            startActivity(iv);
            finish();
        }
    });
    /*Login button */
    LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login);
    ll_Login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            LinearLayout ll_Login = (LinearLayout) v;
            TextView loginTxt = (TextView) findViewById(R.id.login_txt);
            if (loginTxt.getText().equals("Login")) {
                Intent iv = new Intent(MainActivity.this, Login.class);
                startActivity(iv);
                finish();
            } else if (loginTxt.getText().equals("Logout")) {
                final Dialog alertDialog = new Dialog(MainActivity.this);
                alertDialog.setContentView(R.layout.logout_dilaog);
                alertDialog.setTitle("Logout");
                alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.clear();
                        editor.commit();
                        ImageView loginImg = (ImageView) findViewById(R.id.login_img);
                        TextView loginTxt = (TextView) findViewById(R.id.login_txt);
                        loginTxt.setText("Login");
                        loginImg.setImageResource(R.drawable.pg_action_lock_open);

                        globalVariables = ((GlobalVariables) getApplication());
                        globalVariables.SetCurrentUser(null);
                        globalVariables.SetUserPictureBitMap(null);
                        globalVariables.SetUsersList(null);
                        globalVariables.SetUsersImagesMap(null);

                        Util.clearCookies(getApplicationContext());

                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.show(); //<-- See This!
            }

        }
    });

    /*Setting button*/
    LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings);
    ll_Setting.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this,
                    com.inc.playground.playground.upLeft3StripesButton.SettingsActivity.class);
            startActivity(iv);
            finish();
        }
    });

    /*My profile button*/
    LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile);
    ll_my_profile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // new changes
            globalVariables = ((GlobalVariables) getApplication());
            User currentUser = globalVariables.GetCurrentUser();
            if (currentUser == null) {
                Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show();
            } else {

                Intent iv = new Intent(MainActivity.this,
                        com.inc.playground.playground.upLeft3StripesButton.MyProfile.class);

                //for my profile
                iv.putExtra("name", currentUser.getName());
                iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents());
                //pass events
                iv.putExtra("events", currentUser.getEvents());
                iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval());
                iv.putExtra("events_decline", currentUser.getEvents_decline());

                iv.putExtra("photoUrl", currentUser.getPhotoUrl());
                startActivity(iv);
                //
            }
        }
    });

    LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about);
    ll_aboutUs.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, AboutUs.class);
            startActivity(iv);
            finish();
        }
    });

}

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 .j a va2 s  .c  o m
    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.example.android.navigationdrawerexample.MainActivity.java

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

    StrictMode.enableDefaults(); //STRICT MODE ENABLED

    db = new DBHelper(this);
    session = new Session(getApplicationContext());

    inflatedView = getLayoutInflater().inflate(R.layout.full_layout, null);
    mTitle = mDrawerTitle = getTitle();/*w  ww.  j  a  v a  2s . co  m*/
    login_layout = (RelativeLayout) findViewById(R.id.login_layout);
    //   order_list_layout= (RelativeLayout) findViewById(R.id.order_list_layout);
    signup_layout = (RelativeLayout) findViewById(R.id.signup_layout);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    actionBar = getActionBar();

    text = (TextView) inflatedView.findViewById(R.id.user_name);
    login_option = (TextView) inflatedView.findViewById(R.id.textView1);

    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    order_list = (ListView) findViewById(R.id.order_list);

    final LayoutInflater factory = getLayoutInflater();

    final View vendor_menu = factory.inflate(R.layout.vendor_menu, null);
    final View order_menu = factory.inflate(R.layout.my_order, null);
    menu_list = (ListView) vendor_menu.findViewById(R.id.menu_list);
    // loginPopup= (TextView) vendor_menu.findViewById(R.id.menu_title);
    // Log.d
    //menu_list.addView(order_menu,0);

    Signup = (Button) findViewById(R.id.Signup);
    Gosignup = (Button) findViewById(R.id.Gosignup);
    Login = (ImageButton) findViewById(R.id.Login);

    Sign_username = (EditText) findViewById(R.id.SignUsername);
    Sign_name = (EditText) findViewById(R.id.vendor);
    Sign_pass = (EditText) findViewById(R.id.SignPass);
    Sign_cpass = (EditText) findViewById(R.id.SignCpass);
    Sign_phone = (EditText) findViewById(R.id.Phone);

    Login_pass = (EditText) findViewById(R.id.Logpass);
    Login_email = (EditText) findViewById(R.id.Logusername);

    // Log_username= (EditText) findViewById(R.id.Logusername);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener

    adapter = new MyAdapter(this);
    //adapter2=new MyAdapter2(this);
    // menu_adapter=new MyAdapter2(this);
    mDrawerList.setAdapter(adapter);
    mDrawerList.setDividerHeight(0);
    //mDrawerList.setAdapter(adapter);
    // order_list.setAdapter(adapter2);
    // menu_list.setAdapter(menu_adapter);

    menu_list.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, adapter.mPlanetTitles));

    ImageView floatoption = new ImageView(this);
    floatoption.setImageResource(R.drawable.foption);

    ImageView floatadd = new ImageView(this);
    floatadd.setImageResource(R.drawable.fplus);

    floatin = new ImageView(this);
    floatin.setImageResource(R.drawable.flogin);

    floatout = new ImageView(this);
    floatout.setImageResource(R.drawable.flogout);

    ImageView floatrefresh = new ImageView(this);
    floatrefresh.setImageResource(R.drawable.refresh);

    itemBuilder = new SubActionButton.Builder(this);

    loginout = itemBuilder.setContentView(floatin).build();
    refresh = itemBuilder.setContentView(floatrefresh).build();
    additem = itemBuilder.setContentView(floatadd).build();

    actionButton = new FloatingActionButton.Builder(this).setContentView(floatoption).build();

    actionMenu = new FloatingActionMenu.Builder(this).addSubActionView(loginout).addSubActionView(additem)
            .addSubActionView(refresh)

            // ...
            .attachTo(actionButton).build();

    Signup.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            View v = mDrawerList.getChildAt(0);
            View v2 = mDrawerList.getChildAt(5);

            text = (TextView) v.findViewById(R.id.user_name);
            login_option = (TextView) v2.findViewById(R.id.textView1);
            profile = (ImageView) v.findViewById(R.id.user_image);
            profile.setImageResource(R.drawable.welcome);
            text.setTextSize(20);
            text.setTextColor(Color.MAGENTA);
            text.setText("" + Sign_name.getText().toString());

            login_option.setText("Logout");

            floatout.setImageResource(R.drawable.flogout);
            // loginout.setContentView(floatout);
            long id = db.Insert(Sign_username.getText().toString(), Sign_name.getText().toString(),
                    Sign_pass.getText().toString(), Sign_phone.getText().toString());

            Log.d("This is-----------==", (String) text.getText() + id);

            //mDrawerList.invalidateViews();

            //mDrawerList.removeViewAt(0);
            adapter.notifyDataSetChanged();

            loginout.removeView(floatin);
            loginout.setContentView(floatout);

            order_list.setVisibility(View.VISIBLE);
            signup_layout.setVisibility(View.INVISIBLE);
            login_layout.setVisibility(View.INVISIBLE);

        }
    });

    Login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            user_name = Login_email.getText().toString();
            user_pass = Login_pass.getText().toString();

            new GetAllCustomerTask().execute(new ApiConnector());
            new Order_details().execute(new ApiConnector());

        }
    });

    if (!session.getusename().equals("")) {
        user_id = session.getusename();
        user_name = session.getusename();
        user_pass = session.getpassword();
        login_layout.setVisibility(View.INVISIBLE);
        new GetAllCustomerTask().execute(new ApiConnector());
        // new Order_details().execute(new ApiConnector());
        // View vt = mDrawerList.getChildAt(0);
        //login_check(jsonArray);

        //new Order_details().execute(new ApiConnector());
    }

    additem.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (logged_in) {
                Intent i = new Intent(getApplicationContext(), Add_Item.class);
                startActivity(i);
            } else
                Toast.makeText(getApplicationContext(), "You Need To Login...", Toast.LENGTH_LONG).show();

        }
    });
    loginout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (logged_in) {
                session.setusename("", "");
                finish();
                startActivity(getIntent());
                Toast.makeText(getApplicationContext(), "You are Loged Out", Toast.LENGTH_SHORT).show();
            } else
                Toast.makeText(getApplicationContext(), "You Need To Login...", Toast.LENGTH_LONG).show();

        }
    });

    Login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            user_name = Login_email.getText().toString();
            user_pass = Login_pass.getText().toString();
            new GetAllCustomerTask().execute(new ApiConnector());
            //   new Order_details().execute(new ApiConnector());

        }
    });

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    order_list.setOnItemClickListener(new OrderItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(0xFF3BBD8F));

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            text = (TextView) inflatedView.findViewById(R.id.user_name);
            Log.d("Thit is----------------", (String) text.getText());
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }

}