Search in sources :

Example 31 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project Aegis by Decad3nce.

the class AegisActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final SharedPreferences preferences = getSharedPreferences(PREFERENCES_AEGIS, MODE_PRIVATE);
    mVersion = preferences.getString(PREFERENCES_AEGIS_VERSION, "35");
    FragmentManager fragmentManager = getFragmentManager();
    setContentView(R.layout.drawer_layout);
    final ActionBar bar = getActionBar();
    bar.setDisplayShowHomeEnabled(true);
    bar.setHomeButtonEnabled(true);
    bar.setDisplayHomeAsUpEnabled(true);
    Fragment fragment = new SMSAlarmFragment();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
    mTitle = mDrawerTitle = getTitle();
    mMenuTitles = getMenuTitles();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {

        public void onDrawerClosed(View view) {
            ((BaseAdapter) mDrawerList.getAdapter()).notifyDataSetChanged();
            invalidateOptionsMenu();
            getActionBar().setTitle(mTitle);
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle("Menu");
            ((BaseAdapter) mDrawerList.getAdapter()).notifyDataSetChanged();
            Utils.hideItem(R.id.alarm_menu_settings, thisMenu);
            Utils.hideItem(R.id.lock_menu_settings, thisMenu);
            Utils.hideItem(R.id.locate_menu_settings, thisMenu);
            Utils.hideItem(R.id.wipe_menu_settings, thisMenu);
            Utils.hideItem(R.id.data_menu_settings, thisMenu);
            Utils.showItem(R.id.action_help, thisMenu);
        }
    };
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerList.setAdapter(new DrawerLayoutAdapter(this, R.layout.drawer_list_item, new ArrayList(Arrays.asList(mMenuTitles))));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    int versionCode = 0;
    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        versionCode = packageInfo.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
    //shwat
    }
    if (savedInstanceState == null) {
        if (versionCode > Integer.parseInt(mVersion)) {
            mVersion = String.valueOf(versionCode);
            WebView webView = new WebView(this);
            webView.loadUrl("file:///android_asset/changelog.html");
            AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            dialog.setView(webView);
            dialog.setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    SharedPreferences.Editor editor = preferences.edit();
                    // value to store
                    editor.putString(PREFERENCES_AEGIS_VERSION, mVersion);
                    editor.commit();
                    dialog.dismiss();
                }
            });
            dialog.show();
        } else {
            selectItem(0);
        }
    } else {
        selectItem(mIndex);
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) ArrayList(java.util.ArrayList) WebView(android.webkit.WebView) PackageManager(android.content.pm.PackageManager) WebView(android.webkit.WebView)

Example 32 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project Gadgetbridge by Freeyourgadget.

the class ControlCenterv2 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (GBApplication.isDarkThemeEnabled()) {
        setTheme(R.style.GadgetbridgeThemeDark_NoActionBar);
    } else {
        setTheme(R.style.GadgetbridgeTheme_NoActionBar);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_controlcenterv2);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            launchDiscoveryActivity();
        }
    });
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.controlcenter_navigation_drawer_open, R.string.controlcenter_navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    //end of material design boilerplate
    deviceManager = ((GBApplication) getApplication()).getDeviceManager();
    deviceListView = (RecyclerView) findViewById(R.id.deviceListView);
    deviceListView.setHasFixedSize(true);
    deviceListView.setLayoutManager(new LinearLayoutManager(this));
    background = (ImageView) findViewById(R.id.no_items_bg);
    deviceList = deviceManager.getDevices();
    mGBDeviceAdapter = new GBDeviceAdapterv2(this, deviceList);
    deviceListView.setAdapter(this.mGBDeviceAdapter);
    ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.LEFT, ItemTouchHelper.RIGHT) {

        @Override
        public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
            if (dX > 50)
                dX = 50;
            super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            GB.toast(getBaseContext(), "onMove", Toast.LENGTH_LONG, GB.ERROR);
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            GB.toast(getBaseContext(), "onSwiped", Toast.LENGTH_LONG, GB.ERROR);
        }

        @Override
        public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
        }
    });
    //uncomment to enable fixed-swipe to reveal more actions
    //swipeToDismissTouchHelper.attachToRecyclerView(deviceListView);
    registerForContextMenu(deviceListView);
    IntentFilter filterLocal = new IntentFilter();
    filterLocal.addAction(GBApplication.ACTION_QUIT);
    filterLocal.addAction(DeviceManager.ACTION_DEVICES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
    refreshPairedDevices();
    /*
         * Ask for permission to intercept notifications on first run.
         */
    Prefs prefs = GBApplication.getPrefs();
    if (prefs.getBoolean("firstrun", true)) {
        prefs.getPreferences().edit().putBoolean("firstrun", false).apply();
        Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
        startActivity(enableIntent);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkAndRequestPermissions();
    }
    ChangeLog cl = new ChangeLog(this);
    if (cl.isFirstRun()) {
        cl.getLogDialog().show();
    }
    GBApplication.deviceService().start();
    if (GB.isBluetoothEnabled() && deviceList.isEmpty() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        startActivity(new Intent(this, DiscoveryActivity.class));
    } else {
        GBApplication.deviceService().requestDeviceInfo();
    }
}
Also used : IntentFilter(android.content.IntentFilter) NavigationView(android.support.design.widget.NavigationView) Canvas(android.graphics.Canvas) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) GBDeviceAdapterv2(nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) ChangeLog(de.cketti.library.changelog.ChangeLog) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 33 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project LeafPic by HoraApps.

the class MainActivity method initUI.

private void initUI() {
    /**** TOOLBAR ****/
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    /**** RECYCLER VIEW ****/
    rvAlbums = (RecyclerView) findViewById(R.id.grid_albums);
    rvMedia = ((RecyclerView) findViewById(R.id.grid_photos));
    rvAlbums.setHasFixedSize(true);
    rvAlbums.setItemAnimator(new DefaultItemAnimator());
    rvMedia.setHasFixedSize(true);
    rvMedia.setItemAnimator(new DefaultItemAnimator());
    albumsAdapter = new AlbumsAdapter(getAlbums().dispAlbums, MainActivity.this);
    albumsAdapter.setOnClickListener(albumOnClickListener);
    albumsAdapter.setOnLongClickListener(albumOnLongCLickListener);
    rvAlbums.setAdapter(albumsAdapter);
    mediaAdapter = new MediaAdapter(getAlbum().getMedia(), MainActivity.this);
    mediaAdapter.setOnClickListener(photosOnClickListener);
    mediaAdapter.setOnLongClickListener(photosOnLongClickListener);
    rvMedia.setAdapter(mediaAdapter);
    int spanCount = SP.getInt("n_columns_folders", 2);
    rvAlbumsDecoration = new GridSpacingItemDecoration(spanCount, Measure.pxToDp(3, getApplicationContext()), true);
    rvAlbums.addItemDecoration(rvAlbumsDecoration);
    rvAlbums.setLayoutManager(new GridLayoutManager(this, spanCount));
    spanCount = SP.getInt("n_columns_media", 3);
    rvMediaDecoration = new GridSpacingItemDecoration(spanCount, Measure.pxToDp(3, getApplicationContext()), true);
    rvMedia.setLayoutManager(new GridLayoutManager(getApplicationContext(), spanCount));
    rvMedia.addItemDecoration(rvMediaDecoration);
    /**** SWIPE TO REFRESH ****/
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setColorSchemeColors(getAccentColor());
    swipeRefreshLayout.setProgressBackgroundColorSchemeColor(getBackgroundColor());
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            if (albumsMode) {
                getAlbums().clearSelectedAlbums();
                new PrepareAlbumTask().execute();
            } else {
                getAlbum().clearSelectedPhotos();
                new PreparePhotosTask().execute();
            }
        }
    });
    /**** DRAWER ****/
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.addDrawerListener(new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {

        public void onDrawerClosed(View view) {
        //Put your code here
        // materialMenu.animateIconState(MaterialMenuDrawable.IconState.BURGER);
        }

        public void onDrawerOpened(View drawerView) {
        //Put your code here
        //materialMenu.animateIconState(MaterialMenuDrawable.IconState.ARROW);
        }
    });
    /**** FAB ***/
    fabCamera = (FloatingActionButton) findViewById(R.id.fab_camera);
    fabCamera.setImageDrawable(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_camera_alt).color(Color.WHITE));
    fabCamera.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA));
        }
    });
    //region TESTING
    fabCamera.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // NOTE: this is used to acquire write permission on sd with api 21
            // TODO call this one when unable to write on sd
            requestSdCardPermissions();
            return false;
        }
    });
    //endregion
    setRecentApp(getString(R.string.app_name));
    setupUI();
}
Also used : AlbumsAdapter(org.horaapps.leafpic.adapters.AlbumsAdapter) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) MediaAdapter(org.horaapps.leafpic.adapters.MediaAdapter) Intent(android.content.Intent) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SearchView(android.support.v7.widget.SearchView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) IconicsImageView(com.mikepenz.iconics.view.IconicsImageView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) GridSpacingItemDecoration(org.horaapps.leafpic.views.GridSpacingItemDecoration)

