-
-
Save RamitPahwa/268153e13bfb7ef7cb184093efa7b9d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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