1
0
Fork 0
mirror of https://github.com/MatomoCamp/matomocamp-companion-android.git synced 2024-09-19 16:13:46 +02:00

Added Floating Action Button in dual-pane layout of TrackScheduleActivity

This commit is contained in:
Christophe Beyls 2015-01-19 00:20:24 +01:00
parent 3a66da1ce1
commit fbf3dfbb30
13 changed files with 198 additions and 41 deletions

View file

@ -10,6 +10,7 @@ import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.ImageView;
import be.digitalia.fosdem.R;
import be.digitalia.fosdem.fragments.EventDetailsFragment;
@ -26,7 +27,10 @@ import be.digitalia.fosdem.utils.NfcUtils.CreateNfcAppDataCallback;
*
* @author Christophe Beyls
*/
public class TrackScheduleActivity extends ActionBarActivity implements TrackScheduleListFragment.Callbacks, CreateNfcAppDataCallback {
public class TrackScheduleActivity extends ActionBarActivity
implements TrackScheduleListFragment.Callbacks,
EventDetailsFragment.FloatingActionButtonProvider,
CreateNfcAppDataCallback {
public static final String EXTRA_DAY = "day";
public static final String EXTRA_TRACK = "track";
@ -38,12 +42,16 @@ public class TrackScheduleActivity extends ActionBarActivity implements TrackSch
private boolean isTabletLandscape;
private Event lastSelectedEvent;
private ImageView floatingActionButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.track_schedule);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
floatingActionButton = (ImageView) findViewById(R.id.fab);
Bundle extras = getIntent().getExtras();
day = extras.getParcelable(EXTRA_DAY);
track = extras.getParcelable(EXTRA_TRACK);
@ -101,14 +109,6 @@ public class TrackScheduleActivity extends ActionBarActivity implements TrackSch
}
}
@Override
public byte[] createNfcAppData() {
if (lastSelectedEvent == null) {
return null;
}
return String.valueOf(lastSelectedEvent.getId()).getBytes();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -119,6 +119,8 @@ public class TrackScheduleActivity extends ActionBarActivity implements TrackSch
return false;
}
// TrackScheduleListFragment.Callbacks
@Override
public void onEventSelected(int position, Event event) {
if (isTabletLandscape) {
@ -149,4 +151,21 @@ public class TrackScheduleActivity extends ActionBarActivity implements TrackSch
startActivity(intent);
}
}
// EventDetailsFragment.FloatingActionButtonProvider
@Override
public ImageView getActionButton() {
return floatingActionButton;
}
// CreateNfcAppDataCallback
@Override
public byte[] createNfcAppData() {
if (lastSelectedEvent == null) {
return null;
}
return String.valueOf(lastSelectedEvent.getId()).getBytes();
}
}

View file

