Example usage for android.view Gravity RIGHT

List of usage examples for android.view Gravity RIGHT

Introduction

In this page you can find the example usage for android.view Gravity RIGHT.

Prototype

int RIGHT

To view the source code for android.view Gravity RIGHT.

Click Source Link

Document

Push object to the right of its container, not changing its size.

Usage

From source file:com.farmerbb.taskbar.service.StartMenuService.java

@SuppressLint("RtlHardcoded")
private void drawStartMenu() {
    IconCache.getInstance(this).clearCache();

    final SharedPreferences pref = U.getSharedPreferences(this);
    final boolean hasHardwareKeyboard = getResources()
            .getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;

    switch (pref.getString("show_search_bar", "keyboard")) {
    case "always":
        shouldShowSearchBox = true;//from w ww.  j a va  2 s. com
        break;
    case "keyboard":
        shouldShowSearchBox = hasHardwareKeyboard;
        break;
    case "never":
        shouldShowSearchBox = false;
        break;
    }

    // Initialize layout params
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            shouldShowSearchBox ? 0
                    : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            PixelFormat.TRANSLUCENT);

    // Determine where to show the start menu on screen
    switch (U.getTaskbarPosition(this)) {
    case "bottom_left":
        layoutId = R.layout.start_menu_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        break;
    case "bottom_vertical_left":
        layoutId = R.layout.start_menu_vertical_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        break;
    case "bottom_right":
        layoutId = R.layout.start_menu_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        break;
    case "bottom_vertical_right":
        layoutId = R.layout.start_menu_vertical_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        break;
    case "top_left":
        layoutId = R.layout.start_menu_top_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        break;
    case "top_vertical_left":
        layoutId = R.layout.start_menu_vertical_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        break;
    case "top_right":
        layoutId = R.layout.start_menu_top_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        break;
    case "top_vertical_right":
        layoutId = R.layout.start_menu_vertical_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        break;
    }

    // Initialize views
    int theme = 0;

    switch (pref.getString("theme", "light")) {
    case "light":
        theme = R.style.AppTheme;
        break;
    case "dark":
        theme = R.style.AppTheme_Dark;
        break;
    }

    ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme);
    layout = (StartMenuLayout) LayoutInflater.from(wrapper).inflate(layoutId, null);
    startMenu = (GridView) layout.findViewById(R.id.start_menu);

    if ((shouldShowSearchBox && !hasHardwareKeyboard)
            || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        layout.viewHandlesBackButton();

    boolean scrollbar = pref.getBoolean("scrollbar", false);
    startMenu.setFastScrollEnabled(scrollbar);
    startMenu.setFastScrollAlwaysVisible(scrollbar);
    startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);

    if (pref.getBoolean("transparent_start_menu", false))
        startMenu.setBackgroundColor(0);

    searchView = (SearchView) layout.findViewById(R.id.search);

    int backgroundTint = U.getBackgroundTint(this);

    FrameLayout startMenuFrame = (FrameLayout) layout.findViewById(R.id.start_menu_frame);
    FrameLayout searchViewLayout = (FrameLayout) layout.findViewById(R.id.search_view_layout);
    startMenuFrame.setBackgroundColor(backgroundTint);
    searchViewLayout.setBackgroundColor(backgroundTint);

    if (shouldShowSearchBox) {
        if (!hasHardwareKeyboard)
            searchView.setIconifiedByDefault(true);

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                if (!hasSubmittedQuery) {
                    ListAdapter adapter = startMenu.getAdapter();
                    if (adapter != null) {
                        hasSubmittedQuery = true;

                        if (adapter.getCount() > 0) {
                            View view = adapter.getView(0, null, startMenu);
                            LinearLayout layout = (LinearLayout) view.findViewById(R.id.entry);
                            layout.performClick();
                        } else {
                            if (pref.getBoolean("hide_taskbar", true)
                                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                                LocalBroadcastManager.getInstance(StartMenuService.this)
                                        .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR"));
                            else
                                LocalBroadcastManager.getInstance(StartMenuService.this)
                                        .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));

                            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
                            intent.putExtra(SearchManager.QUERY, query);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            if (intent.resolveActivity(getPackageManager()) != null)
                                startActivity(intent);
                            else {
                                Uri uri = new Uri.Builder().scheme("https").authority("www.google.com")
                                        .path("search").appendQueryParameter("q", query).build();

                                intent = new Intent(Intent.ACTION_VIEW);
                                intent.setData(uri);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                                try {
                                    startActivity(intent);
                                } catch (ActivityNotFoundException e) {
                                    /* Gracefully fail */ }
                            }
                        }
                    }
                }
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                searchView.setIconified(false);

                View closeButton = searchView.findViewById(R.id.search_close_btn);
                if (closeButton != null)
                    closeButton.setVisibility(View.GONE);

                refreshApps(newText, false);

                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
                    new Handler().postDelayed(() -> {
                        EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);
                        if (editText != null) {
                            editText.requestFocus();
                            editText.setSelection(editText.getText().length());
                        }
                    }, 50);
                }

                return true;
            }
        });

        searchView.setOnQueryTextFocusChangeListener((view, b) -> {
            if (!hasHardwareKeyboard) {
                ViewGroup.LayoutParams params1 = startMenu.getLayoutParams();
                params1.height = getResources().getDimensionPixelSize(b
                        && !U.isServiceRunning(this, "com.farmerbb.secondscreen.service.DisableKeyboardService")
                                ? R.dimen.start_menu_height_half
                                : R.dimen.start_menu_height);
                startMenu.setLayoutParams(params1);
            }

            if (!b) {
                if (hasHardwareKeyboard && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
                    LocalBroadcastManager.getInstance(StartMenuService.this)
                            .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
                else {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
            }
        });

        searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);

        LinearLayout powerButton = (LinearLayout) layout.findViewById(R.id.power_button);
        powerButton.setOnClickListener(view -> {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(location);
        });

        powerButton.setOnGenericMotionListener((view, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                    && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                int[] location = new int[2];
                view.getLocationOnScreen(location);
                openContextMenu(location);
            }
            return false;
        });

        searchViewLayout.setOnClickListener(view -> searchView.setIconified(false));

        startMenu.setOnItemClickListener((parent, view, position, id) -> {
            hideStartMenu();

            AppEntry entry = (AppEntry) parent.getAdapter().getItem(position);
            U.launchApp(StartMenuService.this, entry.getPackageName(), entry.getComponentName(),
                    entry.getUserId(StartMenuService.this), null, false, false);
        });

        if (pref.getBoolean("transparent_start_menu", false))
            layout.findViewById(R.id.search_view_child_layout).setBackgroundColor(0);
    } else
        searchViewLayout.setVisibility(View.GONE);

    textView = (TextView) layout.findViewById(R.id.no_apps_found);

    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiverAlt);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver);

    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiver,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU"));
    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiverAlt,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU_ALT"));
    LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver,
            new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU"));

    handler = new Handler();
    refreshApps(true);

    windowManager.addView(layout, params);
}

From source file:com.jgraves.achievementunlocked.AchievementsList_Fragment.java

private void addAchievementToList(Long id, String name, int points) {
    Log.i(ExploraApp.TAG, "Adding achievement image request of id " + id + " with height, " + imageViewHeight);
    FrameLayout fl = new FrameLayout(getActivity());
    touchMap.put(fl, id);/*from   w  ww.  java2 s.c o m*/
    fl.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Long id = touchMap.get(v);
            Log.i(ExploraApp.TAG, "TOUCHED " + id);
            Intent intent = new Intent(getActivity(), Activity_AchievementInfo.class);
            intent.putExtra("achievement_id", Long.toString(id));
            startActivity(intent);
        }
    });
    TextView tv_name = new TextView(getActivity());
    TextView tv_points = new TextView(getActivity());
    ImageView iv = new ImageView(getActivity());
    fl.setMinimumHeight(imageViewHeight);
    fl.setMinimumWidth(ExploraApp.screenWidth);
    robotoTypeface = Typeface.createFromAsset(getActivity().getAssets(), "Roboto-Thin.ttf");
    tv_name.setText(name);
    tv_name.setTextSize(15f);
    tv_points.setTextSize(15f);
    tv_name.setTypeface(robotoTypeface);
    tv_points.setTypeface(robotoTypeface);
    tv_points.setText(Integer.toString(points));
    tv_points.setGravity(Gravity.RIGHT);
    tv_points.setTextColor(Color.WHITE);
    tv_name.setTextColor(Color.WHITE);
    iv.setMinimumHeight(imageViewHeight);
    iv.setMinimumWidth(ExploraApp.screenWidth);
    fl.addView(iv);
    fl.addView(tv_name);
    fl.addView(tv_points);
    ll_images_container.addView(fl);
    sv_images.bringChildToFront(mQuickReturnView);
    DefaultImageListener listener = new DefaultImageListener(iv);
    ImageRequest imageRequest = new ImageRequest(
            ExploraApp.url_main + "/achievement/" + id + "/photo?y=" + imageViewHeight + "&x="
                    + ExploraApp.screenWidth,
            listener, ExploraApp.screenWidth, imageViewHeight, Bitmap.Config.ARGB_8888, listener);
    ExploraApp.mRequestQueue.add(imageRequest);
}

From source file:com.iangclifton.android.floatlabel.FloatLabel.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) {
    if (child.getVisibility() != GONE) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();

        int childLeft;
        final int childTop = parentTop + lp.topMargin;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }//from  w  w  w.ja  v a  2 s . co m

        final int layoutDirection;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutDirection = LAYOUT_DIRECTION_LTR;
        } else {
            layoutDirection = getLayoutDirection();
        }

        final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection);

        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.RIGHT:
            childLeft = parentRight - width - lp.rightMargin;
            break;
        case Gravity.LEFT:
        default:
            childLeft = parentLeft + lp.leftMargin;
        }

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:com.abewy.android.apps.klyph.app.MainActivity.java

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

    /*//  w ww. ja v  a  2 s. c o m
     * if (KlyphSession.getSessionUserName() != null)
     * {
     * loggedIn = true;
     * setTitle(KlyphSession.getSessionUserName());
     * }
     * else
     * {
     * if (KlyphFlags.IS_PRO_VERSION == true)
     * setTitle(R.string.app_pro_name);
     * else
     * setTitle(R.string.app_name);
     * }
     */
    setTitle("");

    if (Session.getActiveSession() == null || KlyphSession.getSessionUserId() == null
            || (Session.getActiveSession() != null && Session.getActiveSession().isOpened() == false)) {
        getActionBar().hide();
        getFragmentManager().beginTransaction().add(R.id.main, new LoginFragment(), FRAGMENT_TAG).commit();
    }

    // notificationsFragment.setHasOptionsMenu(false);
    adContainer = (ViewGroup) findViewById(R.id.ad);

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    drawerToggle = new ActionBarDrawerToggle(this, drawer, AttrUtil.getResourceId(this, R.attr.drawerIcon),
            R.string.open, R.string.close) {
        @Override
        public void onDrawerOpened(View view) {
            Log.d("MainActivity.onCreate(...).new ActionBarDrawerToggle() {...}", "onDrawerOpened: ");
            super.onDrawerOpened(view);

            Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_TAG);

            if (drawer.isDrawerOpen(Gravity.RIGHT)) {
                // drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, Gravity.RIGHT);

                if (notificationsFragment != null) {
                    notificationsFragment.setHasOptionsMenu(true);
                    notificationsFragment.onOpenPane();
                }

                if (fragment != null)
                    fragment.setHasOptionsMenu(false);
            } else if (drawer.isDrawerOpen(Gravity.LEFT)) {

                if (notificationsFragment != null) {
                    notificationsFragment.setHasOptionsMenu(false);
                }

                if (fragment != null)
                    fragment.setHasOptionsMenu(true);
            }

            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);

            drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);

            if (!drawer.isDrawerOpen(Gravity.RIGHT)) {
                if (notificationsFragment != null)
                    notificationsFragment.setHasOptionsMenu(false);

                Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_TAG);

                if (fragment != null)
                    fragment.setHasOptionsMenu(true);
            }
            invalidateOptionsMenu();
        }
    };

    drawer.setDrawerListener(drawerToggle);

    final List<String> labels = KlyphPreferences.getLeftDrawerMenuLabels();
    classes = new ArrayList<String>(KlyphPreferences.getLeftDrawerMenuClasses());
    classes.add("com.abewy.android.apps.klyph.fragment.UserTimeline");
    navAdapter = new DrawerLayoutAdapter(getActionBar().getThemedContext(), R.layout.item_drawer_layout,
            labels);

    final ListView navList = (ListView) findViewById(R.id.drawer);

    // Setting drawers max width
    int maxWidth = getResources().getDimensionPixelSize(R.dimen.max_drawer_layout_width);

    int w = Math.min(KlyphDevice.getDeviceWidth(), KlyphDevice.getDeviceHeight())
            - getResources().getDimensionPixelSize(R.dimen.dip_64);

    int finalWidth = Math.min(maxWidth, w);

    LayoutParams params = ((View) navList.getParent()).getLayoutParams();
    params.width = finalWidth;
    ((View) navList.getParent()).setLayoutParams(params);

    final View notificationContainer = findViewById(R.id.notifications_container);
    params = notificationContainer.getLayoutParams();
    params.width = finalWidth;
    notificationContainer.setLayoutParams(params);

    // End max width
    navList.setFadingEdgeLength(0);
    navList.setVerticalFadingEdgeEnabled(false);
    navList.setAdapter(navAdapter);

    navList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int pos, long id) {
            updateContent(pos);
            drawer.closeDrawer(Gravity.LEFT);
        }
    });

    // Try to use more data here. ANDROID_ID is a single point of attack.
    // String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

    // Library calls this when it's done.
    // mLicenseCheckerCallback = new MyLicenseCheckerCallback();

    // Construct the LicenseChecker with a policy.
    // mChecker = new LicenseChecker(this, new ServerManagedPolicy(this, new AESObfuscator(SALT, getPackageName(), deviceId)), BASE64_PUBLIC_KEY);

    // mChecker.checkAccess(mLicenseCheckerCallback)

    // Facebook HashKey
    if (KlyphFlags.LOG_FACEBOOK_HASH)
        FacebookUtil.logHash(this);

    // Hierarchy View Connector
    if (KlyphFlags.ENABLE_HIERACHY_VIEW_CONNECTOR)
        HierachyViewUtil.connectHierarchyView(this);
}

From source file:com.facebook.react.flat.RCTText.java

@ReactProp(name = ViewProps.TEXT_ALIGN)
public void setTextAlign(@Nullable String textAlign) {
    if (textAlign == null || "auto".equals(textAlign)) {
        mAlignment = Gravity.NO_GRAVITY;
    } else if ("left".equals(textAlign)) {
        // left and right may yield potentially different results (relative to non-nodes) in cases
        // when supportsRTL="true" in the manifest.
        mAlignment = Gravity.LEFT;/*from   ww  w  . j av a2  s. c  o  m*/
    } else if ("right".equals(textAlign)) {
        mAlignment = Gravity.RIGHT;
    } else if ("center".equals(textAlign)) {
        mAlignment = Gravity.CENTER;
    } else {
        throw new JSApplicationIllegalArgumentException("Invalid textAlign: " + textAlign);
    }

    notifyChanged(false);
}

From source file:com.abewy.android.apps.openklyph.app.MainActivity.java

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

    /*//from www .j av  a2s . co  m
     * if (KlyphSession.getSessionUserName() != null)
     * {
     * loggedIn = true;
     * setTitle(KlyphSession.getSessionUserName());
     * }
     * else
     * {
     * if (KlyphFlags.IS_PRO_VERSION == true)
     * setTitle(R.string.app_pro_name);
     * else
     * setTitle(R.string.app_name);
     * }
     */
    setTitle("");

    if (Session.getActiveSession() == null || KlyphSession.getSessionUserId() == null
            || (Session.getActiveSession() != null && Session.getActiveSession().isOpened() == false)) {
        getActionBar().hide();
        getFragmentManager().beginTransaction().add(R.id.main, new LoginFragment(), FRAGMENT_TAG).commit();
    }

    // notificationsFragment.setHasOptionsMenu(false);
    adContainer = (ViewGroup) findViewById(R.id.ad);

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    drawerToggle = new ActionBarDrawerToggle(this, drawer, AttrUtil.getResourceId(this, R.attr.drawerIcon),
            R.string.open, R.string.close) {
        @Override
        public void onDrawerOpened(View view) {
            Log.d("MainActivity.onCreate(...).new ActionBarDrawerToggle() {...}", "onDrawerOpened: ");
            super.onDrawerOpened(view);

            Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_TAG);

            if (drawer.isDrawerOpen(Gravity.RIGHT)) {
                // drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, Gravity.RIGHT);

                if (notificationsFragment != null) {
                    notificationsFragment.setHasOptionsMenu(true);
                    notificationsFragment.onOpenPane();
                }

                if (fragment != null)
                    fragment.setHasOptionsMenu(false);
            } else if (drawer.isDrawerOpen(Gravity.LEFT)) {

                if (notificationsFragment != null) {
                    notificationsFragment.setHasOptionsMenu(false);
                }

                if (fragment != null)
                    fragment.setHasOptionsMenu(true);
            }

            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);

            drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);

            if (!drawer.isDrawerOpen(Gravity.RIGHT)) {
                if (notificationsFragment != null)
                    notificationsFragment.setHasOptionsMenu(false);

                Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_TAG);

                if (fragment != null)
                    fragment.setHasOptionsMenu(true);
            }
            invalidateOptionsMenu();
        }
    };

    drawer.setDrawerListener(drawerToggle);

    final List<String> labels = KlyphPreferences.getLeftDrawerMenuLabels();
    classes = new ArrayList<String>(KlyphPreferences.getLeftDrawerMenuClasses());
    classes.add("com.abewy.android.apps.openklyph.fragment.UserTimeline");
    navAdapter = new DrawerLayoutAdapter(getActionBar().getThemedContext(), R.layout.item_drawer_layout,
            labels);

    final ListView navList = (ListView) findViewById(R.id.drawer);

    // Setting drawers max width
    int maxWidth = getResources().getDimensionPixelSize(R.dimen.max_drawer_layout_width);

    int w = Math.min(KlyphDevice.getDeviceWidth(), KlyphDevice.getDeviceHeight())
            - getResources().getDimensionPixelSize(R.dimen.dip_64);

    int finalWidth = Math.min(maxWidth, w);

    LayoutParams params = ((View) navList.getParent()).getLayoutParams();
    params.width = finalWidth;
    ((View) navList.getParent()).setLayoutParams(params);

    final View notificationContainer = findViewById(R.id.notifications_container);
    params = notificationContainer.getLayoutParams();
    params.width = finalWidth;
    notificationContainer.setLayoutParams(params);

    // End max width
    navList.setFadingEdgeLength(0);
    navList.setVerticalFadingEdgeEnabled(false);
    navList.setAdapter(navAdapter);

    navList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int pos, long id) {
            updateContent(pos);
            drawer.closeDrawer(Gravity.LEFT);
        }
    });

    // Try to use more data here. ANDROID_ID is a single point of attack.
    // String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

    // Library calls this when it's done.
    // mLicenseCheckerCallback = new MyLicenseCheckerCallback();

    // Construct the LicenseChecker with a policy.
    // mChecker = new LicenseChecker(this, new ServerManagedPolicy(this, new AESObfuscator(SALT, getPackageName(), deviceId)), BASE64_PUBLIC_KEY);

    // mChecker.checkAccess(mLicenseCheckerCallback)

    // Facebook HashKey
    if (KlyphFlags.LOG_FACEBOOK_HASH)
        FacebookUtil.logHash(this);

    // Hierarchy View Connector
    if (KlyphFlags.ENABLE_HIERACHY_VIEW_CONNECTOR)
        HierachyViewUtil.connectHierarchyView(this);
}

From source file:com.vinfotech.widget.FloatLabel.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void layoutChild(View child, int parentLeft, int parentTop, int parentRight, int parentBottom) {
    if (child.getVisibility() != GONE) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();

        int childLeft;
        final int childTop = parentTop + lp.topMargin;

        int gravity = lp.gravity;
        if (gravity == -1) {
            gravity = Gravity.TOP | Gravity.START;
        }/*  w  w  w. j a  va 2  s. com*/

        final int layoutDirection;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutDirection = LAYOUT_DIRECTION_LTR;
        } else {
            layoutDirection = getLayoutDirection();
        }

        final int absoluteGravity = GravityCompat.getAbsoluteGravity(gravity, layoutDirection);

        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin;
            break;
        case Gravity.RIGHT:
            childLeft = parentRight - width - lp.rightMargin;
            break;
        case Gravity.LEFT:

        default:
            childLeft = parentLeft + lp.leftMargin;
        }

        child.layout(childLeft, childTop, childLeft + width, childTop + height);
    }
}

From source file:com.scoreflex.ScoreflexView.java

/**
 * The constructor of the view./*from  w ww  . j  av  a  2s . c  om*/
 * @param activity The activity holding the view.
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public ScoreflexView(Activity activity, AttributeSet attrs, int defStyle) {
    super(activity, attrs, defStyle);

    // Keep a reference on the activity
    mParentActivity = activity;

    // Default layout params
    if (null == getLayoutParams()) {
        setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                Scoreflex.getDensityIndependantPixel(R.dimen.scoreflex_panel_height)));
    }

    // Set our background color
    setBackgroundColor(getContext().getResources().getColor(R.color.scoreflex_background_color));

    // Create the top bar
    View topBar = new View(getContext());
    topBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height), Gravity.TOP));
    topBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.scoreflex_gradient_background));
    addView(topBar);

    // Create the retry button
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mErrorLayout = (ViewGroup) inflater.inflate(R.layout.scoreflex_error_layout, null);
    if (mErrorLayout != null) {

        // Configure refresh button
        Button refreshButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_retry_button);
        if (null != refreshButton) {
            refreshButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (null == Scoreflex.getPlayerId()) {
                        setUserInterfaceState(new LoadingState());
                        loadUrlAfterLoggedIn(mInitialResource, mInitialRequestParams);
                    } else if (null == mWebView.getUrl()) {
                        setResource(mInitialResource);
                    } else {
                        mWebView.reload();
                    }
                }
            });
        }

        // Configure cancel button
        Button cancelButton = (Button) mErrorLayout.findViewById(R.id.scoreflex_cancel_button);
        if (null != cancelButton) {
            cancelButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    close();
                }
            });
        }

        // Get hold of the message view
        mMessageView = (TextView) mErrorLayout.findViewById(R.id.scoreflex_error_message_view);
        addView(mErrorLayout);

    }

    // Create the close button
    mCloseButton = new ImageButton(getContext());
    Drawable closeButtonDrawable = getResources().getDrawable(R.drawable.scoreflex_close_button);
    int closeButtonMargin = (int) ((getResources().getDimensionPixelSize(R.dimen.scoreflex_topbar_height)
            - closeButtonDrawable.getIntrinsicHeight()) / 2.0f);
    FrameLayout.LayoutParams closeButtonLayoutParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
            Gravity.TOP | Gravity.RIGHT);
    closeButtonLayoutParams.setMargins(0, closeButtonMargin, closeButtonMargin, 0);
    mCloseButton.setLayoutParams(closeButtonLayoutParams);
    mCloseButton.setImageDrawable(closeButtonDrawable);
    mCloseButton.setBackgroundDrawable(null);
    mCloseButton.setPadding(0, 0, 0, 0);
    mCloseButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            close();
        }
    });
    addView(mCloseButton);

    // Create the web view
    mWebView = new WebView(mParentActivity);
    mWebView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    // mWebView.setBackgroundColor(Color.RED);
    mWebView.setWebViewClient(new ScoreflexWebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d("Scoreflex", "javascript Error: "
                    + String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId()));
            return true;
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg) {
            // mtbActivity.mUploadMessage = uploadMsg;
            mUploadMessage = uploadMsg;

            String fileName = "picture.jpg";
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, fileName);
            // mOutputFileUri = mParentActivity.getContentResolver().insert(
            // MediaStore.Images.Media.DATA, values);
            final List<Intent> cameraIntents = new ArrayList<Intent>();
            final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            final PackageManager packageManager = mParentActivity.getPackageManager();
            final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
            for (ResolveInfo res : listCam) {
                final String packageName = res.activityInfo.packageName;
                final Intent intent = new Intent(captureIntent);
                intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
                intent.setPackage(packageName);
                cameraIntents.add(intent);
            }

            // Filesystem.
            final Intent galleryIntent = new Intent();
            galleryIntent.setType("image/*");
            galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

            // Chooser of filesystem options.
            final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source please");

            // Add the camera options.
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));

            mParentActivity.startActivityForResult(chooserIntent, Scoreflex.FILECHOOSER_RESULTCODE);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
            openFileChooser(uploadMsg);
        }

        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            openFileChooser(uploadMsg);
        }
    });
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setDatabasePath(
            getContext().getFilesDir().getPath() + "/data/" + getContext().getPackageName() + "/databases/");
    addView(mWebView);

    TypedArray a = mParentActivity.obtainStyledAttributes(attrs, R.styleable.ScoreflexView, defStyle, 0);
    String resource = a.getString(R.styleable.ScoreflexView_resource);
    if (null != resource)
        setResource(resource);

    a.recycle();

    // Create the animated spinner

    mProgressBar = (ProgressBar) ((LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.scoreflex_progress_bar, null);
    mProgressBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
    addView(mProgressBar);
    LocalBroadcastManager.getInstance(activity).registerReceiver(mLoginReceiver,
            new IntentFilter(Scoreflex.INTENT_USER_LOGED_IN));
    setUserInterfaceState(new InitialState());
}

From source file:com.gome.haoyuangong.views.MyViewPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;//www . j  a  v a2s.  co m
    tabView.setTag("tavView");
    tabView.setId(index);
    //      tabView.setFocusable(true);
    //      tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    //tabView.setPadding(pointSize, 0, pointSize, 0);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tabView.setMaxLines(1);
    tabView.setGravity(Gravity.CENTER);
    XmlPullParser xrp = getResources().getXml(R.drawable.tab_button);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
        tabView.setTextColor(csl);
    } catch (Exception e) {

    }

    if (iconResId != 0) {
        //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabView.setLayoutParams(tabTvL);

    //measureView(tabView);

    LinearLayout layoutWraper1 = new LinearLayout(getContext());
    LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1);
    layoutWraper1.setLayoutParams(lp1);
    layoutWraper1.setGravity(Gravity.CENTER);
    layoutWraper1.setFocusable(true);
    layoutWraper1.setOnClickListener(mTabClickListener);
    layoutWraper1.setPadding(0, 0, 0, 0);
    layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red);

    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setTag("framelayout");
    //      FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5));
    FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    //      frameLayout.setPadding(padding, padding, padding, padding);
    frameLayout.setLayoutParams(fl2);
    //      frameLayout.addView(tabView);

    View hasNew = new View(getContext());
    FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize);
    hasNew.setLayoutParams(hasNewL);
    hasNewL.gravity = Gravity.TOP | Gravity.RIGHT;
    hasNew.setBackgroundResource(R.drawable.shape_circle);

    FrameLayout tabTvframe = new FrameLayout(getContext());
    FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabTvframeL.gravity = Gravity.CENTER;
    tabTvframe.setLayoutParams(tabTvframeL);
    tabTvframe.addView(tabView);
    tabTvframe.addView(hasNew);
    hasNew.setVisibility(View.GONE);

    frameLayout.addView(tabTvframe);

    layoutWraper1.addView(frameLayout);

    tabView.setTagView(hasNew);

    mTabLayout.addView(layoutWraper1, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    Resources resources = getResources();
    Activity context = (Activity) mContext;

    // layout FAB and follow circles
    int fabWidth = mFAB.getMeasuredWidth();
    int fabHeight = mFAB.getMeasuredHeight();
    int bottomInsets = Utils.getInsetsBottom(context, this);

    int fabX = 0;
    int fabY = 0;
    if (mGravity == (Gravity.BOTTOM | Gravity.RIGHT)) {
        int marginX = Utils.dpToPx(mMarginSize, resources);
        int marginY = Utils.dpToPx(mMarginSize, resources) + bottomInsets;
        fabX = right - fabWidth - marginX;
        fabY = bottom - fabHeight - marginY;
        mFAB.layout(fabX, fabY, fabX + fabWidth, fabY + fabHeight);
    } else if (mGravity == (Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)) {
        int marginY = Utils.dpToPx(mMarginSize, resources) + bottomInsets;
        fabX = right / 2 - fabWidth / 2;
        fabY = bottom - fabHeight - marginY;
        mFAB.layout(fabX, fabY, fabX + fabWidth, fabY + fabHeight);
    } else {/*from   w ww. ja va 2 s .  c  om*/
        throw new IllegalStateException("gravity only support bottom center and bottom right");
    }

    int fabCenterX = fabX + fabWidth / 2;
    int fabCenterY = fabY + fabHeight / 2;

    for (ImageButton circle : mFollowCircles) {
        int x = fabCenterX - circle.getWidth() / 2;
        int y = fabCenterY - circle.getHeight() / 2;
        circle.layout(x, y, x + circle.getMeasuredWidth(), y + circle.getMeasuredHeight());
    }

    int x = fabCenterX - mRevealCircle.getWidth() / 2;
    int y = fabCenterY - mRevealCircle.getHeight() / 2;
    mRevealCircle.layout(x, y, x + mRevealCircle.getMeasuredWidth(), y + mRevealCircle.getMeasuredHeight());

    //layout menu items
    layoutMenuItems(left, top, right, bottom);
}