123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- /*
- * 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.accounts.Account;
- import android.accounts.AccountManager;
- import android.content.Context;
- import android.content.Intent;
- import android.content.res.Configuration;
- import android.graphics.Color;
- import android.net.Uri;
- import android.os.Bundle;
- import android.support.v4.view.ViewPager;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import com.owncloud.android.MainApp;
- import com.owncloud.android.R;
- import com.owncloud.android.authentication.AccountUtils;
- import com.owncloud.android.authentication.AuthenticatorActivity;
- import com.owncloud.android.db.PreferenceManager;
- import com.owncloud.android.features.FeatureItem;
- import com.owncloud.android.ui.adapter.FeaturesViewAdapter;
- import com.owncloud.android.ui.whatsnew.ProgressIndicator;
- import com.owncloud.android.utils.DisplayUtils;
- /**
- * Activity displaying general feature after a fresh install.
- */
- public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageChangeListener {
- public static final String EXTRA_ALLOW_CLOSE = "ALLOW_CLOSE";
- public static final int FIRST_RUN_RESULT_CODE = 199;
- private ProgressIndicator progressIndicator;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.first_run_activity);
- boolean isProviderOrOwnInstallationVisible = getResources().getBoolean(R.bool.show_provider_or_own_installation);
- setSlideshowSize(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
- Button loginButton = findViewById(R.id.login);
- loginButton.setBackgroundColor(Color.WHITE);
- loginButton.setTextColor(Color.BLACK);
- loginButton.setOnClickListener(v -> {
- if (getIntent().getBooleanExtra(EXTRA_ALLOW_CLOSE, false)) {
- Intent authenticatorActivityIntent = new Intent(this, AuthenticatorActivity.class);
- authenticatorActivityIntent.putExtra(AuthenticatorActivity.EXTRA_USE_PROVIDER_AS_WEBLOGIN, false);
- startActivityForResult(authenticatorActivityIntent, FIRST_RUN_RESULT_CODE);
- } else {
- finish();
- }
- });
- Button providerButton = findViewById(R.id.signup);
- providerButton.setBackgroundColor(getResources().getColor(R.color.primary_dark));
- providerButton.setTextColor(getResources().getColor(R.color.login_text_color));
- providerButton.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);
- providerButton.setOnClickListener(v -> {
- Intent authenticatorActivityIntent = new Intent(this, AuthenticatorActivity.class);
- authenticatorActivityIntent.putExtra(AuthenticatorActivity.EXTRA_USE_PROVIDER_AS_WEBLOGIN, true);
- if (getIntent().getBooleanExtra(EXTRA_ALLOW_CLOSE, false)) {
- startActivityForResult(authenticatorActivityIntent, FIRST_RUN_RESULT_CODE);
- } else {
- authenticatorActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(authenticatorActivityIntent);
- }
- });
- TextView hostOwnServerTextView = findViewById(R.id.host_own_server);
- hostOwnServerTextView.setTextColor(getResources().getColor(R.color.login_text_color));
- hostOwnServerTextView.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);
- progressIndicator = findViewById(R.id.progressIndicator);
- ViewPager viewPager = findViewById(R.id.contentPanel);
- // Sometimes, accounts are not deleted when you uninstall the application so we'll do it now
- if (isFirstRun(this)) {
- AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
- if (am != null) {
- for (Account account : AccountUtils.getAccounts(this)) {
- am.removeAccount(account, null, null);
- }
- }
- }
- FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(),
- getFirstRun());
- progressIndicator.setNumberOfSteps(featuresViewAdapter.getCount());
- viewPager.setAdapter(featuresViewAdapter);
- viewPager.addOnPageChangeListener(this);
- }
- private void setSlideshowSize(boolean isLandscape) {
- boolean isProviderOrOwnInstallationVisible = getResources().getBoolean(R.bool.show_provider_or_own_installation);
- LinearLayout buttonLayout = findViewById(R.id.buttonLayout);
- LinearLayout.LayoutParams layoutParams;
- buttonLayout.setOrientation(isLandscape ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL);
- LinearLayout bottomLayout = findViewById(R.id.bottomLayout);
- if (isProviderOrOwnInstallationVisible) {
- layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- } else {
- layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- DisplayUtils.convertDpToPixel(isLandscape ? 100f : 150f, this));
- }
- bottomLayout.setLayoutParams(layoutParams);
- }
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
- setSlideshowSize(true);
- } else {
- setSlideshowSize(false);
- }
- }
- @Override
- public void onBackPressed() {
- onFinish();
- if (getIntent().getBooleanExtra(EXTRA_ALLOW_CLOSE, false)) {
- super.onBackPressed();
- }
- }
- private void onFinish() {
- PreferenceManager.setLastSeenVersionCode(this, MainApp.getVersionCode());
- }
- @Override
- protected void onStop() {
- onFinish();
- super.onStop();
- }
- private static boolean isFirstRun(Context context) {
- return AccountUtils.getCurrentOwnCloudAccount(context) == null;
- }
- public static boolean runIfNeeded(Context context) {
- boolean isProviderOrOwnInstallationVisible = context.getResources()
- .getBoolean(R.bool.show_provider_or_own_installation);
- if (!isProviderOrOwnInstallationVisible) {
- return false;
- }
- if (context instanceof FirstRunActivity) {
- return false;
- }
- if (isFirstRun(context) && context instanceof AuthenticatorActivity) {
- context.startActivity(new Intent(context, FirstRunActivity.class));
- return true;
- } else {
- return false;
- }
- }
- @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) {
- progressIndicator.animateToStep(position + 1);
- }
- @Override
- public void onPageScrollStateChanged(int state) {
- // unused but to be implemented due to abstract parent
- }
- public void onHostYourOwnServerClick(View view) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_server_install)));
- DisplayUtils.startIntentIfAppAvailable(intent, this, R.string.no_browser_available);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (FIRST_RUN_RESULT_CODE == requestCode && RESULT_OK == resultCode) {
- String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
- Account account = AccountUtils.getOwnCloudAccountByName(this, accountName);
- if (account == null) {
- DisplayUtils.showSnackMessage(this, R.string.account_creation_failed);
- return;
- }
- setAccount(account);
- AccountUtils.setCurrentOwnCloudAccount(this, account.name);
- onAccountSet(false);
- Intent i = new Intent(this, FileDisplayActivity.class);
- i.setAction(FileDisplayActivity.RESTART);
- i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(i);
- }
- }
- public static FeatureItem[] getFirstRun() {
- return new FeatureItem[]{
- new FeatureItem(R.drawable.logo, R.string.first_run_1_text, R.string.empty, true, false),
- new FeatureItem(R.drawable.first_run_files, R.string.first_run_2_text, R.string.empty, true, false),
- new FeatureItem(R.drawable.first_run_groupware, R.string.first_run_3_text, R.string.empty, true, false),
- new FeatureItem(R.drawable.first_run_talk, R.string.first_run_4_text, R.string.empty, true, false)};
- }
- }
|