Example usage for android.view ViewGroup addView

List of usage examples for android.view ViewGroup addView

Introduction

In this page you can find the example usage for android.view ViewGroup addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.taobao.luaview.view.adapter.LVPagerAdapter.java

public Object newItem(ViewGroup container, int position) {
    //View?/*  w w w. j  a  v a2  s  . c o m*/
    final UDView page = new UDViewGroup(createPageLayout(), mGlobals, null);//TODO mLuaUserData.getmetatable()?
    //??LuaTable
    final UDLuaTable pageData = new UDLuaTable(page);
    final View pageView = pageData.getView();
    //view
    if (container != null && pageView != null) {
        container.addView(pageView);
    }
    //?View
    initView(pageData, position);
    //?
    renderView(pageData, position);
    //add to list
    mViews.put(position, new WeakReference<View>(pageView));
    return pageView;
}

From source file:com.actinarium.kinetic.ui.ResultsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_results, container, false);

    DataSet3 accelData = mHost.getAccelData();
    DataSet3 gyroData = mHost.getGyroData();

    // Discard button (X)
    ImageButton discard = (ImageButton) view.findViewById(R.id.discard);
    discard.setImageAlpha(180);//w w w  .j a  va2  s .c  o m
    discard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onDiscard();
        }
    });

    // Preview animation
    View animatedView = view.findViewById(R.id.preview_sprite);
    float linearMagnitude = getResources().getDimension(R.dimen.linear_magnitude);
    mFullDuration = (accelData.times[accelData.length - 1] - accelData.times[0]) / 1000000L;
    mPreviewHolder = new PreviewHolder(animatedView);
    mPreviewHolder.setDuration(mFullDuration);

    // Trim range
    mTrimStart = (SeekBar) view.findViewById(R.id.trim_start);
    mTrimStart.setOnSeekBarChangeListener(this);
    mTrimEnd = (SeekBar) view.findViewById(R.id.trim_end);
    mTrimEnd.setOnSeekBarChangeListener(this);
    mMax = mTrimStart.getMax();

    String[] resultTitles = getResources().getStringArray(R.array.result_titles);
    mResultEnabledStates = mHost.getResultHoldersState();
    mMap = mHost.getHolderToAnimatorMap();
    ViewGroup resultsContainer = (ViewGroup) view.findViewById(R.id.item_container);
    for (int i = 0; i < 6; i++) {
        View item = inflater.inflate(R.layout.item_measurement, resultsContainer, false);
        resultsContainer.addView(item);
        mHolders[i] = new ResultHolder(i, this, item, resultTitles[i], i >= 3, mResultEnabledStates[i],
                mMap[i]);
    }

    Button export = (Button) inflater.inflate(R.layout.item_export_button, resultsContainer, false);
    export.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onExport();
        }
    });
    resultsContainer.addView(export);
    mEpithets = getResources().getStringArray(R.array.epithets);

    mHolders[0].setData(accelData.times, accelData.valuesX, accelData.length, linearMagnitude);
    mHolders[1].setData(accelData.times, accelData.valuesY, accelData.length, linearMagnitude);
    mHolders[2].setData(accelData.times, accelData.valuesZ, accelData.length, linearMagnitude);
    mHolders[3].setData(gyroData.times, gyroData.valuesX, gyroData.length, 0f);
    mHolders[4].setData(gyroData.times, gyroData.valuesY, gyroData.length, 0f);
    mHolders[5].setData(gyroData.times, gyroData.valuesZ, gyroData.length, 0f);

    // Wire up animators to results
    for (int i = 0; i < mMap.length; i++) {
        final int animator = mMap[i];
        if (animator != PreviewHolder.NO_ANIMATOR) {
            // This holder is mapped to an animator. Inject result data into animation holder
            final ResultHolder holder = mHolders[i];
            mPreviewHolder.setInterpolator(animator, holder.getInterpolator(), holder.getMagnitude());
            mPreviewHolder.setEnabled(animator, holder.isEnabled());
        }
    }
    mPreviewHolder.startAnimation();

    return view;
}

From source file:com.thevelopment.poc.Fragments.FirstFragment.java

public FloatingActionButton createFAB(ViewGroup parentView) {
    FloatingActionButton fab = new FloatingActionButton(getActivity());
    fab.setImageResource(R.drawable.ic_go);
    LinearLayout.LayoutParams fabParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    fabParams.gravity = Gravity.RIGHT;/*from   ww  w  . j  av a2  s  . c  om*/
    fab.setLayoutParams(fabParams);

    parentView.addView(fab);
    return fab;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VoiceObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.play);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    frame.addView(imageView);
}

From source file:com.android.gallery3d2.ingest.adapter.MtpPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    MtpFullscreenView v;//from  w w w. j  av  a  2s  . c om
    if (mReusableView != null) {
        v = mReusableView;
        mReusableView = null;
    } else {
        v = (MtpFullscreenView) mInflater.inflate(R.layout.ingest_fullsize, container, false);
    }
    MtpObjectInfo i = mModel.getWithoutLabels(position, mSortOrder);
    v.getImageView().setMtpDeviceAndObjectInfo(mModel.getDevice(), i, mGeneration);
    v.setPositionAndBroker(position, mBroker);
    container.addView(v);
    return v;
}

From source file:com.dreamfactory.kurtishu.pretty.view.adapter.ImageViewerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View contentView = views.get(position);
    if (null == contentView) {
        contentView = mInflater.inflate(R.layout.image_detail_item, container, false);
        views.put(position, contentView);
    }/*from   w w w. jav  a 2s.co m*/

    PhotoImageView simpleDraweeView = (PhotoImageView) contentView.findViewById(R.id.detail_image_view);
    Picture picture = mItems.get(position);
    Uri uri = Uri.parse(picture.getImg());
    simpleDraweeView.setImageURI(uri);

    container.addView(contentView);
    return contentView;
}

From source file:com.serenegiant.aceparrot.ConfigPagerAdapter.java

@Override
public synchronized Object instantiateItem(final ViewGroup container, final int position) {
    if (DEBUG)/*w w w.ja  va 2s .c om*/
        Log.v(TAG, "instantiateItem:position=" + position);
    View view = null;
    final int n = mConfigs != null ? mConfigs.length : 0;
    if ((position >= 0) && (position < n)) {
        final PagerAdapterConfig config = mConfigs[position];
        view = mInflater.inflate(config.layout_id, container, false);
        config.handler.initialize(mParent, view);
    }
    if (view != null) {
        container.addView(view);
    }
    return view;
}

From source file:com.android.gallery3d.ingest.adapter.MtpPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    MtpFullscreenView v;// w w w  . j  av a 2  s .c  om
    if (mReusableView != null) {
        v = mReusableView;
        mReusableView = null;
    } else {
        v = (MtpFullscreenView) mInflater.inflate(R.layout.ingest_fullsize, container, false);
    }
    IngestObjectInfo i = mModel.getWithoutLabels(position, mSortOrder);
    v.getImageView().setMtpDeviceAndObjectInfo(mModel.getDevice(), i, mGeneration);
    v.setPositionAndBroker(position, mBroker);
    container.addView(v);
    return v;
}

From source file:com.mirasense.scanditsdk.plugin.SubViewPickerController.java

@Override
public void show(final JSONObject settings, final Bundle options, final Bundle overlayOptions,
        boolean legacyMode) {
    mPendingClose.set(false);/*from   ww  w.ja va 2s.  c om*/
    mLegacyMode = legacyMode;
    mContinuousMode = PhonegapParamParser.shouldRunInContinuousMode(options);
    mOrientationHandler = new SubViewPickerOrientationHandler(Looper.getMainLooper(), mPlugin, null);
    mCloseWhenDidScanCallbackFinishes = false;
    mOrientationHandler.start(true);
    final Activity pluginActivity = mPlugin.cordova.getActivity();
    DisplayMetrics display = pluginActivity.getApplicationContext().getResources().getDisplayMetrics();
    int width = (int) (display.widthPixels * 160.f / display.densityDpi);
    int height = (int) (display.heightPixels * 160.f / display.densityDpi);
    mScreenDimensions = new Point(Math.min(width, height), Math.max(width, height));

    // initialization must be performed on main thread.
    this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ScanSettings scanSettings;
            if (settings == null) {
                scanSettings = LegacySettingsParamParser.getSettings(options);
            } else {
                try {
                    scanSettings = ScanSettings.createWithJson(settings);
                } catch (JSONParseException e) {
                    Log.e("ScanditSDK", "Exception while creating settings");
                    e.printStackTrace();
                    sendRuntimeError("Exception while creating settings: " + e.getMessage()
                            + ". Falling back to default scan settings.");
                    scanSettings = ScanSettings.create();
                }
            }
            BarcodePickerWithSearchBar picker = new BarcodePickerWithSearchBar(pluginActivity, scanSettings);
            picker.setOnScanListener(SubViewPickerController.this);
            mPickerStateMachine = new PickerStateMachine(picker, SubViewPickerController.this);
            mOrientationHandler.setScreenDimensions(mScreenDimensions);
            mOrientationHandler.setPicker(mPickerStateMachine.getPicker());
            // Set all the UI options.
            PhonegapParamParser.updatePicker(picker, options, SubViewPickerController.this);
            internalUpdateUI(overlayOptions, options);
            // Create the layout to add the picker to and add it on top of the web view.
            mLayout = new RelativeLayout(pluginActivity);
            ViewGroup viewGroup = getPickerParent();
            if (viewGroup == null)
                return; // couldn't determine view group, nothing to be done.
            viewGroup.addView(mLayout);
            RelativeLayout.LayoutParams rLayoutParams = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
            mLayout.addView(mPickerStateMachine.getPicker(), rLayoutParams);
            PhonegapParamParser.updateLayout(pluginActivity, mPickerStateMachine.getPicker(), options,
                    mScreenDimensions);

            if (mPendingClose.compareAndSet(true, false)) {
                // picker was closed(canceled) in the meantime. close it now.
                SubViewPickerController.this.close();
            }
            if (!mLegacyMode)
                return;

            // In legacy mode, start scanning when show is called.
            int state = PhonegapParamParser.shouldStartInPausedState(options) ? PickerStateMachine.PAUSED
                    : PickerStateMachine.ACTIVE;
            mPickerStateMachine.setState(state);

        }
    });
}

From source file:com.microblink.ocr.ScanActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_scan);

    // obtain references to needed member variables
    mRecognizerView = (RecognizerView) findViewById(R.id.rec_view);
    mFlashButton = (ImageButton) findViewById(R.id.btnFlash);
    mResultView = findViewById(R.id.layResult);
    mMessage = (TextView) findViewById(R.id.txtMessage);
    mResult = (EditText) findViewById(R.id.txtResult);
    mTitleIndicator = (SlidingTabLayout) findViewById(R.id.indicator);

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setAdapter(new SamplePagerAdapter());

    mTitleIndicator = (SlidingTabLayout) findViewById(R.id.indicator);
    mTitleIndicator.setViewPager(viewPager);

    // set ViewPager.OnPageChangeListener to enable the layout
    // to update it's scroll position correctly
    mTitleIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override// w  w w .  ja  v a  2 s  . c  o m
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            // update currently selected configuration
            mSelectedConfiguration = position;
            // hide previous result
            mResultView.setVisibility(View.INVISIBLE);
            // update message and title based on selected configuration
            // and update recognizer settings (flag is set to true)
            updateUI(true);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    // camera events listener is required as it will receive camera-related events
    // such as startup errors, autofocus callbacks etc.
    mRecognizerView.setCameraEventsListener(this);
    // scan result listener is requires as it will receive recognition results
    mRecognizerView.setScanResultListener(this);

    // we want camera to use whole available view space by cropping the camera preview
    // instead of letterboxing it
    mRecognizerView.setAspectMode(CameraAspectMode.ASPECT_FILL);
    // In order for scanning to work, you must enter a valid licence key. Without licence key,
    // scanning will not work. Licence key is bound the the package name of your app, so when
    // obtaining your licence key from Microblink make sure you give us the correct package name
    // of your app. You can obtain your licence key at http://microblink.com/login or contact us
    // at http://help.microblink.com.
    // Licence key also defines which recognizers are enabled and which are not. Since the licence
    // key validation is performed on image processing thread in native code, all enabled recognizers
    // that are disallowed by licence key will be turned off without any error and information
    // about turning them off will be logged to ADB logcat.
    try {
        mRecognizerView.setLicenseKey(LICENSE_KEY);
    } catch (InvalidLicenceKeyException e) {
        e.printStackTrace();
        Toast.makeText(this, "Invalid license key!", Toast.LENGTH_SHORT).show();
        finish();
    }
    mRecognizerView.setOptimizeCameraForNearScan(true);

    // initialize BlinkOCR recognizer with currently selected parser
    // create BlinkOCR recognizer settings object and add parser to it
    BlinkOCRRecognizerSettings ocrSett = new BlinkOCRRecognizerSettings();
    ocrSett.addParser(mConfiguration[mSelectedConfiguration].getParserName(),
            mConfiguration[mSelectedConfiguration].getParserSettings());

    // prepare the recognition settings
    RecognitionSettings recognitionSettings = new RecognitionSettings();
    // add BlinkOCR recognizer settings object to recognizer settings array
    // BlinkOCR recognizer will be used in the recognition process
    recognitionSettings.setRecognizerSettingsArray(new RecognizerSettings[] { ocrSett });

    mRecognizerView.setRecognitionSettings(recognitionSettings);

    // define the scanning region of the image that will be scanned.
    // You must ensure that scanning region define here is the same as in the layout
    // The coordinates for scanning region are relative to recognizer view:
    // the following means: rectangle starts at 10% of recognizer view's width and
    // 34% of its height. Rectangle width is 80% of recognizer view's width and
    // 13% of its height.
    // If you do not set this, OCR will be performed on full camera frame and this
    // will result in very poor performance.
    mRecognizerView.setScanningRegion(new Rectangle(0.1f, 0.34f, 0.8f, 0.13f), false);

    // instantiate the camera permission manager
    mCameraPermissionManager = new CameraPermissionManager(this);
    // get the built in layout that should be displayed when camera permission is not given
    View v = mCameraPermissionManager.getAskPermissionOverlay();
    if (v != null) {
        // add it to the current layout that contains the recognizer view
        ViewGroup vg = (ViewGroup) findViewById(R.id.custom_segment_scan_root);
        vg.addView(v);
    }

    // all activity's lifecycle methods must be passed to recognizer view
    mRecognizerView.create();
    // update message and title based on selected configuration
    // update of recognizer settings is not needed (flag is set to false)
    updateUI(false);
}