Skip to content

Instantly share code, notes, and snippets.

@RamitPahwa
Last active July 27, 2021 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RamitPahwa/268153e13bfb7ef7cb184093efa7b9d6 to your computer and use it in GitHub Desktop.
Save RamitPahwa/268153e13bfb7ef7cb184093efa7b9d6 to your computer and use it in GitHub Desktop.
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