Example usage for android.widget LinearLayout VERTICAL

List of usage examples for android.widget LinearLayout VERTICAL

Introduction

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

Prototype

int VERTICAL

To view the source code for android.widget LinearLayout VERTICAL.

Click Source Link

Usage

From source file:org.odk.collect.android.widgets.DrawWidget.java

private void setupScreen() {
    setOrientation(LinearLayout.VERTICAL);

    // Retrieve answer from data model and update ui
    mBinaryName = mPrompt.getAnswerText();

    // Set location of folder containing answer
    mInstanceFolder = FormEntryActivity.mInstancePath.substring(0,
            FormEntryActivity.mInstancePath.lastIndexOf("/") + 1);

    // Error text, if needed
    mErrorTextView = new TextView(getContext());
    mErrorTextView.setText("Selected file is not a valid image");

    LayoutParams layoutParams = new TableLayout.LayoutParams();
    layoutParams.setMargins(7, 5, 7, 5);

    mCaptureButton = new Button(getContext());
    mCaptureButton.setText(getCapturePrompt());
    mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mCaptureButton.setPadding(20, 20, 20, 20);
    mCaptureButton.setEnabled(!mPrompt.isReadOnly());
    mCaptureButton.setLayoutParams(layoutParams);

    // Launch capture intent on click
    mCaptureButton.setOnClickListener(new View.OnClickListener() {
        @Override/*  w w  w  .jav  a  2s . co m*/
        public void onClick(View v) {
            mWaitingForData = true;
            mErrorTextView.setVisibility(View.GONE);

            File tmp = new File(
                    FileUtilsExtended.EXTERNAL_CACHE + File.separator + FileUtilsExtended.CAPTURED_IMAGE_FILE);

            // Copy existing image into temporary slot (edit existing image)
            if (mBinaryName == null) {
                // Remove this file if it's still sitting around
                tmp.delete();
            } else {
                try {
                    org.apache.commons.io.FileUtils.copyFile(new File(mInstanceFolder, mBinaryName), tmp);
                } catch (IOException e) {
                    Log.e(Collect.LOGTAG,
                            t + "unable to copy existing binary image to temporary location: " + e.toString());
                    e.printStackTrace();
                }
            }

            Intent i = new Intent(getContext(), DrawActivity.class);
            i.putExtra(DrawActivity.KEY_DRAW_MODE, mDrawMode);
            i.putExtra(DrawActivity.KEY_OUTPUT_URI, Uri.fromFile(tmp));
            ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE);
        }
    });

    addView(mCaptureButton);

    // Proceed to add the imageView only if the user has taken a picture
    if (mBinaryName == null)
        return;

    // Below taken from ImageWidget (w/o onClick for loading a larger image)
    mImageView = new ImageView(getContext());

    Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    int screenWidth = display.getWidth();
    int screenHeight = display.getHeight();

    File f = new File(mInstanceFolder + "/" + mBinaryName);

    if (f.exists()) {
        Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth);

        if (bmp == null) {
            mErrorTextView.setVisibility(View.VISIBLE);
        }

        mImageView.setImageBitmap(bmp);
    } else {
        mImageView.setImageBitmap(null);
    }

    mImageView.setPadding(10, 10, 10, 10);
    mImageView.setAdjustViewBounds(true);

    addView(mImageView);
}

From source file:org.mariotaku.twidere.activity.SignInActivity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_EDIT_API: {
        if (resultCode == RESULT_OK) {
            Bundle bundle = new Bundle();
            if (data != null) {
                bundle = data.getExtras();
            }/* w  ww .ja  v  a2  s. c  o  m*/
            if (bundle != null) {
                mRESTBaseURL = bundle.getString(Accounts.REST_BASE_URL);
                mSigningRESTBaseURL = bundle.getString(Accounts.SIGNING_REST_BASE_URL);
                mOAuthBaseURL = bundle.getString(Accounts.OAUTH_BASE_URL);
                mSigningOAuthBaseURL = bundle.getString(Accounts.SIGNING_OAUTH_BASE_URL);
                mAuthType = bundle.getInt(Accounts.AUTH_TYPE);
                final boolean is_twip_o_mode = mAuthType == Accounts.AUTH_TYPE_TWIP_O_MODE;
                final boolean is_oauth = mAuthType == Accounts.AUTH_TYPE_OAUTH;
                mBrowserSignInButton.setVisibility(is_oauth ? View.VISIBLE : View.GONE);
                mUsernamePasswordContainer.setVisibility(is_twip_o_mode ? View.GONE : View.VISIBLE);
                mSigninSignupContainer
                        .setOrientation(is_twip_o_mode ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL);
            }
        }
        setSignInButton();
        break;
    }
    case REQUEST_SET_COLOR: {
        if (resultCode == BaseActivity.RESULT_OK)
            if (data != null) {
                mUserColor = data.getIntExtra(Accounts.USER_COLOR, Color.TRANSPARENT);
            }
        setUserColorButton();
        break;
    }
    case REQUEST_BROWSER_SIGN_IN: {
        if (resultCode == BaseActivity.RESULT_OK)
            if (data != null && data.getExtras() != null) {
                doLogin(true, data.getExtras());
            }
        break;
    }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:fr.cph.chicago.core.activity.BikeStationActivity.java

private void drawData() {
    final Context context = getApplicationContext();

    final LinearLayout availableLayout = new LinearLayout(context);
    final LinearLayout availableBikes = new LinearLayout(context);
    final LinearLayout availableDocks = new LinearLayout(context);

    final TextView availableBike = new TextView(context);
    final TextView availableDock = new TextView(context);
    final TextView amountBike = new TextView(context);
    final TextView amountDock = new TextView(context);

    container.removeAllViews();//from  w  w  w  .  j  a  v  a 2  s.co m
    container.setOrientation(LinearLayout.HORIZONTAL);
    availableLayout.setOrientation(LinearLayout.VERTICAL);
    availableBikes.setOrientation(LinearLayout.HORIZONTAL);
    availableBike.setText(bikeAvailableBikes);
    availableBike.setTextColor(grey_5);
    availableBikes.addView(availableBike);
    amountBike.setText(String.valueOf(bikeStation.getAvailableBikes()));
    if (bikeStation.getAvailableBikes() == 0) {
        amountBike.setTextColor(red);
    } else {
        amountBike.setTextColor(green);
    }
    availableBikes.addView(amountBike);
    availableLayout.addView(availableBikes);
    availableDocks.setOrientation(LinearLayout.HORIZONTAL);
    availableDock.setText(bikeAvailableDocks);
    availableDock.setTextColor(grey_5);
    availableDocks.addView(availableDock);
    amountDock.setText(String.valueOf(bikeStation.getAvailableDocks()));
    if (bikeStation.getAvailableDocks() == 0) {
        amountDock.setTextColor(red);
    } else {
        amountDock.setTextColor(green);
    }
    availableDocks.addView(amountDock);
    availableLayout.addView(availableDocks);
    container.addView(availableLayout);
}

From source file:com.farbod.labelledspinner.LabelledSpinner.java

/**
 * Inflates the layout and sets layout parameters
 *///from  ww w  .  j ava2  s  . c om
private void prepareLayout(Context context) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.widget_labelled_spinner, this, true);

    setOrientation(LinearLayout.VERTICAL);
    setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}

From source file:com.mci.firstidol.view.ActionSheet.java

@SuppressWarnings("deprecation")
private View createView() {
    FrameLayout parent = new FrameLayout(getActivity());
    parent.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT));
    mBg = new View(getActivity());
    mBg.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT));
    mBg.setBackgroundColor(Color.argb(136, 0, 0, 0));
    mBg.setId(ActionSheet.BG_VIEW_ID);//from  ww  w  .  j a  va  2s  . c o m
    mBg.setOnClickListener(this);

    mPanel = new LinearLayout(getActivity());
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.BOTTOM;
    mPanel.setLayoutParams(params);
    mPanel.setOrientation(LinearLayout.VERTICAL);

    TextView titleView = new TextView(getActivity());
    titleView.setText(TextUtils.isEmpty(getTitle()) ? "" : getTitle());
    titleView.setGravity(Gravity.CENTER);
    titleView.setTextColor(Color.GRAY);
    titleView.setBackgroundDrawable(mAttrs.actionSheetTitleBackground);
    mPanel.addView(titleView);

    parent.addView(mBg);
    parent.addView(mPanel);
    return parent;
}

From source file:com.zzb.mynew.view.ExpandableTextView.java

/**
 * ?/*from w  w  w.  ja  v a  2 s  .c o m*/
 * @param attrs
 */
private void init(AttributeSet attrs) {
    mCollapsedStatus = new SparseBooleanArray();

    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
    mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines,
            MAX_COLLAPSED_LINES);
    mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION);
    mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable);
    mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable);

    textCollapse = typedArray.getString(R.styleable.ExpandableTextView_textCollapse);
    textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand);
    showExpandCollapseDrawable = typedArray
            .getBoolean(R.styleable.ExpandableTextView_showExpandCollapseDrawable, true);

    if (showExpandCollapseDrawable) {
        if (mExpandDrawable == null) {
            mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down);
        }
        if (mCollapseDrawable == null) {
            mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up);
        }
    }

    if (TextUtils.isEmpty(textCollapse)) {
        textCollapse = getContext().getString(R.string.shink);
    }
    if (TextUtils.isEmpty(textExpand)) {
        textExpand = getContext().getString(R.string.expand);
    }
    contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor,
            ContextCompat.getColor(getContext(), R.color.light_gray));
    contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize,
            DisplayUtil.sp2px(14));
    collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor,
            ContextCompat.getColor(getContext(), R.color.main_color));
    collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize,
            DisplayUtil.sp2px(14));

    grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT);

    typedArray.recycle();
    // enforces vertical orientation
    setOrientation(LinearLayout.VERTICAL);
    // default visibility is gone
    setVisibility(GONE);
}

From source file:com.morlunk.mumbleclient.channel.ChannelMenu.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    boolean adding = false;
    switch (item.getItemId()) {
    case R.id.context_channel_join:
        mService.joinChannel(mChannel.getId());
        break;/*from   www .j  av a 2  s  .c o  m*/
    case R.id.context_channel_add:
        adding = true;
    case R.id.context_channel_edit:
        ChannelEditFragment addFragment = new ChannelEditFragment();
        Bundle args = new Bundle();
        if (adding)
            args.putInt("parent", mChannel.getId());
        else
            args.putInt("channel", mChannel.getId());
        args.putBoolean("adding", adding);
        addFragment.setArguments(args);
        addFragment.show(mFragmentManager, "ChannelAdd");
        break;
    case R.id.context_channel_remove:
        AlertDialog.Builder adb = new AlertDialog.Builder(mContext);
        adb.setTitle(R.string.confirm);
        adb.setMessage(R.string.confirm_delete_channel);
        adb.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mService.removeChannel(mChannel.getId());
            }
        });
        adb.setNegativeButton(android.R.string.cancel, null);
        adb.show();
        break;
    case R.id.context_channel_view_description:
        Bundle commentArgs = new Bundle();
        commentArgs.putInt("channel", mChannel.getId());
        commentArgs.putString("comment", mChannel.getDescription());
        commentArgs.putBoolean("editing", false);
        DialogFragment commentFragment = (DialogFragment) Fragment.instantiate(mContext,
                ChannelDescriptionFragment.class.getName(), commentArgs);
        commentFragment.show(mFragmentManager, ChannelDescriptionFragment.class.getName());
        break;
    case R.id.context_channel_pin:
        long serverId = mService.getConnectedServer().getId();
        boolean pinned = mDatabase.isChannelPinned(serverId, mChannel.getId());
        if (!pinned)
            mDatabase.addPinnedChannel(serverId, mChannel.getId());
        else
            mDatabase.removePinnedChannel(serverId, mChannel.getId());
        break;
    case R.id.context_channel_link: {
        IChannel channel = mService.getSessionChannel();
        if (!item.isChecked()) {
            mService.linkChannels(channel, mChannel);
        } else {
            mService.unlinkChannels(channel, mChannel);
        }
        break;
    }
    case R.id.context_channel_unlink_all:
        mService.unlinkAllChannels(mChannel);
        break;
    case R.id.context_channel_shout: {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle(R.string.shout_configure);
        LinearLayout layout = new LinearLayout(mContext);
        layout.setOrientation(LinearLayout.VERTICAL);

        final CheckBox subchannelBox = new CheckBox(mContext);
        subchannelBox.setText(R.string.shout_include_subchannels);
        layout.addView(subchannelBox);

        final CheckBox linkedBox = new CheckBox(mContext);
        linkedBox.setText(R.string.shout_include_linked);
        layout.addView(linkedBox);

        builder.setView(layout);
        builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mService == null
                        || mService.getConnectionState() != JumbleService.ConnectionState.CONNECTED)
                    return;

                // Unregister any existing voice target.
                if (mService.getVoiceTargetMode() == VoiceTargetMode.WHISPER) {
                    mService.unregisterWhisperTarget(mService.getVoiceTargetId());
                }

                WhisperTargetChannel channelTarget = new WhisperTargetChannel(mChannel, linkedBox.isChecked(),
                        subchannelBox.isChecked(), null);
                byte id = mService.registerWhisperTarget(channelTarget);
                if (id > 0) {
                    mService.setVoiceTargetId(id);
                } else {
                    Toast.makeText(mContext, R.string.shout_failed, Toast.LENGTH_LONG).show();
                }
            }
        });
        builder.setNegativeButton(android.R.string.cancel, null);
        builder.show();

        break;
    }
    default:
        return false;
    }
    return true;
}

From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java

/**
 * ?/*from  www  .ja  v a2s  .c  om*/
 * @param attrs
 */
private void init(AttributeSet attrs) {
    mCollapsedStatus = new SparseBooleanArray();

    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
    mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines,
            MAX_COLLAPSED_LINES);
    mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION);
    mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable);
    mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable);

    textCollapse = typedArray.getString(R.styleable.ExpandableTextView_textCollapse);
    textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand);
    showExpandCollapseDrawable = typedArray
            .getBoolean(R.styleable.ExpandableTextView_showExpandCollapseDrawable, true);

    if (showExpandCollapseDrawable) {
        if (mExpandDrawable == null) {
            mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down);
        }
        if (mCollapseDrawable == null) {
            mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up);
        }
    }

    if (TextUtils.isEmpty(textCollapse)) {
        textCollapse = getContext().getString(R.string.shink);
    }
    if (TextUtils.isEmpty(textExpand)) {
        textExpand = getContext().getString(R.string.expand);
    }
    contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor,
            ContextCompat.getColor(getContext(), R.color.light_gray));
    contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize,
            DisplayUtil.sp2px(14));

    collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor,
            ContextCompat.getColor(getContext(), R.color.main_color));
    collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize,
            DisplayUtil.sp2px(14));

    grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT);

    typedArray.recycle();
    // enforces vertical orientation
    setOrientation(LinearLayout.VERTICAL);
    // default visibility is gone
    setVisibility(GONE);
}

From source file:nz.ac.auckland.lablet.script.components.TextComponent.java

@Override
public View createView(Context context, Fragment parent) {
    ScriptTreeNodeSheetBase.Counter counter = this.component.getCounter("QuestionCounter");

    // Note: we have to do this programmatically because findViewById would find the wrong child
    // items if there is more than one text question.

    LinearLayout layout = new LinearLayout(context);
    layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    layout.setOrientation(LinearLayout.VERTICAL);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        layout.setBackgroundColor(context.getResources().getColor(R.color.sc_question_background_color, null));
    } else {/*from w ww.j  a  va 2  s .com*/
        layout.setBackgroundColor(context.getResources().getColor(R.color.sc_question_background_color));
    }

    TextView textView = new TextView(context);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        textView.setTextAppearance(android.R.style.TextAppearance_Medium);
    } else {
        textView.setTextAppearance(context, android.R.style.TextAppearance_Medium);
    }
    question_num = counter.increaseValue();
    textView.setText("Q" + question_num + ": " + text);

    EditText editText = new EditText(context);
    editText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    editText.setText(answer);
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            answer = editable.toString();
            update();
        }
    });

    layout.addView(textView);
    layout.addView(editText);
    return layout;
}

From source file:com.cairoconfessions.MainActivity.java

public void report(View view) {

    final EditText edit = new EditText(this);
    final RadioGroup choices = new RadioGroup(this);
    edit.setText("I would like to report this confession");
    final String[] selectedItem = getResources().getStringArray(R.array.report_choices);

    for (int i = 0; i < selectedItem.length; i++) {
        RadioButton choice = new RadioButton(this);
        choice.setText(selectedItem[i]);
        choices.addView(choice);//from  w w  w. j av a 2  s  . c o  m
    }
    choices.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // checkedId is the RadioButton selected
            edit.setText("I would like to report this confession as "
                    + ((RadioButton) group.findViewById(checkedId)).getText().toString());

        }
    });
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(choices);
    ll.addView(edit);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Choose which categories:").setView(ll)
            .setPositiveButton(R.string.send, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User clicked OK button
                    reportReceived();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User clicked Cancel button
                }
            }).show();
}