Java Code Examples for android.widget.LinearLayout#addView()

The following examples show how to use android.widget.LinearLayout#addView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IdleExitTestActivity.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    ll.setPadding(30, 30, 30, 30);

    mTextView = onCreateTextView();
    mTextView.setText("Shake detector");

    ll.addView(mTextView);
    setContentView(ll);
}
 
Example 2
Source File: UIToast.java    From Auie with GNU General Public License v2.0 5 votes vote down vote up
private static UIToast builder(Context context, Object text, int[] colors, long type){

		UIToast result = new UIToast(context);
		
		LinearLayout rootLayout = new LinearLayout(context);
		rootLayout.setLayoutParams(getParams());
		rootLayout.setGravity(Gravity.CENTER);
		int padding = UEMethod.dp2px(context, 8);
		TextView textView = new TextView(context);
		textView.setLayoutParams(getParams());
		textView.setPadding(padding * 3, padding, padding * 3, padding);
		textView.setTextSize(14);
		textView.setText(String.valueOf(text));
		if (colors.length > 0) {
			textView.setTextColor(colors[0]);			
		}else{
			textView.setTextColor(Color.parseColor("#F8F8F8"));	
		}
		int background = Color.parseColor("#99000000");
		if (colors.length > 1) {
			background = colors[1];			
		}
		if (type == 0) {
			rootLayout.setBackgroundDrawable(createBackground(background, padding * 4 + textView.getHeight()));
		}else {
			rootLayout.setBackgroundColor(background);
		}
		rootLayout.addView(textView);
		
		result.setView(rootLayout);
		
		return result;
	}
 
Example 3
Source File: CodeLayout.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	LayoutParams params1 = new LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.WRAP_CONTENT);

	TextView text = new TextView(this);
	text.setText("Hello");
	text.setLayoutParams(params1);
	EditText edit = new EditText(this);
	edit.setHint("This is your input...");
	edit.setLayoutParams(params1);
	Button button = new Button(this);
	button.setText("Press me");
	button.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			Toast makeText = Toast.makeText(v.getContext(), "Pressed", 200);
			makeText.show();
		}
	});
	LinearLayout layout = new LinearLayout(this);
	layout.setOrientation(LinearLayout.VERTICAL);
	layout.setPadding(10, 10, 10, 10);
	layout.addView(text);
	layout.addView(edit);
	layout.addView(button);
	setContentView(layout);
}
 
Example 4
Source File: MapLayerListFragment.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindDragView(View clickedView, View dragView) {
    LinearLayout clickedLayout = (LinearLayout) clickedView;
    View clickedHeader = clickedLayout.getChildAt(0);
    RecyclerView clickedRecyclerView = (RecyclerView) clickedLayout.getChildAt(1);

    View dragHeader = dragView.findViewById(R.id.drag_header);
    ScrollView dragScrollView = dragView.findViewById(R.id.drag_scroll_view);
    LinearLayout dragLayout = dragView.findViewById(R.id.drag_list);
    dragLayout.removeAllViews();

    ((TextView) dragHeader.findViewById(R.id.text)).setText(((TextView) clickedHeader.findViewById(R.id.text)).getText());
    ((TextView) dragHeader.findViewById(R.id.item_count)).setText(((TextView) clickedHeader.findViewById(R.id.item_count)).getText());
    for (int i = 0; i < clickedRecyclerView.getChildCount(); i++) {
        View mapItemView = View.inflate(dragView.getContext(), R.layout.column_item, null);

        ((TextView) mapItemView.findViewById(R.id.text)).setText(((TextView) clickedRecyclerView.getChildAt(i).findViewById(R.id.text)).getText());
        dragLayout.addView(mapItemView);

        if (i == 0) {
            dragScrollView.setScrollY(-clickedRecyclerView.getChildAt(i).getTop());
        }
    }

    dragView.setPivotY(0);
    dragView.setPivotX(clickedView.getMeasuredWidth() / 2);
}
 
Example 5
Source File: SystemWebChromeClient.java    From chappiecast with Mozilla Public License 2.0 5 votes vote down vote up
@Override
/**
 * Ask the host application for a custom progress view to show while
 * a <video> is loading.
 * @return View The progress view.
 */
public View getVideoLoadingProgressView() {

    if (mVideoProgressView == null) {            
        // Create a new Loading view programmatically.
        
        // create the linear layout
        LinearLayout layout = new LinearLayout(parentEngine.getView().getContext());
        layout.setOrientation(LinearLayout.VERTICAL);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
        layout.setLayoutParams(layoutParams);
        // the proress bar
        ProgressBar bar = new ProgressBar(parentEngine.getView().getContext());
        LinearLayout.LayoutParams barLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        barLayoutParams.gravity = Gravity.CENTER;
        bar.setLayoutParams(barLayoutParams);   
        layout.addView(bar);
        
        mVideoProgressView = layout;
    }
return mVideoProgressView; 
}
 
Example 6
Source File: BoardFragment.java    From DragListView with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindDragView(View clickedView, View dragView) {
    LinearLayout clickedLayout = (LinearLayout) clickedView;
    View clickedHeader = clickedLayout.getChildAt(0);
    RecyclerView clickedRecyclerView = (RecyclerView) clickedLayout.getChildAt(1);

    View dragHeader = dragView.findViewById(R.id.drag_header);
    ScrollView dragScrollView = dragView.findViewById(R.id.drag_scroll_view);
    LinearLayout dragLayout = dragView.findViewById(R.id.drag_list);

    Drawable clickedColumnBackground = clickedLayout.getBackground();
    if (clickedColumnBackground != null) {
        ViewCompat.setBackground(dragView, clickedColumnBackground);
    }

    Drawable clickedRecyclerBackground = clickedRecyclerView.getBackground();
    if (clickedRecyclerBackground != null) {
        ViewCompat.setBackground(dragLayout, clickedRecyclerBackground);
    }

    dragLayout.removeAllViews();

    ((TextView) dragHeader.findViewById(R.id.text)).setText(((TextView) clickedHeader.findViewById(R.id.text)).getText());
    ((TextView) dragHeader.findViewById(R.id.item_count)).setText(((TextView) clickedHeader.findViewById(R.id.item_count)).getText());
    for (int i = 0; i < clickedRecyclerView.getChildCount(); i++) {
        View view = View.inflate(dragView.getContext(), R.layout.column_item, null);
        ((TextView) view.findViewById(R.id.text)).setText(((TextView) clickedRecyclerView.getChildAt(i).findViewById(R.id.text)).getText());
        dragLayout.addView(view);

        if (i == 0) {
            dragScrollView.setScrollY(-clickedRecyclerView.getChildAt(i).getTop());
        }
    }

    dragView.setPivotY(0);
    dragView.setPivotX(clickedView.getMeasuredWidth() / 2);
}
 
Example 7
Source File: AlertsCreator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static AlertDialog createAccountSelectDialog(Activity parentActivity, final AccountSelectDelegate delegate) {
    if (UserConfig.getActivatedAccountsCount() < 2) {
        return null;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    final Runnable dismissRunnable = builder.getDismissRunnable();
    final AlertDialog[] alertDialog = new AlertDialog[1];

    final LinearLayout linearLayout = new LinearLayout(parentActivity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
        TLRPC.User u = UserConfig.getInstance(a).getCurrentUser();
        if (u != null) {
            AccountSelectCell cell = new AccountSelectCell(parentActivity);
            cell.setAccount(a, false);
            cell.setPadding(AndroidUtilities.dp(14), 0, AndroidUtilities.dp(14), 0);
            cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
            linearLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            cell.setOnClickListener(v -> {
                if (alertDialog[0] != null) {
                    alertDialog[0].setOnDismissListener(null);
                }
                dismissRunnable.run();
                AccountSelectCell cell1 = (AccountSelectCell) v;
                delegate.didSelectAccount(cell1.getAccountNumber());
            });
        }
    }

    builder.setTitle(LocaleController.getString("SelectAccount", R.string.SelectAccount));
    builder.setView(linearLayout);
    builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    return alertDialog[0] = builder.create();
}
 
Example 8
Source File: NormalListDialog.java    From FlycoDialog_Master with MIT License 5 votes vote down vote up
@Override
public View onCreateView() {
    LinearLayout ll_container = new LinearLayout(mContext);
    ll_container.setOrientation(LinearLayout.VERTICAL);

    /** title */
    mTvTitle = new TextView(mContext);
    mTvTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    mTvTitle.setSingleLine(true);
    mTvTitle.setPadding(dp2px(18), dp2px(10), 0, dp2px(10));

    ll_container.addView(mTvTitle);

    /** listview */
    mLv = new ListView(mContext);
    mLv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    mLv.setCacheColorHint(Color.TRANSPARENT);
    mLv.setFadingEdgeLength(0);
    mLv.setVerticalScrollBarEnabled(false);
    mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));

    ll_container.addView(mLv);

    return ll_container;
}
 
Example 9
Source File: BoardView.java    From BoardView with Apache License 2.0 5 votes vote down vote up
private void switchItemFromPosition(int change,View view){
    LinearLayout parentLayout = (LinearLayout)(view.getParent());
    int columnPos = parentLayout.indexOfChild(view);
    if (columnPos + change >= 0 && columnPos + change < parentLayout.getChildCount()) {
        parentLayout.removeView(view);
        parentLayout.addView(view, columnPos + change);
        if (mDragItemStartCallback != null) {
            int newPos = parentLayout.indexOfChild(view);
            last_swap = System.currentTimeMillis();
            mLastSwap = newPos;
            int newColumnPos = ((LinearLayout) mobileView.getParent().getParent().getParent().getParent()).indexOfChild((View) (mobileView.getParent().getParent().getParent()));
            mDragItemStartCallback.changedPosition(view, originalItemPosition, originalPosition, newPos, newColumnPos);
        }
    }
}
 
Example 10
Source File: FixedIndicatorView.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
@Override
public void onChange() {
	if (!inRun.isFinished()) {
		inRun.stop();
	}
	positionOffset = 0;
	int count = getChildCount();
	int newCount = mAdapter.getCount();
	views.clear();
	for (int i = 0; i < count && i < newCount; i++) {
		views.add((ViewGroup) getChildAt(i));
	}
	removeAllViews();
	int size = views.size();
	for (int i = 0; i < newCount; i++) {
		LinearLayout result = new LinearLayout(getContext());
		View view;
		if (i < size) {
			View temp = views.get(i).getChildAt(0);
			views.get(i).removeView(temp);
			view = mAdapter.getView(i, temp, result);
		} else {
			view = mAdapter.getView(i, null, result);
		}
		result.addView(view);
		result.setOnClickListener(onClickListener);
		result.setTag(i);
		addView(result, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
	}
	mPreSelectedTabIndex = -1;
	setCurrentItem(mSelectedTabIndex, false);
	measureTabs();
}
 
Example 11
Source File: InputButton.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void addToLayout(LinearLayout root) {
    Button button = new Button(root.getContext());

    button.setText(text);
    button.setOnClickListener(view -> {
        if (runnable != null)
            runnable.run();
    });

    root.addView(button);
}
 
Example 12
Source File: EditPageLand.java    From LQRWeChat with MIT License 5 votes vote down vote up
private void initBottom(LinearLayout llBottom, float ratio) {
	LinearLayout llAt = new LinearLayout(activity);
	llAt.setPadding(0, 0, 0, 5);
	llAt.setBackgroundColor(0xffffffff);
	int bottomHeight = (int) (DESIGN_BOTTOM_HEIGHT * ratio);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, bottomHeight);
	llBottom.addView(llAt, lp);

	tvAt = new TextView(activity);
	tvAt.setTextColor(0xff3b3b3b);
	tvAt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	tvAt.setGravity(Gravity.BOTTOM);
	tvAt.setText("@");
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	tvAt.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	llAt.addView(tvAt, lp);
	tvAt.setOnClickListener(this);
	if (isShowAtUserLayout(platform.getName())) {
		tvAt.setVisibility(View.VISIBLE);
	} else {
		tvAt.setVisibility(View.INVISIBLE);
	}

	tvTextCouter = new TextView(activity);
	tvTextCouter.setTextColor(0xff3b3b3b);
	tvTextCouter.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
	tvTextCouter.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
	onTextChanged(etContent.getText(), 0, 0, 0);
	tvTextCouter.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	lp.weight = 1;
	llAt.addView(tvTextCouter, lp);

	View v = new View(activity);
	v.setBackgroundColor(0xffcccccc);
	int px1 = ratio > 1 ? ((int) ratio) : 1;
	lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, px1);
	llBottom.addView(v, lp);
}
 
Example 13
Source File: DrawerItemViewHelper.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
public View build() {
    //create the container view
    LinearLayout linearLayout = new LinearLayout(mContext);
    linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    //create the divider
    if (mDivider) {
        LinearLayout divider = new LinearLayout(mContext);
        divider.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        divider.setMinimumHeight((int) UIUtils.convertDpToPixel(1, mContext));
        divider.setOrientation(LinearLayout.VERTICAL);
        divider.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mContext, R.attr.material_drawer_divider, R.color.material_drawer_divider));
        linearLayout.addView(divider);
    }

    //add all drawer items
    for (IDrawerItem drawerItem : mDrawerItems) {
        View view = drawerItem.generateView(mContext);
        view.setTag(drawerItem);

        if (drawerItem.isEnabled()) {
            view.setBackgroundResource(DrawerUIUtils.getSelectableBackground(mContext));
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mOnDrawerItemClickListener != null) {
                        mOnDrawerItemClickListener.onItemClick(v, (IDrawerItem) v.getTag());
                    }
                }
            });
        }

        linearLayout.addView(view);
    }

    return linearLayout;
}
 
Example 14
Source File: ImagePreviewDialog.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
     * Default Constructor
     *
     * @param c
     */
    public ImagePreviewDialog(Context c) {
        super(c);
        LinearLayout fv = new LinearLayout(c);
        imageView = new ImageView(c);
        zoomInButton = new Button(c);
        zoomInButton.setText(c.getText(R.string.general_zoom_in));
        zoomInButton.setOnClickListener(this);
        zoomOutButton = new Button(c);
        zoomOutButton.setText(c.getText(R.string.general_zoom_out));
        zoomOutButton.setOnClickListener(this);
        centerButton = new Button(c);
        centerButton.setText(c.getText(R.string.general_center));
        centerButton.setOnClickListener(this);
        endButton = new Button(c);
        endButton.setText(c.getText(R.string.general_back));
        endButton.setOnClickListener(this);
        LinearLayout buttonContainer = new LinearLayout(c);
        buttonContainer.setOrientation(LinearLayout.HORIZONTAL);
        buttonContainer.addView(zoomInButton);
        buttonContainer.addView(zoomOutButton);
        buttonContainer.addView(centerButton);
        buttonContainer.addView(endButton);
        imageView.setOnClickListener(this);
        imageView.setOnTouchListener(this);
        gestureDetector = new GestureDetector(this);

//		height is a hack set for the G1 phone
//		imageView.setLayoutParams(new LayoutParams(-1, -1));

        fv.addView(buttonContainer);
        fv.addView(imageView);
        fv.setOrientation(LinearLayout.VERTICAL);
        fv.setGravity(Gravity.CENTER_HORIZONTAL);
        fv.setLayoutParams(new LayoutParams(150, -1));
        setTitle("View Photos");
        setContentView(fv);
    }
 
Example 15
Source File: MainActivity.java    From VirtualAPK with Apache License 2.0 5 votes vote down vote up
public void onButtonClick(View v) {
    if (v.getId() == R.id.button) {
        final String pkg = "com.didi.virtualapk.demo";
        if (PluginManager.getInstance(this).getLoadedPlugin(pkg) == null) {
            Toast.makeText(this, "plugin [com.didi.virtualapk.demo] not loaded", Toast.LENGTH_SHORT).show();
            return;
        }

        // test Activity and Service
        Intent intent = new Intent();
        intent.setClassName(this, "com.didi.virtualapk.demo.aidl.BookManagerActivity");
        startActivity(intent);

        // test ContentProvider
        Uri bookUri = Uri.parse("content://com.didi.virtualapk.demo.book.provider/book");
        LoadedPlugin plugin = PluginManager.getInstance(this).getLoadedPlugin(pkg);
        bookUri = PluginContentResolver.wrapperUri(plugin, bookUri);

        Cursor bookCursor = getContentResolver().query(bookUri, new String[]{"_id", "name"}, null, null, null);
        if (bookCursor != null) {
            while (bookCursor.moveToNext()) {
                int bookId = bookCursor.getInt(0);
                String bookName = bookCursor.getString(1);
                Log.d("ryg", "query book:" + bookId + ", " + bookName);
            }
            bookCursor.close();
        }
    } else if (v.getId() == R.id.about) {
        showAbout();
    } else if (v.getId() == R.id.webview) {
        LinearLayout linearLayout = (LinearLayout) v.getParent();
        WebView webView = new WebView(this);
        linearLayout.addView(webView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1));
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("http://github.com/didi/VirtualAPK");
    }
}
 
Example 16
Source File: PhotoPickerAlbumsCell.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public AlbumView(Context context) {
    super(context);

    imageView = new BackupImageView(context);
    addView(imageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setBackgroundColor(0x7f000000);
    addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 28, Gravity.LEFT | Gravity.BOTTOM));

    nameTextView = new TextView(context);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    nameTextView.setTextColor(0xffffffff);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setMaxLines(1);
    nameTextView.setGravity(Gravity.CENTER_VERTICAL);
    linearLayout.addView(nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 8, 0, 0, 0));

    countTextView = new TextView(context);
    countTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    countTextView.setTextColor(0xffaaaaaa);
    countTextView.setSingleLine(true);
    countTextView.setEllipsize(TextUtils.TruncateAt.END);
    countTextView.setMaxLines(1);
    countTextView.setGravity(Gravity.CENTER_VERTICAL);
    linearLayout.addView(countTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, 4, 0, 4, 0));

    selector = new View(context);
    selector.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
}
 
Example 17
Source File: PaymentRequestUI.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares the PaymentRequestUI for initial display.
 *
 * TODO(dfalcantara): Ideally, everything related to the request and its views would just be put
 *                    into its own class but that'll require yanking out a lot of this class.
 *
 * @param activity Activity displaying the UI.
 * @param title    Title of the page.
 * @param origin   Host of the page.
 */
private void prepareRequestView(Activity activity, String title, String origin) {
    mSpinnyLayout = mRequestView.findViewById(R.id.payment_request_spinny);

    // Indicate that we're preparing the dialog for display.
    TextView messageView = (TextView) mRequestView.findViewById(R.id.message);
    messageView.setText(R.string.payments_loading_message);

    ((TextView) mRequestView.findViewById(R.id.page_title)).setText(title);
    ((TextView) mRequestView.findViewById(R.id.hostname)).setText(origin);

    // Set up the buttons.
    mCloseButton = mRequestView.findViewById(R.id.close_button);
    mCloseButton.setOnClickListener(this);
    mPayButton = DualControlLayout.createButtonForLayout(
            activity, true, activity.getString(R.string.payments_pay_button), this);
    mEditButton = DualControlLayout.createButtonForLayout(
            activity, false, activity.getString(R.string.payments_edit_button), this);
    mButtonBar = (DualControlLayout) mRequestView.findViewById(R.id.button_bar);
    mButtonBar.setAlignment(DualControlLayout.ALIGN_END);
    mButtonBar.setStackedMargin(activity.getResources().getDimensionPixelSize(
            R.dimen.infobar_margin_between_stacked_buttons));
    mButtonBar.addView(mPayButton);
    mButtonBar.addView(mEditButton);

    // Create all the possible sections.
    mSectionSeparators = new ArrayList<SectionSeparator>();
    mPaymentContainer = (ScrollView) mRequestView.findViewById(R.id.option_container);
    mPaymentContainerLayout =
            (LinearLayout) mRequestView.findViewById(R.id.payment_container_layout);
    mOrderSummarySection = new LineItemBreakdownSection(activity,
            activity.getString(R.string.payments_order_summary_label), this);
    mShippingSummarySection = new ExtraTextSection(activity,
            activity.getString(R.string.payments_shipping_summary_label), this);
    mShippingAddressSection = new OptionSection(activity,
            activity.getString(R.string.payments_shipping_address_label),
            activity.getString(R.string.payments_select_shipping_address_prompt), this);
    mShippingOptionSection = new OptionSection(activity,
            activity.getString(R.string.payments_shipping_option_label),
            activity.getString(R.string.payments_select_shipping_option_prompt), this);
    mContactDetailsSection = new OptionSection(activity,
            activity.getString(R.string.payments_contact_details_label),
            activity.getString(R.string.payments_select_contact_details_prompt), this);
    mPaymentMethodSection = new OptionSection(activity,
            activity.getString(R.string.payments_method_of_payment_label), null, this);

    // Add the necessary sections to the layout.
    mPaymentContainerLayout.addView(mOrderSummarySection, new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout));
    if (mRequestShipping) {
        // The shipping breakout sections are only added if they are needed.
        mPaymentContainerLayout.addView(mShippingSummarySection, new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout));
    }
    mPaymentContainerLayout.addView(mPaymentMethodSection, new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    if (mRequestContactDetails) {
        // Contact details are optional, depending on the merchant website.
        mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout));
        mPaymentContainerLayout.addView(mContactDetailsSection, new LinearLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    }
    mRequestView.addOnLayoutChangeListener(new FadeInAnimator());
    mRequestView.addOnLayoutChangeListener(new PeekingAnimator());

    // Enabled in updatePayButtonEnabled() when the user has selected all payment options.
    mPayButton.setEnabled(false);
}
 
Example 18
Source File: EditorView.java    From Nimbus with GNU General Public License v3.0 4 votes vote down vote up
public EditorView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);


    inflater = LayoutInflater.from(context);

    allLayout = new LinearLayout(context);
    allLayout.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    addView(allLayout, layoutParams);

    onClickListener = new OnClickListener() {
        @Override
        public void onClick(View view) {
            allLayout.removeView(view);
        }
    };

    focusChangeListener = new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean b) {
            if (b) {
                lastEditText = (EditText) view;
            }
        }
    };

    keyListener = new OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_DEL) {
                EditText editText = (EditText) view;
                onBackPress(editText);
            }
            return false;
        }
    };

    EditText e = createEditText("Title", dip2px(10));
    LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    allLayout.addView(e, p);

    EditText content = createEditText("Enter Description or Insert Any Image", dip2px(10));
    LinearLayout.LayoutParams contentp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    allLayout.addView(content, contentp
    );
    lastEditText = content;

}
 
Example 19
Source File: ConfirmPopup.java    From AndroidPicker with MIT License 4 votes vote down vote up
/**
 * @see #makeHeaderView()
 * @see #makeCenterView()
 * @see #makeFooterView()
 */
@Override
protected final View makeContentView() {
    LinearLayout rootLayout = new LinearLayout(activity);
    rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    rootLayout.setBackgroundColor(backgroundColor);
    rootLayout.setOrientation(LinearLayout.VERTICAL);
    rootLayout.setGravity(Gravity.CENTER);
    rootLayout.setPadding(0, 0, 0, 0);
    rootLayout.setClipToPadding(false);
    View headerView = makeHeaderView();
    if (headerView != null) {
        rootLayout.addView(headerView);
    }
    if (topLineVisible) {
        View lineView = new View(activity);
        lineView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, topLineHeightPixels));
        lineView.setBackgroundColor(topLineColor);
        rootLayout.addView(lineView);
    }
    if (centerView == null) {
        centerView = makeCenterView();
    }
    int lr = 0;
    int tb = 0;
    if (contentLeftAndRightPadding > 0) {
        lr = ConvertUtils.toPx(activity, contentLeftAndRightPadding);
    }
    if (contentTopAndBottomPadding > 0) {
        tb = ConvertUtils.toPx(activity, contentTopAndBottomPadding);
    }
    centerView.setPadding(lr, tb, lr, tb);
    ViewGroup vg = (ViewGroup) centerView.getParent();
    if (vg != null) {
        //IllegalStateException: The specified child already has a parent
        vg.removeView(centerView);
    }
    rootLayout.addView(centerView, new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
    View footerView = makeFooterView();
    if (footerView != null) {
        rootLayout.addView(footerView);
    }
    return rootLayout;
}
 
Example 20
Source File: ProviderTable.java    From ssj with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param activity   Activity
 * @param mainObject Object
 * @param dividerTop boolean
 * @return TableRow
 */
public static TableRow createStreamTable(Activity activity, final Object mainObject, boolean dividerTop, int heading)
{
    TableRow tableRow = new TableRow(activity);
    tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
    LinearLayout linearLayout = new LinearLayout(activity);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    if (dividerTop)
    {
        //add divider
        linearLayout.addView(Util.addDivider(activity));
    }
    TextView textViewName = new TextView(activity);
    textViewName.setText(heading);
    textViewName.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
    textViewName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
    linearLayout.addView(textViewName);
    //get possible providers
    final Object[] objects = PipelineBuilder.getInstance().getPossibleStreamConnections(mainObject);
    //
    if (objects.length > 0) {
        for (int i = 0; i < objects.length; i++) {
            CheckBox checkBox = new CheckBox(activity);
            checkBox.setText(objects[i].getClass().getSimpleName());
            checkBox.setTextSize(TypedValue.COMPLEX_UNIT_SP, 19);
            Object[] providers = PipelineBuilder.getInstance().getStreamConnections(mainObject);
            if (providers != null) {
                for (Object provider : providers) {
                    if (objects[i].equals(provider)) {
                        checkBox.setChecked(true);
                        break;
                    }
                }
            }
            final int count = i;
            checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                final Object o = objects[count];

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        PipelineBuilder.getInstance().addStreamConnection(mainObject, (Provider) o);
                    } else {
                        PipelineBuilder.getInstance().removeStreamConnection(mainObject, (Provider) o);
                    }
                }
            });
            linearLayout.addView(checkBox);
        }
    } else
    {
        return null;
    }
    tableRow.addView(linearLayout);
    return tableRow;
}