Example usage for android.widget FrameLayout addView

List of usage examples for android.widget FrameLayout addView

Introduction

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

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.b44t.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    actionBar/*from  w w w . j  a  v a 2 s . c om*/
            .setBackButtonImage(screen == SCREEN0_SETTINGS ? R.drawable.ic_ab_back : R.drawable.ic_close_white);
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (screen != SCREEN0_SETTINGS) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (screen == SCREEN1_ENTER_CODE1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView
                        .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(
                        LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView
                    .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (screen == SCREEN1_ENTER_CODE1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    return true;
                }
                return false;
            }
        });
        passwordEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (passwordEditText.length() == 4) {
                    if (screen == SCREEN2_ENTER_CODE2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });

        passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });

        if (screen == SCREEN1_ENTER_CODE1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, 0);
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item,
                    LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item,
                    LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1));
                } else if (i == passcodeOnOffRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("Disabled", R.string.Disabled);
                            } else if (value == 1) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Minutes, 1, 1);
                            } else if (value == 2) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Minutes, 5, 5);
                            } else if (value == 3) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Hours, 1, 1);
                            } else if (value == 4) {
                                return ApplicationLoader.applicationContext.getResources()
                                        .getQuantityString(R.plurals.Hours, 5, 5);
                            }
                            return "";
                        }
                    });
                    numberPicker.setWrapSelectorWheel(false);
                    builder.setView(numberPicker);
                    builder.setNegativeButton(LocaleController.getString("Done", R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }

    return fragmentView;
}

From source file:kr.wdream.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    Log.d(LOG_TAG, "createView");
    if (type != 3) {
        actionBar.setBackButtonImage(kr.wdream.storyshop.R.drawable.ic_ab_back);
    }/*from  ww w.  ja  va 2  s . com*/
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (type != 0) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, kr.wdream.storyshop.R.drawable.ic_done, AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (type == 1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView.setText(LocaleController.getString("EnterNewPasscode",
                        kr.wdream.storyshop.R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(LocaleController.getString("EnterNewFirstPasscode",
                        kr.wdream.storyshop.R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView.setText(LocaleController.getString("EnterCurrentPasscode",
                    kr.wdream.storyshop.R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (type == 1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    return true;
                }
                return false;
            }
        });
        passwordEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (passwordEditText.length() == 4) {
                    if (type == 2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (type == 1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });

        passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });

        if (type == 1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, 0);
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item,
                    LocaleController.getString("PasscodePIN", kr.wdream.storyshop.R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item, LocaleController.getString("PasscodePassword",
                    kr.wdream.storyshop.R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0,
                    kr.wdream.storyshop.R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(LocaleController.getString("Passcode", kr.wdream.storyshop.R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(LocaleController.getString("Passcode", kr.wdream.storyshop.R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(1));
                } else if (i == passcodeRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(
                            LocaleController.getString("AutoLock", kr.wdream.storyshop.R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("AutoLockDisabled",
                                        kr.wdream.storyshop.R.string.AutoLockDisabled);
                            } else if (value == 1) {
                                return LocaleController.formatString("AutoLockInTime",
                                        kr.wdream.storyshop.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 1));
                            } else if (value == 2) {
                                return LocaleController.formatString("AutoLockInTime",
                                        kr.wdream.storyshop.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 5));
                            } else if (value == 3) {
                                return LocaleController.formatString("AutoLockInTime",
                                        kr.wdream.storyshop.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 1));
                            } else if (value == 4) {
                                return LocaleController.formatString("AutoLockInTime",
                                        kr.wdream.storyshop.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 5));
                            }
                            return "";
                        }
                    });
                    builder.setView(numberPicker);
                    builder.setNegativeButton(
                            LocaleController.getString("Done", kr.wdream.storyshop.R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }

    return fragmentView;
}

From source file:plugin.google.maps.GoogleMaps.java

@SuppressWarnings("unused")
private void showDialog(final JSONArray args, final CallbackContext callbackContext) {
    if (windowLayer != null) {
        return;/*from w  w w  .j a  va 2  s. c om*/
    }

    // window layout
    windowLayer = new LinearLayout(activity);
    windowLayer.setPadding(0, 0, 0, 0);
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    windowLayer.setLayoutParams(layoutParams);

    // dialog window layer
    FrameLayout dialogLayer = new FrameLayout(activity);
    dialogLayer.setLayoutParams(layoutParams);
    //dialogLayer.setPadding(15, 15, 15, 0);
    dialogLayer.setBackgroundColor(Color.LTGRAY);
    windowLayer.addView(dialogLayer);

    // map frame
    final FrameLayout mapFrame = new FrameLayout(activity);
    mapFrame.setPadding(0, 0, 0, (int) (40 * density));
    dialogLayer.addView(mapFrame);

    if (this.mPluginLayout != null && this.mPluginLayout.getMyView() != null) {
        this.mPluginLayout.detachMyView();
    }

    ViewGroup.LayoutParams lParams = (ViewGroup.LayoutParams) mapView.getLayoutParams();
    if (lParams == null) {
        lParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
    }
    lParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    lParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
    if (lParams instanceof AbsoluteLayout.LayoutParams) {
        AbsoluteLayout.LayoutParams params = (AbsoluteLayout.LayoutParams) lParams;
        params.x = 0;
        params.y = 0;
        mapView.setLayoutParams(params);
    } else if (lParams instanceof LinearLayout.LayoutParams) {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lParams;
        params.topMargin = 0;
        params.leftMargin = 0;
        mapView.setLayoutParams(params);
    } else if (lParams instanceof FrameLayout.LayoutParams) {
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lParams;
        params.topMargin = 0;
        params.leftMargin = 0;
        mapView.setLayoutParams(params);
    }
    mapFrame.addView(this.mapView);

    // button frame
    LinearLayout buttonFrame = new LinearLayout(activity);
    buttonFrame.setOrientation(LinearLayout.HORIZONTAL);
    buttonFrame.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    LinearLayout.LayoutParams buttonFrameParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    buttonFrame.setLayoutParams(buttonFrameParams);
    dialogLayer.addView(buttonFrame);

    //close button
    LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT, 1.0f);
    TextView closeLink = new TextView(activity);
    closeLink.setText("Close");
    closeLink.setLayoutParams(buttonParams);
    closeLink.setTextColor(Color.BLUE);
    closeLink.setTextSize(20);
    closeLink.setGravity(Gravity.LEFT);
    closeLink.setPadding((int) (10 * density), 0, 0, (int) (10 * density));
    closeLink.setOnClickListener(GoogleMaps.this);
    closeLink.setId(CLOSE_LINK_ID);
    buttonFrame.addView(closeLink);

    //license button
    TextView licenseLink = new TextView(activity);
    licenseLink.setText("Legal Notices");
    licenseLink.setTextColor(Color.BLUE);
    licenseLink.setLayoutParams(buttonParams);
    licenseLink.setTextSize(20);
    licenseLink.setGravity(Gravity.RIGHT);
    licenseLink.setPadding((int) (10 * density), (int) (20 * density), (int) (10 * density),
            (int) (10 * density));
    licenseLink.setOnClickListener(GoogleMaps.this);
    licenseLink.setId(LICENSE_LINK_ID);
    buttonFrame.addView(licenseLink);

    webView.setVisibility(View.GONE);
    root.addView(windowLayer);

    //Dummy view for the back-button event
    FrameLayout dummyLayout = new FrameLayout(activity);

    /*
    this.webView.showCustomView(dummyLayout, new WebChromeClient.CustomViewCallback() {
            
      @Override
      public void onCustomViewHidden() {
        mapFrame.removeView(mapView);
        if (mPluginLayout != null &&
    mapDivLayoutJSON != null) {
          mPluginLayout.attachMyView(mapView);
          mPluginLayout.updateViewPosition();
        }
        root.removeView(windowLayer);
        webView.setVisibility(View.VISIBLE);
        windowLayer = null;
                
                
        GoogleMaps.this.onMapEvent("map_close");
      }
    });
    */

    this.sendNoResult(callbackContext);
}

From source file:com.wellsandwhistles.android.redditsp.fragments.WebViewFragment.java

@SuppressLint("NewApi")
@Override/*from  ww w  .ja v  a2 s. c  om*/
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    mActivity = (AppCompatActivity) getActivity();

    CookieSyncManager.createInstance(mActivity);

    outer = (FrameLayout) inflater.inflate(R.layout.web_view_fragment, null);

    webView = (WebViewFixed) outer.findViewById(R.id.web_view_fragment_webviewfixed);
    final FrameLayout loadingViewFrame = (FrameLayout) outer
            .findViewById(R.id.web_view_fragment_loadingview_frame);

    /*handle download links show an alert box to load this outside the internal browser*/
    webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(final String url, String userAgent, String contentDisposition,
                String mimetype, long contentLength) {
            {
                new AlertDialog.Builder(mActivity).setTitle(R.string.download_link_title)
                        .setMessage(R.string.download_link_message)
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent i = new Intent(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(url));
                                getContext().startActivity(i);
                                mActivity.onBackPressed(); //get back from internal browser
                            }
                        }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                mActivity.onBackPressed(); //get back from internal browser
                            }
                        }).setIcon(android.R.drawable.ic_dialog_alert).show();
            }
        }
    });
    /*handle download links end*/

    progressView = new ProgressBar(mActivity, null, android.R.attr.progressBarStyleHorizontal);
    loadingViewFrame.addView(progressView);
    loadingViewFrame.setPadding(General.dpToPixels(mActivity, 10), 0, General.dpToPixels(mActivity, 10), 0);

    final WebSettings settings = webView.getSettings();

    settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(false);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDomStorageEnabled(true);
    settings.setDisplayZoomControls(false);

    // TODO handle long clicks

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, final int newProgress) {

            super.onProgressChanged(view, newProgress);

            General.UI_THREAD_HANDLER.post(new Runnable() {
                @Override
                public void run() {
                    progressView.setProgress(newProgress);
                    progressView.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);
                }
            });
        }
    });

    if (mUrl != null) {
        webView.loadUrl(mUrl);
    } else {
        webView.loadDataWithBaseURL("https://reddit.com/", html, "text/html; charset=UTF-8", null, null);
    }

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(final WebView view, final String url) {

            if (url == null)
                return false;

            if (url.startsWith("data:")) {
                // Prevent imgur bug where we're directed to some random data URI
                return true;
            }

            // Go back if loading same page to prevent redirect loops.
            if (goingBack && currentUrl != null && url.equals(currentUrl)) {

                General.quickToast(mActivity,
                        String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt),
                        Toast.LENGTH_SHORT);

                lastBackDepthAttempt--;

                if (webView.canGoBackOrForward(lastBackDepthAttempt)) {
                    webView.goBackOrForward(lastBackDepthAttempt);
                } else {
                    mActivity.finish();
                }
            } else {

                if (RedditURLParser.parse(Uri.parse(url)) != null) {
                    LinkHandler.onLinkClicked(mActivity, url, false);
                } else {
                    webView.loadUrl(url);
                    currentUrl = url;
                }
            }

            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

            if (mUrl != null && url != null) {

                final AppCompatActivity activity = mActivity;

                if (activity != null) {
                    activity.setTitle(url);
                }
            }
        }

        @Override
        public void onPageFinished(final WebView view, final String url) {
            super.onPageFinished(view, url);

            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {

                    General.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {

                            if (currentUrl == null || url == null)
                                return;

                            if (!url.equals(view.getUrl()))
                                return;

                            if (goingBack && url.equals(currentUrl)) {

                                General.quickToast(mActivity, String.format(Locale.US,
                                        "Handling redirect loop (level %d)", -lastBackDepthAttempt));

                                lastBackDepthAttempt--;

                                if (webView.canGoBackOrForward(lastBackDepthAttempt)) {
                                    webView.goBackOrForward(lastBackDepthAttempt);
                                } else {
                                    mActivity.finish();
                                }

                            } else {
                                goingBack = false;
                            }
                        }
                    });
                }
            }, 1000);
        }

        @Override
        public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
            super.doUpdateVisitedHistory(view, url, isReload);
        }
    });

    final FrameLayout outerFrame = new FrameLayout(mActivity);
    outerFrame.addView(outer);

    return outerFrame;
}

From source file:ir.besteveryeverapp.ui.PasscodeActivity.java

@Override
public View createView(Context context) {
    if (type != 3) {
        actionBar.setBackButtonImage(ir.besteveryeverapp.telegram.R.drawable.ic_ab_back);
    }//from w  w w .jav  a2s .  co m
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (passcodeSetStep == 0) {
                    processNext();
                } else if (passcodeSetStep == 1) {
                    processDone();
                }
            } else if (id == pin_item) {
                currentPasswordType = 0;
                updateDropDownTextView();
            } else if (id == password_item) {
                currentPasswordType = 1;
                updateDropDownTextView();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;

    if (type != 0) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.addItemWithWidth(done_button, ir.besteveryeverapp.telegram.R.drawable.ic_done,
                AndroidUtilities.dp(56));

        titleTextView = new TextView(context);
        titleTextView.setTextColor(0xff757575);
        if (type == 1) {
            if (UserConfig.passcodeHash.length() != 0) {
                titleTextView.setText(LocaleController.getString("EnterNewPasscode",
                        ir.besteveryeverapp.telegram.R.string.EnterNewPasscode));
            } else {
                titleTextView.setText(LocaleController.getString("EnterNewFirstPasscode",
                        ir.besteveryeverapp.telegram.R.string.EnterNewFirstPasscode));
            }
        } else {
            titleTextView.setText(LocaleController.getString("EnterCurrentPasscode",
                    ir.besteveryeverapp.telegram.R.string.EnterCurrentPasscode));
        }
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
        frameLayout.addView(titleTextView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.topMargin = AndroidUtilities.dp(38);
        titleTextView.setLayoutParams(layoutParams);

        passwordEditText = new EditText(context);
        passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        passwordEditText.setTextColor(0xff000000);
        passwordEditText.setMaxLines(1);
        passwordEditText.setLines(1);
        passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
        passwordEditText.setSingleLine(true);
        if (type == 1) {
            passcodeSetStep = 0;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        } else {
            passcodeSetStep = 1;
            passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordEditText.setTypeface(Typeface.DEFAULT);
        AndroidUtilities.clearCursorDrawable(passwordEditText);
        frameLayout.addView(passwordEditText);
        layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
        layoutParams.topMargin = AndroidUtilities.dp(90);
        layoutParams.height = AndroidUtilities.dp(36);
        layoutParams.leftMargin = AndroidUtilities.dp(40);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.rightMargin = AndroidUtilities.dp(40);
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        passwordEditText.setLayoutParams(layoutParams);
        passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (passcodeSetStep == 0) {
                    processNext();
                    return true;
                } else if (passcodeSetStep == 1) {
                    processDone();
                    return true;
                }
                return false;
            }
        });
        passwordEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (passwordEditText.length() == 4) {
                    if (type == 2 && UserConfig.passcodeType == 0) {
                        processDone();
                    } else if (type == 1 && currentPasswordType == 0) {
                        if (passcodeSetStep == 0) {
                            processNext();
                        } else if (passcodeSetStep == 1) {
                            processDone();
                        }
                    }
                }
            }
        });

        passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });

        if (type == 1) {
            dropDownContainer = new ActionBarMenuItem(context, menu, //R.drawable.bar_selector_f
                    SkinMan.barSelector(context));
            dropDownContainer.setSubMenuOpenSide(1);
            dropDownContainer.addSubItem(pin_item, LocaleController.getString("PasscodePIN",
                    ir.besteveryeverapp.telegram.R.string.PasscodePIN), 0);
            dropDownContainer.addSubItem(password_item, LocaleController.getString("PasscodePassword",
                    ir.besteveryeverapp.telegram.R.string.PasscodePassword), 0);
            actionBar.addView(dropDownContainer);
            layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
            layoutParams.height = LayoutHelper.MATCH_PARENT;
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.rightMargin = AndroidUtilities.dp(40);
            layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64)
                    : AndroidUtilities.dp(56);
            layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
            dropDownContainer.setLayoutParams(layoutParams);
            dropDownContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dropDownContainer.toggleSubMenu();
                }
            });

            dropDown = new TextView(context);
            dropDown.setGravity(Gravity.LEFT);
            dropDown.setSingleLine(true);
            dropDown.setLines(1);
            dropDown.setMaxLines(1);
            dropDown.setEllipsize(TextUtils.TruncateAt.END);
            dropDown.setTextColor(0xffffffff);
            dropDown.setTypeface(FontManager.instance().getTypeface());
            dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0,
                    ir.besteveryeverapp.telegram.R.drawable.ic_arrow_drop_down, 0);
            dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
            dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
            dropDownContainer.addView(dropDown);
            layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams();
            layoutParams.width = LayoutHelper.WRAP_CONTENT;
            layoutParams.height = LayoutHelper.WRAP_CONTENT;
            layoutParams.leftMargin = AndroidUtilities.dp(16);
            layoutParams.gravity = Gravity.CENTER_VERTICAL;
            layoutParams.bottomMargin = AndroidUtilities.dp(1);
            dropDown.setLayoutParams(layoutParams);
        } else {
            actionBar.setTitle(
                    LocaleController.getString("Passcode", ir.besteveryeverapp.telegram.R.string.Passcode));
        }

        updateDropDownTextView();
    } else {
        actionBar.setTitle(
                LocaleController.getString("Passcode", ir.besteveryeverapp.telegram.R.string.Passcode));
        frameLayout.setBackgroundColor(0xfff0f0f0);
        listView = new ListView(context);
        listView.setDivider(null);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == changePasscodeRow) {
                    presentFragment(new PasscodeActivity(1));
                } else if (i == passcodeRow) {
                    TextCheckCell cell = (TextCheckCell) view;
                    if (UserConfig.passcodeHash.length() != 0) {
                        UserConfig.passcodeHash = "";
                        UserConfig.appLocked = false;
                        UserConfig.saveConfig(false);
                        int count = listView.getChildCount();
                        for (int a = 0; a < count; a++) {
                            View child = listView.getChildAt(a);
                            if (child instanceof TextSettingsCell) {
                                TextSettingsCell textCell = (TextSettingsCell) child;
                                textCell.setTextColor(0xffc6c6c6);
                                break;
                            }
                        }
                        cell.setChecked(UserConfig.passcodeHash.length() != 0);
                        NotificationCenter.getInstance()
                                .postNotificationName(NotificationCenter.didSetPasscode);
                    } else {
                        presentFragment(new PasscodeActivity(1));
                    }
                } else if (i == autoLockRow) {
                    if (getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AutoLock",
                            ir.besteveryeverapp.telegram.R.string.AutoLock));
                    final NumberPicker numberPicker = new NumberPicker(getParentActivity());
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(4);
                    if (UserConfig.autoLockIn == 0) {
                        numberPicker.setValue(0);
                    } else if (UserConfig.autoLockIn == 60) {
                        numberPicker.setValue(1);
                    } else if (UserConfig.autoLockIn == 60 * 5) {
                        numberPicker.setValue(2);
                    } else if (UserConfig.autoLockIn == 60 * 60) {
                        numberPicker.setValue(3);
                    } else if (UserConfig.autoLockIn == 60 * 60 * 5) {
                        numberPicker.setValue(4);
                    }
                    numberPicker.setFormatter(new NumberPicker.Formatter() {
                        @Override
                        public String format(int value) {
                            if (value == 0) {
                                return LocaleController.getString("AutoLockDisabled",
                                        ir.besteveryeverapp.telegram.R.string.AutoLockDisabled);
                            } else if (value == 1) {
                                return LocaleController.formatString("AutoLockInTime",
                                        ir.besteveryeverapp.telegram.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 1));
                            } else if (value == 2) {
                                return LocaleController.formatString("AutoLockInTime",
                                        ir.besteveryeverapp.telegram.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Minutes", 5));
                            } else if (value == 3) {
                                return LocaleController.formatString("AutoLockInTime",
                                        ir.besteveryeverapp.telegram.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 1));
                            } else if (value == 4) {
                                return LocaleController.formatString("AutoLockInTime",
                                        ir.besteveryeverapp.telegram.R.string.AutoLockInTime,
                                        LocaleController.formatPluralString("Hours", 5));
                            }
                            return "";
                        }
                    });
                    builder.setView(numberPicker);
                    builder.setNegativeButton(
                            LocaleController.getString("Done", ir.besteveryeverapp.telegram.R.string.Done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    which = numberPicker.getValue();
                                    if (which == 0) {
                                        UserConfig.autoLockIn = 0;
                                    } else if (which == 1) {
                                        UserConfig.autoLockIn = 60;
                                    } else if (which == 2) {
                                        UserConfig.autoLockIn = 60 * 5;
                                    } else if (which == 3) {
                                        UserConfig.autoLockIn = 60 * 60;
                                    } else if (which == 4) {
                                        UserConfig.autoLockIn = 60 * 60 * 5;
                                    }
                                    listView.invalidateViews();
                                    UserConfig.saveConfig(false);
                                }
                            });
                    showDialog(builder.create());
                } else if (i == fingerprintRow) {
                    UserConfig.useFingerprint = !UserConfig.useFingerprint;
                    UserConfig.saveConfig(false);
                    ((TextCheckCell) view).setChecked(UserConfig.useFingerprint);
                }
            }
        });
    }
    NightModeUtil.dark(fragmentView);
    FontManager.instance().setTypefaceImmediate(fragmentView);
    return fragmentView;
}

