Example usage for android.widget RelativeLayout addView

List of usage examples for android.widget RelativeLayout addView

Introduction

In this page you can find the example usage for android.widget RelativeLayout addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.zt.hackman.model.HackmanModel.java

/**
 * ??/*from  www. j  a  va  2 s.c  o m*/
 */
private void initImage(RelativeLayout btn, String text) {
    View view = LayoutInflater.from(ac).inflate(R.layout.layout_front_one, btn, false);
    ImageView imageView = (ImageView) view.findViewById(R.id.layout_one_img);
    TextView textView = (TextView) view.findViewById(R.id.layout_one_text);
    if (textView == null) {
        textView.setVisibility(View.GONE);
    } else {
        textView.setText(text);
    }
    btn.addView(view);
}

From source file:com.mllrsohn.videodialog.VideoDialogPlugin.java

private void playVideo(JSONObject params, final CallbackContext callbackContext) throws JSONException {

    loopVideo = params.optBoolean("loop", true);
    path = params.optString("url");

    uri = Uri.parse(path);//from w  ww  .  j av a2s . com

    if (path.contains(ASSETS)) {
        try {
            String filepath = path.replace(ASSETS, "");
            String filename = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());
            File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + filename);

            if (!fp.exists()) {
                this.copy(filepath, filename);
            }
            uri = Uri.parse("file://" + this.cordova.getActivity().getFilesDir() + "/" + filename);
        } catch (IOException e) {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION));
        }

    }

    // Create dialog in new thread
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {

            // Set Basic Dialog
            dialog = new Dialog((Context) cordova.getActivity(), android.R.style.Theme_NoTitleBar_Fullscreen);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);

            // Layout View
            RelativeLayout main = new RelativeLayout((Context) cordova.getActivity());
            main.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

            // Video View
            mVideoView = new VideoView((Context) cordova.getActivity());
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            lp.addRule(RelativeLayout.CENTER_IN_PARENT);
            mVideoView.setLayoutParams(lp);

            mVideoView.setVideoPath(uri.toString());
            mVideoView.start();
            main.addView(mVideoView);

            dialog.setContentView(main);
            dialog.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
            dialog.show();

            // Close on touch
            mVideoView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "stopped"));
                    dialog.dismiss();
                    return true;
                }
            });

            // Set Looping
            mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.setLooping(loopVideo);
                }
            });

            // On Completion
            mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mediaplayer) {
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "Done"));
                    dialog.dismiss();
                }
            });

        }
    });
}

From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

private void initAnnotateImageView(Bitmap bitmap, String originalImagePath) {
    annotateImageView = new AnnotateImageView(this);
    // Set the bitmap to draw on
    annotateImageView.drawBitmap(bitmap);
    // Add the file of the original image
    annotateImageView.addCroppedImage(new File(originalImagePath));
    // Set the background color of the canvas (used for the eraser)
    annotateImageView.setBaseColor(Color.WHITE);
    // Set the mode
    annotateImageView.setMode(AnnotateImageView.Mode.DRAW);
    // Set the drawer
    annotateImageView.setDrawer(AnnotateImageView.Drawer.PEN);
    // Set the paint attributes
    annotateImageView.setPaintStyle(Paint.Style.STROKE);
    annotateImageView.setPaintStrokeColor(Color.RED);
    annotateImageView.setLineCap(Paint.Cap.ROUND);
    annotateImageView.setLineJoin(Paint.Join.ROUND);
    float strokeWidth = getResources().getDisplayMetrics().density < 1.6F ? 6F : 12F;
    annotateImageView.setPaintStrokeWidth(strokeWidth);
    annotateImageView.setPaintFillColor(Color.RED);
    annotateImageView.setOpacity(255);/*from  w  w w.j av a 2  s.c o  m*/
    annotateImageView.setBlur(0F);
    // Set the text attributes
    annotateImageView.setText("Default text");
    annotateImageView.setFontFamily(Typeface.DEFAULT);
    annotateImageView.setFontSize(32F);
    annotateImageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    RelativeLayout relativeLayout = (RelativeLayout) findViewById(
            R.id.supersede_feedbacklibrary_annotate_image_layout);
    if (relativeLayout != null) {
        relativeLayout.addView(annotateImageView);
    }
}

From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java

