2017-11-18 8 views
0

私は問題なく完全にうまくいきますが、ロックスクリーンを無効にしたい場合は、このチェックボックスをオフにしてユーザーがチェックボックスをチェックすると有効にします。 それは私のロック画面くれmy checknox in lockscreen menu NU私のチェックボックスをオフにする方法私のロック画面を無効にする

はこの画像では、チェックボックスがあると私は、ユーザーがそれ

01をクリックしたときに何をすべきか知っておく必要があります私のロック画面コード

public class LockscreenService extends Service { 
private LinearLayout linearLayout; 
private WindowManager.LayoutParams layoutParams; 
private WindowManager windowManager; 
String p; 
ImageView img,aimg; 
final ArrayList<Bitmap> beforeshuffle = new ArrayList<>(9); 
final ArrayList<Bitmap> aftershuffle = new ArrayList<>(9); 
ArrayList<Bitmap> smallimages = new ArrayList<Bitmap>(9); 
GridView grid; 
Bitmap bs; 
Bitmap as; 
@Nullable 
@Override 
public IBinder onBind(Intent intent) { 
    return null; 
} 
BroadcastReceiver screenReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF) && linearLayout == null) { 
      init(); 
     } 
    } 
}; 
@Override 
public void onCreate() { 
    super.onCreate(); 
    IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); 
    registerReceiver(screenReceiver, intentFilter); 
    windowManager = ((WindowManager) getSystemService(WINDOW_SERVICE)); 
    layoutParams = new WindowManager.LayoutParams(
      WindowManager.LayoutParams.MATCH_PARENT, 
      WindowManager.LayoutParams.MATCH_PARENT, 
      WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, 
      WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN 
        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION, 
      PixelFormat.TRANSLUCENT); 
} 
private void init() { 
    linearLayout = new LinearLayout(this); 
    windowManager.addView(linearLayout, layoutParams); 
    ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.lockscreen, linearLayout); 
    // View btnClose = linearLayout.findViewById(R.id.button); 
    img = (ImageView) linearLayout.findViewById(R.id.bs); 
    aimg = (ImageView) linearLayout.findViewById(R.id.as); 
    grid = (GridView) linearLayout.findViewById(R.id.gridView); 
    Globalvariable c=new Globalvariable(); 
    bs=c.giveBitmap(); 

    String p="/data/user/0/com.example.user.myapplication/app_imageDir/profile.jpg"; 
    Toast.makeText(getApplication(),p,Toast.LENGTH_SHORT).show(); 
    Log.d("path",p); 
    String bspath="/data/user/0/com.example.user.myapplication/app_Beforeshuffle/beforeshuffle"; 





    bs=loadImageFromStorage(bspath); 

    // Bitmap bitmap = (Bitmap) i.getParcelableExtra("bitmap"); 

    //smallimage_Numbers is to tell how many smallimage_s the image should split 

    int smallimage_Numbers = 9; 

    //Getting the source image to split 

    // ImageView image = (ImageView) findViewById(R.id.source_image); 
    // File imgFile = new File("profile.jpg" 

    Bitmap myBitmap = BitmapFactory.decodeFile(p); 
    splitImage(myBitmap, smallimage_Numbers); 
    View btnClose = linearLayout.findViewById(R.id.button8); 
    btnClose.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      img.setImageBitmap(bs); 
      as=getBitmapFromView(grid); 
      aimg.setImageBitmap(as); 
      Bitmap a=getBitmapFromView(img); 
      Bitmap b=getBitmapFromView(aimg); 
      img.setVisibility(View.INVISIBLE); 
      aimg.setVisibility(View.INVISIBLE); 
      // do something when the corky3 is clicked 
      if(b.sameAs(a)){ 
      // Toast.makeText(getApplicationContext(),"CORRECT",Toast.LENGTH_SHORT).show(); 
       ///Intent service = new Intent(LockscreenService.this, calculator.class); 
       // startService(service); 
       Intent service = new Intent(LockscreenService.this, caclservice.class); 
       startService(service); 
       // windowManager.removeView(linearLayout); 
       // linearLayout = null; 
      } 
      else 
      { 
       Log.d("jhgeiugh","jhgfeug"); 
       // Toast.makeText(getApplicationContext(),"WRONG",Toast.LENGTH_SHORT).show(); 
      } 

     } 
    }); 

を 行います共有好みに

コード

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main_layout); 
    sharedPreferences =getSharedPreferences(mypreference, Context.MODE_PRIVATE); 
    final IntentFilter filter = new IntentFilter(); 
    filter.addAction(Intent.ACTION_SCREEN_OFF); 
CustomList adapter = new 
     CustomList(this, web, imageId); 
list=(ListView)findViewById(R.id.List); 
list.setAdapter(adapter); 
list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

    @Override 
    public void onItemClick(AdapterView<?> parent, View view, 
          int position, long id) { 
     final CheckBox cb = (CheckBox) view.findViewById(R.id.cb); 
     if (position == 1) { 
      startActivity(new Intent(getApplicationContext(), ChangePassword.class)); 
     } else if (position == 2) { 
      startActivity(new Intent(getApplicationContext(), Changephoto.class)); 
     } else if (position == 4) { 
      startActivity(new Intent(getApplicationContext(), Puzzle.class)); 
     } else if (position == 5) { 
      startActivity(new Intent(getApplicationContext(), choosephoto.class)); 
     } 



    } 
}); 

    cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
     @Override 
     public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { 

      if(isChecked){ 
       Log.d("ghjk", "ghfu"); 
       sharedPreferences = getSharedPreferences(mypreference, Context.MODE_PRIVATE); 
       SharedPreferences.Editor editor = sharedPreferences.edit(); 
       editor.putString(name1, "true"); 
       editor.commit(); 
       cb.setChecked(true); 
       KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE); 
       KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); 
       lock.reenableKeyguard(); 
      }else { 
       sharedPreferences = getSharedPreferences(mypreference, Context.MODE_PRIVATE); 
       SharedPreferences.Editor editor = sharedPreferences.edit(); 
       editor.putString(name1, "false"); 
       editor.commit(); 
       KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE); 
       KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE); 
       lock.reenableKeyguard(); 
      } 
     } 
    }); 

    if(sharedPreferences.contains(name1)){ 
     String b=sharedPreferences.getString(name1,""); 
     Log.d("dsf",b); 
     if(b.equals("true")) { 
      cb.setChecked(true); 
     }else 
     { 
      cb.setChecked(false); 
     } 
    } 
+0

のような放送受信機の登録を解除することを確認そのチェックボックスがチェックされている/選択されていない場合、共有設定にある価値を保存します。その値をチェックしてサービスを有効/無効にします –

+0

無効にすることは意味ですか?パズルの機能を無効/有効にしたい場合は、ロック画面を保護するだけでチェックボックスの切り替えを開始/停止することができます。 –

答えて

0

私は、チェックボックスにフラグを格納し@ashwinで述べたような問題を解決し、フラグ値は、あなたが何をすべきか、この

BroadcastReceiver screenReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     boolean b = sp.getBoolean(name4, false); 
     if(b) 
     { 
      if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF) && linearLayout == null) { 
       init(); 
      } 

     }else 
      unregisterReceiver(screenReceiver); 

    } 
}; 
関連する問題