Android Open Source - UTMShuttleAndroid Main Activity






From Project

Back to project page UTMShuttleAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project UTMShuttleAndroid 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 activities;
//from  ww  w  . ja v  a2 s  .  c o  m
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState;
import com.nineoldandroids.view.ViewPropertyAnimator;

import adapters.TimesListAdapter;
import async.NoticesTask;
import async.RoutesTask;
import global.App;
import me.echeung.utmshuttleandroid.R;
import util.NetworkHelper;


public class MainActivity extends ActionBarActivity implements ObservableScrollViewCallbacks {

    private Toolbar mToolbar;
    private LinearLayout mRouteSelector;

    private View mFab;
    private boolean mFabIsShown;

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

        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mRouteSelector = (LinearLayout) findViewById(R.id.route_selector);

        ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.container);
        scrollView.setScrollViewCallbacks(this);

        if (NetworkHelper.isNetworkAvailable(this)) {
            LinearLayout mTimesList = (LinearLayout) findViewById(R.id.times_list);

            mFab = findViewById(R.id.fab);
//            ViewHelper.setScaleX(mFab, 0);
//            ViewHelper.setScaleY(mFab, 0);
            mFab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getBaseContext(), "Clicked FAB", Toast.LENGTH_SHORT).show();
                }
            });

            TextView mDate = (TextView) findViewById(R.id.date);
            mDate.setText(App.getStrDate());

            TextView mNotices = (TextView) findViewById(R.id.notice);
            TimesListAdapter adapter = new TimesListAdapter(this, mTimesList);

            new RoutesTask(App.getMonth(),
                    App.getDate(),
                    App.getYear(),
                    adapter).execute();

            new NoticesTask(this, mNotices).execute();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onScrollChanged(int i, boolean b, boolean b2) {

//        https://github.com/ksoichiro/Android-ObservableScrollView/blob/master/observablescrollview-samples/src/main/java/com/github/ksoichiro/android/observablescrollview/samples/FlexibleSpaceWithImageScrollViewActivity.java

    }

    @Override
    public void onDownMotionEvent() {
    }

    @Override
    public void onUpOrCancelMotionEvent(ScrollState scrollState) {
//        ActionBar ab = getSupportActionBar();
//        if (scrollState == ScrollState.UP) {
//            if (ab.isShowing()) {
//                ab.hide();
//            }
//        } else if (scrollState == ScrollState.DOWN) {
//            if (!ab.isShowing()) {
//                ab.show();
//            }
//        }
    }

    private void showFab() {
        if (!mFabIsShown) {
            ViewPropertyAnimator.animate(mFab).cancel();
            ViewPropertyAnimator.animate(mFab).scaleX(1).scaleY(1).setDuration(200).start();
            mFabIsShown = true;
        }
    }

    private void hideFab() {
        if (mFabIsShown) {
            ViewPropertyAnimator.animate(mFab).cancel();
            ViewPropertyAnimator.animate(mFab).scaleX(0).scaleY(0).setDuration(200).start();
            mFabIsShown = false;
        }
    }
}




Java Source Code List

activities.MainActivity.java
adapters.TimesListAdapter.java
async.NoticesTask.java
async.RoutesTask.java
classes.Route.java
classes.Routes.java
global.App.java
util.NetworkHelper.java
util.Scraper.java