@Nullable
private TextAnnotationImageView addTextAnnotation(int imageResourceId) {
    if (textAnnotationCounter <= textAnnotationCounterMaximum) {
        TextAnnotationImageView stickerViewTextAnnotationImageView = new TextAnnotationImageView(this);
        stickerViewTextAnnotationImageView.setOnTextAnnotationChangedListener(this);
        stickerViewTextAnnotationImageView.setImageResource(imageResourceId);
        stickerViewTextAnnotationImageView.setAnnotationInputTextHint(
                getResources().getString(R.string.supersede_feedbacklibrary_text_annotation_dialog_hint));
        stickerViewTextAnnotationImageView.setAnnotationInputTextLabel(
                getResources().getString(R.string.supersede_feedbacklibrary_text_annotation_dialog_label));
        TextView textView = stickerViewTextAnnotationImageView.getAnnotationNumberView();
        if (textView != null) {
            String newAnnotationNumber = Integer.toString(textAnnotationCounter);
            textView.setText(newAnnotationNumber);
            textAnnotationCounter++;//from   w ww.j  a  v a2 s  .  c om
        }
        RelativeLayout relativeLayout = (RelativeLayout) findViewById(
                R.id.supersede_feedbacklibrary_annotate_image_layout);
        if (relativeLayout != null) {
            relativeLayout.addView(stickerViewTextAnnotationImageView);
        }
        if (textAnnotationCounter > textAnnotationCounterMaximum) {
            ImageButton textAnnotationButton = (ImageButton) findViewById(
                    R.id.supersede_feedbacklibrary_text_comment_btn);
            if (textAnnotationButton != null) {
                textAnnotationButton.setEnabled(false);
                textAnnotationButton.setAlpha(0.4F);
            }
        }
        return stickerViewTextAnnotationImageView;
    }
    return null;
}

From source file:com.game.simple.Game3.java

private void createAd() {

    adView = new AdView(this);
    adView.setAdUnitId(AD_UNIT_ID);/*from  w w  w.j a  v  a2 s.  co  m*/
    adView.setAdSize(AdSize.BANNER);
    try {
        AdView.LayoutParams layoutParams = new AdView.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);

        RelativeLayout relativeLayout = new RelativeLayout(this);

        RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);

        relativeLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);

        adView.setLayoutParams(layoutParams);

        relativeLayout.addView(adView);

        addContentView(relativeLayout, rlp);

        AdRequest req = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice("6BAC439445EBA320C6E42298650F159E").build();

        adView.loadAd(req);

        adView.setVisibility(View.INVISIBLE);

    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.almalence.opencam.ui.AlmalenceStore.java

public void showStore() {
    LayoutInflater inflater = LayoutInflater.from(MainScreen.getInstance());
    List<RelativeLayout> pages = new ArrayList<RelativeLayout>();

    // <!-- -+-
    final boolean unlocked = false;
    //-+- -->//from   w  ww.  j a  v a2s. c o  m
    /* <!-- +++
    final boolean unlocked = true; 
     +++ --> */

    // page 1
    RelativeLayout page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    initStoreList();

    RelativeLayout store = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_store, null);
    final ImageView imgStoreNext = (ImageView) store.findViewById(R.id.storeWhatsNew);
    GridView gridview = (GridView) store.findViewById(R.id.storeGrid);
    gridview.setAdapter(storeAdapter);

    if (!unlocked) {
        page.addView(store);
        pages.add(page);
    }

    // page 2
    page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    RelativeLayout features = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_features, null);
    final ImageView imgFeaturesPrev = (ImageView) features.findViewById(R.id.storeWhatsNew);
    imgFeaturesPrev.setVisibility(View.INVISIBLE);
    WebView wv = (WebView) features.findViewById(R.id.text_features);
    wv.loadUrl("file:///android_asset/www/features.html");

    page.addView(features);
    pages.add(page);

    SamplePagerAdapter pagerAdapter = new SamplePagerAdapter(pages);
    final ViewPager viewPager = new ViewPager(MainScreen.getInstance());
    viewPager.setAdapter(pagerAdapter);
    if (!unlocked)
        viewPager.setCurrentItem(0);
    else
        viewPager.setCurrentItem(1);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            switch (position) {
            case 0:
                // 0
                imgStoreNext.setVisibility(View.VISIBLE);
                // 1
                imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            case 1:
                // 0
                imgStoreNext.setVisibility(View.INVISIBLE);
                // 1
                if (!unlocked)
                    imgFeaturesPrev.setVisibility(View.VISIBLE);
                else
                    imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            default:
                break;
            }
        }
    });

    imgStoreNext.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(1);
        }
    });

    imgFeaturesPrev.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(0);
        }
    });

    guiView.findViewById(R.id.buttonGallery).setEnabled(false);
    guiView.findViewById(R.id.buttonShutter).setEnabled(false);
    guiView.findViewById(R.id.buttonSelectMode).setEnabled(false);

    PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
            ApplicationInterface.MSG_CONTROL_LOCKED);

    MainScreen.getGUIManager().lockControls = true;

    // <!-- -+-
    if (MainScreen.getInstance().showPromoRedeemed) {
        Toast.makeText(MainScreen.getInstance(),
                "The promo code has been successfully redeemed. All PRO-Features are unlocked",
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemed = false;
    }
    if (MainScreen.getInstance().showPromoRedeemedJulius) {
        Toast.makeText(MainScreen.getInstance(),
                MainScreen.getInstance().getResources().getString(R.string.promoRedeemedJulius),
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemedJulius = false;
    }
    //-+- -->

    final RelativeLayout pagerLayout = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayout));
    pagerLayout.addView(viewPager);

    final RelativeLayout pagerLayoutMain = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayoutMain));
    pagerLayoutMain.setVisibility(View.VISIBLE);
    pagerLayoutMain.bringToFront();

    // We need this timer, to show store on top, after we return from google
    // play.
    // In MainScreen there is timer, which brings main buttons on top,
    // after MainScreen activity resumed.
    // So this timer "blocks" timer from MainScreen if we want to show
    // store.
    new CountDownTimer(600, 10) {
        public void onTick(long millisUntilFinished) {
            pagerLayoutMain.bringToFront();
        }

        public void onFinish() {
            pagerLayoutMain.bringToFront();
        }
    }.start();
}

