I need to create an APP with several tabs, just like intagram and WhatsApp. And that when it happens to a specific Tab, it stays in fullScreem, or at least that disappear to ActionBar, and when to move to other Tabs everything returns to normal.
PS: It's exactly the same as WhatsApp that when dragged into the Camera Tab, the screen goes fullScreem.
Activity Main
public class MainActivity extends AppCompatActivity {
private final int PERMISSAO_REQUEST = 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//deixa em FullScreem
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//IMPORTANTE: aqui verifica as permiçoes
permicoes();
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
}
private void permicoes() {
//USUARIA DAR A PERMISSAO
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CAMERA)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA},
PERMISSAO_REQUEST);
}
}
//USUARIA DAR A PERMISSAO
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
PERMISSAO_REQUEST);
}
}
}
private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int pos) {
switch(pos) {
//IMPORTANTE: Ao adicionar ou retirar case's, ATUALIZE o getCount() abaixo
case 0: return CameraFragment.newInstance("CameraFragment, Instance 1");
default: return TelaPrincipalFragment.newInstance("TelaPrincipalFragment, Default");
}
}
@Override
public int getCount() {
//IMPORTANTE representa o numero de telas (la no switch)
return 2;
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (requestCode == PERMISSAO_REQUEST) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// A permissão foi concedida. Pode continuar
} else {
// A permissão foi negada. Precisa ver o que deve ser desabilitado
}
return;
}
}
}
Fragment 1 (just a snippet)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_camera, container, false);
surfaceView = v.findViewById(R.id.surfaceView);
surfaceHolder = surfaceView.getHolder();
//Instalamos uma surfaceHolder.Callback então nós notificamos quando o underlying surface é criado e destroido.
surfaceHolder.addCallback(this);
//APARENTEMENTE essa linha nao foi necessaria
//surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
return v;
}
Fragment 2
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_tela_principal, container, false);
lvListaMaterias = (ListView) v.findViewById(R.id.lvListaMaterias);
return v;
}
Basically this is what I want during fragment 1 to be fullscreem, and when it passes pro fragment 2 the screen returns to normal with action bar, etc.