Android Open Source - ExampleApp Home Activity






From Project

Back to project page ExampleApp.

License

The source code is released under:

Copyright (c) 2014, Altinn All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redis...

If you think the Android project ExampleApp 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.altinn.apps.fisher.ui.screen;
/**/*from   w  ww  .j  a v  a  2  s .c om*/
 * If user is already logged in, then after splash this screen comes in picture
 * 
 * On first launch (user is not logged in)login browser is invoked, and after completion of 
 * Login UserProfile activity is launched. and back operation on this user will be brought into HomeActivity
 * 
 * Any other subsequent launch (currently user is not logged in but earlier in the history he was ever logged in)
 * Login browser is invoked, and after completion of login user can see home screen.
 * 
 */

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.altinn.apps.fisher.AppContext;
import com.altinn.apps.fisher.R;
import com.altinn.apps.fisher.net.TaskNotifier;
import com.altinn.apps.fisher.net.tasks.UserProfileTask;
import com.altinn.apps.fisher.utils.PreferenceUtils;
import com.altinn.apps.fisher.utils.Utils;

public class HomeActivity extends BaseActivity implements OnClickListener  , TaskNotifier{

  private final String TAG = "HomeActivity";
  public static final int MENU_REPORT_RECEIVED = 101;
  public static final int MENU_REPORT_CAUGHT = 102;
  //private boolean isSettingsUpdatRequired;
  //private boolean onCreateState = true;
  private UserProfileTask mProfileTask;
  
  

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    mLayOutId = R.layout.home;
    super.onCreate(savedInstanceState);  
    init();
  }

  public void init() {
    findViewById(R.id.rl_report_action).setOnClickListener(this);
    findViewById(R.id.rl_catch_action).setOnClickListener(this);
    setTitle(R.string.title_home,-1);  
    
    if(!AppContext.TEST_MODE){
      if(!PreferenceUtils.getInstance().isUserRegistered()){    
        if(Utils.isNetworkAvailable(this)){
          Intent intentWeb = new Intent(this,BrowserActivity.class);
          intentWeb.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
          startActivityForResult(intentWeb, REQUEST_CODE);
        }else{
          displayDialog(NO_NETWORK_DIALOG_ID);
        }      
      }else{
        if(Utils.isNetworkAvailable(this)){    
          if(AppContext.getInstance().isTokenExpired()){
            Intent intentWeb = new Intent(this,BrowserActivity.class);
            intentWeb.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivityForResult(intentWeb, REQUEST_CODE);
          }else if(AppContext.getInstance().isRefreshNeeded()){
            callWebService();//this flow will take care Browser-invocation in case login failed
          }else{
            AppContext.getInstance().startRefreshTask();//Silently update the token, in case of creation of home screen
            //Because other refresh task will be invoked through scheduler AppContext.scheduleRefreshTimer
            //This scheduler refresh the token when needed, token is stale by more than 15 mins.
            //But scheduler's First refresh task will be started after 8 mins if conditions are in favor
          }
        }else{
          displayDialog(NO_NETWORK_DIALOG_ID);
        }
      }
    }
  }
  
  

  public void onDestroy() {
    AppContext.getInstance().exitApp();
    super.onDestroy();

  }
  
  protected void onInfoClicked() {

  }


  @Override
  public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.rl_report_action) {
      startActivity(ReportReceivedFishActivity.class);
    } else if (id == R.id.rl_catch_action) {
      //TODO: At present no action is scheduled for First item of home screen
      //callWebService();
      //Intent intentWeb = new Intent(this,BrowserActivity.class);
      //intentWeb.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
      //startActivityForResult(intentWeb, REQUEST_CODE);
    }

  }
  
  public void onResume(){
    super.onResume();    
  }
  
  /**
   * Action invoke to execute network operation to update user profile, and may have refresh token to authorized user of web-service
   */
  public void callWebService(Object... arguments){
    if(mProfileTask != null){
      mProfileTask.cancel(true);
    }
    mProfileTask = new UserProfileTask(this,this);
    mProfileTask.execute(arguments);
  }
  
  public void onSuccess(){
  }

  @Override
  public void onError(int message) {  
  }

  @Override
  public void onProgress() {
    // TODO Auto-generated method stub
    
  }
  
}




Java Source Code List

com.altinn.apps.fisher.AppContext.java
com.altinn.apps.fisher.CacheManager.java
com.altinn.apps.fisher.common.AppConstants.java
com.altinn.apps.fisher.common.IStatusMessage.java
com.altinn.apps.fisher.common.MenuItem.java
com.altinn.apps.fisher.common.StatusMessage.java
com.altinn.apps.fisher.db.DataBaseHelper.java
com.altinn.apps.fisher.db.FactoryDBHelper.java
com.altinn.apps.fisher.db.FishCategoryDBHelper.java
com.altinn.apps.fisher.db.FormDBHelper.java
com.altinn.apps.fisher.db.IDBHelper.java
com.altinn.apps.fisher.db.RegsDBHelper.java
com.altinn.apps.fisher.db.VesselDBHelper.java
com.altinn.apps.fisher.gps.CLocationProvider.java
com.altinn.apps.fisher.gps.ILocationUpdateListner.java
com.altinn.apps.fisher.models.CaughtInfoData.java
com.altinn.apps.fisher.models.InfoData.java
com.altinn.apps.fisher.models.ReportInfoData.java
com.altinn.apps.fisher.models.UserProfile.java
com.altinn.apps.fisher.net.AbstractWorkerTask.java
com.altinn.apps.fisher.net.CookieHelper.java
com.altinn.apps.fisher.net.IParser.java
com.altinn.apps.fisher.net.JSParser.java
com.altinn.apps.fisher.net.ParseManager.java
com.altinn.apps.fisher.net.TaskNotifier.java
com.altinn.apps.fisher.net.jsobj.AttachmentObj.java
com.altinn.apps.fisher.net.jsobj.FormObj.java
com.altinn.apps.fisher.net.jsobj.JSConstants.java
com.altinn.apps.fisher.net.jsobj.JsonObj.java
com.altinn.apps.fisher.net.jsobj.LinkItemObj.java
com.altinn.apps.fisher.net.jsobj.LinkObj.java
com.altinn.apps.fisher.net.jsobj.MessageObj.java
com.altinn.apps.fisher.net.jsobj.MessagesEmbedded.java
com.altinn.apps.fisher.net.jsobj.OrganisationObj.java
com.altinn.apps.fisher.net.tasks.LoginTask.java
com.altinn.apps.fisher.net.tasks.RefreshTokenTask.java
com.altinn.apps.fisher.net.tasks.SendReportTask.java
com.altinn.apps.fisher.net.tasks.UserProfileTask.java
com.altinn.apps.fisher.settings.FactoryDetails.java
com.altinn.apps.fisher.settings.FishDetails.java
com.altinn.apps.fisher.settings.SettingItem.java
com.altinn.apps.fisher.settings.VesselsDetails.java
com.altinn.apps.fisher.ui.component.DurationTimePickDialog.java
com.altinn.apps.fisher.ui.component.RAutoCompleteTextView.java
com.altinn.apps.fisher.ui.component.RButton.java
com.altinn.apps.fisher.ui.component.REditText.java
com.altinn.apps.fisher.ui.component.RTextView.java
com.altinn.apps.fisher.ui.screen.BaseActivity.java
com.altinn.apps.fisher.ui.screen.BrowserActivity.java
com.altinn.apps.fisher.ui.screen.FactoryDetailsActivity.java
com.altinn.apps.fisher.ui.screen.HomeActivity.java
com.altinn.apps.fisher.ui.screen.InformationActivity.java
com.altinn.apps.fisher.ui.screen.MenuNavigationActivity.java
com.altinn.apps.fisher.ui.screen.ReportActivity.java
com.altinn.apps.fisher.ui.screen.ReportReceivedFishActivity.java
com.altinn.apps.fisher.ui.screen.ReportSendDetailActivity.java
com.altinn.apps.fisher.ui.screen.SplashActivity.java
com.altinn.apps.fisher.ui.screen.UserProfileActivity.java
com.altinn.apps.fisher.utils.PreferenceUtils.java
com.altinn.apps.fisher.utils.Utils.java
net.simonvt.menudrawer.BuildLayerFrameLayout.java
net.simonvt.menudrawer.ColorDrawable.java
net.simonvt.menudrawer.DraggableDrawer.java
net.simonvt.menudrawer.FloatScroller.java
net.simonvt.menudrawer.MenuDrawer.java
net.simonvt.menudrawer.NoClickThroughFrameLayout.java
net.simonvt.menudrawer.OverlayDrawer.java
net.simonvt.menudrawer.PeekInterpolator.java
net.simonvt.menudrawer.Position.java
net.simonvt.menudrawer.Scroller.java
net.simonvt.menudrawer.SinusoidalInterpolator.java
net.simonvt.menudrawer.SlideDrawable.java
net.simonvt.menudrawer.SlidingDrawer.java
net.simonvt.menudrawer.SmoothInterpolator.java
net.simonvt.menudrawer.StaticDrawer.java
net.simonvt.menudrawer.ViewHelper.java
net.simonvt.menudrawer.compat.ActionBarHelperCompat.java
net.simonvt.menudrawer.compat.ActionBarHelperNative.java
net.simonvt.menudrawer.compat.ActionBarHelper.java