Android Open Source - UTHPortal-Android-Gradle Main Screen






From Project

Back to project page UTHPortal-Android-Gradle.

License

The source code is released under:

MIT License

If you think the Android project UTHPortal-Android-Gradle 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.uth.uthportal;
//  ww  w  . j  a  va2 s.  co  m
import java.util.List;

import com.uth.uthportal.adapter.AdapterManager;
import com.uth.uthportal.adapter.TabsPagerAdapter;
import com.uth.uthportal.buffers.CoursesParser;
import com.uth.uthportal.buffers.FoodParser;
import com.uth.uthportal.buffers.GeneralAnnParser;
import com.uth.uthportal.collections.Course;
import com.uth.uthportal.collections.Food;
import com.uth.uthportal.collections.GeneralAnnouncement;
import com.uth.uthportal.network.AppRater;
import com.uth.uthportal.service.DataSyncService;
import com.uth.uthportal.ui.ZoomOutPageTransformer;

import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ExpandableListView;
import android.widget.Toast;

public class MainScreen extends FragmentActivity implements android.app.ActionBar.TabListener{
  //tab stuff.
  private ViewPager viewPager;
  private TabsPagerAdapter mAdapter;
  private ActionBar actionBar;
  private String[] tabs ={"????????", "?????", "????? ??????"
    };

  //!----------
  AdapterManager _adapterManager;
  ResponseHandler receiver;

    // Shared preferences to detect first run
    SharedPreferences prefs = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_screen);

        AppRater.appLaunched(getContext());

        // Initializations
        prefs = getSharedPreferences("com.uth.uthportal", MODE_PRIVATE);


        mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

        viewPager = (ViewPager) findViewById(R.id.pager);
        viewPager.setAdapter(mAdapter);
        viewPager.setPageTransformer(false, new ZoomOutPageTransformer());
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            //listener to make a tab selected when the view is switched by swiping.
            @Override
            public void onPageSelected(int position) {
                //make the tab item selected.
                actionBar.setSelectedNavigationItem(position);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
            }
        });

        actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setHomeButtonEnabled(false);
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

            for (String tab_name : tabs) {
                actionBar.addTab(
                        actionBar.newTab()
                            .setText(tab_name)
                            .setTabListener(this)); //This class implements ActionBar.TabListener
            }
        }


        //Receive broadcast intent filters
        IntentFilter filter = new IntentFilter(DataSyncService.ACTION_RESP);
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        receiver = new ResponseHandler(); //bind response handler
        registerReceiver(receiver, filter);
        //!-------

        //initialize adapter manager
        _adapterManager = new AdapterManager(getContext());

        Intent calledIntent = getIntent();
        if (calledIntent.getAction().equals(DataSyncService.NOTIFY_INTENT)) {
            //Opened by a notification click
            int notificationType =
                    calledIntent.getIntExtra(DataSyncService.PARAM_NOTIFICATION_TYPE, -1);

            switch (notificationType) {
                case DataSyncService.NOTIFY_COURSE:
                    actionBar.setSelectedNavigationItem(0);
                    break;
                case DataSyncService.NOTIFY_GEN:
                    actionBar.setSelectedNavigationItem(1);
                    break;
                case DataSyncService.NOTIFY_FOOD:
                    actionBar.setSelectedNavigationItem(2);
                    break;
            }
        }

        //Start update service
        Intent msgIntent = new Intent(this, DataSyncService.class);
        // msgIntent.putExtra(SimpleIntentService.PARAM_IN_MSG, strInputMsg);
        startService(msgIntent);
  }

    @Override
    protected void onResume() {
        super.onResume();

        if (prefs.getBoolean("first_run", true)) {
            // Show about screen on first run
            startActivity(new Intent(this, AboutScreen.class));
            Toast.makeText(
                    getContext(),
                    "??? ??????? ????????? ????????\n??? ??? ?????????? ???? ?????",
                    Toast.LENGTH_LONG
            ).show();

            prefs.edit().putBoolean("first_run", false).apply();
        }
    }

  @Override
  protected void onDestroy(){
    unregisterReceiver(receiver);
    super.onDestroy();
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    //TODO: add more items to the menu
    getMenuInflater().inflate(R.menu.main_screen, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle item selection
        Intent intent;
      switch (item.getItemId()) {
        case R.id.action_settings:
            intent = new Intent(this, SettingsScreen.class);
                startActivity(intent);
                break;
            case R.id.action_about:
                intent = new Intent(this, AboutScreen.class);
                startActivity(intent);
                break;
            case R.id.action_refresh:
                intent = new Intent(this, DataSyncService.class);
                startService(intent);
                _adapterManager.refreshCoursesAdapter((ExpandableListView)findViewById(R.id.coursesList));
                _adapterManager.refreshGeneralAnnAdapter((ExpandableListView)findViewById(R.id.generalAnnList));
                _adapterManager.refreshFoodAdapter((ExpandableListView)findViewById(R.id.foodList));
                break;
        default:
                return super.onOptionsItemSelected(item);
      }

        return super.onOptionsItemSelected(item);
  }
  @Override
  public void onTabReselected(Tab tab, FragmentTransaction ft) {
        onTabSelected(tab, ft);
  }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // using this, so OnCreate() is not called on orientation changes

        /* Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        }
        */
    }

    @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {
    //we have to refresh adapters each item our tab is selected
     viewPager.setCurrentItem(tab.getPosition());
     if(_adapterManager!=null){
       switch(tab.getPosition()){
         case 0:
           _adapterManager.refreshCoursesAdapter((ExpandableListView)findViewById(R.id.coursesList));
         case 1:
           _adapterManager.refreshGeneralAnnAdapter((ExpandableListView)findViewById(R.id.generalAnnList));
         case 2:
           _adapterManager.refreshFoodAdapter((ExpandableListView)findViewById(R.id.foodList));
       }
     }
    
  }

  @Override
  public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    
  }

  public class ResponseHandler extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle extras = intent.getExtras();
            if(!extras.getBoolean(DataSyncService.PARAM_RESULT)){
                 //we got error.
                Toast.makeText(
                    getContext(),
                    "Error!: " + extras.getString(DataSyncService.PARAM_ERROR),
                    Toast.LENGTH_LONG
                ).show();
            } else {
                //receive logic is implemented here
                 String type = extras.getString(DataSyncService.PARAM_TYPE);
                 if(type.equals(DataSyncService.TYPE_COURSES)){
                     //we got courses broadcasted
                    List<String> list = (List<String>)extras.getSerializable(DataSyncService.PARAM_ITEM);
                    CoursesParser coursesParser = new CoursesParser();
                    List<Course> courses = coursesParser.parseCourses(list);

                    _adapterManager.setCoursesList(courses, (ExpandableListView)findViewById(R.id.coursesList));

                 } else if(type.equals(DataSyncService.TYPE_FOOD)){
                     //we got food broadcasted
                    String foodBuffer = extras.getString(DataSyncService.PARAM_ITEM);
                    FoodParser foodParser = new FoodParser();
                    Food food = foodParser.parseFood(foodBuffer);
                    if (foodParser.wasSuccessful){
                        _adapterManager.setFood(food, (ExpandableListView)findViewById(R.id.foodList));
                    } else {
                        Log.e("e.ms.Error parsing food", foodParser.errorMessage);
                    }

                 } else if (type.equals(DataSyncService.TYPE_DEPARTMENT)) {
                     //we got general announcements broadcasted
                     String annBuffer = extras.getString(DataSyncService.PARAM_ITEM);
                     GeneralAnnParser generalAnnParser = new GeneralAnnParser();
                     List<GeneralAnnouncement> announcements = generalAnnParser.parseGeneralAnnouncements(annBuffer);
                     if (generalAnnParser.wasSuccessful) {
                         _adapterManager.setGeneralAnnList(announcements, (ExpandableListView) findViewById(R.id.generalAnnList));
                     } else {
                         Log.e("e.ms.Error parsing general ann.", generalAnnParser.errorMessage);
                     }
                 }

            }//if
       }//onReceive
  }
  public Context getContext(){
        return this;
  }
}




Java Source Code List

com.uth.uthportal.AboutScreen.java
com.uth.uthportal.CoursesFragment.java
com.uth.uthportal.DepartmentFragment.java
com.uth.uthportal.FoodFragment.java
com.uth.uthportal.MainScreen.java
com.uth.uthportal.SettingsScreen.java
com.uth.uthportal.adapter.AdapterManager.java
com.uth.uthportal.adapter.AdapterProvider.java
com.uth.uthportal.adapter.ExpandableListAdapter.java
com.uth.uthportal.adapter.SettingsAdapter.java
com.uth.uthportal.adapter.TabsPagerAdapter.java
com.uth.uthportal.buffers.AvailableCoursesParser.java
com.uth.uthportal.buffers.CoursesParser.java
com.uth.uthportal.buffers.FileOperation.java
com.uth.uthportal.buffers.FoodParser.java
com.uth.uthportal.buffers.GeneralAnnParser.java
com.uth.uthportal.buffers.SettingsManager.java
com.uth.uthportal.collections.AnnItem.java
com.uth.uthportal.collections.Announcements.java
com.uth.uthportal.collections.AvailableCourse.java
com.uth.uthportal.collections.CourseInfo.java
com.uth.uthportal.collections.Course.java
com.uth.uthportal.collections.DayMenu.java
com.uth.uthportal.collections.DefaultIntervals.java
com.uth.uthportal.collections.Dish.java
com.uth.uthportal.collections.Food.java
com.uth.uthportal.collections.GeneralAnnouncement.java
com.uth.uthportal.collections.Settings.java
com.uth.uthportal.network.ApiLinks.java
com.uth.uthportal.network.AppRater.java
com.uth.uthportal.network.AsyncJSONDownloader.java
com.uth.uthportal.network.JSONDownloader.java
com.uth.uthportal.service.DataSyncService.java
com.uth.uthportal.util.SystemUiHiderBase.java
com.uth.uthportal.util.SystemUiHiderHoneycomb.java
com.uth.uthportal.util.SystemUiHider.java