Java Code Examples for android.support.design.widget.NavigationView#setCheckedItem()

The following examples show how to use android.support.design.widget.NavigationView#setCheckedItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NavigationViewActivity.java    From EtsyBlur with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_view);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.nav_view);

    if (savedInstanceState == null) {
        title = getString(R.string.title_section1);
        navigationView.setCheckedItem(R.id.nav_menu1);
        replaceFragment(1);
    }

    initView();
}
 
Example 2
Source File: MainActivity.java    From BlueBoard with Apache License 2.0 6 votes vote down vote up
private void setUpDrawerContent(NavigationView navigationView) {
    navigationView.setCheckedItem(R.id.nav_home);
    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    switch (menuItem.getItemId()) {
                        case R.id.nav_home:
                            menuItem.setChecked(true);
                            break;
                        case R.id.nav_download:
                            DownLoadActivity.newInstance(MainActivity.this);
                            break;

                        default:
                            break;
                    }
                    mDrawerLayout.closeDrawers();
                    return true;
                }
            });
}
 
Example 3
Source File: MainActivity.java    From swipe-maker with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    showFragment(RightSwipeFragment.newInstance(), RightSwipeFragment.TAG);
    navigationView.setCheckedItem(R.id.nav_rightswipe);
}
 
Example 4
Source File: MainActivity.java    From Girls with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, mToolbar, 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.setCheckedItem(R.id.nav_new);
    changeFragment(new NewFragment());
}
 
Example 5
Source File: MainActivity.java    From flickabledialog with MIT License 6 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

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

  DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle =
      new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open,
          R.string.navigation_drawer_close);
  drawer.addDrawerListener(toggle);
  toggle.syncState();

  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);
  navigationView.setCheckedItem(R.id.nav_mail);

  setDefaultFragment();
}
 
Example 6
Source File: BreadcrumbActivity.java    From BreadcrumbToolbar with Apache License 2.0 6 votes vote down vote up
private void bindViews() {
    // Bind toolbar
    toolbar = (BreadcrumbToolbar) findViewById(R.id.toolbar);
    // We can't use setSupportActionBar()
    toolbar.setBreadcrumbToolbarListener(this);
    toolbar.setTitle(R.string.app_name);
    // Set animated drawer icon to toolbar
    DrawerArrowDrawable drawerArrow = new DrawerArrowDrawable(this);
    drawerArrow.setColor(ContextCompat.getColor(this, android.R.color.white));
    toolbar.setNavigationIcon(drawerArrow);
    getSupportFragmentManager().addOnBackStackChangedListener(this);

    // Bind drawer and toggle button
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    bindDrawerToggle();
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setCheckedItem(R.id.nav_home);

    // Bind FAB
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(this::openBreadCrumbFragment);
}
 
Example 7
Source File: MainActivity.java    From FloatingActionButton with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

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

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawerLayout.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(navigationItemSelectedListener);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.fragment, new HomeFragment()).commit();
    }

    navigationView.setCheckedItem(R.id.home);
}
 
Example 8
Source File: HomeActivity.java    From MousePaint with MIT License 6 votes vote down vote up
private void init() {
    view_hide.setOnClickListener(this);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationIcon(R.drawable.ic_menu);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    if (mNavigationView != null) {
        setupDrawerContent(mNavigationView);
        mNavigationView.setCheckedItem(R.id.nav_home);
    }

    mHomeFragment = HomeFragment.newInstance();
    switchFragment(TAG_HOME, mHomeFragment);

    setupRecyclerView();

    mIntent = new Intent();

    handFabPathAndSearch();
}
 
Example 9
Source File: MainActivity.java    From KinoCast with MIT License 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    VideoCastManager.getInstance().incrementUiCounter();
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation);
    // remove active state from settings
    if(mNavItemLast != -1) {
        navigationView.setCheckedItem(mNavItemLast);
        navigate(mNavItemLast);
        mNavItemLast = -1;
    }

}
 
Example 10
Source File: MainActivity.java    From SuperToasts with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    final ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            // Stop animating the navigation icon
            super.onDrawerSlide(drawerView, 0);
        }
    };
    drawerLayout.addDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();

    final NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setCheckedItem(R.id.navigation_drawer_supertoast);

    // setCheckedItem() does not actually call the associated listener
    if (savedInstanceState == null) this.onNavigationItemSelected(navigationView.getMenu().getItem(0));
}
 
Example 11
Source File: MainActivity.java    From CineLog with GNU General Public License v3.0 5 votes vote down vote up
private void configureDrawer() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setCheckedItem(R.id.nav_reviews);

    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                    // close drawer when item is tapped
                    drawerLayout.closeDrawers();

                    switch (menuItem.getItemId()) {
                        case R.id.nav_wishlist:
                            Intent intent = new Intent(getApplicationContext(), WishlistActivity.class);
                            startActivity(intent);
                            break;
                    }

                    setViewPager(viewPager);

                    fab.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            setReviewFragment();
                        }
                    });

                    return true;
                }
            }
    );
}
 
Example 12
Source File: MainActivity.java    From PopCorn with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
    if (sharedPreferences.getBoolean(Constants.FIRST_TIME_LAUNCH, true)) {
        startActivity(new Intent(MainActivity.this, IntroActivity.class));
        SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
        sharedPreferencesEditor.putBoolean(Constants.FIRST_TIME_LAUNCH, false);
        sharedPreferencesEditor.apply();
    }

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

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, mDrawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawer.setDrawerListener(toggle);
    toggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(MainActivity.this);

    mNavigationView.setCheckedItem(R.id.nav_movies);
    setTitle(R.string.movies);
    setFragment(new MoviesFragment());
}
 
Example 13
Source File: Main.java    From kute with Apache License 2.0 5 votes vote down vote up
/*********************** Overrides ************************/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    route_request_number = (TextView) findViewById(R.id.numberRouteRequests);
    route_request=(ImageButton)findViewById(R.id.routeRequests);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    /****************************** Drawer Layout Setup ************************/
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    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);
    /******************************* End Of Drawer Setup **************************/
    /********************* Load Home Base Fragment**********/
   setupHomeFragment();
    navigationView.setCheckedItem(R.id.Home);
    final SharedPreferences pref = getApplicationContext().getSharedPreferences("user_credentials", 0); // 0 - for private mode
    Log.d("SharedPreference", pref.getString("Profile_Image", null));


}
 
Example 14
Source File: MainActivity.java    From ShapeRipple with Apache License 2.0 4 votes vote down vote up
private void setupToolbar() {
    AppCompatActivity activity = this;
    activity.setSupportActionBar(mToolbar);

    if (activity.getSupportActionBar() != null) {
        activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mDrawerLayout = (DrawerLayout) findViewById(R.id.main_drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.ripples, R.string.ripple_circle) {

        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    NavigationView navigationView = (NavigationView) findViewById(R.id.main_navigation_view);
    navigationView.setCheckedItem(R.id.nav_circle);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {

            switch (item.getItemId()) {
                case R.id.nav_circle:
                    ripple.setRippleShape(new Circle());
                    break;
                case R.id.nav_square:
                    ripple.setRippleShape(new Square());
                    break;
                case R.id.nav_triangle:
                    ripple.setRippleShape(new Triangle());
                    break;
                case R.id.nav_star:
                    ripple.setRippleShape(new Star());
                    break;
                case R.id.nav_image:
                    ripple.setRippleShape(new Image(R.drawable.dodge));
                    break;
                case R.id.nav_github:
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/poldz123/ShapeRipple"));
                    startActivity(browserIntent);
                    break;
                case R.id.nav_about:

                    View layout = LayoutInflater.from(MainActivity.this).inflate(R.layout.about_dialog, null, false);
                    TextView version = (TextView) layout.findViewById(R.id.version);

                    version.setText(String.format("Version %s", MainActivity.this.getString(R.string.version)));
                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                    builder.setPositiveButton("Ok", null);
                    builder.setView(layout);

                    final AlertDialog dialog = builder.create();
                    dialog.setCanceledOnTouchOutside(true);
                    dialog.setCancelable(true);
                    dialog.show();

                    break;

            }

            mDrawerLayout.closeDrawers();
            return true;
        }
    });

    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
}
 
Example 15
Source File: HomeActivity.java    From BuildmLearn-Toolkit-Android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("SkipTutorial", true);
    editor.apply();

    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    View menuHeaderView = navigationView.getHeaderView(0);
    final TextView name = (TextView) menuHeaderView.findViewById(R.id.name);
    name.setText(String.format(" %s", prefs.getString(getString(R.string.key_user_name), "")));


    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    smoothNavigationToggle = new SmoothNavigationToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close){
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            name.setText(String.format(" %s", prefs.getString(getString(R.string.key_user_name), "")));
            LoadProjectFragment f = (LoadProjectFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG_PROJECT);
            if (f != null)
                f.closeSearch();

            LoadApkFragment f2 = (LoadApkFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG_APK);
            if (f2 != null)
                f2.closeSearch();
        }
    };
    drawer.addDrawerListener(smoothNavigationToggle);
    smoothNavigationToggle.syncState();

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.container, new HomeFragment(), FRAGMENT_TAG_HOME).commit();
    navigationView.setCheckedItem(R.id.nav_home);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(R.string.app_name);
    }
}
 
Example 16
Source File: BaseActivity.java    From android-design-template with Apache License 2.0 4 votes vote down vote up
/**
 * Updated the checked item in the navigation drawer
 * @param navigationView the navigation view
 */
private void setSelectedItem(NavigationView navigationView) {
    // Which navigation item should be selected?
    int selectedItem = getSelfNavDrawerItem(); // subclass has to override this method
    navigationView.setCheckedItem(selectedItem);
}
 
Example 17
Source File: MainActivity.java    From soundcom with Apache License 2.0 4 votes vote down vote up
public void initHistory() {

        final Context context = getApplicationContext();
        CharSequence text = "Your Recent Chat";
        int duration = Toast.LENGTH_SHORT;

        long free = Runtime.getRuntime().freeMemory();

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
        setContentView(R.layout.history_nav);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setCheckedItem(R.id.history);
        System.out.println("History inited");
            messageAdapter = new MessageAdapter(this);

            try {
            System.out.println(loadJSONFromAsset(myInternalFile)); //loading messages from json file
            JSONObject obj = new JSONObject(loadJSONFromAsset(myInternalFile));
            JSONArray messages = obj.getJSONArray("messages");
            for (int i = 0; i < messages.length(); i++) {
                JSONObject jo_inside = messages.getJSONObject(i);
                String textvalue = jo_inside.getString("text");
                JSONObject data = jo_inside.getJSONObject("data");
                MemberData datavalue = new MemberData(data.getString("name"),data.getString("color"));
                boolean iscurrentuser = Boolean.valueOf(jo_inside.getString("user"));
                final Message message = new Message(textvalue,datavalue,iscurrentuser);
                messagesView = (ListView) findViewById(R.id.messages_view);
                messagesView.setAdapter(messageAdapter); //display message list

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        messageAdapter.add(message);            //add message to messages_list
                        messagesView.setSelection(messagesView.getCount() - 1);
                        System.out.println("message added");
                    }
                });
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
 
Example 18
Source File: HomeActivity.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    // Set a Toolbar to replace the ActionBar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.home_toolbar);
    setSupportActionBar(toolbar);

    LAUNCH_ACTIVITY_ANIM_BUNDLE = ActivityOptions.
            makeCustomAnimation(HomeActivity.this,
                    R.transition.left_in,
                    R.transition.left_out).toBundle();

    // Initialize settings to defaults

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new SmoothDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open,  R.string.drawer_close);

    mDrawerLayout.addDrawerListener(mDrawerToggle);

    NavigationView navDrawer = (NavigationView) findViewById(R.id.navDrawer);
    setupDrawerContent(navDrawer);


    PreferenceManager.setDefaultValues(this, R.xml.main_settings, false);
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    Fragment frag = new HomeFragment();

    // Add a new fragment to the appropriate view element
    FragmentManager fragmentManager = getSupportFragmentManager();
    if (fragmentManager.findFragmentById(R.id.flContent) == null) {
        fragmentManager.beginTransaction().add(R.id.flContent, frag).commit();
    }

    if (mPreferences.getInt(getString(R.string.version_key), 0) < Constants.VERSION_CODE
            && mPreferences.getBoolean(getString(R.string.done_first_launch_key), false)) {
        // App has been updated
        // TODO: For version 2.9.18 - Update Android SDK to latest version & work on improved schedule feature

        mPreferences.edit().putInt(getString(R.string.version_key), Constants.VERSION_CODE).apply();

        if (mPreferences.getInt(getString(R.string.placeholder_dismiss_delay_key), 0) < Constants.DEFAULT_DELAY_SECONDS) {
            // Set default Dismiss Placeholder notification delay to 7. Low delays can cause
            // problems with relaying notifications.
            mPreferences.edit()
                        .putInt(getString(R.string.placeholder_dismiss_delay_key),
                                Constants.DEFAULT_DELAY_SECONDS).apply();
        }

        navDrawer.setCheckedItem(R.id.nav_whats_new);
        setTitle(R.string.whats_new);
        frag = InfoFragment.newInstance(getString(R.string.whats_new_text));
        fragmentManager.beginTransaction().replace(R.id.flContent, frag).commit();

        // Open the database to update it in case the version is incremented.
        AppSelectionsStore store = AppSelectionsStore.get(this);
    }

    if (!mPreferences.getBoolean(getString(R.string.done_first_launch_key), false)) { // This is the first launch
        startActivityForResult(new Intent(HomeActivity.this, AppIntroActivity.class),
                APP_INTRO_FIRST_LAUNCH_INTENT,
                LAUNCH_ACTIVITY_ANIM_BUNDLE);
    }

    createNotificationChannel();
}
 
Example 19
Source File: Permission.java    From soundcom with Apache License 2.0 4 votes vote down vote up
public void initTransmit() {
        final Context context = getApplicationContext();

        CharSequence text = "Transmitter Mode Activated";
        int duration = Toast.LENGTH_SHORT;

        long free = Runtime.getRuntime().freeMemory();
//        generate(context);

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();

        setContentView(R.layout.activity_transmitter);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setCheckedItem(R.id.transmit);


        gen = (Button) findViewById(R.id.generate);
        gen.setOnClickListener(this);
        mEdit = (EditText) findViewById(R.id.transmitString);


        fab_trans = (FloatingActionButton) findViewById(R.id.fab);
        fab_trans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Transmitting Modulated Waveform", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

                mediaplayer = new MediaPlayer();


                String root = Environment.getExternalStorageDirectory().toString();
                File dir = new File(root, "RedTooth");
                if (!dir.exists()) {
                    dir.mkdir();
                }

                try {
                    mediaplayer.setDataSource(dir + File.separator + "FSK.wav");
                    mediaplayer.prepare();
                    mediaplayer.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        fab_trans.hide();


    }
 
Example 20
Source File: MainActivity.java    From soundcom with Apache License 2.0 4 votes vote down vote up
public void initTransmit() {
        final Context context = getApplicationContext();

        CharSequence text = "Transmitter Mode Activated";
        int duration = Toast.LENGTH_SHORT;

        long free = Runtime.getRuntime().freeMemory();
//        generate(context);

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();

        setContentView(R.layout.activity_transmitter);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setCheckedItem(R.id.transmit);


        gen = (Button) findViewById(R.id.generate);
        mEdit = (EditText) findViewById(R.id.transmitString);
        gen.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                clickHelper(context,mEdit,v);
            }

        });


        fab_trans = (FloatingActionButton) findViewById(R.id.fab);
        fab_trans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {  //playing the wav file
                Snackbar.make(view, "Transmitting Modulated Waveform", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

                mediaplayer = new MediaPlayer();

                String root = Environment.getExternalStorageDirectory().toString();
                File dir = new File(root, "Soundcom");
                if (!dir.exists()) {
                    dir.mkdir();
                }

                try {
                    mediaplayer.setDataSource(dir + File.separator + "FSK.wav");
                    mediaplayer.prepare();
                    mediaplayer.start();
                    MemberData data = new MemberData(a, getRandomColor());
                    boolean belongsToCurrentUser=true;
                    final Message message = new Message(src, data, belongsToCurrentUser);
                    printmessage(message);  //add transmitted message to chat

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        fab_trans.hide();
    }