From 552a830726e86036234b562f6726d420e6b62eb0 Mon Sep 17 00:00:00 2001 From: Yuku on yuku8 Date: Mon, 12 Oct 2015 12:41:19 +0800 Subject: [PATCH 01/62] Add stetho debugger --- Alkitab/build.gradle | 2 ++ .../debug/java/yuku/stethoshim/StethoShim.java | 16 ++++++++++++++++ Alkitab/src/main/java/yuku/alkitab/base/App.java | 12 +++++++++++- .../release/java/yuku/stethoshim/StethoShim.java | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Alkitab/src/debug/java/yuku/stethoshim/StethoShim.java create mode 100644 Alkitab/src/release/java/yuku/stethoshim/StethoShim.java diff --git a/Alkitab/build.gradle b/Alkitab/build.gradle index 7b440674c..75a85082b 100644 --- a/Alkitab/build.gradle +++ b/Alkitab/build.gradle @@ -83,4 +83,6 @@ dependencies { testCompile 'junit:junit:4.12' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' + debugCompile 'com.facebook.stetho:stetho:1.2.0' + debugCompile 'com.facebook.stetho:stetho-okhttp:1.2.0' } diff --git a/Alkitab/src/debug/java/yuku/stethoshim/StethoShim.java b/Alkitab/src/debug/java/yuku/stethoshim/StethoShim.java new file mode 100644 index 000000000..9cb6fc76b --- /dev/null +++ b/Alkitab/src/debug/java/yuku/stethoshim/StethoShim.java @@ -0,0 +1,16 @@ +package yuku.stethoshim; + +import android.app.Application; +import com.facebook.stetho.Stetho; +import com.facebook.stetho.okhttp.StethoInterceptor; +import com.squareup.okhttp.OkHttpClient; + +public class StethoShim { + public static void initializeWithDefaults(final Application application) { + Stetho.initializeWithDefaults(application); + } + + public static void addNetworkInterceptor(final OkHttpClient client) { + client.networkInterceptors().add(new StethoInterceptor()); + } +} diff --git a/Alkitab/src/main/java/yuku/alkitab/base/App.java b/Alkitab/src/main/java/yuku/alkitab/base/App.java index 2675ebfcd..02eb5c0d7 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/App.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/App.java @@ -26,6 +26,7 @@ import yuku.alkitabfeedback.FeedbackSender; import yuku.alkitabintegration.display.Launcher; import yuku.kirimfidbek.CrashReporter; +import yuku.stethoshim.StethoShim; import java.io.IOException; import java.lang.reflect.Field; @@ -44,11 +45,16 @@ enum OkHttpClientWrapper { OkHttpClient defaultClient = new OkHttpClient(); OkHttpClient longTimeoutClient = new OkHttpClient(); - { + { // init longTimeoutClient longTimeoutClient.setConnectTimeout(300, TimeUnit.SECONDS); longTimeoutClient.setReadTimeout(300, TimeUnit.SECONDS); longTimeoutClient.setWriteTimeout(600, TimeUnit.SECONDS); } + + { // init stetho interceptor + StethoShim.addNetworkInterceptor(defaultClient); + StethoShim.addNetworkInterceptor(longTimeoutClient); + } } enum GsonWrapper { @@ -95,6 +101,10 @@ public static OkHttpClient getLongTimeoutOkHttpClient() { { // LeakCanary, also we need the Application instance. LeakCanary.install(this); } + + { // Stetho call through proxy + StethoShim.initializeWithDefaults(this); + } } public synchronized static void staticInit() { diff --git a/Alkitab/src/release/java/yuku/stethoshim/StethoShim.java b/Alkitab/src/release/java/yuku/stethoshim/StethoShim.java new file mode 100644 index 000000000..a81032180 --- /dev/null +++ b/Alkitab/src/release/java/yuku/stethoshim/StethoShim.java @@ -0,0 +1,14 @@ +package yuku.stethoshim; + +import android.app.Application; +import com.squareup.okhttp.OkHttpClient; + +public class StethoShim { + public static void initializeWithDefaults(final Application application) { + // no-op + } + + public static void addNetworkInterceptor(final OkHttpClient client) { + // no-op + } +} From e7c1ce8662466deb6f722f3df27a597c46a19590 Mon Sep 17 00:00:00 2001 From: Yuku on yuku8 Date: Fri, 16 Oct 2015 12:22:14 +0800 Subject: [PATCH 02/62] Add user-agent header to all http requests for debugging --- Alkitab/src/main/java/yuku/alkitab/base/App.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Alkitab/src/main/java/yuku/alkitab/base/App.java b/Alkitab/src/main/java/yuku/alkitab/base/App.java index 02eb5c0d7..c60e7d9bc 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/App.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/App.java @@ -13,8 +13,10 @@ import com.google.gson.Gson; import com.squareup.leakcanary.LeakCanary; import com.squareup.okhttp.Call; +import com.squareup.okhttp.Interceptor; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; +import com.squareup.okhttp.internal.Version; import yuku.afw.storage.Preferences; import yuku.alkitab.base.model.SyncShadow; import yuku.alkitab.base.model.VersionImpl; @@ -45,6 +47,20 @@ enum OkHttpClientWrapper { OkHttpClient defaultClient = new OkHttpClient(); OkHttpClient longTimeoutClient = new OkHttpClient(); + { + final Interceptor userAgent = chain -> { + final Request originalRequest = chain.request(); + final Request requestWithUserAgent = originalRequest.newBuilder() + .removeHeader("User-Agent") + .addHeader("User-Agent", Version.userAgent() + " " + App.context.getPackageName() + "/" + App.getVersionName()) + .build(); + return chain.proceed(requestWithUserAgent); + }; + + defaultClient.networkInterceptors().add(userAgent); + longTimeoutClient.networkInterceptors().add(userAgent); + } + { // init longTimeoutClient longTimeoutClient.setConnectTimeout(300, TimeUnit.SECONDS); longTimeoutClient.setReadTimeout(300, TimeUnit.SECONDS); From d7175f554e2d10dea657ecb0cfc59192f1711901 Mon Sep 17 00:00:00 2001 From: Yuku on yuku8 Date: Fri, 16 Oct 2015 15:37:48 +0800 Subject: [PATCH 03/62] Update libraries --- Afw/build.gradle | 2 +- Alkitab/build.gradle | 19 +++++++++---------- AlkitabFeedback/build.gradle | 6 ++++-- AlkitabModel/build.gradle | 2 +- AmbilWarna/build.gradle | 4 +++- DragSortListView/build.gradle | 2 +- FileChooser/build.gradle | 2 +- build.gradle | 1 + .../example-imagesharer/app/build.gradle | 2 +- 9 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Afw/build.gradle b/Afw/build.gradle index e2ad8b6ab..3dd417853 100644 --- a/Afw/build.gradle +++ b/Afw/build.gradle @@ -23,5 +23,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-annotations:23.0.1' + compile 'com.android.support:support-annotations:23.1.0' } diff --git a/Alkitab/build.gradle b/Alkitab/build.gradle index 75a85082b..488738c88 100644 --- a/Alkitab/build.gradle +++ b/Alkitab/build.gradle @@ -45,12 +45,6 @@ android { } } -repositories { - maven { - url 'https://oss.sonatype.org/content/repositories/snapshots/' - } -} - dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':AlkitabFeedback') @@ -68,7 +62,7 @@ dependencies { compile project(':AmbilWarna') compile project(':FileChooser') compile project(':ImportedDesktopVerseUtil') - compile 'com.android.support:support-v4:23.0.1' + compile 'com.android.support:support-v4:23.1.0' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.okhttp:okhttp:2.5.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0' @@ -76,10 +70,15 @@ dependencies { compile 'com.google.code.gson:gson:2.3.1' compile 'com.google.android.gms:play-services-analytics:8.1.0' compile 'com.google.android.gms:play-services-gcm:8.1.0' - compile 'com.android.support:appcompat-v7:23.0.1' + compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.android.support:multidex:1.0.1' - compile 'com.afollestad:material-dialogs:0.7.6.0' - compile 'com.android.support:design:23.0.1' + compile('com.afollestad.material-dialogs:core:0.8.3.0@aar') { + transitive = true + } + compile('com.afollestad.material-dialogs:commons:0.8.3.0@aar') { + transitive = true + } + compile 'com.android.support:design:23.1.0' testCompile 'junit:junit:4.12' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' diff --git a/AlkitabFeedback/build.gradle b/AlkitabFeedback/build.gradle index 3087358ac..52db4e7de 100644 --- a/AlkitabFeedback/build.gradle +++ b/AlkitabFeedback/build.gradle @@ -29,8 +29,10 @@ repositories { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-v4:23.0.1' + compile 'com.android.support:support-v4:23.1.0' compile 'com.squareup.okhttp:okhttp:2.5.0' - compile 'com.afollestad:material-dialogs:0.7.6.0' + compile('com.afollestad.material-dialogs:core:0.8.3.0@aar') { + transitive = true + } compile project(':Afw') } diff --git a/AlkitabModel/build.gradle b/AlkitabModel/build.gradle index e2ad8b6ab..3dd417853 100644 --- a/AlkitabModel/build.gradle +++ b/AlkitabModel/build.gradle @@ -23,5 +23,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-annotations:23.0.1' + compile 'com.android.support:support-annotations:23.1.0' } diff --git a/AmbilWarna/build.gradle b/AmbilWarna/build.gradle index 00c8737db..f14ace29d 100644 --- a/AmbilWarna/build.gradle +++ b/AmbilWarna/build.gradle @@ -25,5 +25,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.afollestad:material-dialogs:0.7.6.0' + compile('com.afollestad.material-dialogs:core:0.8.3.0@aar') { + transitive = true + } } diff --git a/DragSortListView/build.gradle b/DragSortListView/build.gradle index e3e62aaec..7c26eeb17 100644 --- a/DragSortListView/build.gradle +++ b/DragSortListView/build.gradle @@ -25,5 +25,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-v4:23.0.1' + compile 'com.android.support:support-v4:23.1.0' } diff --git a/FileChooser/build.gradle b/FileChooser/build.gradle index 3b5cee745..da0c17527 100644 --- a/FileChooser/build.gradle +++ b/FileChooser/build.gradle @@ -24,5 +24,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':ATree') - compile 'com.android.support:appcompat-v7:23.0.1' + compile 'com.android.support:appcompat-v7:23.1.0' } diff --git a/build.gradle b/build.gradle index 51252e079..882b5cb02 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,7 @@ repositories { allprojects { repositories { jcenter() + maven { url "https://jitpack.io" } } } diff --git a/extensions/example-imagesharer/app/build.gradle b/extensions/example-imagesharer/app/build.gradle index 0b9bca9e7..2fa8909e0 100644 --- a/extensions/example-imagesharer/app/build.gradle +++ b/extensions/example-imagesharer/app/build.gradle @@ -21,5 +21,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23.0.1' + compile 'com.android.support:appcompat-v7:23.1.0' } From 973ec5d88cd7777790eed651deef6af537100d3d Mon Sep 17 00:00:00 2001 From: Yuku on yuku8 Date: Fri, 16 Oct 2015 16:38:18 +0800 Subject: [PATCH 04/62] target sdk = 23. Upgrade retrolambda --- build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 882b5cb02..dc4a9a907 100644 --- a/build.gradle +++ b/build.gradle @@ -7,13 +7,13 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:1.3.1' - classpath 'me.tatarka:gradle-retrolambda:3.2.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files } } +plugins { + id "me.tatarka.retrolambda" version "3.2.3" +} + // Required because retrolambda is on maven central repositories { mavenCentral() @@ -30,5 +30,5 @@ ext { compileSdkVersion = 23 buildToolsVersion = "23.0.1" minSdkVersion = 14 - targetSdkVersion = 22 + targetSdkVersion = 23 } From 20b50590b32872ec9406f412e1db2ea19e1a3a1d Mon Sep 17 00:00:00 2001 From: Yuku on yuku8 Date: Fri, 16 Oct 2015 16:39:06 +0800 Subject: [PATCH 05/62] Replace slidingtablayout with support design tablayout. Add up button and menu to not ask verse --- .../iosched/ui/widget/SlidingTabLayout.java | 321 ------------------ .../iosched/ui/widget/SlidingTabStrip.java | 167 --------- .../yuku/alkitab/base/ac/GotoActivity.java | 59 +++- .../alkitab/base/ac/VersionsActivity.java | 26 +- .../yuku/alkitab/base/storage/Prefkey.java | 6 + Alkitab/src/main/res/layout/activity_goto.xml | 14 +- .../src/main/res/layout/activity_versions.xml | 4 +- Alkitab/src/main/res/menu/activity_goto.xml | 10 + Alkitab/src/main/res/values/strings.xml | 1 + 9 files changed, 94 insertions(+), 514 deletions(-) delete mode 100644 Alkitab/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabLayout.java delete mode 100644 Alkitab/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabStrip.java create mode 100644 Alkitab/src/main/res/menu/activity_goto.xml diff --git a/Alkitab/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabLayout.java b/Alkitab/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabLayout.java deleted file mode 100644 index 6a8d436d9..000000000 --- a/Alkitab/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabLayout.java +++ /dev/null @@ -1,321 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.samples.apps.iosched.ui.widget; - -import android.content.Context; -import android.graphics.Typeface; -import android.support.v4.view.PagerAdapter; -import android.support.v4.view.ViewPager; -import android.util.AttributeSet; -import android.util.SparseArray; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.HorizontalScrollView; -import android.widget.LinearLayout; -import android.widget.TextView; - -/** - * To be used with ViewPager to provide a tab indicator component which give constant feedback as to - * the user's scroll progress. - *

- * To use the component, simply add it to your view hierarchy. Then in your - * {@link android.app.Activity} or {@link android.support.v4.app.Fragment} call - * {@link #setViewPager(ViewPager)} providing it the ViewPager this layout is being used for. - *

- * The colors can be customized in two ways. The first and simplest is to provide an array of colors - * via {@link #setSelectedIndicatorColors(int...)}. The - * alternative is via the {@link TabColorizer} interface which provides you complete control over - * which color is used for any individual position. - *

- * The views used as tabs can be customized by calling {@link #setCustomTabView(int, int)}, - * providing the layout ID of your custom layout. - */ -public class SlidingTabLayout extends HorizontalScrollView { - /** - * Allows complete control over the colors drawn in the tab layout. Set with - * {@link #setCustomTabColorizer(TabColorizer)}. - */ - public interface TabColorizer { - - /** - * @return return the color of the indicator used when {@code position} is selected. - */ - int getIndicatorColor(int position); - - } - - private static final int TITLE_OFFSET_DIPS = 24; - private static final int TAB_VIEW_PADDING_DIPS = 16; - private static final int TAB_VIEW_TEXT_SIZE_SP = 12; - - private int mTitleOffset; - - private int mTabViewLayoutId; - private int mTabViewTextViewId; - private boolean mDistributeEvenly; - - private ViewPager mViewPager; - private SparseArray mContentDescriptions = new SparseArray(); - private ViewPager.OnPageChangeListener mViewPagerPageChangeListener; - - private final SlidingTabStrip mTabStrip; - - public SlidingTabLayout(Context context) { - this(context, null); - } - - public SlidingTabLayout(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - - // Disable the Scroll Bar - setHorizontalScrollBarEnabled(false); - // Make sure that the Tab Strips fills this View - setFillViewport(true); - - mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density); - - mTabStrip = new SlidingTabStrip(context); - addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); - } - - /** - * Set the custom {@link TabColorizer} to be used. - * - * If you only require simple custmisation then you can use - * {@link #setSelectedIndicatorColors(int...)} to achieve - * similar effects. - */ - public void setCustomTabColorizer(TabColorizer tabColorizer) { - mTabStrip.setCustomTabColorizer(tabColorizer); - } - - public void setDistributeEvenly(boolean distributeEvenly) { - mDistributeEvenly = distributeEvenly; - } - - /** - * Sets the colors to be used for indicating the selected tab. These colors are treated as a - * circular array. Providing one color will mean that all tabs are indicated with the same color. - */ - public void setSelectedIndicatorColors(int... colors) { - mTabStrip.setSelectedIndicatorColors(colors); - } - - /** - * Set the {@link ViewPager.OnPageChangeListener}. When using {@link SlidingTabLayout} you are - * required to set any {@link ViewPager.OnPageChangeListener} through this method. This is so - * that the layout can update it's scroll position correctly. - * - * @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener) - */ - public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) { - mViewPagerPageChangeListener = listener; - } - - /** - * Set the custom layout to be inflated for the tab views. - * - * @param layoutResId Layout id to be inflated - * @param textViewId id of the {@link TextView} in the inflated view - */ - public void setCustomTabView(int layoutResId, int textViewId) { - mTabViewLayoutId = layoutResId; - mTabViewTextViewId = textViewId; - } - - /** - * Sets the associated view pager. Note that the assumption here is that the pager content - * (number of tabs and tab titles) does not change after this call has been made. - */ - public void setViewPager(ViewPager viewPager) { - mTabStrip.removeAllViews(); - - mViewPager = viewPager; - if (viewPager != null) { - viewPager.setOnPageChangeListener(new InternalViewPagerListener()); - populateTabStrip(); - } - } - - /** - * Create a default view to be used for tabs. This is called if a custom tab view is not set via - * {@link #setCustomTabView(int, int)}. - */ - protected TextView createDefaultTabView(Context context) { - TextView textView = new TextView(context); - textView.setGravity(Gravity.CENTER); - textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); - textView.setTypeface(Typeface.DEFAULT_BOLD); - textView.setLayoutParams(new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - - TypedValue outValue = new TypedValue(); - getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, - outValue, true); - textView.setBackgroundResource(outValue.resourceId); - textView.setAllCaps(true); - - int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); - textView.setPadding(padding, padding, padding, padding); - - return textView; - } - - private void populateTabStrip() { - final PagerAdapter adapter = mViewPager.getAdapter(); - final View.OnClickListener tabClickListener = new TabClickListener(); - - for (int i = 0; i < adapter.getCount(); i++) { - View tabView = null; - TextView tabTitleView = null; - - if (mTabViewLayoutId != 0) { - // If there is a custom tab view layout id set, try and inflate it - tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, - false); - tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); - } - - if (tabView == null) { - tabView = createDefaultTabView(getContext()); - } - - if (tabTitleView == null && TextView.class.isInstance(tabView)) { - tabTitleView = (TextView) tabView; - } - - if (mDistributeEvenly) { - LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); - lp.width = 0; - lp.weight = 1; - } - - tabTitleView.setText(adapter.getPageTitle(i)); - tabView.setOnClickListener(tabClickListener); - String desc = mContentDescriptions.get(i, null); - if (desc != null) { - tabView.setContentDescription(desc); - } - - mTabStrip.addView(tabView); - if (i == mViewPager.getCurrentItem()) { - tabView.setSelected(true); - } - } - } - - public void setContentDescription(int i, String desc) { - mContentDescriptions.put(i, desc); - } - - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - - if (mViewPager != null) { - scrollToTab(mViewPager.getCurrentItem(), 0); - } - } - - private void scrollToTab(int tabIndex, int positionOffset) { - final int tabStripChildCount = mTabStrip.getChildCount(); - if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) { - return; - } - - View selectedChild = mTabStrip.getChildAt(tabIndex); - if (selectedChild != null) { - int targetScrollX = selectedChild.getLeft() + positionOffset; - - if (tabIndex > 0 || positionOffset > 0) { - // If we're not at the first child and are mid-scroll, make sure we obey the offset - targetScrollX -= mTitleOffset; - } - - scrollTo(targetScrollX, 0); - } - } - - private class InternalViewPagerListener implements ViewPager.OnPageChangeListener { - private int mScrollState; - - @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - int tabStripChildCount = mTabStrip.getChildCount(); - if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) { - return; - } - - mTabStrip.onViewPagerPageChanged(position, positionOffset); - - View selectedTitle = mTabStrip.getChildAt(position); - int extraOffset = (selectedTitle != null) - ? (int) (positionOffset * selectedTitle.getWidth()) - : 0; - scrollToTab(position, extraOffset); - - if (mViewPagerPageChangeListener != null) { - mViewPagerPageChangeListener.onPageScrolled(position, positionOffset, - positionOffsetPixels); - } - } - - @Override - public void onPageScrollStateChanged(int state) { - mScrollState = state; - - if (mViewPagerPageChangeListener != null) { - mViewPagerPageChangeListener.onPageScrollStateChanged(state); - } - } - - @Override - public void onPageSelected(int position) { - if (mScrollState == ViewPager.SCROLL_STATE_IDLE) { - mTabStrip.onViewPagerPageChanged(position, 0f); - scrollToTab(position, 0); - } - for (int i = 0; i < mTabStrip.getChildCount(); i++) { - mTabStrip.getChildAt(i).setSelected(position == i); - } - if (mViewPagerPageChangeListener != null) { - mViewPagerPageChangeListener.onPageSelected(position); - } - } - - } - - private class TabClickListener implements View.OnClickListener { - @Override - public void onClick(View v) { - for (int i = 0; i < mTabStrip.getChildCount(); i++) { - if (v == mTabStrip.getChildAt(i)) { - mViewPager.setCurrentItem(i); - return; - } - } - } - } - -} \ No newline at end of file diff --git a/Alkitab/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabStrip.java b/Alkitab/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabStrip.java deleted file mode 100644 index c391593b3..000000000 --- a/Alkitab/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabStrip.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2014 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.samples.apps.iosched.ui.widget; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.util.AttributeSet; -import android.util.TypedValue; -import android.view.View; -import android.widget.LinearLayout; - -class SlidingTabStrip extends LinearLayout { - - private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 0; - private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26; - private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 3; - private static final int DEFAULT_SELECTED_INDICATOR_COLOR = 0xFF33B5E5; - - private final int mBottomBorderThickness; - private final Paint mBottomBorderPaint; - - private final int mSelectedIndicatorThickness; - private final Paint mSelectedIndicatorPaint; - - private final int mDefaultBottomBorderColor; - - private int mSelectedPosition; - private float mSelectionOffset; - - private SlidingTabLayout.TabColorizer mCustomTabColorizer; - private final SimpleTabColorizer mDefaultTabColorizer; - - SlidingTabStrip(Context context) { - this(context, null); - } - - SlidingTabStrip(Context context, AttributeSet attrs) { - super(context, attrs); - setWillNotDraw(false); - - final float density = getResources().getDisplayMetrics().density; - - TypedValue outValue = new TypedValue(); - context.getTheme().resolveAttribute(android.R.attr.colorForeground, outValue, true); - final int themeForegroundColor = outValue.data; - - mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor, - DEFAULT_BOTTOM_BORDER_COLOR_ALPHA); - - mDefaultTabColorizer = new SimpleTabColorizer(); - mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR); - - mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density); - mBottomBorderPaint = new Paint(); - mBottomBorderPaint.setColor(mDefaultBottomBorderColor); - - mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density); - mSelectedIndicatorPaint = new Paint(); - } - - void setCustomTabColorizer(SlidingTabLayout.TabColorizer customTabColorizer) { - mCustomTabColorizer = customTabColorizer; - invalidate(); - } - - void setSelectedIndicatorColors(int... colors) { - // Make sure that the custom colorizer is removed - mCustomTabColorizer = null; - mDefaultTabColorizer.setIndicatorColors(colors); - invalidate(); - } - - void onViewPagerPageChanged(int position, float positionOffset) { - mSelectedPosition = position; - mSelectionOffset = positionOffset; - invalidate(); - } - - @Override - protected void onDraw(Canvas canvas) { - final int height = getHeight(); - final int childCount = getChildCount(); - final SlidingTabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null - ? mCustomTabColorizer - : mDefaultTabColorizer; - - // Thick colored underline below the current selection - if (childCount > 0) { - View selectedTitle = getChildAt(mSelectedPosition); - int left = selectedTitle.getLeft(); - int right = selectedTitle.getRight(); - int color = tabColorizer.getIndicatorColor(mSelectedPosition); - - if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) { - int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1); - if (color != nextColor) { - color = blendColors(nextColor, color, mSelectionOffset); - } - - // Draw the selection partway between the tabs - View nextTitle = getChildAt(mSelectedPosition + 1); - left = (int) (mSelectionOffset * nextTitle.getLeft() + - (1.0f - mSelectionOffset) * left); - right = (int) (mSelectionOffset * nextTitle.getRight() + - (1.0f - mSelectionOffset) * right); - } - - mSelectedIndicatorPaint.setColor(color); - - canvas.drawRect(left, height - mSelectedIndicatorThickness, right, - height, mSelectedIndicatorPaint); - } - - // Thin underline along the entire bottom edge - canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint); - } - - /** - * Set the alpha value of the {@code color} to be the given {@code alpha} value. - */ - private static int setColorAlpha(int color, byte alpha) { - return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)); - } - - /** - * Blend {@code color1} and {@code color2} using the given ratio. - * - * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend, - * 0.0 will return {@code color2}. - */ - private static int blendColors(int color1, int color2, float ratio) { - final float inverseRation = 1f - ratio; - float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation); - float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation); - float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation); - return Color.rgb((int) r, (int) g, (int) b); - } - - private static class SimpleTabColorizer implements SlidingTabLayout.TabColorizer { - private int[] mIndicatorColors; - - @Override - public final int getIndicatorColor(int position) { - return mIndicatorColors[position % mIndicatorColors.length]; - } - - void setIndicatorColors(int... colors) { - mIndicatorColors = colors; - } - } -} \ No newline at end of file diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/GotoActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/GotoActivity.java index def836527..4f0b56324 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/GotoActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/GotoActivity.java @@ -2,13 +2,17 @@ import android.content.Intent; import android.os.Bundle; +import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; +import android.support.v7.app.ActionBar; +import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; -import com.google.samples.apps.iosched.ui.widget.SlidingTabLayout; import yuku.afw.App; import yuku.afw.V; import yuku.afw.storage.Preferences; @@ -16,11 +20,11 @@ import yuku.alkitab.base.fr.GotoDialerFragment; import yuku.alkitab.base.fr.GotoDirectFragment; import yuku.alkitab.base.fr.GotoGridFragment; -import yuku.alkitab.base.fr.base.BaseGotoFragment.GotoFinishListener; +import yuku.alkitab.base.fr.base.BaseGotoFragment; import yuku.alkitab.base.storage.Prefkey; import yuku.alkitab.debug.R; -public class GotoActivity extends BaseActivity implements GotoFinishListener { +public class GotoActivity extends BaseActivity implements BaseGotoFragment.GotoFinishListener { public static final String TAG = GotoActivity.class.getSimpleName(); private static final String EXTRA_bookId = "bookId"; @@ -51,8 +55,9 @@ public static Result obtainResult(Intent data) { return res; } + Toolbar toolbar; ViewPager viewPager; - SlidingTabLayout slidingTabs; + TabLayout tablayout; GotoPagerAdapter pagerAdapter; boolean okToHideKeyboard = false; @@ -69,10 +74,19 @@ public static Result obtainResult(Intent data) { chapter_1 = getIntent().getIntExtra(EXTRA_chapter, 0); verse_1 = getIntent().getIntExtra(EXTRA_verse, 0); + toolbar = V.get(this, R.id.toolbar); + setSupportActionBar(toolbar); + final ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayShowTitleEnabled(false); + actionBar.setDisplayHomeAsUpEnabled(true); + toolbar.setNavigationOnClickListener(v -> navigateUp()); + } + // ViewPager and its adapters use support library fragments, so use getSupportFragmentManager. viewPager = V.get(this, R.id.viewPager); viewPager.setAdapter(pagerAdapter = new GotoPagerAdapter(getSupportFragmentManager())); - viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { if (okToHideKeyboard && position != 1) { @@ -86,9 +100,11 @@ public void onPageSelected(int position) { } }); - slidingTabs = V.get(this, R.id.sliding_tabs); - slidingTabs.setCustomTabColorizer(position -> getResources().getColor(R.color.accent)); - slidingTabs.setViewPager(viewPager); + tablayout = V.get(this, R.id.tablayout); + tablayout.setTabMode(TabLayout.MODE_SCROLLABLE); + tablayout.setTabsFromPagerAdapter(pagerAdapter); + tablayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager)); + viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout)); if (savedInstanceState == null) { // get from preferences @@ -114,6 +130,33 @@ public void onPageSelected(int position) { } } + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + getMenuInflater().inflate(R.menu.activity_goto, menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(final Menu menu) { + final MenuItem menuAskForVerse = menu.findItem(R.id.menuAskForVerse); + final boolean val = Preferences.getBoolean(Prefkey.gotoAskForVerse, Prefkey.GOTO_ASK_FOR_VERSE_DEFAULT); + menuAskForVerse.setChecked(val); + + return true; + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + if (item.getItemId() == R.id.menuAskForVerse) { + final boolean val = Preferences.getBoolean(Prefkey.gotoAskForVerse, Prefkey.GOTO_ASK_FOR_VERSE_DEFAULT); + Preferences.setBoolean(Prefkey.gotoAskForVerse, !val); + supportInvalidateOptionsMenu(); + return true; + } + + return super.onOptionsItemSelected(item); + } + @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(INSTANCE_STATE_tab, viewPager.getCurrentItem()); diff --git a/Alkitab/src/main/java/yuku/alkitab/base/ac/VersionsActivity.java b/Alkitab/src/main/java/yuku/alkitab/base/ac/VersionsActivity.java index def9e3431..9bd6892fb 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/ac/VersionsActivity.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/ac/VersionsActivity.java @@ -15,6 +15,7 @@ import android.os.Environment; import android.provider.MediaStore; import android.provider.Settings; +import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; @@ -45,7 +46,6 @@ import android.widget.Toast; import com.afollestad.materialdialogs.AlertDialogWrapper; import com.afollestad.materialdialogs.MaterialDialog; -import com.google.samples.apps.iosched.ui.widget.SlidingTabLayout; import com.mobeta.android.dslv.DragSortController; import com.mobeta.android.dslv.DragSortListView; import yuku.afw.V; @@ -102,10 +102,10 @@ public class VersionsActivity extends BaseActivity { private static final int REQCODE_openFile = 1; - SectionsPagerAdapter mSectionsPagerAdapter; + SectionsPagerAdapter sectionsPagerAdapter; - ViewPager mViewPager; - SlidingTabLayout slidingTabs; + ViewPager viewPager; + TabLayout tablayout; String query_text; public static Intent createIntent() { @@ -126,15 +126,17 @@ protected void onCreate(Bundle savedInstanceState) { // Create the adapter that will return a fragment for each of the three // primary sections of the activity. - mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); + sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. - mViewPager = V.get(this, R.id.viewPager); - mViewPager.setAdapter(mSectionsPagerAdapter); + viewPager = V.get(this, R.id.viewPager); + viewPager.setAdapter(sectionsPagerAdapter); - slidingTabs = V.get(this, R.id.sliding_tabs); - slidingTabs.setCustomTabColorizer(position -> getResources().getColor(R.color.accent)); - slidingTabs.setViewPager(mViewPager); + tablayout = V.get(this, R.id.tablayout); + tablayout.setTabMode(TabLayout.MODE_SCROLLABLE); + tablayout.setTabsFromPagerAdapter(sectionsPagerAdapter); + tablayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager)); + viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout)); processIntent(getIntent(), "onCreate"); @@ -164,7 +166,7 @@ private void checkAndProcessOpenFileIntent(Intent intent) { if (!U.equals(intent.getAction(), Intent.ACTION_VIEW)) return; // we are trying to open a file, so let's go to the DOWNLOADED tab, as it is more relevant. - mViewPager.setCurrentItem(1); + viewPager.setCurrentItem(1); Uri uri = intent.getData(); @@ -658,7 +660,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } // we are trying to open a file, so let's go to the DOWNLOADED tab, as it is more relevant. - mViewPager.setCurrentItem(1); + viewPager.setCurrentItem(1); final String filename = result.firstFilename; diff --git a/Alkitab/src/main/java/yuku/alkitab/base/storage/Prefkey.java b/Alkitab/src/main/java/yuku/alkitab/base/storage/Prefkey.java index 0a3b51454..095137570 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/storage/Prefkey.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/storage/Prefkey.java @@ -125,4 +125,10 @@ public enum Prefkey { /** Current reading vars */ current_reading_ari_start, current_reading_ari_end, + + /** Option to ask for verse number in goto screen */ + gotoAskForVerse, + ; + + public static final boolean GOTO_ASK_FOR_VERSE_DEFAULT = true; } diff --git a/Alkitab/src/main/res/layout/activity_goto.xml b/Alkitab/src/main/res/layout/activity_goto.xml index 366f9066d..1842cd04b 100644 --- a/Alkitab/src/main/res/layout/activity_goto.xml +++ b/Alkitab/src/main/res/layout/activity_goto.xml @@ -4,11 +4,17 @@ android:layout_height="match_parent" android:orientation="vertical"> - + android:layout_height="wrap_content"> + + + + - diff --git a/Alkitab/src/main/res/menu/activity_goto.xml b/Alkitab/src/main/res/menu/activity_goto.xml new file mode 100644 index 000000000..5e4bdc419 --- /dev/null +++ b/Alkitab/src/main/res/menu/activity_goto.xml @@ -0,0 +1,10 @@ + +

+ + + \ No newline at end of file diff --git a/Alkitab/src/main/res/values/strings.xml b/Alkitab/src/main/res/values/strings.xml index 84b844648..053925213 100644 --- a/Alkitab/src/main/res/values/strings.xml +++ b/Alkitab/src/main/res/values/strings.xml @@ -206,6 +206,7 @@ Dialer Direct Grid + Ask for verse number Font Manager From a83f0225f44f7ae00d354ec995be1e2aea00d083 Mon Sep 17 00:00:00 2001 From: Yuku on yuku8 Date: Fri, 16 Oct 2015 18:10:18 +0800 Subject: [PATCH 06/62] Revamp goto keypad measurements --- Alkitab/build.gradle | 1 + .../alkitab/base/fr/GotoDialerFragment.java | 115 +++------ ..._backspace.png => ic_keypad_backspace.png} | Bin ..._backspace.png => ic_keypad_backspace.png} | Bin ..._backspace.png => ic_keypad_backspace.png} | Bin ..._backspace.png => ic_keypad_backspace.png} | Bin .../main/res/drawable/goto_dialer_active.xml | 2 +- .../res/layout-land/fragment_goto_dialer.xml | 234 ++++++++++++++---- Alkitab/src/main/res/layout-land/keypad.xml | 129 ---------- .../src/main/res/layout-small-port/keypad.xml | 153 ------------ .../main/res/layout-sw360dp-port/keypad.xml | 154 ------------ Alkitab/src/main/res/layout/activity_goto.xml | 4 +- .../src/main/res/layout/activity_versions.xml | 4 +- Alkitab/src/main/res/layout/buttonbar_ok.xml | 2 +- .../main/res/layout/fragment_goto_dialer.xml | 218 ++++++++++++---- Alkitab/src/main/res/layout/keypad.xml | 152 ------------ .../src/main/res/layout/left_drawer_songs.xml | 2 +- Alkitab/src/main/res/values/styles.xml | 9 + 18 files changed, 412 insertions(+), 767 deletions(-) rename Alkitab/src/main/res/drawable-hdpi/{ic_song_keypad_backspace.png => ic_keypad_backspace.png} (100%) rename Alkitab/src/main/res/drawable-mdpi/{ic_song_keypad_backspace.png => ic_keypad_backspace.png} (100%) rename Alkitab/src/main/res/drawable-xhdpi/{ic_song_keypad_backspace.png => ic_keypad_backspace.png} (100%) rename Alkitab/src/main/res/drawable-xxhdpi/{ic_song_keypad_backspace.png => ic_keypad_backspace.png} (100%) delete mode 100644 Alkitab/src/main/res/layout-land/keypad.xml delete mode 100644 Alkitab/src/main/res/layout-small-port/keypad.xml delete mode 100644 Alkitab/src/main/res/layout-sw360dp-port/keypad.xml delete mode 100644 Alkitab/src/main/res/layout/keypad.xml create mode 100644 Alkitab/src/main/res/values/styles.xml diff --git a/Alkitab/build.gradle b/Alkitab/build.gradle index 488738c88..ff2029dd2 100644 --- a/Alkitab/build.gradle +++ b/Alkitab/build.gradle @@ -79,6 +79,7 @@ dependencies { transitive = true } compile 'com.android.support:design:23.1.0' + compile 'com.android.support:percent:23.1.0' testCompile 'junit:junit:4.12' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' diff --git a/Alkitab/src/main/java/yuku/alkitab/base/fr/GotoDialerFragment.java b/Alkitab/src/main/java/yuku/alkitab/base/fr/GotoDialerFragment.java index 5a53ccf8a..ff3749621 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/fr/GotoDialerFragment.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/fr/GotoDialerFragment.java @@ -1,17 +1,13 @@ package yuku.alkitab.base.fr; -import android.os.Build; import android.os.Bundle; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.ViewTreeObserver; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.CheckedTextView; -import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; import yuku.afw.App; @@ -27,9 +23,9 @@ public class GotoDialerFragment extends BaseGotoFragment { public static final String TAG = GotoDialerFragment.class.getSimpleName(); - private static final String EXTRA_verse = "verse"; //$NON-NLS-1$ - private static final String EXTRA_chapter = "chapter"; //$NON-NLS-1$ - private static final String EXTRA_bookId = "bookId"; //$NON-NLS-1$ + private static final String EXTRA_verse = "verse"; + private static final String EXTRA_chapter = "chapter"; + private static final String EXTRA_bookId = "bookId"; TextView active; TextView passive; @@ -102,29 +98,7 @@ public static Bundle createArgs(int bookId, int chapter_1, int verse_1) { V.get(res, R.id.bDigit7).setOnClickListener(button_click); V.get(res, R.id.bDigit8).setOnClickListener(button_click); V.get(res, R.id.bDigit9).setOnClickListener(button_click); - V.get(res, R.id.bDigitC).setOnClickListener(button_click); - V.get(res, R.id.bDigitSwitch).setOnClickListener(button_click); - - // if the scrolled content height is not more than the available space, remove the gravity - final View scrollRoot = V.get(res, R.id.scrollRoot); - scrollRoot.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - final ScrollView.LayoutParams lp = (ScrollView.LayoutParams) scrollRoot.getLayoutParams(); - final int contentHeight = scrollRoot.getMeasuredHeight(); - final int containerHeight = res.getMeasuredHeight(); - lp.gravity = contentHeight <= containerHeight ? Gravity.CENTER_VERTICAL : Gravity.NO_GRAVITY; - scrollRoot.setLayoutParams(lp); - - if (Build.VERSION.SDK_INT >= 16) { - scrollRoot.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } else { - // what!? Deprecated because of typo!? - //noinspection deprecation - scrollRoot.getViewTreeObserver().removeGlobalOnLayoutListener(this); - } - } - }); + V.get(res, R.id.bDigitBackspace).setOnClickListener(button_click); return res; } @@ -152,22 +126,20 @@ public void onItemSelected(AdapterView parent, View view, int position, long } }); - bOk.setOnClickListener(new View.OnClickListener() { - @Override public void onClick(View v) { - int chapter = 0; - int verse = 0; + bOk.setOnClickListener(v -> { + int chapter = 0; + int verse = 0; - try { - chapter = Integer.parseInt(tChapter.getText().toString()); - verse = Integer.parseInt(tVerse.getText().toString()); - } catch (NumberFormatException e) { - // let it still be 0 - } + try { + chapter = Integer.parseInt(tChapter.getText().toString()); + verse = Integer.parseInt(tVerse.getText().toString()); + } catch (NumberFormatException e) { + // let it still be 0 + } - int bookId = adapter.getItem(cbBook.getSelectedItemPosition()).bookId; + int bookId1 = adapter.getItem(cbBook.getSelectedItemPosition()).bookId; - ((GotoFinishListener) getActivity()).onGotoFinished(GotoFinishListener.GOTO_TAB_dialer, bookId, chapter, verse); - } + ((GotoFinishListener) getActivity()).onGotoFinished(GotoFinishListener.GOTO_TAB_dialer, bookId1, chapter, verse); }); active = tChapter; @@ -197,42 +169,24 @@ public void onItemSelected(AdapterView parent, View view, int position, long } }; - View.OnClickListener button_click = new View.OnClickListener() { - @Override public void onClick(View v) { - int id = v.getId(); - if (id == R.id.bDigit0) press("0"); //$NON-NLS-1$ - if (id == R.id.bDigit1) press("1"); //$NON-NLS-1$ - if (id == R.id.bDigit2) press("2"); //$NON-NLS-1$ - if (id == R.id.bDigit3) press("3"); //$NON-NLS-1$ - if (id == R.id.bDigit4) press("4"); //$NON-NLS-1$ - if (id == R.id.bDigit5) press("5"); //$NON-NLS-1$ - if (id == R.id.bDigit6) press("6"); //$NON-NLS-1$ - if (id == R.id.bDigit7) press("7"); //$NON-NLS-1$ - if (id == R.id.bDigit8) press("8"); //$NON-NLS-1$ - if (id == R.id.bDigit9) press("9"); //$NON-NLS-1$ - if (id == R.id.bDigitC) press("C"); //$NON-NLS-1$ - if (id == R.id.bDigitSwitch) press(":"); //$NON-NLS-1$ - } + View.OnClickListener button_click = v -> { + int id = v.getId(); + if (id == R.id.bDigit0) press("0"); + if (id == R.id.bDigit1) press("1"); + if (id == R.id.bDigit2) press("2"); + if (id == R.id.bDigit3) press("3"); + if (id == R.id.bDigit4) press("4"); + if (id == R.id.bDigit5) press("5"); + if (id == R.id.bDigit6) press("6"); + if (id == R.id.bDigit7) press("7"); + if (id == R.id.bDigit8) press("8"); + if (id == R.id.bDigit9) press("9"); + if (id == R.id.bDigitBackspace) press("backspace"); }; - -// TODO (move to activity to support keyboard) @Override public boolean onKeyDown(int keyCode, KeyEvent event) { -// if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9) { -// pencet(String.valueOf((char) ('0' + keyCode - KeyEvent.KEYCODE_0))); -// return true; -// } else if (keyCode == KeyEvent.KEYCODE_STAR) { -// pencet("C"); //$NON-NLS-1$ -// return true; -// } else if (keyCode == KeyEvent.KEYCODE_POUND) { -// pencet(":"); //$NON-NLS-1$ -// return true; -// } -// -// return super.onKeyDown(keyCode, event); -// } int tryReadChapter() { try { - return Integer.parseInt("0" + tChapter.getText().toString()); //$NON-NLS-1$ + return Integer.parseInt("0" + tChapter.getText().toString()); } catch (NumberFormatException e) { return 0; } @@ -240,7 +194,7 @@ int tryReadChapter() { int tryReadVerse() { try { - return Integer.parseInt("0" + tVerse.getText().toString()); //$NON-NLS-1$ + return Integer.parseInt("0" + tVerse.getText().toString()); } catch (NumberFormatException e) { return 0; } @@ -272,13 +226,8 @@ void fixChapterOverflow() { void press(String s) { if (active != null) { - if (s.equals("C")) { //$NON-NLS-1$ - active.setText(""); //$NON-NLS-1$ - return; - } else if (s.equals(":")) { //$NON-NLS-1$ - if (passive != null) { - activate(passive, active); - } + if (s.equals("backspace")) { + active.setText(""); // TODO make it backspace return; } diff --git a/Alkitab/src/main/res/drawable-hdpi/ic_song_keypad_backspace.png b/Alkitab/src/main/res/drawable-hdpi/ic_keypad_backspace.png similarity index 100% rename from Alkitab/src/main/res/drawable-hdpi/ic_song_keypad_backspace.png rename to Alkitab/src/main/res/drawable-hdpi/ic_keypad_backspace.png diff --git a/Alkitab/src/main/res/drawable-mdpi/ic_song_keypad_backspace.png b/Alkitab/src/main/res/drawable-mdpi/ic_keypad_backspace.png similarity index 100% rename from Alkitab/src/main/res/drawable-mdpi/ic_song_keypad_backspace.png rename to Alkitab/src/main/res/drawable-mdpi/ic_keypad_backspace.png diff --git a/Alkitab/src/main/res/drawable-xhdpi/ic_song_keypad_backspace.png b/Alkitab/src/main/res/drawable-xhdpi/ic_keypad_backspace.png similarity index 100% rename from Alkitab/src/main/res/drawable-xhdpi/ic_song_keypad_backspace.png rename to Alkitab/src/main/res/drawable-xhdpi/ic_keypad_backspace.png diff --git a/Alkitab/src/main/res/drawable-xxhdpi/ic_song_keypad_backspace.png b/Alkitab/src/main/res/drawable-xxhdpi/ic_keypad_backspace.png similarity index 100% rename from Alkitab/src/main/res/drawable-xxhdpi/ic_song_keypad_backspace.png rename to Alkitab/src/main/res/drawable-xxhdpi/ic_keypad_backspace.png diff --git a/Alkitab/src/main/res/drawable/goto_dialer_active.xml b/Alkitab/src/main/res/drawable/goto_dialer_active.xml index 3848a810a..cd8d82c87 100644 --- a/Alkitab/src/main/res/drawable/goto_dialer_active.xml +++ b/Alkitab/src/main/res/drawable/goto_dialer_active.xml @@ -1,6 +1,6 @@ + android:shape="oval"> diff --git a/Alkitab/src/main/res/layout-land/fragment_goto_dialer.xml b/Alkitab/src/main/res/layout-land/fragment_goto_dialer.xml index 047f561d6..1ae03362a 100644 --- a/Alkitab/src/main/res/layout-land/fragment_goto_dialer.xml +++ b/Alkitab/src/main/res/layout-land/fragment_goto_dialer.xml @@ -1,74 +1,222 @@ - + android:layout_height="wrap_content" + android:gravity="center_horizontal" + android:orientation="vertical"> - + + - + + + android:layout_gravity="center" + tools:listitem="@android:layout/simple_spinner_dropdown_item" + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp"/> + + + + + + + android:textSize="24sp" + tools:text="123" /> + android:layout_height="fill_parent" + android:layout_marginLeft="16dp" + android:layout_marginRight="8dp" + android:gravity="center_vertical" + android:text="@string/ayat_sebelumangka" /> + android:textSize="24sp" + tools:text="123" /> - - + android:layout_height="1dp" + android:layout_gravity="bottom" + android:layout_marginLeft="32dp" + android:layout_marginRight="32dp" + android:src="#1effffff" /> + + + + + + + +