Example usage for android.widget FrameLayout getMeasuredWidth

List of usage examples for android.widget FrameLayout getMeasuredWidth

Introduction

In this page you can find the example usage for android.widget FrameLayout getMeasuredWidth.

Prototype

public final int getMeasuredWidth() 

Source Link

Document

Like #getMeasuredWidthAndState() , but only returns the raw width component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:de.cachebox_test.splash.java

private void startInitial() {

    // show wait dialog if not running
    if (pWaitD == null)
        showPleaseWaitDialog();//from ww  w.j ava 2s  .co m

    // saved workPath found -> use this
    Thread thread = new Thread() {

        @Override
        public void run() {
            // wait for measure layout

            final FrameLayout frame = (FrameLayout) findViewById(R.id.frameLayout1);
            width = frame.getMeasuredWidth();
            height = frame.getMeasuredHeight();

            while (width == 0 || height == 0) {
                splash.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        frame.forceLayout();
                    }
                });
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
                width = frame.getMeasuredWidth();
                height = frame.getMeasuredHeight();
            }

            // lolipop ask write permission
            if (android.os.Build.VERSION.SDK_INT > 20) {
                Initial(width, height);

                // Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
                // startActivityForResult(intent, 42);
            } else {
                Initial(width, height);
            }

        }
    };

    thread.start();

}

From source file:com.example.guxiuzhong.pagerslidingtab_lib.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        FrameLayout frameLayout = (FrameLayout) tabsContainer.getChildAt(i);
        frameLayout.setBackgroundResource(tabBackgroundResId);

        for (int j = 0; j < frameLayout.getChildCount(); j++) {
            View v = frameLayout.getChildAt(j);
            if (v instanceof TextView) {
                TextView tab = (TextView) v;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
                tab.setTypeface(tabTypeface, tabTypefaceStyle);
                if (j == 0) {
                    tab.setTextColor(tabTextColor);
                } else {
                    tab.setTextColor(selectedTabTextColor);
                }//  w  w  w  . j  a  v  a  2s . c o m
                ViewHelper.setAlpha(tabViews.get(i).get("normal"), 1);
                ViewHelper.setAlpha(tabViews.get(i).get("selected"), 0);

                //set normal  Scale
                ViewHelper.setPivotX(frameLayout, frameLayout.getMeasuredWidth() * 0.5f);
                ViewHelper.setPivotY(frameLayout, frameLayout.getMeasuredHeight() * 0.5f);
                ViewHelper.setScaleX(frameLayout, 1f);
                ViewHelper.setScaleY(frameLayout, 1f);

                // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
                // pre-ICS-build
                if (textAllCaps) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        tab.setAllCaps(true);
                    } else {
                        tab.setText(tab.getText().toString().toUpperCase(locale));
                    }
                }
                if (i == selectedPosition) {
                    ViewHelper.setAlpha(tabViews.get(i).get("normal"), 0);
                    ViewHelper.setAlpha(tabViews.get(i).get("selected"), 1);

                    //set select  Scale
                    ViewHelper.setPivotX(frameLayout, frameLayout.getMeasuredWidth() * 0.5f);
                    ViewHelper.setPivotY(frameLayout, frameLayout.getMeasuredHeight() * 0.5f);
                    ViewHelper.setScaleX(frameLayout, 1 + zoomMax);
                    ViewHelper.setScaleY(frameLayout, 1 + zoomMax);
                }
            }
        }
    }
}

From source file:de.cachebox_test.splash.java

@SuppressWarnings("deprecation")
@Override//from w  ww.  jav a 2  s .com
protected void onStart() {
    super.onStart();
    Log.debug(log, "onStart");

    if (android.os.Build.VERSION.SDK_INT >= 23) {
        PermissionCheck.checkNeededPermissions(this);
    }

    // initial GDX
    Gdx.files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());
    // first, try to find stored preferences of workPath
    androidSetting = this.getSharedPreferences(Global.PREFS_NAME, 0);

    workPath = androidSetting.getString("WorkPath", Environment.getDataDirectory() + "/cachebox");
    boolean askAgain = androidSetting.getBoolean("AskAgain", true);
    showSandbox = androidSetting.getBoolean("showSandbox", false);

    Global.initTheme(this);
    Global.InitIcons(this);

    CB_Android_FileExplorer fileExplorer = new CB_Android_FileExplorer(this);
    PlatformConnector.setGetFileListener(fileExplorer);
    PlatformConnector.setGetFolderListener(fileExplorer);

    String LangPath = androidSetting.getString("Sel_LanguagePath", "");
    if (LangPath.length() == 0) {
        // set default lang

        String locale = Locale.getDefault().getLanguage();
        if (locale.contains("de")) {
            LangPath = "data/lang/de/strings.ini";
        } else if (locale.contains("cs")) {
            LangPath = "data/lang/cs/strings.ini";
        } else if (locale.contains("cs")) {
            LangPath = "data/lang/cs/strings.ini";
        } else if (locale.contains("fr")) {
            LangPath = "data/lang/fr/strings.ini";
        } else if (locale.contains("nl")) {
            LangPath = "data/lang/nl/strings.ini";
        } else if (locale.contains("pl")) {
            LangPath = "data/lang/pl/strings.ini";
        } else if (locale.contains("pt")) {
            LangPath = "data/lang/pt/strings.ini";
        } else if (locale.contains("hu")) {
            LangPath = "data/lang/hu/strings.ini";
        } else {
            LangPath = "data/lang/en-GB/strings.ini";
        }
    }

    new Translation(workPath, FileType.Internal);
    try {
        Translation.LoadTranslation(LangPath);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // check Write permission
    if (!askAgain) {
        if (!FileIO.checkWritePermission(workPath)) {
            askAgain = true;
            if (!ToastEx) {
                ToastEx = true;
                String WriteProtectionMsg = Translation.Get("NoWriteAcces");
                Toast.makeText(splash.this, WriteProtectionMsg, Toast.LENGTH_LONG).show();
            }
        }
    }

    if ((askAgain)) {
        // no saved workPath found -> search sd-cards and if more than 1 is found give the user the possibility to select one

        String externalSd = getExternalSdPath("/CacheBox");

        boolean hasExtSd;
        final String externalSd2 = externalSd;

        if (externalSd != null) {
            hasExtSd = (externalSd.length() > 0) && (!externalSd.equalsIgnoreCase(workPath));
        } else {
            hasExtSd = false;
        }

        // externe SD wurde gefunden != internal
        // oder Tablet Layout mglich
        // -> Auswahldialog anzeigen
        try {
            final Dialog dialog = new Dialog(context) {
                @Override
                public boolean onKeyDown(int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK) {
                        splash.this.finish();
                    }
                    return super.onKeyDown(keyCode, event);
                }
            };

            dialog.setContentView(R.layout.sdselectdialog);
            TextView title = (TextView) dialog.findViewById(R.id.select_sd_title);
            title.setText(Translation.Get("selectWorkSpace") + "\n\n");
            /*
             * TextView tbLayout = (TextView) dialog.findViewById(R.id.select_sd_layout); tbLayout.setText("\nLayout"); final RadioGroup
             * rgLayout = (RadioGroup) dialog.findViewById(R.id.select_sd_radiogroup); final RadioButton rbHandyLayout = (RadioButton)
             * dialog.findViewById(R.id.select_sd_handylayout); final RadioButton rbTabletLayout = (RadioButton)
             * dialog.findViewById(R.id.select_sd_tabletlayout); rbHandyLayout.setText("Handy-Layout");
             * rbTabletLayout.setText("Tablet-Layout"); if (!GlobalCore.posibleTabletLayout) {
             * rgLayout.setVisibility(RadioGroup.INVISIBLE); rbHandyLayout.setChecked(true); } else { if (GlobalCore.isTab) {
             * rbTabletLayout.setChecked(true); } else { rbHandyLayout.setChecked(true); } }
             */
            final CheckBox cbAskAgain = (CheckBox) dialog.findViewById(R.id.select_sd_askagain);
            cbAskAgain.setText(Translation.Get("AskAgain"));
            cbAskAgain.setChecked(askAgain);
            Button buttonI = (Button) dialog.findViewById(R.id.button1);
            buttonI.setText("Internal SD\n\n" + workPath);
            buttonI.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // close select dialog
                    dialog.dismiss();

                    // show please wait dialog
                    showPleaseWaitDialog();

                    // use internal SD -> nothing to change
                    Thread thread = new Thread() {
                        @Override
                        public void run() {
                            boolean askAgain = cbAskAgain.isChecked();
                            // boolean useTabletLayout = rbTabletLayout.isChecked();
                            saveWorkPath(askAgain/* , useTabletLayout */);
                            dialog.dismiss();
                            startInitial();
                        }
                    };
                    thread.start();
                }
            });
            Button buttonE = (Button) dialog.findViewById(R.id.button2);
            final boolean isSandbox = externalSd == null ? false
                    : externalSd.contains("Android/data/de.cachebox_test");
            if (!hasExtSd) {
                buttonE.setVisibility(Button.INVISIBLE);
            } else {
                String extSdText = isSandbox ? "External SD SandBox\n\n" : "External SD\n\n";
                buttonE.setText(extSdText + externalSd);
            }

            buttonE.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // show KitKat Massage?

                    if (isSandbox && !showSandbox) {
                        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

                        // set title
                        alertDialogBuilder.setTitle("KitKat Sandbox");

                        // set dialog message
                        alertDialogBuilder.setMessage(Translation.Get("Desc_Sandbox")).setCancelable(false)
                                .setPositiveButton(Translation.Get("yes"),
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int id) {
                                                // if this button is clicked, run Sandbox Path

                                                showSandbox = true;
                                                Config.AcceptChanges();

                                                // close select dialog
                                                dialog.dismiss();

                                                // show please wait dialog
                                                showPleaseWaitDialog();

                                                // use external SD -> change workPath
                                                Thread thread = new Thread() {
                                                    @Override
                                                    public void run() {
                                                        workPath = externalSd2;
                                                        boolean askAgain = cbAskAgain.isChecked();
                                                        // boolean useTabletLayout = rbTabletLayout.isChecked();
                                                        saveWorkPath(askAgain/* , useTabletLayout */);
                                                        startInitial();
                                                    }
                                                };
                                                thread.start();
                                            }
                                        })
                                .setNegativeButton(Translation.Get("no"),
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int id) {
                                                // if this button is clicked, just close
                                                // the dialog box and do nothing
                                                dialog.cancel();
                                            }
                                        });

                        // create alert dialog
                        AlertDialog alertDialog = alertDialogBuilder.create();

                        // show it
                        alertDialog.show();
                    } else {
                        // close select dialog
                        dialog.dismiss();

                        // show please wait dialog
                        showPleaseWaitDialog();

                        // use external SD -> change workPath
                        Thread thread = new Thread() {
                            @Override
                            public void run() {
                                workPath = externalSd2;
                                boolean askAgain = cbAskAgain.isChecked();
                                // boolean useTabletLayout = rbTabletLayout.isChecked();
                                saveWorkPath(askAgain/* , useTabletLayout */);
                                startInitial();
                            }
                        };
                        thread.start();
                    }
                }
            });

            LinearLayout ll = (LinearLayout) dialog.findViewById(R.id.scrollViewLinearLayout);

            // add all Buttons for created Workspaces

            AdditionalWorkPathArray = getAdditionalWorkPathArray();

            for (final String AddWorkPath : AdditionalWorkPathArray) {

                final String Name = FileIO.GetFileNameWithoutExtension(AddWorkPath);

                if (!FileIO.checkWritePermission(AddWorkPath)) {
                    // delete this Work Path
                    deleteWorkPath(AddWorkPath);
                    continue;
                }

                Button buttonW = new Button(context);
                buttonW.setText(Name + "\n\n" + AddWorkPath);

                buttonW.setOnLongClickListener(new OnLongClickListener() {

                    @Override
                    public boolean onLongClick(View v) {

                        // setting the MassageBox then the UI_sizes are not initial in this moment
                        Resources res = splash.this.getResources();
                        float scale = res.getDisplayMetrics().density;
                        float calcBase = 533.333f * scale;

                        FrameLayout frame = (FrameLayout) findViewById(R.id.frameLayout1);
                        int width = frame.getMeasuredWidth();
                        int height = frame.getMeasuredHeight();

                        MessageBox.Builder.WindowWidth = width;
                        MessageBox.Builder.WindowHeight = height;
                        MessageBox.Builder.textSize = (calcBase
                                / res.getDimensionPixelSize(R.dimen.BtnTextSize)) * scale;
                        MessageBox.Builder.ButtonHeight = (int) (50 * scale);

                        // Ask before delete
                        msg = (MessageBox) MessageBox.Show(Translation.Get("shuredeleteWorkspace", Name),
                                Translation.Get("deleteWorkspace"), MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question, new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (which == MessageBox.BUTTON_POSITIVE) {
                                            // Delete this Workpath only from Settings don't delete any File
                                            deleteWorkPath(AddWorkPath);
                                        }
                                        // Start again to exclude the old Folder
                                        msg.dismiss();
                                        onStart();
                                    }

                                });

                        dialog.dismiss();
                        return true;
                    }
                });

                buttonW.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // close select dialog
                        dialog.dismiss();

                        // show please wait dialog
                        showPleaseWaitDialog();

                        // use external SD -> change workPath
                        Thread thread = new Thread() {
                            @Override
                            public void run() {
                                workPath = AddWorkPath;
                                boolean askAgain = cbAskAgain.isChecked();
                                // boolean useTabletLayout = rbTabletLayout.isChecked();
                                saveWorkPath(askAgain/* , useTabletLayout */);
                                startInitial();
                            }
                        };
                        thread.start();

                    }
                });

                ll.addView(buttonW);
            }

            Button buttonC = (Button) dialog.findViewById(R.id.buttonCreateWorkspace);
            buttonC.setText(Translation.Get("createWorkSpace"));
            buttonC.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // close select dialog
                    dialog.dismiss();
                    getFolderReturnListener = new IgetFolderReturnListener() {

                        @Override
                        public void getFolderReturn(String Path) {
                            if (FileIO.checkWritePermission(Path)) {

                                AdditionalWorkPathArray.add(Path);
                                writeAdditionalWorkPathArray(AdditionalWorkPathArray);
                                // Start again to include the new Folder
                                onStart();
                            } else {
                                String WriteProtectionMsg = Translation.Get("NoWriteAcces");
                                Toast.makeText(splash.this, WriteProtectionMsg, Toast.LENGTH_LONG).show();
                            }
                        }
                    };

                    PlatformConnector.getFolder("", Translation.Get("select_folder"), Translation.Get("select"),
                            getFolderReturnListener);

                }
            });

            dialog.show();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else {
        if (GlobalCore.displayType == DisplayType.Large || GlobalCore.displayType == DisplayType.xLarge)
            GlobalCore.isTab = isLandscape;

        // restore the saved workPath
        // test whether workPath is available by checking the free size on the SD
        String workPathToTest = workPath.substring(0, workPath.lastIndexOf("/"));
        long bytesAvailable = 0;
        try {
            StatFs stat = new StatFs(workPathToTest);
            bytesAvailable = (long) stat.getBlockSize() * (long) stat.getBlockCount();
        } catch (Exception ex) {
            bytesAvailable = 0;
        }
        if (bytesAvailable == 0) {
            // there is a workPath stored but this workPath is not available at the moment (maybe SD is removed)
            Toast.makeText(splashActivity,
                    "WorkPath " + workPath + " is not available!\nMaybe SD-Card is removed?", Toast.LENGTH_LONG)
                    .show();
            finish();
            return;
        }

        startInitial();
    }

}