diff --git a/android/app/build.gradle b/android/app/build.gradle index c63f481f8c..70f7c622a0 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -110,6 +110,10 @@ dependencies { compile 'com.squareup.retrofit2:converter-gson:2.4.0' implementation 'com.squareup.picasso:picasso:2.71828' + compile 'com.squareup.retrofit2:retrofit:2.4.0' + compile 'com.squareup.retrofit2:converter-gson:2.4.0' + implementation 'com.squareup.picasso:picasso:2.71828' + implementation fileTree(include: ['*.jar'], dir: 'libs') } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 1b6f3b1304..e105f5bccf 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -39,17 +39,10 @@ --> - - + +High Fidelity Privacy Policy +
+ +

High Fidelity, Inc. ("High Fidelity") respects the privacy of its online visitors and users of its products and services. We recognize the importance of protecting information collected from our users and have adopted this Privacy Policy to inform you about how we gather, store and use information derived from your use of our products, services and online sites in accordance with local law in the places where we operate. +By using our online sites, products, and services (collectively, the "Service"), you agree that we may collect personally identifiable information (as defined below). We will not share your personally identifiable information except as described herein. +

+1. Types of Information We Collect +

+ We collect two basic types of information - personal information and anonymous information - and we may use personal and anonymous information to create a third type of information, aggregate information. Personal Information means information that identifies (whether directly or indirectly) a particular individual, such as the individual's first and last name, postal address, e-mail address and/or telephone number. Anonymous Information means information that does not directly or indirectly identify, and cannot reasonably be used to identify, an individual (including an individual's computing device). Aggregate Information means information about groups or categories of individuals which does not identify and cannot reasonably be used to identify an individual. We may share Aggregate and Anonymous Information with other parties without restriction. + + We collect the following categories of information: + + Registration information you provide when you create an account, which may include your first name and surname, country of residence, gender, date of birth, e-mail address, username and password. + + Transaction information you provide when you request information or purchase a product or service from us, whether on our sites or through our applications, including your postal address, telephone number and payment information. If you conduct transactions, we may collect and retain some or all of the information related to these transactions, including transaction amount(s), parties involved, time and manner of exchange, and other transaction circumstances. + + Information you provide in public forums on our Service. Please note that our sites and applications may offer chat, forums, community environments (including multiplayer gameplay) or other tools that do not have a restricted audience. If you provide Personal Information when you use any of these features, that Personal Information may be publicly posted and otherwise disclosed without limitation as to its use by us or by a third party. We have no obligation to keep private personally identifiable information that you have made available to other users or the public using these functions. To request removal of your Personal Information from a public forum on one of our sites or applications, please contact Customer Support. + + Information sent either one-to-one or within a limited group using our message, chat, post or similar functionality, where we are permitted by law to collect this information. + + Information you provide to us when you use our sites and applications, our applications on third-party sites or platforms (such as social networking sites), or link your profile from a third-party site or platform to your registered account. + + Location information when you visit our sites or use our applications, including location information either provided by a mobile device interacting with one of our sites or applications, or associated with your IP address, where we are permitted by law to process this information. + + Usage, viewing and technical data, including your device identifier or IP address, when you visit our sites, use our applications on third-party sites or platforms, or open e-mails that we send. + + Additionally there are a few special circumstances to note: + + Intellectual Property Claim Notices: If you notify us of an intellectual property claim, the information in your claim notice may be shared with other parties to the disagreement or third parties in our discretion and as required by law. + + Beta Service User: If you volunteer to serve as a beta participant for our pre-commercial content, we may track bug reports and individual system performance in an effort to test our technology rigorously before it is deployed. + + Former Customer: If you discontinue your use of our Service, we may keep your registration file in our database for use in the event that you elect to renew your use of our Service, as well as for anti-fraud and other such protective measures. + + Job Postings or Unsolicited Communications: Please note that information we receive in reference to a job posting or by unsolicited communications does not fall within the terms outlined in this Privacy Policy, however information from your resume will be used solely for the purpose of evaluating your candidacy for employment. +

+ 2. How We Collect Your Information +

+ + We collect information you provide to us when you request products, services or information from us, register with us, participate in public forums or other activities on our sites and applications, respond to customer inquiries or surveys, or otherwise interact with us. + + We collect information through technology, such as cookies and other technologies (such as web beacons and pixel tags), including when you visit our sites and applications or use our applications on third-party sites or platforms. A cookie is a small string of data which often includes an anonymous unique identifier sent to your Internet browser from a website's computers, which is stored on your computer's hard drive and is used to customize your use of a product or online site, keep records of your access to an online site or product, or store information needed by you on a regular basis (e.g. password retention functionality). High Fidelity (itself or through third parties acting on our behalf) use cookies for a number of purposes relating to our websites, applications and services, including to access your account information where you "login" to our websites, forums or other areas and to keep track of your website session data. You can configure your browser to accept all cookies, reject all cookies, or notify you when a cookie is set. Each browser is different, so consult the "Help" menu of your browser to learn how you change your cookie preferences. Please note that if you reject all cookies, you may not be able to use certain of our (or other companies') web pages. + + We may participate in ad and/or affiliate networks operated by various third party companies. These companies collect and may use certain anonymous information about your visits to our Service as a function of referring Internet traffic to our Service. We do not permit these companies to collect any Personal Information about you; however these companies may collect your IP address. These companies may set and use cookies, web beacons, pixels and other technologies to collect anonymous information about your visits to our Service, and may otherwise aggregate, analyze and anonymize that data. If you would like to learn more about these specialized advertising technologies, the Network Advertising Initiative offers useful information about Internet advertising companies, including information about how to opt-out of certain information collection. + + We acquire information from other trusted sources to update or supplement the information you provided or we collected automatically. Local law may require that you authorize the third party to share your information with us before we can acquire it. +

+ 3. Use of Your Information by High Fidelity +

+ High Fidelity will be the data controller for your information, and will have access to your information for use for the following purposes (unless prohibited by law): + + Provide you with the products and services you request + + Communicate with you about your account or transactions with us and send you information about features on our sites and applications or changes to our policies + + Consistent with local law and choices and controls that may be available to you: + + Send you offers and promotions for our products and services or, as permitted, third-party products and services + + Personalize content and experiences on our sites and applications + + Provide you with advertising based on your activity on our sites and applications and on third-party sites and applications. + Optimize or improve our products, services and operations + + Detect, investigate and prevent activities that may violate our policies or be illegal + + Except under certain limited circumstances as set forth here and in our Terms of Service, High Fidelity does not disclose to third parties the Personal Information or other account-related information that you provide to us without your permission. You understand, however, that High Fidelity may disclose your Personal Information or other account-related information under the following circumstances: + + If we believe in good faith that such disclosure is necessary under applicable law, or to comply with legal process served on High Fidelity; + + In order to protect and defend the rights or interests of High Fidelity, its products and services, and/or the other users of such products and services; + + In order to report to law enforcement authorities, or assist in their investigation of suspected illegal or wrongful activity, or to report any instance in which we believe a person may be in danger; + + To service providers with whom we have contracted to assist us with the features or operations (such as anti-fraud functions, billing, collections, registration, customer support, e-mail delivery, age verification), to fulfill your service requests, offer new content or help us improve our products and/or services. + Our contracts with third parties prohibit them from using any of your Personal Information for purposes unrelated to the product or services they are providing; + + To other third parties (a) to provide you with services you have requested, (b) to offer you information about our products or services (e.g. events or features), or (c) to whom you explicitly ask us to send your information (or about whom you are otherwise explicitly notified and consent to when using a specific service). For instance, we may provide certain information to our payment processor, to credit card associations, banks or issuers (if you are using a credit card), to PayPal (if you are using a PayPal account), or to providers of other services you request. If you choose to use these third parties' products or services, then their use of your information is governed by their privacy policies. You should evaluate the practices of third party providers before deciding to use their services; and + + To other business entities, should we plan to merge with or be acquired by that business entity. +

+ + 4. Sharing Your Information with Other Companies +

+ + We will not share your Personal Information outside of High Fidelity except in limited circumstances, including: + + When you allow us to share your Personal Information with another company, such as: + + Directing us to share your Personal Information with third-party sites or platforms, such as social networking sites + Please note that once we share your Personal Information with another company, the information received by the other company becomes subject to the other company's privacy practices. + + When companies perform services on our behalf; however, these companies are prohibited from using your Personal Information for purposes other than those requested by us or required by law. + + When we share Personal Information with third parties in connection with the sale of a business, to enforce our Terms of Service or rules, to ensure the safety and security of our users and third parties, to comply with legal process or in other cases if we believe in good faith that disclosure is required by law. +

+ 5. Data Transfers, Storage and Processing Globally +

+ + We operate globally and may transfer your Personal Information to locations around the world for the purposes described in this Privacy Policy. Whenever your Personal Information is transferred, stored or processed by us, we will take reasonable steps to safeguard the privacy of your Personal Information in accordance with applicable law. +

+ 6. Changes to this Privacy Policy +

+ + From time to time, we may change this Privacy Policy to accommodate new technologies, industry practices, regulatory requirements or for other purposes. If we decide to change our privacy policy, we will post those changes to this privacy statement, and other places we deem appropriate so that you are aware of what information we collect, how we use it, and under what circumstances, if any, we disclose it. We reserve the right to modify this privacy statement at any time, so please review it frequently. If we make material changes to this policy, we will notify you here, by email, or by means of a notice on our home page. +

+ + 7. Comments and Questions +

+ + If you have a comment or question about this Privacy Policy or our privacy practices, please send an e-mail to privacy@highfidelity.com. +

+
+Notice to California Residents: +

+If you are a California resident, California Civil Code Section 1798.83 permits you to request information regarding the disclosure of your Personal Information by High Fidelity to third parties for the third parties' direct marketing purposes. With respect to these entities, this Privacy Policy applies only to their activities within the State of California. To make such a request, please send an e-mail to privacy@highfidelity.com or write us at the address listed immediately above. +

+ + \ No newline at end of file diff --git a/android/app/src/main/cpp/native.cpp b/android/app/src/main/cpp/native.cpp index 9a5d29d675..3179534b34 100644 --- a/android/app/src/main/cpp/native.cpp +++ b/android/app/src/main/cpp/native.cpp @@ -24,9 +24,9 @@ #include QAndroidJniObject __interfaceActivity; -QAndroidJniObject __loginActivity; +QAndroidJniObject __loginCompletedListener; QAndroidJniObject __loadCompleteListener; - +QAndroidJniObject __usernameChangedListener; void tempMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { if (!message.isEmpty()) { const char * local=message.toStdString().c_str(); @@ -152,9 +152,15 @@ JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnCrea unpackAndroidAssets(); qInstallMessageHandler(oldMessageHandler); - QObject::connect(&AndroidHelper::instance(), &AndroidHelper::androidActivityRequested, [](const QString& a) { + QObject::connect(&AndroidHelper::instance(), &AndroidHelper::androidActivityRequested, [](const QString& a, const bool backToScene) { QAndroidJniObject string = QAndroidJniObject::fromString(a); - __interfaceActivity.callMethod("openAndroidActivity", "(Ljava/lang/String;)V", string.object()); + jboolean jBackToScene = (jboolean) backToScene; + __interfaceActivity.callMethod("openAndroidActivity", "(Ljava/lang/String;Z)V", string.object(), jBackToScene); + }); + + QObject::connect(&AndroidHelper::instance(), &AndroidHelper::hapticFeedbackRequested, [](int duration) { + jint iDuration = (jint) duration; + __interfaceActivity.callMethod("performHapticFeedback", "(I)V", iDuration); }); } @@ -178,10 +184,6 @@ JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnResu JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeOnExitVr(JNIEnv* env, jobject obj) { } -JNIEXPORT void Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeGoBackFromAndroidActivity(JNIEnv *env, jobject instance) { - AndroidHelper::instance().goBackFromAndroidActivity(); -} - // HifiUtils JNIEXPORT jstring JNICALL Java_io_highfidelity_hifiinterface_HifiUtils_getCurrentAddress(JNIEnv *env, jobject instance) { QSharedPointer addressManager = DependencyManager::get(); @@ -209,8 +211,9 @@ JNIEXPORT jstring JNICALL Java_io_highfidelity_hifiinterface_HifiUtils_protocolV } JNIEXPORT void JNICALL -Java_io_highfidelity_hifiinterface_LoginActivity_nativeLogin(JNIEnv *env, jobject instance, - jstring username_, jstring password_) { +Java_io_highfidelity_hifiinterface_fragment_LoginFragment_nativeLogin(JNIEnv *env, jobject instance, + jstring username_, jstring password_, + jobject usernameChangedListener) { const char *c_username = env->GetStringUTFChars(username_, 0); const char *c_password = env->GetStringUTFChars(password_, 0); QString username = QString(c_username); @@ -220,19 +223,26 @@ Java_io_highfidelity_hifiinterface_LoginActivity_nativeLogin(JNIEnv *env, jobjec auto accountManager = AndroidHelper::instance().getAccountManager(); - __loginActivity = QAndroidJniObject(instance); + __loginCompletedListener = QAndroidJniObject(instance); + __usernameChangedListener = QAndroidJniObject(usernameChangedListener); QObject::connect(accountManager.data(), &AccountManager::loginComplete, [](const QUrl& authURL) { jboolean jSuccess = (jboolean) true; - __loginActivity.callMethod("handleLoginCompleted", "(Z)V", jSuccess); + __loginCompletedListener.callMethod("handleLoginCompleted", "(Z)V", jSuccess); }); QObject::connect(accountManager.data(), &AccountManager::loginFailed, []() { jboolean jSuccess = (jboolean) false; - __loginActivity.callMethod("handleLoginCompleted", "(Z)V", jSuccess); + __loginCompletedListener.callMethod("handleLoginCompleted", "(Z)V", jSuccess); }); - QMetaObject::invokeMethod(accountManager.data(), "requestAccessToken", Q_ARG(const QString&, username), Q_ARG(const QString&, password)); + QObject::connect(accountManager.data(), &AccountManager::usernameChanged, [](const QString& username) { + QAndroidJniObject string = QAndroidJniObject::fromString(username); + __usernameChangedListener.callMethod("handleUsernameChanged", "(Ljava/lang/String;)V", string.object()); + }); + + QMetaObject::invokeMethod(accountManager.data(), "requestAccessToken", + Q_ARG(const QString&, username), Q_ARG(const QString&, password)); } JNIEXPORT void JNICALL @@ -252,20 +262,30 @@ Java_io_highfidelity_hifiinterface_SplashActivity_registerLoadCompleteListener(J } JNIEXPORT jboolean JNICALL -Java_io_highfidelity_hifiinterface_HomeActivity_nativeIsLoggedIn(JNIEnv *env, jobject instance) { +Java_io_highfidelity_hifiinterface_MainActivity_nativeIsLoggedIn(JNIEnv *env, jobject instance) { return AndroidHelper::instance().getAccountManager()->isLoggedIn(); } JNIEXPORT void JNICALL -Java_io_highfidelity_hifiinterface_HomeActivity_nativeLogout(JNIEnv *env, jobject instance) { +Java_io_highfidelity_hifiinterface_MainActivity_nativeLogout(JNIEnv *env, jobject instance) { AndroidHelper::instance().getAccountManager()->logout(); } JNIEXPORT jstring JNICALL -Java_io_highfidelity_hifiinterface_HomeActivity_nativeGetDisplayName(JNIEnv *env, +Java_io_highfidelity_hifiinterface_MainActivity_nativeGetDisplayName(JNIEnv *env, jobject instance) { QString username = AndroidHelper::instance().getAccountManager()->getAccountInfo().getUsername(); return env->NewStringUTF(username.toLatin1().data()); } +JNIEXPORT void JNICALL +Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeEnterBackground(JNIEnv *env, jobject obj) { + AndroidHelper::instance().notifyEnterBackground(); +} + +JNIEXPORT void JNICALL +Java_io_highfidelity_hifiinterface_InterfaceActivity_nativeEnterForeground(JNIEnv *env, jobject obj) { + AndroidHelper::instance().notifyEnterForeground(); +} + } diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/GotoActivity.java b/android/app/src/main/java/io/highfidelity/hifiinterface/GotoActivity.java deleted file mode 100644 index 125483da94..0000000000 --- a/android/app/src/main/java/io/highfidelity/hifiinterface/GotoActivity.java +++ /dev/null @@ -1,82 +0,0 @@ -package io.highfidelity.hifiinterface; - -import android.content.Intent; -import android.os.Bundle; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.AppCompatButton; -import android.support.v7.widget.Toolbar; -import android.view.KeyEvent; -import android.view.MenuItem; -import android.view.View; -import android.widget.EditText; - -public class GotoActivity extends AppCompatActivity { - - public static final String PARAM_DOMAIN_URL = "domain_url"; - - private EditText mUrlEditText; - private AppCompatButton mGoBtn; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_goto); - - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - toolbar.setTitleTextAppearance(this, R.style.HomeActionBarTitleStyle); - setSupportActionBar(toolbar); - - ActionBar actionbar = getSupportActionBar(); - actionbar.setDisplayHomeAsUpEnabled(true); - - mUrlEditText = (EditText) findViewById(R.id.url_text); - mUrlEditText.setOnKeyListener(new View.OnKeyListener() { - @Override - public boolean onKey(View view, int i, KeyEvent keyEvent) { - if (i == KeyEvent.KEYCODE_ENTER) { - actionGo(); - return true; - } - return false; - } - }); - - mUrlEditText.setText(HifiUtils.getInstance().getCurrentAddress()); - - mGoBtn = (AppCompatButton) findViewById(R.id.go_btn); - - mGoBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - actionGo(); - } - }); - } - - private void actionGo() { - String urlString = mUrlEditText.getText().toString(); - if (!urlString.trim().isEmpty()) { - urlString = HifiUtils.getInstance().sanitizeHifiUrl(urlString); - - Intent intent = new Intent(); - intent.putExtra(GotoActivity.PARAM_DOMAIN_URL, urlString); - setResult(RESULT_OK, intent); - finish(); - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - switch (id) { - case android.R.id.home: - finish(); - return true; - } - return super.onOptionsItemSelected(item); - } -} diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/HifiUtils.java b/android/app/src/main/java/io/highfidelity/hifiinterface/HifiUtils.java index 368862bc49..f92cd0a385 100644 --- a/android/app/src/main/java/io/highfidelity/hifiinterface/HifiUtils.java +++ b/android/app/src/main/java/io/highfidelity/hifiinterface/HifiUtils.java @@ -9,7 +9,7 @@ import java.net.URISyntaxException; public class HifiUtils { - public static final String BASE_URL = "https://metaverse.highfidelity.com"; + public static final String METAVERSE_BASE_URL = "https://metaverse.highfidelity.com"; private static HifiUtils instance; @@ -39,7 +39,12 @@ public class HifiUtils { return urlString; } + public String absoluteHifiAssetUrl(String urlString) { + return absoluteHifiAssetUrl(urlString, METAVERSE_BASE_URL); + } + + public String absoluteHifiAssetUrl(String urlString, String baseUrl) { urlString = urlString.trim(); if (!urlString.isEmpty()) { URI uri; @@ -49,7 +54,7 @@ public class HifiUtils { return urlString; } if (uri.getScheme() == null || uri.getScheme().isEmpty()) { - urlString = BASE_URL + urlString; + urlString = baseUrl + urlString; } } return urlString; diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/HomeActivity.java b/android/app/src/main/java/io/highfidelity/hifiinterface/HomeActivity.java deleted file mode 100644 index 62e487f8b7..0000000000 --- a/android/app/src/main/java/io/highfidelity/hifiinterface/HomeActivity.java +++ /dev/null @@ -1,245 +0,0 @@ -package io.highfidelity.hifiinterface; - -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import android.support.annotation.NonNull; -import android.support.design.widget.NavigationView; -import android.support.v4.content.ContextCompat; -import android.support.v4.view.GravityCompat; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.KeyEvent; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.TextView; - -import org.qtproject.qt5.android.bindings.QtActivity; - -import io.highfidelity.hifiinterface.view.DomainAdapter; - -public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { - - public native boolean nativeIsLoggedIn(); - public native void nativeLogout(); - public native String nativeGetDisplayName(); - - /** - * Set this intent extra param to NOT start a new InterfaceActivity after a domain is selected" - */ - //public static final String PARAM_NOT_START_INTERFACE_ACTIVITY = "not_start_interface_activity"; - - public static final int ENTER_DOMAIN_URL = 1; - - private DomainAdapter mDomainAdapter; - private DrawerLayout mDrawerLayout; - private NavigationView mNavigationView; - private RecyclerView mDomainsView; - private TextView searchNoResultsView; - private ImageView mSearchIconView; - private ImageView mClearSearch; - private EditText mSearchView; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_home); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - toolbar.setTitleTextAppearance(this, R.style.HomeActionBarTitleStyle); - setSupportActionBar(toolbar); - - ActionBar actionbar = getSupportActionBar(); - actionbar.setDisplayHomeAsUpEnabled(true); - actionbar.setHomeAsUpIndicator(R.drawable.ic_menu); - - mDrawerLayout = findViewById(R.id.drawer_layout); - - mNavigationView = (NavigationView) findViewById(R.id.nav_view); - mNavigationView.setNavigationItemSelectedListener(this); - - searchNoResultsView = findViewById(R.id.searchNoResultsView); - - mDomainsView = findViewById(R.id.rvDomains); - int numberOfColumns = 1; - GridLayoutManager gridLayoutMgr = new GridLayoutManager(this, numberOfColumns); - mDomainsView.setLayoutManager(gridLayoutMgr); - mDomainAdapter = new DomainAdapter(this, HifiUtils.getInstance().protocolVersionSignature()); - mDomainAdapter.setClickListener(new DomainAdapter.ItemClickListener() { - - @Override - public void onItemClick(View view, int position, DomainAdapter.Domain domain) { - new Handler(getMainLooper()).postDelayed(new Runnable() { - @Override - public void run() { - gotoDomain(domain.url); - } - }, 400); // a delay so the ripple effect can be seen - } - }); - mDomainAdapter.setListener(new DomainAdapter.AdapterListener() { - @Override - public void onEmptyAdapter() { - searchNoResultsView.setText(R.string.search_no_results); - searchNoResultsView.setVisibility(View.VISIBLE); - mDomainsView.setVisibility(View.GONE); - } - - @Override - public void onNonEmptyAdapter() { - searchNoResultsView.setVisibility(View.GONE); - mDomainsView.setVisibility(View.VISIBLE); - } - - @Override - public void onError(Exception e, String message) { - - } - }); - mDomainsView.setAdapter(mDomainAdapter); - - mSearchView = findViewById(R.id.searchView); - mSearchIconView = findViewById(R.id.search_mag_icon); - mClearSearch = findViewById(R.id.search_clear); - - mSearchView.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - - @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} - - @Override - public void afterTextChanged(Editable editable) { - mDomainAdapter.loadDomains(editable.toString()); - if (editable.length() > 0) { - mSearchIconView.setVisibility(View.GONE); - mClearSearch.setVisibility(View.VISIBLE); - } else { - mSearchIconView.setVisibility(View.VISIBLE); - mClearSearch.setVisibility(View.GONE); - } - } - }); - mSearchView.setOnKeyListener((view, i, keyEvent) -> { - if (i == KeyEvent.KEYCODE_ENTER) { - String urlString = mSearchView.getText().toString(); - if (!urlString.trim().isEmpty()) { - urlString = HifiUtils.getInstance().sanitizeHifiUrl(urlString); - } - gotoDomain(urlString); - return true; - } - return false; - }); - - getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); - - updateLoginMenu(); - - Window window = getWindow(); - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.setStatusBarColor(ContextCompat.getColor(this, R.color.statusbar_color)); - } - - private void updateLoginMenu() { - TextView loginOption = findViewById(R.id.login); - TextView logoutOption = findViewById(R.id.logout); - if (nativeIsLoggedIn()) { - loginOption.setVisibility(View.GONE); - logoutOption.setVisibility(View.VISIBLE); - } else { - loginOption.setVisibility(View.VISIBLE); - logoutOption.setVisibility(View.GONE); - } - } - - private void gotoDomain(String domainUrl) { - Intent intent = new Intent(HomeActivity.this, InterfaceActivity.class); - intent.putExtra(InterfaceActivity.DOMAIN_URL, domainUrl); - HomeActivity.this.finish(); - intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); - startActivity(intent); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - //getMenuInflater().inflate(R.menu.menu_home, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - switch (id) { - case android.R.id.home: - mDrawerLayout.openDrawer(GravityCompat.START); - return true; - } - - return super.onOptionsItemSelected(item); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - } - - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - switch(item.getItemId()) { - case R.id.action_goto: - Intent i = new Intent(this, GotoActivity.class); - startActivityForResult(i, ENTER_DOMAIN_URL); - return true; - } - return false; - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == ENTER_DOMAIN_URL && resultCode == RESULT_OK) { - gotoDomain(data.getStringExtra(GotoActivity.PARAM_DOMAIN_URL)); - } - } - - @Override - protected void onStart() { - super.onStart(); - updateLoginMenu(); - } - - public void onLoginClicked(View view) { - Intent intent = new Intent(this, LoginActivity.class); - startActivity(intent); - } - - public void onLogoutClicked(View view) { - nativeLogout(); - updateLoginMenu(); - } - @Override - public void onBackPressed() { - finishAffinity(); - } - - public void onSearchClear(View view) { - mSearchView.setText(""); - } -} diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/InterfaceActivity.java b/android/app/src/main/java/io/highfidelity/hifiinterface/InterfaceActivity.java index 419ba8c45e..2165339918 100644 --- a/android/app/src/main/java/io/highfidelity/hifiinterface/InterfaceActivity.java +++ b/android/app/src/main/java/io/highfidelity/hifiinterface/InterfaceActivity.java @@ -15,6 +15,9 @@ import android.content.Intent; import android.content.res.AssetManager; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; +import android.os.Vibrator; +import android.view.HapticFeedbackConstants; import android.view.WindowManager; import android.util.Log; import org.qtproject.qt5.android.bindings.QtActivity; @@ -33,16 +36,14 @@ public class InterfaceActivity extends QtActivity { public static final String DOMAIN_URL = "url"; private static final String TAG = "Interface"; + private Vibrator mVibrator; //public static native void handleHifiURL(String hifiURLString); private native long nativeOnCreate(InterfaceActivity instance, AssetManager assetManager); private native void nativeOnDestroy(); private native void nativeGotoUrl(String url); - private native void nativeGoBackFromAndroidActivity(); private native void nativeEnterBackground(); private native void nativeEnterForeground(); - //private native void saveRealScreenSize(int width, int height); - //private native void setAppVersion(String version); private native long nativeOnExitVr(); private AssetManager assetManager; @@ -89,7 +90,6 @@ public class InterfaceActivity extends QtActivity { Point size = new Point(); getWindowManager().getDefaultDisplay().getRealSize(size); -// saveRealScreenSize(size.x, size.y); try { PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0); @@ -102,17 +102,13 @@ public class InterfaceActivity extends QtActivity { final View rootView = getWindow().getDecorView().findViewById(android.R.id.content); // This is a workaround to hide the menu bar when the virtual keyboard is shown from Qt - rootView.getViewTreeObserver().addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - int heightDiff = rootView.getRootView().getHeight() - rootView.getHeight(); - if (getActionBar().isShowing()) { - getActionBar().hide(); - } + rootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> { + if (getActionBar() != null && getActionBar().isShowing()) { + getActionBar().hide(); } }); startActivity(new Intent(this, SplashActivity.class)); - + mVibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE); } @Override @@ -195,13 +191,16 @@ public class InterfaceActivity extends QtActivity { if (intent.hasExtra(DOMAIN_URL)) { nativeGotoUrl(intent.getStringExtra(DOMAIN_URL)); } - nativeGoBackFromAndroidActivity(); } - public void openAndroidActivity(String activityName) { + public void openAndroidActivity(String activityName, boolean backToScene) { switch (activityName) { - case "Home": { - Intent intent = new Intent(this, HomeActivity.class); + case "Home": + case "Privacy Policy": + case "Login": { + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_FRAGMENT, activityName); + intent.putExtra(MainActivity.EXTRA_BACK_TO_SCENE, backToScene); startActivity(intent); break; } @@ -216,8 +215,14 @@ public class InterfaceActivity extends QtActivity { super.isLoading = false; } + public void performHapticFeedback(int duration) { + if (duration > 0) { + mVibrator.vibrate(duration); + } + } + @Override public void onBackPressed() { - openAndroidActivity("Home"); + openAndroidActivity("Home", false); } -} \ No newline at end of file +} diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/LoginActivity.java b/android/app/src/main/java/io/highfidelity/hifiinterface/LoginActivity.java deleted file mode 100644 index 9fd256aa82..0000000000 --- a/android/app/src/main/java/io/highfidelity/hifiinterface/LoginActivity.java +++ /dev/null @@ -1,106 +0,0 @@ -package io.highfidelity.hifiinterface; - -import android.app.ProgressDialog; -import android.support.annotation.MainThread; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.util.Log; -import android.view.KeyEvent; -import android.view.View; -import android.view.inputmethod.EditorInfo; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; -import android.widget.Toast; - -public class LoginActivity extends AppCompatActivity { - - public native void nativeLogin(String username, String password); - - private EditText mUsername; - private EditText mPassword; - private TextView mError; - private Button mLoginButton; - - private ProgressDialog mDialog; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_login); - - mUsername = findViewById(R.id.username); - mPassword = findViewById(R.id.password); - mError = findViewById(R.id.error); - mLoginButton = findViewById(R.id.loginButton); - - mPassword.setOnEditorActionListener( - new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { - if (actionId == EditorInfo.IME_ACTION_DONE) { - mLoginButton.performClick(); - return true; - } - return false; - } - }); - - } - - @Override - protected void onStop() { - super.onStop(); - cancelActivityIndicator(); - } - - public void login(View view) { - String username = mUsername.getText().toString(); - String password = mPassword.getText().toString(); - if (username.isEmpty() || password.isEmpty()) { - showError(getString(R.string.login_username_or_password_incorrect)); - } else { - mLoginButton.setEnabled(false); - hideError(); - showActivityIndicator(); - nativeLogin(username, password); - } - } - - private void showActivityIndicator() { - if (mDialog == null) { - mDialog = new ProgressDialog(this); - } - mDialog.setMessage(getString(R.string.logging_in)); - mDialog.setCancelable(false); - mDialog.show(); - } - - private void cancelActivityIndicator() { - if (mDialog != null) { - mDialog.cancel(); - } - } - private void showError(String error) { - mError.setText(error); - mError.setVisibility(View.VISIBLE); - } - - private void hideError() { - mError.setText(""); - mError.setVisibility(View.INVISIBLE); - } - - public void handleLoginCompleted(boolean success) { - runOnUiThread(() -> { - mLoginButton.setEnabled(true); - cancelActivityIndicator(); - if (success) { - finish(); - } else { - showError(getString(R.string.login_username_or_password_incorrect)); - } - }); - } - -} diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/MainActivity.java b/android/app/src/main/java/io/highfidelity/hifiinterface/MainActivity.java new file mode 100644 index 0000000000..54161f60c6 --- /dev/null +++ b/android/app/src/main/java/io/highfidelity/hifiinterface/MainActivity.java @@ -0,0 +1,310 @@ +package io.highfidelity.hifiinterface; + +import android.app.Fragment; +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.design.widget.NavigationView; +import android.support.v4.content.ContextCompat; +import android.support.v4.graphics.drawable.RoundedBitmapDrawable; +import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; + +import com.squareup.picasso.Callback; +import com.squareup.picasso.Picasso; + +import io.highfidelity.hifiinterface.fragment.HomeFragment; +import io.highfidelity.hifiinterface.fragment.LoginFragment; +import io.highfidelity.hifiinterface.fragment.PolicyFragment; +import io.highfidelity.hifiinterface.task.DownloadProfileImageTask; + +public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, + LoginFragment.OnLoginInteractionListener, + HomeFragment.OnHomeInteractionListener { + + private static final int PROFILE_PICTURE_PLACEHOLDER = R.drawable.default_profile_avatar; + public static final String DEFAULT_FRAGMENT = "Home"; + public static final String EXTRA_FRAGMENT = "fragment"; + public static final String EXTRA_BACK_TO_SCENE = "backToScene"; + + private String TAG = "HighFidelity"; + + public native boolean nativeIsLoggedIn(); + public native void nativeLogout(); + public native String nativeGetDisplayName(); + + private DrawerLayout mDrawerLayout; + private NavigationView mNavigationView; + private ImageView mProfilePicture; + private TextView mDisplayName; + private View mLoginPanel; + private View mProfilePanel; + private TextView mLogoutOption; + + private boolean backToScene; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mNavigationView = findViewById(R.id.nav_view); + mNavigationView.setNavigationItemSelectedListener(this); + + mLoginPanel = mNavigationView.getHeaderView(0).findViewById(R.id.loginPanel); + mProfilePanel = mNavigationView.getHeaderView(0).findViewById(R.id.profilePanel); + + mLogoutOption = mNavigationView.findViewById(R.id.logout); + + mDisplayName = mNavigationView.getHeaderView(0).findViewById(R.id.displayName); + mProfilePicture = mNavigationView.getHeaderView(0).findViewById(R.id.profilePicture); + + Toolbar toolbar = findViewById(R.id.toolbar); + toolbar.setTitleTextAppearance(this, R.style.HomeActionBarTitleStyle); + setSupportActionBar(toolbar); + + ActionBar actionbar = getSupportActionBar(); + actionbar.setDisplayHomeAsUpEnabled(true); + actionbar.setHomeAsUpIndicator(R.drawable.ic_menu); + + mDrawerLayout = findViewById(R.id.drawer_layout); + + Window window = getWindow(); + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(ContextCompat.getColor(this, R.color.statusbar_color)); + + if (getIntent() != null) { + if (getIntent().hasExtra(EXTRA_FRAGMENT)) { + loadFragment(getIntent().getStringExtra(EXTRA_FRAGMENT)); + } else { + loadFragment(DEFAULT_FRAGMENT); + } + + if (getIntent().hasExtra(EXTRA_BACK_TO_SCENE)) { + backToScene = getIntent().getBooleanExtra(EXTRA_BACK_TO_SCENE, false); + } + } + } + + private void loadFragment(String fragment) { + switch (fragment) { + case "Login": + loadLoginFragment(); + break; + case "Home": + loadHomeFragment(); + break; + case "Privacy Policy": + loadPrivacyPolicyFragment(); + break; + default: + Log.e(TAG, "Unknown fragment " + fragment); + } + + } + + private void loadHomeFragment() { + Fragment fragment = HomeFragment.newInstance(); + loadFragment(fragment, getString(R.string.home), false); + } + + private void loadLoginFragment() { + Fragment fragment = LoginFragment.newInstance(); + + loadFragment(fragment, getString(R.string.login), true); + } + + private void loadPrivacyPolicyFragment() { + Fragment fragment = PolicyFragment.newInstance(); + + loadFragment(fragment, getString(R.string.privacyPolicy), true); + } + + private void loadFragment(Fragment fragment, String title, boolean addToBackStack) { + FragmentManager fragmentManager = getFragmentManager(); + FragmentTransaction ft = fragmentManager.beginTransaction(); + ft.replace(R.id.content_frame, fragment); + if (addToBackStack) { + ft.addToBackStack(null); + } + ft.commit(); + setTitle(title); + mDrawerLayout.closeDrawer(mNavigationView); + } + + + private void updateLoginMenu() { + if (nativeIsLoggedIn()) { + mLoginPanel.setVisibility(View.GONE); + mProfilePanel.setVisibility(View.VISIBLE); + mLogoutOption.setVisibility(View.VISIBLE); + updateProfileHeader(); + } else { + mLoginPanel.setVisibility(View.VISIBLE); + mProfilePanel.setVisibility(View.GONE); + mLogoutOption.setVisibility(View.GONE); + mDisplayName.setText(""); + } + } + + private void updateProfileHeader() { + updateProfileHeader(nativeGetDisplayName()); + } + private void updateProfileHeader(String username) { + if (!username.isEmpty()) { + mDisplayName.setText(username); + updateProfilePicture(username); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + //getMenuInflater().inflate(R.menu.menu_navigation, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + switch (id) { + case android.R.id.home: + mDrawerLayout.openDrawer(GravityCompat.START); + return true; + } + + return super.onOptionsItemSelected(item); + } + + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + switch(item.getItemId()) { + case R.id.action_home: + loadHomeFragment(); + return true; + } + return false; + } + + @Override + protected void onStart() { + super.onStart(); + updateLoginMenu(); + } + + public void onLoginClicked(View view) { + loadLoginFragment(); + } + + public void onLogoutClicked(View view) { + nativeLogout(); + updateLoginMenu(); + } + + public void onSelectedDomain(String domainUrl) { + goToDomain(domainUrl); + } + + private void goToLastLocation() { + goToDomain(""); + } + + private void goToDomain(String domainUrl) { + Intent intent = new Intent(this, InterfaceActivity.class); + intent.putExtra(InterfaceActivity.DOMAIN_URL, domainUrl); + finish(); + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + startActivity(intent); + } + + @Override + public void onLoginCompleted() { + loadHomeFragment(); + updateLoginMenu(); + if (backToScene) { + backToScene = false; + goToLastLocation(); + } + } + + public void handleUsernameChanged(String username) { + runOnUiThread(() -> updateProfileHeader(username)); + } + + /** + * This is a temporary way to get the profile picture URL + * TODO: this should be get from an API (at the moment there is no one for this) + */ + private void updateProfilePicture(String username) { + mProfilePicture.setImageResource(PROFILE_PICTURE_PLACEHOLDER); + new DownloadProfileImageTask(url -> { if (url != null && !url.isEmpty()) { + Picasso.get().load(url).into(mProfilePicture, new RoundProfilePictureCallback()); + } } ).execute(username); + } + + public void onPrivacyPolicyClicked(View view) { + loadPrivacyPolicyFragment(); + } + + private class RoundProfilePictureCallback implements Callback { + @Override + public void onSuccess() { + Bitmap imageBitmap = ((BitmapDrawable) mProfilePicture.getDrawable()).getBitmap(); + RoundedBitmapDrawable imageDrawable = RoundedBitmapDrawableFactory.create(getResources(), imageBitmap); + imageDrawable.setCircular(true); + imageDrawable.setCornerRadius(Math.max(imageBitmap.getWidth(), imageBitmap.getHeight()) / 2.0f); + mProfilePicture.setImageDrawable(imageDrawable); + } + + @Override + public void onError(Exception e) { + mProfilePicture.setImageResource(PROFILE_PICTURE_PLACEHOLDER); + } + } + + @Override + public void onBackPressed() { + int index = getFragmentManager().getBackStackEntryCount() - 1; + if (index > -1) { + super.onBackPressed(); + if (backToScene) { + backToScene = false; + goToLastLocation(); + } + } else { + finishAffinity(); + } + } + + @Override + public void onSaveInstanceState(Bundle savedInstanceState) { + super.onSaveInstanceState(savedInstanceState); + savedInstanceState.putBoolean(EXTRA_BACK_TO_SCENE, backToScene); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + backToScene = savedInstanceState.getBoolean(EXTRA_BACK_TO_SCENE, false); + } +} diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/SplashActivity.java b/android/app/src/main/java/io/highfidelity/hifiinterface/SplashActivity.java index 122884b6be..e0aa967aaa 100644 --- a/android/app/src/main/java/io/highfidelity/hifiinterface/SplashActivity.java +++ b/android/app/src/main/java/io/highfidelity/hifiinterface/SplashActivity.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; +import android.view.View; public class SplashActivity extends Activity { @@ -21,13 +22,22 @@ public class SplashActivity extends Activity { super.onStart(); } + @Override + protected void onResume() { + super.onResume(); + View decorView = getWindow().getDecorView(); + // Hide the status bar. + int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + decorView.setSystemUiVisibility(uiOptions); + } + @Override protected void onStop() { super.onStop(); } public void onAppLoadedComplete() { - startActivity(new Intent(this, HomeActivity.class)); // + 2 sec + startActivity(new Intent(this, MainActivity.class)); SplashActivity.this.finish(); } } diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/fragment/HomeFragment.java b/android/app/src/main/java/io/highfidelity/hifiinterface/fragment/HomeFragment.java new file mode 100644 index 0000000000..606dbca123 --- /dev/null +++ b/android/app/src/main/java/io/highfidelity/hifiinterface/fragment/HomeFragment.java @@ -0,0 +1,156 @@ +package io.highfidelity.hifiinterface.fragment; + +import android.app.Fragment; +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; + +import io.highfidelity.hifiinterface.HifiUtils; +import io.highfidelity.hifiinterface.R; +import io.highfidelity.hifiinterface.view.DomainAdapter; + +public class HomeFragment extends Fragment { + + private DomainAdapter mDomainAdapter; + private RecyclerView mDomainsView; + private TextView searchNoResultsView; + private ImageView mSearchIconView; + private ImageView mClearSearch; + private EditText mSearchView; + + + private OnHomeInteractionListener mListener; + + public HomeFragment() { + // Required empty public constructor + } + + public static HomeFragment newInstance() { + HomeFragment fragment = new HomeFragment(); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_home, container, false); + + searchNoResultsView = rootView.findViewById(R.id.searchNoResultsView); + + mDomainsView = rootView.findViewById(R.id.rvDomains); + int numberOfColumns = 1; + GridLayoutManager gridLayoutMgr = new GridLayoutManager(getContext(), numberOfColumns); + mDomainsView.setLayoutManager(gridLayoutMgr); + mDomainAdapter = new DomainAdapter(getContext(), HifiUtils.getInstance().protocolVersionSignature()); + mDomainAdapter.setClickListener((view, position, domain) -> { + new Handler(getActivity().getMainLooper()).postDelayed(() -> mListener.onSelectedDomain(domain.url), 400); // a delay so the ripple effect can be seen + }); + mDomainAdapter.setListener(new DomainAdapter.AdapterListener() { + @Override + public void onEmptyAdapter() { + searchNoResultsView.setText(R.string.search_no_results); + searchNoResultsView.setVisibility(View.VISIBLE); + mDomainsView.setVisibility(View.GONE); + } + + @Override + public void onNonEmptyAdapter() { + searchNoResultsView.setVisibility(View.GONE); + mDomainsView.setVisibility(View.VISIBLE); + } + + @Override + public void onError(Exception e, String message) { + + } + }); + mDomainsView.setAdapter(mDomainAdapter); + + mSearchView = rootView.findViewById(R.id.searchView); + mSearchIconView = rootView.findViewById(R.id.search_mag_icon); + mClearSearch = rootView.findViewById(R.id.search_clear); + + mSearchView.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {} + + @Override + public void afterTextChanged(Editable editable) { + mDomainAdapter.loadDomains(editable.toString()); + if (editable.length() > 0) { + mSearchIconView.setVisibility(View.GONE); + mClearSearch.setVisibility(View.VISIBLE); + } else { + mSearchIconView.setVisibility(View.VISIBLE); + mClearSearch.setVisibility(View.GONE); + } + } + }); + mSearchView.setOnKeyListener((view, i, keyEvent) -> { + if (i == KeyEvent.KEYCODE_ENTER) { + String urlString = mSearchView.getText().toString(); + if (!urlString.trim().isEmpty()) { + urlString = HifiUtils.getInstance().sanitizeHifiUrl(urlString); + } + mListener.onSelectedDomain(urlString); + return true; + } + return false; + }); + + mClearSearch.setOnClickListener(view -> onSearchClear(view)); + + getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + + return rootView; + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnHomeInteractionListener) { + mListener = (OnHomeInteractionListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnHomeInteractionListener"); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + public interface OnHomeInteractionListener { + void onSelectedDomain(String domainUrl); + } + + public void onSearchClear(View view) { + mSearchView.setText(""); + } + + +} diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/fragment/LoginFragment.java b/android/app/src/main/java/io/highfidelity/hifiinterface/fragment/LoginFragment.java new file mode 100644 index 0000000000..f29c237ed7 --- /dev/null +++ b/android/app/src/main/java/io/highfidelity/hifiinterface/fragment/LoginFragment.java @@ -0,0 +1,205 @@ +package io.highfidelity.hifiinterface.fragment; + +import android.app.Activity; +import android.app.Fragment; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import io.highfidelity.hifiinterface.R; + +public class LoginFragment extends Fragment { + + private EditText mUsername; + private EditText mPassword; + private TextView mError; + private TextView mForgotPassword; + private Button mLoginButton; + + private ProgressDialog mDialog; + + public native void nativeLogin(String username, String password, Activity usernameChangedListener); + + private LoginFragment.OnLoginInteractionListener mListener; + + public LoginFragment() { + // Required empty public constructor + } + + public static LoginFragment newInstance() { + LoginFragment fragment = new LoginFragment(); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_login, container, false); + + mUsername = rootView.findViewById(R.id.username); + mPassword = rootView.findViewById(R.id.password); + mError = rootView.findViewById(R.id.error); + mLoginButton = rootView.findViewById(R.id.loginButton); + mForgotPassword = rootView.findViewById(R.id.forgotPassword); + + mUsername.addTextChangedListener(new TextWatcher() { + boolean ignoreNextChange = false; + boolean hadBlankSpace = false; + @Override + public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) { + hadBlankSpace = charSequence.length() > 0 && charSequence.charAt(charSequence.length()-1) == ' '; + } + + @Override + public void onTextChanged(CharSequence charSequence, int start, int count, int after) { + + } + + @Override + public void afterTextChanged(Editable editable) { + if (!ignoreNextChange) { + ignoreNextChange = true; + boolean spaceFound = false; + for (int i = 0; i < editable.length(); i++) { + if (editable.charAt(i) == ' ') { + spaceFound=true; + editable.delete(i, i + 1); + i--; + } + } + + if (hadBlankSpace && !spaceFound && editable.length() > 0) { + editable.delete(editable.length()-1, editable.length()); + } + + editable.append(' '); + ignoreNextChange = false; + } + + } + }); + + + mLoginButton.setOnClickListener(view -> login()); + + mForgotPassword.setOnClickListener(view -> forgotPassword()); + + mPassword.setOnEditorActionListener( + (textView, actionId, keyEvent) -> { + if (actionId == EditorInfo.IME_ACTION_DONE) { + mLoginButton.performClick(); + return true; + } + return false; + }); + return rootView; + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnLoginInteractionListener) { + mListener = (OnLoginInteractionListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnLoginInteractionListener"); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + @Override + public void onStop() { + super.onStop(); + cancelActivityIndicator(); + hideKeyboard(); + } + + public void login() { + String username = mUsername.getText().toString().trim(); + String password = mPassword.getText().toString(); + hideKeyboard(); + if (username.isEmpty() || password.isEmpty()) { + showError(getString(R.string.login_username_or_password_incorrect)); + } else { + mLoginButton.setEnabled(false); + hideError(); + showActivityIndicator(); + nativeLogin(username, password, getActivity()); + } + } + + private void hideKeyboard() { + View view = getActivity().getCurrentFocus(); + if (view != null) { + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + + private void forgotPassword() { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://highfidelity.com/users/password/new")); + startActivity(intent); + } + + private void showActivityIndicator() { + if (mDialog == null) { + mDialog = new ProgressDialog(getContext()); + } + mDialog.setMessage(getString(R.string.logging_in)); + mDialog.setCancelable(false); + mDialog.show(); + } + + private void cancelActivityIndicator() { + if (mDialog != null) { + mDialog.cancel(); + } + } + private void showError(String error) { + mError.setText(error); + mError.setVisibility(View.VISIBLE); + } + + private void hideError() { + mError.setText(""); + mError.setVisibility(View.INVISIBLE); + } + + public void handleLoginCompleted(boolean success) { + Log.d("[LOGIN]", "handleLoginCompleted " + success); + getActivity().runOnUiThread(() -> { + mLoginButton.setEnabled(true); + cancelActivityIndicator(); + if (success) { + if (mListener != null) { + mListener.onLoginCompleted(); + } + } else { + showError(getString(R.string.login_username_or_password_incorrect)); + } + }); + } + + public interface OnLoginInteractionListener { + void onLoginCompleted(); + } + +} diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/fragment/PolicyFragment.java b/android/app/src/main/java/io/highfidelity/hifiinterface/fragment/PolicyFragment.java new file mode 100644 index 0000000000..cd9aec244a --- /dev/null +++ b/android/app/src/main/java/io/highfidelity/hifiinterface/fragment/PolicyFragment.java @@ -0,0 +1,60 @@ +package io.highfidelity.hifiinterface.fragment; + +import android.app.Fragment; +import android.os.Bundle; +import android.text.Html; +import android.text.Spanned; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import java.io.IOException; +import java.io.InputStream; + +import io.highfidelity.hifiinterface.R; + +public class PolicyFragment extends Fragment { + + private static final String POLICY_FILE = "privacy_policy.html"; + + public PolicyFragment() { + // Required empty public constructor + } + + public static PolicyFragment newInstance() { + PolicyFragment fragment = new PolicyFragment(); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_policy, container, false); + + TextView policy = rootView.findViewById(R.id.policyText); + + + Spanned myStringSpanned = null; + try { + myStringSpanned = Html.fromHtml(loadHTMLFromAsset(), null, null); + policy.setText(myStringSpanned, TextView.BufferType.SPANNABLE); + } catch (IOException e) { + policy.setText("N/A"); + } + + return rootView; + } + + public String loadHTMLFromAsset() throws IOException { + String html = null; + InputStream is = getContext().getAssets().open(POLICY_FILE); + int size = is.available(); + byte[] buffer = new byte[size]; + is.read(buffer); + is.close(); + html = new String(buffer, "UTF-8"); + return html; + } + +} diff --git a/android/app/src/main/java/io/highfidelity/hifiinterface/task/DownloadProfileImageTask.java b/android/app/src/main/java/io/highfidelity/hifiinterface/task/DownloadProfileImageTask.java new file mode 100644 index 0000000000..f32227a31e --- /dev/null +++ b/android/app/src/main/java/io/highfidelity/hifiinterface/task/DownloadProfileImageTask.java @@ -0,0 +1,71 @@ +package io.highfidelity.hifiinterface.task; + +import android.os.AsyncTask; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; + +import io.highfidelity.hifiinterface.HifiUtils; + +/** + * This is a temporary solution until the profile picture URL is + * available in an API + */ +public class DownloadProfileImageTask extends AsyncTask { + + private static final String BASE_PROFILE_URL = "https://highfidelity.com"; + private static final String TAG = "Interface"; + + private final DownloadProfileImageResultProcessor mResultProcessor; + + public interface DownloadProfileImageResultProcessor { + void onResultAvailable(String url); + } + + public DownloadProfileImageTask(DownloadProfileImageResultProcessor resultProcessor) { + mResultProcessor = resultProcessor; + } + + @Override + protected String doInBackground(String... usernames) { + URL userPage = null; + for (String username: usernames) { + try { + userPage = new URL(BASE_PROFILE_URL + "/users/" + username); + BufferedReader in = new BufferedReader( + new InputStreamReader( + userPage.openStream())); + + StringBuffer strBuff = new StringBuffer(); + String inputLine; + while ((inputLine = in.readLine()) != null) { + strBuff.append(inputLine); + } + in.close(); + String substr = "img class=\"users-img\" src=\""; + int indexBegin = strBuff.indexOf(substr) + substr.length(); + if (indexBegin >= substr.length()) { + int indexEnd = strBuff.indexOf("\"", indexBegin); + if (indexEnd > 0) { + String url = strBuff.substring(indexBegin, indexEnd); + return HifiUtils.getInstance().absoluteHifiAssetUrl(url, BASE_PROFILE_URL); + } + } + } catch (IOException e) { + Log.e(TAG, "Error getting profile picture for username " + username); + } + } + return null; + } + + @Override + protected void onPostExecute(String url) { + super.onPostExecute(url); + if (mResultProcessor != null) { + mResultProcessor.onResultAvailable(url); + } + } +} diff --git a/android/app/src/main/res/drawable/default_profile_avatar.xml b/android/app/src/main/res/drawable/default_profile_avatar.xml new file mode 100644 index 0000000000..5db00acdd6 --- /dev/null +++ b/android/app/src/main/res/drawable/default_profile_avatar.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/drawable/hifi_logo_header.xml b/android/app/src/main/res/drawable/hifi_logo_header.xml new file mode 100644 index 0000000000..017e636184 --- /dev/null +++ b/android/app/src/main/res/drawable/hifi_logo_header.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/drawable/hifi_logo_splash.xml b/android/app/src/main/res/drawable/hifi_logo_splash.xml new file mode 100644 index 0000000000..919b2737e8 --- /dev/null +++ b/android/app/src/main/res/drawable/hifi_logo_splash.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/font/raleway_italic.xml b/android/app/src/main/res/font/raleway_italic.xml new file mode 100644 index 0000000000..6bf9dfa29c --- /dev/null +++ b/android/app/src/main/res/font/raleway_italic.xml @@ -0,0 +1,7 @@ + + + diff --git a/android/app/src/main/res/layout/activity_goto.xml b/android/app/src/main/res/layout/activity_goto.xml deleted file mode 100644 index 06e1383da5..0000000000 --- a/android/app/src/main/res/layout/activity_goto.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - diff --git a/android/app/src/main/res/layout/activity_home.xml b/android/app/src/main/res/layout/activity_main.xml similarity index 73% rename from android/app/src/main/res/layout/activity_home.xml rename to android/app/src/main/res/layout/activity_main.xml index 91fb8603cd..f14bb66586 100644 --- a/android/app/src/main/res/layout/activity_home.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -22,8 +22,10 @@ android:elevation="4dp" /> - - + @@ -32,9 +34,10 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" + app:headerLayout="@layout/navigation_header" android:fitsSystemWindows="true" android:background="@color/colorPrimaryDark" - app:menu="@menu/menu_home" + app:menu="@menu/menu_navigation" > - + android:textColor="@color/menuOption" + android:paddingTop="15dp" + android:paddingBottom="15dp"/> + diff --git a/android/app/src/main/res/layout/activity_splash.xml b/android/app/src/main/res/layout/activity_splash.xml index 5b4f91e733..ed25797917 100644 --- a/android/app/src/main/res/layout/activity_splash.xml +++ b/android/app/src/main/res/layout/activity_splash.xml @@ -5,8 +5,11 @@ android:id="@+id/root_activity_splash" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/backgroundLight"> - - - + android:background="@android:color/black"> + diff --git a/android/app/src/main/res/layout/content_home.xml b/android/app/src/main/res/layout/fragment_home.xml similarity index 96% rename from android/app/src/main/res/layout/content_home.xml rename to android/app/src/main/res/layout/fragment_home.xml index 4ebb4bbf01..cb39b8f69e 100644 --- a/android/app/src/main/res/layout/content_home.xml +++ b/android/app/src/main/res/layout/fragment_home.xml @@ -7,7 +7,7 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:background="@color/colorPrimary" - tools:context="io.highfidelity.hifiinterface.HomeActivity" + tools:context="io.highfidelity.hifiinterface.MainActivity" tools:showIn="@layout/activity_home"> + android:background="@color/backgroundLight"> + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/hifi_header" />