Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating Context Menu to Upload Photo #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 15 additions & 111 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,129 +1,33 @@
*/target
target
tmp
*~
bin
*/test-output
temp-testng-customsuite.xml
**pom.xml.releaseBackup
release.properties
gen
*/seed.txt
notes
logs
gen-external-apklibs
.idea
*.iml
.DS_Store
*.swp
out
.gradle
/local.properties
/build

###OSX###

.DS_Store
.AppleDouble
.LSOverride

# Icon must ends with two \r.
Icon


# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes


###Linux###

*~

# KDE directory preferences
.directory


###Android###

# Built application files
#built application files
*.apk
*.ap_

# Files for ART and Dalvik VM
# files for the dex VM
*.dex

# Java class files
*.class

# Generated files
# generated files
bin/
gen/

# Gradle files
.gradle/
.gradletasknamecache
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Lint
lint-report.html
lint-report_files/
lint_result.txt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Windows thumbnail db
Thumbs.db

# OSX files
.DS_Store

###IntelliJ###
# Eclipse project files
.classpath
.project

# Android Studio
*.iml
*.ipr
*.iws
.idea/


###Eclipse###

*.pydevproject
.metadata
tmp/
*.tmp
*.bak
*.swp
*~.nib
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

# sbteclipse plugin
.target

# TeXlipse plugin
.texlipse
.idea
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
.gradle
build/
1 change: 1 addition & 0 deletions app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<supports-screens
android:largeScreens="true"
Expand Down
7 changes: 7 additions & 0 deletions app/res/menu/floating_context_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/id_upload_image"
android:title="@string/title_upload"
></item>
</menu>
3 changes: 3 additions & 0 deletions app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,7 @@
<string name="delete_successful">Repository is deleted</string>
<string name="login_or_email">Login or Email</string>

<!--Floating Context Menu for changing image icon -->
<string name="title_upload">Upload Photo</string>

</resources>
100 changes: 92 additions & 8 deletions app/src/main/java/com/github/mobile/ui/NavigationDrawerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.ContextMenu;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -24,6 +32,7 @@
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.github.mobile.R;
import com.github.mobile.util.AvatarLoader;
Expand All @@ -50,6 +59,9 @@ public class NavigationDrawerFragment extends Fragment implements AdapterView.On
private TextView userRealName;
private TextView userName;

private int PICK_IMAGE_REQUEST = 1;
private String mCurrentPhotoPath;

public NavigationDrawerFragment() {
}

Expand Down Expand Up @@ -87,6 +99,33 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
return inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
}

//created a floating menu
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater;
inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.floating_context_menu, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.id_upload_image:
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
return true;

default:
return super.onContextItemSelected(item);
}
}


@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Expand All @@ -99,7 +138,7 @@ public boolean isDrawerOpen() {
}

public void setUp(int fragmentId, DrawerLayout drawerLayout, NavigationDrawerAdapter adapter, AvatarLoader avatar,
User user) {
User user) {
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
//mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
Expand All @@ -109,7 +148,11 @@ public void setUp(int fragmentId, DrawerLayout drawerLayout, NavigationDrawerAda


View header = getActivity().getLayoutInflater().inflate(R.layout.drawer_header, mDrawerListView, false);
//adding a context menu on user image icon
userImage = (ImageView) header.findViewById(R.id.user_picture);
registerForContextMenu(userImage);


userRealName = (TextView) header.findViewById(R.id.user_real_name);
userName = (TextView) header.findViewById(R.id.user_name);

Expand All @@ -132,9 +175,9 @@ public void setUp(int fragmentId, DrawerLayout drawerLayout, NavigationDrawerAda
actionBar.setHomeButtonEnabled(true);

mDrawerToggle = new ActionBarDrawerToggle(
getActivity(), mDrawerLayout,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close) {
getActivity(), mDrawerLayout,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
Expand All @@ -145,6 +188,7 @@ public void onDrawerClosed(View drawerView) {
getActivity().supportInvalidateOptionsMenu();
}


@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
Expand All @@ -155,7 +199,7 @@ public void onDrawerOpened(View drawerView) {
if (!mUserLearnedDrawer) {
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(getActivity());
.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
}

Expand Down Expand Up @@ -207,6 +251,46 @@ public void onSaveInstanceState(Bundle outState) {
outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
}

//Result activity

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (requestCode == PICK_IMAGE_REQUEST && resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
setPic();
userImage.setImageBitmap(imageBitmap);

}gi

}
}

// Scale user Image Icon
public void setPic() {
// Get the dimensions of the View
int targetW = userImage.getWidth();
int targetH = userImage.getHeight();

// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;

// Determine how much to scale down the image
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);

// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;

Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
userImage.setImageBitmap(bitmap);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Expand All @@ -228,11 +312,11 @@ public static interface NavigationDrawerCallbacks {

public boolean checkTabletOrLandscape() {
boolean landscape = getActivity().getResources()
.getConfiguration()
.orientation == Configuration.ORIENTATION_LANDSCAPE;
.getConfiguration()
.orientation == Configuration.ORIENTATION_LANDSCAPE;
boolean tablet =
(getActivity().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
== Configuration.SCREENLAYOUT_SIZE_XLARGE;
== Configuration.SCREENLAYOUT_SIZE_XLARGE;

return landscape || tablet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;

import com.github.mobile.ui.NavigationDrawerFragment;
import com.google.inject.Key;

import java.util.HashMap;
Expand Down Expand Up @@ -126,9 +127,11 @@ public void onSupportContentChanged() {

@Override
protected void onActivityResult( int requestCode, int resultCode, Intent data ) {
if (requestCode == 2 & requestCode ==1) {
super.onActivityResult(requestCode, resultCode, data);

super.onActivityResult( requestCode, resultCode, data );
eventManager.fire( new OnActivityResultEvent( requestCode, resultCode, data ) );
eventManager.fire(new OnActivityResultEvent(requestCode, resultCode, data));
}
}

@Override
Expand Down
Loading