Android Open Source - android_app Main Activity






From Project

Back to project page android_app.

License

The source code is released under:

Apache License

If you think the Android project android_app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.t_danbubbletea;
/*/*from  www  .  jav a  2 s .c  o  m*/
~ *******************************************************************************
~   Copyright (c) 2013-2014 Daniel Lin, Kamal Chaya, Sean Penney, and Daniel Chuang 
~   
~   Licensed under the Apache License, Version 2.0 (the "License");
~   you may not use this file except in compliance with the License.
~   You may obtain a copy of the License at
~
~   http://www.apache.org/licenses/LICENSE-2.0
~
~   Unless required by applicable law or agreed to in writing, software
~   distributed under the License is distributed on an "AS IS" BASIS,
~   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~   See the License for the specific language governing permissions and
~   limitations under the License.
~  *****************************************************************************
*/

import com.capricorn.RayMenu;
import models.DiscountFragment;
import models.HomeFragment;
import models.InternetConnectivityCheck;
import models.MyCheckOut;
import models.ResideMenu;
import models.ResideMenuItem;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {
  // initialize variables
  private ResideMenu resideMenu;
  private ResideMenuItem item_home;
  private ResideMenuItem item_discount;
  private ResideMenuItem item_tea;
  private ResideMenuItem item_checkout;
  private Fragment fm;    
  private InternetConnectivityCheck checkInternet;
  private boolean isInternetPresent = false;  
  // create menu item labels;
    String titles[] = { "Home", "Discounts", "Teas", "Checkout"};
    int icon[] = { R.drawable.home, R.drawable.discounts,R.drawable.tea, R.drawable.checkout};
    // dummy images, subject to replacement
    final int[] drawableItems = { R.drawable.cart1, R.drawable.home, R.drawable.tea};
  @Override
  protected void onCreate(Bundle savedInstanceState) {    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);    
    // open home fragment when app starts 
    fm = new HomeFragment();
    fragmentSetter();
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // no horizontal orientation allowed     
    checkInternet();  
    // add arc menu 
    /*  The MIT License (MIT)
      Copyright (c) 2013 SpecialCyCi
      Modified by Dan Lin 10/3/14
      Permission is hereby granted, free of charge, to any person obtaining a copy of
      this software and associated documentation files (the "Software"), to deal in
      the Software without restriction, including without limitation the rights to
      use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
      the Software, and to permit persons to whom the Software is furnished to do so,
      subject to the following conditions:

        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.

      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
      FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
      COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
      IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
      CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
    
    RayMenu rayMenu = (RayMenu) findViewById(R.id.ray_menu);
        initArcMenu(rayMenu, drawableItems);
    // Initialize ResideMenu 
        resideMenu = new ResideMenu(this);
        resideMenu.setBackground(R.drawable.back_37);
        resideMenu.attachToActivity(this);
        // Disable swipe
        resideMenu.setSwipeDirectionDisable(ResideMenu.DIRECTION_RIGHT);
        resideMenu.setSwipeDirectionDisable(ResideMenu.DIRECTION_LEFT);
        // set the drawer items using ResideMenu
        item_home = new ResideMenuItem(this, icon[0], titles[0]);
        item_home.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        fm = new HomeFragment();
        fragmentSetter();
        resideMenu.closeMenu();
      }
     
        });      
        resideMenu.addMenuItem(item_home,  ResideMenu.DIRECTION_LEFT); // or  ResideMenu.DIRECTION_RIGHT       
        item_discount = new ResideMenuItem(this, icon[1], titles[1]);
        item_discount.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View v) {
        fm = new DiscountFragment();
        fragmentSetter();
        resideMenu.closeMenu();
      }
        
        });
        resideMenu.addMenuItem(item_discount,  ResideMenu.DIRECTION_LEFT); 
        
        item_tea = new ResideMenuItem(this, icon[2], titles[2]);
        item_tea.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View v) {        
        fm = new MySelections();
        fragmentSetter();
        resideMenu.closeMenu();
      }
        
        });
        resideMenu.addMenuItem(item_tea,  ResideMenu.DIRECTION_LEFT);
      
        item_checkout = new ResideMenuItem(this, icon[3], titles[3]);
        item_checkout.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View v) {        
        fm = new MyCheckOut();
        fragmentSetter();
        resideMenu.closeMenu();
      }
        
        });
        resideMenu.addMenuItem(item_checkout,  ResideMenu.DIRECTION_LEFT); // or  ResideMenu.DIRECTION_RIGHT
        // complete adding items to ResideMenu
  }

  private void initArcMenu(RayMenu menu, int[] itemDrawables) {
    /* Copyright 2012 Capricorn
     * Modified by Dan Lin 10/3/14
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *  http://www.apache.org/licenses/LICENSE-2.0
      *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.*/
    
    final int itemCount = itemDrawables.length;
        // populate the RayMenu
        for (int i = 0; i < itemCount; i++) {
            ImageView item = new ImageView(this);
            item.setImageResource(itemDrawables[i]);
            final int position = i;
            if(position == 0){
              menu.addItem(item, new OnClickListener() {
                @Override
                public void onClick(View v) {
                  fm = new MyCheckOut();
                  fragmentSetter();
                }
              });
            } else if(position == 1) {
              menu.addItem(item, new OnClickListener() {
                @Override
                public void onClick(View v) {
                  fm = new HomeFragment();
                  fragmentSetter();
                }
                 });
            } else {
              menu.addItem(item, new OnClickListener() {
          @Override
          public void onClick(View v) {
            fm = new MySelections();
            fragmentSetter();
            
          }
              });              
            }
        }
    }
  /* Function to set fragments
   * 
   */
  private void fragmentSetter(){ 
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.frame_container, fm).commit();
  }
  
  /*
   * Function to check whether user has internet connection
   * TODO: Check if user is logged in to their router
   */
  private void checkInternet(){
    checkInternet = new InternetConnectivityCheck(getApplicationContext());
    isInternetPresent = checkInternet.IsConnected();
    if(isInternetPresent == true){
      Context context = getApplicationContext();
      CharSequence text = "You Have Internet Connection, App Works As Normal";
      int duration = Toast.LENGTH_SHORT;
      Toast toast = Toast.makeText(context, text, duration);
      toast.show();
    } else {  
      Context context = getApplicationContext();
      CharSequence text = "You Do Not Have Internet Connection, App Will Not Work";
      int duration = Toast.LENGTH_SHORT;
      Toast toast = Toast.makeText(context, text, duration);
      toast.show();
    }
  }
  
  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity_main_action_buttons, menu);
        return super.onCreateOptionsMenu(menu); // set up drawer button in action bar
    }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
       // If user click on drawer icon, open ResideMenu drawer
       if (item.getItemId() == R.id.action_open_drawer) { 
         resideMenu.openMenu(ResideMenu.DIRECTION_LEFT);
         return true;
       }      
       return false;
  }
}




Java Source Code List

TabAdapterPackage.GridViewCustomAdapter.java
TabAdapterPackage.ImageAdapterDiscount.java
TabAdapterPackage.ImageAdapter.java
TabAdapterPackage.ListContactAdapter.java
com.capricorn.ArcLayout.java
com.capricorn.ArcMenu.java
com.capricorn.RayLayout.java
com.capricorn.RayMenu.java
com.capricorn.RotateAndTranslateAnimation.java
com.example.t_danbubbletea.MainActivity.java
com.example.t_danbubbletea.MySelections.java
com.example.t_danbubbletea.SplashScreen.java
it.gmariotti.cardslib.library.Constants.java
it.gmariotti.cardslib.library.internal.BaseGroupExpandableCard.java
it.gmariotti.cardslib.library.internal.CardArrayAdapter.java
it.gmariotti.cardslib.library.internal.CardArrayMultiChoiceAdapter.java
it.gmariotti.cardslib.library.internal.CardCursorAdapter.java
it.gmariotti.cardslib.library.internal.CardCursorMultiChoiceAdapter.java
it.gmariotti.cardslib.library.internal.CardExpand.java
it.gmariotti.cardslib.library.internal.CardExpandableListAdapter.java
it.gmariotti.cardslib.library.internal.CardGridArrayAdapter.java
it.gmariotti.cardslib.library.internal.CardGridArrayMultiChoiceAdapter.java
it.gmariotti.cardslib.library.internal.CardGridCursorAdapter.java
it.gmariotti.cardslib.library.internal.CardHeader.java
it.gmariotti.cardslib.library.internal.CardThumbnail.java
it.gmariotti.cardslib.library.internal.Card.java
it.gmariotti.cardslib.library.internal.ViewToClickToExpand.java
it.gmariotti.cardslib.library.internal.base.BaseCardArrayAdapter.java
it.gmariotti.cardslib.library.internal.base.BaseCardCursorAdapter.java
it.gmariotti.cardslib.library.internal.base.BaseCard.java
it.gmariotti.cardslib.library.internal.base.CardUIInferface.java
it.gmariotti.cardslib.library.internal.dismissanimation.BaseDismissAnimation.java
it.gmariotti.cardslib.library.internal.dismissanimation.SwipeDismissAnimation.java
it.gmariotti.cardslib.library.internal.multichoice.DefaultOptionMultiChoice.java
it.gmariotti.cardslib.library.internal.multichoice.MultiChoiceAdapterHelperBase.java
it.gmariotti.cardslib.library.internal.multichoice.MultiChoiceAdapter.java
it.gmariotti.cardslib.library.internal.multichoice.OptionMultiChoice.java
it.gmariotti.cardslib.library.internal.overflowanimation.BaseCardOverlayAnimation.java
it.gmariotti.cardslib.library.internal.overflowanimation.BaseOverflowAnimation.java
it.gmariotti.cardslib.library.internal.overflowanimation.TwoCardOverlayAnimation.java
it.gmariotti.cardslib.library.prototypes.CardSection.java
it.gmariotti.cardslib.library.prototypes.CardWithList.java
it.gmariotti.cardslib.library.prototypes.LinearListView.java
it.gmariotti.cardslib.library.prototypes.SectionedCardAdapter.java
it.gmariotti.cardslib.library.prototypes.SwipeDismissListItemViewTouchListener.java
it.gmariotti.cardslib.library.utils.BitmapUtils.java
it.gmariotti.cardslib.library.utils.CacheUtil.java
it.gmariotti.cardslib.library.view.BaseCardView.java
it.gmariotti.cardslib.library.view.CardExpandableListView.java
it.gmariotti.cardslib.library.view.CardGridView.java
it.gmariotti.cardslib.library.view.CardListView.java
it.gmariotti.cardslib.library.view.CardView.java
it.gmariotti.cardslib.library.view.ForegroundLinearLayout.java
it.gmariotti.cardslib.library.view.base.CardViewInterface.java
it.gmariotti.cardslib.library.view.component.CardHeaderView.java
it.gmariotti.cardslib.library.view.component.CardShadowView.java
it.gmariotti.cardslib.library.view.component.CardThumbnailView.java
it.gmariotti.cardslib.library.view.listener.SwipeDismissListViewTouchListener.java
it.gmariotti.cardslib.library.view.listener.SwipeDismissTopBottomTouchListener.java
it.gmariotti.cardslib.library.view.listener.SwipeDismissTouchListener.java
it.gmariotti.cardslib.library.view.listener.SwipeDismissViewTouchListener.java
it.gmariotti.cardslib.library.view.listener.SwipeOnScrollListener.java
it.gmariotti.cardslib.library.view.listener.UndoBarController.java
it.gmariotti.cardslib.library.view.listener.UndoCard.java
it.gmariotti.cardslib.library.view.listener.dismiss.AbstractDismissableManager.java
it.gmariotti.cardslib.library.view.listener.dismiss.DefaultDismissableManager.java
it.gmariotti.cardslib.library.view.listener.dismiss.Dismissable.java
models.AboutUsAndIngredientsCard.java
models.ApiConnectorPromotions.java
models.ApiConnector.java
models.CardDiscountAndCheckoutFormat.java
models.CommentsFragment.java
models.ContactListCard.java
models.ContactListLayout.java
models.ContactListObject.java
models.DatabaseTeaInfo.java
models.DiscountFragment.java
models.HomeFragment.java
models.IngredientsFragment.java
models.InternetConnectivityCheck.java
models.MyCheckOut.java
models.MySQLiteHelper.java
models.ResideMenuItem.java
models.ResideMenu.java
models.TeaData.java
models.TeaTypeSelection.java
models.TeaViewFragment.java
models.TouchDisableView.java
models.aboutUsFragment.java
models.newArrivalFragment.java