use of android.support.v7.app.ActionBar in project WordPress-Android by wordpress-mobile.
the class SelectCategoriesActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((WordPress) getApplication()).component().inject(this);
mDispatcher.register(this);
if (savedInstanceState == null) {
mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE);
} else {
mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
}
if (mSite == null) {
ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT);
finish();
return;
}
setContentView(R.layout.select_categories);
setTitle(getResources().getString(R.string.select_categories));
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
mListView = (ListView) findViewById(android.R.id.list);
mListScrollPositionManager = new ListScrollPositionManager(mListView, false);
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
mListView.setItemsCanFocus(false);
mEmptyView = (TextView) findViewById(R.id.empty_view);
mListView.setEmptyView(mEmptyView);
mSelectedCategories = new HashSet<>();
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey(KEY_POST)) {
PostModel post = (PostModel) extras.getSerializable(KEY_POST);
if (post != null) {
for (Long categoryId : post.getCategoryIdList()) {
mSelectedCategories.add(categoryId);
}
}
}
}
// swipe to refresh setup
mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new RefreshListener() {
@Override
public void onRefreshStarted() {
if (!NetworkUtils.checkConnection(getBaseContext())) {
mSwipeToRefreshHelper.setRefreshing(false);
return;
}
refreshCategories();
}
});
populateCategoryList();
if (NetworkUtils.isNetworkAvailable(this)) {
mEmptyView.setText(R.string.empty_list_default);
if (isCategoryListEmpty()) {
refreshCategories();
}
} else {
mEmptyView.setText(R.string.no_network_title);
}
}
use of android.support.v7.app.ActionBar in project StylishMusicPlayer by ryanhoo.
the class BaseActivity method supportActionBar.
/**
* An easy way to set up non-home(no back button on the toolbar) activity to enable
* go back action.
*
* @param toolbar The toolbar with go back button
* @return ActionBar
*/
protected ActionBar supportActionBar(Toolbar toolbar) {
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
return actionBar;
}
use of android.support.v7.app.ActionBar in project Shuttle by timusus.
the class NavigationDrawerFragment method setup.
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
* @param drawerLayout The DrawerLayout containing this fragment's UI.
*/
public void setup(DrawerLayout drawerLayout) {
mDrawerLayout = drawerLayout;
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
// ActionBarDrawerToggle ties together the the proper interactions
// between the navigation drawer and the action bar app icon.
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close) {
/* "close drawer" description for accessibility */
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) {
return;
}
// calls onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) {
return;
}
if (!mUserLearnedDrawer) {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
}
// calls onPrepareOptionsMenu()
getActivity().supportInvalidateOptionsMenu();
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// which is the only view which should cause animation)
if (drawerView != null) {
slideOffset = 0;
}
// this disables the animation
super.onDrawerSlide(drawerView, slideOffset);
}
};
// per the navigation drawer design guidelines.
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(GravityCompat.START);
}
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(() -> mDrawerToggle.syncState());
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
use of android.support.v7.app.ActionBar in project Shuttle by timusus.
the class NavigationDrawerFragment method showGlobalContextActionBar.
/**
* Per the navigation drawer design guidelines, updates the action bar to show the global app
* 'context', rather than just what's in the current screen.
*/
private void showGlobalContextActionBar() {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
}
use of android.support.v7.app.ActionBar in project Shuttle by timusus.
the class EqualizerActivity method onCreate.
@SuppressLint("InlinedApi")
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onCreate(Bundle savedInstanceState) {
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
ThemeUtils.setTheme(this);
if (!ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
mTintManager = new SystemBarTintManager(this);
}
if (!ShuttleUtils.hasKitKat()) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
if (SettingsManager.getInstance().canTintNavBar()) {
getWindow().setNavigationBarColor(ColorUtils.getPrimaryColorDark(this));
}
super.onCreate(savedInstanceState);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
setContentView(R.layout.activity_equalizer);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ThemeUtils.themeActionBar(this);
ThemeUtils.themeStatusBar(this, mTintManager);
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(getResources().getString(R.string.equalizer));
try {
//Query available effects
final AudioEffect.Descriptor[] effects = AudioEffect.queryEffects();
//Determine available/supported effects
if (effects != null && effects.length != 0) {
for (final AudioEffect.Descriptor effect : effects) {
//Equalizer
if (effect.type.equals(UUID.fromString(EFFECT_TYPE_EQUALIZER))) {
mEqualizerSupported = true;
} else if (effect.type.equals(UUID.fromString(EFFECT_TYPE_BASS_BOOST))) {
mBassBoostSupported = true;
} else if (effect.type.equals(UUID.fromString(EFFECT_TYPE_VIRTUALIZER))) {
mVirtualizerSupported = true;
}
}
}
} catch (NoClassDefFoundError ignored) {
//The user doesn't have the AudioEffect/AudioEffect.Descriptor class. How sad.
}
mSpinner = (Spinner) findViewById(R.id.eqSpinner);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mEqPreset = position;
equalizerSetPreset(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
setupPresets();
if (mSpinnerAdapter != null && mSpinnerAdapter.getCount() > mEqPreset) {
mSpinner.setSelection(mEqPreset);
}
//Initialize the equalizer elements
View eqContainer = findViewById(R.id.eqContainer);
mNumberEqualizerBands = Integer.parseInt(mPrefs.getString("equalizer.number_of_bands", "5"));
final int[] centerFreqs = getCenterFreqs();
final int[] bandLevelRange = getBandLevelRange();
for (int band = 0; band < mNumberEqualizerBands; band++) {
//Unit conversion from mHz to Hz and use k prefix if necessary to display
float centerFreqHz = centerFreqs[band] / 1000;
String unitPrefix = "";
if (centerFreqHz >= 1000) {
centerFreqHz = centerFreqHz / 1000;
unitPrefix = "k";
}
(eqContainer.findViewById(eqViewElementIds[band][0])).setVisibility(View.VISIBLE);
(eqContainer.findViewById(eqViewTextElementIds[band][0])).setVisibility(View.VISIBLE);
(eqContainer.findViewById(eqViewElementIds[band][1])).setVisibility(View.VISIBLE);
(eqContainer.findViewById(eqViewTextElementIds[band][1])).setVisibility(View.VISIBLE);
((TextView) eqContainer.findViewById(eqViewElementIds[band][0])).setText(format("%.0f ", centerFreqHz) + unitPrefix + "Hz");
mEqualizerSeekBar[band] = (SizableSeekBar) eqContainer.findViewById(eqViewElementIds[band][1]);
ThemeUtils.themeSeekBar(this, mEqualizerSeekBar[band]);
mEqualizerSeekBar[band].setMax((bandLevelRange[1] / 100) - (bandLevelRange[0] / 100));
mEqualizerSeekBar[band].setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
if (fromUser) {
//Determine which band changed
int seekbarId = seekBar.getId();
int band = 0;
for (int i = 0; i < eqViewElementIds.length; i++) {
if (eqViewElementIds[i][1] == seekbarId) {
band = i;
}
}
if (mEqPreset != mEqCustomPresetPosition) {
equalizerCopyToCustom();
if (mSpinnerAdapter != null && mSpinnerAdapter.getCount() > mEqCustomPresetPosition) {
mSpinner.setSelection(mEqCustomPresetPosition);
}
} else {
int level = getBandLevelRange()[0] + (progress * 100);
equalizerBandUpdate(band, level);
}
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
});
}
// Set the SeekBar listener.
if (mBassBoostSupported) {
final SizableSeekBar seekbar = (SizableSeekBar) findViewById(R.id.bb_strength);
ThemeUtils.themeSeekBar(this, seekbar);
seekbar.setMax(OpenSLESConstants.BASSBOOST_MAX_STRENGTH - OpenSLESConstants.BASSBOOST_MIN_STRENGTH);
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
// set parameter and state
if (fromUser) {
mPrefs.edit().putBoolean("audiofx.bass.enable", true).apply();
mPrefs.edit().putString("audiofx.bass.strength", String.valueOf(progress)).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
// If slider pos was 0 when starting re-enable effect
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
if (seekBar.getProgress() == 0) {
mPrefs.edit().putBoolean("audiofx.bass.enable", true).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
// If slider pos = 0 when stopping disable effect
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
if (seekBar.getProgress() == 0) {
// disable
mPrefs.edit().putBoolean("audiofx.bass.enable", false).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
});
}
// Set the SeekBar listener.
if (mVirtualizerSupported) {
final SizableSeekBar seekbar = (SizableSeekBar) findViewById(R.id.virtualizer_strength);
ThemeUtils.themeSeekBar(this, seekbar);
seekbar.setMax(OpenSLESConstants.VIRTUALIZER_MAX_STRENGTH - OpenSLESConstants.VIRTUALIZER_MIN_STRENGTH);
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
// set parameter and state
if (fromUser) {
mPrefs.edit().putBoolean("audiofx.virtualizer.enable", true).apply();
mPrefs.edit().putString("audiofx.virtualizer.strength", String.valueOf(progress)).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
// If slider pos was 0 when starting re-enable effect
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
if (seekBar.getProgress() == 0) {
mPrefs.edit().putBoolean("audiofx.virtualizer.enable", true).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
// If slider pos = 0 when stopping disable effect
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
if (seekBar.getProgress() == 0) {
// disable
mPrefs.edit().putBoolean("audiofx.virtualizer.enable", false).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
});
}
}
Aggregations