Commit e4961ec5 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Merge branch '130-blisslauncher_android_weather_widget' into 'master'

Expose the weather widget as a normal widget

Closes backlog#130

See merge request !69
parents 7b6cf9b0 35873f48
Pipeline #177974 passed with stage
in 2 minutes and 41 seconds
......@@ -52,6 +52,7 @@ public class Preferences {
private static final String CURRENT_MIGRATION_VERSION = "current_migration_version";
private static final String ADDED_WEATHER_WIDGET = "added_weather_widget";
private static final String ADDED_ECLOUD_WIDGET = "added_ecloud_widget";
private static final String ADDED_PRIVACY_WIDGET = "added_privacy_widget";
......@@ -364,6 +365,14 @@ public class Preferences {
return getPrefs(context).getBoolean(ENABLE_LOCATION, false);
}
public static void setAddedWeatherWidget(Context context) {
getPrefs(context).edit().putBoolean(ADDED_WEATHER_WIDGET, true).apply();
}
public static boolean getAddedWeatherWidget(Context context) {
return getPrefs(context).getBoolean(ADDED_WEATHER_WIDGET, false);
}
public static void setAddedEcloudWidget(Context context) {
getPrefs(context).edit().putBoolean(ADDED_ECLOUD_WIDGET, true).apply();
}
......
......@@ -52,6 +52,7 @@ public class Preferences {
private static final String CURRENT_MIGRATION_VERSION = "current_migration_version";
private static final String ADDED_WEATHER_WIDGET = "added_weather_widget";
private static final String ADDED_ECLOUD_WIDGET = "added_ecloud_widget";
private static final String ADDED_PRIVACY_WIDGET = "added_privacy_widget";
......@@ -364,6 +365,14 @@ public class Preferences {
return getPrefs(context).getBoolean(ENABLE_LOCATION, false);
}
public static void setAddedWeatherWidget(Context context) {
getPrefs(context).edit().putBoolean(ADDED_WEATHER_WIDGET, true).apply();
}
public static boolean getAddedWeatherWidget(Context context) {
return getPrefs(context).getBoolean(ADDED_WEATHER_WIDGET, false);
}
public static void setAddedEcloudWidget(Context context) {
getPrefs(context).edit().putBoolean(ADDED_ECLOUD_WIDGET, true).apply();
}
......
......@@ -169,5 +169,15 @@
<meta-data
android:name="android.nfc.disable_beam_default"
android:value="true" />
<receiver android:name="foundation.e.blisslauncher.features.weather.WeatherAppWidgetProvider"
android:exported="false"
android:label="@string/weather">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/weather_appwidget_info" />
</receiver>
</application>
</manifest>
......@@ -5,6 +5,9 @@ import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import foundation.e.blisslauncher.features.weather.WeatherAppWidgetProvider;
import foundation.e.blisslauncher.features.weather.WeatherWidgetHostView;
public class WidgetHost extends AppWidgetHost {
public WidgetHost(Context context, int hostId) {
......@@ -13,6 +16,9 @@ public class WidgetHost extends AppWidgetHost {
@Override
protected AppWidgetHostView onCreateView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
if (appWidget.provider.equals(WeatherAppWidgetProvider.COMPONENT_NAME)) {
return new WeatherWidgetHostView(context);
}
return new RoundedWidgetView(context);
}
......
......@@ -13,13 +13,11 @@ import android.app.WallpaperManager;
import android.app.usage.UsageStats;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
......@@ -136,7 +134,7 @@ import foundation.e.blisslauncher.features.suggestions.SuggestionProvider;
import foundation.e.blisslauncher.features.suggestions.SuggestionsResult;
import foundation.e.blisslauncher.features.usagestats.AppUsageStats;
import foundation.e.blisslauncher.features.weather.DeviceStatusService;
import foundation.e.blisslauncher.features.weather.ForecastBuilder;
import foundation.e.blisslauncher.features.weather.WeatherAppWidgetProvider;
import foundation.e.blisslauncher.features.weather.WeatherPreferences;
import foundation.e.blisslauncher.features.weather.WeatherSourceListenerService;
import foundation.e.blisslauncher.features.weather.WeatherUpdateService;
......@@ -166,6 +164,8 @@ public class LauncherActivity extends AppCompatActivity implements
private static final int REQUEST_PERMISSION_CALL_PHONE = 14;
private static final int REQUEST_LOCATION_SOURCE_SETTING = 267;
private static final int STORAGE_PERMISSION_REQUEST_CODE = 586;
public static final String ACTION_LAUNCHER_RESUME = "foundation.e.blisslauncher.LauncherActivity.LAUNCHER_RESUME";
public static boolean longPressed;
private final Alarm mReorderAlarm = new Alarm();
private final Alarm mDockReorderAlarm = new Alarm();
......@@ -202,8 +202,6 @@ public class LauncherActivity extends AppCompatActivity implements
private boolean mLongClickStartsDrag = true;
private boolean isDragging;
private BlissDragShadowBuilder dragShadowBuilder;
private View mWeatherPanel;
private View mWeatherSetupTextView;
private boolean allAppsDisplayed;
private boolean forceRefreshSuggestedApps = false;
......@@ -213,14 +211,6 @@ public class LauncherActivity extends AppCompatActivity implements
private InsettableRelativeLayout workspace;
private View blurLayer; // Blur layer for folders and search container.
private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!intent.getBooleanExtra(WeatherUpdateService.EXTRA_UPDATE_CANCELLED, false)) {
updateWeatherPanel();
}
}
};
private FolderItem activeFolder;
private BlissFrameLayout activeFolderView;
private int activeDot;
......@@ -405,6 +395,12 @@ public class LauncherActivity extends AppCompatActivity implements
Preferences.setAddedPrivacyWidget(this);
}
}
if (!Preferences.getAddedWeatherWidget(this)) {
if (allocateAndBindWidget(WeatherAppWidgetProvider.COMPONENT_NAME)) {
Preferences.setAddedWeatherWidget(this);
}
}
}
private boolean allocateAndBindWidget(ComponentName provider) {
......@@ -455,14 +451,14 @@ public class LauncherActivity extends AppCompatActivity implements
@Override
protected void onResume() {
super.onResume();
if (mWeatherPanel != null) {
updateWeatherPanel();
}
if (widgetsPage != null) {
refreshSuggestedApps(widgetsPage, forceRefreshSuggestedApps);
}
final Intent resumeIntent = new Intent(ACTION_LAUNCHER_RESUME);
LocalBroadcastManager.getInstance(this).sendBroadcast(resumeIntent);
if (widgetContainer != null) {
WidgetManager widgetManager = WidgetManager.getInstance();
Integer id = widgetManager.dequeRemoveId();
......@@ -515,7 +511,6 @@ public class LauncherActivity extends AppCompatActivity implements
// Unregister active receivers
TimeChangeBroadcastReceiver.unregister(this, timeChangedReceiver);
ManagedProfileBroadcastReceiver.unregister(this, managedProfileReceiver);
LocalBroadcastManager.getInstance(this).unregisterReceiver(mWeatherReceiver);
// Dispose CompositeDisposable
getCompositeDisposable().dispose();
......@@ -1426,31 +1421,12 @@ public class LauncherActivity extends AppCompatActivity implements
findViewById(R.id.edit_widgets_button).setOnClickListener(
view -> startActivity(new Intent(this, WidgetsActivity.class)));
// Prepare weather widget view
// [[BEGIN]]
findViewById(R.id.weather_setting_imageview).setOnClickListener(
v -> startActivity(new Intent(this, WeatherPreferences.class)));
mWeatherSetupTextView = findViewById(R.id.weather_setup_textview);
mWeatherPanel = findViewById(R.id.weather_panel);
mWeatherPanel.setOnClickListener(v -> {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(
"foundation.e.weather");
if (launchIntent != null) {
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(launchIntent);
}
});
updateWeatherPanel();
if (WeatherUtils.isWeatherServiceAvailable(
this)) {
startService(new Intent(this, WeatherSourceListenerService.class));
startService(new Intent(this, DeviceStatusService.class));
}
LocalBroadcastManager.getInstance(this).registerReceiver(mWeatherReceiver, new IntentFilter(
WeatherUpdateService.ACTION_UPDATE_FINISHED));
if (!Preferences.useCustomWeatherLocation(this)) {
if (!WeatherPreferences.hasLocationPermission(this)) {
......@@ -1528,21 +1504,6 @@ public class LauncherActivity extends AppCompatActivity implements
}
}
private void updateWeatherPanel() {
if (Preferences.getCachedWeatherInfo(this) == null) {
mWeatherSetupTextView.setVisibility(VISIBLE);
mWeatherPanel.setVisibility(GONE);
mWeatherSetupTextView.setOnClickListener(
v -> startActivity(
new Intent(LauncherActivity.this, WeatherPreferences.class)));
return;
}
mWeatherSetupTextView.setVisibility(GONE);
mWeatherPanel.setVisibility(VISIBLE);
ForecastBuilder.buildLargePanel(this, mWeatherPanel,
Preferences.getCachedWeatherInfo(this));
}
private void showLocationEnableDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// Build and show the dialog
......
package foundation.e.blisslauncher.features.weather;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import foundation.e.blisslauncher.BuildConfig;
public class WeatherAppWidgetProvider extends AppWidgetProvider {
public static final ComponentName COMPONENT_NAME = new ComponentName(
BuildConfig.APPLICATION_ID, WeatherAppWidgetProvider.class.getName());
}
package foundation.e.blisslauncher.features.weather;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.Preferences;
import foundation.e.blisslauncher.features.launcher.LauncherActivity;
public class WeatherInfoView extends LinearLayout {
private View mWeatherPanel;
private View mWeatherSetupTextView;
private final BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!intent.getBooleanExtra(WeatherUpdateService.EXTRA_UPDATE_CANCELLED, false)) {
updateWeatherPanel();
}
}
};
private final BroadcastReceiver mResumeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateWeatherPanel();
}
};
public WeatherInfoView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mWeatherSetupTextView = findViewById(R.id.weather_setup_textview);
mWeatherPanel = findViewById(R.id.weather_panel);
mWeatherPanel.setOnClickListener(v -> {
Intent launchIntent = getContext().getPackageManager().getLaunchIntentForPackage(
"foundation.e.weather");
if (launchIntent != null) {
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(launchIntent);
}
});
findViewById(R.id.weather_setting_imageview).setOnClickListener(v -> startWeatherPreferences());
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getContext());
broadcastManager.registerReceiver(mWeatherReceiver, new IntentFilter(
WeatherUpdateService.ACTION_UPDATE_FINISHED));
broadcastManager.registerReceiver(mResumeReceiver, new IntentFilter(
LauncherActivity.ACTION_LAUNCHER_RESUME));
updateWeatherPanel();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getContext());
broadcastManager.unregisterReceiver(mWeatherReceiver);
broadcastManager.unregisterReceiver(mResumeReceiver);
}
private void updateWeatherPanel() {
if (Preferences.getCachedWeatherInfo(getContext()) == null) {
mWeatherSetupTextView.setVisibility(VISIBLE);
mWeatherPanel.setVisibility(GONE);
mWeatherSetupTextView.setOnClickListener(v -> startWeatherPreferences());
return;
}
mWeatherSetupTextView.setVisibility(GONE);
mWeatherPanel.setVisibility(VISIBLE);
ForecastBuilder.buildLargePanel(getContext(), mWeatherPanel,
Preferences.getCachedWeatherInfo(getContext()));
}
private void startWeatherPreferences() {
final Intent intent = new Intent(getContext(), WeatherPreferences.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(intent);
}
}
package foundation.e.blisslauncher.features.weather;
import android.content.Context;
import android.view.LayoutInflater;
import android.widget.RemoteViews;
import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.customviews.RoundedWidgetView;
public class WeatherWidgetHostView extends RoundedWidgetView {
public WeatherWidgetHostView(Context context) {
super(context);
LayoutInflater.from(context).inflate(R.layout.layout_weather_info, this);
}
@Override
public void updateAppWidget(RemoteViews remoteViews) {
// do nothing
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<foundation.e.blisslauncher.features.weather.WeatherInfoView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:clipChildren="true"
android:clipToPadding="true"
android:orientation="vertical"
......@@ -160,4 +158,4 @@
</LinearLayout>
</FrameLayout>
</LinearLayout>
\ No newline at end of file
</foundation.e.blisslauncher.features.weather.WeatherInfoView>
......@@ -23,10 +23,6 @@
<include layout="@layout/layout_search_suggestion" />
<include
android:id="@+id/weather_info_layout"
layout="@layout/layout_weather_info" />
<FrameLayout
android:id="@+id/drag_layer"
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp"
android:minHeight="40dp"
android:updatePeriodMillis="0"
android:description="@string/weather"
android:initialLayout="@layout/layout_weather_info"
android:resizeMode="none"
android:widgetCategory="home_screen">
</appwidget-provider>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment