Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

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

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:de.da_sense.moses.client.FormFragment.java

/**
 * Displays a single choice question to the user.
 * @param question the question to be displayed
 * @param linearLayoutInsideAScrollView the view to add the question to
 * @param ordinal the ordinal number of the question i.e. 1, 2, 3, 4 or 5
 *///from   ww  w  .j  a v a2 s .com
private void makeSingleChoice(final Question question, LinearLayout linearLayoutInsideAScrollView,
        int ordinal) {
    LinearLayout questionContainer = generateQuestionContainer(linearLayoutInsideAScrollView);
    String questionText = question.getTitle();
    List<PossibleAnswer> possibleAnswers = question.getPossibleAnswers();
    Collections.sort(possibleAnswers);

    TextView questionView = new TextView(getActivity());
    questionView.setText(ordinal + ". " + questionText);
    if (question.isMandatory())
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyleMandatory);
    else
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyle);
    questionContainer.addView(questionView);
    mQuestionTitleMappings.put(question, questionView);

    final RadioButton[] rb = new RadioButton[possibleAnswers.size()];
    RadioGroup rg = new RadioGroup(getActivity()); // create the RadioGroup
    rg.setOrientation(RadioGroup.VERTICAL);// or RadioGroup.VERTICAL
    String madeAnswer = question.getAnswer();
    int madeAnswerInt = -1;
    if (!madeAnswer.equals(Question.ANSWER_UNANSWERED))
        madeAnswerInt = Integer.parseInt(madeAnswer);

    for (int i = 0; i < rb.length; i++) {
        rb[i] = new RadioButton(getActivity());
        if (i % 2 == 0)
            rb[i].setBackgroundColor(getActivity().getResources().getColor(R.color.light_gray));
        rg.addView(rb[i]); // the RadioButtons are added to the radioGroup
        // instead of the layout
        PossibleAnswer possibleAnswer = possibleAnswers.get(i);
        rb[i].setText(possibleAnswer.getTitle());
        final int possibleAnswerId = possibleAnswer.getId();
        if (madeAnswerInt == possibleAnswerId)
            rb[i].setChecked(true);
        rb[i].setTextAppearance(getActivity(), R.style.PossibleAnswerTextStyle);
        LayoutParams rowParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        rb[i].setLayoutParams(rowParam);

        // click handling
        rb[i].setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                question.setAnswer(String.valueOf(possibleAnswerId));
            }
        });
        if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY)
            rb[i].setEnabled(false);

        rb[i].setVisibility(View.VISIBLE);
    }

    rg.setVisibility(View.VISIBLE);
    if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY)
        rg.setEnabled(false);
    Log.i(LOG_TAG, "last rg = " + rg);
    questionContainer.addView(rg);
}

From source file:com.arctech.stikyhive.ChattingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    recipientStkid = getIntent().getExtras().getString("recipientStkid");
    chatRecipient = getIntent().getExtras().getString("chatRecipient");
    chatRecipientUrl = getIntent().getExtras().getString("chatRecipientUrl");
    senderToken = getIntent().getExtras().getString("senderToken");
    recipientToken = getIntent().getExtras().getString("recipientToken");
    noti = getIntent().getExtras().getBoolean("noti");
    message = getIntent().getExtras().getString("message");
    rows = getIntent().getExtras().getInt("rows");

    pref = PreferenceManager.getDefaultSharedPreferences(this);
    ws = new JsonWebService();
    dbHelper = new DBHelper(this);
    dialog = new ProgressDialog(this);
    listChatContact = new ArrayList<>();
    listChatContact = dbHelper.getChatContact();
    Log.i(" Chat Contact ", " " + listChatContact.size());
    //to change font
    faceSemi_bold = Typeface.createFromAsset(getAssets(), fontOSSemi_bold);
    Typeface faceLight = Typeface.createFromAsset(getAssets(), fontOSLight);
    faceRegular = Typeface.createFromAsset(getAssets(), fontOSRegular);

    imageLoader = ImageLoader.getInstance();
    if (!imageLoader.isInited()) {
        imageLoader.init(ImageLoaderConfiguration.createDefault(this));
    }/*from   ww w  . j  a  va  2s.c  om*/

    start = new Date();
    SimpleDateFormat oFormat = new SimpleDateFormat("dd MMM HH:mm");
    timeSend = oFormat.format(start);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.chat);

    txtUserName = (TextView) findViewById(R.id.txtChatName);
    edTxtMsg = (EditText) findViewById(R.id.edTxtMsg);
    imgViewProfile = (ImageView) findViewById(R.id.imgViewChat);
    imgViewAddCon = (ImageView) findViewById(R.id.imgAddContact);
    lv = (ListView) findViewById(R.id.listView1);
    layoutLabel = (LinearLayout) findViewById(R.id.layoutLabel);
    txtLabel1 = (TextView) findViewById(R.id.txtLabel1);
    txtLabel2 = (TextView) findViewById(R.id.txtLabel2);
    txtLabel3 = (TextView) findViewById(R.id.txtLabel3);
    txtLabel2.setText(" " + chatRecipient + " ");
    txtLabel1.setTypeface(faceLight);
    txtLabel2.setTypeface(faceRegular);
    txtLabel3.setTypeface(faceLight);
    // lv.smoothScrollToPosition(adapter.getCount() - 1);

    for (ChatContact contact : listChatContact) {
        if (contact.getContactId().equals(recipientStkid)) {
            imgViewAddCon.setVisibility(View.INVISIBLE);
            layoutLabel.setVisibility(View.GONE);
            break;
        }
    }
    Log.i(TAG, " come back again");
    adapter = new ChatArrayAdapter(getApplicationContext(), R.layout.messaging_listview, faceSemi_bold,
            faceRegular);
    lv.setAdapter(adapter);
    // adapter.add(new StikyChat(chatRecipientUrl, "Hello", false, "12.10.2015", "12.1.2014"));

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    // BEGIN_INCLUDE (change_colors)
    // Set the color scheme of the SwipeRefreshLayout by providing 4 color resource ids
    swipeRefreshLayout.setColorScheme(R.color.swipe_color_1, R.color.swipe_color_2, R.color.swipe_color_3,
            R.color.swipe_color_4);
    limitMsg = 7;
    // END_INCLUDE (change_colors)
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Log.i(" Refresh Layout ", "onRefresh called from SwipeRefreshLayout");
            if (limitMsg < rows) {
                Log.i("Limit Message ", " " + limitMsg);
                limitMsg *= 2;
                fetchRecords();
            } else if (limitMsg > rows && (limitMsg - rows < 7)) {
                fetchRecords();
            } else {
                Log.i("No data ", "to refresh");
                swipeRefreshLayout.setRefreshing(false);
                Toast.makeText(getApplicationContext(), "No data to refresh!", Toast.LENGTH_SHORT).show();
            }

            // initiateRefresh();
        }
    });

    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout headerLayout = (LinearLayout) findViewById(R.id.header);
    View header = inflator.inflate(R.layout.header, null);

    TextView textView = (TextView) header.findViewById(R.id.textView1);
    textView.setText("StikyChat");
    textView.setTypeface(faceSemi_bold);
    textView.setVisibility(View.VISIBLE);
    headerLayout.addView(header);
    LinearLayout layoutRight = (LinearLayout) header.findViewById(R.id.layoutRight);
    layoutRight.setVisibility(View.GONE);

    txtUserName.setText(chatRecipient);
    Log.i(TAG, "Activity Name " + txtUserName.getText().toString());
    txtUserName.setTypeface(faceSemi_bold);

    String url = "";
    if (chatRecipientUrl.contains("http")) {
        url = chatRecipientUrl;
    } else {
        url = this.getResources().getString(R.string.url) + "/" + chatRecipientUrl;
    }
    addAndroidUniversalImageLoader(imgViewProfile, url);
    //        if (noti && (!message.equals(""))) {
    //            adapter.add(new StikyChat(chatRecipientUrl, message, true, timeSend, ""));
    //            lv.smoothScrollToPosition(adapter.getCount() - 1);
    //        }

    //to show history chats between two users(sender & recipient)
    dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat2 = new SimpleDateFormat("dd MMM HH:mm");
    listHistory = dbHelper.getStikyChat();
    if (listHistory.size() > 0) {
        Collections.reverse(listHistory);
        for (StikyChatTb chatTb : listHistory) {
            String getDate = chatTb.getSendDate();
            String fromStikyBee = chatTb.getSender();
            try {
                String createDate = dateFormat2.format(dateFormat.parse(getDate));
                if (fromStikyBee.equals(pref.getString("stkid", ""))) {
                    adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), false, createDate, ""));
                } else {
                    adapter.add(new StikyChat(chatRecipientUrl, chatTb.getMessage(), true, createDate, ""));
                }
                lv.smoothScrollToPosition(adapter.getCount() - 1);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }

    mRegistrationBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            messageGCM = sharedPreferences.getString("message", "");
            recipientProfileGCM = sharedPreferences.getString("chatRecipientUrl", "");
            recipientNameGCM = sharedPreferences.getString("chatRecipientName", "");
            recipientStkidGCM = sharedPreferences.getString("recipientStkid", "");
            recipientTokenGCM = sharedPreferences.getString("recipientToken", "");
            senderTokenGCM = sharedPreferences.getString("senderToken", "");

            Log.i(TAG, "..." + recipientStkidGCM.trim() + " STKID " + recipientStkid.trim() + ":");
            if (firstConnect) {
                if (recipientStkidGCM.trim() == recipientStkid.trim()
                        || recipientStkidGCM.equals(recipientStkid)) {
                    MyGcmListenerService.flagSendNoti = false;
                    Log.i(TAG, " " + message);
                    // (1) get today's date
                    start = new Date();
                    SimpleDateFormat oFormat = new SimpleDateFormat("dd MMM HH:mm");
                    timeSend = oFormat.format(start);

                    Log.i(TAG, "First connect " + firstConnect);
                    StikyChat stikyChat = new StikyChat(recipientProfileGCM, messageGCM, true, timeSend, "");
                    Log.i(TAG, " First " + message + " " + recipientProfileGCM + " " + timeSend);
                    Log.i(TAG, "User " + txtUserName.getText().toString());
                    //txtUserName.setText(message);
                    Log.i(TAG, "User 2 " + txtUserName.getText().toString());
                    adapter.add(stikyChat);
                    adapter.notifyDataSetChanged();
                    //new regTask2().execute("Obj ");
                    lv.smoothScrollToPosition(adapter.getCount() - 1);
                } else {
                    Log.i(TAG, "..." + recipientStkidGCM.trim());
                    Log.i(TAG, "&&&" + recipientStkid.trim());
                    Log.i(TAG, "else casee");
                    //notificaton send
                    flagNotifi = true;
                    new regTask2().execute("Notification");
                }
                firstConnect = false;
            }
        }
    };
}

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 v a 2s  . 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:com.adarshahd.indianrailinfo.donate.TrainDetails.java

private void createTableLayoutTrainFare() {
    if (mPage.contains("SORRY")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Not a valid class, Please select a different class and try again.");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();//from   w w  w .  j  av a2  s  .c o m
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }
    if (mPage.contains("ISL Of")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Station is not in ISL Of the Train. \nPlease modify the source/destination!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("ERROR")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Your request resulted in an error.\nPlease check!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("Network Connectivity")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Looks like the server is busy.\nPlease try later!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("unavailable")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText(
                "Response from server:\n\nYour request could not be processed now. \nPlease try again later!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mDetails == null || !mDetails.getTrainNumber().equals(mTrainNumber)) {
        Iterator iterator = null;
        try {
            iterator = mElements.first().parent().parent().parent().getElementsByTag("tr").iterator();
        } catch (Exception e) {
            Log.i("TrainDetails", mPage);
        }
        mListFr = new ArrayList<List<String>>();
        List<String> list;
        Element tmp;
        while (iterator.hasNext()) {
            tmp = (Element) iterator.next();
            list = new ArrayList<String>();
            list.add(tmp.select("td").get(0).text());
            list.add(tmp.select("td").get(1).text());
            mListFr.add(list);
        }
        mDetails = new Details(mListFr, TrainEnquiry.FARE, mTrainNumber);
    } else {
        mListFr = mDetails.getList();
    }
    mTblLayoutFr = new TableLayout(mActivity);
    TableRow row;
    TextView tv1, tv2;
    mTblLayoutFr.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    for (int i = 0; i < mListFr.size(); i++) {
        row = new TableRow(mActivity);
        tv1 = new TextView(mActivity);
        tv2 = new TextView(mActivity);

        tv1.setText("   " + mListFr.get(i).get(0));
        tv2.setText("   " + mListFr.get(i).get(1));

        tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);

        tv1.setPadding(5, 5, 5, 5);
        tv2.setPadding(5, 5, 5, 5);

        /*tv2.setBackgroundResource(R.drawable.card_divider);
        tv3.setBackgroundResource(R.drawable.card_divider);
        tv4.setBackgroundResource(R.drawable.card_divider);*/

        row.addView(tv1);
        row.addView(tv2);

        row.setBackgroundResource(R.drawable.button_selector);
        row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        mTblLayoutFr.addView(row);
    }
    LinearLayout ll = new LinearLayout(mActivity);
    ScrollView scrollView = new ScrollView(mActivity);
    TextView textViewTrnDtls = new TextView(mActivity);
    textViewTrnDtls.setText("Fare details:");
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(textViewTrnDtls);
    ll.addView(mTblLayoutFr);
    scrollView.addView(ll);
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(scrollView);
    if (mDialog.isShowing()) {
        mDialog.cancel();
    }
}

From source file:net.evecom.androidecssp.activity.taskresponse.TaskAndResponsesInfoActivity.java

/**
 * //from   w  w w  .j  a v  a2s  .  c o  m
 * 
 * 
 * @author Mars zhang
 * @created 2015-12-29 7:52:06
 */
private void loadResponses() {
    responseLayout.removeAllViews();
    LayoutInflater inflater = LayoutInflater.from(instance);
    for (int i = 0; i < taskResponseInfos.size(); i++) {
        final BaseModel baseModel = taskResponseInfos.get(i);
        View view = inflater.inflate(R.layout.task_response_response_item, null, true);
        responseLayout.addView(view);
        // LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(
        // LinearLayout.LayoutParams.WRAP_CONTENT,
        // LinearLayout.LayoutParams.WRAP_CONTENT);
        // lp.setMargins(0, 0, 0, 10);
        // view.setLayoutParams(lp);
        TextView dept = (TextView) view.findViewById(R.id.task_response_info_response_dept);
        TextView createtime = (TextView) view.findViewById(R.id.task_response_info_response_createtime);
        TextView name = (TextView) view.findViewById(R.id.task_response_info_response_name);
        TextView context = (TextView) view.findViewById(R.id.task_response_info_response_content);
        LinearLayout layout = (LinearLayout) view.findViewById(R.id.task_response_info_response_imagely);

        dept.setText(ifnull(baseModel.get("name"), ""));
        createtime.setText(ifnull(baseModel.get("createtime"), ""));
        name.setText(ifnull(baseModel.get("responsetitle"), ""));
        context.setText(ifnull(baseModel.get("responsecon"), ""));
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), TaskResponseInfoActivity.class);
                pushData("responseinfo", baseModel, intent);
                startActivity(intent);
            }
        });

        String imageids = ifnull(baseModel.get("detailattach"), "");
        if (imageids.length() > 0) {
            String[] imagesplits = imageids.split(",");
            for (int j = 0; j < imagesplits.length && j < 6; j++) {
                View imgview = inflater.inflate(R.layout.task_response_response_item_image, null, true);
                layout.addView(imgview);
                // LinearLayout.LayoutParams imagelp=new
                // LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                // LinearLayout.LayoutParams.WRAP_CONTENT);
                // lp.setMargins(2, 2, 2, 2);
                // imgview.setLayoutParams(imagelp);
                ImageView imageView = (ImageView) imgview.findViewById(R.id.task_response_rsponse_item_iamge);
                HashMap<String, String> mparas = new HashMap<String, String>();
                mparas.put("fileid", imagesplits[j]);
                displayImageWithWidthHeight(imageView,
                        HttpUtil.getPCURL() + "jfs/ecssp/mobile/pubCtr/getImageFlowById", mparas, 60, 60);
            }
        }

    }

}

From source file:com.google.android.gcm.demo.ui.TopicsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        // Check if at least a topic is subscribed for this sender
        int subscribedTopics = 0;
        for (Boolean subscribed : sender.topics.values()) {
            if (subscribed) {
                subscribedTopics++;//  ww  w.  j ava2 s . co  m
            }
        }
        if (subscribedTopics > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Map.Entry<String, Boolean> topic : sender.topics.entrySet()) {
                if (topic.getValue()) {
                    LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                            .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                    Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                    icon.setImageResource(R.drawable.bigtop_updates_grey600);
                    label.setText(topic.getKey());
                    button.setText(R.string.topics_unsubscribe);
                    button.setTag(R.id.tag_action, ACTION_UNSUBSCRIBE);
                    button.setTag(R.id.tag_senderid, sender.senderId);
                    button.setTag(R.id.tag_topic, topic.getKey());
                    button.setOnClickListener(this);
                    row.setPadding((int) (16 * density), 0, 0, 0);
                    sendersList.addView(row);
                }
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.topics_no_topic_subscribed));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.topics_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:com.grarak.kerneladiutor.fragments.other.SettingsFragment.java

private void colorDialog(int selection) {
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    int padding = (int) getResources().getDimension(R.dimen.dialog_padding);
    linearLayout.setPadding(padding, padding, padding, padding);

    final List<BorderCircleView> circles = new ArrayList<>();

    LinearLayout subView = null;/*from  w ww. jav a2 s.com*/
    for (int i = 0; i < BorderCircleView.sAccentColors.size(); i++) {
        if (subView == null || i % 5 == 0) {
            subView = new LinearLayout(getActivity());
            subView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            linearLayout.addView(subView);
        }

        BorderCircleView circle = new BorderCircleView(getActivity());
        circle.setChecked(i == selection);
        circle.setBackgroundColor(
                ContextCompat.getColor(getActivity(), BorderCircleView.sAccentColors.keyAt(i)));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, 1);
        int margin = (int) getResources().getDimension(R.dimen.color_dialog_margin);
        params.setMargins(margin, margin, margin, margin);
        circle.setLayoutParams(params);
        circle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (BorderCircleView borderCircleView : circles) {
                    if (v == borderCircleView) {
                        borderCircleView.setChecked(true);
                        mColorSelection = circles.indexOf(borderCircleView);
                    } else {
                        borderCircleView.setChecked(false);
                    }
                }
            }
        });

        circles.add(circle);
        subView.addView(circle);
    }

    new Dialog(getActivity()).setView(linearLayout)
            .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (mColorSelection >= 0) {
                        Prefs.saveString(KEY_ACCENT_COLOR,
                                BorderCircleView.sAccentColors.valueAt(mColorSelection), getActivity());
                    }
                    getActivity().finish();
                    Intent intent = new Intent(getActivity(), MainActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                }
            }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    mColorSelection = -1;
                }
            }).show();
}

From source file:cc.softwarefactory.lokki.android.fragments.PlacesFragment.java

private void setListAdapter() {

    Log.d(TAG, "setListAdapter");

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.places_row_layout, placesList) {

        @Override/*from www  . jav  a 2s. c o m*/
        public View getView(int position, View unusedView, ViewGroup parent) {

            View convertView = getActivity().getLayoutInflater().inflate(R.layout.places_row_layout, parent,
                    false);
            AQuery aq = new AQuery(getActivity(), convertView);

            final String placeName = getItem(position);
            aq.id(R.id.place_name).text(placeName);

            aq.id(R.id.places_context_menu_button).clicked(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    v.showContextMenu();
                }
            });

            Log.d(TAG, "Plane name: " + placeName);
            Log.d(TAG, "peopleInsidePlace? " + peopleInsidePlace.has(placeName));

            if (peopleInsidePlace.has(placeName)) { // People are inside this place
                Log.d(TAG, "Inside loop");
                try {
                    JSONArray people = peopleInsidePlace.getJSONArray(placeName);
                    LinearLayout avatarRow = (LinearLayout) convertView.findViewById(R.id.avatar_row);
                    avatarRow.removeAllViewsInLayout(); // Deletes old avatars, if any.

                    for (int i = 0; i < people.length(); i++) {

                        final String email = people.getString(i);
                        if (MainApplication.iDontWantToSee.has(email)) {
                            continue;
                        }
                        RoundedImageView image = createAvatar(email);

                        if (MainApplication.avatarCache.get(email) != null) {
                            image.setImageBitmap(MainApplication.avatarCache.get(email));
                        } else {
                            Log.d(TAG, "Avatar not in cache, email: " + email);
                            image.setImageResource(R.drawable.default_avatar);
                        }
                        image.setContentDescription(email);

                        avatarRow.addView(image);
                    }

                } catch (Exception ex) {
                    Log.d(TAG, "Error in adding avatars");
                }
            }

            return convertView;
        }
    };

    listView.setAdapter(adapter);

}

From source file:com.adarshahd.indianrailinfo.donate.TrainDetails.java

private void createTableLayoutTrainAvailability() {

    if (mPage.contains("SORRY")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Not a valid class, Please select a different class and try again.");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();/*  w  w w .j  a v a  2  s  .  co  m*/
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("ISL Of")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Station is not in ISL Of the Train. \nPlease modify the source/destination!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("ERROR")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Your request resulted in an error.\nPlease check!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("Network Connectivity")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText("Looks like the server is busy.\nPlease try later!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mPage.contains("unavailable")) {
        TextView textViewTrnDtls = new TextView(mActivity);
        textViewTrnDtls.setText(
                "Response from server:\n\nYour request could not be processed now.\nPlease try again later!");
        textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
        textViewTrnDtls.setPadding(10, 10, 10, 10);
        textViewTrnDtls.setTextColor(Color.RED);
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(textViewTrnDtls);
        if (mDialog.isShowing()) {
            mDialog.cancel();
        }
        return;
    }

    if (mDetails == null || !mDetails.getTrainNumber().equals(mTrainNumber)) {
        Iterator iterator = null;
        try {
            iterator = mElements.first().parent().parent().parent().getElementsByTag("tr").iterator();
        } catch (Exception e) {
            Log.i("TrainDetails", mPage);
            e.printStackTrace();
            return;
        }
        mListAv = new ArrayList<List<String>>();
        List<String> list;
        Element tmp;
        tmp = (Element) iterator.next();
        list = new ArrayList<String>();
        list.add(tmp.select("th").get(0).text());
        list.add("Date");
        list.add(tmp.select("th").get(2).text());
        //list.add(tmp.select("th").get(3).text());
        mListAv.add(list);
        while (iterator.hasNext()) {
            tmp = (Element) iterator.next();
            if (!tmp.hasText()) {
                continue;
            }
            list = new ArrayList<String>();
            list.add(tmp.select("td").get(0).text());
            list.add(tmp.select("td").get(1).text());
            list.add(tmp.select("td").get(2).text());
            //list.add(tmp.select("td").get(3).text());
            mListAv.add(list);
        }
        mDetails = new Details(mListAv, TrainEnquiry.AVAILABILITY, mTrainNumber);
    } else {
        mListAv = mDetails.getList();
    }
    mTblLayoutAv = new TableLayout(mActivity);
    TableRow row;
    TextView tv1, tv2, tv3;
    mTblLayoutAv.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    for (int i = 0; i < mListAv.size(); i++) {
        row = new TableRow(mActivity);
        tv1 = new TextView(mActivity);
        tv2 = new TextView(mActivity);
        tv3 = new TextView(mActivity);
        //tv4 = new TextView(mActivity);

        tv1.setText("   " + mListAv.get(i).get(0));
        tv2.setText("   " + mListAv.get(i).get(1));
        tv3.setText("   " + mListAv.get(i).get(2));
        //tv4.setText("   " + mListAv.get(i).get(3));

        tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv3.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        //tv4.setTextAppearance(mActivity,android.R.style.TextAppearance_DeviceDefault_Medium);

        tv1.setPadding(5, 5, 5, 5);
        tv2.setPadding(5, 5, 5, 5);
        tv3.setPadding(5, 5, 5, 5);
        //tv4.setPadding(5,5,5,5);

        /*tv2.setBackgroundResource(R.drawable.card_divider);
        tv3.setBackgroundResource(R.drawable.card_divider);
        tv4.setBackgroundResource(R.drawable.card_divider);*/

        row.addView(tv1);
        row.addView(tv2);
        row.addView(tv3);
        //row.addView(tv4);

        row.setBackgroundResource(R.drawable.button_selector);
        row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        row.setOnClickListener(this);
        mTblLayoutAv.addView(row);
    }
    LinearLayout ll = new LinearLayout(mActivity);
    ScrollView scrollView = new ScrollView(mActivity);
    TextView textViewTrnDtls = new TextView(mActivity);
    textViewTrnDtls.setText("Availability details:");
    textViewTrnDtls.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Large);
    textViewTrnDtls.setPadding(10, 10, 10, 10);
    ll.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(textViewTrnDtls);
    ll.addView(mTblLayoutAv);
    scrollView.addView(ll);
    mFrameLayout.removeAllViews();
    mFrameLayout.addView(scrollView);
    if (mDialog.isShowing()) {
        mDialog.cancel();
    }
}