Android Open Source - BCC Install Activity






From Project

Back to project page BCC.

License

The source code is released under:

MIT License

If you think the Android project BCC 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

/*
 * Copyright (C) 2009 IT Wizard.//ww  w.j  a v  a2s .  c  o  m
 * http://www.itwizard.ro
 *
 * 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.
 */

package com.itwizard.mezzofanti;

import com.bcc.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;

/**
 * 
 * wrapper activity for the AssetsManager 
 *
 */
public class InstallActivity extends Activity 
{
  private static final String TAG = "MLOG: InstallActivity.java: ";
  
  private ProgressBar m_LocalProgressBar = null;      // parent progress bar, to indicate the install status
  private static Handler m_ParentMessageHandler = null;  // parent message handler, for communication
  private AssetsManager m_AssetsManager = null;      // local AssetsManager, to install the language assets from the package

  /**
   * set the parent message handler, for later communication
   * @param mh parent message handler
   */
  public static void SetParentMessageHandler(Handler mh)
  {
    m_ParentMessageHandler = mh;
  }
  
  /**
   * the onCreate method: allocate all variables
   */
  public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        
        try
        {
          Log.v(TAG, "Starting app ---------------------------");
          this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
          
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
          
          // never enter standby when camera open
          Window window = getWindow();
          window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            
          // set the layout to the xml definition
          setContentView(R.layout.install);
            /*EditText tbox = (EditText) findViewById(R.id.installactivity_welcome_text);
            tbox.setText(R.string.installactivity_mainMessage);
            
            tbox.setOnLongClickListener(new View.OnLongClickListener()
            {
        //@Override
        public boolean onLongClick(View v) {
          return true;
        }
              
            });
            tbox.setOnClickListener(new View.OnClickListener()
            {
        //@Override
        public void onClick(View v) {
        }
              
            });*/
            Log.v(TAG, "welcome");
            
            
            m_LocalProgressBar = (ProgressBar) findViewById(R.id.installactivity_progressbar);
            m_AssetsManager = new AssetsManager(m_LocalMessageHandler, m_LocalProgressBar);
            m_AssetsManager.InstallLanguageAssetsJob();
        }
        catch (Exception ex)
        {
          Log.e(TAG, "mexeption: " + ex.toString());
        }
        catch (Throwable t)
        {
          Log.e(TAG, "mexpcetion: " + t.toString());
        }
    }
  
  
  @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) 
  {    
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        if ( keyCode == KeyEvent.KEYCODE_BACK )
        {   // if "BACK-KEY" pressed
            if (event.getRepeatCount() == 0)
            {
              if (AssetsManager.IsInstalled() == false)
              {
                // installation stopped by user, before it ended: we do not have valid langs, so we shut down
                SendKillToParent();
              }
            }  
        }
        
        return super.onKeyDown(keyCode, event);
    }
  
  /**
   * the installation finished, thus we hide the status bar and diplay the "start-app" button
   */
  private void InstallFinishedStartApp()
  {
    m_LocalProgressBar.setVisibility(View.GONE);
    /*TextView tv = (TextView) findViewById(R.id.installactivity_status_text);
    tv.setVisibility(View.GONE);
    
    Button bt = (Button) findViewById(R.id.installactivity_buttondone);
    bt.setVisibility(View.VISIBLE);
    bt.setOnClickListener(new View.OnClickListener()
      {
        //@Override
        public void onClick(View v) 
        {
          finish();
        }
      }
    );*/
  }

  /**
   * used by the AssetsManager for communication
   */
  private Handler m_LocalMessageHandler = new Handler() 
  {
    @Override
    public void handleMessage(Message msg) 
    {
      switch(msg.what)
      {
        // ---------------------------------------------------------------
        case R.id.assetsmanager_installingdone:
        {
                Log.v(TAG, "Installing done.");
          Bundle bdl = msg.getData();
          boolean bModifOnDisk = bdl.getBoolean("modifondisk");
          if (bModifOnDisk)
            OCR.mConfig.LoadFabricDefaults();
          
            InstallFinishedStartApp();
            finish();
          break;
        }  
          // ---------------------------------------------------------------        
        case R.id.assetsmanager_installingcorrupted:
        {
          Bundle bdl = msg.getData();
          long lNeededSpace = bdl.getLong("needed_space");
          long lFreeSpace = bdl.getLong("free_space");
          DisplayProblemsInstallingAlert(lNeededSpace, lFreeSpace);
              break;
        }
        default:
          break;
          
      }
      
      super.handleMessage(msg);
    }
  };
  
  private void DisplayProblemsInstallingAlert(long lNeededSpace, long lFreeSpace)
  {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setIcon(R.drawable.alert32);
      builder.setTitle(R.string.assetsmanager_title);
      builder.setMessage(getString(R.string.assetsmanager_msg1) + (lNeededSpace/(1024*1024)) + "[MB] " 
          + getString(R.string.assetsmanager_msg2)+ (lFreeSpace/(1024*1024)) + "[MB]");
      builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
      {
      //@Override
      public void onClick(DialogInterface dialog, int which) 
      {
        SendKillToParent();
        finish();
      }
        
      });
      builder.setCancelable(false);
      builder.show();
      
  }

  
  private void SendKillToParent()
  {
    Log.v(TAG, "Send kill to parent");
    m_ParentMessageHandler.sendEmptyMessageDelayed(R.id.installactivity_killApp, 500);
  }

}




Java Source Code List

com.bcc.AddBCCManage.java
com.bcc.AddBCC.java
com.bcc.BCCActivity.java
com.bcc.ImportExportBCC.java
com.bcc.ImportExportManage.java
com.bcc.OCRResult.java
com.bcc.SetPrefs.java
com.bcc.util.BCCUtil.java
com.bcc.util.Facade.java
com.bcc.util.adaptor.ManageBCCListAdaptor.java
com.bcc.util.adaptor.ManageListAdaptor.java
com.itwizard.mezzofanti.AssetsManager.java
com.itwizard.mezzofanti.CameraManager.java
com.itwizard.mezzofanti.CaptureLayout.java
com.itwizard.mezzofanti.CustomImageButton.java
com.itwizard.mezzofanti.DownloadManager.java
com.itwizard.mezzofanti.InstallActivity.java
com.itwizard.mezzofanti.Mezzofanti.java
com.itwizard.mezzofanti.OCR.java
com.itwizard.mezzofanti.OnScreenHint.java
com.sdsu.bcc.BCCConstants.java
com.sdsu.bcc.database.DatabaseImpl.java
com.sdsu.bcc.database.DatabaseOperation.java
com.sdsu.bcc.database.data.CardInformation.java
com.sdsu.bcc.database.data.CategoryInformation.java
com.sdsu.bcc.database.data.ContactInformation.java
com.sdsu.bcc.database.data.FilesInformation.java
com.sdsu.bcc.database.data.ImageInformation.java
com.sdsu.bcc.database.impl.BCCDataStore.java
com.sdsu.bcc.database.impl.CategoryDataStore.java
com.sdsu.bcc.database.impl.ContactDataStore.java
com.sdsu.bcc.database.impl.FilesDataStore.java
com.sdsu.bcc.database.impl.ImageDataStore.java
com.sdsu.bcc.file.FileDataStoreFactory.java
com.sdsu.bcc.file.FileDataStoreOperations.java
com.sdsu.bcc.file.impl.CSVDataStore.java