From source file:org.schabi.newpipe.VideoItemDetailFragment.java

private void updateInfo(final StreamInfo info) {
    try {// w  w  w.  j  ava 2  s . c  om
        Context c = getContext();
        VideoInfoItemViewCreator videoItemViewCreator = new VideoInfoItemViewCreator(
                LayoutInflater.from(getActivity()));

        RelativeLayout textContentLayout = (RelativeLayout) activity.findViewById(R.id.detailTextContentLayout);
        final TextView videoTitleView = (TextView) activity.findViewById(R.id.detailVideoTitleView);
        TextView uploaderView = (TextView) activity.findViewById(R.id.detailUploaderView);
        TextView viewCountView = (TextView) activity.findViewById(R.id.detailViewCountView);
        TextView thumbsUpView = (TextView) activity.findViewById(R.id.detailThumbsUpCountView);
        TextView thumbsDownView = (TextView) activity.findViewById(R.id.detailThumbsDownCountView);
        TextView uploadDateView = (TextView) activity.findViewById(R.id.detailUploadDateView);
        TextView descriptionView = (TextView) activity.findViewById(R.id.detailDescriptionView);
        FrameLayout nextVideoFrame = (FrameLayout) activity.findViewById(R.id.detailNextVideoFrame);
        RelativeLayout nextVideoRootFrame = (RelativeLayout) activity
                .findViewById(R.id.detailNextVideoRootLayout);
        Button nextVideoButton = (Button) activity.findViewById(R.id.detailNextVideoButton);
        TextView similarTitle = (TextView) activity.findViewById(R.id.detailSimilarTitle);
        Button backgroundButton = (Button) activity
                .findViewById(R.id.detailVideoThumbnailWindowBackgroundButton);
        View topView = activity.findViewById(R.id.detailTopView);
        View nextVideoView = null;
        if (info.next_video != null) {
            nextVideoView = videoItemViewCreator.getViewFromVideoInfoItem(null, nextVideoFrame,
                    info.next_video);
        } else {
            activity.findViewById(R.id.detailNextVidButtonAndContentLayout).setVisibility(View.GONE);
            activity.findViewById(R.id.detailNextVideoTitle).setVisibility(View.GONE);
            activity.findViewById(R.id.detailNextVideoButton).setVisibility(View.GONE);
        }

        progressBar.setVisibility(View.GONE);
        if (nextVideoView != null) {
            nextVideoFrame.addView(nextVideoView);
        }

        initThumbnailViews(info, nextVideoFrame);

        textContentLayout.setVisibility(View.VISIBLE);
        if (android.os.Build.VERSION.SDK_INT < 18) {
            playVideoButton.setVisibility(View.VISIBLE);
        } else {
            ImageView playArrowView = (ImageView) activity.findViewById(R.id.playArrowView);
            playArrowView.setVisibility(View.VISIBLE);
        }

        if (!showNextVideoItem) {
            nextVideoRootFrame.setVisibility(View.GONE);
            similarTitle.setVisibility(View.GONE);
        }

        videoTitleView.setText(info.title);

        topView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
                    ImageView arrow = (ImageView) activity.findViewById(R.id.toggleDescriptionView);
                    View extra = activity.findViewById(R.id.detailExtraView);
                    if (extra.getVisibility() == View.VISIBLE) {
                        extra.setVisibility(View.GONE);
                        arrow.setImageResource(R.drawable.arrow_down);
                    } else {
                        extra.setVisibility(View.VISIBLE);
                        arrow.setImageResource(R.drawable.arrow_up);
                    }
                }
                return true;
            }
        });

        // Since newpipe is designed to work even if certain information is not available,
        // the UI has to react on missing information.
        videoTitleView.setText(info.title);
        if (!info.uploader.isEmpty()) {
            uploaderView.setText(info.uploader);
        } else {
            activity.findViewById(R.id.detailUploaderWrapView).setVisibility(View.GONE);
        }
        if (info.view_count >= 0) {
            viewCountView.setText(Localization.localizeViewCount(info.view_count, c));
        } else {
            viewCountView.setVisibility(View.GONE);
        }
        if (info.dislike_count >= 0) {
            thumbsDownView.setText(Localization.localizeNumber(info.dislike_count, c));
        } else {
            thumbsDownView.setVisibility(View.INVISIBLE);
            activity.findViewById(R.id.detailThumbsDownImgView).setVisibility(View.GONE);
        }
        if (info.like_count >= 0) {
            thumbsUpView.setText(Localization.localizeNumber(info.like_count, c));
        } else {
            thumbsUpView.setVisibility(View.GONE);
            activity.findViewById(R.id.detailThumbsUpImgView).setVisibility(View.GONE);
            thumbsDownView.setVisibility(View.GONE);
            activity.findViewById(R.id.detailThumbsDownImgView).setVisibility(View.GONE);
        }
        if (!info.upload_date.isEmpty()) {
            uploadDateView.setText(Localization.localizeDate(info.upload_date, c));
        } else {
            uploadDateView.setVisibility(View.GONE);
        }
        if (!info.description.isEmpty()) {
            descriptionView.setText(Html.fromHtml(info.description));
        } else {
            descriptionView.setVisibility(View.GONE);
        }

        descriptionView.setMovementMethod(LinkMovementMethod.getInstance());

        // parse streams
        Vector<VideoStream> streamsToUse = new Vector<>();
        for (VideoStream i : info.video_streams) {
            if (useStream(i, streamsToUse)) {
                streamsToUse.add(i);
            }
        }

        nextVideoButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent detailIntent = new Intent(getActivity(), VideoItemDetailActivity.class);
                /*detailIntent.putExtra(
                        VideoItemDetailFragment.ARG_ITEM_ID, currentVideoInfo.nextVideo.id); */
                detailIntent.putExtra(VideoItemDetailFragment.VIDEO_URL, info.next_video.webpage_url);
                detailIntent.putExtra(VideoItemDetailFragment.STREAMING_SERVICE, streamingServiceId);
                startActivity(detailIntent);
            }
        });
        textContentLayout.setVisibility(View.VISIBLE);

        if (info.related_videos != null && !info.related_videos.isEmpty()) {
            initSimilarVideos(info, videoItemViewCreator);
        } else {
            activity.findViewById(R.id.detailSimilarTitle).setVisibility(View.GONE);
            activity.findViewById(R.id.similarVideosView).setVisibility(View.GONE);
        }

        setupActionBarHandler(info);

        if (autoPlayEnabled) {
            playVideo(info);
        }

        if (android.os.Build.VERSION.SDK_INT < 18) {
            playVideoButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    playVideo(info);
                }
            });
        }

        backgroundButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                playVideo(info);
            }
        });

    } catch (java.lang.NullPointerException e) {
        Log.w(TAG, "updateInfo(): Fragment closed before thread ended work... or else");
        e.printStackTrace();
    }
}

From source file:org.quantumbadger.redreader.fragments.WebViewFragment.java

@SuppressLint("NewApi")
@Override//  w w w  .j  a va  2 s .  co m
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    mActivity = (AppCompatActivity) getActivity();

    CookieSyncManager.createInstance(mActivity);

    outer = (FrameLayout) inflater.inflate(R.layout.web_view_fragment, null);

    final RedditPost src_post = getArguments().getParcelable("post");
    final RedditPreparedPost post;

    if (src_post != null) {

        final RedditParsedPost parsedPost = new RedditParsedPost(src_post, false);

        post = new RedditPreparedPost(mActivity, CacheManager.getInstance(mActivity), 0, parsedPost, -1, false,
                false);

    } else {
        post = null;
    }

    webView = (WebViewFixed) outer.findViewById(R.id.web_view_fragment_webviewfixed);
    final FrameLayout loadingViewFrame = (FrameLayout) outer
            .findViewById(R.id.web_view_fragment_loadingview_frame);

    /*handle download links show an alert box to load this outside the internal browser*/
    webView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(final String url, String userAgent, String contentDisposition,
                String mimetype, long contentLength) {
            {
                new AlertDialog.Builder(mActivity).setTitle(R.string.download_link_title)
                        .setMessage(R.string.download_link_message)
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent i = new Intent(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(url));
                                getContext().startActivity(i);
                                mActivity.onBackPressed(); //get back from internal browser
                            }
                        }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                mActivity.onBackPressed(); //get back from internal browser
                            }
                        }).setIcon(android.R.drawable.ic_dialog_alert).show();
            }
        }
    });
    /*handle download links end*/

    progressView = new ProgressBar(mActivity, null, android.R.attr.progressBarStyleHorizontal);
    loadingViewFrame.addView(progressView);
    loadingViewFrame.setPadding(General.dpToPixels(mActivity, 10), 0, General.dpToPixels(mActivity, 10), 0);

    final WebSettings settings = webView.getSettings();

    settings.setBuiltInZoomControls(true);
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(false);
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDomStorageEnabled(true);

    if (AndroidApi.isHoneyCombOrLater()) {
        settings.setDisplayZoomControls(false);
    }

    // TODO handle long clicks

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, final int newProgress) {

            super.onProgressChanged(view, newProgress);

            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                @Override
                public void run() {
                    progressView.setProgress(newProgress);
                    progressView.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);
                }
            });
        }
    });

    if (mUrl != null) {
        webView.loadUrl(mUrl);
    } else {
        webView.loadDataWithBaseURL("https://reddit.com/", html, "text/html; charset=UTF-8", null, null);
    }

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(final WebView view, final String url) {

            if (url == null)
                return false;

            if (url.startsWith("data:")) {
                // Prevent imgur bug where we're directed to some random data URI
                return true;
            }

            // Go back if loading same page to prevent redirect loops.
            if (goingBack && currentUrl != null && url.equals(currentUrl)) {

                General.quickToast(mActivity,
                        String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt),
                        Toast.LENGTH_SHORT);

                lastBackDepthAttempt--;

                if (webView.canGoBackOrForward(lastBackDepthAttempt)) {
                    webView.goBackOrForward(lastBackDepthAttempt);
                } else {
                    mActivity.finish();
                }
            } else {

                if (RedditURLParser.parse(Uri.parse(url)) != null) {
                    LinkHandler.onLinkClicked(mActivity, url, false);
                } else {
                    webView.loadUrl(url);
                    currentUrl = url;
                }
            }

            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

            if (mUrl != null && url != null) {

                final AppCompatActivity activity = mActivity;

                if (activity != null) {
                    activity.setTitle(url);
                }
            }
        }

        @Override
        public void onPageFinished(final WebView view, final String url) {
            super.onPageFinished(view, url);

            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {

                    AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                        @Override
                        public void run() {

                            if (currentUrl == null || url == null)
                                return;

                            if (!url.equals(view.getUrl()))
                                return;

                            if (goingBack && url.equals(currentUrl)) {

                                General.quickToast(mActivity, String.format(Locale.US,
                                        "Handling redirect loop (level %d)", -lastBackDepthAttempt));

                                lastBackDepthAttempt--;

                                if (webView.canGoBackOrForward(lastBackDepthAttempt)) {
                                    webView.goBackOrForward(lastBackDepthAttempt);
                                } else {
                                    mActivity.finish();
                                }

                            } else {
                                goingBack = false;
                            }
                        }
                    });
                }
            }, 1000);
        }

        @Override
        public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
            super.doUpdateVisitedHistory(view, url, isReload);
        }
    });

    final FrameLayout outerFrame = new FrameLayout(mActivity);
    outerFrame.addView(outer);

    if (post != null) {

        final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(mActivity);

        final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(mActivity,
                new BezelSwipeOverlay.BezelSwipeListener() {
                    @Override
                    public boolean onSwipe(@BezelSwipeOverlay.SwipeEdge int edge) {

                        toolbarOverlay.setContents(post.generateToolbar(mActivity, false, toolbarOverlay));
                        toolbarOverlay.show(
                                edge == BezelSwipeOverlay.LEFT ? SideToolbarOverlay.SideToolbarPosition.LEFT
                                        : SideToolbarOverlay.SideToolbarPosition.RIGHT);
                        return true;
                    }

                    @Override
                    public boolean onTap() {

                        if (toolbarOverlay.isShown()) {
                            toolbarOverlay.hide();
                            return true;
                        }

                        return false;
                    }
                });

        outerFrame.addView(bezelOverlay);
        outerFrame.addView(toolbarOverlay);

        bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

        toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
    }

    return outerFrame;
}

From source file:com.github.yggie.pulltorefresh.PullListFragment.java

/**
 * Called to do initial creation of the fragment. Creates all the Views in code
 *
 * @param inflater The LayoutInflater//  w w w  .  j a  va2  s.  c  o m
 * @param container The parent container
 * @param savedInstanceState The saved pullState
 * @return The inflated view
 */

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    // setup the list view
    listView = new CustomListView(this);
    listView.setId(ID_LIST_VIEW);
    final RelativeLayout.LayoutParams listViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    listViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    listViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    listView.setLayoutParams(listViewParams);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            onListItemClick((ListView) adapterView, view, position, id);
        }
    });

    // setup the empty view
    final TextView textView = new TextView(context);
    textView.setLayoutParams(listViewParams);
    textView.setGravity(Gravity.CENTER);
    textView.setText("Nothing to show");
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18.0f);
    emptyView = textView;
    emptyView.setId(ID_EMPTY_VIEW);

    // setup top pulled view
    final RelativeLayout.LayoutParams topViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    topViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    topViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    final FrameLayout topFrameLayout = new FrameLayout(context);
    topFrameLayout.setLayoutParams(topViewParams);
    // setup the default child of the FrameLayout
    topManager = new DefaultPulledView(this, true);
    topFrameLayout.addView(topManager);
    topPulledView = topFrameLayout;
    topPulledView.setId(ID_TOP_VIEW);

    // setup bottom pulled view
    final RelativeLayout.LayoutParams bottomViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    bottomViewParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    bottomViewParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    final FrameLayout bottomFrameLayout = new FrameLayout(context);
    bottomFrameLayout.setLayoutParams(bottomViewParams);
    // setup the default child in the FrameLayout
    bottomManager = new DefaultPulledView(this, false);
    bottomFrameLayout.addView(bottomManager);
    bottomPulledView = bottomFrameLayout;
    bottomPulledView.setId(ID_BOTTOM_VIEW);

    layout = new PullToRefreshLayout(this);
    layout.addView(topPulledView);
    layout.addView(bottomPulledView);
    layout.addView(listView);
    layout.addView(emptyView);
    layout.setId(ID_LAYOUT);

    listShown = false;
    listView.setVisibility(View.GONE);
    emptyView.setVisibility(View.VISIBLE);

    // applies the XML attributes, if exists
    if (attrs != null) {
        final TypedArray a = getActivity().obtainStyledAttributes(attrs, R.styleable.PullListFragment);
        if (a != null) {
            parseXmlAttributes(a);
            a.recycle();
        }
        attrs = null;
    }

    return layout;
}

From source file:org.videolan.vlc.gui.video.VideoPlayerActivity.java

@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.player);/*from   w  ww.j av  a  2 s . c o  m*/
    final MyHandler myHandler = new MyHandler();
    final LayoutInflater inflater = LayoutInflater.from(this);
    msgContainer = (LinearLayout) findViewById(R.id.msg_container);
    int current_locID;
    if (ActivityDevice.current_locID == -1)
        current_locID = ActivityShiPin.current_locID;
    else
        current_locID = ActivityDevice.current_locID;
    ArrayList<Integer> locIDList = MainActivity.locIDList;
    HashMap<Integer, ArrayList<Integer>> loc_devMap = MainActivity.loc_devMap;
    dev_typeMap = MainActivity.dev_typeMap;
    HashMap<Integer, String> dev_nameMap = MainActivity.dev_nameMap;
    Log.e("*****localID", String.valueOf(current_locID));
    if (current_locID != -1) {
        if (loc_devMap.containsKey(current_locID)) {
            devList = loc_devMap.get(current_locID);
            if (devList.size() != 0) {
                int sub = devList.get(0) - 0;
                final ArrayList<Integer> brokenList = new ArrayList<Integer>();
                brokenList.add(0);
                int i;
                for (i = 0; i < devList.size(); i++) {
                    int devID = devList.get(i);
                    Log.e("@@@@@@@@", String.valueOf(i));
                    if (sub != devID - i) {
                        brokenList.add(i);
                        sub = devID - i;
                    }
                    //int typeID=dev_typeMap.get(devID);
                    final View view = inflater.inflate(R.layout.senssor_msg, null);
                    TextView type = (TextView) view.findViewById(R.id.type);
                    TextView msg = (TextView) view.findViewById(R.id.msg);
                    type.setText(dev_nameMap.get(devID) + ":");
                    msgContainer.addView(view);

                }
                brokenList.add(i);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        Log.e(">>>>>>>>>", "??");
                        String a = null;
                        try {
                            a = WebServiceUtil.getHd("sss", "njuptcloud");
                        } catch (Exception e1) {
                            // TODO Auto-generated catch block
                            //Toast.makeText(VideoPlayerActivity.this,"?a " , Toast.LENGTH_SHORT).show();
                            Log.e(">>>>>>>>>", "?a " + e1.getMessage());
                            e1.printStackTrace();

                        }
                        if (a != null) {
                            int i = 0;
                            List<String> msgList = new ArrayList<String>();
                            while (i < (brokenList.size() - 1)) {
                                try {
                                    //Toast.makeText(VideoPlayerActivity.this,"??... " , Toast.LENGTH_SHORT).show();
                                    msgList.addAll(WebServiceUtil.getMs(a, devList.get(brokenList.get(i)),
                                            devList.get(brokenList.get(i + 1) - 1)));
                                } catch (Exception e) {
                                    //Toast.makeText(VideoPlayerActivity.this,"?? " , Toast.LENGTH_SHORT).show();
                                    e.printStackTrace();
                                }
                                i++;
                            }
                            //                              List<String> resultList=new ArrayList<String>();
                            //                              resultList.add(object)
                            Message msg = new Message();
                            //Toast.makeText(VideoPlayerActivity.this,msgList.get(0) , Toast.LENGTH_SHORT).show();
                            msg.obj = msgList;
                            myHandler.sendMessage(msg);
                        } else {
                            Log.e(">>>>>>>", "??");
                            Message msg = new Message();
                            //Toast.makeText(VideoPlayerActivity.this,msgList.get(0) , Toast.LENGTH_SHORT).show();
                            msg.obj = null;
                            myHandler.sendMessage(msg);
                        }

                        //Toast.makeText(VideoPlayerActivity.this, "??", Toast.LENGTH_SHORT).show();
                    }
                }).start();
            }
        }
    }

    directionLayout = (LinearLayout) findViewById(R.id.direction_layout);

    left = (ImageButton) findViewById(R.id.left);
    left.setOnClickListener(directionListenr);
    bottom = (ImageButton) findViewById(R.id.bottom);
    bottom.setOnClickListener(directionListenr);
    top = (ImageButton) findViewById(R.id.top);
    top.setOnClickListener(directionListenr);
    right = (ImageButton) findViewById(R.id.right);
    right.setOnClickListener(directionListenr);

    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    if (Util.isICSOrLater())
        getWindow().getDecorView().findViewById(android.R.id.content)
                .setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        if (visibility == mUiVisibility)
                            return;
                        setSurfaceSize(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight,
                                mSarNum, mSarDen);
                        if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing) {
                            showOverlay();
                        }
                        mUiVisibility = visibility;
                    }
                });

    /** initialize Views an their Events */
    mOverlayHeader = findViewById(R.id.player_overlay_header);
    mOverlayHeader.setVisibility(View.GONE);
    mOverlayLock = findViewById(R.id.lock_overlay);
    mOverlayOption = findViewById(R.id.option_overlay);
    mOverlayProgress = findViewById(R.id.progress_overlay);
    mOverlayInterface = findViewById(R.id.interface_overlay);

    play_lay = (RelativeLayout) findViewById(R.id.play_lay);
    progress_lay = (LinearLayout) findViewById(R.id.progress_lay);

    /* header */
    mTitle = (TextView) findViewById(R.id.player_overlay_title);
    mSysTime = (TextView) findViewById(R.id.player_overlay_systime);
    mBattery = (TextView) findViewById(R.id.player_overlay_battery);

    // Position and remaining time
    mTime = (TextView) findViewById(R.id.player_overlay_time);
    mTime.setOnClickListener(mRemainingTimeListener);
    mLength = (TextView) findViewById(R.id.player_overlay_length);
    mLength.setOnClickListener(mRemainingTimeListener);

    // the info textView is not on the overlay
    mInfo = (TextView) findViewById(R.id.player_overlay_info);

    mEnableWheelbar = pref.getBoolean("enable_wheel_bar", false);
    mEnableBrightnessGesture = pref.getBoolean("enable_brightness_gesture", true);
    mScreenOrientation = Integer
            .valueOf(pref.getString("screen_orientation_value", "4" /*SCREEN_ORIENTATION_SENSOR*/));

    mControls = mEnableWheelbar ? new PlayerControlWheel(this) : new PlayerControlClassic(this);
    mControls.setOnPlayerControlListener(mPlayerControlListener);
    FrameLayout mControlContainer = (FrameLayout) findViewById(R.id.player_control);
    mControlContainer.addView((View) mControls);

    mAudioTrack = (ImageButton) findViewById(R.id.player_overlay_audio);
    mAudioTrack.setVisibility(View.GONE);
    mSubtitle = (ImageButton) findViewById(R.id.player_overlay_subtitle);
    mSubtitle.setVisibility(View.GONE);

    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            /*FIXME
             * The setTracksAndSubtitles method probably doesn't work in case of many many Tracks and Subtitles
             * Moreover, in a video stream, if Tracks & Subtitles change, they won't be updated
             */
            setESTrackLists();
        }
    }, 1500);

    mLock = (ImageButton) findViewById(R.id.lock_overlay_button);
    mLock.setOnClickListener(mLockListener);

    mSize = (ImageButton) findViewById(R.id.player_overlay_size);
    mSize.setOnClickListener(mSizeListener);

    snapshot_lay = (LinearLayout) findViewById(R.id.snapshot_lay);//??
    radio_onOrPause_lay = (LinearLayout) findViewById(R.id.radio_onOrPause_lay);//???        record_lay = (LinearLayout) findViewById(R.id.record_lay);//
    voice_lay = (LinearLayout) findViewById(R.id.voice_lay);//

    mSnapShot = (ImageButton) findViewById(R.id.snapshot_overlay_button);
    mSnapShot.setOnClickListener(mSnapShotListener);

    mRecord = (ImageButton) findViewById(R.id.record_overlay_button);
    mRecord.setOnClickListener(mRecordListener);

    //???        
    mRadio = (ImageButton) findViewById(R.id.radio_onOrPause_button);
    mRadio_tv = (TextView) findViewById(R.id.radio_onOrPause_tv);
    mRadio.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (mRadio.getBackground().getConstantState() == getResources().getDrawable(R.drawable.radio_on1)
                    .getConstantState()) {
                //?????
                if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                    mRadio.setBackgroundDrawable(getResources().getDrawable(R.drawable.radio_pause));
                } else {
                    mRadio.setBackground(getResources().getDrawable(R.drawable.radio_pause));
                }
                mRadio_tv.setText("?");
                play();
            } else {
                //????
                if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                    mRadio.setBackgroundDrawable(getResources().getDrawable(R.drawable.radio_on1));
                } else {
                    mRadio.setBackground(getResources().getDrawable(R.drawable.radio_on1));
                }
                mRadio_tv.setText("?");
                pause();
            }
        }
    });

    mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    mAudioMax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    //
    mVoice = (ImageButton) findViewById(R.id.voice_overlay_button);
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mAudioMax, 0);
    mVoice.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (mVoice.getBackground().getConstantState() == getResources().getDrawable(R.drawable.voice_on)
                    .getConstantState()) {
                //??
                if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                    mVoice.setBackgroundDrawable(getResources().getDrawable(R.drawable.voice_off));
                } else {
                    mVoice.setBackground(getResources().getDrawable(R.drawable.voice_off));
                }
                mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
            } else {
                //??
                if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                    mVoice.setBackgroundDrawable(getResources().getDrawable(R.drawable.voice_on));
                } else {
                    mVoice.setBackground(getResources().getDrawable(R.drawable.voice_on));
                }
                mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mAudioMax, 0);
            }
        }
    });

    mSurface = (SurfaceView) findViewById(R.id.player_surface);
    mSurfaceHolder = mSurface.getHolder();
    mSurfaceFrame = (FrameLayout) findViewById(R.id.player_surface_frame);
    mSurfaceFrame.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if (MotionEvent.ACTION_DOWN == event.getAction()) {
                if (System.currentTimeMillis() - clickTime < 500) {
                    //??
                    if (mCurrentSize == SURFACE_4_3) {
                        //???
                        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                    } else {
                        //??
                        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                    }
                } else {
                    if (!mShowing) {
                        showOverlay();
                        mSurfaceFrame.setFocusable(false);
                    } else {
                        hideOverlay(true);
                    }
                }
                clickTime = System.currentTimeMillis();
                if (directionLayout.getVisibility() == View.INVISIBLE) {
                    directionLayout.setVisibility(View.VISIBLE);
                } else {
                    directionLayout.setVisibility(View.INVISIBLE);
                }
            }
            return true;
        }
    });

    mOrientationListener = new OrientationEventListener(this) {
        @Override
        public void onOrientationChanged(int rotation) {
            if (((rotation >= 0) && (rotation <= 45)) || (rotation >= 315)
                    || ((rotation >= 135) && (rotation <= 225))) {//portrait
                mCurrentOrient = true;
                if (mCurrentOrient != mScreenProtrait) {
                    mScreenProtrait = mCurrentOrient;
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                    Log.d(TAG, "Screen orientation changed from Landscape to Portrait!");
                }
            } else if (((rotation > 45) && (rotation < 135)) || ((rotation > 225) && (rotation < 315))) {//landscape
                mCurrentOrient = false;
                if (mCurrentOrient != mScreenProtrait) {
                    mScreenProtrait = mCurrentOrient;
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                    Log.d(TAG, "Screen orientation changed from Portrait to Landscape!");
                }
            }
        }
    };
    mOrientationListener.enable();

    int pitch;
    String chroma = pref.getString("chroma_format", "");
    if (Util.isGingerbreadOrLater() && chroma.equals("YV12")) {
        mSurfaceHolder.setFormat(ImageFormat.YV12);
        pitch = ImageFormat.getBitsPerPixel(ImageFormat.YV12) / 8;
    } else if (chroma.equals("RV16")) {
        mSurfaceHolder.setFormat(PixelFormat.RGB_565);
        PixelFormat info = new PixelFormat();
        PixelFormat.getPixelFormatInfo(PixelFormat.RGB_565, info);
        pitch = info.bytesPerPixel;
    } else {
        mSurfaceHolder.setFormat(PixelFormat.RGBX_8888);
        PixelFormat info = new PixelFormat();
        PixelFormat.getPixelFormatInfo(PixelFormat.RGBX_8888, info);
        pitch = info.bytesPerPixel;
    }
    mSurfaceAlign = 16 / pitch - 1;
    mSurfaceHolder.addCallback(mSurfaceCallback);

    mSeekbar = (SeekBar) findViewById(R.id.player_overlay_seekbar);
    mSeekbar.setOnSeekBarChangeListener(mSeekListener);

    mSwitchingView = false;
    mEndReached = false;

    // Clear the resume time, since it is only used for resumes in external
    // videos.
    SharedPreferences preferences = getSharedPreferences(PreferencesActivity.NAME, MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putLong(PreferencesActivity.VIDEO_RESUME_TIME, -1);
    // Also clear the subs list, because it is supposed to be per session
    // only (like desktop VLC). We don't want the customs subtitle file
    // to persist forever with this video.
    editor.putString(PreferencesActivity.VIDEO_SUBTITLE_FILES, null);
    editor.commit();

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_BATTERY_CHANGED);
    filter.addAction(VLCApplication.SLEEP_INTENT);
    registerReceiver(mReceiver, filter);

    try {
        mLibVLC = Util.getLibVlcInstance();
    } catch (LibVlcException e) {
        Log.d(TAG, "LibVLC initialisation failed");
        return;
    }

    EventHandler em = EventHandler.getInstance();
    em.addHandler(eventHandler);

    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // 100 is the value for screen_orientation_start_lock,??
    //        setRequestedOrientation(mScreenOrientation != 100
    //                ? mScreenOrientation
    //                : getScreenOrientation());

    //???
    //        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    //??
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

From source file:com.tct.mail.ui.ConversationViewFragment.java

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

    //TS: chao-zhang 2015-12-10 EMAIL BUGFIX_1121860 MOD_S    544
    //NOTE: when infalte conversationView which is implements from WebView,webview.jar is not exist
    //or not found,NameNotFoundException exception thrown,and InflateException thrown in Email,BAD!!!
    View rootView;//from ww  w  . j  a v a  2 s. co m
    try {
        rootView = inflater.inflate(R.layout.conversation_view, container, false);
    } catch (InflateException e) {
        LogUtils.e(LOG_TAG, e, "InflateException happen during inflate conversationView");
        //TS: xing.zhao 2016-4-1 EMAIL BUGFIX_1892015 MOD_S
        if (getActivity() == null) {
            return null;
        } else {
            rootView = new View(getActivity().getApplicationContext());
            return rootView;
        }
        //TS: xing.zhao 2016-4-1 EMAIL BUGFIX_1892015 MOD_E
    }
    //TS: chao-zhang 2015-12-10 EMAIL BUGFIX_1121860 MOD_E
    //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_S
    //Here we romve the imagebutton and then add it ,to make it show on the top level.
    //Because we can't add the fab button at last on the layout xml.
    mFabButton = (ConversationReplyFabView) rootView.findViewById(R.id.conversation_view_fab);
    FrameLayout framelayout = (FrameLayout) rootView.findViewById(R.id.conversation_view_framelayout);
    framelayout.removeView(mFabButton);
    framelayout.addView(mFabButton);
    //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_E
    mConversationContainer = (ConversationContainer) rootView.findViewById(R.id.conversation_container);
    mConversationContainer.setAccountController(this);

    mTopmostOverlay = (ViewGroup) mConversationContainer.findViewById(R.id.conversation_topmost_overlay);
    mTopmostOverlay.setOnKeyListener(this);
    inflateSnapHeader(mTopmostOverlay, inflater);
    mConversationContainer.setupSnapHeader();

    setupNewMessageBar();

    mProgressController = new ConversationViewProgressController(this, getHandler());
    mProgressController.instantiateProgressIndicators(rootView);

    mWebView = (ConversationWebView) mConversationContainer.findViewById(R.id.conversation_webview);
    //TS: junwei-xu 2015-3-25 EMAIL BUGFIX_919767 ADD_S
    if (mWebView != null) {
        mWebView.setActivity(getActivity());
    }
    //TS: junwei-xu 2015-3-25 EMAIL BUGFIX_919767 ADD_E
    //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_S
    mWebView.setFabButton(mFabButton);
    //TS: tao.gan 2015-09-10 EMAIL FEATURE-559891 ADD_E

    mWebView.addJavascriptInterface(mJsBridge, "mail");
    // On JB or newer, we use the 'webkitAnimationStart' DOM event to signal load complete
    // Below JB, try to speed up initial render by having the webview do supplemental draws to
    // custom a software canvas.
    // TODO(mindyp):
    //PAGE READINESS SIGNAL FOR JELLYBEAN AND NEWER
    // Notify the app on 'webkitAnimationStart' of a simple dummy element with a simple no-op
    // animation that immediately runs on page load. The app uses this as a signal that the
    // content is loaded and ready to draw, since WebView delays firing this event until the
    // layers are composited and everything is ready to draw.
    // This signal does not seem to be reliable, so just use the old method for now.
    final boolean isJBOrLater = Utils.isRunningJellybeanOrLater();
    final boolean isUserVisible = isUserVisible();
    mWebView.setUseSoftwareLayer(!isJBOrLater);
    mEnableContentReadySignal = isJBOrLater && isUserVisible;
    mWebView.onUserVisibilityChanged(isUserVisible);
    mWebView.setWebViewClient(mWebViewClient);
    final WebChromeClient wcc = new WebChromeClient() {
        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            if (consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR) {
                //TS: wenggangjin 2015-01-29 EMAIL BUGFIX_-917007 MOD_S
                //                    LogUtils.wtf(LOG_TAG, "JS: %s (%s:%d) f=%s", consoleMessage.message(),
                LogUtils.w(LOG_TAG, "JS: %s (%s:%d) f=%s", consoleMessage.message(), consoleMessage.sourceId(),
                        consoleMessage.lineNumber(), ConversationViewFragment.this);
                //TS: wenggangjin 2015-01-29 EMAIL BUGFIX_-917007 MOD_E
            } else {
                LogUtils.i(LOG_TAG, "JS: %s (%s:%d) f=%s", consoleMessage.message(), consoleMessage.sourceId(),
                        consoleMessage.lineNumber(), ConversationViewFragment.this);
            }
            return true;
        }
    };
    mWebView.setWebChromeClient(wcc);

    final WebSettings settings = mWebView.getSettings();

    final ScrollIndicatorsView scrollIndicators = (ScrollIndicatorsView) rootView
            .findViewById(R.id.scroll_indicators);
    scrollIndicators.setSourceView(mWebView);

    settings.setJavaScriptEnabled(true);

    ConversationViewUtils.setTextZoom(getResources(), settings);
    //Enable third-party cookies. b/16014255
    if (Utils.isRunningLOrLater()) {
        CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true /* accept */);
    }

    mViewsCreated = true;
    mWebViewLoadedData = false;

    return rootView;
}