Skip to content

Commit

Permalink
Opening app when clicking in the widget's title
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbrandwein committed Nov 18, 2017
1 parent 1448133 commit 3baae9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import android.content.Intent;
import android.net.Uri;
import android.widget.RemoteViews;
import org.fedorahosted.freeotp.ClipboardManagerUtil;
import org.fedorahosted.freeotp.R;
import org.fedorahosted.freeotp.Token;
import org.fedorahosted.freeotp.TokenPersistence;
import org.fedorahosted.freeotp.*;

/**
* Created by root on 13/04/17.
Expand All @@ -22,7 +19,7 @@ public class OtpListWidgetProvider extends AppWidgetProvider {
/**
* Should be called whenever the {@link Token}s in the {@link TokenPersistence} are changed.
*/
public static void notifyWidgetDataChanged(final Context context){
public static void notifyWidgetDataChanged(final Context context) {
final AppWidgetManager manager = AppWidgetManager.getInstance(context);
final ComponentName providerComponentName = new ComponentName(context, OtpListWidgetProvider.class);
final int[] widgetIds = manager.getAppWidgetIds(providerComponentName);
Expand Down Expand Up @@ -70,6 +67,8 @@ private RemoteViews getFirstWidget(Context context, int widgetId) {
widget.setRemoteAdapter(R.id.list_widget, serviceIntent);
widget.setEmptyView(R.id.list_widget, android.R.id.empty);

setTitleIntent(context, widget);

final Intent showCodeIntent = new Intent(context, OtpListWidgetProvider.class)
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
showCodeIntent.setData(Uri.parse(showCodeIntent.toUri(Intent.URI_INTENT_SCHEME)));
Expand All @@ -79,6 +78,13 @@ private RemoteViews getFirstWidget(Context context, int widgetId) {
return widget;
}

private void setTitleIntent(final Context context, final RemoteViews widget) {
final Intent intent = new Intent(context, MainActivity.class)
.setAction(Intent.ACTION_MAIN);
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
widget.setOnClickPendingIntent(R.id.widget_title_container, pendingIntent);
}

private String getCodeForTokenId(final Context context, final String id) {
final TokenPersistence persistence = new TokenPersistence(context);
for (int i = 0; i <= persistence.length(); i++) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/list_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:orientation="vertical">

<LinearLayout
android:id="@+id/widget_title_container"
android:background="#88000000"
android:layout_width="match_parent"
android:layout_height="28dp"
Expand Down

0 comments on commit 3baae9c

Please sign in to comment.