Java tutorial
/* * WiFiAnalyzer * Copyright (C) 2017 VREM Software Development <VREMSoftwareDevelopment@gmail.com> * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/> */ package com.vrem.wifianalyzer.about; import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.NavUtils; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; import android.view.View; import android.widget.TextView; import android.widget.Toast; import com.vrem.wifianalyzer.BuildConfig; import com.vrem.wifianalyzer.Configuration; import com.vrem.wifianalyzer.MainContext; import com.vrem.wifianalyzer.R; import com.vrem.wifianalyzer.settings.Settings; import com.vrem.wifianalyzer.settings.ThemeStyle; public class AboutActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { setCustomTheme(); super.onCreate(savedInstanceState); setContentView(R.layout.about_content); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); setExtraInformation(); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); } } private void setCustomTheme() { Settings settings = MainContext.INSTANCE.getSettings(); if (settings != null) { ThemeStyle themeStyle = settings.getThemeStyle(); setTheme(themeStyle.themeAppCompatStyle()); } } private void setExtraInformation() { String text = BuildConfig.VERSION_NAME + " - " + BuildConfig.VERSION_CODE; Configuration configuration = MainContext.INSTANCE.getConfiguration(); if (configuration != null) { if (configuration.isSizeAvailable()) { text += "S"; } if (configuration.isLargeScreen()) { text += "L"; } } text += " (" + Build.VERSION.RELEASE + "-" + Build.VERSION.SDK_INT + ")"; setText(R.id.about_version_info, text); setText(R.id.about_package_name, BuildConfig.APPLICATION_ID); } private void setText(int id, String text) { TextView version = (TextView) findViewById(id); if (version != null) { version.setText(text); } } @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } public void writeReview(@NonNull View view) { String url = "market://details?id=" + BuildConfig.APPLICATION_ID; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } } }