-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathBaseActivity.java
More file actions
109 lines (96 loc) · 3.79 KB
/
BaseActivity.java
File metadata and controls
109 lines (96 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus 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.
*
* ClockPlus 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 ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2;
import android.media.AudioManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.CallSuper;
import android.support.annotation.LayoutRes;
import android.support.annotation.MenuRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Created by Phillip Hsu on 5/31/2016.
*/
public abstract class BaseActivity extends AppCompatActivity {
@Nullable
@BindView(R.id.toolbar)
Toolbar mToolbar;
private Menu mMenu;
@LayoutRes protected abstract int layoutResId();
@MenuRes protected abstract int menuResId();
@CallSuper
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initialize the associated SharedPreferences file with default values
// for each preference when the user first opens your application.
// When false, the system sets the default values only if this method has
// never been called in the past (or the KEY_HAS_SET_DEFAULT_VALUES in the
// default value shared preferences file is false).
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
// ========================================================================================
// TOneverDO: Set theme after setContentView()
final String themeDark = getString(R.string.theme_dark);
final String themeBlack = getString(R.string.theme_black);
String theme = PreferenceManager.getDefaultSharedPreferences(this).getString(
getString(R.string.key_theme), null);
if (themeDark.equals(theme)) {
setTheme(R.style.AppTheme_Dark);
} else if (themeBlack.equals(theme)) {
setTheme(R.style.AppTheme_Black);
}
// ========================================================================================
setContentView(layoutResId());
// Direct volume changes to the alarm stream
setVolumeControlStream(AudioManager.STREAM_ALARM);
ButterKnife.bind(this);
if (mToolbar != null) {
setSupportActionBar(mToolbar);
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(isDisplayHomeUpEnabled());
ab.setDisplayShowTitleEnabled(isDisplayShowTitleEnabled());
}
}
}
@Override
public final boolean onCreateOptionsMenu(Menu menu) {
if (menuResId() != 0) {
getMenuInflater().inflate(menuResId(), menu);
mMenu = menu;
}
return super.onCreateOptionsMenu(menu);
}
@Nullable
public final Menu getMenu() {
return mMenu;
}
protected boolean isDisplayHomeUpEnabled() {
return true;
}
protected boolean isDisplayShowTitleEnabled() {
return false;
}
}