Android Open Source - RobolectricSample Recent Activity Activity






From Project

Back to project page RobolectricSample.

License

The source code is released under:

MIT License

If you think the Android project RobolectricSample 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.pivotallabs.tracker;
//from ww w  .j av  a 2s.  c  om
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import com.pivotallabs.NotifyDataSetChangedCallbacks;
import com.pivotallabs.R;
import com.pivotallabs.ViewVisibleWhileOutstandingCallbacks;
import com.pivotallabs.api.ApiGateway;

public class RecentActivityActivity extends Activity {

    ApiGateway apiGateway = new ApiGateway();
    SignInDialog signInDialog;

    private AuthenticationGateway authenticationGateway;
    private RecentActivities recentActivities;
    private ViewVisibleWhileOutstandingCallbacks showLoadingWhileOutstanding;
    private NotifyDataSetChangedCallbacks notifyDataSetChangedCallbacks;

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

        authenticationGateway = new AuthenticationGateway(apiGateway, this);
        recentActivities = new RecentActivities(apiGateway, authenticationGateway);

        ListView recentActivityListView = (ListView) findViewById(R.id.recent_activity_list);

        View loadingView = getLayoutInflater().inflate(R.layout.loading_view, recentActivityListView, false);
        recentActivityListView.addFooterView(loadingView, null, false);
        recentActivityListView.setFooterDividersEnabled(false);

        RecentActivityAdapter recentActivityAdapter = new RecentActivityAdapter(recentActivities, getLayoutInflater());
        recentActivityListView.setAdapter(recentActivityAdapter);

        showLoadingWhileOutstanding = new ViewVisibleWhileOutstandingCallbacks(loadingView);
        notifyDataSetChangedCallbacks = new NotifyDataSetChangedCallbacks(recentActivityAdapter);

        updateOrSignIn();
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        menu.clear();
        addSignOutMenuItem(menu);
        return true;
    }

    private void updateOrSignIn() {
        if (authenticationGateway.isAuthenticated()) {
            update();
        } else {
            showSignInDialog();
        }
    }

    private void update() {
        recentActivities.update(
                showLoadingWhileOutstanding,
                notifyDataSetChangedCallbacks
        );
    }

    private void addSignOutMenuItem(Menu menu) {
        MenuItem signOutMenuItem = menu.add("Sign Out");
        signOutMenuItem.setEnabled(authenticationGateway.isAuthenticated());
        signOutMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                authenticationGateway.signOut();
                finish();
                return true;
            }
        });
    }

    private void showSignInDialog() {
        signInDialog = new SignInDialog(this, authenticationGateway);
        signInDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                updateOrFinish();
            }
        });
        signInDialog.show();
    }

    private void updateOrFinish() {
        if (authenticationGateway.isAuthenticated()) {
            update();
        } else {
            finish();
        }
    }
}




Java Source Code List

com.pivotallabs.AuthenticationCallbacks.java
com.pivotallabs.Callbacks.java
com.pivotallabs.EmptyOnClickListener.java
com.pivotallabs.GenericAdapter.java
com.pivotallabs.HomeActivity.java
com.pivotallabs.MultiCallbacks.java
com.pivotallabs.NamesActivity.java
com.pivotallabs.NamesAdapter.java
com.pivotallabs.NotifyDataSetChangedCallbacks.java
com.pivotallabs.OnChangeListener.java
com.pivotallabs.StubTextWatcher.java
com.pivotallabs.ViewEnablingTextWatcher.java
com.pivotallabs.ViewVisibleWhileOutstandingCallbacks.java
com.pivotallabs.api.ApiGateway.java
com.pivotallabs.api.ApiRequest.java
com.pivotallabs.api.ApiResponseCallbacks.java
com.pivotallabs.api.ApiResponse.java
com.pivotallabs.api.CertificateIgnoringSSLSocketFactory.java
com.pivotallabs.api.Http.java
com.pivotallabs.api.TrustingTrustManager.java
com.pivotallabs.api.Xmls.java
com.pivotallabs.injected.Counter.java
com.pivotallabs.injected.InjectedActivity.java
com.pivotallabs.injected.RobolectricSampleModule.java
com.pivotallabs.injected.SampleGuiceApplication.java
com.pivotallabs.tracker.AuthenticationGateway.java
com.pivotallabs.tracker.RecentActivities.java
com.pivotallabs.tracker.RecentActivityActivity.java
com.pivotallabs.tracker.RecentActivityAdapter.java
com.pivotallabs.tracker.RecentActivityRequest.java
com.pivotallabs.tracker.RecentActivity.java
com.pivotallabs.tracker.SignInDialog.java
com.pivotallabs.tracker.TrackerAuthenticationRequest.java
com.pivotallabs.util.Pair.java
com.pivotallabs.util.Strings.java