Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "sk.inloop.support"
Copy link
Copy Markdown

@DanielNovak DanielNovak Dec 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using "eu.inloop....."

minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/adammihalik/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sk.inloop.support.sample;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("sk.inloop.support.sample", appContext.getPackageName());
}
}
28 changes: 28 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sk.inloop.support.sample">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".IncorrectMainActivity"
android:label="@string/fail_activity_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".FixedMainActivity"
android:label="@string/fixed_activity_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>

</manifest>
56 changes: 56 additions & 0 deletions app/src/main/java/sk/inloop/support/sample/FixedMainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package sk.inloop.support.sample;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

import sk.inloop.support.sample.adapter.CorrectFragmentAdapter;

public class FixedMainActivity extends AppCompatActivity {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should separate these "test" activities into a separate module - so that it's not part of the library .aar.


private CorrectFragmentAdapter mSectionsPagerAdapter;

private ViewPager mViewPager;

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

Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

mSectionsPagerAdapter = new CorrectFragmentAdapter(getSupportFragmentManager());

mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);

((Button)findViewById(R.id.test_start_btn)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSectionsPagerAdapter.toggleState();
}
});

((Button)findViewById(R.id.switch_tests_btn)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FixedMainActivity.this, IncorrectMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
FixedMainActivity.this.startActivity(intent);
}
});
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package sk.inloop.support.sample;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

import sk.inloop.support.sample.adapter.IncorrectFragmentAdapter;

public class IncorrectMainActivity extends AppCompatActivity {

private IncorrectFragmentAdapter mSectionsPagerAdapter;

private ViewPager mViewPager;

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

Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

mSectionsPagerAdapter = new IncorrectFragmentAdapter(getSupportFragmentManager());

mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);

((Button)findViewById(R.id.test_start_btn)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSectionsPagerAdapter.toggleState();
}
});

((Button)findViewById(R.id.switch_tests_btn)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(IncorrectMainActivity.this, FixedMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
IncorrectMainActivity.this.startActivity(intent);
}
});
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}

}
38 changes: 38 additions & 0 deletions app/src/main/java/sk/inloop/support/sample/SampleFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package sk.inloop.support.sample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
* Created by adammihalik on 05/12/2016.
*/

public class SampleFragment extends Fragment {
public static SampleFragment newInstance(String label) {
Bundle bundle = new Bundle();
bundle.putString("label", label);
SampleFragment testFragment = new SampleFragment();
testFragment.setArguments(bundle);
return testFragment;
}

public String getLabel() {
return getArguments().getString("label");
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_template, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
((TextView)view.findViewById(R.id.fragment_label)).setText(getLabel());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package sk.inloop.support.sample.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

import sk.inloop.support.sample.SampleFragment;
import sk.inloop.support.v4.app.FragmentStatePagerAdapter;

/**
* Extends {@link sk.inloop.support.v4.app.FragmentStatePagerAdapter}, therefore {@link #notifyDataSetChanged()} will not fail.
*/
public class CorrectFragmentAdapter extends FragmentStatePagerAdapter {

private boolean mState = true;

public CorrectFragmentAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}

@Override
public int getCount() {
return 3;
}

public void toggleState() {
mState = !mState;
notifyDataSetChanged();
}

private String getLabel(int position) {
switch (position) {
case 0:
return "A";
case 1:
return mState ? "B" : "C";
default:
return mState ? "C" : "B";
}
}

@Override
public int getItemPosition(Object object) {
String label = ((SampleFragment) object).getLabel();
if (label.equals("A")) {
return 0;
} else if (label.equals("B")) {
return mState ? 1 : 2;
} else {
return mState ? 2 : 1;
}
}

@Override
public CharSequence getPageTitle(int position) {
return getLabel(position);
}

@Override
public Fragment getItem(int position) {
return SampleFragment.newInstance(getLabel(position));
}
}
Loading