@ -1,6 +1,7 @@
package be.digitalia.fosdem.fragments;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
@ -27,6 +28,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.text.DateFormat;
@ -47,6 +49,14 @@ import be.digitalia.fosdem.utils.StringUtils;
public class EventDetailsFragment extends Fragment {
/**
* Interface implemented by container activities
*/
public interface FloatingActionButtonProvider {
// May return null
ImageView getActionButton();
}
private static class EventDetails {
List<Person> persons;
List<Link> links;
@ -71,6 +81,7 @@ public class EventDetailsFragment extends Fragment {
private ViewHolder holder;
private MenuItem bookmarkMenuItem;
private ImageView actionButton;
public static EventDetailsFragment newInstance(Event event) {
EventDetailsFragment f = new EventDetailsFragment();
@ -84,7 +95,6 @@ public class EventDetailsFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
event = getArguments().getParcelable(ARG_EVENT);
setHasOptionsMenu(true);
}
public Event getEvent() {
@ -165,47 +175,100 @@ public class EventDetailsFragment extends Fragment {
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
holder = null;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Activity activity = getActivity();
if (activity instanceof FloatingActionButtonProvider) {
actionButton = ((FloatingActionButtonProvider) activity).getActionButton();
if (actionButton != null) {
actionButton.setOnClickListener(actionButtonClickListener);
}
}
// Ensure the actionButton is initialized before creating the options menu
setHasOptionsMenu(true);
LoaderManager loaderManager = getLoaderManager();
loaderManager.initLoader(BOOKMARK_STATUS_LOADER_ID, null, bookmarkStatusLoaderCallbacks);
loaderManager.initLoader(EVENT_DETAILS_LOADER_ID, null, eventDetailsLoaderCallbacks);
}
private final View.OnClickListener actionButtonClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isBookmarked != null) {
new UpdateBookmarkAsyncTask(event).execute(isBookmarked);
}
}
};
@Override
public void onDestroyView() {
super.onDestroyView();
holder = null;
if (actionButton != null) {
// Clear the reference to this fragment
actionButton.setOnClickListener(null);
actionButton = null;
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.event, menu);
menu.findItem(R.id.share).setIntent(getShareChooserIntent());
bookmarkMenuItem = menu.findItem(R.id.bookmark);
if (actionButton != null) {
bookmarkMenuItem.setEnabled(false).setVisible(false);
}
updateOptionsMenu();
}
private Intent getShareChooserIntent() {
return ShareCompat.IntentBuilder.from(getActivity()).setSubject(String.format("%1$s (FOSDEM)", event.getTitle())).setType("text/plain")
.setText(String.format("%1$s %2$s #FOSDEM", event.getTitle(), event.getUrl())).setChooserTitle(R.string.share).createChooserIntent();
return ShareCompat.IntentBuilder.from(getActivity())
.setSubject(String.format("%1$s (FOSDEM)", event.getTitle()))
.setType("text/plain")
.setText(String.format("%1$s %2$s #FOSDEM", event.getTitle(), event.getUrl()))
.setChooserTitle(R.string.share)
.createChooserIntent();
}
private void updateOptionsMenu() {
if (bookmarkMenuItem != null) {
if (actionButton != null) {
// Action Button is used as bookmark button
if (isBookmarked == null) {
bookmarkMenuItem.setEnabled(false);
actionButton.setEnabled(false);
} else {
bookmarkMenuItem.setEnabled(true);
actionButton.setEnabled(true);
if (isBookmarked) {
bookmarkMenuItem.setTitle(R.string.remove_bookmark);
bookmarkMenuItem.setIcon(R.drawable.ic_bookmark_white_24dp);
actionButton.setContentDescription(getString(R.string.remove_bookmark));
actionButton.setImageResource(R.drawable.ic_bookmark_white_24dp);
} else {
bookmarkMenuItem.setTitle(R.string.add_bookmark);
bookmarkMenuItem.setIcon(R.drawable.ic_bookmark_outline_white_24dp);
actionButton.setContentDescription(getString(R.string.add_bookmark));
actionButton.setImageResource(R.drawable.ic_bookmark_outline_white_24dp);
}
}
} else {
// Standard menu item is used as bookmark button
if (bookmarkMenuItem != null) {
if (isBookmarked == null) {
bookmarkMenuItem.setEnabled(false);
} else {
bookmarkMenuItem.setEnabled(true);
if (isBookmarked) {
bookmarkMenuItem.setTitle(R.string.remove_bookmark);
bookmarkMenuItem.setIcon(R.drawable.ic_bookmark_white_24dp);
} else {
bookmarkMenuItem.setTitle(R.string.add_bookmark);
bookmarkMenuItem.setIcon(R.drawable.ic_bookmark_outline_white_24dp);
}
}
}
}

View file

@ -174,7 +174,7 @@ public class AlarmIntentService extends IntentService {
bigText = spannableBigText;
}
int notificationColor = getResources().getColor(R.color.fosdem_purple);
int notificationColor = getResources().getColor(R.color.color_primary);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_fosdem)

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueFrom="@dimen/fab_elevation_low"
android:valueTo="@dimen/fab_elevation_high"
android:valueType="floatType"/>
</item>
<item>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueFrom="@dimen/fab_elevation_high"
android:valueTo="@dimen/fab_elevation_low"
android:valueType="floatType"/>
</item>
</selector>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?colorControlHighlight">
<item>
<shape android:shape="oval">
<solid android:color="?colorAccent"/>
</shape>
</item>
</ripple>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:enterFadeDuration="@android:integer/config_mediumAnimTime"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:drawable="@drawable/fab_background_highlighted" android:state_pressed="true"/>
<item android:drawable="@drawable/fab_background_highlighted" android:state_focused="true"/>
<item>
<shape android:shape="oval">
<solid android:color="@color/color_accent"/>
</shape>
</item>
</selector>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/color_accent"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="@color/ripple_material_light"/>
</shape>
</item>
</layer-list>

View file

@ -29,6 +29,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/schedule_column_width"
android:layout_marginRight="48dp"
android:layout_marginRight="120dp"
android:layout_marginTop="64dp"/>
<ImageView
android:id="@+id/fab"
style="@style/FloatingActionButton"
android:layout_gravity="top|right"
android:layout_marginRight="32dp"
android:layout_marginTop="100dp"
android:src="@drawable/ic_bookmark_outline_white_24dp"/>
</FrameLayout>

View file

@ -8,9 +8,9 @@
</style>
<style name="AlertDialogTheme" parent="android:Theme.Material.Light.Dialog.Alert">
<item name="android:colorPrimary">@color/fosdem_purple</item>
<item name="android:colorPrimaryDark">@color/fosdem_purple_dark</item>
<item name="android:colorAccent">@color/fosdem_blue</item>
<item name="android:colorPrimary">@color/color_primary</item>
<item name="android:colorPrimaryDark">@color/color_primary_dark</item>
<item name="android:colorAccent">@color/color_accent</item>
<item name="android:textColorLink">?android:attr/colorAccent</item>
</style>

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="fosdem_purple">#a91991</color>
<color name="fosdem_purple_dark">#76005e</color>
<color name="fosdem_blue">#3479c4</color>
<color name="color_primary">#a91991</color>
<color name="color_primary_dark">#76005e</color>
<color name="color_accent">#3479c4</color>
<color name="fosdem_blue_translucent">#663479c4</color>
<color name="secondary_text">#323232</color>
<color name="main_menu_background">#fffafafa</color>

View file

@ -11,5 +11,8 @@
<dimen name="content_margin">16dp</dimen>
<dimen name="toolbar_elevation">8dp</dimen>
<dimen name="schedule_column_width">360dp</dimen>
<dimen name="fab_diameter">56dp</dimen>
<dimen name="fab_elevation_low">2dp</dimen>
<dimen name="fab_elevation_high">4dp</dimen>
</resources>

View file

@ -4,9 +4,9 @@
<!-- Main theme -->
<style name="Base.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/fosdem_purple</item>
<item name="colorPrimaryDark">@color/fosdem_purple_dark</item>
<item name="colorAccent">@color/fosdem_blue</item>
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryDark">@color/color_primary_dark</item>
<item name="colorAccent">@color/color_accent</item>
<item name="android:textColorLink">?attr/colorAccent</item>
<item name="activatedBackgroundIndicator">@drawable/activated_background</item>
@ -28,9 +28,9 @@
</style>
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/fosdem_purple</item>
<item name="colorPrimaryDark">@color/fosdem_purple_dark</item>
<item name="colorAccent">@color/fosdem_blue</item>
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryDark">@color/color_primary_dark</item>
<item name="colorAccent">@color/color_accent</item>
</style>
<style name="Toolbar.Fosdem" parent="Widget.AppCompat.Toolbar">
@ -67,6 +67,17 @@
<item name="textColor">@color/tab_text</item>
</style>
<style name="FloatingActionButton" tools:ignore="newApi">
<item name="android:layout_width">@dimen/fab_diameter</item>
<item name="android:layout_height">@dimen/fab_diameter</item>
<item name="android:background">@drawable/fab_background</item>
<item name="android:elevation">@dimen/fab_elevation_low</item>
<item name="android:stateListAnimator">@anim/fab_elevation</item>
<item name="android:scaleType">center</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
</style>
<style name="SeparatorLine">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
@ -88,7 +99,7 @@
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:textSize">20sp</item>
<item name="android:textColor">@color/fosdem_purple</item>
<item name="android:textColor">@color/color_primary</item>
</style>
<style name="RoomImageDialogAnimations">

View file

@ -20,6 +20,6 @@
<bool name="default_underline_indicator_fades">true</bool>
<integer name="default_underline_indicator_fade_delay">300</integer>
<integer name="default_underline_indicator_fade_length">400</integer>
<color name="default_underline_indicator_selected_color">@color/fosdem_purple</color>
<color name="default_underline_indicator_selected_color">@color/color_primary</color>
</resources>