当我切换到飞行模式时,如何立即禁用完成按钮?

时间:2015-11-10 13:07:02

标签: android android-layout android-fragments android-intent android-settings

我的应用程序中有一个完成按钮,当我切换到飞行模式时,我想禁用它。我的应用程序中有相同的工作代码。但是,只要我将应用程序切换到飞行模式,它就不会禁用。它仅在我切换到其他视图然后返回此视图时禁用。我的应用程序检测到离线模式的那一刻,有没有办法可以立即禁用它?到目前为止,这是我的代码:

  private static boolean isAirplaneModeOn(Context context) {

            return Settings.System.getInt(context.getContentResolver(),
                    Settings.System.AIRPLANE_MODE_ON, 0) != 0;

        }

在我的oncreateview中,我有:

if(isAirplaneModeOn(Application.getAppContext())){
            Toast toast = Toast.makeText(this.getActivity(),getResources().getString(R.string.offline), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mDoneBtn.setActivated(false);
            mDoneBtn.setTextColor(Color.DKGRAY);
            mDoneBtn.setOnClickListener(null);

        }else {
            mDoneBtn.setOnClickListener(this);
        }

有没有其他方法可以做到这一点哪个更好?或者可以改进以实现我的目标?有任何想法吗? 谢谢!

1 个答案:

答案 0 :(得分:3)

为什么不尝试禁用它:

nrows = 3;
ncols = 16;
M = zeros(nrows,ncols);    

%// seed the first row
M(1,1:ncols/2) = 1;
M(1,:) = M(1,randperm(ncols));

for r = 2:nrows

    %// Find ncols/4 random between 1 and ncols/2. These will be used to index half of the previous rows 1 elements and set them to one
    idx = randperm(ncols/2);
    idx1 =  idx(1:ncols/4);
    %// Do the same thing again, but this time it will be used for the 0 elements of the previous row
    idx = randperm(ncols/2);
    idx0 =  idx(1:ncols/4);

    idx_prev1 = find(M(r-1,:)); %// Find where the 1 elements were in the last row
    idx_prev0 = find(~M(r-1,:)); %// Find where the 0 elements were in the last row   

    M(r,idx_prev1(idx1))=1; %// Set half of the previous rows 1 elements in this row to 1
    M(r,idx_prev0(idx0))=1; %// Set half of the previous rows 0 elements in this row to 1

end