Example usage for android.widget RelativeLayout setPadding

List of usage examples for android.widget RelativeLayout setPadding

Introduction

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

Prototype

public void setPadding(int left, int top, int right, int bottom) 

Source Link

Document

Sets the padding.

Usage

From source file:edu.rowan.app.fragments.HomescreenFragment.java

/**
 * Construct the view for this fragment.
 * The core layout of this fragment is a CarouselView and grid of available buttons
 *///from  w  w w. j  a va 2s  .  c  o  m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // hide actionbar loading indicator TODO: move this elsewhere
    activity.showLoading(false);

    View view = inflater.inflate(R.layout.activity_main, container, false);
    RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.mainLayout);
    layout.setPadding(0, 20, 0, 0);

    CarouselView rowanFeatures = new CarouselView(inflater.getContext());
    // set view Id so that relativeLayout can position. Without an Id relativeLayout doesn't work
    rowanFeatures.setId(2342343);
    layout.addView(rowanFeatures);
    setTouchListener(rowanFeatures);

    GridView grid = new GridView(inflater.getContext());
    grid.setOnItemClickListener(this);
    grid.setNumColumns(3);
    grid.setVerticalSpacing(20);
    grid.setAdapter(new RowanAdapter());
    RelativeLayout.LayoutParams gridParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    gridParams.addRule(RelativeLayout.BELOW, rowanFeatures.getId());
    gridParams.topMargin = 20;
    layout.addView(grid, gridParams);

    return view;
}

From source file:net.pocketmagic.android.carousel.MainActivity.java

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

    //no keyboard unless requested by user
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // compute screen size and scaling
    Singleton.getInstance().InitGUIFrame(this);

    int padding = m_Inst.Scale(10);
    // create the interface : full screen container
    RelativeLayout panel = new RelativeLayout(this);
    panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    panel.setPadding(padding, padding, padding, padding);
    panel.setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { Color.WHITE, Color.GRAY }));
    setContentView(panel);/*www  .jav  a 2s.co m*/

    // copy images from assets to sdcard
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma1.png", "plasma1.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma2.png", "plasma2.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma3.png", "plasma3.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma4.png", "plasma4.png", false);

    //Create carousel view documents
    ArrayList<CarouselDataItem> Docus = new ArrayList<CarouselDataItem>();
    for (int i = 0; i < 1000; i++) {
        CarouselDataItem docu;
        if (i % 4 == 0)
            docu = new CarouselDataItem("/mnt/sdcard/plasma1.png", 0, "First Image " + i);
        else if (i % 4 == 1)
            docu = new CarouselDataItem("/mnt/sdcard/plasma2.png", 0, "Second Image " + i);
        else if (i % 4 == 2)
            docu = new CarouselDataItem("/mnt/sdcard/plasma3.png", 0, "Third Image " + i);
        else
            docu = new CarouselDataItem("/mnt/sdcard/plasma4.png", 0, "4th Image " + i);
        Docus.add(docu);
    }

    // add the serach filter
    EditText etSearch = new EditText(this);
    etSearch.setHint("Search your documents");
    etSearch.setSingleLine();
    etSearch.setTextColor(Color.BLACK);
    etSearch.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_menu_search, 0, 0, 0);
    AppUtils.AddView(panel, etSearch, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] {
            new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_TOP } }, -1,
            -1);
    etSearch.addTextChangedListener((TextWatcher) this);

    // add logo
    TextView tv = new TextView(this);
    tv.setTextColor(Color.BLACK);
    tv.setText("www.pocketmagic.net");
    AppUtils.AddView(panel, tv, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] {
            new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_BOTTOM } },
            -1, -1);

    // create the carousel
    CarouselView coverFlow = new CarouselView(this);

    // create adapter and specify device independent items size (scaling)
    // for more details see: http://www.pocketmagic.net/2013/04/how-to-scale-an-android-ui-on-multiple-screens/
    m_carouselAdapter = new CarouselViewAdapter(this, Docus, m_Inst.Scale(400), m_Inst.Scale(300));
    coverFlow.setAdapter(m_carouselAdapter);
    coverFlow.setSpacing(-1 * m_Inst.Scale(150));
    coverFlow.setSelection(Integer.MAX_VALUE / 2, true);
    coverFlow.setAnimationDuration(1000);
    coverFlow.setOnItemSelectedListener((OnItemSelectedListener) this);

    AppUtils.AddView(panel, coverFlow, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,
            new int[][] { new int[] { RelativeLayout.CENTER_IN_PARENT } }, -1, -1);
}

From source file:me.ziccard.secureit.fragment.EmptyFragment.java

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

    if ((savedInstanceState != null) && savedInstanceState.containsKey(CONTENT)) {
        mContent = savedInstanceState.getString(CONTENT);
    }/* w ww.  j a va  2s  .c  o m*/

    TextView text = new TextView(getActivity());
    text.setGravity(Gravity.CENTER);
    text.setText(mContent);
    text.setTextSize(20 * getResources().getDisplayMetrics().density);

    RelativeLayout layout = new RelativeLayout(getActivity());
    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    layout.setGravity(Gravity.CENTER);

    RelativeLayout alert = new RelativeLayout(getActivity());
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.leftMargin = 20;
    params.rightMargin = 20;
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    alert.setLayoutParams(params);
    alert.setBackgroundResource(R.drawable.red_back);
    alert.setPadding(30, 0, 30, 0);
    alert.addView(text);
    layout.addView(alert);

    return layout;
}

From source file:com.support.android.designlibdemo.MatchedPetsDetailActivity.java

/**********************************************************************************************/

private AlertDialog createReportDialog(String titulo, String message) {
    // Instanciamos un nuevo AlertDialog Builder y le asociamos titulo y mensaje
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(titulo);
    alertDialogBuilder.setMessage(message);
    RelativeLayout linearLayout = new RelativeLayout(this);
    final EditText link = new EditText(this);
    link.setHint("Causa de la denuncia");
    link.setWidth(750);/*from   w w  w . j  a  va 2 s.  c  o m*/
    linearLayout.addView(link);
    linearLayout.setPadding(70, 0, 0, 0);
    alertDialogBuilder.setView(linearLayout);
    link.invalidate();
    linearLayout.invalidate();
    final String petId = getIntent().getStringExtra("id");
    final String reporterId = this.loginUser.getId();

    // Creamos un nuevo OnClickListener para el boton OK que realice la conexion
    DialogInterface.OnClickListener listenerOk = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            reportComplain(petId, reporterId, link.getText().toString());
        }
    };

    // Creamos un nuevo OnClickListener para el boton Cancelar
    DialogInterface.OnClickListener listenerCancelar = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    };

    // Asignamos los botones positivo y negativo a sus respectivos listeners
    //OJO: estan al reves para que sea display si - no en vez de no - si
    alertDialogBuilder.setPositiveButton(R.string.dialogCancel, listenerCancelar);
    alertDialogBuilder.setNegativeButton(R.string.dialogSend, listenerOk);

    return alertDialogBuilder.create();
}

From source file:com.polyvi.xface.extension.inappbrowser.XInAppBrowser.java

/**
 * ???/*from w ww .ja v  a 2 s .c  o  m*/
 * @param horizontalGravity ??
 * @param verticalGravity ??
 * @return
 */
protected RelativeLayout createToolbarLayout(int horizontalGravity, int verticalGravity) {
    RelativeLayout toolbarLayOut = new RelativeLayout(mContext);
    toolbarLayOut.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, dpToPixels(44)));
    toolbarLayOut.setPadding(dpToPixels(2), dpToPixels(2), dpToPixels(2), dpToPixels(2));
    toolbarLayOut.setHorizontalGravity(horizontalGravity);
    toolbarLayOut.setVerticalGravity(verticalGravity);
    return toolbarLayOut;
}

From source file:com.ichi2.anki.widgets.DeckAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    // Update views for this node
    Sched.DeckDueTreeNode node = mDeckList.get(position);
    // Set the expander icon and padding according to whether or not there are any subdecks
    RelativeLayout deckLayout = holder.deckLayout;
    int rightPadding = (int) deckLayout.getResources().getDimension(R.dimen.deck_picker_right_padding);
    if (mHasSubdecks) {
        int smallPadding = (int) deckLayout.getResources().getDimension(R.dimen.deck_picker_left_padding_small);
        deckLayout.setPadding(smallPadding, 0, rightPadding, 0);
        holder.deckExpander.setVisibility(View.VISIBLE);
        // Create the correct expander for this deck
        setDeckExpander(holder.deckExpander, holder.indentView, node);
    } else {/*www  .  jav  a 2s.c  o m*/
        holder.deckExpander.setVisibility(View.GONE);
        int normalPadding = (int) deckLayout.getResources().getDimension(R.dimen.deck_picker_left_padding);
        deckLayout.setPadding(normalPadding, 0, rightPadding, 0);
    }

    if (node.children.size() > 0) {
        holder.deckExpander.setTag(node.did);
        holder.deckExpander.setOnClickListener(mDeckExpanderClickListener);
    } else {
        holder.deckExpander.setOnClickListener(null);
    }
    holder.deckLayout.setBackgroundResource(mRowCurrentDrawable);
    // Set background colour. The current deck has its own color
    if (node.did == mCol.getDecks().current().optLong("id")) {
        holder.deckLayout.setBackgroundResource(mRowCurrentDrawable);
    } else {
        CompatHelper.getCompat().setSelectableBackground(holder.deckLayout);
    }
    // Set deck name and colour. Filtered decks have their own colour
    holder.deckName.setText(node.names[0]);
    if (mCol.getDecks().isDyn(node.did)) {
        holder.deckName.setTextColor(mDeckNameDynColor);
    } else {
        holder.deckName.setTextColor(mDeckNameDefaultColor);
    }

    // Set the card counts and their colors
    holder.deckNew.setText(String.valueOf(node.newCount));
    holder.deckNew.setTextColor((node.newCount == 0) ? mZeroCountColor : mNewCountColor);
    holder.deckLearn.setText(String.valueOf(node.lrnCount));
    holder.deckLearn.setTextColor((node.lrnCount == 0) ? mZeroCountColor : mLearnCountColor);
    holder.deckRev.setText(String.valueOf(node.revCount));
    holder.deckRev.setTextColor((node.revCount == 0) ? mZeroCountColor : mReviewCountColor);

    // Store deck ID in layout's tag for easy retrieval in our click listeners
    holder.deckLayout.setTag(node.did);
    holder.countsLayout.setTag(node.did);

    // Set click listeners
    holder.deckLayout.setOnClickListener(mDeckClickListener);
    holder.deckLayout.setOnLongClickListener(mDeckLongClickListener);
    holder.countsLayout.setOnClickListener(mCountsClickListener);
}

From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java

private View handleBuses(final int position, @NonNull final ViewGroup parent) {
    final LayoutInflater vi = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View convertView = vi.inflate(R.layout.list_nearby, parent, false);

    // Bus/* ww w  .  j a v a2 s. c  o  m*/
    final int index = position - stations.size();
    final BusStop busStop = busStops.get(index);

    final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(
            ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bus_white_24dp));

    final TextView routeView = (TextView) convertView.findViewById(R.id.station_name);
    routeView.setText(busStop.getName());

    final LinearLayout resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results);

    final Map<String, List<BusArrival>> arrivalsForStop = busArrivals.get(busStop.getId(), new HashMap<>());

    Stream.of(arrivalsForStop.entrySet()).forEach(entry -> {
        final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        final RelativeLayout insideLayout = new RelativeLayout(context);
        insideLayout.setLayoutParams(leftParam);
        insideLayout.setPadding(line1PaddingColor * 2, stopsPaddingTop, 0, 0);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            insideLayout.setBackground(ContextCompat.getDrawable(parent.getContext(), R.drawable.any_selector));
        }

        final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
        int lineId = Util.generateViewId();
        lineIndication.setId(lineId);

        final RelativeLayout.LayoutParams stopParam = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        stopParam.addRule(RelativeLayout.RIGHT_OF, lineId);
        stopParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

        final LinearLayout stopLayout = new LinearLayout(context);
        stopLayout.setOrientation(LinearLayout.VERTICAL);
        stopLayout.setLayoutParams(stopParam);
        int stopId = Util.generateViewId();
        stopLayout.setId(stopId);

        final RelativeLayout.LayoutParams boundParam = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        boundParam.addRule(RelativeLayout.RIGHT_OF, stopId);

        final LinearLayout boundLayout = new LinearLayout(context);
        boundLayout.setOrientation(LinearLayout.HORIZONTAL);

        final String direction = entry.getKey();
        final List<BusArrival> busArrivals = entry.getValue();
        final String routeId = busArrivals.get(0).getRouteId();

        final TextView bound = new TextView(context);
        final String routeIdText = routeId + " (" + direction + "): ";
        bound.setText(routeIdText);
        bound.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
        boundLayout.addView(bound);

        Stream.of(busArrivals).forEach(busArrival -> {
            final TextView timeView = new TextView(context);
            final String timeLeftDueDelay = busArrival.getTimeLeftDueDelay() + " ";
            timeView.setText(timeLeftDueDelay);
            timeView.setTextColor(ContextCompat.getColor(context, R.color.grey));
            timeView.setLines(1);
            timeView.setEllipsize(TruncateAt.END);
            boundLayout.addView(timeView);
        });

        stopLayout.addView(boundLayout);

        insideLayout.addView(lineIndication);
        insideLayout.addView(stopLayout);
        resultLayout.addView(insideLayout);
    });

    convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, busStop.getId(),
            busStop.getPosition().getLatitude(), busStop.getPosition().getLongitude()));
    return convertView;
}

From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java

private View handleBikes(final int position, @NonNull final ViewGroup parent) {
    final LayoutInflater vi = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View convertView = vi.inflate(R.layout.list_nearby, parent, false);

    final int index = position - (stations.size() + busStops.size());
    final BikeStation bikeStation = bikeStations.get(index);

    final LinearLayout favoritesData = (LinearLayout) convertView.findViewById(R.id.nearby_results);

    final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(/*from ww  w  .ja v a  2 s.c o  m*/
            ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bike_white_24dp));

    final TextView routeView = (TextView) convertView.findViewById(R.id.station_name);
    routeView.setText(bikeStation.getName());

    final LinearLayout llh = new LinearLayout(context);
    llh.setOrientation(LinearLayout.HORIZONTAL);
    llh.setPadding(line1PaddingColor, stopsPaddingTop, 0, 0);

    final LinearLayout availableLayout = new LinearLayout(context);
    availableLayout.setOrientation(LinearLayout.VERTICAL);

    final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final RelativeLayout availableBikes = new RelativeLayout(context);
    availableBikes.setLayoutParams(leftParam);
    availableBikes.setPadding(line1PaddingColor, 0, 0, 0);

    final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
    int lineId = Util.generateViewId();
    lineIndication.setId(lineId);

    final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableParam.addRule(RelativeLayout.RIGHT_OF, lineId);
    availableParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

    final TextView availableBike = new TextView(context);
    availableBike.setText(context.getString(R.string.bike_available_bikes));
    availableBike.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
    availableBike.setLayoutParams(availableParam);
    int availableBikeId = Util.generateViewId();
    availableBike.setId(availableBikeId);

    final RelativeLayout.LayoutParams amountParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    amountParam.addRule(RelativeLayout.RIGHT_OF, availableBikeId);

    final TextView amountBike = new TextView(context);
    final String amountBikeText = String.valueOf(bikeStation.getAvailableBikes());
    amountBike.setText(amountBikeText);
    int color = bikeStation.getAvailableBikes() == 0 ? R.color.red : R.color.green;
    amountBike.setTextColor(ContextCompat.getColor(context, color));
    amountBike.setLayoutParams(amountParam);

    availableBikes.addView(lineIndication);
    availableBikes.addView(availableBike);
    availableBikes.addView(amountBike);

    final LinearLayout.LayoutParams leftParam2 = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final RelativeLayout availableDocks = new RelativeLayout(context);
    availableDocks.setLayoutParams(leftParam2);
    availableDocks.setPadding(line1PaddingColor, 0, 0, 0);

    final RelativeLayout lineIndication2 = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
    int lineId2 = Util.generateViewId();
    lineIndication2.setId(lineId2);

    final RelativeLayout.LayoutParams availableDockParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableDockParam.addRule(RelativeLayout.RIGHT_OF, lineId2);
    availableDockParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

    final TextView availableDock = new TextView(context);
    availableDock.setText(context.getString(R.string.bike_available_docks));
    availableDock.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
    availableDock.setLayoutParams(availableDockParam);
    int availableDockBikeId = Util.generateViewId();
    availableDock.setId(availableDockBikeId);

    final RelativeLayout.LayoutParams amountParam2 = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    amountParam2.addRule(RelativeLayout.RIGHT_OF, availableDockBikeId);

    final TextView amountDock = new TextView(context);
    final String amountDockText = String.valueOf(bikeStation.getAvailableDocks());
    amountDock.setText(amountDockText);
    color = bikeStation.getAvailableDocks() == 0 ? R.color.red : R.color.green;
    amountDock.setTextColor(ContextCompat.getColor(context, color));

    amountDock.setLayoutParams(amountParam2);

    availableDocks.addView(lineIndication2);
    availableDocks.addView(availableDock);
    availableDocks.addView(amountDock);

    availableLayout.addView(availableBikes);
    availableLayout.addView(availableDocks);

    llh.addView(availableLayout);

    favoritesData.addView(llh);

    convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, bikeStation.getId(),
            bikeStation.getLatitude(), bikeStation.getLongitude()));
    return convertView;
}

From source file:com.breadwallet.presenter.fragments.MainFragmentQR.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The last two arguments ensure LayoutParams are inflated
    // properly.//from w w  w. ja va 2 s  .com
    final View rootView = inflater.inflate(R.layout.fragment_qr_main, container, false);

    BRWalletManager.refreshAddress();
    receiveAddress = SharedPreferencesManager.getReceiveAddress(getActivity());
    qrImageLayout = (LinearLayout) rootView.findViewById(R.id.qr_image_address_layout);
    qrcode = (ImageView) rootView.findViewById(R.id.main_image_qr_code);
    sharingFragment = new FragmentSharing();
    final RelativeLayout mainFragmentQr = (RelativeLayout) rootView.findViewById(R.id.main_fragment_qr);
    mainAddressText = (TextView) rootView.findViewById(R.id.main_address_text);
    addressLayout = (RelativeLayout) rootView.findViewById(R.id.theAddressLayout);
    String bitcoinUrl = "bitcoin:" + receiveAddress;
    mainAddressText.setText(receiveAddress);
    BRWalletManager.getInstance(getActivity()).generateQR(bitcoinUrl, qrcode);
    fm = getActivity().getFragmentManager();
    mainFragmentQr.setPadding(0, MainActivity.screenParametersPoint.y / 5, 0, 0);
    final BreadWalletApp breadWalletApp = (BreadWalletApp) getActivity().getApplication();
    addressLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            breadWalletApp.cancelToast();
            if (BRAnimator.checkTheMultipressingAvailability()) {
                MainActivity app = MainActivity.app;
                if (app != null)
                    app.hideAllBubbles();
                //                    Log.e(TAG, "finalReceiveAddress: " + receiveAddress);
                sharingFragment.setTheAddress(receiveAddress);
                saveBitmapToFile();
                sharingFragment.show(fm, FragmentSharing.class.getName());
            }
        }
    });
    qrcode.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTips();
        }
    });
    qrImageLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showTips();
        }
    });

    final MainActivity app = MainActivity.app;
    if (app != null) {
        app.qrBubble1 = (BubbleTextView) rootView.findViewById(R.id.qr_bubble1);
        app.qrBubble2 = (BubbleTextView) rootView.findViewById(R.id.qr_bubble2);
    }
    rootView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (app != null) {
                app.hideAllBubbles();
            }
        }
    });

    setTipsPositions(rootView);

    return rootView;
}

From source file:mobi.monaca.framework.plugin.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/*  ww  w . j a  va 2s  . c  o  m*/
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         *
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            ImageButton back = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setImageResource(R.drawable.childbroswer_icon_arrow_left);
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            ImageButton forward = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            forward.setImageResource(R.drawable.childbroswer_icon_arrow_right);
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close button
            ImageButton close = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            close.setImageResource(R.drawable.childbroswer_icon_close);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(cordova.getActivity());
            webview.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);
            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            //TODO check LocalFileBootloader
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}