Example usage for android.widget TabHost setLayoutParams

List of usage examples for android.widget TabHost setLayoutParams

Introduction

In this page you can find the example usage for android.widget TabHost setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:org.geometerplus.android.fbreader.bookmark.EditBookmarkActivity.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.edit_bookmark);

    myBookmark = FBReaderIntents.getBookmarkExtra(getIntent());
    if (myBookmark == null) {
        finish();//from   w w w .  j av a  2 s  . co  m
        return;
    }

    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final int width = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 500, dm),
            dm.widthPixels * 9 / 10);
    final int height = Math.min((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350, dm),
            dm.heightPixels * 9 / 10);

    final TabHost tabHost = (TabHost) findViewById(R.id.edit_bookmark_tabhost);
    tabHost.setLayoutParams(new FrameLayout.LayoutParams(new ViewGroup.LayoutParams(width, height)));
    tabHost.setup();

    addTab(tabHost, "text", R.id.edit_bookmark_content_text);
    addTab(tabHost, "style", R.id.edit_bookmark_content_style);
    addTab(tabHost, "delete", R.id.edit_bookmark_content_delete);

    final ZLStringOption currentTabOption = new ZLStringOption("LookNFeel", "EditBookmark", "text");
    tabHost.setCurrentTabByTag(currentTabOption.getValue());
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        public void onTabChanged(String tag) {
            if (!"delete".equals(tag)) {
                currentTabOption.setValue(tag);
            }
        }
    });

    final EditText editor = (EditText) findViewById(R.id.edit_bookmark_text);
    editor.setText(myBookmark.getText());
    final int len = editor.getText().length();
    editor.setSelection(len, len);

    final Button saveTextButton = (Button) findViewById(R.id.edit_bookmark_save_text_button);
    saveTextButton.setEnabled(false);
    saveTextButton.setText(myResource.getResource("saveText").getValue());
    saveTextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            myCollection.bindToService(EditBookmarkActivity.this, new Runnable() {
                public void run() {
                    myBookmark.setText(editor.getText().toString());
                    myCollection.saveBookmark(myBookmark);
                    saveTextButton.setEnabled(false);
                }
            });
        }
    });
    editor.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence sequence, int start, int before, int count) {
            final String originalText = myBookmark.getText();
            saveTextButton.setEnabled(!originalText.equals(editor.getText().toString()));
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    final Button deleteButton = (Button) findViewById(R.id.edit_bookmark_delete_button);
    deleteButton.setText(myResource.getResource("deleteBookmark").getValue());
    deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            myCollection.bindToService(EditBookmarkActivity.this, new Runnable() {
                public void run() {
                    myCollection.deleteBookmark(myBookmark);
                    finish();
                }
            });
        }
    });
}