123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- /**
- * Nextcloud Android client application
- *
- * @author Bartosz Przybylski
- * Copyright (C) 2015 Bartosz Przybylski
- * Copyright (C) 2015 ownCloud Inc.
- * Copyright (C) 2016 Nextcloud.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.owncloud.android.ui.activity;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Build;
- import android.os.Bundle;
- import android.preference.PreferenceManager;
- import android.support.annotation.Nullable;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentActivity;
- import android.support.v4.app.FragmentManager;
- import android.support.v4.app.FragmentPagerAdapter;
- import android.support.v4.view.ViewPager;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.ImageButton;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.owncloud.android.MainApp;
- import com.owncloud.android.R;
- import com.owncloud.android.authentication.AccountAuthenticatorActivity;
- import com.owncloud.android.authentication.AccountUtils;
- import com.owncloud.android.features.FeatureList;
- import com.owncloud.android.features.FeatureList.FeatureItem;
- import com.owncloud.android.ui.whatsnew.ProgressIndicator;
- /**
- * Activity displaying general feature after a fresh install and new features after an update.
- */
- public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPageChangeListener {
- private static final String KEY_LAST_SEEN_VERSION_CODE = "lastSeenVersionCode";
- private static final String SCREEN_NAME = "What's new";
- private static final String TAG = WhatsNewActivity.class.getSimpleName();
- private ImageButton mForwardFinishButton;
- private Button mSkipButton;
- private ProgressIndicator mProgress;
- private ViewPager mPager;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.whats_new_activity);
- mProgress = (ProgressIndicator) findViewById(R.id.progressIndicator);
- mPager = (ViewPager)findViewById(R.id.contentPanel);
- final boolean isBeta = getResources().getBoolean(R.bool.is_beta);
- FeaturesViewAdapter adapter = new FeaturesViewAdapter(getSupportFragmentManager(),
- FeatureList.getFiltered(getLastSeenVersionCode(), isFirstRun(), isBeta));
- mProgress.setNumberOfSteps(adapter.getCount());
- mPager.setAdapter(adapter);
- mPager.addOnPageChangeListener(this);
- mForwardFinishButton = (ImageButton) findViewById(R.id.forward);
- mForwardFinishButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (mProgress.hasNextStep()) {
- mPager.setCurrentItem(mPager.getCurrentItem()+1, true);
- mProgress.animateToStep(mPager.getCurrentItem()+1);
- } else {
- onFinish();
- finish();
- }
- updateNextButtonIfNeeded();
- }
- });
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- mForwardFinishButton.setBackground(null);
- } else {
- mForwardFinishButton.setBackgroundDrawable(null);
- }
- mSkipButton = (Button) findViewById(R.id.skip);
- mSkipButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- onFinish();
- finish();
- }
- });
- TextView tv = (TextView)findViewById(R.id.welcomeText);
- tv.setText(isFirstRun() ? R.string.empty : R.string.whats_new_title);
- updateNextButtonIfNeeded();
- }
- @Override
- public void onBackPressed() {
- onFinish();
- super.onBackPressed();
- }
- private void updateNextButtonIfNeeded() {
- if (!mProgress.hasNextStep()) {
- mForwardFinishButton.setImageResource(R.drawable.ic_done_white);
- mSkipButton.setVisibility(View.INVISIBLE);
- } else {
- mForwardFinishButton.setImageResource(R.drawable.arrow_right);
- mSkipButton.setVisibility(View.VISIBLE);
- }
- }
- private void onFinish() {
- SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
- SharedPreferences.Editor editor = pref.edit();
- editor.putInt(KEY_LAST_SEEN_VERSION_CODE, MainApp.getVersionCode());
- editor.apply();
- }
- static private int getLastSeenVersionCode() {
- SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext());
- return pref.getInt(KEY_LAST_SEEN_VERSION_CODE, 0);
- }
- static private boolean isFirstRun() {
- return getLastSeenVersionCode() == 0 && AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext()) == null;
- }
- static public void runIfNeeded(Context context) {
- if (context instanceof WhatsNewActivity) {
- return;
- }
- if (shouldShow(context)) {
- context.startActivity(new Intent(context, WhatsNewActivity.class));
- }
- }
- static private boolean shouldShow(Context context) {
- final boolean isBeta = context.getResources().getBoolean(R.bool.is_beta);
- return (isFirstRun() && context instanceof AccountAuthenticatorActivity) ||
- (
- !(isFirstRun() && (context instanceof FileDisplayActivity)) &&
- !(context instanceof PassCodeActivity) &&
- (FeatureList.getFiltered(getLastSeenVersionCode(), isFirstRun(), isBeta).length > 0)
- );
- }
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- // unused but to be implemented due to abstract parent
- }
- @Override
- public void onPageSelected(int position) {
- mProgress.animateToStep(position+1);
- updateNextButtonIfNeeded();
- }
- @Override
- public void onPageScrollStateChanged(int state) {
- // unused but to be implemented due to abstract parent
- }
- private final class FeaturesViewAdapter extends FragmentPagerAdapter {
- private FeatureItem[] mFeatures;
- public FeaturesViewAdapter(FragmentManager fm, FeatureItem[]features) {
- super(fm);
- mFeatures = features;
- }
- @Override
- public Fragment getItem(int position) {
- return FeatureFragment.newInstance(mFeatures[position]);
- }
- @Override
- public int getCount() {
- return mFeatures.length;
- }
- }
- public static class FeatureFragment extends Fragment {
- private FeatureItem mItem;
- static public FeatureFragment newInstance(FeatureItem item) {
- FeatureFragment f = new FeatureFragment();
- Bundle args = new Bundle();
- args.putParcelable("feature", item);
- f.setArguments(args);
- return f;
- }
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mItem = getArguments() != null ? (FeatureItem)getArguments().getParcelable("feature") : null;
- }
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater,
- @Nullable ViewGroup container,
- @Nullable Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.whats_new_element, container, false);
- ImageView iv = (ImageView)v.findViewById(R.id.whatsNewImage);
- if (mItem.shouldShowImage()) {
- iv.setImageResource(mItem.getImage());
- }
- TextView tv2 = (TextView)v.findViewById(R.id.whatsNewTitle);
- if (mItem.shouldShowTitleText()) {
- tv2.setText(mItem.getTitleText());
- }
- tv2 = (TextView)v.findViewById(R.id.whatsNewText);
- if (mItem.shouldShowContentText()) {
- tv2.setText(mItem.getContentText());
- }
- return v;
- }
- }
- }
|