Example usage for android.view Gravity START

List of usage examples for android.view Gravity START

Introduction

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

Prototype

int START

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

Click Source Link

Document

Push object to x-axis position at the start of its container, not changing its size.

Usage

From source file:me.xiaopan.android.spear.sample.activity.MainActivity.java

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

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.drawer_open, R.string.drawer_close);
    drawerToggle.syncState();//  w  w w  .j  a  v  a 2  s  . c om
    drawerLayout.setDrawerListener(drawerToggle);

    drawerLayout.setDrawerShadow(R.drawable.shape_drawer_shadow_down_left, Gravity.START);

    // ????
    ViewGroup.LayoutParams params = leftMenuView.getLayoutParams();
    params.width = (int) (getResources().getDisplayMetrics().widthPixels * 0.6);
    leftMenuView.setLayoutParams(params);

    starButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawerLayout.closeDrawer(Gravity.START);

            if (type != Type.STAR) {
                getSupportActionBar().setTitle("");
                AnimationUtils.visibleViewByAlpha(starTabStrip);
                AnimationUtils.invisibleViewByAlpha(appListTabStrip);
                type = Type.STAR;
                getSupportFragmentManager().beginTransaction()
                        .setCustomAnimations(R.anim.window_push_enter, R.anim.window_push_exit)
                        .replace(R.id.frame_main_content, new StarFragment()).commit();
            }
        }
    });

    searchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawerLayout.closeDrawer(Gravity.START);

            if (type != Type.SEARCH) {
                AnimationUtils.invisibleViewByAlpha(starTabStrip);
                AnimationUtils.invisibleViewByAlpha(appListTabStrip);
                type = Type.SEARCH;
                getSupportFragmentManager().beginTransaction()
                        .setCustomAnimations(R.anim.window_push_enter, R.anim.window_push_exit)
                        .replace(R.id.frame_main_content, new SearchFragment()).commit();
            }
        }
    });

    photoAlbumButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawerLayout.closeDrawer(Gravity.START);

            if (type != Type.LOCAL_PHOTO_ALBUM) {
                AnimationUtils.invisibleViewByAlpha(starTabStrip);
                AnimationUtils.invisibleViewByAlpha(appListTabStrip);
                getSupportActionBar().setTitle("");
                type = Type.LOCAL_PHOTO_ALBUM;
                getSupportFragmentManager().beginTransaction()
                        .setCustomAnimations(R.anim.window_push_enter, R.anim.window_push_exit)
                        .replace(R.id.frame_main_content, new PhotoAlbumFragment()).commit();
            }
        }
    });

    appListButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawerLayout.closeDrawer(Gravity.START);

            if (type != Type.APP_LIST) {
                getSupportActionBar().setTitle("APP");
                AnimationUtils.invisibleViewByAlpha(starTabStrip);
                AnimationUtils.visibleViewByAlpha(appListTabStrip);
                type = Type.APP_LIST;
                getSupportFragmentManager().beginTransaction()
                        .setCustomAnimations(R.anim.window_push_enter, R.anim.window_push_exit)
                        .replace(R.id.frame_main_content, new AppListFragment()).commit();
            }
        }
    });

    aboutButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawerLayout.closeDrawer(Gravity.START);

            if (type != Type.ABOUT) {
                AnimationUtils.invisibleViewByAlpha(starTabStrip);
                AnimationUtils.invisibleViewByAlpha(appListTabStrip);
                getSupportActionBar().setTitle("");
                type = Type.ABOUT;
                getSupportFragmentManager().beginTransaction()
                        .setCustomAnimations(R.anim.window_push_enter, R.anim.window_push_exit)
                        .replace(R.id.frame_main_content, new AboutFragment()).commit();
            }
        }
    });

    starTabStrip.setTabViewFactory(new TitleTabFactory(new String[] { "", "??" }, getBaseContext()));
    appListTabStrip.setTabViewFactory(
            new TitleTabFactory(new String[] { "", "" }, getBaseContext()));

    appListButton.performClick();
}

From source file:org.amahi.anywhere.activity.ServerActivity.java

private void setUpNavigationDrawer() {
    this.navigationDrawerToggle = buildNavigationDrawerToggle();

    getDrawer().setDrawerListener(this);
    getDrawer().setDrawerShadow(R.drawable.bg_shadow_drawer, Gravity.START);
}

From source file:com.github.pennyfive.cinemafinlando.ui.activity.generic.DrawerActivity.java

public final void setActionBarNavigationMode(int mode) {
    navigationMode = mode;/*from w  ww .j av a 2 s  .  c o  m*/
    if (drawer == null || !drawer.isDrawerOpen(Gravity.START)) {
        getActionBar().setNavigationMode(mode);
    }
}

From source file:andrupal.oauth.sample.HomeActivity.java

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

    setActionBarIcon(R.drawable.ic_ab_drawer);

    drawer = (DrawerLayout) findViewById(R.id.drawer);
    drawer.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
}

From source file:org.docrj.smartcard.reader.NavDrawer.java

public NavDrawer(Activity activity, Bundle inState, int resId, DrawerLayout drawerLayout, Toolbar toolbar) {
    mActivity = activity;//from  w w  w.j  av a 2  s.com
    mResId = resId;
    mDrawerLayout = drawerLayout;

    // this only takes effect on Lollipop, or when using translucentStatusBar on Kitkat
    drawerLayout.setStatusBarBackgroundColor(activity.getResources().getColor(R.color.primary));
    mParentItem = drawerLayout.findViewById(resId);
    mParentItem.setActivated(true);

    mDrawerToggle = new ActionBarDrawerToggle(activity, drawerLayout, toolbar, R.string.app_name,
            R.string.app_name) {

        /** called when a drawer has settled in a completely closed state */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            // force call to onPrepareOptionsMenu()
            mActivity.invalidateOptionsMenu();
        }

        /** called when a drawer has settled in a completely open state */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // force call to onPrepareOptionsMenu()
            mActivity.invalidateOptionsMenu();
        }
    };
    drawerLayout.setDrawerListener(mDrawerToggle);

    View appSelect = drawerLayout.findViewById(R.id.app_select);
    View batchSelect = drawerLayout.findViewById(R.id.batch_select);
    View emvRead = drawerLayout.findViewById(R.id.emv_read);
    View apps = drawerLayout.findViewById(R.id.apps);
    View settings = drawerLayout.findViewById(R.id.settings);

    appSelect.setOnClickListener(mClickListener);
    batchSelect.setOnClickListener(mClickListener);
    emvRead.setOnClickListener(mClickListener);
    apps.setOnClickListener(mClickListener);
    settings.setOnClickListener(mClickListener);

    if (inState != null) {
        if (inState.getBoolean("drawer_open")) {
            drawerLayout.openDrawer(Gravity.START | Gravity.LEFT);
        }
    }
}

From source file:com.android.fastexample.ui.activity.DrawerActivity.java

/**
 * Initializes the list that controls which fragment will be shown.
 *///w  w  w.  j ava 2 s  .c o m
private void initializeList() {
    mListView = (ListView) findViewById(R.id.drawer_list);
    mListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    mListView.setAdapter(mListAdapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            mFragmentSwitcher.setCurrentItem(position);
            mDrawerLayout.closeDrawer(Gravity.START);
        }
    });
}

From source file:com.andryr.musicplayer.fragments.LibraryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tab_layout);
    tabLayout.setupWithViewPager(mViewPager);

    MainActivity activity = (MainActivity) getActivity();

    Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);

    DrawerLayout drawerLayout = activity.getDrawerLayout();

    activity.setSupportActionBar(toolbar);

    ToolbarDrawerToggle drawerToggle = new ToolbarDrawerToggle(activity, drawerLayout, toolbar,
            new int[] { Gravity.START });
    drawerLayout.setDrawerListener(drawerToggle);
    return rootView;
}

From source file:com.github.xizzhu.simpletooltip.sample.MainActivity.java

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

    setContentView(R.layout.activity_main);
    findViewById(R.id.top_left_button).setOnClickListener(new View.OnClickListener() {
        @Override/*from ww w  .  jav a2 s. c  o  m*/
        public void onClick(View v) {
            showToolTipView(v, Gravity.RIGHT, "Simple tool tip!",
                    ContextCompat.getColor(MainActivity.this, R.color.blue));
        }
    });
    findViewById(R.id.top_right_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showToolTipView(v, Gravity.BOTTOM, "It is yet another very simple tool tip!",
                    ContextCompat.getColor(MainActivity.this, R.color.green));
        }
    });
    findViewById(R.id.central_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showToolTipView(v, Gravity.END, "It is a very simple tool tip in the center!",
                    ContextCompat.getColor(MainActivity.this, R.color.magenta));
        }
    });
    findViewById(R.id.bottom_left_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showToolTipView(v, Gravity.TOP, "Tool tip, once more!",
                    ContextCompat.getColor(MainActivity.this, R.color.maroon));
        }
    });
    findViewById(R.id.bottom_right_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showToolTipView(v, Gravity.LEFT, "Magical tool tip!",
                    ContextCompat.getColor(MainActivity.this, R.color.navy));
        }
    });

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showToolTipViewWithParent((Button) v, Gravity.BOTTOM);
        }
    };
    findViewById(R.id.button1).setOnClickListener(listener);
    findViewById(R.id.button2).setOnClickListener(listener);
    findViewById(R.id.button3).setOnClickListener(listener);
    findViewById(R.id.button4).setOnClickListener(listener);
    findViewById(R.id.button5).setOnClickListener(listener);
    findViewById(R.id.button6).setOnClickListener(listener);
    findViewById(R.id.button7).setOnClickListener(listener);

    showToolTipView(findViewById(R.id.central_button), Gravity.START, "A simple tool tip!",
            ContextCompat.getColor(MainActivity.this, R.color.magenta), 750L);
}

From source file:com.klinker.android.twitter.listeners.MainDrawerClickListener.java

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    context.sendBroadcast(new Intent("com.klinker.android.twitter.MARK_POSITION"));
    if (i < 3) {
        if (MainDrawerArrayAdapter.current < 3) {
            new Handler().postDelayed(new Runnable() {
                @Override//  w w w. j  a  va 2s  .c o  m
                public void run() {
                    try {
                        drawer.closeDrawer(Gravity.START);
                    } catch (Exception e) {
                        // landscape mode
                    }
                }
            }, noWait ? 0 : 300);

            viewPager.setCurrentItem(i + extraPages, true);
        } else {
            final int pos = i;
            try {
                drawer.closeDrawer(Gravity.START);
            } catch (Exception e) {
                // landscape mode
            }

            Intent intent = new Intent(context, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            intent.putExtra("page_to_open", pos + extraPages);
            intent.putExtra("from_drawer", true);

            sharedPreferences.edit().putBoolean("should_refresh", false).commit();

            final Intent fIntent = intent;
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        context.startActivity(fIntent);
                        ((Activity) context).overridePendingTransition(0, 0);
                        ((Activity) context).finish();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }, noWait ? 0 : 400);

        }
    } else {
        final int pos = i;
        try {
            drawer.closeDrawer(Gravity.START);
        } catch (Exception e) {
            // landscape mode
        }
        Intent intent = null;

        switch (pos) {
        case 3:
            intent = new Intent(context, DiscoverPager.class);
            break;
        case 4:
            intent = new Intent(context, ListsActivity.class);
            break;
        case 5:
            intent = new Intent(context, FavoriteUsersActivity.class);
            break;
        case 6:
            intent = new Intent(context, RetweetActivity.class);
            break;
        case 7:
            intent = new Intent(context, FavoritesActivity.class);
            break;
        case 8:
            intent = new Intent(context, SavedSearchesActivity.class);
            break;
        }

        final Intent fIntent = intent;

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                try {
                    context.startActivity(fIntent);
                    ((Activity) context).finish();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, noWait ? 0 : 400);

    }

}

From source file:com.daiv.android.twitter.listeners.MainDrawerClickListener.java

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    context.sendBroadcast(new Intent("com.daiv.android.twitter.MARK_POSITION"));

    // we will increment until we find one that is in the set of shown elements
    for (int index = 0; index <= i; index++) {
        if (!set.contains(index + "")) {
            i++;/*from  ww  w  .j  a  v a 2s  .  c  om*/
        }
    }

    if (i < swipablePages) {
        if (MainDrawerArrayAdapter.current < swipablePages) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        drawer.closeDrawer(Gravity.START);
                    } catch (Exception e) {
                        // landscape mode
                    }
                }
            }, noWait ? 0 : 300);

            viewPager.setCurrentItem(i, true);
        } else {
            final int pos = i;
            try {
                drawer.closeDrawer(Gravity.START);
            } catch (Exception e) {
                // landscape mode
            }

            Intent intent = new Intent(context, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            intent.putExtra("page_to_open", pos);
            intent.putExtra("from_drawer", true);

            sharedPreferences.edit().putBoolean("should_refresh", false).commit();

            final Intent fIntent = intent;
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        context.startActivity(fIntent);
                        ((Activity) context).overridePendingTransition(0, 0);
                        ((Activity) context).finish();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }, noWait ? 0 : 400);

        }
    } else {
        final int pos = i;
        try {
            drawer.closeDrawer(Gravity.START);
        } catch (Exception e) {
            // landscape mode
        }

        Intent intent = null;

        final Intent fIntent = intent;

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                try {
                    context.startActivity(fIntent);
                    ((Activity) context).overridePendingTransition(0, 0);
                    ((Activity) context).finish();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, noWait ? 0 : 400);

    }

}