Search in sources :

Example 66 with Window

use of android.view.Window in project android_frameworks_base by ParanoidAndroid.

the class Instrumentation method invokeMenuActionSync.

/**
     * Execute a particular menu item.
     * 
     * @param targetActivity The activity in question.
     * @param id The identifier associated with the menu item.
     * @param flag Additional flags, if any.
     * @return Whether the invocation was successful (for example, it could be
     *         false if item is disabled).
     */
public boolean invokeMenuActionSync(Activity targetActivity, int id, int flag) {
    class MenuRunnable implements Runnable {

        private final Activity activity;

        private final int identifier;

        private final int flags;

        boolean returnValue;

        public MenuRunnable(Activity _activity, int _identifier, int _flags) {
            activity = _activity;
            identifier = _identifier;
            flags = _flags;
        }

        public void run() {
            Window win = activity.getWindow();
            returnValue = win.performPanelIdentifierAction(Window.FEATURE_OPTIONS_PANEL, identifier, flags);
        }
    }
    MenuRunnable mr = new MenuRunnable(targetActivity, id, flag);
    runOnMainSync(mr);
    return mr.returnValue;
}
Also used : Window(android.view.Window)

Example 67 with Window

use of android.view.Window in project Timber by naman14.

the class ATEUtils method setStatusBarColor.

public static void setStatusBarColor(Activity activity, String key, int color) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            final Window window = activity.getWindow();
            if (Config.coloredStatusBar(activity, key))
                window.setStatusBarColor(getStatusBarColor(color));
            else
                window.setStatusBarColor(Color.BLACK);
            if (Config.coloredNavigationBar(activity, key))
                window.setNavigationBarColor(color);
            else
                window.setNavigationBarColor(Color.BLACK);
            applyTaskDescription(activity, key, color);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            final View decorView = activity.getWindow().getDecorView();
            final int lightStatusMode = Config.lightStatusBarMode(activity, key);
            boolean lightStatusEnabled = false;
            switch(lightStatusMode) {
                case Config.LIGHT_STATUS_BAR_OFF:
                default:
                    break;
                case Config.LIGHT_STATUS_BAR_ON:
                    lightStatusEnabled = true;
                    break;
                case Config.LIGHT_STATUS_BAR_AUTO:
                    lightStatusEnabled = Util.isColorLight(color);
                    break;
            }
            final int systemUiVisibility = decorView.getSystemUiVisibility();
            if (lightStatusEnabled) {
                decorView.setSystemUiVisibility(systemUiVisibility | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            } else {
                decorView.setSystemUiVisibility(systemUiVisibility & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            }
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            final int color2 = Config.coloredStatusBar(activity, key) ? Color.TRANSPARENT : Color.BLACK;
            activity.getWindow().setStatusBarColor(color2);
        }
        if (Config.coloredStatusBar(activity, key))
            ((DrawerLayout) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0)).setStatusBarBackgroundColor(getStatusBarColor(color));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Window(android.view.Window) ViewGroup(android.view.ViewGroup) View(android.view.View)

Example 68 with Window

use of android.view.Window in project SystemBarTint by jgilfelt.

the class MatchActionBarActivity method setTranslucentStatus.

@TargetApi(19)
private void setTranslucentStatus(boolean on) {
    Window win = getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if (on) {
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);
}
Also used : Window(android.view.Window) WindowManager(android.view.WindowManager) TargetApi(android.annotation.TargetApi)

Example 69 with Window

use of android.view.Window in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.setStatusBarColor(getResources().getColor(R.color.primary_dark));
    mgr = (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE);
}
Also used : Window(android.view.Window)

Example 70 with Window

use of android.view.Window in project MaterialNavigationDrawer by neokree.

the class MaterialNavigationDrawer method onCreate.

@SuppressWarnings("unchecked")
@Override
protected /**
     * Do not Override this method!!! <br>
     * Use init() instead
     */
void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Resources.Theme theme = this.getTheme();
    TypedValue typedValue = new TypedValue();
    theme.resolveAttribute(R.attr.drawerType, typedValue, true);
    drawerHeaderType = typedValue.data;
    theme.resolveAttribute(R.attr.rippleBackport, typedValue, false);
    rippleSupport = typedValue.data != 0;
    theme.resolveAttribute(R.attr.uniqueToolbarColor, typedValue, false);
    uniqueToolbarColor = typedValue.data != 0;
    theme.resolveAttribute(R.attr.singleAccount, typedValue, false);
    singleAccount = typedValue.data != 0;
    theme.resolveAttribute(R.attr.multipaneSupport, typedValue, false);
    multiPaneSupport = typedValue.data != 0;
    theme.resolveAttribute(R.attr.learningPattern, typedValue, false);
    learningPattern = typedValue.data != 0;
    theme.resolveAttribute(R.attr.drawerColor, typedValue, true);
    drawerColor = typedValue.data;
    theme.resolveAttribute(R.attr.defaultSectionLoaded, typedValue, true);
    defaultSectionLoaded = typedValue.data;
    theme.resolveAttribute(R.attr.toolbarElevation, typedValue, false);
    toolbarElevation = typedValue.data != 0;
    if (drawerHeaderType == DRAWERHEADER_ACCOUNTS)
        super.setContentView(R.layout.activity_material_navigation_drawer);
    else
        super.setContentView(R.layout.activity_material_navigation_drawer_customheader);
    // init Typeface
    fontManager = new TypefaceManager(this.getAssets());
    // init toolbar & status bar
    statusBar = (ImageView) findViewById(R.id.statusBar);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    // init drawer components
    layout = (MaterialDrawerLayout) this.findViewById(R.id.drawer_layout);
    content = (RelativeLayout) this.findViewById(R.id.content);
    drawer = (RelativeLayout) this.findViewById(R.id.drawer);
    if (drawerHeaderType == DRAWERHEADER_ACCOUNTS) {
        username = (TextView) this.findViewById(R.id.user_nome);
        usermail = (TextView) this.findViewById(R.id.user_email);
        userphoto = (ImageView) this.findViewById(R.id.user_photo);
        userSecondPhoto = (ImageView) this.findViewById(R.id.user_photo_2);
        userThirdPhoto = (ImageView) this.findViewById(R.id.user_photo_3);
        usercover = (ImageView) this.findViewById(R.id.user_cover);
        usercoverSwitcher = (ImageView) this.findViewById(R.id.user_cover_switcher);
        userButtonSwitcher = (ImageButton) this.findViewById(R.id.user_switcher);
        // set Roboto Fonts
        username.setTypeface(fontManager.getRobotoMedium());
        usermail.setTypeface(fontManager.getRobotoRegular());
        // get and set username and mail text colors
        theme.resolveAttribute(R.attr.accountStyle, typedValue, true);
        TypedArray attributes = theme.obtainStyledAttributes(typedValue.resourceId, R.styleable.MaterialAccount);
        try {
            username.setTextColor(attributes.getColor(R.styleable.MaterialAccount_titleColor, 0xFFF));
            usermail.setTextColor(attributes.getColor(R.styleable.MaterialAccount_subtitleColor, 0xFFF));
        } finally {
            attributes.recycle();
        }
        // set the button image
        if (!singleAccount) {
            userButtonSwitcher.setImageResource(R.drawable.ic_arrow_drop_down_white_24dp);
            userButtonSwitcher.setOnClickListener(accountSwitcherListener);
        }
    } else
        customDrawerHeader = (LinearLayout) this.findViewById(R.id.drawer_header);
    sections = (LinearLayout) this.findViewById(R.id.sections);
    bottomSections = (LinearLayout) this.findViewById(R.id.bottom_sections);
    // init lists
    sectionList = new LinkedList<>();
    bottomSectionList = new LinkedList<>();
    accountManager = new LinkedList<>();
    accountSectionList = new LinkedList<>();
    subheaderList = new LinkedList<>();
    elementsList = new LinkedList<>();
    childFragmentStack = new LinkedList<>();
    childTitleStack = new LinkedList<>();
    // init listeners
    if (drawerHeaderType == DRAWERHEADER_ACCOUNTS) {
        userphoto.setOnClickListener(currentAccountListener);
        if (singleAccount)
            usercover.setOnClickListener(currentAccountListener);
        else
            usercover.setOnClickListener(accountSwitcherListener);
        userSecondPhoto.setOnClickListener(secondAccountListener);
        userThirdPhoto.setOnClickListener(thirdAccountListener);
    }
    // set drawer backgrond color
    drawer.setBackgroundColor(drawerColor);
    //get resources and density
    resources = this.getResources();
    density = resources.getDisplayMetrics().density;
    // set the right drawer width
    DrawerLayout.LayoutParams drawerParams = (android.support.v4.widget.DrawerLayout.LayoutParams) drawer.getLayoutParams();
    drawerParams.width = Utils.getDrawerWidth(resources);
    drawer.setLayoutParams(drawerParams);
    // get primary color
    theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
    primaryColor = typedValue.data;
    theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
    primaryDarkColor = typedValue.data;
    // if device is kitkat
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        TypedArray windowTraslucentAttribute = theme.obtainStyledAttributes(new int[] { android.R.attr.windowTranslucentStatus });
        kitkatTraslucentStatusbar = windowTraslucentAttribute.getBoolean(0, false);
        if (kitkatTraslucentStatusbar) {
            Window window = this.getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            RelativeLayout.LayoutParams statusParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, resources.getDimensionPixelSize(R.dimen.traslucentStatusMargin));
            statusBar.setLayoutParams(statusParams);
            statusBar.setImageDrawable(new ColorDrawable(darkenColor(primaryColor)));
            if (drawerHeaderType == DRAWERHEADER_ACCOUNTS) {
                RelativeLayout.LayoutParams photoParams = (RelativeLayout.LayoutParams) userphoto.getLayoutParams();
                photoParams.setMargins((int) (16 * density), resources.getDimensionPixelSize(R.dimen.traslucentPhotoMarginTop), 0, 0);
                userphoto.setLayoutParams(photoParams);
            }
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
    // INIT TOOLBAR ELEVATION
    if (toolbarElevation) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // 4 dp elevation
            toolbar.setElevation(4 * density);
        } else {
            View elevation = LayoutInflater.from(this).inflate(R.layout.layout_toolbar_elevation, content, false);
            content.addView(elevation);
        }
    }
    // INIT ACTION BAR
    this.setSupportActionBar(toolbar);
    actionBar = getSupportActionBar();
    // DEVELOPER CALL TO INIT
    init(savedInstanceState);
    if (sectionList.size() == 0) {
        throw new RuntimeException("You must add at least one Section to top list.");
    }
    if (deviceSupportMultiPane()) {
        // se il multipane e' attivo, si e' in landscape e si e' un tablet allora si passa in multipane mode
        layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, drawer);
        DrawerLayout.LayoutParams params = new DrawerLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.setMargins((int) (320 * density), 0, 0, 0);
        content.setLayoutParams(params);
        layout.setScrimColor(Color.TRANSPARENT);
        layout.openDrawer(drawer);
        layout.setMultipaneSupport(true);
    } else {
        // se non si sta lavorando in multiPane allora si inserisce il pulsante per aprire/chiudere
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        pulsante = new MaterialActionBarDrawerToggle<Fragment>(this, layout, toolbar, R.string.nothing, R.string.nothing) {

            @Override
            public void onDrawerClosed(View view) {
                // creates call to onPrepareOptionsMenu()
                invalidateOptionsMenu();
                // abilita il touch del drawer
                setDrawerTouchable(true);
                if (drawerListener != null)
                    drawerListener.onDrawerClosed(view);
                if (hasRequest()) {
                    MaterialSection section = getRequestedSection();
                    changeToolbarColor(section);
                    setFragment((Fragment) section.getTargetFragment(), section.getTitle(), (Fragment) currentSection.getTargetFragment());
                    afterFragmentSetted((Fragment) section.getTargetFragment(), section.getTitle());
                    this.removeRequest();
                }
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                // creates call to onPrepareOptionsMenu()
                invalidateOptionsMenu();
                if (drawerListener != null)
                    drawerListener.onDrawerOpened(drawerView);
            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                // if user wants the sliding arrow it compare
                if (slidingDrawerEffect)
                    super.onDrawerSlide(drawerView, slideOffset);
                else
                    super.onDrawerSlide(drawerView, 0);
                if (drawerListener != null)
                    drawerListener.onDrawerSlide(drawerView, slideOffset);
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                super.onDrawerStateChanged(newState);
                if (drawerListener != null)
                    drawerListener.onDrawerStateChanged(newState);
            }
        };
        pulsante.setToolbarNavigationClickListener(toolbarToggleListener);
        layout.setDrawerListener(pulsante);
        layout.setMultipaneSupport(false);
    }
    // si procede con gli altri elementi dopo la creazione delle viste
    ViewTreeObserver vto = drawer.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            // quando l'immagine e' stata caricata
            // change user space to 16:9
            int width = drawer.getWidth();
            int heightCover = 0;
            switch(drawerHeaderType) {
                default:
                case DRAWERHEADER_ACCOUNTS:
                case DRAWERHEADER_IMAGE:
                case DRAWERHEADER_CUSTOM:
                    // si fa il rapporto in 16 : 9
                    heightCover = (9 * width) / 16;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                        heightCover += (int) (24 * density);
                    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT && kitkatTraslucentStatusbar)
                        heightCover += (int) (25 * density);
                    break;
                case DRAWERHEADER_NO_HEADER:
                    break;
            }
            // set user space
            if (drawerHeaderType == DRAWERHEADER_ACCOUNTS) {
                usercover.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, heightCover));
                usercoverSwitcher.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, heightCover));
            } else {
                customDrawerHeader.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, heightCover));
            }
            // adding status bar height for other version of android that not have traslucent status bar
            if ((Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT && !kitkatTraslucentStatusbar) || Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
                heightCover += (int) (25 * density);
            }
            //  heightCover (DRAWER HEADER) + 8 (PADDING) + sections + 8 (PADDING) + 1 (DIVISOR) + bottomSections + subheaders
            int heightDrawer = (int) (((8 + 8) * density) + 1 + heightCover + sections.getHeight() + ((density * 48) * bottomSectionList.size()) + (subheaderList.size() * (35 * density)));
            // create the divisor
            View divisor = new View(MaterialNavigationDrawer.this);
            divisor.setBackgroundColor(Color.parseColor("#8f8f8f"));
            // si aggiungono le bottom sections
            if (heightDrawer >= Utils.getScreenHeight(MaterialNavigationDrawer.this)) {
                // add the divisor to the section view
                LinearLayout.LayoutParams paramDivisor = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
                paramDivisor.setMargins(0, (int) (8 * density), 0, (int) (8 * density));
                sections.addView(divisor, paramDivisor);
                for (MaterialSection section : bottomSectionList) {
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (48 * density));
                    sections.addView(section.getView(), params);
                }
            } else {
                // add the divisor to the bottom section listview
                LinearLayout.LayoutParams paramDivisor = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
                bottomSections.addView(divisor, paramDivisor);
                for (MaterialSection section : bottomSectionList) {
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (48 * density));
                    bottomSections.addView(section.getView(), params);
                }
            }
            ViewTreeObserver obs = drawer.getViewTreeObserver();
            // si rimuove il listener
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                obs.removeOnGlobalLayoutListener(this);
            } else {
                obs.removeGlobalOnLayoutListener(this);
            }
        }
    });
    MaterialSection section;
    if (savedInstanceState == null) {
        // init account views
        if (accountManager.size() > 0) {
            currentAccount = accountManager.get(0);
            notifyAccountDataChanged();
        }
        // init section
        if (defaultSectionLoaded < 0 || defaultSectionLoaded >= sectionList.size()) {
            throw new RuntimeException("You are trying to open at startup a section that does not exist");
        }
        section = sectionList.get(defaultSectionLoaded);
        if (section.getTarget() != MaterialSection.TARGET_FRAGMENT)
            throw new RuntimeException("The first section added must have a fragment as target");
    } else {
        ArrayList<Integer> accountNumbers = savedInstanceState.getIntegerArrayList(STATE_ACCOUNT);
        // ripristina gli account | restore accounts
        for (int i = 0; i < accountNumbers.size(); i++) {
            MaterialAccount account = accountManager.get(i);
            account.setAccountNumber(accountNumbers.get(i));
            if (account.getAccountNumber() == MaterialAccount.FIRST_ACCOUNT) {
                currentAccount = account;
            }
        }
        notifyAccountDataChanged();
        int sectionSelected = savedInstanceState.getInt(STATE_SECTION);
        int sectionListType = savedInstanceState.getInt(STATE_LIST);
        if (sectionListType == Element.TYPE_SECTION) {
            section = sectionList.get(sectionSelected);
        } else
            section = bottomSectionList.get(sectionSelected);
        if (section.getTarget() != MaterialSection.TARGET_FRAGMENT) {
            section = sectionList.get(0);
        }
    }
    title = section.getTitle();
    currentSection = section;
    section.select();
    setFragment((Fragment) section.getTargetFragment(), section.getTitle(), null, savedInstanceState != null);
    // change the toolbar color for the first section
    changeToolbarColor(section);
    // add the first section to the child stack
    childFragmentStack.add((Fragment) section.getTargetFragment());
    childTitleStack.add(section.getTitle());
    // learning pattern
    if (learningPattern) {
        layout.openDrawer(drawer);
        disableLearningPattern();
    }
}
Also used : TypefaceManager(it.neokree.materialnavigationdrawer.util.TypefaceManager) MaterialAccount(it.neokree.materialnavigationdrawer.elements.MaterialAccount) TypedArray(android.content.res.TypedArray) MaterialSection(it.neokree.materialnavigationdrawer.elements.MaterialSection) MaterialDrawerLayout(it.neokree.materialnavigationdrawer.util.MaterialDrawerLayout) DrawerLayout(android.support.v4.widget.DrawerLayout) ViewTreeObserver(android.view.ViewTreeObserver) TypedValue(android.util.TypedValue) Window(android.view.Window) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ColorDrawable(android.graphics.drawable.ColorDrawable) RelativeLayout(android.widget.RelativeLayout) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Aggregations

Window (android.view.Window)322 View (android.view.View)72 WindowManager (android.view.WindowManager)58 TextView (android.widget.TextView)34 TargetApi (android.annotation.TargetApi)29 ImageView (android.widget.ImageView)25 ViewGroup (android.view.ViewGroup)22 Activity (android.app.Activity)17 Dialog (android.app.Dialog)17 ColorDrawable (android.graphics.drawable.ColorDrawable)16 AdapterView (android.widget.AdapterView)16 PhoneWindow (com.android.internal.policy.PhoneWindow)15 Intent (android.content.Intent)11 Context (android.content.Context)10 LayoutInflater (android.view.LayoutInflater)10 WindowDecorActionBar (com.android.internal.app.WindowDecorActionBar)10 RemoteException (android.os.RemoteException)9 DisplayMetrics (android.util.DisplayMetrics)9 LinearLayout (android.widget.LinearLayout)9 PopupWindow (android.widget.PopupWindow)8