Example usage for android.widget Button Button

List of usage examples for android.widget Button Button

Introduction

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

Prototype

public Button(Context context) 

Source Link

Document

Simple constructor to use when creating a button from code.

Usage

From source file:com.fa.imaged.activity.DetailActivityV2.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mApp = new InstagramApp(getBaseContext(), ApplicationData.CLIENT_ID, ApplicationData.CLIENT_SECRET,
            ApplicationData.CALLBACK_URL);
    // Get Theme Info
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    selectedTheme = prefs.getString("theme_color", "0");
    selectedThemeInt = Integer.parseInt(selectedTheme);
    themePrimaryColors = getResources().getStringArray(R.array.themeColorsPrimary);
    themePrimaryDarkColors = getResources().getStringArray(R.array.themeColorsPrimaryDark);

    headerHeight = getResources().getDimensionPixelSize(R.dimen.action_bar_max_height);
    minHeaderHeight = getResources().getDimensionPixelSize(R.dimen.action_bar_height);
    toolbarTitleLeftMargin = getResources().getDimensionPixelSize(R.dimen.toolbar_left_margin);

    detailImageLoaderv2 = (InstagramImage) getIntent().getSerializableExtra("EXTRA_DATA");

    detailVideoV2 = (VideoView) findViewById(R.id.post_video);
    detailImageV2 = (ImageView) findViewById(R.id.post_image);
    ViewCompat.setTransitionName(detailImageV2, EXTRA_IMAGE);
    ViewCompat.setTransitionName(detailVideoV2, EXTRA_IMAGE);

    detailScrollView = (ObservableScrollView) findViewById(R.id.detail_scrollview);
    detailUserInfo = (RelativeLayout) findViewById(R.id.detail_userinfo);
    detailShare = (LinearLayout) findViewById(R.id.detail_share);
    detailComments = (LinearLayout) findViewById(R.id.detail_comments);
    detailLike = (LinearLayout) findViewById(R.id.detail_like);

    detailFullName = (TextView) findViewById(R.id.detail_fullname);
    detailUserName = (TextView) findViewById(R.id.detail_username);
    detailDate = (TextView) findViewById(R.id.detail_date);
    detailCaption = (TextView) findViewById(R.id.detail_postcaption);

    detailLikeStatus = (ImageView) findViewById(R.id.detail_likeStatus);
    detailLikeCounts = (TextView) findViewById(R.id.detail_likeCounts);
    detailCommentCounts = (TextView) findViewById(R.id.detail_commentCounts);

    detailProfilePic = (ImageView) findViewById(R.id.detail_user_pic);

    detailvBgLike = (View) findViewById(R.id.vBgLike);
    detailivLike = (ImageView) findViewById(R.id.ivLike);

    Picasso.with(this).load(detailImageLoaderv2.profile_picture).transform(new PicassoRound())
            .into(detailProfilePic);/*ww w  .  j  av a 2  s  .  c  o m*/

    detailFullName.setText(detailImageLoaderv2.full_name);
    detailUserName.setText(detailImageLoaderv2.username + ", ");
    detailDate.setText(detailImageLoaderv2.taken_at);

    if (detailImageLoaderv2.user_has_liked) {
        Drawable myIcon = getResources().getDrawable(R.drawable.ic_like);
        myIcon.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
        detailLikeStatus.setImageDrawable(myIcon);
    }

    if (detailImageLoaderv2.caption != null) {
        detailCaption.setText(detailImageLoaderv2.caption);
    } else {
        detailCaption.setVisibility(View.GONE);
    }
    detailLikeCounts.setText(String.valueOf(detailImageLoaderv2.liker_count));
    detailCommentCounts.setText(String.valueOf(detailImageLoaderv2.comment_count));

    detailImageV2.setOnTouchListener(new OnTouchListener() {
        private GestureDetector gestureDetector = new GestureDetector(DetailActivityV2.this,
                new GestureDetector.SimpleOnGestureListener() {
                    boolean isTouchFirst = true;

                    @Override
                    public boolean onDoubleTap(MotionEvent eV) {
                        animatePhotoLike();
                        if (!detailImageLoaderv2.user_has_liked) {
                            HeartPostTask liker = new HeartPostTask(detailImageLoaderv2, true, 0);
                            liker.execute();
                            try {
                                detailImageLoaderv2 = liker.get();
                            } catch (InterruptedException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (ExecutionException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            if (detailImageLoaderv2.user_has_liked) {
                                Drawable myIcon = getResources().getDrawable(R.drawable.ic_like);
                                myIcon.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
                                detailLikeStatus.setImageDrawable(myIcon);
                            }
                            detailLikeCounts.setText(String.valueOf(detailImageLoaderv2.liker_count));
                        }
                        return super.onDoubleTap(eV);
                    }

                    // implement here other callback methods like onFling, onScroll as necessary
                    @Override
                    public boolean onSingleTapConfirmed(MotionEvent e) {
                        if (isTouchFirst) {
                            isTouchFirst = false;

                            getToolbar().animate().translationY(-getToolbar().getBottom()).alpha(0)
                                    .setDuration(320).setInterpolator(new DecelerateInterpolator());

                        } else {
                            isTouchFirst = true;
                            getToolbar().animate().translationY(0).alpha(1).setDuration(400)
                                    .setInterpolator(new DecelerateInterpolator());

                            //mSystemUiHider.show();
                            Log.d("Here isTouch is false", ">");

                        }
                        return true;
                    }
                });

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            gestureDetector.onTouchEvent(event);
            return true;
        }
    });
    detailShare.setOnClickListener(this);
    detailLike.setOnClickListener(this);
    detailProfilePic.setOnClickListener(this);
    detailScrollView.getViewTreeObserver()
            .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {

                @Override
                public void onScrollChanged() {

                    int scroll = detailScrollView.getScrollY();
                    saveInitialScroll(scroll);
                    /*
                    if(detailUserInfo != null){
                       if (getAlpha(-scroll - getToolbar().getHeight()) >= 1.0f) {
                          detailUserInfo.setTranslationY(-detailUserInfo.getHeight() + getToolbar().getHeight());
                       }
                       else {
                          detailUserInfo.setTranslationY(-scroll - detailUserInfo.getHeight());
                       }
                    }
                    */
                    findViewById(R.id.detail_image_container)
                            .setTranslationY(Math.max(0, detailScrollView.getScrollY() + minHeaderTranslation));

                    float offset = 1 - Math.max((float) (-minHeaderTranslation - detailScrollView.getScrollY())
                            / -minHeaderTranslation, 0f);

                    // Now that we have this ratio, we only have to apply translations, scales,
                    // alpha, etc. to the header views

                    // For instance, this will move the toolbar title & subtitle on the X axis 
                    // from its original position when the ListView will be completely scrolled
                    // down, to the Toolbar title position when it will be scrolled up.
                    //detailFullName.setTranslationX(toolbarTitleLeftMargin * offset);
                    //detailUserName.setTranslationX(toolbarTitleLeftMargin * offset);
                    //detailProfilePic.animate().alpha(1.0f * offset).translationX(-toolbarTitleLeftMargin * offset);
                }
            });
    commentsAdapter = new CommentsAdapter(this, detailImageLoaderv2.comment_list);
    if (detailImageLoaderv2.comment_count > 8) {
        Button load_more_button = new Button(this);
        load_more_button.setText(getResources().getString(R.string.load_old_comments));
        load_more_button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), getResources().getString(R.string.coming_soon),
                        Toast.LENGTH_SHORT).show();

            }
        });
        detailComments.addView(load_more_button, 0);
    }
    for (int i = 0; i < commentsAdapter.getCount(); i++) {

        View item = commentsAdapter.getView(i, null, detailComments);

        detailComments.addView(item);
    }
}

From source file:fi.mikuz.boarder.gui.internet.DownloadBoard.java

private void fillBoard(String favoriteText) {
    DownloadBoard.this.setTitle(mBoard.getUploaderUsername() + " - " + mBoard.getBoardName());

    TextView description = (TextView) findViewById(R.id.descriptionText);
    description.setText(mBoard.getDescription() + "\n\n");

    final TextView version = (TextView) findViewById(R.id.versionText);
    final String versionStr = "Version " + mBoard.getBoardVersion() + "\n";

    if (mBoard.getBoardVersion() > mBoard.getFavoriteBoardVersion() && mBoard.getFavoriteBoardVersion() != -1) {
        version.setText(versionStr + "Your version is " + mBoard.getFavoriteBoardVersion());
        final Button versionButton = (Button) findViewById(R.id.versionButton);
        versionButton.setVisibility(View.VISIBLE);
        versionButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                HashMap<String, String> sendList = new HashMap<String, String>();
                sendList.put(InternetMenu.USER_ID_KEY, mUserId);
                sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                sendList.put(InternetMenu.BOARD_ID_KEY, Integer.toString(mBoard.getBoardId()));
                new ConnectionManager(DownloadBoard.this, InternetMenu.mUpdateFavoriteBoardURL, sendList);

                version.setText(versionStr);
                versionButton.setVisibility(View.GONE);
            }//from w w  w.  j  a  va  2  s . co  m
        });
    } else {
        version.setText(versionStr);
    }

    Button comments = (Button) findViewById(R.id.comments);
    comments.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(DownloadBoard.this, DownloadBoardComments.class);
            XStream xstream = new XStream();
            i.putExtra(BOARD_KEY, xstream.toXML(mBoard));
            i.putExtra(DownloadBoardList.LOGGED_IN_KEY, mLoggedIn);

            if (mLoggedIn) {
                i.putExtra(InternetMenu.USER_ID_KEY, mUserId);
                i.putExtra(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
            }

            startActivity(i);
        }
    });

    mFavorite = (Button) findViewById(R.id.favorite);
    if (favoriteText != null) {
        mFavorite.setText(favoriteText);
    }
    mFavorite.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mLoggedIn) {
                HashMap<String, String> sendList = new HashMap<String, String>();
                sendList.put(InternetMenu.USER_ID_KEY, mUserId);
                sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                sendList.put(InternetMenu.BOARD_ID_KEY, Integer.toString(mBoard.getBoardId()));
                new ConnectionManager(DownloadBoard.this, InternetMenu.mFavoriteURL, sendList);
            } else {
                Toast.makeText(DownloadBoard.this, "Please login to favorite", Toast.LENGTH_LONG).show();
            }
        }
    });

    LinearLayout buttonLayout = (LinearLayout) findViewById(R.id.buttonLayout);
    for (final String boardUrl : mBoard.getUrlList()) {
        if (!boardUrl.equals("")) {
            Button boardUrlBtn = new Button(DownloadBoard.this);
            boardUrlBtn.setText(boardUrl);
            boardUrlBtn.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {
                        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(boardUrl));
                        startActivity(browserIntent);
                    } catch (ActivityNotFoundException e) {
                        Log.e(TAG, "Unable to open board url", e);
                        ACRA.getErrorReporter().handleException(e);
                    }
                }
            });
            buttonLayout.addView(boardUrlBtn);
        }
    }

    mScreenshot = (ImageView) findViewById(R.id.screenshot);

    try {
        URL screenshotUrl = new URL(mBoard.getScreenshot0Url());
        new DownloadScreenshot().execute(screenshotUrl);
    } catch (MalformedURLException e) {
        Log.e(TAG, "Error downloading screenshot " + e.getMessage());
        setProgressBarIndeterminateVisibility(false);
    }

    mThumbUpImage = (ImageView) findViewById(R.id.thumbUp);
    mThumbDownImage = (ImageView) findViewById(R.id.thumbDown);

    if (mLoggedIn) {

        HashMap<String, String> sendList = new HashMap<String, String>();
        sendList.put(InternetMenu.USER_ID_KEY, mUserId);
        sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
        sendList.put(InternetMenu.BOARD_ID_KEY, Integer.toString(mBoard.getBoardId()));
        new ConnectionManager(DownloadBoard.this, InternetMenu.mGetBoardThumbStatusURL, sendList);

        mThumbUpImage.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                HashMap<String, String> sendList = new HashMap<String, String>();
                sendList.put(InternetMenu.USER_ID_KEY, mUserId);
                sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                sendList.put(InternetMenu.BOARD_ID_KEY, Integer.toString(mBoard.getBoardId()));
                sendList.put(InternetMenu.RATE_GOOD_KEY, "1");
                new ConnectionManager(DownloadBoard.this, InternetMenu.mRateBoardURL, sendList);
            }
        });

        mThumbDownImage.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                HashMap<String, String> sendList = new HashMap<String, String>();
                sendList.put(InternetMenu.USER_ID_KEY, mUserId);
                sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                sendList.put(InternetMenu.BOARD_ID_KEY, Integer.toString(mBoard.getBoardId()));
                sendList.put(InternetMenu.RATE_GOOD_KEY, "0");
                new ConnectionManager(DownloadBoard.this, InternetMenu.mRateBoardURL, sendList);
            }
        });
    } else {
        mWaitDialog.dismiss();

        mThumbUpImage.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(DownloadBoard.this, "Please login to vote", Toast.LENGTH_LONG).show();
            }
        });

        mThumbDownImage.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(DownloadBoard.this, "Please login to vote", Toast.LENGTH_LONG).show();
            }
        });
    }
}

From source file:it.ielettronica.TVS.MyListAdapterExt.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    //If there's no recycled view, inflate one and tag each of the views
    //you'll want to modify later
    //Log.d("Inside", "GetView");

    plv = null;/*w w w.  j a v a2 s . c  o m*/
    if (convertView == null) {

        convertView = mInflater.inflate(R.layout.row_site_remote, parent, false);
        plv = new PlaylistValues();

        plv.nameTxt = (TextView) convertView.findViewById(R.id.nameTxt);
        plv.aboutTxt = (TextView) convertView.findViewById(R.id.aboutTxt);
        plv.iconImg = (ImageView) convertView.findViewById(R.id.iconImg);
        plv.btnPlayLocal = (Button) convertView.findViewById(R.id.btnPlayLocal);
        plv.indicator = (ProgressBar) convertView.findViewById(R.id.progress);
        plv.btnAddLocal = (Button) convertView.findViewById(R.id.btnAddLocal);
        plv.imageState = (ImageView) convertView.findViewById(R.id.imgState);
        plv.btnEditDel = (Button) convertView.findViewById(R.id.btnEditDel);
        //This assumes layout/row_left.xml includes a TextView with an id of "textview"
        convertView.setTag(plv);
    } else {
        plv = (PlaylistValues) convertView.getTag();
    }

    //Initially we want the progress indicator visible, and the image invisible
    plv.indicator.setVisibility(View.VISIBLE);
    plv.iconImg.setVisibility(View.INVISIBLE);

    if (MainActivity.isAmministrator()) {
        plv.btnEditDel.setVisibility(View.VISIBLE);
    } else {
        plv.btnEditDel.setVisibility(View.INVISIBLE);
    }

    //Retrieve the tagged view, get the item for that position, and
    //update the text

    ImageLoadingListener listener = new ImageLoadingListener() {

        @Override
        public void onLoadingStarted(String arg0, View arg1) {
            // TODO Auto-generated method stub
            plv.indicator.setVisibility(View.INVISIBLE);
            plv.iconImg.setVisibility(View.VISIBLE);

        }

        @Override
        public void onLoadingCancelled(String arg0, View arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
            //plv.indicator.setVisibility(View.INVISIBLE);
            //plv.iconImg.setVisibility(View.VISIBLE);
        }

        @Override
        public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
            // TODO Auto-generated method stub

        }

    };

    stk = mItems.get(position);
    plv.nameTxt.setText(stk.getName());
    plv.aboutTxt.setText(stk.getAbout());

    String uri = "@drawable/myresource"; // where myresource.png is the file
    // extension removed from the String

    if (MainActivity.isAmministrator() == Boolean.TRUE) {
        Drawable res;
        if (stk.getAccepted() == 1) {
            res = ContextCompat.getDrawable(MainActivity.getAppContext(), R.drawable.good);
        } else {
            res = ContextCompat.getDrawable(MainActivity.getAppContext(), R.drawable.warning);
        }
        plv.imageState.setImageDrawable(res);
    }

    imageLoader.displayImage(stk.getImgUrl(), plv.iconImg, options, listener);

    plv.btnEditDel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            final StackSite stkloc = mItems.get(position);
            MainActivity.posRemoteListBeforeExecuted = sitesMusic.getFirstVisiblePosition();
            Intent intent = new Intent(MainActivity.getAppContext(), ModChannel.class);

            intent.putExtra("TitleChannel", stkloc.getName());
            intent.putExtra("DescrChannel", stkloc.getAbout());
            intent.putExtra("IconChannel", stkloc.getImgUrl());
            intent.putExtra("isAccepted", stkloc.getAccepted());
            intent.putExtra("NameGroup", GroupVSeletced.getGroupName());
            intent.putExtra("LevelGroup", GroupVSeletced.getGroupLevel());
            intent.putExtra("TypeGroup", GroupVSeletced.getGroupType());

            intent.putExtra("GroupLevel", GroupVSeletced.getGroupLevel());
            tabFromDB.fa.startActivity(intent);

        }
    });

    plv.btnPlayLocal.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            //                final Intent intent = new Intent(v.getContext(), MediaPlayerDemo_Video.class);
            final StackSite stkloc = mItems.get(position);
            MainActivity.posRemoteListBeforeExecuted = sitesMusic.getFirstVisiblePosition();

            GroupType = GroupVSeletced.getGroupType();

            RemoteCommunications rm = new RemoteCommunications();
            List<StackLink> Links = new ArrayList<StackLink>();
            rm.getLinks(Links, stkloc.getName(), new GetLinkCallback() {
                @Override
                public void done(List<StackLink> returnedLinks) {
                    List<StackLink> Links = returnedLinks;
                    if (Links.size() == 1) {
                        MainActivity.posLocalListBeforeExecuted = tabFromDB.sitesMusic
                                .getFirstVisiblePosition();
                        if (MainActivity.isAmministrator()) {

                            Intent intent = new Intent(MainActivity.getAppContext(), LinksLists.class);
                            intent.putExtra("VideoStreamName", stkloc.getName());
                            intent.putExtra("GroupType", GroupType);

                            tabFromDB.fa.startActivity(intent);

                        } else {
                            String linkVal = Links.get(0).getLinkValue();
                            //Uri myUri = Uri.parse(linkVal);

                            if (GroupType == 0) {

                                Intent mpdIntent = new Intent(tabLocal.Fa.getContext(), PlayerActivity.class)
                                        .setData(Uri.parse(linkVal))
                                        .putExtra(PlayerActivity.CONTENT_ID_EXTRA, "")
                                        .putExtra(PlayerActivity.CONTENT_TYPE_EXTRA, PlayerActivity.TYPE_HLS)
                                        .putExtra(PlayerActivity.PROVIDER_EXTRA, "");
                                tabFromDB.fa.getContext().startActivity(mpdIntent);

                            } else if (GroupType == 1) {

                                //                                    Intent intent2 = new Intent(tabLocal.Fa.getContext(), MediaPlayerDemo_VideoView.class);
                                //                                    intent2.putExtra("pathValue", linkVal);
                                //                                    tabFromDB.fa.getContext().startActivity(intent2);

                            } else {

                                //                                    intent.putExtra("media", 5);
                                //                                    intent.putExtra("pathValue", linkVal);
                                //
                                //                                    try {
                                //                                        tabFromDB.fa.startActivity(intent);
                                //                                    } catch (Exception ex) {
                                //                                        Toast.makeText(cloc, ex.toString(),
                                //                                                Toast.LENGTH_SHORT).show();
                                //                                    }

                            }

                            Toast.makeText(cloc, "Play: " + stkloc.getName(), Toast.LENGTH_SHORT).show();

                        }

                    } else if (Links.size() == 0) {
                        Toast.makeText(cloc,
                                "the channel:  '" + stkloc.getName() + "' doesn't have any link associated",
                                Toast.LENGTH_SHORT).show();
                    } else {

                        Intent intent = new Intent(MainActivity.getAppContext(), LinksLists.class);
                        intent.putExtra("VideoStreamName", stkloc.getName());
                        tabFromDB.fa.startActivity(intent);

                    }
                }
            });

        }
    });

    plv.btnAddLocal.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            stkloc = mItems.get(position);

            RemoteCommunications rm = new RemoteCommunications();
            List<StackLink> Links = new ArrayList<StackLink>();
            rm.getLinks(Links, stkloc.getName(), new GetLinkCallback() {
                @Override
                public void done(List<StackLink> returnedLinks) {

                    AlertDialog.Builder alertDialog;
                    try {
                        alertDialog = new AlertDialog.Builder(tabFromDB.fa.getContext());
                    } catch (Exception ex) {
                        alertDialog = new AlertDialog.Builder(MainActivity.getAppContext());
                    }

                    retLinks = returnedLinks;
                    LinearLayout layout = new LinearLayout(MainActivity.getAppContext());
                    layout.setOrientation(LinearLayout.VERTICAL);

                    if (returnedLinks.size() > 1) {

                        LinearLayout rlayoutLink = new LinearLayout(MainActivity.getAppContext());
                        rlayoutLink.setOrientation(LinearLayout.HORIZONTAL);
                        final TextView textView = new TextView(MainActivity.getAppContext());
                        textView.setText("Links:  ");
                        textView.setGravity(Gravity.RIGHT);
                        textView.setLayoutParams(
                                new FrameLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT));
                        rlayoutLink.addView(textView);
                        listLinks = new Spinner(MainActivity.getAppContext());

                        List<String> retLinksString = new ArrayList<String>();
                        for (int i = 0; i < returnedLinks.size(); i++) {
                            retLinksString.add(returnedLinks.get(i).getLinkTxt());
                        }

                        listLinks.setAdapter(new MyCustomAdapter(MainActivity.getAppContext(),
                                R.layout.rowspinnertake, retLinksString, returnedLinks));

                        //ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.getAppContext(), android.R.layout.simple_spinner_item, retLinksString);
                        //adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        //listLinks.setAdapter(adapter);

                        listLinks.setLayoutParams(
                                new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT));

                        rlayoutLink.addView(listLinks);
                        layout.addView(rlayoutLink);
                    }

                    final Button btnAddToTheEnd = new Button(MainActivity.getAppContext());
                    btnAddToTheEnd.setText("Add");

                    btnAddToTheEnd.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {

                            StackSite stkloc = mItems.get(position);

                            if (listLinks != null) {
                                posSpinnerLink = listLinks.getSelectedItemPosition();
                            } else {
                                posSpinnerLink = 0;
                            }

                            if (retLinks.size() == 0) {
                                Toast.makeText(cloc,
                                        "the channel:  '" + stkloc.getName()
                                                + "' doesn't have any link associated",
                                        Toast.LENGTH_SHORT).show();
                            } else {

                                String url;

                                if (retLinks.size() == 1) {

                                    url = retLinks.get(0).getLinkValue();

                                } else {
                                    url = retLinks.get(posSpinnerLink).getLinkValue();
                                }

                                stkloc.setLink(url);
                                stkloc.setTypeStream(GroupVSeletced.getGroupType());
                                stkloc.setStaticName(stkloc.getName());
                                String nameStation = stkloc.getName();
                                stkloc.setOrigin(0);
                                boolean isAdded = dbHandler.addSite(stkloc);
                                if (isAdded) {
                                    Toast.makeText(MainActivity.getAppContext(),
                                            nameStation + " is added in Local Playlist", Toast.LENGTH_SHORT)
                                            .show();
                                }
                                List<StackSite> itemsLocal;
                                itemsLocal = dbHandler.getStackSites();
                                if (itemsLocal.size() == 0) {
                                    tabLocal.editEmptyLocalList.setVisibility(View.VISIBLE);
                                } else {
                                    tabLocal.editEmptyLocalList.setVisibility(View.INVISIBLE);
                                }

                                tabLocal.sitesLocal.setCheeseList(itemsLocal);
                                tabLocal.sitesLocal.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
                                StableArrayAdapter adapterLocal = new StableArrayAdapter(
                                        tabLocal.Fa.getContext(), R.layout.row_site_local, itemsLocal);
                                tabLocal.sitesLocal.setAdapter(adapterLocal);

                                OptionDialog.dismiss();

                            }

                        }
                    });
                    btnAddToTheEnd.setLayoutParams(
                            new FrameLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT));
                    layout.addView(btnAddToTheEnd);

                    final Button btnAddAfter = new Button(MainActivity.getAppContext());
                    final Spinner listChannelAlreadyAdded = new Spinner(MainActivity.getAppContext());
                    List<String> ListNameChannel;
                    ListNameChannel = dbHandler.getNamesFromStackSites();
                    ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(MainActivity.getAppContext(),
                            android.R.layout.simple_spinner_item, ListNameChannel);
                    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    listChannelAlreadyAdded.setAdapter(adapter2);
                    posSpinner = listChannelAlreadyAdded.getSelectedItemPosition();

                    if (posSpinner != -1) {
                        LinearLayout rlayout = new LinearLayout(MainActivity.getAppContext());
                        rlayout.setOrientation(LinearLayout.HORIZONTAL);

                        btnAddAfter.setText("Add Before");
                        btnAddAfter.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {

                                if (listLinks != null) {
                                    posSpinnerLink = listLinks.getSelectedItemPosition();
                                } else {
                                    posSpinnerLink = 0;
                                }

                                StackSite stkloc = mItems.get(position);

                                if (retLinks.size() == 0) {
                                    Toast.makeText(cloc,
                                            "the channel:  '" + stkloc.getName()
                                                    + "' doesn't have any link associated",
                                            Toast.LENGTH_SHORT).show();
                                } else {

                                    String url;

                                    if (retLinks.size() == 1) {

                                        url = retLinks.get(0).getLinkValue();

                                    } else {
                                        url = retLinks.get(posSpinnerLink).getLinkValue();
                                    }

                                    stkloc.setLink(url);
                                    stkloc.setOrigin(0);
                                    stkloc.setTypeStream(GroupVSeletced.getGroupType());
                                    String nameStation = stkloc.getName();
                                    posSpinner = listChannelAlreadyAdded.getSelectedItemPosition();

                                    boolean isAdded = dbHandler.addSiteBefore(stkloc, posSpinner);
                                    if (isAdded) {
                                        Toast.makeText(MainActivity.getAppContext(),
                                                nameStation + " is added in Local Playlist", Toast.LENGTH_SHORT)
                                                .show();
                                    }
                                    List<StackSite> itemsLocal;
                                    itemsLocal = dbHandler.getStackSites();
                                    tabLocal.sitesLocal.setCheeseList(itemsLocal);
                                    tabLocal.sitesLocal.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
                                    StableArrayAdapter adapterLocal = new StableArrayAdapter(
                                            tabLocal.Fa.getContext(), R.layout.row_site_local, itemsLocal);
                                    tabLocal.sitesLocal.setAdapter(adapterLocal);

                                    OptionDialog.dismiss();

                                }

                            }
                        });

                        btnAddAfter.setLayoutParams(
                                new FrameLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT));
                        rlayout.addView(btnAddAfter);
                        listChannelAlreadyAdded.setLayoutParams(
                                new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT));
                        rlayout.addView(listChannelAlreadyAdded);
                        layout.addView(rlayout);
                    }

                    final Button btnCancel = new Button(MainActivity.getAppContext());
                    btnCancel.setText("Cancel");
                    btnCancel.setLayoutParams(
                            new FrameLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT));

                    btnCancel.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            OptionDialog.dismiss();
                        }
                    });

                    layout.addView(btnCancel);
                    alertDialog.setView(layout); // uncomment this line
                    alertDialog.setTitle("Take the Channel");
                    OptionDialog = alertDialog.create();
                    OptionDialog.show();
                }

            });

        }

    });

    return convertView;
}

From source file:org.protocoderrunner.apprunner.AppRunnerFragment.java

public RelativeLayout initLayout() {
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    // add main layout
    mainLayout = new RelativeLayout(mActivity);
    mainLayout.setLayoutParams(layoutParams);
    mainLayout.setGravity(Gravity.BOTTOM);
    // mainLayout.setBackgroundColor(getResources().getColor(R.color.transparent));
    mainLayout.setBackgroundColor(getResources().getColor(R.color.white));

    // set the parent
    parentScriptedLayout = new RelativeLayout(mActivity);
    parentScriptedLayout.setLayoutParams(layoutParams);
    parentScriptedLayout.setGravity(Gravity.BOTTOM);
    parentScriptedLayout.setBackgroundColor(getResources().getColor(R.color.transparent));
    mainLayout.addView(parentScriptedLayout);

    // editor layout
    editorLayout = new FrameLayout(mActivity);
    FrameLayout.LayoutParams editorParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);/* w ww .  jav a 2 s. c om*/
    editorLayout.setLayoutParams(editorParams);
    editorLayout.setId(EDITOR_ID);
    mainLayout.addView(editorLayout);

    // console layout
    consoleRLayout = new RelativeLayout(mActivity);
    RelativeLayout.LayoutParams consoleLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            getResources().getDimensionPixelSize(R.dimen.apprunner_console));
    consoleLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    consoleLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    consoleRLayout.setLayoutParams(consoleLayoutParams);
    consoleRLayout.setGravity(Gravity.BOTTOM);
    consoleRLayout.setBackgroundColor(getResources().getColor(R.color.blacktransparent));
    consoleRLayout.setVisibility(View.GONE);
    mainLayout.addView(consoleRLayout);

    // Create the text view to add to the console layout
    consoleText = new TextView(mActivity);
    LayoutParams consoleTextParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    consoleText.setBackgroundColor(getResources().getColor(R.color.transparent));
    consoleText.setTextColor(getResources().getColor(R.color.white));
    consoleText.setLayoutParams(consoleTextParams);
    int textPadding = getResources().getDimensionPixelSize(R.dimen.apprunner_console_text_padding);
    consoleText.setPadding(textPadding, textPadding, textPadding, textPadding);
    consoleRLayout.addView(consoleText);

    //add a close button
    Button closeBtn = new Button(mActivity);
    closeBtn.setText("x");
    closeBtn.setPadding(5, 5, 5, 5);
    closeBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showConsole(false);
        }
    });
    RelativeLayout.LayoutParams closeBtnLayoutParams = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    closeBtnLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    closeBtnLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    closeBtn.setLayoutParams(closeBtnLayoutParams);
    consoleRLayout.addView(closeBtn);

    liveCoding = new PLiveCodingFeedback(mActivity);
    mainLayout.addView(liveCoding.add());

    return mainLayout;
}

From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java

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

    try {//from   ww w.  ja  va 2s .  com
        Tabs1.db.showfulldblog(Tabs1.db.TABLE_MCR_METERINGLIST);
    } catch (Throwable e) {

    }
    ctx = this;

    try {
        if (Tabs1.foldername.contains("_")) {
            tempfoldername = Tabs1.foldername.substring(0, Tabs1.foldername.indexOf("_"));
        } else {
            tempfoldername = Tabs1.foldername;
        }

        Log.d("foldername", tempfoldername);

        dbtablename = "floorplan";
        if (Tabs1.db.checktableindb(dbtablename)) {
            //
        } else {
            try {
                Tabs1.db.createfloorplandb(dbtablename);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }

        try {
            MULTILEVEL = ReadBoolean(this, "multilevel", false);
        } catch (Throwable e) {
            System.out.println("couldn't read multilevel value from preferences on start");
            MULTILEVEL = false;
        }

        try {
            NGBICONS = ReadBoolean(this, "ngbicons", false);
        } catch (Throwable e) {
            System.out.println("couldn't read autorenumber temp sensors value from preferences on start");
            NGBICONS = true;
        }

        try {
            DRAWSAMREFERENCE = ReadBoolean(this, "drawsamreferencetable", true);
        } catch (Throwable e) {

        }
        try {
            RAPIDPLACEMENT = ReadBoolean(this, "rapidplacement", false);
        } catch (Throwable e) {

        }

        // Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        // Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        Intent intent = getIntent();

        FloorPlanActivity.floorplannumber = intent.getExtras().getInt("floorplannumber");
        try {
            FloorPlanActivity.floorplancount = Tabs1.FloorPlanCount;
        } catch (Throwable e) {
            FloorPlanActivity.floorplancount = new File(Tabs1.inputfloorplandirectory).list().length;
        }
        MODE = MODE_DONOTHING;

        progressDialog = new ProgressDialog(this);
        progressDialog.setIndeterminate(true);
        if (tempfoldername.equals("Paul")) {
            progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.anim.paul_animation));

        } else if (tempfoldername.equals("Will")) {
            progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.anim.will_animation));

        } else if (tempfoldername.equals("Bill")) {
            progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.anim.bill_animation));
        } else {
            progressDialog.setIndeterminateDrawable(
                    getResources().getDrawable(R.anim.progress_dialog_icon_drawable_animation));

        }

        progressDialog.setIcon(R.drawable.ic_launcher);
        progressDialog.setTitle("Loading");
        progressDialog.setMessage("Please Wait");
        progressDialog.setCancelable(false);

        rl = new RelativeLayout(this);
        RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
        rl.setLayoutParams(rllp);

        toolbar = new View(this);
        LayoutInflater inflater = (LayoutInflater) getBaseContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        toolbar = inflater.inflate(R.layout.toolbar, null);

        toptoolbar = (View) toolbar.findViewById(R.id.toptoolbar);
        righttoolbar = (View) toolbar.findViewById(R.id.righttoolbar);
        righttoolbarbuttonparent = (View) toolbar.findViewById(R.id.righttoolbarbuttonparent);

        righttoolbarscrollview = (ScrollView) toolbar.findViewById(R.id.righttoolbarscrollview);

        floorplanprevious = (ImageView) toolbar.findViewById(R.id.floorplanprevious);
        floorplannext = (ImageView) toolbar.findViewById(R.id.floorplannext);
        fullscreen = (ImageView) toolbar.findViewById(R.id.fullscreen);
        unfullscreen = (ImageView) toolbar.findViewById(R.id.unfullscreen);
        showlayers = (ImageView) toolbar.findViewById(R.id.layers);
        resizeicons = (ImageView) toolbar.findViewById(R.id.resizeicons);
        metersperpixelbutton = (ImageView) toolbar.findViewById(R.id.metersperpixelbutton);

        resizeiconsseekbar = (SeekBar) toolbar.findViewById(R.id.resizeiconsseekbar);
        resizeiconsseekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                // TODO Auto-generated method stub
                view.invalidate();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }
        });

        resizeiconscancel = (Button) toolbar.findViewById(R.id.resizeiconscancel);
        resizeiconsfinished = (Button) toolbar.findViewById(R.id.resizeiconsfinished);

        preferences = (ImageView) toolbar.findViewById(R.id.preferences);

        floorplantitle = (TextView) toolbar.findViewById(R.id.floorplantitle);
        BMS = (ImageView) toolbar.findViewById(R.id.bms);
        ELC = (ImageView) toolbar.findViewById(R.id.elc);
        Gateway = (ImageView) toolbar.findViewById(R.id.gateway);
        SAM = (ImageView) toolbar.findViewById(R.id.sam);
        tempsensor = (ImageView) toolbar.findViewById(R.id.tempsensor);
        ethernetport = (ImageView) toolbar.findViewById(R.id.ethernetport);
        distributionboard = (ImageView) toolbar.findViewById(R.id.distributionboard);
        samarray = (ImageView) toolbar.findViewById(R.id.samarray);
        datahub = (ImageView) toolbar.findViewById(R.id.datahub);

        AddText = (ImageView) toolbar.findViewById(R.id.addtexttofloorplan);

        legend = (ImageView) toolbar.findViewById(R.id.legend);

        hiddenaddpicturebutton = new Button(this);
        hiddenaddpicturebutton.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {

                int tabforpicture = view.gettabofitemselected(view.itemselectednumber);
                String foldername = view.getGenericDisplayText(view.itemselectednumber);

                //   System.out.println("this is the name of the new file to be saved."+imageF.getAbsolutePath());
                //takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                //      Uri.fromFile(imageF));

                Intent takePictureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
                u.log("starting activity camera");

                PICTURESTARTTIME = System.currentTimeMillis();
                TABFORGETPICTURE = tabforpicture;
                FOLDERNAMEFORGETPICTURE = foldername;

                startActivityForResult(takePictureIntent, FLOORPLANGETPICFROMCAMERA);

            }
        });
        hiddeneditpicturebutton = new Button(this);
        hiddeneditpicturebutton.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {

                Intent intent = u.openpicture(editpicturelocation);
                System.out.println("this is the name of the file to be edited." + editpicturelocation);
                startActivityForResult(intent, EDITPICTUREACTIVITY);

            }
        });
        floorplantitle.setTextColor(view.presentableblue);
        floorplantitle.setText(Tabs1.floorplanname);

        floorplanprevious.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                ACTION = ACTION_FLOORPLANPREVIOUS;
                view.invalidate();
            }
        });
        floorplannext.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                ACTION = ACTION_FLOORPLANNEXT;
                view.invalidate();
            }
        });
        fullscreen.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {

                ACTION = ACTION_FULLSCREEN;
                toptoolbar.setVisibility(View.INVISIBLE);
                righttoolbar.setVisibility(View.INVISIBLE);
                unfullscreen.setVisibility(View.VISIBLE);

            }
        });

        unfullscreen.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                ACTION = ACTION_UNFULLSCREEN;
                toptoolbar.setVisibility(View.VISIBLE);
                righttoolbar.setVisibility(View.VISIBLE);
                unfullscreen.setVisibility(View.INVISIBLE);

            }
        });
        showlayers.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                Log.d("show layers selected", "true");
                if (!(ACTION == ACTION_SHOWLAYERS)) {
                    ACTION = ACTION_SHOWLAYERS;
                } else {
                    ACTION = ACTION_DONOTHING;
                }
                view.invalidate();

            }
        });
        metersperpixelbutton.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                //show dialog asking if you want scale from google maps, or from 2 points on map
                getscaledialog();
                //startActivity(u.intent("Getscalefromgooglemaps"));

            }
        });

        resizeicons.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                view.resizeboolean = true;
                ACTION = ACTION_RESIZEICONS;
                toptoolbar.setVisibility(View.INVISIBLE);
                righttoolbar.setVisibility(View.INVISIBLE);

                resizeiconsseekbar.setVisibility(View.VISIBLE);
                resizeiconscancel.setVisibility(View.VISIBLE);
                resizeiconsfinished.setVisibility(View.VISIBLE);

            }
        });
        resizeiconscancel.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View arg0) {
                //restore size
                //resizeiconsseekbar.setProgress((int)((float)resizeiconsseekbar.getMax()/(float)4));
                view.invalidate();
                ACTION = ACTION_DONOTHING;
                toptoolbar.setVisibility(View.VISIBLE);
                righttoolbar.setVisibility(View.VISIBLE);

                resizeiconsseekbar.setVisibility(View.INVISIBLE);
                resizeiconscancel.setVisibility(View.INVISIBLE);
                resizeiconsfinished.setVisibility(View.INVISIBLE);

            }
        });
        resizeiconsfinished.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View arg0) {
                if (ACTION == ACTION_RESIZEICON) {
                    writeonedbitem(view.itemselectednumber);
                } else {
                    rewritewholedb();
                }

                ACTION = ACTION_DONOTHING;
                toptoolbar.setVisibility(View.VISIBLE);
                righttoolbar.setVisibility(View.VISIBLE);

                resizeiconsseekbar.setVisibility(View.INVISIBLE);
                resizeiconscancel.setVisibility(View.INVISIBLE);
                resizeiconsfinished.setVisibility(View.INVISIBLE);

            }
        });

        preferences.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                ACTION = ACTION_PREFERENCES;
                //preferences();
                startActivityForResult(u.intent("FloorPlanPrefs"), PREFS);
            }
        });

        BMS.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_BMS;
                Log.d("mode", u.s(MODE));

            }
        });
        ELC.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_ELC;
                Log.d("mode", u.s(MODE));

            }
        });
        Gateway.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_GATEWAY;
                Log.d("mode", u.s(MODE));

            }
        });
        SAM.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                //MODE = MODE_SAM;
                //Log.d("mode", u.s(MODE));
                int itemnum = -1;
                for (int k = 0; k < view.i; k++) {
                    if (view.ITEMtype[k] == view.TYPE_ELC) {
                        itemnum = k;
                    }
                }
                if (!(itemnum == -1)) {
                    view.addsamsdialog("ELC# " + u.s(view.ELCdisplaynumber[itemnum]) + ": SAMs Menu", itemnum);
                }

            }
        });
        tempsensor.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_TEMPSENSOR;
                Log.d("mode", u.s(MODE));

            }
        });
        ethernetport.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_ETHERNETPORT;
                Log.d("mode", u.s(MODE));

            }
        });
        distributionboard.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_DISTRIBUTIONBOARD;
                Log.d("mode", u.s(MODE));

            }
        });
        samarray.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_SAMARRAY;
                Log.d("mode", u.s(MODE));

            }
        });
        datahub.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_DATAHUB;
                Log.d("mode", u.s(MODE));

            }
        });

        AddText.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_ADDTEXT;
                getaddtextdialog("ADD TEXT", view.i, FloorPlanActivity.this).show();
                Log.d("mode", u.s(MODE));

            }
        });

        legend.setOnClickListener(new ImageView.OnClickListener() {
            public void onClick(View arg0) {
                highlightbutton(arg0);
                MODE = MODE_LEGEND;
                Log.d("mode", u.s(MODE));

            }
        });

        view = new FloorPlanView(this);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        rl.addView(view);
        rl.addView(toolbar);

        setContentView(rl);
        //readexcel();

        AUTORENUMBERTEMPS = !Tabs1.db.tableexists(dbtablename);

        WriteBoolean(this, "autorenumbertemps", AUTORENUMBERTEMPS);
        System.out.println("auto number=" + AUTORENUMBERTEMPS);

        readdb();
        grabsamcounts();
        grabelccount();
        System.out.println("item" + " " + "type" + "  " + "tempcount");
        for (int h = 0; h < view.i; h++) {
            System.out.println(h + " " + view.ITEMtype[h] + "  " + view.ITEMtempsensorcount[h]);
        }
    } catch (Throwable e) {
        e.printStackTrace();
        finish();
    }
}

From source file:org.openremote.android.console.AppSettingsActivity.java

/**
 * Creates the clear image cache button, add listener for clear image cache.
 * @return the relative layout//from ww  w  . j ava  2 s.  c om
 */
private RelativeLayout createClearImageCacheButton() {
    RelativeLayout clearImageView = new RelativeLayout(this);
    clearImageView.setLayoutParams(
            new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    Button clearImgCacheBtn = new Button(this);
    clearImgCacheBtn.setText("Clear Image Cache");
    RelativeLayout.LayoutParams clearButtonLayout = new RelativeLayout.LayoutParams(150,
            LayoutParams.WRAP_CONTENT);
    clearButtonLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    clearImgCacheBtn.setLayoutParams(clearButtonLayout);
    clearImgCacheBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            ViewHelper.showAlertViewWithTitleYesOrNo(AppSettingsActivity.this, "",
                    "Are you sure you want to clear image cache?", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            FileUtil.clearImagesInCache(AppSettingsActivity.this);
                        }
                    });
        }
    });

    clearImageView.addView(clearImgCacheBtn);
    return clearImageView;
}

From source file:oyagev.projects.android.ArduCopter.BluetoothChat.java

private void addControl(String name, String type, int commandValue) {

    Log.d(TAG, "Adding cmd: " + commandValue);

    LinearLayout row = new LinearLayout(this);
    row.setOrientation(LinearLayout.HORIZONTAL);
    row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    View view = new TextView(this);

    //hidden view for command value
    TextView cmdView = new TextView(this);
    cmdView.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
    cmdView.setVisibility(View.INVISIBLE);
    cmdView.setText(String.valueOf(commandValue));
    cmdView.setTag("cmd");

    //Setup the control
    if (type.equals("Button")) {
        view = new Button(this);

        ((Button) view).setText(name);
        ((Button) view).setOnClickListener(new OnClickListener() {

            @Override/*w  ww  .j a  va 2  s .c  o  m*/
            public void onClick(View v) {
                TextView cmd = (TextView) ((LinearLayout) v.getParent()).findViewWithTag("cmd");

                dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), new byte[] { 1 });

            }
        });
    } else if (type.equals("Edit")) {
        view = new EditText(this);

        ((EditText) view).setText(name);
    } else if (type.equals("Label")) {
        view = new TextView(this);

        ((TextView) view).setText(name);
    } else if (type.equals("Scrollbar")) {
        view = new LinearLayout(this);

        TextView text = new TextView(this);
        text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        text.setText(name);
        text.setTag("seek_text");
        SeekBar bar = new SeekBar(this);
        bar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        ((LinearLayout) view).setOrientation(LinearLayout.VERTICAL);

        ((LinearLayout) view).addView(text);
        ((LinearLayout) view).addView(bar);

        bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

                TextView cmd = (TextView) ((LinearLayout) ((LinearLayout) seekBar.getParent()).getParent())
                        .findViewWithTag("cmd");

                ByteBuffer buffer = ByteBuffer.allocate(2);
                buffer.putShort((short) progress);

                dispatchUserEvent((int) Integer.valueOf(cmd.getText().toString()), buffer.array());

            }
        });
    } else if (type.equals("Input String")) {
        view = new LinearLayout(this);

        TextView text = new TextView(this);
        text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        text.setText(name);
        text.setTag("inp_text");
        TextView inp = new TextView(this);
        inp.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        //((LinearLayout)view).setOrientation(LinearLayout.VERTICAL);

        ((LinearLayout) view).addView(text);
        ((LinearLayout) view).addView(inp);

        ycomm.registerCallback((byte) commandValue, new CallbackView(getApplicationContext(), inp) {
            @Override
            public void run(byte type, byte command, byte[] data, byte data_langth) {
                // TODO Auto-generated method stub
                String str = new String(data);
                ((TextView) this.view).setText(str);
            }
        });
    } else {
        return;
    }
    view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    row.addView(cmdView);
    row.addView(view);
    ((LinearLayout) findViewById(R.id.controls_layout)).addView(row);

}

From source file:org.zeroxlab.zeroxbenchmark.Benchmark.java

private void initViews() {
        /*/*from  w  w  w  .j a v a 2  s.  c  o m*/
        mRun = (Button)findViewById(R.id.btn_run);
        mRun.setOnClickListener(this);
            
        mShow = (Button)findViewById(R.id.btn_show);
        mShow.setOnClickListener(this);
        mShow.setClickable(false);
            
        mLinearLayout = (LinearLayout)findViewById(R.id.list_container);
        mMainView = (LinearLayout)findViewById(R.id.main_view);
            
        mBannerInfo = (TextView)findViewById(R.id.banner_info);
        mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com");
        */

        mTabHost = getTabHost();

        int length = mCases.size();
        mCheckList = new CheckBox[length];
        mDesc = new TextView[length];
        for (int i = 0; i < length; i++) {
            mCheckList[i] = new CheckBox(this);
            mCheckList[i].setText(mCases.get(i).getTitle());
            mDesc[i] = new TextView(this);
            mDesc[i].setText(mCases.get(i).getDescription());
            mDesc[i].setTextSize(mDesc[i].getTextSize() - 2);
            mDesc[i].setPadding(42, 0, 10, 10);
        }

        TabContentFactory mTCF = new TabContentFactory() {
            public View createTabContent(String tag) {
                ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.FILL_PARENT);
                ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
                LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                wrapContent.gravity = Gravity.CENTER;
                LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                weightedFillWrap.weight = 1;

                if (tag.equals(MAIN)) {
                    LinearLayout mMainView = new LinearLayout(Benchmark.this);
                    mMainView.setOrientation(1);
                    ScrollView mListScroll = new ScrollView(Benchmark.this);

                    LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this);
                    mMainViewContainer.setOrientation(1);
                    ImageView mIconView = new ImageView(Benchmark.this);
                    mIconView.setImageResource(R.drawable.icon);

                    TextView mBannerInfo = new TextView(Benchmark.this);
                    mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:");

                    d2CheckBox = new CheckBox(Benchmark.this);
                    d2CheckBox.setText(D2);
                    d2CheckBox.setOnClickListener(Benchmark.this);

                    d3CheckBox = new CheckBox(Benchmark.this);
                    d3CheckBox.setText(D3);
                    d3CheckBox.setOnClickListener(Benchmark.this);

                    mathCheckBox = new CheckBox(Benchmark.this);
                    mathCheckBox.setText(MATH);
                    mathCheckBox.setOnClickListener(Benchmark.this);

                    vmCheckBox = new CheckBox(Benchmark.this);
                    vmCheckBox.setText(VM);
                    vmCheckBox.setOnClickListener(Benchmark.this);

                    nativeCheckBox = new CheckBox(Benchmark.this);
                    nativeCheckBox.setText(NATIVE);
                    nativeCheckBox.setOnClickListener(Benchmark.this);

                    miscCheckBox = new CheckBox(Benchmark.this);
                    miscCheckBox.setText(MISC);
                    miscCheckBox.setOnClickListener(Benchmark.this);

                    TextView mWebInfo = new TextView(Benchmark.this);
                    mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com");

                    LinearLayout mButtonContainer = new LinearLayout(Benchmark.this);
                    mRun = new Button(Benchmark.this);
                    mShow = new Button(Benchmark.this);
                    mRun.setText("Run");
                    mShow.setText("Show");
                    mRun.setOnClickListener(Benchmark.this);
                    mShow.setOnClickListener(Benchmark.this);
                    mButtonContainer.addView(mRun, weightedFillWrap);
                    mButtonContainer.addView(mShow, weightedFillWrap);
                    WebView mTracker = new WebView(Benchmark.this);
                    mTracker.clearCache(true);
                    mTracker.setWebViewClient(new WebViewClient() {
                        public void onPageFinished(WebView view, String url) {
                            Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url);
                        }

                        public void onReceivedError(WebView view, int errorCode, String description,
                                String failingUrl) {
                            Log.e(TAG, "Track err: " + description);
                        }
                    });
                    mTracker.loadUrl(trackerUrl);
                    mMainViewContainer.addView(mIconView, wrapContent);
                    mMainViewContainer.addView(mBannerInfo);
                    mMainViewContainer.addView(mathCheckBox);
                    mMainViewContainer.addView(d2CheckBox);
                    mMainViewContainer.addView(d3CheckBox);
                    mMainViewContainer.addView(vmCheckBox);
                    mMainViewContainer.addView(nativeCheckBox);
                    mMainViewContainer.addView(miscCheckBox);
                    mMainViewContainer.addView(mWebInfo);
                    mMainViewContainer.addView(mButtonContainer, fillWrap);
                    mMainViewContainer.addView(mTracker, 0, 0);
                    mListScroll.addView(mMainViewContainer, fillParent);
                    mMainView.addView(mListScroll, fillWrap);

                    return mMainView;

                }

                LinearLayout mMainView = new LinearLayout(Benchmark.this);
                mMainView.setOrientation(1);
                ScrollView mListScroll = new ScrollView(Benchmark.this);
                LinearLayout mListContainer = new LinearLayout(Benchmark.this);
                mListContainer.setOrientation(1);
                mListScroll.addView(mListContainer, fillParent);
                mMainView.addView(mListScroll, fillWrap);

                boolean gray = true;
                int length = mCases.size();
                Log.i(TAG, "L: " + length);
                Log.i(TAG, "TCF: " + tag);
                for (int i = 0; i < length; i++) {
                    if (!mCategory.get(tag).contains(mCases.get(i)))
                        continue;
                    Log.i(TAG, "Add: " + i);
                    mListContainer.addView(mCheckList[i], fillWrap);
                    mListContainer.addView(mDesc[i], fillWrap);
                    if (gray) {
                        int color = 0xFF333333; //ARGB
                        mCheckList[i].setBackgroundColor(color);
                        mDesc[i].setBackgroundColor(color);
                    }
                    gray = !gray;
                }
                return mMainView;
            }
        };

        mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(NATIVE)
                .setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc))
                .setContent(mTCF));
    }

From source file:mroza.forms.ChooseProgramActivity.java

private void enableShowAllButton(boolean enable) {
    LinearLayout layout = (LinearLayout) findViewById(R.id.LayoutGrid);
    Button button = (Button) findViewById(R.id.show_all_programs_button_id);

    if (enable && button == null) {
        button = new Button(this);
        button.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        button.setText(R.string.show_all_programs);
        button.setId(R.id.show_all_programs_button_id);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                List<ChildTable> childTables;
                clearFilters(true);//from w w  w. ja v a2  s  .  c om
                clearSearchField();

                Term selectedTerm = getSelectedTerm();
                childTables = ChildTablesRepository.getChildTableByTerm(ChooseProgramActivity.this,
                        selectedTerm, child);
                handleListViewBehavior(childTables, selectedTerm);

                enableShowAllButton(false);
            }
        });
        layout.addView(button, 1);
    } else if (!enable && button != null) {
        layout.removeView(button);
    }
}

From source file:tinygsn.gui.android.ActivityViewDataNew.java

private void addTableViewModeCustomize() {
    table_view_mode = (TableLayout) findViewById(R.id.table_view_mode);
    table_view_mode.removeAllViews();//from   w ww  . java 2  s  . c  o  m

    // Row From
    TableRow row = new TableRow(this);
    TextView txt = new TextView(this);
    txt.setText("From: ");
    txt.setTextColor(Color.parseColor("#000000"));
    row.addView(txt);

    // Date time = new Date();
    startTime = new Date();
    startTime.setMinutes(startTime.getMinutes() - 1);
    endTime = new Date();

    // Start Time
    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
    txtStartTime = new TextView(this);
    txtStartTime.setText(formatter.format(startTime) + "");
    txtStartTime.setTextColor(Color.parseColor("#000000"));
    txtStartTime.setBackgroundColor(Color.parseColor("#8dc63f"));
    row.addView(txtStartTime);

    txtStartTime.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new TimePickerDialog(context, startTimeSetListener, dateAndTime.get(Calendar.HOUR_OF_DAY) - 1,
                    dateAndTime.get(Calendar.MINUTE), true).show();
        }
    });

    // Add space
    txt = new TextView(this);
    txt.setText("     ");
    row.addView(txt);

    // Start Date
    formatter = new SimpleDateFormat("dd/MM/yyyy");
    // txtStartDate, txtStartTime
    txtStartDate = new TextView(this);
    txtStartDate.setText(formatter.format(startTime) + "");
    txtStartDate.setTextColor(Color.parseColor("#000000"));
    txtStartDate.setBackgroundColor(Color.parseColor("#8dc63f"));
    row.addView(txtStartDate);

    txtStartDate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new DatePickerDialog(context, startDateSetListener, dateAndTime.get(Calendar.YEAR),
                    dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
        }
    });

    table_view_mode.addView(row);

    // Add a space row
    row = new TableRow(this);
    txt = new TextView(this);
    txt.setText("-");
    row.addView(txt);
    table_view_mode.addView(row);

    // Row To
    row = new TableRow(this);
    txt = new TextView(this);
    txt.setText("To");
    txt.setTextColor(Color.parseColor("#000000"));
    row.addView(txt);

    // End Time
    formatter = new SimpleDateFormat("HH:mm:ss");
    txtEndTime = new TextView(this);
    txtEndTime.setText(formatter.format(endTime) + "");
    txtEndTime.setTextColor(Color.parseColor("#000000"));
    txtEndTime.setBackgroundColor(Color.parseColor("#8dc63f"));
    row.addView(txtEndTime);

    txtEndTime.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new TimePickerDialog(context, endTimeSetListener, dateAndTime.get(Calendar.HOUR_OF_DAY),
                    dateAndTime.get(Calendar.MINUTE), true).show();
        }
    });

    // Add space
    txt = new TextView(this);
    txt.setText("     ");
    row.addView(txt);

    // End Date
    formatter = new SimpleDateFormat("dd/MM/yyyy");
    // txtStartDate, txtStartTime
    txtEndDate = new TextView(this);
    txtEndDate.setText(formatter.format(endTime) + "");
    txtEndDate.setTextColor(Color.parseColor("#000000"));
    txtEndDate.setBackgroundColor(Color.parseColor("#8dc63f"));
    row.addView(txtEndDate);

    txtEndDate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new DatePickerDialog(context, endDateSetListener, dateAndTime.get(Calendar.YEAR),
                    dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
        }
    });

    table_view_mode.addView(row);

    // Row
    row = new TableRow(this);
    Button detailBtn = new Button(this);
    detailBtn.setTextSize(TEXT_SIZE + 2);
    detailBtn.setText("Detail");
    detailBtn.setTextColor(Color.parseColor("#000000"));
    detailBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    Button plotDataBtn = new Button(this);
    plotDataBtn.setTextSize(TEXT_SIZE + 2);
    plotDataBtn.setText("Plot data");
    plotDataBtn.setTextColor(Color.parseColor("#000000"));
    plotDataBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewChart();
        }
    });

    TableRow.LayoutParams params = new TableRow.LayoutParams();
    // params.addRule(TableRow.LayoutParams.FILL_PARENT);
    params.span = 2;

    row.addView(detailBtn, params);
    row.addView(plotDataBtn, params);
    row.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    table_view_mode.addView(row);

}