From source file:com.primalpond.hunt.TheHunt.java

private void returnFromTutorial() {
    mInTutorial = false;/* w ww .  j a va 2  s.c o m*/

    mGLView.onPause();
    final RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.root_layout);
    Handler handler = new Handler();
    class RefreshRunnable implements Runnable {

        public RefreshRunnable() {

        }

        public void run() {
            rootLayout.removeView(findViewById(R.id.glSurfaceView));

            D3GLSurfaceView surfaceview = new D3GLSurfaceView(getApplication(), null,
                    new TheHuntRenderer(TheHunt.this));
            surfaceview.setId(R.id.glSurfaceView);
            rootLayout.addView(surfaceview);

            mGLView = (D3GLSurfaceView) findViewById(R.id.glSurfaceView);

            View actionBarPart = findViewById(R.id.actionBarPart);
            actionBarPart.bringToFront();

            mGLView.mRenderer.setActivity(TheHunt.this);
            MyApplication.setFirstRun(false);
        }
    }
    ;

    RefreshRunnable r = new RefreshRunnable();
    handler.postDelayed(r, 500);
}

From source file:com.primalpond.hunt.TheHunt.java

private void beginTutorial() {
    mInTutorial = true;//from  w  w  w.j  a va2 s.  com

    if (mGLView != null) {
        mGLView.onPause();
    }
    final RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.root_layout);
    Handler handler = new Handler();
    class RefreshRunnable implements Runnable {

        public RefreshRunnable() {

        }

        public void run() {
            rootLayout.removeView(findViewById(R.id.glSurfaceView));

            D3GLSurfaceView surfaceview = new D3GLSurfaceView(getApplication(), null,
                    new TutorialRenderer(TheHunt.this));
            surfaceview.setId(R.id.glSurfaceView);
            rootLayout.addView(surfaceview);

            View actionBarPart = findViewById(R.id.actionBarPart);
            actionBarPart.bringToFront();

            mGLView = (D3GLSurfaceView) findViewById(R.id.glSurfaceView);

            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            mTutorialFragment = new TutorialFragment();
            ft.add(R.id.root_layout, mTutorialFragment);
            ft.commit();
            mGLView.mRenderer.setActivity(TheHunt.this);
            onToHideNavigation();
        }
    }
    ;

    RefreshRunnable r = new RefreshRunnable();
    handler.postDelayed(r, 500);
}

From source file:HeaderGridView.java

/** added by Ahmed Basyouni
* this method take supported fragment and fragment activity to add that
* fragment as a banner to listView it create a layout at runtime then when
* view is added to list we replace it with fragment otherwise it will crash
* since view is not on screen to be replaced
* 
* @param fragment/*from   www  . j a  v  a2  s  .  c  o m*/
* @param activity
*/
public void addBannerFragment(final Fragment fragment, final FragmentActivity activity) {

    RelativeLayout layout = new RelativeLayout(activity);

    AbsListView.LayoutParams param = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);

    layout.setLayoutParams(param);

    // please don't ever remove that view otherwise application will crash and I mean it :D
    View view = new View(activity);

    view.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 300));

    view.setVisibility(View.INVISIBLE);

    layout.addView(view);

    layout.setId(CONTAINER_ID);

    addHeaderView(layout);

    this.addOnLayoutChangeListener(new OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {

            HeaderGridView.this.removeOnLayoutChangeListener(this);

            FragmentManager manager = activity.getSupportFragmentManager();
            FragmentTransaction transaction = manager.beginTransaction();

            transaction.replace(CONTAINER_ID, fragment).commit();
        }
    });

}

From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java

public void createButtonWithText(Activity activity, ViewGroup l, String text, String button,
        View.OnClickListener onclick) {
    RelativeLayout r = new RelativeLayout(activity);
    r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    TextView tv = new TextView(activity);
    RelativeLayout.LayoutParams tvparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tvparams.addRule(RelativeLayout.ABOVE, R.id.reload_button);
    tvparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    tv.setLayoutParams(tvparams);/*from  w  w w.  j  av  a 2s  .co m*/
    tv.setText(text);
    tv.setTextSize(23);
    tv.setPadding(0, 0, 0, toPixels(15));
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    r.addView(tv);

    Button b = new Button(activity);
    RelativeLayout.LayoutParams bparams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    bparams.addRule(RelativeLayout.CENTER_VERTICAL);
    bparams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    b.setLayoutParams(bparams);
    b.setId(R.id.reload_button);
    b.setText(button);
    b.setTextSize(23);
    b.setAllCaps(false);
    b.setTypeface(null, Typeface.NORMAL);
    b.setOnClickListener(onclick);
    r.addView(b);

    l.addView(r);
}