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.example.intern01.driverlicense.activity.MainActivity.java
@Override public void onBackPressed() { if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawers();/*from w w w .j av a 2 s .c o m*/ return; } // This code loads home fragment when back key is pressed // when user is in other fragment than home if (shouldLoadHomeFragOnBackPress) { // checking if user is on other navigation menu // rather than home if (navItemIndex != 0) { navItemIndex = 0; CURRENT_TAG = TAG_PROFILE; loadHomeFragment(); return; } } super.onBackPressed(); }
From source file:com.dm.material.dashboard.candybar.activities.CandyBarMainActivity.java
@Override public void onBackPressed() { if (mFragManager.getBackStackEntryCount() > 0) { clearBackStack();/* w w w .ja v a 2s.co m*/ return; } if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawers(); return; } if (!mFragmentTag.equals(TAG_HOME)) { mPosition = mLastPosition = 0; setFragment(getFragment(mPosition)); return; } super.onBackPressed(); }
From source file:com.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java
private void recalculate(int width) { // reset stateful objects that might change over measure passes paint.setTextSize(collapsedTextSize); displayText = new SpannableStringBuilder(title); // Calculate line height; ensure it' a multiple of 4dp to sit on the grid final float fourDip = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics()); Paint.FontMetricsInt fm = paint.getFontMetricsInt(); int fontHeight = Math.abs(fm.ascent - fm.descent) + fm.leading; final int baselineAlignedLineHeight = (int) (fourDip * (float) Math.ceil(lineHeightHint / fourDip)); lineSpacingAdd = Math.max(0, baselineAlignedLineHeight - fontHeight); // now create the layout with our desired insets & line height createLayout(width, lineSpacingAdd); // adjust the title top inset to vertically center text with the toolbar collapsedHeight = (int) Math.max(ViewUtils.getActionBarSize(getContext()), (fourDip + baselineAlignedLineHeight + fourDip)); titleInsetTop = (collapsedHeight - baselineAlignedLineHeight) / 2f; if (lineCount == 1) { // single line mode layout = null;/*from w w w.ja v a 2s . c om*/ collapsingText = new CollapsingTextHelper(this); collapsingText.setText(title); collapsingText.setCollapsedBounds(titleInsetStart, 0, width - titleInsetEnd, (int) collapsedHeight); collapsingText.setExpandedBounds(titleInsetStart, (int) titleInsetTop, width - titleInsetEnd, getMinimumHeight() - titleInsetBottom); collapsingText.setCollapsedTextColor(paint.getColor()); collapsingText.setExpandedTextColor(paint.getColor()); collapsingText.setCollapsedTextSize(collapsedTextSize); int expandedTitleTextSize = (int) Math.max(collapsedTextSize, ViewUtils.getSingleLineTextSize(displayText.toString(), paint, width - titleInsetStart - titleInsetEnd, collapsedTextSize, maxExpandedTextSize, 0.5f, getResources().getDisplayMetrics())); collapsingText.setExpandedTextSize(expandedTitleTextSize); collapsingText.setExpandedTextGravity(GravityCompat.START | Gravity.BOTTOM); collapsingText.setCollapsedTextGravity(GravityCompat.START | Gravity.CENTER_VERTICAL); collapsingText.setTypeface(paint.getTypeface()); textTop = getHeight() - titleInsetBottom - fontHeight; scrollRange = getMinimumHeight() - (int) collapsedHeight; } else { // multi-line mode // bottom align the text textTop = getDesiredHeight() - titleInsetBottom - layout.getHeight(); // pre-calculate at what scroll offsets lines should disappear scrollRange = (int) (textTop - titleInsetTop); final int fadeDistance = layout.getLineBottom(0) - layout.getLineBaseline(0); lines = new Line[lineCount]; for (int i = 1; i < lineCount; i++) { int lineBottomScrollOffset = scrollRange + ((lineCount - i - 1) * baselineAlignedLineHeight); lines[i] = new Line(layout.getLineStart(i), layout.getLineEnd(i), new TextColorSpan(paint.getColor()), lineBottomScrollOffset, lineBottomScrollOffset + fadeDistance); } } calculatedWithWidth = width; }
From source file:com.commonsware.cwac.crossport.v7.app.ActionBarDrawerToggle.java
/** * Synchronize the state of the drawer indicator/affordance with the linked DrawerLayout. * * <p>This should be called from your <code>Activity</code>'s * {@link Activity#onPostCreate(android.os.Bundle) onPostCreate} method to synchronize after * the DrawerLayout's instance state has been restored, and any other time when the state * may have diverged in such a way that the ActionBarDrawerToggle was not notified. * (For example, if you stop forwarding appropriate drawer events for a period of time.)</p> *//*from w w w . j a va2 s . co m*/ public void syncState() { if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { setPosition(1); } else { setPosition(0); } if (mDrawerIndicatorEnabled) { setActionBarUpIndicator((Drawable) mSlider, mDrawerLayout.isDrawerOpen(GravityCompat.START) ? mCloseDrawerContentDescRes : mOpenDrawerContentDescRes); } }
From source file:com.cerema.cloud2.ui.preview.PreviewImageActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { boolean returnValue = false; switch (item.getItemId()) { case android.R.id.home: if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); } else {/*from w ww. j a v a 2 s .com*/ backToDisplayActivity(); } returnValue = true; break; default: returnValue = super.onOptionsItemSelected(item); } return returnValue; }
From source file:cc.metapro.openct.myclass.ClassActivity.java
@Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else {/*from w w w. j av a 2s .co m*/ if (mExitState) { finish(); } else { Toast.makeText(this, R.string.one_more_press_to_exit, Toast.LENGTH_SHORT).show(); mExitState = true; new Handler().postDelayed(new Runnable() { @Override public void run() { mExitState = false; } }, 2000); } } }
From source file:com.cw.litenote.DrawerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { /////w w w . j av a 2s.c o m // StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() // // .detectDiskReads() // .detectDiskWrites() // .detectNetwork() // .penaltyLog() // .build()); // // StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() //// .detectLeakedSqlLiteObjects() //??? unmark this line will cause strict mode error // .penaltyLog() // .penaltyDeath() // .build()); /// super.onCreate(savedInstanceState); mDrawerActivity = this; setContentView(R.layout.drawer_activity); // Release mode: no debug message if (Define.CODE_MODE == Define.RELEASE_MODE) { OutputStream nullDev = new OutputStream() { public void close() { } public void flush() { } public void write(byte[] b) { } public void write(byte[] b, int off, int len) { } public void write(int b) { } }; System.setOut(new PrintStream(nullDev)); } //Log.d below can be disabled by applying proguard //1. enable proguard-android-optimize.txt in project.properties //2. be sure to use newest version to avoid build error //3. add the following in proguard-project.txt /*-assumenosideeffects class android.util.Log { public static boolean isLoggable(java.lang.String, int); public static int v(...); public static int i(...); public static int w(...); public static int d(...); public static int e(...); } */ Log.d("test log tag", "start app"); System.out.println("================start application =================="); System.out.println("DrawerActivity / onCreate"); UtilImage.getDefaultSacleInPercent(DrawerActivity.this); mAppTitle = getTitle(); mDrawerChildTitles = new ArrayList<String>(); Context context = getApplicationContext(); if (mDb != null) mDb.close(); mDb = new DB(context); mDb.initDrawerDb(mDb); if (mDb_tabs != null) mDb_tabs.close(); mDb_tabs = new DB(context, Util.getPref_lastTimeView_tabs_tableId(this)); mDb_tabs.initTabsDb(mDb_tabs); if (mDb_notes != null) mDb_tabs.close(); mDb_notes = new DB(context, Util.getPref_lastTimeView_notes_tableId(this)); mDb_notes.initNotesDb(mDb_notes); //Add note with the link String intentLink = addIntentLink(getIntent()); if (!Util.isEmptyString(intentLink)) { finish(); // for no active DrawerActivity case } else { // check DB final boolean ENABLE_DB_CHECK = false;//true;// if (ENABLE_DB_CHECK) { // list all drawer tables int drawerCount = mDb.getDrawerChildCount(); for (int drawerPos = 0; drawerPos < drawerCount; drawerPos++) { String drawerTitle = mDb.getDrawerChild_Title(drawerPos); DrawerActivity.mFocus_drawerChildPos = drawerPos; // list all tab tables int tabsTableId = mDb.getTabsTableId(drawerPos); System.out.println("--- tabs table Id = " + tabsTableId + ", drawer title = " + drawerTitle); mDb_tabs = new DB(context, tabsTableId); mDb_tabs.initTabsDb(mDb_tabs); int tabsCount = mDb_tabs.getTabsCount(true); for (int tabPos = 0; tabPos < tabsCount; tabPos++) { TabsHostFragment.mCurrent_tabIndex = tabPos; int tabId = mDb_tabs.getTabId(tabPos, true); int notesTableId = mDb_tabs.getNotesTableId(tabPos, true); String tabTitle = mDb_tabs.getTabTitle(tabPos, true); System.out.println(" --- tab Id = " + tabId); System.out.println(" --- notes table Id = " + notesTableId); System.out.println(" --- tab title = " + tabTitle); mLastOkTabId = tabId; try { mDb_notes = new DB(context, String.valueOf(notesTableId)); mDb_notes.initNotesDb(mDb_notes); mDb_notes.doOpenNotes(); mDb_notes.doCloseNotes(); } catch (Exception e) { } } } // recover focus int tabsTableId = Util.getPref_lastTimeView_tabs_tableId(this); DB.setFocus_tabsTableId(tabsTableId); String notesTableId = Util.getPref_lastTimeView_notes_tableId(this); DB.setFocus_notes_tableId(notesTableId); } //if(ENABLE_DB_CHECK) // get last time drawer number, default drawer number: 1 if (savedInstanceState == null) { for (int i = 0; i < mDb.getDrawerChildCount(); i++) { if (mDb.getTabsTableId(i) == Util.getPref_lastTimeView_tabs_tableId(this)) { mFocus_drawerChildPos = i; System.out .println("DrawerActivity / onCreate / mFocusDrawerId = " + mFocus_drawerChildPos); } } AudioPlayer.mPlayerState = AudioPlayer.PLAYER_AT_STOP; UtilAudio.mIsCalledWhilePlayingAudio = false; } // set drawer title if (mDb.getDrawerChildCount() == 0) { for (int i = 0; i < Define.ORIGIN_TABS_TABLE_COUNT; i++) { String drawerTitle = Define.getDrawerTitle(mDrawerActivity, i); mDrawerChildTitles.add(drawerTitle); mDb.insertDrawerChild(i + 1, drawerTitle); } } else { for (int i = 0; i < mDb.getDrawerChildCount(); i++) { mDrawerChildTitles.add(""); // init only mDrawerChildTitles.set(i, mDb.getDrawerChild_Title(i)); } } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerListView = (DragSortListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set adapter mDb.doOpenDrawer(); Cursor cursor = DB.mCursor_drawerChild; String[] from = new String[] { DB.KEY_DRAWER_TITLE }; int[] to = new int[] { R.id.drawerText }; drawerAdapter = new DrawerAdapter(this, R.layout.drawer_list_item, cursor, from, to, 0); mDb.doCloseDrawer(); mDrawerListView.setAdapter(drawerAdapter); // set up click listener MainUi.addDrawerItemListeners();//??? move to resume? mDrawerListView.setOnItemClickListener(MainUi.itemClick); // set up long click listener mDrawerListView.setOnItemLongClickListener(MainUi.itemLongClick); mController = DrawerListview.buildController(mDrawerListView); mDrawerListView.setFloatViewManager(mController); mDrawerListView.setOnTouchListener(mController); // init drawer dragger mPref_show_note_attribute = getSharedPreferences("show_note_attribute", 0); if (mPref_show_note_attribute.getString("KEY_ENABLE_DRAWER_DRAGGABLE", "no").equalsIgnoreCase("yes")) mDrawerListView.setDragEnabled(true); else mDrawerListView.setDragEnabled(false); mDrawerListView.setDragListener(DrawerListview.onDrag); mDrawerListView.setDropListener(DrawerListview.onDrop); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // getActionBar().setBackgroundDrawable(new ColorDrawable(ColorSet.bar_color)); getActionBar().setBackgroundDrawable(new ColorDrawable(ColorSet.getBarColor(mDrawerActivity))); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* navigation drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { System.out.println("mDrawerToggle onDrawerClosed "); int pos = mDrawerListView.getCheckedItemPosition(); int tblId = mDb.getTabsTableId(pos); DB.setSelected_tabsTableId(tblId); mDrawerChildTitle = mDb.getDrawerChild_Title(pos); setTitle(mDrawerChildTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() // add for deleting drawer if (TabsHostFragment.mTabHost == null) { MainUi.selectDrawerChild(mFocus_drawerChildPos); setTitle(mDrawerChildTitle); } } public void onDrawerOpened(View drawerView) { System.out.println("mDrawerToggle onDrawerOpened "); setTitle(mAppTitle); drawerAdapter.notifyDataSetChanged(); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mContext = getBaseContext(); bEnableConfig = false; // add on back stack changed listener fragmentManager = getSupportFragmentManager(); mOnBackStackChangedListener = DrawerActivity.this; fragmentManager.addOnBackStackChangedListener(mOnBackStackChangedListener); // register an audio stream receiver if (noisyAudioStreamReceiver == null) { noisyAudioStreamReceiver = new NoisyAudioStreamReceiver(); intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY); registerReceiver(noisyAudioStreamReceiver, intentFilter); } } // Show license dialog new EULA_dlg(this).show(); }
From source file:com.androcast.illusion.illusionmod.MainActivity.java
/** * Define all views//www .j ava2 s . c om */ private void setView() { mScrimInsetsFrameLayout = (ScrimInsetsFrameLayout) findViewById(R.id.scrimInsetsFrameLayout); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); if (mDrawerLayout != null) { mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.statusbar_color)); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); } mDrawerList = (RecyclerView) findViewById(R.id.drawer_list); mSplashView = (SplashView) findViewById(R.id.splash_view); LinearLayoutManager mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); mLayoutManager.setSmoothScrollbarEnabled(true); mDrawerList.setLayoutManager(mLayoutManager); mDrawerList.setHasFixedSize(true); mDrawerList.setAdapter(new RecyclerView.Adapter() { @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return null; } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { } @Override public int getItemCount() { return 0; } }); }
From source file:com.example.mego.adas.main.MainActivity.java
@Override public void onBackPressed() { DrawerLayout drawer = findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else {//from w ww .ja v a 2 s. c om super.onBackPressed(); } }
From source file:com.cypress.cysmart.CommonFragments.NavigationDrawerFragment.java
/** * Users of this fragment must call this method to set up the navigation * drawer interactions./*from ww w . jav a2s. c o m*/ * * @param fragmentId The android:id of this fragment in its activity's layout. * @param drawerLayout The DrawerLayout containing this fragment's UI. */ 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); ActionBar actionBar = getActivity().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_launcher, /* NavigationDrawer 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; } getActivity().invalidateOptionsMenu(); // calls // onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) { return; } getActivity().invalidateOptionsMenu(); // calls // onPrepareOptionsMenu() } }; // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mDrawerLayout.setDrawerListener(mDrawerToggle); }