forked from mozilla-mobile/focus-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement overflow menu. (mozilla-mobile#52)
- Loading branch information
Showing
19 changed files
with
343 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.menu; | ||
|
||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.PopupWindow; | ||
|
||
import org.mozilla.focus.R; | ||
import org.mozilla.focus.fragment.BrowserFragment; | ||
|
||
public class BrowserMenu extends PopupWindow { | ||
public BrowserMenu(Context context, BrowserFragment fragment) { | ||
final View view = LayoutInflater.from(context).inflate(R.layout.menu, null); | ||
setContentView(view); | ||
|
||
RecyclerView menuList = (RecyclerView) view.findViewById(R.id.list); | ||
menuList.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); | ||
menuList.setAdapter(new BrowserMenuAdapter(this, fragment)); | ||
|
||
setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); | ||
|
||
setFocusable(true); | ||
|
||
setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | ||
setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); | ||
|
||
setElevation(context.getResources().getDimension(R.dimen.menu_elevation)); | ||
} | ||
|
||
public void show(View anchor) { | ||
super.showAsDropDown(anchor, 0, -(anchor.getHeight() + anchor.getPaddingBottom())); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
app/src/main/java/org/mozilla/focus/menu/BrowserMenuAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.menu; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.ViewGroup; | ||
|
||
import org.mozilla.focus.R; | ||
import org.mozilla.focus.fragment.BrowserFragment; | ||
|
||
public class BrowserMenuAdapter extends RecyclerView.Adapter<BrowserMenuViewHolder> { | ||
static class MenuItem { | ||
public final int id; | ||
public final int label; | ||
|
||
public MenuItem(int id, int label) { | ||
this.id = id; | ||
this.label = label; | ||
} | ||
} | ||
|
||
private static final MenuItem[] MENU_ITEMS = new MenuItem[] { | ||
new MenuItem(R.id.share, R.string.menu_share), | ||
new MenuItem(R.id.open, R.string.menu_open_with), | ||
new MenuItem(R.id.settings, R.string.menu_settings) | ||
}; | ||
|
||
private final BrowserMenu menu; | ||
private final BrowserFragment fragment; | ||
|
||
public BrowserMenuAdapter(BrowserMenu menu, BrowserFragment fragment) { | ||
this.menu = menu; | ||
this.fragment = fragment; | ||
} | ||
|
||
@Override | ||
public BrowserMenuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
final LayoutInflater inflater = LayoutInflater.from(parent.getContext()); | ||
|
||
if (viewType == NavigationItemViewHolder.LAYOUT_ID) { | ||
return new NavigationItemViewHolder(inflater.inflate(R.layout.menu_navigation, parent, false), fragment); | ||
} else if (viewType == MenuItemViewHolder.LAYOUT_ID) { | ||
return new MenuItemViewHolder(inflater.inflate(R.layout.menu_item, parent, false)); | ||
} | ||
|
||
throw new IllegalArgumentException("Unknown view type: " + viewType); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(BrowserMenuViewHolder holder, int position) { | ||
holder.setMenu(menu); | ||
holder.setOnClickListener(fragment); | ||
|
||
if (position > 0) { | ||
((MenuItemViewHolder) holder).bind(MENU_ITEMS[position - 1]); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemViewType(int position) { | ||
if (position == 0) { | ||
return NavigationItemViewHolder.LAYOUT_ID; | ||
} else { | ||
return MenuItemViewHolder.LAYOUT_ID; | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return 1 + MENU_ITEMS.length; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/org/mozilla/focus/menu/BrowserMenuViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.menu; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
|
||
public abstract class BrowserMenuViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
private BrowserMenu menu; | ||
private View.OnClickListener listener; | ||
|
||
public BrowserMenuViewHolder(View itemView) { | ||
super(itemView); | ||
} | ||
|
||
public void setMenu(BrowserMenu menu) { | ||
this.menu = menu; | ||
} | ||
|
||
public void setOnClickListener(View.OnClickListener listener) { | ||
this.listener = listener; | ||
} | ||
|
||
@Override | ||
public void onClick(View view) { | ||
if (menu != null) { | ||
menu.dismiss(); | ||
} | ||
|
||
if (listener != null) { | ||
listener.onClick(view); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/org/mozilla/focus/menu/MenuItemViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.menu; | ||
|
||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import org.mozilla.focus.R; | ||
import org.mozilla.focus.fragment.BrowserFragment; | ||
|
||
/* package-private */ class MenuItemViewHolder extends BrowserMenuViewHolder { | ||
/* package-private */ static final int LAYOUT_ID = R.layout.menu_item; | ||
|
||
private TextView menuItemView; | ||
|
||
/* package-private */ MenuItemViewHolder(View itemView) { | ||
super(itemView); | ||
|
||
menuItemView = (TextView) itemView; | ||
} | ||
|
||
/* package-private */ void bind(BrowserMenuAdapter.MenuItem menuItem) { | ||
menuItemView.setId(menuItem.id); | ||
menuItemView.setText(menuItem.label); | ||
menuItemView.setOnClickListener(this); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/org/mozilla/focus/menu/NavigationItemViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.focus.menu; | ||
|
||
import android.view.View; | ||
|
||
import org.mozilla.focus.R; | ||
import org.mozilla.focus.fragment.BrowserFragment; | ||
|
||
public class NavigationItemViewHolder extends BrowserMenuViewHolder { | ||
public static int LAYOUT_ID = R.layout.menu_navigation; | ||
|
||
public NavigationItemViewHolder(View itemView, BrowserFragment fragment) { | ||
super(itemView); | ||
|
||
itemView.findViewById(R.id.refresh).setOnClickListener(this); | ||
|
||
final View forwardView = itemView.findViewById(R.id.forward); | ||
if (!fragment.canGoForward()) { | ||
forwardView.setEnabled(false); | ||
forwardView.setAlpha(0.5f); | ||
} else { | ||
forwardView.setOnClickListener(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z" | ||
android:fillColor="#ffffff"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z" | ||
android:fillColor="#ffffff"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
<android.support.v7.widget.CardView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:cardCornerRadius="4dp" | ||
app:cardElevation="4dp"> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/list" | ||
android:layout_width="250dp" | ||
android:layout_height="wrap_content" /> | ||
|
||
</android.support.v7.widget.CardView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This Source Code Form is subject to the terms of the Mozilla Public | ||
- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> | ||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="48dp" | ||
android:paddingStart="16dp" | ||
android:paddingEnd="16dp" | ||
android:clickable="true" | ||
android:textSize="16sp" | ||
android:gravity="center_vertical" | ||
android:background="?android:attr/selectableItemBackground" | ||
style="@android:style/TextAppearance.Material.Menu"/> |
Oops, something went wrong.