Example usage for android.widget LinearLayout setOrientation

List of usage examples for android.widget LinearLayout setOrientation

Introduction

In this page you can find the example usage for android.widget LinearLayout setOrientation.

Prototype

public void setOrientation(@OrientationMode int orientation) 

Source Link

Document

Should the layout be a column or a row.

Usage

From source file:com.phonegap.plugins.slaveBrowser.SlaveBrowser.java

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

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(ctx.getContext());
            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");
                    }
                }
            });

            LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);
            LinearLayout main = new LinearLayout(ctx.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(ctx.getContext());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            edittext = new TextView(ctx.getContext());
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(zeTitle);
            edittext.setTextSize(TypedValue.COMPLEX_UNIT_PX, 24);
            edittext.setGravity(Gravity.CENTER);
            edittext.setTextColor(Color.DKGRAY);
            edittext.setTypeface(Typeface.DEFAULT_BOLD);
            edittext.setLayoutParams(editParams);

            webview = new WebView(ctx.getContext());
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setBuiltInZoomControls(true);

            // dda: intercept calls to console.log
            webview.setWebChromeClient(new WebChromeClient() {
                public boolean onConsoleMessage(ConsoleMessage cmsg) {
                    // check secret prefix
                    if (cmsg.message().startsWith("MAGICHTML")) {
                        String msg = cmsg.message().substring(9); // strip off prefix
                        /* process HTML */
                        try {
                            JSONObject obj = new JSONObject();
                            obj.put("type", PAGE_LOADED);
                            obj.put("html", msg);
                            sendUpdate(obj, true);
                        } catch (JSONException e) {
                            Log.d(LOG_TAG, "This should never happen");
                        }
                        return true;
                    }
                    return false;
                }
            });

            // dda: inject the JavaScript on page load
            webview.setWebViewClient(new SlaveBrowserClient(edittext) {
                public void onPageFinished(WebView view, String address) {
                    // have the page spill its guts, with a secret prefix
                    view.loadUrl(
                            "javascript:console.log('MAGICHTML'+document.getElementsByTagName('html')[0].innerHTML);");
                }
            });

            webview.loadUrl(url);
            webview.setId(5);
            webview.setInitialScale(0);
            webview.setLayoutParams(wvParams);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            toolbar.addView(edittext);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            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 {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}

From source file:com.androcast.illusion.illusionmod.MainActivity.java

/**
 * Dialog which asks the user to enter his password
 *
 * @param password current encoded password
 *///  w ww  . j a v a  2s.c o  m
private void askPassword(final String password) {
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

    final AppCompatEditText mPassword = new AppCompatEditText(this);
    mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mPassword.setHint(getString(R.string.password));
    linearLayout.addView(mPassword);

    new AlertDialog.Builder(this).setView(linearLayout).setCancelable(false)
            .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (mPassword.getText().toString().equals(Utils.decodeString(password)))
                        new Task().execute();
                    else {
                        Utils.toast(getString(R.string.password_wrong), MainActivity.this);
                        finish();
                    }
                }
            }).show();
}

From source file:com.azure.webapi.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 * //from  w  w w. j av  a  2s .  c  o m
 * @param provider
 *            The provider used for the authentication process
 * @param startUrl
 *            The initial URL for the authentication process
 * @param endUrl
 *            The final URL for the authentication process
 * @param context
 *            The context used to create the authentication dialog
 * @param callback
 *            Callback to invoke when the authentication process finishes
 */
protected void showLoginUI(MobileServiceAuthenticationProvider provider, final String startUrl,
        final String endUrl, final Context context, LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setTitle("Connecting to a service");
    builder.setCancelable(true);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });

    // Set cancel button's action
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
            wv.destroy();
        }
    });

    wv.getSettings().setJavaScriptEnabled(true);

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished
            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}

From source file:com.stan.createcustommap.MainActivity.java

private void addMarker() {
    if (mMap != null) {
        LinearLayout layout = new LinearLayout(MainActivity.this);
        layout.setLayoutParams(new ActionBar.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        layout.setOrientation(LinearLayout.VERTICAL);

        final EditText titleField = new EditText(MainActivity.this);
        titleField.setHint("Title");

        final EditText latField = new EditText(MainActivity.this);
        latField.setHint("Latitude");
        latField.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED);
        final EditText longField = new EditText(MainActivity.this);
        longField.setHint("Longitude");
        longField.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED);

        layout.addView(titleField);//from   w  w w  .ja  va  2  s .c  o m
        layout.addView(latField);
        layout.addView(longField);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Add Marker");
        builder.setView(layout);
        AlertDialog alertDialog = builder.create();
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean parsable = true;
                Double lat = null, lon = null;
                String strLat = latField.getText().toString();
                String strLon = longField.getText().toString();
                String strTitle = titleField.getText().toString();
                try {
                    lat = Double.parseDouble(strLat);

                } catch (NumberFormatException ex) {
                    parsable = false;
                    Toast.makeText(MainActivity.this, "Latitude does not contain a parsable double",
                            Toast.LENGTH_LONG).show();
                }
                try {
                    lon = Double.parseDouble(strLon);
                } catch (NumberFormatException ex) {
                    parsable = false;
                    Toast.makeText(MainActivity.this, "Longitude does not contain a parsable double",
                            Toast.LENGTH_LONG);
                }
                if (parsable) {
                    LatLng targetLatLng = new LatLng(lat, lon);
                    MarkerOptions markerOptions = new MarkerOptions().position(targetLatLng).title(strTitle);

                    markerOptions.draggable(true);
                    mMap.addMarker(markerOptions);
                    mMap.moveCamera(CameraUpdateFactory.newLatLng(targetLatLng));
                }

            }
        });
        builder.setNegativeButton("Cancel", null);
        builder.show();
    } else {
        Toast.makeText(MainActivity.this, "Map not ready", Toast.LENGTH_LONG).show();
    }
}

From source file:org.sufficientlysecure.keychain.ui.base.RecyclerFragment.java

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

    final Context context = getContext();
    FrameLayout root = new FrameLayout(context);

    LinearLayout progressContainer = new LinearLayout(context);
    progressContainer.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    progressContainer.setOrientation(LinearLayout.VERTICAL);
    progressContainer.setGravity(Gravity.CENTER);
    progressContainer.setVisibility(View.GONE);

    ProgressBar progressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);

    progressContainer.addView(progressBar, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(progressContainer, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    FrameLayout listContainer = new FrameLayout(context);
    listContainer.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView textView = new TextView(context);
    textView.setId(INTERNAL_EMPTY_VIEW_ID);
    textView.setGravity(Gravity.CENTER);

    listContainer.addView(textView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    RecyclerView listView = new RecyclerView(context);
    listView.setId(INTERNAL_LIST_VIEW_ID);

    int padding = FormattingUtils.dpToPx(context, 8);
    listView.setPadding(padding, 0, padding, 0);
    listView.setClipToPadding(false);// ww  w  .j  a  v a  2s .c om

    listContainer.addView(listView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(listContainer, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:vit.collegecode.mediadb.fragments.HeaderFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Activity activity = getActivity();
    assert activity != null;
    mFrameLayout = new FrameLayout(activity);

    mHeader = onCreateHeaderView(inflater, mFrameLayout);
    mHeaderHeader = mHeader.findViewById(android.R.id.title);
    mHeaderBackground = mHeader.findViewById(android.R.id.background);
    assert mHeader.getLayoutParams() != null;
    mHeaderHeight = mHeader.getLayoutParams().height;

    mFakeHeader = new Space(activity);
    mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight));

    View content = onCreateContentView(inflater, mFrameLayout);
    if (content instanceof ListView) {
        isListViewEmpty = true;/*from  ww  w.j a v a 2  s. c o m*/

        final ListView listView = (ListView) content;
        listView.addHeaderView(mFakeHeader);
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScrollStateChanged(absListView, scrollState);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (isListViewEmpty) {
                    scrollHeaderTo(0);
                } else {
                    final View child = absListView.getChildAt(0);
                    assert child != null;
                    scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight);
                }
            }
        });
    } else {

        // Merge fake header view and content view.
        final LinearLayout view = new LinearLayout(activity);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setOrientation(LinearLayout.VERTICAL);
        view.addView(mFakeHeader);
        view.addView(content);

        // Put merged content to ScrollView
        final NotifyingScrollView scrollView = new NotifyingScrollView(activity);
        scrollView.addView(view);
        scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() {
            @Override
            public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
                scrollHeaderTo(-t);
            }
        });
        content = scrollView;
    }

    mFrameLayout.addView(content);
    mFrameLayout.addView(mHeader);

    // Content overlay view always shows at the top of content.
    if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) {
        mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    // Post initial scroll
    mFrameLayout.post(new Runnable() {
        @Override
        public void run() {
            scrollHeaderTo(0, true);
        }
    });

    Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_bottom);
    mFrameLayout.startAnimation(anim);

    return mFrameLayout;
}

From source file:mobisocial.musubi.objects.IntroductionObj.java

@Override
public View createView(Context context, ViewGroup frame) {
    LinearLayout wrap = new LinearLayout(context);
    wrap.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    wrap.setOrientation(LinearLayout.VERTICAL);
    wrap.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    wrap.setEnabled(false);//from   w  w  w .j a v  a  2  s .c  o m
    wrap.setFocusableInTouchMode(false);
    wrap.setFocusable(false);
    wrap.setClickable(false);

    TextView title = new TextView(context);
    title.setText(R.string.introduced);
    title.setTypeface(null, Typeface.BOLD);
    title.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    wrap.addView(title);

    Gallery intro = new Gallery(context);
    intro.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    hackGalleryInit(context, intro);
    wrap.addView(intro);
    return wrap;
}

From source file:net.gaast.giggity.ChooserActivity.java

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

    //this.setTheme(android.R.style.Theme_Holo);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_PROGRESS);

    /*//test stuff/*w  w w . j a  v a 2 s.c  o  m*/
    Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = {  };
    v.vibrate(pattern, -1);
    */

    Giggity app = (Giggity) getApplication();
    db = app.getDb();
    pref = PreferenceManager.getDefaultSharedPreferences(app);

    refreshSeed(false);

    list = new ListView(this);
    list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
            DbSchedule item = (DbSchedule) lista.getItem(position);
            if (item != null) {
                openSchedule(item, false);
            }
        }
    });
    list.setLongClickable(true);
    list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
            DbSchedule sched = (DbSchedule) lista.getItem((int) mi.id);
            if (sched != null) {
                menu.setHeaderTitle(sched.getTitle());
                menu.add(ContextMenu.NONE, 0, 0, R.string.refresh);
                menu.add(ContextMenu.NONE, 3, 0, R.string.unhide);
                menu.add(ContextMenu.NONE, 1, 0, R.string.remove);
                menu.add(ContextMenu.NONE, 2, 0, R.string.show_url);
            }
        }
    });

    /* Filling in the list in onResume(). */
    refresher = new SwipeRefreshLayout(this);
    refresher.setOnRefreshListener(this);
    refresher.addView(list);

    LinearLayout cont = new LinearLayout(this);
    cont.setOrientation(LinearLayout.VERTICAL);
    cont.addView(refresher, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1));

    setContentView(cont);
}

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(LT, "App created.");
    Events.intEnableDebug(1);/*  www .  j a  v a2s .  c o  m*/
    // disable the titlebar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // create a basic user interface
    LinearLayout panel = new LinearLayout(this);
    panel.setOrientation(LinearLayout.VERTICAL);
    setContentView(panel);

    EditText v = new EditText(this);
    v.setId(idTextView);
    v.setOnClickListener(this);
    panel.addView(v);

    // --
    Button b = new Button(this);
    b.setText("Scan Input Devs");
    b.setId(idButScan);
    b.setOnClickListener(this);
    panel.addView(b);

    // put list in a scroll view
    LinearLayout listLayout = new LinearLayout(this);
    listLayout.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    m_lvDevices = new ListView(this);
    LayoutParams lvLayoutParam = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    m_lvDevices.setLayoutParams(lvLayoutParam);
    m_lvDevices.setId(idLVDevices);
    m_lvDevices.setDividerHeight(0);
    m_lvDevices.setFadingEdgeLength(0);
    m_lvDevices.setCacheColorHint(0);
    m_lvDevices.setAdapter(null);

    listLayout.addView(m_lvDevices);
    panel.addView(listLayout);
    // --
    LinearLayout panelH = new LinearLayout(this);
    panelH.setOrientation(LinearLayout.HORIZONTAL);
    panel.addView(panelH);
    // --
    m_selDevSpinner = new Spinner(this);
    m_selDevSpinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    m_selDevSpinner.setId(idSelSpin);
    m_selDevSpinner.setOnItemSelectedListener((OnItemSelectedListener) this);
    panelH.addView(m_selDevSpinner);
    // -- simulate key event
    b = new Button(this);
    b.setText(">Key");
    b.setId(idButInjectKey);
    b.setOnClickListener(this);
    panelH.addView(b);
    // -- simulate touch event
    b = new Button(this);
    b.setText(">Tch");
    b.setId(idButInjectTouch);
    b.setOnClickListener(this);
    panelH.addView(b);
    // --
    m_tvMonitor = new TextView(this);
    m_tvMonitor.setText("Event Monitor stopped.");
    panel.addView(m_tvMonitor);
    // --
    panelH = new LinearLayout(this);
    panelH.setOrientation(LinearLayout.HORIZONTAL);
    panel.addView(panelH);
    // --
    b = new Button(this);
    b.setText("Monitor Start");
    b.setId(idButMonitorStart);
    b.setOnClickListener(this);
    panelH.addView(b);
    // --
    b = new Button(this);
    b.setText("Monitor Stop");
    b.setId(idButMonitorStop);
    b.setOnClickListener(this);
    panelH.addView(b);
    // -- simulate test event
    b = new Button(this);
    b.setText(">Test");
    b.setId(idButTest);
    b.setOnClickListener(this);
    panelH.addView(b);
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java

private void populateKeyboardRow(KeyboardRow keyboardRow, int keyHeight) {
    Context context = getContext();
    LinearLayout keyContainer = new LinearLayout(context);
    keyContainer.setOrientation(HORIZONTAL);
    keyContainer.setGravity(Gravity.CENTER);

    List<KeyboardKey> keyList = keyboardRow.getKeyList();
    if (keyList != null) {
        for (int i = 0; i < keyList.size(); i++) {
            KeyboardKey keyboardKey = keyList.get(i);
            if (keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_NORMAL) {
                TextView key = new TextView(context);
                key.setGravity(Gravity.CENTER);
                key.setTypeface(mCharTypeface, Typeface.BOLD);
                key.setText(keyboardKey.getCharCode());
                key.setTextSize(16f);/*from  w w  w . j a v  a 2s . co  m*/
                key.setTextColor(
                        ContextCompat.getColorStateList(context, R.color.amharic_key_text_color_selector));
                key.setTag(keyboardKey);
                key.setIncludeFontPadding(false);
                keyContainer.setBaselineAligned(false);
                handleChild(key, keyboardKey.getColumnCount(), keyContainer, keyHeight);
            } else if (keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_BACKSPACE
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_SPACE
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_NEW_LINE
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_EVENT_ENTER
                    || keyboardKey.getKeyCommand() == KeyboardKey.KEY_HIDE_KEYBOARD) {
                ImageView child = new ImageView(context);
                child.setImageResource(keyboardKey.getCommandImage());
                int padding = getCustomSize(6);
                child.setPadding(padding, padding, padding, padding);
                child.setTag(keyboardKey);
                handleChild(child, keyboardKey.getColumnCount(), keyContainer, keyHeight);
            }
        }
    }
    addView(keyContainer, new LayoutParams(LayoutParams.MATCH_PARENT, keyHeight));
}