Example usage for android.util TypedValue COMPLEX_UNIT_PT

List of usage examples for android.util TypedValue COMPLEX_UNIT_PT

Introduction

In this page you can find the example usage for android.util TypedValue COMPLEX_UNIT_PT.

Prototype

int COMPLEX_UNIT_PT

To view the source code for android.util TypedValue COMPLEX_UNIT_PT.

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is in points.

Usage

From source file:Main.java

public static float applyDimension(int unit, float value, DisplayMetrics metrics) {
    switch (unit) {
    case TypedValue.COMPLEX_UNIT_PX:
        return value;
    case TypedValue.COMPLEX_UNIT_DIP:
        return value * metrics.density;
    case TypedValue.COMPLEX_UNIT_SP:
        return value * metrics.scaledDensity;
    case TypedValue.COMPLEX_UNIT_PT:
        return value * metrics.xdpi * (1.0f / 72);
    case TypedValue.COMPLEX_UNIT_IN:
        return value * metrics.xdpi;
    case TypedValue.COMPLEX_UNIT_MM:
        return value * metrics.xdpi * (1.0f / 25.4f);
    }/*  w  ww . j a  v a2s. c om*/
    return 0;
}

From source file:com.nextlevel.playarduino.arduinofullstack.WebRTC.HudFragment.java

private void hudViewsSetProperties(int visibility) {
    hudViewBwe.setVisibility(visibility);
    hudViewConnection.setVisibility(visibility);
    hudViewVideoSend.setVisibility(visibility);
    hudViewVideoRecv.setVisibility(visibility);
    hudViewBwe.setTextSize(TypedValue.COMPLEX_UNIT_PT, 5);
    hudViewConnection.setTextSize(TypedValue.COMPLEX_UNIT_PT, 5);
    hudViewVideoSend.setTextSize(TypedValue.COMPLEX_UNIT_PT, 5);
    hudViewVideoRecv.setTextSize(TypedValue.COMPLEX_UNIT_PT, 5);
}

From source file:com.infthink.demo.webrtc.MainActivity.java

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

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

    setContentView(R.layout.activity_fullscreen);

    // init flint related
    String APPLICATION_ID = "~flint_android_webrtc_demo";
    Flint.FlintApi.setApplicationId(APPLICATION_ID);

    mWebrtcChannel = new MyWebrtcChannel();

    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    mMediaRouteSelector = new MediaRouteSelector.Builder()
            .addControlCategory(FlintMediaControlIntent.categoryForFlint(APPLICATION_ID)).build();

    mMediaRouterCallback = new MediaRouterCallback();
    mFlingListener = new FlingListener();
    mConnectionCallbacks = new ConnectionCallbacks();

    mIceConnected = false;/*from  w w w  .  ja v a2s  . com*/

    // init views
    mRootView = findViewById(android.R.id.content);
    mEncoderStatView = (TextView) findViewById(R.id.encoder_stat);
    mMenuBar = findViewById(R.id.menubar_fragment);
    mRoomName = (TextView) findViewById(R.id.room_name);
    mVideoView = (GLSurfaceView) findViewById(R.id.glview);

    mMediaRouteButton = (MediaRouteButton) mMenuBar.findViewById(R.id.media_route_button);
    mMediaRouteButton.setRouteSelector(mMediaRouteSelector);

    VideoRendererGui.setView(mVideoView);

    mScalingType = ScalingType.SCALE_ASPECT_FILL;
    mRemoteRender = VideoRendererGui.create(0, 0, 100, 100, mScalingType, false);
    mLocalRender = VideoRendererGui.create(0, 0, 100, 100, mScalingType, true);

    mVideoView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int visibility = mMenuBar.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE;
            mEncoderStatView.setVisibility(visibility);
            mMenuBar.setVisibility(visibility);
            mRoomName.setVisibility(visibility);
            if (visibility == View.VISIBLE) {
                mEncoderStatView.bringToFront();
                mMenuBar.bringToFront();
                mRoomName.bringToFront();
                mRootView.invalidate();
            }
        }
    });

    ((ImageButton) findViewById(R.id.button_disconnect)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            logAndToast("Disconnecting call.");
            disconnect();
        }
    });

    ((ImageButton) findViewById(R.id.button_switch_camera)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mPeerConn != null) {
                mPeerConn.switchCamera();
            }
        }
    });

    ((ImageButton) findViewById(R.id.button_toggle_debug)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int visibility = mHudView.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE;
            mHudView.setVisibility(visibility);

            // use this to send view switch
            if (mApiClient != null && mApiClient.isConnected()) {
                mWebrtcChannel.sendSwitchView(mApiClient);
            }
        }
    });

    mVideoScalingButton = (ImageButton) findViewById(R.id.button_scaling_mode);
    mVideoScalingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mScalingType == ScalingType.SCALE_ASPECT_FILL) {
                mVideoScalingButton.setBackgroundResource(R.drawable.ic_action_full_screen);
                mScalingType = ScalingType.SCALE_ASPECT_FIT;
            } else {
                mVideoScalingButton.setBackgroundResource(R.drawable.ic_action_return_from_full_screen);
                mScalingType = ScalingType.SCALE_ASPECT_FILL;
            }
            updateVideoView();
        }
    });

    mHudView = new TextView(this);
    mHudView.setTextColor(Color.BLACK);
    mHudView.setBackgroundColor(Color.WHITE);
    mHudView.setAlpha(0.4f);
    mHudView.setTextSize(TypedValue.COMPLEX_UNIT_PT, 5);
    mHudView.setVisibility(View.INVISIBLE);
    addContentView(mHudView, mHudLayout);

    // Create and audio manager that will take care of audio routing,
    // audio modes, audio device enumeration etc.
    mAudioManager = AppRTCAudioManager.create(this);

    // ready to init webrtc params
    mWebrtcHelper = new WebRtcHelper(this);
    mWebrtcHelper.initParams();
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static int getSizeUnits(final String size) {
    int units = TypedValue.COMPLEX_UNIT_PX;
    String unitString = null;/*from   w ww .j av a2  s .com*/

    if (size != null) {
        Matcher m = SIZED_VALUE.matcher(size.trim());
        if (m.matches()) {
            if (m.groupCount() == 2) {
                unitString = m.group(2);
            }
        }
    }

    if (unitString == null) {
        unitString = TiApplication.getInstance().getDefaultUnit();
    }

    if (TiDimension.UNIT_PX.equals(unitString) || TiDimension.UNIT_SYSTEM.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_PX;
    } else if (TiDimension.UNIT_PT.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_PT;
    } else if (TiDimension.UNIT_DP.equals(unitString) || TiDimension.UNIT_DIP.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_DIP;
    } else if (TiDimension.UNIT_SP.equals(unitString) || TiDimension.UNIT_SIP.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_SP;
    } else if (TiDimension.UNIT_MM.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_MM;
    } else if (TiDimension.UNIT_CM.equals(unitString)) {
        units = TiDimension.COMPLEX_UNIT_CM;
    } else if (TiDimension.UNIT_IN.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_IN;
    } else {
        if (unitString != null) {
            Log.w(TAG, "Unknown unit: " + unitString, Log.DEBUG_MODE);
        }
    }

    return units;
}

From source file:com.example.damerap_ver1.IntroVideoActivity.java

/**
* Create the view in which the video will be rendered.
*///from w w w . ja va 2  s.  c om
private void setupView() {
    LinearLayout lLinLayout = new LinearLayout(this);
    lLinLayout.setId(1);
    lLinLayout.setOrientation(LinearLayout.VERTICAL);
    lLinLayout.setGravity(Gravity.CENTER);
    lLinLayout.setBackgroundColor(Color.BLACK);

    LayoutParams lLinLayoutParms = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    lLinLayout.setLayoutParams(lLinLayoutParms);

    this.setContentView(lLinLayout);

    RelativeLayout lRelLayout = new RelativeLayout(this);
    lRelLayout.setId(2);
    lRelLayout.setGravity(Gravity.CENTER);
    lRelLayout.setBackgroundColor(Color.BLACK);
    android.widget.RelativeLayout.LayoutParams lRelLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
    lRelLayout.setLayoutParams(lRelLayoutParms);
    lLinLayout.addView(lRelLayout);

    mVideoView = new VideoView(this);
    mVideoView.setId(3);
    android.widget.RelativeLayout.LayoutParams lVidViewLayoutParams = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lVidViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    mVideoView.setLayoutParams(lVidViewLayoutParams);
    lRelLayout.addView(mVideoView);

    mProgressBar = new ProgressBar(this);
    mProgressBar.setId(4);
    android.widget.RelativeLayout.LayoutParams lProgressBarLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressBarLayoutParms.addRule(RelativeLayout.CENTER_IN_PARENT);
    mProgressBar.setLayoutParams(lProgressBarLayoutParms);
    lRelLayout.addView(mProgressBar);

    mProgressMessage = new TextView(this);
    mProgressMessage.setId(5);
    android.widget.RelativeLayout.LayoutParams lProgressMsgLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressMsgLayoutParms.addRule(RelativeLayout.CENTER_HORIZONTAL);
    lProgressMsgLayoutParms.addRule(RelativeLayout.BELOW, 4);
    mProgressMessage.setLayoutParams(lProgressMsgLayoutParms);
    mProgressMessage.setTextColor(Color.LTGRAY);
    mProgressMessage.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);
    mProgressMessage.setText("...");
    lRelLayout.addView(mProgressMessage);
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static void getSizeAndUnits(final String size, final float[] result) {
    int units = TypedValue.COMPLEX_UNIT_PX;
    float value = 15.0f;
    String unitString = null;/*from   ww  w . ja va 2  s.c  o m*/

    if (size != null) {
        Matcher m = SIZED_VALUE.matcher(size.trim());
        if (m.matches()) {
            if (m.groupCount() == 2) {
                unitString = m.group(2);
                value = Float.parseFloat(m.group(1));
            }
        }
    }

    if (unitString == null) {
        unitString = TiApplication.getInstance().getDefaultUnit();
    }

    if (TiDimension.UNIT_PX.equals(unitString) || TiDimension.UNIT_SYSTEM.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_PX;
    } else if (TiDimension.UNIT_PT.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_PT;
    } else if (TiDimension.UNIT_DP.equals(unitString) || TiDimension.UNIT_DIP.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_DIP;
    } else if (TiDimension.UNIT_SP.equals(unitString) || TiDimension.UNIT_SIP.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_SP;
    } else if (TiDimension.UNIT_MM.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_MM;
    } else if (TiDimension.UNIT_CM.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_MM;
        value *= 10;
    } else if (TiDimension.UNIT_IN.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_IN;
    } else {
        if (unitString != null) {
            Log.w(TAG, "Unknown unit: " + unitString, Log.DEBUG_MODE);
        }
    }
    result[0] = units;
    result[1] = value;
}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url// w ww.j av  a  2  s . c o  m
 * @param features
 * @return
 */
