Added Quick Launch Icon to the Home Screen Widget #1296 (#2862)

This commit is contained in:
Madhur Gupta 2019-04-11 14:02:11 +05:30 committed by Josephine Lim
parent 6bde4f97cf
commit a838962f49
2 changed files with 30 additions and 7 deletions

View file

@ -25,6 +25,7 @@ import javax.inject.Inject;
import androidx.annotation.Nullable;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.MainActivity;
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
import io.reactivex.android.schedulers.AndroidSchedulers;
@ -45,6 +46,13 @@ public class PicOfDayAppWidget extends AppWidgetProvider {
void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.pic_of_day_app_widget);
// Launch App on Button Click
Intent viewIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, viewIntent, 0);
views.setOnClickPendingIntent(R.id.camera_button, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
loadPictureOfTheDay(context, views, appWidgetManager, appWidgetId);
}

View file

@ -1,19 +1,34 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:padding="@dimen/widget_margin"
android:orientation="vertical">
<TextView
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="20sp"
android:gravity="center"
android:layout_marginTop="10dp"
android:text="@string/app_widget_heading"/>
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/app_widget_heading"
android:textColor="@color/white"
android:layout_centerHorizontal="true"
android:textSize="20sp" />
<ImageView
android:id="@+id/camera_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_photo_camera_white_24dp" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"