Skip to content

Instantly share code, notes, and snippets.

@RamitPahwa
Last active Jul 27, 2021
Embed
What would you like to do?
public class AppRestrictionSchemaFragment extends Fragment implements View.OnClickListener
{
private static final String KEY_CAN_SAY_HELLO = "can_say_hello";
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
mTextSayHello = (TextView) view.findViewById(R.id.say_hello_explanation);
mButtonSayHello.setOnClickListener(this);
}
@Override
public void onResume() {
super.onResume();
resolveRestrictions();
updateCanSayHello();
}
@Override
public void onStart()
{
super.onStart();
// We need to create a broadcast receiver for ACTION_APPLICATION_RESTRICTIONS_CHANGED which send out a broadcast when restrictions change
mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent)
{
resolveRestrictions();
updateCanSayHello();
}
};
getActivity().registerReceiver(mBroadcastReceiver,new IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED));
}
@Override
public void onStop()
{
super.onStop();
if (mBroadcastReceiver != null) {
getActivity().unregisterReceiver(mBroadcastReceiver);
mBroadcastReceiver = null;
}
}
@Override
public void onClick(View view)
{
switch (view.getId())
{
case R.id.say_hello:
{
Toast.makeText(getActivity(), getString(R.string.message, mMessage),
Toast.LENGTH_SHORT).show();
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment