Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Uplift of "What's new" feature. (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
pocmo committed Oct 10, 2017
1 parent 20bfa5f commit 68f8c3c
Show file tree
Hide file tree
Showing 27 changed files with 566 additions and 77 deletions.
19 changes: 19 additions & 0 deletions app/src/main/java/org/mozilla/focus/ext/Context.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* 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.ext

import android.content.Context

// Extension functions for the Context class

/**
* The (visible) version name of the application, as specified by the <manifest> tag's versionName
* attribute. E.g. "2.0".
*/
val Context.appVersionName: String?
get() {
val packageInfo = packageManager.getPackageInfo(packageName, 0)
return packageInfo.versionName
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import org.mozilla.focus.broadcastreceiver.DownloadBroadcastReceiver;
import org.mozilla.focus.customtabs.CustomTabConfig;
import org.mozilla.focus.locale.LocaleAwareAppCompatActivity;
import org.mozilla.focus.menu.BrowserMenu;
import org.mozilla.focus.menu.WebContextMenu;
import org.mozilla.focus.menu.browser.BrowserMenu;
import org.mozilla.focus.menu.context.WebContextMenu;
import org.mozilla.focus.open.OpenWithFragment;
import org.mozilla.focus.session.NullSession;
import org.mozilla.focus.session.Session;
Expand Down
67 changes: 27 additions & 40 deletions app/src/main/java/org/mozilla/focus/fragment/UrlInputFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.PopupMenu;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
Expand All @@ -32,21 +29,24 @@
import org.mozilla.focus.autocomplete.UrlAutoCompleteFilter;
import org.mozilla.focus.locale.LocaleAwareAppCompatActivity;
import org.mozilla.focus.locale.LocaleAwareFragment;
import org.mozilla.focus.menu.home.HomeMenu;
import org.mozilla.focus.session.Session;
import org.mozilla.focus.session.SessionManager;
import org.mozilla.focus.session.Source;
import org.mozilla.focus.telemetry.TelemetryWrapper;
import org.mozilla.focus.utils.Settings;
import org.mozilla.focus.utils.SupportUtils;
import org.mozilla.focus.utils.ThreadUtils;
import org.mozilla.focus.utils.UrlUtils;
import org.mozilla.focus.utils.ViewUtils;
import org.mozilla.focus.whatsnew.WhatsNew;
import org.mozilla.focus.widget.InlineAutocompleteEditText;
import org.mozilla.focus.widget.ResizableKeyboardLinearLayout;

/**
* Fragment for displaying he URL input controls.
*/
public class UrlInputFragment extends LocaleAwareFragment implements View.OnClickListener, InlineAutocompleteEditText.OnCommitListener, InlineAutocompleteEditText.OnFilterListener, PopupMenu.OnMenuItemClickListener {
public class UrlInputFragment extends LocaleAwareFragment implements View.OnClickListener, InlineAutocompleteEditText.OnCommitListener, InlineAutocompleteEditText.OnFilterListener {
public static final String FRAGMENT_TAG = "url_input";

private static final String ARGUMENT_ANIMATION = "animation";
Expand Down Expand Up @@ -115,7 +115,7 @@ public static UrlInputFragment createWithBackground() {
private View toolbarBackgroundView;
private View menuView;

private @Nullable PopupMenu displayedPopupMenu;
private @Nullable HomeMenu displayedPopupMenu;

private volatile boolean isAnimating;

Expand Down Expand Up @@ -267,12 +267,28 @@ public void onClick(View view) {
break;

case R.id.menu:
final PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
popupMenu.getMenuInflater().inflate(R.menu.menu_home, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(this);
popupMenu.setGravity(Gravity.TOP);
popupMenu.show();
displayedPopupMenu = popupMenu;
final HomeMenu menu = new HomeMenu(getContext(), this);
menu.show(view);

displayedPopupMenu = menu;
break;

case R.id.whats_new:
TelemetryWrapper.openWhatsNewEvent(WhatsNew.shouldHighlightWhatsNew(getContext()));

WhatsNew.userViewedWhatsNew(getContext());

SessionManager.getInstance()
.createSession(Source.MENU, SupportUtils.getWhatsNewUrl(getContext()));
break;

case R.id.settings:
((LocaleAwareAppCompatActivity) getActivity()).openPreferences();
break;

case R.id.help:
final Intent helpIntent = InfoActivity.getHelpIntent(getActivity());
startActivity(helpIntent);
break;

default:
Expand Down Expand Up @@ -571,33 +587,4 @@ public void onFilter(String searchText, InlineAutocompleteEditText view) {
searchViewContainer.setVisibility(View.VISIBLE);
}
}

@Override
public boolean onMenuItemClick(MenuItem item) {
final int id = item.getItemId();

switch (id) {
case R.id.settings:
((LocaleAwareAppCompatActivity) getActivity()).openPreferences();
return true;

case R.id.about:
Intent aboutIntent = InfoActivity.getAboutIntent(getActivity());
startActivity(aboutIntent);
return true;

case R.id.rights:
Intent rightsIntent = InfoActivity.getRightsIntent(getActivity());
startActivity(rightsIntent);
return true;

case R.id.help:
Intent helpIntent = InfoActivity.getHelpIntent(getActivity());
startActivity(helpIntent);
return true;

default:
throw new IllegalStateException("Unhandled view ID in onMenuItemClick()");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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;
package org.mozilla.focus.menu.browser;

import android.view.View;
import android.widget.CompoundButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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;
package org.mozilla.focus.menu.browser;

import android.annotation.SuppressLint;
import android.content.Context;
Expand All @@ -22,6 +22,9 @@
import org.mozilla.focus.fragment.BrowserFragment;
import org.mozilla.focus.utils.ViewUtils;

/**
* The overflow menu shown in the BrowserFragment containing page actions like "Refresh", "Share" etc.
*/
public class BrowserMenu extends PopupWindow {
private BrowserMenuAdapter adapter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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;
package org.mozilla.focus.menu.browser;

import android.app.PendingIntent;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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;
package org.mozilla.focus.menu.browser;

import android.support.v7.widget.RecyclerView;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mozilla.focus.menu;
package org.mozilla.focus.menu.browser;

import android.app.PendingIntent;
import android.content.Intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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;
package org.mozilla.focus.menu.browser;

import android.view.View;
import android.widget.TextView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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;
package org.mozilla.focus.menu.browser;

import android.view.View;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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;
package org.mozilla.focus.menu.context;

import android.app.Dialog;
import android.content.ClipData;
Expand All @@ -29,6 +29,9 @@
import org.mozilla.focus.web.Download;
import org.mozilla.focus.web.IWebView;

/**
* The context menu shown when long pressing a URL or an image inside the WebView.
*/
public class WebContextMenu {

private static View createTitleView(final @NonNull Context context, final @NonNull String title) {
Expand Down
55 changes: 55 additions & 0 deletions app/src/main/java/org/mozilla/focus/menu/home/HomeMenu.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* 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.home

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import kotlinx.android.synthetic.main.menu.view.*
import org.mozilla.focus.R
import org.mozilla.focus.utils.ViewUtils

/**
* The overflow menu shown on the start/home screen.
*/
class HomeMenu(
val context: Context,
val listener: View.OnClickListener
) : PopupWindow(), View.OnClickListener {
init {
contentView = LayoutInflater.from(context).inflate(R.layout.menu, null)

with(contentView.list) {
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
adapter = HomeMenuAdapter(context, this@HomeMenu)
}

setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

isFocusable = true

height = ViewGroup.LayoutParams.WRAP_CONTENT
width = ViewGroup.LayoutParams.WRAP_CONTENT

elevation = context.resources.getDimension(R.dimen.menu_elevation)
}

fun show(anchor: View) {
val xOffset = if (ViewUtils.isRTL(anchor)) -anchor.width else 0

super.showAsDropDown(anchor, xOffset, -(anchor.height + anchor.paddingBottom))
}

override fun onClick(view: View?) {
dismiss()

listener.onClick(view)
}
}
Loading

0 comments on commit 68f8c3c

Please sign in to comment.