recall

/*
 * Copyright (c) 201020xxx BYD Corporation.  All rights reserved.
 *
 * BYD Corporation and its licensors retain all intellectual property
 * and proprietary rights in and to this software, related documentation
 * and any modifications thereto.  Any use, reproduction, disclosure or
 * distribution of this software and related documentation without an express
 * license agreement from BYD Corporation is strictly prohibited.
 *
 * File Name:  bp_log.c
 *
 * General Description: This file implements all the bp panic block log functions.
 *
 *
 *    Date               Author            CR/PR                Reference
 *    ========      ========     ==========      ==========================
 *    2010-12-13    Huang.jinhu             T601T_C000067     Add recall function
 *    2010-12-25 huangjinhu    T601T_P000199 Can not auto redial successfully after redial twice.
 */

package com.android.phone;

import android.app.Activity;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.content.ContextWrapper;
import com.android.internal.app.AlertActivity;
import com.android.internal.app.AlertController;
import java.util.Timer;
import java.util.TimerTask;
import com.android.internal.telephony.Connection;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;

 

public class reCall extends AlertActivity implements DialogInterface.OnClickListener {
 private Timer timer=new Timer();
 private String numStr;
 private String cause;
 private long time;
 private PhoneApp app;
 WakeLock wakeLock;
 KeyguardManager mKeyguardManager=null;
 KeyguardLock mKeyguardLock=null;
 //send intent for recall
 Handler handler = new Handler(){  
        public void handleMessage(Message msg) {          
             Intent inte=new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+numStr));
       startActivity(inte);
       finish();         
            super.handleMessage(msg);  
        }  
          
    };
 private TimerTask timetask=new TimerTask() {
  public void run() {
   Message message = new Message();         
            handler.sendMessage(message);    
  }
 };
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  app=PhoneApp.getInstance();
  Log.i("reCall oncreate+","+");
  Bundle extras = getIntent().getExtras();
  cause = extras.getString("cause");
  numStr=extras.getString("num");
  time=extras.getLong("time");
  
  //key guard manager for dialog
  mKeyguardManager= (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
        mKeyguardLock= mKeyguardManager.newKeyguardLock("");
        createDialog(cause);
        timer.schedule(timetask, time);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
  
       
 }
  protected void onResume () {
   super.onResume();
   Log.i("reCall onResum cause+","+cause="+cause+" numStr="+numStr+" time="+time);
   acquireWakeLock();
   mKeyguardLock.disableKeyguard();
     }
  protected void onPause () {
   super.onPause();
   Log.i("reCall onPause+","+finish");
   mKeyguardLock.reenableKeyguard();
   releaseWakeLock();
     }
 
 //create dialog for recall
 public void createDialog(String causeStr)
 {
  AlertController.AlertParams p = mAlertParams;
  p.mIconId = android.R.drawable.ic_dialog_alert;
        p.mTitle = getResources().getString(R.string.reCall_title);
       
        //T601T_P000199 hjh change connection state from enumerate --begin
        if(causeStr.equals(String.valueOf(Connection.RedialFailCause.USER_BUSY)))
        {
         p.mMessage=getResources().getString(R.string.reCall_message_busy);
        }
        if(causeStr.equals(String.valueOf(Connection.RedialFailCause.TEMPORARY_FAILURE)))
        {
         p.mMessage=getResources().getString(R.string.reCall_message_no_response);
        }
        if(causeStr.equals(String.valueOf(Connection.RedialFailCause.PERMANENT_FAILURE)))
        {
         p.mMessage=getResources().getString(R.string.reCall_message_error);
        }
        //--end--
       
        p.mNegativeButtonText = getResources().getString(R.string.reCall_Cancel);
        p.mNegativeButtonListener = this;
        setupAlert();
 }
 
 
 public void onClick(DialogInterface dialog, int which)
 {
  app.notifier.setOristate();
 }
    public boolean onKeyDown(int keyCode, KeyEvent event) {  
     return false;
    } 
 private void acquireWakeLock() {
       if(wakeLock ==null) {
           PowerManager pm =(PowerManager) getSystemService(Context.POWER_SERVICE);
           wakeLock =pm.newWakeLock(PowerManager.FULL_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP,  this.getClass().getCanonicalName());
           wakeLock.acquire();
          }
   }
 private void releaseWakeLock() {
        if(wakeLock !=null&&wakeLock.isHeld()) {
        wakeLock.release();
        wakeLock =null;
           }
   }
 protected void onStart () {
  Log.d("reCall onstart +","+");
  super.onStart();
    }
    protected void onStop () {
     Log.d("reCall onstop +","+");
     super.onStop();
     timer.cancel();
    }
    protected void onDestroy () {
     Log.d("reCall ondestroy +","+");
     super.onDestroy();
    }

}

你可能感兴趣的:(recall)