add a Share button to the menu

This commit is contained in:
tibbi 2016-02-23 23:28:51 +01:00
parent be087a3f6a
commit 95ab204fc0
3 changed files with 38 additions and 2 deletions

View file

@ -27,7 +27,6 @@
<activity
android:name=".activities.ViewPagerActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
android:screenOrientation="portrait"/>
</application>
</manifest>

View file

@ -4,7 +4,10 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.io.File;
@ -20,6 +23,7 @@ import gallery.simplemobiletools.com.adapters.MyPagerAdapter;
public class ViewPagerActivity extends AppCompatActivity {
private int pos;
private boolean isFullScreen;
private ActionBar actionbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -27,6 +31,7 @@ public class ViewPagerActivity extends AppCompatActivity {
setContentView(R.layout.activity_photo);
pos = 0;
actionbar = getSupportActionBar();
isFullScreen = true;
hideSystemUI();
@ -46,6 +51,22 @@ public class ViewPagerActivity extends AppCompatActivity {
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_share:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private List<String> getPhotos() {
final List<String> photos = new ArrayList<>();
final String path = getIntent().getStringExtra(Constants.PHOTO);
@ -87,6 +108,9 @@ public class ViewPagerActivity extends AppCompatActivity {
}
private void hideSystemUI() {
if (actionbar != null)
actionbar.hide();
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
@ -96,6 +120,9 @@ public class ViewPagerActivity extends AppCompatActivity {
}
private void showSystemUI() {
if (actionbar != null)
actionbar.show();
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_share"
app:showAsAction="always"
android:icon="@android:drawable/ic_menu_share"
android:title="Share"/>
</menu>