Example 34 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project UltimateAndroid by cymcsg.

the class FoldingDrawerLayoutActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.folding_drawer_activity_drawer);
    mTitle = mDrawerTitle = getTitle();
    mAnimalTitles = getResources().getStringArray(R.array.items_name);
    mDrawerLayout = (FoldingDrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    // mFoldLayout = (FoldingNavigationLayout)findViewById(R.id.fold_view);
    // mFoldLayout.setBackgroundColor(Color.BLACK);
    // 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
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.left_menu_layout, mAnimalTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    mItemSelectedListener = new ItemSelectedListener();
    // enable ActionBar app icon to behave as action to toggle nav drawer
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    // 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, /* nav drawer image to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description for accessibility */
    R.string.drawer_close) {

        /* "close drawer" description for accessibility */
        @SuppressLint("NewApi")
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            if (IS_HONEYCOMB) {
                // creates call to
                invalidateOptionsMenu();
            // onPrepareOptionsMenu()
            }
        }

        public void onDrawerSlide(View drawerView, float slideOffset) {
        }

        @SuppressLint("NewApi")
        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            if (IS_HONEYCOMB) {
                // creates call to
                invalidateOptionsMenu();
            // onPrepareOptionsMenu()
            }
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    if (savedInstanceState == null) {
        selectItem(0);
    }
    //        try {
    //            mDrawerLayout.getFoldingLayout(mDrawerList).setNumberOfFolds(
    //                    numOfFolder);
    //        } catch (Exception e) {
    //            e.printStackTrace();
    //            Logs.e(e, "" + (mDrawerLayout != null) + "   " + (mDrawerList != null)
    //                    + "  " + (mDrawerLayout.getFoldingLayout(mDrawerList) != null));
    //        }
    HandlerUtils.sendMessageHandlerDelay(getNumHandler, 0, 1000);
}
Also used : OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) SuppressLint(android.annotation.SuppressLint) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 35 with DrawerLayout

use of android.support.v4.widget.DrawerLayout in project UltimateAndroid by cymcsg.

the class NavigationDrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fading_actionbar_activity_navigation_drawer);
    mTitle = mDrawerTitle = getTitle();
    mCityNames = getResources().getStringArray(R.array.drawer_items);
    TypedArray typedArray = getResources().obtainTypedArray(R.array.city_images);
    mCityImages = new int[typedArray.length()];
    for (int i = 0; i < typedArray.length(); ++i) {
        mCityImages[i] = typedArray.getResourceId(i, 0);
    }
    typedArray.recycle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.fading_actionbar_drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.fading_actionbar_drawer_list_item, mCityNames));
    mDrawerList.setOnItemClickListener(this);
    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    // 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.fading_actionbar_ic_drawer, /* nav 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) {
            getActionBar().setTitle(mTitle);
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    if (savedInstanceState == null) {
        selectItem(0);
    }
}
Also used : TypedArray(android.content.res.TypedArray) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Aggregations

DrawerLayout (android.support.v4.widget.DrawerLayout)63 View (android.view.View)59 ActionBarDrawerToggle (android.support.v4.app.ActionBarDrawerToggle)33 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)22 AdapterView (android.widget.AdapterView)22 NavigationView (android.support.design.widget.NavigationView)21 ListView (android.widget.ListView)21 Intent (android.content.Intent)19 Toolbar (android.support.v7.widget.Toolbar)19 TextView (android.widget.TextView)15 ImageView (android.widget.ImageView)12 ActionBar (android.support.v7.app.ActionBar)9 SharedPreferences (android.content.SharedPreferences)8 FloatingActionButton (android.support.design.widget.FloatingActionButton)7 ViewPager (android.support.v4.view.ViewPager)6 SuppressLint (android.annotation.SuppressLint)5 TabLayout (android.support.design.widget.TabLayout)5 ArrayList (java.util.ArrayList)5 ActionBar (android.app.ActionBar)4 TypedArray (android.content.res.TypedArray)4