Instantly share code, notes, and snippets.

Embed
What would you like to do?
Main Activity Part 1 of the Lock Screen Device App for the SSaurel's Channel
package com.ssaurel.lockdevice;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button lock, disable, enable;
public static final int RESULT_ENABLE = 11;
private DevicePolicyManager devicePolicyManager;
private ComponentName compName;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
compName = new ComponentName(this, MyAdmin.class);
lock = (Button) findViewById(R.id.lock);
enable = (Button) findViewById(R.id.enableBtn);
disable = (Button) findViewById(R.id.disableBtn);
lock.setOnClickListener(this);
enable.setOnClickListener(this);
disable.setOnClickListener(this);
}
@Override
protected void onResume() {
super.onResume();
boolean isActive = devicePolicyManager.isAdminActive(compName);
disable.setVisibility(isActive ? View.VISIBLE : View.GONE);
enable.setVisibility(isActive ? View.GONE : View.VISIBLE);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment