Example usage for android.view View inflate

List of usage examples for android.view View inflate

Introduction

In this page you can find the example usage for android.view View inflate.

Prototype

public static View inflate(Context context, @LayoutRes int resource, ViewGroup root) 

Source Link

Document

Inflate a view from an XML resource.

Usage

From source file:com.wlanjie.streaming.camera.CameraView.java

@SuppressWarnings("WrongConstant")
public CameraView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // Internal setup

    final View view = View.inflate(context, R.layout.texture_view, this);
    mGLSurfaceView = (GLSurfaceView) view.findViewById(R.id.gl_surface_view);
    mGLSurfaceView.setEGLContextClientVersion(2);
    mGLSurfaceView.setRenderer(this);
    mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    mTextureId = OpenGLUtils.getExternalOESTextureID();
    mSurfaceTexture = new SurfaceTexture(mTextureId);

    mCallbacks = new CallbackBridge();
    if (Build.VERSION.SDK_INT < 21) {
        mImpl = new Camera1(mCallbacks);
    } else if (Build.VERSION.SDK_INT < 23) {
        mImpl = new Camera2(mCallbacks, context);
    } else {/*  ww  w. j  a v  a 2  s  .  c o  m*/
        mImpl = new Camera2Api23(mCallbacks, context);
    }
    mImpl.setPreviewSurface(mSurfaceTexture);
    // Attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CameraView, defStyleAttr,
            R.style.Widget_CameraView);
    mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, false);
    setFacing(a.getInt(R.styleable.CameraView_facing, FACING_BACK));
    String aspectRatio = a.getString(R.styleable.CameraView_aspectRatio);
    if (aspectRatio != null) {
        setAspectRatio(AspectRatio.parse(aspectRatio));
    } else {
        setAspectRatio(Constants.DEFAULT_ASPECT_RATIO);
    }
    setFlash(a.getInt(R.styleable.CameraView_flash, Constants.FLASH_AUTO));
    a.recycle();
    // Display orientation detector
    mDisplayOrientationDetector = new DisplayOrientationDetector(context) {
        @Override
        public void onDisplayOrientationChanged(int displayOrientation) {
            mImpl.setDisplayOrientation(displayOrientation);
        }
    };
}

From source file:ca.hoogit.soundchooser.SoundChooserDialog.java

@NonNull
@Override//  ww w  .  ja v a2  s .co m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    View view;
    ContextThemeWrapper context;
    if (mThemeId != 0) {
        context = new ContextThemeWrapper(getActivity(), mThemeId);
        view = View.inflate(context, R.layout.sound_picker_dialog, null);
    } else {
        context = new ContextThemeWrapper(getActivity(), R.style.AlertDialog_AppCompat_Light);
        view = LayoutInflater.from(getActivity()).inflate(R.layout.sound_picker_dialog, null);
    }

    mPalette = (SoundChooserPalette) view.findViewById(R.id.sound_picker);
    mPalette.init(mCircleColor, mSize, mColumns, this);

    mSoundPlayer = new SoundPlayer(activity, mStreamType);

    if (mSounds != null) {
        showPaletteView();
    }

    mAlertDialog = new AlertDialog.Builder(context).setTitle(mTitle).setView(view)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mListener.onPositive(dialog, mLastSound);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mListener.onNegative(dialog);
                }
            }).create();

    return mAlertDialog;
}

From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_screen_dice, container, false);

    ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    fab_dice = (FloatingActionButton) rootView.findViewById(R.id.fab_dice);
    lv = (ListView) rootView.findViewById(R.id.list);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
    lvItems = (ListView) rootView.findViewById(R.id.lvItems);

    fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1);
    fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2);
    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1);
    FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override// w w w  .  j a v a2s  . c o m
        public void onClick(View view) {
            if (!isFABOpen) {
                showFABMenu();
            } else {
                closeFABMenu();
            }
        }
    });

    fab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();

            android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity());
            View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.note_title_input);
            edit_title.setHint(R.string.title_hint);

            final EditText edit_cont = (EditText) dialogView.findViewById(R.id.note_text_input);
            edit_cont.setHint(R.string.text_hint);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTitle = edit_title.getText().toString().trim();
                    String inputCont = edit_cont.getText().toString().trim();

                    if (db.isExist(inputTitle)) {
                        Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show();
                    } else {
                        db.insert(inputTitle, inputCont, "", "", helper_main.createDate());
                        dialog.dismiss();
                        setRandomList();
                        Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show();
                    }
                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final android.app.AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(getActivity(), edit_title);
        }
    });

    fab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();
            Intent mainIntent = new Intent(getActivity(), Popup_courseList.class);
            mainIntent.setAction("courseList_random");
            startActivity(mainIntent);
        }
    });

    fab_dice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            try {
                Random rand = new Random();
                final int n = rand.nextInt(lvItems.getCount());

                setAdapter(n);
                lvItems.setSelection(n - 1);

            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
            }
        }
    });

    //calling Notes_DbAdapter
    db = new Random_DbAdapter(getActivity());
    db.open();

    setRandomList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:aenadon.wienerlinienalarm.activities.MainActivity.java

private Dialog batteryWarningWithoutDoze() {
    View batteryReminderDialog = View.inflate(MainActivity.this, R.layout.checkbox, null);
    final CheckBox batteryReminderCheckbox = batteryReminderDialog.findViewById(R.id.battery_reminder_checkbox);

    String messageBody = getString(R.string.battery_optimization_warning_dialog_text);

    return new AlertDialog.Builder(MainActivity.this)
            .setTitle(getString(R.string.battery_optimization_warning_dialog_title)).setMessage(messageBody)
            .setView(batteryReminderDialog).setPositiveButton(R.string.ok, (dialog, which) -> {
                if (batteryReminderCheckbox.isChecked()) {
                    dismissBatteryReminder();
                }//from w  w  w .  ja va 2 s .c o m
            }).create();
}

From source file:com.abhi.barcode.fragment.BarCodeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View c = View.inflate(getActivity(), R.layout.superimposedcamera, null);
    viewfinderView = (ViewfinderView) c.findViewById(R.id.viewFinder_View);
    hasSurface = false;/*from   w  w  w  .ja va2  s.  co  m*/
    mHandler = new Handler();
    runCamera = true;
    return c;
}

From source file:com.vuze.android.remote.AndroidUtils.java

/**
 * Creates an AlertDialog.Builder that has the proper theme for Gingerbread
 *//*from w w  w.j av  a 2 s . co  m*/
public static AndroidUtils.AlertDialogBuilder createAlertDialogBuilder(Activity activity, int resource) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    // Not sure if we need this anymore, but once upon a time, pre-honeycomb
    // (2.x) had dialog color issues
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        builder.setInverseBackgroundForced(true);
    }

    View view = View.inflate(activity, resource, null);
    builder.setView(view);

    return new AndroidUtils.AlertDialogBuilder(view, builder);
}

From source file:cn.wander.Utils.views.pageindicator.TabPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    RelativeLayout tablayout = (RelativeLayout) View.inflate(getContext(), R.layout.tab_item_layout, null);

    final TextView tabView = (TextView) tablayout.findViewById(R.id.tab_item_title);
    tabView.setTag(index);//  w w  w  .  ja  va  2 s. c  o  m
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 19);
    tabView.setText(text);
    tabView.setTextColor(getResources().getColor(R.color.kw_common_cl_white));
    if (iconResId != 0) {
        //             tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
        ImageView iconView = (ImageView) tablayout.findViewById(R.id.tab_item_icon);
        iconView.setImageResource(iconResId);
        iconView.setVisibility(View.VISIBLE);
    }

    mTabLayout.addView(tablayout, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:com.android.nsboc.ComposeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mItem != null) {
        switch (mItem.id + "") {
        case "1":
            mRootView = inflater.inflate(R.layout.form_unlicensed, container, false);
            break;
        case "2":
            mRootView = inflater.inflate(R.layout.form_salon, container, false);
            break;
        }//from w ww  .  j av a2s . c o  m
    }

    showCurrentDateInEditText();

    ToggleButton complianceToggle = (ToggleButton) mRootView.findViewById(R.id.compliance_toggle);
    if (complianceToggle != null) {
        final LinearLayout complianceContainer = (LinearLayout) mRootView
                .findViewById(R.id.compliance_container);

        complianceToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!isChecked) {
                    complianceContainer.setVisibility(View.VISIBLE);

                    final LinearLayout complianceLayout = (LinearLayout) View.inflate(getActivity(),
                            R.layout.compliance_layout, null);

                    Spinner violationTypeSpinner = (Spinner) complianceLayout
                            .findViewById(R.id.violation_type_spinner);
                    violationTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            switch (position) {
                            case 0:
                                complianceLayout.findViewById(R.id.type_citation_container)
                                        .setVisibility(View.VISIBLE);
                                break;
                            case 1:
                                complianceLayout.findViewById(R.id.type_citation_container)
                                        .setVisibility(View.GONE);
                                break;
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {
                        }
                    });

                    ToggleButton anotherToggle = (ToggleButton) complianceLayout
                            .findViewById(R.id.compliance_toggle);
                    anotherToggle.setOnCheckedChangeListener(getNextToggleListener(complianceLayout));

                    complianceContainer.addView(complianceLayout);
                } else {
                    complianceContainer.setVisibility(View.GONE);
                }
            }
        });
    }

    ToggleButton emailToggle = (ToggleButton) mRootView.findViewById(R.id.emailTo_toggle);
    if (emailToggle != null) {
        final LinearLayout emailLayout = (LinearLayout) mRootView.findViewById(R.id.emailTo_layout);

        emailToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    emailLayout.setVisibility(View.VISIBLE);
                } else {
                    emailLayout.setVisibility(View.GONE);
                }
            }
        });
    }

    final TextView noticeTextView = (TextView) mRootView.findViewById(R.id.notice_textview);
    if (noticeTextView != null) {
        noticeTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (noticeTextView.getCurrentTextColor() == Color.BLACK) {
                    noticeTextView.setText(R.string.civil_citation_header);
                    noticeTextView.setTextColor(Color.parseColor("#17405e"));
                    noticeTextView.setText(Html.fromHtml("<u>" + noticeTextView.getText() + "</u>"));
                    mRootView.findViewById(R.id.civil_citation).requestFocus();
                } else {
                    noticeTextView.setText(R.string.civil_citation_notice);
                    noticeTextView.setMaxLines(Integer.MAX_VALUE);
                    noticeTextView.setTextColor(Color.BLACK);
                    noticeTextView.setText(
                            noticeTextView.getText().toString().replace("<u>", "").replace("</u>", ""));
                }
            }
        });
    }

    Spinner stateSpinner = (Spinner) mRootView.findViewById(R.id.state);
    if (stateSpinner != null) {
        stateSpinner.setSelection(27);
    }

    return mRootView;
}

From source file:com.ovrhere.android.careerstack.ui.fragments.dialogs.DistanceDialogFragment.java

@SuppressLint("InflateParams")
@Override/*from w  ww.  j  av  a 2s  .  co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context ctx = getCompatContext();
    AlertDialog dialog = new AlertDialog.Builder(ctx)
            .setTitle(getResources().getString(R.string.careerstack_dialog_distance_title))
            .setPositiveButton(android.R.string.ok, this).setNegativeButton(android.R.string.cancel, this)
            .create(); //create basic dialog

    //insert custom views
    View content = View.inflate(ctx, R.layout.viewstub_distance_seekbar, null);
    initViews(content); //preload views

    Resources r = getResources();
    content.setPadding(r.getDimensionPixelSize(R.dimen.dialog_margins),
            r.getDimensionPixelSize(R.dimen.dialog_margins), r.getDimensionPixelSize(R.dimen.dialog_margins),
            r.getDimensionPixelSize(R.dimen.dialog_margins));
    dialog.setView(content);
    onValueUpdate(currentDistanceValue);
    return dialog;
}

From source file:com.bobomee.android.gank.io.widget.CompactTabLayout.java

@Override
public void addTab(@NonNull Tab tab, boolean setSelected) {
    TextView textView = (TextView) View.inflate(getContext(), R.layout.tab_text, null);
    textView.setText(tab.getText());/*from  ww  w  .j av  a 2  s .  co m*/
    /* Selected first one by default */
    if (tabViews.isEmpty()) {
        renderSelectedText(textView);
    }
    tab.setCustomView(textView);
    tabViews.add(textView);
    super.addTab(tab, setSelected);
}