Skip to content
This repository was archived by the owner on Dec 1, 2017. It is now read-only.

upgrade sample into sdk 23 #245

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
}
}

8 changes: 4 additions & 4 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ repositories {
}

dependencies {
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
}

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileSdkVersion 23
buildToolsVersion '23.0.2'
resourcePrefix 'twowayview_'

defaultConfig {
minSdkVersion 10
targetSdkVersion 21
targetSdkVersion 23
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class ClickItemTouchListener implements OnItemTouchListener {
private final GestureDetectorCompat mGestureDetector;

ClickItemTouchListener(RecyclerView hostView) {
mGestureDetector = new ItemClickGestureDetector(hostView.getContext(),
mGestureDetector = new GestureDetectorCompat(hostView.getContext(),
new ItemClickGestureListener(hostView));
}

Expand Down Expand Up @@ -51,7 +51,7 @@ public void onTouchEvent(RecyclerView recyclerView, MotionEvent event) {
abstract boolean performItemClick(RecyclerView parent, View view, int position, long id);
abstract boolean performItemLongClick(RecyclerView parent, View view, int position, long id);

private class ItemClickGestureDetector extends GestureDetectorCompat {
/*private class ItemClickGestureDetector extends GestureDetectorCompat {
private final ItemClickGestureListener mGestureListener;

public ItemClickGestureDetector(Context context, ItemClickGestureListener listener) {
Expand All @@ -70,7 +70,7 @@ public boolean onTouchEvent(MotionEvent event) {

return handled;
}
}
}*/

private class ItemClickGestureListener extends SimpleOnGestureListener {
private final RecyclerView mHostView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,10 @@ boolean performItemLongClick(RecyclerView parent, View view, int position, long

return false;
}

@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -527,5 +527,10 @@ boolean performItemClick(RecyclerView parent, View view, int position, long id)
boolean performItemLongClick(RecyclerView parent, View view, int position, long id) {
return true;
}

@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

}
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Jan 31 22:57:10 GMT 2015
#Mon Feb 29 15:18:23 GMT+08:00 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
8 changes: 4 additions & 4 deletions layouts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ repositories {
}

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileSdkVersion 23
buildToolsVersion '23.0.2'
resourcePrefix 'twowayview_'

defaultConfig {
minSdkVersion 10
targetSdkVersion 21
targetSdkVersion 23
}
}

dependencies {
compile project(':core')
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
}

apply from: "${rootDir}/gradle/scripts/gradle-mvn-push.gradle"
13 changes: 8 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ repositories {
}

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 10
targetSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
productFlavors {
}
}

dependencies {
compile project(':core')
compile project(':layouts')
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
}
2 changes: 1 addition & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<application android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
android:theme="@style/NoActionBarTheme">

<activity android:name=".MainActivity" >
<intent-filter>
Expand Down
98 changes: 54 additions & 44 deletions sample/src/main/java/org/lucasr/twowayview/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,63 @@
package org.lucasr.twowayview.sample;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends ActionBarActivity {
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
private final String ARG_SELECTED_LAYOUT_ID = "selectedLayoutId";

private final int DEFAULT_LAYOUT = R.layout.layout_list;

private int mSelectedLayoutId;

private TabLayout mTabLayout;
private ViewPager mViewPager;

private int[] mIconArray = {
R.drawable.ic_list,
R.drawable.ic_grid,
R.drawable.ic_staggered,
R.drawable.ic_spannable
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.tabs_layout);

ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
mTabLayout = (TabLayout) findViewById(R.id.tabs);
mViewPager = (ViewPager) findViewById(R.id.pagers);

mSelectedLayoutId = DEFAULT_LAYOUT;
if (savedInstanceState != null) {
mSelectedLayoutId = savedInstanceState.getInt(ARG_SELECTED_LAYOUT_ID);
}

addLayoutTab(
actionBar, R.layout.layout_list, R.drawable.ic_list, "list");
addLayoutTab(
actionBar, R.layout.layout_grid, R.drawable.ic_grid, "grid");
addLayoutTab(
actionBar, R.layout.layout_staggered_grid, R.drawable.ic_staggered, "staggered");
addLayoutTab(
actionBar, R.layout.layout_spannable_grid, R.drawable.ic_spannable, "spannable");
CustomeFragmentAdapter adapter = new CustomeFragmentAdapter(getSupportFragmentManager());
adapter.addFragment(LayoutFragment.newInstance(R.layout.layout_list), "list");
adapter.addFragment(LayoutFragment.newInstance(R.layout.layout_grid), "grid");
adapter.addFragment(LayoutFragment.newInstance(R.layout.layout_staggered_grid), "staggered");
adapter.addFragment(LayoutFragment.newInstance(R.layout.layout_spannable_grid), "spannable");

mViewPager.setAdapter(adapter);

mTabLayout.setupWithViewPager(mViewPager);

int count = mTabLayout.getTabCount();

for (int i = 0; i < count; i++) {
mTabLayout.getTabAt(i).setText(null);
mTabLayout.getTabAt(i).setIcon(mIconArray[i]);
}
}

@Override
Expand All @@ -59,46 +82,33 @@ protected void onSaveInstanceState(Bundle outState) {
outState.putInt(ARG_SELECTED_LAYOUT_ID, mSelectedLayoutId);
}

private void addLayoutTab(ActionBar actionBar, int layoutId, int iconId, String tag) {
ActionBar.Tab tab = actionBar.newTab()
.setText("")
.setIcon(iconId)
.setTabListener(new TabListener(layoutId, tag));
actionBar.addTab(tab, layoutId == mSelectedLayoutId);
}
public class CustomeFragmentAdapter extends FragmentPagerAdapter {

public class TabListener implements ActionBar.TabListener {
private LayoutFragment mFragment;
private final int mLayoutId;
private final String mTag;
private final List<Fragment> mFragments = new ArrayList<>();
private final List<String> mFragmentTitles = new ArrayList<>();

public CustomeFragmentAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
}

public TabListener(int layoutId, String tag) {
mLayoutId = layoutId;
mTag = tag;
public void addFragment(Fragment fragment, String title) {
mFragments.add(fragment);
mFragmentTitles.add(title);
}

@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
mFragment = (LayoutFragment) getSupportFragmentManager().findFragmentByTag(mTag);
if (mFragment == null) {
mFragment = (LayoutFragment) LayoutFragment.newInstance(mLayoutId);
ft.add(R.id.content, mFragment, mTag);
} else {
ft.attach(mFragment);
}

mSelectedLayoutId = mFragment.getLayoutId();
public Fragment getItem(int position) {
return mFragments.get(position);
}

@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
if (mFragment != null) {
ft.detach(mFragment);
}
public int getCount() {
return mFragments.size();
}

@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
public CharSequence getPageTitle(int position) {
return mFragmentTitles.get(position);
}
}
}
Binary file modified sample/src/main/res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/main/res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/src/main/res/drawable-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions sample/src/main/res/layout/tabs_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!--
~ Copyright (C) 2014 Lucas Rocha
~
~ 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.
-->

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"
/>

<android.support.v4.view.ViewPager
android:id="@+id/pagers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabs"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_gravity="bottom|center"
android:layout_alignBottom="@id/pagers">

<TextView
android:id="@+id/position"
style="@style/StateText"/>

<TextView
android:id="@+id/count"
style="@style/StateText"/>

<TextView
android:id="@+id/state"
style="@style/StateText"/>

</LinearLayout>

</RelativeLayout>
2 changes: 1 addition & 1 deletion sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
<color name="item_default_color">#EEEEEE</color>
<color name="item_pressed_color">#CCCCCC</color>
<color name="item_activated_color">#77CEEE</color>

<color name="black">#000000</color>
</resources>
4 changes: 4 additions & 0 deletions sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>

<style name="NoActionBarTheme" parent="Theme.AppCompat.NoActionBar">

</style>

<style name="TwoWayViewBase">
<item name="android:background">#999999</item>
</style>
Expand Down