Experience upgrade splash screen.
Behaves similarly to the DatabaseUpgradeActivity. You have a static list of ExperienceUpgrade models that include a "trigger" version, where when a user upgrades through it a notification will appear, and there will be a splash explanation screen. Right now the splash screens are basic and not too configurable, but that can be reworked as upgrades demand. Closes #4151pull/1/head
parent
0b20e99cd2
commit
3035dc4df9
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
Binary file not shown.
After Width: | Height: | Size: 509 B |
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:background="#FF2090ea">
|
||||
|
||||
<TextView android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:id="@+id/blurb"
|
||||
android:textSize="34sp"
|
||||
android:textIsSelectable="false"
|
||||
android:gravity="center_horizontal|bottom"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingRight="20dp"
|
||||
android:fontFamily="sans-serif-light"
|
||||
tools:text="@string/ExperienceUpgradeActivity_welcome_to_signal"
|
||||
android:textColor="@android:color/white" />
|
||||
|
||||
<ImageView android:id="@+id/watermark"
|
||||
android:layout_width="@dimen/onboarding_watermark_size"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="2"
|
||||
android:maxHeight="@dimen/onboarding_watermark_size"
|
||||
android:scaleType="fitCenter"
|
||||
tools:src="@drawable/splash_logo"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_below="@id/blurb"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_marginTop="@dimen/onboarding_margin_vert" />
|
||||
|
||||
<TextView android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="3"
|
||||
android:id="@+id/subblurb"
|
||||
android:textSize="20sp"
|
||||
android:textIsSelectable="false"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_marginTop="20dp"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingRight="20dp"
|
||||
android:fontFamily="sans-serif-light"
|
||||
tools:text="@string/ExperienceUpgradeActivity_textsecure_is_now_called_signal"
|
||||
android:textColor="@android:color/white" />
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:fab="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/container"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<Button android:id="@+id/continue_button"
|
||||
android:layout_width="140sp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="continue"
|
||||
android:visibility="invisible"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<me.relex.circleindicator.CircleIndicator
|
||||
android:id="@+id/indicator"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_marginBottom="25dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:layout_height="40dp" />
|
||||
|
||||
<com.melnykov.fab.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:layout_margin="25dp"
|
||||
android:src="@drawable/ic_arrow_forward_white_24dp"
|
||||
android:focusable="true"
|
||||
android:contentDescription="@string/conversation_list_fragment__fab_content_description"
|
||||
fab:fab_shadow="false"
|
||||
fab:fab_colorNormal="#33000000"
|
||||
fab:fab_colorPressed="#66000000"
|
||||
fab:fab_colorRipple="#66000000" />
|
||||
</FrameLayout>
|
@ -0,0 +1,54 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class BasicIntroFragment extends Fragment {
|
||||
|
||||
private static final String ARG_DRAWABLE = "drawable";
|
||||
private static final String ARG_TEXT = "text";
|
||||
private static final String ARG_SUBTEXT = "subtext";
|
||||
|
||||
private int drawable;
|
||||
private int text;
|
||||
private int subtext;
|
||||
|
||||
public static BasicIntroFragment newInstance(int drawable, int text, int subtext) {
|
||||
BasicIntroFragment fragment = new BasicIntroFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_DRAWABLE, drawable);
|
||||
args.putInt(ARG_TEXT, text);
|
||||
args.putInt(ARG_SUBTEXT, subtext);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public BasicIntroFragment() {}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
drawable = getArguments().getInt(ARG_DRAWABLE);
|
||||
text = getArguments().getInt(ARG_TEXT );
|
||||
subtext = getArguments().getInt(ARG_SUBTEXT );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.color_fragment, container, false);
|
||||
|
||||
((ImageView)v.findViewById(R.id.watermark)).setImageResource(drawable);
|
||||
((TextView)v.findViewById(R.id.blurb)).setText(text);
|
||||
((TextView)v.findViewById(R.id.subblurb)).setText(subtext);
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
@ -0,0 +1,224 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
import com.nineoldandroids.animation.ArgbEvaluator;
|
||||
|
||||
import org.thoughtcrime.securesms.IntroPagerAdapter.IntroPage;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import me.relex.circleindicator.CircleIndicator;
|
||||
|
||||
public class ExperienceUpgradeActivity extends BaseActionBarActivity {
|
||||
private static final String TAG = ExperienceUpgradeActivity.class.getSimpleName();
|
||||
private static final int NOTIFICATION_ID = 1339;
|
||||
|
||||
private enum ExperienceUpgrade {
|
||||
SIGNAL_REBRANDING(155,
|
||||
new IntroPage(0xFF2090EA,
|
||||
BasicIntroFragment.newInstance(R.drawable.splash_logo,
|
||||
R.string.ExperienceUpgradeActivity_welcome_to_signal_dgaf,
|
||||
R.string.ExperienceUpgradeActivity_textsecure_is_now_called_signal)),
|
||||
R.string.ExperienceUpgradeActivity_welcome_to_signal_excited,
|
||||
R.string.ExperienceUpgradeActivity_textsecure_is_now_signal,
|
||||
R.string.ExperienceUpgradeActivity_textsecure_is_now_signal_long);
|
||||
|
||||
private int version;
|
||||
private List<IntroPage> pages;
|
||||
private @StringRes int notificationTitle;
|
||||
private @StringRes int notificationText;
|
||||
private @StringRes int notificationBigText;
|
||||
|
||||
ExperienceUpgrade(int version,
|
||||
@NonNull List<IntroPage> pages,
|
||||
@StringRes int notificationTitle,
|
||||
@StringRes int notificationText,
|
||||
@StringRes int notificationBigText)
|
||||
{
|
||||
this.version = version;
|
||||
this.pages = pages;
|
||||
this.notificationTitle = notificationTitle;
|
||||
this.notificationText = notificationText;
|
||||
this.notificationBigText = notificationBigText;
|
||||
}
|
||||
|
||||
ExperienceUpgrade(int version,
|
||||
@NonNull IntroPage page,
|
||||
@StringRes int notificationTitle,
|
||||
@StringRes int notificationText,
|
||||
@StringRes int notificationBigText)
|
||||
{
|
||||
this(version, Collections.singletonList(page), notificationTitle, notificationText, notificationBigText);
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public List<IntroPage> getPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
public IntroPage getPage(int i) {
|
||||
return pages.get(i);
|
||||
}
|
||||
|
||||
public int getNotificationTitle() {
|
||||
return notificationTitle;
|
||||
}
|
||||
|
||||
public int getNotificationText() {
|
||||
return notificationText;
|
||||
}
|
||||
|
||||
public int getNotificationBigText() {
|
||||
return notificationBigText;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setStatusBarColor(getResources().getColor(R.color.signal_primary_dark));
|
||||
|
||||
Optional<ExperienceUpgrade> upgrade = getExperienceUpgrade(this);
|
||||
if (!upgrade.isPresent()) {
|
||||
onContinue();
|
||||
return;
|
||||
}
|
||||
|
||||
setContentView(R.layout.experience_upgrade_activity);
|
||||
final ViewPager pager = ViewUtil.findById(this, R.id.pager);
|
||||
final CircleIndicator indicator = ViewUtil.findById(this, R.id.indicator);
|
||||
final FloatingActionButton fab = ViewUtil.findById(this, R.id.fab);
|
||||
|
||||
pager.setAdapter(new IntroPagerAdapter(getSupportFragmentManager(), upgrade.get().getPages()));
|
||||
|
||||
if (upgrade.get().getPages().size() > 1) {
|
||||
indicator.setViewPager(pager);
|
||||
indicator.setOnPageChangeListener(new OnPageChangeListener(upgrade.get()));
|
||||
} else {
|
||||
indicator.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
fab.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onContinue();
|
||||
}
|
||||
});
|
||||
|
||||
getWindow().setBackgroundDrawable(new ColorDrawable(upgrade.get().getPage(0).backgroundColor));
|
||||
ServiceUtil.getNotificationManager(this).cancel(NOTIFICATION_ID);
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.LOLLIPOP)
|
||||
private void setStatusBarColor(int color) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().setStatusBarColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
private void onContinue() {
|
||||
TextSecurePreferences.setLastExperienceVersionCode(this, Util.getCurrentApkReleaseVersion(this));
|
||||
startActivity((Intent)getIntent().getParcelableExtra("next_intent"));
|
||||
finish();
|
||||
}
|
||||
|
||||
public static boolean isUpdate(Context context) {
|
||||
return getExperienceUpgrade(context).isPresent();
|
||||
}
|
||||
|
||||
public static Optional<ExperienceUpgrade> getExperienceUpgrade(Context context) {
|
||||
final int currentVersionCode = Util.getCurrentApkReleaseVersion(context);
|
||||
final int lastSeenVersion = TextSecurePreferences.getLastExperienceVersionCode(context);
|
||||
Log.w(TAG, "getExperienceUpgrade(" + lastSeenVersion + ")");
|
||||
|
||||
if (lastSeenVersion >= currentVersionCode || lastSeenVersion == 0) {
|
||||
TextSecurePreferences.setLastExperienceVersionCode(context, currentVersionCode);
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
Optional<ExperienceUpgrade> eligibleUpgrade = Optional.absent();
|
||||
for (ExperienceUpgrade upgrade : ExperienceUpgrade.values()) {
|
||||
if (lastSeenVersion < upgrade.getVersion()) eligibleUpgrade = Optional.of(upgrade);
|
||||
}
|
||||
|
||||
return eligibleUpgrade;
|
||||
}
|
||||
|
||||
private final class OnPageChangeListener implements ViewPager.OnPageChangeListener {
|
||||
private final ArgbEvaluator evaluator = new ArgbEvaluator();
|
||||
private final ExperienceUpgrade upgrade;
|
||||
|
||||
public OnPageChangeListener(ExperienceUpgrade upgrade) {
|
||||
this.upgrade = upgrade;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
final int nextPosition = (position + 1) % upgrade.getPages().size();
|
||||
|
||||
final int color = (Integer)evaluator.evaluate(positionOffset,
|
||||
upgrade.getPage(position).backgroundColor,
|
||||
upgrade.getPage(nextPosition).backgroundColor);
|
||||
getWindow().setBackgroundDrawable(new ColorDrawable(color));
|
||||
}
|
||||
}
|
||||
|
||||
public static class AppUpgradeReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if(Intent.ACTION_PACKAGE_REPLACED.equals(intent.getAction()) &&
|
||||
intent.getData().getSchemeSpecificPart().equals(context.getPackageName()))
|
||||
{
|
||||
Optional<ExperienceUpgrade> experienceUpgrade = getExperienceUpgrade(context);
|
||||
if (!experienceUpgrade.isPresent()) return;
|
||||
|
||||
Intent targetIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
Notification notification = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.icon_notification)
|
||||
.setColor(context.getResources().getColor(R.color.signal_primary))
|
||||
.setContentTitle(context.getString(experienceUpgrade.get().getNotificationTitle()))
|
||||
.setContentText(context.getString(experienceUpgrade.get().getNotificationText()))
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(experienceUpgrade.get().getNotificationBigText())))
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(PendingIntent.getActivity(context, 0,
|
||||
targetIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
.build();
|
||||
ServiceUtil.getNotificationManager(context).notify(NOTIFICATION_ID, notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IntroPagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
public static class IntroPage {
|
||||
final int backgroundColor;
|
||||
final Fragment fragment;
|
||||
|
||||
public IntroPage(int backgroundColor, Fragment fragment) {
|
||||
this.backgroundColor = backgroundColor;
|
||||
this.fragment = fragment;
|
||||
}
|
||||
}
|
||||
|
||||
private List<IntroPage> pages;
|
||||
|
||||
public IntroPagerAdapter(FragmentManager fm, List<IntroPage> pages) {
|
||||
super(fm);
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
IntroPage page = pages.get(i);
|
||||
return page.fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return pages.size();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue