Java tutorial
/** * Copyright (c) 2017 Giovanni Terlingen * <p/> * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * <p/> * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * <p/> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. **/ package com.giovanniterlingen.windesheim.view; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.provider.Settings; import android.support.design.widget.Snackbar; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.view.View; import com.giovanniterlingen.windesheim.R; import com.giovanniterlingen.windesheim.controllers.PermissionController; import com.giovanniterlingen.windesheim.view.Fragments.ContentsFragment; /** * A schedule app for students and teachers of Windesheim * * @author Giovanni Terlingen */ public class NatschoolActivity extends AppCompatActivity { private View view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_contents); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeAsUpIndicator(R.drawable.ic_arrow_back); actionBar.setDisplayHomeAsUpEnabled(true); } view = findViewById(R.id.coordinator_layout); new PermissionController().verifyStoragePermissions(this); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.contents_fragment, new ContentsFragment()); ft.commit(); } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: super.onBackPressed(); return true; } return super.onOptionsItemSelected(item); } public void downloadCanceled() { Snackbar snackbar = Snackbar.make(view, getResources().getString(R.string.canceled_downloading), Snackbar.LENGTH_SHORT); snackbar.show(); } public void noSupportedApp() { Snackbar snackbar = Snackbar.make(view, getResources().getString(R.string.no_app_found), Snackbar.LENGTH_SHORT); snackbar.show(); } public void noPermission() { Snackbar snackbar = Snackbar.make(view, getResources().getString(R.string.no_permission), Snackbar.LENGTH_LONG); snackbar.setAction(getResources().getString(R.string.fix), new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", getPackageName(), null); intent.setData(uri); startActivity(intent); } }); snackbar.show(); } }