AboutActivity.java
/*
* Copyright 2016 the Cook-E development team
*
* This file is part of Cook-E.
*
* Cook-E is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cook-E is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cook-E. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cook_e.cook_e;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
public class AboutActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setUpActionBar();
final Button websiteButton = (Button) findViewById(R.id.website_button);
websiteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
"https://cook-e-team.github.io/Cook-E/user/"));
startActivity(browserIntent);
}
});
}
private void setUpActionBar() {
final ActionBar bar = getSupportActionBar();
if (bar != null) {
bar.setDisplayHomeAsUpEnabled(true);
try {
final PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
bar.setTitle(String.format(
getResources().getText(R.string.about_heading).toString(), info.versionName,
info.versionCode));
} catch (PackageManager.NameNotFoundException e) {
bar.setTitle(R.string.app_name);
}
}
}
/*
* This is a workaround for inconsistent behavior.
*
* Pressing the system back button or calling finish() returns a result to the parent activity,
* as expected. However, the default action when the up button is pressed does not send a result
* to the parent. This override ensures that a result is sent when the action bar up button is
* pressed.
*/
@Override
public boolean onSupportNavigateUp() {
finish();
return true;
}
}