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

The following examples show how to use android.widget.LinearLayout#setBackground() . 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: RoundCornerProgressBar.java    From RoundCornerProgressBar with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawProgress(@NonNull LinearLayout layoutProgress,
                            @NonNull GradientDrawable progressDrawable,
                            float max,
                            float progress,
                            float totalWidth,
                            int radius,
                            int padding,
                            boolean isReverse) {
    int newRadius = radius - (padding / 2);
    progressDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius});
    layoutProgress.setBackground(progressDrawable);
    float ratio = max / progress;
    int progressWidth = (int) ((totalWidth - (padding * 2)) / ratio);
    ViewGroup.MarginLayoutParams progressParams = (ViewGroup.MarginLayoutParams) layoutProgress.getLayoutParams();
    progressParams.width = progressWidth;
    if (padding + (progressWidth / 2) < radius) {
        int margin = Math.max(radius - padding, 0) - (progressWidth / 2);
        progressParams.topMargin = margin;
        progressParams.bottomMargin = margin;
    } else {
        progressParams.topMargin = 0;
        progressParams.bottomMargin = 0;
    }
    layoutProgress.setLayoutParams(progressParams);
}
 
Example 2
Source File: EmptyLoadingView.java    From android_tv_metro with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void init(Context context) {
	LayoutInflater.from(context).inflate(R.layout.empty_loading_layout, this);
	mProgressLayout = (LinearLayout) this.findViewById(R.id.progress_layout);
	mProgressView = (ImageView) this.findViewById(R.id.empty_progress_view);

	mEmptyView = (LinearLayout) this.findViewById(R.id.empty_layout);
       if(Build.VERSION.SDK_INT >= 16){
           mEmptyView.setBackground(null);
       }else {
           mEmptyView.setBackgroundDrawable(null);
       }
	mTextView = (TextView) this.findViewById(R.id.empty_textview);
	mTextView.getPaint().setFakeBoldText(true);

}
 
Example 3
Source File: RoundCornerProgressBar.java    From RoundCornerProgressBar with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawProgress(@NonNull LinearLayout layoutProgress,
                            @NonNull GradientDrawable progressDrawable,
                            float max,
                            float progress,
                            float totalWidth,
                            int radius,
                            int padding,
                            boolean isReverse) {
    int newRadius = radius - (padding / 2);
    progressDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius});
    layoutProgress.setBackground(progressDrawable);
    float ratio = max / progress;
    int progressWidth = (int) ((totalWidth - (padding * 2)) / ratio);
    ViewGroup.MarginLayoutParams progressParams = (ViewGroup.MarginLayoutParams) layoutProgress.getLayoutParams();
    progressParams.width = progressWidth;
    if (padding + (progressWidth / 2) < radius) {
        int margin = Math.max(radius - padding, 0) - (progressWidth / 2);
        progressParams.topMargin = margin;
        progressParams.bottomMargin = margin;
    } else {
        progressParams.topMargin = 0;
        progressParams.bottomMargin = 0;
    }
    layoutProgress.setLayoutParams(progressParams);
}
 
Example 4
Source File: MaterialNavHeadItemActivity.java    From AdvancedMaterialDrawer with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@SuppressWarnings("deprecation")
private void initHeadViews() {
    headItemTitle = (TextView) this.findViewById(R.id.current_head_item_title);
    headItemTitle.setTextColor(headItemTitleColor);

    headItemSubTitle = (TextView) this.findViewById(R.id.current_head_item_sub_title);
    headItemSubTitle.setTextColor(headItemSubTitleColor);

    headItemFirstPhoto = (ImageView) this.findViewById(R.id.current_head_item_photo);
    headItemSecondPhoto = (ImageView) this.findViewById(R.id.second_head_item_photo);
    headItemThirdPhoto = (ImageView) this.findViewById(R.id.third_head_item_photo);
    headItemBackground = (ImageView) this.findViewById(R.id.current_back_item_background);
    headItemBackgroundSwitcher = (ImageView) this.findViewById(R.id.background_switcher);
    headItemButtonSwitcher = (ImageButton) this.findViewById(R.id.user_switcher);
    headItemBackgroundGradientLL = (LinearLayout) this.findViewById(R.id.background_gradient);
    int sdk = android.os.Build.VERSION.SDK_INT;
    if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        headItemBackgroundGradientLL.setBackgroundDrawable(headItemBackgroundGradient);
    } else {
        headItemBackgroundGradientLL.setBackground(headItemBackgroundGradient);
    }
}
 
Example 5
Source File: RxRoundProgressBar.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void drawProgress(LinearLayout layoutProgress, float max, float progress, float totalWidth,
                            int radius, int padding, int colorProgress, boolean isReverse) {
    GradientDrawable backgroundDrawable = createGradientDrawable(colorProgress);
    int newRadius = radius - (padding / 2);
    backgroundDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius});
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutProgress.setBackground(backgroundDrawable);
    } else {
        layoutProgress.setBackgroundDrawable(backgroundDrawable);
    }

    float ratio = max / progress;
    int progressWidth = (int) ((totalWidth - (padding * 2)) / ratio);
    ViewGroup.LayoutParams progressParams = layoutProgress.getLayoutParams();
    progressParams.width = progressWidth;
    layoutProgress.setLayoutParams(progressParams);
}
 
Example 6
Source File: RxTextRoundProgressBar.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
@Override
protected void drawProgress(LinearLayout layoutProgress, float max, float progress, float totalWidth,
                            int radius, int padding, int colorProgress, boolean isReverse) {
    GradientDrawable backgroundDrawable = createGradientDrawable(colorProgress);
    int newRadius = radius - (padding / 2);
    backgroundDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius});
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutProgress.setBackground(backgroundDrawable);
    } else {
        layoutProgress.setBackgroundDrawable(backgroundDrawable);
    }

    float ratio = max / progress;
    int progressWidth = (int) ((totalWidth - (padding * 2)) / ratio);
    ViewGroup.LayoutParams progressParams = layoutProgress.getLayoutParams();
    progressParams.width = progressWidth;
    layoutProgress.setLayoutParams(progressParams);
}
 
Example 7
Source File: RxIconRoundProgressBar.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void drawProgress(LinearLayout layoutProgress, float max, float progress, float totalWidth,
                            int radius, int padding, int colorProgress, boolean isReverse) {
    GradientDrawable backgroundDrawable = createGradientDrawable(colorProgress);
    int newRadius = radius - (padding / 2);
    if (isReverse && progress != max)
        backgroundDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius});
    else
        backgroundDrawable.setCornerRadii(new float[]{0, 0, newRadius, newRadius, newRadius, newRadius, 0, 0});

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        layoutProgress.setBackground(backgroundDrawable);
    } else {
        layoutProgress.setBackgroundDrawable(backgroundDrawable);
    }

    float ratio = max / progress;
    int progressWidth = (int) ((totalWidth - ((padding * 2) + ivProgressIcon.getWidth())) / ratio);
    ViewGroup.LayoutParams progressParams = layoutProgress.getLayoutParams();
    progressParams.width = progressWidth;
    layoutProgress.setLayoutParams(progressParams);
}
 
Example 8
Source File: TorqueHistogram.java    From mobile-android-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TorqueHistogram(Context context, TorqueShipActivity activity) {

        super(context);

        intervals = new ArrayList<>();

        outerContainer = new RelativeLayout(context);
        addView(outerContainer);

        container = new LinearLayout(context);
        container.setOrientation(LinearLayout.HORIZONTAL);

        GradientDrawable drawable = new GradientDrawable();
        drawable.setColor(BackgroundColor);
        drawable.setCornerRadius(5);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            container.setBackground(drawable);
        } else {
            container.setBackgroundColor(BackgroundColor);
        }

        container.setLayoutParams(new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT)
        );

        indicator = new TorqueIndicator(context);

        Counter = new TorqueCounter(context);

        Button = new TorqueButton(context, activity);

        histogramInterface = activity;
    }
 
Example 9
Source File: AProgressBar.java    From Stylish-Widget-for-Android with Apache License 2.0 5 votes vote down vote up
private GradientDrawable createGradientDrawableWithCorner(LinearLayout layout, int color) {
        GradientDrawable backgroundDrawable = createGradientDrawable(color);
        int newRadius = radius;
        backgroundDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius});

//        backgroundDrawable.setCornerRadii(new float[]{0, 0, newRadius, newRadius, newRadius, newRadius, 0, 0});

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            layout.setBackground(backgroundDrawable);
        } else {
            layout.setBackgroundDrawable(backgroundDrawable);
        }
        return backgroundDrawable;
    }
 
Example 10
Source File: MaterialDialog.java    From DialogUtil with Apache License 2.0 5 votes vote down vote up
public void setBackground(Drawable drawable) {
    LinearLayout linearLayout = (LinearLayout) mAlertDialogWindow.findViewById(
            R.id.material_background);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        linearLayout.setBackground(drawable);
    }
}
 
Example 11
Source File: AppCompat.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
public static void useSimpleStyleForSearchView(SearchView searchView, String hint){
    AppCompatImageView search = searchView.findViewById(androidx.appcompat.R.id.search_mag_icon);
    search.setImageDrawable(null);
    LinearLayout plate = searchView.findViewById(R.id.search_plate);
    plate.setBackground(null);
    AppCompatImageView close = searchView.findViewById(R.id.search_close_btn);
    AppCompat.setTint(close, searchView.getResources().getColor(R.color.colorBarText));
    SearchView.SearchAutoComplete searchAutoComplete = searchView.findViewById(R.id.search_src_text);
    searchAutoComplete.setHint(hint);
}
 
Example 12
Source File: TextRoundCornerProgressBar.java    From RoundCornerProgressBar with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawProgress(@NonNull LinearLayout layoutProgress,
                            @NonNull GradientDrawable progressDrawable,
                            float max,
                            float progress,
                            float totalWidth,
                            int radius,
                            int padding,
                            boolean isReverse) {
    int newRadius = radius - (padding / 2);
    progressDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius});
    layoutProgress.setBackground(progressDrawable);

    float ratio = max / progress;
    int progressWidth = (int) ((totalWidth - (padding * 2)) / ratio);
    ViewGroup.MarginLayoutParams progressParams = (ViewGroup.MarginLayoutParams) layoutProgress.getLayoutParams();
    if (padding + (progressWidth / 2) < radius) {
        int margin = Math.max(radius - padding, 0) - (progressWidth / 2);
        progressParams.topMargin = margin;
        progressParams.bottomMargin = margin;
    } else {
        progressParams.topMargin = 0;
        progressParams.bottomMargin = 0;
    }
    progressParams.width = progressWidth;
    layoutProgress.setLayoutParams(progressParams);
}
 
Example 13
Source File: IconRoundCornerProgressBar.java    From RoundCornerProgressBar with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawProgress(@NonNull LinearLayout layoutProgress,
                            @NonNull GradientDrawable progressDrawable,
                            float max,
                            float progress,
                            float totalWidth,
                            int radius,
                            int padding,
                            boolean isReverse) {
    int newRadius = radius - (padding / 2);
    if (isReverse && progress != max) {
        progressDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius});
    } else {
        progressDrawable.setCornerRadii(new float[]{0, 0, newRadius, newRadius, newRadius, newRadius, 0, 0});
    }
    layoutProgress.setBackground(progressDrawable);

    float ratio = max / progress;
    int progressWidth = (int) ((totalWidth - ((padding * 2) + ivProgressIcon.getWidth())) / ratio);
    ViewGroup.MarginLayoutParams progressParams = (ViewGroup.MarginLayoutParams) layoutProgress.getLayoutParams();
    if (isReverse) {
        if (padding + (progressWidth / 2) < radius) {
            int margin = Math.max(radius - padding, 0) - (progressWidth / 2);
            progressParams.topMargin = margin;
            progressParams.bottomMargin = margin;
        } else {
            progressParams.topMargin = 0;
            progressParams.bottomMargin = 0;
        }
    }
    progressParams.width = progressWidth;
    layoutProgress.setLayoutParams(progressParams);
}
 
Example 14
Source File: BackgroundBitmapLoaderTask.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
protected void onPostExecute(Bitmap bitmap) {
    if (linearLayoutReference != null && bitmap != null) {
        final LinearLayout linearLayout = linearLayoutReference.get();
        if (linearLayout != null) {
            if (Build.VERSION.SDK_INT >= 16)
                linearLayout.setBackground(new BitmapDrawable(resources, bitmap));
            else
                linearLayout.setBackgroundDrawable(new BitmapDrawable(resources, bitmap));
        }
    }
}
 
Example 15
Source File: IconRoundCornerProgressBar.java    From RoundCornerProgressBar with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawProgress(@NonNull LinearLayout layoutProgress,
                            @NonNull GradientDrawable progressDrawable,
                            float max,
                            float progress,
                            float totalWidth,
                            int radius,
                            int padding,
                            boolean isReverse) {
    int newRadius = radius - (padding / 2);
    if (isReverse && progress != max) {
        progressDrawable.setCornerRadii(new float[]{newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius, newRadius});
    } else {
        progressDrawable.setCornerRadii(new float[]{0, 0, newRadius, newRadius, newRadius, newRadius, 0, 0});
    }
    layoutProgress.setBackground(progressDrawable);

    float ratio = max / progress;
    int progressWidth = (int) ((totalWidth - ((padding * 2) + ivProgressIcon.getWidth())) / ratio);
    ViewGroup.MarginLayoutParams progressParams = (ViewGroup.MarginLayoutParams) layoutProgress.getLayoutParams();
    if (isReverse) {
        if (padding + (progressWidth / 2) < radius) {
            int margin = Math.max(radius - padding, 0) - (progressWidth / 2);
            progressParams.topMargin = margin;
            progressParams.bottomMargin = margin;
        } else {
            progressParams.topMargin = 0;
            progressParams.bottomMargin = 0;
        }
    }
    progressParams.width = progressWidth;
    layoutProgress.setLayoutParams(progressParams);
}
 
Example 16
Source File: ProjectAdapter.java    From microbit with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    Project project = mProjects.get(position);
    if(convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(MBApp.getApp());
        convertView = inflater.inflate(R.layout.project_items, null);
    }

    Button appNameButton = (Button) convertView.findViewById(R.id.appNameButton);
    appNameButton.setTypeface(MBApp.getApp().getRobotoTypeface());

    ExtendedEditText appNameEdit = (ExtendedEditText) convertView.findViewById(R.id.appNameEdit);
    appNameEdit.setTypeface(MBApp.getApp().getRobotoTypeface());

    LinearLayout actionBarLayout = (LinearLayout) convertView.findViewById(R.id.actionBarForProgram);
    if(actionBarLayout != null) {
        if(project.actionBarExpanded) {
            actionBarLayout.setVisibility(View.VISIBLE);
            appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
                    , R.drawable.ic_arrow_down), null);
        } else {
            actionBarLayout.setVisibility(View.GONE);
            appNameButton.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(MBApp.getApp()
                    , R.drawable.ic_arrow_left), null);
        }
    }

    appNameButton.setText(project.name);
    appNameButton.setTag(R.id.positionId, position);
    appNameButton.setTag(R.id.textEdit, appNameEdit);
    appNameButton.setOnClickListener(appNameClickListener);
    appNameButton.setOnLongClickListener(appNameLongClickListener);

    appNameEdit.setTag(R.id.positionId, position);
    appNameEdit.setTag(R.id.editbutton, appNameButton);
    appNameEdit.setOnEditorActionListener(editorOnActionListener);
    appNameEdit.setFilters(new InputFilter[]{renameFilter});

    if(project.inEditMode) {
        appNameEdit.setVisibility(View.VISIBLE);

        appNameEdit.setText(project.name);
        appNameEdit.setSelection(project.name.length());
        appNameEdit.requestFocus();
        appNameButton.setVisibility(View.INVISIBLE);

    } else {
        appNameEdit.setVisibility(View.INVISIBLE);
        appNameButton.setVisibility(View.VISIBLE);
        //dismissKeyBoard(appNameEdit, false);
    }

    //appNameEdit.setOnClickListener(appNameClickListener);

    TextView flashBtnText = (TextView) convertView.findViewById(R.id.project_item_text);
    flashBtnText.setTypeface(MBApp.getApp().getRobotoTypeface());
    LinearLayout sendBtnLayout = (LinearLayout) convertView.findViewById(R.id.sendBtn);
    sendBtnLayout.setTag(position);
    sendBtnLayout.setOnClickListener(sendBtnClickListener);

    ImageButton deleteBtn = (ImageButton) convertView.findViewById(R.id.deleteBtn);
    deleteBtn.setTag(position);
    deleteBtn.setOnClickListener(deleteBtnClickListener);
    deleteBtn.setEnabled(true);


    Drawable myIcon;
    if(project.runStatus) {
        flashBtnText.setText("");
        myIcon = convertView.getResources().getDrawable(R.drawable.green_btn);
    } else {
        flashBtnText.setText(R.string.flash);
        myIcon = convertView.getResources().getDrawable(R.drawable.blue_btn);
    }
    sendBtnLayout.setBackground(myIcon);

    sendBtnLayout.setClickable(true);
    return convertView;
}
 
Example 17
Source File: GTwoAutoCompleteConnectedTextView.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param context               the context to use.
 * @param attrs                 attributes.
 * @param parentView            parent
 * @param label                 label
 * @param value                 _value
 * @param dataMap               the map of the data.
 * @param constraintDescription constraints
 */
public GTwoAutoCompleteConnectedTextView(Context context, AttributeSet attrs, LinearLayout parentView, String label, String value,
                                         LinkedHashMap<String, List<String>> dataMap, String constraintDescription) {
    super(context, attrs);
    this.dataMap = dataMap;

    if (value == null)
        value = "";

    String[] valueSplit = value.split(SEP);
    String _combo1Value;
    String _combo2Value;
    if (valueSplit.length == 2) {
        _combo1Value = valueSplit[0];
        _combo2Value = valueSplit[1];
    } else {
        _combo1Value = "";
        _combo2Value = "";
    }

    selectedCombo1Entry = _combo1Value;
    selectedCombo2Entry = _combo2Value;

    TextView textView = new TextView(context);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    textViewParams.setMargins(15, 25, 15, 15);
    textView.setLayoutParams(textViewParams);
    textView.setPadding(2, 2, 2, 2);
    textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(Compat.getColor(context, R.color.formcolor));
    parentView.addView(textView);

    LinearLayout combosLayout = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    combosLayout.setLayoutParams(layoutParams);
    combosLayout.setOrientation(LinearLayout.VERTICAL);
    combosLayout.setBackground(Compat.getDrawable(context, R.drawable.thin_background_frame));
    parentView.addView(combosLayout);

    createCombo1(context, _combo1Value, dataMap);

    List<String> combo2ItemsList = new ArrayList<>();
    if (_combo1Value.length() > 0) {
        combo2ItemsList = dataMap.get(_combo1Value);
    }

    createCombo2(context, _combo2Value, combo2ItemsList);

    combosLayout.addView(autoCompleteTextView1);
    combosLayout.addView(autoCompleteTextView2);
}
 
Example 18
Source File: ClickableToast.java    From Dashchan with Apache License 2.0 4 votes vote down vote up
private ClickableToast(Holder holder) {
	this.holder = holder;
	Context context = holder.context;
	float density = ResourceUtils.obtainDensity(context);
	int innerPadding = (int) (8f * density);
	LayoutInflater inflater = LayoutInflater.from(context);
	View toast1 = inflater.inflate(LAYOUT_ID, null);
	View toast2 = inflater.inflate(LAYOUT_ID, null);
	TextView message1 = toast1.findViewById(android.R.id.message);
	TextView message2 = toast2.findViewById(android.R.id.message);
	View backgroundSource = null;
	Drawable backgroundDrawable = toast1.getBackground();
	if (backgroundDrawable == null) {
		backgroundDrawable = message1.getBackground();
		if (backgroundDrawable == null) {
			View messageParent = (View) message1.getParent();
			if (messageParent != null) {
				backgroundDrawable = messageParent.getBackground();
				backgroundSource = messageParent;
			}
		} else {
			backgroundSource = message1;
		}
	} else {
		backgroundSource = toast1;
	}

	StringBuilder builder = new StringBuilder();
	for (int i = 0; i < 100; i++) builder.append('W'); // Make long text
	message1.setText(builder); // Avoid minimum widths
	int measureSize = (int) (context.getResources().getConfiguration().screenWidthDp * density + 0.5f);
	toast1.measure(View.MeasureSpec.makeMeasureSpec(measureSize, View.MeasureSpec.AT_MOST),
			View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
	toast1.layout(0, 0, toast1.getMeasuredWidth(), toast1.getMeasuredHeight());
	Rect backgroundSourceTotalPadding = getViewTotalPadding(toast1, backgroundSource);
	Rect messageTotalPadding = getViewTotalPadding(toast1, message1);
	messageTotalPadding.left -= backgroundSourceTotalPadding.left;
	messageTotalPadding.top -= backgroundSourceTotalPadding.top;
	messageTotalPadding.right -= backgroundSourceTotalPadding.right;
	messageTotalPadding.bottom -= backgroundSourceTotalPadding.bottom;
	int horizontalPadding = Math.max(messageTotalPadding.left, messageTotalPadding.right) +
			Math.max(message1.getPaddingLeft(), message1.getPaddingRight());
	int verticalPadding = Math.max(messageTotalPadding.top, messageTotalPadding.bottom) +
			Math.max(message1.getPaddingTop(), message1.getPaddingBottom());

	ViewUtils.removeFromParent(message1);
	ViewUtils.removeFromParent(message2);
	LinearLayout linearLayout = new LinearLayout(context);
	linearLayout.setOrientation(LinearLayout.HORIZONTAL);
	linearLayout.setDividerDrawable(new ToastDividerDrawable(0xccffffff, (int) (density + 0.5f)));
	linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
	linearLayout.setDividerPadding((int) (4f * density));
	linearLayout.setTag(this);
	linearLayout.addView(message1, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
	linearLayout.addView(message2, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
	((LinearLayout.LayoutParams) message1.getLayoutParams()).weight = 1f;
	linearLayout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

	partialClickDrawable = new PartialClickDrawable(backgroundDrawable);
	message1.setBackground(null);
	message2.setBackground(null);
	linearLayout.setBackground(partialClickDrawable);
	linearLayout.setOnTouchListener(partialClickDrawable);
	message1.setPadding(0, 0, 0, 0);
	message2.setPadding(innerPadding, 0, 0, 0);
	message1.setSingleLine(true);
	message2.setSingleLine(true);
	message1.setEllipsize(TextUtils.TruncateAt.END);
	message2.setEllipsize(TextUtils.TruncateAt.END);
	container = linearLayout;
	message = message1;
	button = message2;

	windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
}
 
Example 19
Source File: GTwoConnectedComboView.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param context               the context to use.
 * @param attrs                 attributes.
 * @param parentView            parent
 * @param label                 label
 * @param value                 _value
 * @param dataMap               the map of the data.
 * @param constraintDescription constraints
 */
public GTwoConnectedComboView(Context context, AttributeSet attrs, LinearLayout parentView, String label, String value,
                              LinkedHashMap<String, List<String>> dataMap, String constraintDescription) {
    super(context, attrs);
    this.dataMap = dataMap;

    if (value == null)
        value = "";

    String[] valueSplit = value.split(SEP);
    String _combo1Value;
    String _combo2Value;
    if (valueSplit.length == 2) {
        _combo1Value = valueSplit[0];
        _combo2Value = valueSplit[1];
    } else {
        _combo1Value = "";
        _combo2Value = "";
    }

    TextView textView = new TextView(context);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    textViewParams.setMargins(15, 25, 15, 15);
    textView.setLayoutParams(textViewParams);
    textView.setPadding(2, 2, 2, 2);
    textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(Compat.getColor(context, R.color.formcolor));
    parentView.addView(textView);

    LinearLayout combosLayout = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    combosLayout.setLayoutParams(layoutParams);
    combosLayout.setOrientation(LinearLayout.VERTICAL);
    combosLayout.setBackground(Compat.getDrawable(context, R.drawable.thin_background_frame));
    parentView.addView(combosLayout);

    combo1Spinner = new Spinner(context);
    LinearLayout.LayoutParams titleSpinnerParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    titleSpinnerParams.setMargins(15, 25, 15, 15);
    combo1Spinner.setLayoutParams(titleSpinnerParams);
    Set<String> titlesSet = dataMap.keySet();
    ArrayList<String> combo1Items = new ArrayList<>(titlesSet);
    combo1Items.add(0, "");
    ArrayAdapter<String> titleListAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, combo1Items);
    titleListAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    combo1Spinner.setAdapter(titleListAdapter);
    combo1Spinner.setPopupBackgroundDrawable(Compat.getDrawable(context, R.drawable.thin_background_frame));
    combo1Spinner.setBackground(Compat.getDrawable(context, R.drawable.thin_background_frame));
    int minHeight = getMinComboHeight(context);
    combo1Spinner.setMinimumHeight(minHeight);

    combo2Spinner = new Spinner(context);
    LinearLayout.LayoutParams valueSpinnerParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    valueSpinnerParams.setMargins(15, 25, 15, 15);
    combo2Spinner.setLayoutParams(valueSpinnerParams);
    combo2Spinner.setPopupBackgroundDrawable(Compat.getDrawable(context, R.drawable.thin_background_frame));
    combo2Spinner.setBackground(Compat.getDrawable(context, R.drawable.thin_background_frame));
    combo2Spinner.setMinimumHeight(minHeight);

    List<String> combo2ItemsList = new ArrayList<>();
    if (_combo1Value.length() > 0) {
        combo2ItemsList = dataMap.get(_combo1Value);
        int indexOf = combo1Items.indexOf(_combo1Value.trim());
        if (indexOf != -1) {
            combo1Spinner.setSelection(indexOf, false);
        }
    }
    ArrayAdapter<String> combo2ListAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, combo2ItemsList);
    combo2ListAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    combo2Spinner.setAdapter(combo2ListAdapter);

    combosLayout.addView(combo1Spinner);
    combosLayout.addView(combo2Spinner);

    if (_combo2Value.length() > 0) {
        int position = combo2ListAdapter.getPosition(_combo2Value);
        combo2Spinner.setSelection(position, false);
    }

    combo1Spinner.setOnItemSelectedListener(this);
}
 
Example 20
Source File: MaterialDialog.java    From pius1 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setBackground(Drawable drawable)
{
           LinearLayout linearLayout = (LinearLayout) mAlertDialogWindow.findViewById(
	R.id.material_background);
           linearLayout.setBackground(drawable);
       }