mirror of https://github.com/tasks/tasks
Remove welcome walkthrough, sync upgrade prompt
parent
79313d1b0d
commit
e060d36256
@ -1,137 +0,0 @@
|
|||||||
package com.todoroo.astrid.actfm.sync;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.timsu.astrid.R;
|
|
||||||
import com.todoroo.andlib.utility.DateUtilities;
|
|
||||||
import com.todoroo.andlib.utility.Preferences;
|
|
||||||
import com.todoroo.astrid.actfm.ActFmLoginActivity;
|
|
||||||
import com.todoroo.astrid.core.PluginServices;
|
|
||||||
|
|
||||||
public class SyncUpgradePrompt {
|
|
||||||
|
|
||||||
private static final String P_SYNC_UPGRADE_PROMPT = "p_sync_upgr_prompt"; //$NON-NLS-1$
|
|
||||||
private static long lastPromptDate = -1;
|
|
||||||
|
|
||||||
public static void showSyncUpgradePrompt(final Activity activity) {
|
|
||||||
if (lastPromptDate == -1) {
|
|
||||||
lastPromptDate = Preferences.getLong(P_SYNC_UPGRADE_PROMPT, 0L);
|
|
||||||
}
|
|
||||||
|
|
||||||
Dialog d = null;
|
|
||||||
if (DateUtilities.now() - lastPromptDate > DateUtilities.ONE_WEEK * 3) {
|
|
||||||
if (!PluginServices.getActFmPreferenceService().isLoggedIn()) {
|
|
||||||
if (PluginServices.getGtasksPreferenceService().isLoggedIn()) {
|
|
||||||
// Logged into google but not astrid
|
|
||||||
d = getDialog(activity, R.string.sync_upgr_gtasks_only_title, R.string.sync_upgr_gtasks_only_body,
|
|
||||||
R.string.sync_upgr_gtasks_only_btn1, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
activity.startActivity(new Intent(activity, ActFmLoginActivity.class));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
R.string.sync_upgr_gtasks_only_btn2,
|
|
||||||
null);
|
|
||||||
} else {
|
|
||||||
// Logged into neither
|
|
||||||
d = getDialog(activity, R.string.sync_upgr_neither_title, R.string.sync_upgr_neither_body,
|
|
||||||
R.string.sync_upgr_neither_btn1, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
activity.startActivity(new Intent(activity, ActFmLoginActivity.class));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
setLastPromptDate(DateUtilities.now());
|
|
||||||
} else if (PluginServices.getGtasksPreferenceService().isLoggedIn()) {
|
|
||||||
// Logged into both
|
|
||||||
d = getDialog(activity, R.string.sync_upgr_both_title, R.string.sync_upgr_both_body,
|
|
||||||
R.string.sync_upgr_both_btn1,
|
|
||||||
null,
|
|
||||||
R.string.sync_upgr_both_btn2, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
new ActFmSyncV2Provider().signOut(activity);
|
|
||||||
Toast.makeText(activity, R.string.sync_upgr_logged_out, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
setLastPromptDate(Long.MAX_VALUE);
|
|
||||||
} else {
|
|
||||||
// Logged into just astrid--don't need to show prompts anymore
|
|
||||||
setLastPromptDate(Long.MAX_VALUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d != null) {
|
|
||||||
d.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setLastPromptDate(long date) {
|
|
||||||
lastPromptDate = date;
|
|
||||||
Preferences.setLong(P_SYNC_UPGRADE_PROMPT, lastPromptDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Dialog getDialog(Activity activity, int title, int body, Object... buttonsAndListeners) {
|
|
||||||
final Dialog d = new Dialog(activity, R.style.ReminderDialog);
|
|
||||||
d.setContentView(R.layout.astrid_reminder_view_portrait);
|
|
||||||
((TextView) d.findViewById(R.id.reminder_title)).setText(title);
|
|
||||||
((TextView) d.findViewById(R.id.reminder_message)).setText(body);
|
|
||||||
|
|
||||||
d.findViewById(R.id.dismiss).setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
d.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
d.findViewById(R.id.reminder_complete).setVisibility(View.GONE);
|
|
||||||
TypedValue tv = new TypedValue();
|
|
||||||
activity.getTheme().resolveAttribute(R.attr.asThemeTextColor, tv, false);
|
|
||||||
|
|
||||||
int button1 = (Integer) buttonsAndListeners[0];
|
|
||||||
final Runnable listener1 = (Runnable) buttonsAndListeners[1];
|
|
||||||
Button b1 = (Button) d.findViewById(R.id.reminder_edit);
|
|
||||||
b1.setText(button1);
|
|
||||||
b1.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
d.dismiss();
|
|
||||||
if (listener1 != null) {
|
|
||||||
listener1.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
b1.setBackgroundColor(activity.getResources().getColor(tv.data));
|
|
||||||
|
|
||||||
if (buttonsAndListeners.length < 3) {
|
|
||||||
d.findViewById(R.id.reminder_snooze).setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
int button2 = (Integer) buttonsAndListeners[2];
|
|
||||||
final Runnable listener2 = (Runnable) buttonsAndListeners[3];
|
|
||||||
Button b2 = (Button) d.findViewById(R.id.reminder_snooze);
|
|
||||||
b2.setText(button2);
|
|
||||||
b2.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
d.dismiss();
|
|
||||||
if (listener2 != null) {
|
|
||||||
listener2.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
b2.setBackgroundColor(activity.getResources().getColor(tv.data));
|
|
||||||
}
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Binary file not shown.
Before Width: | Height: | Size: 69 KiB |
Binary file not shown.
Before Width: | Height: | Size: 79 KiB |
Binary file not shown.
Before Width: | Height: | Size: 69 KiB |
Binary file not shown.
Before Width: | Height: | Size: 84 KiB |
Binary file not shown.
Before Width: | Height: | Size: 65 KiB |
@ -1,56 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
** Copyright (c) 2012 Todoroo Inc
|
|
||||||
**
|
|
||||||
** See the file "LICENSE" for the full license governing this code.
|
|
||||||
-->
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
|
|
||||||
<android.support.v4.view.ViewPager
|
|
||||||
android:id="@+id/pager"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:paddingTop="3dip"
|
|
||||||
android:paddingBottom="3dip"
|
|
||||||
android:background="#55000000"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
<com.viewpagerindicator.CirclePageIndicator
|
|
||||||
android:id="@+id/indicator"
|
|
||||||
android:padding="15dip"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:background="#00000000"
|
|
||||||
style="@style/CustomCirclePageIndicator"/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/next"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_marginRight="5dip"
|
|
||||||
android:text="@string/welcome_next"
|
|
||||||
android:textColor="#444444"
|
|
||||||
android:textSize="20dip"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:paddingRight="10dip"
|
|
||||||
android:shadowRadius="2"
|
|
||||||
android:shadowDy="1"
|
|
||||||
android:shadowColor="@android:color/white" />
|
|
||||||
</RelativeLayout>
|
|
||||||
</RelativeLayout>
|
|
||||||
</LinearLayout>
|
|
@ -1,119 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
** Copyright (c) 2012 Todoroo Inc
|
|
||||||
**
|
|
||||||
** See the file "LICENSE" for the full license governing this code.
|
|
||||||
-->
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:paddingLeft="4dip"
|
|
||||||
android:paddingRight="4dip"
|
|
||||||
android:background="#d0d0d0"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/logo"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="110dip"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:paddingBottom="10dip"
|
|
||||||
android:layout_marginTop="30dip"
|
|
||||||
android:text="@string/welcome_title_7"
|
|
||||||
android:textColor="#444444"
|
|
||||||
android:textSize="40dip"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:shadowRadius="2"
|
|
||||||
android:shadowDy="1"
|
|
||||||
android:shadowColor="@android:color/white"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/error"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center"
|
|
||||||
android:textColor="#ff0000"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="253dp"
|
|
||||||
android:paddingTop="5dip" >
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tos"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="35dip"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:gravity="center"
|
|
||||||
android:paddingLeft="20dip"
|
|
||||||
android:paddingRight="20dip"
|
|
||||||
android:textSize="12.5sp"
|
|
||||||
android:textColor="#444444" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/gg_login"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="45dip"
|
|
||||||
android:layout_below="@id/tos"
|
|
||||||
android:paddingLeft="20dip"
|
|
||||||
android:paddingRight="20dip"
|
|
||||||
android:layout_marginLeft="15dip"
|
|
||||||
android:layout_marginRight="15dip"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:drawableLeft="@drawable/google"
|
|
||||||
android:text="@string/actfm_ALA_gg_login" />
|
|
||||||
|
|
||||||
<com.facebook.android.LoginButton
|
|
||||||
android:id="@+id/fb_login"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="45dip"
|
|
||||||
android:layout_below="@id/gg_login"
|
|
||||||
android:paddingLeft="20dip"
|
|
||||||
android:paddingRight="20dip"
|
|
||||||
android:layout_marginLeft="15dip"
|
|
||||||
android:layout_marginRight="15dip"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:drawableLeft="@drawable/facebook"
|
|
||||||
android:text="@string/actfm_ALA_fb_login" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/pw_signup"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="45dip"
|
|
||||||
android:layout_below="@id/fb_login"
|
|
||||||
android:paddingLeft="20dip"
|
|
||||||
android:paddingRight="20dip"
|
|
||||||
android:layout_marginLeft="15dip"
|
|
||||||
android:layout_marginRight="15dip"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:text="@string/welcome_login_pw"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/pw_login"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="35dip"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_below="@id/pw_signup"
|
|
||||||
android:textColor="#444"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:text="@string/welcome_sign_in"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/login_later"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="45dip"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_below="@id/pw_login"
|
|
||||||
android:paddingLeft="20dip"
|
|
||||||
android:paddingRight="20dip"
|
|
||||||
android:paddingBottom="5dip"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:text="@string/welcome_login_later"
|
|
||||||
android:textColor="#444444" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
</LinearLayout>
|
|
@ -1,48 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
** Copyright (c) 2012 Todoroo Inc
|
|
||||||
**
|
|
||||||
** See the file "LICENSE" for the full license governing this code.
|
|
||||||
-->
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:background="#d0d0d0">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/welcome_walkthrough_title"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="27dp"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:text="Hello"
|
|
||||||
android:textColor="#444444"
|
|
||||||
android:textSize="40dip"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:shadowRadius="2"
|
|
||||||
android:shadowDy="1"
|
|
||||||
android:shadowColor="@android:color/white" />
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/welcome_walkthrough_image"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:src="@drawable/welcome_walkthrough_1"
|
|
||||||
android:scaleType="fitCenter"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/welcome_walkthrough_body"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="75dp"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:text="Hello"
|
|
||||||
android:textColor="#444444"
|
|
||||||
android:textSize="20dip"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:shadowRadius="2"
|
|
||||||
android:shadowDy="1"
|
|
||||||
android:shadowColor="@android:color/white" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@ -1,45 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:background="@drawable/astrid_com_gradient"
|
|
||||||
android:gravity="center_horizontal">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:paddingTop="39dip"
|
|
||||||
android:src="@drawable/astrid_com_logo_new"
|
|
||||||
android:scaleType="center" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/quick_login_google"
|
|
||||||
android:layout_width="280dip"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:minHeight="45dip"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:background="@drawable/google_login_background"
|
|
||||||
android:textColor="@android:color/white"
|
|
||||||
android:layout_marginBottom="15dip"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/quick_login_reject"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="45dip"
|
|
||||||
android:layout_marginBottom="70dip"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:textColor="@android:color/white"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/error"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="45dip"
|
|
||||||
android:gravity="center"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:textColor="#ff0000"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@ -1,194 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2012 Todoroo Inc
|
|
||||||
*
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.welcome.tutorial;
|
|
||||||
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.support.v4.view.PagerAdapter;
|
|
||||||
import android.support.v4.view.ViewPager;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager;
|
|
||||||
import com.timsu.astrid.R;
|
|
||||||
import com.todoroo.andlib.service.Autowired;
|
|
||||||
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
||||||
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
|
|
||||||
import com.todoroo.astrid.utility.Constants;
|
|
||||||
import com.viewpagerindicator.TitleProvider;
|
|
||||||
|
|
||||||
public class WelcomePagerAdapter extends PagerAdapter implements TitleProvider
|
|
||||||
{
|
|
||||||
private int[] images = new int[] {
|
|
||||||
R.drawable.welcome_walkthrough_1,
|
|
||||||
R.drawable.welcome_walkthrough_2,
|
|
||||||
R.drawable.welcome_walkthrough_3,
|
|
||||||
R.drawable.welcome_walkthrough_4,
|
|
||||||
R.drawable.welcome_walkthrough_5,
|
|
||||||
R.drawable.welcome_walkthrough_6,
|
|
||||||
0
|
|
||||||
};
|
|
||||||
private int[] title = new int[] {
|
|
||||||
R.string.welcome_title_1,
|
|
||||||
R.string.welcome_title_2,
|
|
||||||
R.string.welcome_title_3,
|
|
||||||
R.string.welcome_title_4,
|
|
||||||
R.string.welcome_title_5,
|
|
||||||
R.string.welcome_title_6,
|
|
||||||
R.string.welcome_title_7,
|
|
||||||
};
|
|
||||||
private int[] body = new int[] {
|
|
||||||
R.string.welcome_body_1,
|
|
||||||
R.string.welcome_body_2,
|
|
||||||
R.string.welcome_body_3,
|
|
||||||
R.string.welcome_body_4,
|
|
||||||
R.string.welcome_body_5,
|
|
||||||
R.string.welcome_body_6,
|
|
||||||
R.string.welcome_body_7,
|
|
||||||
};
|
|
||||||
public int[] layouts = new int[] {
|
|
||||||
R.layout.welcome_walkthrough_page,
|
|
||||||
R.layout.welcome_walkthrough_page,
|
|
||||||
R.layout.welcome_walkthrough_page,
|
|
||||||
R.layout.welcome_walkthrough_page,
|
|
||||||
R.layout.welcome_walkthrough_page,
|
|
||||||
R.layout.welcome_walkthrough_page,
|
|
||||||
R.layout.actfm_login_activity,
|
|
||||||
};
|
|
||||||
|
|
||||||
public int fallbackLoginPage;
|
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
public Account[] accounts;
|
|
||||||
public WelcomeWalkthrough parent;
|
|
||||||
@Autowired ActFmPreferenceService actFmPreferenceService;
|
|
||||||
|
|
||||||
public WelcomePagerAdapter(Context context, boolean manual) {
|
|
||||||
this.context = context;
|
|
||||||
DependencyInjectionService.getInstance().inject(this);
|
|
||||||
|
|
||||||
accounts = null;
|
|
||||||
try {
|
|
||||||
GoogleAccountManager am = new GoogleAccountManager(context);
|
|
||||||
accounts = am.getAccounts();
|
|
||||||
} catch (Exception e) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
if (manual) {
|
|
||||||
layouts[layouts.length - 1] = R.layout.welcome_walkthrough_page;
|
|
||||||
title[title.length - 1] = R.string.welcome_title_7_return;
|
|
||||||
images[images.length - 1] = R.drawable.welcome_walkthrough_1;
|
|
||||||
body[body.length - 1] = R.string.welcome_body_7_return;
|
|
||||||
fallbackLoginPage = R.layout.actfm_login_activity;
|
|
||||||
} else {
|
|
||||||
if (Constants.ASTRID_LITE) {
|
|
||||||
adjustResourcesForLite();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup login page from AB tests
|
|
||||||
fallbackLoginPage = layouts[layouts.length - 1];
|
|
||||||
if (accounts != null && accounts.length > 0) { // If has google account
|
|
||||||
layouts[layouts.length - 1] = R.layout.welcome_walkthrough_simple_login;
|
|
||||||
fallbackLoginPage = R.layout.actfm_login_activity;
|
|
||||||
} else { // If no google account
|
|
||||||
fallbackLoginPage = layouts[layouts.length - 1] = R.layout.actfm_login_activity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void adjustResourcesForLite() {
|
|
||||||
images = new int[] { 0 };
|
|
||||||
title = new int[] { R.string.welcome_title_7 };
|
|
||||||
body = new int[] { R.string.welcome_body_7 };
|
|
||||||
layouts = new int[] { R.layout.actfm_login_activity };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPrimaryItem(ViewGroup container, int position, Object object) {
|
|
||||||
super.setPrimaryItem(container, position, object);
|
|
||||||
|
|
||||||
parent.onPageChanged(container, position);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return layouts.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void changeLoginPage(int newLayout) {
|
|
||||||
layouts[layouts.length - 1] = newLayout;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object instantiateItem(final View pager, final int position) {
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(context);
|
|
||||||
|
|
||||||
View pageView = inflater.inflate(layouts[position], null, true);
|
|
||||||
pageView.setLayoutParams(new ViewGroup.LayoutParams(
|
|
||||||
WindowManager.LayoutParams.MATCH_PARENT,
|
|
||||||
WindowManager.LayoutParams.MATCH_PARENT));
|
|
||||||
|
|
||||||
if (pageView.findViewById(R.id.welcome_walkthrough_image) != null) {
|
|
||||||
ImageView imageView = (ImageView) pageView.findViewById(R.id.welcome_walkthrough_image);
|
|
||||||
imageView.setImageResource(images[position]);
|
|
||||||
|
|
||||||
TextView titleView = (TextView) pageView.findViewById(R.id.welcome_walkthrough_title);
|
|
||||||
titleView.setText(title[position]);
|
|
||||||
|
|
||||||
TextView bodyView = (TextView) pageView.findViewById(R.id.welcome_walkthrough_body);
|
|
||||||
bodyView.setText(body[position]);
|
|
||||||
}
|
|
||||||
|
|
||||||
((ViewPager) pager).addView(pageView, 0);
|
|
||||||
parent.instantiatePage(position);
|
|
||||||
return pageView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroyItem(View pager, int position, Object view) {
|
|
||||||
((ViewPager) pager).removeView((View) view);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isViewFromObject(View view, Object object) {
|
|
||||||
return view.equals(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finishUpdate(View view) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void restoreState(Parcelable p, ClassLoader c) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Parcelable saveState() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startUpdate(View view) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTitle(int position) {
|
|
||||||
return context.getString(title[position]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,269 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2012 Todoroo Inc
|
|
||||||
*
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.todoroo.astrid.welcome.tutorial;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.accounts.AccountManager;
|
|
||||||
import android.accounts.AccountManagerCallback;
|
|
||||||
import android.accounts.AccountManagerFuture;
|
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.view.ViewPager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.view.Window;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager;
|
|
||||||
import com.timsu.astrid.R;
|
|
||||||
import com.todoroo.andlib.utility.DialogUtilities;
|
|
||||||
import com.todoroo.astrid.actfm.ActFmGoogleAuthActivity;
|
|
||||||
import com.todoroo.astrid.actfm.ActFmLoginActivity;
|
|
||||||
import com.todoroo.astrid.service.StatisticsConstants;
|
|
||||||
import com.viewpagerindicator.CirclePageIndicator;
|
|
||||||
|
|
||||||
public class WelcomeWalkthrough extends ActFmLoginActivity {
|
|
||||||
private ViewPager mPager;
|
|
||||||
private WelcomePagerAdapter mAdapter;
|
|
||||||
private Account[] accounts;
|
|
||||||
private CirclePageIndicator mIndicator;
|
|
||||||
private View currentView;
|
|
||||||
private int currentPage;
|
|
||||||
|
|
||||||
private String authToken;
|
|
||||||
private boolean onSuccess = false;
|
|
||||||
private boolean dismissDialog = false;
|
|
||||||
|
|
||||||
public static final String KEY_SHOWED_WELCOME_LOGIN = "key_showed_welcome_login"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
public static final String TOKEN_MANUAL_SHOW = "manual"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
mAdapter = new WelcomePagerAdapter(this, getIntent().hasExtra(TOKEN_MANUAL_SHOW));
|
|
||||||
mAdapter.parent = this;
|
|
||||||
accounts = mAdapter.accounts;
|
|
||||||
|
|
||||||
mPager = (ViewPager)findViewById(R.id.pager);
|
|
||||||
mPager.setAdapter(mAdapter);
|
|
||||||
|
|
||||||
mIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
|
|
||||||
mIndicator.setViewPager(mPager);
|
|
||||||
if (mAdapter.getCount() <= 1) {
|
|
||||||
mIndicator.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected int getContentViewResource() {
|
|
||||||
return R.layout.welcome_walkthrough;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getTitleResource() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void instantiatePage(int position){
|
|
||||||
if (position == mAdapter.getCount()-1) {
|
|
||||||
initializeUI();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getLoginPageLayout() {
|
|
||||||
return mAdapter.fallbackLoginPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initializeUI() {
|
|
||||||
String email = null;
|
|
||||||
if (accounts != null && accounts.length > 0 && !TextUtils.isEmpty(accounts[0].name)) {
|
|
||||||
email = accounts[0].name;
|
|
||||||
}
|
|
||||||
Button simpleLogin = (Button) findViewById(R.id.quick_login_google);
|
|
||||||
if (simpleLogin != null && !TextUtils.isEmpty(email)) {
|
|
||||||
initializeSimpleUI(email);
|
|
||||||
} else {
|
|
||||||
if (mAdapter != null && mAdapter.layouts[mAdapter.layouts.length - 1] != getLoginPageLayout()) {
|
|
||||||
mAdapter.changeLoginPage(getLoginPageLayout());
|
|
||||||
}
|
|
||||||
super.initializeUI();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeSimpleUI(final String email) {
|
|
||||||
Button simpleLogin = (Button) findViewById(R.id.quick_login_google);
|
|
||||||
simpleLogin.setText(getString(R.string.actfm_quick_login, email));
|
|
||||||
simpleLogin.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
final ProgressDialog pd = DialogUtilities.progressDialog(WelcomeWalkthrough.this, getString(R.string.gtasks_GLA_authenticating));
|
|
||||||
pd.show();
|
|
||||||
getAuthToken(email, pd);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getAuthToken(final String e,
|
|
||||||
final ProgressDialog pd) {
|
|
||||||
final GoogleAccountManager accountManager = new GoogleAccountManager(WelcomeWalkthrough.this);
|
|
||||||
Account a = accountManager.getAccountByName(e);
|
|
||||||
AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() {
|
|
||||||
@Override
|
|
||||||
public void run(final AccountManagerFuture<Bundle> future) {
|
|
||||||
new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Bundle bundle = future.getResult(30, TimeUnit.SECONDS);
|
|
||||||
if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
|
|
||||||
authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
|
|
||||||
if (!onSuccess) {
|
|
||||||
accountManager.manager.invalidateAuthToken(ActFmGoogleAuthActivity.AUTH_TOKEN_TYPE, authToken);
|
|
||||||
getAuthToken(e, pd);
|
|
||||||
onSuccess = true;
|
|
||||||
} else {
|
|
||||||
onAuthTokenSuccess(e, authToken);
|
|
||||||
dismissDialog = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dismissDialog = true;
|
|
||||||
}
|
|
||||||
} catch (final Exception e) {
|
|
||||||
Log.e("actfm-google-auth", "Login Error", e); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
int error = e instanceof IOException ? R.string.gtasks_GLA_errorIOAuth :
|
|
||||||
R.string.gtasks_GLA_errorAuth;
|
|
||||||
Toast.makeText(WelcomeWalkthrough.this,
|
|
||||||
error,
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
onAuthError();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
if (dismissDialog) {
|
|
||||||
DialogUtilities.dismissDialog(WelcomeWalkthrough.this, pd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
accountManager.manager.getAuthToken(a, ActFmGoogleAuthActivity.AUTH_TOKEN_TYPE, null, WelcomeWalkthrough.this, callback, null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
TextView rejectQuickLogin = (TextView) findViewById(R.id.quick_login_reject);
|
|
||||||
rejectQuickLogin.setText(getString(R.string.actfm_quick_login_reject, email));
|
|
||||||
rejectQuickLogin.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
switchToLoginPage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
errors = (TextView) findViewById(R.id.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onAuthTokenSuccess(final String email, final String authToken) {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
authenticate(email, email, "", "google", authToken); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onAuthError() {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
switchToLoginPage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void switchToLoginPage() {
|
|
||||||
mAdapter.changeLoginPage(getLoginPageLayout());
|
|
||||||
mPager.setAdapter(mAdapter);
|
|
||||||
mPager.setCurrentItem(mAdapter.layouts.length - 1, false);
|
|
||||||
initializeUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPageChanged(View view, int position) {
|
|
||||||
currentPage = position;
|
|
||||||
currentView = view;
|
|
||||||
findViewById(R.id.next).setVisibility(
|
|
||||||
position == mAdapter.getCount() - 1 ? View.GONE : View.VISIBLE);
|
|
||||||
|
|
||||||
if(currentPage == mAdapter.getCount() - 1) {
|
|
||||||
if(findViewById(R.id.fb_login) != null) {
|
|
||||||
setupLoginLater();
|
|
||||||
} else {
|
|
||||||
OnClickListener done = new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View arg0) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
View title = currentView.findViewById(R.id.welcome_walkthrough_title);
|
|
||||||
if (title != null) {
|
|
||||||
title.setOnClickListener(done);
|
|
||||||
}
|
|
||||||
View image = currentView.findViewById(R.id.welcome_walkthrough_image);
|
|
||||||
if (image != null) {
|
|
||||||
image.setOnClickListener(done);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
((CirclePageIndicator) mIndicator).setVisibility(currentPage == mAdapter.getCount()-1 ? View.GONE : View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setupPWLogin() {
|
|
||||||
Button pwLogin = (Button) findViewById(R.id.pw_signup);
|
|
||||||
pwLogin.setOnClickListener(signUpListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setupLoginLater() {
|
|
||||||
TextView loginLater = (TextView)currentView.findViewById(R.id.login_later);
|
|
||||||
loginLater.setOnClickListener(loginLaterListener);
|
|
||||||
loginLater.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected final OnClickListener loginLaterListener = new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View arg0) {
|
|
||||||
String title = getString(R.string.welcome_login_confirm_later_title);
|
|
||||||
String confirmLater = getString(R.string.welcome_login_confirm_later_dialog);
|
|
||||||
DialogUtilities.okCancelCustomDialog(WelcomeWalkthrough.this, title, confirmLater,
|
|
||||||
R.string.welcome_login_confirm_later_ok,
|
|
||||||
R.string.welcome_login_confirm_later_cancel,
|
|
||||||
android.R.drawable.ic_dialog_alert,
|
|
||||||
null, confirmLaterListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final DialogInterface.OnClickListener confirmLaterListener = new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue