Example usage for android.widget LinearLayout setOnClickListener

List of usage examples for android.widget LinearLayout setOnClickListener

Introduction

In this page you can find the example usage for android.widget LinearLayout setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:org.alfresco.mobile.android.application.fragments.workflow.task.TaskDetailsFragment.java

private void initInitiator() {
    // Display Initiator
    if (initiator != null) {
        LinearLayout layout = (LinearLayout) vRoot.findViewById(R.id.task_initiator_group);
        layout.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                UserProfileFragment.with(getActivity()).personId(initiator.getIdentifier()).displayAsDialog();
            }/* ww  w .  j av  a  2  s . c  om*/
        });

        TextView tv = (TextView) vRoot.findViewById(R.id.task_initiator);
        tv.setText(initiator.getFullName());
    } else {
        vRoot.findViewById(R.id.task_initiator_group).setVisibility(View.GONE);
        vRoot.findViewById(R.id.task_initiator_icon).setVisibility(View.GONE);
    }
}

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();//w  w  w .j a v  a2 s .  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.ess.tudarmstadt.de.sleepsense.mgraph.SleepEstimGPlotFragment.java

private void createGraph(String graphTitle, GraphViewSeries series, final int Rid, boolean isBarChart) {
    GraphView graphView = null;// ww w  .j a v a2 s.c o m

    if (isBarChart) {
        graphView = new BarGraphView(getActivity().getApplicationContext(), graphTitle);
        // ((BarGraphView) graphView).setColWidth(1.09f);
        // graphView.setVerticalLabels(new String[] { "high", "mid", "low"
        // });
        // graphView.setManualYAxisBounds(11.0d, 9.0d);
    } else {
        graphView = new LineGraphView(getActivity().getApplicationContext(), graphTitle);

    }
    // add data
    graphView.addSeries(series);
    // graphView.setScrollable(true);
    // graphView.setViewPort(0, 23);
    // optional - activate scaling / zooming
    // graphView.setScalable(true);
    // optional - legend
    // graphView.setShowLegend(true);

    graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
        @Override
        public String formatLabel(double axis_value, boolean isValueX) {
            if (isValueX) {
                // X-Axis
                // decompose x_axis from adding up before
                double value = axis_value;
                if (axis_value >= 200) {
                    value = axis_value - 200;
                } else if (axis_value >= 100)
                    value = axis_value - 100;

                // convert (double) hour.mm to hour:mm
                // make sure not have smth like 4:60 or 11:83 in the time frame!
                double whole = value;
                double fractionalPart = value % 1;
                double integralPart = value - fractionalPart;
                if (fractionalPart >= 0.60) {
                    whole = integralPart + 1.0d + (fractionalPart - 0.60);
                }

                return new DecimalFormat("00.00").format(whole).replaceAll("\\,", ":");
            } else {
                // Y-Axis
                return ""; //new DecimalFormat("#0.0").format(axis_value);
            }
        }
    });

    graphView.getGraphViewStyle().setNumVerticalLabels(4);
    graphView.getGraphViewStyle().setNumHorizontalLabels(0); //AUTO
    graphView.getGraphViewStyle().setTextSize(17f);
    graphView.getGraphViewStyle().setVerticalLabelsAlign(Align.CENTER);
    graphView.getGraphViewStyle().setVerticalLabelsWidth(0);
    graphView.getGraphViewStyle().setGridColor(Color.WHITE);

    LinearLayout layout = (LinearLayout) rootView.findViewById(Rid);
    layout.removeAllViews();
    layout.addView(graphView);
    rootView.postInvalidate();
    layout.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            openBig();
        }
    });

}

From source file:ovh.ice.icecons.MainActivity.java