public String showWebPage(final String url, final Options features) {
    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new ThemeableBrowserDialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar,
                    features.hardwareback);
            if (!features.disableAnimation) {
                dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            }
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setThemeableBrowser(getThemeableBrowser());

            // Main container layout
            ViewGroup main = null;

            if (features.fullscreen) {
                main = new FrameLayout(cordova.getActivity());
            } else {
                main = new LinearLayout(cordova.getActivity());
                ((LinearLayout) main).setOrientation(LinearLayout.VERTICAL);
            }

            // Toolbar layout
            Toolbar toolbarDef = features.toolbar;
            FrameLayout toolbar = new FrameLayout(cordova.getActivity());
            toolbar.setBackgroundColor(hexStringToColor(
                    toolbarDef != null && toolbarDef.color != null ? toolbarDef.color : "#ffffffff"));
            toolbar.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
                    dpToPixels(toolbarDef != null ? toolbarDef.height : TOOLBAR_DEF_HEIGHT)));

            if (toolbarDef != null && (toolbarDef.image != null || toolbarDef.wwwImage != null)) {
                try {
                    Drawable background = getImage(toolbarDef.image, toolbarDef.wwwImage,
                            toolbarDef.wwwImageDensity);
                    setBackground(toolbar, background);
                } catch (Resources.NotFoundException e) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.image));
                } catch (IOException ioe) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.wwwImage));
                }
            }

            // Left Button Container layout
            LinearLayout leftButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams leftButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            leftButtonContainerParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
            leftButtonContainer.setLayoutParams(leftButtonContainerParams);
            leftButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Right Button Container layout
            LinearLayout rightButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams rightButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            rightButtonContainerParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
            rightButtonContainer.setLayoutParams(rightButtonContainerParams);
            rightButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            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;
                }
            });

            // Back button
            final Button back = createButton(features.backButton, "back button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.backButton, inAppWebView.getUrl());

                    if (features.backButtonCanClose && !canGoBack()) {
                        closeDialog();
                    } else {
                        goBack();
                    }
                }
            });

            if (back != null) {
                back.setEnabled(features.backButtonCanClose);
            }

            // Forward button
            final Button forward = createButton(features.forwardButton, "forward button",
                    new View.OnClickListener() {
                        public void onClick(View v) {
                            emitButtonEvent(features.forwardButton, inAppWebView.getUrl());

                            goForward();
                        }
                    });

            if (forward != null) {
                forward.setEnabled(false);
            }

            // Close/Done button
            Button close = createButton(features.closeButton, "close button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.closeButton, inAppWebView.getUrl());
                    closeDialog();
                }
            });

            // Menu button
            Spinner menu = features.menu != null ? new MenuSpinner(cordova.getActivity()) : null;
            if (menu != null) {
                menu.setLayoutParams(
                        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                menu.setContentDescription("menu button");
                setButtonImages(menu, features.menu, DISABLED_ALPHA);

                // We are not allowed to use onClickListener for Spinner, so we will use
                // onTouchListener as a fallback.
                menu.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            emitButtonEvent(features.menu, inAppWebView.getUrl());
                        }
                        return false;
                    }
                });

                if (features.menu.items != null) {
                    HideSelectedAdapter<EventLabel> adapter = new HideSelectedAdapter<EventLabel>(
                            cordova.getActivity(), android.R.layout.simple_spinner_item, features.menu.items);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    menu.setAdapter(adapter);
                    menu.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                            if (inAppWebView != null && i < features.menu.items.length) {
                                emitButtonEvent(features.menu.items[i], inAppWebView.getUrl(), i);
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> adapterView) {
                        }
                    });
                }
            }

            // Title
            final TextView title = features.title != null ? new TextView(cordova.getActivity()) : null;
            final TextView subtitle = features.title != null ? new TextView(cordova.getActivity()) : null;
            if (title != null) {
                FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                title.setLayoutParams(titleParams);
                title.setSingleLine();
                title.setEllipsize(TextUtils.TruncateAt.END);
                title.setGravity(Gravity.CENTER | Gravity.TOP);
                title.setTextColor(
                        hexStringToColor(features.title.color != null ? features.title.color : "#000000ff"));
                title.setTypeface(title.getTypeface(), Typeface.BOLD);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);

                FrameLayout.LayoutParams subtitleParams = new FrameLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                subtitle.setLayoutParams(subtitleParams);
                subtitle.setSingleLine();
                subtitle.setEllipsize(TextUtils.TruncateAt.END);
                subtitle.setGravity(Gravity.CENTER | Gravity.BOTTOM);
                subtitle.setTextColor(hexStringToColor(
                        features.title.subColor != null ? features.title.subColor : "#000000ff"));
                subtitle.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6);
                subtitle.setVisibility(View.GONE);

                if (features.title.staticText != null) {
                    title.setGravity(Gravity.CENTER);
                    title.setText(features.title.staticText);
                } else {
                    subtitle.setVisibility(View.VISIBLE);
                }
            }

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen
                    ? new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                    : new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
            if (!features.fullscreen) {
                ((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
            }
            inAppWebView.setLayoutParams(inAppWebViewParams);
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {

                @Override
                public void onPageStarted(String url) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle
                            && features.title.loadingText != null) {
                        title.setText(features.title.loadingText);
                        subtitle.setText(url);
                    }
                }

                @Override
                public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle) {
                        title.setText(inAppWebView.getTitle());
                        subtitle.setText(inAppWebView.getUrl());
                    }

                    if (back != null) {
                        back.setEnabled(canGoBack || features.backButtonCanClose);
                    }

                    if (forward != null) {
                        forward.setEnabled(canGoForward);
                    }
                }
            });
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(features.zoom);
            settings.setDisplayZoomControls(false);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null
                    || appSettings.getBoolean("ThemeableBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("themeableBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (features.clearcache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (features.clearsessioncache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add buttons to either leftButtonsContainer or
            // rightButtonsContainer according to user's alignment
            // configuration.
            int leftContainerWidth = 0;
            int rightContainerWidth = 0;

            if (features.customButtons != null) {
                for (int i = 0; i < features.customButtons.length; i++) {
                    final BrowserButton buttonProps = features.customButtons[i];
                    final int index = i;
                    Button button = createButton(buttonProps, String.format("custom button at %d", i),
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (inAppWebView != null) {
                                        emitButtonEvent(buttonProps, inAppWebView.getUrl(), index);
                                    }
                                }
                            });

                    if (ALIGN_RIGHT.equals(buttonProps.align)) {
                        rightButtonContainer.addView(button);
                        rightContainerWidth += button.getLayoutParams().width;
                    } else {
                        leftButtonContainer.addView(button, 0);
                        leftContainerWidth += button.getLayoutParams().width;
                    }
                }
            }

            // Back and forward buttons must be added with special ordering logic such
            // that back button is always on the left of forward button if both buttons
            // are on the same side.
            if (forward != null && features.forwardButton != null
                    && !ALIGN_RIGHT.equals(features.forwardButton.align)) {
                leftButtonContainer.addView(forward, 0);
                leftContainerWidth += forward.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && ALIGN_RIGHT.equals(features.backButton.align)) {
                rightButtonContainer.addView(back);
                rightContainerWidth += back.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && !ALIGN_RIGHT.equals(features.backButton.align)) {
                leftButtonContainer.addView(back, 0);
                leftContainerWidth += back.getLayoutParams().width;
            }

            if (forward != null && features.forwardButton != null
                    && ALIGN_RIGHT.equals(features.forwardButton.align)) {
                rightButtonContainer.addView(forward);
                rightContainerWidth += forward.getLayoutParams().width;
            }

            if (menu != null) {
                if (features.menu != null && ALIGN_RIGHT.equals(features.menu.align)) {
                    rightButtonContainer.addView(menu);
                    rightContainerWidth += menu.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(menu, 0);
                    leftContainerWidth += menu.getLayoutParams().width;
                }
            }

            if (close != null) {
                if (features.closeButton != null && ALIGN_RIGHT.equals(features.closeButton.align)) {
                    rightButtonContainer.addView(close);
                    rightContainerWidth += close.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(close, 0);
                    leftContainerWidth += close.getLayoutParams().width;
                }
            }

            // Add the views to our toolbar
            toolbar.addView(leftButtonContainer);
            // Don't show address bar.
            // toolbar.addView(edittext);
            toolbar.addView(rightButtonContainer);

            if (title != null) {
                int titleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams titleParams = (FrameLayout.LayoutParams) title.getLayoutParams();
                titleParams.setMargins(titleMargin, 8, titleMargin, 0);
                toolbar.addView(title);
            }

            if (subtitle != null) {
                int subtitleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams subtitleParams = (FrameLayout.LayoutParams) subtitle.getLayoutParams();
                subtitleParams.setMargins(subtitleMargin, 0, subtitleMargin, 8);
                toolbar.addView(subtitle);
            }

            if (features.fullscreen) {
                // If full screen mode, we have to add inAppWebView before adding toolbar.
                main.addView(inAppWebView);
            }

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

            if (!features.fullscreen) {
                // If not full screen, we add inAppWebView after adding toolbar.
                main.addView(inAppWebView);
            }

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

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (features.hidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:self.philbrown.droidQuery.$.java

/**
 * Interprets the CSS-style String and sets the value
 * @param view the view that will change.
 * @param key the name of the attribute/*  www  .  j a va 2 s  .com*/
 * @param _value the end animation value
 * @return the computed value
 */
public Number getAnimationValue(View view, String key, String _value) {
    Number value = null;

    boolean negativeValue = false;
    if (_value.startsWith("-")) {
        negativeValue = true;
        _value = _value.substring(1);
    }

    String[] split = (_value).split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
    if (negativeValue)
        split[0] = String.format(Locale.US, "-%s", split[0]);
    if (split.length == 1) {
        if (split[0].contains(".")) {
            value = Float.valueOf(split[0]);
        } else {
            value = Integer.valueOf(split[0]);
        }
    } else {
        if (split.length > 2) {
            Log.w("droidQuery", "parsererror for key " + key);
            return null;
        }
        if (split[1].equalsIgnoreCase("px")) {
            //this is the default. Just determine if float or int
            if (split[0].contains(".")) {
                value = Float.valueOf(split[0]);
            } else {
                value = Integer.valueOf(split[0]);
            }
        } else if (split[1].equalsIgnoreCase("dip") || split[1].equalsIgnoreCase("dp")) {
            float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, Float.parseFloat(split[0]),
                    context.getResources().getDisplayMetrics());
            if (split[0].contains(".")) {
                value = px;
            } else {
                value = (int) px;
            }
        } else if (split[1].equalsIgnoreCase("in")) {
            float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_IN, Float.parseFloat(split[0]),
                    context.getResources().getDisplayMetrics());
            if (split[0].contains(".")) {
                value = px;
            } else {
                value = (int) px;
            }
        } else if (split[1].equalsIgnoreCase("mm")) {
            float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, Float.parseFloat(split[0]),
                    context.getResources().getDisplayMetrics());
            if (split[0].contains(".")) {
                value = px;
            } else {
                value = (int) px;
            }
        } else if (split[1].equalsIgnoreCase("pt")) {
            float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, Float.parseFloat(split[0]),
                    context.getResources().getDisplayMetrics());
            if (split[0].contains(".")) {
                value = px;
            } else {
                value = (int) px;
            }
        } else if (split[1].equalsIgnoreCase("sp")) {
            float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, Float.parseFloat(split[0]),
                    context.getResources().getDisplayMetrics());
            if (split[0].contains(".")) {
                value = px;
            } else {
                value = (int) px;
            }
        } else if (split[1].equals("%")) {
            ViewParent parent = view.getParent();
            float pixels = 0;
            if (parent == null || !(parent instanceof View)) {
                pixels = context.getResources().getDisplayMetrics().widthPixels;
                //use best guess for width or height dpi
                if (split[0].equalsIgnoreCase("y") || split[0].equalsIgnoreCase("top")
                        || split[0].equalsIgnoreCase("bottom")) {
                    pixels = context.getResources().getDisplayMetrics().heightPixels;
                }
            } else {
                pixels = ((View) parent).getWidth();
                if (split[0].equalsIgnoreCase("y") || split[0].equalsIgnoreCase("top")
                        || split[0].equalsIgnoreCase("bottom")) {
                    pixels = ((View) parent).getHeight();
                }
            }
            float percent = 0;
            if (pixels != 0)
                percent = Float.valueOf(split[0]) / 100 * pixels;
            if (split[0].contains(".")) {
                value = percent;
            } else {
                value = (int) percent;
            }
        } else {
            Log.w("droidQuery", "invalid units for Object with key " + key);
            return null;
        }
    }
    return value;
}