2016-04-28 5 views
0

こんにちは私のアプリケーションでは、デバイスの呼び出し元画面のルックアンドフィールを変更したいのですが(今は間違っているかもしれません)、これを行う唯一の方法はポップアップを呼び出すことですあなたがそれを変更することができないので、デフォルトのアンドロイド発信者画面の上にウィンドウ。画面上のポップアップウィンドウを修正する方法

私のポップアップウィンドウは、ユーザーがダイヤルした後に表示されますが、デフォルトの発信者画面に置き換えられます。ポップアップはデフォルトの発信者画面の後ろにあります。

どのように私は他の画面に置き換えられないように画面上のポップアップウィンドウを修正することができます。

マイDialerFragment.java:このコードが見つかり

package com.heroicjokester.android.haid; 

import android.Manifest; 
import android.content.Context; 
import android.content.Intent; 
import android.content.pm.PackageManager; 
import android.net.Uri; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.util.Log; 
import android.view.Gravity; 
import android.view.LayoutInflater; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.LinearLayout; 
import android.widget.PopupWindow; 
import android.widget.RelativeLayout; 
import android.widget.Toast; 
import android.support.v4.content.ContextCompat; 

/** 
* Created by Ripcord on 01-Apr-16. 
*/ 
public class DialerFragment extends Fragment { 
private EditText mPhoneField; 
private Button mDialButton; 
private LinearLayout mLinearLayout; 
private LayoutInflater mLayoutInflater; 
private PopupWindow mPopupWindow; 

//Requesting Permissions on Runtime. 
final private int REQUEST_CODE_ASK_PERMISSIONS=0; 

private void InitiateCall(){ 
    int hasCallPermission = ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.READ_PHONE_STATE); 
    if (hasCallPermission != PackageManager.PERMISSION_GRANTED){ 
     requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, 
       REQUEST_CODE_ASK_PERMISSIONS); 
     return; 
    } 
} 

@Override 
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){ 
    switch (requestCode){ 
     case REQUEST_CODE_ASK_PERMISSIONS: 
      if (grantResults[0]==PackageManager.PERMISSION_GRANTED){ 
       //YAY! PERMISSION GRANTED 
       InitiateCall(); 
      }else{ 
       //GD! PERMISSION DENIED 
       Toast.makeText(getActivity(), R.string.permission_denied, Toast.LENGTH_SHORT).show(); 
      } 
      break; 
     default: 
      super.onRequestPermissionsResult(requestCode, permissions, grantResults); 

    } 
} 



@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

} 

@Override 
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){ 
    View v=inflater.inflate(R.layout.fragment_dialer,container,false); 

    mPhoneField=(EditText) v.findViewById(R.id.input_pno); 
    mDialButton=(Button) v.findViewById(R.id.dial_button); 
    mLinearLayout=(LinearLayout) v.findViewById(R.id.popup_linearlayout); 

    mDialButton.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      try { 
       if (mPhoneField != null && (mPhoneField.getText().length() == 10 || mPhoneField.getText().length() == 11)) { 
        startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mPhoneField.getText()))); 
       } else if (mPhoneField != null && mPhoneField.getText().length() == 0) { 
        Toast.makeText(getActivity(), R.string.no_number_toast, Toast.LENGTH_SHORT).show(); 
       } else if (mPhoneField != null && mPhoneField.getText().length() < 10) { 
        Toast.makeText(getActivity(), R.string.wrong_number_toast, Toast.LENGTH_SHORT).show(); 
       } 
      } catch (Exception e) { 
       Log.e("DialerAppActivity", "error: " + e.getMessage(), e);//Runtime error will be logged 
      } 

      mLayoutInflater = (LayoutInflater) getActivity().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      ViewGroup container = (ViewGroup) mLayoutInflater.inflate(R.layout.dialer_popup, null); 

      mPopupWindow = new PopupWindow(container, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, false); 
      mPopupWindow.showAtLocation(mLinearLayout, Gravity.NO_GRAVITY, 0, 0); 

      container.setOnTouchListener(new View.OnTouchListener() { 
       @Override 
       public boolean onTouch(View view, MotionEvent motionEvent) { 
        Toast.makeText(getActivity(), R.string.hit_it, Toast.LENGTH_LONG).show(); 
        return true; 

       } 
      }); 

     } 
    }); 

    InitiateCall(); 

    return v; 


} 


} 
+0

問題はIntent.ACTION_CALLです。それは別のアプリの活動に行くだろう...あなたがなぜポップアップは動作しませんのです –

+0

それで周りに何か方法はありますか? これをやっているアプリケーションがありますが、それをどうやって管理しましたか? – HeroicJokester

答えて

0

、それは誤りそれらを削除する方法任意のアイデアを「変数のarg0とarg1にに解決できません」の取得ブロードキャストレシーバ イムを使用していますか?

// onReceive function of the Broadcast Receiver 
    public void onReceive(Context arg0, Intent arg1) { 
     String state = arg1.getStringExtra(TelephonyManager.EXTRA_STATE); 

     // Adds a view on top of the dialer app when it launches. 
     if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){ 
      wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); 
      params1 = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.MATCH_PARENT, 
        WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | 
        WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, 
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | 
          WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, 
        PixelFormat.TRANSPARENT); 

      params1.height = 75; 
      params1.width = 512; 
      params1.x = 265; 
      params1.y = 400; 
      params1.format = PixelFormat.TRANSLUCENT; 

      mLinearLayout = new LinearLayout(getContext()); 
      mLinearLayout.setBackgroundColor(Color.BLACK); 
      mLinearLayout.setOrientation(LinearLayout.VERTICAL); 

      wm.addView(mLinearLayout, params1); 
     } 

     // To remove the view once the dialer app is closed. 
     if(arg1.getAction().equals("android.intent.action.PHONE_STATE")){ 
      state = arg1.getStringExtra(TelephonyManager.EXTRA_STATE); 
      if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){ 
       WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); 
       if(mLinearLayout!=null) 
       { 
        wm.removeView(mLinearLayout); 
        mLinearLayout = null; 
       } 
      } 
     } 
    } 
関連する問題