Android Open Source - example-lock-app Prompt Utils






From Project

Back to project page example-lock-app.

License

The source code is released under:

Apache License

If you think the Android project example-lock-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lockapp.fragments;
//  w  w w .  j ava  2  s. co  m
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.lockapp.R;

/**
 * Created by Andrei on 30/01/2015.
 */
public abstract class PromptUtils extends FragmentUtils {
    public static final String BROADCAST_ADMIN_ENABLED = "BROADCAST_ADMIN_ENABLED";

    private Button mModifyAdminButton;

    private BroadcastReceiver mAdminEnabledReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            swapFragment();
        }
    };

    @Override
    final public View onCreateView(final Activity activity, LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
        init(activity);
        View root = inflater.inflate(R.layout.fragment_prompt, parent, false);
        mModifyAdminButton = (Button) root.findViewById(R.id.modify_admin);
        mModifyAdminButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent addAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                addAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, getLockName());
                addAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                        "Used for locking the device");
                activity.startActivity(addAdminIntent);
            }
        });
        getSharedElement().setEnabled(true);
        return root;
    }


    @Override
    final public void checkStatus() {
        if (getLockName() != null && getPolicyManager() != null) {
            boolean adminEnabled = getPolicyManager().isAdminActive(getLockName());

            if (adminEnabled) {
                getSharedElement().setEnabled(false);
                swapFragmentDelayed();
            }
        }
    }
    @Override
    final public View getSharedElement() {
        return mModifyAdminButton;
    }

    @Override
    final public void onResume() {
        getBroadcastManager().registerReceiver(mAdminEnabledReceiver, new IntentFilter(BROADCAST_ADMIN_ENABLED));
        checkStatus();
    }

    @Override
    final public void onPause() {
        getBroadcastManager().unregisterReceiver(mAdminEnabledReceiver);
    }

}




Java Source Code List

com.lockapp.AboutActivity.java
com.lockapp.LockDeviceReceiver.java
com.lockapp.LockWidgetProvider.java
com.lockapp.MainActivity.java
com.lockapp.fragments.FragmentUtils.java
com.lockapp.fragments.NotificationStatus.java
com.lockapp.fragments.PromptUtils.java
com.lockapp.fragments.lollipop.ControlsFragment.java
com.lockapp.fragments.lollipop.ControlsUtils.java
com.lockapp.fragments.lollipop.PromptFragment.java
com.lockapp.fragments.others.ControlsFragment.java
com.lockapp.fragments.others.PromptFragment.java