private void createLayout() {

    // main centered layout

    LinearLayout.LayoutParams smallLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
    float scale = IceScreenUtils.densityScale(getApplicationContext());
    ViewGroup.LayoutParams buttonParams = new ViewGroup.LayoutParams(Math.round(48 * scale),
            Math.round(48 * scale));

    LinearLayout frameLayout = new LinearLayout(this);
    frameLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    frameLayout.setBackgroundColor(0xffffffff);
    frameLayout.setGravity(Gravity.CENTER);
    setContentView(frameLayout);/*from  ww w  . jav a  2 s  .c o  m*/

    LinearLayout baseLayout = new LinearLayout(this);
    baseLayout.setOrientation(LinearLayout.VERTICAL);
    baseLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    baseLayout.setGravity(Gravity.LEFT);
    frameLayout.addView(baseLayout);

    // wallpaper button

    LinearLayout wallpaperLayout = new LinearLayout(this);
    wallpaperLayout.setOrientation(LinearLayout.HORIZONTAL);
    wallpaperLayout.setLayoutParams(smallLayoutParams);
    wallpaperLayout.setGravity(Gravity.CENTER_VERTICAL);
    baseLayout.addView(wallpaperLayout);

    LinearLayout wallpaperClickLayout = new LinearLayout(this);
    wallpaperClickLayout.setOrientation(LinearLayout.HORIZONTAL);
    wallpaperClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    wallpaperClickLayout.setGravity(Gravity.CENTER);
    wallpaperLayout.addView(wallpaperClickLayout);
    wallpaperClickLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            wallpaperPicker(v);
        }
    });

    Button wallpaperButton = new Button(this);
    wallpaperButton.setLayoutParams(buttonParams);
    wallpaperButton.setBackground(
            new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(),
                    R.drawable.ic_wallpaper_button, Math.round(48 * scale), Math.round(48 * scale))));
    wallpaperClickLayout.addView(wallpaperButton);

    TextView wallpaperText = new TextView(this);
    wallpaperText.setText("wallpapers");
    wallpaperText.setTextSize(24);
    wallpaperText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    wallpaperText.setPadding(64, 64, 64, 64);
    wallpaperClickLayout.addView(wallpaperText);

    // icon view button

    LinearLayout iconLayout = new LinearLayout(this);
    iconLayout.setOrientation(LinearLayout.HORIZONTAL);
    iconLayout.setLayoutParams(smallLayoutParams);
    iconLayout.setGravity(Gravity.CENTER_VERTICAL);
    baseLayout.addView(iconLayout);

    LinearLayout iconClickLayout = new LinearLayout(this);
    iconClickLayout.setOrientation(LinearLayout.HORIZONTAL);
    iconClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    iconClickLayout.setGravity(Gravity.CENTER);
    iconLayout.addView(iconClickLayout);
    iconClickLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            iconView(v);
        }
    });

    Button iconButton = new Button(this);
    iconButton.setLayoutParams(buttonParams);
    iconButton.setBackground(
            new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(),
                    R.drawable.ic_icon_button, Math.round(48 * scale), Math.round(48 * scale))));
    iconClickLayout.addView(iconButton);

    TextView iconText = new TextView(this);
    iconText.setText("view icons");
    iconText.setTextSize(24);
    iconText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    iconText.setPadding(64, 64, 64, 64);
    iconClickLayout.addView(iconText);

    // source code button

    LinearLayout sourceLayout = new LinearLayout(this);
    sourceLayout.setOrientation(LinearLayout.HORIZONTAL);
    sourceLayout.setLayoutParams(smallLayoutParams);
    sourceLayout.setGravity(Gravity.CENTER_VERTICAL);
    baseLayout.addView(sourceLayout);

    LinearLayout sourceClickLayout = new LinearLayout(this);
    sourceClickLayout.setOrientation(LinearLayout.HORIZONTAL);
    sourceClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    sourceClickLayout.setGravity(Gravity.CENTER);
    sourceLayout.addView(sourceClickLayout);
    sourceClickLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            gitLink(v);
        }
    });

    Button sourceButton = new Button(this);
    sourceButton.setLayoutParams(buttonParams);
    sourceButton.setBackground(
            new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(),
                    R.drawable.ic_source_button, Math.round(48 * scale), Math.round(48 * scale))));
    sourceClickLayout.addView(sourceButton);

    TextView sourceText = new TextView(this);
    sourceText.setText("source code");
    sourceText.setTextSize(24);
    sourceText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    sourceText.setPadding(64, 64, 64, 64);
    sourceClickLayout.addView(sourceText);

    // license button

    LinearLayout aboutLayout = new LinearLayout(this);
    aboutLayout.setOrientation(LinearLayout.HORIZONTAL);
    aboutLayout.setLayoutParams(smallLayoutParams);
    aboutLayout.setGravity(Gravity.CENTER_VERTICAL);
    baseLayout.addView(aboutLayout);

    LinearLayout aboutClickLayout = new LinearLayout(this);
    aboutClickLayout.setOrientation(LinearLayout.HORIZONTAL);
    aboutClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    aboutClickLayout.setGravity(Gravity.CENTER);
    aboutLayout.addView(aboutClickLayout);
    aboutClickLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            licenseShow(v);
        }
    });

    Button aboutButton = new Button(this);
    aboutButton.setLayoutParams(buttonParams);
    aboutButton.setBackground(
            new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(),
                    R.drawable.ic_license_button, Math.round(48 * scale), Math.round(48 * scale))));
    aboutClickLayout.addView(aboutButton);

    TextView aboutText = new TextView(this);
    aboutText.setText("license");
    aboutText.setTextSize(24);
    aboutText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    aboutText.setPadding(64, 64, 64, 64);
    aboutClickLayout.addView(aboutText);

}

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();/*  w w w. ja v  a 2  s  .  co 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);
    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.gome.haoyuangong.views.MyViewPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;//  ww w. java  2s .c o m
    tabView.setTag("tavView");
    tabView.setId(index);
    //      tabView.setFocusable(true);
    //      tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    //tabView.setPadding(pointSize, 0, pointSize, 0);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tabView.setMaxLines(1);
    tabView.setGravity(Gravity.CENTER);
    XmlPullParser xrp = getResources().getXml(R.drawable.tab_button);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
        tabView.setTextColor(csl);
    } catch (Exception e) {

    }

    if (iconResId != 0) {
        //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabView.setLayoutParams(tabTvL);

    //measureView(tabView);

    LinearLayout layoutWraper1 = new LinearLayout(getContext());
    LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1);
    layoutWraper1.setLayoutParams(lp1);
    layoutWraper1.setGravity(Gravity.CENTER);
    layoutWraper1.setFocusable(true);
    layoutWraper1.setOnClickListener(mTabClickListener);
    layoutWraper1.setPadding(0, 0, 0, 0);
    layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red);

    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setTag("framelayout");
    //      FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5));
    FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    //      frameLayout.setPadding(padding, padding, padding, padding);
    frameLayout.setLayoutParams(fl2);
    //      frameLayout.addView(tabView);

    View hasNew = new View(getContext());
    FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize);
    hasNew.setLayoutParams(hasNewL);
    hasNewL.gravity = Gravity.TOP | Gravity.RIGHT;
    hasNew.setBackgroundResource(R.drawable.shape_circle);

    FrameLayout tabTvframe = new FrameLayout(getContext());
    FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabTvframeL.gravity = Gravity.CENTER;
    tabTvframe.setLayoutParams(tabTvframeL);
    tabTvframe.addView(tabView);
    tabTvframe.addView(hasNew);
    hasNew.setVisibility(View.GONE);

    frameLayout.addView(tabTvframe);

    layoutWraper1.addView(frameLayout);

    tabView.setTagView(hasNew);

    mTabLayout.addView(layoutWraper1, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:eu.focusnet.app.ui.activity.ProjectsListingActivity.java

/**
 * Prepare the view. This is called in {@link #onCreate(Bundle)}, before actually rendering the
 * UI.// www . j  a  v a2 s .  co  m
 * <p/>
 * See {@link super#onCreate(Bundle)}.
 */
@Override
protected void setupSpecificUiElements() {
    LayoutInflater inflater = getLayoutInflater();

    // set the default section that will initially be loaded
    this.sectionToRender = this.previouslySelectedSectionToRender = Constant.Navigation.UI_MENU_ENTRY_PROJECTS_LISTING;

    // create a Drawer
    this.drawerItems = this.getDrawerItems();
    this.drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    this.drawerListMenu = (ListView) findViewById(R.id.focus_drawer);
    if (this.drawerListMenu == null) {
        throw new FocusInternalErrorException("Cannot retrieve drawer view.");
    }

    // get the header and add it to the ListView
    // FIXME pass something else as the Context
    LinearLayout menuHeader = (LinearLayout) inflater.inflate(R.layout.include_drawer_header, null);
    menuHeader.setEnabled(false);
    menuHeader.setOnClickListener(null);
    this.drawerListMenu.addHeaderView(menuHeader, null, false);
    // adjust content of header
    /** @deprecated for production version, we should put the name/email of the user */
    String appVersion = getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME;
    TextView appInfo = (TextView) findViewById(R.id.drawer_app_info);
    if (appInfo != null) {
        appInfo.setText(appVersion);
    }
    // scroll the menu to the very top (at the top of the header)
    // set in a runnable such that this is called when the system decides, an not too early.
    this.drawerListMenu.post(new Runnable() {
        @Override
        public void run() {
            drawerListMenu.smoothScrollToPositionFromTop(0, 0);
        }
    });

    this.drawerLayout.bringToFront();
    this.drawerListMenu.bringToFront();
    this.drawerListMenu.setOnItemClickListener(this.getOnClickDrawerItemListener());

    // Assign a ListAdapter to our Drawer
    DrawerListAdapter adapter = new DrawerListAdapter(ApplicationHelper.getApplicationContext(),
            this.drawerItems);
    drawerListMenu.setAdapter(adapter);

    this.drawerToggle = new ActionBarDrawerToggle(this, this.drawerLayout, this.toolbar,
            R.string.focus_drawer_open_description, R.string.focus_drawer_close_description);

    // overrides getSupportActionBar().setDisplayHomeAsUpEnabled
    this.drawerToggle.setDrawerIndicatorEnabled(true);

    // Set the drawer toggle as the DrawerListener
    this.drawerLayout.addDrawerListener(drawerToggle);

    // set a subtitle
    this.actionBar.setSubtitle(FocusAppLogic.getCurrentApplicationContent().getTitle());
}

From source file:com.mooshim.mooshimeter.main.ScanActivity.java

private void addDevice(final MooshimeterDevice d) {
    mEmptyMsg.setVisibility(View.GONE);

    if (mMeterList.contains(d)) {
        // The meter as already been added
        Log.e(TAG, "Tried to add the same meter twice");
        return;/*from   ww w . ja va2  s  . com*/
    }

    mMeterList.add(d);
    mMeterDict.put(d.getAddress(), d);

    final LinearLayout wrapper = new LinearLayout(this);
    wrapper.setOrientation(LinearLayout.VERTICAL);
    wrapper.setLayoutParams(mDeviceScrollView.getLayoutParams());

    wrapper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (d.mConnectionState == BluetoothProfile.STATE_CONNECTED
                    || d.mConnectionState == BluetoothProfile.STATE_CONNECTING) {
                startSingleMeterActivity(d);
            } else {
                final Button bv = (Button) view.findViewById(R.id.btnConnect);
                toggleConnectionState(bv, d);
            }
        }
    });

    wrapper.addView(mInflater.inflate(R.layout.element_mm_titlebar, wrapper, false));
    //wrapper.setTag(Integer.valueOf(R.layout.element_mm_titlebar));

    refreshMeterTile(d, wrapper);
    mDeviceScrollView.addView(wrapper);
    mTileList.add(wrapper);

    if (mMeterList.size() > 1)
        setStatus(mMeterList.size() + " devices");
    else
        setStatus("1 device");
}

From source file:org.otempo.view.StationActivity.java

/**
 * Actualiza la parte del layout que visualiza predicciones
 *//*from w  w w.  j av a  2 s.  co m*/
private void updateLayout() {

    final LinearLayout scrolled = findViewById(R.id.scrolled);
    scrolled.removeAllViews();
    final LinearLayout predictedGroup = findViewById(R.id.predictedGroup);
    if (predictedGroup != null) { // en landscape no hay
        predictedGroup.setVisibility(LinearLayout.INVISIBLE);
    }
    final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutUtils.dips(75, this),
            LinearLayout.LayoutParams.WRAP_CONTENT);
    Station currentStation = _stationManager.getStation();
    if (currentStation == null) {
        // Si no hay estacin elegida, nada ms que hacer...
        return;
    }
    final int currentStationId = currentStation.getId();
    if (currentStation.getPredictions().size() > 0) {
        removeDialog(DIALOG_LOADING_ID);
        if (predictedGroup != null) { // en landscape no hay
            final TextView predictionTime = findViewById(R.id.predictionTime);
            predictionTime.setText(getPredictionTimeString(currentStation.getLastCreationDate()));
            predictedGroup.setVisibility(LinearLayout.VISIBLE);
        }
        currentStation.acceptPredictionVisitor(new StationPredictionVisitor() {
            @Override
            public void apply(@NonNull StationShortTermPrediction shortPred, final int index) {
                Calendar predictionDate = shortPred.getDate();
                if (predictionDate == null || !DateUtils.isFromToday(predictionDate)) {
                    return;
                }
                LinearLayout day = new LinearLayout(StationActivity.this);
                day.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                        showDialog(DIALOG_DAY_COMMENT_MASK + index + currentStationId * MAX_PREDICTED_DAYS);
                    }
                });
                day.setOrientation(LinearLayout.VERTICAL);
                TextView dayName = getDayName(shortPred.getDate());
                day.addView(dayName);
                ImageView morningIcon = new ImageView(StationActivity.this);
                morningIcon.setImageResource(ResourceUtils.getResource(shortPred.getSkyStateMorning(), true));
                day.addView(morningIcon);
                ImageView afternoonIcon = new ImageView(StationActivity.this);
                afternoonIcon
                        .setImageResource(ResourceUtils.getResource(shortPred.getSkyStateAfternoon(), true));
                day.addView(afternoonIcon);
                ImageView nightIcon = new ImageView(StationActivity.this);
                nightIcon.setImageResource(ResourceUtils.getResource(shortPred.getSkyStateNight(), false));
                day.addView(nightIcon);
                TextView temps = new TextView(StationActivity.this);
                temps.setText(shortPred.getMinTemp() + " - " + shortPred.getMaxTemp() + " C");
                temps.setGravity(Gravity.CENTER_HORIZONTAL);
                day.addView(temps);
                if (DateUtils.isToday(predictionDate)) {
                    day.setBackgroundResource(R.drawable.today_bg);
                    temps.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                    dayName.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                }
                scrolled.addView(day, params);
            }

            @Override
            public void apply(@NonNull StationMediumTermPrediction medPred, final int index) {
                Calendar predictionDate = medPred.getDate();
                if (predictionDate == null || !DateUtils.isFromToday(predictionDate)) {
                    return;
                }
                LinearLayout day = new LinearLayout(StationActivity.this);
                day.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                        showDialog(DIALOG_DAY_COMMENT_MASK + index + currentStationId * MAX_PREDICTED_DAYS);
                    }
                });
                day.setOrientation(LinearLayout.VERTICAL);
                TextView dayName = getDayName(medPred.getDate());
                day.addView(dayName);
                ImageView morningIcon = new ImageView(StationActivity.this);
                morningIcon.setImageResource(ResourceUtils.getResource(medPred.getSkyState(), true));
                day.addView(morningIcon);
                TextView temps = new TextView(StationActivity.this);
                temps.setText(medPred.getMinTemp() + " - " + medPred.getMaxTemp() + " C");
                temps.setGravity(Gravity.CENTER_HORIZONTAL);
                temps.setTextColor(Color.WHITE);
                day.addView(temps);
                scrolled.addView(day, params);
            }
        });
    } else {
        // Ahora mostramos el dilogo si hace falta, y sino borramos la marca de skip
        if (_skipDialog) {
            _skipDialog = false;
        } else {
            if (!this.isFinishing()) {
                showDialog(DIALOG_LOADING_ID);
                fetchThenShow(currentStation, false);
            }
        }
    }
}

From source file:com.eugene.fithealthmaingit.UI.SaveSearchAddItemActivityMain.java

private void updateItems() {

    mServingSizeUpdated.setText("1");

    LinearLayout changeServing = (LinearLayout) findViewById(R.id.changeServing);
    changeServing.setOnClickListener(new View.OnClickListener() {
        @Override/*w  w w.j  a v a 2  s  .c o m*/
        public void onClick(View v) {
            AlertDialog.Builder alert = new AlertDialog.Builder(SaveSearchAddItemActivityMain.this);

            alert.setTitle("Update Serving Size: ");
            alert.setMessage("Servings Consumed");

            final EditText input = new EditText(SaveSearchAddItemActivityMain.this);
            input.setText(mServingg.getText().toString());
            input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            input.selectAll();
            input.setGravity(Gravity.CENTER_HORIZONTAL);
            alert.setView(input, 64, 0, 64, 0);
            alert.setPositiveButton("Update", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    double values = Double.valueOf(input.getText().toString());
                    mServingg.setText(df.format(values));
                    mServingSizeUpdated.setText(df.format(values));
                    mCalUpdate.setText(dfW.format(Double.valueOf(mCalories) * values));
                    mCalorieProgress = Double.valueOf(mCalories) * values;
                    mFattieUpdate.setText(df.format(Double.valueOf(mFat) * values));
                    mFatProgress = Double.valueOf(mFat) * values;
                    mSaturatedFatUpdate.setText(df.format(Double.valueOf(mSaturatedFat) * values));
                    mCholesterolUpdate.setText(df.format(Double.valueOf(mCholesterol) * values));
                    mSodiumUpdate.setText(df.format(Double.valueOf(mSodium) * values));
                    mCarbUpdate.setText(df.format(Double.valueOf(mCarbohydrates) * values));
                    mCarbProgress = Double.valueOf(mCarbohydrates) * values;
                    mFiberUpdate.setText(df.format(Double.valueOf(mFiber) * values));
                    mSugarUpdate.setText(df.format(Double.valueOf(mSugar) * values));
                    mProUpdate.setText(df.format(Double.valueOf(mProtein) * values));
                    mProteinProgress = Double.valueOf(mProtein) * values;
                    mVitAUpdate.setText(df.format(Double.valueOf(mVitA) * values));
                    mVitCUpdate.setText(df.format(Double.valueOf(mVitC) * values));
                    mCalciumUpdate.setText(df.format(Double.valueOf(mCalcium) * values));
                    mIronUpdate.setText(df.format(Double.valueOf(mIron) * values));
                    progressBars();
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(input.getWindowToken(), 0);
                }
            });
            alert.setCancelable(false);
            alert.show();
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                    .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    });

}