List of usage examples for android.support.v4.view GravityCompat START
int START
To view the source code for android.support.v4.view GravityCompat START.
Click Source Link
From source file:com.android.documentsui.DocumentsActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mRoots = DocumentsApplication.getRootsCache(this); setResult(Activity.RESULT_CANCELED); setContentView(R.layout.activity);// w w w . j a va2s . c om final Resources res = getResources(); mShowAsDialog = res.getBoolean(R.bool.show_as_dialog); if (mShowAsDialog) { // backgroundDimAmount from theme isn't applied; do it manually final WindowManager.LayoutParams a = getWindow().getAttributes(); a.dimAmount = 0.6f; getWindow().setAttributes(a); getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND); // Inset ourselves to look like a dialog final Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x); final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y); final int insetX = (size.x - width) / 2; final int insetY = (size.y - height) / 2; final Drawable before = getWindow().getDecorView().getBackground(); final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY); getWindow().getDecorView().setBackground(after); // Dismiss when touch down in the dimmed inset area getWindow().getDecorView().setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { final float x = event.getX(); final float y = event.getY(); if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) { finish(); return true; } } return false; } }); } else { // Non-dialog means we have a drawer mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerListener); mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START); mRootsContainer = findViewById(R.id.container_roots); } mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory); if (icicle != null) { mState = icicle.getParcelable(EXTRA_STATE); } else { buildDefaultState(); } // Hide roots when we're managing a specific root if (mState.action == ACTION_MANAGE) { if (mShowAsDialog) { findViewById(R.id.dialog_roots).setVisibility(View.GONE); } else { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } } if (mState.action == ACTION_CREATE) { final String mimeType = getIntent().getType(); final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE); SaveFragment.show(getFragmentManager(), mimeType, title); } if (mState.action == ACTION_GET_CONTENT) { final Intent moreApps = new Intent(getIntent()); moreApps.setComponent(null); moreApps.setPackage(null); RootsFragment.show(getFragmentManager(), moreApps); } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) { RootsFragment.show(getFragmentManager(), null); } if (!mState.restored) { if (mState.action == ACTION_MANAGE) { final Uri rootUri = getIntent().getData(); new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor()); } else { new RestoreStackTask().execute(); } } else { onCurrentDirectoryChanged(ANIM_NONE); } }
From source file:com.he5ed.lib.cloudprovider.picker.CloudPickerActivity.java
/** * @hide/*from www. j a va 2s . co m*/ */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cp_activity_picker); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); // lock right drawer from been swiped open drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); navigationView.setItemIconTintList(null); // remove the auto grey tint to keep icon color Menu menu = navigationView.getMenu(); CloudProvider cloudProvider = CloudProvider.getInstance(this); // check whether individual account is assigned String accountId = getIntent().getStringExtra(EXTRA_PICK_ACCOUNT_ID); if (!TextUtils.isEmpty(accountId)) { mAccounts = new CloudAccount[1]; mAccounts[0] = cloudProvider.getAccountById(accountId); } else { mAccounts = cloudProvider.getCloudAccounts(); } // populate navigation menu for (int i = 0; i < mAccounts.length; i++) { CloudAccount account = mAccounts[i]; MenuItem item = menu.add(0, i, 0, account.getUser().email); // use cloud API class reflection try { Class clazz = Class.forName(account.api); Field iconResource = clazz.getField("ICON_RESOURCE"); item.setIcon(iconResource.getInt(null)); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); item.setIcon(R.drawable.ic_cloud_black_24dp); } catch (IllegalAccessException e) { e.printStackTrace(); } item.setCheckable(true); } mFragmentManager = getSupportFragmentManager(); mItemFragment = (ItemFragment) mFragmentManager.findFragmentById(R.id.right_drawer_view); if (mItemFragment == null) { mItemFragment = new ItemFragment(); mFragmentManager.beginTransaction().add(R.id.right_drawer_view, mItemFragment).commit(); } mProgressBar = (ProgressBar) findViewById(R.id.progress_bar); mErrorView = (LinearLayout) findViewById(R.id.error_view); if (savedInstanceState != null) { switch (savedInstanceState.getInt("empty_view_visibility")) { case View.VISIBLE: mErrorView.setVisibility(View.VISIBLE); ImageView icon = (ImageView) mErrorView.findViewById(R.id.empty_icon_image_view); TextView title = (TextView) mErrorView.findViewById(R.id.empty_title_text_view); TextView detail = (TextView) mErrorView.findViewById(R.id.empty_detail_text_view); Bitmap bitmap = savedInstanceState.getParcelable("icon_drawable"); icon.setImageBitmap(bitmap); title.setText(savedInstanceState.getCharSequence("title_text")); detail.setText(savedInstanceState.getCharSequence("detail_text")); break; case View.INVISIBLE: mErrorView.setVisibility(View.INVISIBLE); break; case View.GONE: mErrorView.setVisibility(View.GONE); break; } } else { // open drawer on first load drawer.openDrawer(GravityCompat.START); } }
From source file:com.arlib.floatingsearchviewdemo.MainActivity.java
private void setupFloatingSearch() { mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { @Override//from w w w . j av a2s. c om public void onSearchTextChanged(String oldQuery, final String newQuery) { if (!oldQuery.equals("") && newQuery.equals("")) { mSearchView.clearSuggestions(); } else { //this shows the top left circular progress //you can call it where ever you want, but //it makes sense to do it when loading something in //the background. mSearchView.showProgress(); //simulates a query call to a data source //with a new query. DataHelper.findSuggestions(MainActivity.this, newQuery, 5, FIND_SUGGESTION_SIMULATED_DELAY, new DataHelper.OnFindSuggestionsListener() { @Override public void onResults(List<ColorSuggestion> results) { //this will swap the data and //render the collapse/expand animations as necessary mSearchView.swapSuggestions(results); //let the users know that the background //process has completed mSearchView.hideProgress(); } }); } Log.d(TAG, "onSearchTextChanged()"); } }); mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { @Override public void onSuggestionClicked(SearchSuggestion searchSuggestion) { ColorSuggestion colorSuggestion = (ColorSuggestion) searchSuggestion; DataHelper.findColors(MainActivity.this, colorSuggestion.getBody(), new DataHelper.OnFindColorsListener() { @Override public void onResults(List<ColorWrapper> results) { mSearchResultsAdapter.swapData(results); } }); Log.d(TAG, "onSuggestionClicked()"); } @Override public void onSearchAction(String query) { DataHelper.findColors(MainActivity.this, query, new DataHelper.OnFindColorsListener() { @Override public void onResults(List<ColorWrapper> results) { mSearchResultsAdapter.swapData(results); } }); Log.d(TAG, "onSearchAction()"); } }); mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() { @Override public void onFocus() { mSearchView.clearQuery(); //show suggestions when search bar gains focus (typically history suggestions) mSearchView.swapSuggestions(DataHelper.getHistory(MainActivity.this, 3)); Log.d(TAG, "onFocus()"); } @Override public void onFocusCleared() { Log.d(TAG, "onFocusCleared()"); } }); //handle menu clicks the same way as you would //in a regular activity mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() { @Override public void onActionMenuItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_change_colors) { mIsDarkSearchTheme = true; //demonstrate setting colors for items mSearchView.setBackgroundColor(Color.parseColor("#787878")); mSearchView.setViewTextColor(Color.parseColor("#e9e9e9")); mSearchView.setHintTextColor(Color.parseColor("#e9e9e9")); mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9")); mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9")); mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9")); mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9")); mSearchView.setDividerColor(Color.parseColor("#BEBEBE")); mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9")); } else { //just print action Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show(); } } }); //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHamburger" mSearchView.setOnLeftMenuClickListener(new FloatingSearchView.OnLeftMenuClickListener() { @Override public void onMenuOpened() { Log.d(TAG, "onMenuOpened()"); mDrawerLayout.openDrawer(GravityCompat.START); } @Override public void onMenuClosed() { Log.d(TAG, "onMenuClosed()"); } }); //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHome" mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() { @Override public void onHomeClicked() { Log.d(TAG, "onHomeClicked()"); } }); /* * Here you have access to the left icon and the text of a given suggestion * item after as it is bound to the suggestion list. You can utilize this * callback to change some properties of the left icon and the text. For example, you * can load the left icon images using your favorite image loading library, or change text color. * * * Important: * Keep in mind that the suggestion list is a RecyclerView, so views are reused for different * items in the list. */ mSearchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() { @Override public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) { ColorSuggestion colorSuggestion = (ColorSuggestion) item; String textColor = mIsDarkSearchTheme ? "#ffffff" : "#000000"; String textLight = mIsDarkSearchTheme ? "#bfbfbf" : "#787878"; if (colorSuggestion.getIsHistory()) { leftIcon.setImageDrawable( ResourcesCompat.getDrawable(getResources(), R.drawable.ic_history_black_24dp, null)); Util.setIconColor(leftIcon, Color.parseColor(textColor)); leftIcon.setAlpha(.36f); } else { leftIcon.setAlpha(0.0f); leftIcon.setImageDrawable(null); } textView.setTextColor(Color.parseColor(textColor)); String text = colorSuggestion.getBody().replaceFirst(mSearchView.getQuery(), "<font color=\"" + textLight + "\">" + mSearchView.getQuery() + "</font>"); textView.setText(Html.fromHtml(text)); } }); //listen for when suggestion list expands/shrinks in order to move down/up the //search results list mSearchView.setOnSuggestionsListHeightChanged(new FloatingSearchView.OnSuggestionsListHeightChanged() { @Override public void onSuggestionsListHeightChanged(float newHeight) { mSearchResultsList.setTranslationY(newHeight); } }); }
From source file:com.actionbarsherlock.app.ActionBarSherlockDrawerToggle.java
/** * Enable or disable the drawer indicator. The indicator defaults to * enabled./*w w w .ja v a 2 s .c om*/ * * <p> * When the indicator is disabled, the <code>ActionBar</code> will revert to * displaying the home-as-up indicator provided by the <code>Activity</code> * 's theme in the <code>android.R.attr.homeAsUpIndicator</code> attribute * instead of the animated drawer glyph. * </p> * * @param enable * true to enable, false to disable */ public void setDrawerIndicatorEnabled(boolean enable) { if (enable != mDrawerIndicatorEnabled) { if (enable) { mSetIndicatorInfo = IMPL.setActionBarUpIndicator(mSetIndicatorInfo, mActivity, mSlider, mDrawerLayout.isDrawerOpen(GravityCompat.START) ? mOpenDrawerContentDescRes : mCloseDrawerContentDescRes); } else { mSetIndicatorInfo = IMPL.setActionBarUpIndicator(mSetIndicatorInfo, mActivity, mThemeImage, 0); } mDrawerIndicatorEnabled = enable; } }
From source file:be.evias.cloudLogin.FragmentNavigationDrawer.java
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. *//*from w w w. j av a2 s . co m*/ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; /* set a custom shadow that overlays the main content when the drawer opens. */ mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); /* configure actionbar buttons. */ ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */ ) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) return; /* calls onPrepareOptionsMenu() */ getActivity().supportInvalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) return; if (!mUserLearnedDrawer) { /* The user manually opened the drawer; store this flag to prevent auto-showing the navigation drawer automatically in the future. */ mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } /* calls onPrepareOptionsMenu() */ getActivity().supportInvalidateOptionsMenu(); } }; /* If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, per the navigation drawer design guidelines. */ if (!mUserLearnedDrawer && !mFromSavedInstanceState) mDrawerLayout.openDrawer(mFragmentContainerView); /* Defer code dependent on restoration of previous instance state. */ mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
From source file:com.actionbarsherlock.plus.SherlockActionBarToggle.java
protected boolean isViewOpen() { switch (view_type) { case Slider:/*from ww w . ja v a2s. c o m*/ return !mSlidingPaneLayout.isOpen(); case Drawer: return mDrawerLayout.isDrawerOpen(GravityCompat.START); } return true; }
From source file:com.example.igorklimov.popularmoviesdemo.activities.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.by_popularity: Utility.setSortByPreference(this, 1); SyncAdapter.syncImmediately(this); reload();// w ww .j a v a 2s . c o m break; case R.id.by_release_date: Utility.setSortByPreference(this, 2); SyncAdapter.syncImmediately(this); reload(); break; case R.id.by_votes: Utility.setSortByPreference(this, 3); SyncAdapter.syncImmediately(this); reload(); break; case R.id.action_favorites: Utility.setSortByPreference(this, 4); SyncAdapter.syncImmediately(this); reload(); break; } mDrawer.closeDrawer(GravityCompat.START); return true; }
From source file:blackman.matt.infinitebrowser.NavigationDrawerFragment.java
/** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. *//* w ww . ja v a 2 s . c o m*/ public void setUp(int fragmentId, DrawerLayout drawerLayout) { mFragmentContainerView = getActivity().findViewById(fragmentId); mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.navigation_drawer_open, /* "open drawer" description for accessibility */ R.string.navigation_drawer_close /* "close drawer" description for accessibility */ ) { /** * Handles the drawer being closed. * * @param drawerView The drawer being closed. */ @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } /** * Handles the drawer being opened. * * @param drawerView The drawer being opened. */ @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } setUpListAdapter(); getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String boardRoot = "/tech/"; if (view instanceof TextView) { boardRoot = ((TextView) view).getText().toString(); } FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Board newBoard = Board.newInstance(boardRoot); fragmentTransaction.replace(R.id.container, newBoard, boardRoot); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); closeDrawer(); } }); // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { mDrawerLayout.openDrawer(mFragmentContainerView); } // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }
From source file:com.he5ed.lib.cloudprovider.picker.CloudPickerActivity.java
/** * @hide//w w w.j a v a 2 s . com */ @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else if (drawer.isDrawerOpen(GravityCompat.END)) { drawer.closeDrawer(GravityCompat.END); } else { super.onBackPressed(); } }
From source file:com.carver.paul.truesight.Ui.MainActivity.java
@Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. switch (item.getItemId()) { case R.id.about: startAboutActivity();//from ww w . ja v a 2 s. c om break; case R.id.demo: mPresenter.demoPhotoRecognition(); break; case R.id.use_last_photo: mPresenter.useLastPhoto(); break; } /* } else if (id == R.id.debug_specific_hue) { startDebugLineActivity(); }*/ /* } else if (id == R.id.debug_whole_process) { startDebugWholeProcessActivity();*/ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }