|
| 1 | +/* |
| 2 | + * Copyright 2016 the Cook-E development team |
| 3 | + * |
| 4 | + * This file is part of Cook-E. |
| 5 | + * |
| 6 | + * Cook-E is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * Cook-E is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with Cook-E. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.cook_e.cook_e; |
| 21 | + |
| 22 | +import android.content.Intent; |
| 23 | +import android.content.pm.PackageInfo; |
| 24 | +import android.content.pm.PackageManager; |
| 25 | +import android.net.Uri; |
| 26 | +import android.support.v7.app.ActionBar; |
| 27 | +import android.support.v7.app.AppCompatActivity; |
| 28 | +import android.os.Bundle; |
| 29 | +import android.support.v7.widget.Toolbar; |
| 30 | +import android.view.View; |
| 31 | +import android.widget.Button; |
| 32 | + |
| 33 | +public class AboutActivity extends AppCompatActivity { |
| 34 | + |
| 35 | + @Override |
| 36 | + protected void onCreate(Bundle savedInstanceState) { |
| 37 | + super.onCreate(savedInstanceState); |
| 38 | + setContentView(R.layout.activity_about); |
| 39 | + |
| 40 | + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
| 41 | + setSupportActionBar(toolbar); |
| 42 | + setUpActionBar(); |
| 43 | + |
| 44 | + |
| 45 | + final Button websiteButton = (Button) findViewById(R.id.website_button); |
| 46 | + websiteButton.setOnClickListener(new View.OnClickListener() { |
| 47 | + @Override |
| 48 | + public void onClick(View v) { |
| 49 | + final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse( |
| 50 | + "https://cook-e-team.github.io/Cook-E/user/")); |
| 51 | + startActivity(browserIntent); |
| 52 | + } |
| 53 | + }); |
| 54 | + } |
| 55 | + |
| 56 | + private void setUpActionBar() { |
| 57 | + final ActionBar bar = getSupportActionBar(); |
| 58 | + if (bar != null) { |
| 59 | + bar.setDisplayHomeAsUpEnabled(true); |
| 60 | + try { |
| 61 | + final PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0); |
| 62 | + bar.setTitle(String.format( |
| 63 | + getResources().getText(R.string.about_heading).toString(), info.versionName, |
| 64 | + info.versionCode)); |
| 65 | + } catch (PackageManager.NameNotFoundException e) { |
| 66 | + bar.setTitle(R.string.app_name); |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /* |
| 72 | + * This is a workaround for inconsistent behavior. |
| 73 | + * |
| 74 | + * Pressing the system back button or calling finish() returns a result to the parent activity, |
| 75 | + * as expected. However, the default action when the up button is pressed does not send a result |
| 76 | + * to the parent. This override ensures that a result is sent when the action bar up button is |
| 77 | + * pressed. |
| 78 | + */ |
| 79 | + @Override |
| 80 | + public boolean onSupportNavigateUp() { |
| 81 | + finish(); |
| 82 | + return true; |
| 83 | + } |
| 84 | +} |
0 commit comments