Пример #1
0
  private void configureDrawer() {
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer);

    actionBarDrawerToggle =
        new ActionBarDrawerToggle(
            this,
            drawerLayout,
            R.mipmap.ic_menu_closed,
            R.string.app_name,
            R.string.action_settings) {
          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            drawerView.bringToFront();
          }
        };
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    drawerLayout.setDrawerShadow(R.mipmap.drawer_shadow, GravityCompat.START);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    ListView drawerList = (ListView) findViewById(R.id.drawer_list);
    drawerList.setAdapter(new DrawerListViewAdapter(this));

    onDrawerItemSelected();
  }
  public void setUp(int fragmentId, final DrawerLayout drawerLayout) {
    fragmentContainerView = baseActivity.findViewById(fragmentId);
    this.drawerLayout = drawerLayout;

    drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    ActionBar actionBar = baseActivity.getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    drawerToggle =
        new QMActionBarDrawerToggle(
            baseActivity,
            drawerLayout,
            R.drawable.ic_drawer,
            R.string.nvd_open,
            R.string.nvd_close);

    if (!userLearnedDrawer && !fromSavedInstanceState) {
      drawerLayout.openDrawer(fragmentContainerView);
    }

    drawerLayout.post(
        new Runnable() {
          @Override
          public void run() {
            drawerToggle.syncState();
          }
        });

    drawerLayout.setDrawerListener(drawerToggle);
  }
Пример #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.i(TAG, "onCreate");

    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();
    mCategories = getResources().getStringArray(R.array.app_subcomponents);
    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.drawer_shadow, GravityCompat.START);

    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mCategories));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // 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.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);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }

          public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
        };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
      selectItem(0);
    }

    mBundle = new Bundle();
    mBundle.putString("unique-id", Utils.getUniqueId(this));

    // Intent intent = new Intent(this, MeasurementsService.class);
    // startService(intent);

    mPrefs = getPreferences(Context.MODE_PRIVATE);
    ;
    mMeasurementsActivated = mPrefs.getBoolean("mMeasurementsActivated", false);
    Log.i(TAG, "get prferencees: mMeasurementsActivated was: " + mMeasurementsActivated);
  }
  private void initView() {
    final ViewPager pager = (ViewPager) this.findViewById(R.id.pager);
    mPagerAdapter = new BrowserTabsAdapter(getFragmentManager());
    pager.setAdapter(mPagerAdapter);
    mPagerAdapter.setViewPager(pager);
    pager.setOffscreenPageLimit(2);

    mDrawerLayout = (DrawerLayout) this.findViewById(R.id.drawer);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    final int themeId = ThemeUtils.getInteger(getTheme(), R.attr.themeId, PureFM.THEME_ID_DARK);

    mDrawerToggle =
        new BrowserActivityDrawerToggle(
            this,
            this.mDrawerLayout,
            themeId == PureFM.THEME_ID_LIGHT
                ? R.drawable.holo_light_ic_drawer
                : R.drawable.holo_dark_ic_drawer,
            R.string.menu_bookmarks,
            R.string.app_name);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    mDrawerList = (ListView) this.findViewById(R.id.drawerList);
    mDrawerList.setAdapter(mBookmarksAdapter = new BookmarksAdapter(this));
  }
Пример #5
0
  private void initToolBar() {
    toolbar.setTitleTextColor(Color.parseColor("#ffffff")); // 设置标题颜色
    toolbar.setLogo(R.mipmap.ic_launcher);
    setSupportActionBar(toolbar);

    //        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//返回键是否显示
    //        getSupportActionBar().setHomeButtonEnabled(true);//应用图标是否可以点击,此api在toolbar中好像没有效果,待验证
    //        getSupportActionBar().setDisplayShowHomeEnabled(true);//应用图标是否显示
    mDrawerToggle =
        new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open, R.string.close) {
          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            //                mAnimationDrawable.stop();
          }

          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            //                mAnimationDrawable.start();
          }
        };

    mDrawerToggle.syncState();
    drawerLayout.setDrawerListener(mDrawerToggle);

    drawerLayout.setDrawerShadow(R.drawable.navigation_drawer_shadow, GravityCompat.START);
    //        drawerLayout.setDrawerListener(openDrawerListener);

  }
