Java tutorial
/* * Copyright (c) 2016 ? (OHMAE Ryosuke) * * This software is released under the MIT License. * http://opensource.org/licenses/MIT */ package net.mm2d.dmsexplorer; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.preference.PreferenceFragment; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; import android.view.MenuItem; import net.mm2d.android.util.LaunchUtils; import java.util.List; /** * ?Activity * * @author <a href="mailto:ryo@mm2d.net">?(OHMAE Ryosuke)</a> */ public class SettingsActivity extends AppCompatPreferenceActivity { private static final String TAG = "SettingsActivity"; /** * ??Activity????Intent?? * * <p>Extra?????????? * ???Extra?????? * * @param context * @return ??Activity????Intent */ public static Intent makeIntent(Context context) { return new Intent(context, SettingsActivity.class); } private static boolean isXLargeTablet(Context context) { return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.defaultStatusBar)); } final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } } @Override public boolean onOptionsItemSelected(MenuItem item) { final int id = item.getItemId(); if (id == android.R.id.home) { onBackPressed(); return true; } return super.onOptionsItemSelected(item); } @Override public boolean onIsMultiPane() { return isXLargeTablet(this); } @Override public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.pref_headers, target); } @Override protected boolean isValidFragment(String fragmentName) { return PreferenceFragment.class.getName().equals(fragmentName) || GeneralPreferenceFragment.class.getName().equals(fragmentName) || InformationPreferenceFragment.class.getName().equals(fragmentName); } public static class GeneralPreferenceFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_general); setHasOptionsMenu(true); } } public static class InformationPreferenceFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_information); findPreference("PLAY_STORE").setOnPreferenceClickListener(preference -> { final Context context = preference.getContext(); LaunchUtils.openUri(context, "market://details?id=" + context.getPackageName()); return true; }); findPreference("VERSION_NUMBER").setSummary(BuildConfig.VERSION_NAME); findPreference("LICENSE").setOnPreferenceClickListener(preference -> { final WebViewDialog dialog = WebViewDialog.newInstance(getString(R.string.pref_title_license), "file:///android_asset/license.html"); dialog.show(getFragmentManager(), ""); return true; }); } } }