Example usage for android.util TypedValue COMPLEX_UNIT_PX

List of usage examples for android.util TypedValue COMPLEX_UNIT_PX

Introduction

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

Prototype

int COMPLEX_UNIT_PX

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

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is raw pixels.

Usage

From source file:ru.moscow.tuzlukov.sergey.weatherlog.MainActivity.java

private void makePlot(double minTemp, double maxTemp) {
    //all graphics should have a room, to be visible in plot viewport, i.e. max from greatest and min from the least ordinates:
    double lowLimit = Math.min(Math.round(minTemp), temperatureLimit2);
    double highLimit = Math.max(Math.round(maxTemp), temperatureLimit1);
    //round for drawing scale with 5-degrees step:
    lowLimit = Math.floor(lowLimit / 5.0) * 5.0;
    highLimit = Math.ceil(highLimit / 5.0) * 5.0;

    //fill in the plot with all data series:
    List<DataPoint> dataPoints = new ArrayList<>();
    for (Long time : temperatureMap.keySet())
        dataPoints.add(new DataPoint(time, temperatureMap.get(time)));
    dataPoints.add(new DataPoint(currentTime, dataPoints.get(dataPoints.size() - 1).getY())); //fix for using data from cache
    LineGraphSeries<DataPoint> temperatureSeries = new LineGraphSeries<>(
            dataPoints.toArray(new DataPoint[dataPoints.size()]));
    LineGraphSeries<DataPoint> temperatureLimit1Series = new LineGraphSeries<>(
            new DataPoint[] { new DataPoint(currentTimeMinus24h, temperatureLimit1),
                    new DataPoint(currentTime, temperatureLimit1) });
    LineGraphSeries<DataPoint> temperatureLimit2Series = new LineGraphSeries<>(
            new DataPoint[] { new DataPoint(currentTimeMinus24h, temperatureLimit2),
                    new DataPoint(currentTime, temperatureLimit2) });
    graphView.addSeries(temperatureSeries);
    graphView.addSeries(temperatureLimit1Series);
    graphView.addSeries(temperatureLimit2Series);

    //lay out the plot:
    GridLabelRenderer gridLabelRenderer = graphView.getGridLabelRenderer();
    Viewport viewport = graphView.getViewport();
    //adjust grid settings:
    gridLabelRenderer.setGridStyle(GridLabelRenderer.GridStyle.BOTH);
    gridLabelRenderer.setHighlightZeroLines(true);
    gridLabelRenderer.setHorizontalLabelsVisible(false);
    gridLabelRenderer.setVerticalLabelsVisible(true);
    //tune view of lines:
    viewport.setBackgroundColor(getResources().getColor(R.color.plot_viewport_background_color));
    temperatureSeries.setColor(getResources().getColor(R.color.temperature_series_color));
    temperatureSeries.setThickness(2);/*from w ww .j  av  a  2  s .  c om*/
    temperatureLimit1Series.setColor(getResources().getColor(R.color.limit1_series_color));
    temperatureLimit1Series.setThickness(2);
    temperatureLimit2Series.setColor(getResources().getColor(R.color.limit2_series_color));
    temperatureLimit2Series.setThickness(2);
    //set viewport bounds and set the scale:
    //...in horizontal:
    gridLabelRenderer.setNumHorizontalLabels(2);
    viewport.setMinX(currentTimeMinus24h);
    viewport.setMaxX(currentTime);
    viewport.setXAxisBoundsManual(true);
    //...in vertical:
    int numVerticalLabels = (int) (highLimit - lowLimit) / 5 + 1;
    numVerticalLabels = numVerticalLabels < 2 ? 2 : numVerticalLabels;
    gridLabelRenderer.setNumVerticalLabels(numVerticalLabels);
    viewport.setMinY(lowLimit);
    viewport.setMaxY(highLimit);
    viewport.setYAxisBoundsManual(true);
    //set horizontal labels:
    LinearLayout llHorizontalLabels = (LinearLayout) findViewById(R.id.llHorizontalLabels);
    if (llHorizontalLabels.getChildCount() == 0) {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) llHorizontalLabels.getLayoutParams();
        params.bottomMargin = 0;
        llHorizontalLabels.setLayoutParams(params);
        gridLabelRenderer.setTextSize(gridLabelRenderer.getTextSize() - 2); //make text a bit smaller
        for (int n = -24; n < 0; n += 3) {
            TextView textView = new TextView(MainActivity.this);
            textView.setText(String.valueOf(n));
            textView.setGravity(Gravity.START);
            textView.setSingleLine();
            params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f / 8.0f);
            textView.setLayoutParams(params);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, gridLabelRenderer.getTextSize());
            textView.setTextColor(gridLabelRenderer.getVerticalLabelsColor());
            llHorizontalLabels.addView(textView);
        }
        TextView tvZeroLabel = (TextView) findViewById(R.id.tvZeroLabel);
        tvZeroLabel.setText("-0 " + getString(R.string.hours_caption));
        tvZeroLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, gridLabelRenderer.getTextSize());
        tvZeroLabel.setTextColor(gridLabelRenderer.getVerticalLabelsColor());
        tvZeroLabel.setVisibility(View.VISIBLE);
        gridLabelRenderer.setPadding(gridLabelRenderer.getPadding() + 2); //make plot a bit smaller
    }
}

From source file:yjbo.yy.ynewsrecycle.mainutil.PSFirst.java

private void unSelect(View tab) {
    if (tab != null) {
        TextView tab_title = (TextView) tab.findViewById(R.id.psts_tab_title);
        if (tab_title != null) {
            tab_title.setSelected(false);
            //LogUtils.i("--select----");
            //                setTextColor(mTabTextColor);
            tab_title.setTextColor(Color.parseColor("#666666"));
            tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabTextSize);
            //                TextPaint tp = tab_title.getPaint();
            //                tp.setFakeBoldText(false);
        }/*from  www . jav a  2s  .co  m*/
        if (isCustomTabs)
            ((CustomTabProvider) mPager.getAdapter()).tabUnselected(tab);
    }
}

From source file:yjbo.yy.ynewsrecycle.mainutil.PSFirst.java

private void select(View tab) {
    if (tab != null) {
        TextView tab_title = (TextView) tab.findViewById(R.id.psts_tab_title);
        if (tab_title != null) {
            tab_title.setSelected(true);
            // LogUtils.i("--select----");
            tab_title.setTextColor(Color.parseColor("#29b4ed"));
            tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabTextSize);
            //                TextPaint tp = tab_title.getPaint();
            //                tp.setFakeBoldText(true);
        }/*www  .j ava  2s. com*/
        if (isCustomTabs)
            ((CustomTabProvider) mPager.getAdapter()).tabSelected(tab);
    }
}

From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java

/**
 * Automatically computes and sets the text size.
 *
 * @hide/*w  w  w.ja va  2s.co  m*/
 */
@RestrictTo(LIBRARY_GROUP)
void autoSizeText() {
    if (!isAutoSizeEnabled()) {
        return;
    }

    if (mNeedsAutoSizeText) {
        if (mTextView.getMeasuredHeight() <= 0 || mTextView.getMeasuredWidth() <= 0) {
            return;
        }

        final boolean horizontallyScrolling = invokeAndReturnWithDefault(mTextView, "getHorizontallyScrolling",
                false);
        final int availableWidth = horizontallyScrolling ? VERY_WIDE
                : mTextView.getMeasuredWidth() - mTextView.getTotalPaddingLeft()
                        - mTextView.getTotalPaddingRight();
        final int availableHeight = mTextView.getHeight() - mTextView.getCompoundPaddingBottom()
                - mTextView.getCompoundPaddingTop();

        if (availableWidth <= 0 || availableHeight <= 0) {
            return;
        }

        synchronized (TEMP_RECTF) {
            TEMP_RECTF.setEmpty();
            TEMP_RECTF.right = availableWidth;
            TEMP_RECTF.bottom = availableHeight;
            final float optimalTextSize = findLargestTextSizeWhichFits(TEMP_RECTF);
            if (optimalTextSize != mTextView.getTextSize()) {
                setTextSizeInternal(TypedValue.COMPLEX_UNIT_PX, optimalTextSize);
            }
        }
    }
    // Always try to auto-size if enabled. Functions that do not want to trigger auto-sizing
    // after the next layout pass should set this to false.
    mNeedsAutoSizeText = true;
}

From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    TextView txt = (TextView) convertView;
    if (txt == null) {
        txt = new TextView(getApplication());
        txt.setPadding(UI._8dp, UI._4dp, UI._8dp, UI._4dp);
        txt.setTypeface(UI.defaultTypeface);
        txt.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        txt.setTextColor(defaultTextColors);
    }/*  ww  w .j a  v  a  2s . c om*/
    txt.setText(getGenreString(position));
    return txt;
}

From source file:com.waz.zclient.pages.main.participants.ParticipantHeaderFragment.java

@Override
public void onConnectUserUpdated(final User user, IConnectStore.UserRequester usertype) {
    if (usertype != userRequester) {
        return;//from ww w  .j a  va  2  s. co  m
    }
    headerReadOnlyTextView.setText(user.getName());

    // TODO: https://wearezeta.atlassian.net/browse/AN-4278
    //        textViewAddressBookNameContainer.setVisibility(View.VISIBLE);
    //        textViewAddressBookName.setText("Marc Prengemann");

    subHeader.setText(user.getEmail());
    subHeader.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            getResources().getDimension(R.dimen.participants__subheader__font_size__one_to_one));
    if (!TextUtils.isEmpty(user.getEmail())) {
        subHeader.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final Uri uri = Uri.parse(String.format("mailto:%s", user.getEmail()));
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
            }
        });
    } else {
        subHeader.setOnClickListener(null);
    }
    headerEditText.setVisibility(View.GONE);

    new Handler().post(new Runnable() {
        @Override
        public void run() {
            if (getView() != null && getControllerFactory().getConversationScreenController() != null) {
                final int height = getView().getMeasuredHeight();
                getControllerFactory().getConversationScreenController().setParticipantHeaderHeight(height);
            }
        }
    });
}

From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    TextView txt = (TextView) convertView;
    if (txt == null) {
        txt = new TextView(getApplication());
        txt.setPadding(UI._DLGdppad, UI._DLGsppad, UI._DLGdppad, UI._DLGsppad);
        txt.setTypeface(UI.defaultTypeface);
        txt.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        txt.setTextColor(defaultTextColors);
    }//from   w  w w. j  a v  a2  s  .c  om
    txt.setText(getGenreString(position));
    return txt;
}

From source file:com.phonegap.bossbolo.plugin.inappbrowser.InAppBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject/*from  w  w  w.j a  v a  2  s  .c o  m*/
 * @param header
 */
public String showWebPage(final String url, HashMap<String, Boolean> features, final String header) {
    // Determine if we should hide the location bar.
    showLocationBar = true;
    showZoomControls = true;
    openWindowHidden = false;
    if (features != null) {
        Boolean show = features.get(LOCATION);
        if (show != null) {
            showLocationBar = show.booleanValue();
        }
        Boolean zoom = features.get(ZOOM);
        if (zoom != null) {
            showZoomControls = zoom.booleanValue();
        }
        Boolean hidden = features.get(HIDDEN);
        if (hidden != null) {
            openWindowHidden = hidden.booleanValue();
        }
        Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
        if (hardwareBack != null) {
            hadwareBackButton = hardwareBack.booleanValue();
        }
        Boolean cache = features.get(CLEAR_ALL_CACHE);
        if (cache != null) {
            clearAllCache = cache.booleanValue();
        } else {
            cache = features.get(CLEAR_SESSION_CACHE);
            if (cache != null) {
                clearSessionCache = cache.booleanValue();
            }
        }
    }

    final CordovaWebView thatWebView = this.webView;

    // 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;
        }

        @SuppressLint("NewApi")
        public void run() {
            int backgroundColor = Color.parseColor("#46bff7");
            // Let's create the main dialog
            dialog = new InAppBrowserDialog(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.setInAppBroswer(getInAppBrowser());

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

            // Toolbar layout  header
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            //Please, no more black! 
            toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(50)));
            toolbar.setPadding(this.dpToPixels(8), this.dpToPixels(10), this.dpToPixels(8),
                    this.dpToPixels(10));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);
            toolbar.setBackgroundColor(backgroundColor);

            // 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
            Button back = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            back.setWidth(this.dpToPixels(34));
            back.setHeight(this.dpToPixels(31));
            Resources activityRes = cordova.getActivity().getResources();
            int backResId = activityRes.getIdentifier("back", "drawable",
                    cordova.getActivity().getPackageName());
            Drawable backIcon = activityRes.getDrawable(backResId);
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                back.setBackgroundDrawable(backIcon);
            } else {
                back.setBackground(backIcon);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                    //                        goBack();
                }
            });

            // Edit Text Box
            titletext = new TextView(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, this.dpToPixels(65));
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, this.dpToPixels(10));
            titletext.setLayoutParams(textLayoutParams);
            titletext.setId(3);
            titletext.setSingleLine(true);
            titletext.setText(header);
            titletext.setTextColor(Color.WHITE);
            titletext.setGravity(Gravity.CENTER);
            titletext.setTextSize(TypedValue.COMPLEX_UNIT_PX, this.dpToPixels(20));
            titletext.setSingleLine();
            titletext.setEllipsize(TruncateAt.END);

            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            editLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            editLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setVisibility(View.GONE);

            // Forward button
            /*Button forward = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
            Drawable fwdIcon = activityRes.getDrawable(fwdResId);
            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            {
            forward.setBackgroundDrawable(fwdIcon);
            }
            else
            {
            forward.setBackground(fwdIcon);
            }
            forward.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                goForward();
            }
            });
                    
            // Edit Text Box
            edittext = new TextView(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.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/Done button
            Button close = new Button(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
            Drawable closeIcon = activityRes.getDrawable(closeResId);
            if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
            {
            close.setBackgroundDrawable(closeIcon);
            }
            else
            {
            close.setBackground(closeIcon);
            }
            close.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                closeDialog();
            }
            });*/

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(getShowZoomControls());
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

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

            if (clearAllCache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (clearSessionCache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.setId(6);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.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(titletext);
            //                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(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 (openWindowHidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:net.toload.main.hd.candidate.CandidateView.java

/**
 * Jeremy '12,6,2 separated from doupdateComposing
 *///from   w w w .j a  va  2  s .c  o  m

public void doSetComposing(String composingText) {
    if (DEBUG)
        Log.i(TAG,
                "doSetComposing():" + composingText + "; this.isShown()" + this.isShown()
                        + "(mComposingTextView == null):" + (mComposingTextView == null)
                        + ";(embeddedComposing == null):" + (embeddedComposing != null));

    // Initialize mComposingTextView as embedding composing or popup window for fixed candidate mode. Jeremy '15,6,4

    if (embeddedComposing != null) {
        if (mComposingTextView != embeddedComposing) {
            mComposingTextView = embeddedComposing;
            mComposingTextView.setBackgroundColor(mColorComposingBackground);
            mComposingTextView.setTextColor(mColorComposingText);
        }

    } else {
        if (mComposingPopupTextView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mComposingPopupTextView = (TextView) inflater.inflate(R.layout.composingtext,
                    (ViewGroup) getRootView(), false);

            if (mComposingTextPopup == null) {
                mComposingTextPopup = new PopupWindow(mContext);
                mComposingTextPopup.setTouchable(false);
            }
            //mComposingTextPopup.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);  //Deprecated in API 23. Jeremy '16,7,16
            mComposingTextPopup.setWidth(LayoutParams.WRAP_CONTENT);
            mComposingTextPopup.setHeight(LayoutParams.WRAP_CONTENT);
            mComposingTextPopup.setContentView(mComposingPopupTextView);
            mComposingTextPopup.setBackgroundDrawable(null);
        }
        if (mComposingTextView != mComposingPopupTextView) {
            mComposingTextView = mComposingPopupTextView;
            mComposingTextView.setBackgroundColor(mColorComposingBackground);
            mComposingTextView.setTextColor(mColorComposingText);

        }
    }

    if (composingText != null) {
        mComposingTextView.setText(composingText);
        //The textsize got is coverted into PX already. Thus force setup the setTextSize in unit of PX.
        float scaledTextSize = mContext.getResources().getDimensionPixelSize(R.dimen.composing_text_size)
                * mLIMEPref.getFontSize();
        mComposingTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, scaledTextSize);

    } else
        return;

    mComposingTextView.invalidate(); //Jeremy '12,6,2 invalidate and measure so as to get correct height and width later. 
    mComposingTextView.setVisibility(VISIBLE);

    //Jeremy '15,6, 4 bypass updating popup when composing view is embedded in candidate container

    if (embeddedComposing == null)
        doUpdateComposing();

}

From source file:com.nbplus.vbroadlauncher.fragment.LauncherFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_launcher, container, false);

    mMainViewLayout = (LinearLayout) v.findViewById(R.id.main_view_layout);

    // push agent ??.
    mPushServiceStatus = (ImageView) v.findViewById(R.id.ic_nav_wifi);
    if (((BaseActivity) getActivity()).isPushServiceConnected()) {
        mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_on);
    } else {//from w  w  w .j  av a  2 s. c  o m
        mPushServiceStatus.setImageResource(R.drawable.ic_nav_wifi_off);
    }

    mVillageName = (TextView) v.findViewById(R.id.launcher_village_name);
    mVillageName.setText(LauncherSettings.getInstance(getActivity()).getVillageName());

    mApplicationsView = (LinearLayout) v.findViewById(R.id.ic_nav_apps);
    mApplicationsView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getActivity(), ShowApplicationActivity.class);
            startActivity(intent);
            getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
        }
    });
    mServiceTreeMap = (LinearLayout) v.findViewById(R.id.ic_nav_show_map);
    mServiceTreeMap.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!NetworkUtils.isConnected(getActivity())) {
                ((BaseActivity) getActivity()).showNetworkConnectionAlertDialog();
                return;
            }
            Intent intent = new Intent(getActivity(), BroadcastWebViewActivity.class);

            ShortcutData data = new ShortcutData(Constants.SHORTCUT_TYPE_WEB_DOCUMENT_SERVER,
                    R.string.btn_show_map, getActivity().getResources().getString(R.string.addr_show_map),
                    R.drawable.ic_menu_04, R.drawable.ic_menu_shortcut_02_selector, 0, null);

            VBroadcastServer serverInfo = LauncherSettings.getInstance(getActivity()).getServerInformation();
            data.setDomain(serverInfo.getDocServer());

            intent.putExtra(Constants.EXTRA_NAME_SHORTCUT_DATA, data);
            startActivity(intent);
        }
    });
    mOutdoorMode = (LinearLayout) v.findViewById(R.id.ic_nav_outdoor);
    mOutdoorText = (TextView) v.findViewById(R.id.tv_outdoor);
    if (LauncherSettings.getInstance(getActivity()).isOutdoorMode()) {
        mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_on));
        mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_on, 0, 0, 0);
    } else {
        mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_off));
        mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_off, 0, 0, 0);
    }
    mOutdoorMode.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast toast;

            boolean mode = false;
            if (LauncherSettings.getInstance(getActivity()).isOutdoorMode()) {
                LauncherSettings.getInstance(getActivity()).setIsOutdoorMode(false);
                mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_off, 0, 0, 0);
                mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_off));

                toast = Toast.makeText(getActivity(), R.string.outdoor_mode_off, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                toast.show();
            } else {
                mode = true;
                LauncherSettings.getInstance(getActivity()).setIsOutdoorMode(true);
                mOutdoorText.setTextColor(getResources().getColor(R.color.btn_color_absentia_on));
                mOutdoorText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_nav_absentia_on, 0, 0, 0);

                toast = Toast.makeText(getActivity(), R.string.outdoor_mode_on, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                toast.show();
            }

            HomeLauncherApplication application = (HomeLauncherApplication) getActivity()
                    .getApplicationContext();
            if (application != null) {
                application.outdoorModeChanged(mode);
            }
        }
    });
    // ?? ?
    mIoTDataSync = (LinearLayout) v.findViewById(R.id.ic_iot_data_sync);
    mIoTDataSyncText = (TextView) v.findViewById(R.id.tv_iot_data_sync);
    mIoTDataSync.setOnClickListener(mIoTSyncClickListener);
    mIoTDataSync.setClickable(true);
    mIoTDataSync.setEnabled(true);

    mTextClock = (TextClock) v.findViewById(R.id.text_clock);
    if (mTextClock != null) {
        mTextClock.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_APP_CALENDAR);
                    startActivity(intent);
                    getActivity().overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
                } catch (ActivityNotFoundException e) {
                    e.printStackTrace();
                    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
                    alert.setPositiveButton(R.string.alert_ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent i = new Intent(
                                    android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
                            i.addCategory(Intent.CATEGORY_DEFAULT);
                            startActivity(i);
                        }
                    });
                    alert.setMessage(R.string.alert_calendar_not_found);
                    alert.show();
                }
            }
        });
    }
    mWeatherView = (WeatherView) v.findViewById(R.id.weather_view);
    mMainViewLeftPanel = (LinearLayout) v.findViewById(R.id.main_view_left_panel);
    mMainViewRightPanel = (LinearLayout) v.findViewById(R.id.main_view_right_panel);

    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // add main shortcut.
    ArrayList<ShortcutData> mainShortcutDatas = LauncherSettings.getInstance(getActivity())
            .getLauncherMainShortcuts();
    mMainShortcutGridLayout = (GridLayout) v.findViewById(R.id.main_shortcut_grid);
    float dp;// = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_main_shortcut_width);
    //        float widthPx = DisplayUtils.pxFromDp(getActivity(), dp);
    //
    //        dp = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_main_shortcut_height);
    //        float heightPx = DisplayUtils.pxFromDp(getActivity(), dp);

    dp = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_main_shortcut_font_size);
    float mainShortcutFontPx = DisplayUtils.pxFromDp(getActivity(), dp);
    for (int i = 0; i < mMainShortcutGridLayout.getColumnCount(); i++) {
        /**
         * right shortcut panel
         */
        ShortcutData data = mainShortcutDatas.get(i);
        FrameLayout btnLayout = (FrameLayout) layoutInflater.inflate(R.layout.launcher_menu_top_item,
                mMainShortcutGridLayout, false);//new Button(getActivity());
        mMainShortcutGridLayout.addView(btnLayout);
        if (data.getPushType() != null && data.getPushType().length > 0) {
            data.setLauncherButton(btnLayout);
            mPushNotifiableShorcuts.add(data);
        }

        btnLayout.setBackgroundResource(data.getIconBackResId());

        //            GridLayout.LayoutParams lp = (GridLayout.LayoutParams)btnLayout.getLayoutParams();
        //            lp.width = (int)widthPx;
        //            lp.height = (int)heightPx;
        //            btnLayout.setLayoutParams(lp);

        TextView label = (TextView) btnLayout.findViewById(R.id.menu_item_label);
        label.setText(data.getName());
        label.setTextSize(TypedValue.COMPLEX_UNIT_PX, mainShortcutFontPx);
        label.setTextColor(getResources().getColor(R.color.white));
        label.setTypeface(null, Typeface.BOLD);
        label.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

        ImageView icon = (ImageView) btnLayout.findViewById(R.id.menu_item_image);
        icon.setImageResource(data.getIconResId());

        btnLayout.setTag(data);
        btnLayout.setOnClickListener(this);
    }

    // add other shortcuts.
    mShorcutGridLayout = (GridLayout) v.findViewById(R.id.shortcut_grid);
    ArrayList<ShortcutData> shortcutDatas = LauncherSettings.getInstance(getActivity()).getLauncherShortcuts();
    int columnNum = mShorcutGridLayout.getColumnCount();
    final int MAX_ROW_NUM = 3;

    int shortcutNum = shortcutDatas.size() > (columnNum * MAX_ROW_NUM) ? (columnNum * MAX_ROW_NUM)
            : shortcutDatas.size();
    dp = DisplayUtils.getDimension(getActivity(), R.dimen.launcher_ic_menu_shortcut_font_size);
    float btnFontPx = DisplayUtils.pxFromDp(getActivity(), dp);

    for (int i = 0; i < shortcutNum; i++) {
        /**
         * right shortcut panel
         */
        ShortcutData data = shortcutDatas.get(i);
        FrameLayout btnLayout = (FrameLayout) layoutInflater.inflate(R.layout.launcher_menu_item,
                mShorcutGridLayout, false);//new Button(getActivity());
        mShorcutGridLayout.addView(btnLayout);
        if (data.getPushType() != null && data.getPushType().length > 0) {
            data.setLauncherButton(btnLayout);
            mPushNotifiableShorcuts.add(data);
        }

        btnLayout.setBackgroundResource(data.getIconBackResId());

        TextView label = (TextView) btnLayout.findViewById(R.id.menu_item_label);
        label.setText(data.getName());
        label.setTextSize(TypedValue.COMPLEX_UNIT_PX, btnFontPx);
        label.setTextColor(getResources().getColor(R.color.white));
        label.setTypeface(null, Typeface.BOLD);
        label.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

        ImageView icon = (ImageView) btnLayout.findViewById(R.id.menu_item_image);
        icon.setImageResource(data.getIconResId());

        btnLayout.setTag(data);
        btnLayout.setOnClickListener(this);
    }

    setContentViewByOrientation();

    return v;
}