Пример #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawer = (ListView) findViewById(R.id.left_drawer);

    mDrawerLayout.setDrawerListener(new DrawerListener());
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    mDrawerTitles = getResources().getStringArray(R.array.nav_drawer_titles);
    mDrawer.setAdapter(
        new ArrayAdapter<String>(
            this, R.layout.drawer_list_item, mDrawerTitles)); // android.R.layout.simple_list_item_1
    mDrawer.setOnItemClickListener(new DrawerItemClickListener());

    mActionBarHelper = new ActionBarHelper();
    mActionBarHelper.init();

    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);

    if (savedInstanceState == null) {
      // select first item
      selectItem(0, null);
    }
  }
Пример #7
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo_activity_main);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    _initMenu();
    mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
    mDrawer.setDrawerListener(mDrawerToggle);

    // ---------------------------------------------------------------
    // ...
    String base64EncodedPublicKey = IabUtil.key;

    // compute your public key and store it in base64EncodedPublicKey
    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.enableDebugLogging(true);

    mHelper.startSetup(
        new IabHelper.OnIabSetupFinishedListener() {
          public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
              // Oh noes, there was a problem.
              Log.d(TAG, "Problem setting up In-app Billing: " + result);
              return;
            }

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) return;

            // Hooray, IAB is fully set up!
            IabUtil.getInstance().retrieveData(mHelper);
          }
        });

    // -----------------------------------------------------------------
    // BaseFragment baseFragment = null;
    if (savedInstanceState != null) {
      mSelectedFragment = savedInstanceState.getInt(BUNDLE_SELECTEDFRAGMENT);

      FragmentManager fragmentManager = getFragmentManager();
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
      if (fragmentManager.findFragmentById(R.id.fragment_main) == null)
        mBaseFragment = selectFragment(mSelectedFragment);
      // if (mBaseFragment==null)
      //    mBaseFragment = selectFragment(mSelectedFragment);
    } else {
      mBaseFragment = new HeaderFragment();
      openFragment(mBaseFragment);
    }

    // -----------------------------------------------------------------
  }
Пример #8
0
  private void initClusterDrawer() {
    emptyClusterCursor = new MatrixCursor(CLUSTER_PROJECTION);
    emptyClusterCursor.addRow(new String[] {allClusters, null, null, null});

    SimpleCursorAdapter clusterListAdapter =
        new SimpleCursorAdapter(
            this,
            R.layout.cluster_list_item,
            null,
            CLUSTER_PROJECTION,
            new int[] {R.id.cluster_view},
            0);

    CursorAdapterLoader clusterAdapterLoader =
        new CursorAdapterLoader(clusterListAdapter) {
          @Override
          public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            return provider.query(Cluster.class).orderBy(NAME).asLoader();
          }

          @Override
          public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
            super.onLoadFinished(loader, new MergeCursor(new Cursor[] {emptyClusterCursor, data}));
          }
        };

    clusterListAdapter.setViewBinder(
        new SimpleCursorAdapter.ViewBinder() {
          @Override
          public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (columnIndex != 0) {
              // do not display id column
              return true;
            }
            TextView textView = (TextView) view;
            String clusterName =
                cursor.getString(
                    cursor.getColumnIndex(NAME)); // only names selected, thus only 1 column
            textView.setText(clusterName);

            return true;
          }
        });
    clusterDrawer.setAdapter(clusterListAdapter);

    getSupportLoaderManager().initLoader(CLUSTER_LOADER, null, clusterAdapterLoader);

    drawerToggle =
        new ActionBarDrawerToggle(
            this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

    drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    drawerLayout.setDrawerListener(drawerToggle);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    drawerToggle.syncState();
  }
Пример #9
0
  @Override
  protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    dataList = new ArrayList<Test_drawitem>();
    mTitle = mDrawerTitle = getTitle();
    draw_lay = (DrawerLayout) findViewById(R.id.drawl);
    draw_List = (ListView) findViewById(R.id.left_draw);
    // titles1=getResources().getStringArray(R.array.items1);
    ab = getSupportActionBar();
    draw_lay.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    dataList.add(new Test_drawitem("Home", R.drawable.home));
    dataList.add(new Test_drawitem("Sell Books", R.drawable.sellbook));
    dataList.add(new Test_drawitem("Books Status", R.drawable.book4));
    dataList.add(new Test_drawitem("Exit", R.drawable.signout));

    adapter = new Test_custom_adap(this, R.layout.test_item, dataList);

    draw_List.setAdapter(adapter);

    draw_List.setOnItemClickListener(new DrawerItemClickListener());

    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    fr = new NavDraw1_Frag1();
    ft.replace(R.id.fl1, fr).commit();
    draw_List.setItemChecked(0, true);
    // draw_List.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
    // titles1));
    // draw_List.setOnItemClickListener(new Click());

    mDrawerToggle =
        new android.support.v4.app.ActionBarDrawerToggle(
            this, /* host Activity */
            draw_lay, /* DrawerLayout object */
            R.drawable.draw, /* nav_drawer image to replace 'Up' caret */
            R.string.open_draw, /* "open drawer" description for accessibility */
            R.string.close_draw /* "close drawer" description for accessibility */) {
          @TargetApi(Build.VERSION_CODES.HONEYCOMB)
          public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            invalidateOptionsMenu();
          }

          @TargetApi(Build.VERSION_CODES.HONEYCOMB)
          public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu();
          }
        };
    draw_lay.setDrawerListener(mDrawerToggle);
    ab.setHomeButtonEnabled(true);
    ab.setDisplayHomeAsUpEnabled(true); // for creating a back arrow for home
    ab.setHomeAsUpIndicator(getResources().getDrawable(R.drawable.draw));
  }
  /**
   * 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.
   */
  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
    // 给DrawerLayout设置阴影
    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);

    // 创建自定义返回按钮内容
    drawerArrow =
        new DrawerArrowDrawable(getActivity()) {
          @Override
          public boolean isLayoutRtl() {
            return false;
          }
        };

    // 创建v7包下的返回按钮ActionBarDrawerToggle, (封装DrawerArrowDrawable)
    mDrawerToggle =
        new ActionBarDrawerToggle(
            getActivity(),
            mDrawerLayout,
            drawerArrow,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {

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

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

    mDrawerLayout.post(
        new Runnable() {
          @Override
          public void run() {
            // 同步开关状态
            mDrawerToggle.syncState();
          }
        });

    // 设置按钮监听, 点击之后, 或者拖拽过程中返回按钮可以实时更新其动画位置.
    mDrawerLayout.setDrawerListener(mDrawerToggle);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.conten_app);

    mTitle = mDrawerTitle = getTitle();
    mItemsMenu = getResources().getStringArray(R.array.menu_principal);

    // Ontenemos el contendor Drawer principal, para trabajar con el
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    // Obtenemos el Layout que contiene toda la parte del menu izquierdo
    mDrawerView = (View) findViewById(R.id.layout_menu_completo);

    // Obtenemos el ListView que va a contener todo el menu
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // ApLicamos una sombra al contenedor principal cunado abrimos el menu
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // Lenamos el ListView con los datos que le pasamos en el arreglo "mItemsMenu"
    mDrawerList.setAdapter(new AdaptadorListView(this, mItemsMenu));

    // Escucha los eventos click del ListView (Menu)
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // Hace que el icono drawer_shadow se comporte como una acción
    // para abrir el menu
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_navigation_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) {
            super.onDrawerClosed(view);
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }

          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
        };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
    if (savedInstanceState == null) {
      selectItem(0);
    }
  }
  @SuppressLint("NewApi")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.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.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.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.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);
    }
    // 初始化带返回按钮的标题栏
    ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    // StrictMode.setThreadPolicy(policy);

    mPlayer = SplashActivity.mPlayer;
    mTitle = mDrawerTitle = getTitle();
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    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.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(
        new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // 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.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);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
          }

          public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
          }
        };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
      selectItem(0);
    }
  }
Пример #14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerList = (ListView) findViewById(R.id.left_drawer);
    try {
      drawerListRight = (ListView) findViewById(R.id.right_drawer);
    } catch (Exception ex) {
    }

    // set a custom shadow that overlays the main content when the drawer opens
    drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // set up the drawer's list view with items and click listener
    // Set the adapter for the list view
    final DrawerAdapter adapter =
        new DrawerAdapter(this, Interface.GetAvailableModules(module), module);
    drawerList.setAdapter(adapter);

    // Set the list's click listener
    drawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    drawerToggle =
        new ActionBarDrawerToggle(
            this, /* host Activity */
            drawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */) {

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

          /** Called when a drawer has settled in a completely open state. */
          public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
        };

    // Set the drawer toggle as the DrawerListener
    drawerLayout.setDrawerListener(drawerToggle);
    context = this;
  }
Пример #15
0
  private void setupView() {
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ActionBarDrawerToggle drawerToggle =
        new ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
    drawerLayout.setDrawerListener(drawerToggle);
    drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT);

    drawerToggle.setDrawerIndicatorEnabled(true);
    drawerToggle.syncState();

    initDrawerView();
  }
Пример #16
0
  @Override
  protected void initView() {
    setContentView(R.layout.activity_main);

    drawer_layout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer_layout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);
    drawer_layout.setDrawerListener(this);

    PagerTab tabs = (PagerTab) findViewById(R.id.tabs);
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    MainAdapter adapter = new MainAdapter(getSupportFragmentManager());
    pager.setAdapter(adapter);
    tabs.setViewPager(pager);
    tabs.setOnPageChangeListener(this);
  }
Пример #17
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    final CharSequence mTitle = getTitle();
    mDrawerToggle =
        new ActionBarDrawerToggle(
            this,
            mDrawerLayout,
            R.drawable.ic_drawer,
            R.string.drawer_open,
            R.string.drawer_close) {

          @Override
          public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu();
          }

          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu();
          }
        };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    List<NavigationItem> navigationItems = new ArrayList<NavigationItem>();
    navigationItems.add(new NavigationItem(R.drawable.ic_action_settings, "Settings"));
    navigationItems.add(new NavigationItem(R.drawable.ic_action_help, "Help"));
    navigationItems.add(new NavigationItem(R.drawable.ic_action_about, "About"));

    final ListView navigation = (ListView) findViewById(R.id.navigation);
    NavigationListAdapter adapter =
        new NavigationListAdapter(this, R.layout.navigation_item, navigationItems);
    navigation.setAdapter(adapter);
  }
Пример #18
0
  public void setUp(int fragmentId, DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    getActivity()
        .findViewById(R.id.sidebar_toggle_btn)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                toggleDrawer();
              }
            });
    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
  }
Пример #19
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    MainActivity.mKeyringAdapter = new ArrayAdapter<KeyringInfo>(this, R.layout.drawer_list_item);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerList.setAdapter(MainActivity.mKeyringAdapter);

    MainActivity.createKeyringList();

    registerForContextMenu(mDrawerList);
    mDrawerList.setOnItemClickListener(this);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawerToggle =
        new ActionBarDrawerToggle(
            this,
            mDrawerLayout,
            R.drawable.ic_drawer,
            R.string.drawer_open,
            R.string.drawer_close) {

          public void onDrawerClosed(View view) {
            getActionBar().setTitle(R.string.passwords);
            drawerstate = false;
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }

          public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(R.string.app_name);
            drawerstate = true;
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
        };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (drawerstate) mDrawerLayout.openDrawer(mDrawerList);
    else mDrawerLayout.closeDrawer(mDrawerList);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_frame_layout);

    Fragment fragment = new HomeFragment(this);
    fragmentManager = getFragmentManager();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.add(R.id.content_frame, fragment);
    // transaction.addToBackStack(null);
    transaction.commit();
    fragmentManager.executePendingTransactions();
    // drawer tamjam
    mDrawerTitles = getResources().getStringArray(R.array.drawer_contents);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerLinearLayout = (LinearLayout) findViewById(R.id.drawer_lin_layout);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    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.drawer_list_item, mDrawerTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    LinearLayout action_lin_original =
        (LinearLayout) findViewById(R.id.action_bar_lin_layout_main_page);
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getSupportActionBar().setCustomView(R.layout.custom_action_bar_main_page);
    final ImageView drawer_img = (ImageView) findViewById(R.id.drawer);
    drawer_img.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub
            boolean isDrawerOpen = mDrawerLayout.isDrawerOpen(mDrawerLinearLayout);
            if (isDrawerOpen) {
              mDrawerLayout.closeDrawer(mDrawerLinearLayout);
            } else {
              mDrawerLayout.openDrawer(mDrawerLinearLayout);
            }
          }
        });
  }
  public void setUp(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerToggle =
        new ActionBarDrawerToggle(
            getActivity(), mDrawerLayout, toolbar, R.string.app_name, R.string.app_name) {
          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
              return;
            }

            getActivity().supportInvalidateOptionsMenu();
          }

          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
              return;
            }

            if (!mUserLearnedDrawer) {
              mUserLearnedDrawer = true;
              PreferencesEditor.savePreference(
                  Dribbble.getContext(), PREF_USER_LEARNED_DRAWER, true);
            }

            getActivity().supportInvalidateOptionsMenu();
          }
        };

    mDrawerLayout.post(
        new Runnable() {
          @Override
          public void run() {
            mDrawerToggle.syncState();
          }
        });
    mDrawerLayout.setDrawerListener(mDrawerToggle);
  }
Пример #22
0
  protected void setupDrawer() {
    mTitle = getTitle();
    DrawerLayout mDrawerLayout = getDrawerLayout();
    if (mDrawerLayout == null) {
      Log.w(
          "SilkDrawerActivtiy",
          "You must return a drawer layout in getDrawerLayout() of your Activity in order for the drawer to be displayed.");
      return;
    }
    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, getDrawerIndicatorRes(), getOpenedTextRes(), getOpenedTextRes()) {
          @Override
          public void onDrawerOpened(View drawerView) {
            invalidateOpenClosed();
          }

          @Override
          public void onDrawerClosed(View drawerView) {
            invalidateOpenClosed();
          }
        };
    mDrawerLayout.setDrawerShadow(getDrawerShadowRes(), Gravity.START);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    try {
      Field mDragger =
          mDrawerLayout
              .getClass()
              .getDeclaredField("mLeftDragger"); // mRightDragger for right obviously
      mDragger.setAccessible(true);
      ViewDragHelper draggerObj = (ViewDragHelper) mDragger.get(mDrawerLayout);

      Field mEdgeSize = draggerObj.getClass().getDeclaredField("mEdgeSize");
      mEdgeSize.setAccessible(true);
      int edge = mEdgeSize.getInt(draggerObj);

      mEdgeSize.setInt(draggerObj, edge * 2);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private void initViews() {
    // INITIALIZE TOOLBAR
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    // INITIALIZE DRAWER
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    // set a custom shadow that overlay 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
    mActionBarDrawerToggle =
        new ActionBarDrawerToggle(
            this, mDrawerLayout, mToolbar, R.string.app_name, R.string.app_name);
    mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);

    // INITIALIZE RECYCLER VIEW
    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    // If the size of views will not change as the data changes.
    mRecyclerView.setHasFixedSize(true);
    // setting the layout manager
    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);
    // setting the adapter
    mAdapter = new MyRecyclerAdapter(this);
    mRecyclerView.setAdapter(mAdapter);

    // INITIALIZE TAB LAYOUT
    mTabLayout = (TabLayout) findViewById(R.id.tabLayout);
    mTabLayout.addTab(mTabLayout.newTab().setText("News Feed"));
    mTabLayout.addTab(mTabLayout.newTab().setText("Favorites"));
    mTabLayout.addTab(mTabLayout.newTab().setText("Your Posts"));

    // INITIALIZE FLOATING ACTION BUTTON
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.fab);
    mFloatingActionButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivity(new Intent(MainActivity2.this, MyItemInputFieldsActivity.class));
          }
        });
  }
  /**
   * 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.
   */
  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(),
            mDrawerLayout,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {
          @Override
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            ((MenuActivity) getActivity()).hideKeyBoard();
          }
        };

    // Defer code dependent on restoration of previous instance state.
    mDrawerLayout.post(
        new Runnable() {
          @Override
          public void run() {
            mDrawerToggle.syncState();
          }
        });

    mDrawerLayout.setDrawerListener(mDrawerToggle);
  }
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main_ui);

    mTitle = mDrawerTitle = getTitle();

    mDrawerRootLayout = (DrawerLayout) findViewById(R.id.main_root_layout);
    mDrawerRootLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT);
    mDrawerToggle =
        new ActionBarDrawerToggle(
            this, /* host Activity */
            mDrawerRootLayout, /* DrawerLayout object */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */) {

          /** Called when a drawer has settled in a completely closed state. */
          public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            ActivityCompat.invalidateOptionsMenu(
                MainSettingsActivity.this); // creates call to onPrepareOptionsMenu()
          }

          /** Called when a drawer has settled in a completely open state. */
          public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            ActivityCompat.invalidateOptionsMenu(
                MainSettingsActivity.this); // creates call to onPrepareOptionsMenu()
          }
        };

    // Set the drawer toggle as the DrawerListener
    mDrawerRootLayout.setDrawerListener(mDrawerToggle);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    AnyApplication.getConfig().addChangedListener(menuExtraUpdaterOnConfigChange);
  }
  private void setupDrawer() {
    mDrawer = (ListView) findViewById(R.id.left_drawer);

    // Set shadow of navigation drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // Add Navigation Drawer to ActionBar
    mDrawerToggle =
        new android.support.v7.app.ActionBarDrawerToggle(
            this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
          @Override
          public void onDrawerOpened(View drawerView) {
            supportInvalidateOptionsMenu();
          }

          @Override
          public void onDrawerClosed(View view) {
            supportInvalidateOptionsMenu();
          }
        };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
  }
  /**
   * 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.
   */
  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 */) {
          @Override
          public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
              return;
            }

            getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
          }

          @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();
            }

            getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
          }
        };

    // 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);
  }
Пример #28
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bridget);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (GridView) 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 up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ImageAdapter(this, ALPHABET));

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    mDrawerList.setOnDragListener(new DrawerItemDragListener());

    // views to drop onto
    block5 = (ImageView) findViewById(R.id.myanswer5);
    block6 = (ImageView) findViewById(R.id.myanswer6);
    block7 = (ImageView) findViewById(R.id.myanswer7);
    block8 = (ImageView) findViewById(R.id.myanswer8);

    // set drag listener
    block5.setOnDragListener(new ChoiceDragListener());
    block6.setOnDragListener(new ChoiceDragListener());
    block7.setOnDragListener(new ChoiceDragListener());
    block8.setOnDragListener(new ChoiceDragListener());

    // 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.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);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }

          public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

            // view to drag
            blocka = (ImageView) findViewById(R.id.myimage1);
            blockb = (ImageView) findViewById(R.id.myimage2);
            blockc = (ImageView) findViewById(R.id.myimage3);
            blockd = (ImageView) findViewById(R.id.myimage4);
            blocke = (ImageView) findViewById(R.id.myimage5);
            blockf = (ImageView) findViewById(R.id.myimage6);
            blockg = (ImageView) findViewById(R.id.myimage7);
            blockh = (ImageView) findViewById(R.id.myimage8);
            blocki = (ImageView) findViewById(R.id.myimage9);
            blockj = (ImageView) findViewById(R.id.myimage10);
            blockk = (ImageView) findViewById(R.id.myimage11);
            blockl = (ImageView) findViewById(R.id.myimage12);
            blockm = (ImageView) findViewById(R.id.myimage13);
            blockn = (ImageView) findViewById(R.id.myimage14);
            blocko = (ImageView) findViewById(R.id.myimage15);
            blockp = (ImageView) findViewById(R.id.myimage16);
            blockq = (ImageView) findViewById(R.id.myimage17);
            blockr = (ImageView) findViewById(R.id.myimage18);
            blocks = (ImageView) findViewById(R.id.myimage19);
            blockt = (ImageView) findViewById(R.id.myimage20);
            blocku = (ImageView) findViewById(R.id.myimage21);
            blockv = (ImageView) findViewById(R.id.myimage22);
            blockw = (ImageView) findViewById(R.id.myimage23);
            blockx = (ImageView) findViewById(R.id.myimage24);
            blocky = (ImageView) findViewById(R.id.myimage25);
            blockz = (ImageView) findViewById(R.id.myimage26);

            // set touch listener
            blocka.setOnTouchListener(new ChoiceTouchListener());
            blockb.setOnTouchListener(new ChoiceTouchListener());
            blockc.setOnTouchListener(new ChoiceTouchListener());
            blockd.setOnTouchListener(new ChoiceTouchListener());
            blocke.setOnTouchListener(new ChoiceTouchListener());
            blockf.setOnTouchListener(new ChoiceTouchListener());
            blockg.setOnTouchListener(new ChoiceTouchListener());
            blockh.setOnTouchListener(new ChoiceTouchListener());
            blocki.setOnTouchListener(new ChoiceTouchListener());
            blockj.setOnTouchListener(new ChoiceTouchListener());
            blockk.setOnTouchListener(new ChoiceTouchListener());
            blockl.setOnTouchListener(new ChoiceTouchListener());
            blockm.setOnTouchListener(new ChoiceTouchListener());
            blockn.setOnTouchListener(new ChoiceTouchListener());
            blocko.setOnTouchListener(new ChoiceTouchListener());
            blockp.setOnTouchListener(new ChoiceTouchListener());
            blockq.setOnTouchListener(new ChoiceTouchListener());
            blockr.setOnTouchListener(new ChoiceTouchListener());
            blocks.setOnTouchListener(new ChoiceTouchListener());
            blockt.setOnTouchListener(new ChoiceTouchListener());
            blocku.setOnTouchListener(new ChoiceTouchListener());
            blockv.setOnTouchListener(new ChoiceTouchListener());
            blockw.setOnTouchListener(new ChoiceTouchListener());
            blockx.setOnTouchListener(new ChoiceTouchListener());
            blocky.setOnTouchListener(new ChoiceTouchListener());
            blockz.setOnTouchListener(new ChoiceTouchListener());
          }
        };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
      selectItem(0);
    }
  }
Пример #29
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ContactsDatabaseHandler contactDB = new ContactsDatabaseHandler(this);
    /** CRUD Operations */
    // Inserting Contacts
    if (contactDB.getAllContacts().size() == 0) {
      Log.d("Insert: ", "Inserting ..");
      contactDB.addContact(new ContactObject("JD", "Knapp", "*****@*****.**"));
      contactDB.addContact(new ContactObject("Ben", "Olayinka", "*****@*****.**"));
      contactDB.addContact(new ContactObject("Brandon", "Phillips", "*****@*****.**"));
      contactDB.addContact(new ContactObject("Mike", "Stek", "*****@*****.**"));
    } else {
      // Log.d("INSERT: ", "Not performed, DB is populated");
    }
    /*
    // How to read contacts and print to log
    Log.d("Reading: ", "Reading all contacts..");
    ArrayList<ContactObject> contacts = contactDB.getAllContacts();

    for (ContactObject cn : contacts) {
        String log = "Id: "+cn.getId()+" ,Name: " + cn.getFullName() + " ,Email: " + cn.getEmailAddr();
            // Writing Contacts to
    Log.d("Name: ", log);
    }
    */
    contactDB.close();

    mTitle = mDrawerTitle = getTitle();
    mMenuItems = getResources().getStringArray(R.array.main_navigation_menu);
    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.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mMenuItems));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // 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.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);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }

          public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
        };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
      selectItem(0);
    }
  }
Пример #30
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set the font
    appFont = Typeface.createFromAsset(this.getAssets(), "Lato-Regular.ttf");

    mTitle = mDrawerTitle = getTitle();
    mDrawerTitles = getResources().getStringArray(R.array.drawer_titles);
    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.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(
        new ArrayAdapter<String>(this, R.layout.drawer_list_item, mDrawerTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // 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.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);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }

          public void onDrawerOpened(View drawerView) {
            // getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
        };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
      selectItem(0); // opens the first one - summary
    }

    // Initialise Bluetooth handlers and connections
    bluetoothIn =
        new Handler() {
          public void handleMessage(android.os.Message msg) {
            if (msg.what == handlerState) { // if message is what we want
              String readMessage = (String) msg.obj; // msg.arg1 = bytes from connect thread
              recDataString.append(readMessage);

              Log.e("test", "Message received: " + readMessage);

              // Determine the type of message received
              int EOLIndexMulti = recDataString.indexOf("~"); // determine the end-of-line
              int EOLIndexSingle = recDataString.indexOf("$");
              int sunscreenNotification = recDataString.indexOf("&");

              if (EOLIndexMulti > 0) {
                // Multiple values requested
                String dataInPrint = recDataString.substring(0, EOLIndexMulti); // extract string
                int dataLength = dataInPrint.length();
                if (recDataString.charAt(0) == '#') {
                  // A valid message - extract each UV reading from string

                  String readingsString = recDataString.substring(1, dataLength);
                  if (!readingsString.equals("")) {
                    Vector<String> readings =
                        new Vector<String>(Arrays.asList(readingsString.split("\\+")));

                    // Construct file name based on current date
                    String fileName = getCurrDate() + ".readings";

                    // Write the readings to a file in internal storage
                    writeReadingsToFile(fileName, readings);
                  }

                  // Calculate and update the exposure level
                  updateExposureLevel();

                  // Display to the user that successful synced has been done with arduino
                  ShortToast("Synced");
                }
                recDataString.delete(0, recDataString.length()); // clear all string data
                dataInPrint = " ";
              } else if (EOLIndexSingle > 0) { // single measurement was received
                String dataInPrint = recDataString.substring(0, EOLIndexSingle);
                int dataLength = dataInPrint.length();
                if (recDataString.charAt(0) == '#') {
                  String currUVMeasurement = recDataString.substring(1, 5);
                  // Update current UV Measurement
                  currentUVValue = Double.valueOf(currUVMeasurement);
                  Log.e("test", "Current UV level: " + currentUVValue);

                  // Update the current UV reading on the UI
                  updateCurrentUVLevel();

                  // Display to the user that successful reading of current UV has been done
                  // with arduino
                  ShortToast("Measured UV");
                }
                recDataString.delete(0, recDataString.length()); // clear all string data
                dataInPrint = " ";
              } else if (sunscreenNotification > 0) {
                String dataInPrint =
                    recDataString.substring(0, sunscreenNotification); // extract string
                int dataLength = dataInPrint.length();
                if (recDataString.charAt(0) == '#') {

                  // Extract and confirm the notification message is valid
                  String readingsString = recDataString.substring(1, dataLength);
                  if (readingsString.equals("note")) {
                    // Sunscreen notification message received
                    // - Create dialog box
                    // - Turn on vibration
                    // Turn on vibration if one exists
                    final Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
                    if (vibrator.hasVibrator()) {
                      vibrator.vibrate(getVibratorPattern(), 1); // put vibration on repeat
                    }
                    // Build and display a dialog box
                    AlertDialog.Builder dlgAlert = new AlertDialog.Builder(MainActivity.this);
                    dlgAlert.setMessage("Please apply some sunscreen now!");
                    dlgAlert.setTitle("Sunscreen Notification");
                    dlgAlert.setPositiveButton(
                        "OK",
                        new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int which) {
                            // Close dialog box
                            // By default, vibrator will close when dialog closes
                            vibrator.cancel();
                          }
                        });
                    dlgAlert.setCancelable(true);
                    dlgAlert.create().show();
                  }
                }
                recDataString.delete(0, recDataString.length());
              }
            }
          }
        };

    btAdapter = BluetoothAdapter.getDefaultAdapter(); // get Bluetooth adapter
    checkBTState();

    // Update the current uv levels and percentage
    updateCurrentUVLevel();
    updateExposureLevel();
  }