mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-04 08:15:02 -05:00
Custom actionbar to indicate swipe down effect
This commit is contained in:
parent
df21b258ae
commit
c9fee47fb3
@ -36,6 +36,7 @@ import android.support.v4.content.Loader;
|
|||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v4.widget.CursorAdapter;
|
import android.support.v4.widget.CursorAdapter;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
@ -43,6 +44,7 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -94,6 +96,8 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
private Button mButtonEmptyCreate;
|
private Button mButtonEmptyCreate;
|
||||||
private Button mButtonEmptyImport;
|
private Button mButtonEmptyImport;
|
||||||
|
|
||||||
|
boolean hideMenu = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load custom layout with StickyListView from library
|
* Load custom layout with StickyListView from library
|
||||||
*/
|
*/
|
||||||
@ -134,10 +138,50 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
R.color.android_purple_dark,
|
R.color.android_purple_dark,
|
||||||
R.color.android_purple_light);
|
R.color.android_purple_light);
|
||||||
mSwipeRefreshLayout.setStickyListHeadersListView(mStickyList);
|
mSwipeRefreshLayout.setStickyListHeadersListView(mStickyList);
|
||||||
|
mSwipeRefreshLayout.setOnTouchListener(new View.OnTouchListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||||
|
updateActionbarForSwipe(true);
|
||||||
|
} else {
|
||||||
|
updateActionbarForSwipe(false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateActionbarForSwipe(boolean show) {
|
||||||
|
ActionBarActivity activity = (ActionBarActivity) getActivity();
|
||||||
|
ActionBar bar = activity.getSupportActionBar();
|
||||||
|
|
||||||
|
if (show) {
|
||||||
|
bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
bar.setDisplayUseLogoEnabled(false);
|
||||||
|
bar.setCustomView(R.layout.custom_actionbar);
|
||||||
|
TextView title = (TextView) getActivity().findViewById(R.id.custom_actionbar_text);
|
||||||
|
title.setText(R.string.swipe_to_update);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||||
|
hideMenu = true;
|
||||||
|
activity.invalidateOptionsMenu();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bar.setTitle(getActivity().getTitle());
|
||||||
|
bar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
bar.setDisplayShowTitleEnabled(true);
|
||||||
|
bar.setDisplayUseLogoEnabled(true);
|
||||||
|
bar.setDisplayShowHomeEnabled(true);
|
||||||
|
bar.setDisplayShowCustomEnabled(false);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||||
|
hideMenu = false;
|
||||||
|
activity.invalidateOptionsMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
String[] servers = Preferences.getPreferences(getActivity()).getKeyServers();
|
String[] servers = Preferences.getPreferences(getActivity()).getKeyServers();
|
||||||
@ -421,6 +465,12 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (hideMenu) {
|
||||||
|
for (int i = 0; i < menu.size(); i++) {
|
||||||
|
menu.getItem(i).setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,5 +773,6 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
updateHelper.updateAllKeys(getActivity(), finishedHandler);
|
updateHelper.updateAllKeys(getActivity(), finishedHandler);
|
||||||
|
updateActionbarForSwipe(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
OpenKeychain/src/main/res/layout/custom_actionbar.xml
Normal file
14
OpenKeychain/src/main/res/layout/custom_actionbar.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/custom_actionbar_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:text=""
|
||||||
|
android:textSize="18sp" />
|
||||||
|
</LinearLayout>
|
@ -834,6 +834,7 @@
|
|||||||
<string name="error_no_encrypt_subkey">"No encryption subkey available!"</string>
|
<string name="error_no_encrypt_subkey">"No encryption subkey available!"</string>
|
||||||
<string name="info_no_manual_account_creation">"Do not create OpenKeychain-Accounts manually.\nFor more information, see Help."</string>
|
<string name="info_no_manual_account_creation">"Do not create OpenKeychain-Accounts manually.\nFor more information, see Help."</string>
|
||||||
<string name="contact_show_key">"Show key (%s)"</string>
|
<string name="contact_show_key">"Show key (%s)"</string>
|
||||||
|
<string name="swipe_to_update">"Swipe down to update from keyserver"</string>
|
||||||
|
|
||||||
<!-- First Time -->
|
<!-- First Time -->
|
||||||
<string name="first_time_text1">"Take back your privacy with OpenKeychain!"</string>
|
<string name="first_time_text1">"Take back your privacy with OpenKeychain!"</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user