23 |
24 |
--------------------------------------------------------------------------------
/TrinaryCalculator/wear/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
17 |
18 |
22 |
23 |
--------------------------------------------------------------------------------
/TrinaryCalculator/things/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.trinarycalculator.ayidouble.trinarycalculator"
7 | minSdkVersion 24
8 | targetSdkVersion 28
9 | versionCode 2
10 | versionName "1.1"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
24 | testImplementation 'junit:junit:4.12'
25 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
26 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
27 | compileOnly 'com.google.android.things:androidthings:+'
28 | }
29 |
--------------------------------------------------------------------------------
/TrinaryCalculator/wear/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.trinarycalculator.ayidouble.trinarycalculator"
7 | minSdkVersion 23
8 | targetSdkVersion 28
9 | versionCode 2
10 | versionName "1.1"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation fileTree(dir: 'libs', include: ['*.jar'])
22 | implementation 'com.google.android.support:wearable:2.3.0'
23 | implementation 'com.google.android.gms:play-services-wearable:16.0.1'
24 | implementation 'com.android.support:percent:28.0.0'
25 | implementation 'com.android.support:support-v4:28.0.0'
26 | implementation 'com.android.support:recyclerview-v7:28.0.0'
27 | implementation 'com.android.support:wear:28.0.0'
28 | compileOnly 'com.google.android.wearable:wearable:2.3.0'
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Alpay Yildirim
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import android.app.Activity;
18 | import android.os.Bundle;
19 |
20 | /*
21 | * MainActivity class that loads {@link MainFragment}.
22 | */
23 | public class MainActivity extends Activity {
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.ap_
3 |
4 | # Files for the ART/Dalvik VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 |
10 | # Generated files
11 | bin/
12 | gen/
13 | out/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Android Studio Navigation editor temp files
29 | .navigation/
30 |
31 | # Android Studio captures folder
32 | captures/
33 |
34 | # IntelliJ
35 | *.iml
36 | .idea/workspace.xml
37 | .idea/tasks.xml
38 | .idea/gradle.xml
39 | .idea/assetWizardSettings.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 | .idea/caches
43 |
44 | # Keystore files
45 | # Uncomment the following line if you do not want to check your keystore files in.
46 | #*.jks
47 |
48 | # External native build folder generated in Android Studio 2.2 and later
49 | .externalNativeBuild
50 |
51 | # Google Services (e.g. APIs or Firebase)
52 | google-services.json
53 |
54 | # Freeline
55 | freeline.py
56 | freeline/
57 | freeline_project_description.json
58 |
59 | # fastlane
60 | fastlane/report.xml
61 | fastlane/Preview.html
62 | fastlane/screenshots
63 | fastlane/test_output
64 | fastlane/readme.md
65 |
--------------------------------------------------------------------------------
/TrinaryCalculator/feature/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/DetailsDescriptionPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import android.support.v17.leanback.widget.AbstractDetailsDescriptionPresenter;
18 |
19 | public class DetailsDescriptionPresenter extends AbstractDetailsDescriptionPresenter {
20 |
21 | @Override
22 | protected void onBindDescription(ViewHolder viewHolder, Object item) {
23 | Movie movie = (Movie) item;
24 |
25 | if (movie != null) {
26 | viewHolder.getTitle().setText(movie.getTitle());
27 | viewHolder.getSubtitle().setText(movie.getStudio());
28 | viewHolder.getBody().setText(movie.getDescription());
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/DetailsActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import android.app.Activity;
18 | import android.os.Bundle;
19 |
20 | /*
21 | * Details activity class that loads LeanbackDetailsFragment class
22 | */
23 | public class DetailsActivity extends Activity {
24 | public static final String SHARED_ELEMENT_NAME = "hero";
25 | public static final String MOVIE = "Movie";
26 |
27 | /**
28 | * Called when the activity is first created.
29 | */
30 | @Override
31 | public void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_details);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/PlaybackActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import android.os.Bundle;
18 | import android.support.v4.app.FragmentActivity;
19 |
20 | /**
21 | * Loads {@link PlaybackVideoFragment}.
22 | */
23 | public class PlaybackActivity extends FragmentActivity {
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | if (savedInstanceState == null) {
29 | getSupportFragmentManager()
30 | .beginTransaction()
31 | .replace(android.R.id.content, new PlaybackVideoFragment())
32 | .commit();
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/TrinaryCalculator/wear/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
18 |
22 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/TrinaryCalculator/things/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.trinarycalculator.ayidouble.trinarycalculator;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.webkit.WebSettings;
6 | import android.webkit.WebView;
7 |
8 | /**
9 | * Skeleton of an Android Things activity.
10 | *
11 | * Android Things peripheral APIs are accessible through the class
12 | * PeripheralManagerService. For example, the snippet below will open a GPIO pin and
13 | * set it to HIGH:
14 | *
15 | *
37 |
38 |
--------------------------------------------------------------------------------
/TrinaryCalculator/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/PlaybackVideoFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import android.net.Uri;
18 | import android.os.Bundle;
19 | import android.support.v17.leanback.app.VideoSupportFragment;
20 | import android.support.v17.leanback.app.VideoSupportFragmentGlueHost;
21 | import android.support.v17.leanback.media.MediaPlayerAdapter;
22 | import android.support.v17.leanback.media.PlaybackTransportControlGlue;
23 | import android.support.v17.leanback.widget.PlaybackControlsRow;
24 |
25 | /**
26 | * Handles video playback with media controls.
27 | */
28 | public class PlaybackVideoFragment extends VideoSupportFragment {
29 |
30 | private PlaybackTransportControlGlue mTransportControlGlue;
31 |
32 | @Override
33 | public void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 |
36 | final Movie movie =
37 | (Movie) getActivity().getIntent().getSerializableExtra(DetailsActivity.MOVIE);
38 |
39 | VideoSupportFragmentGlueHost glueHost =
40 | new VideoSupportFragmentGlueHost(PlaybackVideoFragment.this);
41 |
42 | MediaPlayerAdapter playerAdapter = new MediaPlayerAdapter(getActivity());
43 | playerAdapter.setRepeatAction(PlaybackControlsRow.RepeatAction.INDEX_NONE);
44 |
45 | mTransportControlGlue = new PlaybackTransportControlGlue<>(getActivity(), playerAdapter);
46 | mTransportControlGlue.setHost(glueHost);
47 | mTransportControlGlue.setTitle(movie.getTitle());
48 | mTransportControlGlue.setSubtitle(movie.getDescription());
49 | mTransportControlGlue.playWhenPrepared();
50 | playerAdapter.setDataSource(Uri.parse(movie.getVideoUrl()));
51 | }
52 |
53 | @Override
54 | public void onPause() {
55 | super.onPause();
56 | if (mTransportControlGlue != null) {
57 | mTransportControlGlue.pause();
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/TrinaryCalculator/.idea/assetWizardSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/Movie.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import java.io.Serializable;
18 |
19 | /*
20 | * Movie class represents video entity with title, description, image thumbs and video url.
21 | */
22 | public class Movie implements Serializable {
23 | static final long serialVersionUID = 727566175075960653L;
24 | private long id;
25 | private String title;
26 | private String description;
27 | private String bgImageUrl;
28 | private String cardImageUrl;
29 | private String videoUrl;
30 | private String studio;
31 |
32 | public Movie() {
33 | }
34 |
35 | public long getId() {
36 | return id;
37 | }
38 |
39 | public void setId(long id) {
40 | this.id = id;
41 | }
42 |
43 | public String getTitle() {
44 | return title;
45 | }
46 |
47 | public void setTitle(String title) {
48 | this.title = title;
49 | }
50 |
51 | public String getDescription() {
52 | return description;
53 | }
54 |
55 | public void setDescription(String description) {
56 | this.description = description;
57 | }
58 |
59 | public String getStudio() {
60 | return studio;
61 | }
62 |
63 | public void setStudio(String studio) {
64 | this.studio = studio;
65 | }
66 |
67 | public String getVideoUrl() {
68 | return videoUrl;
69 | }
70 |
71 | public void setVideoUrl(String videoUrl) {
72 | this.videoUrl = videoUrl;
73 | }
74 |
75 | public String getBackgroundImageUrl() {
76 | return bgImageUrl;
77 | }
78 |
79 | public void setBackgroundImageUrl(String bgImageUrl) {
80 | this.bgImageUrl = bgImageUrl;
81 | }
82 |
83 | public String getCardImageUrl() {
84 | return cardImageUrl;
85 | }
86 |
87 | public void setCardImageUrl(String cardImageUrl) {
88 | this.cardImageUrl = cardImageUrl;
89 | }
90 |
91 | @Override
92 | public String toString() {
93 | return "Movie{" +
94 | "id=" + id +
95 | ", title='" + title + '\'' +
96 | ", videoUrl='" + videoUrl + '\'' +
97 | ", backgroundImageUrl='" + bgImageUrl + '\'' +
98 | ", cardImageUrl='" + cardImageUrl + '\'' +
99 | '}';
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/BrowseErrorActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package com.trinarycalculator.ayidouble.trinarycalculator;
15 |
16 | import android.app.Activity;
17 | import android.app.Fragment;
18 | import android.os.Bundle;
19 | import android.os.Handler;
20 | import android.view.Gravity;
21 | import android.view.LayoutInflater;
22 | import android.view.View;
23 | import android.view.ViewGroup;
24 | import android.widget.FrameLayout;
25 | import android.widget.ProgressBar;
26 |
27 | /*
28 | * BrowseErrorActivity shows how to use ErrorFragment
29 | */
30 | public class BrowseErrorActivity extends Activity {
31 | private static final int TIMER_DELAY = 3000;
32 | private static final int SPINNER_WIDTH = 100;
33 | private static final int SPINNER_HEIGHT = 100;
34 |
35 | private ErrorFragment mErrorFragment;
36 | private SpinnerFragment mSpinnerFragment;
37 |
38 | /**
39 | * Called when the activity is first created.
40 | */
41 | @Override
42 | public void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_main);
45 |
46 | testError();
47 | }
48 |
49 | private void testError() {
50 | mErrorFragment = new ErrorFragment();
51 | getFragmentManager()
52 | .beginTransaction()
53 | .add(R.id.main_browse_fragment, mErrorFragment)
54 | .commit();
55 |
56 | mSpinnerFragment = new SpinnerFragment();
57 | getFragmentManager()
58 | .beginTransaction()
59 | .add(R.id.main_browse_fragment, mSpinnerFragment)
60 | .commit();
61 |
62 | final Handler handler = new Handler();
63 | handler.postDelayed(new Runnable() {
64 | @Override
65 | public void run() {
66 | getFragmentManager()
67 | .beginTransaction()
68 | .remove(mSpinnerFragment)
69 | .commit();
70 | mErrorFragment.setErrorContent();
71 | }
72 | }, TIMER_DELAY);
73 | }
74 |
75 | public static class SpinnerFragment extends Fragment {
76 | @Override
77 | public View onCreateView(
78 | LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
79 | ProgressBar progressBar = new ProgressBar(container.getContext());
80 | if (container instanceof FrameLayout) {
81 | FrameLayout.LayoutParams layoutParams =
82 | new FrameLayout.LayoutParams(SPINNER_WIDTH, SPINNER_HEIGHT, Gravity.CENTER);
83 | progressBar.setLayoutParams(layoutParams);
84 | }
85 | return progressBar;
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at GitHub. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [📱 Trinary Calculator Android Java App 📱](https://play.google.com/store/apps/details?id=com.trinarycalculator.ayidouble.trinarycalculator.app)
2 |
3 |
4 |
5 |
6 |
7 | A Completely **Free** handy Calculator for trinary operations 📱
8 |
9 | **Official Google Play Store Download Link** : **[https://play.google.com/store/apps/details?id=com.trinarycalculator.ayidouble.trinarycalculator.app](https://play.google.com/store/apps/details?id=com.trinarycalculator.ayidouble.trinarycalculator.app)**
10 |
11 | A handy **Calculator** for trinary operations, that works on **all devices**. 📱 💻 🖥
12 |
13 | You can choose, if you want to calculate with **Balanced Ternary (-,0,+)** or **Trinary (0,1,2)**. 0️⃣1️⃣2️⃣
14 |
15 | Feel free to use the **Calculator** for teaching Numeral systems as an example.
16 | If you have Suggestions or find Errors, you're free to contact me on GitHub or submit your changes.
17 | The Reason why I build this **Calculator** was, because there wasn't a good one on the Web.
18 |
19 | ## [📱 FREE Download Google Play Store: 📱](https://play.google.com/store/apps/details?id=com.trinarycalculator.ayidouble.trinarycalculator.app)
20 | 
21 |
22 | ## [📱 Mobile (Smartphone): 📱](https://ayidouble.github.io/Trinary-Calculator-JavaScript)
23 | 
24 | 
25 |
26 | ## [💻 Desktop: 🖥](https://ayidouble.github.io/Trinary-Calculator-JavaScript)
27 | 
28 |
29 | **[The Trinary Calculator is just a Website](https://ayidouble.github.io/Trinary-Calculator-JavaScript)** that each possible device can access to.
30 | ## ***You can use the Trinary Calculator on your: 📱 💻 🖥***
31 | - ***[Smartphone](https://ayidouble.github.io/Trinary-Calculator-JavaScript) (Android/iOS etc.) 📱***
32 | - ***[Tablet](https://ayidouble.github.io/Trinary-Calculator-JavaScript) (Chrome, Firefox, Edge, Safari) 📱***
33 | - ***[Laptop](https://ayidouble.github.io/Trinary-Calculator-JavaScript) (Chrome, Firefox, Edge, Safari) 💻***
34 | - ***[Desktop](https://ayidouble.github.io/Trinary-Calculator-JavaScript) (Chrome, Firefox, Edge, Safari) 🖥***
35 |
36 | ## Trinary Operations ➕ ➖ ➗ ✖️
37 |
38 | - **\+ (Addition)**
39 | - **\- (Subtraction)**
40 | - **\* (Multiplication)**
41 | - **\/ (Division)**
42 |
43 | ## As efficient as possible ⚙️
44 |
45 | The **Calculator** is designed to give responses on every action,
46 | this is noticeable as an example at the addition of two Trytes,
47 | while you're typing, an algorithm already calculates every number you type and displays the result.
48 |
49 | ## The Calculator allows you to ⛓
50 |
51 | - calculate with **balanced Ternary (-,0,+)** or **Trinary (0,1,2)** 0️⃣1️⃣2️⃣
52 | - see how Binary Values are stored in Trinary
53 | - how much **8, 16, 32, 64, 3, 6, 9, 21, 27, 81 Trit** can store, (ex. unsigned **8-Trit** can store values from **(00000000) 0 ... 6561 (22222222)**)
54 | - see how other numeral systems are working (**ternary**, **quaternary**, **octal**, **hexadecimal**)
55 |
56 | 
57 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/CardPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import android.graphics.drawable.Drawable;
18 | import android.support.v17.leanback.widget.ImageCardView;
19 | import android.support.v17.leanback.widget.Presenter;
20 | import android.support.v4.content.ContextCompat;
21 | import android.util.Log;
22 | import android.view.ViewGroup;
23 |
24 | import com.bumptech.glide.Glide;
25 |
26 | /*
27 | * A CardPresenter is used to generate Views and bind Objects to them on demand.
28 | * It contains an Image CardView
29 | */
30 | public class CardPresenter extends Presenter {
31 | private static final String TAG = "CardPresenter";
32 |
33 | private static final int CARD_WIDTH = 313;
34 | private static final int CARD_HEIGHT = 176;
35 | private static int sSelectedBackgroundColor;
36 | private static int sDefaultBackgroundColor;
37 | private Drawable mDefaultCardImage;
38 |
39 | private static void updateCardBackgroundColor(ImageCardView view, boolean selected) {
40 | int color = selected ? sSelectedBackgroundColor : sDefaultBackgroundColor;
41 | // Both background colors should be set because the view's background is temporarily visible
42 | // during animations.
43 | view.setBackgroundColor(color);
44 | view.findViewById(R.id.info_field).setBackgroundColor(color);
45 | }
46 |
47 | @Override
48 | public ViewHolder onCreateViewHolder(ViewGroup parent) {
49 | Log.d(TAG, "onCreateViewHolder");
50 |
51 | sDefaultBackgroundColor =
52 | ContextCompat.getColor(parent.getContext(), R.color.default_background);
53 | sSelectedBackgroundColor =
54 | ContextCompat.getColor(parent.getContext(), R.color.selected_background);
55 | /*
56 | * This template uses a default image in res/drawable, but the general case for Android TV
57 | * will require your resources in xhdpi. For more information, see
58 | * https://developer.android.com/training/tv/start/layouts.html#density-resources
59 | */
60 | mDefaultCardImage = ContextCompat.getDrawable(parent.getContext(), R.drawable.movie);
61 |
62 | ImageCardView cardView =
63 | new ImageCardView(parent.getContext()) {
64 | @Override
65 | public void setSelected(boolean selected) {
66 | updateCardBackgroundColor(this, selected);
67 | super.setSelected(selected);
68 | }
69 | };
70 |
71 | cardView.setFocusable(true);
72 | cardView.setFocusableInTouchMode(true);
73 | updateCardBackgroundColor(cardView, false);
74 | return new ViewHolder(cardView);
75 | }
76 |
77 | @Override
78 | public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
79 | Movie movie = (Movie) item;
80 | ImageCardView cardView = (ImageCardView) viewHolder.view;
81 |
82 | Log.d(TAG, "onBindViewHolder");
83 | if (movie.getCardImageUrl() != null) {
84 | cardView.setTitleText(movie.getTitle());
85 | cardView.setContentText(movie.getStudio());
86 | cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT);
87 | Glide.with(viewHolder.view.getContext())
88 | .load(movie.getCardImageUrl())
89 | .centerCrop()
90 | .error(mDefaultCardImage)
91 | .into(cardView.getMainImageView());
92 | }
93 | }
94 |
95 | @Override
96 | public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
97 | Log.d(TAG, "onUnbindViewHolder");
98 | ImageCardView cardView = (ImageCardView) viewHolder.view;
99 | // Remove references to images so that the garbage collector can free up memory
100 | cardView.setBadgeImage(null);
101 | cardView.setMainImage(null);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/TrinaryCalculator/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/MovieList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | public final class MovieList {
21 | public static final String MOVIE_CATEGORY[] = {
22 | "Category Zero",
23 | "Category One",
24 | "Category Two",
25 | "Category Three",
26 | "Category Four",
27 | "Category Five",
28 | };
29 |
30 | private static List list;
31 | private static long count = 0;
32 |
33 | public static List getList() {
34 | if (list == null) {
35 | list = setupMovies();
36 | }
37 | return list;
38 | }
39 |
40 | public static List setupMovies() {
41 | list = new ArrayList<>();
42 | String title[] = {
43 | "Zeitgeist 2010_ Year in Review",
44 | "Google Demo Slam_ 20ft Search",
45 | "Introducing Gmail Blue",
46 | "Introducing Google Fiber to the Pole",
47 | "Introducing Google Nose"
48 | };
49 |
50 | String description = "Fusce id nisi turpis. Praesent viverra bibendum semper. "
51 | + "Donec tristique, orci sed semper lacinia, quam erat rhoncus massa, non congue tellus est "
52 | + "quis tellus. Sed mollis orci venenatis quam scelerisque accumsan. Curabitur a massa sit "
53 | + "amet mi accumsan mollis sed et magna. Vivamus sed aliquam risus. Nulla eget dolor in elit "
54 | + "facilisis mattis. Ut aliquet luctus lacus. Phasellus nec commodo erat. Praesent tempus id "
55 | + "lectus ac scelerisque. Maecenas pretium cursus lectus id volutpat.";
56 | String studio[] = {
57 | "Studio Zero", "Studio One", "Studio Two", "Studio Three", "Studio Four"
58 | };
59 | String videoUrl[] = {
60 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/Zeitgeist/Zeitgeist%202010_%20Year%20in%20Review.mp4",
61 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/Demo%20Slam/Google%20Demo%20Slam_%2020ft%20Search.mp4",
62 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Gmail%20Blue.mp4",
63 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Google%20Fiber%20to%20the%20Pole.mp4",
64 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Google%20Nose.mp4"
65 | };
66 | String bgImageUrl[] = {
67 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/Zeitgeist/Zeitgeist%202010_%20Year%20in%20Review/bg.jpg",
68 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/Demo%20Slam/Google%20Demo%20Slam_%2020ft%20Search/bg.jpg",
69 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Gmail%20Blue/bg.jpg",
70 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Google%20Fiber%20to%20the%20Pole/bg.jpg",
71 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Google%20Nose/bg.jpg",
72 | };
73 | String cardImageUrl[] = {
74 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/Zeitgeist/Zeitgeist%202010_%20Year%20in%20Review/card.jpg",
75 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/Demo%20Slam/Google%20Demo%20Slam_%2020ft%20Search/card.jpg",
76 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Gmail%20Blue/card.jpg",
77 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Google%20Fiber%20to%20the%20Pole/card.jpg",
78 | "http://commondatastorage.googleapis.com/android-tv/Sample%20videos/April%20Fool's%202013/Introducing%20Google%20Nose/card.jpg"
79 | };
80 |
81 | for (int index = 0; index < title.length; ++index) {
82 | list.add(
83 | buildMovieInfo(
84 | title[index],
85 | description,
86 | studio[index],
87 | videoUrl[index],
88 | cardImageUrl[index],
89 | bgImageUrl[index]));
90 | }
91 |
92 | return list;
93 | }
94 |
95 | private static Movie buildMovieInfo(
96 | String title,
97 | String description,
98 | String studio,
99 | String videoUrl,
100 | String cardImageUrl,
101 | String backgroundImageUrl) {
102 | Movie movie = new Movie();
103 | movie.setId(count++);
104 | movie.setTitle(title);
105 | movie.setDescription(description);
106 | movie.setStudio(studio);
107 | movie.setCardImageUrl(cardImageUrl);
108 | movie.setBackgroundImageUrl(backgroundImageUrl);
109 | movie.setVideoUrl(videoUrl);
110 | return movie;
111 | }
112 | }
--------------------------------------------------------------------------------
/TrinaryCalculator/base/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/VideoDetailsFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import android.content.Context;
18 | import android.content.Intent;
19 | import android.graphics.Bitmap;
20 | import android.os.Bundle;
21 | import android.support.v17.leanback.app.DetailsFragment;
22 | import android.support.v17.leanback.app.DetailsFragmentBackgroundController;
23 | import android.support.v17.leanback.widget.Action;
24 | import android.support.v17.leanback.widget.ArrayObjectAdapter;
25 | import android.support.v17.leanback.widget.ClassPresenterSelector;
26 | import android.support.v17.leanback.widget.DetailsOverviewRow;
27 | import android.support.v17.leanback.widget.FullWidthDetailsOverviewRowPresenter;
28 | import android.support.v17.leanback.widget.FullWidthDetailsOverviewSharedElementHelper;
29 | import android.support.v17.leanback.widget.HeaderItem;
30 | import android.support.v17.leanback.widget.ImageCardView;
31 | import android.support.v17.leanback.widget.ListRow;
32 | import android.support.v17.leanback.widget.ListRowPresenter;
33 | import android.support.v17.leanback.widget.OnActionClickedListener;
34 | import android.support.v17.leanback.widget.OnItemViewClickedListener;
35 | import android.support.v17.leanback.widget.Presenter;
36 | import android.support.v17.leanback.widget.Row;
37 | import android.support.v17.leanback.widget.RowPresenter;
38 | import android.support.v4.app.ActivityOptionsCompat;
39 | import android.support.v4.content.ContextCompat;
40 | import android.util.Log;
41 | import android.widget.Toast;
42 |
43 | import com.bumptech.glide.Glide;
44 | import com.bumptech.glide.load.resource.drawable.GlideDrawable;
45 | import com.bumptech.glide.request.animation.GlideAnimation;
46 | import com.bumptech.glide.request.target.SimpleTarget;
47 |
48 | import java.util.Collections;
49 | import java.util.List;
50 |
51 | /*
52 | * LeanbackDetailsFragment extends DetailsFragment, a Wrapper fragment for leanback details screens.
53 | * It shows a detailed view of video and its meta plus related videos.
54 | */
55 | public class VideoDetailsFragment extends DetailsFragment {
56 | private static final String TAG = "VideoDetailsFragment";
57 |
58 | private static final int ACTION_WATCH_TRAILER = 1;
59 | private static final int ACTION_RENT = 2;
60 | private static final int ACTION_BUY = 3;
61 |
62 | private static final int DETAIL_THUMB_WIDTH = 274;
63 | private static final int DETAIL_THUMB_HEIGHT = 274;
64 |
65 | private static final int NUM_COLS = 10;
66 |
67 | private Movie mSelectedMovie;
68 |
69 | private ArrayObjectAdapter mAdapter;
70 | private ClassPresenterSelector mPresenterSelector;
71 |
72 | private DetailsFragmentBackgroundController mDetailsBackground;
73 |
74 | @Override
75 | public void onCreate(Bundle savedInstanceState) {
76 | Log.d(TAG, "onCreate DetailsFragment");
77 | super.onCreate(savedInstanceState);
78 |
79 | mDetailsBackground = new DetailsFragmentBackgroundController(this);
80 |
81 | mSelectedMovie =
82 | (Movie) getActivity().getIntent().getSerializableExtra(DetailsActivity.MOVIE);
83 | if (mSelectedMovie != null) {
84 | mPresenterSelector = new ClassPresenterSelector();
85 | mAdapter = new ArrayObjectAdapter(mPresenterSelector);
86 | setupDetailsOverviewRow();
87 | setupDetailsOverviewRowPresenter();
88 | setupRelatedMovieListRow();
89 | setAdapter(mAdapter);
90 | initializeBackground(mSelectedMovie);
91 | setOnItemViewClickedListener(new ItemViewClickedListener());
92 | } else {
93 | Intent intent = new Intent(getActivity(), MainActivity.class);
94 | startActivity(intent);
95 | }
96 | }
97 |
98 | private void initializeBackground(Movie data) {
99 | mDetailsBackground.enableParallax();
100 | Glide.with(getActivity())
101 | .load(data.getBackgroundImageUrl())
102 | .asBitmap()
103 | .centerCrop()
104 | .error(R.drawable.default_background)
105 | .into(new SimpleTarget() {
106 | @Override
107 | public void onResourceReady(Bitmap bitmap,
108 | GlideAnimation super Bitmap> glideAnimation) {
109 | mDetailsBackground.setCoverBitmap(bitmap);
110 | mAdapter.notifyArrayItemRangeChanged(0, mAdapter.size());
111 | }
112 | });
113 | }
114 |
115 | private void setupDetailsOverviewRow() {
116 | Log.d(TAG, "doInBackground: " + mSelectedMovie.toString());
117 | final DetailsOverviewRow row = new DetailsOverviewRow(mSelectedMovie);
118 | row.setImageDrawable(
119 | ContextCompat.getDrawable(getActivity(), R.drawable.default_background));
120 | int width = convertDpToPixel(getActivity().getApplicationContext(), DETAIL_THUMB_WIDTH);
121 | int height = convertDpToPixel(getActivity().getApplicationContext(), DETAIL_THUMB_HEIGHT);
122 | Glide.with(getActivity())
123 | .load(mSelectedMovie.getCardImageUrl())
124 | .centerCrop()
125 | .error(R.drawable.default_background)
126 | .into(new SimpleTarget(width, height) {
127 | @Override
128 | public void onResourceReady(GlideDrawable resource,
129 | GlideAnimation super GlideDrawable>
130 | glideAnimation) {
131 | Log.d(TAG, "details overview card image url ready: " + resource);
132 | row.setImageDrawable(resource);
133 | mAdapter.notifyArrayItemRangeChanged(0, mAdapter.size());
134 | }
135 | });
136 |
137 | ArrayObjectAdapter actionAdapter = new ArrayObjectAdapter();
138 |
139 | actionAdapter.add(
140 | new Action(
141 | ACTION_WATCH_TRAILER,
142 | getResources().getString(R.string.watch_trailer_1),
143 | getResources().getString(R.string.watch_trailer_2)));
144 | actionAdapter.add(
145 | new Action(
146 | ACTION_RENT,
147 | getResources().getString(R.string.rent_1),
148 | getResources().getString(R.string.rent_2)));
149 | actionAdapter.add(
150 | new Action(
151 | ACTION_BUY,
152 | getResources().getString(R.string.buy_1),
153 | getResources().getString(R.string.buy_2)));
154 | row.setActionsAdapter(actionAdapter);
155 |
156 | mAdapter.add(row);
157 | }
158 |
159 | private void setupDetailsOverviewRowPresenter() {
160 | // Set detail background.
161 | FullWidthDetailsOverviewRowPresenter detailsPresenter =
162 | new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
163 | detailsPresenter.setBackgroundColor(
164 | ContextCompat.getColor(getActivity(), R.color.selected_background));
165 |
166 | // Hook up transition element.
167 | FullWidthDetailsOverviewSharedElementHelper sharedElementHelper =
168 | new FullWidthDetailsOverviewSharedElementHelper();
169 | sharedElementHelper.setSharedElementEnterTransition(
170 | getActivity(), DetailsActivity.SHARED_ELEMENT_NAME);
171 | detailsPresenter.setListener(sharedElementHelper);
172 | detailsPresenter.setParticipatingEntranceTransition(true);
173 |
174 | detailsPresenter.setOnActionClickedListener(new OnActionClickedListener() {
175 | @Override
176 | public void onActionClicked(Action action) {
177 | if (action.getId() == ACTION_WATCH_TRAILER) {
178 | Intent intent = new Intent(getActivity(), PlaybackActivity.class);
179 | intent.putExtra(DetailsActivity.MOVIE, mSelectedMovie);
180 | startActivity(intent);
181 | } else {
182 | Toast.makeText(getActivity(), action.toString(), Toast.LENGTH_SHORT).show();
183 | }
184 | }
185 | });
186 | mPresenterSelector.addClassPresenter(DetailsOverviewRow.class, detailsPresenter);
187 | }
188 |
189 | private void setupRelatedMovieListRow() {
190 | String subcategories[] = {getString(R.string.related_movies)};
191 | List list = MovieList.getList();
192 |
193 | Collections.shuffle(list);
194 | ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
195 | for (int j = 0; j < NUM_COLS; j++) {
196 | listRowAdapter.add(list.get(j % 5));
197 | }
198 |
199 | HeaderItem header = new HeaderItem(0, subcategories[0]);
200 | mAdapter.add(new ListRow(header, listRowAdapter));
201 | mPresenterSelector.addClassPresenter(ListRow.class, new ListRowPresenter());
202 | }
203 |
204 | private int convertDpToPixel(Context context, int dp) {
205 | float density = context.getResources().getDisplayMetrics().density;
206 | return Math.round((float) dp * density);
207 | }
208 |
209 | private final class ItemViewClickedListener implements OnItemViewClickedListener {
210 | @Override
211 | public void onItemClicked(
212 | Presenter.ViewHolder itemViewHolder,
213 | Object item,
214 | RowPresenter.ViewHolder rowViewHolder,
215 | Row row) {
216 |
217 | if (item instanceof Movie) {
218 | Log.d(TAG, "Item: " + item.toString());
219 | Intent intent = new Intent(getActivity(), DetailsActivity.class);
220 | intent.putExtra(getResources().getString(R.string.movie), mSelectedMovie);
221 |
222 | Bundle bundle =
223 | ActivityOptionsCompat.makeSceneTransitionAnimation(
224 | getActivity(),
225 | ((ImageCardView) itemViewHolder.view).getMainImageView(),
226 | DetailsActivity.SHARED_ELEMENT_NAME)
227 | .toBundle();
228 | getActivity().startActivity(intent, bundle);
229 | }
230 | }
231 | }
232 | }
233 |
--------------------------------------------------------------------------------
/TrinaryCalculator/tv/src/main/java/com/trinarycalculator/ayidouble/trinarycalculator/MainFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 |
15 | package com.trinarycalculator.ayidouble.trinarycalculator;
16 |
17 | import android.content.Intent;
18 | import android.graphics.Color;
19 | import android.graphics.drawable.Drawable;
20 | import android.os.Bundle;
21 | import android.os.Handler;
22 | import android.support.v17.leanback.app.BackgroundManager;
23 | import android.support.v17.leanback.app.BrowseFragment;
24 | import android.support.v17.leanback.widget.ArrayObjectAdapter;
25 | import android.support.v17.leanback.widget.HeaderItem;
26 | import android.support.v17.leanback.widget.ImageCardView;
27 | import android.support.v17.leanback.widget.ListRow;
28 | import android.support.v17.leanback.widget.ListRowPresenter;
29 | import android.support.v17.leanback.widget.OnItemViewClickedListener;
30 | import android.support.v17.leanback.widget.OnItemViewSelectedListener;
31 | import android.support.v17.leanback.widget.Presenter;
32 | import android.support.v17.leanback.widget.Row;
33 | import android.support.v17.leanback.widget.RowPresenter;
34 | import android.support.v4.app.ActivityOptionsCompat;
35 | import android.support.v4.content.ContextCompat;
36 | import android.util.DisplayMetrics;
37 | import android.util.Log;
38 | import android.view.Gravity;
39 | import android.view.View;
40 | import android.view.ViewGroup;
41 | import android.widget.TextView;
42 | import android.widget.Toast;
43 |
44 | import com.bumptech.glide.Glide;
45 | import com.bumptech.glide.load.resource.drawable.GlideDrawable;
46 | import com.bumptech.glide.request.animation.GlideAnimation;
47 | import com.bumptech.glide.request.target.SimpleTarget;
48 |
49 | import java.util.Collections;
50 | import java.util.List;
51 | import java.util.Timer;
52 | import java.util.TimerTask;
53 |
54 | public class MainFragment extends BrowseFragment {
55 | private static final String TAG = "MainFragment";
56 |
57 | private static final int BACKGROUND_UPDATE_DELAY = 300;
58 | private static final int GRID_ITEM_WIDTH = 200;
59 | private static final int GRID_ITEM_HEIGHT = 200;
60 | private static final int NUM_ROWS = 6;
61 | private static final int NUM_COLS = 15;
62 |
63 | private final Handler mHandler = new Handler();
64 | private Drawable mDefaultBackground;
65 | private DisplayMetrics mMetrics;
66 | private Timer mBackgroundTimer;
67 | private String mBackgroundUri;
68 | private BackgroundManager mBackgroundManager;
69 |
70 | @Override
71 | public void onActivityCreated(Bundle savedInstanceState) {
72 | Log.i(TAG, "onCreate");
73 | super.onActivityCreated(savedInstanceState);
74 |
75 | prepareBackgroundManager();
76 |
77 | setupUIElements();
78 |
79 | loadRows();
80 |
81 | setupEventListeners();
82 | }
83 |
84 | @Override
85 | public void onDestroy() {
86 | super.onDestroy();
87 | if (null != mBackgroundTimer) {
88 | Log.d(TAG, "onDestroy: " + mBackgroundTimer.toString());
89 | mBackgroundTimer.cancel();
90 | }
91 | }
92 |
93 | private void loadRows() {
94 | List list = MovieList.setupMovies();
95 |
96 | ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
97 | CardPresenter cardPresenter = new CardPresenter();
98 |
99 | int i;
100 | for (i = 0; i < NUM_ROWS; i++) {
101 | if (i != 0) {
102 | Collections.shuffle(list);
103 | }
104 | ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
105 | for (int j = 0; j < NUM_COLS; j++) {
106 | listRowAdapter.add(list.get(j % 5));
107 | }
108 | HeaderItem header = new HeaderItem(i, MovieList.MOVIE_CATEGORY[i]);
109 | rowsAdapter.add(new ListRow(header, listRowAdapter));
110 | }
111 |
112 | HeaderItem gridHeader = new HeaderItem(i, "PREFERENCES");
113 |
114 | GridItemPresenter mGridPresenter = new GridItemPresenter();
115 | ArrayObjectAdapter gridRowAdapter = new ArrayObjectAdapter(mGridPresenter);
116 | gridRowAdapter.add(getResources().getString(R.string.grid_view));
117 | gridRowAdapter.add(getString(R.string.error_fragment));
118 | gridRowAdapter.add(getResources().getString(R.string.personal_settings));
119 | rowsAdapter.add(new ListRow(gridHeader, gridRowAdapter));
120 |
121 | setAdapter(rowsAdapter);
122 | }
123 |
124 | private void prepareBackgroundManager() {
125 |
126 | mBackgroundManager = BackgroundManager.getInstance(getActivity());
127 | mBackgroundManager.attach(getActivity().getWindow());
128 |
129 | mDefaultBackground = ContextCompat.getDrawable(getActivity(), R.drawable.default_background);
130 | mMetrics = new DisplayMetrics();
131 | getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
132 | }
133 |
134 | private void setupUIElements() {
135 | // setBadgeDrawable(getActivity().getResources().getDrawable(
136 | // R.drawable.videos_by_google_banner));
137 | setTitle(getString(R.string.browse_title)); // Badge, when set, takes precedent
138 | // over title
139 | setHeadersState(HEADERS_ENABLED);
140 | setHeadersTransitionOnBackEnabled(true);
141 |
142 | // set fastLane (or headers) background color
143 | setBrandColor(ContextCompat.getColor(getActivity(), R.color.fastlane_background));
144 | // set search icon color
145 | setSearchAffordanceColor(ContextCompat.getColor(getActivity(), R.color.search_opaque));
146 | }
147 |
148 | private void setupEventListeners() {
149 | setOnSearchClickedListener(new View.OnClickListener() {
150 |
151 | @Override
152 | public void onClick(View view) {
153 | Toast.makeText(getActivity(), "Implement your own in-app search", Toast.LENGTH_LONG)
154 | .show();
155 | }
156 | });
157 |
158 | setOnItemViewClickedListener(new ItemViewClickedListener());
159 | setOnItemViewSelectedListener(new ItemViewSelectedListener());
160 | }
161 |
162 | private void updateBackground(String uri) {
163 | int width = mMetrics.widthPixels;
164 | int height = mMetrics.heightPixels;
165 | Glide.with(getActivity())
166 | .load(uri)
167 | .centerCrop()
168 | .error(mDefaultBackground)
169 | .into(new SimpleTarget(width, height) {
170 | @Override
171 | public void onResourceReady(GlideDrawable resource,
172 | GlideAnimation super GlideDrawable>
173 | glideAnimation) {
174 | mBackgroundManager.setDrawable(resource);
175 | }
176 | });
177 | mBackgroundTimer.cancel();
178 | }
179 |
180 | private void startBackgroundTimer() {
181 | if (null != mBackgroundTimer) {
182 | mBackgroundTimer.cancel();
183 | }
184 | mBackgroundTimer = new Timer();
185 | mBackgroundTimer.schedule(new UpdateBackgroundTask(), BACKGROUND_UPDATE_DELAY);
186 | }
187 |
188 | private final class ItemViewClickedListener implements OnItemViewClickedListener {
189 | @Override
190 | public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
191 | RowPresenter.ViewHolder rowViewHolder, Row row) {
192 |
193 | if (item instanceof Movie) {
194 | Movie movie = (Movie) item;
195 | Log.d(TAG, "Item: " + item.toString());
196 | Intent intent = new Intent(getActivity(), DetailsActivity.class);
197 | intent.putExtra(DetailsActivity.MOVIE, movie);
198 |
199 | Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(
200 | getActivity(),
201 | ((ImageCardView) itemViewHolder.view).getMainImageView(),
202 | DetailsActivity.SHARED_ELEMENT_NAME)
203 | .toBundle();
204 | getActivity().startActivity(intent, bundle);
205 | } else if (item instanceof String) {
206 | if (((String) item).contains(getString(R.string.error_fragment))) {
207 | Intent intent = new Intent(getActivity(), BrowseErrorActivity.class);
208 | startActivity(intent);
209 | } else {
210 | Toast.makeText(getActivity(), ((String) item), Toast.LENGTH_SHORT).show();
211 | }
212 | }
213 | }
214 | }
215 |
216 | private final class ItemViewSelectedListener implements OnItemViewSelectedListener {
217 | @Override
218 | public void onItemSelected(
219 | Presenter.ViewHolder itemViewHolder,
220 | Object item,
221 | RowPresenter.ViewHolder rowViewHolder,
222 | Row row) {
223 | if (item instanceof Movie) {
224 | mBackgroundUri = ((Movie) item).getBackgroundImageUrl();
225 | startBackgroundTimer();
226 | }
227 | }
228 | }
229 |
230 | private class UpdateBackgroundTask extends TimerTask {
231 |
232 | @Override
233 | public void run() {
234 | mHandler.post(new Runnable() {
235 | @Override
236 | public void run() {
237 | updateBackground(mBackgroundUri);
238 | }
239 | });
240 | }
241 | }
242 |
243 | private class GridItemPresenter extends Presenter {
244 | @Override
245 | public ViewHolder onCreateViewHolder(ViewGroup parent) {
246 | TextView view = new TextView(parent.getContext());
247 | view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT));
248 | view.setFocusable(true);
249 | view.setFocusableInTouchMode(true);
250 | view.setBackgroundColor(
251 | ContextCompat.getColor(getActivity(), R.color.default_background));
252 | view.setTextColor(Color.WHITE);
253 | view.setGravity(Gravity.CENTER);
254 | return new ViewHolder(view);
255 | }
256 |
257 | @Override
258 | public void onBindViewHolder(ViewHolder viewHolder, Object item) {
259 | ((TextView) viewHolder.view).setText((String) item);
260 | }
261 |
262 | @Override
263 | public void onUnbindViewHolder(ViewHolder viewHolder) {
264 | }
265 | }
266 |
267 | }
268 |
--------------------------------------------------------------------------------